17b94a
From 3f1eee125a35c33ecb078e5d3bfd80d80e63881d Mon Sep 17 00:00:00 2001
17b94a
From: Barak Sason Rofman <bsasonro@redhat.com>
17b94a
Date: Wed, 15 Jan 2020 12:02:05 +0200
17b94a
Subject: [PATCH 502/511] dht - fixing a permission update issue
17b94a
17b94a
When bringing back a downed brick and performing lookup from the client
17b94a
side, the permission on said brick aren't updated on the first lookup,
17b94a
but only on the second.
17b94a
17b94a
This patch modifies permission update logic so the first lookup will
17b94a
trigger a permission update on the downed brick.
17b94a
17b94a
LIMITATIONS OF THE PATCH:
17b94a
As the choice of source depends on whether the directory has layout or not.
17b94a
Even the directories on the newly added brick will have layout xattr[zeroed], but the same is not true for a root directory.
17b94a
Hence, in case in the entire cluster only the newly added bricks are up [and others are down], then any change in permission during this time will be overwritten by the older permissions when the cluster is restarted.
17b94a
17b94a
Upstream:
17b94a
> Reviewed-on: https://review.gluster.org/#/c/glusterfs/+/24020/
17b94a
> fixes: #999
17b94a
> Change-Id: Ieb70246d41e59f9cae9f70bc203627a433dfbd33
17b94a
> Signed-off-by: Barak Sason Rofman <bsasonro@redhat.com>
17b94a
17b94a
BUG: 1663821
17b94a
Change-Id: Ieb70246d41e59f9cae9f70bc203627a433dfbd33
17b94a
Signed-off-by: Barak Sason Rofman <bsasonro@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/221116
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 tests/bugs/bug-1064147.t                 | 71 ++++++++++++++++++++++++++++++++
17b94a
 xlators/cluster/dht/src/dht-common.c     | 28 ++++++++++---
17b94a
 xlators/cluster/dht/src/dht-selfheal.c   | 15 +++++--
17b94a
 xlators/storage/posix/src/posix-common.c | 16 +++----
17b94a
 4 files changed, 111 insertions(+), 19 deletions(-)
17b94a
 create mode 100755 tests/bugs/bug-1064147.t
17b94a
17b94a
diff --git a/tests/bugs/bug-1064147.t b/tests/bugs/bug-1064147.t
17b94a
new file mode 100755
17b94a
index 0000000..617a1aa
17b94a
--- /dev/null
17b94a
+++ b/tests/bugs/bug-1064147.t
17b94a
@@ -0,0 +1,71 @@
17b94a
+#!/bin/bash
17b94a
+
17b94a
+. $(dirname $0)/../include.rc
17b94a
+. $(dirname $0)/../volume.rc
17b94a
+
17b94a
+# Initialize
17b94a
+#------------------------------------------------------------
17b94a
+cleanup;
17b94a
+
17b94a
+# Start glusterd
17b94a
+TEST glusterd;
17b94a
+TEST pidof glusterd;
17b94a
+TEST $CLI volume info;
17b94a
+
17b94a
+# Create a volume
17b94a
+TEST $CLI volume create $V0 $H0:/${V0}{1,2};
17b94a
+
17b94a
+# Verify volume creation
17b94a
+ EXPECT "$V0" volinfo_field $V0 'Volume Name';
17b94a
+ EXPECT 'Created' volinfo_field $V0 'Status';
17b94a
+
17b94a
+# Start volume and verify successful start
17b94a
+ TEST $CLI volume start $V0;
17b94a
+ EXPECT 'Started' volinfo_field $V0 'Status';
17b94a
+ TEST glusterfs -s $H0 --volfile-id=$V0 $M0
17b94a
+#------------------------------------------------------------
17b94a
+
17b94a
+# Test case 1 - Subvolume down + Healing
17b94a
+#------------------------------------------------------------
17b94a
+# Kill 2nd brick process
17b94a
+TEST kill -9  `ps aux | grep glusterfsd | grep ${V0}2 | grep -v grep | awk '{print $2}'`;
17b94a
+
17b94a
+# Change root permissions
17b94a
+TEST chmod 444 $M0
17b94a
+
17b94a
+# Store permission for comparision
17b94a
+TEST permission_new=`stat -c "%A" $M0`
17b94a
+
17b94a
+# Bring up the killed brick process
17b94a
+TEST $CLI volume start $V0 force
17b94a
+
17b94a
+# Perform lookup
17b94a
+sleep 5
17b94a
+TEST ls $M0
17b94a
+
17b94a
+# Check brick permissions
17b94a
+TEST brick_perm=`stat -c "%A" /${V0}2`
17b94a
+TEST [ ${brick_perm} = ${permission_new} ]
17b94a
+#------------------------------------------------------------
17b94a
+
17b94a
+# Test case 2 - Add-brick + Healing
17b94a
+#------------------------------------------------------------
17b94a
+# Change root permissions
17b94a
+TEST chmod 777 $M0
17b94a
+
17b94a
+# Store permission for comparision
17b94a
+TEST permission_new_2=`stat -c "%A" $M0`
17b94a
+
17b94a
+# Add a 3rd brick
17b94a
+TEST $CLI volume add-brick $V0 $H0:/${V0}3
17b94a
+
17b94a
+# Perform lookup
17b94a
+sleep 5
17b94a
+TEST ls $M0
17b94a
+
17b94a
+# Check permissions on the new brick
17b94a
+TEST brick_perm2=`stat -c "%A" /${V0}3`
17b94a
+
17b94a
+TEST [ ${brick_perm2} = ${permission_new_2} ]
17b94a
+
17b94a
+cleanup;
17b94a
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
17b94a
index 4db89df..fe1d0ee 100644
17b94a
--- a/xlators/cluster/dht/src/dht-common.c
17b94a
+++ b/xlators/cluster/dht/src/dht-common.c
17b94a
@@ -1363,13 +1363,29 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
17b94a
             dht_aggregate_xattr(local->xattr, xattr);
17b94a
         }
17b94a
 
17b94a
+        if (__is_root_gfid(stbuf->ia_gfid)) {
17b94a
+            ret = dht_dir_has_layout(xattr, conf->xattr_name);
17b94a
+            if (ret >= 0) {
17b94a
+                if (is_greater_time(local->prebuf.ia_ctime,
17b94a
+                                    local->prebuf.ia_ctime_nsec,
17b94a
+                                    stbuf->ia_ctime, stbuf->ia_ctime_nsec)) {
17b94a
+                    /* Choose source */
17b94a
+                    local->prebuf.ia_gid = stbuf->ia_gid;
17b94a
+                    local->prebuf.ia_uid = stbuf->ia_uid;
17b94a
+
17b94a
+                    local->prebuf.ia_ctime = stbuf->ia_ctime;
17b94a
+                    local->prebuf.ia_ctime_nsec = stbuf->ia_ctime_nsec;
17b94a
+                    local->prebuf.ia_prot = stbuf->ia_prot;
17b94a
+                }
17b94a
+            }
17b94a
+        }
17b94a
+
17b94a
         if (local->stbuf.ia_type != IA_INVAL) {
17b94a
             /* This is not the first subvol to respond */
17b94a
-            if (!__is_root_gfid(stbuf->ia_gfid) &&
17b94a
-                ((local->stbuf.ia_gid != stbuf->ia_gid) ||
17b94a
-                 (local->stbuf.ia_uid != stbuf->ia_uid) ||
17b94a
-                 (is_permission_different(&local->stbuf.ia_prot,
17b94a
-                                          &stbuf->ia_prot)))) {
17b94a
+            if ((local->stbuf.ia_gid != stbuf->ia_gid) ||
17b94a
+                (local->stbuf.ia_uid != stbuf->ia_uid) ||
17b94a
+                (is_permission_different(&local->stbuf.ia_prot,
17b94a
+                                         &stbuf->ia_prot))) {
17b94a
                 local->need_attrheal = 1;
17b94a
             }
17b94a
         }
17b94a
@@ -10969,7 +10985,7 @@ dht_notify(xlator_t *this, int event, void *data, ...)
17b94a
                 if ((cmd == GF_DEFRAG_CMD_STATUS) ||
17b94a
                     (cmd == GF_DEFRAG_CMD_STATUS_TIER) ||
17b94a
                     (cmd == GF_DEFRAG_CMD_DETACH_STATUS))
17b94a
-                	gf_defrag_status_get(conf, output, _gf_false);
17b94a
+                    gf_defrag_status_get(conf, output, _gf_false);
17b94a
                 else if (cmd == GF_DEFRAG_CMD_START_DETACH_TIER)
17b94a
                     gf_defrag_start_detach_tier(defrag);
17b94a
                 else if (cmd == GF_DEFRAG_CMD_DETACH_START)
17b94a
diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c
17b94a
index f5dfff9..f4e17d1 100644
17b94a
--- a/xlators/cluster/dht/src/dht-selfheal.c
17b94a
+++ b/xlators/cluster/dht/src/dht-selfheal.c
17b94a
@@ -2097,9 +2097,18 @@ dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
17b94a
     local->selfheal.dir_cbk = dir_cbk;
17b94a
     local->selfheal.layout = dht_layout_ref(this, layout);
17b94a
 
17b94a
-    if (local->need_attrheal && !IA_ISINVAL(local->mds_stbuf.ia_type)) {
17b94a
-        /*Use the one in the mds_stbuf*/
17b94a
-        local->stbuf = local->mds_stbuf;
17b94a
+    if (local->need_attrheal) {
17b94a
+        if (__is_root_gfid(local->stbuf.ia_gfid)) {
17b94a
+            local->stbuf.ia_gid = local->prebuf.ia_gid;
17b94a
+            local->stbuf.ia_uid = local->prebuf.ia_uid;
17b94a
+
17b94a
+            local->stbuf.ia_ctime = local->prebuf.ia_ctime;
17b94a
+            local->stbuf.ia_ctime_nsec = local->prebuf.ia_ctime_nsec;
17b94a
+            local->stbuf.ia_prot = local->prebuf.ia_prot;
17b94a
+
17b94a
+        } else if (!IA_ISINVAL(local->mds_stbuf.ia_type)) {
17b94a
+            local->stbuf = local->mds_stbuf;
17b94a
+        }
17b94a
     }
17b94a
 
17b94a
     if (!__is_root_gfid(local->stbuf.ia_gfid)) {
17b94a
diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c
17b94a
index c5a43a1..e5c6e62 100644
17b94a
--- a/xlators/storage/posix/src/posix-common.c
17b94a
+++ b/xlators/storage/posix/src/posix-common.c
17b94a
@@ -598,6 +598,7 @@ posix_init(xlator_t *this)
17b94a
     int force_directory = -1;
17b94a
     int create_mask = -1;
17b94a
     int create_directory_mask = -1;
17b94a
+    char value;
17b94a
 
17b94a
     dir_data = dict_get(this->options, "directory");
17b94a
 
17b94a
@@ -654,16 +655,11 @@ posix_init(xlator_t *this)
17b94a
     }
17b94a
 
17b94a
     /* Check for Extended attribute support, if not present, log it */
17b94a
-    op_ret = sys_lsetxattr(dir_data->data, "trusted.glusterfs.test", "working",
17b94a
-                           8, 0);
17b94a
-    if (op_ret != -1) {
17b94a
-        ret = sys_lremovexattr(dir_data->data, "trusted.glusterfs.test");
17b94a
-        if (ret) {
17b94a
-            gf_msg(this->name, GF_LOG_DEBUG, errno, P_MSG_INVALID_OPTION,
17b94a
-                   "failed to remove xattr: "
17b94a
-                   "trusted.glusterfs.test");
17b94a
-        }
17b94a
-    } else {
17b94a
+    size = sys_lgetxattr(dir_data->data, "user.x", &value, sizeof(value));
17b94a
+
17b94a
+    if ((size == -1) && (errno == EOPNOTSUPP)) {
17b94a
+        gf_msg(this->name, GF_LOG_DEBUG, 0, P_MSG_XDATA_GETXATTR,
17b94a
+               "getxattr returned %zd", size);
17b94a
         tmp_data = dict_get(this->options, "mandate-attribute");
17b94a
         if (tmp_data) {
17b94a
             if (gf_string2boolean(tmp_data->data, &tmp_bool) == -1) {
17b94a
-- 
17b94a
1.8.3.1
17b94a