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