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