diff options
author | Meghana M <mmadhusu@redhat.com> | 2015-06-15 08:43:44 +0000 |
---|---|---|
committer | Kaleb KEITHLEY <kkeithle@redhat.com> | 2015-06-16 05:50:14 -0700 |
commit | 4a829e33d9c0d62a710650337406dc25d89cc599 (patch) | |
tree | 65673e0eb6515104fced6d389a1bc8b29f554d2a /extras | |
parent | a9f58cd6cfc29a47af868fff29ce3133b9f9efe5 (diff) |
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: Ibff769ca04fef0c2a129c83fe31fc9c869350e8d
BUG: 1231738
Signed-off-by: Meghana Madhusudhan <mmadhusu@redhat.com>
Reviewed-on: http://review.gluster.org/11247
Reviewed-by: soumya k <skoduri@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/hook-scripts/set/post/Makefile.am | 2 | ||||
-rwxr-xr-x | extras/hook-scripts/set/post/S31ganesha-set.sh | 290 | ||||
-rw-r--r-- | extras/hook-scripts/start/post/Makefile.am | 2 | ||||
-rwxr-xr-x | extras/hook-scripts/start/post/S31ganesha-start.sh | 114 |
4 files changed, 116 insertions, 292 deletions
diff --git a/extras/hook-scripts/set/post/Makefile.am b/extras/hook-scripts/set/post/Makefile.am index 99dfaa3eafb..db86bc2eb51 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 f839aa37061..00000000000 --- 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 d9cba93ed52..ad53233b1c9 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 00000000000..7ba8af1e6e4 --- /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 + + |