From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Bruce Fields" Subject: [PATCH] nfsd4: allow __d_obtain_alias() to return unhashed dentries Date: Fri, 3 Dec 2010 17:33:27 -0500 Message-ID: <20101203223326.GB28763@fieldses.org> References: <20101112184353.GA32745@fieldses.org> <20101115174837.GB10044@fieldses.org> <20101129193248.GA9897@fieldses.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Nick Piggin , linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Alexander Viro Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-nfs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-fsdevel.vger.kernel.org =46rom: J. Bruce Fields Without this patch =C2=A0 =C2=A0 =C2=A0 =C2=A0client$ mount -tnfs4 server:/export/ /mnt/ =C2=A0 =C2=A0 =C2=A0 =C2=A0client$ tail -f /mnt/FOO =C2=A0 =C2=A0 =C2=A0 =C2=A0... =C2=A0 =C2=A0 =C2=A0 =C2=A0server$ df -i /export =C2=A0 =C2=A0 =C2=A0 =C2=A0server$ rm /export/FOO =C2=A0 =C2=A0 =C2=A0 =C2=A0(^C the tail -f) =C2=A0 =C2=A0 =C2=A0 =C2=A0server$ df -i /export =C2=A0 =C2=A0 =C2=A0 =C2=A0server$ echo 2 >/proc/sys/vm/drop_caches =C2=A0 =C2=A0 =C2=A0 =C2=A0server$ df -i /export the df's will show that the inode is not freed on the filesystem until the last step, when it could have been freed after killing the client's tail -f. =C2=A0On-disk data won't be deallocated either, leading to pos= sible spurious ENOSPC. This occurs because when the client does the close, it arrives in a compound with a putfh and a close, processed like: =C2=A0 =C2=A0 =C2=A0 =C2=A0- putfh: look up the filehandle. =C2=A0The o= nly alias found for the =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0inode will be DCACHE_UNHASHED alias r= eferenced by the filp =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0associated with the nfsd open. =C2=A0= d_obtain_alias() doesn't like =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0this, so it creates a new DCACHE_DISC= ONECTED dentry and =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0returns that instead. Nick Piggin suggested fixing this by allowing d_obtain_alias to return the unhashed dentry that is referenced by the filp, instead of making i= t create a new dentry. Cc: Nick Piggin Signed-off-by: J. Bruce Fields --- fs/dcache.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) 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 w= rote: > >> > 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? > >> >>> > >> >>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (S_ISDIR= (inode->i_mode) || !d_unhashed(alias)) { > >> >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=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 any= 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 dent= ry may > >> > be unhashed at any time concurrently to nfsd operation, so it sh= ould 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? It = seems > >> to work in my testing (and do the right thing with freeing the ino= de). > > > > Bah, sorry, I read too quickly, got the sense of the test backwards= , and > > thought you were suggesting __d_find_alias() shouldn't return an al= ias > > 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? =C2=A0Could w= e get rid > > of it entirely? >=20 > Well when the inode still has links I think we actually do want any n= ew > references to go to hashed dentries. Definitely for d_splice_alias. So here's a version with a changelog; objections? --b. 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 inode = *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; --=20 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html