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