NFSv4: Allow user to set the port used by the NFSv4 callback channel
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Tue, 3 Jan 2006 08:55:41 +0000 (09:55 +0100)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 6 Jan 2006 19:58:52 +0000 (14:58 -0500)
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Documentation/kernel-parameters.txt
fs/nfs/Makefile
fs/nfs/callback.c
fs/nfs/callback.h
fs/nfs/inode.c
fs/nfs/sysctl.c [new file with mode: 0644]
include/linux/nfs_fs.h

index 61a56b100c62d287e05ec52c42636c6345159f14..309c9cec6e7c576a26e7efda557b84e44eb92844 100644 (file)
@@ -910,6 +910,10 @@ running once the system is up.
        nfsroot=        [NFS] nfs root filesystem for disk-less boxes.
                        See Documentation/nfsroot.txt.
 
+       nfs.callback_tcpport=
+                       [NFS] set the TCP port on which the NFSv4 callback
+                       channel should listen.
+
        nmi_watchdog=   [KNL,BUGS=IA-32] Debugging features for SMP kernels
 
        no387           [BUGS=IA-32] Tells the kernel to use the 387 maths
index 8b3bb715d177397d1f9df4e6f308c1108b911231..ec61fd56a1a93b693e7379ec0bbb80db02632a82 100644 (file)
@@ -13,4 +13,5 @@ nfs-$(CONFIG_NFS_V4)  += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
                           delegation.o idmap.o \
                           callback.o callback_xdr.o callback_proc.o
 nfs-$(CONFIG_NFS_DIRECTIO) += direct.o
+nfs-$(CONFIG_SYSCTL) += sysctl.o
 nfs-objs               := $(nfs-y)
index 30cae3602867b532773fb6c0074f5663c04d2734..fcd97406a778899a8fbec50ed6aa641d39b34ab8 100644 (file)
@@ -34,6 +34,7 @@ static struct nfs_callback_data nfs_callback_info;
 static DECLARE_MUTEX(nfs_callback_sema);
 static struct svc_program nfs4_callback_program;
 
+unsigned int nfs_callback_set_tcpport;
 unsigned short nfs_callback_tcpport;
 
 /*
@@ -98,7 +99,7 @@ int nfs_callback_up(void)
        if (!serv)
                goto out_err;
        /* FIXME: We don't want to register this socket with the portmapper */
-       ret = svc_makesock(serv, IPPROTO_TCP, 0);
+       ret = svc_makesock(serv, IPPROTO_TCP, nfs_callback_set_tcpport);
        if (ret < 0)
                goto out_destroy;
        if (!list_empty(&serv->sv_permsocks)) {
index a0db2d4f9415a04cb3513bda3808df4ddfe55280..b252e7fe53a5c2ffb52e053a609368f280cad2a4 100644 (file)
@@ -65,6 +65,7 @@ extern unsigned nfs4_callback_recall(struct cb_recallargs *args, void *dummy);
 extern int nfs_callback_up(void);
 extern int nfs_callback_down(void);
 
+extern unsigned int nfs_callback_set_tcpport;
 extern unsigned short nfs_callback_tcpport;
 
 #endif /* __LINUX_FS_NFS_CALLBACK_H */
index 7270b1d73d3056829b15d0fb5d44013d1634be6a..648cb1aef3b1098b4f3b51ed983d331d5b428e0d 100644 (file)
@@ -40,6 +40,7 @@
 #include <asm/uaccess.h>
 
 #include "nfs4_fs.h"
+#include "callback.h"
 #include "delegation.h"
 
 #define NFSDBG_FACILITY                NFSDBG_VFS
@@ -2036,6 +2037,21 @@ static struct file_system_type nfs4_fs_type = {
        .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static const int nfs_set_port_min = 0;
+static const int nfs_set_port_max = 65535;
+static int param_set_port(const char *val, struct kernel_param *kp)
+{
+       char *endp;
+       int num = simple_strtol(val, &endp, 0);
+       if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
+               return -EINVAL;
+       *((int *)kp->arg) = num;
+       return 0;
+}
+
+module_param_call(callback_tcpport, param_set_port, param_get_int,
+                &nfs_callback_set_tcpport, 0644);
+
 #define nfs4_init_once(nfsi) \
        do { \
                INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2043,8 +2059,25 @@ static struct file_system_type nfs4_fs_type = {
                nfsi->delegation_state = 0; \
                init_rwsem(&nfsi->rwsem); \
        } while(0)
-#define register_nfs4fs() register_filesystem(&nfs4_fs_type)
-#define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type)
+
+static inline int register_nfs4fs(void)
+{
+       int ret;
+
+       ret = nfs_register_sysctl();
+       if (ret != 0)
+               return ret;
+       ret = register_filesystem(&nfs4_fs_type);
+       if (ret != 0)
+               nfs_unregister_sysctl();
+       return ret;
+}
+
+static inline void unregister_nfs4fs(void)
+{
+       unregister_filesystem(&nfs4_fs_type);
+       nfs_unregister_sysctl();
+}
 #else
 #define nfs4_init_once(nfsi) \
        do { } while (0)
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
new file mode 100644 (file)
index 0000000..fdc64b5
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * linux/fs/nfs/sysctl.c
+ *
+ * Sysctl interface to NFS parameters
+ */
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/linkage.h>
+#include <linux/ctype.h>
+#include <linux/fs.h>
+#include <linux/sysctl.h>
+#include <linux/module.h>
+#include <linux/nfs4.h>
+
+#include "callback.h"
+
+static const int nfs_set_port_min = 0;
+static const int nfs_set_port_max = 65535;
+static struct ctl_table_header *nfs_callback_sysctl_table;
+/*
+ * Something that isn't CTL_ANY, CTL_NONE or a value that may clash.
+ * Use the same values as fs/lockd/svc.c
+ */
+#define CTL_UNNUMBERED -2
+
+static ctl_table nfs_cb_sysctls[] = {
+#ifdef CONFIG_NFS_V4
+       {
+               .ctl_name = CTL_UNNUMBERED,
+               .procname = "nfs_callback_tcpport",
+               .data = &nfs_callback_set_tcpport,
+               .maxlen = sizeof(int),
+               .mode = 0644,
+               .proc_handler = &proc_dointvec_minmax,
+               .extra1 = (int *)&nfs_set_port_min,
+               .extra2 = (int *)&nfs_set_port_max,
+       },
+#endif
+       { .ctl_name = 0 }
+};
+
+static ctl_table nfs_cb_sysctl_dir[] = {
+       {
+               .ctl_name = CTL_UNNUMBERED,
+               .procname = "nfs",
+               .mode = 0555,
+               .child = nfs_cb_sysctls,
+       },
+       { .ctl_name = 0 }
+};
+
+static ctl_table nfs_cb_sysctl_root[] = {
+       {
+               .ctl_name = CTL_FS,
+               .procname = "fs",
+               .mode = 0555,
+               .child = nfs_cb_sysctl_dir,
+       },
+       { .ctl_name = 0 }
+};
+
+int nfs_register_sysctl(void)
+{
+       nfs_callback_sysctl_table = register_sysctl_table(nfs_cb_sysctl_root, 0);
+       if (nfs_callback_sysctl_table == NULL)
+               return -ENOMEM;
+       return 0;
+}
+
+void nfs_unregister_sysctl(void)
+{
+       unregister_sysctl_table(nfs_callback_sysctl_table);
+       nfs_callback_sysctl_table = NULL;
+}
index 408d82d3d97cc5e264b586686b3475d5abd5a44d..547d649b274e25918491c184d7a1178b738ad875 100644 (file)
@@ -391,6 +391,17 @@ extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_
  */
 extern struct inode_operations nfs_symlink_inode_operations;
 
+/*
+ * linux/fs/nfs/sysctl.c
+ */
+#ifdef CONFIG_SYSCTL
+extern int nfs_register_sysctl(void);
+extern void nfs_unregister_sysctl(void);
+#else
+#define nfs_register_sysctl() do { } while(0)
+#define nfs_unregister_sysctl() do { } while(0)
+#endif
+
 /*
  * linux/fs/nfs/unlink.c
  */