summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--extras/hook-scripts/Makefile.am2
-rw-r--r--extras/hook-scripts/reset/Makefile.am2
-rw-r--r--extras/hook-scripts/reset/post/Makefile.am1
-rwxr-xr-xextras/hook-scripts/reset/post/S31ganesha-reset.sh38
-rw-r--r--extras/hook-scripts/reset/pre/Makefile.am1
-rw-r--r--extras/hook-scripts/set/post/Makefile.am2
-rwxr-xr-xextras/hook-scripts/set/post/S31ganesha-set.sh247
-rw-r--r--glusterfs.spec.in6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c28
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-set.c10
-rw-r--r--xlators/nfs/server/src/nfs.c10
13 files changed, 356 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index ae0bc78c4b5..e032e8f311c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -183,6 +183,9 @@ AC_CONFIG_FILES([Makefile
extras/hook-scripts/set/post/Makefile
extras/hook-scripts/stop/Makefile
extras/hook-scripts/stop/pre/Makefile
+ extras/hook-scripts/reset/Makefile
+ extras/hook-scripts/reset/post/Makefile
+ extras/hook-scripts/reset/pre/Makefile
contrib/fuse-util/Makefile
contrib/uuid/uuid_types.h
glusterfs-api.pc
diff --git a/extras/hook-scripts/Makefile.am b/extras/hook-scripts/Makefile.am
index dd67c248e1a..4a1adb3d5db 100644
--- a/extras/hook-scripts/Makefile.am
+++ b/extras/hook-scripts/Makefile.am
@@ -1,2 +1,2 @@
EXTRA_DIST = S40ufo-stop.py S56glusterd-geo-rep-create-post.sh
-SUBDIRS = add-brick set start stop
+SUBDIRS = add-brick set start stop reset
diff --git a/extras/hook-scripts/reset/Makefile.am b/extras/hook-scripts/reset/Makefile.am
new file mode 100644
index 00000000000..6e2701e909e
--- /dev/null
+++ b/extras/hook-scripts/reset/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = post pre
+CLEANFILES =
diff --git a/extras/hook-scripts/reset/post/Makefile.am b/extras/hook-scripts/reset/post/Makefile.am
new file mode 100644
index 00000000000..fcdd8ab55ba
--- /dev/null
+++ b/extras/hook-scripts/reset/post/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST = S31ganesha-reset.sh
diff --git a/extras/hook-scripts/reset/post/S31ganesha-reset.sh b/extras/hook-scripts/reset/post/S31ganesha-reset.sh
new file mode 100755
index 00000000000..68411e4bd95
--- /dev/null
+++ b/extras/hook-scripts/reset/post/S31ganesha-reset.sh
@@ -0,0 +1,38 @@
+#/bin/bash
+PROGNAME="Sganesha-reset"
+OPTSPEC="volname:"
+VOL=
+
+function parse_args () {
+ ARGS=$(getopt -l $OPTSPEC -o "o" -name $PROGNAME $@)
+ eval set -- "$ARGS"
+ case $1 in
+ --volname)
+ shift
+ VOL=$1
+ ;;
+ esac
+}
+
+function is_volume_started () {
+ volname=$1
+ echo "$(grep status /var/lib/glusterd/vols/"$volname"/info |\
+ cut -d"=" -f2)"
+}
+
+parse_args $@
+if ps aux | grep -q "[g]anesha.nfsd"
+ then
+ kill -s TERM `cat /var/run/ganesha.pid`
+ sleep 10
+ rm -rf /var/lib/ganesha/exports
+ rm -rf /var/lib/ganesha/export_added
+ sed -i /conf/d /var/lib/ganesha/nfs-ganesha.conf
+ if [ "1" = $(is_volume_started "$VOL") ];
+ then
+ gluster volume start $VOL force
+ fi
+fi
+
+
+
diff --git a/extras/hook-scripts/reset/pre/Makefile.am b/extras/hook-scripts/reset/pre/Makefile.am
new file mode 100644
index 00000000000..1b336ac1a85
--- /dev/null
+++ b/extras/hook-scripts/reset/pre/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST =
diff --git a/extras/hook-scripts/set/post/Makefile.am b/extras/hook-scripts/set/post/Makefile.am
index 9ded234cf9b..3ec25d94134 100644
--- a/extras/hook-scripts/set/post/Makefile.am
+++ b/extras/hook-scripts/set/post/Makefile.am
@@ -1 +1 @@
-EXTRA_DIST = S30samba-set.sh
+EXTRA_DIST = S30samba-set.sh S31ganesha-set.sh
diff --git a/extras/hook-scripts/set/post/S31ganesha-set.sh b/extras/hook-scripts/set/post/S31ganesha-set.sh
new file mode 100755
index 00000000000..3b74c766b7d
--- /dev/null
+++ b/extras/hook-scripts/set/post/S31ganesha-set.sh
@@ -0,0 +1,247 @@
+#!/bin/bash
+PROGNAME="Sganesha-set"
+OPTSPEC="volname:"
+VOL=
+declare -i EXPORT_ID
+CONF1="/var/lib/ganesha/nfs-ganesha.conf"
+LOG="/tmp/ganesha.log"
+gnfs="enabled"
+enable_ganesha=""
+host_name="none"
+IS_HOST_SET="NO"
+LOC=""
+
+
+
+function parse_args ()
+{
+ ARGS=$(getopt -l $OPTSPEC -o "o" -name $PROGNAME $@)
+ eval set -- "$ARGS"
+
+ while true; do
+ case $1 in
+ --volname)
+ shift
+ VOL=$1
+ ;;
+ *)
+ shift
+ for pair in $@; do
+ read key value < <(echo "$pair" | tr "=" " ")
+ case "$key" in
+ "nfs-ganesha.enable")
+ enable_ganesha=$value
+ ;;
+ "nfs-ganesha.host")
+ host_name=$value
+ ;;
+ *)
+ ;;
+ esac
+ done
+
+ shift
+ break
+ ;;
+ esac
+ shift
+ done
+}
+
+
+function check_if_host_set()
+{
+ if cat /var/lib/glusterd/vols/$VOL/info | grep -q "nfs-ganesha.host"
+ then
+ IS_HOST_SET="YES"
+ 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 /var/lib/glusterd/vols/$VOL/info | grep -q "nfs.disable=ON"
+ then
+ gnfs="disabled"
+ 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 "Pseudo=\"/$1\";"
+ echo "NFS_Protocols = \"3,4\" ;"
+ echo "Transport_Protocols = \"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 /var/lib/ganesha/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 /var/lib/ganesha/export_added`
+ EXPORT_ID=EXPORT_ID+1
+ #fi
+ fi
+ echo $EXPORT_ID > /var/lib/ganesha/export_added
+ sed -i s/Export_Id.*/"Export_Id = $EXPORT_ID;"/ \
+/var/lib/ganesha/exports/export.$VOL.conf
+ echo "%include \"/var/lib/ganesha/exports/export.$VOL.conf\"" >> $CONF1
+
+
+}
+
+function export_remove()
+{
+ $removed_id=`cat /var/lib/ganesha/exports/export.$VOL.conf | grep Export_Id | cut -d " " -f3`
+ echo $removed_id >> /var/lib/ganesha/export_removed
+}
+
+function start_ganesha()
+{
+ if [ "$IS_HOST_SET" = "NO" ]
+ then
+ gluster volume set $VOL nfs-ganesha.enable OFF
+ else
+ check_gluster_nfs
+
+ #Remove export entry from nfs-ganesha.conf
+ sed -i /$VOL.conf/d $CONF1
+ pkill ganesha.nfsd
+ sleep 10
+ gluster volume set $VOL nfs.disable ON
+ sleep 4
+
+ #Create a new export entry
+ export_add
+ if ls /usr/bin/ | grep -q "ganesha.nfsd"
+ then
+ sed -i s/FSAL_Shared.*/FSAL_Shared_Library=\
+"\"\/usr\/lib64\/ganesha\/libfsalgluster.so\";"/ $CONF1
+ /usr/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_FULL_DEBUG -d
+ sleep 2
+ else
+ sed -i s/FSAL_Shared.*/FSAL_Shared_Library=\
+"\"\/usr\/local\/lib64\/ganesha\/libfsalgluster.so\";"/ $CONF1
+ /usr/local/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_FULL_DEBUG -d
+ sleep 2
+ fi
+
+ if ! ps aux | grep -q "[g]anesha.nfsd"
+ then
+ if [ "$gnfs" = "enabled" ]
+ then
+ gluster volume set $VOL nfs.disable OFF
+ fi
+ rm -rf /var/lib/ganesha/exports/*
+ rm -rf /var/lib/ganesha/export_added
+ gluster volume set $VOL nfs-ganesha.enable OFF
+ gluster volume set $VOL nfs-ganesha.host none
+ exit 1
+ fi
+ 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 /var/lib/ganesha/exports/ | grep -q $VOL.conf
+ then
+ write_conf $VOL $host_name >\
+/var/lib/ganesha/exports/export.$VOL.conf
+ else
+ sed -i s/hostname.*/"hostname=\
+\"$host_name\";"/ /var/lib/ganesha/exports/export.$VOL.conf
+ fi
+
+}
+
+
+function stop_ganesha()
+{
+ if ps aux | grep -q "[g]anesha.nfsd"
+ then
+ pkill ganesha.nfsd
+ sleep 10
+ fi
+ gluster vol set $VOL nfs-ganesha.host none
+ #Remove the specfic export configuration file
+ rm -rf /var/lib/ganesha/exports/export.$VOL.conf
+ #Remove that entry from nfs-ganesha.conf
+ sed -i /$VOL.conf/d $CONF1
+ #If there are any other volumes exported, restart nfs-ganesha
+ if [ "$(ls -A /var/lib/ganesha/exports)" ];
+ then
+ check_nfsd_loc
+ $LOC/bin/ganesha.nfsd -f $CONF1 -L $LOG -N NIV_FULL_DEBUG -d
+ else
+ rm -rf /var/lib/ganesha/export_added
+ fi
+
+}
+
+ parse_args $@
+ if [ ! -d "/var/lib/ganesha/exports" ];
+ then
+ mkdir /var/lib/ganesha/exports
+ fi
+ if echo $enable_ganesha | grep -q -i "ON"
+ then
+ check_if_host_set $VOL
+ start_ganesha
+ elif echo $enable_ganesha | grep -q -i "OFF"
+ then
+ check_if_host_set
+ if [ "$IS_HOST_SET" = "YES" ]
+ then
+ stop_ganesha
+ fi
+ fi
+ if [ "$host_name" != "none" ];
+ then
+ check_if_host_set
+ set_hostname
+ if cat /var/lib/glusterd/vols/$VOL/info\
+| grep -i -q "nfs-ganesha.enable=on"
+ then
+ start_ganesha
+ fi
+ fi
+
+
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index 43bbc97617e..755c9fd8478 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -649,6 +649,9 @@ mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/stop/pre
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/start
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/start/post
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/start/pre
+mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/reset
+mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/reset/post
+mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/reset/pre
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/remove-brick
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/remove-brick/post
mkdir -p %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/remove-brick/pre
@@ -691,6 +694,9 @@ install -p -m 0744 extras/hook-scripts/S56glusterd-geo-rep-create-post.sh \
%{buildroot}%{_sharedstatedir}/glusterd/hooks/1/add-brick/post
%{__install} -p -m 0744 extras/hook-scripts/add-brick/pre/*.sh \
%{buildroot}%{_sharedstatedir}/glusterd/hooks/1/add-brick/pre
+%{__install} -p -m 0744 extras/hook-scripts/reset/post/*.sh \
+ %{buildroot}%{_sharedstatedir}/glusterd/hooks/1/reset/post
+
find ./tests ./run-tests.sh -type f | cpio -pd %{buildroot}%{_prefix}/share/glusterfs
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c
index 78730a5645f..a845f540afa 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c
@@ -46,7 +46,7 @@ char glusterd_hook_dirnames[GD_OP_MAX][256] =
[GD_OP_REMOVE_BRICK] = "remove-brick",
[GD_OP_REPLACE_BRICK] = EMPTY,
[GD_OP_SET_VOLUME] = "set",
- [GD_OP_RESET_VOLUME] = EMPTY,
+ [GD_OP_RESET_VOLUME] = "reset",
[GD_OP_SYNC_VOLUME] = EMPTY,
[GD_OP_LOG_ROTATE] = EMPTY,
[GD_OP_GSYNC_CREATE] = "gsync-create",
@@ -277,6 +277,13 @@ glusterd_hooks_add_op_args (runner_t *runner, glusterd_op_t op,
glusterd_hooks_add_hooks_version (runner);
glusterd_hooks_add_op (runner, "add-brick");
glusterd_hooks_add_working_dir (runner, priv);
+ break;
+
+ case GD_OP_RESET_VOLUME:
+ glusterd_hooks_add_hooks_version (runner);
+ glusterd_hooks_add_op (runner, "reset");
+ glusterd_hooks_add_working_dir (runner, priv);
+ break;
default:
break;
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index ecc8f7cafe6..82ff8826843 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -3057,6 +3057,34 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
+ if (! strcmp (vme->option, "!nfs-ganesha.enable")) {
+ ret = gf_asprintf (&aa, "nfs-ganesha.%s.enable",
+ volinfo->volname);
+
+ if (ret != -1) {
+ ret = xlator_set_option (xl, aa, vme->value);
+ GF_FREE (aa);
+ }
+
+ if (ret)
+ return -1;
+ }
+
+ if (! strcmp (vme->option, "!nfs-ganesha.host")) {
+ ret = gf_asprintf (&aa, "nfs-ganesha.%s.host",
+ volinfo->volname);
+
+ if (ret != -1) {
+ ret = xlator_set_option (xl, aa, vme->value);
+ GF_FREE (aa);
+ }
+
+ if (ret)
+ return -1;
+ }
+
+
+
if ( (strcmp (vme->voltype, "nfs/server") == 0) &&
(vme->option && vme->option[0]!='!') ) {
ret = xlator_set_option (xl, vme->option, vme->value);
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
index 8998d8478d0..b8eb8a56582 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
@@ -1392,6 +1392,16 @@ struct volopt_map_entry glusterd_volopt_map[] = {
.option = "!nfs-disable",
.op_version = 1
},
+ { .key = "nfs-ganesha.enable",
+ .voltype = "nfs/server",
+ .option = "!nfs-ganesha.enable",
+ .op_version = 4
+ },
+ { .key = "nfs-ganesha.host",
+ .voltype = "nfs/server",
+ .option = "!nfs-ganesha.host",
+ .op_version = 4
+ },
{ .key = "nfs.nlm",
.voltype = "nfs/server",
.option = "nfs.nlm",
diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c
index 918e8631255..65814ebc17c 100644
--- a/xlators/nfs/server/src/nfs.c
+++ b/xlators/nfs/server/src/nfs.c
@@ -1827,6 +1827,16 @@ struct volume_options options[] = {
.description = "This option is used to start or stop the NFS server "
"for individual volumes."
},
+ { .key = {"nfs-ganesha.*.host"},
+ .type = GF_OPTION_TYPE_INTERNET_ADDRESS_LIST,
+ .default_value = "none",
+ .description = "Set nfs-ganesha host IP"
+ },
+ { .key = {"nfs-ganesha.*.enable"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "This option, if set to 'on', enables exports via nfs-ganesha "
+ },
{ .key = {"nfs.nlm"},
.type = GF_OPTION_TYPE_BOOL,