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