nfsd41: split out share_access want and signal flags while decoding
[linux-2.6.git] / fs / nfsd / nfs4recover.c
index 7e26caa..0b3e875 100644 (file)
@@ -45,6 +45,7 @@
 
 /* Globals */
 static struct file *rec_file;
+static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
 
 static int
 nfs4_save_creds(const struct cred **original_creds)
@@ -88,7 +89,7 @@ nfs4_make_rec_clidname(char *dname, struct xdr_netobj *clname)
        struct xdr_netobj cksum;
        struct hash_desc desc;
        struct scatterlist sg;
-       __be32 status = nfserr_resource;
+       __be32 status = nfserr_jukebox;
 
        dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
                        clname->len, clname->data);
@@ -116,8 +117,7 @@ out_no_tfm:
        return status;
 }
 
-int
-nfsd4_create_clid_dir(struct nfs4_client *clp)
+void nfsd4_create_clid_dir(struct nfs4_client *clp)
 {
        const struct cred *original_cred;
        char *dname = clp->cl_recdir;
@@ -126,12 +126,14 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
 
        dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname);
 
-       if (!rec_file || clp->cl_firststate)
-               return 0;
-
+       if (clp->cl_firststate)
+               return;
+       clp->cl_firststate = 1;
+       if (!rec_file)
+               return;
        status = nfs4_save_creds(&original_cred);
        if (status < 0)
-               return status;
+               return;
 
        dir = rec_file->f_path.dentry;
        /* lock the parent */
@@ -142,27 +144,33 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
                status = PTR_ERR(dentry);
                goto out_unlock;
        }
-       status = -EEXIST;
-       if (dentry->d_inode) {
-               dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
+       if (dentry->d_inode)
+               /*
+                * In the 4.1 case, where we're called from
+                * reclaim_complete(), records from the previous reboot
+                * may still be left, so this is OK.
+                *
+                * In the 4.0 case, we should never get here; but we may
+                * as well be forgiving and just succeed silently.
+                */
                goto out_put;
-       }
-       status = mnt_want_write(rec_file->f_path.mnt);
+       status = mnt_want_write_file(rec_file);
        if (status)
                goto out_put;
        status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU);
-       mnt_drop_write(rec_file->f_path.mnt);
+       mnt_drop_write_file(rec_file);
 out_put:
        dput(dentry);
 out_unlock:
        mutex_unlock(&dir->d_inode->i_mutex);
-       if (status == 0) {
-               clp->cl_firststate = 1;
+       if (status == 0)
                vfs_fsync(rec_file, 0);
-       }
+       else
+               printk(KERN_ERR "NFSD: failed to write recovery record"
+                               " (err %d); please check that %s exists"
+                               " and is writeable", status,
+                               user_recovery_dirname);
        nfs4_reset_creds(original_cred);
-       dprintk("NFSD: nfsd4_create_clid_dir returns %d\n", status);
-       return status;
 }
 
 typedef int (recdir_func)(struct dentry *, struct dentry *);
@@ -191,52 +199,42 @@ nfsd4_build_namelist(void *arg, const char *name, int namlen,
 }
 
 static int
-nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f)
+nfsd4_list_rec_dir(recdir_func *f)
 {
        const struct cred *original_cred;
-       struct file *filp;
+       struct dentry *dir = rec_file->f_path.dentry;
        LIST_HEAD(names);
-       struct name_list *entry;
-       struct dentry *dentry;
        int status;
 
-       if (!rec_file)
-               return 0;
-
        status = nfs4_save_creds(&original_cred);
        if (status < 0)
                return status;
 
-       filp = dentry_open(dget(dir), mntget(rec_file->f_path.mnt), O_RDONLY,
-                          current_cred());
-       status = PTR_ERR(filp);
-       if (IS_ERR(filp))
-               goto out;
-       status = vfs_readdir(filp, nfsd4_build_namelist, &names);
-       fput(filp);
+       status = vfs_llseek(rec_file, 0, SEEK_SET);
+       if (status < 0) {
+               nfs4_reset_creds(original_cred);
+               return status;
+       }
+
+       status = vfs_readdir(rec_file, nfsd4_build_namelist, &names);
        mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
        while (!list_empty(&names)) {
+               struct name_list *entry;
                entry = list_entry(names.next, struct name_list, list);
-
-               dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
-               if (IS_ERR(dentry)) {
-                       status = PTR_ERR(dentry);
-                       break;
+               if (!status) {
+                       struct dentry *dentry;
+                       dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
+                       if (IS_ERR(dentry)) {
+                               status = PTR_ERR(dentry);
+                               break;
+                       }
+                       status = f(dir, dentry);
+                       dput(dentry);
                }
-               status = f(dir, dentry);
-               dput(dentry);
-               if (status)
-                       break;
                list_del(&entry->list);
                kfree(entry);
        }
        mutex_unlock(&dir->d_inode->i_mutex);
-out:
-       while (!list_empty(&names)) {
-               entry = list_entry(names.next, struct name_list, list);
-               list_del(&entry->list);
-               kfree(entry);
-       }
        nfs4_reset_creds(original_cred);
        return status;
 }
@@ -276,7 +274,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
        if (!rec_file || !clp->cl_firststate)
                return;
 
-       status = mnt_want_write(rec_file->f_path.mnt);
+       status = mnt_want_write_file(rec_file);
        if (status)
                goto out;
        clp->cl_firststate = 0;
@@ -289,7 +287,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
        nfs4_reset_creds(original_cred);
        if (status == 0)
                vfs_fsync(rec_file, 0);
-       mnt_drop_write(rec_file->f_path.mnt);
+       mnt_drop_write_file(rec_file);
 out:
        if (status)
                printk("NFSD: Failed to remove expired client state directory"
@@ -302,7 +300,6 @@ purge_old(struct dentry *parent, struct dentry *child)
 {
        int status;
 
-       /* note: we currently use this path only for minorversion 0 */
        if (nfs4_has_reclaimed_state(child->d_name.name, false))
                return 0;
 
@@ -320,13 +317,13 @@ nfsd4_recdir_purge_old(void) {
 
        if (!rec_file)
                return;
-       status = mnt_want_write(rec_file->f_path.mnt);
+       status = mnt_want_write_file(rec_file);
        if (status)
                goto out;
-       status = nfsd4_list_rec_dir(rec_file->f_path.dentry, purge_old);
+       status = nfsd4_list_rec_dir(purge_old);
        if (status == 0)
                vfs_fsync(rec_file, 0);
-       mnt_drop_write(rec_file->f_path.mnt);
+       mnt_drop_write_file(rec_file);
 out:
        if (status)
                printk("nfsd4: failed to purge old clients from recovery"
@@ -353,7 +350,7 @@ nfsd4_recdir_load(void) {
        if (!rec_file)
                return 0;
 
-       status = nfsd4_list_rec_dir(rec_file->f_path.dentry, load_recdir);
+       status = nfsd4_list_rec_dir(load_recdir);
        if (status)
                printk("nfsd4: failed loading clients from recovery"
                        " directory %s\n", rec_file->f_path.dentry->d_name.name);
@@ -365,13 +362,13 @@ nfsd4_recdir_load(void) {
  */
 
 void
-nfsd4_init_recdir(char *rec_dirname)
+nfsd4_init_recdir()
 {
        const struct cred *original_cred;
        int status;
 
        printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
-                       rec_dirname);
+                       user_recovery_dirname);
 
        BUG_ON(rec_file);
 
@@ -383,10 +380,10 @@ nfsd4_init_recdir(char *rec_dirname)
                return;
        }
 
-       rec_file = filp_open(rec_dirname, O_RDONLY | O_DIRECTORY, 0);
+       rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
        if (IS_ERR(rec_file)) {
                printk("NFSD: unable to find recovery directory %s\n",
-                               rec_dirname);
+                               user_recovery_dirname);
                rec_file = NULL;
        }
 
@@ -401,3 +398,30 @@ nfsd4_shutdown_recdir(void)
        fput(rec_file);
        rec_file = NULL;
 }
+
+/*
+ * Change the NFSv4 recovery directory to recdir.
+ */
+int
+nfs4_reset_recoverydir(char *recdir)
+{
+       int status;
+       struct path path;
+
+       status = kern_path(recdir, LOOKUP_FOLLOW, &path);
+       if (status)
+               return status;
+       status = -ENOTDIR;
+       if (S_ISDIR(path.dentry->d_inode->i_mode)) {
+               strcpy(user_recovery_dirname, recdir);
+               status = 0;
+       }
+       path_put(&path);
+       return status;
+}
+
+char *
+nfs4_recoverydir(void)
+{
+       return user_recovery_dirname;
+}