From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Piggin Subject: Re: [PATCH] nfsd4: allow __d_obtain_alias() to return unhashed dentries Date: Mon, 13 Dec 2010 16:19:44 +1100 Message-ID: <20101213051944.GA8688@amd> References: <20101112184353.GA32745@fieldses.org> <20101115174837.GB10044@fieldses.org> <20101129193248.GA9897@fieldses.org> <20101203223326.GB28763@fieldses.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Alexander Viro , Nick Piggin , linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org To: "J. Bruce Fields" Return-path: Received: from ipmail06.adl2.internode.on.net ([150.101.137.129]:24199 "EHLO ipmail06.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903Ab0LMFTu (ORCPT ); Mon, 13 Dec 2010 00:19:50 -0500 Content-Disposition: inline In-Reply-To: <20101203223326.GB28763@fieldses.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Dec 03, 2010 at 05:33:27PM -0500, J. Bruce Fields wrote: > From: J. Bruce Fields >=20 > Without this patch >=20 > =A0 =A0 =A0 =A0client$ mount -tnfs4 server:/export/ /mnt/ > =A0 =A0 =A0 =A0client$ tail -f /mnt/FOO > =A0 =A0 =A0 =A0... > =A0 =A0 =A0 =A0server$ df -i /export > =A0 =A0 =A0 =A0server$ rm /export/FOO > =A0 =A0 =A0 =A0(^C the tail -f) > =A0 =A0 =A0 =A0server$ df -i /export > =A0 =A0 =A0 =A0server$ echo 2 >/proc/sys/vm/drop_caches > =A0 =A0 =A0 =A0server$ df -i /export >=20 > the df's will show that the inode is not freed on the filesystem unti= l > the last step, when it could have been freed after killing the client= 's > tail -f. =A0On-disk data won't be deallocated either, leading to poss= ible > spurious ENOSPC. >=20 > This occurs because when the client does the close, it arrives in a > compound with a putfh and a close, processed like: >=20 > =A0 =A0 =A0 =A0- putfh: look up the filehandle. =A0The only alias fou= nd for the > =A0 =A0 =A0 =A0 =A0inode will be DCACHE_UNHASHED alias referenced by = the filp > =A0 =A0 =A0 =A0 =A0associated with the nfsd open. =A0d_obtain_alias()= doesn't like > =A0 =A0 =A0 =A0 =A0this, so it creates a new DCACHE_DISCONECTED dentr= y and > =A0 =A0 =A0 =A0 =A0returns that instead. >=20 > Nick Piggin suggested fixing this by allowing d_obtain_alias to retur= n > the unhashed dentry that is referenced by the filp, instead of making= it > create a new dentry. >=20 > Cc: Nick Piggin > Signed-off-by: J. Bruce Fields > --- > fs/dcache.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) >=20 > On Tue, Nov 30, 2010 at 12:00:16PM +1100, Nick Piggin wrote: > > On Tue, Nov 30, 2010 at 6:32 AM, J. Bruce Fields wrote: > > > On Mon, Nov 29, 2010 at 02:56:22PM +1100, Nick Piggin wrote: > > >> On Tue, Nov 16, 2010 at 5:45 PM, Nick Piggin = wrote: > > >> > On Tue, Nov 16, 2010 at 4:48 AM, J. Bruce Fields wrote: > > >> >> On Sat, Nov 13, 2010 at 10:53:12PM +1100, Nick Piggin wrote: > > >> >>> Can you even put the link check into __d_find_alias? > > >> >>> > > >> >>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (S_ISDIR(inode->i_mode) || = !d_unhashed(alias)) { > > >> >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (S_ISDIR(inode->i_mode) || = !inode->i_nlink || > > >> >>> !d_unhashed(alias)) { > > >> >>> > > >> >>> Something like that? > > >> >> > > >> >> The immediate result of that would be for the close rpc (or a= ny rpc's > > >> >> sent after the file was unlinked) to fail with ESTALE. > > >> > > > >> > Why is that? Seems like it would be a bug, because a hashed de= ntry may > > >> > be unhashed at any time concurrently to nfsd operation, so it = should be > > >> > able to tolerate that so long as it has a ref on the inode? > > >> > > >> Ping? Did you work out why nfs fails with ESTALE in that case? I= t seems > > >> to work in my testing (and do the right thing with freeing the i= node). > > > > > > Bah, sorry, I read too quickly, got the sense of the test backwar= ds, and > > > thought you were suggesting __d_find_alias() shouldn't return an = alias > > > in the i_nlink =3D=3D 0 case! > > > > > > Yes, agreed, that should solve my problem. > >=20 > > OK, good. > >=20 > > > But what's the reason for the d_unhashed() check now? =A0Could we= get rid > > > of it entirely? > >=20 > > Well when the inode still has links I think we actually do want any= new > > references to go to hashed dentries. Definitely for d_splice_alias. >=20 > So here's a version with a changelog; objections? Not sure where Al's hiding... But I would like to update the comments, and perhaps even a new add a new function here (or new flag to __d_find_alias). AFAIKS, the callers are OK, however I suppose d_splice_alias and d_materialise_unique should not have unlinked inodes at this point, so at least a BUG_ON for them might be a good idea? >=20 > --b. >=20 > diff --git a/fs/dcache.c b/fs/dcache.c > index 23702a9..afa8a0d 100644 > --- a/fs/dcache.c > +++ b/fs/dcache.c > @@ -368,7 +368,7 @@ static struct dentry * __d_find_alias(struct inod= e *inode, int want_discon) > next =3D tmp->next; > prefetch(next); > alias =3D list_entry(tmp, struct dentry, d_alias); > - if (S_ISDIR(inode->i_mode) || !d_unhashed(alias)) { > + if (S_ISDIR(inode->i_mode) || !inode->i_nlink || !d_unhashed(alias= )) { > if (IS_ROOT(alias) && > (alias->d_flags & DCACHE_DISCONNECTED)) > discon_alias =3D alias; -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html