50dc83
From 6565749c95e90f360a994bde1416cffd22cd8ce9 Mon Sep 17 00:00:00 2001
50dc83
From: N Balachandran <nbalacha@redhat.com>
50dc83
Date: Mon, 25 Mar 2019 15:56:56 +0530
50dc83
Subject: [PATCH 126/141] cluster/dht: refactor dht lookup functions
50dc83
50dc83
Part 1:  refactor the dht_lookup_dir_cbk
50dc83
and dht_selfheal_directory functions.
50dc83
Added a simple dht selfheal directory test
50dc83
50dc83
upstream: https://review.gluster.org/#/c/glusterfs/+/22407/
50dc83
> Change-Id: I1410c26359e3c14b396adbe751937a52bd2fcff9
50dc83
> updates: bz#1590385
50dc83
50dc83
Change-Id: Idd0a7df7122d634c371ecf30c0dbb94dc6063416
50dc83
BUG: 1703897
50dc83
Signed-off-by: N Balachandran <nbalacha@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/169037
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Susant Palai <spalai@redhat.com>
50dc83
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
50dc83
---
50dc83
 tests/basic/distribute/dir-heal.t      | 145 +++++++++++++++++++++++++++
50dc83
 xlators/cluster/dht/src/dht-common.c   | 178 +++++++++++++++------------------
50dc83
 xlators/cluster/dht/src/dht-selfheal.c |  65 +++++++-----
50dc83
 3 files changed, 264 insertions(+), 124 deletions(-)
50dc83
 create mode 100644 tests/basic/distribute/dir-heal.t
50dc83
50dc83
diff --git a/tests/basic/distribute/dir-heal.t b/tests/basic/distribute/dir-heal.t
50dc83
new file mode 100644
50dc83
index 0000000..851f765
50dc83
--- /dev/null
50dc83
+++ b/tests/basic/distribute/dir-heal.t
50dc83
@@ -0,0 +1,145 @@
50dc83
+#!/bin/bash
50dc83
+
50dc83
+. $(dirname $0)/../../include.rc
50dc83
+. $(dirname $0)/../../volume.rc
50dc83
+. $(dirname $0)/../../nfs.rc
50dc83
+. $(dirname $0)/../../common-utils.rc
50dc83
+
50dc83
+# Test 1 overview:
50dc83
+# ----------------
50dc83
+#
50dc83
+# 1. Kill one brick of the volume.
50dc83
+# 2. Create directories and change directory properties.
50dc83
+# 3. Bring up the brick and access the directory
50dc83
+# 4. Check the permissions and xattrs on the backend
50dc83
+
50dc83
+cleanup
50dc83
+
50dc83
+TEST glusterd
50dc83
+TEST pidof glusterd
50dc83
+
50dc83
+TEST $CLI volume create $V0 $H0:$B0/$V0-{1..3}
50dc83
+TEST $CLI volume start $V0
50dc83
+
50dc83
+# We want the lookup to reach DHT
50dc83
+TEST $CLI volume set $V0 performance.stat-prefetch off
50dc83
+
50dc83
+# Mount using FUSE , kill a brick and create directories
50dc83
+TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0
50dc83
+
50dc83
+ls $M0/
50dc83
+cd $M0
50dc83
+
50dc83
+TEST kill_brick $V0 $H0 $B0/$V0-1
50dc83
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "0" brick_up_status $V0 $H0 $B0/$V0-1
50dc83
+
50dc83
+TEST mkdir dir{1..4}
50dc83
+
50dc83
+# No change for dir1
50dc83
+# Change permissions for dir2
50dc83
+# Set xattr on dir3
50dc83
+# Change permissions and set xattr on dir4
50dc83
+
50dc83
+TEST chmod 777 $M0/dir2
50dc83
+
50dc83
+TEST setfattr -n "user.test" -v "test" $M0/dir3
50dc83
+
50dc83
+TEST chmod 777 $M0/dir4
50dc83
+TEST setfattr -n "user.test" -v "test" $M0/dir4
50dc83
+
50dc83
+
50dc83
+# Start all bricks
50dc83
+
50dc83
+TEST $CLI volume start $V0 force
50dc83
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/$V0-1
50dc83
+
50dc83
+#$CLI volume status
50dc83
+
50dc83
+# It takes a while for the client to reconnect to the brick
50dc83
+sleep 5
50dc83
+
50dc83
+stat $M0/dir* > /dev/null
50dc83
+
50dc83
+# Check that directories have been created on the brick that was killed
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir1
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir2
50dc83
+EXPECT "777" stat -c "%a" $B0/$V0-1/dir2
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir3
50dc83
+EXPECT "test" getfattr -n "user.test" --absolute-names --only-values $B0/$V0-1/dir3
50dc83
+
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir4
50dc83
+EXPECT "777" stat -c "%a" $B0/$V0-1/dir4
50dc83
+EXPECT "test" getfattr -n "user.test" --absolute-names --only-values $B0/$V0-1/dir4
50dc83
+
50dc83
+
50dc83
+TEST rm -rf $M0/*
50dc83
+
50dc83
+cd
50dc83
+
50dc83
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
50dc83
+
50dc83
+
50dc83
+# Test 2 overview:
50dc83
+# ----------------
50dc83
+# 1. Create directories with all bricks up.
50dc83
+# 2. Kill a brick and change directory properties and set user xattr.
50dc83
+# 2. Bring up the brick and access the directory
50dc83
+# 3. Check the permissions and xattrs on the backend
50dc83
+
50dc83
+
50dc83
+TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0
50dc83
+
50dc83
+ls $M0/
50dc83
+cd $M0
50dc83
+TEST mkdir dir{1..4}
50dc83
+
50dc83
+TEST kill_brick $V0 $H0 $B0/$V0-1
50dc83
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "0" brick_up_status $V0 $H0 $B0/$V0-1
50dc83
+
50dc83
+# No change for dir1
50dc83
+# Change permissions for dir2
50dc83
+# Set xattr on dir3
50dc83
+# Change permissions and set xattr on dir4
50dc83
+
50dc83
+TEST chmod 777 $M0/dir2
50dc83
+
50dc83
+TEST setfattr -n "user.test" -v "test" $M0/dir3
50dc83
+
50dc83
+TEST chmod 777 $M0/dir4
50dc83
+TEST setfattr -n "user.test" -v "test" $M0/dir4
50dc83
+
50dc83
+
50dc83
+# Start all bricks
50dc83
+
50dc83
+TEST $CLI volume start $V0 force
50dc83
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/$V0-1
50dc83
+
50dc83
+#$CLI volume status
50dc83
+
50dc83
+# It takes a while for the client to reconnect to the brick
50dc83
+sleep 5
50dc83
+
50dc83
+stat $M0/dir* > /dev/null
50dc83
+
50dc83
+# Check directories on the brick that was killed
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir2
50dc83
+EXPECT "777" stat -c "%a" $B0/$V0-1/dir2
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir3
50dc83
+EXPECT "test" getfattr -n "user.test" --absolute-names --only-values $B0/$V0-1/dir3
50dc83
+
50dc83
+
50dc83
+TEST ls $B0/$V0-1/dir4
50dc83
+EXPECT "777" stat -c "%a" $B0/$V0-1/dir4
50dc83
+EXPECT "test" getfattr -n "user.test" --absolute-names --only-values $B0/$V0-1/dir4
50dc83
+cd
50dc83
+
50dc83
+
50dc83
+# Cleanup
50dc83
+cleanup
50dc83
+
50dc83
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
50dc83
index 2a68193..d3e900c 100644
50dc83
--- a/xlators/cluster/dht/src/dht-common.c
50dc83
+++ b/xlators/cluster/dht/src/dht-common.c
50dc83
@@ -801,9 +801,8 @@ dht_common_mark_mdsxattr(call_frame_t *frame, int *errst,
50dc83
     call_frame_t *xattr_frame = NULL;
50dc83
     gf_boolean_t vol_down = _gf_false;
50dc83
 
50dc83
-    this = frame->this;
50dc83
-
50dc83
     GF_VALIDATE_OR_GOTO("dht", frame, out);
50dc83
+    this = frame->this;
50dc83
     GF_VALIDATE_OR_GOTO("dht", this, out);
50dc83
     GF_VALIDATE_OR_GOTO(this->name, frame->local, out);
50dc83
     GF_VALIDATE_OR_GOTO(this->name, this->private, out);
50dc83
@@ -812,6 +811,7 @@ dht_common_mark_mdsxattr(call_frame_t *frame, int *errst,
50dc83
     conf = this->private;
50dc83
     layout = local->selfheal.layout;
50dc83
     local->mds_heal_fresh_lookup = mark_during_fresh_lookup;
50dc83
+
50dc83
     gf_uuid_unparse(local->gfid, gfid_local);
50dc83
 
50dc83
     /* Code to update hashed subvol consider as a mds subvol
50dc83
@@ -1240,6 +1240,31 @@ out:
50dc83
 }
50dc83
 
50dc83
 int
50dc83
+dht_needs_selfheal(call_frame_t *frame, xlator_t *this)
50dc83
+{
50dc83
+    dht_local_t *local = NULL;
50dc83
+    dht_layout_t *layout = NULL;
50dc83
+    int needs_selfheal = 0;
50dc83
+    int ret = 0;
50dc83
+
50dc83
+    local = frame->local;
50dc83
+    layout = local->layout;
50dc83
+
50dc83
+    if (local->need_attrheal || local->need_xattr_heal ||
50dc83
+        local->need_selfheal) {
50dc83
+        needs_selfheal = 1;
50dc83
+    }
50dc83
+
50dc83
+    ret = dht_layout_normalize(this, &local->loc, layout);
50dc83
+
50dc83
+    if (ret != 0) {
50dc83
+        gf_msg_debug(this->name, 0, "fixing assignment on %s", local->loc.path);
50dc83
+        needs_selfheal = 1;
50dc83
+    }
50dc83
+    return needs_selfheal;
50dc83
+}
50dc83
+
50dc83
+int
50dc83
 dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
                    int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf,
50dc83
                    dict_t *xattr, struct iatt *postparent)
50dc83
@@ -1256,8 +1281,6 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
     char gfid_local[GF_UUID_BUF_SIZE] = {0};
50dc83
     char gfid_node[GF_UUID_BUF_SIZE] = {0};
50dc83
     int32_t mds_xattr_val[1] = {0};
50dc83
-    call_frame_t *copy = NULL;
50dc83
-    dht_local_t *copy_local = NULL;
50dc83
 
50dc83
     GF_VALIDATE_OR_GOTO("dht", frame, out);
50dc83
     GF_VALIDATE_OR_GOTO("dht", this, out);
50dc83
@@ -1270,7 +1293,11 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
     conf = this->private;
50dc83
 
50dc83
     layout = local->layout;
50dc83
+    gf_msg_debug(this->name, op_errno,
50dc83
+                 "%s: lookup on %s returned with op_ret = %d, op_errno = %d",
50dc83
+                 local->loc.path, prev->name, op_ret, op_errno);
50dc83
 
50dc83
+    /* The first successful lookup*/
50dc83
     if (!op_ret && gf_uuid_is_null(local->gfid)) {
50dc83
         memcpy(local->gfid, stbuf->ia_gfid, 16);
50dc83
     }
50dc83
@@ -1298,13 +1325,10 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
 
50dc83
         if (op_ret == -1) {
50dc83
             local->op_errno = op_errno;
50dc83
-            gf_msg_debug(this->name, op_errno,
50dc83
-                         "%s: lookup on %s returned error", local->loc.path,
50dc83
-                         prev->name);
50dc83
 
50dc83
             /* The GFID is missing on this subvol. Force a heal. */
50dc83
             if (op_errno == ENODATA) {
50dc83
-                local->need_selfheal = 1;
50dc83
+                local->need_lookup_everywhere = 1;
50dc83
             }
50dc83
             goto unlock;
50dc83
         }
50dc83
@@ -1312,12 +1336,11 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
         is_dir = check_is_dir(inode, stbuf, xattr);
50dc83
         if (!is_dir) {
50dc83
             gf_msg_debug(this->name, 0,
50dc83
-                         "lookup of %s on %s returned non"
50dc83
-                         "dir 0%o"
50dc83
+                         "%s: lookup on %s returned non dir 0%o"
50dc83
                          "calling lookup_everywhere",
50dc83
                          local->loc.path, prev->name, stbuf->ia_type);
50dc83
 
50dc83
-            local->need_selfheal = 1;
50dc83
+            local->need_lookup_everywhere = 1;
50dc83
             goto unlock;
50dc83
         }
50dc83
 
50dc83
@@ -1328,14 +1351,8 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
             dht_aggregate_xattr(local->xattr, xattr);
50dc83
         }
50dc83
 
50dc83
-        if (dict_get(xattr, conf->mds_xattr_key)) {
50dc83
-            local->mds_subvol = prev;
50dc83
-            local->mds_stbuf.ia_gid = stbuf->ia_gid;
50dc83
-            local->mds_stbuf.ia_uid = stbuf->ia_uid;
50dc83
-            local->mds_stbuf.ia_prot = stbuf->ia_prot;
50dc83
-        }
50dc83
-
50dc83
         if (local->stbuf.ia_type != IA_INVAL) {
50dc83
+            /* This is not the first subvol to respond */
50dc83
             if (!__is_root_gfid(stbuf->ia_gfid) &&
50dc83
                 ((local->stbuf.ia_gid != stbuf->ia_gid) ||
50dc83
                  (local->stbuf.ia_uid != stbuf->ia_uid) ||
50dc83
@@ -1348,65 +1365,64 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
50dc83
         if (local->inode == NULL)
50dc83
             local->inode = inode_ref(inode);
50dc83
 
50dc83
+        /* This could be a problem */
50dc83
         dht_iatt_merge(this, &local->stbuf, stbuf);
50dc83
         dht_iatt_merge(this, &local->postparent, postparent);
50dc83
 
50dc83
         if (!dict_get(xattr, conf->mds_xattr_key)) {
50dc83
             gf_msg_debug(this->name, 0,
50dc83
-                         "Internal xattr %s is not present "
50dc83
-                         " on path %s gfid is %s ",
50dc83
-                         conf->mds_xattr_key, local->loc.path, gfid_local);
50dc83
+                         "%s: mds xattr %s is not present "
50dc83
+                         "on %s(gfid = %s)",
50dc83
+                         local->loc.path, conf->mds_xattr_key, prev->name,
50dc83
+                         gfid_local);
50dc83
             goto unlock;
50dc83
-        } else {
50dc83
-            /* Save mds subvol on inode ctx */
50dc83
-            ret = dht_inode_ctx_mdsvol_set(local->inode, this, prev);
50dc83
-            if (ret) {
50dc83
-                gf_msg(this->name, GF_LOG_ERROR, 0,
50dc83
-                       DHT_MSG_SET_INODE_CTX_FAILED,
50dc83
-                       "Failed to set hashed subvol for %s vol is %s",
50dc83
-                       local->loc.path, prev->name);
50dc83
-            }
50dc83
+        }
50dc83
+
50dc83
+        local->mds_subvol = prev;
50dc83
+        local->mds_stbuf = *stbuf;
50dc83
+
50dc83
+        /* Save mds subvol on inode ctx */
50dc83
+
50dc83
+        ret = dht_inode_ctx_mdsvol_set(local->inode, this, prev);
50dc83
+        if (ret) {
50dc83
+            gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_SET_INODE_CTX_FAILED,
50dc83
+                   "%s: Failed to set mds (%s)", local->loc.path, prev->name);
50dc83
         }
50dc83
         check_mds = dht_dict_get_array(xattr, conf->mds_xattr_key,
50dc83
                                        mds_xattr_val, 1, &errst);
50dc83
         if ((check_mds < 0) && !errst) {
50dc83
             local->mds_xattr = dict_ref(xattr);
50dc83
             gf_msg_debug(this->name, 0,
50dc83
-                         "Value of %s is not zero on hashed subvol "
50dc83
-                         "so xattr needs to be heal on non hashed"
50dc83
-                         " path is %s and vol name is %s "
50dc83
-                         " gfid is %s",
50dc83
-                         conf->mds_xattr_key, local->loc.path, prev->name,
50dc83
+                         "%s: %s is not zero on %s. Xattrs need to be healed."
50dc83
+                         "(gfid = %s)",
50dc83
+                         local->loc.path, conf->mds_xattr_key, prev->name,
50dc83
                          gfid_local);
50dc83
             local->need_xattr_heal = 1;
50dc83
-            local->mds_subvol = prev;
50dc83
         }
50dc83
     }
50dc83
+
50dc83
 unlock:
50dc83
     UNLOCK(&frame->lock);
50dc83
 
50dc83
     this_call_cnt = dht_frame_return(frame);
50dc83
 
50dc83
     if (is_last_call(this_call_cnt)) {
50dc83
+        /* If the mds subvol is not set correctly*/
50dc83
+        if (!__is_root_gfid(local->gfid) &&
50dc83
+            (!dict_get(local->xattr, conf->mds_xattr_key))) {
50dc83
+            local->need_selfheal = 1;
50dc83
+        }
50dc83
+
50dc83
         /* No need to call xattr heal code if volume count is 1
50dc83
          */
50dc83
-        if (conf->subvolume_cnt == 1)
50dc83
+        if (conf->subvolume_cnt == 1) {
50dc83
             local->need_xattr_heal = 0;
50dc83
-
50dc83
-        /* Code to update all extended attributed from hashed subvol
50dc83
-           to local->xattr
50dc83
-        */
50dc83
-        if (local->need_xattr_heal && (local->mds_xattr)) {
50dc83
-            dht_dir_set_heal_xattr(this, local, local->xattr, local->mds_xattr,
50dc83
-                                   NULL, NULL);
50dc83
-            dict_unref(local->mds_xattr);
50dc83
-            local->mds_xattr = NULL;
50dc83
         }
50dc83
 
50dc83
-        if (local->need_selfheal) {
50dc83
-            local->need_selfheal = 0;
50dc83
+        if (local->need_selfheal || local->need_lookup_everywhere) {
50dc83
             /* Set the gfid-req so posix will set the GFID*/
50dc83
             if (!gf_uuid_is_null(local->gfid)) {
50dc83
+                /* Ok, this should _never_ happen */
50dc83
                 ret = dict_set_static_bin(local->xattr_req, "gfid-req",
50dc83
                                           local->gfid, 16);
50dc83
             } else {
50dc83
@@ -1414,73 +1430,36 @@ unlock:
50dc83
                     ret = dict_set_static_bin(local->xattr_req, "gfid-req",
50dc83
                                               local->gfid_req, 16);
50dc83
             }
50dc83
+        }
50dc83
+
50dc83
+        if (local->need_lookup_everywhere) {
50dc83
+            local->need_lookup_everywhere = 0;
50dc83
             dht_lookup_everywhere(frame, this, &local->loc);
50dc83
             return 0;
50dc83
         }
50dc83
 
50dc83
         if (local->op_ret == 0) {
50dc83
-            ret = dht_layout_normalize(this, &local->loc, layout);
50dc83
-
50dc83
-            if (ret != 0) {
50dc83
-                gf_msg_debug(this->name, 0, "fixing assignment on %s",
50dc83
-                             local->loc.path);
50dc83
+            if (dht_needs_selfheal(frame, this)) {
50dc83
                 goto selfheal;
50dc83
             }
50dc83
 
50dc83
             dht_layout_set(this, local->inode, layout);
50dc83
-            if (!dict_get(local->xattr, conf->mds_xattr_key) ||
50dc83
-                local->need_xattr_heal)
50dc83
-                goto selfheal;
50dc83
-        }
50dc83
-
50dc83
-        if (local->inode) {
50dc83
-            dht_inode_ctx_time_update(local->inode, this, &local->stbuf, 1);
50dc83
-        }
50dc83
-
50dc83
-        if (local->loc.parent) {
50dc83
-            dht_inode_ctx_time_update(local->loc.parent, this,
50dc83
-                                      &local->postparent, 1);
50dc83
-        }
50dc83
-
50dc83
-        if (local->need_attrheal) {
50dc83
-            local->need_attrheal = 0;
50dc83
-            if (!__is_root_gfid(inode->gfid)) {
50dc83
-                local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
50dc83
-                local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
50dc83
-                local->stbuf.ia_prot = local->mds_stbuf.ia_prot;
50dc83
+            if (local->inode) {
50dc83
+                dht_inode_ctx_time_update(local->inode, this, &local->stbuf, 1);
50dc83
             }
50dc83
-            copy = create_frame(this, this->ctx->pool);
50dc83
-            if (copy) {
50dc83
-                copy_local = dht_local_init(copy, &local->loc, NULL, 0);
50dc83
-                if (!copy_local) {
50dc83
-                    DHT_STACK_DESTROY(copy);
50dc83
-                    goto skip_attr_heal;
50dc83
-                }
50dc83
-                copy_local->stbuf = local->stbuf;
50dc83
-                gf_uuid_copy(copy_local->loc.gfid, local->stbuf.ia_gfid);
50dc83
-                copy_local->mds_stbuf = local->mds_stbuf;
50dc83
-                copy_local->mds_subvol = local->mds_subvol;
50dc83
-                copy->local = copy_local;
50dc83
-                FRAME_SU_DO(copy, dht_local_t);
50dc83
-                ret = synctask_new(this->ctx->env, dht_dir_attr_heal,
50dc83
-                                   dht_dir_attr_heal_done, copy, copy);
50dc83
-                if (ret) {
50dc83
-                    gf_msg(this->name, GF_LOG_ERROR, ENOMEM,
50dc83
-                           DHT_MSG_DIR_ATTR_HEAL_FAILED,
50dc83
-                           "Synctask creation failed to heal attr "
50dc83
-                           "for path %s gfid %s ",
50dc83
-                           local->loc.path, local->gfid);
50dc83
-                    DHT_STACK_DESTROY(copy);
50dc83
-                }
50dc83
+
50dc83
+            if (local->loc.parent) {
50dc83
+                dht_inode_ctx_time_update(local->loc.parent, this,
50dc83
+                                          &local->postparent, 1);
50dc83
             }
50dc83
         }
50dc83
 
50dc83
-    skip_attr_heal:
50dc83
         DHT_STRIP_PHASE1_FLAGS(&local->stbuf);
50dc83
         dht_set_fixed_dir_stat(&local->postparent);
50dc83
         /* Delete mds xattr at the time of STACK UNWIND */
50dc83
         if (local->xattr)
50dc83
             GF_REMOVE_INTERNAL_XATTR(conf->mds_xattr_key, local->xattr);
50dc83
+
50dc83
         DHT_STACK_UNWIND(lookup, frame, local->op_ret, local->op_errno,
50dc83
                          local->inode, &local->stbuf, local->xattr,
50dc83
                          &local->postparent);
50dc83
@@ -5444,9 +5423,8 @@ dht_dir_common_set_remove_xattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
50dc83
         } else {
50dc83
             gf_msg(this->name, GF_LOG_ERROR, 0,
50dc83
                    DHT_MSG_HASHED_SUBVOL_GET_FAILED,
50dc83
-                   "Failed to get mds subvol for path %s"
50dc83
-                   "gfid is %s ",
50dc83
-                   loc->path, gfid_local);
50dc83
+                   "%s: Failed to get mds subvol. (gfid is %s)", loc->path,
50dc83
+                   gfid_local);
50dc83
         }
50dc83
         (*op_errno) = ENOENT;
50dc83
         goto err;
50dc83
diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c
50dc83
index bd1b7ea..5420fca 100644
50dc83
--- a/xlators/cluster/dht/src/dht-selfheal.c
50dc83
+++ b/xlators/cluster/dht/src/dht-selfheal.c
50dc83
@@ -1033,18 +1033,27 @@ dht_selfheal_dir_setattr(call_frame_t *frame, loc_t *loc, struct iatt *stbuf,
50dc83
     int missing_attr = 0;
50dc83
     int i = 0, ret = -1;
50dc83
     dht_local_t *local = NULL;
50dc83
+    dht_conf_t *conf = NULL;
50dc83
     xlator_t *this = NULL;
50dc83
     int cnt = 0;
50dc83
 
50dc83
     local = frame->local;
50dc83
     this = frame->this;
50dc83
+    conf = this->private;
50dc83
+
50dc83
+    /* We need to heal the attrs if:
50dc83
+     * 1. Any directories were missing - the newly created dirs will need
50dc83
+     *    to have the correct attrs set
50dc83
+     * 2. An existing dir does not have the correct permissions -they may
50dc83
+     *    have been changed when a brick was down.
50dc83
+     */
50dc83
 
50dc83
     for (i = 0; i < layout->cnt; i++) {
50dc83
         if (layout->list[i].err == -1)
50dc83
             missing_attr++;
50dc83
     }
50dc83
 
50dc83
-    if (missing_attr == 0) {
50dc83
+    if ((missing_attr == 0) && (local->need_attrheal == 0)) {
50dc83
         if (!local->heal_layout) {
50dc83
             gf_msg_trace(this->name, 0, "Skip heal layout for %s gfid = %s ",
50dc83
                          loc->path, uuid_utoa(loc->gfid));
50dc83
@@ -1062,19 +1071,12 @@ dht_selfheal_dir_setattr(call_frame_t *frame, loc_t *loc, struct iatt *stbuf,
50dc83
         return 0;
50dc83
     }
50dc83
 
50dc83
-    local->call_cnt = missing_attr;
50dc83
-    cnt = layout->cnt;
50dc83
+    cnt = local->call_cnt = conf->subvolume_cnt;
50dc83
 
50dc83
     for (i = 0; i < cnt; i++) {
50dc83
-        if (layout->list[i].err == -1) {
50dc83
-            gf_msg_trace(this->name, 0, "%s: setattr on subvol %s, gfid = %s",
50dc83
-                         loc->path, layout->list[i].xlator->name,
50dc83
-                         uuid_utoa(loc->gfid));
50dc83
-
50dc83
-            STACK_WIND(
50dc83
-                frame, dht_selfheal_dir_setattr_cbk, layout->list[i].xlator,
50dc83
-                layout->list[i].xlator->fops->setattr, loc, stbuf, valid, NULL);
50dc83
-        }
50dc83
+        STACK_WIND(frame, dht_selfheal_dir_setattr_cbk, layout->list[i].xlator,
50dc83
+                   layout->list[i].xlator->fops->setattr, loc, stbuf, valid,
50dc83
+                   NULL);
50dc83
     }
50dc83
 
50dc83
     return 0;
50dc83
@@ -1492,6 +1494,9 @@ dht_selfheal_dir_mkdir(call_frame_t *frame, loc_t *loc, dht_layout_t *layout,
50dc83
     }
50dc83
 
50dc83
     if (missing_dirs == 0) {
50dc83
+        /* We don't need to create any directories. Proceed to heal the
50dc83
+         * attrs and xattrs
50dc83
+         */
50dc83
         if (!__is_root_gfid(local->stbuf.ia_gfid)) {
50dc83
             if (local->need_xattr_heal) {
50dc83
                 local->need_xattr_heal = 0;
50dc83
@@ -1499,8 +1504,8 @@ dht_selfheal_dir_mkdir(call_frame_t *frame, loc_t *loc, dht_layout_t *layout,
50dc83
                 if (ret)
50dc83
                     gf_msg(this->name, GF_LOG_ERROR, ret,
50dc83
                            DHT_MSG_DIR_XATTR_HEAL_FAILED,
50dc83
-                           "xattr heal failed for "
50dc83
-                           "directory  %s gfid %s ",
50dc83
+                           "%s:xattr heal failed for "
50dc83
+                           "directory (gfid = %s)",
50dc83
                            local->loc.path, local->gfid);
50dc83
             } else {
50dc83
                 if (!gf_uuid_is_null(local->gfid))
50dc83
@@ -1512,8 +1517,8 @@ dht_selfheal_dir_mkdir(call_frame_t *frame, loc_t *loc, dht_layout_t *layout,
50dc83
 
50dc83
                 gf_msg(this->name, GF_LOG_INFO, 0,
50dc83
                        DHT_MSG_DIR_XATTR_HEAL_FAILED,
50dc83
-                       "Failed to set mds xattr "
50dc83
-                       "for directory  %s gfid %s ",
50dc83
+                       "%s: Failed to set mds xattr "
50dc83
+                       "for directory (gfid = %s)",
50dc83
                        local->loc.path, local->gfid);
50dc83
             }
50dc83
         }
50dc83
@@ -2085,10 +2090,10 @@ dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
50dc83
                        loc_t *loc, dht_layout_t *layout)
50dc83
 {
50dc83
     dht_local_t *local = NULL;
50dc83
+    xlator_t *this = NULL;
50dc83
     uint32_t down = 0;
50dc83
     uint32_t misc = 0;
50dc83
     int ret = 0;
50dc83
-    xlator_t *this = NULL;
50dc83
     char pgfid[GF_UUID_BUF_SIZE] = {0};
50dc83
     char gfid[GF_UUID_BUF_SIZE] = {0};
50dc83
     inode_t *linked_inode = NULL, *inode = NULL;
50dc83
@@ -2099,6 +2104,11 @@ dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
50dc83
     local->selfheal.dir_cbk = dir_cbk;
50dc83
     local->selfheal.layout = dht_layout_ref(this, layout);
50dc83
 
50dc83
+    if (local->need_attrheal && !IA_ISINVAL(local->mds_stbuf.ia_type)) {
50dc83
+        /*Use the one in the mds_stbuf*/
50dc83
+        local->stbuf = local->mds_stbuf;
50dc83
+    }
50dc83
+
50dc83
     if (!__is_root_gfid(local->stbuf.ia_gfid)) {
50dc83
         gf_uuid_unparse(local->stbuf.ia_gfid, gfid);
50dc83
         gf_uuid_unparse(loc->parent->gfid, pgfid);
50dc83
@@ -2118,6 +2128,13 @@ dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
50dc83
         inode_unref(inode);
50dc83
     }
50dc83
 
50dc83
+    if (local->need_xattr_heal && (local->mds_xattr)) {
50dc83
+        dht_dir_set_heal_xattr(this, local, local->xattr, local->mds_xattr,
50dc83
+                               NULL, NULL);
50dc83
+        dict_unref(local->mds_xattr);
50dc83
+        local->mds_xattr = NULL;
50dc83
+    }
50dc83
+
50dc83
     dht_layout_anomalies(this, loc, layout, &local->selfheal.hole_cnt,
50dc83
                          &local->selfheal.overlaps_cnt,
50dc83
                          &local->selfheal.missing_cnt, &local->selfheal.down,
50dc83
@@ -2128,18 +2145,18 @@ dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
50dc83
 
50dc83
     if (down) {
50dc83
         gf_msg(this->name, GF_LOG_WARNING, 0, DHT_MSG_DIR_SELFHEAL_FAILED,
50dc83
-               "Directory selfheal failed: %d subvolumes down."
50dc83
-               "Not fixing. path = %s, gfid = %s",
50dc83
-               down, loc->path, gfid);
50dc83
+               "%s: Directory selfheal failed: %d subvolumes down."
50dc83
+               "Not fixing. gfid = %s",
50dc83
+               loc->path, down, gfid);
50dc83
         ret = 0;
50dc83
         goto sorry_no_fix;
50dc83
     }
50dc83
 
50dc83
     if (misc) {
50dc83
         gf_msg(this->name, GF_LOG_WARNING, 0, DHT_MSG_DIR_SELFHEAL_FAILED,
50dc83
-               "Directory selfheal failed : %d subvolumes "
50dc83
-               "have unrecoverable errors. path = %s, gfid = %s",
50dc83
-               misc, loc->path, gfid);
50dc83
+               "%s: Directory selfheal failed : %d subvolumes "
50dc83
+               "have unrecoverable errors. gfid = %s",
50dc83
+               loc->path, misc, gfid);
50dc83
 
50dc83
         ret = 0;
50dc83
         goto sorry_no_fix;
50dc83
@@ -2369,13 +2386,13 @@ dht_dir_attr_heal(void *data)
50dc83
 
50dc83
     frame = data;
50dc83
     local = frame->local;
50dc83
-    mds_subvol = local->mds_subvol;
50dc83
     this = frame->this;
50dc83
     GF_VALIDATE_OR_GOTO("dht", this, out);
50dc83
     GF_VALIDATE_OR_GOTO("dht", local, out);
50dc83
     conf = this->private;
50dc83
     GF_VALIDATE_OR_GOTO("dht", conf, out);
50dc83
 
50dc83
+    mds_subvol = local->mds_subvol;
50dc83
     call_cnt = conf->subvolume_cnt;
50dc83
 
50dc83
     if (!__is_root_gfid(local->stbuf.ia_gfid) && (!mds_subvol)) {
50dc83
-- 
50dc83
1.8.3.1
50dc83