diff options
Diffstat (limited to 'xlators/mount/fuse/utils')
-rw-r--r-- | xlators/mount/fuse/utils/Makefile.am | 10 | ||||
-rwxr-xr-x | xlators/mount/fuse/utils/mount.glusterfs.in | 152 | ||||
-rwxr-xr-x | xlators/mount/fuse/utils/mount_glusterfs.in | 181 |
3 files changed, 343 insertions, 0 deletions
diff --git a/xlators/mount/fuse/utils/Makefile.am b/xlators/mount/fuse/utils/Makefile.am new file mode 100644 index 00000000000..1217c30dafa --- /dev/null +++ b/xlators/mount/fuse/utils/Makefile.am @@ -0,0 +1,10 @@ +utildir = $(destdir)/sbin + +if GF_DARWIN_HOST_OS +util_SCRIPTS = mount_glusterfs +else +util_SCRIPTS = mount.glusterfs +endif + +CLEANFILES = + diff --git a/xlators/mount/fuse/utils/mount.glusterfs.in b/xlators/mount/fuse/utils/mount.glusterfs.in new file mode 100755 index 00000000000..481fd265fff --- /dev/null +++ b/xlators/mount/fuse/utils/mount.glusterfs.in @@ -0,0 +1,152 @@ +#!/bin/sh +# (C) 2006, 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA + + + +_init () +{ + # log level definitions + LOG_NONE=NONE; + LOG_CRITICAL=CRITICAL; + LOG_ERROR=ERROR; + LOG_WARNING=WARNING; + LOG_DEBUG=DEBUG; + + # set default log level to ERROR + log_level=$LOG_WARNING; +} + +start_glusterfs () +{ + prefix="@prefix@"; + exec_prefix=@exec_prefix@; + cmd_line=$(echo "@sbindir@/glusterfs"); + + if [ -n "$log_level_str" ]; then + case "$log_level_str" in + "ERROR") + log_level=$LOG_ERROR; + ;; + "DEBUG") + log_level=$LOG_DEBUG; + ;; + "CRITICAL") + log_level=$LOG_CRITICAL; + ;; + "WARNING") + log_level=$LOG_WARNING; + ;; + "NONE") + log_level=$LOG_NONE; + ;; + *) + echo "invalid log level $log_level_str, using ERROR"; + log_level=$LOG_ERROR; + ;; + esac + fi + cmd_line=$(echo "$cmd_line --log-level=$log_level"); + + if [ -n "$log_file" ]; then + cmd_line=$(echo "$cmd_line --log-file=$log_file"); + fi + + if [ -n "$direct_io_mode" ]; then + cmd_line=$(echo "$cmd_line --direct-io-mode=$direct_io_mode"); + fi + + if [ -z "$volfile_loc" ]; then + if [ -n "$transport" ]; then + cmd_line=$(echo "$cmd_line \ +--volfile-server=$server_ip \ +--volfile-server-port=$server_port \ +--volfile-server-transport=$transport"); + else + cmd_line=$(echo "$cmd_line \ +--volfile-server=$server_ip \ +--volfile-server-port=$server_port"); + fi + else + cmd_line=$(echo "$cmd_line --volfile=$volfile_loc"); + fi + + if [ -n "$volume_name" ]; then + cmd_line=$(echo "$cmd_line --volume-name=$volume_name"); + fi + + if [ -n "$volume_id" ]; then + cmd_line=$(echo "$cmd_line --volfile-id=$volume_id"); + fi + + cmd_line=$(echo "$cmd_line $mount_point"); + exec $cmd_line; +} + + +main () +{ + options=$(echo "$@" | sed -n 's/.*\-o[ ]*\([^ ]*\).*/\1/p'); + new_log_level=$(echo "$options" | sed -n 's/.*log-level=\([^,]*\).*/\1/p'); + + [ -n "$new_log_level" ] && { + log_level_str="$new_log_level"; + } + log_file=$(echo "$options" | sed -n 's/.*log-file=\([^,]*\).*/\1/p'); + + transport=$(echo "$options" | sed -n 's/.*transport=\([^,]*\).*/\1/p'); + + direct_io_mode=$(echo "$options" | sed -n 's/.*direct-io-mode=\([^,]*\).*/\1/p'); + + volume_name=$(echo "$options" | sed -n 's/.*volume-name=\([^,]*\).*/\1/p'); + + volume_id=$(echo "$options" | sed -n 's/.*volume-id=\([^,]*\).*/\1/p'); + + volfile_loc="$1"; + + [ -r "$volfile_loc" ] || { + server_ip=$(echo "$volfile_loc" | sed -n 's/\([^\:]*\).*/\1/p'); + server_port=$(echo "$volfile_loc" | sed -n 's/.*:\([^ ]*\).*/\1/p'); + [ -n "$server_port" ] || { + server_port="6996"; + } + + volfile_loc=""; + } + new_fs_options=$(echo "$options" | sed -e 's/[,]*log-file=[^,]*//' \ + -e 's/[,]*log-level=[^,]*//' \ + -e 's/[,]*volume-name=[^,]*//' \ + -e 's/[,]*direct-io-mode=[^,]*//' \ + -e 's/[,]*transport=[^,]*//' \ + -e 's/[,]*volume-id=[^,]*//'); + # following line is product of love towards sed + # $2=$(echo "$@" | sed -n 's/[^ ]* \([^ ]*\).*/\1/p'); + + mount_point="$2"; + + # Simple check to avoid multiple identical mounts + if grep -q "glusterfs $mount_point fuse" /etc/mtab; then + echo "$0: according to mtab, GlusterFS is already mounted on $mount_point" + exit 1 + fi + + fs_options=$(echo "$fs_options,$new_fs_options"); + + start_glusterfs; +} + +_init "$@" && main "$@"; diff --git a/xlators/mount/fuse/utils/mount_glusterfs.in b/xlators/mount/fuse/utils/mount_glusterfs.in new file mode 100755 index 00000000000..1376a8897ab --- /dev/null +++ b/xlators/mount/fuse/utils/mount_glusterfs.in @@ -0,0 +1,181 @@ +#!/bin/sh +# (C) 2008 Z RESEARCH Inc. <http://www.zresearch.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA + + + +_init () +{ + # log level definitions + LOG_NONE=NONE; + LOG_CRITICAL=CRITICAL; + LOG_ERROR=ERROR; + LOG_WARNING=WARNING; + LOG_DEBUG=DEBUG; + + # set default log level to ERROR + log_level=$LOG_WARNING; +} + +start_glusterfs () +{ + prefix="@prefix@"; + exec_prefix=@exec_prefix@; + cmd_line=$(echo "@sbindir@/glusterfs"); + + if [ -n "$log_level_str" ]; then + case "$log_level_str" in + "ERROR") + log_level=$LOG_ERROR; + ;; + "DEBUG") + log_level=$LOG_DEBUG; + ;; + "CRITICAL") + log_level=$LOG_CRITICAL; + ;; + "WARNING") + log_level=$LOG_WARNING; + ;; + "NONE") + log_level=$LOG_NONE; + ;; + *) + echo "invalid log level $log_level_str, using ERROR"; + log_level=$LOG_WARNING; + ;; + esac + fi + cmd_line=$(echo "$cmd_line --log-level=$log_level"); + + if [ -n "$log_file" ]; then + cmd_line=$(echo "$cmd_line --log-file=$log_file"); + fi + + if [ -n "$direct_io_mode" ]; then + cmd_line=$(echo "$cmd_line --direct-io-mode=$direct_io_mode"); + fi + + if [ -z "$volfile_loc" ]; then + if [ -n "$transport" ]; then + cmd_line=$(echo "$cmd_line \ +--volfile-server=$server_ip \ +--volfile-server-port=$server_port \ +--volfile-server-transport=$transport"); + else + cmd_line=$(echo "$cmd_line \ +--volfile-server=$server_ip \ +--volfile-server-port=$server_port"); + fi + else + cmd_line=$(echo "$cmd_line --volfile=$volfile_loc"); + fi + + if [ -n "$volume_name" ]; then + cmd_line=$(echo "$cmd_line --volume-name=$volume_name"); + fi + + if [ -n "$volume_id" ]; then + cmd_line=$(echo "$cmd_line --volfile-id=$volume_id"); + fi + + cmd_line=$(echo "$cmd_line $mount_point"); + exec $cmd_line; +} + + +main () +{ + + new_log_level="" + log_file="" + transport="" + direct_io_mode="" + volume_name="" + new_fs_options="" + + while getopts o: opt; do + case "$opt" in + o) + options=$(echo $OPTARG | sed -n 's/.*\-o[ ]*\([^ ]*\).*/\1/p'); + [ -z $new_log_level ] && { + new_log_level=$(echo "$options" | sed -n 's/.*log-level=\([^,]*\).*/\1/p'); + } + + [ -z $log_file ] && { + log_file=$(echo "$options" | sed -n 's/.*log-file=\([^,]*\).*/\1/p'); + } + + [ -z $transport ] && { + transport=$(echo "$options" | sed -n 's/.*transport=\([^,]*\).*/\1/p'); + } + + [ -z $direct_io_mode ] && { + direct_io_mode=$(echo "$options" | sed -n 's/.*direct-io-mode=\([^,]*\).*/\1/p'); + } + + [ -z $volume_name ] && { + volume_name=$(echo "$options" | sed -n 's/.*volume-name=\([^,]*\).*/\1/p'); + } + + [ -z $volume_id ] && { + volume_id=$(echo "$options" | sed -n 's/.*volume-id=\([^,]*\).*/\1/p'); + } + + this_option=$(echo "$options" | sed -e 's/[,]*log-file=[^,]*//' \ + -e 's/[,]*log-level=[^,]*//' \ + -e 's/[,]*volume-name=[^,]*//' \ + -e 's/[,]*direct-io-mode=[^,]*//' \ + -e 's/[,]*transport=[^,]*//' \ + -e 's/[,]*volume-id=[^,]*//'); + new_fs_options="$new_fs_options $this_option"; + ;; + esac + done + + [ -n "$new_log_level" ] && { + log_level_str="$new_log_level"; + } + + # TODO: use getopt. This is very much darwin specific + volfile_loc="$1"; + while [ "$volfile_loc" == "-o" ] ; do + shift ; + shift ; + volfile_loc="$1"; + done + + [ -r "$volfile_loc" ] || { + server_ip=$(echo "$volfile_loc" | sed -n 's/\([^\:]*\).*/\1/p'); + server_port=$(echo "$volfile_loc" | sed -n 's/.*:\([^ ]*\).*/\1/p'); + [ -n "$server_port" ] || { + server_port="6996"; + } + + volfile_loc=""; + } + # following line is product of love towards sed + # $2=$(echo "$@" | sed -n 's/[^ ]* \([^ ]*\).*/\1/p'); + + mount_point="$2"; + + fs_options=$(echo "$fs_options,$new_fs_options"); + + start_glusterfs; +} + +_init "$@" && main "$@"; |