233933
From d7bb933742f4d9135621590bf13713633c549af1 Mon Sep 17 00:00:00 2001
233933
From: Aravinda VK <avishwan@redhat.com>
233933
Date: Thu, 14 Mar 2019 20:06:54 +0530
233933
Subject: [PATCH 52/52] geo-rep: IPv6 support
233933
233933
`address_family=inet6` needs to be added while mounting master and
233933
slave volumes in gverify script.
233933
233933
New option introduced to gluster cli(`--inet6`) which will be used
233933
internally by geo-rep while calling `gluster volume info
233933
--remote-host=<ipv6>`.
233933
233933
Backport of https://review.gluster.org/22363
233933
233933
Fixes: bz#1688231
233933
Change-Id: I1e0d42cae07158df043e64a2f991882d8c897837
233933
Signed-off-by: Aravinda VK <avishwan@redhat.com>
233933
Reviewed-on: https://code.engineering.redhat.com/gerrit/167120
233933
Tested-by: RHGS Build Bot <nigelb@redhat.com>
233933
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
233933
---
233933
 cli/src/cli.c                                | 11 ++++++++++
233933
 cli/src/cli.h                                |  1 +
233933
 geo-replication/src/gverify.sh               | 22 ++++++++++++++++----
233933
 geo-replication/syncdaemon/argsupgrade.py    | 13 +++++++++++-
233933
 geo-replication/syncdaemon/gsyncd.py         |  1 +
233933
 geo-replication/syncdaemon/subcmds.py        |  9 +++++++--
233933
 xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 30 ++++++++++++++++++++++++++--
233933
 7 files changed, 78 insertions(+), 9 deletions(-)
233933
233933
diff --git a/cli/src/cli.c b/cli/src/cli.c
233933
index 08f117e..c33d152 100644
233933
--- a/cli/src/cli.c
233933
+++ b/cli/src/cli.c
233933
@@ -433,6 +433,12 @@ cli_opt_parse(char *opt, struct cli_state *state)
233933
         return 0;
233933
     }
233933
 
233933
+    oarg = strtail(opt, "inet6");
233933
+    if (oarg) {
233933
+        state->address_family = "inet6";
233933
+        return 0;
233933
+    }
233933
+
233933
     oarg = strtail(opt, "log-file=");
233933
     if (oarg) {
233933
         state->log_file = oarg;
233933
@@ -679,6 +685,11 @@ cli_rpc_init(struct cli_state *state)
233933
     this = THIS;
233933
     cli_rpc_prog = &cli_prog;
233933
 
233933
+    /* If address family specified in CLI */
233933
+    if (state->address_family) {
233933
+        addr_family = state->address_family;
233933
+    }
233933
+
233933
     /* Connect to glusterd using the specified method, giving preference
233933
      * to a unix socket connection.  If nothing is specified, connect to
233933
      * the default glusterd socket.
233933
diff --git a/cli/src/cli.h b/cli/src/cli.h
233933
index 5df86d5..b79a0a2 100644
233933
--- a/cli/src/cli.h
233933
+++ b/cli/src/cli.h
233933
@@ -136,6 +136,7 @@ struct cli_state {
233933
     gf_loglevel_t log_level;
233933
 
233933
     char *glusterd_sock;
233933
+    char *address_family;
233933
 };
233933
 
233933
 struct cli_local {
233933
diff --git a/geo-replication/src/gverify.sh b/geo-replication/src/gverify.sh
233933
index d048de0..7c88f9f 100755
233933
--- a/geo-replication/src/gverify.sh
233933
+++ b/geo-replication/src/gverify.sh
233933
@@ -94,6 +94,7 @@ echo $cmd_line;
233933
 function master_stats()
233933
 {
233933
     MASTERVOL=$1;
233933
+    local inet6=$2;
233933
     local d;
233933
     local i;
233933
     local disk_size;
233933
@@ -102,7 +103,12 @@ function master_stats()
233933
     local m_status;
233933
 
233933
     d=$(mktemp -d -t ${0##*/}.XXXXXX 2>/dev/null);
233933
-    glusterfs -s localhost --xlator-option="*dht.lookup-unhashed=off" --volfile-id $MASTERVOL -l $master_log_file $d;
233933
+    if [ "$inet6" = "inet6" ]; then
233933
+        glusterfs -s localhost --xlator-option="*dht.lookup-unhashed=off" --xlator-option="transport.address-family=inet6" --volfile-id $MASTERVOL -l $master_log_file $d;
233933
+    else
233933
+        glusterfs -s localhost --xlator-option="*dht.lookup-unhashed=off" --volfile-id $MASTERVOL -l $master_log_file $d;
233933
+    fi
233933
+
233933
     i=$(get_inode_num $d);
233933
     if [[ "$i" -ne "1" ]]; then
233933
         echo 0:0;
233933
@@ -124,12 +130,18 @@ function slave_stats()
233933
     SLAVEUSER=$1;
233933
     SLAVEHOST=$2;
233933
     SLAVEVOL=$3;
233933
+    local inet6=$4;
233933
     local cmd_line;
233933
     local ver;
233933
     local status;
233933
 
233933
     d=$(mktemp -d -t ${0##*/}.XXXXXX 2>/dev/null);
233933
-    glusterfs --xlator-option="*dht.lookup-unhashed=off" --volfile-server $SLAVEHOST --volfile-id $SLAVEVOL -l $slave_log_file $d;
233933
+    if [ "$inet6" = "inet6" ]; then
233933
+        glusterfs --xlator-option="*dht.lookup-unhashed=off" --xlator-option="transport.address-family=inet6" --volfile-server $SLAVEHOST --volfile-id $SLAVEVOL -l $slave_log_file $d;
233933
+    else
233933
+        glusterfs --xlator-option="*dht.lookup-unhashed=off" --volfile-server $SLAVEHOST --volfile-id $SLAVEVOL -l $slave_log_file $d;
233933
+    fi
233933
+
233933
     i=$(get_inode_num $d);
233933
     if [[ "$i" -ne "1" ]]; then
233933
         echo 0:0;
233933
@@ -167,6 +179,8 @@ function main()
233933
     log_file=$6
233933
     > $log_file
233933
 
233933
+    inet6=$7
233933
+
233933
     # Use FORCE_BLOCKER flag in the error message to differentiate
233933
     # between the errors which the force command should bypass
233933
 
233933
@@ -204,8 +218,8 @@ function main()
233933
     fi;
233933
 
233933
     ERRORS=0;
233933
-    master_data=$(master_stats $1);
233933
-    slave_data=$(slave_stats $2 $3 $4);
233933
+    master_data=$(master_stats $1 ${inet6});
233933
+    slave_data=$(slave_stats $2 $3 $4 ${inet6});
233933
     master_disk_size=$(echo $master_data | cut -f1 -d':');
233933
     slave_disk_size=$(echo $slave_data | cut -f1 -d':');
233933
     master_used_size=$(echo $master_data | cut -f2 -d':');
233933
diff --git a/geo-replication/syncdaemon/argsupgrade.py b/geo-replication/syncdaemon/argsupgrade.py
233933
index 4018143..7af4063 100644
233933
--- a/geo-replication/syncdaemon/argsupgrade.py
233933
+++ b/geo-replication/syncdaemon/argsupgrade.py
233933
@@ -84,6 +84,10 @@ def upgrade():
233933
     # fail when it does stat to check the existence.
233933
     init_gsyncd_template_conf()
233933
 
233933
+    inet6 = False
233933
+    if "--inet6" in sys.argv:
233933
+        inet6 = True
233933
+
233933
     if "--monitor" in sys.argv:
233933
         # python gsyncd.py --path=/bricks/b1
233933
         # --monitor -c gsyncd.conf
233933
@@ -147,8 +151,11 @@ def upgrade():
233933
 
233933
             user, hname = remote_addr.split("@")
233933
 
233933
+            if not inet6:
233933
+                hname = gethostbyname(hname)
233933
+
233933
             print(("ssh://%s@%s:gluster://127.0.0.1:%s" % (
233933
-                user, gethostbyname(hname), vol)))
233933
+                user, hname, vol)))
233933
 
233933
         sys.exit(0)
233933
     elif "--normalize-url" in sys.argv:
233933
@@ -346,3 +353,7 @@ def upgrade():
233933
 
233933
         if pargs.reset_sync_time:
233933
             sys.argv.append("--reset-sync-time")
233933
+
233933
+    if inet6:
233933
+        # Add `--inet6` as first argument
233933
+        sys.argv = [sys.argv[0], "--inet6"] + sys.argv[1:]
233933
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
233933
index 037f351..effe0ce 100644
233933
--- a/geo-replication/syncdaemon/gsyncd.py
233933
+++ b/geo-replication/syncdaemon/gsyncd.py
233933
@@ -47,6 +47,7 @@ def main():
233933
         sys.exit(0)
233933
 
233933
     parser = ArgumentParser()
233933
+    parser.add_argument("--inet6", action="store_true")
233933
     sp = parser.add_subparsers(dest="subcmd")
233933
 
233933
     # Monitor Status File update
233933
diff --git a/geo-replication/syncdaemon/subcmds.py b/geo-replication/syncdaemon/subcmds.py
233933
index 30050ec..4ece7e0 100644
233933
--- a/geo-replication/syncdaemon/subcmds.py
233933
+++ b/geo-replication/syncdaemon/subcmds.py
233933
@@ -110,8 +110,13 @@ def subcmd_voluuidget(args):
233933
 
233933
     ParseError = XET.ParseError if hasattr(XET, 'ParseError') else SyntaxError
233933
 
233933
-    po = Popen(['gluster', '--xml', '--remote-host=' + args.host,
233933
-                'volume', 'info', args.volname], bufsize=0,
233933
+    cmd = ['gluster', '--xml', '--remote-host=' + args.host,
233933
+           'volume', 'info', args.volname]
233933
+
233933
+    if args.inet6:
233933
+        cmd.append("--inet6")
233933
+
233933
+    po = Popen(cmd, bufsize=0,
233933
                stdin=None, stdout=PIPE, stderr=PIPE,
233933
                universal_newlines=True)
233933
 
233933
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
233933
index 49baa58..0f40bea 100644
233933
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
233933
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
233933
@@ -76,6 +76,19 @@ static char *gsync_reserved_opts[] = {"gluster-command",
233933
 static char *gsync_no_restart_opts[] = {"checkpoint", "log_rsync_performance",
233933
                                         "log-rsync-performance", NULL};
233933
 
233933
+void
233933
+set_gsyncd_inet6_arg(runner_t *runner)
233933
+{
233933
+    xlator_t *this = NULL;
233933
+    char *af;
233933
+    int ret;
233933
+
233933
+    this = THIS;
233933
+    ret = dict_get_str(this->options, "transport.address-family", &af);
233933
+    if (ret == 0)
233933
+        runner_argprintf(runner, "--%s", af);
233933
+}
233933
+
233933
 int
233933
 __glusterd_handle_sys_exec(rpcsvc_request_t *req)
233933
 {
233933
@@ -384,6 +397,7 @@ glusterd_urltransform_init(runner_t *runner, const char *transname)
233933
 {
233933
     runinit(runner);
233933
     runner_add_arg(runner, GSYNCD_PREFIX "/gsyncd");
233933
+    set_gsyncd_inet6_arg(runner);
233933
     runner_argprintf(runner, "--%s-url", transname);
233933
 }
233933
 
233933
@@ -725,6 +739,7 @@ glusterd_get_slave_voluuid(char *slave_host, char *slave_vol, char *vol_uuid)
233933
 
233933
     runinit(&runner);
233933
     runner_add_arg(&runner, GSYNCD_PREFIX "/gsyncd");
233933
+    set_gsyncd_inet6_arg(&runner);
233933
     runner_add_arg(&runner, "--slavevoluuid-get");
233933
     runner_argprintf(&runner, "%s::%s", slave_host, slave_vol);
233933
 
233933
@@ -788,6 +803,7 @@ glusterd_gsync_get_config(char *master, char *slave, char *conf_path,
233933
     runinit(&runner);
233933
     runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL);
233933
     runner_argprintf(&runner, "%s", conf_path);
233933
+    set_gsyncd_inet6_arg(&runner);
233933
     runner_argprintf(&runner, "--iprefix=%s", DATADIR);
233933
     runner_argprintf(&runner, ":%s", master);
233933
     runner_add_args(&runner, slave, "--config-get-all", NULL);
233933
@@ -917,6 +933,7 @@ glusterd_gsync_get_status(char *master, char *slave, char *conf_path,
233933
     runinit(&runner);
233933
     runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL);
233933
     runner_argprintf(&runner, "%s", conf_path);
233933
+    set_gsyncd_inet6_arg(&runner);
233933
     runner_argprintf(&runner, "--iprefix=%s", DATADIR);
233933
     runner_argprintf(&runner, ":%s", master);
233933
     runner_add_args(&runner, slave, "--status-get", NULL);
233933
@@ -937,6 +954,7 @@ glusterd_gsync_get_param_file(char *prmfile, const char *param, char *master,
233933
     runinit(&runner);
233933
     runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL);
233933
     runner_argprintf(&runner, "%s", conf_path);
233933
+    set_gsyncd_inet6_arg(&runner);
233933
     runner_argprintf(&runner, "--iprefix=%s", DATADIR);
233933
     runner_argprintf(&runner, ":%s", master);
233933
     runner_add_args(&runner, slave, "--config-get", NULL);
233933
@@ -2811,6 +2829,7 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol,
233933
     char *slave_ip = NULL;
233933
     glusterd_conf_t *priv = NULL;
233933
     xlator_t *this = NULL;
233933
+    char *af = NULL;
233933
 
233933
     this = THIS;
233933
     GF_ASSERT(this);
233933
@@ -2852,9 +2871,16 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol,
233933
     runner_argprintf(&runner, "%s", slave_vol);
233933
     runner_argprintf(&runner, "%d", ssh_port);
233933
     runner_argprintf(&runner, "%s", log_file_path);
233933
-    gf_msg_debug(this->name, 0, "gverify Args = %s %s %s %s %s %s %s",
233933
+    ret = dict_get_str(this->options, "transport.address-family", &af);
233933
+    if (ret)
233933
+        af = "-";
233933
+
233933
+    runner_argprintf(&runner, "%s", af);
233933
+
233933
+    gf_msg_debug(this->name, 0, "gverify Args = %s %s %s %s %s %s %s %s",
233933
                  runner.argv[0], runner.argv[1], runner.argv[2], runner.argv[3],
233933
-                 runner.argv[4], runner.argv[5], runner.argv[6]);
233933
+                 runner.argv[4], runner.argv[5], runner.argv[6],
233933
+                 runner.argv[7]);
233933
     runner_redir(&runner, STDOUT_FILENO, RUN_PIPE);
233933
     synclock_unlock(&priv->big_lock);
233933
     ret = runner_run(&runner);
233933
-- 
233933
1.8.3.1
233933