Blob Blame History Raw
From ae01f8acacf8e51b6c3486e3349497bb4e982866 Mon Sep 17 00:00:00 2001
From: Milind Changire <mchangir@redhat.com>
Date: Sat, 9 Feb 2019 13:38:40 +0530
Subject: [PATCH 521/529] rpc: use address-family option from vol file

This patch helps enable IPv6 connections in the cluster.
The default address-family is IPv4 without using this option explicitly.

When address-family is set to "inet6" in the /etc/glusterfs/glusterd.vol
file, the mount command-line also needs to have
-o xlator-option="transport.address-family=inet6" added to it.

This option also gets added to the brick command-line.
Snapshot and gfapi use-cases should also use this option to pass in the
inet6 address-family.

mainline:
> Change-Id: I97db91021af27bacb6d7578e33ea4817f66d7270
> fixes: bz#1635863
> Signed-off-by: Milind Changire <mchangir@redhat.com>
> Reviewed-on: https://review.gluster.org/c/glusterfs/+/21948

Change-Id: I97db91021af27bacb6d7578e33ea4817f66d7270
BUG: 1618669
Signed-off-by: Milind Changire <mchangir@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/162620
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Amar Tumballi Suryanarayan <amarts@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 api/src/glfs-mgmt.c                                    | 12 +++++++++---
 glusterfsd/src/glusterfsd-mgmt.c                       |  6 +++++-
 libglusterfs/src/common-utils.c                        | 18 ++++++++++++++++--
 libglusterfs/src/common-utils.h                        |  3 +++
 rpc/rpc-lib/src/rpc-transport.c                        |  6 +++---
 rpc/rpc-lib/src/rpc-transport.h                        |  2 +-
 .../snapview-server/src/snapview-server-mgmt.c         |  5 ++++-
 xlators/mgmt/glusterd/src/glusterd-handler.c           | 11 ++++++++---
 xlators/mgmt/glusterd/src/glusterd-utils.c             |  7 +++++++
 9 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c
index b70dc35..f1281bb 100644
--- a/api/src/glfs-mgmt.c
+++ b/api/src/glfs-mgmt.c
@@ -646,8 +646,10 @@ glfs_mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count,
 	*  volfile if topology hasn't changed.
 	*  glusterfs_volfile_reconfigure returns 3 possible return states
 	*  return 0	     =======> reconfiguration of options has succeeded
-	*  return 1	     =======> the graph has to be reconstructed and all the xlators should be inited
-	*  return -1(or -ve) =======> Some Internal Error occurred during the operation
+	*  return 1	     =======> the graph has to be reconstructed and all the
+    *                         xlators should be inited
+	*  return -1(or -ve) =======> Some Internal Error occurred during the
+    *                             operation
 	*/
 
         ret = gf_volfile_reconfigure (fs->oldvollen, tmpfp, fs->ctx,
@@ -988,7 +990,11 @@ glfs_mgmt_init (struct glfs *fs)
             !strcmp (cmd_args->volfile_server_transport, "unix")) {
                 ret = rpc_transport_unix_options_build (&options, host, 0);
         } else {
-                ret = rpc_transport_inet_options_build (&options, host, port);
+                xlator_cmdline_option_t *opt =
+                        find_xlator_option_in_cmd_args_t("address-family",
+                                                         cmd_args);
+                ret = rpc_transport_inet_options_build(&options, host, port,
+                                                       (opt ? opt->value : NULL));
         }
 
 	if (ret)
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
index b952526..e38ad64 100644
--- a/glusterfsd/src/glusterfsd-mgmt.c
+++ b/glusterfsd/src/glusterfsd-mgmt.c
@@ -2552,6 +2552,7 @@ glusterfs_mgmt_init (glusterfs_ctx_t *ctx)
         int                     ret = -1;
         int                     port = GF_DEFAULT_BASE_PORT;
         char                    *host = NULL;
+        xlator_cmdline_option_t *opt = NULL;
 
         cmd_args = &ctx->cmd_args;
         GF_VALIDATE_OR_GOTO (THIS->name, cmd_args->volfile_server, out);
@@ -2570,7 +2571,10 @@ glusterfs_mgmt_init (glusterfs_ctx_t *ctx)
             !strcmp (cmd_args->volfile_server_transport, "unix")) {
                 ret = rpc_transport_unix_options_build (&options, host, 0);
         } else {
-                ret = rpc_transport_inet_options_build (&options, host, port);
+                opt = find_xlator_option_in_cmd_args_t("address-family",
+                                                       cmd_args);
+                ret = rpc_transport_inet_options_build(&options, host, port,
+                                                       (opt ? opt->value : NULL));
         }
         if (ret)
                 goto out;
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 1243754..e3f3989 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -477,8 +477,9 @@ gf_resolve_ip6 (const char *hostname,
                 }
                 if ((ret = getaddrinfo(hostname, port_str, &hints, &cache->first)) != 0) {
                         gf_msg ("resolver", GF_LOG_ERROR, 0,
-                                LG_MSG_GETADDRINFO_FAILED, "getaddrinfo failed"
-                                " (%s)", gai_strerror (ret));
+                                LG_MSG_GETADDRINFO_FAILED,
+                                "getaddrinfo failed (family:%d) (%s)", family,
+                                gai_strerror (ret));
 
                         GF_FREE (*dnscache);
                         *dnscache = NULL;
@@ -5136,3 +5137,16 @@ out:
         return NULL;
 }
 
+xlator_cmdline_option_t *
+find_xlator_option_in_cmd_args_t(const char *option_name, cmd_args_t *args)
+{
+        xlator_cmdline_option_t *pos = NULL;
+        xlator_cmdline_option_t *tmp = NULL;
+
+        list_for_each_entry_safe(pos, tmp, &args->xlator_options, cmd_args)
+        {
+                if (strcmp(pos->key, option_name) == 0)
+                        return pos;
+        }
+        return NULL;
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 50c1f9a..15a31a3 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -945,4 +945,7 @@ glusterfs_compute_sha256 (const unsigned char *content, size_t size,
 char*
 get_struct_variable (int mem_num, gf_gsync_status_t *sts_val);
 
+xlator_cmdline_option_t *
+find_xlator_option_in_cmd_args_t(const char *option_name, cmd_args_t *args);
+
 #endif /* _COMMON_UTILS_H */
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 0c6ab66..b737ff2 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -666,7 +666,7 @@ out:
 
 int
 rpc_transport_inet_options_build (dict_t **options, const char *hostname,
-                                  int port)
+                                  int port, char *af)
 {
         dict_t          *dict = NULL;
         char            *host = NULL;
@@ -702,10 +702,10 @@ rpc_transport_inet_options_build (dict_t **options, const char *hostname,
                 goto out;
         }
 
-        ret = dict_set_str (dict, "address-family", addr_family);
+        ret = dict_set_str (dict, "address-family", (af != NULL ? af : addr_family));
         if (ret) {
                 gf_log (THIS->name, GF_LOG_WARNING,
-                        "failed to set address-family to %s", addr_family);
+                        "failed to set address-family to %s", (af != NULL ? af : addr_family));
                 goto out;
         }
 
diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h
index f5fb6e1..c97f98d 100644
--- a/rpc/rpc-lib/src/rpc-transport.h
+++ b/rpc/rpc-lib/src/rpc-transport.h
@@ -316,7 +316,7 @@ rpc_transport_unix_options_build (dict_t **options, char *filepath,
                                   int frame_timeout);
 
 int
-rpc_transport_inet_options_build (dict_t **options, const char *hostname, int port);
+rpc_transport_inet_options_build (dict_t **options, const char *hostname, int port, char *af);
 
 void
 rpc_transport_cleanup(rpc_transport_t *);
diff --git a/xlators/features/snapview-server/src/snapview-server-mgmt.c b/xlators/features/snapview-server/src/snapview-server-mgmt.c
index 18c902d..f82c8a0 100644
--- a/xlators/features/snapview-server/src/snapview-server-mgmt.c
+++ b/xlators/features/snapview-server/src/snapview-server-mgmt.c
@@ -84,6 +84,7 @@ svs_mgmt_init (xlator_t *this)
         char            *host     = NULL;
         cmd_args_t      *cmd_args = NULL;
         glusterfs_ctx_t *ctx      = NULL;
+        xlator_cmdline_option_t *opt = NULL;
 
         GF_VALIDATE_OR_GOTO ("snapview-server", this, out);
         GF_VALIDATE_OR_GOTO (this->name, this->private, out);
@@ -98,7 +99,9 @@ svs_mgmt_init (xlator_t *this)
         if (cmd_args->volfile_server)
                 host = cmd_args->volfile_server;
 
-        ret = rpc_transport_inet_options_build (&options, host, port);
+        opt = find_xlator_option_in_cmd_args_t("address-family", cmd_args);
+        ret = rpc_transport_inet_options_build(&options, host, port,
+                                               (opt != NULL ? opt->value : NULL));
         if (ret) {
                 gf_log (this->name, GF_LOG_ERROR, "failed to build the "
                         "transport options");
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 81b1c02..e92cb5f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -3440,7 +3440,7 @@ out:
 
 int
 glusterd_transport_inet_options_build (dict_t **options, const char *hostname,
-                                       int port)
+                                       int port, char *af)
 {
         xlator_t *this = NULL;
         dict_t  *dict = NULL;
@@ -3458,7 +3458,7 @@ glusterd_transport_inet_options_build (dict_t **options, const char *hostname,
                 port = GLUSTERD_DEFAULT_PORT;
 
         /* Build default transport options */
-        ret = rpc_transport_inet_options_build (&dict, hostname, port);
+        ret = rpc_transport_inet_options_build (&dict, hostname, port, af);
         if (ret)
                 goto out;
 
@@ -3518,6 +3518,7 @@ glusterd_friend_rpc_create (xlator_t *this, glusterd_peerinfo_t *peerinfo,
         int                       ret     = -1;
         glusterd_peerctx_t       *peerctx = NULL;
         data_t                   *data    = NULL;
+        char                     *af      = NULL;
 
         peerctx = GF_CALLOC (1, sizeof (*peerctx), gf_gld_mt_peerctx_t);
         if (!peerctx)
@@ -3532,10 +3533,14 @@ glusterd_friend_rpc_create (xlator_t *this, glusterd_peerinfo_t *peerinfo,
                                                          number can be used to
                                                          uniquely identify a
                                                          peerinfo */
+        ret = dict_get_str(this->options, "transport.address-family", &af);
+        if (ret)
+                gf_log(this->name, GF_LOG_TRACE,
+                       "option transport.address-family is not set in xlator options");
 
         ret = glusterd_transport_inet_options_build (&options,
                                                      peerinfo->hostname,
-                                                     peerinfo->port);
+                                                     peerinfo->port, af);
         if (ret)
                 goto out;
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index bafc3af..50758ca 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1975,6 +1975,7 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t  *volinfo,
         rpc_clnt_connection_t   *conn  = NULL;
         int                     pid    = -1;
         glusterd_brick_proc_t   *brick_proc = NULL;
+        char                    *inet_family = NULL;
 
         GF_ASSERT (volinfo);
         GF_ASSERT (brickinfo);
@@ -2140,6 +2141,12 @@ retry:
                 runner_argprintf (&runner,
                                   "--volfile-server-transport=socket,rdma");
 
+        ret = dict_get_str(this->options, "transport.address-family", &inet_family);
+        if (!ret) {
+                runner_add_arg(&runner, "--xlator-option");
+                runner_argprintf(&runner, "transport.address-family=%s", inet_family);
+        }
+
         if (volinfo->memory_accounting)
                 runner_add_arg (&runner, "--mem-accounting");
 
-- 
1.8.3.1