f338ef
From 4a2441e76f4240568093080769ede07bb7fb2016 Mon Sep 17 00:00:00 2001
f338ef
From: Kotresh HR <khiremat@redhat.com>
f338ef
Date: Sun, 20 Oct 2019 01:01:39 +0530
f338ef
Subject: [PATCH 311/313] geo-rep: Fix Permission denied traceback on non root
f338ef
 setup
f338ef
f338ef
Problem:
f338ef
While syncing rename of directory in hybrid crawl, geo-rep
f338ef
crashes as below.
f338ef
f338ef
Traceback (most recent call last):
f338ef
  File "/usr/local/libexec/glusterfs/python/syncdaemon/repce.py", line 118, in worker
f338ef
    res = getattr(self.obj, rmeth)(*in_data[2:])
f338ef
  File "/usr/local/libexec/glusterfs/python/syncdaemon/resource.py", line 588, in entry_ops
f338ef
    src_entry = get_slv_dir_path(slv_host, slv_volume, gfid)
f338ef
  File "/usr/local/libexec/glusterfs/python/syncdaemon/syncdutils.py", line 687, in get_slv_dir_path
f338ef
    [ENOENT], [ESTALE])
f338ef
  File "/usr/local/libexec/glusterfs/python/syncdaemon/syncdutils.py", line 546, in errno_wrap
f338ef
    return call(*arg)
f338ef
PermissionError: [Errno 13] Permission denied: '/bricks/brick1/b1/.glusterfs/8e/c0/8ec0fcd4-d50f-4a6e-b473-a7943ab66640'
f338ef
f338ef
Cause:
f338ef
Conversion of gfid to path for a directory uses readlink on backend
f338ef
.glusterfs gfid path. But this fails for non root user with
f338ef
permission denied.
f338ef
f338ef
Fix:
f338ef
Use gfid2path interface to get the path from gfid
f338ef
f338ef
Backport of:
f338ef
 > Patch: https://review.gluster.org/23570
f338ef
 > Change-Id: I9d40c713a1b32cea95144cbc0f384ada82972222
f338ef
 > fixes: bz#1763439
f338ef
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
f338ef
f338ef
Change-Id: I9d40c713a1b32cea95144cbc0f384ada82972222
f338ef
BUG: 1763412
f338ef
Signed-off-by: Kotresh HR <khiremat@redhat.com>
f338ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/183665
f338ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
f338ef
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
f338ef
---
f338ef
 geo-replication/syncdaemon/gsyncd.py               |  3 +-
f338ef
 geo-replication/syncdaemon/syncdutils.py           | 35 ++++++++++++++++------
f338ef
 tests/00-geo-rep/00-georep-verify-non-root-setup.t | 30 +++++++++++++++----
f338ef
 3 files changed, 52 insertions(+), 16 deletions(-)
f338ef
f338ef
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
f338ef
index 7b48d82..8940384 100644
f338ef
--- a/geo-replication/syncdaemon/gsyncd.py
f338ef
+++ b/geo-replication/syncdaemon/gsyncd.py
f338ef
@@ -231,7 +231,8 @@ def main():
f338ef
     # Set default path for config file in that case
f338ef
     # If an subcmd accepts config file then it also accepts
f338ef
     # master and Slave arguments.
f338ef
-    if config_file is None and hasattr(args, "config_file"):
f338ef
+    if config_file is None and hasattr(args, "config_file") \
f338ef
+        and args.subcmd != "slave":
f338ef
         config_file = "%s/geo-replication/%s_%s_%s/gsyncd.conf" % (
f338ef
             GLUSTERD_WORKDIR,
f338ef
             args.master,
f338ef
diff --git a/geo-replication/syncdaemon/syncdutils.py b/geo-replication/syncdaemon/syncdutils.py
f338ef
index aadaebd..b08098e 100644
f338ef
--- a/geo-replication/syncdaemon/syncdutils.py
f338ef
+++ b/geo-replication/syncdaemon/syncdutils.py
f338ef
@@ -57,6 +57,7 @@ from hashlib import sha256 as sha256
f338ef
 
f338ef
 # auxiliary gfid based access prefix
f338ef
 _CL_AUX_GFID_PFX = ".gfid/"
f338ef
+ROOT_GFID = "00000000-0000-0000-0000-000000000001"
f338ef
 GF_OP_RETRIES = 10
f338ef
 
f338ef
 GX_GFID_CANONICAL_LEN = 37  # canonical gfid len + '\0'
f338ef
@@ -670,6 +671,7 @@ def get_slv_dir_path(slv_host, slv_volume, gfid):
f338ef
     global slv_bricks
f338ef
 
f338ef
     dir_path = ENOENT
f338ef
+    pfx = gauxpfx()
f338ef
 
f338ef
     if not slv_bricks:
f338ef
         slv_info = Volinfo(slv_volume, slv_host, master=False)
f338ef
@@ -683,15 +685,30 @@ def get_slv_dir_path(slv_host, slv_volume, gfid):
f338ef
                                gfid[2:4],
f338ef
                                gfid], [ENOENT], [ESTALE])
f338ef
         if dir_path != ENOENT:
f338ef
-            realpath = errno_wrap(os.readlink, [dir_path],
f338ef
-                                  [ENOENT], [ESTALE])
f338ef
-            if not isinstance(realpath, int):
f338ef
-                realpath_parts = realpath.split('/')
f338ef
-                pargfid = realpath_parts[-2]
f338ef
-                basename = realpath_parts[-1]
f338ef
-                pfx = gauxpfx()
f338ef
-                dir_entry = os.path.join(pfx, pargfid, basename)
f338ef
-                return dir_entry
f338ef
+            try:
f338ef
+                realpath = errno_wrap(os.readlink, [dir_path],
f338ef
+                                      [ENOENT], [ESTALE])
f338ef
+                if not isinstance(realpath, int):
f338ef
+                    realpath_parts = realpath.split('/')
f338ef
+                    pargfid = realpath_parts[-2]
f338ef
+                    basename = realpath_parts[-1]
f338ef
+                    dir_entry = os.path.join(pfx, pargfid, basename)
f338ef
+                    return dir_entry
f338ef
+            except OSError:
f338ef
+                # .gfid/GFID
f338ef
+                gfidpath = unescape_space_newline(os.path.join(pfx, gfid))
f338ef
+                realpath = errno_wrap(Xattr.lgetxattr_buf,
f338ef
+                      [gfidpath, 'glusterfs.gfid2path'], [ENOENT], [ESTALE])
f338ef
+                if not isinstance(realpath, int):
f338ef
+                    basename = os.path.basename(realpath).rstrip('\x00')
f338ef
+                    dirpath = os.path.dirname(realpath)
f338ef
+                    if dirpath is "/":
f338ef
+                        pargfid = ROOT_GFID
f338ef
+                    else:
f338ef
+                        dirpath = dirpath.strip("/")
f338ef
+                        pargfid = get_gfid_from_mnt(dirpath)
f338ef
+                    dir_entry = os.path.join(pfx, pargfid, basename)
f338ef
+                    return dir_entry
f338ef
 
f338ef
     return None
f338ef
 
f338ef
diff --git a/tests/00-geo-rep/00-georep-verify-non-root-setup.t b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
f338ef
index e753c1f..c9fd8b2 100644
f338ef
--- a/tests/00-geo-rep/00-georep-verify-non-root-setup.t
f338ef
+++ b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
f338ef
@@ -118,8 +118,8 @@ clean_lock_files
f338ef
 TEST /usr/sbin/groupadd $grp
f338ef
 
f338ef
 clean_lock_files
f338ef
-##Create non-root user and assign it to newly created group
f338ef
-
f338ef
+##Del if exists and create non-root user and assign it to newly created group
f338ef
+userdel -r -f $usr
f338ef
 TEST /usr/sbin/useradd -G $grp $usr
f338ef
 
f338ef
 ##Modify password for non-root user to have control over distributing ssh-key
f338ef
@@ -140,8 +140,6 @@ TEST killall_gluster;
f338ef
 TEST glusterd;
f338ef
 TEST pidof glusterd;
f338ef
 
f338ef
-
f338ef
-
f338ef
 ##Create, start and mount meta_volume
f338ef
 TEST $CLI volume create $META_VOL replica 3 $H0:$B0/${META_VOL}{1,2,3};
f338ef
 TEST $CLI volume start $META_VOL
f338ef
@@ -225,6 +223,26 @@ TEST $GEOREP_CLI  $master $slave_url resume
f338ef
 #Validate failure of volume stop when geo-rep is running
f338ef
 TEST ! $CLI volume stop $GMV0
f338ef
 
f338ef
+#Hybrid directory rename test BZ#1763439
f338ef
+TEST $GEOREP_CLI $master $slave_url config change_detector xsync
f338ef
+mkdir ${master_mnt}/dir1
f338ef
+mkdir ${master_mnt}/dir1/dir2
f338ef
+mkdir ${master_mnt}/dir1/dir3
f338ef
+mkdir ${master_mnt}/hybrid_d1
f338ef
+
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/hybrid_d1
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/dir2
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/dir3
f338ef
+
f338ef
+mv ${master_mnt}/hybrid_d1 ${master_mnt}/hybrid_rn_d1
f338ef
+mv ${master_mnt}/dir1/dir2 ${master_mnt}/rn_dir2
f338ef
+mv ${master_mnt}/dir1/dir3 ${master_mnt}/dir1/rn_dir3
f338ef
+
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/hybrid_rn_d1
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/rn_dir2
f338ef
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 directory_ok ${slave_mnt}/dir1/rn_dir3
f338ef
+
f338ef
 #Stop Geo-rep
f338ef
 TEST $GEOREP_CLI $master $slave_url stop
f338ef
 
f338ef
@@ -232,8 +250,8 @@ TEST $GEOREP_CLI $master $slave_url stop
f338ef
 TEST $GEOREP_CLI $master $slave_url delete
f338ef
 
f338ef
 #Cleanup authorized_keys
f338ef
-sed -i '/^command=.*SSH_ORIGINAL_COMMAND#.*/d' ~/.ssh/authorized_keys
f338ef
-sed -i '/^command=.*gsyncd.*/d' ~/.ssh/authorized_keys
f338ef
+sed -i '/^command=.*SSH_ORIGINAL_COMMAND#.*/d' /home/$usr/.ssh/authorized_keys
f338ef
+sed -i '/^command=.*gsyncd.*/d' /home/$usr/.ssh/authorized_keys
f338ef
 
f338ef
 #clear mountbroker
f338ef
 gluster-mountbroker remove --user $usr
f338ef
-- 
f338ef
1.8.3.1
f338ef