From 5d9668dbb4f20ec7ce385e1d348e46b1425e4e84 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Mon, 10 Aug 2015 19:10:21 +0530 Subject: features/shard: Ensure shards are owned by the same owner/group as the original file Backport of: http://review.gluster.org/#/c/11874/ Change-Id: I8c905917430c32eb2e6573968722920d3b27fb55 BUG: 1253151 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/11927 Tested-by: Gluster Build System Tested-by: NetBSD Build System Reviewed-by: Pranith Kumar Karampuri --- xlators/features/shard/src/shard.c | 73 ++++++++++++++++++++++---------------- xlators/features/shard/src/shard.h | 3 ++ 2 files changed, 45 insertions(+), 31 deletions(-) (limited to 'xlators/features/shard/src') diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c index 52b95472ba7..ba1579f1170 100644 --- a/xlators/features/shard/src/shard.c +++ b/xlators/features/shard/src/shard.c @@ -2551,8 +2551,11 @@ shard_common_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, done: call_count = shard_call_count_return (frame); - if (call_count == 0) + if (call_count == 0) { + frame->root->uid = local->uid; + frame->root->gid = local->gid; local->post_mknod_handler (frame, this); + } return 0; } @@ -2581,9 +2584,14 @@ shard_common_resume_mknod (call_frame_t *frame, xlator_t *this, fd = local->fd; shard_idx_iter = local->first_block; last_block = local->last_block; - call_count = local->call_count; + call_count = local->call_count = local->create_count; local->post_mknod_handler = post_mknod_handler; + local->uid = frame->root->uid; + local->gid = frame->root->gid; + frame->root->uid = local->prebuf.ia_uid; + frame->root->gid = local->prebuf.ia_gid; + ret = shard_inode_ctx_get_all (fd->inode, this, &ctx_tmp); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to get inode ctx for" @@ -2697,11 +2705,13 @@ shard_post_resolve_readv_handler (call_frame_t *frame, xlator_t *this) } } - if (local->call_count) + if (local->call_count) { + local->create_count = local->call_count; shard_common_resume_mknod (frame, this, shard_post_mknod_readv_handler); - else + } else { shard_readv_do (frame, this); + } return 0; } @@ -3033,7 +3043,7 @@ next: } int -shard_post_lookup_writev_handler (call_frame_t *frame, xlator_t *this) +shard_post_lookup_shards_writev_handler (call_frame_t *frame, xlator_t *this) { shard_local_t *local = NULL; @@ -3045,21 +3055,13 @@ shard_post_lookup_writev_handler (call_frame_t *frame, xlator_t *this) return 0; } - local->postbuf = local->prebuf; - - /* At this point, calculate the size of the hole if it is going to be - * created as part of this write. - */ - if (local->offset > local->prebuf.ia_size) - local->hole_size = local->offset - local->prebuf.ia_size; - shard_writev_do (frame, this); return 0; } int -shard_post_lookup_shards_writev_handler (call_frame_t *frame, xlator_t *this) +shard_post_mknod_writev_handler (call_frame_t *frame, xlator_t *this) { shard_local_t *local = NULL; @@ -3071,13 +3073,19 @@ shard_post_lookup_shards_writev_handler (call_frame_t *frame, xlator_t *this) return 0; } - shard_lookup_base_file (frame, this, &local->loc, - shard_post_lookup_writev_handler); + if (!local->eexist_count) { + shard_writev_do (frame, this); + } else { + local->call_count = local->eexist_count; + shard_common_lookup_shards (frame, this, local->loc.inode, + shard_post_lookup_shards_writev_handler); + } + return 0; } int -shard_post_mknod_writev_handler (call_frame_t *frame, xlator_t *this) +shard_post_lookup_writev_handler (call_frame_t *frame, xlator_t *this) { shard_local_t *local = NULL; @@ -3089,14 +3097,19 @@ shard_post_mknod_writev_handler (call_frame_t *frame, xlator_t *this) return 0; } - if (!local->eexist_count) { - shard_lookup_base_file (frame, this, &local->loc, - shard_post_lookup_writev_handler); - } else { - local->call_count = local->eexist_count; - shard_common_lookup_shards (frame, this, local->loc.inode, - shard_post_lookup_shards_writev_handler); - } + local->postbuf = local->prebuf; + + /* At this point, calculate the size of the hole if it is going to be + * created as part of this write. + */ + if (local->offset > local->prebuf.ia_size) + local->hole_size = local->offset - local->prebuf.ia_size; + + if (local->create_count) + shard_common_resume_mknod (frame, this, + shard_post_mknod_writev_handler); + else + shard_writev_do (frame, this); return 0; } @@ -3114,12 +3127,10 @@ shard_post_resolve_writev_handler (call_frame_t *frame, xlator_t *this) return 0; } - if (local->call_count) - shard_common_resume_mknod (frame, this, - shard_post_mknod_writev_handler); - else - shard_lookup_base_file (frame, this, &local->loc, - shard_post_lookup_writev_handler); + local->create_count = local->call_count; + + shard_lookup_base_file (frame, this, &local->loc, + shard_post_lookup_writev_handler); return 0; } diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h index 9307cee071d..e6144a29e68 100644 --- a/xlators/features/shard/src/shard.h +++ b/xlators/features/shard/src/shard.h @@ -149,9 +149,12 @@ typedef struct shard_local { int num_blocks; int call_count; int eexist_count; + int create_count; int xflag; int count; uint32_t flags; + uint32_t uid; + uint32_t gid; uint64_t block_size; uint64_t dst_block_size; off_t offset; -- cgit