new file mode 100644
@@ -0,0 +1,21 @@
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expr) \
+ ({ long int _res; \
+ do _res = (long int) (expr); \
+ while (_res == -1L && errno == EINTR); \
+ _res; })
+#endif
+
+typedef signed char __s8;
+typedef unsigned char __u8;
+typedef signed short __s16;
+typedef unsigned short __u16;
+typedef signed int __s32;
+typedef unsigned int __u32;
+typedef signed long __s64;
+typedef unsigned long __u64;
+
+typedef unsigned short __le16;
+typedef unsigned int __le32;
+typedef unsigned long __le64;
+
@@ -1,4 +1,5 @@
#!/bin/sh
+LIBTOOLIZE=$(which glibtoolize || which libtoolize)
check_for_pkg_config() {
which pkg-config >/dev/null && return
@@ -14,7 +15,7 @@ check_for_pkg_config() {
rm -f config.cache
aclocal #-I m4
check_for_pkg_config
-libtoolize --force --copy
+$LIBTOOLIZE --force --copy
autoconf
autoheader
automake -a --add-missing -Wall
@@ -15,6 +15,13 @@
#define CEPH_CRYPTO_H
#include "include/types.h"
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expr) \
+ ({ long int _res; \
+ do _res = (long int) (expr); \
+ while (_res == -1L && errno == EINTR); \
+ _res; })
+#endif
/*
* match encoding of struct ceph_secret
@@ -2,7 +2,12 @@
#define FS_CEPH_IOCTL_H
#include <linux/ioctl.h>
-#include <linux/types.h>
+
+#if defined(__APPLE__)
+ #include "include/mac-compat.h
+#else
+ #include <linux/types.h>
+#endif
#define CEPH_IOCTL_MAGIC 0x97
@@ -4,6 +4,10 @@
#include "config.h"
#include "debug.h"
+#if defined(__APPLE__)
+#include <malloc/malloc.h>
+#endif
+
#include <fstream>
void MemoryModel::_sample(snap *psnap)
@@ -85,11 +89,14 @@ void MemoryModel::_sample(snap *psnap)
psnap->heap = heap >> 10;
// ...
+#if defined(__APPLE__)
+ struct mstats ms = mstats();
+ psnap->malloc = ms.bytes_used >> 10;
+ psnap->mmap = ms.chunks_used >> 10;
+#else
struct mallinfo mi = mallinfo();
-
psnap->malloc = mi.uordblks >> 10;
psnap->mmap = mi.hblks >> 10;
-
ofstream log("/tmp/memlog", ios::app);
log << "heap " << heap
@@ -101,4 +108,6 @@ void MemoryModel::_sample(snap *psnap)
<< "\t" << mi.hblks
<< "\t" << mi.hblkhd / 1024
<< std::endl;
+#endif
+
}
@@ -1,5 +1,8 @@
-
-#include <linux/errno.h>
+#if defined(__APPLE__)
+ #include <sys/errno.h>
+#else
+ #include <linux/errno.h>
+#endif
/*
* base64 encode/decode.
@@ -41,9 +41,12 @@ __FBSDID("$FreeBSD: src/sys/netinet/sctp_crc32.c,v 1.8 2007/05/08 17:01:10 rrs E
#endif
#include <stdint.h>
-#include <endian.h>
-
+#if defined(__APPLE__)
+ #include <architecture/byte_order.h>
+#else
+ #include <endian.h>
+#endif
#ifndef SCTP_USE_ADLER32
@@ -1,8 +1,11 @@
#ifndef CEPH_CRUSH_CRUSH_H
#define CEPH_CRUSH_CRUSH_H
-#include <linux/types.h>
-
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
/*
* CRUSH is a pseudo-random data distribution algorithm that
* efficiently distributes input values (typically, data objects)
@@ -1,5 +1,8 @@
-
-#include <linux/types.h>
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#include "hash.h"
/*
@@ -7,8 +7,12 @@
# include <stdlib.h>
#endif
-
-#include <linux/types.h> /* just for int types */
+/* just for int types */
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#ifndef BUG_ON
# define BUG_ON(x) assert(!(x))
@@ -28,7 +28,8 @@ namespace ceph {
class Spinlock {
private:
- pthread_spinlock_t _s;
+// pthread_spinlock_t _s;
+ pthread_mutex_t _s;
int nlock;
// don't allow copying.
@@ -71,12 +72,14 @@ public:
, name(n), id(-1), lockdep(ld), backtrace(bt)
#endif
{
- pthread_spin_init(&_s, 0);
+// pthread_spin_init(&_s, 0);
+ pthread_mutex_init(&_s, 0);
_register();
}
~Spinlock() {
assert(nlock == 0);
- pthread_spin_destroy(&_s);
+// pthread_spin_destroy(&_s);
+ pthread_mutex_destroy(&_s);
}
bool is_locked() {
@@ -84,7 +87,7 @@ public:
}
bool try_lock() {
- int r = pthread_spin_trylock(&_s);
+ int r = pthread_mutex_trylock(&_s);
if (r == 0) {
_locked();
nlock++;
@@ -94,7 +97,7 @@ public:
void lock() {
_will_lock();
- int r = pthread_spin_lock(&_s);
+ int r = pthread_mutex_lock(&_s);
_locked();
assert(r == 0);
nlock++;
@@ -104,7 +107,7 @@ public:
assert(nlock > 0);
--nlock;
_will_unlock();
- int r = pthread_spin_unlock(&_s);
+ int r = pthread_mutex_unlock(&_s);
assert(r == 0);
}
@@ -1,7 +1,9 @@
#ifndef CEPH_ASSERT_H
#define CEPH_ASSERT_H
+#if !defined(__APPLE__)
#include <features.h>
+#endif
#ifdef __CEPH__
# include "acconfig.h"
@@ -31,18 +33,20 @@ struct FailedAssertion {
#endif
-#if defined __cplusplus && __GNUC_PREREQ (2,95)
-# define __CEPH_ASSERT_VOID_CAST static_cast<void>
-#else
-# define __CEPH_ASSERT_VOID_CAST (void)
-#endif
+//#if defined __cplusplus && __GNUC_PREREQ (2,95)
+//# define __CEPH_ASSERT_VOID_CAST static_cast<void>
+//#else
+#define __CEPH_ASSERT_VOID_CAST (void)
+//#endif
/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
which contains the name of the function currently being defined.
This is broken in G++ before version 2.6.
C9x has a similar variable called __func__, but prefer the GCC one since
it demangles C++ function names. */
-# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
+# define __ASSERT_FUNCTION __PRETTY_FUNCTION__
+
+/*# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
# define __ASSERT_FUNCTION __PRETTY_FUNCTION__
# else
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
@@ -51,7 +55,7 @@ struct FailedAssertion {
# define __ASSERT_FUNCTION ((__const char *) 0)
# endif
# endif
-
+*/
extern void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *function)
__attribute__ ((__noreturn__));
extern void __ceph_assert_warn(const char *assertion, const char *file, int line, const char *function);
@@ -14,8 +14,11 @@
#ifndef CEPH_BUFFER_H
#define CEPH_BUFFER_H
-
-#include <linux/types.h>
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 600
@@ -35,8 +38,11 @@ void *valloc(size_t);
#else
-
-#include <malloc.h>
+#if !defined(__APPLE__)
+ #include <malloc.h>
+#else
+ #include <malloc/malloc.h>
+#endif
#endif
#include <stdint.h>
#include <string.h>
@@ -6,8 +6,11 @@
#ifndef CEPH_BYTEORDER_H
#define CEPH_BYTEORDER_H
-
-#include <endian.h>
+#if defined(__APPLE__)
+ #include <architecture/byte_order.h>
+#else
+ #include <endian.h>
+#endif
static __inline__ __u16 swab16(__u16 val)
{
@@ -2,6 +2,9 @@
#define CEPH_INTTYPES_H
#include <stdint.h>
-#include <linux/types.h>
-
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#endif
@@ -6,7 +6,12 @@ extern "C" {
#endif
#include <netinet/in.h>
-#include <linux/types.h>
+
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>>
+#endif
#include <string.h>
#ifndef CEPH_OSD_TMAP_SET
@@ -13,7 +13,18 @@
#ifndef CEPH_RBD_TYPES_H
#define CEPH_RBD_TYPES_H
-#include <linux/types.h>
+#if defined(__APPLE__)
+typedef signed char __s8;
+typedef unsigned char __u8;
+typedef signed short __s16;
+typedef unsigned short __u16;
+typedef signed int __s32;
+typedef unsigned int __u32;
+typedef signed long __s64;
+typedef unsigned long __u64;
+#else
+ #include <linux/types.h>
+#endif
/*
* rbd image 'foo' consists of objects
@@ -5,7 +5,12 @@ typedef char bool;
#define true 1
#include <netinet/in.h>
-#include <linux/types.h>
+
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#include <string.h>
#include <fcntl.h>
@@ -1990,8 +1990,11 @@ int SimpleMessenger::Pipe::do_sendmsg(int sd, struct msghdr *msg, int len, bool
l += msg->msg_iov[i].iov_len;
assert(l == len);
}
-
- int r = ::sendmsg(sd, msg, more ? MSG_MORE : 0);
+ #if defined(__APPLE__)
+ int r = ::sendmsg(sd, msg, more ? 0 : 0);
+ #else
+ int r = ::sendmsg(sd, msg, more ? MSG_MORE : 0);
+ #endif
if (r == 0)
dout(10) << "do_sendmsg hmm do_sendmsg got r==0!" << dendl;
if (r < 0) {
@@ -133,10 +133,10 @@ private:
Mutex pipe_lock;
int state;
+ Connection *connection_state;
protected:
friend class SimpleMessenger;
- Connection *connection_state;
utime_t backoff; // backoff time
@@ -1,4 +1,4 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include <poll.h>
@@ -8,7 +8,7 @@
/******************
* tcp crap
*/
-int tcp_read(int sd, char *buf, int len, int timeout)
+int tcp_read(int sd, char *buf, int len, int timeout)
{
if (sd < 0)
return -1;
@@ -37,18 +37,26 @@ int tcp_read(int sd, char *buf, int len, int timeout)
return len;
}
-int tcp_read_wait(int sd, int timeout)
+int tcp_read_wait(int sd, int timeout)
{
if (sd < 0)
return -1;
struct pollfd pfd;
pfd.fd = sd;
+
+ #if defined(__APPLE__)
+ pfd.events = POLLIN; // figure out if we _really_ need POLLRDHUP equivalent
+ #else
pfd.events = POLLIN | POLLRDHUP;
+ #endif
if (poll(&pfd, 1, timeout) <= 0)
return -1;
-
+ #if defined(__APPLE__)
+ if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL))
+ #else
if (pfd.revents & (POLLERR | POLLHUP | POLLRDHUP | POLLNVAL))
+ #endif
return -1;
if (!(pfd.revents & POLLIN))
@@ -90,7 +98,12 @@ int tcp_write(int sd, const char *buf, int len)
return -1;
struct pollfd pfd;
pfd.fd = sd;
+ #if defined(__APPLE__)
+ pfd.events = POLLOUT | POLLHUP | POLLNVAL | POLLERR;
+ #else
pfd.events = POLLOUT | POLLHUP | POLLRDHUP | POLLNVAL | POLLERR;
+ #endif
+
if (g_conf.ms_inject_socket_failures && sd >= 0) {
if (rand() % g_conf.ms_inject_socket_failures == 0) {
@@ -108,7 +121,11 @@ int tcp_write(int sd, const char *buf, int len)
//generic_dout(DBL) << "tcp_write writing " << len << dendl;
assert(len > 0);
while (len > 0) {
+ #if defined(__APPLE__)
+ int did = ::send( sd, buf, len, SO_NOSIGPIPE );
+ #else
int did = ::send( sd, buf, len, MSG_NOSIGNAL );
+ #endif
if (did < 0) {
//generic_dout(1) << "tcp_write error did = " << did << " errno " << errno << " " << strerror(errno) << dendl;
//generic_derr(1) << "tcp_write error did = " << did << " errno " << errno << " " << strerror(errno) << dendl;
@@ -25,7 +25,11 @@ typedef __u64 __le64;
#include <winsock.h>
#else
#include <netinet/in.h>
-#include <linux/types.h>
+#if defined(__APPLE__)
+ #include "include/mac-compat.h"
+#else
+ #include <linux/types.h>
+#endif
#endif
typedef int bool;