linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* lifetime of DCACHE_DISCONECTED dentries
@ 2010-11-12 18:43 J. Bruce Fields
  2010-11-13 11:53 ` Nick Piggin
  0 siblings, 1 reply; 41+ messages in thread
From: J. Bruce Fields @ 2010-11-12 18:43 UTC (permalink / raw)
  To: linux-nfs, linux-fsdevel

DCACHE_DISCONECTED dentries aren't always getting destroyed as soon as
I'd have expected in the NFSv4 case.

I'm not sure what the right fix is; any ideas?  The below at least
demonstrates the problem.

--b.

commit bb125ffbe5fc3f80ac7a5b20f51cc542c175cd49
Author: J. Bruce Fields <bfields@redhat.com>
Date:   Thu Nov 11 19:22:00 2010 -0500

    dput: free DCACHE_DISCONNECTED dentries sooner
    
    DCACHE_DISCONECTED dentries are normally left around for the benefit of
    future nfsd operations.  But there's no point keeping them around once
    the inode has been deleted.
    
    Without this patch
    
    	client$ mount -tnfs4 server:/export/ /mnt/
    	client$ tail -f /mnt/FOO
    	...
    	server$ df -i /export
    	server$ rm /export/FOO
    	(^C the tail -f)
    	server$ df -i /export
    	server$ echo 2 >/proc/sys/vm/drop_caches
    	server$ 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.  On-disk data won't be deallocated either, leading to possible
    spurious ENOSPC.
    
    This occurs because when the client does the close, it arrives in a
    compound with a putfh and a close, processed like:
    
    	- putfh: look up the filehandle.  The only alias found for the
    	  inode will be DCACHE_UNHASHED alias referenced by the filp
    	  associated with the nfsd open.  d_obtain_alias() doesn't like
    	  this, so it creates a new DCACHE_DISCONECTED dentry and
    	  returns that instead.
    	- close: closes the existing filp, which is destroyed
    	  immediately by dput() since it's DCACHE_UNHASHED.
    	- end of the compound: release the reference to the current
    	  filehandle, and dput() the new DCACHE_DISCONECTED dentry,
    	  which gets put on the unused list instead of being destroyed
    	  immediately.
    
    Signed-off-by: J. Bruce Fields <bfields@redhat.com>

diff --git a/fs/dcache.c b/fs/dcache.c
index 28fa7e5..5132f13 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -241,6 +241,10 @@ repeat:
 	/* Unreachable? Get rid of it */
  	if (d_unhashed(dentry))
 		goto kill_it;
+	if (dentry->d_flags & DCACHE_DISCONNECTED
+	    && dentry->d_inode
+	    && dentry->d_inode->i_nlink == 0)
+		goto kill_it;
   	if (list_empty(&dentry->d_lru)) {
   		dentry->d_flags |= DCACHE_REFERENCED;
 		dentry_lru_add(dentry);

^ permalink raw reply related	[flat|nested] 41+ messages in thread
* DCACHE_DISCONNECTED patches
@ 2012-05-09 21:18 J. Bruce Fields
       [not found] ` <1336598286-28636-1-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 41+ messages in thread
From: J. Bruce Fields @ 2012-05-09 21:18 UTC (permalink / raw)
  To: Al Viro
  Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA

This is a resend of a couple DCACHE_DISCONNECTED patches that I think
could go into 3.5.

--b.

--
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

^ permalink raw reply	[flat|nested] 41+ messages in thread
* [PATCH 1/2] vfs: stop d_splice_alias creating directory aliases
@ 2012-05-23 22:05 J. Bruce Fields
  2012-05-23 22:05 ` [PATCH 2/2] vfs: remove unused __d_splice_alias argument J. Bruce Fields
  0 siblings, 1 reply; 41+ messages in thread
From: J. Bruce Fields @ 2012-05-23 22:05 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, linux-nfs, J. Bruce Fields

From: "J. Bruce Fields" <bfields@redhat.com>

A directory should never have more than one dentry pointing to it.

But d_splice_alias() will add one if it finds a directory with an
already-existing non-DISCONNECTED dentry.

I can't find an obvious reproducer, but I also can't see what prevents
d_splice_alias() from encountering such a case.

It therefore seems safest to allow d_splice_alias to use any dentry it
finds.

(Prior to the removal of dentry_unhash() from vfs_rmdir(), around v3.0,
this could cause an nfsd deadlock like this:

	- Somebody attempts to remove a non-empty directory.
	- The dentry_unhash() in vfs_rmdir() unhashes the dentry
	  pointing to the non-empty directory.
	- ->rmdir() then fails with -ENOTEMPTY
	- Before the vfs_rmdir() caller reaches dput(), an nfsd process
	  in rename looks up the directory by filehandle; at the end of
	  that lookup, this dentry is found by d_alloc_anon(), and a
	  reference is taken on it, preventing dput() from removing it.
	- A regular lookup of the directory calls d_splice_alias(),
	  finds only an unhashed (not a DISCONNECTED) dentry, and
	  insteads adds a new one, so the directory now has two
	  dentries.
	- The nfsd process in rename, which was previously looking up
	  the source directory of the rename, now looks up the target
	  directory (which is the same), and gets the dentry newly
	  created by the previous lookup.
	- The rename, seeing two different dentries, assumes this is a
	  cross-directory rename and attempts to take the i_mutex on the
	  directory twice.

That reproducer no longer exists, but I don't think there was anything
fundamentally incorrect about the vfs_rmdir() behavior there, so I think
the real fault was here in d_splice_alias().)

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/dcache.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index b60ddc4..2434c1e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1606,9 +1606,8 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
 
 	if (inode && S_ISDIR(inode->i_mode)) {
 		spin_lock(&inode->i_lock);
-		new = __d_find_alias(inode, 1);
+		new = __d_find_any_alias(inode);
 		if (new) {
-			BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED));
 			spin_unlock(&inode->i_lock);
 			security_d_instantiate(new, inode);
 			d_move(new, dentry);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2012-07-01 23:15 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-12 18:43 lifetime of DCACHE_DISCONECTED dentries J. Bruce Fields
2010-11-13 11:53 ` Nick Piggin
2010-11-15 17:48   ` J. Bruce Fields
     [not found]     ` <20101115174837.GB10044-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-11-16  6:45       ` Nick Piggin
2010-11-29  3:56         ` Nick Piggin
2010-11-29 19:32           ` J. Bruce Fields
     [not found]             ` <20101129193248.GA9897-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-11-30  1:00               ` Nick Piggin
     [not found]                 ` <AANLkTikwzDJ_q65==uxDsAhp3h8bU7Rkt7U9gVgRAK0D-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-11-30 18:39                   ` J. Bruce Fields
2010-12-03 22:33                   ` [PATCH] nfsd4: allow __d_obtain_alias() to return unhashed dentries J. Bruce Fields
2010-12-13  5:19                     ` Nick Piggin
2010-12-14 22:01                       ` J. Bruce Fields
     [not found]                         ` <20101214220102.GM24828-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-12-17 17:53                           ` [PATCH] fs/dcache: use standard list macro for d_find_alias J. Bruce Fields
2010-12-17 18:00                           ` [PATCH 2/2] fs/dcache: allow __d_obtain_alias() to return unhashed dentries J. Bruce Fields
2010-12-18  2:01                             ` Nick Piggin
2010-12-18 16:16                               ` J. Bruce Fields
     [not found]                                 ` <20101218161609.GA22150-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2010-12-19 14:53                                   ` Nick Piggin
     [not found]                                     ` <AANLkTingRv_gtRSctGzMfYrKg02M_sKj97HSQPRm_mA_-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-27 23:46                                       ` [PATCH] " J. Bruce Fields
     [not found]                                         ` <20101227234641.GA22248-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-01-18 20:45                                           ` J. Bruce Fields
     [not found]                                             ` <20110118204509.GA10903-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-01-18 22:02                                               ` Nick Piggin
     [not found]                                                 ` <AANLkTikL2CDSWQJ1QH_Y4G-j70Vd=VesNMMnYTmMGHC9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-01-18 22:08                                                   ` J. Bruce Fields
     [not found]                                                     ` <20110118220817.GF10903-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-03-08 18:13                                                       ` J. Bruce Fields
     [not found]                                                         ` <20110308181320.GA15566-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2011-03-10 10:58                                                           ` Al Viro
     [not found]                                                             ` <20110310105821.GE22723-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2011-03-11  4:07                                                               ` NeilBrown
     [not found]                                                                 ` <20110311150749.2fa2be66-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-14 17:03                                                                   ` J. Bruce Fields
     [not found]                                                                     ` <20120214170300.GA4309-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-15 16:56                                                                       ` J. Bruce Fields
     [not found]                                                                         ` <20120215165633.GE12490-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-16  3:06                                                                           ` NeilBrown
     [not found]                                                                             ` <20120216140603.08cb4900-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-16 11:51                                                                               ` J. Bruce Fields
     [not found]                                                                                 ` <20120216115133.GA20279-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-16 16:08                                                                                   ` J. Bruce Fields
2012-02-16 22:30                                                                             ` J. Bruce Fields
     [not found]                                                                               ` <20120216223011.GA23997-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-02-17 16:34                                                                                 ` Peng Tao
2012-03-13 20:55                                                                                   ` J. Bruce Fields
2012-03-13 20:58                                                                                     ` [PATCH 1/2] vfs: stop d_splice_alias creating directory aliases J. Bruce Fields
2012-03-13 20:58                                                                                     ` [PATCH 2/2] vfs: remove unused __d_splice_alias argument J. Bruce Fields
2012-02-20  2:55                                                                                 ` [PATCH] fs/dcache: allow __d_obtain_alias() to return unhashed dentries NeilBrown
     [not found]                                                                                   ` <20120220135537.3078e20b-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-02-29 23:10                                                                                     ` J. Bruce Fields
2012-06-28 13:59                                                                   ` J. Bruce Fields
     [not found]                                                                     ` <20120628135927.GA6406-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-06-29 20:10                                                                       ` J. Bruce Fields
     [not found]                                                                         ` <20120629201034.GA17103-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2012-06-29 20:29                                                                           ` J. Bruce Fields
2012-07-01 23:15                                                                             ` NeilBrown
  -- strict thread matches above, loose matches on Subject: below --
2012-05-09 21:18 DCACHE_DISCONNECTED patches J. Bruce Fields
     [not found] ` <1336598286-28636-1-git-send-email-bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-05-09 21:18   ` [PATCH 2/2] vfs: remove unused __d_splice_alias argument J. Bruce Fields
2012-05-23 22:05 [PATCH 1/2] vfs: stop d_splice_alias creating directory aliases J. Bruce Fields
2012-05-23 22:05 ` [PATCH 2/2] vfs: remove unused __d_splice_alias argument J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).