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