summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2015-04-01 15:13:11 +0530
committerVijay Bellur <vbellur@redhat.com>2015-04-06 23:09:28 -0700
commitd1a5c805610115122b8ef61367b61425d7e39db5 (patch)
treedd28c0abe91d8f7af4599b5fb3e330ea3e97c8ae /xlators
parent2ef9ad2dc5822b9b88243cb7f60816fe1c531e91 (diff)
features/shard: Refactor code
* Renamed shard_writev_create_write_shards() to shard_common_resolve_shards() to appropriately reflect its functionality and for reuse in other fops too. * Move code common to MKNOD and CREATE into a macro. * Cut down on if nesting in shard_lookup_cbk() Change-Id: I488255499673accd426390c6d42f2b39bab3d637 BUG: 1205661 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com> Reviewed-on: http://review.gluster.org/10096 Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/features/shard/src/shard.c68
-rw-r--r--xlators/features/shard/src/shard.h21
2 files changed, 40 insertions, 49 deletions
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index 99c1496386f..2dccbb0da8d 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -240,19 +240,18 @@ shard_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (op_ret < 0)
goto unwind;
- if ((op_ret == 0) && (!IA_ISDIR (buf->ia_type))) {
- ret = dict_get_uint64 (xdata, GF_XATTR_SHARD_BLOCK_SIZE, &size);
- if (!ret && size) {
- ctx_tmp.block_size = ntoh64 (size);
- ctx_tmp.mode = st_mode_from_ia (buf->ia_prot,
- buf->ia_type);
- ctx_tmp.rdev = buf->ia_rdev;
- ret = shard_inode_ctx_set_all (inode, this, &ctx_tmp);
- if (ret)
- gf_log (this->name, GF_LOG_WARNING, "Failed to "
- "set inode ctx for %s",
- uuid_utoa (inode->gfid));
- }
+ if (IA_ISDIR (buf->ia_type))
+ goto unwind;
+
+ ret = dict_get_uint64 (xdata, GF_XATTR_SHARD_BLOCK_SIZE, &size);
+ if (!ret && size) {
+ ctx_tmp.block_size = ntoh64 (size);
+ ctx_tmp.mode = st_mode_from_ia (buf->ia_prot, buf->ia_type);
+ ctx_tmp.rdev = buf->ia_rdev;
+ ret = shard_inode_ctx_set_all (inode, this, &ctx_tmp);
+ if (ret)
+ gf_log (this->name, GF_LOG_WARNING, "Failed to set "
+ "inode ctx for %s", uuid_utoa (buf->ia_gfid));
}
/* To-Do: return the call with aggregated values of ia_size and
@@ -411,12 +410,7 @@ int
shard_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
dev_t rdev, mode_t umask, dict_t *xdata)
{
- int ret = -1;
- int32_t op_errno = ENOMEM;
shard_local_t *local = NULL;
- shard_priv_t *priv = NULL;
-
- priv = this->private;
local = mem_get0 (this->local_pool);
if (!local)
@@ -424,24 +418,15 @@ shard_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
frame->local = local;
- local->block_size = hton64 (priv->block_size);
-
- ret = dict_set_static_bin (xdata, GF_XATTR_SHARD_BLOCK_SIZE,
- &local->block_size, sizeof (uint64_t));
- if (ret) {
- gf_log (this->name, GF_LOG_WARNING, "Failed to set key: %s "
- "on path %s", GF_XATTR_SHARD_BLOCK_SIZE, loc->path);
- goto err;
- }
+ SHARD_INODE_CREATE_INIT (this, local, xdata, loc, err);
STACK_WIND (frame, shard_mknod_cbk, FIRST_CHILD (this),
FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask,
xdata);
return 0;
-
err:
- SHARD_STACK_UNWIND (mknod, frame, -1, op_errno, NULL, NULL, NULL,
+ SHARD_STACK_UNWIND (mknod, frame, -1, ENOMEM, NULL, NULL, NULL,
NULL, NULL);
return 0;
@@ -566,12 +551,7 @@ int
shard_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- int ret = -1;
- int32_t op_errno = ENOMEM;
shard_local_t *local = NULL;
- shard_priv_t *priv = NULL;
-
- priv = this->private;
local = mem_get0 (this->local_pool);
if (!local)
@@ -579,15 +559,7 @@ shard_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
frame->local = local;
- local->block_size = hton64 (priv->block_size);
-
- ret = dict_set_static_bin (xdata, GF_XATTR_SHARD_BLOCK_SIZE,
- &local->block_size, sizeof (uint64_t));
- if (ret) {
- gf_log (this->name, GF_LOG_WARNING, "Failed to set key: %s "
- "on path %s", GF_XATTR_SHARD_BLOCK_SIZE, loc->path);
- goto err;
- }
+ SHARD_INODE_CREATE_INIT (this, local, xdata, loc, err);
STACK_WIND (frame, shard_create_cbk, FIRST_CHILD (this),
FIRST_CHILD(this)->fops->create, loc, flags, mode, umask,
@@ -595,7 +567,7 @@ shard_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
return 0;
err:
- SHARD_STACK_UNWIND (create, frame, -1, op_errno, NULL, NULL, NULL,
+ SHARD_STACK_UNWIND (create, frame, -1, ENOMEM, NULL, NULL, NULL,
NULL, NULL, NULL);
return 0;
@@ -1160,7 +1132,7 @@ err:
}
int
-shard_writev_create_write_shards (call_frame_t *frame, xlator_t *this)
+shard_common_resolve_shards (call_frame_t *frame, xlator_t *this)
{
int i = -1;
uint32_t shard_idx_iter = 0;
@@ -1249,7 +1221,7 @@ shard_lookup_dot_shard_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
}
shard_link_dot_shard_inode (local, inode, buf);
- shard_writev_create_write_shards (frame, this);
+ shard_common_resolve_shards (frame, this);
return 0;
unwind:
@@ -1316,7 +1288,7 @@ shard_writev_mkdir_dot_shard_cbk (call_frame_t *frame, void *cookie,
}
shard_link_dot_shard_inode (local, inode, buf);
- shard_writev_create_write_shards (frame, this);
+ shard_common_resolve_shards (frame, this);
return 0;
unwind:
@@ -1460,7 +1432,7 @@ shard_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
if (!local->dot_shard_loc.inode)
shard_writev_mkdir_dot_shard (frame, this);
else
- shard_writev_create_write_shards (frame, this);
+ shard_common_resolve_shards (frame, this);
return 0;
out:
diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h
index 4c4637567da..879aa030991 100644
--- a/xlators/features/shard/src/shard.h
+++ b/xlators/features/shard/src/shard.h
@@ -65,7 +65,26 @@
shard_local_wipe (__local); \
mem_put (__local); \
} \
-} while (0) \
+} while (0)
+
+
+#define SHARD_INODE_CREATE_INIT(this, local, xattr_req, loc, label) do { \
+ int __ret = -1; \
+ shard_priv_t *__priv = NULL; \
+ \
+ __priv = this->private; \
+ \
+ local->block_size = hton64 (__priv->block_size); \
+ __ret = dict_set_static_bin (xattr_req, GF_XATTR_SHARD_BLOCK_SIZE, \
+ &local->block_size, \
+ sizeof (local->block_size)); \
+ if (__ret) { \
+ gf_log (this->name, GF_LOG_WARNING, "Failed to set key: %s " \
+ "on path %s", GF_XATTR_SHARD_BLOCK_SIZE, loc->path); \
+ goto label; \
+ } \
+ \
+} while (0)
typedef struct shard_priv {
uint64_t block_size;