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