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