Patchwork [BUG:1743,3/3] nfs: Introduce rpc.register-with-portmap to disable portmap registration

login
register
Submitter Shehjar Tikoo
Date 2010-11-03 12:05:29
Message ID <1288785929-516-3-git-send-email-shehjart@gluster.com>
Download mbox | patch
Permalink /patch/5635/
State Accepted
Headers show

Comments

Shehjar Tikoo - 2010-11-03 12:05:29
From: Shehjar Tikoo <shehjart@gluster.com>

For systems that need to run multiple nfs servers, we need to prevent
more than one from registering with portmap service. Use this option
to turn off portmap registration for Gluster NFS.

Portmap registration is on by default.

Signed-off-by: Shehjar Tikoo <shehjart@gluster.com>
---
 xlators/nfs/lib/src/rpcsvc.c |   47 +++++++++++++++++++++++++++++++++++++----
 xlators/nfs/lib/src/rpcsvc.h |    2 +
 xlators/nfs/server/src/nfs.c |    7 ++++++
 3 files changed, 51 insertions(+), 5 deletions(-)

Patch

diff --git a/xlators/nfs/lib/src/rpcsvc.c b/xlators/nfs/lib/src/rpcsvc.c
index 6a99514..112bf63 100644
--- a/xlators/nfs/lib/src/rpcsvc.c
+++ b/xlators/nfs/lib/src/rpcsvc.c
@@ -117,8 +117,39 @@  free_stg:
 int
 nfs_rpcsvc_init_options (rpcsvc_t *svc, dict_t *options)
 {
+        char            *optstr = NULL;
+        int             ret = -1;
+
+        if ((!svc) || (!options))
+                return -1;
+
         svc->memfactor = RPCSVC_DEFAULT_MEMFACTOR;
-        return 0;
+
+        svc->register_portmap = _gf_true;
+        if (dict_get (options, "rpc.register-with-portmap")) {
+                ret = dict_get_str (options, "rpc.register-with-portmap",
+                                    &optstr);
+                if (ret < 0) {
+                        gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to parse "
+                                "dict");
+                        goto out;
+                }
+
+                ret = gf_string2boolean (optstr, &svc->register_portmap);
+                if (ret < 0) {
+                        gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to parse bool "
+                                "string");
+                        goto out;
+                }
+        }
+
+        if (!svc->register_portmap)
+                gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Portmap registration "
+                        "disabled");
+
+        ret = 0;
+out:
+        return ret;
 }
 
 
@@ -2614,11 +2645,14 @@  err:
 
 /* Register the program with the local portmapper service. */
 int
-nfs_rpcsvc_program_register_portmap (rpcsvc_program_t *newprog)
+nfs_rpcsvc_program_register_portmap (rpcsvc_t *svc, rpcsvc_program_t *newprog)
 {
         if (!newprog)
                 return -1;
 
+        if (!svc->register_portmap)
+                return 0;
+
         if (!(pmap_set(newprog->prognum, newprog->progver, IPPROTO_TCP,
                        newprog->progport))) {
                 gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not register with"
@@ -2631,11 +2665,14 @@  nfs_rpcsvc_program_register_portmap (rpcsvc_program_t *newprog)
 
 
 int
-nfs_rpcsvc_program_unregister_portmap (rpcsvc_program_t *prog)
+nfs_rpcsvc_program_unregister_portmap (rpcsvc_t *svc, rpcsvc_program_t *prog)
 {
         if (!prog)
                 return -1;
 
+        if (!svc->register_portmap)
+                return 0;
+
         if (!(pmap_unset(prog->prognum, prog->progver))) {
                 gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not unregister with"
                         " portmap");
@@ -2704,7 +2741,7 @@  nfs_rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t program)
                 goto free_prog;
         }
 
-        ret = nfs_rpcsvc_program_register_portmap (newprog);
+        ret = nfs_rpcsvc_program_register_portmap (svc, newprog);
         if (ret == -1) {
                 gf_log (GF_RPCSVC, GF_LOG_ERROR, "portmap registration of"
                         " program failed");
@@ -2753,7 +2790,7 @@  nfs_rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t prog)
                 return -1;
 
         /* TODO: De-init the listening connection for this program. */
-        ret = nfs_rpcsvc_program_unregister_portmap (&prog);
+        ret = nfs_rpcsvc_program_unregister_portmap (svc, &prog);
         if (ret == -1) {
                 gf_log (GF_RPCSVC, GF_LOG_ERROR, "portmap unregistration of"
                         " program failed");
diff --git a/xlators/nfs/lib/src/rpcsvc.h b/xlators/nfs/lib/src/rpcsvc.h
index 7f73520..5a669cf 100644
--- a/xlators/nfs/lib/src/rpcsvc.h
+++ b/xlators/nfs/lib/src/rpcsvc.h
@@ -520,6 +520,8 @@  typedef struct rpc_svc_state {
         int                     allow_insecure;
 
         glusterfs_ctx_t         *ctx;
+
+        gf_boolean_t            register_portmap;
 } rpcsvc_t;
 
 
diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c
index c81e483..109c56c 100644
--- a/xlators/nfs/server/src/nfs.c
+++ b/xlators/nfs/server/src/nfs.c
@@ -828,6 +828,13 @@  struct volume_options options[] = {
                          "32-bit inode numbers instead. Disabled by default so "
                          "NFS returns 64-bit inode numbers by default."
         },
+        { .key  = {"rpc.register-with-portmap"},
+          .type = GF_OPTION_TYPE_BOOL,
+          .description = "For systems that need to run multiple nfs servers, we"
+                         "need to prevent more than one from registering with "
+                         "portmap service. Use this option to turn off portmap "
+                         "registration for Gluster NFS. On by default"
+        },
 	{ .key  = {NULL} },
 };