[Gluster-devel] Replacement mount.glusterfs

Michael Fincham michael at unleash.co.nz
Thu Sep 27 11:11:34 UTC 2007


Hi all,

Have added a -o direct-io-mode=blah as an option and tweaked a couple of
other (minor) things. Notably -o options may now be passed in any case.
This adds a dependency on printf and tr but these are both in coreutils so
can't be worse than sed ;)

Script follows:

#!/bin/sh
# (C) 2006 Gluster core team <http://www.gluster.org/>
#
# 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;

    # direct io definitions
    DIO_ENABLE="ENABLE";
    DIO_DISABLE="DISABLE";

    # set default log level to ERROR
    log_level_default=$LOG_ERROR;

    # set default direct-io-mode to ENABLE
    direct_io_mode_default=$DIO_ENABLE;

    direct_io_mode=$direct_io_mode_default;
    log_level=$log_level_default;
}

start_glusterfs ()
{
    prefix="/usr";
    exec_prefix=${prefix};
    cmd_line=$(echo "${exec_prefix}/sbin/glusterfs");

    if [ -n "$direct_io_mode_str" ]; then
        case "$( printf "%s\n" "$direct_io_mode_str" | tr '[A-Z]' '[a-z]'
)" in
            "enable")
                direct_io_mode=$DIO_ENABLE;
                ;;
            "disable")
                direct_io_mode=$DIO_DISABLE;
                ;;
            *)
                echo "invalid direct-io setting '$direct_io_mode_str',
using default '$direct_io_mode_default'";
                direct_io_mode=$direct_io_mode_default;
                ;;
        esac
    fi

    if [ -n "$log_level_str" ]; then
        case "$( printf "%s\n" "$log_level_str" | tr '[A-Z]' '[a-z]' )" 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 default
'$log_level_default'";
                log_level=$log_level_default;
                ;;
        esac
    fi
    cmd_line=$(echo "$cmd_line --log-level=$log_level
--direct-io-mode=$direct_io_mode ");

    if [ -n "$log_file" ]; then
        cmd_line=$(echo "$cmd_line --log-file=$log_file");
    fi

    if [ -z "$spec_location" ]; then
        cmd_line=$(echo "$cmd_line \
--server=$spec_server_ip \
--port=$spec_server_port");
    else
        cmd_line=$(echo "$cmd_line --spec-file=$spec_location");
    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');

    direct_io_mode_str=$(echo "$options" | sed -n
's/.*direct-io-mode=\([^,]*\).*/\1/p');

    spec_location="$1";

    [ -r "$spec_location" ] || {
        spec_server_ip=$(echo "$spec_location" | sed -n
's/\([^\:]*\).*/\1/p');
        spec_server_port=$(echo "$spec_location" | sed -n 's/.*:\([^
]*\).*/\1/p');
        [ -n "$spec_server_port" ] || {
            spec_server_port="6996";
        }

        spec_location="";
    }
    new_fs_options=$(echo "$options" | sed -e 's/[,]*log-file=[^,]*//' \
                                           -e 's/[,]*log-level=[^,]*//' \
                                           -e
's/[,]*direct-io-mode=[^,]*//'
\
                                           -e 's/[,]*spec=[^,]*//');
    # 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 "$@";







More information about the Gluster-devel mailing list