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