Re: [lkp] [nfsd] b44061d0b9: BUG: Dentry ffff880027d7c540{i=1846f,n=0a} still in use (1) [unmount of btrfs vda]

From: Jeff Layton
Date: Wed Aug 10 2016 - 15:06:33 EST


On Wed, 2016-08-10 at 14:46 -0400, Josef Bacik wrote:
> On 08/10/2016 02:25 PM, Linus Torvalds wrote:
> >
> > > > On Wed, Aug 10, 2016 at 11:22 AM, Josef Bacik <jbacik@xxxxxx> wrote:
> > >
> > > On 08/10/2016 02:06 PM, Linus Torvalds wrote:
> > > >
> > > >
> > > > More information in the original email on lkml.
> > >
> > > I'm not subscribed to lkml and for some reason I can't find the original
> > > email in any of the lkml/linux-nfs archives.ÂÂCould you forward more of the
> > > details?
> >
> > Done.
> >
>
> So my naive fix would be something like this
>
>
> > From: Josef Bacik <jbacik@xxxxxx>
> Date: Wed, 10 Aug 2016 14:43:08 -0400
> Subject: [PATCH] nfsd: fix dentry refcounting problem
>
> b44061d0b9 introduced a dentry ref counting bug, previously we were grabbing one
> ref to dchild in nfsd_create(), but with the creation of nfsd_create_locked() we
> have a ref for dchild from the lookup in nfsd_create(), and then another ref in
> nfsd_create_locked().ÂÂThe ref from the lookup in nfsd_create() is never dropped
> and results in dentries still in use at unmount.
>
> > Signed-off-by: Josef Bacik <jbacik@xxxxxx>
> ---
> Â fs/nfsd/vfs.c | 9 ++++++---
> Â 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index ba944123..ff476e6 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -1252,10 +1252,13 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > ÂÂ if (IS_ERR(dchild))
> > ÂÂ return nfserrno(host_err);
> > ÂÂ err = fh_compose(resfhp, fhp->fh_export, dchild, fhp);
> > - if (err) {
> > - dput(dchild);
> > + /*
> > + Â* We unconditionally drop our ref to dchild as fh_compose will have
> > + Â* already grabbed its own ref for it.
> > + Â*/
> > + dput(dchild);
> > + if (err)
> > ÂÂ return err;
> > - }
> > ÂÂ return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type,
> > ÂÂ rdev, resfhp);
> Â }

Looks correct to me:

Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>