887953
From 3f7ff1a0343045c737fcca3ffbdc380be8a1f065 Mon Sep 17 00:00:00 2001
887953
From: N Balachandran <nbalacha@redhat.com>
887953
Date: Mon, 11 Mar 2019 11:30:05 +0530
887953
Subject: [PATCH 537/538] cluster/dht: Do not use gfid-req in fresh lookup
887953
887953
Fuse sets a random gfid-req value for a fresh lookup. Posix
887953
lookup will set this gfid on entries with missing gfids causing
887953
a GFID mismatch for directories.
887953
DHT will now ignore the Fuse provided gfid-req and use the GFID
887953
returned from other subvols to heal the missing gfid.
887953
887953
upstream: https://review.gluster.org/#/c/22112/
887953
887953
> Change-Id: I5f541978808f246ba4542564251e341ec490db14
887953
> fixes: bz#1670259
887953
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
887953
887953
Change-Id: I50e5a9cb4db8164989082daab30a0d5cac70920c
887953
BUG: 1661258
887953
Signed-off-by: N Balachandran <nbalacha@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/164947
887953
Tested-by: RHGS Build Bot <nigelb@redhat.com>
887953
Reviewed-by: Mohit Agrawal <moagrawa@redhat.com>
887953
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
887953
---
887953
 xlators/cluster/dht/src/dht-common.c | 63 ++++++++++++++++++++++++++++++++++--
887953
 xlators/cluster/dht/src/dht-common.h |  2 ++
887953
 2 files changed, 62 insertions(+), 3 deletions(-)
887953
887953
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
887953
index 1311a8d..12a17e6 100644
887953
--- a/xlators/cluster/dht/src/dht-common.c
887953
+++ b/xlators/cluster/dht/src/dht-common.c
887953
@@ -1347,7 +1347,7 @@ dht_lookup_dir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
         if (!op_ret && gf_uuid_is_null (local->gfid)) {
887953
                 memcpy (local->gfid, stbuf->ia_gfid, 16);
887953
         }
887953
-        if (local->gfid)
887953
+        if (!gf_uuid_is_null (local->gfid))
887953
                 gf_uuid_unparse(local->gfid, gfid_local);
887953
 
887953
         /* Check if the gfid is different for file from other node */
887953
@@ -1376,9 +1376,13 @@ dht_lookup_dir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
                 if (op_ret == -1) {
887953
                         local->op_errno = op_errno;
887953
                         gf_msg_debug (this->name, op_errno,
887953
-                                      "lookup of %s on %s returned error",
887953
+                                      "%s: lookup on %s returned error",
887953
                                       local->loc.path, prev->name);
887953
 
887953
+                        /* The GFID is missing on this subvol. Force a heal. */
887953
+                        if (op_errno == ENODATA) {
887953
+                                local->need_selfheal = 1;
887953
+                        }
887953
                         goto unlock;
887953
                 }
887953
 
887953
@@ -1485,6 +1489,17 @@ unlock:
887953
 
887953
                 if (local->need_selfheal) {
887953
                         local->need_selfheal = 0;
887953
+                        /* Set the gfid-req so posix will set the GFID*/
887953
+                        if (!gf_uuid_is_null(local->gfid)) {
887953
+                                ret = dict_set_static_bin(local->xattr_req,
887953
+                                                          "gfid-req",
887953
+                                                          local->gfid, 16);
887953
+                        } else {
887953
+                                if (!gf_uuid_is_null(local->gfid_req))
887953
+                                        ret = dict_set_static_bin(local->xattr_req,
887953
+                                                           "gfid-req",
887953
+                                                           local->gfid_req, 16);
887953
+                        }
887953
                         dht_lookup_everywhere (frame, this, &local->loc);
887953
                         return 0;
887953
                 }
887953
@@ -1686,6 +1701,12 @@ dht_revalidate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
                                         local->need_lookup_everywhere = 1;
887953
                                 }
887953
                         }
887953
+                      /* The GFID is missing on this subvol*/
887953
+                        if ((op_errno == ENODATA) &&
887953
+                            (IA_ISDIR(local->loc.inode->ia_type))) {
887953
+                                local->need_lookup_everywhere = 1;
887953
+                        }
887953
+
887953
                         goto unlock;
887953
                 }
887953
 
887953
@@ -1931,6 +1952,13 @@ cont:
887953
                         /* We know that current cached subvol is no more
887953
                            valid, get the new one */
887953
                         local->cached_subvol = NULL;
887953
+                        if (local->xattr_req) {
887953
+                                if (!gf_uuid_is_null(local->gfid)) {
887953
+                                        ret = dict_set_static_bin(local->xattr_req,
887953
+                                                                  "gfid-req",
887953
+                                                                  local->gfid, 16);
887953
+                                }
887953
+                        }
887953
                         dht_lookup_everywhere (frame, this, &local->loc);
887953
                         return 0;
887953
                 }
887953
@@ -2391,6 +2419,17 @@ dht_lookup_everywhere_done (call_frame_t *frame, xlator_t *this)
887953
                 return 0;
887953
         }
887953
 
887953
+        if (local->op_ret && local->gfid_missing) {
887953
+                if (gf_uuid_is_null(local->gfid_req)) {
887953
+                        DHT_STACK_UNWIND(lookup, frame, -1, ENODATA, NULL,
887953
+                                         NULL, NULL, NULL);
887953
+                        return 0;
887953
+                }
887953
+                /* A hack */
887953
+                dht_lookup_directory(frame, this, &local->loc);
887953
+                return 0;
887953
+        }
887953
+
887953
         if (local->dir_count) {
887953
                 dht_lookup_directory (frame, this, &local->loc);
887953
                 return 0;
887953
@@ -2751,6 +2790,8 @@ dht_lookup_everywhere_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
                 if (op_ret == -1) {
887953
                         if (op_errno != ENOENT)
887953
                                 local->op_errno = op_errno;
887953
+                        if (op_errno == ENODATA)
887953
+                                local->gfid_missing = _gf_true;
887953
                         goto unlock;
887953
                 }
887953
 
887953
@@ -3292,7 +3333,8 @@ dht_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
                 }
887953
         }
887953
 
887953
-        if (is_dir || (op_ret == -1 && op_errno == ENOTCONN)) {
887953
+        if (is_dir || (op_ret == -1 &&
887953
+                      ((op_errno == ENOTCONN) || (op_errno == ENODATA)))) {
887953
                 dht_lookup_directory (frame, this, &local->loc);
887953
                 return 0;
887953
         }
887953
@@ -3421,6 +3463,7 @@ dht_lookup (call_frame_t *frame, xlator_t *this,
887953
         int           call_cnt = 0;
887953
         int           gen = 0;
887953
         loc_t         new_loc = {0,};
887953
+        void         *gfid_req_ptr = NULL;
887953
 
887953
         VALIDATE_OR_GOTO (frame, err);
887953
         VALIDATE_OR_GOTO (this, err);
887953
@@ -3630,6 +3673,20 @@ dht_lookup (call_frame_t *frame, xlator_t *this,
887953
                 /* need it for dir self-heal */
887953
                 dht_check_and_set_acl_xattr_req (loc->inode, local->xattr_req);
887953
 
887953
+                /* Fuse sets a random value in gfid-req. If the gfid is missing
887953
+                 * on one or more subvols, posix will set the gfid to this
887953
+                 * value, causing GFID mismatches for directories.
887953
+                 */
887953
+                ret = dict_get_ptr(local->xattr_req, "gfid-req",
887953
+                                   &gfid_req_ptr);
887953
+                if (ret) {
887953
+                        gf_msg_debug(this->name, 0,
887953
+                                     "%s: No gfid-req available", loc->path);
887953
+                } else {
887953
+                        memcpy(local->gfid_req, gfid_req_ptr, sizeof(uuid_t));
887953
+                        dict_del(local->xattr_req, "gfid-req");
887953
+                }
887953
+
887953
                 if (!hashed_subvol) {
887953
 
887953
                         gf_msg_debug (this->name, 0,
887953
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
887953
index b40815c..94a0869 100644
887953
--- a/xlators/cluster/dht/src/dht-common.h
887953
+++ b/xlators/cluster/dht/src/dht-common.h
887953
@@ -346,6 +346,7 @@ struct dht_local {
887953
 
887953
         /* gfid related */
887953
         uuid_t  gfid;
887953
+        uuid_t  gfid_req;
887953
 
887953
         /* flag used to make sure we need to return estale in
887953
            {lookup,revalidate}_cbk */
887953
@@ -394,6 +395,7 @@ struct dht_local {
887953
         loc_t        loc2_copy;
887953
         gf_boolean_t locked;
887953
         gf_boolean_t dont_create_linkto;
887953
+        gf_boolean_t gfid_missing;
887953
 };
887953
 typedef struct dht_local dht_local_t;
887953
 
887953
-- 
887953
1.8.3.1
887953