Commit e0a7aae9 authored by Ian Kent's avatar Ian Kent Committed by Linus Torvalds

[PATCH] autofs4: expire mounts that hold no (extra) references only

Alter the expire semantics that define how "busyness" is determined.
Currently a last_used counter is updated on every revalidate from processes
other than the mount owner process group.

This patch changes that so that an expire candidate is busy only if it has a
reference count greater than the expected minimum, such as when there is an
open file or working directory in use.

This method is the only way that busyness can be established for direct mounts
within the new implementation.  For consistency the expire semantic is made
the same for all mounts.

A side effect of the patch is that mounts which remain mounted unessessarily
in the presence of some GUI programs that scan the filesystem should now
expire.
Signed-off-by: default avatarIan Kent <raven@themaw.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 1aff3c8b
...@@ -47,6 +47,7 @@ static inline int autofs4_can_expire(struct dentry *dentry, ...@@ -47,6 +47,7 @@ static inline int autofs4_can_expire(struct dentry *dentry,
/* Check a mount point for busyness */ /* Check a mount point for busyness */
static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry) static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
{ {
struct dentry *top = dentry;
int status = 1; int status = 1;
DPRINTK("dentry %p %.*s", DPRINTK("dentry %p %.*s",
...@@ -62,9 +63,14 @@ static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry) ...@@ -62,9 +63,14 @@ static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
if (is_autofs4_dentry(dentry)) if (is_autofs4_dentry(dentry))
goto done; goto done;
/* The big question */ /* Update the expiry counter if fs is busy */
if (may_umount_tree(mnt) == 0) if (may_umount_tree(mnt)) {
status = 0; struct autofs_info *ino = autofs4_dentry_ino(top);
ino->last_used = jiffies;
goto done;
}
status = 0;
done: done:
DPRINTK("returning = %d", status); DPRINTK("returning = %d", status);
mntput(mnt); mntput(mnt);
...@@ -101,7 +107,7 @@ static int autofs4_tree_busy(struct vfsmount *mnt, ...@@ -101,7 +107,7 @@ static int autofs4_tree_busy(struct vfsmount *mnt,
unsigned long timeout, unsigned long timeout,
int do_now) int do_now)
{ {
struct autofs_info *ino; struct autofs_info *top_ino = autofs4_dentry_ino(top);
struct dentry *p; struct dentry *p;
DPRINTK("top %p %.*s", DPRINTK("top %p %.*s",
...@@ -127,14 +133,16 @@ static int autofs4_tree_busy(struct vfsmount *mnt, ...@@ -127,14 +133,16 @@ static int autofs4_tree_busy(struct vfsmount *mnt,
* Is someone visiting anywhere in the subtree ? * Is someone visiting anywhere in the subtree ?
* If there's no mount we need to check the usage * If there's no mount we need to check the usage
* count for the autofs dentry. * count for the autofs dentry.
* If the fs is busy update the expiry counter.
*/ */
ino = autofs4_dentry_ino(p);
if (d_mountpoint(p)) { if (d_mountpoint(p)) {
if (autofs4_mount_busy(mnt, p)) { if (autofs4_mount_busy(mnt, p)) {
top_ino->last_used = jiffies;
dput(p); dput(p);
return 1; return 1;
} }
} else { } else {
struct autofs_info *ino = autofs4_dentry_ino(p);
unsigned int ino_count = atomic_read(&ino->count); unsigned int ino_count = atomic_read(&ino->count);
/* allow for dget above and top is already dgot */ /* allow for dget above and top is already dgot */
...@@ -144,6 +152,7 @@ static int autofs4_tree_busy(struct vfsmount *mnt, ...@@ -144,6 +152,7 @@ static int autofs4_tree_busy(struct vfsmount *mnt,
ino_count++; ino_count++;
if (atomic_read(&p->d_count) > ino_count) { if (atomic_read(&p->d_count) > ino_count) {
top_ino->last_used = jiffies;
dput(p); dput(p);
return 1; return 1;
} }
...@@ -183,14 +192,13 @@ static struct dentry *autofs4_check_leaves(struct vfsmount *mnt, ...@@ -183,14 +192,13 @@ static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
if (d_mountpoint(p)) { if (d_mountpoint(p)) {
/* Can we expire this guy */ /* Can we umount this guy */
if (!autofs4_can_expire(p, timeout, do_now)) if (autofs4_mount_busy(mnt, p))
goto cont; goto cont;
/* Can we umount this guy */ /* Can we expire this guy */
if (!autofs4_mount_busy(mnt, p)) if (autofs4_can_expire(p, timeout, do_now))
return p; return p;
} }
cont: cont:
dput(p); dput(p);
...@@ -246,12 +254,12 @@ static struct dentry *autofs4_expire(struct super_block *sb, ...@@ -246,12 +254,12 @@ static struct dentry *autofs4_expire(struct super_block *sb,
DPRINTK("checking mountpoint %p %.*s", DPRINTK("checking mountpoint %p %.*s",
dentry, (int)dentry->d_name.len, dentry->d_name.name); dentry, (int)dentry->d_name.len, dentry->d_name.name);
/* Can we expire this guy */ /* Can we umount this guy */
if (!autofs4_can_expire(dentry, timeout, do_now)) if (autofs4_mount_busy(mnt, dentry))
goto next; goto next;
/* Can we umount this guy */ /* Can we expire this guy */
if (!autofs4_mount_busy(mnt, dentry)) { if (autofs4_can_expire(dentry, timeout, do_now)) {
expired = dentry; expired = dentry;
break; break;
} }
......
...@@ -330,6 +330,10 @@ static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int f ...@@ -330,6 +330,10 @@ static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int f
if (!autofs4_oz_mode(sbi)) if (!autofs4_oz_mode(sbi))
autofs4_update_usage(mnt, dentry); autofs4_update_usage(mnt, dentry);
/* Initialize expiry counter after successful mount */
if (ino)
ino->last_used = jiffies;
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment