12a457
From abcb46358062e0c99f4f679141a387f6b942491d Mon Sep 17 00:00:00 2001
12a457
From: Gaurav Kumar Garg <garg.gaurav52@gmail.com>
12a457
Date: Mon, 14 Mar 2016 14:36:11 +0530
12a457
Subject: [PATCH 03/26] glusterd: disabling enable-shared-storage option should not delete volume
12a457
12a457
This patch is a backport of: http://review.gluster.org/#/c/12232/
12a457
12a457
Previously, when you create volume with "glusterd_shared_storage" name
12a457
and if user disable, enable-shared-storage option then gluster will
12a457
delete the "glusterd_shared_storage" volume.
12a457
12a457
With this fix gluster will do appropriate validation of
12a457
enable-shared-storage option and it will not delete volume with
12a457
"glusterd_shared_storage" name if it is a user created volume.
12a457
12a457
Change-Id: I8cb160fece702a730e25dadbc740e74efc57483e
12a457
BUG: 1319695
12a457
12a457
  >> Change-Id: I2bd92f938fb3de6ef496a934933bdcea9f251491
12a457
  >> BUG: 1266818
12a457
  >> Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
12a457
  >> Reviewed-on: http://review.gluster.org/12232
12a457
  >> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
12a457
  >> Reviewed-by: Anand Nekkunti <anekkunt@redhat.com>
12a457
  >> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
12a457
  >> Tested-by: Gluster Build System <jenkins@build.gluster.com>
12a457
12a457
Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
12a457
Change-Id: Ida3dccbb5829b5442b057ffb9b7b7e90955f338a
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/70335
12a457
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
12a457
Tested-by: Atin Mukherjee <amukherj@redhat.com>
12a457
---
12a457
 .../glusterd/bug-1266818-shared-storage-disable.t  |   36 ++++++++++++++++++++
12a457
 xlators/mgmt/glusterd/src/glusterd-messages.h      |    2 +-
12a457
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |   28 ++++++++++++---
12a457
 3 files changed, 60 insertions(+), 6 deletions(-)
12a457
 create mode 100644 tests/bugs/glusterd/bug-1266818-shared-storage-disable.t
12a457
12a457
diff --git a/tests/bugs/glusterd/bug-1266818-shared-storage-disable.t b/tests/bugs/glusterd/bug-1266818-shared-storage-disable.t
12a457
new file mode 100644
12a457
index 0000000..a9ccf1b
12a457
--- /dev/null
12a457
+++ b/tests/bugs/glusterd/bug-1266818-shared-storage-disable.t
12a457
@@ -0,0 +1,36 @@
12a457
+#!/bin/bash
12a457
+
12a457
+## Test case for BZ 1266818;
12a457
+## Disabling enable-shared-storage option should not delete user created
12a457
+## volume with name glusterd_shared_storage
12a457
+
12a457
+. $(dirname $0)/../../include.rc
12a457
+. $(dirname $0)/../../volume.rc
12a457
+. $(dirname $0)/../../cluster.rc
12a457
+
12a457
+cleanup;
12a457
+
12a457
+## Start a 2 node virtual cluster
12a457
+TEST launch_cluster 2;
12a457
+
12a457
+## Peer probe server 2 from server 1 cli
12a457
+TEST $CLI_1 peer probe $H2;
12a457
+
12a457
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
12a457
+
12a457
+## Creating a volume with name glusterd_shared_storage
12a457
+TEST $CLI_1 volume create glusterd_shared_storage  $H1:$B1/${V0}0 $H2:$B1/${V0}1
12a457
+
12a457
+## Disabling enable-shared-storage should not succeed and should not delete the
12a457
+## user created volume with name "glusterd_shared_storage"
12a457
+TEST ! $CLI_1 volume all enable-shared-storage disable
12a457
+
12a457
+## Volume with name should exist
12a457
+TEST $CLI_1 volume info glusterd_shared_storage
12a457
+
12a457
+cleanup;
12a457
+
12a457
+
12a457
+
12a457
+
12a457
+
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
index 9b3f517..8dcbcdb 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
@@ -46,7 +46,7 @@
12a457
 
12a457
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
12a457
 
12a457
-#define GLFS_NUM_MESSAGES       568
12a457
+#define GLFS_NUM_MESSAGES       573
12a457
 
12a457
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
12a457
 /* Messaged with message IDs */
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
12a457
index 86b6c48..444408f 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
12a457
@@ -778,13 +778,19 @@ out:
12a457
 static int
12a457
 glusterd_validate_shared_storage (char *key, char *value, char *errstr)
12a457
 {
12a457
-        int32_t       ret      = -1;
12a457
-        int32_t       exists   = -1;
12a457
-        int32_t       count    = -1;
12a457
-        xlator_t     *this     = NULL;
12a457
+        int32_t            ret      = -1;
12a457
+        int32_t            exists   = -1;
12a457
+        int32_t            count    = -1;
12a457
+        char              *op       = NULL;
12a457
+        xlator_t          *this     = NULL;
12a457
+        glusterd_conf_t   *conf     = NULL;
12a457
 
12a457
         this = THIS;
12a457
         GF_VALIDATE_OR_GOTO ("glusterd", this, out);
12a457
+
12a457
+        conf = this->private;
12a457
+        GF_VALIDATE_OR_GOTO (this->name, conf, out);
12a457
+
12a457
         GF_VALIDATE_OR_GOTO (this->name, key, out);
12a457
         GF_VALIDATE_OR_GOTO (this->name, value, out);
12a457
         GF_VALIDATE_OR_GOTO (this->name, errstr, out);
12a457
@@ -806,7 +812,19 @@ glusterd_validate_shared_storage (char *key, char *value, char *errstr)
12a457
                 goto out;
12a457
         }
12a457
 
12a457
-        if (strcmp (value, "enable")) {
12a457
+        if (!strncmp (value, "disable", strlen ("disable"))) {
12a457
+                ret = dict_get_str (conf->opts, GLUSTERD_SHARED_STORAGE_KEY,
12a457
+                                                                           &op);
12a457
+                if (ret || !strncmp (op, "disable", strlen ("disable"))) {
12a457
+                        snprintf (errstr, PATH_MAX, "Shared storage volume "
12a457
+                                  "does not exist. Please enable shared storage"
12a457
+                                  " for creating shared storage volume.");
12a457
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
+                                GD_MSG_SHARED_STORAGE_DOES_NOT_EXIST, "%s",
12a457
+                                errstr);
12a457
+                        ret = -1;
12a457
+                        goto out;
12a457
+                }
12a457
                 goto out;
12a457
         }
12a457
 
12a457
-- 
12a457
1.7.1
12a457