3604df
From 820d39aabe509392c91f22ca214afe0be7b1f7e9 Mon Sep 17 00:00:00 2001
3604df
From: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Date: Wed, 22 Feb 2017 14:43:46 +0530
3604df
Subject: [PATCH 296/300] features/shard: Put onus of choosing the inode to
3604df
 resolve on individual fops
3604df
3604df
        Backport of: https://review.gluster.org/16709
3604df
3604df
... as opposed to adding checks in "common" functions to choose the inode
3604df
to resolve based local->fop, which is rather ugly and prone to errors.
3604df
3604df
Change-Id: I0fcd0dc452ac783e2ff4793eaac00318a3b106ba
3604df
BUG: 1412554
3604df
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/98553
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 xlators/features/shard/src/shard.c | 46 +++++++++++++++++---------------------
3604df
 xlators/features/shard/src/shard.h |  1 +
3604df
 2 files changed, 21 insertions(+), 26 deletions(-)
3604df
3604df
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
3604df
index 934aaaf..59a0cfa 100644
3604df
--- a/xlators/features/shard/src/shard.c
3604df
+++ b/xlators/features/shard/src/shard.c
3604df
@@ -549,19 +549,20 @@ shard_common_inode_write_success_unwind (glusterfs_fop_t fop,
3604df
 
3604df
 int
3604df
 shard_common_resolve_shards (call_frame_t *frame, xlator_t *this,
3604df
-                             inode_t *res_inode,
3604df
                              shard_post_resolve_fop_handler_t post_res_handler)
3604df
 {
3604df
         int                   i              = -1;
3604df
         uint32_t              shard_idx_iter = 0;
3604df
         char                  path[PATH_MAX] = {0,};
3604df
         inode_t              *inode          = NULL;
3604df
+        inode_t              *res_inode      = NULL;
3604df
         shard_priv_t         *priv           = NULL;
3604df
         shard_local_t        *local          = NULL;
3604df
 
3604df
         priv = this->private;
3604df
         local = frame->local;
3604df
         shard_idx_iter = local->first_block;
3604df
+        res_inode = local->resolver_base_inode;
3604df
 
3604df
         if (local->op_ret < 0)
3604df
                 goto out;
3604df
@@ -797,10 +798,7 @@ shard_lookup_dot_shard_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3604df
         }
3604df
 
3604df
         shard_link_dot_shard_inode (local, inode, buf);
3604df
-        shard_common_resolve_shards (frame, this,
3604df
-                                     (local->fop == GF_FOP_RENAME) ?
3604df
-                                     local->loc2.inode : local->loc.inode,
3604df
-                                     local->post_res_handler);
3604df
+        shard_common_resolve_shards (frame, this, local->post_res_handler);
3604df
         return 0;
3604df
 
3604df
 unwind:
3604df
@@ -1813,6 +1811,8 @@ shard_truncate_begin (call_frame_t *frame, xlator_t *this)
3604df
                                                local->block_size);
3604df
 
3604df
         local->num_blocks = local->last_block - local->first_block + 1;
3604df
+        local->resolver_base_inode = (local->fop == GF_FOP_TRUNCATE) ?
3604df
+                                     local->loc.inode : local->fd->inode;
3604df
 
3604df
         if ((local->first_block == 0) && (local->num_blocks == 1)) {
3604df
                 if (local->fop == GF_FOP_TRUNCATE)
3604df
@@ -1844,9 +1844,6 @@ shard_truncate_begin (call_frame_t *frame, xlator_t *this)
3604df
                                         shard_post_resolve_truncate_handler);
3604df
         } else {
3604df
                 shard_common_resolve_shards (frame, this,
3604df
-                                             (local->fop == GF_FOP_TRUNCATE) ?
3604df
-                                              local->loc.inode :
3604df
-                                              local->fd->inode,
3604df
                                            shard_post_resolve_truncate_handler);
3604df
         }
3604df
         return 0;
3604df
@@ -2158,10 +2155,7 @@ shard_post_lookup_shards_unlink_handler (call_frame_t *frame, xlator_t *this)
3604df
         local->op_ret = 0;
3604df
         local->op_errno = 0;
3604df
 
3604df
-        shard_unlink_shards_do (frame, this,
3604df
-                                (local->fop == GF_FOP_RENAME)
3604df
-                                             ? local->loc2.inode
3604df
-                                             : local->loc.inode);
3604df
+        shard_unlink_shards_do (frame, this, local->resolver_base_inode);
3604df
         return 0;
3604df
 }
3604df
 
3604df
@@ -2208,14 +2202,10 @@ shard_post_resolve_unlink_handler (call_frame_t *frame, xlator_t *this)
3604df
 
3604df
         if (!local->call_count)
3604df
                 shard_unlink_shards_do (frame, this,
3604df
-                                        (local->fop == GF_FOP_RENAME)
3604df
-                                                     ? local->loc2.inode
3604df
-                                                     : local->loc.inode);
3604df
+                                        local->resolver_base_inode);
3604df
         else
3604df
                 shard_common_lookup_shards (frame, this,
3604df
-                                            (local->fop == GF_FOP_RENAME)
3604df
-                                                         ? local->loc2.inode
3604df
-                                                         : local->loc.inode,
3604df
+                                            local->resolver_base_inode,
3604df
                                        shard_post_lookup_shards_unlink_handler);
3604df
         return 0;
3604df
 }
3604df
@@ -2252,6 +2242,7 @@ shard_unlink_base_file_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3604df
         local->last_block = get_highest_block (0, local->prebuf.ia_size,
3604df
                                                local->block_size);
3604df
         local->num_blocks = local->last_block - local->first_block + 1;
3604df
+        local->resolver_base_inode = local->loc.inode;
3604df
 
3604df
         /* num_blocks = 1 implies that the file has not crossed its
3604df
          * shard block size. So unlink boils down to unlinking just the
3604df
@@ -2282,7 +2273,7 @@ shard_unlink_base_file_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3604df
                 shard_lookup_dot_shard (frame, this,
3604df
                                         shard_post_resolve_unlink_handler);
3604df
         } else {
3604df
-                shard_common_resolve_shards (frame, this, local->loc.inode,
3604df
+                shard_common_resolve_shards (frame, this,
3604df
                                              shard_post_resolve_unlink_handler);
3604df
         }
3604df
 
3604df
@@ -2605,6 +2596,7 @@ shard_rename_unlink_dst_shards_do (call_frame_t *frame, xlator_t *this)
3604df
         local->last_block = get_highest_block (0, local->postbuf.ia_size,
3604df
                                                local->dst_block_size);
3604df
         local->num_blocks = local->last_block - local->first_block + 1;
3604df
+        local->resolver_base_inode = local->loc2.inode;
3604df
 
3604df
         if ((local->xattr_rsp) &&
3604df
             (!dict_get_uint32 (local->xattr_rsp, GET_LINK_COUNT, &link_count))
3604df
@@ -2632,7 +2624,7 @@ shard_rename_unlink_dst_shards_do (call_frame_t *frame, xlator_t *this)
3604df
                 shard_lookup_dot_shard (frame, this,
3604df
                                         shard_post_resolve_unlink_handler);
3604df
         } else {
3604df
-                shard_common_resolve_shards (frame, this, local->loc2.inode,
3604df
+                shard_common_resolve_shards (frame, this,
3604df
                                              shard_post_resolve_unlink_handler);
3604df
         }
3604df
 
3604df
@@ -3361,6 +3353,7 @@ shard_post_lookup_readv_handler (call_frame_t *frame, xlator_t *this)
3604df
                                                local->block_size);
3604df
 
3604df
         local->num_blocks = local->last_block - local->first_block + 1;
3604df
+        local->resolver_base_inode = local->loc.inode;
3604df
 
3604df
         local->inode_list = GF_CALLOC (local->num_blocks, sizeof (inode_t *),
3604df
                                        gf_shard_mt_inode_list);
3604df
@@ -3395,7 +3388,7 @@ shard_post_lookup_readv_handler (call_frame_t *frame, xlator_t *this)
3604df
                 shard_lookup_dot_shard (frame, this,
3604df
                                         shard_post_resolve_readv_handler);
3604df
         } else {
3604df
-                shard_common_resolve_shards (frame, this, local->loc.inode,
3604df
+                shard_common_resolve_shards (frame, this,
3604df
                                              shard_post_resolve_readv_handler);
3604df
         }
3604df
         return 0;
3604df
@@ -3879,8 +3872,7 @@ shard_mkdir_dot_shard_cbk (call_frame_t *frame, void *cookie,
3604df
         shard_link_dot_shard_inode (local, inode, buf);
3604df
 
3604df
 unwind:
3604df
-        shard_common_resolve_shards (frame, this, local->loc.inode,
3604df
-                                     local->post_res_handler);
3604df
+        shard_common_resolve_shards (frame, this, local->post_res_handler);
3604df
         return 0;
3604df
 }
3604df
 
3604df
@@ -4623,6 +4615,7 @@ shard_common_inode_write_begin (call_frame_t *frame, xlator_t *this,
3604df
         local->last_block = get_highest_block (offset, local->total_size,
3604df
                                                local->block_size);
3604df
         local->num_blocks = local->last_block - local->first_block + 1;
3604df
+        local->resolver_base_inode = local->fd->inode;
3604df
         local->inode_list = GF_CALLOC (local->num_blocks, sizeof (inode_t *),
3604df
                                        gf_shard_mt_inode_list);
3604df
         if (!local->inode_list)
3604df
@@ -4641,12 +4634,13 @@ shard_common_inode_write_begin (call_frame_t *frame, xlator_t *this,
3604df
         local->dot_shard_loc.inode = inode_find (this->itable,
3604df
                                                  priv->dot_shard_gfid);
3604df
 
3604df
-        if (!local->dot_shard_loc.inode)
3604df
+        if (!local->dot_shard_loc.inode) {
3604df
                 shard_mkdir_dot_shard (frame, this,
3604df
                                  shard_common_inode_write_post_resolve_handler);
3604df
-        else
3604df
-                shard_common_resolve_shards (frame, this, local->loc.inode,
3604df
+        } else {
3604df
+                shard_common_resolve_shards (frame, this,
3604df
                                  shard_common_inode_write_post_resolve_handler);
3604df
+        }
3604df
 
3604df
         return 0;
3604df
 out:
3604df
diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h
3604df
index 8303a2c..f626fae 100644
3604df
--- a/xlators/features/shard/src/shard.h
3604df
+++ b/xlators/features/shard/src/shard.h
3604df
@@ -254,6 +254,7 @@ typedef struct shard_local {
3604df
                 fop_inodelk_cbk_t inodelk_cbk;
3604df
                 shard_lock_t *shard_lock;
3604df
         } lock;
3604df
+        inode_t *resolver_base_inode;
3604df
 } shard_local_t;
3604df
 
3604df
 typedef struct shard_inode_ctx {
3604df
-- 
3604df
2.9.3
3604df