summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2014-04-28 14:18:50 +0000
committerJeff Darcy <jdarcy@redhat.com>2014-04-28 14:18:50 +0000
commite139b4d0ba2286c0d4d44ba81260c2b287016019 (patch)
tree0a21f0761528e0f79da0a9f67106eb128ace0cf7 /libglusterfs
parent73b60c87ca7f62517a8466431f5a8cf167589c8c (diff)
parentf2bac9f9d5b9956969ddd25a54bc636b82f6923e (diff)
Merge branch 'upstream'HEADmaster
Conflicts: rpc/xdr/src/glusterfs3-xdr.c rpc/xdr/src/glusterfs3-xdr.h xlators/features/changelog/src/Makefile.am xlators/features/changelog/src/changelog-helpers.h xlators/features/changelog/src/changelog.c xlators/mgmt/glusterd/src/glusterd-sm.c Change-Id: I9972a5e6184503477eb77a8b56c50a4db4eec3e2
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.c165
-rw-r--r--libglusterfs/src/common-utils.h14
-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.h13
-rw-r--r--libglusterfs/src/lvm-defaults.h25
-rw-r--r--libglusterfs/src/options.c78
-rw-r--r--libglusterfs/src/options.h13
-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, 499 insertions, 96 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index 8934b35f2..569d69be3 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 1bf3de3f5..bdaf5289d 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 80d9d2940..e63ffa142 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)
@@ -1858,6 +1880,70 @@ out:
return ret;
}
+/**
+ * valid_ipv4_subnetwork() takes the pattern and checks if it contains
+ * a valid ipv4 subnetwork pattern i.e. xx.xx.xx.xx/n. IPv4 address
+ * part (xx.xx.xx.xx) and mask bits lengh part (n). The mask bits lengh
+ * must be in 0-32 range (ipv4 addr is 32 bit). The pattern must be
+ * in this format.
+ *
+ * Returns _gf_true if both IP addr and mask bits len are valid
+ * _gf_false otherwise.
+ */
+gf_boolean_t
+valid_ipv4_subnetwork (const char *address)
+{
+ char *slash = NULL;
+ char *paddr = NULL;
+ char *endptr = NULL;
+ long prefixlen = -1;
+ gf_boolean_t retv = _gf_true;
+
+ if (address == NULL) {
+ gf_log_callingfn (THIS->name, GF_LOG_WARNING,
+ "argument invalid");
+ return _gf_false;
+ }
+
+ paddr = gf_strdup (address);
+ if (paddr == NULL) /* ENOMEM */
+ return _gf_false;
+
+ /*
+ * INVALID: If '/' is not present OR
+ * Nothing specified after '/'
+ */
+ slash = strchr(paddr, '/');
+ if ((slash == NULL) || (slash[1] == '\0')) {
+ gf_log_callingfn (THIS->name, GF_LOG_WARNING,
+ "Invalid IPv4 subnetwork format");
+ retv = _gf_false;
+ goto out;
+ }
+
+ *slash = '\0';
+ retv = valid_ipv4_address (paddr, strlen(paddr), _gf_false);
+ if (retv == _gf_false) {
+ gf_log_callingfn (THIS->name, GF_LOG_WARNING,
+ "Invalid IPv4 subnetwork address");
+ goto out;
+ }
+
+ prefixlen = strtol (slash + 1, &endptr, 10);
+ if ((errno != 0) || (*endptr != '\0') ||
+ (prefixlen < 0) || (prefixlen > 32)) {
+ gf_log_callingfn (THIS->name, GF_LOG_WARNING,
+ "Invalid IPv4 subnetwork mask");
+ retv = _gf_false;
+ goto out;
+ }
+
+ retv = _gf_true;
+out:
+ GF_FREE (paddr);
+ return retv;
+}
+
char
valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc)
{
@@ -1939,6 +2025,65 @@ out:
}
/**
+ * valid_mount_auth_address - Validate the rpc-auth.addr.allow/reject pattern
+ *
+ * @param address - Pattern to be validated
+ *
+ * @return _gf_true if "address" is "*" (anonymous) 'OR'
+ * if "address" is valid FQDN or valid IPv4/6 address 'OR'
+ * if "address" contains wildcard chars e.g. "'*' or '?' or '['"
+ * if "address" is valid ipv4 subnet pattern (xx.xx.xx.xx/n)
+ * _gf_false otherwise
+ *
+ *
+ * NB: If the user/admin set for wildcard pattern, then it does not have
+ * to be validated. Make it similar to the way exportfs (kNFS) works.
+ */
+gf_boolean_t
+valid_mount_auth_address (char *address)
+{
+ int length = 0;
+ char *cp = NULL;
+
+ /* 1. Check for "NULL and empty string */
+ if ((address == NULL) || (address[0] == '\0')){
+ gf_log_callingfn (THIS->name,
+ GF_LOG_WARNING, "argument invalid");
+ return _gf_false;
+ }
+
+ /* 2. Check for Anonymous */
+ if (strcmp(address, "*") == 0)
+ return _gf_true;
+
+ for (cp = address; *cp; cp++) {
+ /* 3. Check for wildcard pattern */
+ if (*cp == '*' || *cp == '?' || *cp == '[') {
+ return _gf_true;
+ }
+
+ /*
+ * 4. check for IPv4 subnetwork i.e. xx.xx.xx.xx/n
+ * TODO: check for IPv6 subnetwork
+ * NB: Wildcard must not be mixed with subnetwork.
+ */
+ if (*cp == '/') {
+ return valid_ipv4_subnetwork (address);
+ }
+ }
+
+ /* 5. Check for v4/v6 IP addr and FQDN/hostname */
+ length = strlen (address);
+ if ((valid_ipv4_address (address, length, _gf_false)) ||
+ (valid_ipv6_address (address, length, _gf_false)) ||
+ (valid_host_name (address, length))) {
+ return _gf_true;
+ }
+
+ return _gf_false;
+}
+
+/**
* gf_sock_union_equal_addr - check if two given gf_sock_unions have same addr
*
* @param a - first sock union
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index e17029dba..f11c95fa8 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);
@@ -580,9 +581,8 @@ char valid_host_name (char *address, int length);
char valid_ipv4_address (char *address, int length, gf_boolean_t wildcard_acc);
char valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc);
char valid_internet_address (char *address, gf_boolean_t wildcard_acc);
-char valid_ipv4_wildcard_check (char *address);
-char valid_ipv6_wildcard_check (char *address);
-char valid_wildcard_internet_address (char *address);
+gf_boolean_t valid_mount_auth_address (char *address);
+gf_boolean_t valid_ipv4_subnetwork (const char *address);
gf_boolean_t gf_sock_union_equal_addr (union gf_sock_union *a,
union gf_sock_union *b);
@@ -627,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 359a4a3b5..81408dbd0 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 1bed8bf9b..1198c65b1 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 36cc4d056..2d50aa62e 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 a172c2a85..2bb3558e9 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 f343731c7..2afa2f354 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 210602c32..0c5c3b4c4 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -24,17 +24,28 @@
#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"
+#define GF_PRI_USEC "ld"
#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 000000000..4d3b010b2
--- /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 31e5a681d..f63c60476 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,
@@ -574,16 +574,55 @@ out:
return ret;
}
+static int
+xlator_option_validate_mntauth (xlator_t *xl, const char *key,
+ const char *value, volume_option_t *opt,
+ char **op_errstr)
+{
+ int ret = -1;
+ char *dup_val = NULL;
+ char *addr_tok = NULL;
+ char *save_ptr = NULL;
+ char errstr[4096] = {0,};
+
+ dup_val = gf_strdup (value);
+ if (!dup_val)
+ goto out;
+
+ addr_tok = strtok_r (dup_val, ",", &save_ptr);
+ if (addr_tok == NULL)
+ goto out;
+ while (addr_tok) {
+ if (!valid_mount_auth_address (addr_tok))
+ goto out;
+
+ addr_tok = strtok_r (NULL, ",", &save_ptr);
+ }
+ ret = 0;
+
+out:
+ if (ret) {
+ snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not "
+ "a valid mount-auth-address", key, value, value);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ if (op_errstr)
+ *op_errstr = gf_strdup (errstr);
+ }
+ GF_FREE (dup_val);
+
+ return ret;
+}
+
/*XXX: the rules to validate are as per block-size required for stripe xlator */
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;
@@ -744,10 +783,11 @@ xlator_option_validate (xlator_t *xl, char *key, char *value,
xlator_option_validate_priority_list,
[GF_OPTION_TYPE_SIZE_LIST] = xlator_option_validate_size_list,
[GF_OPTION_TYPE_ANY] = xlator_option_validate_any,
+ [GF_OPTION_TYPE_CLIENT_AUTH_ADDR] = xlator_option_validate_mntauth,
[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;
@@ -1080,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;
}
@@ -1103,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);
@@ -1118,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 62f4ee92e..05a3d4332 100644
--- a/libglusterfs/src/options.h
+++ b/libglusterfs/src/options.h
@@ -38,6 +38,7 @@ typedef enum {
GF_OPTION_TYPE_INTERNET_ADDRESS_LIST,
GF_OPTION_TYPE_PRIORITY_LIST,
GF_OPTION_TYPE_SIZE_LIST,
+ GF_OPTION_TYPE_CLIENT_AUTH_ADDR,
GF_OPTION_TYPE_MAX,
} volume_option_type_t;
@@ -107,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);
@@ -162,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; \
}
@@ -188,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 d1b9ef84c..723695867 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 f1c9f58c3..bbf23bef0 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 a0c281a1e..5242ecc8c 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 490255df9..f37194b97 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);