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