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