e7a346
From 2802d400934b247436edf4d9f85839ad455307ca Mon Sep 17 00:00:00 2001
e7a346
From: Raghavendra G <rgowdapp@redhat.com>
e7a346
Date: Thu, 8 Feb 2018 13:44:38 +0530
e7a346
Subject: [PATCH 262/271] cluster/dht: store the 'reaction' on failures per
e7a346
 lock
e7a346
e7a346
Currently its passed in dht_blocking_inode(entry)lk, which would be a
e7a346
global value for all the locks passed in the argument. This would
e7a346
be a limitation for cases where we want to ignore failures on only few
e7a346
locks and fail for others.
e7a346
e7a346
>Change-Id: I02cfbcaafb593ad8140c0e5af725c866b630fb6b
e7a346
>BUG: 1543279
e7a346
>Signed-off-by: Raghavendra G <rgowdapp@redhat.com>
e7a346
e7a346
upstream patch: https://review.gluster.org/19546/
e7a346
BUG: 1488120
e7a346
Change-Id: I2d575530d14c89f90a0ffb790810748d4e296972
e7a346
Signed-off-by: Raghavendra G <rgowdapp@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/138153
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Nithya Balachandran <nbalacha@redhat.com>
e7a346
---
e7a346
 xlators/cluster/dht/src/dht-common.c   | 11 ++++++-----
e7a346
 xlators/cluster/dht/src/dht-common.h   | 16 +++++++++-------
e7a346
 xlators/cluster/dht/src/dht-lock.c     | 27 ++++++++++++++-------------
e7a346
 xlators/cluster/dht/src/dht-lock.h     |  9 ++++-----
e7a346
 xlators/cluster/dht/src/dht-rename.c   |  8 +++++---
e7a346
 xlators/cluster/dht/src/dht-selfheal.c | 13 ++++++++-----
e7a346
 6 files changed, 46 insertions(+), 38 deletions(-)
e7a346
e7a346
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
e7a346
index a985481..5b2c897 100644
e7a346
--- a/xlators/cluster/dht/src/dht-common.c
e7a346
+++ b/xlators/cluster/dht/src/dht-common.c
e7a346
@@ -7248,7 +7248,8 @@ dht_mknod_lock (call_frame_t *frame, xlator_t *subvol)
e7a346
                 goto err;
e7a346
 
e7a346
         lk_array[0] = dht_lock_new (frame->this, subvol, &local->loc, F_RDLCK,
e7a346
-                                    DHT_LAYOUT_HEAL_DOMAIN, NULL);
e7a346
+                                    DHT_LAYOUT_HEAL_DOMAIN, NULL,
e7a346
+                                    IGNORE_ENOENT_ESTALE);
e7a346
 
e7a346
         if (lk_array[0] == NULL)
e7a346
                 goto err;
e7a346
@@ -7256,8 +7257,7 @@ dht_mknod_lock (call_frame_t *frame, xlator_t *subvol)
e7a346
         local->lock[0].layout.parent_layout.locks = lk_array;
e7a346
         local->lock[0].layout.parent_layout.lk_count = count;
e7a346
 
e7a346
-        ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
-                                    IGNORE_ENOENT_ESTALE, dht_mknod_lock_cbk);
e7a346
+        ret = dht_blocking_inodelk (frame, lk_array, count, dht_mknod_lock_cbk);
e7a346
 
e7a346
         if (ret < 0) {
e7a346
                 local->lock[0].layout.parent_layout.locks = NULL;
e7a346
@@ -8392,7 +8392,8 @@ dht_create_lock (call_frame_t *frame, xlator_t *subvol)
e7a346
                 goto err;
e7a346
 
e7a346
         lk_array[0] = dht_lock_new (frame->this, subvol, &local->loc, F_RDLCK,
e7a346
-                                    DHT_LAYOUT_HEAL_DOMAIN, NULL);
e7a346
+                                    DHT_LAYOUT_HEAL_DOMAIN, NULL,
e7a346
+                                    IGNORE_ENOENT_ESTALE);
e7a346
 
e7a346
         if (lk_array[0] == NULL)
e7a346
                 goto err;
e7a346
@@ -8401,7 +8402,7 @@ dht_create_lock (call_frame_t *frame, xlator_t *subvol)
e7a346
         local->lock[0].layout.parent_layout.lk_count = count;
e7a346
 
e7a346
         ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
-                                    IGNORE_ENOENT_ESTALE, dht_create_lock_cbk);
e7a346
+                                    dht_create_lock_cbk);
e7a346
 
e7a346
         if (ret < 0) {
e7a346
                 local->lock[0].layout.parent_layout.locks = NULL;
e7a346
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
e7a346
index 9d429af..fbc1e29 100644
e7a346
--- a/xlators/cluster/dht/src/dht-common.h
e7a346
+++ b/xlators/cluster/dht/src/dht-common.h
e7a346
@@ -173,6 +173,7 @@ typedef enum {
e7a346
 } qdstatfs_action_t;
e7a346
 
e7a346
 typedef enum {
e7a346
+        REACTION_INVALID,
e7a346
         FAIL_ON_ANY_ERROR,
e7a346
         IGNORE_ENOENT_ESTALE
e7a346
 } dht_reaction_type_t;
e7a346
@@ -187,15 +188,16 @@ struct dht_skip_linkto_unlink {
e7a346
 };
e7a346
 
e7a346
 typedef struct {
e7a346
-        xlator_t     *xl;
e7a346
-        loc_t         loc;     /* contains/points to inode to lock on. */
e7a346
-        short         type;    /* read/write lock.                     */
e7a346
-        char         *domain;  /* Only locks within a single domain
e7a346
+        xlator_t            *xl;
e7a346
+        loc_t                loc; /* contains/points to inode to lock on. */
e7a346
+        short                type; /* read/write lock.                     */
e7a346
+        char                *domain;  /* Only locks within a single domain
e7a346
                                 * contend with each other
e7a346
                                 */
e7a346
-        char         *basename; /* Required for entrylk */
e7a346
-        gf_lkowner_t  lk_owner;
e7a346
-        gf_boolean_t  locked;
e7a346
+        char                *basename; /* Required for entrylk */
e7a346
+        gf_lkowner_t         lk_owner;
e7a346
+        gf_boolean_t         locked;
e7a346
+        dht_reaction_type_t  do_on_failure;
e7a346
 } dht_lock_t;
e7a346
 
e7a346
 /* The lock structure represents inodelk. */
e7a346
diff --git a/xlators/cluster/dht/src/dht-lock.c b/xlators/cluster/dht/src/dht-lock.c
e7a346
index 45ebeec..3e82c98 100644
e7a346
--- a/xlators/cluster/dht/src/dht-lock.c
e7a346
+++ b/xlators/cluster/dht/src/dht-lock.c
e7a346
@@ -191,7 +191,8 @@ out:
e7a346
 
e7a346
 dht_lock_t *
e7a346
 dht_lock_new (xlator_t *this, xlator_t *xl, loc_t *loc, short type,
e7a346
-              const char *domain, const char *basename)
e7a346
+              const char *domain, const char *basename,
e7a346
+              dht_reaction_type_t do_on_failure)
e7a346
 {
e7a346
         dht_conf_t *conf = NULL;
e7a346
         dht_lock_t *lock = NULL;
e7a346
@@ -204,6 +205,7 @@ dht_lock_new (xlator_t *this, xlator_t *xl, loc_t *loc, short type,
e7a346
 
e7a346
         lock->xl = xl;
e7a346
         lock->type = type;
e7a346
+        lock->do_on_failure = do_on_failure;
e7a346
 
e7a346
         lock->domain = gf_strdup (domain);
e7a346
         if (lock->domain == NULL) {
e7a346
@@ -540,7 +542,7 @@ dht_blocking_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
e7a346
                 switch (op_errno) {
e7a346
                 case ESTALE:
e7a346
                 case ENOENT:
e7a346
-                        if (local->lock[0].ns.directory_ns.reaction != IGNORE_ENOENT_ESTALE) {
e7a346
+                        if (local->lock[0].ns.directory_ns.locks[lk_index]->do_on_failure != IGNORE_ENOENT_ESTALE) {
e7a346
                                 local->lock[0].ns.directory_ns.op_ret = -1;
e7a346
                                 local->lock[0].ns.directory_ns.op_errno = op_errno;
e7a346
                                 goto cleanup;
e7a346
@@ -597,8 +599,7 @@ dht_blocking_entrylk_rec (call_frame_t *frame, int i)
e7a346
 
e7a346
 int
e7a346
 dht_blocking_entrylk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
-                      int lk_count, dht_reaction_type_t reaction,
e7a346
-                      fop_entrylk_cbk_t entrylk_cbk)
e7a346
+                      int lk_count, fop_entrylk_cbk_t entrylk_cbk)
e7a346
 {
e7a346
         int           ret        = -1;
e7a346
         call_frame_t *lock_frame = NULL;
e7a346
@@ -621,7 +622,6 @@ dht_blocking_entrylk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
         dht_set_lkowner (lk_array, lk_count, &lock_frame->root->lk_owner);
e7a346
 
e7a346
         local = lock_frame->local;
e7a346
-        local->lock[0].ns.directory_ns.reaction = reaction;
e7a346
         local->main_frame = frame;
e7a346
 
e7a346
         dht_blocking_entrylk_rec (lock_frame, 0);
e7a346
@@ -1029,7 +1029,8 @@ dht_blocking_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
e7a346
                 switch (op_errno) {
e7a346
                 case ESTALE:
e7a346
                 case ENOENT:
e7a346
-                        if (local->lock[0].layout.my_layout.reaction != IGNORE_ENOENT_ESTALE) {
e7a346
+                        if (local->lock[0].layout.my_layout.locks[lk_index]->do_on_failure
e7a346
+                            != IGNORE_ENOENT_ESTALE) {
e7a346
                                 gf_uuid_unparse (local->lock[0].layout.my_layout.locks[lk_index]->loc.gfid, gfid);
e7a346
                                 local->lock[0].layout.my_layout.op_ret = -1;
e7a346
                                 local->lock[0].layout.my_layout.op_errno = op_errno;
e7a346
@@ -1100,8 +1101,7 @@ dht_blocking_inodelk_rec (call_frame_t *frame, int i)
e7a346
 
e7a346
 int
e7a346
 dht_blocking_inodelk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
-                      int lk_count, dht_reaction_type_t reaction,
e7a346
-                      fop_inodelk_cbk_t inodelk_cbk)
e7a346
+                      int lk_count, fop_inodelk_cbk_t inodelk_cbk)
e7a346
 {
e7a346
         int           ret                       = -1;
e7a346
         call_frame_t *lock_frame                = NULL;
e7a346
@@ -1139,7 +1139,6 @@ dht_blocking_inodelk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
         dht_set_lkowner (lk_array, lk_count, &lock_frame->root->lk_owner);
e7a346
 
e7a346
         local = lock_frame->local;
e7a346
-        local->lock[0].layout.my_layout.reaction = reaction;
e7a346
         local->main_frame = frame;
e7a346
 
e7a346
         dht_blocking_inodelk_rec (lock_frame, 0);
e7a346
@@ -1210,7 +1209,7 @@ dht_blocking_entrylk_after_inodelk (call_frame_t *frame, void *cookie,
e7a346
         lk_array = entrylk->locks;
e7a346
         count = entrylk->lk_count;
e7a346
 
e7a346
-        ret = dht_blocking_entrylk (frame, lk_array, count, FAIL_ON_ANY_ERROR,
e7a346
+        ret = dht_blocking_entrylk (frame, lk_array, count,
e7a346
                                     dht_protect_namespace_cbk);
e7a346
 
e7a346
         if (ret < 0) {
e7a346
@@ -1303,7 +1302,8 @@ dht_protect_namespace (call_frame_t *frame, loc_t *loc,
e7a346
         }
e7a346
 
e7a346
         inodelk->locks[0] = dht_lock_new (this, subvol, &parent, F_RDLCK,
e7a346
-                                        DHT_LAYOUT_HEAL_DOMAIN, NULL);
e7a346
+                                          DHT_LAYOUT_HEAL_DOMAIN, NULL,
e7a346
+                                          FAIL_ON_ANY_ERROR);
e7a346
         if (inodelk->locks[0] == NULL) {
e7a346
                 local->op_errno = ENOMEM;
e7a346
                 gf_msg (this->name, GF_LOG_WARNING, local->op_errno,
e7a346
@@ -1330,7 +1330,8 @@ dht_protect_namespace (call_frame_t *frame, loc_t *loc,
e7a346
         }
e7a346
 
e7a346
         entrylk->locks[0] = dht_lock_new (this, subvol, &parent, F_WRLCK,
e7a346
-                                          DHT_ENTRY_SYNC_DOMAIN, loc->name);
e7a346
+                                          DHT_ENTRY_SYNC_DOMAIN, loc->name,
e7a346
+                                          FAIL_ON_ANY_ERROR);
e7a346
         if (entrylk->locks[0] == NULL) {
e7a346
                 local->op_errno = ENOMEM;
e7a346
                 gf_msg (this->name, GF_LOG_WARNING, local->op_errno,
e7a346
@@ -1347,7 +1348,7 @@ dht_protect_namespace (call_frame_t *frame, loc_t *loc,
e7a346
          * on name in cbk.
e7a346
          */
e7a346
         lk_array = inodelk->locks;
e7a346
-        ret = dht_blocking_inodelk (frame, lk_array, count, FAIL_ON_ANY_ERROR,
e7a346
+        ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
                                     dht_blocking_entrylk_after_inodelk);
e7a346
         if (ret < 0) {
e7a346
                 local->op_errno = EIO;
e7a346
diff --git a/xlators/cluster/dht/src/dht-lock.h b/xlators/cluster/dht/src/dht-lock.h
e7a346
index 0557858..f36bf3f 100644
e7a346
--- a/xlators/cluster/dht/src/dht-lock.h
e7a346
+++ b/xlators/cluster/dht/src/dht-lock.h
e7a346
@@ -22,7 +22,8 @@ dht_lock_count (dht_lock_t **lk_array, int lk_count);
e7a346
 
e7a346
 dht_lock_t *
e7a346
 dht_lock_new (xlator_t *this, xlator_t *xl, loc_t *loc, short type,
e7a346
-              const char *domain, const char *basename);
e7a346
+              const char *domain, const char *basename,
e7a346
+              dht_reaction_type_t do_on_failure);
e7a346
 
e7a346
 int32_t
e7a346
 dht_unlock_entrylk_wrapper (call_frame_t *, dht_elock_wrap_t *);
e7a346
@@ -32,8 +33,7 @@ dht_blocking_entrylk_rec (call_frame_t *frame, int i);
e7a346
 
e7a346
 int
e7a346
 dht_blocking_entrylk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
-                      int lk_count, dht_reaction_type_t reaction,
e7a346
-                      fop_inodelk_cbk_t entrylk_cbk);
e7a346
+                      int lk_count, fop_inodelk_cbk_t entrylk_cbk);
e7a346
 
e7a346
 int32_t
e7a346
 dht_unlock_inodelk (call_frame_t *frame, dht_lock_t **lk_array, int lk_count,
e7a346
@@ -70,8 +70,7 @@ dht_blocking_inodelk_rec (call_frame_t *frame, int i);
e7a346
 
e7a346
 int
e7a346
 dht_blocking_inodelk (call_frame_t *frame, dht_lock_t **lk_array,
e7a346
-                      int lk_count, dht_reaction_type_t reaction,
e7a346
-                      fop_inodelk_cbk_t inodelk_cbk);
e7a346
+                      int lk_count, fop_inodelk_cbk_t inodelk_cbk);
e7a346
 
e7a346
 int32_t
e7a346
 dht_blocking_entrylk_after_inodelk (call_frame_t *frame, void *cookie,
e7a346
diff --git a/xlators/cluster/dht/src/dht-rename.c b/xlators/cluster/dht/src/dht-rename.c
e7a346
index 5a72c1f..3dc042e 100644
e7a346
--- a/xlators/cluster/dht/src/dht-rename.c
e7a346
+++ b/xlators/cluster/dht/src/dht-rename.c
e7a346
@@ -1649,14 +1649,16 @@ dht_rename_lock (call_frame_t *frame)
e7a346
                 goto err;
e7a346
 
e7a346
         lk_array[0] = dht_lock_new (frame->this, local->src_cached, &local->loc,
e7a346
-                                    F_WRLCK, DHT_FILE_MIGRATE_DOMAIN, NULL);
e7a346
+                                    F_WRLCK, DHT_FILE_MIGRATE_DOMAIN, NULL,
e7a346
+                                    FAIL_ON_ANY_ERROR);
e7a346
         if (lk_array[0] == NULL)
e7a346
                 goto err;
e7a346
 
e7a346
         if (local->dst_cached) {
e7a346
                 lk_array[1] = dht_lock_new (frame->this, local->dst_cached,
e7a346
                                             &local->loc2, F_WRLCK,
e7a346
-                                            DHT_FILE_MIGRATE_DOMAIN, NULL);
e7a346
+                                            DHT_FILE_MIGRATE_DOMAIN, NULL,
e7a346
+                                            FAIL_ON_ANY_ERROR);
e7a346
                 if (lk_array[1] == NULL)
e7a346
                         goto err;
e7a346
         }
e7a346
@@ -1665,7 +1667,7 @@ dht_rename_lock (call_frame_t *frame)
e7a346
         local->lock[0].layout.parent_layout.lk_count = count;
e7a346
 
e7a346
         ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
-                                    FAIL_ON_ANY_ERROR, dht_rename_lock_cbk);
e7a346
+                                    dht_rename_lock_cbk);
e7a346
         if (ret < 0) {
e7a346
                 local->lock[0].layout.parent_layout.locks = NULL;
e7a346
                 local->lock[0].layout.parent_layout.lk_count = 0;
e7a346
diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c
e7a346
index 5812f12..e9b1db9 100644
e7a346
--- a/xlators/cluster/dht/src/dht-selfheal.c
e7a346
+++ b/xlators/cluster/dht/src/dht-selfheal.c
e7a346
@@ -588,7 +588,8 @@ dht_selfheal_layout_lock (call_frame_t *frame, dht_layout_t *layout,
e7a346
                                                     conf->subvolumes[i],
e7a346
                                                     &local->loc, F_WRLCK,
e7a346
                                                     DHT_LAYOUT_HEAL_DOMAIN,
e7a346
-                                                    NULL);
e7a346
+                                                    NULL,
e7a346
+                                                    FAIL_ON_ANY_ERROR);
e7a346
                         if (lk_array[i] == NULL) {
e7a346
                                 gf_uuid_unparse (local->stbuf.ia_gfid, gfid);
e7a346
                                 gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM,
e7a346
@@ -613,7 +614,8 @@ dht_selfheal_layout_lock (call_frame_t *frame, dht_layout_t *layout,
e7a346
 
e7a346
                 lk_array[0] = dht_lock_new (frame->this, local->hashed_subvol,
e7a346
                                             &local->loc, F_WRLCK,
e7a346
-                                            DHT_LAYOUT_HEAL_DOMAIN, NULL);
e7a346
+                                            DHT_LAYOUT_HEAL_DOMAIN, NULL,
e7a346
+                                            FAIL_ON_ANY_ERROR);
e7a346
                 if (lk_array[0] == NULL) {
e7a346
                         gf_uuid_unparse (local->stbuf.ia_gfid, gfid);
e7a346
                         gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM,
e7a346
@@ -627,7 +629,7 @@ dht_selfheal_layout_lock (call_frame_t *frame, dht_layout_t *layout,
e7a346
         local->lock[0].layout.my_layout.locks = lk_array;
e7a346
         local->lock[0].layout.my_layout.lk_count = count;
e7a346
 
e7a346
-        ret = dht_blocking_inodelk (frame, lk_array, count, FAIL_ON_ANY_ERROR,
e7a346
+        ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
                                     dht_selfheal_layout_lock_cbk);
e7a346
         if (ret < 0) {
e7a346
                 local->lock[0].layout.my_layout.locks = NULL;
e7a346
@@ -2783,7 +2785,8 @@ dht_update_commit_hash_for_layout (call_frame_t *frame)
e7a346
                 lk_array[i] = dht_lock_new (frame->this,
e7a346
                                             conf->local_subvols[i],
e7a346
                                             &local->loc, F_WRLCK,
e7a346
-                                            DHT_LAYOUT_HEAL_DOMAIN, NULL);
e7a346
+                                            DHT_LAYOUT_HEAL_DOMAIN, NULL,
e7a346
+                                            FAIL_ON_ANY_ERROR);
e7a346
                 if (lk_array[i] == NULL)
e7a346
                         goto err;
e7a346
         }
e7a346
@@ -2791,7 +2794,7 @@ dht_update_commit_hash_for_layout (call_frame_t *frame)
e7a346
         local->lock[0].layout.my_layout.locks = lk_array;
e7a346
         local->lock[0].layout.my_layout.lk_count = count;
e7a346
 
e7a346
-        ret = dht_blocking_inodelk (frame, lk_array, count, FAIL_ON_ANY_ERROR,
e7a346
+        ret = dht_blocking_inodelk (frame, lk_array, count,
e7a346
                                     dht_update_commit_hash_for_layout_resume);
e7a346
         if (ret < 0) {
e7a346
                 local->lock[0].layout.my_layout.locks = NULL;
e7a346
-- 
e7a346
1.8.3.1
e7a346