vsprintf: factor out skip_space code in a separate function
[safe/jmp/linux-2.6] / fs / autofs4 / root.c
index e062ee5..b96a3c5 100644 (file)
@@ -25,7 +25,6 @@ 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_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
 static void *autofs4_follow_link(struct dentry *, struct nameidata *);
 
@@ -36,7 +35,8 @@ const struct file_operations autofs4_root_operations = {
        .open           = dcache_dir_open,
        .release        = dcache_dir_close,
        .read           = generic_read_dir,
-       .readdir        = autofs4_root_readdir,
+       .readdir        = dcache_readdir,
+       .llseek         = dcache_dir_lseek,
        .ioctl          = autofs4_root_ioctl,
 };
 
@@ -45,6 +45,7 @@ const struct file_operations autofs4_dir_operations = {
        .release        = dcache_dir_close,
        .read           = generic_read_dir,
        .readdir        = dcache_readdir,
+       .llseek         = dcache_dir_lseek,
 };
 
 const struct inode_operations autofs4_indirect_root_inode_operations = {
@@ -71,28 +72,6 @@ const struct inode_operations autofs4_dir_inode_operations = {
        .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_path.dentry->d_sb);
-       int oz_mode = autofs4_oz_mode(sbi);
-
-       DPRINTK("called, filp->f_pos = %lld", 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("needs_reghost = %d", sbi->needs_reghost);
-
-       return dcache_readdir(file, dirent, filldir);
-}
-
 static int autofs4_dir_open(struct inode *inode, struct file *file)
 {
        struct dentry *dentry = file->f_path.dentry;
@@ -130,34 +109,6 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags)
        struct autofs_info *ino = autofs4_dentry_ino(dentry);
        int status;
 
-       /* Block on any pending expiry here; invalidate the dentry
-           when expiration is done to trigger mount request with a new
-           dentry */
-       spin_lock(&sbi->fs_lock);
-       if (ino->flags & AUTOFS_INF_EXPIRING) {
-               spin_unlock(&sbi->fs_lock);
-
-               DPRINTK("waiting for expire %p name=%.*s",
-                        dentry, dentry->d_name.len, dentry->d_name.name);
-
-               status = autofs4_wait(sbi, dentry, NFY_NONE);
-               wait_for_completion(&ino->expire_complete);
-
-               DPRINTK("expire done status=%d", status);
-
-               /*
-                * If the directory still exists the mount request must
-                * continue otherwise it can't be followed at the right
-                * time during the walk.
-                */
-               status = d_invalidate(dentry);
-               if (status != -EBUSY)
-                       return -EAGAIN;
-
-               goto cont;
-       }
-       spin_unlock(&sbi->fs_lock);
-cont:
        DPRINTK("dentry=%p %.*s ino=%p",
                 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
 
@@ -230,7 +181,7 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
                nd->flags);
        /*
         * For an expire of a covered direct or offset mount we need
-        * to beeak out of follow_down() at the autofs mount trigger
+        * to break out of follow_down() at the autofs mount trigger
         * (d_mounted--), so we can see the expiring flag, and manage
         * the blocking and following here until the expire is completed.
         */
@@ -239,7 +190,7 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
                if (ino->flags & AUTOFS_INF_EXPIRING) {
                        spin_unlock(&sbi->fs_lock);
                        /* Follow down to our covering mount. */
-                       if (!follow_down(&nd->path.mnt, &nd->path.dentry))
+                       if (!follow_down(&nd->path))
                                goto done;
                        goto follow;
                }
@@ -248,22 +199,8 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
        }
 
        /* If an expire request is pending everyone must wait. */
-       spin_lock(&sbi->fs_lock);
-       if (ino->flags & AUTOFS_INF_EXPIRING) {
-               spin_unlock(&sbi->fs_lock);
+       autofs4_expire_wait(dentry);
 
-               DPRINTK("waiting for active request %p name=%.*s",
-                       dentry, dentry->d_name.len, dentry->d_name.name);
-
-               status = autofs4_wait(sbi, dentry, NFY_NONE);
-               wait_for_completion(&ino->expire_complete);
-
-               DPRINTK("request done status=%d", status);
-
-               goto cont;
-       }
-       spin_unlock(&sbi->fs_lock);
-cont:
        /* We trigger a mount for almost all flags */
        lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
        if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
@@ -293,8 +230,7 @@ follow:
         * to follow it.
         */
        if (d_mountpoint(dentry)) {
-               if (!autofs4_follow_mount(&nd->path.mnt,
-                                         &nd->path.dentry)) {
+               if (!autofs4_follow_mount(&nd->path)) {
                        status = -ENOENT;
                        goto out_error;
                }
@@ -332,6 +268,14 @@ static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
                        return 1;
 
                /*
+                * If the directory has gone away due to an expire
+                * we have been called as ->d_revalidate() and so
+                * we need to return false and proceed to ->lookup().
+                */
+               if (autofs4_expire_wait(dentry) == -EAGAIN)
+                       return 0;
+
+               /*
                 * A zero status is success otherwise we have a
                 * negative error code.
                 */
@@ -339,15 +283,6 @@ static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
                if (status == 0)
                        return 1;
 
-               /*
-                * A status of EAGAIN here means that the dentry has gone
-                * away while waiting for an expire to complete. If we are
-                * racing with expire lookup will wait for it so this must
-                * be a revalidate and we need to send it to lookup.
-                */
-               if (status == -EAGAIN)
-                       return 0;
-
                return status;
        }
        spin_unlock(&sbi->fs_lock);
@@ -413,13 +348,13 @@ void autofs4_dentry_release(struct dentry *de)
 }
 
 /* For dentries of directories in the root dir */
-static struct dentry_operations autofs4_root_dentry_operations = {
+static const struct dentry_operations autofs4_root_dentry_operations = {
        .d_revalidate   = autofs4_revalidate,
        .d_release      = autofs4_dentry_release,
 };
 
 /* For other dentries */
-static struct dentry_operations autofs4_dentry_operations = {
+static const struct dentry_operations autofs4_dentry_operations = {
        .d_revalidate   = autofs4_revalidate,
        .d_release      = autofs4_dentry_release,
 };
@@ -549,34 +484,6 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
        DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
                 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
 
-       expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
-       if (expiring) {
-               /*
-                * If we are racing with expire the request might not
-                * be quite complete but the directory has been removed
-                * so it must have been successful, so just wait for it.
-                */
-               ino = autofs4_dentry_ino(expiring);
-               spin_lock(&sbi->fs_lock);
-               if (ino->flags & AUTOFS_INF_EXPIRING) {
-                       spin_unlock(&sbi->fs_lock);
-                       DPRINTK("wait for incomplete expire %p name=%.*s",
-                               expiring, expiring->d_name.len,
-                               expiring->d_name.name);
-                       autofs4_wait(sbi, expiring, NFY_NONE);
-                       wait_for_completion(&ino->expire_complete);
-                       DPRINTK("request completed");
-                       goto cont;
-               }
-               spin_unlock(&sbi->fs_lock);
-cont:
-               spin_lock(&sbi->lookup_lock);
-               if (!list_empty(&ino->expiring))
-                       list_del_init(&ino->expiring);
-               spin_unlock(&sbi->lookup_lock);
-               dput(expiring);
-       }
-
        unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
        if (unhashed)
                dentry = unhashed;
@@ -614,14 +521,31 @@ cont:
        }
 
        if (!oz_mode) {
+               mutex_unlock(&dir->i_mutex);
+               expiring = autofs4_lookup_expiring(sbi,
+                                                  dentry->d_parent,
+                                                  &dentry->d_name);
+               if (expiring) {
+                       /*
+                        * If we are racing with expire the request might not
+                        * be quite complete but the directory has been removed
+                        * so it must have been successful, so just wait for it.
+                        */
+                       ino = autofs4_dentry_ino(expiring);
+                       autofs4_expire_wait(expiring);
+                       spin_lock(&sbi->lookup_lock);
+                       if (!list_empty(&ino->expiring))
+                               list_del_init(&ino->expiring);
+                       spin_unlock(&sbi->lookup_lock);
+                       dput(expiring);
+               }
+
                spin_lock(&dentry->d_lock);
                dentry->d_flags |= DCACHE_AUTOFS_PENDING;
                spin_unlock(&dentry->d_lock);
-               if (dentry->d_op && dentry->d_op->d_revalidate) {
-                       mutex_unlock(&dir->i_mutex);
+               if (dentry->d_op && dentry->d_op->d_revalidate)
                        (dentry->d_op->d_revalidate)(dentry, nd);
-                       mutex_lock(&dir->i_mutex);
-               }
+               mutex_lock(&dir->i_mutex);
        }
 
        /*
@@ -914,44 +838,6 @@ static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user
 }
 
 /*
- * 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 __user *p)
-{
-       int status;
-
-       DPRINTK("returning %d", 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 __user *p)
-{
-       int status;
-       int val;
-
-       status = get_user(val, p);
-
-       DPRINTK("reghost = %d", 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 __user *p)
@@ -1015,11 +901,6 @@ static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
        case AUTOFS_IOC_SETTIMEOUT:
                return autofs4_get_set_timeout(sbi, p);
 
-       case AUTOFS_IOC_TOGGLEREGHOST:
-               return autofs4_toggle_reghost(sbi, p);
-       case AUTOFS_IOC_ASKREGHOST:
-               return autofs4_ask_reghost(sbi, p);
-
        case AUTOFS_IOC_ASKUMOUNT:
                return autofs4_ask_umount(filp->f_path.mnt, p);