[PATCH] knfsd: add some missing newlines in printks
[safe/jmp/linux-2.6] / fs / nfsd / nfsctl.c
index 3d56531..7046ac9 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/linkage.h>
@@ -23,6 +22,7 @@
 #include <linux/seq_file.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
+#include <linux/string.h>
 
 #include <linux/nfs.h>
 #include <linux/nfsd_idmap.h>
@@ -35,6 +35,8 @@
 
 #include <asm/uaccess.h>
 
+unsigned int nfsd_versbits = ~0;
+
 /*
  *     We have a single directory with 9 nodes in it.
  */
@@ -50,7 +52,15 @@ enum {
        NFSD_List,
        NFSD_Fh,
        NFSD_Threads,
+       NFSD_Versions,
+       /*
+        * The below MUST come last.  Otherwise we leave a hole in nfsd_files[]
+        * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
+        */
+#ifdef CONFIG_NFSD_V4
        NFSD_Leasetime,
+       NFSD_RecoveryDir,
+#endif
 };
 
 /*
@@ -65,7 +75,11 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size);
 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
 static ssize_t write_threads(struct file *file, char *buf, size_t size);
+static ssize_t write_versions(struct file *file, char *buf, size_t size);
+#ifdef CONFIG_NFSD_V4
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
+static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
+#endif
 
 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
        [NFSD_Svc] = write_svc,
@@ -77,7 +91,11 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
        [NFSD_Getfs] = write_getfs,
        [NFSD_Fh] = write_filehandle,
        [NFSD_Threads] = write_threads,
+       [NFSD_Versions] = write_versions,
+#ifdef CONFIG_NFSD_V4
        [NFSD_Leasetime] = write_leasetime,
+       [NFSD_RecoveryDir] = write_recoverydir,
+#endif
 };
 
 static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
@@ -86,7 +104,7 @@ static ssize_t nfsctl_transaction_write(struct file *file, const char __user *bu
        char *data;
        ssize_t rv;
 
-       if (ino >= sizeof(write_op)/sizeof(write_op[0]) || !write_op[ino])
+       if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
                return -EINVAL;
 
        data = simple_transaction_get(file, buf, size);
@@ -101,9 +119,23 @@ static ssize_t nfsctl_transaction_write(struct file *file, const char __user *bu
        return rv;
 }
 
-static struct file_operations transaction_ops = {
+static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
+{
+       if (! file->private_data) {
+               /* An attempt to read a transaction file without writing
+                * causes a 0-byte write so that the file can return
+                * state information
+                */
+               ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
+               if (rv < 0)
+                       return rv;
+       }
+       return simple_transaction_read(file, buf, size, pos);
+}
+
+static const struct file_operations transaction_ops = {
        .write          = nfsctl_transaction_write,
-       .read           = simple_transaction_read,
+       .read           = nfsctl_transaction_read,
        .release        = simple_transaction_release,
 };
 
@@ -113,7 +145,7 @@ static int exports_open(struct inode *inode, struct file *file)
        return seq_open(file, &nfs_exports_op);
 }
 
-static struct file_operations exports_operations = {
+static const struct file_operations exports_operations = {
        .open           = exports_open,
        .read           = seq_read,
        .llseek         = seq_lseek,
@@ -326,6 +358,70 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
        return strlen(buf);
 }
 
+static ssize_t write_versions(struct file *file, char *buf, size_t size)
+{
+       /*
+        * Format:
+        *   [-/+]vers [-/+]vers ...
+        */
+       char *mesg = buf;
+       char *vers, sign;
+       int len, num;
+       ssize_t tlen = 0;
+       char *sep;
+
+       if (size>0) {
+               if (nfsd_serv)
+                       return -EBUSY;
+               if (buf[size-1] != '\n')
+                       return -EINVAL;
+               buf[size-1] = 0;
+
+               vers = mesg;
+               len = qword_get(&mesg, vers, size);
+               if (len <= 0) return -EINVAL;
+               do {
+                       sign = *vers;
+                       if (sign == '+' || sign == '-')
+                               num = simple_strtol((vers+1), NULL, 0);
+                       else
+                               num = simple_strtol(vers, NULL, 0);
+                       switch(num) {
+                       case 2:
+                       case 3:
+                       case 4:
+                               if (sign != '-')
+                                       NFSCTL_VERSET(nfsd_versbits, num);
+                               else
+                                       NFSCTL_VERUNSET(nfsd_versbits, num);
+                               break;
+                       default:
+                               return -EINVAL;
+                       }
+                       vers += len + 1;
+                       tlen += len;
+               } while ((len = qword_get(&mesg, vers, size)) > 0);
+               /* If all get turned off, turn them back on, as
+                * having no versions is BAD
+                */
+               if ((nfsd_versbits & NFSCTL_VERALL)==0)
+                       nfsd_versbits = NFSCTL_VERALL;
+       }
+       /* Now write current state into reply buffer */
+       len = 0;
+       sep = "";
+       for (num=2 ; num <= 4 ; num++)
+               if (NFSCTL_VERISSET(NFSCTL_VERALL, num)) {
+                       len += sprintf(buf+len, "%s%c%d", sep,
+                                      NFSCTL_VERISSET(nfsd_versbits, num)?'+':'-',
+                                      num);
+                       sep = " ";
+               }
+       len += sprintf(buf+len, "\n");
+       return len;
+}
+
+#ifdef CONFIG_NFSD_V4
 extern time_t nfs4_leasetime(void);
 
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
@@ -349,6 +445,26 @@ static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
        return strlen(buf);
 }
 
+static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
+{
+       char *mesg = buf;
+       char *recdir;
+       int len, status;
+
+       if (size > PATH_MAX || buf[size-1] != '\n')
+               return -EINVAL;
+       buf[size-1] = 0;
+
+       recdir = mesg;
+       len = qword_get(&mesg, recdir, size);
+       if (len <= 0)
+               return -EINVAL;
+
+       status = nfs4_reset_recoverydir(recdir);
+       return strlen(buf);
+}
+#endif
+
 /*----------------------------------------------------------------------------*/
 /*
  *     populating the filesystem.
@@ -367,18 +483,20 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
                [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
                [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
                [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
+               [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
 #ifdef CONFIG_NFSD_V4
                [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
+               [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
 #endif
                /* last one */ {""}
        };
        return simple_fill_super(sb, 0x6e667364, nfsd_files);
 }
 
-static struct super_block *nfsd_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int nfsd_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_single(fs_type, flags, data, nfsd_fill_super);
+       return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt);
 }
 
 static struct file_system_type nfsd_fs_type = {
@@ -398,9 +516,7 @@ static int __init init_nfsd(void)
        nfsd_export_init();     /* Exports table */
        nfsd_lockd_init();      /* lockd->nfsd callbacks */
        nfs4_state_init();      /* NFSv4 locking state */
-#ifdef CONFIG_NFSD_V4
        nfsd_idmap_init();      /* Name to ID mapping */
-#endif /* CONFIG_NFSD_V4 */
        if (proc_mkdir("fs/nfs", NULL)) {
                struct proc_dir_entry *entry;
                entry = create_proc_entry("fs/nfs/exports", 0, NULL);
@@ -427,9 +543,7 @@ static void __exit exit_nfsd(void)
        remove_proc_entry("fs/nfs", NULL);
        nfsd_stat_shutdown();
        nfsd_lockd_shutdown();
-#ifdef CONFIG_NFSD_V4
        nfsd_idmap_shutdown();
-#endif /* CONFIG_NFSD_V4 */
        unregister_filesystem(&nfsd_fs_type);
 }