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