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