3604df
From 74a0dd4ffd4bae7e5b304edf2b1b3991b15df65b Mon Sep 17 00:00:00 2001
3604df
From: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
Date: Wed, 13 Jul 2016 11:38:10 +0530
3604df
Subject: [PATCH 61/86] glusterd/ganesha : create export configuration file in shared storage
3604df
3604df
This is the second patch which moves export related configuration for
3604df
a volume into shared storage. The main change includes in scripts
3604df
create-export-ganesha.sh, dbus-send.sh and the handling of volume set
3604df
command "ganesha.enable". The manipulation of EXPORT_ID move from
3604df
dbus-send.sh to create-export-ganesha.sh.
3604df
3604df
In volume set handling following has performed
3604df
3604df
    stage                  |    commit
3604df
----------------------------------------------------------
3604df
1.) gluster v set <volname> ganesha.enable on
3604df
3604df
 None			   |	create export file
3604df
			   |    in node where cli executed,
3604df
			   |	thne export volume via dbus
3604df
3604df
2.) gluster v set <volname> ganesha.enable off
3604df
3604df
unexport volume via dbus   |	remove export file from the
3604df
			   |    shared storage
3604df
-----------------------------------------------------------
3604df
3604df
More details can be found at http://review.gluster.org/#/c/15105/
3604df
3604df
Upstream reference :
3604df
>Change-Id: Ia8b0e89bc8fff24b0bc5d20a538a89212894a8e4
3604df
>BUG: 1355956
3604df
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
>Reviewed-on: http://review.gluster.org/14908
3604df
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: soumya k <skoduri@redhat.com>
3604df
>Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
3604df
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
3604df
Change-Id: Ia8b0e89bc8fff24b0bc5d20a538a89212894a8e4
3604df
BUG: 1344675
3604df
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84780
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 extras/ganesha/scripts/create-export-ganesha.sh |   54 ++++++++++-----------
3604df
 extras/ganesha/scripts/dbus-send.sh             |   59 +---------------------
3604df
 xlators/mgmt/glusterd/src/glusterd-ganesha.c    |   55 ++++++++++++++-------
3604df
 xlators/mgmt/glusterd/src/glusterd-op-sm.c      |    6 ++
3604df
 xlators/mgmt/glusterd/src/glusterd.h            |    1 +
3604df
 5 files changed, 72 insertions(+), 103 deletions(-)
3604df
3604df
diff --git a/extras/ganesha/scripts/create-export-ganesha.sh b/extras/ganesha/scripts/create-export-ganesha.sh
3604df
index a1a35db..1ffba42 100755
3604df
--- a/extras/ganesha/scripts/create-export-ganesha.sh
3604df
+++ b/extras/ganesha/scripts/create-export-ganesha.sh
3604df
@@ -21,14 +21,17 @@ if [ -f /etc/default/ganesha ]
3604df
 fi
3604df
 
3604df
 GANESHA_DIR=${1%/}
3604df
-VOL=$2
3604df
-CONF=
3604df
+OPTION=$2
3604df
+VOL=$3
3604df
+CONF=$GANESHA_DIR"/ganesha.conf"
3604df
+declare -i EXPORT_ID
3604df
 
3604df
 function check_cmd_status()
3604df
 {
3604df
         if [ "$1" != "0" ]
3604df
                  then
3604df
                  rm -rf $GANESHA_DIR/exports/export.$VOL.conf
3604df
+                 sed -i /$VOL.conf/d $CONF
3604df
                  exit 1
3604df
         fi
3604df
 }
3604df
@@ -40,28 +43,6 @@ if [ ! -d "$GANESHA_DIR/exports" ];
3604df
         check_cmd_status `echo $?`
3604df
 fi
3604df
 
3604df
-function find_rhel7_conf
3604df
-{
3604df
- while [[ $# > 0 ]]
3604df
-        do
3604df
-                key="$1"
3604df
-                case $key in
3604df
-                        -f)
3604df
-                         CONFFILE="$2"
3604df
-                         ;;
3604df
-                         *)
3604df
-                         ;;
3604df
-                 esac
3604df
-                 shift
3604df
-         done
3604df
-}
3604df
-
3604df
-if [ -z $CONFFILE ]; then
3604df
-        find_rhel7_conf $OPTIONS
3604df
-
3604df
-fi
3604df
-CONF=${CONFFILE:-/etc/ganesha/ganesha.conf}
3604df
-
3604df
 function write_conf()
3604df
 {
3604df
 echo -e "# WARNING : Using Gluster CLI will overwrite manual
3604df
@@ -85,9 +66,26 @@ echo '      Transports = "UDP","TCP";'
3604df
 echo '      SecType = "sys";'
3604df
 echo "     }"
3604df
 }
3604df
-
3604df
-write_conf $@ > $GANESHA_DIR/exports/export.$VOL.conf
3604df
-if ! (cat $CONF | grep  $VOL.conf\"$ )
3604df
+if [ "$OPTION" = "on" ];
3604df
 then
3604df
-echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF
3604df
+        if ! (cat $CONF | grep  $VOL.conf\"$ )
3604df
+        then
3604df
+                write_conf $@ > $GANESHA_DIR/exports/export.$VOL.conf
3604df
+                echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF
3604df
+                count=`ls -l $GANESHA_DIR/exports/*.conf | wc -l`
3604df
+                if [ "$count" = "1" ] ; then
3604df
+                        EXPORT_ID=2
3604df
+                else
3604df
+                        EXPORT_ID=`cat $GANESHA_DIR/.export_added`
3604df
+                        check_cmd_status `echo $?`
3604df
+                        EXPORT_ID=EXPORT_ID+1
3604df
+                        sed -i s/Export_Id.*/"Export_Id= $EXPORT_ID ;"/ \
3604df
+                        $GANESHA_DIR/exports/export.$VOL.conf
3604df
+                        check_cmd_status `echo $?`
3604df
+                fi
3604df
+                echo $EXPORT_ID > $GANESHA_DIR/.export_added
3604df
+        fi
3604df
+else
3604df
+        rm -rf $GANESHA_DIR/exports/export.$VOL.conf
3604df
+        sed -i /$VOL.conf/d $CONF
3604df
 fi
3604df
diff --git a/extras/ganesha/scripts/dbus-send.sh b/extras/ganesha/scripts/dbus-send.sh
3604df
index 14af095..c071d03 100755
3604df
--- a/extras/ganesha/scripts/dbus-send.sh
3604df
+++ b/extras/ganesha/scripts/dbus-send.sh
3604df
@@ -15,71 +15,22 @@ if [ -f /etc/default/ganesha ]
3604df
         . /etc/default/ganesha
3604df
 fi
3604df
 
3604df
-declare -i EXPORT_ID
3604df
 GANESHA_DIR=${1%/}
3604df
 OPTION=$2
3604df
 VOL=$3
3604df
-CONF=
3604df
-
3604df
-function find_rhel7_conf
3604df
-{
3604df
- while [[ $# > 0 ]]
3604df
-        do
3604df
-                key="$1"
3604df
-                case $key in
3604df
-                        -f)
3604df
-                         CONFFILE="$2"
3604df
-                         break;
3604df
-                         ;;
3604df
-                         *)
3604df
-                         ;;
3604df
-                 esac
3604df
-                 shift
3604df
-         done
3604df
-}
3604df
-
3604df
-if [ -z $CONFFILE ]
3604df
-        then
3604df
-        find_rhel7_conf $OPTIONS
3604df
-
3604df
-fi
3604df
-
3604df
-CONF=${CONFFILE:-/etc/ganesha/ganesha.conf}
3604df
+CONF=$GANESHA_DIR"/ganesha.conf"
3604df
 
3604df
 function check_cmd_status()
3604df
 {
3604df
         if [ "$1" != "0" ]
3604df
-                 then
3604df
-                 rm -rf $GANESHA_DIR/exports/export.$VOL.conf
3604df
-                 sed -i /$VOL.conf/d $CONF
3604df
-                 exit 1
3604df
+        then
3604df
+                logger "dynamic export failed on node :${hostname -s}"
3604df
         fi
3604df
 }
3604df
 
3604df
 #This function keeps track of export IDs and increments it with every new entry
3604df
 function dynamic_export_add()
3604df
 {
3604df
-        count=`ls -l $GANESHA_DIR/exports/*.conf | wc -l`
3604df
-        if [ "$count" = "1" ] ;
3604df
-                then
3604df
-                EXPORT_ID=2
3604df
-        else
3604df
-        #if [ -s /var/lib/ganesha/export_removed ];
3604df
-        #               then
3604df
-        #               EXPORT_ID=`head -1 /var/lib/ganesha/export_removed`
3604df
-        #               sed -i -e "1d" /var/lib/ganesha/export_removed
3604df
-        #               else
3604df
-
3604df
-                 EXPORT_ID=`cat $GANESHA_DIR/.export_added`
3604df
-                 check_cmd_status `echo $?`
3604df
-                 EXPORT_ID=EXPORT_ID+1
3604df
-        #fi
3604df
-        fi
3604df
-        echo $EXPORT_ID > $GANESHA_DIR/.export_added
3604df
-        check_cmd_status `echo $?`
3604df
-        sed -i s/Export_Id.*/"Export_Id= $EXPORT_ID ;"/ \
3604df
-$GANESHA_DIR/exports/export.$VOL.conf
3604df
-        check_cmd_status `echo $?`
3604df
         dbus-send  --system \
3604df
 --dest=org.ganesha.nfsd  /org/ganesha/nfsd/ExportMgr \
3604df
 org.ganesha.nfsd.exportmgr.AddExport  string:$GANESHA_DIR/exports/export.$VOL.conf \
3604df
@@ -92,14 +43,10 @@ function dynamic_export_remove()
3604df
 {
3604df
         removed_id=`cat $GANESHA_DIR/exports/export.$VOL.conf |\
3604df
 grep Export_Id | awk -F"[=,;]" '{print$2}'| tr -d '[[:space:]]'`
3604df
-        check_cmd_status `echo $?`
3604df
         dbus-send --print-reply --system \
3604df
 --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
3604df
 org.ganesha.nfsd.exportmgr.RemoveExport uint16:$removed_id
3604df
         check_cmd_status `echo $?`
3604df
-        sed -i /$VOL.conf/d $CONF
3604df
-        rm -rf $GANESHA_DIR/exports/export.$VOL.conf
3604df
-
3604df
 }
3604df
 
3604df
 if [ "$OPTION" = "on" ];
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
index 38fc1f6..670c21f 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
3604df
@@ -180,17 +180,22 @@ glusterd_check_ganesha_export (glusterd_volinfo_t *volinfo) {
3604df
         return is_exported;
3604df
 }
3604df
 
3604df
-
3604df
+/* *
3604df
+ * The below function is called as part of commit phase for volume set option
3604df
+ * "ganesha.enable". If the value is "on", it creates export configuration file
3604df
+ * and then export the volume via dbus command. Incase of "off", the volume
3604df
+ * will be already unexported during stage phase, so it will remove the conf
3604df
+ * file from shared storage
3604df
+ */
3604df
 int
3604df
 glusterd_check_ganesha_cmd (char *key, char *value, char **errstr, dict_t *dict)
3604df
 {
3604df
         int                ret = 0;
3604df
-        xlator_t                *this = NULL;
3604df
+        char               *volname = NULL;
3604df
 
3604df
-        this = THIS;
3604df
-        GF_ASSERT (this);
3604df
         GF_ASSERT (key);
3604df
         GF_ASSERT (value);
3604df
+        GF_ASSERT (dict);
3604df
 
3604df
         if ((strcmp (key, "ganesha.enable") == 0)) {
3604df
                 if ((strcmp (value, "on")) && (strcmp (value, "off"))) {
3604df
@@ -199,15 +204,28 @@ glusterd_check_ganesha_cmd (char *key, char *value, char **errstr, dict_t *dict)
3604df
                         ret = -1;
3604df
                         goto out;
3604df
                 }
3604df
-                ret = glusterd_handle_ganesha_op (dict, errstr, key, value);
3604df
-                if (ret) {
3604df
-                        gf_msg (this->name, GF_LOG_ERROR, 0,
3604df
-                                GD_MSG_NFS_GNS_OP_HANDLE_FAIL,
3604df
-                                "Handling NFS-Ganesha"
3604df
-                                " op failed.");
3604df
-                }
3604df
+                if (strcmp (value, "on") == 0) {
3604df
+                        ret = glusterd_handle_ganesha_op (dict, errstr, key,
3604df
+                                                        value);
3604df
+
3604df
+                 } else if (is_origin_glusterd (dict)) {
3604df
+                        ret = dict_get_str (dict, "volname", &volname);
3604df
+                        if (ret) {
3604df
+                                gf_msg ("glusterd-ganesha", GF_LOG_ERROR, errno,
3604df
+                                GD_MSG_DICT_GET_FAILED,
3604df
+                                "Unable to get volume name");
3604df
+                                goto out;
3604df
+                        }
3604df
+                        ret = create_export_config (volname, "off", errstr);
3604df
+                 }
3604df
         }
3604df
 out:
3604df
+        if (ret) {
3604df
+                gf_msg ("glusterd-ganesha", GF_LOG_ERROR, 0,
3604df
+                        GD_MSG_NFS_GNS_OP_HANDLE_FAIL,
3604df
+                        "Handling NFS-Ganesha"
3604df
+                        " op failed.");
3604df
+        }
3604df
         return ret;
3604df
 }
3604df
 
3604df
@@ -415,7 +433,7 @@ check_host_list (void)
3604df
 }
3604df
 
3604df
 int
3604df
-create_export_config (char *volname, char **op_errstr)
3604df
+create_export_config (char *volname, char *value, char **op_errstr)
3604df
 {
3604df
         runner_t                runner                     = {0,};
3604df
         int                     ret                        = -1;
3604df
@@ -424,7 +442,7 @@ create_export_config (char *volname, char **op_errstr)
3604df
         runinit (&runner);
3604df
         runner_add_args (&runner, "sh",
3604df
                         GANESHA_PREFIX"/create-export-ganesha.sh",
3604df
-                        CONFDIR, volname, NULL);
3604df
+                        CONFDIR, value, volname, NULL);
3604df
         ret = runner_run(&runner);
3604df
 
3604df
         if (ret)
3604df
@@ -513,9 +531,12 @@ ganesha_manage_export (dict_t *dict, char *value, char **op_errstr)
3604df
                 goto out;
3604df
         }
3604df
 
3604df
-        /* Create the export file only when ganesha.enable "on" is executed */
3604df
+        /* *
3604df
+         * Create the export file from the node where ganesha.enable "on"
3604df
+         * is executed
3604df
+         * */
3604df
          if (option) {
3604df
-                ret  =  create_export_config (volname, op_errstr);
3604df
+                ret  =  create_export_config (volname, "on", op_errstr);
3604df
                 if (ret) {
3604df
                         gf_msg (this->name, GF_LOG_ERROR, 0,
3604df
                                 GD_MSG_EXPORT_FILE_CREATE_FAIL,
3604df
@@ -810,11 +831,7 @@ glusterd_handle_ganesha_op (dict_t *dict, char **op_errstr,
3604df
 {
3604df
 
3604df
         int32_t                 ret          = -1;
3604df
-        char                   *volname      = NULL;
3604df
-        xlator_t               *this         = NULL;
3604df
         gf_boolean_t           option        = _gf_false;
3604df
-        static int             export_id     = 1;
3604df
-        glusterd_volinfo_t     *volinfo      = NULL;
3604df
 
3604df
         GF_ASSERT (dict);
3604df
         GF_ASSERT (op_errstr);
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
index a228ba6..75b809d 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
@@ -1060,6 +1060,12 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
3604df
                 if (ret)
3604df
                         goto out;
3604df
 
3604df
+                if ((strcmp (key, "ganesha.enable") == 0) &&
3604df
+                    (strcmp (value, "off") == 0)) {
3604df
+                        ret = ganesha_manage_export (dict, "off", op_errstr);
3604df
+                        if (ret)
3604df
+                                goto out;
3604df
+                }
3604df
                 ret = glusterd_check_quota_cmd (key, value, errstr, sizeof (errstr));
3604df
                 if (ret)
3604df
                         goto out;
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
3604df
index 84b38e5..d981fa5 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd.h
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd.h
3604df
@@ -1073,6 +1073,7 @@ int glusterd_check_ganesha_cmd (char *key, char *value,
3604df
 int glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr);
3604df
 int glusterd_op_set_ganesha (dict_t *dict, char **errstr);
3604df
 int ganesha_manage_export (dict_t *dict, char *value, char **op_errstr);
3604df
+int create_export_config (char *volname, char *value, char **op_errstr);
3604df
 gf_boolean_t glusterd_check_ganesha_export (glusterd_volinfo_t *volinfo);
3604df
 int stop_ganesha (char **op_errstr);
3604df
 int tear_down_cluster (gf_boolean_t run_teardown);
3604df
-- 
3604df
1.7.1
3604df