summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-04-17 15:54:34 -0700
committerAnand Avati <avati@redhat.com>2014-04-24 14:41:48 -0700
commita3cb38e3edf005bef73da4c9cfd958474a14d50f (patch)
treea406029332a9eb096c14d441160bb670a42df8cb /libglusterfs
parent9c13471b109587a639662fc690384285bee02bc6 (diff)
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 <harsha@harshavardhana.net> Signed-off-by: Dennis Schafroth <dennis@schafroth.com> Tested-by: Harshavardhana <harsha@harshavardhana.net> Tested-by: Dennis Schafroth <dennis@schafroth.com> Reviewed-on: http://review.gluster.org/7503 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/Makefile.am7
-rw-r--r--libglusterfs/src/client_t.c2
-rw-r--r--libglusterfs/src/common-utils.c42
-rw-r--r--libglusterfs/src/common-utils.h9
-rw-r--r--libglusterfs/src/compat.h53
-rw-r--r--libglusterfs/src/dict.c6
-rw-r--r--libglusterfs/src/fd.c2
-rw-r--r--libglusterfs/src/glusterfs.h2
-rw-r--r--libglusterfs/src/logging.c20
-rw-r--r--libglusterfs/src/logging.h12
-rw-r--r--libglusterfs/src/lvm-defaults.h25
-rw-r--r--libglusterfs/src/options.c38
-rw-r--r--libglusterfs/src/options.h12
-rw-r--r--libglusterfs/src/syscall.c99
-rw-r--r--libglusterfs/src/syscall.h53
-rw-r--r--libglusterfs/src/timespec.c41
-rw-r--r--libglusterfs/src/timespec.h2
17 files changed, 332 insertions, 93 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index 8934b35f2d8..569d69be330 100644
--- a/libglusterfs/src/Makefile.am
+++ b/libglusterfs/src/Makefile.am
@@ -26,8 +26,8 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
graph-print.c trie.c run.c options.c fd-lk.c circ-buff.c \
event-history.c gidcache.c ctx.c client_t.c event-poll.c event-epoll.c \
$(CONTRIBDIR)/libgen/basename_r.c $(CONTRIBDIR)/libgen/dirname_r.c \
- $(CONTRIBDIR)/stdlib/gf_mkostemp.c strfd.c
-
+ $(CONTRIBDIR)/stdlib/gf_mkostemp.c strfd.c \
+ $(CONTRIBDIR)/mount/mntent.c
nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c gf-error-codes.h
@@ -43,7 +43,8 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h timespec.
$(CONTRIB_BUILDDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h \
run.h options.h lkowner.h fd-lk.h circ-buff.h event-history.h \
gidcache.h client_t.h glusterfs-acl.h glfs-message-id.h \
- template-component-messages.h strfd.h
+ template-component-messages.h strfd.h \
+ $(CONTRIBDIR)/mount/mntent_compat.h lvm-defaults.h
EXTRA_DIST = graph.l graph.y
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index 1bf3de3f5ff..bdaf5289d16 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -52,7 +52,7 @@ gf_client_clienttable_expand (clienttable_t *clienttable, uint32_t nr)
uint32_t oldmax_clients = -1;
int ret = -1;
- if (clienttable == NULL || nr < 0) {
+ if (clienttable == NULL || nr > UINT32_MAX) {
gf_log_callingfn ("client_t", GF_LOG_ERROR, "invalid argument");
ret = EINVAL;
goto out;
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index b7d06d9251e..e63ffa1420a 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1170,7 +1170,7 @@ gf_string2uint8 (const char *str, uint8_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT8_MAX) {
+ if (l <= UINT8_MAX) {
*n = (uint8_t) l;
return 0;
}
@@ -1189,7 +1189,7 @@ gf_string2uint16 (const char *str, uint16_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT16_MAX) {
+ if (l <= UINT16_MAX) {
*n = (uint16_t) l;
return 0;
}
@@ -1208,7 +1208,7 @@ gf_string2uint32 (const char *str, uint32_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT32_MAX) {
+ if (l <= UINT32_MAX) {
*n = (uint32_t) l;
return 0;
}
@@ -1227,7 +1227,7 @@ gf_string2uint64 (const char *str, uint64_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT64_MAX) {
+ if (l <= UINT64_MAX) {
*n = (uint64_t) l;
return 0;
}
@@ -1258,7 +1258,7 @@ gf_string2uint8_base10 (const char *str, uint8_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT8_MAX) {
+ if (l <= UINT8_MAX) {
*n = (uint8_t) l;
return 0;
}
@@ -1277,7 +1277,7 @@ gf_string2uint16_base10 (const char *str, uint16_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT16_MAX) {
+ if (l <= UINT16_MAX) {
*n = (uint16_t) l;
return 0;
}
@@ -1296,7 +1296,7 @@ gf_string2uint32_base10 (const char *str, uint32_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT32_MAX) {
+ if (l <= UINT32_MAX) {
*n = (uint32_t) l;
return 0;
}
@@ -1315,7 +1315,7 @@ gf_string2uint64_base10 (const char *str, uint64_t *n)
if (rv != 0)
return rv;
- if (l >= 0 && l <= UINT64_MAX) {
+ if (l <= UINT64_MAX) {
*n = (uint64_t) l;
return 0;
}
@@ -1361,7 +1361,7 @@ err:
}
int
-gf_string2bytesize (const char *str, uint64_t *n)
+gf_string2bytesize_range (const char *str, uint64_t *n, uint64_t max)
{
double value = 0.0;
char *tail = NULL;
@@ -1410,7 +1410,7 @@ gf_string2bytesize (const char *str, uint64_t *n)
return -1;
}
- if ((UINT64_MAX - value) < 0) {
+ if ((max - value) < 0) {
errno = ERANGE;
return -1;
}
@@ -1421,6 +1421,28 @@ gf_string2bytesize (const char *str, uint64_t *n)
}
int
+gf_string2bytesize_size (const char *str, size_t *n)
+{
+ uint64_t u64;
+ size_t max = (size_t) - 1;
+ int val = gf_string2bytesize_range (str, &u64, max);
+ *n = (size_t) u64;
+ return val;
+}
+
+int
+gf_string2bytesize (const char *str, uint64_t *n)
+{
+ return gf_string2bytesize_range(str, n, UINT64_MAX);
+}
+
+int
+gf_string2bytesize_uint64 (const char *str, uint64_t *n)
+{
+ return gf_string2bytesize_range(str, n, UINT64_MAX);
+}
+
+int
gf_string2percent_or_bytesize (const char *str,
uint64_t *n,
gf_boolean_t *is_percent)
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 3a58a933121..f11c95fa873 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -488,12 +488,12 @@ static inline void
gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt)
{
extern void _gf_timestuff (gf_timefmts *, const char ***, const char ***);
- static gf_timefmts timefmt_last = (gf_timefmts) -1;
+ static gf_timefmts timefmt_last = (gf_timefmts) - 1;
static const char **fmts;
static const char **zeros;
struct tm tm;
- if (timefmt_last == -1)
+ if (timefmt_last == (gf_timefmts) - 1)
_gf_timestuff (&timefmt_last, &fmts, &zeros);
if (timefmt_last < fmt) fmt = gf_timefmt_default;
if (utime && gmtime_r (&utime, &tm) != NULL) {
@@ -552,8 +552,9 @@ int gf_string2uint8_base10 (const char *str, uint8_t *n);
int gf_string2uint16_base10 (const char *str, uint16_t *n);
int gf_string2uint32_base10 (const char *str, uint32_t *n);
int gf_string2uint64_base10 (const char *str, uint64_t *n);
-
int gf_string2bytesize (const char *str, uint64_t *n);
+int gf_string2bytesize_size (const char *str, size_t *n);
+int gf_string2bytesize_uint64 (const char *str, uint64_t *n);
int gf_string2percent_or_bytesize (const char *str, uint64_t *n,
gf_boolean_t *is_percent);
@@ -626,7 +627,7 @@ gf_skip_header_section (int fd, int header_len);
struct iatt;
struct _dict;
-inline gf_boolean_t
+gf_boolean_t
dht_is_linkfile (struct iatt *buf, struct _dict *dict);
int
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 359a4a3b5cf..81408dbd0ae 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -31,11 +31,21 @@
#include <sys/un.h>
#include <linux/limits.h>
#include <sys/xattr.h>
+#include <linux/xattr.h>
#include <endian.h>
#ifdef HAVE_LINUX_FALLOC_H
#include <linux/falloc.h>
#endif
+#ifdef HAVE_ENDIAN_H
+#include <endian.h>
+#endif
+#endif /* GF_LINUX_HOST_OS */
+
+#ifdef HAVE_XATTR_H
+#include <sys/xattr.h>
+#endif
+
/*
* Define the fallocate flags in case we do not have the header. This also
* accounts for older systems that do not define FALLOC_FL_PUNCH_HOLE.
@@ -61,7 +71,29 @@
#define lsetxattr(path,key,value,size,flags) setxattr(path,key,value,size,flags)
#endif /* HAVE_LLISTXATTR */
-#endif /* GF_LINUX_HOST_OS */
+
+
+#ifdef GF_DARWIN_HOST_OS
+#include <machine/endian.h>
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#endif
+
#ifdef GF_BSD_HOST_OS
/* In case of FreeBSD and NetBSD */
@@ -125,12 +157,29 @@ enum {
#endif /* GF_BSD_HOST_OS */
#ifdef GF_DARWIN_HOST_OS
+#include <machine/endian.h>
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
#define UNIX_PATH_MAX 104
+#define AT_SYMLINK_NOFOLLOW 0x100
#include <sys/types.h>
#include <sys/un.h>
-#include <machine/endian.h>
#include <sys/xattr.h>
#include <limits.h>
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index 1bed8bf9b69..1198c65b1d4 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -1041,7 +1041,7 @@ data_to_uint8 (data_t *data)
errno = 0;
value = strtol (str, NULL, 0);
- if ((UCHAR_MAX - value) < 0) {
+ if ((UCHAR_MAX - (uint8_t)value) < 0) {
errno = ERANGE;
gf_log_callingfn ("dict", GF_LOG_WARNING,
"data conversion overflow detected (%s)",
@@ -2157,7 +2157,7 @@ dict_set_bin (dict_t *this, char *key, void *ptr, size_t size)
data_t * data = NULL;
int ret = 0;
- if (!ptr || (size < 0)) {
+ if (!ptr || (size > ULONG_MAX)) {
ret = -EINVAL;
goto err;
}
@@ -2185,7 +2185,7 @@ dict_set_static_bin (dict_t *this, char *key, void *ptr, size_t size)
data_t * data = NULL;
int ret = 0;
- if (!ptr || (size < 0)) {
+ if (!ptr || (size > ULONG_MAX)) {
ret = -EINVAL;
goto err;
}
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index 36cc4d0561f..2d50aa62e42 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -59,7 +59,7 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
uint32_t oldmax_fds = -1;
int ret = -1;
- if (fdtable == NULL || nr < 0) {
+ if (fdtable == NULL || nr > UINT32_MAX) {
gf_log_callingfn ("fd", GF_LOG_ERROR, "invalid argument");
ret = EINVAL;
goto out;
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index c419308f9b5..96a203770e6 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -162,7 +162,7 @@
/* TODO: Keeping it to 200, so that we can fit in 2KB buffer for auth data
* in RPC server code, if there is ever need for having more aux-gids, then
* we have to add aux-gid in payload of actors */
-#define GF_MAX_AUX_GROUPS 65536
+#define GF_MAX_AUX_GROUPS 65535
#define GF_UUID_BUF_SIZE 50
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index f343731c7f4..2afa2f35431 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -21,9 +21,16 @@
#include <locale.h>
#include <string.h>
#include <stdlib.h>
+#include <syslog.h>
+#ifdef HAVE_LIBINTL_H
#include <libintl.h>
-#include <syslog.h>
+#endif
+
+#ifdef HAVE_BACKTRACE
+#include <execinfo.h>
+#endif
+
#include <sys/stat.h>
#include "gf-error-codes.h"
@@ -40,14 +47,6 @@
#include "defaults.h"
#include "glusterfs.h"
-#ifdef GF_LINUX_HOST_OS
-#include <syslog.h>
-#endif
-
-#ifdef HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
-
static char *gf_level_strings[] = {"", /* NONE */
"M", /* EMERGENCY */
"A", /* ALERT */
@@ -374,9 +373,10 @@ gf_openlog (const char *ident, int option, int facility)
/* TODO: Should check for errors here and return appropriately */
setlocale(LC_ALL, "");
+#ifdef HAVE_LIBINTL_H
bindtextdomain("gluster", "/usr/share/locale");
textdomain("gluster");
-
+#endif
/* close the previous syslog if open as we are changing settings */
closelog ();
openlog(ident, _option, _facility);
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index 210602c3210..3c83ebbc0e3 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -24,17 +24,27 @@
#ifdef GF_DARWIN_HOST_OS
#define GF_PRI_FSBLK "u"
#define GF_PRI_DEV PRId32
-#define GF_PRI_NLINK PRIu16
+#define GF_PRI_INODE PRIu64
+#define GF_PRI_NLINK PRIu32
+#define GF_PRI_SECOND "ld"
#define GF_PRI_SUSECONDS "06d"
+#define GF_PRI_USEC "d"
#else
#define GF_PRI_FSBLK PRIu64
#define GF_PRI_DEV PRIu64
+#define GF_PRI_INODE PRIu64
#define GF_PRI_NLINK PRIu32
+#define GF_PRI_SECOND "lu"
#define GF_PRI_SUSECONDS "06ld"
#endif
#define GF_PRI_BLKSIZE PRId32
#define GF_PRI_SIZET "zu"
+#ifdef GF_DARWIN_HOST_OS
+#define GF_PRI_TIME "ld"
+#else
+#define GF_PRI_TIME PRIu64
+#endif
#if 0
/* Syslog definitions :-) */
diff --git a/libglusterfs/src/lvm-defaults.h b/libglusterfs/src/lvm-defaults.h
new file mode 100644
index 00000000000..4d3b010b200
--- /dev/null
+++ b/libglusterfs/src/lvm-defaults.h
@@ -0,0 +1,25 @@
+/*
+ Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
+ 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 _LVM_DEFAULTS_H
+#define _LVM_DEFAULTS_H
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#define LVM_RESIZE "/sbin/lvresize"
+#define LVM_CREATE "/sbin/lvcreate"
+#define LVM_CONVERT "/sbin/lvconvert"
+#define LVM_REMOVE "/sbin/lvremove"
+#define LVS "/sbin/lvs"
+
+#endif /* _LVM_DEFAULTS_H */
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index a0881b4ad91..f63c60476da 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -79,7 +79,7 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,
goto out;
}
- if ((opt->validate == GF_OPT_VALIDATE_MIN)) {
+ if (opt->validate == GF_OPT_VALIDATE_MIN) {
if (inputll < opt->min) {
snprintf (errstr, 256,
"'%lld' in 'option %s %s' is smaller than "
@@ -88,8 +88,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,
gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
goto out;
}
- } else if ((opt->validate == GF_OPT_VALIDATE_MAX)) {
- if ((inputll > opt->max)) {
+ } else if (opt->validate == GF_OPT_VALIDATE_MAX) {
+ if (inputll > opt->max) {
snprintf (errstr, 256,
"'%lld' in 'option %s %s' is greater than "
"maximum value '%.0f'", inputll, key,
@@ -118,12 +118,12 @@ static int
xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,
volume_option_t *opt, char **op_errstr)
{
- uint64_t size = 0;
+ size_t size = 0;
int ret = 0;
char errstr[256];
/* Check the range */
- if (gf_string2bytesize (value, &size) != 0) {
+ if (gf_string2bytesize_size (value, &size) != 0) {
snprintf (errstr, 256,
"invalid number format \"%s\" in option \"%s\"",
value, key);
@@ -142,13 +142,13 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,
if ((size < opt->min) || (size > opt->max)) {
if ((strncmp (key, "cache-size", 10) == 0) &&
(size > opt->max)) {
- snprintf (errstr, 256, "Cache size %"PRId64" is out of "
+ snprintf (errstr, 256, "Cache size %" GF_PRI_SIZET " is out of "
"range [%.0f - %.0f]",
size, opt->min, opt->max);
gf_log (xl->name, GF_LOG_WARNING, "%s", errstr);
} else {
snprintf (errstr, 256,
- "'%"PRId64"' in 'option %s %s' "
+ "'%" GF_PRI_SIZET "' in 'option %s %s' "
"is out of range [%.0f - %.0f]",
size, key, value, opt->min, opt->max);
gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
@@ -478,7 +478,7 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,
goto out;
}
- if ((opt->validate == GF_OPT_VALIDATE_MIN)) {
+ if (opt->validate == GF_OPT_VALIDATE_MIN) {
if (input < opt->min) {
snprintf (errstr, 256,
"'%f' in 'option %s %s' is smaller than "
@@ -487,8 +487,8 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,
gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
goto out;
}
- } else if ((opt->validate == GF_OPT_VALIDATE_MAX)) {
- if ((input > opt->max)) {
+ } else if (opt->validate == GF_OPT_VALIDATE_MAX) {
+ if (input > opt->max) {
snprintf (errstr, 256,
"'%f' in 'option %s %s' is greater than "
"maximum value '%f'", input, key,
@@ -617,12 +617,12 @@ out:
static int
gf_validate_size (const char *sizestr, volume_option_t *opt)
{
- uint64_t value = 0;
+ size_t value = 0;
int ret = 0;
GF_ASSERT (opt);
- if (gf_string2bytesize (sizestr, &value) != 0 ||
+ if (gf_string2bytesize_size (sizestr, &value) != 0 ||
value < opt->min ||
value % 512) {
ret = -1;
@@ -787,7 +787,7 @@ xlator_option_validate (xlator_t *xl, char *key, char *value,
[GF_OPTION_TYPE_MAX] = NULL,
};
- if (opt->type < 0 || opt->type >= GF_OPTION_TYPE_MAX) {
+ if (opt->type > GF_OPTION_TYPE_MAX) {
gf_log (xl->name, GF_LOG_ERROR,
"unknown option type '%d'", opt->type);
goto out;
@@ -1120,18 +1120,18 @@ pc_or_size (char *in, double *out)
{
double pc = 0;
int ret = 0;
- uint64_t size = 0;
+ size_t size = 0;
if (gf_string2percent (in, &pc) == 0) {
if (pc > 100.0) {
- ret = gf_string2bytesize (in, &size);
+ ret = gf_string2bytesize_size (in, &size);
if (!ret)
*out = size;
} else {
*out = pc;
}
} else {
- ret = gf_string2bytesize (in, &size);
+ ret = gf_string2bytesize_size (in, &size);
if (!ret)
*out = size;
}
@@ -1143,7 +1143,8 @@ DEFINE_INIT_OPT(uint64_t, uint64, gf_string2uint64);
DEFINE_INIT_OPT(int64_t, int64, gf_string2int64);
DEFINE_INIT_OPT(uint32_t, uint32, gf_string2uint32);
DEFINE_INIT_OPT(int32_t, int32, gf_string2int32);
-DEFINE_INIT_OPT(uint64_t, size, gf_string2bytesize);
+DEFINE_INIT_OPT(size_t, size, gf_string2bytesize_size);
+DEFINE_INIT_OPT(uint64_t, size_uint64, gf_string2bytesize_uint64);
DEFINE_INIT_OPT(double, percent, gf_string2percent);
DEFINE_INIT_OPT(double, percent_or_size, pc_or_size);
DEFINE_INIT_OPT(gf_boolean_t, bool, gf_string2boolean);
@@ -1158,7 +1159,8 @@ DEFINE_RECONF_OPT(uint64_t, uint64, gf_string2uint64);
DEFINE_RECONF_OPT(int64_t, int64, gf_string2int64);
DEFINE_RECONF_OPT(uint32_t, uint32, gf_string2uint32);
DEFINE_RECONF_OPT(int32_t, int32, gf_string2int32);
-DEFINE_RECONF_OPT(uint64_t, size, gf_string2bytesize);
+DEFINE_RECONF_OPT(size_t, size, gf_string2bytesize_size);
+DEFINE_RECONF_OPT(uint64_t, size_uint64, gf_string2bytesize_uint64);
DEFINE_RECONF_OPT(double, percent, gf_string2percent);
DEFINE_RECONF_OPT(double, percent_or_size, pc_or_size);
DEFINE_RECONF_OPT(gf_boolean_t, bool, gf_string2boolean);
diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h
index 134cc360293..05a3d4332cf 100644
--- a/libglusterfs/src/options.h
+++ b/libglusterfs/src/options.h
@@ -108,7 +108,8 @@ DECLARE_INIT_OPT(uint64_t, uint64);
DECLARE_INIT_OPT(int64_t, int64);
DECLARE_INIT_OPT(uint32_t, uint32);
DECLARE_INIT_OPT(int32_t, int32);
-DECLARE_INIT_OPT(uint64_t, size);
+DECLARE_INIT_OPT(size_t, size);
+DECLARE_INIT_OPT(uint64_t, size_uint64);
DECLARE_INIT_OPT(double, percent);
DECLARE_INIT_OPT(double, percent_or_size);
DECLARE_INIT_OPT(gf_boolean_t, bool);
@@ -163,8 +164,12 @@ xlator_option_init_##type (xlator_t *this, dict_t *options, char *key, \
THIS = this; \
ret = conv (value, val_p); \
THIS = old_THIS; \
- if (ret) \
+ if (ret) { \
+ gf_log (this->name, GF_LOG_INFO, \
+ "option %s convertion failed value %s", \
+ key, value); \
return ret; \
+ } \
ret = xlator_option_validate (this, key, value, opt, NULL); \
return ret; \
}
@@ -189,7 +194,8 @@ DECLARE_RECONF_OPT(uint64_t, uint64);
DECLARE_RECONF_OPT(int64_t, int64);
DECLARE_RECONF_OPT(uint32_t, uint32);
DECLARE_RECONF_OPT(int32_t, int32);
-DECLARE_RECONF_OPT(uint64_t, size);
+DECLARE_RECONF_OPT(size_t, size);
+DECLARE_RECONF_OPT(uint64_t, size_uint64);
DECLARE_RECONF_OPT(double, percent);
DECLARE_RECONF_OPT(double, percent_or_size);
DECLARE_RECONF_OPT(gf_boolean_t, bool);
diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c
index d1b9ef84c96..7236958677d 100644
--- a/libglusterfs/src/syscall.c
+++ b/libglusterfs/src/syscall.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
+#include <fcntl.h>
int
sys_lstat (const char *path, struct stat *buf)
@@ -41,12 +42,58 @@ sys_fstat (int fd, struct stat *buf)
}
+int
+sys_fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
+{
+#ifdef GF_DARWIN_HOST_OS
+ if (fchdir(dirfd) < 0)
+ return -1;
+ if(flags & AT_SYMLINK_NOFOLLOW)
+ return lstat(pathname, buf);
+ else
+ return stat(pathname, buf);
+#else
+ return fstatat (dirfd, pathname, buf, flags);
+#endif
+}
+
+
+int
+sys_openat(int dirfd, const char *pathname, int flags, ...)
+{
+ mode_t mode = 0;
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ }
+
+#ifdef GF_DARWIN_HOST_OS
+ if (fchdir(dirfd) < 0)
+ return -1;
+ return open (pathname, flags, mode);
+#else
+ return openat (dirfd, pathname, flags, mode);
+#endif
+}
+
DIR *
sys_opendir (const char *name)
{
return opendir (name);
}
+int sys_mkdirat(int dirfd, const char *pathname, mode_t mode)
+{
+#ifdef GF_DARWIN_HOST_OS
+ if(fchdir(dirfd) < 0)
+ return -1;
+ return mkdir(pathname, mode);
+#else
+ return mkdirat (dirfd, pathname, mode);
+#endif
+}
struct dirent *
sys_readdir (DIR *dir)
@@ -262,13 +309,43 @@ sys_fsync (int fd)
int
sys_fdatasync (int fd)
{
-#ifdef HAVE_FDATASYNC
- return fdatasync (fd);
+#ifdef GF_DARWIN_HOST_OS
+ return fcntl (fd, F_FULLFSYNC);
#else
- return 0;
+ return fdatasync (fd);
#endif
}
+void
+gf_add_prefix(const char *ns, const char *key, char **newkey)
+{
+ /* if we dont have any namespace, append USER NS */
+ if (strncmp(key, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
+ strncmp(key, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
+ strncmp(key, XATTR_SECURITY_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
+ strncmp(key, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) {
+ int ns_length = strlen(ns);
+ *newkey = GF_MALLOC(ns_length + strlen(key) + 10,
+ gf_common_mt_char);
+ strcpy(*newkey, ns);
+ strcat(*newkey, key);
+ } else {
+ *newkey = gf_strdup(key);
+ }
+}
+
+void
+gf_remove_prefix(const char *ns, const char *key, char **newkey)
+{
+ int ns_length = strlen(ns);
+ if (strncmp(key, ns, ns_length) == 0) {
+ *newkey = GF_MALLOC(-ns_length + strlen(key) + 10,
+ gf_common_mt_char);
+ strcpy(*newkey, key + ns_length);
+ } else {
+ *newkey = gf_strdup(key);
+ }
+}
int
sys_lsetxattr (const char *path, const char *name, const void *value,
@@ -289,8 +366,11 @@ sys_lsetxattr (const char *path, const char *name, const void *value,
#endif
#ifdef GF_DARWIN_HOST_OS
+ /* OS X clients will carry other flags, which will be used on a
+ OS X host, but masked out on others. GF assume NOFOLLOW on Linux,
+ enforcing */
return setxattr (path, name, value, size, 0,
- flags|XATTR_NOFOLLOW);
+ (flags & ~XATTR_NOSECURITY) | XATTR_NOFOLLOW);
#endif
}
@@ -313,12 +393,10 @@ sys_llistxattr (const char *path, char *list, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return listxattr (path, list, size, XATTR_NOFOLLOW);
+ return listxattr (path, list, size, XATTR_NOFOLLOW);
#endif
-
}
-
ssize_t
sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
{
@@ -337,7 +415,7 @@ sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return getxattr (path, name, value, size, 0, XATTR_NOFOLLOW);
+ return getxattr (path, name, value, size, 0, XATTR_NOFOLLOW);
#endif
}
@@ -412,7 +490,7 @@ sys_fsetxattr (int filedes, const char *name, const void *value,
#endif
#ifdef GF_DARWIN_HOST_OS
- return fsetxattr (filedes, name, value, size, 0, flags);
+ return fsetxattr (filedes, name, value, size, 0, flags & ~XATTR_NOSECURITY);
#endif
}
@@ -435,7 +513,7 @@ sys_flistxattr (int filedes, char *list, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return flistxattr (filedes, list, size, XATTR_NOFOLLOW);
+ return flistxattr (filedes, list, size, XATTR_NOFOLLOW);
#endif
}
@@ -491,4 +569,3 @@ sys_fallocate(int fd, int mode, off_t offset, off_t len)
errno = ENOSYS;
return -1;
}
-
diff --git a/libglusterfs/src/syscall.h b/libglusterfs/src/syscall.h
index f1c9f58c3fc..bbf23bef07b 100644
--- a/libglusterfs/src/syscall.h
+++ b/libglusterfs/src/syscall.h
@@ -11,6 +11,41 @@
#ifndef __SYSCALL_H__
#define __SYSCALL_H__
+/* GF follows the Linux XATTR definition, which differs in Darwin. */
+#define GF_XATTR_CREATE 0x1 /* set value, fail if attr already exists */
+#define GF_XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
+
+/* Linux kernel version 2.6.x don't have these defined
+ define if not defined */
+
+#ifndef XATTR_SECURITY_PREFIX
+#define XATTR_SECURITY_PREFIX "security."
+#define XATTR_SECURITY_PREFIX_LEN (sizeof (XATTR_SECURITY_PREFIX) - 1)
+#endif
+
+#ifndef XATTR_SYSTEM_PREFIX
+#define XATTR_SYSTEM_PREFIX "system."
+#define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
+#endif
+
+#ifndef XATTR_TRUSTED_PREFIX
+#define XATTR_TRUSTED_PREFIX "trusted."
+#define XATTR_TRUSTED_PREFIX_LEN (sizeof (XATTR_TRUSTED_PREFIX) - 1)
+#endif
+
+#ifndef XATTR_USER_PREFIX
+#define XATTR_USER_PREFIX "user."
+#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
+#endif
+
+#if defined(GF_DARWIN_HOST_OS)
+#include <sys/xattr.h>
+#define XATTR_DARWIN_NOSECURITY XATTR_NOSECURITY
+#define XATTR_DARWIN_NODEFAULT XATTR_NODEFAULT
+#define XATTR_DARWIN_SHOWCOMPRESSION XATTR_SHOWCOMPRESSION
+#endif
+
+
int
sys_lstat (const char *path, struct stat *buf);
@@ -20,8 +55,13 @@ sys_stat (const char *path, struct stat *buf);
int
sys_fstat (int fd, struct stat *buf);
-DIR *
-sys_opendir (const char *name);
+int
+sys_fstatat (int dirfd, const char *pathname, struct stat *buf,
+ int flags);
+int
+sys_openat (int dirfd, const char *pathname, int flags, ...);
+
+DIR *sys_opendir (const char *name);
struct dirent *
sys_readdir (DIR *dir);
@@ -39,6 +79,9 @@ int
sys_mkdir (const char *pathname, mode_t mode);
int
+sys_mkdirat (int dirfd, const char *pathname, mode_t mode);
+
+int
sys_unlink (const char *pathname);
int
@@ -107,6 +150,12 @@ sys_fsync (int fd);
int
sys_fdatasync (int fd);
+void
+gf_add_prefix(const char *ns, const char *key, char **newkey);
+
+void
+gf_remove_prefix(const char *ns, const char *key, char **newkey);
+
int
sys_lsetxattr (const char *path, const char *name, const void *value,
size_t size, int flags);
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
index a0c281a1efb..5242ecc8cd0 100644
--- a/libglusterfs/src/timespec.c
+++ b/libglusterfs/src/timespec.c
@@ -10,54 +10,51 @@
#include <stdio.h>
#include <inttypes.h>
-#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS
#include <time.h>
#include <sys/time.h>
-#endif
#if defined GF_DARWIN_HOST_OS
#include <mach/mach_time.h>
+static mach_timebase_info_data_t gf_timebase;
#endif
#include "logging.h"
-#include "time.h"
-
-
-void tv2ts (struct timeval tv, struct timespec *ts)
-{
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
-}
+#include "timespec.h"
void timespec_now (struct timespec *ts)
{
#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS
-
if (0 == clock_gettime(CLOCK_MONOTONIC, ts))
return;
else {
struct timeval tv;
if (0 == gettimeofday(&tv, NULL))
- tv2ts(tv, ts);
+ TIMEVAL_TO_TIMESPEC(&tv, ts);
}
#elif defined GF_DARWIN_HOST_OS
- mach_timebase_info_data_t tb = { 0 };
- static double timebase = 0.0;
- uint64_t time = 0;
- mach_timebase_info (&tb);
+ uint64_t time = mach_absolute_time();
+ static double scaling = 0.0;
- timebase *= info.numer;
- timebase /= info.denom;
+ if (mach_timebase_info(&gf_timebase) != KERN_SUCCESS) {
+ gf_timebase.numer = 1;
+ gf_timebase.denom = 1;
+ }
+ if (gf_timebase.denom == 0) {
+ gf_timebase.numer = 1;
+ gf_timebase.denom = 1;
+ }
- time = mach_absolute_time();
- time *= timebase;
+ scaling = (double) gf_timebase.numer / (double) gf_timebase.denom;
+ time *= scaling;
ts->tv_sec = (time * NANO);
- ts->tv_nsec = (time - (ts.tv_sec * GIGA));
+ ts->tv_nsec = (time - (ts->tv_sec * GIGA));
#endif /* Platform verification */
- gf_log_callingfn ("timer", GF_LOG_DEBUG, "%"PRIu64".%09"PRIu64,
+ /*
+ gf_log_callingfn ("timer", GF_LOG_TRACE, "%"GF_PRI_TIME".%09"GF_PRI_TIME,
ts->tv_sec, ts->tv_nsec);
+ */
}
void timespec_adjust_delta (struct timespec *ts, struct timespec delta)
diff --git a/libglusterfs/src/timespec.h b/libglusterfs/src/timespec.h
index 490255df9f3..f37194b97cf 100644
--- a/libglusterfs/src/timespec.h
+++ b/libglusterfs/src/timespec.h
@@ -12,12 +12,12 @@
#define __INCLUDE_TIMESPEC_H__
#include <stdint.h>
+#include <sys/time.h>
#define TS(ts) ((ts.tv_sec * 1000000000LL) + ts.tv_nsec)
#define NANO (+1.0E-9)
#define GIGA UINT64_C(1000000000)
-void tv2ts (struct timeval tv, struct timespec *ts);
void timespec_now (struct timespec *ts);
void timespec_adjust_delta (struct timespec *ts, struct timespec delta);