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