diff options
Diffstat (limited to 'xlators/mount')
| -rw-r--r-- | xlators/mount/fuse/src/fuse-bridge.c | 108 | ||||
| -rw-r--r-- | xlators/mount/fuse/src/fuse-helpers.c | 2 | ||||
| -rwxr-xr-x | xlators/mount/fuse/utils/mount_glusterfs.in | 600 | 
3 files changed, 552 insertions, 158 deletions
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index fd44c4fb5f5..745617a71c1 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -29,6 +29,7 @@ static void fuse_invalidate_inode(xlator_t *this, uint64_t fuse_ino);   * Send an invalidate notification up to fuse to purge the file from local   * page cache.   */ +  static int32_t  fuse_invalidate(xlator_t *this, inode_t *inode)  { @@ -45,8 +46,8 @@ fuse_invalidate(xlator_t *this, inode_t *inode)                  return 0;          nodeid = inode_to_fuse_nodeid(inode); -        gf_log(this->name, GF_LOG_DEBUG, "Invalidate inode id %lu.", nodeid); -        fuse_log_eh (this, "Sending invalidate inode id: %lu gfid: %s", nodeid, +        gf_log(this->name, GF_LOG_DEBUG, "Invalidate inode id %"GF_PRI_INODE"." , nodeid); +        fuse_log_eh (this, "Sending invalidate inode id: %"GF_PRI_INODE" gfid: %s", nodeid,                       uuid_utoa (inode->gfid));          fuse_invalidate_inode(this, nodeid); @@ -236,6 +237,7 @@ send_fuse_data (xlator_t *this, fuse_in_header_t *finh, void *data, size_t size)          send_fuse_data (this, finh, obj, sizeof (*(obj))) +#if FUSE_KERNEL_MINOR_VERSION >= 11  static void  fuse_invalidate_entry (xlator_t *this, uint64_t fuse_ino)  { @@ -293,6 +295,7 @@ fuse_invalidate_entry (xlator_t *this, uint64_t fuse_ino)          if (inode)                  inode_unref (inode);  } +#endif  /*   * Send an inval inode notification to fuse. This causes an invalidation of the @@ -301,6 +304,7 @@ fuse_invalidate_entry (xlator_t *this, uint64_t fuse_ino)  static void  fuse_invalidate_inode(xlator_t *this, uint64_t fuse_ino)  { +#if FUSE_KERNEL_MINOR_VERSION >= 11          struct fuse_out_header *fouh = NULL;          struct fuse_notify_inval_inode_out *fniio = NULL;          fuse_private_t *priv = NULL; @@ -346,8 +350,13 @@ fuse_invalidate_inode(xlator_t *this, uint64_t fuse_ino)          if (inode)                  inode_unref (inode); +#else +	gf_log ("glusterfs-fuse", GF_LOG_WARNING, +		"fuse_invalidate_inode not implemented on OS X due to missing FUSE notification"); +#endif  } +  int  send_fuse_err (xlator_t *this, fuse_in_header_t *finh, int error)  { @@ -368,7 +377,7 @@ send_fuse_err (xlator_t *this, fuse_in_header_t *finh, int error)                                       uuid_utoa (inode->gfid));                  } else {                          fuse_log_eh (this, "Sending %s for operation %d on " -                                     "inode %ld", strerror (error), +                                     "inode %" GF_PRI_INODE,  strerror (error),                                       finh->opcode, finh->nodeid);                  }          } @@ -624,6 +633,7 @@ fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)          GF_FREE (finh);  } +#if FUSE_KERNEL_MINOR_VERSION >= 16  static void  fuse_batch_forget(xlator_t *this, fuse_in_header_t *finh, void *msg)  { @@ -640,9 +650,9 @@ fuse_batch_forget(xlator_t *this, fuse_in_header_t *finh, void *msg)                          continue;  		do_forget(this, finh->unique, ffo[i].nodeid, ffo[i].nlookup);          } -  	GF_FREE(finh);  } +#endif  static int  fuse_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -1142,7 +1152,9 @@ fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg)  {          struct fuse_setattr_in *fsi = msg; +#if FUSE_KERNEL_MINOR_VERSION >= 9          fuse_private_t  *priv = NULL; +#endif          fuse_state_t *state = NULL;          GET_STATE (this, finh, state); @@ -1170,8 +1182,8 @@ fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg)           * http://git.kernel.org/?p=linux/kernel/git/torvalds/           * linux-2.6.git;a=commit;h=v2.6.23-5896-gf333211           */ -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >= 9 +        priv = this->private;          if (priv->proto_minor >= 9 && fsi->valid & FATTR_LOCKOWNER)                  state->lk_owner = fsi->lock_owner;  #endif @@ -1448,11 +1460,11 @@ fuse_mknod (xlator_t *this, fuse_in_header_t *finh, void *msg)          char         *name = (char *)(fmi + 1);          fuse_state_t   *state = NULL; +#if FUSE_KERNEL_MINOR_VERSION >= 12          fuse_private_t *priv = NULL; -        int32_t         ret = -1; +        int32_t         ret  = -1;          priv = this->private; -#if FUSE_KERNEL_MINOR_VERSION >= 12          if (priv->proto_minor < 12)                  name = (char *)msg + FUSE_COMPAT_MKNOD_IN_SIZE;  #endif @@ -1466,8 +1478,8 @@ fuse_mknod (xlator_t *this, fuse_in_header_t *finh, void *msg)          state->mode = fmi->mode;          state->rdev = fmi->rdev; -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >=12 +        priv = this->private;          FUSE_ENTRY_CREATE(this, priv, finh, state, fmi, "MKNOD");  #endif @@ -1515,10 +1527,12 @@ fuse_mkdir (xlator_t *this, fuse_in_header_t *finh, void *msg)  {          struct fuse_mkdir_in *fmi = msg;          char *name = (char *)(fmi + 1); +#if FUSE_KERNEL_MINOR_VERSION >=12          fuse_private_t *priv = NULL; +        int32_t         ret = -1; +#endif          fuse_state_t *state; -        int32_t ret = -1;          GET_STATE (this, finh, state); @@ -1528,8 +1542,8 @@ fuse_mkdir (xlator_t *this, fuse_in_header_t *finh, void *msg)          state->mode = fmi->mode; -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >=12 +        priv = this->private;          FUSE_ENTRY_CREATE(this, priv, finh, state, fmi, "MKDIR");  #endif @@ -2004,17 +2018,17 @@ fuse_create (xlator_t *this, fuse_in_header_t *finh, void *msg)  {  #if FUSE_KERNEL_MINOR_VERSION >= 12          struct fuse_create_in *fci = msg; +        fuse_private_t        *priv = NULL; +	int32_t                ret = -1;  #else          struct fuse_open_in *fci = msg;  #endif          char         *name = (char *)(fci + 1); -        fuse_private_t        *priv = NULL;          fuse_state_t *state = NULL; -        int32_t       ret = -1; -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >= 12 +        priv = this->private;          if (priv->proto_minor < 12)                  name = (char *)((struct fuse_open_in *)msg + 1);  #endif @@ -2028,8 +2042,8 @@ fuse_create (xlator_t *this, fuse_in_header_t *finh, void *msg)          state->mode = fci->mode;          state->flags = fci->flags; -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >=12 +        priv = this->private;          FUSE_ENTRY_CREATE(this, priv, finh, state, fci, "CREATE");  #endif          fuse_resolve_and_resume (state, fuse_create_resume); @@ -2167,7 +2181,9 @@ fuse_readv (xlator_t *this, fuse_in_header_t *finh, void *msg)  {          struct fuse_read_in *fri = msg; +#if FUSE_KERNEL_MINOR_VERSION >= 9          fuse_private_t  *priv = NULL; +#endif          fuse_state_t *state = NULL;          fd_t         *fd = NULL; @@ -2179,8 +2195,8 @@ fuse_readv (xlator_t *this, fuse_in_header_t *finh, void *msg)          fuse_resolve_fd_init (state, &state->resolve, fd);          /* See comment by similar code in fuse_settatr */ -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >= 9 +        priv = this->private;          if (priv->proto_minor >= 9 && fri->read_flags & FUSE_READ_LOCKOWNER)                  state->lk_owner = fri->lock_owner;  #endif @@ -2188,8 +2204,9 @@ fuse_readv (xlator_t *this, fuse_in_header_t *finh, void *msg)          state->size = fri->size;          state->off = fri->offset;          /* lets ignore 'fri->read_flags', but just consider 'fri->flags' */ +#if FUSE_KERNEL_MINOR_VERSION >= 9          state->io_flags = fri->flags; - +#endif          fuse_resolve_and_resume (state, fuse_readv_resume);  } @@ -2270,11 +2287,12 @@ fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg)          struct fuse_write_in *fwi = (struct fuse_write_in *)                                        (finh + 1); -        fuse_private_t  *priv = NULL;          fuse_state_t    *state = NULL;          fd_t            *fd = NULL; - +#if FUSE_KERNEL_MINOR_VERSION >= 9 +        fuse_private_t  *priv = NULL;          priv = this->private; +#endif          GET_STATE (this, finh, state);          fd          = FH_TO_FD (fwi->fh); @@ -2283,7 +2301,11 @@ fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg)          state->off  = fwi->offset;          /* lets ignore 'fwi->write_flags', but just consider 'fwi->flags' */ +#if FUSE_KERNEL_MINOR_VERSION >= 9          state->io_flags = fwi->flags; +#else +	state->io_flags = fwi->write_flags; +#endif          /* TODO: may need to handle below flag             (fwi->write_flags & FUSE_WRITE_CACHE);          */ @@ -2292,8 +2314,8 @@ fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg)          fuse_resolve_fd_init (state, &state->resolve, fd);          /* See comment by similar code in fuse_settatr */ -        priv = this->private;  #if FUSE_KERNEL_MINOR_VERSION >= 9 +        priv = this->private;          if (priv->proto_minor >= 9 && fwi->write_flags & FUSE_WRITE_LOCKOWNER)                  state->lk_owner = fwi->lock_owner;  #endif @@ -2636,7 +2658,7 @@ fuse_readdir (xlator_t *this, fuse_in_header_t *finh, void *msg)          fuse_resolve_and_resume (state, fuse_readdir_resume);  } - +#if FUSE_KERNEL_MINOR_VERSION >= 20  static int  fuse_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,  		   int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, @@ -2751,7 +2773,6 @@ out:  } -  void  fuse_readdirp_resume (fuse_state_t *state)  { @@ -2782,7 +2803,9 @@ fuse_readdirp (xlator_t *this, fuse_in_header_t *finh, void *msg)  	fuse_resolve_and_resume (state, fuse_readdirp_resume);  } +#endif +#if FUSE_KERNEL_MINOR_VERSION >= 19  #ifdef FALLOC_FL_KEEP_SIZE  static int  fuse_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, @@ -2825,7 +2848,7 @@ fuse_fallocate(xlator_t *this, fuse_in_header_t *finh, void *msg)  	fuse_resolve_and_resume(state, fuse_fallocate_resume);  }  #endif /* FALLOC_FL_KEEP_SIZE */ - +#endif /* FUSE minor version >= 19 */  static void  fuse_releasedir (xlator_t *this, fuse_in_header_t *finh, void *msg) @@ -3097,7 +3120,9 @@ fuse_setxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)                  gf_log ("fuse", GF_LOG_TRACE,                          "got request to invalidate %"PRIu64, finh->nodeid);                  send_fuse_err (this, finh, 0); +#if FUSE_KERNEL_MINOR_VERSION >= 11                  fuse_invalidate_entry (this, finh->nodeid); +#endif                  GF_FREE (finh);                  return;          } @@ -3746,7 +3771,7 @@ fuse_setlk (xlator_t *this, fuse_in_header_t *finh, void *msg)          return;  } - +#if FUSE_KERNEL_MINOR_VERSION >= 11  static void *  notify_kernel_loop (void *data)  { @@ -3782,7 +3807,7 @@ notify_kernel_loop (void *data)          return NULL;  } - +#endif  static void  fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg) @@ -3791,8 +3816,10 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)          struct fuse_init_out  fino      = {0,};          fuse_private_t       *priv      = NULL;          int                   ret       = 0; +#if FUSE_KERNEL_MINOR_VERSION >= 9          int                   pfd[2]    = {0,};          pthread_t             messenger; +#endif          priv = this->private; @@ -3885,16 +3912,17 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)          }          if (fini->minor < 9)                  *priv->msg0_len_p = sizeof(*finh) + FUSE_COMPAT_WRITE_IN_SIZE; -#endif +          if (priv->use_readdirp) {                  if (fini->flags & FUSE_DO_READDIRPLUS)                          fino.flags |= FUSE_DO_READDIRPLUS;          } - +#endif  	if (priv->fopen_keep_cache == 2) {  		/* If user did not explicitly set --fopen-keep-cache[=off],  		   then check if kernel support FUSE_AUTO_INVAL_DATA and ...  		*/ +#if FUSE_KERNEL_MINOR_VERSION >= 20  		if (fini->flags & FUSE_AUTO_INVAL_DATA) {  			/* ... enable fopen_keep_cache mode if supported.  			*/ @@ -3903,7 +3931,10 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)  				"fopen_keep_cache automatically.");  			fino.flags |= FUSE_AUTO_INVAL_DATA;  			priv->fopen_keep_cache = 1; -		} else { +		} else +#endif +		{ +  			gf_log ("glusterfs-fuse", GF_LOG_DEBUG, "No support "  				"for FUSE_AUTO_INVAL_DATA. Disabling "  				"fopen_keep_cache."); @@ -3914,20 +3945,24 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)  		/* If user explicitly set --fopen-keep-cache[=on],  		   then enable FUSE_AUTO_INVAL_DATA if possible.  		*/ +#if FUSE_KERNEL_MINOR_VERSION >= 20  		if (fini->flags & FUSE_AUTO_INVAL_DATA) {  			gf_log ("glusterfs-fuse", GF_LOG_DEBUG, "fopen_keep_cache "  				"is explicitly set. Enabling FUSE_AUTO_INVAL_DATA");  			fino.flags |= FUSE_AUTO_INVAL_DATA; -		} else { +		} else +#endif +		{  			gf_log ("glusterfs-fuse", GF_LOG_WARNING, "fopen_keep_cache "  				"is explicitly set. Support for "  				"FUSE_AUTO_INVAL_DATA is missing");  		}  	} +#if FUSE_KERNEL_MINOR_VERSION >= 22  	if (fini->flags & FUSE_ASYNC_DIO)  		fino.flags |= FUSE_ASYNC_DIO; - +#endif          ret = send_fuse_obj (this, finh, &fino);          if (ret == 0)                  gf_log ("glusterfs-fuse", GF_LOG_INFO, @@ -5142,11 +5177,20 @@ static fuse_handler_t *fuse_std_ops[FUSE_OP_HIGH] = {       /* [FUSE_IOCTL] */       /* [FUSE_POLL] */       /* [FUSE_NOTIFY_REPLY] */ + +#if FUSE_KERNEL_MINOR_VERSION >= 16  	[FUSE_BATCH_FORGET]= fuse_batch_forget, +#endif + +#if FUSE_KERNEL_MINOR_VERSION >= 19  #ifdef FALLOC_FL_KEEP_SIZE  	[FUSE_FALLOCATE]   = fuse_fallocate,  #endif /* FALLOC_FL_KEEP_SIZE */ +#endif + +#if FUSE_KERNEL_MINOR_VERSION >= 21  	[FUSE_READDIRPLUS] = fuse_readdirp, +#endif  }; @@ -5279,13 +5323,13 @@ init (xlator_t *this_xl)                  goto cleanup_exit;          } -        GF_OPTION_INIT ("attribute-timeout", priv->attribute_timeout, double, +        GF_OPTION_INIT (ZR_ATTR_TIMEOUT_OPT, priv->attribute_timeout, double,                          cleanup_exit); -        GF_OPTION_INIT ("entry-timeout", priv->entry_timeout, double, +        GF_OPTION_INIT (ZR_ENTRY_TIMEOUT_OPT, priv->entry_timeout, double,                          cleanup_exit); -        GF_OPTION_INIT ("negative-timeout", priv->negative_timeout, double, +        GF_OPTION_INIT (ZR_NEGATIVE_TIMEOUT_OPT, priv->negative_timeout, double,                          cleanup_exit);          GF_OPTION_INIT ("client-pid", priv->client_pid, int32, cleanup_exit); diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c index 2774bdaa812..0936d63111a 100644 --- a/xlators/mount/fuse/src/fuse-helpers.c +++ b/xlators/mount/fuse/src/fuse-helpers.c @@ -235,7 +235,7 @@ out:          if (sysctl(name, namelen, &kp, &kplen, NULL, 0) != 0)                  return; -        ngroups = MIN(kp.kp_eproc.e_ucred.cr_ngroups, GF_MAX_AUX_GROUPS); +        ngroups = MIN(kp.kp_eproc.e_ucred.cr_ngroups, NGROUPS_MAX);  	if (call_stack_alloc_groups (frame->root, ngroups) != 0)  		return;          for (i = 0; i < ngroups; i++) diff --git a/xlators/mount/fuse/utils/mount_glusterfs.in b/xlators/mount/fuse/utils/mount_glusterfs.in index b12b4e04e78..539b0f558c2 100755 --- a/xlators/mount/fuse/utils/mount_glusterfs.in +++ b/xlators/mount/fuse/utils/mount_glusterfs.in @@ -1,188 +1,538 @@  #!/bin/sh -# (C) 2008 Gluster Inc. <http://www.gluster.com> -#  +# (C) 2014 Red Hat Inc. <http://www.redhat.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 +warn () +{ +   echo "$@" >/dev/stderr +}  _init ()  { +      # log level definitions      LOG_NONE=NONE;      LOG_CRITICAL=CRITICAL;      LOG_ERROR=ERROR;      LOG_WARNING=WARNING; -    LOG_INFO=INFO; +    LOG_INFO=INFO      LOG_DEBUG=DEBUG; +    LOG_TRACE=TRACE; -    # set default log level to ERROR -    log_level=$LOG_INFO; -} +    HOST_NAME_MAX=64; -start_glusterfs () -{      prefix="@prefix@";      exec_prefix=@exec_prefix@;      cmd_line=$(echo "@sbindir@/glusterfs"); -     + +    alias lsL='ls -L' +    uname_s=`uname -s` +    case ${uname_s} in +        Darwin) +            getinode="stat -f %i" +            getdev="stat -f %d" +            ;; +    esac +} + +is_valid_hostname () +{ +    local server=$1 + +    length=$(echo $server | wc -c) +    if [ ${length} -gt ${HOST_NAME_MAX} ]; then +        return 1 +    fi +} + +parse_backup_volfile_servers () +{ +    local server_list=$1 +    local servers="" +    local new_servers="" + +    servers=$(echo ${server_list} | sed 's/\:/ /g') +    for server in ${servers}; do +        is_valid_hostname ${server} +        if [ $? -eq 1 ]; then +            continue +        fi +        new_servers=$(echo "${new_servers} ${server}") +    done + +    echo ${new_servers} +} + +parse_volfile_servers () +{ +    local server_list=$1 +    local servers="" +    local new_servers="" + +    servers=$(echo ${server_list} | sed 's/,/ /g') +    for server in ${servers}; do +        is_valid_hostname ${server} +        if [ $? -eq 1 ]; then +            continue +        fi +        new_servers=$(echo "${new_servers} ${server}") +    done + +    echo ${new_servers} +} + +start_glusterfs () +{      if [ -n "$log_level_str" ]; then -	case "$log_level_str" in -	    "ERROR") -		log_level=$LOG_ERROR; -		;; +        case "$( echo $log_level_str | awk '{print toupper($0)}')" in +            "ERROR") +                log_level=$LOG_ERROR; +                ;;              "INFO")                  log_level=$LOG_INFO;                  ;; -	    "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 INFO"; -		log_level=$LOG_INFO; -		;; -	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"); +            "DEBUG") +                log_level=$LOG_DEBUG; +                ;; +            "CRITICAL") +                log_level=$LOG_CRITICAL; +                ;; +            "WARNING") +                log_level=$LOG_WARNING; +                ;; +            "TRACE") +                log_level=$LOG_TRACE; +                ;; +            "NONE") +                log_level=$LOG_NONE; +                ;; +            *) +                warn "invalid log level $log_level_str, using INFO"; +                log_level=$LOG_INFO; +                ;; +        esac +    fi + +    # options without values start here +    if [ -n "$read_only" ]; then +        cmd_line=$(echo "$cmd_line --read-only"); +    fi + +    if [ -n "$acl" ]; then +        cmd_line=$(echo "$cmd_line --acl"); +    fi + +    if [ -n "$selinux" ]; then +         cmd_line=$(echo "$cmd_line --selinux"); +    fi + +    if [ -n "$enable_ino32" ]; then +        cmd_line=$(echo "$cmd_line --enable-ino32"); +    fi + +    if [ -n "$worm" ]; then +        cmd_line=$(echo "$cmd_line --worm"); +    fi +    if [ -n "$volfile_max_fetch_attempts" ]; then +       cmd_line=$(echo "$cmd_line --volfile-max-fetch-attempts=$volfile_max_fetch_attempts") +    fi + +    if [ -n "$fopen_keep_cache" ]; then +        cmd_line=$(echo "$cmd_line --fopen-keep-cache");      fi      if [ -n "$volfile_check" ]; then -	cmd_line=$(echo "$cmd_line --volfile-check"); +        cmd_line=$(echo "$cmd_line --volfile-check"); +    fi + +    if [ -n "$mem_accounting" ]; then +        cmd_line=$(echo "$cmd_line --mem-accounting"); +    fi + +    if [ -n "$aux_gfid_mount" ]; then +        cmd_line=$(echo "$cmd_line --aux-gfid-mount"); +    fi + +    if [ -n "$no_root_squash" ]; then +        cmd_line=$(echo "$cmd_line --no-root-squash"); +    fi + +#options with values start here +    if [ -n "$log_level" ]; then +        cmd_line=$(echo "$cmd_line --log-level=$log_level"); +    fi + +    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 --disable-direct-io-mode"); +        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-transport=$transport"); -	else -	    cmd_line=$(echo "$cmd_line \ ---volfile-server=$server_ip"); -	fi -    else -	cmd_line=$(echo "$cmd_line --volfile=$volfile_loc"); + +    if [ -n "$mac_compat" ]; then +        cmd_line=$(echo "$cmd_line --mac-compat=$mac_compat"); +    fi + +    if [ -n "$use_readdirp" ]; then +        cmd_line=$(echo "$cmd_line --use-readdirp=$use_readdirp");      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"); + +    if [ -n "$attribute_timeout" ]; then +        cmd_line=$(echo "$cmd_line --attribute-timeout=$attribute_timeout"); +    fi + +    if [ -n "$entry_timeout" ]; then +        cmd_line=$(echo "$cmd_line --entry-timeout=$entry_timeout"); +    fi + +    if [ -n "$negative_timeout" ]; then +        cmd_line=$(echo "$cmd_line --negative-timeout=$negative_timeout"); +    fi + +    if [ -n "$gid_timeout" ]; then +        cmd_line=$(echo "$cmd_line --gid-timeout=$gid_timeout"); +    fi + +    if [ -n "$bg_qlen" ]; then +        cmd_line=$(echo "$cmd_line --background-qlen=$bg_qlen"); +    fi + +    if [ -n "$cong_threshold" ]; then +        cmd_line=$(echo "$cmd_line --congestion-threshold=$cong_threshold"); +    fi + +    if [ -n "$fuse_mountopts" ]; then +        cmd_line=$(echo "$cmd_line --fuse-mountopts=$fuse_mountopts"); +    fi + +    if [ -n "$xlator_option" ]; then +        cmd_line=$(echo "$cmd_line --xlator-option=$xlator_option"); +    fi + +    # for rdma volume, we have to fetch volfile with '.rdma' added +    # to volume name, so that it fetches the right client vol file +    volume_id_rdma=""; + +    if [ -z "$volfile_loc" ]; then +        if  [ -n "$server_ip" ]; then + +            servers=$(parse_volfile_servers ${server_ip}); +            if [ -n "$servers" ]; then +                for i in $(echo ${servers}); do +                    cmd_line=$(echo "$cmd_line --volfile-server=$i"); +                done +            else +                warn "ERROR: No valid servers found on command line.. exiting" +                print_usage +                exit 1 +            fi + +            if [ -n "$backupvolfile_server" ]; then +                if [ -z "$backup_volfile_servers" ]; then +                    is_valid_hostname ${backupvolfile_server}; +                    if [ $? -eq 1 ]; then +                        warn "ERROR: Invalid backup server specified.. exiting" +                        exit 1 +                    fi +                    cmd_line=$(echo "$cmd_line --volfile-server=$backupvolfile_server"); +                fi +            fi + +            if [ -n "$backup_volfile_servers" ]; then +                backup_servers=$(parse_backup_volfile_servers ${backup_volfile_servers}) +                for i in $(echo ${backup_servers}); do +                    cmd_line=$(echo "$cmd_line --volfile-server=$i"); +                done +            fi + +            if [ -n "$server_port" ]; then +                cmd_line=$(echo "$cmd_line --volfile-server-port=$server_port"); +            fi + +            if [ -n "$transport" ]; then +                cmd_line=$(echo "$cmd_line --volfile-server-transport=$transport"); +                if [ "$transport" = "rdma" ]; then +                    volume_id_rdma=".rdma"; +                fi +            fi + +            if [ -n "$volume_id" ]; then +                if [ -n "$volume_id_rdma" ]; then +                    volume_id="$volume_id$volume_id_rdma"; +                fi +                cmd_line=$(echo "$cmd_line --volfile-id=$volume_id"); +            fi +        fi +    else +        cmd_line=$(echo "$cmd_line --volfile=$volfile_loc"); +    fi + +    if [ -n "$fuse_mountopts" ]; then +        cmd_line=$(echo "$cmd_line --fuse-mountopts=$fuse_mountopts");      fi      cmd_line=$(echo "$cmd_line $mount_point"); -    exec $cmd_line; +    $cmd_line; + +    if [ $? -ne 0 ]; then +        exit 1; +    fi  } +print_usage () +{ +cat << EOF >/dev/stderr +Usage: $0 <volumeserver>:<volumeid/volumeport> -o<options> <mountpoint> +Options: +man 8 $0 +To display the version number of the mount helper: $0 -V +EOF +} -main () +with_options()  { -     -    new_log_level="" -    log_file="" -    transport="" -    direct_io_mode="" -    volume_name="" -    new_fs_options="" -    volfile_check="" - -    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 $volfile_check ] && { -		    volfile_check=$(echo "$options" | sed -n 's/.*volfile-check=\([^,]*\).*/\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/[,]*volfile-check=[^,]*//' \ -		    -e 's/[,]*direct-io-mode=[^,]*//' \ -		    -e 's/[,]*transport=[^,]*//' \ -		    -e 's/[,]*volume-id=[^,]*//'); -		new_fs_options="$new_fs_options $this_option";		 -		;; -	esac +    local key=$1 +    local value=$2 + +    # Handle options with values. +    case "$key" in +        "log-level") +            log_level_str=$value +            ;; +        "log-file") +            log_file=$value +            ;; +        "transport") +            transport=$value +            ;; +        "direct-io-mode") +            direct_io_mode=$value +            ;; +        "mac-compat") +            mac_compat=$value +            ;; +        "volume-name") +            volume_name=$value +            ;; +        "volume-id") +            volume_id=$value +            ;; +        "volfile-check") +            volfile_check=$value +            ;; +        "server-port") +            server_port=$value +            ;; +        "attribute-timeout") +            attribute_timeout=$value +            ;; +        "entry-timeout") +            entry_timeout=$value +            ;; +        "negative-timeout") +            negative_timeout=$value +            ;; +        "gid-timeout") +            gid_timeout=$value +            ;; +        "background-qlen") +            bg_qlen=$value +            ;; +        "backup-volfile-servers") +            backup_volfile_servers=$value +            ;; +        "backupvolfile-server") +            backupvolfile_server=$value +            ;; +        "fetch-attempts") +            volfile_max_fetch_attempts=$value +            ;; +        "congestion-threshold") +            cong_threshold=$value +            ;; +        "xlator-option") +            xlator_option=$value +            ;; +        "fuse-mountopts") +            fuse_mountopts=$value +            ;; +        "use-readdirp") +            use_readdirp=$value +            ;; +        "no-root-squash") +            if [ $value == "yes" ] || +                [ $value == "on" ] || +                [ $value == "enable" ] || +                [ $value == "true" ] ; then +                no_root_squash=1; +            fi ;; +        "root-squash") +            if [ $value == "no" ] || +                [ $value == "off" ] || +                [ $value == "disable" ] || +                [ $value == "false" ] ; then +                no_root_squash=1; +            fi ;; +        *) +            warn "Invalid option: $key" +            exit 1 +            ;; +    esac +} + +without_options() +{ +    local option=$1 +    # Handle options without values. +    case "$option" in +        "ro") +            read_only=1 +            ;; +        "acl") +            acl=1 +            ;; +        "selinux") +            selinux=1 +            ;; +        "worm") +            worm=1 +            ;; +        "fopen-keep-cache") +            fopen_keep_cache=1 +            ;; +        "enable-ino32") +            enable_ino32=1 +            ;; +        "mem-accounting") +            mem_accounting=1 +            ;; +        "aux-gfid-mount") +            if [ ${uname_s} = "Linux" ]; then +                aux_gfid_mount=1 +            fi +            ;; +         # "mount -t glusterfs" sends this, but it's useless. +        "rw") +            ;; +         # these ones are interpreted during system initialization +        "noauto") +            ;; +        "_netdev") +            ;; +        *) +            warn "Invalid option $option"; +            exit 1 +            ;; +    esac +} + +parse_options() +{ +    local optarg=${1} +    for pair in $(echo ${optarg//,/ }); do +        key=$(echo "$pair" | cut -f1 -d'='); +        value=$(echo "$pair" | cut -f2- -d'='); +        if [ "$key" = "$value" ]; then +            without_options $pair; +        else +            with_options $key $value; +        fi      done +} -    [ -n "$new_log_level" ] && { -	log_level_str="$new_log_level"; -    } +main () +{ +    ## `mount` on OSX specifies options as first argument +    if [[ $1 =~ "-o" ]]; then +        volfile_loc=$3 +        mount_point=$4 +    else +        volfile_loc=$1 +        mount_point=$2 +    fi -    # TODO: use getopt. This is very much darwin specific -    volfile_loc="$1"; -    while [ "$volfile_loc" = "-o" ] ; do -	shift ; -	shift ; -	volfile_loc="$1"; +    while getopts "Vo:h" opt; do +        case "${opt}" in +            o) +                parse_options ${OPTARG}; +                ;; +            V) +                ${cmd_line} -V; +                exit 0; +                ;; +            h) +                print_usage; +                exit 0; +                ;; +            ?) +                print_usage; +                exit 0; +                ;; +        esac      done -     +      [ -r "$volfile_loc" ] || {          server_ip=$(echo "$volfile_loc" | sed -n 's/\([a-zA-Z0-9:.\-]*\):.*/\1/p'); -        volume_id=$(echo "$volfile_loc" | sed -n 's/[a-zA-Z0-9:.\-]*:\(.*\)/\1/p'); -	volfile_loc=""; +        volume_str=$(echo "$volfile_loc" | sed -n 's/.*:\([^ ]*\).*/\1/p'); +        [ -n "$volume_str" ] && { +            volume_id="$volume_str"; +        } +        volfile_loc=""; +    } + +    [ -z "$volume_id" -o -z "$server_ip" ] && { +        cat <<EOF >/dev/stderr +ERROR: Server name/volume name unspecified cannot proceed further.. +Please specify correct format +Usage: +man 8 $0 +EOF +        exit 1; +    } + +    grep_ret=$(echo ${mount_point} | grep '^\-o'); +    [ "x" != "x${grep_ret}" ] && { +        cat <<EOF >/dev/stderr +ERROR: -o options cannot be specified in either first two arguments.. +Please specify correct style +Usage: +man 8 $0 +EOF +        exit 1; +    } + +    # No need to do a ! -d test, it is taken care while initializing the +    # variable mount_point +    [ -z "$mount_point" -o ! -d "$mount_point" ] && { +        cat <<EOF >/dev/stderr +ERROR: Mount point does not exist +Please specify a mount point +Usage: +man 8 $0 +EOF +        exit 1;      } -    # 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;  }  | 
