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