d1681e
From 9a95de08eb49f10c0a342099826d5e4c445749aa Mon Sep 17 00:00:00 2001
d1681e
From: Mohit Agrawal <moagrawa@redhat.com>
d1681e
Date: Thu, 31 May 2018 12:29:35 +0530
d1681e
Subject: [PATCH 313/325] dht: Inconsistent permission for directories after
d1681e
 brick stop/start
d1681e
d1681e
Problem: Inconsistent access permissions on directories after
d1681e
         bringing back the down sub-volumes, in case of directories dht_setattr
d1681e
         first wind a call on MDS once call is finished on MDS then wind a call
d1681e
         on NON-MDS.At the time of revalidating dht just compare the uid/gid with
d1681e
         stbuf uid/gid and if anyone differs set a flag to heal the same.
d1681e
d1681e
Solution: Add a condition to compare permission also in dht_revalidate_cbk
d1681e
          to set a flag to call dht_dir_attr_heal.
d1681e
d1681e
> BUG: 1584517
d1681e
> Change-Id: I3e039607148005015b5d93364536158380d4c5aa
d1681e
> fixes: bz#1584517
d1681e
> (cherry picked from commit e57cbae0bcc3d8649b869eda5ec20f3c6a6d34f0)
d1681e
> (Reviewed on upstream link https://review.gluster.org/#/c/20108/)
d1681e
d1681e
BUG: 1582066
d1681e
Change-Id: I985445521aeeddce52c0a56c20287e523aa3398b
d1681e
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/143721
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d1681e
---
d1681e
 tests/bugs/bug-1584517.t               | 70 +++++++++++++++++++++++++++++
d1681e
 xlators/cluster/dht/src/dht-common.c   | 81 ++++++++++++++++++++++++++++++----
d1681e
 xlators/cluster/dht/src/dht-common.h   |  3 ++
d1681e
 xlators/cluster/dht/src/dht-selfheal.c |  2 +-
d1681e
 4 files changed, 147 insertions(+), 9 deletions(-)
d1681e
 create mode 100644 tests/bugs/bug-1584517.t
d1681e
d1681e
diff --git a/tests/bugs/bug-1584517.t b/tests/bugs/bug-1584517.t
d1681e
new file mode 100644
d1681e
index 0000000..7f48015
d1681e
--- /dev/null
d1681e
+++ b/tests/bugs/bug-1584517.t
d1681e
@@ -0,0 +1,70 @@
d1681e
+#!/bin/bash
d1681e
+. $(dirname $0)/../include.rc
d1681e
+. $(dirname $0)/../volume.rc
d1681e
+. $(dirname $0)/../dht.rc
d1681e
+cleanup;
d1681e
+#This test case verifies attributes (uid/gid/perm) for the
d1681e
+#directory are healed after stop/start brick. To verify the same
d1681e
+#test case change attributes of the directory after down a DHT subvolume
d1681e
+#and one AFR children. After start the volume with force and run lookup
d1681e
+#operation attributes should be healed on started bricks at the backend.
d1681e
+
d1681e
+
d1681e
+TEST glusterd
d1681e
+TEST pidof glusterd
d1681e
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2,3,4,5}
d1681e
+TEST $CLI volume start $V0
d1681e
+TEST useradd dev -M
d1681e
+TEST groupadd QA
d1681e
+
d1681e
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0;
d1681e
+
d1681e
+TEST mkdir $M0/dironedown
d1681e
+
d1681e
+TEST kill_brick $V0 $H0 $B0/${V0}2
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} "5" online_brick_count
d1681e
+
d1681e
+TEST kill_brick $V0 $H0 $B0/${V0}3
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} "4" online_brick_count
d1681e
+
d1681e
+TEST kill_brick $V0 $H0 $B0/${V0}4
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} "3" online_brick_count
d1681e
+
d1681e
+TEST kill_brick $V0 $H0 $B0/${V0}5
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} "2" online_brick_count
d1681e
+
d1681e
+TEST chown dev $M0/dironedown
d1681e
+TEST chgrp QA $M0/dironedown
d1681e
+TEST chmod 777 $M0/dironedown
d1681e
+
d1681e
+#store the permissions for comparision
d1681e
+permission_onedown=`ls -l $M0 | grep dironedown | awk '{print $1}'`
d1681e
+
d1681e
+TEST $CLI volume start $V0 force
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} "6" online_brick_count
d1681e
+
d1681e
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0;
d1681e
+
d1681e
+#Run lookup two times to hit revalidate code path in dht
d1681e
+# to heal user attr
d1681e
+
d1681e
+TEST ls $M0/dironedown
d1681e
+
d1681e
+#check attributes those were created post brick going down
d1681e
+TEST brick_perm=`ls -l $B0/${V0}3 | grep dironedown | awk '{print $1}'`
d1681e
+TEST echo $brick_perm
d1681e
+TEST [ ${brick_perm} = ${permission_onedown} ]
d1681e
+uid=`ls -l $B0/${V0}3 | grep dironedown | awk '{print $3}'`
d1681e
+TEST echo $uid
d1681e
+TEST [ $uid = dev ]
d1681e
+gid=`ls -l $B0/${V0}3 | grep dironedown | awk '{print $4}'`
d1681e
+TEST echo $gid
d1681e
+TEST [ $gid = QA ]
d1681e
+
d1681e
+TEST umount $M0
d1681e
+userdel --force dev
d1681e
+groupdel QA
d1681e
+
d1681e
+cleanup
d1681e
+exit
d1681e
+
d1681e
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
d1681e
index c6adce4..23049b6 100644
d1681e
--- a/xlators/cluster/dht/src/dht-common.c
d1681e
+++ b/xlators/cluster/dht/src/dht-common.c
d1681e
@@ -1329,6 +1329,8 @@ dht_lookup_dir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
d1681e
         char          gfid_local[GF_UUID_BUF_SIZE] = {0};
d1681e
         char          gfid_node[GF_UUID_BUF_SIZE]  = {0};
d1681e
         int32_t       mds_xattr_val[1]                 = {0};
d1681e
+        call_frame_t *copy                         = NULL;
d1681e
+        dht_local_t  *copy_local                   = NULL;
d1681e
 
d1681e
         GF_VALIDATE_OR_GOTO ("dht", frame, out);
d1681e
         GF_VALIDATE_OR_GOTO ("dht", this, out);
d1681e
@@ -1401,6 +1403,23 @@ dht_lookup_dir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
d1681e
                         dht_aggregate_xattr (local->xattr, xattr);
d1681e
                 }
d1681e
 
d1681e
+                if (dict_get (xattr, conf->mds_xattr_key)) {
d1681e
+                        local->mds_subvol  = prev;
d1681e
+                        local->mds_stbuf.ia_gid = stbuf->ia_gid;
d1681e
+                        local->mds_stbuf.ia_uid = stbuf->ia_uid;
d1681e
+                        local->mds_stbuf.ia_prot = stbuf->ia_prot;
d1681e
+                }
d1681e
+
d1681e
+                if (local->stbuf.ia_type != IA_INVAL) {
d1681e
+                        if (!__is_root_gfid (stbuf->ia_gfid) &&
d1681e
+                            ((local->stbuf.ia_gid != stbuf->ia_gid) ||
d1681e
+                            (local->stbuf.ia_uid != stbuf->ia_uid) ||
d1681e
+                            (is_permission_different (&local->stbuf.ia_prot,
d1681e
+                                                      &stbuf->ia_prot)))) {
d1681e
+                                local->need_attrheal = 1;
d1681e
+                        }
d1681e
+                }
d1681e
+
d1681e
                 if (local->inode == NULL)
d1681e
                         local->inode = inode_ref (inode);
d1681e
 
d1681e
@@ -1496,6 +1515,43 @@ unlock:
d1681e
                                                    &local->postparent, 1);
d1681e
                 }
d1681e
 
d1681e
+                if (local->need_attrheal) {
d1681e
+                        local->need_attrheal = 0;
d1681e
+                        if (!__is_root_gfid (inode->gfid)) {
d1681e
+                                gf_uuid_copy (local->gfid, local->mds_stbuf.ia_gfid);
d1681e
+                                local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
d1681e
+                                local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
d1681e
+                                local->stbuf.ia_prot = local->mds_stbuf.ia_prot;
d1681e
+                        }
d1681e
+                        copy = create_frame (this, this->ctx->pool);
d1681e
+                        if (copy) {
d1681e
+                                copy_local = dht_local_init (copy, &local->loc,
d1681e
+                                                             NULL, 0);
d1681e
+                                if (!copy_local) {
d1681e
+                                        DHT_STACK_DESTROY (copy);
d1681e
+                                        goto skip_attr_heal;
d1681e
+                                }
d1681e
+                                copy_local->stbuf = local->stbuf;
d1681e
+                                copy_local->mds_stbuf = local->mds_stbuf;
d1681e
+                                copy_local->mds_subvol = local->mds_subvol;
d1681e
+                                copy->local = copy_local;
d1681e
+                                FRAME_SU_DO (copy, dht_local_t);
d1681e
+                                ret = synctask_new (this->ctx->env,
d1681e
+                                                    dht_dir_attr_heal,
d1681e
+                                                    dht_dir_attr_heal_done,
d1681e
+                                                    copy, copy);
d1681e
+                                if (ret) {
d1681e
+                                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
d1681e
+                                                DHT_MSG_DIR_ATTR_HEAL_FAILED,
d1681e
+                                                "Synctask creation failed to heal attr "
d1681e
+                                                "for path %s gfid %s ",
d1681e
+                                                local->loc.path, local->gfid);
d1681e
+                                        DHT_STACK_DESTROY (copy);
d1681e
+                                }
d1681e
+                        }
d1681e
+                }
d1681e
+
d1681e
+skip_attr_heal:
d1681e
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
d1681e
                 dht_set_fixed_dir_stat (&local->postparent);
d1681e
                 /* Delete mds xattr at the time of STACK UNWIND */
d1681e
@@ -1516,7 +1572,7 @@ out:
d1681e
         return ret;
d1681e
 }
d1681e
 
d1681e
-int static
d1681e
+int
d1681e
 is_permission_different (ia_prot_t *prot1, ia_prot_t *prot2)
d1681e
 {
d1681e
         if ((prot1->owner.read != prot2->owner.read) ||
d1681e
@@ -1677,12 +1733,12 @@ dht_revalidate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
d1681e
                         {
d1681e
                                 if ((local->stbuf.ia_gid != stbuf->ia_gid) ||
d1681e
                                     (local->stbuf.ia_uid != stbuf->ia_uid) ||
d1681e
-                                    (__is_root_gfid (stbuf->ia_gfid) &&
d1681e
                                      is_permission_different (&local->stbuf.ia_prot,
d1681e
-                                                              &stbuf->ia_prot))) {
d1681e
+                                                              &stbuf->ia_prot)) {
d1681e
                                         local->need_selfheal = 1;
d1681e
                                 }
d1681e
                         }
d1681e
+
d1681e
                         if (!dict_get (xattr, conf->mds_xattr_key)) {
d1681e
                                 gf_msg_debug (this->name, 0,
d1681e
                                               "internal xattr %s is not present"
d1681e
@@ -1828,10 +1884,9 @@ out:
d1681e
                         local->need_selfheal = 0;
d1681e
                         if (!__is_root_gfid (inode->gfid)) {
d1681e
                                 gf_uuid_copy (local->gfid, local->mds_stbuf.ia_gfid);
d1681e
-                                if (local->mds_stbuf.ia_gid || local->mds_stbuf.ia_uid) {
d1681e
-                                        local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
d1681e
-                                        local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
d1681e
-                                }
d1681e
+                                local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
d1681e
+                                local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
d1681e
+                                local->stbuf.ia_prot = local->mds_stbuf.ia_prot;
d1681e
                         } else {
d1681e
                                 gf_uuid_copy (local->gfid, local->stbuf.ia_gfid);
d1681e
                                 local->stbuf.ia_gid = local->prebuf.ia_gid;
d1681e
@@ -1843,8 +1898,10 @@ out:
d1681e
                         if (copy) {
d1681e
                                 copy_local = dht_local_init (copy, &local->loc,
d1681e
                                                              NULL, 0);
d1681e
-                                if (!copy_local)
d1681e
+                                if (!copy_local) {
d1681e
+                                        DHT_STACK_DESTROY (copy);
d1681e
                                         goto cont;
d1681e
+                                }
d1681e
                                 copy_local->stbuf = local->stbuf;
d1681e
                                 copy_local->mds_stbuf = local->mds_stbuf;
d1681e
                                 copy_local->mds_subvol = local->mds_subvol;
d1681e
@@ -1854,6 +1911,14 @@ out:
d1681e
                                                     dht_dir_attr_heal,
d1681e
                                                     dht_dir_attr_heal_done,
d1681e
                                                     copy, copy);
d1681e
+                                if (ret) {
d1681e
+                                        gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
d1681e
+                                                DHT_MSG_DIR_ATTR_HEAL_FAILED,
d1681e
+                                                "Synctask creation failed to heal attr "
d1681e
+                                                "for path %s gfid %s ",
d1681e
+                                                local->loc.path, local->gfid);
d1681e
+                                        DHT_STACK_DESTROY (copy);
d1681e
+                                }
d1681e
                         }
d1681e
                 }
d1681e
 cont:
d1681e
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
d1681e
index a70342f..b40815c 100644
d1681e
--- a/xlators/cluster/dht/src/dht-common.h
d1681e
+++ b/xlators/cluster/dht/src/dht-common.h
d1681e
@@ -298,6 +298,7 @@ struct dht_local {
d1681e
         xlator_t                *mds_subvol; /* This is use for dir only */
d1681e
         char                     need_selfheal;
d1681e
         char                     need_xattr_heal;
d1681e
+        char                     need_attrheal;
d1681e
         int                      file_count;
d1681e
         int                      dir_count;
d1681e
         call_frame_t            *main_frame;
d1681e
@@ -1491,4 +1492,6 @@ int
d1681e
 dht_selfheal_dir_setattr (call_frame_t *frame, loc_t *loc, struct iatt *stbuf,
d1681e
                           int32_t valid, dht_layout_t *layout);
d1681e
 
d1681e
+int
d1681e
+is_permission_different (ia_prot_t *prot1, ia_prot_t *prot2);
d1681e
 #endif/* _DHT_H */
d1681e
diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c
d1681e
index e9b1db9..035a709 100644
d1681e
--- a/xlators/cluster/dht/src/dht-selfheal.c
d1681e
+++ b/xlators/cluster/dht/src/dht-selfheal.c
d1681e
@@ -2495,7 +2495,7 @@ dht_dir_attr_heal (void *data)
d1681e
                                               NULL, NULL, NULL, NULL);
d1681e
                 } else {
d1681e
                         ret = syncop_setattr (subvol, &local->loc, &local->mds_stbuf,
d1681e
-                                              (GF_SET_ATTR_UID | GF_SET_ATTR_GID),
d1681e
+                                              (GF_SET_ATTR_UID | GF_SET_ATTR_GID | GF_SET_ATTR_MODE),
d1681e
                                               NULL, NULL, NULL, NULL);
d1681e
                 }
d1681e
 
d1681e
-- 
d1681e
1.8.3.1
d1681e