e7a346
From 6683f3c2702f635a95623c427f343385a1ad8c63 Mon Sep 17 00:00:00 2001
e7a346
From: jiffin tony thottan <jthottan@redhat.com>
e7a346
Date: Mon, 7 Dec 2015 14:38:54 +0530
e7a346
Subject: [PATCH 55/74] glusterd/ganesha : throw proper error for "gluster
e7a346
 nfs-ganesha disable"
e7a346
e7a346
For first time or if "gluster nfs-ganesha enable" fails the global option
e7a346
"nfs-ganesha" won't be stored in glusterd's dictionary. In both cases the
e7a346
"gluster nfs-ganesha disable" throws following error :
e7a346
"nfs-ganesha: failed: nfs-ganesha is already (null)d."
e7a346
e7a346
Also this patch provides the missing prompt for nfs-ganesha disable in 3.10
e7a346
e7a346
Change-Id: I7c9fd6dabedc0cfb14c5190b3554bc63a6bc0340
e7a346
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
e7a346
Reviewed-on: https://review.gluster.org/16791
e7a346
Smoke: Gluster Build System <jenkins@build.gluster.org>
e7a346
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
e7a346
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
e7a346
Reviewed-by: soumya k <skoduri@redhat.com>
e7a346
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
e7a346
---
e7a346
 cli/src/cli-cmd-parser.c                     | 30 ++++++++++++++++++----------
e7a346
 xlators/mgmt/glusterd/src/glusterd-ganesha.c | 28 +++++++++-----------------
e7a346
 2 files changed, 28 insertions(+), 30 deletions(-)
e7a346
e7a346
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
e7a346
index a4c601b..a35fc74 100644
e7a346
--- a/cli/src/cli-cmd-parser.c
e7a346
+++ b/cli/src/cli-cmd-parser.c
e7a346
@@ -897,18 +897,26 @@ cli_cmd_ganesha_parse (struct cli_state *state,
e7a346
                 goto out;
e7a346
         }
e7a346
 
e7a346
-        question = "Enabling NFS-Ganesha requires Gluster-NFS to be"
e7a346
-                   " disabled across the trusted pool. Do you "
e7a346
-                   "still want to continue?\n";
e7a346
-
e7a346
         if (strcmp (value, "enable") == 0) {
e7a346
-                answer = cli_cmd_get_confirmation (state, question);
e7a346
-                if (GF_ANSWER_NO == answer) {
e7a346
-                        gf_log ("cli", GF_LOG_ERROR, "Global operation "
e7a346
-                                "cancelled, exiting");
e7a346
-                        ret = -1;
e7a346
-                        goto out;
e7a346
-                }
e7a346
+                question = "Enabling NFS-Ganesha requires Gluster-NFS to be "
e7a346
+                           "disabled across the trusted pool. Do you "
e7a346
+                           "still want to continue?\n";
e7a346
+
e7a346
+        } else if (strcmp (value, "disable") == 0) {
e7a346
+                question = "Disabling NFS-Ganesha will tear down the entire "
e7a346
+                           "ganesha cluster across the trusted pool. Do you "
e7a346
+                           "still want to continue?\n";
e7a346
+        } else {
e7a346
+                ret = -1;
e7a346
+                goto out;
e7a346
+        }
e7a346
+
e7a346
+        answer = cli_cmd_get_confirmation (state, question);
e7a346
+        if (GF_ANSWER_NO == answer) {
e7a346
+                gf_log ("cli", GF_LOG_ERROR, "Global operation "
e7a346
+                        "cancelled, exiting");
e7a346
+                ret = -1;
e7a346
+                goto out;
e7a346
         }
e7a346
         cli_out ("This will take a few minutes to complete. Please wait ..");
e7a346
 
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
e7a346
index e176df9..5c582cd 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
e7a346
@@ -258,8 +258,7 @@ int
e7a346
 glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr)
e7a346
 {
e7a346
         int                             ret                     = -1;
e7a346
-        int                             value                   = -1;
e7a346
-        gf_boolean_t                    option                  = _gf_false;
e7a346
+        char                            *value                  = NULL;
e7a346
         char                            *str                    = NULL;
e7a346
         glusterd_conf_t                 *priv                   = NULL;
e7a346
         xlator_t                        *this                   = NULL;
e7a346
@@ -270,8 +269,8 @@ glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr)
e7a346
         priv = this->private;
e7a346
         GF_ASSERT (priv);
e7a346
 
e7a346
-        value = dict_get_str_boolean (dict, "value", _gf_false);
e7a346
-        if (value == -1) {
e7a346
+        ret = dict_get_str (dict, "value", &value);
e7a346
+        if (value == NULL) {
e7a346
                 gf_msg (this->name, GF_LOG_ERROR, errno,
e7a346
                         GD_MSG_DICT_GET_FAILED,
e7a346
                         "value not present.");
e7a346
@@ -280,22 +279,13 @@ glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr)
e7a346
         /* This dict_get will fail if the user had never set the key before */
e7a346
         /*Ignoring the ret value and proceeding */
e7a346
         ret = dict_get_str (priv->opts, GLUSTERD_STORE_KEY_GANESHA_GLOBAL, &str);
e7a346
-        if (ret == -1) {
e7a346
-                gf_msg (this->name, GF_LOG_WARNING, errno,
e7a346
-                        GD_MSG_DICT_GET_FAILED, "Global dict not present.");
e7a346
-                ret = 0;
e7a346
-                goto out;
e7a346
+        /* Check if the feature is already enabled/disable, fail in that case */
e7a346
+        if (str ? strcmp (value, str) == 0 : strcmp (value, "disable") == 0) {
e7a346
+                gf_asprintf (op_errstr, "nfs-ganesha is already %sd.", value);
e7a346
+                 ret = -1;
e7a346
+                 goto out;
e7a346
         }
e7a346
-        /* Validity of the value is already checked */
e7a346
-        ret = gf_string2boolean (str, &option);
e7a346
-        /* Check if the feature is already enabled, fail in that case */
e7a346
-        if (value == option) {
e7a346
-                gf_asprintf (op_errstr, "nfs-ganesha is already %sd.", str);
e7a346
-                ret = -1;
e7a346
-                goto out;
e7a346
-        }
e7a346
-
e7a346
-        if (value) {
e7a346
+        if (strcmp (value, "enable") == 0) {
e7a346
                 ret =  start_ganesha (op_errstr);
e7a346
                 if (ret) {
e7a346
                         gf_msg (THIS->name, GF_LOG_ERROR, 0,
e7a346
-- 
e7a346
1.8.3.1
e7a346