21ab4e
From 2baa37f5bd2d29c30e0154758449ac1980fc8db1 Mon Sep 17 00:00:00 2001
21ab4e
From: Poornima G <pgurusid@redhat.com>
21ab4e
Date: Thu, 6 Apr 2017 16:36:29 +0530
21ab4e
Subject: [PATCH 382/393] glusterd: Add validation for options rda-cache-limit
21ab4e
 rda-request-size
21ab4e
21ab4e
Currently when prarallel readdir is enabled, setting any junk value
21ab4e
to rda-cache-limit and rda-request-size succeeds. This is because of
21ab4e
bug in the special handling of these options.
21ab4e
21ab4e
Fixing the same in this patch.
21ab4e
21ab4e
>Reviewed-on: https://review.gluster.org/17008
21ab4e
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Signed-off-by: Poornima G <pgurusid@redhat.com>
21ab4e
21ab4e
Change-Id: I902cd9ac9134c158ab6f8aea4b001254a03547bd
21ab4e
BUG: 1438245
21ab4e
Signed-off-by: Poornima G <pgurusid@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/103634
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 tests/bugs/readdir-ahead/bug-1439640.t          | 30 ++++++++++++++++++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-volgen.c     | 41 ++++++++++++++++++++-----
21ab4e
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |  1 +
21ab4e
 3 files changed, 65 insertions(+), 7 deletions(-)
21ab4e
 create mode 100755 tests/bugs/readdir-ahead/bug-1439640.t
21ab4e
21ab4e
diff --git a/tests/bugs/readdir-ahead/bug-1439640.t b/tests/bugs/readdir-ahead/bug-1439640.t
21ab4e
new file mode 100755
21ab4e
index 0000000..cfa5d1f
21ab4e
--- /dev/null
21ab4e
+++ b/tests/bugs/readdir-ahead/bug-1439640.t
21ab4e
@@ -0,0 +1,30 @@
21ab4e
+#!/bin/bash
21ab4e
+
21ab4e
+. $(dirname $0)/../../include.rc
21ab4e
+. $(dirname $0)/../../volume.rc
21ab4e
+
21ab4e
+cleanup;
21ab4e
+
21ab4e
+TEST glusterd
21ab4e
+
21ab4e
+TEST $CLI volume create $V0 $H0:$B{0..1}/$V0
21ab4e
+TEST $CLI volume start $V0
21ab4e
+
21ab4e
+TEST ! $CLI volume set $V0 parallel-readdir sdf
21ab4e
+
21ab4e
+TEST $CLI volume set $V0 parallel-readdir off
21ab4e
+TEST $CLI volume set $V0 parallel-readdir on
21ab4e
+
21ab4e
+TEST ! $CLI volume set $V0 rda-cache-limit 0
21ab4e
+TEST ! $CLI volume set $V0 rda-cache-limit -634
21ab4e
+TEST ! $CLI volume set $V0 rda-cache-limit 87adh
21ab4e
+TEST ! $CLI volume set $V0 parallel-readdir sdf
21ab4e
+
21ab4e
+TEST ! $CLI volume set $V0 rda-request-size 0
21ab4e
+TEST ! $CLI volume set $V0 rda-request-size -634
21ab4e
+TEST ! $CLI volume set $V0 rda-request-size 87adh
21ab4e
+
21ab4e
+TEST $CLI volume set $V0 rda-cache-limit 10MB
21ab4e
+TEST $CLI volume set $V0 rda-request-size 128KB
21ab4e
+
21ab4e
+#cleanup;
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
index c906306..6e52d44 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
@@ -3624,17 +3624,44 @@ client_graph_set_rda_options (volgen_graph_t *graph,
21ab4e
             !glusterd_volinfo_get_boolean (volinfo, VKEY_READDIR_AHEAD))
21ab4e
                 goto out;
21ab4e
 
21ab4e
-        ret = glusterd_volinfo_get (volinfo, VKEY_RDA_CACHE_LIMIT, &rda_cache_s);
21ab4e
-        if (ret < 0)
21ab4e
+        /* glusterd_volinfo_get() will get the default value if nothing set
21ab4e
+         * explicitly. Hence it is important to check set_dict before checking
21ab4e
+         * glusterd_volinfo_get, so that we consider key value of the in
21ab4e
+         * progress volume set option.
21ab4e
+         */
21ab4e
+        ret = dict_get_str (set_dict, VKEY_RDA_CACHE_LIMIT, &rda_cache_s);
21ab4e
+        if (ret < 0) {
21ab4e
+                ret = glusterd_volinfo_get (volinfo, VKEY_RDA_CACHE_LIMIT,
21ab4e
+                                            &rda_cache_s);
21ab4e
+                if (ret < 0)
21ab4e
+                        goto out;
21ab4e
+        }
21ab4e
+        ret = gf_string2bytesize_uint64 (rda_cache_s, &rda_cache_size);
21ab4e
+        if (ret < 0) {
21ab4e
+                set_graph_errstr (graph, "invalid number format in option "
21ab4e
+                                  VKEY_RDA_CACHE_LIMIT);
21ab4e
                 goto out;
21ab4e
+        }
21ab4e
 
21ab4e
-        gf_string2bytesize_uint64 (rda_cache_s, &rda_cache_size);
21ab4e
-
21ab4e
-        ret = glusterd_volinfo_get (volinfo, VKEY_RDA_REQUEST_SIZE, &rda_req_s);
21ab4e
-        if (ret < 0)
21ab4e
+        ret = dict_get_str (set_dict, VKEY_RDA_REQUEST_SIZE, &rda_req_s);
21ab4e
+        if (ret < 0) {
21ab4e
+                ret = glusterd_volinfo_get (volinfo, VKEY_RDA_REQUEST_SIZE,
21ab4e
+                                            &rda_req_s);
21ab4e
+                if (ret < 0)
21ab4e
+                        goto out;
21ab4e
+        }
21ab4e
+        gf_string2bytesize_uint64 (rda_req_s, &rda_req_size);
21ab4e
+        if (ret < 0) {
21ab4e
+                set_graph_errstr (graph, "invalid number format in option "
21ab4e
+                                  VKEY_RDA_REQUEST_SIZE);
21ab4e
                 goto out;
21ab4e
+        }
21ab4e
 
21ab4e
-        gf_string2bytesize_uint64 (rda_req_s, &rda_req_size);
21ab4e
+        if (rda_cache_size == 0 || rda_req_size == 0) {
21ab4e
+                set_graph_errstr (graph, "Value cannot be 0");
21ab4e
+                ret = -1;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
 
21ab4e
         new_cache_size = rda_cache_size / dist_count;
21ab4e
         if (new_cache_size < rda_req_size) {
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
index e619401..4a1c780 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
21ab4e
@@ -3024,6 +3024,7 @@ struct volopt_map_entry glusterd_volopt_map[] = {
21ab4e
           .value       = "off",
21ab4e
           .type        = DOC,
21ab4e
           .op_version  = GD_OP_VERSION_3_10_0,
21ab4e
+          .validate_fn = validate_boolean,
21ab4e
           .description = "If this option is enabled, the readdir operation is "
21ab4e
                          "performed parallely on all the bricks, thus improving"
21ab4e
                          " the performance of readdir. Note that the performance"
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e