diff options
author | Pranith Kumar K <pkarampu@redhat.com> | 2015-05-09 23:11:15 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2015-05-29 04:47:28 -0700 |
commit | 15a28c2b70003434d448a67d66ff722294e816f7 (patch) | |
tree | 0daaffb2f95bc6869592abdb7643d8adfdc696d6 | |
parent | b0fb6eb3071ce45a8964423237577d1d9b9605d9 (diff) |
worm: Let lock, zero xattrop calls succeed
Locks can be taken just to inspect the data as well, so allow them.
Xattrops are internal fops so we can allow them as well as longs as
it doesn't change the xattr value, i.e. All-zero xattrop.
Change-Id: Idc06d2043eb472c064db40d811a80058f0bda378
BUG: 1211123
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/10727
Reviewed-by: Xavier Hernandez <xhernandez@datalab.es>
Tested-by: NetBSD Build System
-rw-r--r-- | xlators/features/read-only/src/read-only-common.c | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/xlators/features/read-only/src/read-only-common.c b/xlators/features/read-only/src/read-only-common.c index 39937d106c5..24e99036b3c 100644 --- a/xlators/features/read-only/src/read-only-common.c +++ b/xlators/features/read-only/src/read-only-common.c @@ -30,11 +30,29 @@ is_readonly_or_worm_enabled (xlator_t *this) return readonly_or_worm_enabled; } +static int +_check_key_is_zero_filled (dict_t *d, char *k, data_t *v, + void *tmp) +{ + if (mem_0filled ((const char *)v->data, v->len)) { + /* -1 means, no more iterations, treat as 'break' */ + return -1; + } + return 0; +} + int32_t ro_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) + gf_boolean_t allzero = _gf_false; + int ret = 0; + + ret = dict_foreach (dict, _check_key_is_zero_filled, NULL); + if (ret == 0) + allzero = _gf_true; + + if (is_readonly_or_worm_enabled (this) && !allzero) STACK_UNWIND_STRICT (xattrop, frame, -1, EROFS, NULL, xdata); else STACK_WIND_TAIL (frame, FIRST_CHILD (this), @@ -47,7 +65,14 @@ int32_t ro_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) + gf_boolean_t allzero = _gf_false; + int ret = 0; + + ret = dict_foreach (dict, _check_key_is_zero_filled, NULL); + if (ret == 0) + allzero = _gf_true; + + if (is_readonly_or_worm_enabled (this) && !allzero) STACK_UNWIND_STRICT (fxattrop, frame, -1, EROFS, NULL, xdata); else STACK_WIND_TAIL (frame, FIRST_CHILD (this), @@ -62,12 +87,9 @@ ro_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, const char *basename, entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) - STACK_UNWIND_STRICT (entrylk, frame, -1, EROFS, xdata); - else - STACK_WIND_TAIL (frame, FIRST_CHILD (this), - FIRST_CHILD(this)->fops->entrylk, - volume, loc, basename, cmd, type, xdata); + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD(this)->fops->entrylk, + volume, loc, basename, cmd, type, xdata); return 0; } @@ -77,12 +99,9 @@ ro_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd, const char *basename, entrylk_cmd cmd, entrylk_type type, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) - STACK_UNWIND_STRICT (fentrylk, frame, -1, EROFS, xdata); - else - STACK_WIND_TAIL (frame, FIRST_CHILD (this), - FIRST_CHILD(this)->fops->fentrylk, - volume, fd, basename, cmd, type, xdata); + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD(this)->fops->fentrylk, + volume, fd, basename, cmd, type, xdata); return 0; } @@ -91,12 +110,9 @@ int32_t ro_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) - STACK_UNWIND_STRICT (inodelk, frame, -1, EROFS, xdata); - else - STACK_WIND_TAIL (frame, FIRST_CHILD (this), - FIRST_CHILD(this)->fops->inodelk, - volume, loc, cmd, lock, xdata); + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD(this)->fops->inodelk, + volume, loc, cmd, lock, xdata); return 0; } @@ -105,12 +121,9 @@ int32_t ro_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) - STACK_UNWIND_STRICT (finodelk, frame, -1, EROFS, xdata); - else - STACK_WIND_TAIL (frame, FIRST_CHILD (this), - FIRST_CHILD(this)->fops->finodelk, - volume, fd, cmd, lock, xdata); + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD(this)->fops->finodelk, + volume, fd, cmd, lock, xdata); return 0; } @@ -119,12 +132,9 @@ int32_t ro_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int cmd, struct gf_flock *flock, dict_t *xdata) { - if (is_readonly_or_worm_enabled (this)) - STACK_UNWIND_STRICT (lk, frame, -1, EROFS, NULL, xdata); - else - STACK_WIND_TAIL (frame, FIRST_CHILD (this), - FIRST_CHILD(this)->fops->lk, fd, cmd, flock, - xdata); + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD(this)->fops->lk, fd, cmd, flock, + xdata); return 0; } |