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