From a3cb38e3edf005bef73da4c9cfd958474a14d50f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 17 Apr 2014 15:54:34 -0700 Subject: build: MacOSX Porting fixes git@forge.gluster.org:~schafdog/glusterfs-core/osx-glusterfs Working functionality on MacOSX - GlusterD (management daemon) - GlusterCLI (management cli) - GlusterFS FUSE (using OSXFUSE) - GlusterNFS (without NLM - issues with rpc.statd) Change-Id: I20193d3f8904388e47344e523b3787dbeab044ac BUG: 1089172 Signed-off-by: Harshavardhana Signed-off-by: Dennis Schafroth Tested-by: Harshavardhana Tested-by: Dennis Schafroth Reviewed-on: http://review.gluster.org/7503 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/cluster/afr/src/afr-inode-write.c | 3 - xlators/cluster/afr/src/afr-self-heal-entry.c | 4 +- xlators/cluster/afr/src/afr-self-heal-metadata.c | 1 - xlators/cluster/afr/src/afr.c | 6 +- xlators/cluster/dht/src/Makefile.am | 1 - xlators/cluster/dht/src/dht-common.h | 4 +- xlators/cluster/dht/src/dht-shared.c | 5 +- xlators/cluster/stripe/src/Makefile.am | 1 - xlators/cluster/stripe/src/stripe-helpers.c | 10 +- xlators/cluster/stripe/src/stripe.c | 10 +- xlators/debug/io-stats/src/io-stats.c | 2 +- xlators/debug/trace/src/trace.c | 38 ++ xlators/debug/trace/src/trace.h | 37 -- xlators/encryption/crypt/src/crypt.c | 8 +- xlators/encryption/crypt/src/crypt.h | 15 +- xlators/features/changelog/src/Makefile.am | 2 +- xlators/features/changelog/src/changelog-helpers.h | 14 +- xlators/features/compress/src/Makefile.am | 2 +- xlators/features/index/src/index.c | 4 +- xlators/features/locks/src/inodelk.c | 2 +- xlators/features/locks/src/posix.c | 11 +- xlators/features/mac-compat/src/Makefile.am | 5 +- xlators/features/mac-compat/src/mac-compat.c | 246 ++++++--- xlators/features/mac-compat/src/mac-compat.h | 41 ++ xlators/features/marker/src/marker-quota-helper.h | 2 +- xlators/features/marker/src/marker-quota.c | 6 +- xlators/features/marker/src/marker.c | 32 +- xlators/features/quota/src/quota.c | 8 +- xlators/features/quota/src/quotad-aggregator.c | 2 +- xlators/mgmt/glusterd/src/Makefile.am | 2 +- xlators/mgmt/glusterd/src/glusterd-hooks.c | 2 +- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 7 +- xlators/mgmt/glusterd/src/glusterd-quota.c | 6 +- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 92 ++-- xlators/mgmt/glusterd/src/glusterd-store.c | 4 +- xlators/mgmt/glusterd/src/glusterd-utils.c | 31 +- xlators/mgmt/glusterd/src/glusterd-utils.h | 8 +- xlators/mgmt/glusterd/src/glusterd-volgen.c | 20 +- xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 2 +- xlators/mgmt/glusterd/src/glusterd-volume-set.c | 24 +- xlators/mgmt/glusterd/src/glusterd.c | 9 +- xlators/mount/fuse/src/fuse-bridge.c | 108 ++-- xlators/mount/fuse/src/fuse-helpers.c | 2 +- xlators/mount/fuse/utils/mount_glusterfs.in | 600 ++++++++++++++++----- xlators/nfs/server/src/nfs-fops.c | 11 +- xlators/nfs/server/src/nfs.c | 70 ++- xlators/nfs/server/src/nfs.h | 2 + xlators/nfs/server/src/nfs3-helpers.c | 4 +- xlators/nfs/server/src/nfs3.c | 6 +- xlators/nfs/server/src/nlm4.c | 38 +- xlators/nfs/server/src/nlm4.h | 9 + xlators/performance/io-cache/src/io-cache.c | 21 +- xlators/performance/quick-read/src/quick-read.c | 6 +- xlators/performance/read-ahead/src/read-ahead.c | 5 +- .../performance/readdir-ahead/src/readdir-ahead.c | 8 +- .../performance/write-behind/src/write-behind.c | 4 +- xlators/protocol/client/src/client.c | 3 +- xlators/protocol/server/src/server-handshake.c | 2 +- xlators/protocol/server/src/server-helpers.c | 3 +- xlators/protocol/server/src/server-rpc-fops.c | 4 +- xlators/protocol/server/src/server.c | 2 +- xlators/storage/bd/src/bd-helper.c | 2 +- xlators/storage/bd/src/bd.c | 9 +- xlators/storage/bd/src/bd.h | 6 +- xlators/storage/posix/src/posix-helpers.c | 39 +- xlators/storage/posix/src/posix.c | 182 ++++++- xlators/storage/posix/src/posix.h | 10 + 67 files changed, 1356 insertions(+), 529 deletions(-) create mode 100644 xlators/features/mac-compat/src/mac-compat.h (limited to 'xlators') diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index 3013ae730..00e0d2676 100644 --- a/xlators/cluster/afr/src/afr-inode-write.c +++ b/xlators/cluster/afr/src/afr-inode-write.c @@ -37,7 +37,6 @@ #include "afr.h" #include "afr-transaction.h" -//#include "afr-self-heal-common.h" static void @@ -1750,5 +1749,3 @@ out: } /* }}} */ - - diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c index 9605d69f4..9e714b026 100644 --- a/xlators/cluster/afr/src/afr-self-heal-entry.c +++ b/xlators/cluster/afr/src/afr-self-heal-entry.c @@ -585,12 +585,10 @@ afr_selfheal_data_opendir (xlator_t *this, inode_t *inode) } loc_wipe (&loc); - - return fd; + return fd; } - int afr_selfheal_entry (call_frame_t *frame, xlator_t *this, inode_t *inode) { diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c index b31a33237..83628297f 100644 --- a/xlators/cluster/afr/src/afr-self-heal-metadata.c +++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c @@ -18,7 +18,6 @@ #include "afr-self-heal.h" #include "byte-order.h" - #define AFR_HEAL_ATTR (GF_SET_ATTR_UID|GF_SET_ATTR_GID|GF_SET_ATTR_MODE) int diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index 5e12910b7..ead08425f 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -185,7 +185,7 @@ reconfigure (xlator_t *this, dict_t *options) uint32, out); GF_OPTION_RECONF (AFR_SH_READDIR_SIZE_KEY, priv->sh_readdir_size, - options, size, out); + options, size_uint64, out); /* Reset this so we re-discover in case the topology changed. */ GF_OPTION_RECONF ("ensure-durability", priv->ensure_durability, options, bool, out); @@ -331,7 +331,7 @@ init (xlator_t *this) GF_OPTION_INIT ("eager-lock", priv->eager_lock, bool, out); GF_OPTION_INIT ("quorum-type", qtype, str, out); GF_OPTION_INIT ("quorum-count", priv->quorum_count, uint32, out); - GF_OPTION_INIT (AFR_SH_READDIR_SIZE_KEY, priv->sh_readdir_size, size, + GF_OPTION_INIT (AFR_SH_READDIR_SIZE_KEY, priv->sh_readdir_size, size_uint64, out); fix_quorum_options(this,priv,qtype); @@ -436,7 +436,7 @@ fini (xlator_t *this) priv = this->private; this->private = NULL; afr_priv_destroy (priv); - if (this->itable);//I dont see any destroy func + //if (this->itable);//I dont see any destroy func return 0; } diff --git a/xlators/cluster/dht/src/Makefile.am b/xlators/cluster/dht/src/Makefile.am index 174bea841..3fc29bf81 100644 --- a/xlators/cluster/dht/src/Makefile.am +++ b/xlators/cluster/dht/src/Makefile.am @@ -1,4 +1,3 @@ - xlator_LTLIBRARIES = dht.la nufa.la switch.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h index d74d0dfd4..2ece28a61 100644 --- a/xlators/cluster/dht/src/dht-common.h +++ b/xlators/cluster/dht/src/dht-common.h @@ -47,7 +47,7 @@ struct dht_layout { int gen; int type; int ref; /* use with dht_conf_t->layout_lock */ - int search_unhashed; + gf_boolean_t search_unhashed; struct { int err; /* 0 = normal -1 = dir exists and no xattr @@ -263,7 +263,7 @@ struct dht_conf { int gen; dht_du_t *du_stats; double min_free_disk; - double min_free_inodes; + double min_free_inodes; char disk_unit; int32_t refresh_interval; gf_boolean_t unhashed_sticky_bit; diff --git a/xlators/cluster/dht/src/dht-shared.c b/xlators/cluster/dht/src/dht-shared.c index 36c073973..f2e7467ab 100644 --- a/xlators/cluster/dht/src/dht-shared.c +++ b/xlators/cluster/dht/src/dht-shared.c @@ -366,7 +366,6 @@ dht_reconfigure (xlator_t *this, dict_t *options) " lookup-unhashed should be boolean," " not (%s), defaulting to (%d)", temp_str, conf->search_unhashed); - //return -1; ret = -1; goto out; } @@ -449,11 +448,11 @@ gf_defrag_pattern_list_fill (xlator_t *this, gf_defrag_info_t *defrag, char *dat if (!pattern) goto out; if (!num) { - if (gf_string2bytesize(pattern, &pattern_list->size) + if (gf_string2bytesize_uint64(pattern, &pattern_list->size) == 0) { pattern = "*"; } - } else if (gf_string2bytesize (num, &pattern_list->size) != 0) { + } else if (gf_string2bytesize_uint64 (num, &pattern_list->size) != 0) { gf_log (this->name, GF_LOG_ERROR, "invalid number format \"%s\"", num); goto out; diff --git a/xlators/cluster/stripe/src/Makefile.am b/xlators/cluster/stripe/src/Makefile.am index 2d151422a..4268d6f03 100644 --- a/xlators/cluster/stripe/src/Makefile.am +++ b/xlators/cluster/stripe/src/Makefile.am @@ -1,4 +1,3 @@ - xlator_LTLIBRARIES = stripe.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster diff --git a/xlators/cluster/stripe/src/stripe-helpers.c b/xlators/cluster/stripe/src/stripe-helpers.c index a047d4a2e..3c12809d6 100644 --- a/xlators/cluster/stripe/src/stripe-helpers.c +++ b/xlators/cluster/stripe/src/stripe-helpers.c @@ -13,6 +13,7 @@ #include "stripe.h" #include "byte-order.h" #include "mem-types.h" +#include "logging.h" void stripe_local_wipe (stripe_local_t *local) @@ -260,8 +261,8 @@ stripe_fill_pathinfo_xattr (xlator_t *this, stripe_local_t *local, goto out; } - (void) snprintf (stripe_size_str, 20, "%ld", - (local->fctx) ? local->fctx->stripe_size : 0); + (void) snprintf (stripe_size_str, 20, "%"PRId64, + (long long) (local->fctx) ? local->fctx->stripe_size : 0); /* extra bytes for decorations (brackets and <>'s) */ padding = strlen (this->name) + strlen (STRIPE_PATHINFO_HEADER) @@ -504,7 +505,7 @@ set_default_block_size (stripe_private_t *priv, char *num) GF_VALIDATE_OR_GOTO (THIS->name, num, out); - if (gf_string2bytesize (num, &priv->block_size) != 0) { + if (gf_string2bytesize_uint64 (num, &priv->block_size) != 0) { gf_log (THIS->name, GF_LOG_ERROR, "invalid number format \"%s\"", num); goto out; @@ -554,7 +555,7 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) if (ret) goto out; } - if (gf_string2bytesize (num, &stripe_opt->block_size) != 0) { + if (gf_string2bytesize_uint64 (num, &stripe_opt->block_size) != 0) { gf_log (this->name, GF_LOG_ERROR, "invalid number format \"%s\"", num); goto out; @@ -674,4 +675,3 @@ uncoalesced_size(off_t size, uint64_t stripe_size, int stripe_count, return size; } - diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index 79e80b513..0ebea8168 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -4459,7 +4459,7 @@ stripe_is_bd (dict_t *this, char *key, data_t *value, void *data) return 0; } -inline gf_boolean_t +static inline gf_boolean_t stripe_setxattr_is_bd (dict_t *dict) { gf_boolean_t is_bd = _gf_false; @@ -4628,7 +4628,7 @@ out: return ret; } -inline gf_boolean_t +static inline gf_boolean_t stripe_fsetxattr_is_special (dict_t *dict) { gf_boolean_t is_spl = _gf_false; @@ -5080,7 +5080,7 @@ reconfigure (xlator_t *this, dict_t *options) goto unlock; } - if (gf_string2bytesize (opt->default_value, &priv->block_size)){ + if (gf_string2bytesize_uint64 (opt->default_value, &priv->block_size)){ gf_log (this->name, GF_LOG_ERROR, "Unable to set default block-size "); ret = -1; @@ -5187,7 +5187,7 @@ init (xlator_t *this) ret = -1; goto unlock; } - if (gf_string2bytesize (opt->default_value, &priv->block_size)){ + if (gf_string2bytesize_uint64 (opt->default_value, &priv->block_size)){ gf_log (this->name, GF_LOG_ERROR, "Unable to set default block-size "); ret = -1; @@ -5601,7 +5601,7 @@ err: return 0; } -inline gf_boolean_t +static inline gf_boolean_t stripe_is_special_xattr (const char *name) { gf_boolean_t is_spl = _gf_false; diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index d63fbb26c..5b4c833fb 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -509,7 +509,7 @@ out: return 0; } -inline int +static inline int ios_stats_cleanup (xlator_t *this, inode_t *inode) { diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index c9d839356..1efd50e65 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -18,6 +18,44 @@ * Very helpful translator for debugging. */ +static inline void +trace_stat_to_str(struct iatt *buf, char *str) +{ + char atime_buf[256] = {0,}; + char mtime_buf[256] = {0,}; + char ctime_buf[256] = {0,}; + uint64_t ia_time = 0; + + if (!buf) + return; + + ia_time = buf->ia_atime; + strftime (atime_buf, 256, "[%b %d %H:%M:%S]", + localtime ((time_t *)&ia_time)); + ia_time = buf->ia_mtime; + strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", + localtime ((time_t *)&ia_time)); + + ia_time = buf->ia_ctime; + strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", + localtime ((time_t *)&ia_time)); + + snprintf (str, sizeof (str), + "gfid=%s ino=%"PRIu64", mode=%o, " + "nlink=%"GF_PRI_NLINK", uid=%u, " + "gid=%u, size=%"PRIu64", " + "blocks=%"PRIu64", atime=%s, " + "mtime=%s, ctime=%s", + uuid_utoa (buf->ia_gfid), + buf->ia_ino, + st_mode_from_ia (buf->ia_prot, buf->ia_type), + buf->ia_nlink, buf->ia_uid, + buf->ia_gid, buf->ia_size, + buf->ia_blocks, atime_buf, + mtime_buf, ctime_buf); +} + + int dump_history_trace (circular_buffer_t *cb, void *data) { diff --git a/xlators/debug/trace/src/trace.h b/xlators/debug/trace/src/trace.h index 045eefb36..62d1bc9c9 100644 --- a/xlators/debug/trace/src/trace.h +++ b/xlators/debug/trace/src/trace.h @@ -59,40 +59,3 @@ typedef struct { "%s", _string); \ } \ } while (0); - -#define trace_stat_to_str(buf, statstr) \ - do { \ - char atime_buf[256] = {0,}; \ - char mtime_buf[256] = {0,}; \ - char ctime_buf[256] = {0,}; \ - uint64_t ia_time = 0; \ - \ - if (!buf) \ - break; \ - \ - ia_time = buf->ia_atime; \ - strftime (atime_buf, 256, "[%b %d %H:%M:%S]", \ - localtime ((time_t *)&ia_time)); \ - \ - ia_time = buf->ia_mtime; \ - strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", \ - localtime ((time_t *)&ia_time)); \ - \ - ia_time = buf->ia_ctime; \ - strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", \ - localtime ((time_t *)&ia_time)); \ - \ - snprintf (statstr, sizeof (statstr), \ - "gfid=%s ino=%"PRIu64", mode=%o, " \ - "nlink=%"GF_PRI_NLINK", uid=%u, " \ - "gid=%u, size=%"PRIu64", " \ - "blocks=%"PRIu64", atime=%s, " \ - "mtime=%s, ctime=%s", \ - uuid_utoa (buf->ia_gfid), buf->ia_ino, \ - st_mode_from_ia (buf->ia_prot, \ - buf->ia_type), \ - buf->ia_nlink, buf->ia_uid, \ - buf->ia_gid, buf->ia_size, \ - buf->ia_blocks, atime_buf, \ - mtime_buf, ctime_buf); \ - } while (0); diff --git a/xlators/encryption/crypt/src/crypt.c b/xlators/encryption/crypt/src/crypt.c index 1abdad31d..13b1bd962 100644 --- a/xlators/encryption/crypt/src/crypt.c +++ b/xlators/encryption/crypt/src/crypt.c @@ -4169,9 +4169,9 @@ int32_t master_set_block_size (xlator_t *this, crypt_private_t *priv, if (options != NULL) GF_OPTION_RECONF("block-size", block_size, options, - size, error); + size_uint64, error); else - GF_OPTION_INIT("block-size", block_size, size, error); + GF_OPTION_INIT("block-size", block_size, size_uint64, error); switch (block_size) { case 512: @@ -4224,9 +4224,9 @@ static int master_set_data_key_size (xlator_t *this, crypt_private_t *priv, if (options != NULL) GF_OPTION_RECONF("data-key-size", key_size, options, - size, error); + uint64, error); else - GF_OPTION_INIT("data-key-size", key_size, size, error); + GF_OPTION_INIT("data-key-size", key_size, uint64, error); ret = data_cipher_algs[master->m_alg][master->m_mode].check_key(key_size); if (ret) { diff --git a/xlators/encryption/crypt/src/crypt.h b/xlators/encryption/crypt/src/crypt.h index ff8eb571b..eb7291f13 100644 --- a/xlators/encryption/crypt/src/crypt.h +++ b/xlators/encryption/crypt/src/crypt.h @@ -22,6 +22,7 @@ #include #include #include "crypt-mem-types.h" +#include "compat.h" #define CRYPT_XLATOR_ID (0) @@ -38,13 +39,17 @@ #define MASTER_VOL_KEY_SIZE (32) #define NMTD_VOL_KEY_SIZE (16) -#ifdef __NetBSD__ +#if defined(__NetBSD__) typedef off_t loff_t; #endif +#if defined(GF_DARWIN_HOST_OS) +typedef uint64_t loff_t; +#endif + struct crypt_key { uint32_t len; - const char *label; + const char *label; }; /* @@ -124,7 +129,7 @@ struct master_cipher_info { * master key */ unsigned char m_key[MASTER_VOL_KEY_SIZE]; - /* + /* * volume key for oid authentication */ unsigned char m_nmtd_key[NMTD_VOL_KEY_SIZE]; @@ -870,8 +875,8 @@ static inline linkop_unwind_handler_t linkop_unwind_dispatch(glusterfs_fop_t fop return rename_unwind; default: gf_log("crypt", GF_LOG_ERROR, "Bad link operation %d", fop); - return NULL; - } + return NULL; + } } static inline mtd_op_t linkop_mtdop_dispatch(glusterfs_fop_t fop) diff --git a/xlators/features/changelog/src/Makefile.am b/xlators/features/changelog/src/Makefile.am index 54c21ac21..c5d5e100e 100644 --- a/xlators/features/changelog/src/Makefile.am +++ b/xlators/features/changelog/src/Makefile.am @@ -12,7 +12,7 @@ changelog_la_SOURCES = changelog.c changelog-rt.c changelog-helpers.c \ changelog_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -fPIC -D_FILE_OFFSET_BITS=64 \ - -D_GNU_SOURCE -D$(GF_HOST_OS) -shared -nostartfiles -DDATADIR=\"$(localstatedir)\" + -D_GNU_SOURCE -D$(GF_HOST_OS) -shared -DDATADIR=\"$(localstatedir)\" AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/features/changelog/src/changelog-helpers.h b/xlators/features/changelog/src/changelog-helpers.h index b441f7068..53588f55e 100644 --- a/xlators/features/changelog/src/changelog-helpers.h +++ b/xlators/features/changelog/src/changelog-helpers.h @@ -268,9 +268,11 @@ typedef struct { void changelog_thread_cleanup (xlator_t *this, pthread_t thr_id); -inline void * + +void * changelog_get_usable_buffer (changelog_local_t *local); -inline void + +void changelog_set_usable_record_and_length (changelog_local_t *local, size_t len, int xr); void @@ -290,16 +292,16 @@ int changelog_inject_single_event (xlator_t *this, changelog_priv_t *priv, changelog_log_data_t *cld); -inline size_t +size_t changelog_entry_length (); -inline int +int changelog_write (int fd, char *buffer, size_t len); int changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len); -inline int +int changelog_handle_change (xlator_t *this, changelog_priv_t *priv, changelog_log_data_t *cld); -inline void +void changelog_update (xlator_t *this, changelog_priv_t *priv, changelog_local_t *local, changelog_log_type type); void * diff --git a/xlators/features/compress/src/Makefile.am b/xlators/features/compress/src/Makefile.am index 0bf757c06..263b21b78 100644 --- a/xlators/features/compress/src/Makefile.am +++ b/xlators/features/compress/src/Makefile.am @@ -10,7 +10,7 @@ cdc_la_SOURCES = cdc.c cdc-helper.c cdc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS) \ --shared -nostartfiles $(LIBZ_CFLAGS) +-shared $(LIBZ_CFLAGS) AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c index 5c1c65fbd..4b2eb2e29 100644 --- a/xlators/features/index/src/index.c +++ b/xlators/features/index/src/index.c @@ -497,13 +497,13 @@ fop_fxattrop_index_action (xlator_t *this, inode_t *inode, dict_t *xattr) _xattrop_index_action (this, inode, xattr); } -inline gf_boolean_t +static inline gf_boolean_t index_xattrop_track (loc_t *loc, gf_xattrop_flags_t flags, dict_t *dict) { return (flags == GF_XATTROP_ADD_ARRAY); } -inline gf_boolean_t +static inline gf_boolean_t index_fxattrop_track (fd_t *fd, gf_xattrop_flags_t flags, dict_t *dict) { return (flags == GF_XATTROP_ADD_ARRAY); diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c index e7093e60e..2d9aa83ec 100644 --- a/xlators/features/locks/src/inodelk.c +++ b/xlators/features/locks/src/inodelk.c @@ -35,7 +35,7 @@ __pl_inodelk_ref (pl_inode_lock_t *lock) lock->ref++; } -void +inline void __pl_inodelk_unref (pl_inode_lock_t *lock) { lock->ref--; diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index 2db327687..337623d65 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -294,7 +294,7 @@ pl_locks_by_fd (pl_inode_t *pl_inode, fd_t *fd) { list_for_each_entry (l, &pl_inode->ext_list, list) { - if ((l->fd_num == fd_to_fdnum(fd))) { + if (l->fd_num == fd_to_fdnum(fd)) { found = 1; break; } @@ -319,7 +319,7 @@ delete_locks_of_fd (xlator_t *this, pl_inode_t *pl_inode, fd_t *fd) { list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) { - if ((l->fd_num == fd_to_fdnum(fd))) { + if (l->fd_num == fd_to_fdnum(fd)) { if (l->blocked) { list_move_tail (&l->list, &blocked_list); continue; @@ -644,7 +644,8 @@ pl_fgetxattr_handle_lockinfo (xlator_t *this, fd_t *fd, pl_inode_t *pl_inode = NULL; char *key = NULL, *buf = NULL; int32_t op_ret = 0; - unsigned long fdnum = 0, len = 0; + unsigned long fdnum = 0; + int32_t len = 0; dict_t *tmp = NULL; pl_inode = pl_inode_get (this, fd->inode); @@ -1340,7 +1341,7 @@ __fd_has_locks (pl_inode_t *pl_inode, fd_t *fd) posix_lock_t *l = NULL; list_for_each_entry (l, &pl_inode->ext_list, list) { - if ((l->fd_num == fd_to_fdnum(fd))) { + if (l->fd_num == fd_to_fdnum(fd)) { found = 1; break; } @@ -1369,7 +1370,7 @@ __dup_locks_to_fdctx (pl_inode_t *pl_inode, fd_t *fd, int ret = 0; list_for_each_entry (l, &pl_inode->ext_list, list) { - if ((l->fd_num == fd_to_fdnum(fd))) { + if (l->fd_num == fd_to_fdnum(fd)) { duplock = lock_dup (l); if (!duplock) { ret = -1; diff --git a/xlators/features/mac-compat/src/Makefile.am b/xlators/features/mac-compat/src/Makefile.am index f8567edce..42ed350e9 100644 --- a/xlators/features/mac-compat/src/Makefile.am +++ b/xlators/features/mac-compat/src/Makefile.am @@ -6,9 +6,10 @@ mac_compat_la_LDFLAGS = -module -avoid-version mac_compat_la_SOURCES = mac-compat.c mac_compat_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la +noinst_HEADERS = mac-compat.h + AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src AM_CFLAGS = -Wall $(GF_CFLAGS) -CLEANFILES = - +CLEANFILES = diff --git a/xlators/features/mac-compat/src/mac-compat.c b/xlators/features/mac-compat/src/mac-compat.c index 7cb550ad5..0eaf563e8 100644 --- a/xlators/features/mac-compat/src/mac-compat.c +++ b/xlators/features/mac-compat/src/mac-compat.c @@ -15,35 +15,28 @@ #include "xlator.h" #include "defaults.h" #include "compat-errno.h" +#include "syscall.h" +#include "mem-pool.h" +#include "mac-compat.h" - -enum apple_xattr { - GF_FINDER_INFO_XATTR, - GF_RESOURCE_FORK_XATTR, - GF_XATTR_ALL, - GF_XATTR_NONE -}; - -static char *apple_xattr_name[] = { - [GF_FINDER_INFO_XATTR] = "com.apple.FinderInfo", - [GF_RESOURCE_FORK_XATTR] = "com.apple.ResourceFork" -}; - -static const char *apple_xattr_value[] = { - [GF_FINDER_INFO_XATTR] = - /* 1 2 3 4 5 6 7 8 */ - "\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0", - [GF_RESOURCE_FORK_XATTR] = "" -}; - -static int32_t apple_xattr_len[] = { - [GF_FINDER_INFO_XATTR] = 32, - [GF_RESOURCE_FORK_XATTR] = 1 -}; - +static int +dict_key_remove_namespace(dict_t *dict, char *key, data_t *value, void *data) +{ + /* + char buffer[3*value->len+1]; + int index = 0; + for (index = 0; index < value->len; index++) + sprintf(buffer+3*index, " %02x", value->data[index]); + */ + xlator_t *this = (xlator_t *) data; + if (strncmp(key, "user.", 5) == 0) { + dict_set (dict, key + 5, value); + gf_log (this->name, GF_LOG_DEBUG, + "remove_namespace_dict: %s -> %s ", key, key + 5); + dict_del (dict, key); + } + return 0; +} int32_t maccomp_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -53,54 +46,91 @@ maccomp_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, intptr_t ax = (intptr_t)this->private; int i = 0; + gf_log (this->name, GF_LOG_DEBUG, + "getxattr_cbk: dict %p private: %p xdata %p ", dict, + this->private, xdata); + + if (dict) { + dict_foreach(dict, dict_key_remove_namespace, this); + } + else { + // TODO: we expect dict to exist here, don't know why this + // this is needed + dict = dict_new(); + } + gf_log (this->name, GF_LOG_DEBUG, + "getxattr_cbk: dict %p ax: %ld op_ret %d op_err %d ", dict, ax, + op_ret, op_errno); if ((ax == GF_XATTR_ALL && op_ret >= 0) || ax != GF_XATTR_NONE) { op_ret = op_errno = 0; - for (i = 0; i < GF_XATTR_ALL; i++) { if (dict_get (dict, apple_xattr_name[i])) continue; - + /* set dummy data */ + gf_log (this->name, GF_LOG_DEBUG, + "getxattr_cbk: setting dummy data %p, %s", dict, + apple_xattr_name[i]); if (dict_set (dict, apple_xattr_name[i], bin_to_data ((void *)apple_xattr_value[i], apple_xattr_len[i])) == -1) { op_ret = -1; - op_errno = ENOMEM; + op_errno = ENOATTR; break; } } } - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata); - return 0; } -int32_t -maccomp_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name, dict_t *xdata) +static +int prepend_xattr_user_namespace(dict_t *dict, char *key, data_t *value, void *obj) { - intptr_t ax = GF_XATTR_NONE; - int i = 0; + xlator_t *this = (xlator_t *) obj; + dict_t *newdict = (dict_t *) this->private; + char *newkey = NULL; + gf_add_prefix(XATTR_USER_PREFIX, key, &newkey); + key = newkey; + dict_set(newdict, (char *)key, value); + if (newkey) + GF_FREE(newkey); + return 0; +} +intptr_t +check_name(const char *name, char **newkey) +{ + intptr_t ax = GF_XATTR_NONE; if (name) { + int i = 0; for (i = 0; i < GF_XATTR_ALL; i++) { if (strcmp (apple_xattr_name[i], name) == 0) { ax = i; - break; } } + gf_add_prefix("user.", name, newkey); } else ax = GF_XATTR_ALL; + return ax; +} - this->private = (void *)ax; +int32_t +maccomp_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) +{ + char *newkey = NULL; + this->private = (void *) check_name(name, &newkey); + gf_log (this->name, GF_LOG_DEBUG, + "getxattr: name %s private: %p xdata %p ", name, + this->private, xdata); STACK_WIND (frame, maccomp_getxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr, - loc, name, xdata); + loc, newkey, xdata); return 0; } @@ -109,30 +139,17 @@ int32_t maccomp_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, dict_t *xdata) { - intptr_t ax = GF_XATTR_NONE; - int i = 0; - - if (name) { - for (i = 0; i < GF_XATTR_ALL; i++) { - if (strcmp (apple_xattr_name[i], name) == 0) { - ax = i; - - break; - } - } - } else - ax = GF_XATTR_ALL; - - this->private = (void *)ax; + char *newkey = NULL; + this->private = (void *) check_name(name, &newkey); STACK_WIND (frame, maccomp_getxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fgetxattr, - fd, name, xdata); + fd, newkey, xdata); + GF_FREE(newkey); return 0; } - int32_t maccomp_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, dict_t *xdata) @@ -141,12 +158,56 @@ maccomp_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (op_ret == -1 && ax != GF_XATTR_NONE) op_ret = op_errno = 0; - + gf_log (this->name, GF_LOG_DEBUG, + "setxattr_cbk op_ret %d op_errno %d private: %p xdata %p ", + op_ret, op_errno, this->private, xdata); STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); + return 0; +} +int32_t +maccomp_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *iatt1, + struct iatt *iattr2, dict_t *xdata) +{ + gf_log (this->name, GF_LOG_DEBUG, + "setattr_cbk op_ret %d op_errno %d private: %p xdata %p ", + op_ret, op_errno, this->private, xdata); + STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, + iatt1, iattr2, xdata); return 0; } +int map_flags(int flags) +{ + /* DARWIN has different defines on XATTR_ flags. + There do not seem to be a POSIX standard + Parse any other flags over. + NOFOLLOW is always true on Linux and Darwin + */ + int linux_flags = flags & ~(GF_XATTR_CREATE | GF_XATTR_REPLACE | XATTR_REPLACE); + if (XATTR_CREATE & flags) + linux_flags |= GF_XATTR_CREATE; + if (XATTR_REPLACE & flags) + linux_flags |= GF_XATTR_REPLACE; + return linux_flags; +} + +int32_t +maccomp_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + char *newkey = NULL; + + this->private = (void *) check_name(name, &newkey); + + STACK_WIND (frame, default_fremovexattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fremovexattr, + fd, newkey, xdata); + GF_FREE(newkey); + return 0; +} int32_t maccomp_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, @@ -162,16 +223,56 @@ maccomp_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, break; } } + dict_t *newdict = dict_new(); + this->private = (void *) newdict; + dict_foreach(dict, prepend_xattr_user_namespace, this); this->private = (void *)ax; - + int linux_flags = map_flags(flags); + gf_log (this->name, GF_LOG_DEBUG, + "setxattr flags: %d -> %d dict %p private: %p xdata %p ", + flags, linux_flags, dict, this->private, xdata); STACK_WIND (frame, maccomp_setxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, - loc, dict, flags, xdata); + loc, newdict, linux_flags, xdata); + dict_unref(newdict); return 0; } +int32_t +maccomp_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *iattr, + int32_t flags, dict_t *xdata) +{ + gf_log (this->name, GF_LOG_DEBUG, + "setattr iattr %p private: %p xdata %p ", + iattr, this->private, xdata); + STACK_WIND (frame, maccomp_setattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, + loc, iattr, flags, xdata); + return 0; +} + +int32_t +maccomp_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) +{ + char *newkey = NULL; + this->private = (void *) check_name(name, &newkey); + + STACK_WIND (frame, default_removexattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->removexattr, + loc, newkey, xdata); + + gf_log (this->name, GF_LOG_TRACE, + "removeattr name %p private: %p xdata %p ", + name, this->private, xdata); + GF_FREE(newkey); + return 0; + +} int32_t maccomp_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, @@ -188,12 +289,20 @@ maccomp_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, } } - this->private = (void *)ax; + dict_t *newdict = dict_new(); + this->private = (void *) newdict; + dict_foreach(dict, prepend_xattr_user_namespace, this); + this->private = (void *)ax; + int linux_flags = map_flags(flags); + gf_log (this->name, GF_LOG_DEBUG, + "fsetxattr flags: %d -> %d dict %p private: %p xdata %p ", + flags, linux_flags, dict, this->private, xdata); STACK_WIND (frame, maccomp_setxattr_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetxattr, - fd, dict, flags, xdata); + fd, newdict, linux_flags, xdata); + dict_unref(newdict); return 0; } @@ -224,10 +333,13 @@ fini (xlator_t *this) struct xlator_fops fops = { - .getxattr = maccomp_getxattr, - .fgetxattr = maccomp_fgetxattr, - .setxattr = maccomp_setxattr, - .fsetxattr = maccomp_fsetxattr, + .getxattr = maccomp_getxattr, + .fgetxattr = maccomp_fgetxattr, + .setxattr = maccomp_setxattr, + .setattr = maccomp_setattr, + .fsetxattr = maccomp_fsetxattr, + .removexattr = maccomp_removexattr, + .fremovexattr = maccomp_fremovexattr, }; struct xlator_cbks cbks; diff --git a/xlators/features/mac-compat/src/mac-compat.h b/xlators/features/mac-compat/src/mac-compat.h new file mode 100644 index 000000000..b033ca0e4 --- /dev/null +++ b/xlators/features/mac-compat/src/mac-compat.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2014 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __MAC_COMPAT_H__ +#define __MAC_COMPAT_H__ + +enum apple_xattr { + GF_FINDER_INFO_XATTR, + GF_RESOURCE_FORK_XATTR, + GF_XATTR_ALL, + GF_XATTR_NONE +}; + +static char *apple_xattr_name[] = { + [GF_FINDER_INFO_XATTR] = "com.apple.FinderInfo", + [GF_RESOURCE_FORK_XATTR] = "com.apple.ResourceFork" +}; + +static const char *apple_xattr_value[] = { + [GF_FINDER_INFO_XATTR] = + /* 1 2 3 4 5 6 7 8 */ + "\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0", + [GF_RESOURCE_FORK_XATTR] = "" +}; + +static int32_t apple_xattr_len[] = { + [GF_FINDER_INFO_XATTR] = 32, + [GF_RESOURCE_FORK_XATTR] = 1 +}; + +#endif /* __MAC_COMPAT_H__ */ diff --git a/xlators/features/marker/src/marker-quota-helper.h b/xlators/features/marker/src/marker-quota-helper.h index 6cdd14881..b200413b0 100644 --- a/xlators/features/marker/src/marker-quota-helper.h +++ b/xlators/features/marker/src/marker-quota-helper.h @@ -9,7 +9,7 @@ */ #ifndef _MARKER_QUOTA_HELPER_H -#define _MARKER_QUOTA_HELPER +#define _MARKER_QUOTA_HELPER_H #ifndef _CONFIG_H #define _CONFIG_H diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c index a758e938f..1903fdc40 100644 --- a/xlators/features/marker/src/marker-quota.c +++ b/xlators/features/marker/src/marker-quota.c @@ -365,7 +365,10 @@ mq_update_size_xattr (call_frame_t *frame, void *cookie, xlator_t *this, local->loc.path, ntoh64 (*delta)); new_dict = dict_new (); - if (!new_dict); + if (!new_dict) { + errno = ENOMEM; + goto err; + } ret = dict_set_bin (new_dict, QUOTA_SIZE_KEY, delta, 8); if (ret) @@ -385,7 +388,6 @@ mq_update_size_xattr (call_frame_t *frame, void *cookie, xlator_t *this, err: if (op_ret == -1 || ret == -1) { local->err = -1; - mq_release_lock_on_dirty_inode (frame, NULL, this, 0, 0, NULL); } diff --git a/xlators/features/marker/src/marker.c b/xlators/features/marker/src/marker.c index a27a266f0..adcf3d8e7 100644 --- a/xlators/features/marker/src/marker.c +++ b/xlators/features/marker/src/marker.c @@ -255,18 +255,18 @@ out: return 0; } -int32_t +gf_boolean_t call_from_special_client (call_frame_t *frame, xlator_t *this, const char *name) { struct volume_mark *vol_mark = NULL; marker_conf_t *priv = NULL; - gf_boolean_t ret = _gf_true; + gf_boolean_t is_true = _gf_true; priv = (marker_conf_t *)this->private; if (frame->root->pid != GF_CLIENT_PID_GSYNCD || name == NULL || strcmp (name, MARKER_XATTR_PREFIX "." VOLUME_MARK) != 0) { - ret = _gf_false; + is_true = _gf_false; goto out; } @@ -274,7 +274,7 @@ call_from_special_client (call_frame_t *frame, xlator_t *this, const char *name) marker_getxattr_stampfile_cbk (frame, this, name, vol_mark, NULL); out: - return ret; + return is_true; } int32_t @@ -348,10 +348,10 @@ int32_t marker_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, dict_t *xdata) { - gf_boolean_t ret = _gf_false; - marker_conf_t *priv = NULL; - unsigned long cookie = 0; - marker_local_t *local = NULL; + gf_boolean_t is_true = _gf_false; + marker_conf_t *priv = NULL; + unsigned long cookie = 0; + marker_local_t *local = NULL; priv = this->private; @@ -362,16 +362,15 @@ marker_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, MARKER_INIT_LOCAL (frame, local); - ret = loc_copy (&local->loc, loc); - if (ret < 0) - goto out; + if ((loc_copy (&local->loc, loc)) < 0) + goto out; gf_log (this->name, GF_LOG_DEBUG, "USER:PID = %d", frame->root->pid); if (priv && priv->feature_enabled & GF_XTIME) - ret = call_from_special_client (frame, this, name); + is_true = call_from_special_client (frame, this, name); - if (ret == _gf_false) { + if (is_true == _gf_false) { if (name == NULL) { /* Signifies that marker translator * has to filter the quota's xattr's, @@ -380,10 +379,11 @@ marker_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, */ cookie = 1; } - STACK_WIND_COOKIE (frame, marker_getxattr_cbk, (void *)cookie, + STACK_WIND_COOKIE (frame, marker_getxattr_cbk, + (void *)cookie, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->getxattr, loc, - name, xdata); + FIRST_CHILD(this)->fops->getxattr, + loc, name, xdata); } return 0; diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 4beaae341..2ca4da0c1 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -244,7 +244,7 @@ out: return; } -inline void +static inline void quota_link_count_decrement (quota_local_t *local) { call_stub_t *stub = NULL; @@ -270,7 +270,7 @@ out: return; } -inline void +static inline void quota_handle_validate_error (quota_local_t *local, int32_t op_ret, int32_t op_errno) { @@ -377,7 +377,7 @@ quota_timeout (struct timeval *tv, int32_t timeout) return timed_out; } -inline void +static inline void quota_add_parent (quota_dentry_t *dentry, struct list_head *list) { quota_dentry_t *entry = NULL; @@ -928,7 +928,7 @@ err: return 0; } -inline int +static inline int quota_get_limits (xlator_t *this, dict_t *dict, int64_t *hard_lim, int64_t *soft_lim) { diff --git a/xlators/features/quota/src/quotad-aggregator.c b/xlators/features/quota/src/quotad-aggregator.c index f3f65ca2a..5f13fd251 100644 --- a/xlators/features/quota/src/quotad-aggregator.c +++ b/xlators/features/quota/src/quotad-aggregator.c @@ -227,7 +227,7 @@ quotad_aggregator_getlimit (rpcsvc_request_t *req) if (ret) goto err; - ret = dict_set_int32 (state->xdata, GET_ANCESTRY_PATH_KEY,42); + ret = dict_set_int32 (state->xdata, GET_ANCESTRY_PATH_KEY, 42); if (ret) goto err; diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am index 933c44019..b89ec6ddc 100644 --- a/xlators/mgmt/glusterd/src/Makefile.am +++ b/xlators/mgmt/glusterd/src/Makefile.am @@ -29,7 +29,7 @@ noinst_HEADERS = glusterd.h glusterd-utils.h glusterd-op-sm.h \ AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(rpclibdir) -I$(CONTRIBDIR)/rbtree \ -I$(top_srcdir)/rpc/xdr/src -I$(top_srcdir)/rpc/rpc-lib/src \ - -I$(CONTRIBDIR)/uuid \ + -I$(CONTRIBDIR)/uuid -I$(CONTRIBDIR)/mount \ -DSBIN_DIR=\"$(sbindir)\" -DDATADIR=\"$(localstatedir)\" \ -DGSYNCD_PREFIX=\"$(libexecdir)/glusterfs\"\ -DSYNCDAEMON_COMPILE=$(SYNCDAEMON_COMPILE) $(XML_CPPFLAGS) diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c index 352b6ba11..78730a564 100644 --- a/xlators/mgmt/glusterd/src/glusterd-hooks.c +++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c @@ -181,7 +181,7 @@ glusterd_hooks_set_volume_args (dict_t *dict, runner_t *runner) goto out; runner_add_arg (runner, "-o"); - for (i = 1; (ret == 0); i++) { + for (i = 1; ret == 0; i++) { snprintf (query, sizeof (query), "key%d", i); ret = dict_get_str (dict, query, &key); if (ret) diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index fb5e097d9..c22c2ea63 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -1020,7 +1020,7 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) { int ret = 0; char *volname = NULL; - gf_boolean_t exists = _gf_false; + int exists = 0; char msg[2048] = {0}; char *key = NULL; char *key_fixed = NULL; @@ -1068,6 +1068,7 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) ret = -1; goto out; } + if (!exists) { ret = snprintf (msg, sizeof (msg), "Option %s does not exist", key); @@ -1819,7 +1820,7 @@ glusterd_op_set_volume (dict_t *dict) if (dict_count == 0) { ret = glusterd_volset_help (NULL, &op_errstr); if (ret) { - gf_log (this->name, GF_LOG_ERROR, "%s", + gf_log (this->name, GF_LOG_ERROR, "%s", (op_errstr)? op_errstr: "Volume set help internal error"); } @@ -3262,7 +3263,7 @@ glusterd_is_get_op (xlator_t *this, glusterd_op_t op, dict_t *dict) if (op == GD_OP_STATUS_VOLUME) return _gf_true; - if ((op == GD_OP_SET_VOLUME)) { + if (op == GD_OP_SET_VOLUME) { //check for set volume help ret = dict_get_str (dict, "volname", &volname); if (volname && diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index cf23b6404..7f798ad26 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -474,7 +474,7 @@ glusterd_set_quota_limit (char *volname, char *path, char *hard_limit, new_limit.sl = hton64 (new_limit.sl); - ret = gf_string2bytesize (hard_limit, (uint64_t*)&new_limit.hl); + ret = gf_string2bytesize_uint64 (hard_limit, (uint64_t*)&new_limit.hl); if (ret) goto out; @@ -1400,13 +1400,13 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) "Faild to get hard-limit from dict"); goto out; } - ret = gf_string2bytesize (hard_limit_str, &hard_limit); + ret = gf_string2bytesize_uint64 (hard_limit_str, &hard_limit); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to convert hard-limit string to value"); goto out; } - if (hard_limit > INT64_MAX) { + if (hard_limit > UINT64_MAX) { ret = -1; ret = gf_asprintf (op_errstr, "Hard-limit %s is greater" " than %"PRId64"bytes. Please set a " diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index d11abee70..b294d1bc6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -18,6 +18,14 @@ #include #include #include +#include + + +#if !defined(__NetBSD__) && !defined(GF_DARWIN_HOST_OS) +#include +#else +#include "mntent_compat.h" +#endif #include "globals.h" #include "compat.h" @@ -40,9 +48,7 @@ #include "cli1-xdr.h" #include "xdr-generic.h" -#ifdef GF_LINUX_HOST_OS -#include -#endif +#include "lvm-defaults.h" char snap_mount_folder[PATH_MAX]; @@ -267,7 +273,7 @@ out: int snap_max_hard_limits_validate (dict_t *dict, char *volname, - uint64_t value, char **op_errstr) + uint64_t value, char **op_errstr) { char err_str[PATH_MAX] = ""; glusterd_conf_t *conf = NULL; @@ -449,7 +455,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) for (i = 0; i < volume_count; i++) { memset (snapbrckcnt, '\0', sizeof(snapbrckcnt)); ret = snprintf (snapbrckcnt, sizeof(snapbrckcnt) - 1, - "vol%ld_brickcount", i+1); + "vol%"PRId64"_brickcount", i+1); ret = dict_get_int64 (src, snapbrckcnt, &brick_count); if (ret) { gf_log (this->name, GF_LOG_TRACE, @@ -460,7 +466,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) for (j = 0; j < brick_count; j++) { /* Fetching data from source dict */ snprintf (key, sizeof(key) - 1, - "vol%ld.brickdir%ld", i+1, j); + "vol%"PRId64".brickdir%"PRId64, i+1, j); ret = dict_get_ptr (src, key, (void **)&snap_brick_dir); @@ -471,7 +477,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (key, sizeof(key) - 1, - "vol%ld.brick_snapdevice%ld", i+1, j); + "vol%"PRId64".brick_snapdevice%"PRId64, i+1, j); ret = dict_get_ptr (src, key, (void **)&snap_device); @@ -482,7 +488,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (snapbrckord, sizeof(snapbrckord) - 1, - "vol%ld.brick%ld.order", i+1, j); + "vol%"PRId64".brick%"PRId64".order", i+1, j); ret = dict_get_int64 (src, snapbrckord, &brick_order); if (ret) { @@ -493,7 +499,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) /* Adding the data in the dst dict */ snprintf (key, sizeof(key) - 1, - "vol%ld.brickdir%ld", i+1, brick_order); + "vol%"PRId64".brickdir%"PRId64, i+1, brick_order); tmpstr = gf_strdup (snap_brick_dir); if (!tmpstr) { @@ -511,7 +517,7 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (key, sizeof(key) - 1, - "vol%ld.brick_snapdevice%ld", + "vol%"PRId64".brick_snapdevice%"PRId64, i+1, brick_order); tmpstr = gf_strdup (snap_device); @@ -618,8 +624,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, goto out; } if (volcount <= 0) { - snprintf (err_str, sizeof (err_str), "Invalid volume count %ld " - "supplied", volcount); + snprintf (err_str, sizeof (err_str), "Invalid volume count %"PRId64 + " supplied", volcount); ret = -1; goto out; } @@ -638,7 +644,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, } for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%ld", i); + snprintf (key, sizeof (key), "volname%"PRId64, i); ret = dict_get_str (dict, key, &volname); if (ret) { snprintf (err_str, sizeof (err_str), @@ -690,7 +696,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof(key) - 1, "vol%ld_volid", i); + snprintf (key, sizeof(key) - 1, "vol%"PRId64"_volid", i); ret = dict_get_bin (dict, key, (void **)&snap_volid); if (ret) { gf_log (this->name, GF_LOG_ERROR, @@ -745,7 +751,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, } snprintf (key, sizeof(key), - "vol%ld.brick_snapdevice%ld", i, + "vol%"PRId64".brick_snapdevice%"PRId64, i, brick_count); ret = dict_set_dynstr (rsp_dict, key, device); if (ret) { @@ -783,7 +789,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, ret = -1; goto out; } - snprintf (key, sizeof(key), "vol%ld.brickdir%ld", i, + snprintf (key, sizeof(key), "vol%"PRId64".brickdir%"PRId64, i, brick_count); ret = dict_set_dynstr (rsp_dict, key, tmpstr); if (ret) { @@ -793,7 +799,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, } tmpstr = NULL; - snprintf (key, sizeof(key) - 1, "vol%ld.brick%ld.order", + snprintf (key, sizeof(key) - 1, "vol%"PRId64".brick%"PRId64".order", i, brick_count); ret = dict_set_int64 (rsp_dict, key, brick_order); if (ret) { @@ -805,7 +811,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, brick_count++; brick_order++; } - snprintf (key, sizeof(key) - 1, "vol%ld_brickcount", i); + snprintf (key, sizeof(key) - 1, "vol%"PRId64"_brickcount", i); ret = dict_set_int64 (rsp_dict, key, brick_count); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to set %s", @@ -1002,7 +1008,7 @@ glusterd_do_lvm_snapshot_remove (glusterd_volinfo_t *snap_vol, snprintf (msg, sizeof(msg), "remove snapshot of the brick %s:%s, " "device: %s", brickinfo->hostname, brickinfo->path, snap_device); - runner_add_args (&runner, "/sbin/lvremove", "-f", snap_device, NULL); + runner_add_args (&runner, LVM_REMOVE, "-f", snap_device, NULL); runner_log (&runner, "", GF_LOG_DEBUG, msg); ret = runner_run (&runner); @@ -2047,8 +2053,8 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, goto out; } if (volcount <= 0) { - gf_log (this->name, GF_LOG_ERROR, "Invalid volume count %ld " - "supplied", volcount); + gf_log (this->name, GF_LOG_ERROR, "Invalid volume count %"PRId64 + " supplied", volcount); ret = -1; goto out; } @@ -2476,7 +2482,7 @@ glusterd_create_snap_object (dict_t *dict, dict_t *rsp_dict) } if (time_stamp <= 0) { ret = -1; - gf_log (this->name, GF_LOG_ERROR, "Invalid time-stamp: %ld", + gf_log (this->name, GF_LOG_ERROR, "Invalid time-stamp: %"PRId64, time_stamp); goto out; } @@ -2715,7 +2721,7 @@ glusterd_take_lvm_snapshot (glusterd_volinfo_t *snap_vol, /* Figuring out if setactivationskip flag is supported or not */ runinit (&runner); snprintf (msg, sizeof (msg), "running lvcreate help"); - runner_add_args (&runner, "/sbin/lvcreate", "--help", NULL); + runner_add_args (&runner, LVM_CREATE, "--help", NULL); runner_log (&runner, "", GF_LOG_DEBUG, msg); runner_redir (&runner, STDOUT_FILENO, RUN_PIPE); ret = runner_start (&runner); @@ -2744,11 +2750,11 @@ glusterd_take_lvm_snapshot (glusterd_volinfo_t *snap_vol, snprintf (msg, sizeof (msg), "taking snapshot of the brick %s:%s", brickinfo->hostname, brickinfo->path); if (match == _gf_true) - runner_add_args (&runner, "/sbin/lvcreate", "-s", device, + runner_add_args (&runner, LVM_CREATE, "-s", device, "--setactivationskip", "n", "--name", snap_vol->volname, NULL); else - runner_add_args (&runner, "/sbin/lvcreate", "-s", device, + runner_add_args (&runner, LVM_CREATE, "-s", device, "--name", snap_vol->volname, NULL); runner_log (&runner, "", GF_LOG_DEBUG, msg); ret = runner_start (&runner); @@ -2862,7 +2868,11 @@ out: if (ret) { gf_log (this->name, GF_LOG_WARNING, "unmounting the snap brick" " mount %s", snap_brick_mount_path); +#if !defined(GF_DARWIN_HOST_OS) umount (snap_brick_mount_path); +#else + unmount (snap_brick_mount_path, 0); +#endif } gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); @@ -2893,7 +2903,7 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, GF_ASSERT (snap_brickinfo); GF_ASSERT (snap_brick_dir); - snprintf (key, sizeof(key) - 1, "vol%ld.brickdir%d", volcount, + snprintf (key, sizeof(key) - 1, "vol%"PRId64".brickdir%d", volcount, brick_count); ret = dict_get_ptr (dict, key, (void **)snap_brick_dir); if (ret) { @@ -2951,7 +2961,7 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, } } - snprintf (key, sizeof(key), "vol%ld.brick_snapdevice%d", + snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%d", volcount, brick_count); ret = dict_get_ptr (dict, key, (void **)&snap_device); if (ret) { @@ -3129,7 +3139,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, GF_ASSERT (rsp_dict); /* fetch username, password and vol_id from dict*/ - snprintf (key, sizeof(key), "volume%ld_username", volcount); + snprintf (key, sizeof(key), "volume%"PRId64"_username", volcount); ret = dict_get_str (dict, key, &username); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to get %s for " @@ -3137,7 +3147,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof(key), "volume%ld_password", volcount); + snprintf (key, sizeof(key), "volume%"PRId64"_password", volcount); ret = dict_get_str (dict, key, &password); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to get %s for " @@ -3145,7 +3155,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof(key) - 1, "vol%ld_volid", volcount); + snprintf (key, sizeof(key) - 1, "vol%"PRId64"_volid", volcount); ret = dict_get_bin (dict, key, (void **)&snap_volid); if (ret) { gf_log (this->name, GF_LOG_ERROR, @@ -3367,7 +3377,7 @@ glusterd_handle_snapshot_remove (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - snprintf (key, sizeof (key), "volname%ld", volcount); + snprintf (key, sizeof (key), "volname%"PRId64, volcount); ret = dict_set_dynstr (dict, key, volname); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to set " @@ -3771,7 +3781,7 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, } for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%ld", i); + snprintf (key, sizeof (key), "volname%"PRId64, i); ret = dict_get_str (dict, key, &volname); if (ret) { gf_log (this->name, GF_LOG_ERROR, @@ -3922,7 +3932,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, soft_limit_value = (active_hard_limit * conf->snap_max_soft_limit) / 100; - snprintf (buf, sizeof(buf), "volume%ld-volname", count); + snprintf (buf, sizeof(buf), "volume%"PRIu64"-volname", count); ret = dict_set_str (rsp_dict, buf, volinfo->volname); if (ret) { snprintf (err_str, PATH_MAX, @@ -3931,7 +3941,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-hard-limit", count); + "volume%"PRIu64"-snap-max-hard-limit", count); ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit); if (ret) { snprintf (err_str, PATH_MAX, @@ -3940,7 +3950,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-active-hard-limit", count); + "volume%"PRIu64"-active-hard-limit", count); ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit); if (ret) { @@ -3950,7 +3960,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-soft-limit", count); + "volume%"PRIu64"-snap-max-soft-limit", count); ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value); if (ret) { snprintf (err_str, PATH_MAX, @@ -3984,7 +3994,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, soft_limit_value = (active_hard_limit * conf->snap_max_soft_limit) / 100; - snprintf (buf, sizeof(buf), "volume%ld-volname", count); + snprintf (buf, sizeof(buf), "volume%"PRIu64"-volname", count); ret = dict_set_str (rsp_dict, buf, volinfo->volname); if (ret) { snprintf (err_str, PATH_MAX, @@ -3993,7 +4003,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-hard-limit", count); + "volume%"PRIu64"-snap-max-hard-limit", count); ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit); if (ret) { snprintf (err_str, PATH_MAX, @@ -4002,7 +4012,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-active-hard-limit", count); + "volume%"PRIu64"-active-hard-limit", count); ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit); if (ret) { snprintf (err_str, PATH_MAX, @@ -4011,7 +4021,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-soft-limit", count); + "volume%"PRIu64"-snap-max-soft-limit", count); ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value); if (ret) { snprintf (err_str, PATH_MAX, @@ -4196,7 +4206,7 @@ glusterd_get_brick_lvm_details (dict_t *rsp_dict, * for the above given command with separator ":", * The output will be "vgname:lvsize" */ - runner_add_args (&runner, "lvs", device, "--noheading", "-o", + runner_add_args (&runner, LVS, device, "--noheading", "-o", "vg_name,data_percent,lv_size", "--separator", ":", NULL); runner_redir (&runner, STDOUT_FILENO, RUN_PIPE); diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index e28a30c5a..b803ba282 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -2615,7 +2615,7 @@ out: return volinfo; } -inline void +static inline void glusterd_store_set_options_path (glusterd_conf_t *conf, char *path, size_t len) { snprintf (path, len, "%s/options", conf->workdir); @@ -3722,7 +3722,7 @@ glusterd_store_retrieve_quota_version (glusterd_volinfo_t *volinfo) } version = strtoul (version_str, &tmp, 10); - if (version < 0) { + if ((errno == ERANGE) || (errno == EINVAL)) { gf_log (this->name, GF_LOG_DEBUG, "Invalid version number"); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index bb8028003..be2022da4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -13,6 +13,12 @@ #endif #include +#if !defined(__NetBSD__) && !defined(GF_DARWIN_HOST_OS) +#include +#else +#include "mntent_compat.h" +#endif + #include "globals.h" #include "glusterfs.h" #include "compat.h" @@ -44,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -56,11 +61,6 @@ #include #endif - -#ifdef GF_LINUX_HOST_OS -#include -#endif - #ifdef GF_SOLARIS_HOST_OS #include #endif @@ -4520,14 +4520,16 @@ glusterd_nodesvc_start (char *server, gf_boolean_t wait) "--trace-children=yes", "--track-origins=yes", NULL); runner_argprintf (&runner, "--log-file=%s", valgrind_logfile); - } + } runner_add_args (&runner, SBIN_DIR"/glusterfs", "-s", "localhost", "--volfile-id", volfileid, "-p", pidfile, "-l", logfile, - "-S", sockfpath, NULL); + "-S", sockfpath, + "-L", "DEBUG", + NULL); if (!strcmp (server, "glustershd")) { snprintf (glusterd_uuid_option, sizeof (glusterd_uuid_option), @@ -5454,7 +5456,6 @@ out: return -1; } -#ifdef GF_LINUX_HOST_OS int glusterd_get_brick_root (char *path, char **mount_point) { @@ -5750,7 +5751,6 @@ out: return device; } -#endif int glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo, @@ -5824,13 +5824,12 @@ glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo, if (ret) goto out; } -#ifdef GF_LINUX_HOST_OS + ret = glusterd_add_brick_mount_details (brickinfo, dict, count); if (ret) goto out; ret = glusterd_add_inode_size_to_dict (dict, count); -#endif out: if (ret) gf_log (this->name, GF_LOG_DEBUG, "Error adding brick" @@ -8828,7 +8827,7 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src) } for (i = 0; i < voldisplaycount; i++) { - snprintf (buf, sizeof(buf), "volume%ld-volname", i); + snprintf (buf, sizeof(buf), "volume%"PRIu64"-volname", i); ret = dict_get_str (src, buf, &volname); if (ret) { gf_log ("", GF_LOG_ERROR, @@ -8843,7 +8842,7 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-hard-limit", i); + "volume%"PRIu64"-snap-max-hard-limit", i); ret = dict_get_uint64 (src, buf, &value); if (ret) { gf_log ("", GF_LOG_ERROR, @@ -8858,7 +8857,7 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (buf, sizeof(buf), - "volume%ld-active-hard-limit", i); + "volume%"PRIu64"-active-hard-limit", i); ret = dict_get_uint64 (src, buf, &value); if (ret) { gf_log ("", GF_LOG_ERROR, @@ -8873,7 +8872,7 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src) } snprintf (buf, sizeof(buf), - "volume%ld-snap-max-soft-limit", i); + "volume%"PRIu64"-snap-max-soft-limit", i); ret = dict_get_uint64 (src, buf, &value); if (ret) { gf_log ("", GF_LOG_ERROR, diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 23f8ad7f6..d2121778a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -8,7 +8,7 @@ cases as published by the Free Software Foundation. */ #ifndef _GLUSTERD_UTILS_H -#define _GLUSTERD_UTILS_H_ +#define _GLUSTERD_UTILS_H #ifndef _CONFIG_H #define _CONFIG_H @@ -684,14 +684,16 @@ glusterd_rpc_clnt_unref (glusterd_conf_t *conf, rpc_clnt_t *rpc); int32_t glusterd_compare_volume_name(struct list_head *, struct list_head *); -#ifdef GF_LINUX_HOST_OS + char* glusterd_get_brick_mount_details (glusterd_brickinfo_t *brickinfo); + struct mntent * glusterd_get_mnt_entry_info (char *mnt_pt, FILE *mtab); + int glusterd_get_brick_root (char *path, char **mount_point); -#endif //LINUX_HOST + int glusterd_compare_snap_time(struct list_head *, struct list_head *); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index ca799aefc..316b70f77 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -741,7 +741,7 @@ int glusterd_volinfo_get_boolean (glusterd_volinfo_t *volinfo, char *key) { char *val = NULL; - gf_boolean_t boo = _gf_false; + gf_boolean_t enabled = _gf_false; int ret = 0; ret = glusterd_volinfo_get (volinfo, key, &val); @@ -749,14 +749,14 @@ glusterd_volinfo_get_boolean (glusterd_volinfo_t *volinfo, char *key) return -1; if (val) - ret = gf_string2boolean (val, &boo); + ret = gf_string2boolean (val, &enabled); if (ret) { gf_log ("", GF_LOG_ERROR, "value for %s option is not valid", key); return -1; } - return boo; + return enabled; } gf_boolean_t @@ -1258,8 +1258,8 @@ static int server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, glusterd_volinfo_t *volinfo) { - gf_boolean_t bool = _gf_false; - int ret = 0; + gf_boolean_t enabled = _gf_false; + int ret = 0; GF_ASSERT (volinfo); GF_ASSERT (vme); @@ -1267,8 +1267,8 @@ server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, if (strcmp (vme->option, "!xtime") != 0) return 0; - ret = gf_string2boolean (vme->value, &bool); - if (ret || bool) + ret = gf_string2boolean (vme->value, &enabled); + if (ret || enabled) goto out; ret = glusterd_volinfo_get_boolean (volinfo, VKEY_MARKER_XTIME); @@ -1279,10 +1279,10 @@ server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, } if (ret) { - bool = _gf_false; - ret = glusterd_check_gsync_running (volinfo, &bool); + enabled = _gf_false; + ret = glusterd_check_gsync_running (volinfo, &enabled); - if (bool) { + if (enabled) { gf_log ("", GF_LOG_WARNING, GEOREP" sessions active" "for the volume %s, cannot disable marker " ,volinfo->volname); diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index eac926d95..504aeb839 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1213,7 +1213,7 @@ glusterd_op_stage_delete_volume (dict_t *dict, char **op_errstr) if (volinfo->snap_count > 0 || !list_empty(&volinfo->snap_volumes)) { snprintf (msg, sizeof (msg), "Cannot delete Volume %s ," - "as it has %ld snapshots. " + "as it has %"PRIu64" snapshots. " "To delete the volume, " "first delete all the snapshots under it.", volname, volinfo->snap_count); diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 29e9f2b87..1c5d359d9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -116,8 +116,8 @@ validate_cache_max_min_size (dict_t *dict, char *key, char *value, "performance.cache-max-file-size", ¤t_max_value); if (current_max_value) { - gf_string2bytesize (current_max_value, &max_value); - gf_string2bytesize (value, &min_value); + gf_string2bytesize_uint64 (current_max_value, &max_value); + gf_string2bytesize_uint64 (value, &min_value); current_min_value = value; } } else if ((!strcmp (key, "performance.cache-max-file-size")) || @@ -126,8 +126,8 @@ validate_cache_max_min_size (dict_t *dict, char *key, char *value, "performance.cache-min-file-size", ¤t_min_value); if (current_min_value) { - gf_string2bytesize (current_min_value, &min_value); - gf_string2bytesize (value, &max_value); + gf_string2bytesize_uint64 (current_min_value, &min_value); + gf_string2bytesize_uint64 (value, &max_value); current_max_value = value; } } @@ -1370,6 +1370,18 @@ struct volopt_map_entry glusterd_volopt_map[] = { .type = GLOBAL_DOC, .op_version = 1 }, + { .key = "nfs.rpc-statd", + .voltype = "nfs/server", + .option = "nfs.rpc-statd", + .type = NO_DOC, + .op_version = 4, + }, + { .key = "nfs.log-level", + .voltype = "nfs/server", + .option = "nfs.log-level", + .type = NO_DOC, + .op_version = 4, + }, { .key = "nfs.server-aux-gids", .voltype = "nfs/server", .option = "nfs.server-aux-gids", @@ -1434,6 +1446,10 @@ struct volopt_map_entry glusterd_volopt_map[] = { .voltype = "storage/posix", .op_version = 3 }, + { .key = "storage.xattr-user-namespace-mode", + .voltype = "storage/posix", + .op_version = 4 + }, { .key = "storage.owner-uid", .voltype = "storage/posix", .option = "brick-uid", diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 85a6b920a..abef538d8 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -30,6 +30,7 @@ #include "dict.h" #include "compat.h" #include "compat-errno.h" +#include "syscall.h" #include "statedump.h" #include "glusterd-sm.h" #include "glusterd-op-sm.h" @@ -311,7 +312,7 @@ out: } -inline int32_t +static inline int32_t glusterd_program_register (xlator_t *this, rpcsvc_t *svc, rpcsvc_program_t *prog) { @@ -804,7 +805,7 @@ check_prepare_mountbroker_root (char *mountbroker_root) dfd0 = dup (dfd); for (;;) { - ret = openat (dfd, "..", O_RDONLY); + ret = sys_openat (dfd, "..", O_RDONLY); if (ret != -1) { dfd2 = ret; ret = fstat (dfd2, &st2); @@ -839,11 +840,11 @@ check_prepare_mountbroker_root (char *mountbroker_root) st = st2; } - ret = mkdirat (dfd0, MB_HIVE, 0711); + ret = sys_mkdirat (dfd0, MB_HIVE, 0711); if (ret == -1 && errno == EEXIST) ret = 0; if (ret != -1) - ret = fstatat (dfd0, MB_HIVE, &st, AT_SYMLINK_NOFOLLOW); + ret = sys_fstatat (dfd0, MB_HIVE, &st, AT_SYMLINK_NOFOLLOW); if (ret == -1 || st.st_mode != (S_IFDIR|0711)) { gf_log ("", GF_LOG_ERROR, "failed to set up mountbroker-root directory %s", diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index fd44c4fb5..745617a71 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 2774bdaa8..0936d6311 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 b12b4e04e..539b0f558 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. -# +# (C) 2014 Red Hat Inc. +# # 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 : -o +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 </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 </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 </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; } diff --git a/xlators/nfs/server/src/nfs-fops.c b/xlators/nfs/server/src/nfs-fops.c index b91f73a53..56d4cba47 100644 --- a/xlators/nfs/server/src/nfs-fops.c +++ b/xlators/nfs/server/src/nfs-fops.c @@ -38,20 +38,25 @@ nfs_fix_groups (xlator_t *this, call_stack_t *root) struct passwd mypw; char mystrs[1024]; struct passwd *result; +#ifdef GF_DARWIN_HOST_OS + /* BSD/DARWIN does not correctly uses gid_t in getgrouplist */ + int mygroups[GF_MAX_AUX_GROUPS]; +#else gid_t mygroups[GF_MAX_AUX_GROUPS]; +#endif int ngroups; int i; int max_groups; struct nfs_state *priv = this->private; const gid_list_t *agl; - gid_list_t gl; + gid_list_t gl; if (!priv->server_aux_gids) { return; } - /* RPC enforces the GF_AUTH_GLUSTERFS_MAX_GROUPS limit */ - max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(root->lk_owner.len); + /* RPC enforces the GF_AUTH_GLUSTERFS_MAX_GROUPS limit */ + max_groups = GF_AUTH_GLUSTERFS_MAX_GROUPS(root->lk_owner.len); agl = gid_cache_lookup(&priv->gid_cache, root->uid, 0, 0); if (agl) { diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c index d962663ba..918e86312 100644 --- a/xlators/nfs/server/src/nfs.c +++ b/xlators/nfs/server/src/nfs.c @@ -35,12 +35,16 @@ #include "options.h" #include "acl3.h" #include "rpc-drc.h" +#include "syscall.h" #define STRINGIFY(val) #val #define TOSTRING(val) STRINGIFY(val) #define OPT_SERVER_AUX_GIDS "nfs.server-aux-gids" #define OPT_SERVER_GID_CACHE_TIMEOUT "nfs.server.aux-gid-timeout" +#define OPT_SERVER_RPC_STATD "nfs.rpc-statd" +#define OPT_SERVER_RPC_STATD_PIDFILE "nfs.rpc-statd-pidfile" +#define OPT_SERVER_RPC_STATD_NOTIFY_PIDFILE "nfs.rpc-statd-notify-pidfile" /* TODO: DATADIR should be based on configure's $(localstatedir) */ #define DATADIR "/var/lib/glusterd" @@ -942,10 +946,14 @@ nfs_init_state (xlator_t *this) goto free_foppool; } } + GF_OPTION_INIT (OPT_SERVER_RPC_STATD, nfs->rpc_statd, path, free_foppool); + + GF_OPTION_INIT (OPT_SERVER_RPC_STATD_PIDFILE, nfs->rpc_statd_pid_file, path, free_foppool); GF_OPTION_INIT (OPT_SERVER_AUX_GIDS, nfs->server_aux_gids, bool, free_foppool); - GF_OPTION_INIT (OPT_SERVER_GID_CACHE_TIMEOUT, nfs->server_aux_gids_max_age, + GF_OPTION_INIT (OPT_SERVER_GID_CACHE_TIMEOUT, + nfs->server_aux_gids_max_age, uint32, free_foppool); if (gid_cache_init(&nfs->gid_cache, nfs->server_aux_gids_max_age) < 0) { @@ -953,9 +961,17 @@ nfs_init_state (xlator_t *this) goto free_foppool; } - if (stat("/sbin/rpc.statd", &stbuf) == -1) { - gf_log (GF_NFS, GF_LOG_WARNING, "/sbin/rpc.statd not found. " - "Disabling NLM"); + ret = sys_access (nfs->rpc_statd, X_OK); + if (ret) { + gf_log (GF_NFS, GF_LOG_WARNING, "%s not enough permissions to" + " access. Disabling NLM", nfs->rpc_statd); + nfs->enable_nlm = _gf_false; + } + + ret = sys_stat (nfs->rpc_statd, &stbuf); + if (ret || !S_ISREG (stbuf.st_mode)) { + gf_log (GF_NFS, GF_LOG_WARNING, "%s not a regular file." + " Disabling NLM", nfs->rpc_statd); nfs->enable_nlm = _gf_false; } @@ -968,8 +984,8 @@ nfs_init_state (xlator_t *this) } ret = rpcsvc_set_outstanding_rpc_limit (nfs->rpcsvc, - this->options, - RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT); + this->options, + RPCSVC_DEF_NFS_OUTSTANDING_RPC_LIMIT); if (ret < 0) { gf_log (GF_NFS, GF_LOG_ERROR, "Failed to configure outstanding-rpc-limit"); @@ -1023,7 +1039,8 @@ nfs_reconfigure_state (xlator_t *this, dict_t *options) { int ret = 0; int keyindx = 0; - char *optstr = NULL; + char *rmtab = NULL; + char *rpc_statd = NULL; gf_boolean_t optbool; uint32_t optuint32; struct nfs_state *nfs = NULL; @@ -1068,19 +1085,36 @@ nfs_reconfigure_state (xlator_t *this, dict_t *options) goto out; } + /* reconfig nfs.rpc-statd... */ + rpc_statd = GF_RPC_STATD_PROG; + if (dict_get (options, OPT_SERVER_RPC_STATD_PIDFILE)) { + ret = dict_get_str (options, "nfs.rpc-statd", &rpc_statd); + if (ret < 0) { + gf_log (GF_NFS, GF_LOG_ERROR, "Failed to read " + "reconfigured option: nfs.rpc-statd"); + goto out; + } + } + + if (strcmp(nfs->rpc_statd, rpc_statd) != 0) { + gf_log (GF_NFS, GF_LOG_INFO, + "Reconfiguring nfs.rpc-statd needs NFS restart"); + goto out; + } + /* reconfig nfs.mount-rmtab */ - optstr = NFS_DATADIR "/rmtab"; + rmtab = NFS_DATADIR "/rmtab"; if (dict_get (options, "nfs.mount-rmtab")) { - ret = dict_get_str (options, "nfs.mount-rmtab", &optstr); + ret = dict_get_str (options, "nfs.mount-rmtab", &rmtab); if (ret < 0) { gf_log (GF_NFS, GF_LOG_ERROR, "Failed to read " "reconfigured option: nfs.mount-rmtab"); goto out; } - gf_path_strip_trailing_slashes (optstr); + gf_path_strip_trailing_slashes (rmtab); } - if (strcmp (nfs->rmtab, optstr) != 0) { - mount_rewrite_rmtab (nfs->mstate, optstr); + if (strcmp (nfs->rmtab, rmtab) != 0) { + mount_rewrite_rmtab (nfs->mstate, rmtab); gf_log (GF_NFS, GF_LOG_INFO, "Reconfigured nfs.mount-rmtab path: %s", nfs->rmtab); @@ -1819,6 +1853,18 @@ struct volume_options options[] = { "storage, all GlusterFS servers will update and " "output (with 'showmount') the same list." }, + { .key = {OPT_SERVER_RPC_STATD}, + .type = GF_OPTION_TYPE_PATH, + .default_value = GF_RPC_STATD_PROG, + .description = "The executable of RPC statd utility. " + "Defaults to " GF_RPC_STATD_PROG + }, + { .key = {OPT_SERVER_RPC_STATD_PIDFILE}, + .type = GF_OPTION_TYPE_PATH, + .default_value = GF_RPC_STATD_PIDFILE, + .description = "The pid file of RPC statd utility. " + "Defaults to " GF_RPC_STATD_PIDFILE + }, { .key = {OPT_SERVER_AUX_GIDS}, .type = GF_OPTION_TYPE_BOOL, .default_value = "off", diff --git a/xlators/nfs/server/src/nfs.h b/xlators/nfs/server/src/nfs.h index 00c7f8046..fc745fbbd 100644 --- a/xlators/nfs/server/src/nfs.h +++ b/xlators/nfs/server/src/nfs.h @@ -86,6 +86,8 @@ struct nfs_state { gid_cache_t gid_cache; uint32_t generation; gf_boolean_t register_portmap; + char *rpc_statd; + char *rpc_statd_pid_file; }; struct nfs_inode_ctx { diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c index 9059fc341..f67cccf1a 100644 --- a/xlators/nfs/server/src/nfs3-helpers.c +++ b/xlators/nfs/server/src/nfs3-helpers.c @@ -85,7 +85,7 @@ struct nfs3stat_strerror nfs3stat_strerror_table[] = { { NFS3ERR_SERVERFAULT, "Error occurred on the server or IO Error" }, { NFS3ERR_BADTYPE, "Type not supported by the server" }, { NFS3ERR_JUKEBOX, "Cannot complete server initiated request" }, - { -1, "IO Error" }, + { NFS3ERR_END_OF_LIST, "IO Error" }, }; @@ -543,7 +543,7 @@ char * nfsstat3_strerror(int stat) { int i; - for(i = 0; nfs3stat_strerror_table[i].stat != -1; i++) { + for(i = 0; nfs3stat_strerror_table[i].stat != NFS3ERR_END_OF_LIST ; i++) { if (nfs3stat_strerror_table[i].stat == stat) return nfs3stat_strerror_table[i].strerror; } diff --git a/xlators/nfs/server/src/nfs3.c b/xlators/nfs/server/src/nfs3.c index 0fea135c7..6361f9e20 100644 --- a/xlators/nfs/server/src/nfs3.c +++ b/xlators/nfs/server/src/nfs3.c @@ -5186,7 +5186,7 @@ nfs3_init_options (struct nfs3_state *nfs3, dict_t *options) goto err; } - ret = gf_string2bytesize (optstr, &size64); + ret = gf_string2uint64 (optstr, &size64); if (ret == -1) { gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format" " option: nfs3.read-size"); @@ -5209,7 +5209,7 @@ nfs3_init_options (struct nfs3_state *nfs3, dict_t *options) goto err; } - ret = gf_string2bytesize (optstr, &size64); + ret = gf_string2uint64 (optstr, &size64); if (ret == -1) { gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format" " option: nfs3.write-size"); @@ -5232,7 +5232,7 @@ nfs3_init_options (struct nfs3_state *nfs3, dict_t *options) goto err; } - ret = gf_string2bytesize (optstr, &size64); + ret = gf_string2uint64 (optstr, &size64); if (ret == -1) { gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format" " option: nfs3.readdir-size"); diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c index c186537ea..d0caa97c2 100644 --- a/xlators/nfs/server/src/nlm4.c +++ b/xlators/nfs/server/src/nlm4.c @@ -2423,9 +2423,21 @@ nlm4svc_init(xlator_t *nfsx) /* unlink sm-notify.pid so that when we restart rpc.statd/sm-notify * it thinks that the machine has restarted and sends NOTIFY to clients. */ - ret = unlink ("/var/run/sm-notify.pid"); + + /* TODO: + notify/rpc.statd is done differently on OSX + + On OSX rpc.statd is controlled by rpc.lockd and are part for launchd + (unified service management framework) + + A runcmd() should be invoking "launchctl start com.apple.lockd" + instead. This is still a theory but we need to thoroughly test it + out. Until then NLM support is non-existent on OSX. + */ + ret = unlink (GF_SM_NOTIFY_PIDFILE); if (ret == -1 && errno != ENOENT) { - gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink sm-notify"); + gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink %s: %d", + GF_SM_NOTIFY_PIDFILE, errno); goto err; } /* temporary work around to restart statd, not distro/OS independant. @@ -2433,37 +2445,43 @@ nlm4svc_init(xlator_t *nfsx) * killall will cause problems on solaris. */ - pidfile = fopen ("/var/run/rpc.statd.pid", "r"); + char *pid_file = GF_RPC_STATD_PIDFILE; + if (nfs->rpc_statd_pid_file) + pid_file = nfs->rpc_statd_pid_file; + pidfile = fopen (pid_file, "r"); if (pidfile) { ret = fscanf (pidfile, "%d", &pid); if (ret <= 0) { gf_log (GF_NLM, GF_LOG_WARNING, "unable to get pid of " - "rpc.statd"); + "rpc.statd from %s ", GF_RPC_STATD_PIDFILE); ret = runcmd ("killall", "-9", "rpc.statd", NULL); } else kill (pid, SIGKILL); fclose (pidfile); } else { - gf_log (GF_NLM, GF_LOG_WARNING, "opening the pid file of " - "rpc.statd failed (%s)", strerror (errno)); + gf_log (GF_NLM, GF_LOG_WARNING, "opening %s of " + "rpc.statd failed (%s)", pid_file, strerror (errno)); /* if ret == -1, do nothing - case either statd was not * running or was running in valgrind mode */ ret = runcmd ("killall", "-9", "rpc.statd", NULL); } - ret = unlink ("/var/run/rpc.statd.pid"); + ret = unlink (GF_RPC_STATD_PIDFILE); if (ret == -1 && errno != ENOENT) { - gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink rpc.statd"); + gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink %s", pid_file); goto err; } - ret = runcmd ("/sbin/rpc.statd", NULL); + ret = runcmd (nfs->rpc_statd, NULL); if (ret == -1) { - gf_log (GF_NLM, GF_LOG_ERROR, "unable to start rpc.statd"); + gf_log (GF_NLM, GF_LOG_ERROR, "unable to start %s", + nfs->rpc_statd); goto err; } + + pthread_create (&thr, NULL, nsm_thread, (void*)NULL); timeout.tv_sec = nlm_grace_period; diff --git a/xlators/nfs/server/src/nlm4.h b/xlators/nfs/server/src/nlm4.h index 9b5d54081..5b6296110 100644 --- a/xlators/nfs/server/src/nlm4.h +++ b/xlators/nfs/server/src/nlm4.h @@ -34,6 +34,15 @@ /* Registered with portmap */ #define GF_NLM4_PORT 38468 #define GF_NLM GF_NFS"-NLM" +#ifdef GF_DARWIN_HOST_OS +#define GF_RPC_STATD_PROG "/usr/sbin/rpc.statd" +#define GF_RPC_STATD_PIDFILE "/var/run/statd.pid" +#define GF_SM_NOTIFY_PIDFILE "/var/run/statd.notify.pid" +#else +#define GF_RPC_STATD_PROG "/sbin/rpc.stat" +#define GF_RPC_STATD_PIDFILE "/var/run/rpc.statd.pid" +#define GF_SM_NOTIFY_PIDFILE "/var/run/sm-notify.pid" +#endif extern rpcsvc_program_t * nlm4svc_init (xlator_t *nfsx); diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 8febfc8fb..facff5038 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -41,6 +41,9 @@ ioc_hashfn (void *data, int len) return (offset >> ioc_log2_page_size); } +/* TODO: This function is not used, uncomment when we find a + usage for this function. + static inline ioc_inode_t * ioc_inode_reupdate (ioc_inode_t *ioc_inode) { @@ -54,6 +57,7 @@ ioc_inode_reupdate (ioc_inode_t *ioc_inode) return ioc_inode; } + static inline ioc_inode_t * ioc_get_inode (dict_t *dict, char *name) { @@ -77,6 +81,7 @@ ioc_get_inode (dict_t *dict, char *name) return ioc_inode; } +*/ int32_t ioc_inode_need_revalidate (ioc_inode_t *ioc_inode) @@ -1663,12 +1668,12 @@ reconfigure (xlator_t *this, dict_t *options) } GF_OPTION_RECONF ("max-file-size", table->max_file_size, - options, size, unlock); + options, size_uint64, unlock); GF_OPTION_RECONF ("min-file-size", table->min_file_size, - options, size, unlock); + options, size_uint64, unlock); - if ((table->max_file_size >= 0) && + if ((table->max_file_size <= UINT64_MAX) && (table->min_file_size > table->max_file_size)) { gf_log (this->name, GF_LOG_ERROR, "minimum size (%" PRIu64") of a file that can be cached is " @@ -1679,7 +1684,7 @@ reconfigure (xlator_t *this, dict_t *options) } GF_OPTION_RECONF ("cache-size", cache_size_new, - options, size, unlock); + options, size_uint64, unlock); if (!check_cache_size_ok (this, cache_size_new)) { ret = -1; gf_log (this->name, GF_LOG_ERROR, @@ -1736,13 +1741,13 @@ init (xlator_t *this) table->xl = this; table->page_size = this->ctx->page_size; - GF_OPTION_INIT ("cache-size", table->cache_size, size, out); + GF_OPTION_INIT ("cache-size", table->cache_size, size_uint64, out); GF_OPTION_INIT ("cache-timeout", table->cache_timeout, int32, out); - GF_OPTION_INIT ("min-file-size", table->min_file_size, size, out); + GF_OPTION_INIT ("min-file-size", table->min_file_size, size_uint64, out); - GF_OPTION_INIT ("max-file-size", table->max_file_size, size, out); + GF_OPTION_INIT ("max-file-size", table->max_file_size, size_uint64, out); if (!check_cache_size_ok (this, table->cache_size)) { ret = -1; @@ -1768,7 +1773,7 @@ init (xlator_t *this) INIT_LIST_HEAD (&table->inodes); - if ((table->max_file_size >= 0) + if ((table->max_file_size <= UINT64_MAX) && (table->min_file_size > table->max_file_size)) { gf_log ("io-cache", GF_LOG_ERROR, "minimum size (%" PRIu64") of a file that can be cached is " diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 402da886f..b8b4c5326 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -854,7 +854,7 @@ reconfigure (xlator_t *this, dict_t *options) GF_OPTION_RECONF ("cache-timeout", conf->cache_timeout, options, int32, out); - GF_OPTION_RECONF ("cache-size", cache_size_new, options, size, out); + GF_OPTION_RECONF ("cache-size", cache_size_new, options, size_uint64, out); if (!check_cache_size_ok (this, cache_size_new)) { ret = -1; gf_log (this->name, GF_LOG_ERROR, @@ -995,11 +995,11 @@ init (xlator_t *this) LOCK_INIT (&priv->table.lock); conf = &priv->conf; - GF_OPTION_INIT ("max-file-size", conf->max_file_size, size, out); + GF_OPTION_INIT ("max-file-size", conf->max_file_size, size_uint64, out); GF_OPTION_INIT ("cache-timeout", conf->cache_timeout, int32, out); - GF_OPTION_INIT ("cache-size", conf->cache_size, size, out); + GF_OPTION_INIT ("cache-size", conf->cache_size, size_uint64, out); if (!check_cache_size_ok (this, conf->cache_size)) { ret = -1; goto out; diff --git a/xlators/performance/read-ahead/src/read-ahead.c b/xlators/performance/read-ahead/src/read-ahead.c index 6e2d84591..01c861d52 100644 --- a/xlators/performance/read-ahead/src/read-ahead.c +++ b/xlators/performance/read-ahead/src/read-ahead.c @@ -1124,7 +1124,8 @@ reconfigure (xlator_t *this, dict_t *options) GF_OPTION_RECONF ("page-count", conf->page_count, options, uint32, out); - GF_OPTION_RECONF ("page-size", conf->page_size, options, size, out); + GF_OPTION_RECONF ("page-size", conf->page_size, options, size_uint64, + out); ret = 0; out: @@ -1158,7 +1159,7 @@ init (xlator_t *this) conf->page_size = this->ctx->page_size; - GF_OPTION_INIT ("page-size", conf->page_size, size, out); + GF_OPTION_INIT ("page-size", conf->page_size, size_uint64, out); GF_OPTION_INIT ("page-count", conf->page_count, uint32, out); diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead.c b/xlators/performance/readdir-ahead/src/readdir-ahead.c index 53e6756f0..ba96bfcd3 100644 --- a/xlators/performance/readdir-ahead/src/readdir-ahead.c +++ b/xlators/performance/readdir-ahead/src/readdir-ahead.c @@ -459,9 +459,9 @@ reconfigure(xlator_t *this, dict_t *options) GF_OPTION_RECONF("rda-request-size", priv->rda_req_size, options, uint32, err); - GF_OPTION_RECONF("rda-low-wmark", priv->rda_low_wmark, options, size, + GF_OPTION_RECONF("rda-low-wmark", priv->rda_low_wmark, options, size_uint64, err); - GF_OPTION_RECONF("rda-high-wmark", priv->rda_high_wmark, options, size, + GF_OPTION_RECONF("rda-high-wmark", priv->rda_high_wmark, options, size_uint64, err); return 0; @@ -498,8 +498,8 @@ init(xlator_t *this) goto err; GF_OPTION_INIT("rda-request-size", priv->rda_req_size, uint32, err); - GF_OPTION_INIT("rda-low-wmark", priv->rda_low_wmark, size, err); - GF_OPTION_INIT("rda-high-wmark", priv->rda_high_wmark, size, err); + GF_OPTION_INIT("rda-low-wmark", priv->rda_low_wmark, size_uint64, err); + GF_OPTION_INIT("rda-high-wmark", priv->rda_high_wmark, size_uint64, err); return 0; diff --git a/xlators/performance/write-behind/src/write-behind.c b/xlators/performance/write-behind/src/write-behind.c index 00457338d..3cb0d449b 100644 --- a/xlators/performance/write-behind/src/write-behind.c +++ b/xlators/performance/write-behind/src/write-behind.c @@ -2116,7 +2116,7 @@ reconfigure (xlator_t *this, dict_t *options) conf = this->private; - GF_OPTION_RECONF ("cache-size", conf->window_size, options, size, out); + GF_OPTION_RECONF ("cache-size", conf->window_size, options, size_uint64, out); GF_OPTION_RECONF ("flush-behind", conf->flush_behind, options, bool, out); @@ -2163,7 +2163,7 @@ init (xlator_t *this) conf->aggregate_size = WB_AGGREGATE_SIZE; /* configure 'option window-size ' */ - GF_OPTION_INIT ("cache-size", conf->window_size, size, out); + GF_OPTION_INIT ("cache-size", conf->window_size, size_uint64, out); if (!conf->window_size && conf->aggregate_size) { gf_log (this->name, GF_LOG_WARNING, diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c index 306e555ef..98fb10c34 100644 --- a/xlators/protocol/client/src/client.c +++ b/xlators/protocol/client/src/client.c @@ -21,6 +21,7 @@ #include "statedump.h" #include "compat-errno.h" +#include "xdr-rpc.h" #include "glusterfs3.h" extern rpc_clnt_prog_t clnt_handshake_prog; @@ -2458,7 +2459,7 @@ client_init_grace_timer (xlator_t *this, dict_t *options, conf->grace_ts.tv_nsec = 0; gf_log (this->name, GF_LOG_DEBUG, "Client grace timeout " - "value = %"PRIu64, conf->grace_ts.tv_sec); + "value = %"GF_PRI_SECOND, conf->grace_ts.tv_sec); ret = 0; out: diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c index 708acd936..a459f89e1 100644 --- a/xlators/protocol/server/src/server-handshake.c +++ b/xlators/protocol/server/src/server-handshake.c @@ -645,7 +645,7 @@ server_setvolume (rpcsvc_request_t *req) fail: rsp.dict.dict_len = dict_serialized_length (reply); - if (rsp.dict.dict_len < 0) { + if (rsp.dict.dict_len > UINT_MAX) { gf_log ("server-handshake", GF_LOG_DEBUG, "failed to get serialized length of reply dict"); op_ret = -1; diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index 76c0036e0..600a311c3 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -33,6 +33,7 @@ server_decode_groups (call_frame_t *frame, rpcsvc_request_t *req) if (frame->root->ngrps == 0) return 0; + /* ngrps cannot be bigger than USHRT_MAX(65535) */ if (frame->root->ngrps > GF_MAX_AUX_GROUPS) return -1; @@ -744,7 +745,7 @@ serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp) /* if 'dict' is present, pack it */ if (entry->dict) { trav->dict.dict_len = dict_serialized_length (entry->dict); - if (trav->dict.dict_len < 0) { + if (trav->dict.dict_len > UINT_MAX) { gf_log (THIS->name, GF_LOG_ERROR, "failed to get serialized length " "of reply dict"); diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c index 8bdadec6b..ebe62ae7c 100644 --- a/xlators/protocol/server/src/server-rpc-fops.c +++ b/xlators/protocol/server/src/server-rpc-fops.c @@ -1611,8 +1611,8 @@ server_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, fd_no = gf_fd_unused_get (serv_ctx->fdtable, fd); fd_ref (fd); - if ((fd_no < 0) || (fd == 0)) { - op_ret = fd_no; + if ((fd_no > UINT64_MAX) || (fd == 0)) { + op_ret = -1; op_errno = errno; } diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index 785517058..6bd00cac0 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -688,7 +688,7 @@ server_init_grace_timer (xlator_t *this, dict_t *options, conf->grace_ts.tv_sec = 10; gf_log (this->name, GF_LOG_DEBUG, "Server grace timeout " - "value = %"PRIu64, conf->grace_ts.tv_sec); + "value = %"GF_PRI_SECOND, conf->grace_ts.tv_sec); conf->grace_ts.tv_nsec = 0; diff --git a/xlators/storage/bd/src/bd-helper.c b/xlators/storage/bd/src/bd-helper.c index 4bd1d6111..d598e5755 100644 --- a/xlators/storage/bd/src/bd-helper.c +++ b/xlators/storage/bd/src/bd-helper.c @@ -11,6 +11,7 @@ #include "bd.h" #include "bd-mem-types.h" #include "run.h" +#include "lvm-defaults.h" int bd_inode_ctx_set (inode_t *inode, xlator_t *this, bd_attr_t *ctx) @@ -1018,4 +1019,3 @@ out: return ret; } - diff --git a/xlators/storage/bd/src/bd.c b/xlators/storage/bd/src/bd.c index 0954b553d..750b00943 100644 --- a/xlators/storage/bd/src/bd.c +++ b/xlators/storage/bd/src/bd.c @@ -38,6 +38,8 @@ #include "run.h" #include "protocol-common.h" #include "checksum.h" +#include "syscall.h" +#include "lvm-defaults.h" /* * Call back function for setxattr and removexattr. @@ -719,9 +721,8 @@ bd_do_fsync (int fd, int datasync) { int op_errno = 0; -#ifdef HAVE_FDATASYNC if (datasync) { - if (fdatasync (fd)) { + if (sys_fdatasync (fd)) { op_errno = errno; gf_log (THIS->name, GF_LOG_ERROR, "fdatasync on fd=%d failed: %s", @@ -729,9 +730,9 @@ bd_do_fsync (int fd, int datasync) } } else -#endif + { - if (fsync (fd)) { + if (sys_fsync (fd)) { op_errno = errno; gf_log (THIS->name, GF_LOG_ERROR, "fsync on fd=%d failed: %s", diff --git a/xlators/storage/bd/src/bd.h b/xlators/storage/bd/src/bd.h index 5307ca407..62add16cd 100644 --- a/xlators/storage/bd/src/bd.h +++ b/xlators/storage/bd/src/bd.h @@ -38,10 +38,6 @@ #define BD_LV "lv" #define BD_THIN "thin" -#define LVM_RESIZE "/sbin/lvresize" -#define LVM_CREATE "/sbin/lvcreate" -#define LVM_CONVERT "/sbin/lvconvert" - #define VOL_TYPE "volume.type" #define VOL_CAPS "volume.caps" @@ -165,7 +161,7 @@ int bd_clone (bd_local_t *local, bd_priv_t *priv); int bd_merge (bd_priv_t *priv, uuid_t gfid); int bd_get_origin (bd_priv_t *priv, loc_t *loc, fd_t *fd, dict_t *dict); -inline void bd_update_amtime(struct iatt *iatt, int flag); +void bd_update_amtime(struct iatt *iatt, int flag); int bd_snapshot_create (bd_local_t *local, bd_priv_t *priv); int bd_clone (bd_local_t *local, bd_priv_t *priv); int bd_merge (bd_priv_t *priv, uuid_t gfid); diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 5725cad7d..ab46f7f7e 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -784,6 +784,27 @@ out: return op_ret; } +#ifdef GF_DARWIN_HOST_OS +static +void posix_dump_buffer (xlator_t *this, const char *real_path, const char *key, + data_t *value, int flags) +{ + char buffer[3*value->len+1]; + int index = 0; + buffer[0] = 0; + gf_loglevel_t log_level = gf_log_get_loglevel (); + if (log_level == GF_LOG_TRACE) { + char *data = (char *) value->data; + for (index = 0; index < value->len; index++) + sprintf(buffer+3*index, " %02x", data[index]); + } + gf_log (this->name, GF_LOG_DEBUG, + "Dump %s: key:%s flags: %u length:%u data:%s ", + real_path, key, flags, value->len, + (log_level == GF_LOG_TRACE ? buffer : "")); +} +#endif + static int gf_xattr_enotsup_log; int @@ -802,7 +823,9 @@ posix_handle_pair (xlator_t *this, const char *real_path, } else { sys_ret = sys_lsetxattr (real_path, key, value->data, value->len, flags); - +#ifdef GF_DARWIN_HOST_OS + posix_dump_buffer(this, real_path, key, value, flags); +#endif if (sys_ret < 0) { ret = -errno; if (errno == ENOTSUP) { @@ -825,13 +848,13 @@ posix_handle_pair (xlator_t *this, const char *real_path, gf_log (this->name, ((errno == EINVAL) ? GF_LOG_DEBUG : GF_LOG_ERROR), - "%s: key:%s error:%s", - real_path, key, + "%s: key:%s flags: %u length:%d error:%s", + real_path, key, flags, value->len, strerror (errno)); #else /* ! DARWIN */ gf_log (this->name, GF_LOG_ERROR, - "%s: key:%s error:%s", - real_path, key, + "%s: key:%s flags: %u length:%d error:%s", + real_path, key, flags, value->len, strerror (errno)); #endif /* DARWIN */ } @@ -1430,12 +1453,10 @@ posix_fsyncer_process (xlator_t *this, call_stub_t *stub, gf_boolean_t do_fsync) } if (do_fsync) { -#ifdef HAVE_FDATASYNC if (stub->args.datasync) - ret = fdatasync (pfd->fd); + ret = sys_fdatasync (pfd->fd); else -#endif - ret = fsync (pfd->fd); + ret = sys_fsync (pfd->fd); } else { ret = 0; } diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 588079d92..d33b5027e 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -761,7 +761,7 @@ posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, if (ret < 0) { ret = -errno; gf_log(this->name, GF_LOG_ERROR, - "zerofill failed on fd %d length %ld %s", + "zerofill failed on fd %d length %" PRId64 " %s", pfd->fd, len, strerror(errno)); goto out; } @@ -2859,16 +2859,14 @@ posix_fsync (call_frame_t *frame, xlator_t *this, if (datasync) { ; -#ifdef HAVE_FDATASYNC - op_ret = fdatasync (_fd); + op_ret = sys_fdatasync (_fd); if (op_ret == -1) { gf_log (this->name, GF_LOG_ERROR, "fdatasync on fd=%p failed: %s", fd, strerror (errno)); } -#endif } else { - op_ret = fsync (_fd); + op_ret = sys_fsync (_fd); if (op_ret == -1) { op_errno = errno; gf_log (this->name, GF_LOG_ERROR, @@ -2911,6 +2909,23 @@ _handle_setxattr_keyvalue_pair (dict_t *d, char *k, data_t *v, filler->flags); } +#ifdef GF_DARWIN_HOST_OS +static inline int +map_xattr_flags(int flags) +{ + /* DARWIN has different defines on XATTR_ flags. + There do not seem to be a POSIX standard + Parse any other flags over. + */ + int darwinflags = flags & ~(GF_XATTR_CREATE | GF_XATTR_REPLACE | XATTR_REPLACE); + if (GF_XATTR_CREATE & flags) + darwinflags |= XATTR_CREATE; + if (GF_XATTR_REPLACE & flags) + darwinflags |= XATTR_REPLACE; + return darwinflags; +} +#endif + int32_t posix_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, int flags, dict_t *xdata) @@ -2937,7 +2952,11 @@ posix_setxattr (call_frame_t *frame, xlator_t *this, filler.real_path = real_path; filler.this = this; +#ifdef GF_DARWIN_HOST_OS + filler.flags = map_xattr_flags(flags); +#else filler.flags = flags; +#endif op_ret = dict_foreach (dict, _handle_setxattr_keyvalue_pair, &filler); if (op_ret < 0) { @@ -3354,7 +3373,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, char *list = NULL; int32_t list_offset = 0; size_t remaining_size = 0; - char key[4096] = {0,}; + char keybuffer[4096] = {0,}; DECLARE_OLD_FS_ID_VAR; @@ -3522,8 +3541,20 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, } if (name) { - strcpy (key, name); - + strcpy (keybuffer, name); + char *key = keybuffer; +#if defined(GF_DARWIN_HOST_OS_DISABLED) + if (priv->xattr_user_namespace == XATTR_STRIP) { + if (strncmp(key, "user.",5) == 0) { + key += 5; + gf_log (this->name, + GF_LOG_DEBUG, + "getxattr for file %s" + " stripping user key: %s -> %s", + real_path, keybuffer, key); + } + } +#endif size = sys_lgetxattr (real_path, key, NULL, 0); if (size <= 0) { op_errno = errno; @@ -3611,14 +3642,13 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, while (remaining_size > 0) { if (*(list + list_offset) == '\0') break; - - strcpy (key, list + list_offset); - size = sys_lgetxattr (real_path, key, NULL, 0); + strcpy (keybuffer, list + list_offset); + size = sys_lgetxattr (real_path, keybuffer, NULL, 0); if (size == -1) { op_ret = -1; op_errno = errno; gf_log (this->name, GF_LOG_ERROR, "getxattr failed on " - "%s: key = %s (%s)", real_path, key, + "%s: key = %s (%s)", real_path, keybuffer, strerror (op_errno)); break; } @@ -3630,29 +3660,37 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, goto out; } - size = sys_lgetxattr (real_path, key, value, size); + size = sys_lgetxattr (real_path, keybuffer, value, size); if (size == -1) { op_ret = -1; op_errno = errno; gf_log (this->name, GF_LOG_ERROR, "getxattr failed on " - "%s: key = %s (%s)", real_path, key, + "%s: key = %s (%s)", real_path, keybuffer, strerror (op_errno)); GF_FREE (value); break; } value [size] = '\0'; - op_ret = dict_set_dynptr (dict, key, value, size); +#ifdef GF_DARWIN_HOST_OS + /* The protocol expect namespace for now */ + char *newkey = NULL; + gf_add_prefix (XATTR_USER_PREFIX, keybuffer, &newkey); + strcpy (keybuffer, newkey); + GF_FREE (newkey); +#endif + op_ret = dict_set_dynptr (dict, keybuffer, value, size); if (op_ret < 0) { op_errno = -op_ret; gf_log (this->name, GF_LOG_ERROR, "dict set operation " - "on %s for the key %s failed.", real_path, key); + "on %s for the key %s failed.", real_path, + keybuffer); GF_FREE (value); goto out; } - remaining_size -= strlen (key) + 1; - list_offset += strlen (key) + 1; + remaining_size -= strlen (keybuffer) + 1; + list_offset += strlen (keybuffer) + 1; } /* while (remaining_size > 0) */ @@ -3729,7 +3767,16 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, if (name) { strcpy (key, name); - +#ifdef GF_DARWIN_HOST_OS + struct posix_private *priv = NULL; + priv = this->private; + if (priv->xattr_user_namespace == XATTR_STRIP) { + char *newkey = NULL; + gf_add_prefix (XATTR_USER_PREFIX, key, &newkey); + strcpy (key, newkey); + GF_FREE (newkey); + } +#endif size = sys_fgetxattr (_fd, key, NULL, 0); if (size <= 0) { op_errno = errno; @@ -3832,6 +3879,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, } value [size] = '\0'; + op_ret = dict_set_dynptr (dict, key, value, size); if (op_ret) { gf_log (this->name, GF_LOG_ERROR, "dict set operation " @@ -3910,7 +3958,11 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this, filler.fd = _fd; filler.this = this; +#ifdef GF_DARWIN_HOST_OS + filler.flags = map_xattr_flags(flags); +#else filler.flags = flags; +#endif op_ret = dict_foreach (dict, _handle_fsetxattr_keyvalue_pair, &filler); if (op_ret < 0) { @@ -3935,7 +3987,17 @@ _posix_remove_xattr (dict_t *dict, char *key, data_t *value, void *data) filler = (posix_xattr_filler_t *) data; this = filler->this; - +#ifdef GF_DARWIN_HOST_OS + struct posix_private *priv = NULL; + priv = (struct posix_private *) this->private; + char *newkey = NULL; + if (priv->xattr_user_namespace == XATTR_STRIP) { + gf_remove_prefix (XATTR_USER_PREFIX, key, &newkey); + gf_log("remove_xattr", GF_LOG_DEBUG, "key %s => %s" , key, + newkey); + key = newkey; + } +#endif op_ret = sys_lremovexattr (filler->real_path, key); if (op_ret == -1) { filler->op_errno = errno; @@ -3944,7 +4006,9 @@ _posix_remove_xattr (dict_t *dict, char *key, data_t *value, void *data) "removexattr failed on %s (for %s): %s", filler->real_path, key, strerror (errno)); } - +#ifdef GF_DARWIN_HOST_OS + GF_FREE(newkey); +#endif return op_ret; } @@ -4176,10 +4240,19 @@ _posix_handle_xattr_keyvalue_pair (dict_t *d, char *k, data_t *v, optype = (gf_xattrop_flags_t)(filler->flags); this = filler->this; inode = filler->inode; - count = v->len; array = GF_CALLOC (count, sizeof (char), gf_posix_mt_char); +#ifdef GF_DARWIN_HOST_OS + struct posix_private *priv = NULL; + priv = this->private; + if (priv->xattr_user_namespace == XATTR_STRIP) { + if (strncmp(k, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) == 0) { + k += XATTR_USER_PREFIX_LEN; + } + } +#endif + LOCK (&inode->lock); { if (filler->real_path) { @@ -5135,6 +5208,23 @@ set_batch_fsync_mode (struct posix_private *priv, const char *str) return 0; } +#ifdef GF_DARWIN_HOST_OS +static int +set_xattr_user_namespace_mode (struct posix_private *priv, const char *str) +{ + if (strcmp (str, "none") == 0) + priv->xattr_user_namespace = XATTR_NONE; + else if (strcmp (str, "strip") == 0) + priv->xattr_user_namespace = XATTR_STRIP; + else if (strcmp (str, "append") == 0) + priv->xattr_user_namespace = XATTR_APPEND; + else if (strcmp (str, "both") == 0) + priv->xattr_user_namespace = XATTR_BOTH; + else + return -1; + return 0; +} +#endif int reconfigure (xlator_t *this, dict_t *options) @@ -5164,6 +5254,21 @@ reconfigure (xlator_t *this, dict_t *options) goto out; } +#ifdef GF_DARWIN_HOST_OS + + char *xattr_user_namespace_mode_str = NULL; + + GF_OPTION_RECONF ("xattr-user-namespace-mode", xattr_user_namespace_mode_str, + options, str, out); + + if (set_xattr_user_namespace_mode (priv, xattr_user_namespace_mode_str) != 0) { + gf_log (this->name, GF_LOG_ERROR, "Unknown xattr user namespace mode string: %s", + xattr_user_namespace_mode_str); + goto out; + } + +#endif + GF_OPTION_RECONF ("linux-aio", priv->aio_configured, options, bool, out); @@ -5351,7 +5456,8 @@ init (xlator_t *this) dir_data->data); ret = -1; goto out; - } else if ((size == -1) && (errno != ENODATA)) { + } else if ((size == -1) && (errno != ENODATA) && + (errno != ENOATTR)) { /* Wrong 'gfid' is set, it should be error */ gf_log (this->name, GF_LOG_WARNING, "%s: failed to fetch gfid (%s)", @@ -5610,8 +5716,24 @@ init (xlator_t *this) goto out; } - GF_OPTION_INIT ("batch-fsync-delay-usec", _private->batch_fsync_delay_usec, - uint32, out); +#ifdef GF_DARWIN_HOST_OS + + char *xattr_user_namespace_mode_str = NULL; + + GF_OPTION_INIT ("xattr-user-namespace-mode", + xattr_user_namespace_mode_str, str, out); + + if (set_xattr_user_namespace_mode (_private, + xattr_user_namespace_mode_str) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "Unknown xattr user namespace mode string: %s", + xattr_user_namespace_mode_str); + goto out; + } +#endif + + GF_OPTION_INIT ("batch-fsync-delay-usec", _private->batch_fsync_delay_usec, + uint32, out); out: return ret; } @@ -5769,5 +5891,15 @@ struct volume_options options[] = { .default_value = "off", .description = "Enable placeholders for gfid to path conversion" }, +#if GF_DARWIN_HOST_OS + { .key = {"xattr-user-namespace-mode"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "none", + .description = "Option to control XATTR user namespace on the raw filesystem: " + "\t- None: Will use the user namespace, so files will be exchangable with Linux.\n" + " The raw filesystem will not be compatible with OS X Finder.\n" + "\t- Strip: Will strip the user namespace before setting. The raw filesystem will work in OS X.\n" + }, +#endif { .key = {NULL} } }; diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index 91e0664ed..c9bfc984d 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -158,6 +158,16 @@ struct posix_private { uint32_t health_check_interval; pthread_t health_check; gf_boolean_t health_check_active; + +#ifdef GF_DARWIN_HOST_OS + enum { + XATTR_NONE = 0, + XATTR_STRIP, + XATTR_APPEND, + XATTR_BOTH, + } xattr_user_namespace; +#endif + }; typedef struct { -- cgit