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>
This commit is contained in:
Meghana M 2015-06-15 08:43:44 +00:00 committed by Kaleb KEITHLEY
parent a9f58cd6cf
commit 4a829e33d9
8 changed files with 126 additions and 307 deletions

View File

@ -874,7 +874,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);
@ -885,6 +885,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) {

View File

@ -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

View File

@ -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

View File

@ -1 +1 @@
EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh
EXTRA_DIST = S29CTDBsetup.sh S30samba-start.sh S31ganesha-start.sh

View File

@ -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

View File

@ -1140,10 +1140,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
@ -1236,6 +1236,9 @@ fi
%changelog
* 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 (#1231205)

View File

@ -506,9 +506,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)

View File

@ -1573,7 +1573,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;
}
@ -2424,17 +2424,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: