X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=fs%2Fautofs4%2Fexpire.c;h=053d92a745b91c9624cc585f54b718bb8dc22c63;hb=1aff3c8b0511b5bb54acf7859e0c6ec9ae7287a9;hp=bcc17f533699728658ea6833a4ec0e160f5ce65d;hpb=1f5f2c3059ae8cc23cb3303daf324b06ba79517a;p=linux-2.6-omap-h63xx.git diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c index bcc17f53369..053d92a745b 100644 --- a/fs/autofs4/expire.c +++ b/fs/autofs4/expire.c @@ -72,6 +72,27 @@ done: return status; } +/* + * Calculate next entry in top down tree traversal. + * From next_mnt in namespace.c - elegant. + */ +static struct dentry *next_dentry(struct dentry *p, struct dentry *root) +{ + struct list_head *next = p->d_subdirs.next; + + if (next == &p->d_subdirs) { + while (1) { + if (p == root) + return NULL; + next = p->d_u.d_child.next; + if (next != &p->d_parent->d_subdirs) + break; + p = p->d_parent; + } + } + return list_entry(next, struct dentry, d_u.d_child); +} + /* Check a directory tree of mount points for busyness * The tree is not busy iff no mountpoints are busy */ @@ -80,8 +101,8 @@ static int autofs4_tree_busy(struct vfsmount *mnt, unsigned long timeout, int do_now) { - struct dentry *this_parent = top; - struct list_head *next; + struct autofs_info *ino; + struct dentry *p; DPRINTK("top %p %.*s", top, (int)top->d_name.len, top->d_name.name); @@ -90,58 +111,52 @@ static int autofs4_tree_busy(struct vfsmount *mnt, if (!simple_positive(top)) return 1; - /* Timeout of a tree mount is determined by its top dentry */ - if (!autofs4_can_expire(top, timeout, do_now)) - return 1; - - /* Is someone visiting anywhere in the tree ? */ - if (may_umount_tree(mnt)) - return 1; - spin_lock(&dcache_lock); -repeat: - next = this_parent->d_subdirs.next; -resume: - while (next != &this_parent->d_subdirs) { - struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); - + for (p = top; p; p = next_dentry(p, top)) { /* Negative dentry - give up */ - if (!simple_positive(dentry)) { - next = next->next; + if (!simple_positive(p)) continue; - } DPRINTK("dentry %p %.*s", - dentry, (int)dentry->d_name.len, dentry->d_name.name); - - if (!simple_empty_nolock(dentry)) { - this_parent = dentry; - goto repeat; - } + p, (int) p->d_name.len, p->d_name.name); - dentry = dget(dentry); + p = dget(p); spin_unlock(&dcache_lock); - if (d_mountpoint(dentry)) { - /* First busy => tree busy */ - if (autofs4_mount_busy(mnt, dentry)) { - dput(dentry); + /* + * Is someone visiting anywhere in the subtree ? + * If there's no mount we need to check the usage + * count for the autofs dentry. + */ + ino = autofs4_dentry_ino(p); + if (d_mountpoint(p)) { + if (autofs4_mount_busy(mnt, p)) { + dput(p); return 1; } - } + } else { + unsigned int ino_count = atomic_read(&ino->count); - dput(dentry); - spin_lock(&dcache_lock); - next = next->next; - } + /* allow for dget above and top is already dgot */ + if (p == top) + ino_count += 2; + else + ino_count++; - if (this_parent != top) { - next = this_parent->d_u.d_child.next; - this_parent = this_parent->d_parent; - goto resume; + if (atomic_read(&p->d_count) > ino_count) { + dput(p); + return 1; + } + } + dput(p); + spin_lock(&dcache_lock); } spin_unlock(&dcache_lock); + /* Timeout of a tree mount is ultimately determined by its top dentry */ + if (!autofs4_can_expire(top, timeout, do_now)) + return 1; + return 0; } @@ -150,59 +165,38 @@ static struct dentry *autofs4_check_leaves(struct vfsmount *mnt, unsigned long timeout, int do_now) { - struct dentry *this_parent = parent; - struct list_head *next; + struct dentry *p; DPRINTK("parent %p %.*s", parent, (int)parent->d_name.len, parent->d_name.name); spin_lock(&dcache_lock); -repeat: - next = this_parent->d_subdirs.next; -resume: - while (next != &this_parent->d_subdirs) { - struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); - + for (p = parent; p; p = next_dentry(p, parent)) { /* Negative dentry - give up */ - if (!simple_positive(dentry)) { - next = next->next; + if (!simple_positive(p)) continue; - } DPRINTK("dentry %p %.*s", - dentry, (int)dentry->d_name.len, dentry->d_name.name); + p, (int) p->d_name.len, p->d_name.name); - if (!list_empty(&dentry->d_subdirs)) { - this_parent = dentry; - goto repeat; - } - - dentry = dget(dentry); + p = dget(p); spin_unlock(&dcache_lock); - if (d_mountpoint(dentry)) { + if (d_mountpoint(p)) { /* Can we expire this guy */ - if (!autofs4_can_expire(dentry, timeout, do_now)) + if (!autofs4_can_expire(p, timeout, do_now)) goto cont; /* Can we umount this guy */ - if (!autofs4_mount_busy(mnt, dentry)) - return dentry; + if (!autofs4_mount_busy(mnt, p)) + return p; } cont: - dput(dentry); + dput(p); spin_lock(&dcache_lock); - next = next->next; - } - - if (this_parent != parent) { - next = this_parent->d_u.d_child.next; - this_parent = this_parent->d_parent; - goto resume; } spin_unlock(&dcache_lock); - return NULL; }