From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Bruce Fields" Subject: Re: [PATCH 2/2] fs/dcache: allow __d_obtain_alias() to return unhashed dentries Date: Sat, 18 Dec 2010 11:16:09 -0500 Message-ID: <20101218161609.GA22150@fieldses.org> References: <20101115174837.GB10044@fieldses.org> <20101129193248.GA9897@fieldses.org> <20101203223326.GB28763@fieldses.org> <20101213051944.GA8688@amd> <20101214220102.GM24828@fieldses.org> <20101217180022.GB11515@fieldses.org> <20101218020118.GA3179@amd> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Alexander Viro , Nick Piggin , linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Nick Piggin Return-path: Content-Disposition: inline In-Reply-To: <20101218020118.GA3179@amd> Sender: linux-nfs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-fsdevel.vger.kernel.org On Sat, Dec 18, 2010 at 01:01:18PM +1100, Nick Piggin wrote: > On Fri, Dec 17, 2010 at 01:00:23PM -0500, J. Bruce Fields wrote: > > From: J. Bruce Fields > >=20 > > Without this patch > >=20 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0client$ mount -tnfs4 server:/export/ /mn= t/ > > =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 > >=20 > > the df's will show that the inode is not freed on the filesystem un= til > > the last step, when it could have been freed after killing the clie= nt's > > tail -f. =C2=A0On-disk data won't be deallocated either, leading to= possible > > 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 > > =C2=A0 =C2=A0 =C2=A0 =C2=A0- putfh: look up the filehandle. =C2=A0T= he only alias found for the > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0inode will be DCACHE_UNHASHED ali= as referenced by the filp > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0associated with the nfsd open. =C2= =A0d_obtain_alias() doesn't like > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0this, so it creates a new DCACHE_= DISCONECTED dentry and > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0returns that instead. > >=20 > > Nick Piggin suggested fixing this by allowing d_obtain_alias to ret= urn > > the unhashed dentry that is referenced by the filp, instead of maki= ng it > > create a new dentry. > >=20 > > Leave __d_find_alias() alone to avoid changing behavior of other > > callers. > >=20 > > Also nfsd doesn't need all the checks of __d_find_alias(); any dent= ry, > > hashed or unhashed, disconnected or not, should work. > >=20 > > Signed-off-by: J. Bruce Fields > > --- > > fs/dcache.c | 26 ++++++++++++++++++++++++-- > > 1 files changed, 24 insertions(+), 2 deletions(-) > >=20 > > On Tue, Dec 14, 2010 at 05:01:02PM -0500, J. Bruce Fields wrote: > > > On Mon, Dec 13, 2010 at 04:19:44PM +1100, Nick Piggin wrote: > > > > Not sure where Al's hiding... > > > >=20 > > > > 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). > > > >=20 > > > > AFAIKS, the callers are OK, however I suppose d_splice_alias an= d > > > > d_materialise_unique should not have unlinked inodes at this po= int, > > > > so at least a BUG_ON for them might be a good idea? > > >=20 > > > That does sound safer. I'm pretty confused by the various > > > __di_splice_alias callers. I'll go search through them and see i= f I can > > > understand better.... > >=20 > > I think a new __d_find_alias flag would just make it more confusing= =2E > > And it looks like all d_obtain_alias needs is something much simple= r. > > This works for me. >=20 > Well I don't really know if this is clearer. By convention, > __ prefix version should be same as non prefix version but just > take fewer locks. Why do you have the new d_find_any_alias()? Argh, apologies; with typo fixed. --b. commit 5a911af645aae9992d465d57c397237fb35d1f93 Author: J. Bruce Fields Date: Fri Dec 17 09:05:04 2010 -0500 fs/dcache: allow __d_obtain_alias() to return unhashed dentries =20 Without this patch =20 =C2=A0 =C2=A0 =C2=A0 =C2=A0client$ mount -tnfs4 server:/export/ /mn= t/ =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 =20 the df's will show that the inode is not freed on the filesystem un= til the last step, when it could have been freed after killing the clie= nt's tail -f. =C2=A0On-disk data won't be deallocated either, leading to= possible 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 =C2=A0 =C2=A0 =C2=A0 =C2=A0- putfh: look up the filehandle. =C2=A0T= he only alias found for the =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0inode will be DCACHE_UNHASHED ali= as referenced by the filp =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0associated with the nfsd open. =C2= =A0d_obtain_alias() doesn't like =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0this, so it creates a new DCACHE_= DISCONECTED dentry and =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0returns that instead. =20 Nick Piggin suggested fixing this by allowing d_obtain_alias to ret= urn the unhashed dentry that is referenced by the filp, instead of maki= ng it create a new dentry. =20 Leave __d_find_alias() alone to avoid changing behavior of other callers. =20 Also nfsd doesn't need all the checks of __d_find_alias(); any dent= ry, hashed or unhashed, disconnected or not, should work. =20 Signed-off-by: J. Bruce Fields diff --git a/fs/dcache.c b/fs/dcache.c index 5ed93cd..5c014a5 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1135,6 +1135,28 @@ static inline struct hlist_head *d_hash(struct d= entry *parent, return dentry_hashtable + (hash & D_HASHMASK); } =20 +static struct dentry * __d_find_any_alias(struct inode *inode) +{ + struct dentry *alias; + + if (list_empty(&inode->i_dentry)) + return NULL; + alias =3D list_first_entry(&inode->i_dentry, struct dentry, d_alias); + __dget_locked(alias); + return alias; +} + +static struct dentry * d_find_any_alias(struct inode *inode) +{ + struct dentry *de; + + spin_lock(&dcache_lock); + de =3D __d_find_any_alias(inode); + spin_unlock(&dcache_lock); + return de; +} + + /** * d_obtain_alias - find or allocate a dentry for a given inode * @inode: inode to allocate the dentry for @@ -1164,7 +1186,7 @@ struct dentry *d_obtain_alias(struct inode *inode= ) if (IS_ERR(inode)) return ERR_CAST(inode); =20 - res =3D d_find_alias(inode); + res =3D d_find_any_alias(inode); if (res) goto out_iput; =20 @@ -1176,7 +1198,7 @@ struct dentry *d_obtain_alias(struct inode *inode= ) tmp->d_parent =3D tmp; /* make sure dput doesn't croak */ =20 spin_lock(&dcache_lock); - res =3D __d_find_alias(inode, 0); + res =3D __d_find_any_alias(inode); if (res) { spin_unlock(&dcache_lock); dput(tmp); -- 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