diff -Nur linux-2.6.0.orig/fs/Kconfig linux-2.6.0/fs/Kconfig
--- linux-2.6.0.orig/fs/Kconfig 2004-04-05 23:21:54.000000000 +0800
+++ linux-2.6.0/fs/Kconfig 2004-05-08 19:48:48.000000000 +0800
@@ -452,7 +452,7 @@
automounter (amd), which is a pure user space daemon.
To use the automounter you need the user-space tools from
- ; you also
+ ; you also
want to answer Y to "NFS file system support", below.
To compile this support as a module, choose M here: the module will be
diff -Nur linux-2.6.0.orig/fs/autofs4/autofs_i.h linux-2.6.0/fs/autofs4/autofs_i.h
--- linux-2.6.0.orig/fs/autofs4/autofs_i.h 2003-12-18 10:59:05.000000000 +0800
+++ linux-2.6.0/fs/autofs4/autofs_i.h 2004-05-08 19:58:44.000000000 +0800
@@ -25,6 +25,8 @@
#include
#include
#include
+#include
+#include
#include
#include
@@ -82,7 +84,7 @@
char *name;
/* This is for status reporting upon return */
int status;
- int wait_ctr;
+ atomic_t wait_ctr;
};
#define AUTOFS_SBI_MAGIC 0x6d4a556d
@@ -93,8 +95,12 @@
pid_t oz_pgrp;
int catatonic;
int version;
+ int sub_version;
unsigned long exp_timeout;
+ int reghost_enabled;
+ int needs_reghost;
struct super_block *sb;
+ struct semaphore wq_sem;
struct autofs_wait_queue *queues; /* Wait queue pointer */
};
@@ -125,6 +131,12 @@
(inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
}
+static inline void autofs4_copy_atime(struct file *src, struct file *dst)
+{
+ dst->f_dentry->d_inode->i_atime = src->f_dentry->d_inode->i_atime;
+ return;
+}
+
struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
void autofs4_free_ino(struct autofs_info *);
@@ -141,6 +153,7 @@
extern struct inode_operations autofs4_symlink_inode_operations;
extern struct inode_operations autofs4_dir_inode_operations;
extern struct inode_operations autofs4_root_inode_operations;
+extern struct file_operations autofs4_dir_operations;
extern struct file_operations autofs4_root_operations;
/* Initializing function */
@@ -157,6 +170,24 @@
NFY_EXPIRE
};
-int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
+int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
void autofs4_catatonic_mode(struct autofs_sb_info *);
+
+static inline int simple_positive(struct dentry *dentry)
+{
+ return dentry->d_inode && !d_unhashed(dentry);
+}
+
+static inline int simple_empty_nolock(struct dentry *dentry)
+{
+ struct dentry *child;
+ int ret = 0;
+
+ list_for_each_entry(child, &dentry->d_subdirs, d_child)
+ if (simple_positive(child))
+ goto out;
+ ret = 1;
+out:
+ return ret;
+}
diff -Nur linux-2.6.0.orig/fs/autofs4/expire.c linux-2.6.0/fs/autofs4/expire.c
--- linux-2.6.0.orig/fs/autofs4/expire.c 2003-12-18 10:59:05.000000000 +0800
+++ linux-2.6.0/fs/autofs4/expire.c 2004-05-08 19:58:44.000000000 +0800
@@ -4,6 +4,7 @@
*
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
* Copyright 1999-2000 Jeremy Fitzhardinge
+ * Copyright 2001-2003 Ian Kent
*
* This file is part of the Linux kernel and is made available under
* the terms of the GNU General Public License, version 2, or at your
@@ -12,139 +13,198 @@
* ------------------------------------------------------------------------- */
#include "autofs_i.h"
-#include
-/*
- * Determine if a subtree of the namespace is busy.
- *
- * mnt is the mount tree under the autofs mountpoint
+static unsigned long now;
+
+/* Check if a dentry can be expired return 1 if it can else return 0 */
+static inline int autofs4_can_expire(struct dentry *dentry,
+ unsigned long timeout, int do_now)
+{
+ struct autofs_info *ino = autofs4_dentry_ino(dentry);
+
+ /* dentry in the process of being deleted */
+ if (ino == NULL)
+ return 0;
+
+ /* No point expiring a pending mount */
+ if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
+ return 0;
+
+ if (!do_now) {
+ /* Too young to die */
+ if (time_after(ino->last_used + timeout, now))
+ return 0;
+
+ /* update last_used here :-
+ - obviously makes sense if it is in use now
+ - less obviously, prevents rapid-fire expire
+ attempts if expire fails the first time */
+ ino->last_used = now;
+ }
+
+ return 1;
+}
+
+/* Check a mount point for busyness return 1 if not busy, otherwise */
+static int autofs4_check_mount(struct vfsmount *mnt, struct dentry *dentry)
+{
+ int status = 0;
+
+ DPRINTK(("autofs4_check_mount: dentry %p %.*s\n",
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
+
+ mntget(mnt);
+ dget(dentry);
+
+ if (!follow_down(&mnt, &dentry))
+ goto done;
+
+ while (d_mountpoint(dentry) && follow_down(&mnt, &dentry))
+ ;
+
+ /* This is an autofs submount, we can't expire it */
+ if (is_autofs4_dentry(dentry))
+ goto done;
+
+ /* The big question */
+ if (may_umount_tree(mnt) == 0)
+ status = 1;
+done:
+ DPRINTK(("autofs4_check_mount: returning = %d\n", status));
+ mntput(mnt);
+ dput(dentry);
+ return status;
+}
+
+/* Check a directory tree of mount points for busyness
+ * The tree is not busy iff no mountpoints are busy
+ * Return 1 if the tree is busy or 0 otherwise
*/
-static inline int is_vfsmnt_tree_busy(struct vfsmount *mnt)
+static int autofs4_check_tree(struct vfsmount *mnt,
+ struct dentry *top,
+ unsigned long timeout,
+ int do_now)
{
- struct vfsmount *this_parent = mnt;
+ struct dentry *this_parent = top;
struct list_head *next;
- int count;
- count = atomic_read(&mnt->mnt_count) - 1;
+ DPRINTK(("autofs4_check_tree: parent %p %.*s\n",
+ top, (int)top->d_name.len, top->d_name.name));
+ /* Negative dentry - give up */
+ if (!simple_positive(top))
+ return 0;
+
+ /* Timeout of a tree mount is determined by its top dentry */
+ if (!autofs4_can_expire(top, timeout, do_now))
+ return 0;
+
+ spin_lock(&dcache_lock);
repeat:
- next = this_parent->mnt_mounts.next;
- DPRINTK(("is_vfsmnt_tree_busy: mnt=%p, this_parent=%p, next=%p\n",
- mnt, this_parent, next));
+ next = this_parent->d_subdirs.next;
resume:
- for( ; next != &this_parent->mnt_mounts; next = next->next) {
- struct vfsmount *p = list_entry(next, struct vfsmount,
- mnt_child);
-
- /* -1 for struct vfs_mount's normal count,
- -1 to compensate for child's reference to parent */
- count += atomic_read(&p->mnt_count) - 1 - 1;
+ while (next != &this_parent->d_subdirs) {
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
- DPRINTK(("is_vfsmnt_tree_busy: p=%p, count now %d\n",
- p, count));
+ /* Negative dentry - give up */
+ if (!simple_positive(dentry)) {
+ next = next->next;
+ continue;
+ }
- if (!list_empty(&p->mnt_mounts)) {
- this_parent = p;
+ DPRINTK(("autofs4_check_tree: dentry %p %.*s\n",
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
+
+ if (!simple_empty_nolock(dentry)) {
+ this_parent = dentry;
goto repeat;
}
- /* root is busy if any leaf is busy */
- if (atomic_read(&p->mnt_count) > 1)
- return 1;
- }
- /* All done at this level ... ascend and resume the search. */
- if (this_parent != mnt) {
- next = this_parent->mnt_child.next;
- this_parent = this_parent->mnt_parent;
- goto resume;
- }
+ dentry = dget(dentry);
+ spin_unlock(&dcache_lock);
- DPRINTK(("is_vfsmnt_tree_busy: count=%d\n", count));
- return count != 0; /* remaining users? */
-}
+ if (d_mountpoint(dentry)) {
+ /* First busy => tree busy */
+ if (!autofs4_check_mount(mnt, dentry)) {
+ dput(dentry);
+ return 0;
+ }
+ }
-/* Traverse a dentry's list of vfsmounts and return the number of
- non-busy mounts */
-static int check_vfsmnt(struct vfsmount *mnt, struct dentry *dentry)
-{
- int ret = dentry->d_mounted;
- struct vfsmount *vfs = lookup_mnt(mnt, dentry);
+ dput(dentry);
+ spin_lock(&dcache_lock);
+ next = next->next;
+ }
- if (vfs) {
- mntput(vfs);
- if (is_vfsmnt_tree_busy(vfs))
- ret--;
+ if (this_parent != top) {
+ next = this_parent->d_child.next;
+ this_parent = this_parent->d_parent;
+ goto resume;
}
- DPRINTK(("check_vfsmnt: ret=%d\n", ret));
- return ret;
+ spin_unlock(&dcache_lock);
+
+ return 1;
}
-/* Check dentry tree for busyness. If a dentry appears to be busy
- because it is a mountpoint, check to see if the mounted
- filesystem is busy. */
-static int is_tree_busy(struct vfsmount *topmnt, struct dentry *top)
+struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
+ struct dentry *parent,
+ unsigned long timeout,
+ int do_now)
{
- struct dentry *this_parent;
+ struct dentry *this_parent = parent;
struct list_head *next;
- int count;
-
- count = atomic_read(&top->d_count);
-
- DPRINTK(("is_tree_busy: top=%p initial count=%d\n",
- top, count));
- this_parent = top;
-
- if (is_autofs4_dentry(top)) {
- count--;
- DPRINTK(("is_tree_busy: autofs; count=%d\n", count));
- }
- if (d_mountpoint(top))
- count -= check_vfsmnt(topmnt, top);
+ DPRINTK(("autofs4_check_leaves: parent %p %.*s\n",
+ parent, (int)parent->d_name.len, parent->d_name.name));
- repeat:
+ spin_lock(&dcache_lock);
+repeat:
next = this_parent->d_subdirs.next;
- resume:
+resume:
while (next != &this_parent->d_subdirs) {
- int adj = 0;
- struct dentry *dentry = list_entry(next, struct dentry,
- d_child);
- next = next->next;
-
- count += atomic_read(&dentry->d_count) - 1;
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
- if (d_mountpoint(dentry))
- adj += check_vfsmnt(topmnt, dentry);
-
- if (is_autofs4_dentry(dentry)) {
- adj++;
- DPRINTK(("is_tree_busy: autofs; adj=%d\n",
- adj));
+ /* Negative dentry - give up */
+ if (!simple_positive(dentry)) {
+ next = next->next;
+ continue;
}
- count -= adj;
+ DPRINTK(("autofs4_check_leaves: dentry %p %.*s\n",
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
if (!list_empty(&dentry->d_subdirs)) {
this_parent = dentry;
goto repeat;
}
- if (atomic_read(&dentry->d_count) != adj) {
- DPRINTK(("is_tree_busy: busy leaf (d_count=%d adj=%d)\n",
- atomic_read(&dentry->d_count), adj));
- return 1;
+ dentry = dget(dentry);
+ spin_unlock(&dcache_lock);
+
+ if (d_mountpoint(dentry)) {
+ /* Can we expire this guy */
+ if (!autofs4_can_expire(dentry, timeout, do_now))
+ goto cont;
+
+ /* Can we umount this guy */
+ if (autofs4_check_mount(mnt, dentry))
+ return dentry;
+
}
+cont:
+ dput(dentry);
+ spin_lock(&dcache_lock);
+ next = next->next;
}
- /* All done at this level ... ascend and resume the search. */
- if (this_parent != top) {
- next = this_parent->d_child.next;
+ if (this_parent != parent) {
+ next = this_parent->d_child.next;
this_parent = this_parent->d_parent;
goto resume;
}
+ spin_unlock(&dcache_lock);
- DPRINTK(("is_tree_busy: count=%d\n", count));
- return count != 0; /* remaining users? */
+ return NULL;
}
/*
@@ -156,61 +216,86 @@
static struct dentry *autofs4_expire(struct super_block *sb,
struct vfsmount *mnt,
struct autofs_sb_info *sbi,
- int do_now)
+ int how)
{
- unsigned long now = jiffies;
unsigned long timeout;
struct dentry *root = sb->s_root;
- struct list_head *tmp;
+ struct dentry *expired = NULL;
+ struct list_head *next;
+ int do_now = how & AUTOFS_EXP_IMMEDIATE;
+ int exp_leaves = how & AUTOFS_EXP_LEAVES;
- if (!sbi->exp_timeout || !root)
+ if ( !sbi->exp_timeout || !root )
return NULL;
+ now = jiffies;
timeout = sbi->exp_timeout;
spin_lock(&dcache_lock);
- for(tmp = root->d_subdirs.next;
- tmp != &root->d_subdirs;
- tmp = tmp->next) {
- struct autofs_info *ino;
- struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
+ next = root->d_subdirs.next;
- if (dentry->d_inode == NULL)
+ /* On exit from the loop expire is set to a dgot dentry
+ * to expire or it's NULL */
+ while ( next != &root->d_subdirs ) {
+ struct dentry *dentry = list_entry(next, struct dentry, d_child);
+
+ /* Negative dentry - give up */
+ if ( !simple_positive(dentry) ) {
+ next = next->next;
continue;
+ }
- ino = autofs4_dentry_ino(dentry);
+ dentry = dget(dentry);
+ spin_unlock(&dcache_lock);
- if (ino == NULL) {
- /* dentry in the process of being deleted */
- continue;
+ /* Case 1: indirect mount or top level direct mount */
+ if (d_mountpoint(dentry)) {
+ DPRINTK(("autofs4_expire: checking mountpoint %p %.*s\n",
+ dentry, (int)dentry->d_name.len, dentry->d_name.name));
+
+ /* Can we expire this guy */
+ if (!autofs4_can_expire(dentry, timeout, do_now))
+ goto next;
+
+ /* Can we umount this guy */
+ if (autofs4_check_mount(mnt, dentry)) {
+ expired = dentry;
+ break;
+ }
+ goto next;
}
- /* No point expiring a pending mount */
- if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
- continue;
+ if ( simple_empty(dentry) )
+ goto next;
- if (!do_now) {
- /* Too young to die */
- if (time_after(ino->last_used + timeout, now))
- continue;
-
- /* update last_used here :-
- - obviously makes sense if it is in use now
- - less obviously, prevents rapid-fire expire
- attempts if expire fails the first time */
- ino->last_used = now;
+ /* Case 2: tree mount, expire iff entire tree is not busy */
+ if (!exp_leaves) {
+ if (autofs4_check_tree(mnt, dentry, timeout, do_now)) {
+ expired = dentry;
+ break;
+ }
+ /* Case 3: direct mount, expire individual leaves */
+ } else {
+ expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
+ if (expired) {
+ dput(dentry);
+ break;
+ }
}
- if (!is_tree_busy(mnt, dentry)) {
- DPRINTK(("autofs_expire: returning %p %.*s\n",
- dentry, (int)dentry->d_name.len, dentry->d_name.name));
- /* Start from here next time */
- list_del(&root->d_subdirs);
- list_add(&root->d_subdirs, &dentry->d_child);
- dget(dentry);
- spin_unlock(&dcache_lock);
+next:
+ dput(dentry);
+ spin_lock(&dcache_lock);
+ next = next->next;
+ }
- return dentry;
- }
+ if ( expired ) {
+ DPRINTK(("autofs4_expire: returning %p %.*s\n",
+ expired, (int)expired->d_name.len, expired->d_name.name));
+ spin_lock(&dcache_lock);
+ list_del(&expired->d_parent->d_subdirs);
+ list_add(&expired->d_parent->d_subdirs, &expired->d_child);
+ spin_unlock(&dcache_lock);
+ return expired;
}
spin_unlock(&dcache_lock);
@@ -263,7 +348,7 @@
/* This is synchronous because it makes the daemon a
little easier */
de_info->flags |= AUTOFS_INF_EXPIRING;
- ret = autofs4_wait(sbi, &dentry->d_name, NFY_EXPIRE);
+ ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
de_info->flags &= ~AUTOFS_INF_EXPIRING;
dput(dentry);
}
diff -Nur linux-2.6.0.orig/fs/autofs4/inode.c linux-2.6.0/fs/autofs4/inode.c
--- linux-2.6.0.orig/fs/autofs4/inode.c 2003-12-18 10:59:16.000000000 +0800
+++ linux-2.6.0/fs/autofs4/inode.c 2004-05-08 19:58:44.000000000 +0800
@@ -187,6 +187,7 @@
struct file * pipe;
int pipefd;
struct autofs_sb_info *sbi;
+ struct autofs_info *ino;
int minproto, maxproto;
sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
@@ -203,6 +204,8 @@
sbi->oz_pgrp = process_group(current);
sbi->sb = s;
sbi->version = 0;
+ sbi->sub_version = 0;
+ init_MUTEX(&sbi->wq_sem);
sbi->queues = NULL;
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
@@ -212,7 +215,14 @@
/*
* Get the root inode and dentry, but defer checking for errors.
*/
- root_inode = autofs4_get_inode(s, autofs4_mkroot(sbi));
+ ino = autofs4_mkroot(sbi);
+ if (!ino)
+ goto fail_free;
+ root_inode = autofs4_get_inode(s, ino);
+ kfree(ino);
+ if (!root_inode)
+ goto fail_free;
+
root_inode->i_op = &autofs4_root_inode_operations;
root_inode->i_fop = &autofs4_root_operations;
root = d_alloc_root(root_inode);
@@ -241,6 +251,7 @@
}
sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
+ sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
DPRINTK(("autofs: pipe fd = %d, pgrp = %u\n", pipefd, sbi->oz_pgrp));
pipe = fget(pipefd);
@@ -311,7 +313,7 @@
if (S_ISDIR(inf->mode)) {
inode->i_nlink = 2;
inode->i_op = &autofs4_dir_inode_operations;
- inode->i_fop = &simple_dir_operations;
+ inode->i_fop = &autofs4_dir_operations;
} else if (S_ISLNK(inf->mode)) {
inode->i_size = inf->size;
inode->i_op = &autofs4_symlink_inode_operations;
diff -Nur linux-2.6.0.orig/fs/autofs4/root.c linux-2.6.0/fs/autofs4/root.c
--- linux-2.6.0.orig/fs/autofs4/root.c 2003-12-18 10:58:04.000000000 +0800
+++ linux-2.6.0/fs/autofs4/root.c 2004-05-08 19:58:44.000000000 +0800
@@ -4,6 +4,7 @@
*
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
* Copyright 1999-2000 Jeremy Fitzhardinge
+ * Copyright 2001-2003 Ian Kent
*
* This file is part of the Linux kernel and is made available under
* the terms of the GNU General Public License, version 2, or at your
@@ -24,17 +25,28 @@
static int autofs4_dir_rmdir(struct inode *,struct dentry *);
static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
+static int autofs4_dir_open(struct inode *inode, struct file *file);
+static int autofs4_dir_close(struct inode *inode, struct file *file);
+static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
+static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
static struct dentry *autofs4_root_lookup(struct inode *,struct dentry *, struct nameidata *);
+static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
struct file_operations autofs4_root_operations = {
.open = dcache_dir_open,
.release = dcache_dir_close,
- .llseek = dcache_dir_lseek,
.read = generic_read_dir,
- .readdir = dcache_readdir,
+ .readdir = autofs4_root_readdir,
.ioctl = autofs4_root_ioctl,
};
+struct file_operations autofs4_dir_operations = {
+ .open = autofs4_dir_open,
+ .release = autofs4_dir_close,
+ .read = generic_read_dir,
+ .readdir = autofs4_dir_readdir,
+};
+
struct inode_operations autofs4_root_inode_operations = {
.lookup = autofs4_root_lookup,
.unlink = autofs4_dir_unlink,
@@ -51,12 +63,37 @@
.rmdir = autofs4_dir_rmdir,
};
+static int autofs4_root_readdir(struct file *file, void *dirent,
+ filldir_t filldir)
+{
+ struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
+ int oz_mode = autofs4_oz_mode(sbi);
+
+ DPRINTK(("autofs4_root_readdir called, filp->f_pos = %lld\n",
+ file->f_pos));
+
+ /*
+ * Don't set reghost flag if:
+ * 1) f_pos is larger than zero -- we've already been here.
+ * 2) we haven't even enabled reghosting in the 1st place.
+ * 3) this is the daemon doing a readdir
+ */
+ if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
+ sbi->needs_reghost = 1;
+
+ DPRINTK(("autofs4_root_readdir: needs_reghost = %d\n",
+ sbi->needs_reghost));
+
+ return autofs4_dcache_readdir(file, dirent, filldir);
+}
+
/* Update usage from here to top of tree, so that scan of
top-level directories will give a useful result */
static void autofs4_update_usage(struct dentry *dentry)
{
struct dentry *top = dentry->d_sb->s_root;
+ spin_lock(&dcache_lock);
for(; dentry != top; dentry = dentry->d_parent) {
struct autofs_info *ino = autofs4_dentry_ino(dentry);
@@ -65,11 +102,194 @@
ino->last_used = jiffies;
}
}
+ spin_unlock(&dcache_lock);
+}
+
+/*
+ * From 2.4 kernel readdir.c
+ */
+static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
+{
+ int i;
+ struct dentry *dentry = filp->f_dentry;
+
+ i = filp->f_pos;
+ switch (i) {
+ case 0:
+ if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
+ break;
+ i++;
+ filp->f_pos++;
+ /* fallthrough */
+ case 1:
+ if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
+ break;
+ i++;
+ filp->f_pos++;
+ /* fallthrough */
+ default: {
+ struct list_head *list;
+ int j = i-2;
+
+ spin_lock(&dcache_lock);
+ list = dentry->d_subdirs.next;
+
+ for (;;) {
+ if (list == &dentry->d_subdirs) {
+ spin_unlock(&dcache_lock);
+ return 0;
+ }
+ if (!j)
+ break;
+ j--;
+ list = list->next;
+ }
+
+ while(1) {
+ struct dentry *de = list_entry(list, struct dentry, d_child);
+
+ if (!d_unhashed(de) && de->d_inode) {
+ spin_unlock(&dcache_lock);
+ if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
+ break;
+ spin_lock(&dcache_lock);
+ }
+ filp->f_pos++;
+ list = list->next;
+ if (list != &dentry->d_subdirs)
+ continue;
+ spin_unlock(&dcache_lock);
+ break;
+ }
+ }
+ }
+ return 0;
+}
+
+static int autofs4_dir_open(struct inode *inode, struct file *file)
+{
+ struct dentry *dentry = file->f_dentry;
+ struct vfsmount *mnt = file->f_vfsmnt;
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
+ int status;
+
+ DPRINTK(("autofs4_dir_open: file=%p dentry=%p %.*s\n",
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
+
+ if (autofs4_oz_mode(sbi))
+ goto out;
+
+ if (autofs4_ispending(dentry)) {
+ DPRINTK(("autofs4_dir_open: dentry busy\n"));
+ return -EBUSY;
+ }
+
+ if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
+ struct nameidata nd;
+ int empty;
+
+ /* In case there are stale directory dentrys from a failed mount */
+ spin_lock(&dcache_lock);
+ empty = list_empty(&dentry->d_subdirs);
+ spin_unlock(&dcache_lock);
+
+ if (!empty)
+ d_invalidate(dentry);
+
+ nd.flags = LOOKUP_DIRECTORY;
+ status = (dentry->d_op->d_revalidate)(dentry, &nd);
+
+ if (!status)
+ return -ENOENT;
+ }
+
+ if (d_mountpoint(dentry)) {
+ struct file *fp = NULL;
+ struct vfsmount *fp_mnt = mntget(mnt);
+ struct dentry *fp_dentry = dget(dentry);
+
+ while (follow_down(&fp_mnt, &fp_dentry) && d_mountpoint(fp_dentry));
+
+ fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
+ status = PTR_ERR(fp);
+ if (IS_ERR(fp)) {
+ file->private_data = NULL;
+ return status;
+ }
+ file->private_data = fp;
+ }
+out:
+ return 0;
+}
+
+static int autofs4_dir_close(struct inode *inode, struct file *file)
+{
+ struct dentry *dentry = file->f_dentry;
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
+
+ DPRINTK(("autofs4_dir_close: file=%p dentry=%p %.*s\n",
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
+
+ if (autofs4_oz_mode(sbi))
+ goto out;
+
+ if (autofs4_ispending(dentry)) {
+ DPRINTK(("autofs4_dir_close: dentry busy\n"));
+ return -EBUSY;
+ }
+
+ if (d_mountpoint(dentry)) {
+ struct file *fp = file->private_data;
+
+ if (!fp)
+ return -ENOENT;
+
+ filp_close(fp, current->files);
+ file->private_data = NULL;
+ }
+out:
+ return 0;
+}
+
+static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
+{
+ struct dentry *dentry = file->f_dentry;
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
+ int status;
+
+ DPRINTK(("autofs4_readdir: file=%p dentry=%p %.*s\n",
+ file, dentry, dentry->d_name.len, dentry->d_name.name));
+
+ if (autofs4_oz_mode(sbi))
+ goto out;
+
+ if (autofs4_ispending(dentry)) {
+ DPRINTK(("autofs4_readdir: dentry busy\n"));
+ return -EBUSY;
+ }
+
+ if (d_mountpoint(dentry)) {
+ struct file *fp = file->private_data;
+
+ if (!fp)
+ return -ENOENT;
+
+ if (!fp->f_op || !fp->f_op->readdir)
+ goto out;
+
+ status = vfs_readdir(fp, filldir, dirent);
+ file->f_pos = fp->f_pos;
+ if (status)
+ autofs4_copy_atime(file, fp);
+ return status;
+ }
+out:
+ return autofs4_dcache_readdir(file, dirent, filldir);
}
static int try_to_fill_dentry(struct dentry *dentry,
struct super_block *sb,
- struct autofs_sb_info *sbi)
+ struct autofs_sb_info *sbi, int flags)
{
struct autofs_info *de_info = autofs4_dentry_ino(dentry);
int status = 0;
@@ -78,11 +298,10 @@
when expiration is done to trigger mount request with a new
dentry */
if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
- DPRINTK(("try_to_fill_entry: waiting for expire %p name=%.*s, flags&PENDING=%s de_info=%p de_info->flags=%x\n",
- dentry, dentry->d_name.len, dentry->d_name.name,
- dentry->d_flags & DCACHE_AUTOFS_PENDING?"t":"f",
- de_info, de_info?de_info->flags:0));
- status = autofs4_wait(sbi, &dentry->d_name, NFY_NONE);
+ DPRINTK(("try_to_fill_entry: waiting for expire %p name=%.*s\n",
+ dentry, dentry->d_name.len, dentry->d_name.name));
+
+ status = autofs4_wait(sbi, dentry, NFY_NONE);
DPRINTK(("try_to_fill_entry: expire done status=%d\n", status));
@@ -93,11 +312,11 @@
dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode));
/* Wait for a pending mount, triggering one if there isn't one already */
- while(dentry->d_inode == NULL) {
- DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s, de_info=%p de_info->flags=%x\n",
- dentry->d_name.len, dentry->d_name.name,
- de_info, de_info?de_info->flags:0));
- status = autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT);
+ if (dentry->d_inode == NULL) {
+ DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s\n",
+ dentry->d_name.len, dentry->d_name.name));
+
+ status = autofs4_wait(sbi, dentry, NFY_MOUNT);
DPRINTK(("try_to_fill_entry: mount done status=%d\n", status));
@@ -113,19 +332,22 @@
/* Return a negative dentry, but leave it "pending" */
return 1;
}
- }
+ /* Trigger mount for path component or follow link */
+ } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
+ current->link_count) {
+ DPRINTK(("try_to_fill_entry: waiting for mount name=%.*s\n",
+ dentry->d_name.len, dentry->d_name.name));
- /* If this is an unused directory that isn't a mount point,
- bitch at the daemon and fix it in user space */
- spin_lock(&dcache_lock);
- if (S_ISDIR(dentry->d_inode->i_mode) &&
- !d_mountpoint(dentry) &&
- list_empty(&dentry->d_subdirs)) {
- DPRINTK(("try_to_fill_entry: mounting existing dir\n"));
- spin_unlock(&dcache_lock);
- return autofs4_wait(sbi, &dentry->d_name, NFY_MOUNT) == 0;
+ dentry->d_flags |= DCACHE_AUTOFS_PENDING;
+ status = autofs4_wait(sbi, dentry, NFY_MOUNT);
+
+ DPRINTK(("try_to_fill_entry: mount done status=%d\n", status));
+
+ if (status) {
+ dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
+ return 0;
+ }
}
- spin_unlock(&dcache_lock);
/* We don't update the usages for the autofs daemon itself, this
is necessary for recursive autofs mounts */
@@ -136,25 +358,25 @@
return 1;
}
-
/*
* Revalidate is called on every cache lookup. Some of those
* cache lookups may actually happen while the dentry is not
* yet completely filled in, and revalidate has to delay such
* lookups..
*/
-static int autofs4_root_revalidate(struct dentry * dentry, struct nameidata *nd)
+static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd)
{
struct inode * dir = dentry->d_parent->d_inode;
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
int oz_mode = autofs4_oz_mode(sbi);
+ int flags = nd ? nd->flags : 0;
+ int status = 1;
/* Pending dentry */
if (autofs4_ispending(dentry)) {
- if (autofs4_oz_mode(sbi))
- return 1;
- else
- return try_to_fill_dentry(dentry, dir->i_sb, sbi);
+ if (!oz_mode)
+ status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
+ return status;
}
/* Negative dentry.. invalidate if "old" */
@@ -166,13 +388,12 @@
if (S_ISDIR(dentry->d_inode->i_mode) &&
!d_mountpoint(dentry) &&
list_empty(&dentry->d_subdirs)) {
- DPRINTK(("autofs_root_revalidate: dentry=%p %.*s, emptydir\n",
+ DPRINTK(("autofs4_root_revalidate: dentry=%p %.*s, emptydir\n",
dentry, dentry->d_name.len, dentry->d_name.name));
spin_unlock(&dcache_lock);
- if (oz_mode)
- return 1;
- else
- return try_to_fill_dentry(dentry, dir->i_sb, sbi);
+ if (!oz_mode)
+ status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
+ return status;
}
spin_unlock(&dcache_lock);
@@ -183,16 +404,6 @@
return 1;
}
-static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
-{
- struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
-
- if (!autofs4_oz_mode(sbi))
- autofs4_update_usage(dentry);
-
- return 1;
-}
-
static void autofs4_dentry_release(struct dentry *de)
{
struct autofs_info *inf;
@@ -212,7 +423,7 @@
/* For dentries of directories in the root dir */
static struct dentry_operations autofs4_root_dentry_operations = {
- .d_revalidate = autofs4_root_revalidate,
+ .d_revalidate = autofs4_revalidate,
.d_release = autofs4_dentry_release,
};
@@ -224,11 +435,10 @@
/* Lookups in non-root dirs never find anything - if it's there, it's
already in the dcache */
-/* SMP-safe */
static struct dentry *autofs4_dir_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
{
#if 0
- DPRINTK(("autofs_dir_lookup: ignoring lookup of %.*s/%.*s\n",
+ DPRINTK(("autofs4_dir_lookup: iignoring lookup of %.*s/%.*s\n",
dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
dentry->d_name.len, dentry->d_name.name));
#endif
@@ -244,7 +454,7 @@
struct autofs_sb_info *sbi;
int oz_mode;
- DPRINTK(("autofs_root_lookup: name = %.*s\n",
+ DPRINTK(("autofs4_root_lookup: name = %.*s\n",
dentry->d_name.len, dentry->d_name.name));
if (dentry->d_name.len > NAME_MAX)
@@ -252,9 +462,8 @@
sbi = autofs4_sbi(dir->i_sb);
- lock_kernel();
oz_mode = autofs4_oz_mode(sbi);
- DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
+ DPRINTK(("autofs4_lookup: pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
current->pid, process_group(current), sbi->catatonic, oz_mode));
/*
@@ -285,12 +494,16 @@
* a signal. If so we can force a restart..
*/
if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
+ /* See if we were interrupted */
if (signal_pending(current)) {
- unlock_kernel();
- return ERR_PTR(-ERESTARTNOINTR);
+ sigset_t *sigset = ¤t->pending.signal;
+ if (sigismember (sigset, SIGKILL) ||
+ sigismember (sigset, SIGQUIT) ||
+ sigismember (sigset, SIGINT)) {
+ return ERR_PTR(-ERESTARTNOINTR);
+ }
}
}
- unlock_kernel();
/*
* If this dentry is unhashed, then we shouldn't honour this
@@ -313,27 +526,21 @@
struct inode *inode;
char *cp;
- DPRINTK(("autofs_dir_symlink: %s <- %.*s\n", symname,
+ DPRINTK(("autofs4_dir_symlink: %s <- %.*s\n", symname,
dentry->d_name.len, dentry->d_name.name));
- lock_kernel();
- if (!autofs4_oz_mode(sbi)) {
- unlock_kernel();
+ if (!autofs4_oz_mode(sbi))
return -EACCES;
- }
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
- if (ino == NULL) {
- unlock_kernel();
+ if (ino == NULL)
return -ENOSPC;
- }
ino->size = strlen(symname);
ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
if (cp == NULL) {
kfree(ino);
- unlock_kernel();
return -ENOSPC;
}
@@ -353,7 +560,6 @@
dir->i_mtime = CURRENT_TIME;
- unlock_kernel();
return 0;
}
@@ -370,7 +576,7 @@
* If a process is blocked on the dentry waiting for the expire to finish,
* it will invalidate the dentry and try to mount with a new one.
*
- * Also see autofs_dir_rmdir()..
+ * Also see autofs4_dir_rmdir()..
*/
static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
{
@@ -378,11 +584,8 @@
struct autofs_info *ino = autofs4_dentry_ino(dentry);
/* This allows root to remove symlinks */
- lock_kernel();
- if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) ) {
- unlock_kernel();
+ if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
return -EACCES;
- }
dput(ino->dentry);
@@ -393,8 +596,6 @@
d_drop(dentry);
- unlock_kernel();
-
return 0;
}
@@ -403,16 +604,12 @@
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
struct autofs_info *ino = autofs4_dentry_ino(dentry);
- lock_kernel();
- if (!autofs4_oz_mode(sbi)) {
- unlock_kernel();
+ if (!autofs4_oz_mode(sbi))
return -EACCES;
- }
spin_lock(&dcache_lock);
if (!list_empty(&dentry->d_subdirs)) {
spin_unlock(&dcache_lock);
- unlock_kernel();
return -ENOTEMPTY;
}
__d_drop(dentry);
@@ -426,32 +623,24 @@
if (dir->i_nlink)
dir->i_nlink--;
- unlock_kernel();
return 0;
}
-
-
static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
{
struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
struct autofs_info *ino = autofs4_dentry_ino(dentry);
struct inode *inode;
- lock_kernel();
- if ( !autofs4_oz_mode(sbi) ) {
- unlock_kernel();
+ if ( !autofs4_oz_mode(sbi) )
return -EACCES;
- }
- DPRINTK(("autofs_dir_mkdir: dentry %p, creating %.*s\n",
+ DPRINTK(("autofs4_dir_mkdir: dentry %p, creating %.*s\n",
dentry, dentry->d_name.len, dentry->d_name.name));
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
- if (ino == NULL) {
- unlock_kernel();
+ if (ino == NULL)
return -ENOSPC;
- }
inode = autofs4_get_inode(dir->i_sb, ino);
d_instantiate(dentry, inode);
@@ -467,7 +656,6 @@
dir->i_nlink++;
dir->i_mtime = CURRENT_TIME;
- unlock_kernel();
return 0;
}
@@ -496,7 +684,68 @@
return put_user(sbi->version, p);
}
-/* Identify autofs_dentries - this is so we can tell if there's
+/* Return protocol sub version */
+static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int *p)
+{
+ return put_user(sbi->sub_version, p);
+}
+
+/*
+ * Tells the daemon whether we need to reghost or not. Also, clears
+ * the reghost_needed flag.
+ */
+static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int *p)
+{
+ int status;
+
+ DPRINTK(("autofs_ask_reghost: returning %d\n", sbi->needs_reghost));
+
+ status = put_user(sbi->needs_reghost, p);
+ if ( status )
+ return status;
+
+ sbi->needs_reghost = 0;
+ return 0;
+}
+
+/*
+ * Enable / Disable reghosting ioctl() operation
+ */
+static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int *p)
+{
+ int status;
+ int val;
+
+ status = get_user(val, p);
+
+ DPRINTK(("autofs4_toggle_reghost: reghost = %d\n", val));
+
+ if (status)
+ return status;
+
+ /* turn on/off reghosting, with the val */
+ sbi->reghost_enabled = val;
+ return 0;
+}
+
+/*
+* Tells the daemon whether it can umount the autofs mount.
+*/
+static inline int autofs4_ask_umount(struct vfsmount *mnt, int *p)
+{
+ int status = 0;
+
+ if (may_umount(mnt) == 0)
+ status = 1;
+
+ DPRINTK(("autofs_ask_umount: returning %d\n", status));
+
+ status = put_user(status, p);
+
+ return status;
+}
+
+/* Identify autofs4_dentries - this is so we can tell if there's
an extra dentry refcount or not. We only hold a refcount on the
dentry if its non-negative (ie, d_inode != NULL)
*/
@@ -517,7 +766,7 @@
{
struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
- DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
+ DPRINTK(("autofs4_root_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
cmd,arg,sbi,process_group(current)));
if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
@@ -537,9 +786,19 @@
return 0;
case AUTOFS_IOC_PROTOVER: /* Get protocol version */
return autofs4_get_protover(sbi, (int *)arg);
+ case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
+ return autofs4_get_protosubver(sbi, (int *)arg);
case AUTOFS_IOC_SETTIMEOUT:
return autofs4_get_set_timeout(sbi,(unsigned long *)arg);
+ case AUTOFS_IOC_TOGGLEREGHOST:
+ return autofs4_toggle_reghost(sbi, (int *) arg);
+ case AUTOFS_IOC_ASKREGHOST:
+ return autofs4_ask_reghost(sbi, (int *) arg);
+
+ case AUTOFS_IOC_ASKUMOUNT:
+ return autofs4_ask_umount(filp->f_vfsmnt, (int *) arg);
+
/* return a single thing to expire */
case AUTOFS_IOC_EXPIRE:
return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi,
diff -Nur linux-2.6.0.orig/fs/autofs4/waitq.c linux-2.6.0/fs/autofs4/waitq.c
--- linux-2.6.0.orig/fs/autofs4/waitq.c 2003-12-18 10:59:41.000000000 +0800
+++ linux-2.6.0/fs/autofs4/waitq.c 2004-05-08 19:58:44.000000000 +0800
@@ -3,6 +3,7 @@
* linux/fs/autofs/waitq.c
*
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
+ * Copyright 2001-2003 Ian Kent
*
* This file is part of the Linux kernel and is made available under
* the terms of the GNU General Public License, version 2, or at your
@@ -37,7 +38,7 @@
wq->status = -ENOENT; /* Magic is gone - report failure */
kfree(wq->name);
wq->name = NULL;
- wake_up(&wq->queue);
+ wake_up_interruptible(&wq->queue);
wq = nwq;
}
if (sbi->pipe) {
@@ -90,7 +91,7 @@
union autofs_packet_union pkt;
size_t pktsz;
- DPRINTK(("autofs_notify: wait id = 0x%08lx, name = %.*s, type=%d\n",
+ DPRINTK(("autofs4_notify_daemon: wait id = 0x%08lx, name = %.*s, type=%d\n",
wq->wait_queue_token, wq->len, wq->name, type));
memset(&pkt,0,sizeof pkt); /* For security reasons */
@@ -116,7 +117,7 @@
memcpy(ep->name, wq->name, wq->len);
ep->name[wq->len] = '\0';
} else {
- printk("autofs_notify_daemon: bad type %d!\n", type);
+ printk("autofs4_notify_daemon: bad type %d!\n", type);
return;
}
@@ -124,62 +125,107 @@
autofs4_catatonic_mode(sbi);
}
-int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
+static int autofs4_getpath(struct autofs_sb_info *sbi,
+ struct dentry *dentry, char **name)
+{
+ struct dentry *root = sbi->sb->s_root;
+ struct dentry *tmp;
+ char *buf = *name;
+ char *p;
+ int len = 0;
+
+ spin_lock(&dcache_lock);
+ for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
+ len += tmp->d_name.len + 1;
+
+ if (--len > NAME_MAX) {
+ spin_unlock(&dcache_lock);
+ return 0;
+ }
+
+ *(buf + len) = '\0';
+ p = buf + len - dentry->d_name.len;
+ strncpy(p, dentry->d_name.name, dentry->d_name.len);
+
+ for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) {
+ *(--p) = '/';
+ p -= tmp->d_name.len;
+ strncpy(p, tmp->d_name.name, tmp->d_name.len);
+ }
+ spin_unlock(&dcache_lock);
+
+ return len;
+}
+
+int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
enum autofs_notify notify)
{
struct autofs_wait_queue *wq;
- int status;
+ char *name;
+ int len, status;
/* In catatonic mode, we don't wait for nobody */
if ( sbi->catatonic )
return -ENOENT;
- /* We shouldn't be able to get here, but just in case */
- if ( name->len > NAME_MAX )
+ name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+
+ len = autofs4_getpath(sbi, dentry, &name);
+ if (!len) {
+ kfree(name);
return -ENOENT;
+ }
- for ( wq = sbi->queues ; wq ; wq = wq->next ) {
- if ( wq->hash == name->hash &&
- wq->len == name->len &&
- wq->name && !memcmp(wq->name,name->name,name->len) )
+ if (down_interruptible(&sbi->wq_sem)) {
+ kfree(name);
+ return -EINTR;
+ }
+
+ for (wq = sbi->queues ; wq ; wq = wq->next) {
+ if (wq->hash == dentry->d_name.hash &&
+ wq->len == len &&
+ wq->name && !memcmp(wq->name, name, len))
break;
}
-
+
if ( !wq ) {
/* Create a new wait queue */
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
- if ( !wq )
- return -ENOMEM;
-
- wq->name = kmalloc(name->len,GFP_KERNEL);
- if ( !wq->name ) {
- kfree(wq);
+ if ( !wq ) {
+ kfree(name);
+ up(&sbi->wq_sem);
return -ENOMEM;
}
+
wq->wait_queue_token = autofs4_next_wait_queue;
if (++autofs4_next_wait_queue == 0)
autofs4_next_wait_queue = 1;
- init_waitqueue_head(&wq->queue);
- wq->hash = name->hash;
- wq->len = name->len;
- wq->status = -EINTR; /* Status return if interrupted */
- memcpy(wq->name, name->name, name->len);
wq->next = sbi->queues;
sbi->queues = wq;
+ init_waitqueue_head(&wq->queue);
+ wq->hash = dentry->d_name.hash;
+ wq->name = name;
+ wq->len = len;
+ wq->status = -EINTR; /* Status return if interrupted */
+ atomic_set(&wq->wait_ctr, 2);
+ up(&sbi->wq_sem);
- DPRINTK(("autofs_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
- wq->wait_queue_token, wq->len, wq->name, notify));
+ DPRINTK(("autofs4_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+ (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify));
/* autofs4_notify_daemon() may block */
- wq->wait_ctr = 2;
if (notify != NFY_NONE) {
autofs4_notify_daemon(sbi,wq,
- notify == NFY_MOUNT ? autofs_ptype_missing :
- autofs_ptype_expire_multi);
+ notify == NFY_MOUNT ?
+ autofs_ptype_missing :
+ autofs_ptype_expire_multi);
}
} else {
- wq->wait_ctr++;
- DPRINTK(("autofs_wait: existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
- wq->wait_queue_token, wq->len, wq->name, notify));
+ atomic_inc(&wq->wait_ctr);
+ up(&sbi->wq_sem);
+ DPRINTK(("autofs4_wait: existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
+ (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify));
}
/* wq->name is NULL if and only if the lock is already released */
@@ -204,19 +250,20 @@
recalc_sigpending();
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
- interruptible_sleep_on(&wq->queue);
+ wait_event_interruptible(wq->queue, wq->name == NULL);
spin_lock_irqsave(¤t->sighand->siglock, irqflags);
current->blocked = oldset;
recalc_sigpending();
spin_unlock_irqrestore(¤t->sighand->siglock, irqflags);
} else {
- DPRINTK(("autofs_wait: skipped sleeping\n"));
+ DPRINTK(("autofs4_wait: skipped sleeping\n"));
}
status = wq->status;
- if (--wq->wait_ctr == 0) /* Are we the last process to need status? */
+ /* Are we the last process to need status? */
+ if (atomic_dec_and_test(&wq->wait_ctr))
kfree(wq);
return status;
@@ -227,23 +274,28 @@
{
struct autofs_wait_queue *wq, **wql;
+ down(&sbi->wq_sem);
for ( wql = &sbi->queues ; (wq = *wql) ; wql = &wq->next ) {
if ( wq->wait_queue_token == wait_queue_token )
break;
}
- if ( !wq )
+
+ if ( !wq ) {
+ up(&sbi->wq_sem);
return -EINVAL;
+ }
*wql = wq->next; /* Unlink from chain */
+ up(&sbi->wq_sem);
kfree(wq->name);
wq->name = NULL; /* Do not wait on this queue */
wq->status = status;
- if (--wq->wait_ctr == 0) /* Is anyone still waiting for this guy? */
+ if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
kfree(wq);
else
- wake_up(&wq->queue);
+ wake_up_interruptible(&wq->queue);
return 0;
}
diff -Nur linux-2.6.0.orig/fs/namespace.c linux-2.6.0/fs/namespace.c
--- linux-2.6.0.orig/fs/namespace.c 2004-05-08 19:45:13.000000000 +0800
+++ linux-2.6.0/fs/namespace.c 2004-05-08 19:57:51.000000000 +0800
@@ -251,7 +260,65 @@
.show = show_vfsmnt
};
-/*
+/**
+ * may_umount_tree - check if a mount tree is busy
+ * @mnt: root of mount tree
+ *
+ * This is called to check if a tree of mounts has any
+ * open files, pwds, chroots or sub mounts that are
+ * busy.
+ */
+int may_umount_tree(struct vfsmount *mnt)
+{
+ struct list_head *next;
+ struct vfsmount *this_parent = mnt;
+ int actual_refs;
+ int minimum_refs;
+
+ spin_lock(&vfsmount_lock);
+ actual_refs = atomic_read(&mnt->mnt_count);
+ minimum_refs = 2;
+repeat:
+ next = this_parent->mnt_mounts.next;
+resume:
+ while (next != &this_parent->mnt_mounts) {
+ struct vfsmount *p = list_entry(next, struct vfsmount, mnt_child);
+
+ next = next->next;
+
+ actual_refs += atomic_read(&p->mnt_count);
+ minimum_refs += 2;
+
+ if (!list_empty(&p->mnt_mounts)) {
+ this_parent = p;
+ goto repeat;
+ }
+ }
+
+ if (this_parent != mnt) {
+ next = this_parent->mnt_child.next;
+ this_parent = this_parent->mnt_parent;
+ goto resume;
+ }
+ spin_unlock(&vfsmount_lock);
+
+ if (actual_refs > minimum_refs)
+ return -EBUSY;
+
+ return 0;
+}
+
+EXPORT_SYMBOL(may_umount_tree);
+
+/**
+ * may_umount - check if a mount point is busy
+ * @mnt: root of mount
+ *
+ * This is called to check if a mount point has any
+ * open files, pwds, chroots or sub mounts. If the
+ * mount has sub mounts this will return busy
+ * regardless of whether the sub mounts are busy.
+ *
* Doesn't take quota and stuff into account. IOW, in some cases it will
* give false negatives. The main reason why it's here is that we need
* a non-destructive way to look for easily umountable filesystems.
diff -Nur linux-2.6.0.orig/include/linux/auto_fs4.h linux-2.6.0/include/linux/auto_fs4.h
--- linux-2.6.0.orig/include/linux/auto_fs4.h 2003-12-18 10:58:07.000000000 +0800
+++ linux-2.6.0/include/linux/auto_fs4.h 2004-05-08 19:58:28.000000000 +0800
@@ -23,6 +23,12 @@
#define AUTOFS_MIN_PROTO_VERSION 3
#define AUTOFS_MAX_PROTO_VERSION 4
+#define AUTOFS_PROTO_SUBVERSION 5
+
+/* Mask for expire behaviour */
+#define AUTOFS_EXP_IMMEDIATE 1
+#define AUTOFS_EXP_LEAVES 2
+
/* New message type */
#define autofs_ptype_expire_multi 2 /* Expire entry (umount request) */
@@ -41,7 +47,11 @@
struct autofs_packet_expire_multi expire_multi;
};
-#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
+#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
+#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
+#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
+#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
+#define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
#endif /* _LINUX_AUTO_FS4_H */
diff -Nur linux-2.6.0.orig/include/linux/fs.h linux-2.6.0/include/linux/fs.h
--- linux-2.6.0.orig/include/linux/fs.h 2004-05-08 19:44:51.000000000 +0800
+++ linux-2.6.0/include/linux/fs.h 2004-05-08 20:01:53.000000000 +0800
@@ -1042,6 +1042,7 @@
extern int register_filesystem(struct file_system_type *);
extern int unregister_filesystem(struct file_system_type *);
extern struct vfsmount *kern_mount(struct file_system_type *);
+extern int may_umount_tree(struct vfsmount *);
extern int may_umount(struct vfsmount *);
extern long do_mount(char *, char *, char *, unsigned long, void *);