14f8ab
From 884ba13ee47888b5de9b6d6acaf051e895f55053 Mon Sep 17 00:00:00 2001
14f8ab
From: N Balachandran <nbalacha@redhat.com>
14f8ab
Date: Wed, 10 Apr 2019 14:28:55 +0530
14f8ab
Subject: [PATCH 127/141] cluster/dht: Refactor dht lookup functions
14f8ab
14f8ab
Part 2: Modify dht_revalidate_cbk to call
14f8ab
dht_selfheal_directory instead of separate calls
14f8ab
to heal attrs and xattrs.
14f8ab
14f8ab
upstream: https://review.gluster.org/#/c/glusterfs/+/22542/
14f8ab
14f8ab
> Change-Id: Id41ac6c4220c2c35484812bbfc6157fc3c86b142
14f8ab
> updates: bz#1590385
14f8ab
14f8ab
Change-Id: Id53962306dd142efc741de838b585fa5c78f9b1f
14f8ab
BUG:1703897
14f8ab
Signed-off-by: N Balachandran <nbalacha@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/169038
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Susant Palai <spalai@redhat.com>
14f8ab
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
14f8ab
---
14f8ab
 xlators/cluster/dht/src/dht-common.c | 104 ++++++++++-------------------------
14f8ab
 1 file changed, 30 insertions(+), 74 deletions(-)
14f8ab
14f8ab
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
14f8ab
index d3e900c..183872f 100644
14f8ab
--- a/xlators/cluster/dht/src/dht-common.c
14f8ab
+++ b/xlators/cluster/dht/src/dht-common.c
14f8ab
@@ -1365,7 +1365,6 @@ dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
         if (local->inode == NULL)
14f8ab
             local->inode = inode_ref(inode);
14f8ab
 
14f8ab
-        /* This could be a problem */
14f8ab
         dht_iatt_merge(this, &local->stbuf, stbuf);
14f8ab
         dht_iatt_merge(this, &local->postparent, postparent);
14f8ab
 
14f8ab
@@ -1509,8 +1508,6 @@ dht_revalidate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
     int is_dir = 0;
14f8ab
     int is_linkfile = 0;
14f8ab
     int follow_link = 0;
14f8ab
-    call_frame_t *copy = NULL;
14f8ab
-    dht_local_t *copy_local = NULL;
14f8ab
     char gfid[GF_UUID_BUF_SIZE] = {0};
14f8ab
     uint32_t vol_commit_hash = 0;
14f8ab
     xlator_t *subvol = NULL;
14f8ab
@@ -1538,17 +1535,16 @@ dht_revalidate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
 
14f8ab
     gf_uuid_unparse(local->loc.gfid, gfid);
14f8ab
 
14f8ab
+    gf_msg_debug(this->name, op_errno,
14f8ab
+                 "%s: revalidate lookup on %s returned op_ret %d",
14f8ab
+                 local->loc.path, prev->name, op_ret);
14f8ab
+
14f8ab
     LOCK(&frame->lock);
14f8ab
     {
14f8ab
         if (gf_uuid_is_null(local->gfid)) {
14f8ab
             memcpy(local->gfid, local->loc.gfid, 16);
14f8ab
         }
14f8ab
 
14f8ab
-        gf_msg_debug(this->name, op_errno,
14f8ab
-                     "revalidate lookup of %s "
14f8ab
-                     "returned with op_ret %d",
14f8ab
-                     local->loc.path, op_ret);
14f8ab
-
14f8ab
         if (op_ret == -1) {
14f8ab
             local->op_errno = op_errno;
14f8ab
 
14f8ab
@@ -1580,6 +1576,8 @@ dht_revalidate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
                                  local->loc.path);
14f8ab
 
14f8ab
                     local->need_lookup_everywhere = 1;
14f8ab
+                } else if (IA_ISDIR(local->loc.inode->ia_type)) {
14f8ab
+                    local->need_selfheal = 1;
14f8ab
                 }
14f8ab
             }
14f8ab
 
14f8ab
@@ -1638,15 +1636,16 @@ dht_revalidate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
                     (local->stbuf.ia_uid != stbuf->ia_uid) ||
14f8ab
                     is_permission_different(&local->stbuf.ia_prot,
14f8ab
                                             &stbuf->ia_prot)) {
14f8ab
-                    local->need_selfheal = 1;
14f8ab
+                    local->need_attrheal = 1;
14f8ab
                 }
14f8ab
             }
14f8ab
 
14f8ab
             if (!dict_get(xattr, conf->mds_xattr_key)) {
14f8ab
                 gf_msg_debug(this->name, 0,
14f8ab
-                             "internal xattr %s is not present"
14f8ab
-                             " on path %s gfid is %s ",
14f8ab
-                             conf->mds_xattr_key, local->loc.path, gfid);
14f8ab
+                             "%s: internal xattr %s is not present"
14f8ab
+                             " on subvol %s(gfid is %s)",
14f8ab
+                             local->loc.path, conf->mds_xattr_key, prev->name,
14f8ab
+                             gfid);
14f8ab
             } else {
14f8ab
                 check_mds = dht_dict_get_array(xattr, conf->mds_xattr_key,
14f8ab
                                                mds_xattr_val, 1, &errst);
14f8ab
@@ -1734,71 +1733,28 @@ unlock:
14f8ab
             local->need_xattr_heal = 0;
14f8ab
 
14f8ab
         if (IA_ISDIR(local->stbuf.ia_type)) {
14f8ab
-            /* Code to update all extended attributed from hashed
14f8ab
-               subvol to local->xattr and call heal code to heal
14f8ab
-               custom xattr from hashed subvol to non-hashed subvol
14f8ab
-            */
14f8ab
-            if (local->need_xattr_heal && (local->mds_xattr)) {
14f8ab
-                dht_dir_set_heal_xattr(this, local, local->xattr,
14f8ab
-                                       local->mds_xattr, NULL, NULL);
14f8ab
-                dict_unref(local->mds_xattr);
14f8ab
-                local->mds_xattr = NULL;
14f8ab
-                local->need_xattr_heal = 0;
14f8ab
-                ret = dht_dir_xattr_heal(this, local);
14f8ab
-                if (ret)
14f8ab
-                    gf_msg(this->name, GF_LOG_ERROR, ret,
14f8ab
-                           DHT_MSG_DIR_XATTR_HEAL_FAILED,
14f8ab
-                           "xattr heal failed for directory %s "
14f8ab
-                           " gfid %s ",
14f8ab
-                           local->loc.path, gfid);
14f8ab
-            } else {
14f8ab
-                /* Call function to save hashed subvol on inode
14f8ab
-                   ctx if internal mds xattr is not present and
14f8ab
-                   all subvols are up
14f8ab
-                */
14f8ab
-                if (inode && !__is_root_gfid(inode->gfid) && (!local->op_ret))
14f8ab
-                    (void)dht_common_mark_mdsxattr(frame, NULL, 1);
14f8ab
-            }
14f8ab
-        }
14f8ab
-        if (local->need_selfheal) {
14f8ab
-            local->need_selfheal = 0;
14f8ab
-            if (!__is_root_gfid(inode->gfid)) {
14f8ab
-                gf_uuid_copy(local->gfid, local->mds_stbuf.ia_gfid);
14f8ab
-                local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
14f8ab
-                local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
14f8ab
-                local->stbuf.ia_prot = local->mds_stbuf.ia_prot;
14f8ab
-            } else {
14f8ab
-                gf_uuid_copy(local->gfid, local->stbuf.ia_gfid);
14f8ab
-                local->stbuf.ia_gid = local->prebuf.ia_gid;
14f8ab
-                local->stbuf.ia_uid = local->prebuf.ia_uid;
14f8ab
-                local->stbuf.ia_prot = local->prebuf.ia_prot;
14f8ab
-            }
14f8ab
+            if (!__is_root_gfid(local->loc.inode->gfid) &&
14f8ab
+                (!dict_get(local->xattr, conf->mds_xattr_key)))
14f8ab
+                local->need_selfheal = 1;
14f8ab
 
14f8ab
-            copy = create_frame(this, this->ctx->pool);
14f8ab
-            if (copy) {
14f8ab
-                copy_local = dht_local_init(copy, &local->loc, NULL, 0);
14f8ab
-                if (!copy_local) {
14f8ab
-                    DHT_STACK_DESTROY(copy);
14f8ab
-                    goto cont;
14f8ab
-                }
14f8ab
-                copy_local->stbuf = local->stbuf;
14f8ab
-                copy_local->mds_stbuf = local->mds_stbuf;
14f8ab
-                copy_local->mds_subvol = local->mds_subvol;
14f8ab
-                copy->local = copy_local;
14f8ab
-                FRAME_SU_DO(copy, dht_local_t);
14f8ab
-                ret = synctask_new(this->ctx->env, dht_dir_attr_heal,
14f8ab
-                                   dht_dir_attr_heal_done, copy, copy);
14f8ab
-                if (ret) {
14f8ab
-                    gf_msg(this->name, GF_LOG_ERROR, ENOMEM,
14f8ab
-                           DHT_MSG_DIR_ATTR_HEAL_FAILED,
14f8ab
-                           "Synctask creation failed to heal attr "
14f8ab
-                           "for path %s gfid %s ",
14f8ab
-                           local->loc.path, local->gfid);
14f8ab
-                    DHT_STACK_DESTROY(copy);
14f8ab
+            if (dht_needs_selfheal(frame, this)) {
14f8ab
+                if (!__is_root_gfid(local->loc.inode->gfid)) {
14f8ab
+                    local->stbuf.ia_gid = local->mds_stbuf.ia_gid;
14f8ab
+                    local->stbuf.ia_uid = local->mds_stbuf.ia_uid;
14f8ab
+                    local->stbuf.ia_prot = local->mds_stbuf.ia_prot;
14f8ab
+                } else {
14f8ab
+                    local->stbuf.ia_gid = local->prebuf.ia_gid;
14f8ab
+                    local->stbuf.ia_uid = local->prebuf.ia_uid;
14f8ab
+                    local->stbuf.ia_prot = local->prebuf.ia_prot;
14f8ab
                 }
14f8ab
+
14f8ab
+                layout = local->layout;
14f8ab
+                dht_selfheal_directory(frame, dht_lookup_selfheal_cbk,
14f8ab
+                                       &local->loc, layout);
14f8ab
+                return 0;
14f8ab
             }
14f8ab
         }
14f8ab
-    cont:
14f8ab
+
14f8ab
         if (local->layout_mismatch) {
14f8ab
             /* Found layout mismatch in the directory, need to
14f8ab
                fix this in the inode context */
14f8ab
@@ -1814,7 +1770,7 @@ unlock:
14f8ab
             dht_layout_unref(this, local->layout);
14f8ab
             local->layout = NULL;
14f8ab
 
14f8ab
-            /* We know that current cached subvol is no more
14f8ab
+            /* We know that current cached subvol is no longer
14f8ab
                valid, get the new one */
14f8ab
             local->cached_subvol = NULL;
14f8ab
             if (local->xattr_req) {
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab