Blob Blame History Raw
From 945286d6bdd8813e4c107be282cffe64bbeac44f Mon Sep 17 00:00:00 2001
From: Jiffin Tony Thottan <jthottan@redhat.com>
Date: Wed, 23 Nov 2016 16:04:26 +0530
Subject: [PATCH 230/235] glusterd/ganesha : handle volume reset properly for
 ganesha options

The "gluster volume reset" should first unexport the volume and then delete
export configuration file. Also reset option is not applicable for ganesha.enable
if volume value is "all".
This patch also changes the name of create_export_config into manange_export_config

Upstream reference :
>Change-Id: Ie81a49e7d3e39a88bca9fbae5002bfda5cab34af
>BUG: 1397795
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
>Reviewed-on: http://review.gluster.org/15914
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: soumya k <skoduri@redhat.com>
>Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>

Change-Id: Ie81a49e7d3e39a88bca9fbae5002bfda5cab34af
BUG: 1397450
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/92365
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 extras/hook-scripts/reset/post/Makefile.am         |  5 +-
 extras/hook-scripts/reset/post/S31ganesha-reset.sh | 48 ------------------
 glusterfs.spec.in                                  |  4 +-
 xlators/mgmt/glusterd/src/glusterd-ganesha.c       |  6 +--
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         | 57 ++++++++++------------
 xlators/mgmt/glusterd/src/glusterd.h               |  2 +-
 6 files changed, 35 insertions(+), 87 deletions(-)
 delete mode 100755 extras/hook-scripts/reset/post/S31ganesha-reset.sh

diff --git a/extras/hook-scripts/reset/post/Makefile.am b/extras/hook-scripts/reset/post/Makefile.am
index bb28d99..1b336ac 100644
--- a/extras/hook-scripts/reset/post/Makefile.am
+++ b/extras/hook-scripts/reset/post/Makefile.am
@@ -1,4 +1 @@
-EXTRA_DIST = S31ganesha-reset.sh
-
-hookdir = $(GLUSTERD_WORKDIR)/hooks/1/reset/post/
-hook_SCRIPTS = S31ganesha-reset.sh
+EXTRA_DIST =
diff --git a/extras/hook-scripts/reset/post/S31ganesha-reset.sh b/extras/hook-scripts/reset/post/S31ganesha-reset.sh
deleted file mode 100755
index 9538911..0000000
--- a/extras/hook-scripts/reset/post/S31ganesha-reset.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-
-PROGNAME="Sganesha-reset"
-OPTSPEC="volname:,gd-workdir:"
-VOL=
-GLUSTERD_WORKDIR=
-
-function parse_args () {
-        ARGS=$(getopt -l $OPTSPEC  -o "o" -name $PROGNAME $@)
-        eval set -- "$ARGS"
-        while true; do
-            case $1 in
-                --volname)
-                    shift
-                    VOL=$1
-                    ;;
-                --gd-workdir)
-                    shift
-                    GLUSTERD_WORKDIR=$1
-                    ;;
-                 *)
-                    shift
-                    break
-                    ;;
-            esac
-            shift
-        done
-}
-
-function is_volume_started () {
-        volname=$1
-        echo "$(grep status $GLUSTERD_WORKDIR/vols/"$volname"/info |\
-                cut -d"=" -f2)"
-}
-
-parse_args $@
-if ps aux | grep -q "[g]anesha.nfsd"
-        then
-        kill -s TERM `cat /var/run/ganesha.pid`
-        sleep 10
-        rm -rf /var/lib/glusterfs-ganesha/exports
-        rm -rf /var/lib/glusterfs-ganesha/.export_added
-        sed -i /conf/d /var/lib/ganesha/nfs-ganesha.conf
-        if [ "1" = $(is_volume_started "$VOL") ];
-                then
-                gluster volume start $VOL force
-        fi
-fi
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index f2231b3..9b29de3 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -1226,7 +1226,6 @@ exit 0
 %{_libexecdir}/ganesha/*
 %{_prefix}/lib/ocf/resource.d/heartbeat/*
 %{_sharedstatedir}/glusterd/hooks/1/start/post/S31ganesha-start.sh
-%{_sharedstatedir}/glusterd/hooks/1/reset/post/S31ganesha-reset.sh
 %endif
 
 %if ( 0%{?_build_server} )
@@ -2047,6 +2046,9 @@ end
 %endif
 
 %changelog
+* Thu Dec 7 2016 Jiffin Tony Thottan <jhottan@redhat.com>
+- remove S31ganesha-reset.sh from hooks (#1397450)
+
 * Fri Nov 18 2016 Soumya Koduri <skoduri@redhat.com>
 - As an interim fix add dependency on netstat(/net-tools) for glusterfs-ganesha package (#1395574)
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
index 670c21f..470d455 100644
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
@@ -216,7 +216,7 @@ glusterd_check_ganesha_cmd (char *key, char *value, char **errstr, dict_t *dict)
                                 "Unable to get volume name");
                                 goto out;
                         }
-                        ret = create_export_config (volname, "off", errstr);
+                        ret = manage_export_config (volname, "off", errstr);
                  }
         }
 out:
@@ -433,7 +433,7 @@ check_host_list (void)
 }
 
 int
-create_export_config (char *volname, char *value, char **op_errstr)
+manage_export_config (char *volname, char *value, char **op_errstr)
 {
         runner_t                runner                     = {0,};
         int                     ret                        = -1;
@@ -536,7 +536,7 @@ ganesha_manage_export (dict_t *dict, char *value, char **op_errstr)
          * is executed
          * */
          if (option) {
-                ret  =  create_export_config (volname, "on", op_errstr);
+                ret  = manage_export_config (volname, "on", op_errstr);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_EXPORT_FILE_CREATE_FAIL,
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 9afeb52..31b16e8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1500,15 +1500,6 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
                 ret = glusterd_validate_volume_id (dict, volinfo);
                 if (ret)
                         goto out;
-                ret = dict_get_str_boolean (priv->opts,
-                            GLUSTERD_STORE_KEY_GANESHA_GLOBAL, _gf_false);
-                if (ret) {
-                        ret =  stop_ganesha (op_errstr);
-                        if (ret)
-                                gf_msg (THIS->name, GF_LOG_WARNING, 0,
-                                        GD_MSG_NFS_GNS_STOP_FAIL,
-                                        "Could not stop NFS-Ganesha service");
-                }
 
         }
 
@@ -1518,7 +1509,23 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
                         GD_MSG_DICT_GET_FAILED, "Unable to get option key");
                 goto out;
         }
-        if (strcmp(key, "all")) {
+
+        /* *
+         * If key ganesha.enable is set, then volume should be unexported from
+         * ganesha server. Also it is a volume-level option, perform only when
+         * volume name not equal to "all"(in other words if volinfo != NULL)
+         */
+        if (volinfo && (!strcmp (key, "all") || !strcmp(key, "ganesha.enable"))) {
+                if (glusterd_check_ganesha_export (volinfo)) {
+                        ret = ganesha_manage_export (dict, "off", op_errstr);
+                        if (ret)
+                                gf_msg (this->name, GF_LOG_WARNING, 0,
+                                        GD_MSG_NFS_GNS_RESET_FAIL,
+                                        "Could not reset ganesha.enable key");
+                }
+        }
+
+       if (strcmp(key, "all")) {
                 exists = glusterd_check_option_exists (key, &key_fixed);
                 if (exists == -1) {
                         ret = -1;
@@ -2058,7 +2065,6 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict)
         gf_boolean_t    all             = _gf_false;
         char            *next_version   = NULL;
         gf_boolean_t    quorum_action   = _gf_false;
-        gf_boolean_t     option         = _gf_false;
         char            *op_errstr      = NULL;
 
         conf = this->private;
@@ -2088,15 +2094,6 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict)
 
         if (key_fixed)
                 key = key_fixed;
-        option = dict_get_str_boolean (conf->opts, GLUSTERD_STORE_KEY_GANESHA_GLOBAL,
-                            _gf_false);
-        if (option) {
-                ret = tear_down_cluster (is_origin_glusterd (dict));
-                if (ret == -1)
-                        gf_msg (THIS->name, GF_LOG_WARNING, errno,
-                                GD_MSG_DICT_GET_FAILED,
-                                "Could not tear down NFS-Ganesha cluster");
-        }
 
         ret = -1;
         dup_opt = dict_new ();
@@ -2205,16 +2202,6 @@ glusterd_op_reset_volume (dict_t *dict, char **op_rspstr)
 
         if (glusterd_is_quorum_changed (volinfo->dict, key, NULL))
                 quorum_action = _gf_true;
-        ret = glusterd_check_ganesha_export (volinfo);
-        if (ret) {
-                ret = ganesha_manage_export (dict, "off", op_rspstr);
-                if (ret) {
-                        gf_msg (THIS->name, GF_LOG_WARNING, 0,
-                                GD_MSG_NFS_GNS_RESET_FAIL,
-                                "Could not reset ganesha.enable key");
-                        ret = 0;
-                }
-        }
 
         ret = glusterd_options_reset (volinfo, key, &is_force);
         if (ret == -1) {
@@ -2231,6 +2218,16 @@ glusterd_op_reset_volume (dict_t *dict, char **op_rspstr)
                 }
         }
 
+        if (!strcmp(key, "ganesha.enable") || !strcmp (key, "all")) {
+                if (glusterd_check_ganesha_export (volinfo)) {
+                        ret = manage_export_config (volname, "off", op_rspstr);
+                        if (ret)
+                                gf_msg (this->name, GF_LOG_WARNING, 0,
+                                        GD_MSG_NFS_GNS_RESET_FAIL,
+                                        "Could not reset ganesha.enable key");
+                }
+         }
+
 out:
         GF_FREE (key_fixed);
         if (quorum_action)
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 23b7623..b926383 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -1076,7 +1076,7 @@ int glusterd_check_ganesha_cmd (char *key, char *value,
 int glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr);
 int glusterd_op_set_ganesha (dict_t *dict, char **errstr);
 int ganesha_manage_export (dict_t *dict, char *value, char **op_errstr);
-int create_export_config (char *volname, char *value, char **op_errstr);
+int manage_export_config (char *volname, char *value, char **op_errstr);
 gf_boolean_t glusterd_check_ganesha_export (glusterd_volinfo_t *volinfo);
 int stop_ganesha (char **op_errstr);
 int tear_down_cluster (gf_boolean_t run_teardown);
-- 
2.9.3