d84cf8
From d425ed54261d5bc19aa853854cc3b64647e3c897 Mon Sep 17 00:00:00 2001
d84cf8
From: Aravinda Vishwanathapura <aravinda@kadalu.io>
d84cf8
Date: Sun, 12 Jul 2020 12:42:36 +0530
d84cf8
Subject: [PATCH 461/465] geo-replication: Fix IPv6 parsing
d84cf8
d84cf8
Brick paths in Volinfo used `:` as delimiter, Geo-rep uses split
d84cf8
based on `:` char. This will go wrong with IPv6.
d84cf8
d84cf8
This patch handles the IPv6 case and handles the split properly.
d84cf8
Backport of:
d84cf8
   >Upstream Patch: https://review.gluster.org/#/c/glusterfs/+/24706
d84cf8
   >Fixes: #1366
d84cf8
   >Change-Id: I25e88d693744381c0ccf3c1dbf1541b84be2499d
d84cf8
   >Signed-off-by: Aravinda Vishwanathapura <aravinda@kadalu.io>
d84cf8
d84cf8
BUG: 1855966
d84cf8
Change-Id: I25e88d693744381c0ccf3c1dbf1541b84be2499d
d84cf8
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
d84cf8
Reviewed-on: https://code.engineering.redhat.com/gerrit/208610
d84cf8
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d84cf8
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d84cf8
---
d84cf8
 geo-replication/syncdaemon/master.py     |  5 ++--
d84cf8
 geo-replication/syncdaemon/syncdutils.py | 43 +++++++++++++++++++++++++++++---
d84cf8
 2 files changed, 43 insertions(+), 5 deletions(-)
d84cf8
d84cf8
diff --git a/geo-replication/syncdaemon/master.py b/geo-replication/syncdaemon/master.py
d84cf8
index 3f98337..08e98f8 100644
d84cf8
--- a/geo-replication/syncdaemon/master.py
d84cf8
+++ b/geo-replication/syncdaemon/master.py
d84cf8
@@ -26,7 +26,8 @@ from rconf import rconf
d84cf8
 from syncdutils import Thread, GsyncdError, escape_space_newline
d84cf8
 from syncdutils import unescape_space_newline, gauxpfx, escape
d84cf8
 from syncdutils import lstat, errno_wrap, FreeObject, lf, matching_disk_gfid
d84cf8
-from syncdutils import NoStimeAvailable, PartialHistoryAvailable
d84cf8
+from syncdutils import NoStimeAvailable, PartialHistoryAvailable, host_brick_split
d84cf8
+
d84cf8
 
d84cf8
 URXTIME = (-1, 0)
d84cf8
 
d84cf8
@@ -1466,7 +1467,7 @@ class GMasterChangelogMixin(GMasterCommon):
d84cf8
         node = rconf.args.resource_remote
d84cf8
         node_data = node.split("@")
d84cf8
         node = node_data[-1]
d84cf8
-        remote_node_ip = node.split(":")[0]
d84cf8
+        remote_node_ip, _ = host_brick_split(node)
d84cf8
         self.status.set_slave_node(remote_node_ip)
d84cf8
 
d84cf8
     def changelogs_batch_process(self, changes):
d84cf8
diff --git a/geo-replication/syncdaemon/syncdutils.py b/geo-replication/syncdaemon/syncdutils.py
d84cf8
index 7560fa1..f43e13b 100644
d84cf8
--- a/geo-replication/syncdaemon/syncdutils.py
d84cf8
+++ b/geo-replication/syncdaemon/syncdutils.py
d84cf8
@@ -883,6 +883,19 @@ class Popen(subprocess.Popen):
d84cf8
             self.errfail()
d84cf8
 
d84cf8
 
d84cf8
+def host_brick_split(value):
d84cf8
+    """
d84cf8
+    IPv6 compatible way to split and get the host
d84cf8
+    and brick information. Example inputs:
d84cf8
+    node1.example.com:/exports/bricks/brick1/brick
d84cf8
+    fe80::af0f:df82:844f:ef66%utun0:/exports/bricks/brick1/brick
d84cf8
+    """
d84cf8
+    parts = value.split(":")
d84cf8
+    brick = parts[-1]
d84cf8
+    hostparts = parts[0:-1]
d84cf8
+    return (":".join(hostparts), brick)
d84cf8
+
d84cf8
+
d84cf8
 class Volinfo(object):
d84cf8
 
d84cf8
     def __init__(self, vol, host='localhost', prelude=[], master=True):
d84cf8
@@ -925,7 +938,7 @@ class Volinfo(object):
d84cf8
     @memoize
d84cf8
     def bricks(self):
d84cf8
         def bparse(b):
d84cf8
-            host, dirp = b.find("name").text.split(':', 2)
d84cf8
+            host, dirp = host_brick_split(b.find("name").text)
d84cf8
             return {'host': host, 'dir': dirp, 'uuid': b.find("hostUuid").text}
d84cf8
         return [bparse(b) for b in self.get('brick')]
d84cf8
 
d84cf8
@@ -1001,6 +1014,16 @@ class VolinfoFromGconf(object):
d84cf8
     def is_hot(self, brickpath):
d84cf8
         return False
d84cf8
 
d84cf8
+    def is_uuid(self, value):
d84cf8
+        try:
d84cf8
+            uuid.UUID(value)
d84cf8
+            return True
d84cf8
+        except ValueError:
d84cf8
+            return False
d84cf8
+
d84cf8
+    def possible_path(self, value):
d84cf8
+        return "/" in value
d84cf8
+
d84cf8
     @property
d84cf8
     @memoize
d84cf8
     def bricks(self):
d84cf8
@@ -1014,8 +1037,22 @@ class VolinfoFromGconf(object):
d84cf8
         out = []
d84cf8
         for b in bricks_data:
d84cf8
             parts = b.split(":")
d84cf8
-            bpath = parts[2] if len(parts) == 3 else ""
d84cf8
-            out.append({"host": parts[1], "dir": bpath, "uuid": parts[0]})
d84cf8
+            b_uuid = None
d84cf8
+            if self.is_uuid(parts[0]):
d84cf8
+                b_uuid = parts[0]
d84cf8
+                # Set all parts except first
d84cf8
+                parts = parts[1:]
d84cf8
+
d84cf8
+            if self.possible_path(parts[-1]):
d84cf8
+                bpath = parts[-1]
d84cf8
+                # Set all parts except last
d84cf8
+                parts = parts[0:-1]
d84cf8
+
d84cf8
+            out.append({
d84cf8
+                "host": ":".join(parts),   # if remaining parts are IPv6 name
d84cf8
+                "dir": bpath,
d84cf8
+                "uuid": b_uuid
d84cf8
+            })
d84cf8
 
d84cf8
         return out
d84cf8
 
d84cf8
-- 
d84cf8
1.8.3.1
d84cf8