Blob Blame History Raw
From 50bdfe8131b6cfa8a449b374b9af122fe842cdd0 Mon Sep 17 00:00:00 2001
From: Meghana Madhusudhan <mmadhusu@redhat.com>
Date: Fri, 19 Jun 2015 14:29:59 +0530
Subject: [PATCH 116/129] NFS-Ganesha: Automatically export vol that was exported before vol restart

Consider a volume that is exported via NFS-Ganesha. Stopping this
volume will automatically unexport the volume. Starting this volume
should automatically export it. Although the logic was already there,
there was a bug in it. Fixing the same by introducing a hook script.

Also with the new CLI options, the hook script S31ganesha-set.sh
is no longer required. Hence, removing the same.
Adding a comment to tell the user that one of the CLI
commands will take a few minutes to complete.

Change-Id: I4b24dc2b986a6ccc86e4eb890435ef0175ffd547
BUG: 1226863
Signed-off-by: Meghana Madhusudhan <mmadhusu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50876
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-by: Kaleb Keithley <kkeithle@redhat.com>
Tested-by: Kaleb Keithley <kkeithle@redhat.com>
---
 cli/src/cli-cmd-parser.c                           |    3 +-
 extras/hook-scripts/set/post/Makefile.am           |    2 +-
 extras/hook-scripts/set/post/S31ganesha-set.sh     |  290 --------------------
 extras/hook-scripts/start/post/Makefile.am         |    2 +-
 extras/hook-scripts/start/post/S31ganesha-start.sh |  114 ++++++++
 glusterfs.spec.in                                  |    6 +-
 xlators/mgmt/glusterd/src/glusterd-ganesha.c       |    3 +-
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c    |   14 +-
 8 files changed, 127 insertions(+), 307 deletions(-)
 delete mode 100755 extras/hook-scripts/set/post/S31ganesha-set.sh
 create mode 100755 extras/hook-scripts/start/post/S31ganesha-start.sh

diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index a506c9b..2ddbe88 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -879,7 +879,7 @@ cli_cmd_ganesha_parse (struct cli_state *state,
 
         question = "Enabling NFS-Ganesha requires Gluster-NFS to be"
                    " disabled across the trusted pool. Do you "
-                   "still want to continue?";
+                   "still want to continue?\n";
 
         if (strcmp (value, "enable") == 0) {
                 answer = cli_cmd_get_confirmation (state, question);
@@ -890,6 +890,7 @@ cli_cmd_ganesha_parse (struct cli_state *state,
                         goto out;
                 }
         }
+        cli_out ("This will take a few minutes to complete. Please wait ..");
 
         ret = dict_set_str (dict, "key", key);
         if (ret) {
diff --git a/extras/hook-scripts/set/post/Makefile.am b/extras/hook-scripts/set/post/Makefile.am
index 99dfaa3..db86bc2 100644
--- a/extras/hook-scripts/set/post/Makefile.am
+++ b/extras/hook-scripts/set/post/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = S30samba-set.sh S31ganesha-set.sh S32gluster_enable_shared_storage.sh
+EXTRA_DIST = S30samba-set.sh S32gluster_enable_shared_storage.sh
diff --git a/extras/hook-scripts/set/post/S31ganesha-set.sh b/extras/hook-scripts/set/post/S31ganesha-set.sh
deleted file mode 100755
index f839aa3..0000000
--- a/extras/hook-scripts/set/post/S31ganesha-set.sh
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/bin/bash
-PROGNAME="Sganesha-set"
-OPTSPEC="volname:,gd-workdir:"
-VOL=
-declare -i EXPORT_ID
-ganesha_key="FALSE"
-GANESHA_DIR="/var/lib/glusterfs-ganesha"
-CONF1="$GANESHA_DIR/nfs-ganesha.conf"
-GANESHA_LOG_DIR="/var/log/nfs-ganesha/"
-LOG="$GANESHA_LOG_DIR/ganesha.nfsd.log"
-gnfs="enabled"
-enable_ganesha=""
-host_name="none"
-LOC=""
-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
-                    for pair in $@; do
-                        read key value < <(echo "$pair" | tr "=" " ")
-                        case "$key" in
-                          "nfs-ganesha.enable")
-                                    enable_ganesha=$value
-                                    ganesha_key="TRUE"
-                                    ;;
-                          "nfs-ganesha.host")
-                                    host_name=$value
-                                    ganesha_key="TRUE"
-                                    ;;
-                            *)
-                                ;;
-                        esac
-                    done
-                    shift
-                    break
-                    ;;
-            esac
-            shift
-        done
-}
-
-
-function check_if_host_set()
-{
-        if ! cat $GLUSTERD_WORKDIR/vols/$VOL/info | grep -q "nfs-ganesha.host"
-                then
-                exit 1
-        fi
-}
-
-function check_nfsd_loc()
-{
-        if ls /usr/bin | grep "[g]anesha.nfsd"
-                then
-                LOC="/usr"
-        else
-                LOC="/usr/local"
-        fi
-}
-
-
-function check_gluster_nfs()
-{
-        if cat $GLUSTERD_WORKDIR/vols/$VOL/info | grep -q "nfs.disable=ON"
-                 then
-                 gnfs="disabled"
-        fi
-}
-
-function check_cmd_status()
-{
-        if [ "$1" != "0" ]
-                 then
-                 rm -rf $GANESHA_DIR/exports/export.$VOL.conf
-                 exit 1
-        fi
-}
-
-
-
-#This function generates a new export entry as export.volume_name.conf
-function write_conf()
-{
-        echo "EXPORT{
-        "
-        echo "Export_Id = ;"
-        echo "Path=\"/$1\";"
-        echo "FSAL {
-        "
-        echo "name = "GLUSTER";"
-        echo "hostname=\"$2\";"
-        echo  "volume=\"$1\";"
-        echo "}"
-        echo "Access_type = RW;"
-        echo "Squash = No_root_squash;"
-        echo "Disable_ACL = TRUE;"
-        echo "Pseudo=\"/$1\";"
-        echo "Protocols = \"3,4\" ;"
-        echo "Transports = \"UDP,TCP\" ;"
-        echo "SecType = \"sys\";"
-        echo "Tag = \"$1\";"
-        echo "}"
-}
-
-#This function keeps track of export IDs and increments it with every new entry
-function export_add()
-{
-        count=`ls -l $GANESHA_DIR/exports/*.conf | wc -l`
-        if [ "$count" = "1" ] ;
-                then
-                EXPORT_ID=1
-        else
-        #if [ -s /var/lib/ganesha/export_removed ];
-        #               then
-        #               EXPORT_ID=`head -1 /var/lib/ganesha/export_removed`
-        #               sed -i -e "1d" /var/lib/ganesha/export_removed
-        #               else
-
-                 EXPORT_ID=`cat $GANESHA_DIR/.export_added`
-                 check_cmd_status `echo $?`
-                 EXPORT_ID=EXPORT_ID+1
-        #fi
-        fi
-        echo $EXPORT_ID > $GANESHA_DIR/.export_added
-        check_cmd_status `echo $?`
-        sed -i s/Export_Id.*/"Export_Id = $EXPORT_ID ;"/ \
-$GANESHA_DIR/exports/export.$VOL.conf
-        echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF1
-        check_cmd_status `echo $?`
-}
-
-#This function removes an export dynamically(uses the export_id of the export)
-function dynamic_export_remove()
-{
-        removed_id=`cat $GANESHA_DIR/exports/export.$VOL.conf |\
-grep Export_Id | cut -d " " -f3`
-        check_cmd_status `echo $?`
-        dbus-send --print-reply --system \
---dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
-org.ganesha.nfsd.exportmgr.RemoveExport uint16:$removed_id
-        check_cmd_status `echo $?`
-
-}
-
-#This function adds a new export dynamically by sending dbus signals
-function dynamic_export_add()
-{
-        dbus-send --print-reply --system --dest=org.ganesha.nfsd \
-/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.AddExport \
-string:$GANESHA_DIR/exports/export.$VOL.conf string:"EXPORT(Tag=$VOL)"
-        check_cmd_status `echo $?`
-
-}
-
-function start_ganesha()
-{
-        check_gluster_nfs
-        #Remove export entry from nfs-ganesha.conf
-        sed -i /$VOL.conf/d  $CONF1
-        #Create a new export entry
-        export_add
-        if ! ps aux | grep -q  "[g]anesha.nfsd"
-                then
-                if ls /usr/bin/ganesha.nfsd
-                       then
-                       /usr/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_EVENT -d
-                        sleep 2
-                else
-                        /usr/local/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_EVENT -d
-                        sleep 2
-                fi
-        else
-                        dynamic_export_add $VOL
-        fi
-
-
-        if  !(  ps aux | grep -q "[g]anesha.nfsd")
-                then
-                rm -rf $GANESHA_DIR/exports/*
-                rm -rf $GANESHA_DIR/.export_added
-                exit 1
-        fi
-
-}
-
-#This function generates a new config file when ganesha.host is set
-#If the volume is already exported, only hostname is changed
-function set_hostname()
-{
-        if  ! ls $GANESHA_DIR/exports/  | grep -q $VOL.conf
-                then
-                write_conf $VOL $host_name >\
-$GANESHA_DIR/exports/export.$VOL.conf
-        else
-                sed -i  s/hostname.*/"hostname=\
-\"$host_name\";"/ $GANESHA_DIR/exports/export.$VOL.conf
-        fi
-}
-
-
-function check_ganesha_dir()
-{
-        #Check if the configuration file is placed in /etc/glusterfs-ganesha
-        if ! ls  /etc/glusterfs-ganesha  | grep "nfs-ganesha.conf"
-        then
-               exit 1
-        else
-                if [ ! -d "$GANESHA_DIR" ];
-                         then
-                         mkdir $GANESHA_DIR
-                         check_cmd_status `echo $?`
-                fi
-                cp /etc/glusterfs-ganesha/nfs-ganesha.conf $GANESHA_DIR/
-                check_cmd_status `echo $?`
-        fi
-        if [ ! -d "$GANESHA_DIR/exports" ];
-                then
-                mkdir $GANESHA_DIR/exports
-                check_cmd_status `echo $?`
-        fi
-        if [ ! -d "$GANESHA_LOG_DIR" ] ;
-                then
-                mkdir $GANESHA_LOG_DIR
-                check_cmd_status `echo $?`
-        fi
-
-
-
-}
-
-function stop_ganesha()
-{
-        dynamic_export_remove $VOL
-        #Remove the specfic export configuration file
-        rm -rf $GANESHA_DIR/exports/export.$VOL.conf
-        #Remove that entry from nfs-ganesha.conf
-        sed -i /$VOL.conf/d  $CONF1
-        #If there are no other volumes exported, stop nfs-ganesha
-        if [ ! "$(ls -A $GANESHA_DIR/exports)" ];
-                then
-                pkill ganesha.nfsd
-                rm -rf $GANESHA_DIR/.export_added
-        fi
-}
-
-        parse_args $@
-        if [ "$ganesha_key" == "FALSE" ]
-        then
-                exit 0
-        fi
-        check_ganesha_dir $VOL
-        if echo $enable_ganesha | grep -q -i "ON"
-                then
-                check_if_host_set $VOL
-                if ! showmount -e localhost | cut -d "" -f1 | grep -q "$VOL[[:space:]]"
-                        then
-                        start_ganesha
-                fi
-        elif echo $enable_ganesha | grep -q -i "OFF"
-                then
-                check_if_host_set $VOL
-                stop_ganesha
-        fi
-        if [ "$host_name" != "none" ];
-                then
-                if showmount -e localhost | cut -d "" -f1 | grep -q "$VOL[[:space:]]"
-                        then
-                        dynamic_export_remove $VOL
-                        set_hostname
-                        start_ganesha
-                else
-                        set_hostname
-                fi
-
-        fi
diff --git a/extras/hook-scripts/start/post/Makefile.am b/extras/hook-scripts/start/post/Makefile.am
index d9cba93..ad53233 100644
--- a/extras/hook-scripts/start/post/Makefile.am
+++ b/extras/hook-scripts/start/post/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh
+EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh S31ganesha-start.sh
diff --git a/extras/hook-scripts/start/post/S31ganesha-start.sh b/extras/hook-scripts/start/post/S31ganesha-start.sh
new file mode 100755
index 0000000..7ba8af1
--- /dev/null
+++ b/extras/hook-scripts/start/post/S31ganesha-start.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+PROGNAME="Sganesha-start"
+OPTSPEC="volname:,gd-workdir:"
+VOL=
+declare -i EXPORT_ID
+ganesha_key="ganesha.enable"
+GANESHA_DIR="/etc/ganesha"
+CONF1="$GANESHA_DIR/ganesha.conf"
+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
+}
+
+
+
+#This function generates a new export entry as export.volume_name.conf
+function write_conf()
+{
+        echo "EXPORT{
+        "
+        echo "Export_Id = ;"
+        echo "Path=\"/$1\";"
+        echo "FSAL {
+        "
+        echo "name = "GLUSTER";"
+        echo "hostname="localhost";"
+        echo  "volume=\"$1\";"
+        echo "}"
+        echo "Access_type = RW;"
+        echo "Squash = No_root_squash;"
+        echo "Disable_ACL = TRUE;"
+        echo "Pseudo=\"/$1\";"
+        echo "Protocols = \"3\",\"4\" ;"
+        echo "Transports = \"UDP\",\"TCP\" ;"
+        echo "SecType = \"sys\";"
+        echo "}"
+}
+
+#This function keeps track of export IDs and increments it with every new entry
+function export_add()
+{
+        count=`ls -l $GANESHA_DIR/exports/*.conf | wc -l`
+        if [ "$count" = "0" ] ;
+                then
+                EXPORT_ID=2
+        else
+        #if [ -s /var/lib/ganesha/export_removed ];
+        #               then
+        #               EXPORT_ID=`head -1 /var/lib/ganesha/export_removed`
+        #               sed -i -e "1d" /var/lib/ganesha/export_removed
+        #               else
+
+                 EXPORT_ID=`cat $GANESHA_DIR/.export_added`
+                 EXPORT_ID=EXPORT_ID+1
+        #fi
+        fi
+        echo $EXPORT_ID > $GANESHA_DIR/.export_added
+        sed -i s/Export_Id.*/"Export_Id= $EXPORT_ID ;"/ \
+$GANESHA_DIR/exports/export.$VOL.conf
+        echo "%include \"$GANESHA_DIR/exports/export.$VOL.conf\"" >> $CONF1
+}
+
+#This function adds a new export dynamically by sending dbus signals
+function dynamic_export_add()
+{
+        dbus-send --print-reply --system --dest=org.ganesha.nfsd \
+/org/ganesha/nfsd/ExportMgr org.ganesha.nfsd.exportmgr.AddExport \
+string:$GANESHA_DIR/exports/export.$VOL.conf string:"EXPORT(Path=/$VOL)"
+
+}
+
+function start_ganesha()
+{
+        #Remove export entry from nfs-ganesha.conf
+        sed -i /$VOL.conf/d  $CONF1
+        #Create a new export entry
+        export_add $VOL
+        dynamic_export_add $VOL
+
+}
+
+        parse_args $@
+        ganesha_value=$(grep $ganesha_key  $GLUSTERD_WORKDIR/vols/$VOL/info |\
+                        cut -d"=" -f2)
+        if [ "$ganesha_value" = "on" ]
+        then
+                write_conf $VOL
+                start_ganesha $VOL
+        else
+                exit 0
+        fi
+
+
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index 7ee37fa..78bd311 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -1267,10 +1267,10 @@ fi
 %config %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/disabled-quota-root-xattr-heal.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre/S28Quota-enable-root-xattr-heal.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/set/post/S30samba-set.sh
-%config %{_sharedstatedir}/glusterd/hooks/1/set/post/S31ganesha-set.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/set/post/S32gluster_enable_shared_storage.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/start/post/S29CTDBsetup.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/start/post/S30samba-start.sh
+%config %{_sharedstatedir}/glusterd/hooks/1/start/post/S31ganesha-start.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/stop/pre/S30samba-stop.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/stop/pre/S29CTDB-teardown.sh
 %config %{_sharedstatedir}/glusterd/hooks/1/reset/post/S31ganesha-reset.sh
@@ -1930,6 +1930,7 @@ end
 %endif
 
 %changelog
+
 * Fri Jun 19 2015 Bala.FA <barumuga@redhat.com>
 - exclude libgfdb.pc conditionally for rhel-5 (#1233486)
 
@@ -1940,6 +1941,9 @@ end
 * Thu Jun 18 2015 Niels de Vos <ndevos@redhat.com>
 - glusterfs-devel for client-builds should not depend on -server (#1227029)
 
+* Mon Jun 15 2015 Niels de Vos <ndevos@redhat.com>
+- Replace hook script S31ganesha-set.sh by S31ganesha-start.sh (#1231738)
+
 * Fri Jun 12 2015 Aravinda VK <avishwan@redhat.com>
 - Added rsync as dependency to georeplication rpm (#1231213)
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
index 40a74cd..df2dd6d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
@@ -511,9 +511,10 @@ ganesha_manage_export (dict_t *dict, char *value, char **op_errstr)
                         goto out;
                 }
         }
+
+        vol_opts = volinfo->dict;
         /* cache-invalidation should be on when a volume is exported
          *  and off when a volume is unexported.                    */
-        vol_opts = volinfo->dict;
         ret = dict_set_dynstr_with_alloc (vol_opts,
                                          "features.cache-invalidation", value);
         if (ret)
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
index 04b539b..4f6a8dc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
@@ -1578,7 +1578,7 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr)
         if (ret) {
                 ret = ganesha_manage_export(dict, "off", op_errstr);
                 if (ret) {
-                        gf_log (THIS->name, GF_LOG_WARNING, "Could not"
+                        gf_log (THIS->name, GF_LOG_WARNING, "Could not "
                                         "unexport volume via NFS-Ganesha");
                         ret = 0;
                 }
@@ -2431,17 +2431,7 @@ glusterd_op_start_volume (dict_t *dict, char **op_errstr)
                 if (ret)
                         goto out;
         }
-        /* Check if the volume is exported via NFS-Ganesha, if yes
-         * export it as part of starting the volume */
-        ret = glusterd_check_ganesha_export (volinfo);
-        if (ret) {
-                ret = ganesha_manage_export (dict, "on", op_errstr);
-                if (ret) {
-                        gf_log ("glusterd", GF_LOG_WARNING, "NFS-Ganesha couldn't"
-                                "export the volume. %s", *op_errstr);
-                        ret = 0;
-                }
-        }
+
         ret = glusterd_svcs_manager (volinfo);
 
 out:
-- 
1.7.1