summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-06-21 02:00:23 -0700
committerHarshavardhana <harsha@harshavardhana.net>2014-07-02 17:20:34 -0700
commit1b74cf992986287a510fe3b28a8ee7554e8b0992 (patch)
treea5fad911274080947f5874b4d90cc4f67b6f4473 /libglusterfs
parente4a3566681acbadfe0f7bd879443116885ada4eb (diff)
porting: Port for FreeBSD rebased from Mike Ma's efforts
- Provides a working Gluster Management Daemon, CLI - Provides a working GlusterFS server, GlusterNFS server - Provides a working GlusterFS client - execinfo port from FreeBSD is moved into ./contrib/libexecinfo for ease of portability on NetBSD. (FreeBSD 10 and OSX provide execinfo natively) - More portability cleanups for Darwin, FreeBSD and NetBSD - Provides a new rc script for FreeBSD Change-Id: I8dff336f97479ca5a7f9b8c6b730051c0f8ac46f BUG: 1111774 Original-Author: Mike Ma <mikemandarine@gmail.com> Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Reviewed-on: http://review.gluster.org/8141 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/Makefile.am13
-rw-r--r--libglusterfs/src/common-utils.c89
-rw-r--r--libglusterfs/src/common-utils.h7
-rw-r--r--libglusterfs/src/compat.h7
-rw-r--r--libglusterfs/src/logging.c14
-rw-r--r--libglusterfs/src/store.h1
-rw-r--r--libglusterfs/src/syscall.c2
7 files changed, 40 insertions, 93 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index ccac1a1e825..25ee4c27a8b 100644
--- a/libglusterfs/src/Makefile.am
+++ b/libglusterfs/src/Makefile.am
@@ -1,10 +1,10 @@
-libglusterfs_la_CFLAGS = -Wall $(GF_CFLAGS) \
- $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \
- -DDATADIR=\"$(localstatedir)\"
+libglusterfs_la_CFLAGS = -Wall $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \
+ -DDATADIR=\"$(localstatedir)\"
libglusterfs_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \
-DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \
- -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree
+ -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree \
+ -I$(CONTRIBDIR)/libexecinfo
libglusterfs_la_LIBADD = @LEXLIB@
libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION)
@@ -27,7 +27,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.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)/mount/mntent.c
+ $(CONTRIBDIR)/mount/mntent.c $(CONTRIBDIR)/libexecinfo/execinfo.c
nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c
@@ -44,7 +44,8 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h timespec.
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 \
- $(CONTRIBDIR)/mount/mntent_compat.h lvm-defaults.h
+ $(CONTRIBDIR)/mount/mntent_compat.h lvm-defaults.h \
+ $(CONTRIBDIR)/libexecinfo/execinfo_compat.h
EXTRA_DIST = graph.l graph.y
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 6ba5223da0b..124b312f4a1 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -15,6 +15,8 @@
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
+#else
+#include "execinfo_compat.h"
#endif
#include <stdio.h>
@@ -33,7 +35,7 @@
#include <signal.h>
#include <assert.h>
-#if defined GF_BSD_HOST_OS || defined GF_DARWIN_HOST_OS
+#if defined(GF_BSD_HOST_OS) || defined(GF_DARWIN_HOST_OS)
#include <sys/sysctl.h>
#endif
@@ -531,11 +533,9 @@ gf_print_trace (int32_t signum, glusterfs_ctx_t *ctx)
}
gf_dump_config_flags ();
-#if HAVE_BACKTRACE
gf_msg_backtrace_nomem (GF_LOG_ALERT, 200);
sprintf (msg, "---------");
gf_msg_plain_nomem (GF_LOG_ALERT, msg);
-#endif /* HAVE_BACKTRACE */
/* Send a signal to terminate the process */
signal (signum, SIG_DFL);
@@ -3062,82 +3062,29 @@ gf_set_log_ident (cmd_args_t *cmd_args)
int
gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine)(void *), void *arg)
-{
- sigset_t set, old;
- int ret;
-
- sigemptyset (&set);
-
- sigfillset (&set);
- sigdelset (&set, SIGSEGV);
- sigdelset (&set, SIGBUS);
- sigdelset (&set, SIGILL);
- sigdelset (&set, SIGSYS);
- sigdelset (&set, SIGFPE);
- sigdelset (&set, SIGABRT);
-
- pthread_sigmask (SIG_BLOCK, &set, &old);
-
- ret = pthread_create (thread, attr, start_routine, arg);
-
- pthread_sigmask (SIG_SETMASK, &old, NULL);
-
- return ret;
-}
-
-#ifdef __NetBSD__
-#ifdef __MACHINE_STACK_GROWS_UP
-#define BELOW >
-#else
-#define BELOW <
-#endif
-
-struct frameinfo {
- struct frameinfo *next;
- void *return_address;
-};
-
-size_t
-backtrace(void **trace, size_t len)
+ void *(*start_routine)(void *), void *arg)
{
- const struct frameinfo *frame = __builtin_frame_address(0);
- void *stack = &stack;
- size_t i;
+ sigset_t set, old;
+ int ret;
- for (i = 0; i < len; i++) {
- if ((void *)frame BELOW stack)
- return i;
- trace[i] = frame->return_address;
- frame = frame->next;
- }
+ sigemptyset (&set);
- return len;
-}
+ sigfillset (&set);
+ sigdelset (&set, SIGSEGV);
+ sigdelset (&set, SIGBUS);
+ sigdelset (&set, SIGILL);
+ sigdelset (&set, SIGSYS);
+ sigdelset (&set, SIGFPE);
+ sigdelset (&set, SIGABRT);
-char **
-backtrace_symbols(void *const *trace, size_t len)
-{
- static const size_t slen = sizeof("0x123456789abcdef");
- char **ptr = calloc(len, sizeof(*ptr) + slen);
- size_t i;
+ pthread_sigmask (SIG_BLOCK, &set, &old);
- if (ptr == NULL)
- return NULL;
+ ret = pthread_create (thread, attr, start_routine, arg);
- char *str = (void *)(ptr + len);
- size_t cur = 0, left = len * slen;
+ pthread_sigmask (SIG_SETMASK, &old, NULL);
- for (i = 0; i < len; i++) {
- ptr[i] = str + cur;
- cur += snprintf(str + cur, left - cur, "%p", trace[i]) + 1;
- assert(cur < left);
- }
-
- return ptr;
+ return ret;
}
-#undef BELOW
-#endif /* __NetBSD__ */
int
gf_skip_header_section (int fd, int header_len)
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 86848df452d..b4372f10bbc 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -621,12 +621,7 @@ gf_boolean_t gf_is_same_address (char *host1, char *host2);
void md5_wrapper(const unsigned char *data, size_t len, char *md5);
int gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine)(void *), void *arg);
-#ifdef __NetBSD__
-size_t backtrace(void **, size_t);
-char **backtrace_symbols(void *const *, size_t);
-#endif
-
+ void *(*start_routine)(void *), void *arg);
gf_boolean_t
gf_is_service_running (char *pidfile, int *pid);
int
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 81408dbd0ae..5920fce992b 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -125,6 +125,11 @@ enum {
#define sighandler_t sig_t
#endif
+#ifdef __FreeBSD__
+#undef ino_t
+#define ino_t uint64_t
+#endif /* __FreeBSD__ */
+
#ifndef ino64_t
#define ino64_t ino_t
#endif
@@ -153,6 +158,8 @@ enum {
#define F_GETLK64 F_GETLK
#define F_SETLK64 F_SETLK
#define F_SETLKW64 F_SETLKW
+#define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */
+#define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
#endif /* GF_BSD_HOST_OS */
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index b3626538b96..e9734bcfca1 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -25,6 +25,8 @@
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
+#else
+#include "execinfo_compat.h"
#endif
#include <sys/stat.h>
@@ -814,8 +816,6 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
else
basename = file;
-#if HAVE_BACKTRACE
- /* Print 'calling function' */
do {
void *array[5];
char **callingfn = NULL;
@@ -838,7 +838,6 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
free (callingfn);
} while (0);
-#endif /* HAVE_BACKTRACE */
if (ctx->log.log_control_file_found)
{
@@ -1070,7 +1069,6 @@ out:
return ret;
}
-#if HAVE_BACKTRACE
void
_gf_msg_backtrace_nomem (gf_loglevel_t level, int stacksize)
{
@@ -1105,7 +1103,8 @@ _gf_msg_backtrace_nomem (gf_loglevel_t level, int stacksize)
fileno (stderr);
if (bt_size && (fd != -1)) {
/* print to the file fd, to prevent any
- * allocations from backtrace_symbols */
+ allocations from backtrace_symbols
+ */
backtrace_symbols_fd (&array[0], bt_size, fd);
}
}
@@ -1153,7 +1152,6 @@ out:
FREE (callingfn);
return ret;
}
-#endif /* HAVE_BACKTRACE */
int
_gf_msg_nomem (const char *domain, const char *file,
@@ -1261,9 +1259,7 @@ _gf_msg_nomem (const char *domain, const char *file,
}
pthread_mutex_unlock (&ctx->log.logfile_mutex);
-#ifdef HAVE_BACKTRACE
_gf_msg_backtrace_nomem (level, GF_LOG_BACKTRACE_DEPTH);
-#endif
break;
}
@@ -2035,7 +2031,6 @@ _gf_msg (const char *domain, const char *file, const char *function,
if (level > ctx->log.loglevel)
goto out;
-#if HAVE_BACKTRACE
if (trace) {
ret = _gf_msg_backtrace (GF_LOG_BACKTRACE_DEPTH, callstr,
GF_LOG_BACKTRACE_DEPTH);
@@ -2044,7 +2039,6 @@ _gf_msg (const char *domain, const char *file, const char *function,
else
ret = 0;
}
-#endif /* HAVE_BACKTRACE */
pthread_mutex_lock (&ctx->log.logfile_mutex);
{
diff --git a/libglusterfs/src/store.h b/libglusterfs/src/store.h
index beb17ac4a2f..1ffd97c526f 100644
--- a/libglusterfs/src/store.h
+++ b/libglusterfs/src/store.h
@@ -15,6 +15,7 @@
#include "config.h"
#endif
+#include "compat.h"
#include "glusterfs.h"
struct gf_store_handle_ {
diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c
index 7236958677d..48418091676 100644
--- a/libglusterfs/src/syscall.c
+++ b/libglusterfs/src/syscall.c
@@ -311,6 +311,8 @@ sys_fdatasync (int fd)
{
#ifdef GF_DARWIN_HOST_OS
return fcntl (fd, F_FULLFSYNC);
+#elif __FreeBSD__
+ return fsync (fd);
#else
return fdatasync (fd);
#endif