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