Skip to content
  • David Howells's avatar
    [PATCH] VFS: Destroy the dentries contributed by a superblock on unmounting · c636ebdb
    David Howells authored
    
    
    The attached patch destroys all the dentries attached to a superblock in one go
    by:
    
     (1) Destroying the tree rooted at s_root.
    
     (2) Destroying every entry in the anon list, one at a time.
    
     (3) Each entry in the anon list has its subtree consumed from the leaves
         inwards.
    
    This reduces the amount of work generic_shutdown_super() does, and avoids
    iterating through the dentry_unused list.
    
    Note that locking is almost entirely absent in the shrink_dcache_for_umount*()
    functions added by this patch.  This is because:
    
     (1) at the point the filesystem calls generic_shutdown_super(), it is not
         permitted to further touch the superblock's set of dentries, and nor may
         it remove aliases from inodes;
    
     (2) the dcache memory shrinker now skips dentries that are being unmounted;
         and
    
     (3) the superblock no longer has any external references through which the VFS
         can reach it.
    
    Given these points, the only locking we need to do is when we remove dentries
    from the unused list and the name hashes, which we do a directory's worth at a
    time.
    
    We also don't need to guard against reference counts going to zero unexpectedly
    and removing bits of the tree we're working on as nothing else can call dput().
    
    A cut down version of dentry_iput() has been folded into
    shrink_dcache_for_umount_subtree() function.  Apart from not needing to unlock
    things, it also doesn't need to check for inotify watches.
    
    In this version of the patch, the complaint about a dentry still being in use
    has been expanded from a single BUG_ON() and now gives much more information.
    
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Acked-by: default avatarNeilBrown <neilb@suse.de>
    Acked-by: default avatarIan Kent <raven@themaw.net>
    Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    c636ebdb