cb8e9e
From 5311950675dee5588d5eaae5e064e4fd06216343 Mon Sep 17 00:00:00 2001
cb8e9e
From: Pranith Kumar K <pkarampu@redhat.com>
cb8e9e
Date: Sat, 9 May 2015 23:11:15 +0530
cb8e9e
Subject: [PATCH 21/57] worm: Let lock, zero xattrop calls succeed
cb8e9e
cb8e9e
        Backport of http://review.gluster.org/10727
cb8e9e
cb8e9e
Locks can be taken just to inspect the data as well, so allow them.
cb8e9e
Xattrops are internal fops so we can allow them as well as longs as
cb8e9e
it doesn't change the xattr value, i.e. All-zero xattrop.
cb8e9e
cb8e9e
BUG: 1227172
cb8e9e
Change-Id: I9e72806e0605ab2938348a87935966909f1a721f
cb8e9e
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/50311
cb8e9e
---
cb8e9e
 xlators/features/read-only/src/read-only-common.c |   74 ++++++++++++---------
cb8e9e
 1 files changed, 42 insertions(+), 32 deletions(-)
cb8e9e
cb8e9e
diff --git a/xlators/features/read-only/src/read-only-common.c b/xlators/features/read-only/src/read-only-common.c
cb8e9e
index 39937d1..24e9903 100644
cb8e9e
--- a/xlators/features/read-only/src/read-only-common.c
cb8e9e
+++ b/xlators/features/read-only/src/read-only-common.c
cb8e9e
@@ -30,11 +30,29 @@ is_readonly_or_worm_enabled (xlator_t *this)
cb8e9e
         return readonly_or_worm_enabled;
cb8e9e
 }
cb8e9e
 
cb8e9e
+static int
cb8e9e
+_check_key_is_zero_filled (dict_t *d, char *k, data_t *v,
cb8e9e
+                           void *tmp)
cb8e9e
+{
cb8e9e
+        if (mem_0filled ((const char *)v->data, v->len)) {
cb8e9e
+                /* -1 means, no more iterations, treat as 'break' */
cb8e9e
+                return -1;
cb8e9e
+        }
cb8e9e
+        return 0;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int32_t
cb8e9e
 ro_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc,
cb8e9e
             gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
+        gf_boolean_t allzero = _gf_false;
cb8e9e
+        int     ret = 0;
cb8e9e
+
cb8e9e
+        ret = dict_foreach (dict, _check_key_is_zero_filled, NULL);
cb8e9e
+        if (ret == 0)
cb8e9e
+                allzero = _gf_true;
cb8e9e
+
cb8e9e
+        if (is_readonly_or_worm_enabled (this) && !allzero)
cb8e9e
                 STACK_UNWIND_STRICT (xattrop, frame, -1, EROFS, NULL, xdata);
cb8e9e
         else
cb8e9e
                 STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
@@ -47,7 +65,14 @@ int32_t
cb8e9e
 ro_fxattrop (call_frame_t *frame, xlator_t *this,
cb8e9e
              fd_t *fd, gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
+        gf_boolean_t allzero = _gf_false;
cb8e9e
+        int     ret = 0;
cb8e9e
+
cb8e9e
+        ret = dict_foreach (dict, _check_key_is_zero_filled, NULL);
cb8e9e
+        if (ret == 0)
cb8e9e
+                allzero = _gf_true;
cb8e9e
+
cb8e9e
+        if (is_readonly_or_worm_enabled (this) && !allzero)
cb8e9e
                 STACK_UNWIND_STRICT (fxattrop, frame, -1, EROFS, NULL, xdata);
cb8e9e
         else
cb8e9e
                 STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
@@ -62,12 +87,9 @@ ro_entrylk (call_frame_t *frame, xlator_t *this, const char *volume,
cb8e9e
             loc_t *loc, const char *basename, entrylk_cmd cmd,
cb8e9e
             entrylk_type type, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
-                STACK_UNWIND_STRICT (entrylk, frame, -1, EROFS, xdata);
cb8e9e
-        else
cb8e9e
-                STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
-                                 FIRST_CHILD(this)->fops->entrylk,
cb8e9e
-                                 volume, loc, basename, cmd, type, xdata);
cb8e9e
+        STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
+                         FIRST_CHILD(this)->fops->entrylk,
cb8e9e
+                         volume, loc, basename, cmd, type, xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -77,12 +99,9 @@ ro_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume,
cb8e9e
              fd_t *fd, const char *basename, entrylk_cmd cmd, entrylk_type type,
cb8e9e
              dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
-                STACK_UNWIND_STRICT (fentrylk, frame, -1, EROFS, xdata);
cb8e9e
-        else
cb8e9e
-                STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
-                                 FIRST_CHILD(this)->fops->fentrylk,
cb8e9e
-                                 volume, fd, basename, cmd, type, xdata);
cb8e9e
+        STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
+                         FIRST_CHILD(this)->fops->fentrylk,
cb8e9e
+                         volume, fd, basename, cmd, type, xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -91,12 +110,9 @@ int32_t
cb8e9e
 ro_inodelk (call_frame_t *frame, xlator_t *this, const char *volume,
cb8e9e
             loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
-                STACK_UNWIND_STRICT (inodelk, frame, -1, EROFS, xdata);
cb8e9e
-        else
cb8e9e
-                STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
-                                 FIRST_CHILD(this)->fops->inodelk,
cb8e9e
-                                 volume, loc, cmd, lock, xdata);
cb8e9e
+        STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
+                         FIRST_CHILD(this)->fops->inodelk,
cb8e9e
+                         volume, loc, cmd, lock, xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -105,12 +121,9 @@ int32_t
cb8e9e
 ro_finodelk (call_frame_t *frame, xlator_t *this, const char *volume,
cb8e9e
              fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
-                STACK_UNWIND_STRICT (finodelk, frame, -1, EROFS, xdata);
cb8e9e
-        else
cb8e9e
-                STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
-                                 FIRST_CHILD(this)->fops->finodelk,
cb8e9e
-                                 volume, fd, cmd, lock, xdata);
cb8e9e
+        STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
+                         FIRST_CHILD(this)->fops->finodelk,
cb8e9e
+                         volume, fd, cmd, lock, xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
@@ -119,12 +132,9 @@ int32_t
cb8e9e
 ro_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int cmd,
cb8e9e
        struct gf_flock *flock, dict_t *xdata)
cb8e9e
 {
cb8e9e
-        if (is_readonly_or_worm_enabled (this))
cb8e9e
-                STACK_UNWIND_STRICT (lk, frame, -1, EROFS, NULL, xdata);
cb8e9e
-        else
cb8e9e
-                STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
-                                 FIRST_CHILD(this)->fops->lk, fd, cmd, flock,
cb8e9e
-                                 xdata);
cb8e9e
+        STACK_WIND_TAIL (frame, FIRST_CHILD (this),
cb8e9e
+                         FIRST_CHILD(this)->fops->lk, fd, cmd, flock,
cb8e9e
+                         xdata);
cb8e9e
 
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e