summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2015-07-23 14:59:19 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2015-07-26 23:06:19 -0700
commitfd296d90168002a475a9899a72a0dd1811f038ee (patch)
tree5ca35dc8e73ea0b1722c82215c91a87e5fd70faf /xlators
parent7bec717f8850135368609fccf1b1c697af60c546 (diff)
posix,shard: Fill in ia_size and ia_blocks before unwinding (f)setattr
The shard xlator will request for size xattrs in its request and posix will perform xattr_fill of requested keys before unwinding (f)setattr. Change-Id: I4ec4779568be6f805724b875b1b4215787112e7f BUG: 1246082 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com> Reviewed-on: http://review.gluster.org/11754 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/features/shard/src/shard.c158
-rw-r--r--xlators/storage/posix/src/posix.c16
2 files changed, 155 insertions, 19 deletions
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index 681a403459c..da95b92ecd9 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -3465,13 +3465,54 @@ shard_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
}
int
-shard_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+shard_post_setattr_handler (call_frame_t *frame, xlator_t *this)
+{
+ shard_local_t *local = NULL;
+
+ local = frame->local;
+
+ if (local->fop == GF_FOP_SETATTR) {
+ SHARD_STACK_UNWIND (setattr, frame, local->op_ret,
+ local->op_errno, &local->prebuf,
+ &local->postbuf, local->xattr_rsp);
+ } else if (local->fop == GF_FOP_FSETATTR) {
+ SHARD_STACK_UNWIND (fsetattr, frame, local->op_ret,
+ local->op_errno, &local->prebuf,
+ &local->postbuf, local->xattr_rsp);
+ }
+
+ return 0;
+}
+
+int
+shard_common_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
struct iatt *postbuf, dict_t *xdata)
{
- /* To-Do: Call fsetattr on all shards. */
- SHARD_STACK_UNWIND (setattr, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
+ shard_local_t *local = NULL;
+
+ local = frame->local;
+
+ if (op_ret < 0) {
+ local->op_ret = op_ret;
+ local->op_errno = op_errno;
+ goto unwind;
+ }
+
+ local->prebuf = *prebuf;
+ if (shard_modify_size_and_block_count (&local->prebuf, xdata)) {
+ local->op_ret = -1;
+ local->op_errno = EINVAL;
+ goto unwind;
+ }
+ if (xdata)
+ local->xattr_rsp = dict_ref (xdata);
+ local->postbuf = *postbuf;
+ local->postbuf.ia_size = local->prebuf.ia_size;
+ local->postbuf.ia_blocks = local->prebuf.ia_blocks;
+
+unwind:
+ local->handler (frame, this);
return 0;
}
@@ -3479,20 +3520,55 @@ int
shard_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- STACK_WIND (frame, shard_setattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
+ int ret = -1;
+ uint64_t block_size = 0;
+ shard_local_t *local = NULL;
+
+ if ((IA_ISDIR (loc->inode->ia_type)) ||
+ (IA_ISLNK (loc->inode->ia_type))) {
+ STACK_WIND (frame, default_setattr_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->setattr, loc, stbuf,
+ valid, xdata);
+ return 0;
+ }
+
+ ret = shard_inode_ctx_get_block_size (loc->inode, this, &block_size);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get block size "
+ "from inode ctx of %s", uuid_utoa (loc->inode->gfid));
+ goto err;
+ }
+
+ if (!block_size) {
+ STACK_WIND (frame, default_setattr_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->setattr, loc, stbuf,
+ valid, xdata);
+ return 0;
+ }
+
+ local = mem_get0 (this->local_pool);
+ if (!local)
+ goto err;
+
+ frame->local = local;
+
+ local->handler = shard_post_setattr_handler;
+ local->xattr_req = (xdata) ? dict_ref (xdata) : dict_new ();
+ if (!local->xattr_req)
+ goto err;
+ local->fop = GF_FOP_SETATTR;
+
+ SHARD_MD_READ_FOP_INIT_REQ_DICT (this, local->xattr_req,
+ local->loc.gfid, local, err);
+
+ STACK_WIND (frame, shard_common_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid,
+ local->xattr_req);
return 0;
-}
-int
-shard_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
-{
- /* To-Do: Call fsetattr on all shards. */
- SHARD_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
+err:
+ SHARD_STACK_UNWIND (setattr, frame, -1, ENOMEM, NULL, NULL, NULL);
return 0;
}
@@ -3500,9 +3576,57 @@ int
shard_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- STACK_WIND (frame, shard_fsetattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
+ int ret = -1;
+ uint64_t block_size = 0;
+ shard_local_t *local = NULL;
+
+ if ((IA_ISDIR (fd->inode->ia_type)) ||
+ (IA_ISLNK (fd->inode->ia_type))) {
+ STACK_WIND (frame, default_fsetattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD (this)->fops->fsetattr, fd, stbuf,
+ valid, xdata);
+ return 0;
+ }
+ ret = shard_inode_ctx_get_block_size (fd->inode, this, &block_size);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get block size "
+ "from inode ctx of %s", uuid_utoa (fd->inode->gfid));
+ goto err;
+ }
+
+ if (!block_size) {
+ STACK_WIND (frame, default_fsetattr_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->fsetattr, fd, stbuf,
+ valid, xdata);
+ return 0;
+ }
+
+ if (!this->itable)
+ this->itable = fd->inode->table;
+
+ local = mem_get0 (this->local_pool);
+ if (!local)
+ goto err;
+
+ frame->local = local;
+
+ local->handler = shard_post_setattr_handler;
+ local->xattr_req = (xdata) ? dict_ref (xdata) : dict_new ();
+ if (!local->xattr_req)
+ goto err;
+ local->fop = GF_FOP_FSETATTR;
+
+ SHARD_MD_READ_FOP_INIT_REQ_DICT (this, local->xattr_req,
+ fd->inode->gfid, local, err);
+
+ STACK_WIND (frame, shard_common_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid,
+ local->xattr_req);
+ return 0;
+
+err:
+ SHARD_STACK_UNWIND (fsetattr, frame, -1, ENOMEM, NULL, NULL, NULL);
return 0;
}
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 7589e8c7cc2..047600e2e21 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -370,6 +370,7 @@ posix_setattr (call_frame_t *frame, xlator_t *this,
char * real_path = 0;
struct iatt statpre = {0,};
struct iatt statpost = {0,};
+ dict_t *xattr_rsp = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -441,13 +442,18 @@ posix_setattr (call_frame_t *frame, xlator_t *this,
goto out;
}
+ if (xdata)
+ xattr_rsp = posix_xattr_fill (this, real_path, loc, NULL, -1,
+ xdata, &statpost);
op_ret = 0;
out:
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno,
- &statpre, &statpost, NULL);
+ &statpre, &statpost, xattr_rsp);
+ if (xattr_rsp)
+ dict_unref (xattr_rsp);
return 0;
}
@@ -505,6 +511,7 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
struct iatt statpre = {0,};
struct iatt statpost = {0,};
struct posix_fd *pfd = NULL;
+ dict_t *xattr_rsp = NULL;
int32_t ret = -1;
DECLARE_OLD_FS_ID_VAR;
@@ -585,13 +592,18 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
goto out;
}
+ if (xdata)
+ xattr_rsp = posix_xattr_fill (this, NULL, NULL, fd, pfd->fd,
+ xdata, &statpost);
op_ret = 0;
out:
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno,
- &statpre, &statpost, NULL);
+ &statpre, &statpost, xattr_rsp);
+ if (xattr_rsp)
+ dict_unref (xattr_rsp);
return 0;
}