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