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