"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/mount/fuse/utils/mount_glusterfs.in" (16 Sep 2020, 13742 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 # (C) 2014 Red Hat Inc. <http://www.redhat.com>
    3 # (C) 2015 ungleich GmbH <http://www.ungleich.ch>
    4 #
    5 # This program is free software; you can redistribute it and/or
    6 # modify it under the terms of the GNU General Public License as
    7 # published by the Free Software Foundation; either version 2 of
    8 # the License, or (at your option) any later version.
    9 #
   10 # This program is distributed in the hope that it will be useful,
   11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   13 # GNU General Public License for more details.
   14 #
   15 # You should have received a copy of the GNU General Public
   16 # License along with this program; if not, write to the Free
   17 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   18 # Boston, MA 02110-1301 USA
   19 
   20 
   21 warn ()
   22 {
   23    echo "$@" >&2
   24 }
   25 
   26 _init ()
   27 {
   28 
   29     # log level definitions
   30     LOG_NONE=NONE;
   31     LOG_CRITICAL=CRITICAL;
   32     LOG_ERROR=ERROR;
   33     LOG_WARNING=WARNING;
   34     LOG_INFO=INFO
   35     LOG_DEBUG=DEBUG;
   36     LOG_TRACE=TRACE;
   37 
   38     HOST_NAME_MAX=64;
   39 
   40     prefix="@prefix@";
   41     exec_prefix=@exec_prefix@;
   42     cmd_line=$(echo "@sbindir@/glusterfs");
   43 
   44     alias lsL='ls -L'
   45     uname_s=`uname -s`
   46     case ${uname_s} in
   47         Darwin)
   48             getinode="stat -f %i"
   49             getdev="stat -f %d"
   50             ;;
   51     esac
   52 }
   53 
   54 is_valid_hostname ()
   55 {
   56     local server=$1
   57 
   58     length=$(echo $server | wc -c)
   59     if [ ${length} -gt ${HOST_NAME_MAX} ]; then
   60         return 1
   61     fi
   62 }
   63 
   64 parse_backup_volfile_servers ()
   65 {
   66     local server_list=$1
   67     local servers=""
   68     local new_servers=""
   69 
   70     servers=$(echo ${server_list} | sed 's/\:/ /g')
   71     for server in ${servers}; do
   72         is_valid_hostname ${server}
   73         if [ $? -eq 1 ]; then
   74             continue
   75         fi
   76         new_servers=$(echo "${new_servers} ${server}")
   77     done
   78 
   79     echo ${new_servers}
   80 }
   81 
   82 parse_volfile_servers ()
   83 {
   84     local server_list=$1
   85     local servers=""
   86     local new_servers=""
   87 
   88     servers=$(echo ${server_list} | sed 's/,/ /g')
   89     for server in ${servers}; do
   90         is_valid_hostname ${server}
   91         if [ $? -eq 1 ]; then
   92             continue
   93         fi
   94         new_servers=$(echo "${new_servers} ${server}")
   95     done
   96 
   97     echo ${new_servers}
   98 }
   99 
  100 start_glusterfs ()
  101 {
  102     if [ -n "$log_level_str" ]; then
  103         case "$( echo $log_level_str | awk '{print toupper($0)}')" in
  104             "ERROR")
  105                 log_level=$LOG_ERROR;
  106                 ;;
  107             "INFO")
  108                 log_level=$LOG_INFO;
  109                 ;;
  110             "DEBUG")
  111                 log_level=$LOG_DEBUG;
  112                 ;;
  113             "CRITICAL")
  114                 log_level=$LOG_CRITICAL;
  115                 ;;
  116             "WARNING")
  117                 log_level=$LOG_WARNING;
  118                 ;;
  119             "TRACE")
  120                 log_level=$LOG_TRACE;
  121                 ;;
  122             "NONE")
  123                 log_level=$LOG_NONE;
  124                 ;;
  125             *)
  126                 warn "invalid log level $log_level_str, using INFO";
  127                 log_level=$LOG_INFO;
  128                 ;;
  129         esac
  130     fi
  131 
  132     # options without values start here
  133     if [ -n "$read_only" ]; then
  134         cmd_line=$(echo "$cmd_line --read-only");
  135     fi
  136 
  137     if [ -n "$acl" ]; then
  138         cmd_line=$(echo "$cmd_line --acl");
  139     fi
  140 
  141     if [ -n "$selinux" ]; then
  142          cmd_line=$(echo "$cmd_line --selinux");
  143     fi
  144 
  145     if [ -n "$enable_ino32" ]; then
  146         cmd_line=$(echo "$cmd_line --enable-ino32");
  147     fi
  148 
  149     if [ -n "$worm" ]; then
  150         cmd_line=$(echo "$cmd_line --worm");
  151     fi
  152     if [ -n "$volfile_max_fetch_attempts" ]; then
  153        cmd_line=$(echo "$cmd_line --volfile-max-fetch-attempts=$volfile_max_fetch_attempts")
  154     fi
  155 
  156     if [ -n "$fopen_keep_cache" ]; then
  157         cmd_line=$(echo "$cmd_line --fopen-keep-cache");
  158     fi
  159 
  160     if [ -n "$volfile_check" ]; then
  161         cmd_line=$(echo "$cmd_line --volfile-check");
  162     fi
  163 
  164     if [ -n "$mem_accounting" ]; then
  165         cmd_line=$(echo "$cmd_line --mem-accounting");
  166     fi
  167 
  168     if [ -n "$aux_gfid_mount" ]; then
  169         cmd_line=$(echo "$cmd_line --aux-gfid-mount");
  170     fi
  171 
  172     if [ -n "$no_root_squash" ]; then
  173         cmd_line=$(echo "$cmd_line --no-root-squash");
  174     fi
  175 
  176     if [ -n "$capability" ]; then
  177          cmd_line=$(echo "$cmd_line --capability");
  178     fi
  179 
  180 #options with values start here
  181     if [ -n "$log_level" ]; then
  182         cmd_line=$(echo "$cmd_line --log-level=$log_level");
  183     fi
  184 
  185     if [ -n "$log_file" ]; then
  186         cmd_line=$(echo "$cmd_line --log-file=$log_file");
  187     fi
  188 
  189     if [ -n "$direct_io_mode" ]; then
  190         cmd_line=$(echo "$cmd_line --direct-io-mode=$direct_io_mode");
  191     fi
  192 
  193     if [ -n "$mac_compat" ]; then
  194         cmd_line=$(echo "$cmd_line --mac-compat=$mac_compat");
  195     fi
  196 
  197     if [ -n "$use_readdirp" ]; then
  198         cmd_line=$(echo "$cmd_line --use-readdirp=$use_readdirp");
  199     fi
  200 
  201     if [ -n "$volume_name" ]; then
  202         cmd_line=$(echo "$cmd_line --volume-name=$volume_name");
  203     fi
  204 
  205     if [ -n "$attribute_timeout" ]; then
  206         cmd_line=$(echo "$cmd_line --attribute-timeout=$attribute_timeout");
  207     fi
  208 
  209     if [ -n "$entry_timeout" ]; then
  210         cmd_line=$(echo "$cmd_line --entry-timeout=$entry_timeout");
  211     fi
  212 
  213     if [ -n "$negative_timeout" ]; then
  214         cmd_line=$(echo "$cmd_line --negative-timeout=$negative_timeout");
  215     fi
  216 
  217     if [ -n "$gid_timeout" ]; then
  218         cmd_line=$(echo "$cmd_line --gid-timeout=$gid_timeout");
  219     fi
  220 
  221     if [ -n "$bg_qlen" ]; then
  222         cmd_line=$(echo "$cmd_line --background-qlen=$bg_qlen");
  223     fi
  224 
  225     if [ -n "$cong_threshold" ]; then
  226         cmd_line=$(echo "$cmd_line --congestion-threshold=$cong_threshold");
  227     fi
  228 
  229     if [ -n "$fuse_mountopts" ]; then
  230         cmd_line=$(echo "$cmd_line --fuse-mountopts=$fuse_mountopts");
  231     fi
  232 
  233     if [ -n "$xlator_option" ]; then
  234         cmd_line=$(echo "$cmd_line --xlator-option=$xlator_option");
  235     fi
  236 
  237     if [ -n "$process_name" ]; then
  238         cmd_line=$(echo "$cmd_line --process-name fuse.$process_name");
  239     else
  240         cmd_line=$(echo "$cmd_line --process-name fuse");
  241     fi
  242 
  243     if [ -z "$volfile_loc" ]; then
  244         if  [ -n "$server_ip" ]; then
  245 
  246             servers=$(parse_volfile_servers ${server_ip});
  247             if [ -n "$servers" ]; then
  248                 for i in $(echo ${servers}); do
  249                     cmd_line=$(echo "$cmd_line --volfile-server=$i");
  250                 done
  251             else
  252                 warn "ERROR: No valid servers found on command line.. exiting"
  253                 print_usage
  254                 exit 1
  255             fi
  256 
  257             if [ -n "$backupvolfile_server" ]; then
  258                 if [ -z "$backup_volfile_servers" ]; then
  259                     is_valid_hostname ${backupvolfile_server};
  260                     if [ $? -eq 1 ]; then
  261                         warn "ERROR: Invalid backup server specified.. exiting"
  262                         exit 1
  263                     fi
  264                     cmd_line=$(echo "$cmd_line --volfile-server=$backupvolfile_server");
  265                 fi
  266             fi
  267 
  268             if [ -n "$backup_volfile_servers" ]; then
  269                 backup_servers=$(parse_backup_volfile_servers ${backup_volfile_servers})
  270                 for i in $(echo ${backup_servers}); do
  271                     cmd_line=$(echo "$cmd_line --volfile-server=$i");
  272                 done
  273             fi
  274 
  275             if [ -n "$server_port" ]; then
  276                 cmd_line=$(echo "$cmd_line --volfile-server-port=$server_port");
  277             fi
  278 
  279             if [ -n "$transport" ]; then
  280                 cmd_line=$(echo "$cmd_line --volfile-server-transport=$transport");
  281             fi
  282 
  283             if [ -n "$volume_id" ]; then
  284                 cmd_line=$(echo "$cmd_line --volfile-id=$volume_id");
  285             fi
  286         fi
  287     else
  288         cmd_line=$(echo "$cmd_line --volfile=$volfile_loc");
  289     fi
  290 
  291     if [ -n "$fuse_mountopts" ]; then
  292         cmd_line=$(echo "$cmd_line --fuse-mountopts=$fuse_mountopts");
  293     fi
  294 
  295     cmd_line=$(echo "$cmd_line $mount_point");
  296     $cmd_line;
  297 
  298     if [ $? -ne 0 ]; then
  299         exit 1;
  300     fi
  301 }
  302 
  303 print_usage ()
  304 {
  305 cat << EOF >&2
  306 Usage: $0 <volumeserver>:<volumeid/volumeport> -o<options> <mountpoint>
  307 Options:
  308 man 8 $0
  309 To display the version number of the mount helper: $0 -V
  310 EOF
  311 }
  312 
  313 with_options()
  314 {
  315     local key=$1
  316     local value=$2
  317 
  318     # Handle options with values.
  319     case "$key" in
  320         "log-level")
  321             log_level_str=$value
  322             ;;
  323         "log-file")
  324             log_file=$value
  325             ;;
  326         "transport")
  327             transport=$value
  328             ;;
  329         "direct-io-mode")
  330             direct_io_mode=$value
  331             ;;
  332         "mac-compat")
  333             mac_compat=$value
  334             ;;
  335         "volume-name")
  336             volume_name=$value
  337             ;;
  338         "volume-id")
  339             volume_id=$value
  340             ;;
  341         "volfile-check")
  342             volfile_check=$value
  343             ;;
  344         "server-port")
  345             server_port=$value
  346             ;;
  347         "attribute-timeout")
  348             attribute_timeout=$value
  349             ;;
  350         "entry-timeout")
  351             entry_timeout=$value
  352             ;;
  353         "negative-timeout")
  354             negative_timeout=$value
  355             ;;
  356         "gid-timeout")
  357             gid_timeout=$value
  358             ;;
  359         "background-qlen")
  360             bg_qlen=$value
  361             ;;
  362         "backup-volfile-servers")
  363             backup_volfile_servers=$value
  364             ;;
  365         "backupvolfile-server")
  366             backupvolfile_server=$value
  367             ;;
  368         "fetch-attempts")
  369             volfile_max_fetch_attempts=$value
  370             ;;
  371         "congestion-threshold")
  372             cong_threshold=$value
  373             ;;
  374         "xlator-option")
  375             xlator_option=$value
  376             ;;
  377         "fuse-mountopts")
  378             fuse_mountopts=$value
  379             ;;
  380         "use-readdirp")
  381             use_readdirp=$value
  382             ;;
  383         "no-root-squash")
  384             if [ $value = "yes" ] ||
  385                 [ $value = "on" ] ||
  386                 [ $value = "enable" ] ||
  387                 [ $value = "true" ] ; then
  388                 no_root_squash=1;
  389             fi ;;
  390         "root-squash")
  391             if [ $value = "no" ] ||
  392                 [ $value = "off" ] ||
  393                 [ $value = "disable" ] ||
  394                 [ $value = "false" ] ; then
  395                 no_root_squash=1;
  396             fi ;;
  397         "process-name")
  398             process_name=$value
  399             ;;
  400         *)
  401             warn "Invalid option: $key"
  402             exit 1
  403             ;;
  404     esac
  405 }
  406 
  407 without_options()
  408 {
  409     local option=$1
  410     # Handle options without values.
  411     case "$option" in
  412         "ro")
  413             read_only=1
  414             ;;
  415         "acl")
  416             acl=1
  417             ;;
  418         "selinux")
  419             selinux=1
  420             ;;
  421         "worm")
  422             worm=1
  423             ;;
  424         "fopen-keep-cache")
  425             fopen_keep_cache=1
  426             ;;
  427         "enable-ino32")
  428             enable_ino32=1
  429             ;;
  430         "mem-accounting")
  431             mem_accounting=1
  432             ;;
  433         "aux-gfid-mount")
  434             if [ ${uname_s} = "Linux" ]; then
  435                 aux_gfid_mount=1
  436             fi
  437             ;;
  438          # "mount -t glusterfs" sends this, but it's useless.
  439         "rw")
  440             ;;
  441          # these ones are interpreted during system initialization
  442         "noauto")
  443             ;;
  444         "_netdev")
  445             ;;
  446         "capability")
  447             capability=1
  448             ;;
  449         *)
  450             warn "Invalid option $option";
  451             exit 1
  452             ;;
  453     esac
  454 }
  455 
  456 parse_options()
  457 {
  458     local optarg=${1}
  459     for pair in $(echo $optarg | sed 's/,/ /g'); do
  460         key=$(echo "$pair" | cut -f1 -d'=');
  461         value=$(echo "$pair" | cut -f2- -d'=');
  462         if [ "$key" = "$value" ]; then
  463             without_options $pair;
  464         else
  465             with_options $key $value;
  466         fi
  467     done
  468 }
  469 
  470 main ()
  471 {
  472     ## `mount` on OSX specifies options as first argument
  473     echo $1|grep -q -- "-o"
  474     if [ $? -eq 0 ];  then
  475         volfile_loc=$3
  476         mount_point=$4
  477     else
  478         volfile_loc=$1
  479         mount_point=$2
  480     fi
  481 
  482     while getopts "Vo:h" opt; do
  483         case "${opt}" in
  484             o)
  485                 parse_options ${OPTARG};
  486                 ;;
  487             V)
  488                 ${cmd_line} -V;
  489                 exit 0;
  490                 ;;
  491             h)
  492                 print_usage;
  493                 exit 0;
  494                 ;;
  495             ?)
  496                 print_usage;
  497                 exit 0;
  498                 ;;
  499         esac
  500     done
  501 
  502     [ -r "$volfile_loc" ] || {
  503         # '%' included to support ipv6 link local addresses
  504         server_ip=$(echo "$volfile_loc" | sed -n 's/\([a-zA-Z0-9:%.\-]*\):.*/\1/p');
  505         volume_str=$(echo "$volfile_loc" | sed -n 's/.*:\([^ ]*\).*/\1/p');
  506         [ -n "$volume_str" ] && {
  507             volume_id="$volume_str";
  508         }
  509         volfile_loc="";
  510     }
  511 
  512     [ -z "$volume_id" -o -z "$server_ip" ] && {
  513         cat <<EOF >&2
  514 ERROR: Server name/volume name unspecified cannot proceed further..
  515 Please specify correct format
  516 Usage:
  517 man 8 $0
  518 EOF
  519         exit 1;
  520     }
  521 
  522     grep_ret=$(echo ${mount_point} | grep '^\-o');
  523     [ "x" != "x${grep_ret}" ] && {
  524         cat <<EOF >&2
  525 ERROR: -o options cannot be specified in either first two arguments..
  526 Please specify correct style
  527 Usage:
  528 man 8 $0
  529 EOF
  530         exit 1;
  531     }
  532 
  533     # No need to do a ! -d test, it is taken care while initializing the
  534     # variable mount_point
  535     [ -z "$mount_point" -o ! -d "$mount_point" ] && {
  536         cat <<EOF >&2
  537 ERROR: Mount point does not exist
  538 Please specify a mount point
  539 Usage:
  540 man 8 $0
  541 EOF
  542         exit 1;
  543     }
  544 
  545     start_glusterfs;
  546 }
  547 
  548 _init "$@" && main "$@";