3604df
From 9cab3d31da4bfd5784215fe394b46bcfc6214bfd Mon Sep 17 00:00:00 2001
3604df
From: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
Date: Tue, 12 Jul 2016 15:44:23 +0530
3604df
Subject: [PATCH 55/86] glusterd/ganesha : Move ganesha-ha.conf and ganesha.conf to shared storage
3604df
3604df
Currently all the ganesha related configuration files(ganesha.conf,
3604df
ganesha-ha.conf, export files, etc) is stored locally at /etc/ganesha
3604df
on a every node in ganesha cluster. Usually we end up in two issues by
3604df
doing so :
3604df
* difficult in modifiying ganesha related conf file
3604df
* diffciult to maintain consistency of conf file across ganesha cluster
3604df
To tackle this, we plan to move all the ganesha configuration to shared
3604df
storage. As a first step in this patch ganesha.conf and ganesha-ha.conf
3604df
move to shared storage. Here actual ganesha.conf will resides in shared
3604df
stoarge and symlinks will be created in /etc/ganesha when the option
3604df
"gluster nfs-ganesha enable" is executed and remove those during the
3604df
"disable" part.
3604df
3604df
Modified prerequisites to done before running globaloption:
3604df
	* enable shared storage
3604df
	* create nfs-ganesha folder in shared storage
3604df
	* create ganesha.conf and ganesha-ha.conf in it
3604df
3604df
More details can be found at http://review.gluster.org/#/c/15105/
3604df
3604df
Upstream reference :
3604df
>Change-Id: Ifabb6c5db50061f077a03932940190af74e2ca7f
3604df
>BUG: 1355956
3604df
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
>Reviewed-on: http://review.gluster.org/14906
3604df
>Reviewed-by: soumya k <skoduri@redhat.com>
3604df
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
>Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
3604df
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
3604df
Change-Id: Ifabb6c5db50061f077a03932940190af74e2ca7f
3604df
BUG: 1348949
3604df
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84776
3604df
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 extras/ganesha/scripts/ganesha-ha.sh         |   34 ++++++++--
3604df
 xlators/mgmt/glusterd/src/Makefile.am        |    2 +-
3604df
 xlators/mgmt/glusterd/src/glusterd-ganesha.c |  101 +++++++++++++++++++++-----
3604df
 xlators/mgmt/glusterd/src/glusterd-op-sm.c   |   19 ++++--
3604df
 4 files changed, 125 insertions(+), 31 deletions(-)
3604df
3604df
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
3604df
index 8b55abb..31c0c39 100644
3604df
--- a/extras/ganesha/scripts/ganesha-ha.sh
3604df
+++ b/extras/ganesha/scripts/ganesha-ha.sh
3604df
@@ -22,9 +22,9 @@
3604df
 
3604df
 HA_NUM_SERVERS=0
3604df
 HA_SERVERS=""
3604df
-HA_CONFDIR="/etc/ganesha"
3604df
 HA_VOL_NAME="gluster_shared_storage"
3604df
 HA_VOL_MNT="/var/run/gluster/shared_storage"
3604df
+HA_CONFDIR=$HA_VOL_MNT"/nfs-ganesha"
3604df
 SERVICE_MAN="DISTRO_NOT_FOUND"
3604df
 
3604df
 RHEL6_PCS_CNAME_OPTION="--name"
3604df
@@ -416,12 +416,8 @@ teardown_cluster()
3604df
 
3604df
 cleanup_ganesha_config ()
3604df
 {
3604df
-       rm -rf ${HA_CONFDIR}/exports/*.conf
3604df
-       rm -rf ${HA_CONFDIR}/.export_added
3604df
        rm -rf /etc/cluster/cluster.conf*
3604df
        rm -rf /var/lib/pacemaker/cib/*
3604df
-       sed -r -i -e '/^%include[[:space:]]+".+\.conf"$/d' ${GANESHA_CONF}
3604df
-       rm -rf ${HA_VOL_MNT}/nfs-ganesha
3604df
 }
3604df
 
3604df
 do_create_virt_ip_constraints()
3604df
@@ -830,6 +826,29 @@ status()
3604df
     rm -f ${status_file}
3604df
 }
3604df
 
3604df
+create_ganesha_conf_file()
3604df
+{
3604df
+        if [ $1 == "yes" ];
3604df
+        then
3604df
+                if [  -e $GANESHA_CONF ];
3604df
+                then
3604df
+                        rm -rf $GANESHA_CONF
3604df
+                fi
3604df
+        # The symlink /etc/ganesha/ganesha.conf need to be
3604df
+        # created using ganesha conf file mentioned in the
3604df
+        # shared storage. Every node will only have this
3604df
+        # link and actual file will stored in shared storage,
3604df
+        # so that ganesha conf editing of ganesha conf will
3604df
+        # be easy as well as it become more consistent.
3604df
+
3604df
+                ln -s $HA_CONFDIR/ganesha.conf $GANESHA_CONF
3604df
+        else
3604df
+        # Restoring previous file
3604df
+                rm -rf $GANESHA_CONF
3604df
+                sed -r -i -e '/^%include[[:space:]]+".+\.conf"$/d' $HA_CONFDIR/ganesha.conf
3604df
+                cp $HA_CONFDIR/ganesha.conf $GANESHA_CONF
3604df
+        fi
3604df
+}
3604df
 
3604df
 main()
3604df
 {
3604df
@@ -971,6 +990,11 @@ $HA_CONFDIR/ganesha-ha.conf
3604df
         refresh_config ${VOL} ${HA_CONFDIR} ${HA_SERVERS}
3604df
         ;;
3604df
 
3604df
+    setup-ganesha-conf-files | --setup-ganesha-conf-files)
3604df
+
3604df
+        create_ganesha_conf_file ${1}
3604df
+        ;;
3604df
+
3604df
     *)
3604df
         # setup and teardown are not intended to be used by a
3604df
         # casual user
3604df
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am
3604df
index f3381e3..23840cd 100644
3604df
--- a/xlators/mgmt/glusterd/src/Makefile.am
3604df
+++ b/xlators/mgmt/glusterd/src/Makefile.am
3604df
@@ -47,7 +47,7 @@ AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
3604df
 	-I$(CONTRIBDIR)/userspace-rcu \
3604df
 	-DSBIN_DIR=\"$(sbindir)\" -DDATADIR=\"$(localstatedir)\" \
3604df
 	-DGSYNCD_PREFIX=\"$(libexecdir)/glusterfs\" \
3604df
-	-DCONFDIR=\"$(sysconfdir)/ganesha\" \
3604df
+	-DCONFDIR=\"/$(runstatedir)/gluster/shared_storage/nfs-ganesha\" \
3604df
 	-DGANESHA_PREFIX=\"$(libexecdir)/ganesha\" \
3604df
 	-DSYNCDAEMON_COMPILE=$(SYNCDAEMON_COMPILE) $(XML_CPPFLAGS)
3604df
 
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
index d34ec05..3d9a10e 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
@@ -22,8 +22,6 @@
3604df
 
3604df
 #include <ctype.h>
3604df
 
3604df
-#define SHARED_STORAGE_MNT "/var/run/gluster/shared_storage/nfs-ganesha"
3604df
-
3604df
 int start_ganesha (char **op_errstr);
3604df
 
3604df
 
3604df
@@ -267,6 +265,11 @@ glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr)
3604df
                                 "Could not start NFS-Ganesha");
3604df
 
3604df
                 }
3604df
+        } else {
3604df
+                ret =  stop_ganesha (op_errstr);
3604df
+                if (ret)
3604df
+                        gf_msg_debug (THIS->name, 0, "Could not stop "
3604df
+                                                "NFS-Ganesha.");
3604df
         }
3604df
 
3604df
 out:
3604df
@@ -638,8 +641,12 @@ out:
3604df
 int
3604df
 tear_down_cluster(void)
3604df
 {
3604df
-        int     ret     =       0;
3604df
-        runner_t runner =       {0,};
3604df
+        int     ret                     = 0;
3604df
+        runner_t runner                 = {0,};
3604df
+        struct stat     st              = {0,};
3604df
+        DIR            *dir             = NULL;
3604df
+        struct dirent  *entry           = NULL;
3604df
+        char            path[PATH_MAX]  = {0,};
3604df
 
3604df
         if (is_ganesha_host()) {
3604df
                 runinit (&runner);
3604df
@@ -647,7 +654,55 @@ tear_down_cluster(void)
3604df
                                 GANESHA_PREFIX"/ganesha-ha.sh", "teardown",
3604df
                                 CONFDIR, NULL);
3604df
                 ret = runner_run(&runner);
3604df
+                /* *
3604df
+                 * Remove all the entries in CONFDIR expect ganesha.conf and
3604df
+                 * ganesha-ha.conf
3604df
+                 */
3604df
+                dir = sys_opendir (CONFDIR);
3604df
+                if (!dir) {
3604df
+                        gf_msg_debug (THIS->name, 0, "Failed to open directory %s. "
3604df
+                                      "Reason : %s", CONFDIR, strerror (errno));
3604df
+                        ret = 0;
3604df
+                        goto out;
3604df
+                }
3604df
+
3604df
+                GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
3604df
+                while (entry) {
3604df
+                        snprintf (path, PATH_MAX, "%s/%s", CONFDIR, entry->d_name);
3604df
+                        ret = sys_lstat (path, &st);
3604df
+                        if (ret == -1) {
3604df
+                                gf_msg_debug (THIS->name, 0, "Failed to stat entry %s :"
3604df
+                                              " %s", path, strerror (errno));
3604df
+                                goto out;
3604df
+                        }
3604df
+
3604df
+                        if (strcmp(entry->d_name, "ganesha.conf") == 0 ||
3604df
+                            strcmp(entry->d_name, "ganesha-ha.conf") == 0)
3604df
+                                gf_msg_debug (THIS->name, 0, " %s is not required"
3604df
+                                                " to remove", path);
3604df
+                        else if (S_ISDIR (st.st_mode))
3604df
+                                ret = recursive_rmdir (path);
3604df
+                        else
3604df
+                                ret = sys_unlink (path);
3604df
+
3604df
+                        if (ret) {
3604df
+                                gf_msg_debug (THIS->name, 0, " Failed to remove %s. "
3604df
+                                      "Reason : %s", path, strerror (errno));
3604df
+                        }
3604df
+
3604df
+                        gf_msg_debug (THIS->name, 0, "%s %s", ret ?
3604df
+                                      "Failed to remove" : "Removed", entry->d_name);
3604df
+                        GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
3604df
+                }
3604df
+
3604df
+                ret = sys_closedir (dir);
3604df
+                if (ret) {
3604df
+                        gf_msg_debug (THIS->name, 0, "Failed to close dir %s. Reason :"
3604df
+                                      " %s", CONFDIR, strerror (errno));
3604df
+                }
3604df
         }
3604df
+
3604df
+out:
3604df
         return ret;
3604df
 }
3604df
 
3604df
@@ -685,11 +740,6 @@ teardown (char **op_errstr)
3604df
                              " HA config failed.");
3604df
                 goto out;
3604df
         }
3604df
-        ret =  stop_ganesha (op_errstr);
3604df
-        if (ret) {
3604df
-                gf_asprintf (op_errstr, "Could not stop NFS-Ganesha.");
3604df
-                goto out;
3604df
-        }
3604df
 
3604df
         runinit (&runner);
3604df
         runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
3604df
@@ -733,7 +783,17 @@ out:
3604df
 int
3604df
 stop_ganesha (char **op_errstr) {
3604df
 
3604df
-        int ret = 0;
3604df
+        int ret                 = 0;
3604df
+        runner_t runner         = {0,};
3604df
+
3604df
+        runinit (&runner);
3604df
+        runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
3604df
+                         "--setup-ganesha-conf-files", CONFDIR, "no", NULL);
3604df
+        ret =  runner_run (&runner);
3604df
+        if (ret) {
3604df
+                gf_asprintf (op_errstr, "removal of symlink ganesha.conf "
3604df
+                             "in /etc/ganesha failed");
3604df
+        }
3604df
 
3604df
         if (check_host_list ()) {
3604df
                 ret = manage_service ("stop");
3604df
@@ -755,6 +815,7 @@ start_ganesha (char **op_errstr)
3604df
         int count                                          = 0;
3604df
         char *volname                                      = NULL;
3604df
         glusterd_conf_t *priv                              = NULL;
3604df
+        runner_t runner                                    = {0,};
3604df
 
3604df
         priv =  THIS->private;
3604df
         GF_ASSERT (priv);
3604df
@@ -789,6 +850,16 @@ start_ganesha (char **op_errstr)
3604df
                         goto out;
3604df
                 }
3604df
         }
3604df
+
3604df
+        runinit (&runner);
3604df
+        runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
3604df
+                         "--setup-ganesha-conf-files", CONFDIR, "yes", NULL);
3604df
+        ret =  runner_run (&runner);
3604df
+        if (ret) {
3604df
+                gf_asprintf (op_errstr, "creation of symlink ganesha.conf "
3604df
+                             "in /etc/ganesha failed");
3604df
+                goto out;
3604df
+        }
3604df
         if (check_host_list()) {
3604df
                 ret = manage_service ("start");
3604df
                 if (ret)
3604df
@@ -805,15 +876,6 @@ pre_setup (char **op_errstr)
3604df
 {
3604df
         int    ret = 0;
3604df
 
3604df
-        ret = sys_mkdir (SHARED_STORAGE_MNT, 0775);
3604df
-
3604df
-        if ((-1 == ret) && (EEXIST != errno)) {
3604df
-                gf_msg ("THIS->name", GF_LOG_ERROR, errno,
3604df
-                        GD_MSG_CREATE_DIR_FAILED, "mkdir() failed on path %s,",
3604df
-                        SHARED_STORAGE_MNT);
3604df
-                goto out;
3604df
-        }
3604df
-
3604df
         ret = check_host_list();
3604df
 
3604df
         if (ret) {
3604df
@@ -824,7 +886,6 @@ pre_setup (char **op_errstr)
3604df
                                      "Please check the log file for details");
3604df
         }
3604df
 
3604df
-out:
3604df
         return ret;
3604df
 }
3604df
 
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
index d138e81..4b88570 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
@@ -1422,10 +1422,14 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
3604df
         char                                    *key_fixed = NULL;
3604df
         glusterd_volinfo_t                      *volinfo       = NULL;
3604df
         xlator_t                                *this = NULL;
3604df
+        glusterd_conf_t                         *priv    = NULL;
3604df
 
3604df
         this = THIS;
3604df
         GF_ASSERT (this);
3604df
 
3604df
+        priv = this->private;
3604df
+        GF_ASSERT (priv);
3604df
+
3604df
         ret = dict_get_str (dict, "volname", &volname);
3604df
 
3604df
         if (ret) {
3604df
@@ -1452,6 +1456,16 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
3604df
                 ret = glusterd_validate_volume_id (dict, volinfo);
3604df
                 if (ret)
3604df
                         goto out;
3604df
+                ret = dict_get_str_boolean (priv->opts,
3604df
+                            GLUSTERD_STORE_KEY_GANESHA_GLOBAL, _gf_false);
3604df
+                if (ret) {
3604df
+                        ret =  stop_ganesha (op_errstr);
3604df
+                        if (ret)
3604df
+                                gf_msg (THIS->name, GF_LOG_WARNING, 0,
3604df
+                                        GD_MSG_NFS_GNS_STOP_FAIL,
3604df
+                                        "Could not stop NFS-Ganesha service");
3604df
+                }
3604df
+
3604df
         }
3604df
 
3604df
         ret = dict_get_str (dict, "key", &key);
3604df
@@ -2038,11 +2052,6 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict)
3604df
                         gf_msg (THIS->name, GF_LOG_WARNING, errno,
3604df
                                 GD_MSG_DICT_GET_FAILED,
3604df
                                 "Could not tear down NFS-Ganesha cluster");
3604df
-                ret =  stop_ganesha (&op_errstr);
3604df
-                if (ret)
3604df
-                        gf_msg (THIS->name, GF_LOG_WARNING, 0,
3604df
-                                GD_MSG_NFS_GNS_STOP_FAIL,
3604df
-                                "Could not stop NFS-Ganesha service");
3604df
         }
3604df
 
3604df
         ret = -1;
3604df
-- 
3604df
1.7.1
3604df