From patchwork Mon Feb 28 20:02:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannu Valtonen X-Patchwork-Id: 597241 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1SK31gv003924 for ; Mon, 28 Feb 2011 20:03:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754948Ab1B1UDA (ORCPT ); Mon, 28 Feb 2011 15:03:00 -0500 Received: from filtteri6.pp.htv.fi ([213.243.153.189]:35994 "EHLO filtteri6.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754535Ab1B1UC7 (ORCPT ); Mon, 28 Feb 2011 15:02:59 -0500 Received: from localhost (localhost [127.0.0.1]) by filtteri6.pp.htv.fi (Postfix) with ESMTP id 1A4B862A035 for ; Mon, 28 Feb 2011 22:02:58 +0200 (EET) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp5.welho.com ([213.243.153.39]) by localhost (filtteri6.pp.htv.fi [213.243.153.189]) (amavisd-new, port 10024) with ESMTP id Gg7a2JoDKot0 for ; Mon, 28 Feb 2011 22:02:56 +0200 (EET) Received: from FSAPPLE12-2.local (cs181254100.pp.htv.fi [82.181.254.100]) by smtp5.welho.com (Postfix) with ESMTP id B6DF45BC007 for ; Mon, 28 Feb 2011 22:02:56 +0200 (EET) Message-ID: <4D6BFF70.5000502@ormod.com> Date: Mon, 28 Feb 2011 22:02:56 +0200 From: Hannu Valtonen User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: A hacky try at supporting OS X (for archival purpose) Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 28 Feb 2011 20:03:01 +0000 (UTC) diff --git a/src/include/mac-compat.h b/src/include/mac-compat.h new file mode 100644 index 0000000..85fc773 --- /dev/null +++ b/src/include/mac-compat.h @@ -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; + diff --git a/autogen.sh b/autogen.sh index 0b28c8a..6b40c6d 100755 --- a/autogen.sh +++ b/autogen.sh @@ -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 diff --git a/src/auth/Crypto.h b/src/auth/Crypto.h index 782f3bb..25b6f06 100644 --- a/src/auth/Crypto.h +++ b/src/auth/Crypto.h @@ -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 diff --git a/src/client/ioctl.h b/src/client/ioctl.h index 52e8fd7..c341d03 100644 --- a/src/client/ioctl.h +++ b/src/client/ioctl.h @@ -2,7 +2,12 @@ #define FS_CEPH_IOCTL_H #include -#include + +#if defined(__APPLE__) + #include "include/mac-compat.h +#else + #include +#endif #define CEPH_IOCTL_MAGIC 0x97 diff --git a/src/common/MemoryModel.cc b/src/common/MemoryModel.cc index 34abc22..f0a0225 100644 --- a/src/common/MemoryModel.cc +++ b/src/common/MemoryModel.cc @@ -4,6 +4,10 @@ #include "config.h" #include "debug.h" +#if defined(__APPLE__) +#include +#endif + #include 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 + } diff --git a/src/common/armor.c b/src/common/armor.c index dce1fed..e069c17 100644 --- a/src/common/armor.c +++ b/src/common/armor.c @@ -1,5 +1,8 @@ - -#include +#if defined(__APPLE__) + #include +#else + #include +#endif /* * base64 encode/decode. diff --git a/src/common/sctp_crc32.c b/src/common/sctp_crc32.c index b10adf7..6c44f49 100644 --- a/src/common/sctp_crc32.c +++ b/src/common/sctp_crc32.c @@ -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 -#include - +#if defined(__APPLE__) + #include +#else + #include +#endif #ifndef SCTP_USE_ADLER32 diff --git a/src/crush/crush.h b/src/crush/crush.h index 97e435b..d904430 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -1,8 +1,11 @@ #ifndef CEPH_CRUSH_CRUSH_H #define CEPH_CRUSH_CRUSH_H -#include - +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif /* * CRUSH is a pseudo-random data distribution algorithm that * efficiently distributes input values (typically, data objects) diff --git a/src/crush/hash.c b/src/crush/hash.c index 5873aed..5b7dab2 100644 --- a/src/crush/hash.c +++ b/src/crush/hash.c @@ -1,5 +1,8 @@ - -#include +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #include "hash.h" /* diff --git a/src/crush/types.h b/src/crush/types.h index 61f50c2..c0945a0 100644 --- a/src/crush/types.h +++ b/src/crush/types.h @@ -7,8 +7,12 @@ # include #endif - -#include /* just for int types */ +/* just for int types */ +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #ifndef BUG_ON # define BUG_ON(x) assert(!(x)) diff --git a/src/include/Spinlock.h b/src/include/Spinlock.h index 690c87c..d077955 100644 --- a/src/include/Spinlock.h +++ b/src/include/Spinlock.h @@ -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); } diff --git a/src/include/assert.h b/src/include/assert.h index 98199b8..95c7adb 100644 --- a/src/include/assert.h +++ b/src/include/assert.h @@ -1,7 +1,9 @@ #ifndef CEPH_ASSERT_H #define CEPH_ASSERT_H +#if !defined(__APPLE__) #include +#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 -#else -# define __CEPH_ASSERT_VOID_CAST (void) -#endif +//#if defined __cplusplus && __GNUC_PREREQ (2,95) +//# define __CEPH_ASSERT_VOID_CAST static_cast +//#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); diff --git a/src/include/buffer.h b/src/include/buffer.h index 0905e11..ffb30bf 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -14,8 +14,11 @@ #ifndef CEPH_BUFFER_H #define CEPH_BUFFER_H - -#include +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #ifndef _XOPEN_SOURCE # define _XOPEN_SOURCE 600 @@ -35,8 +38,11 @@ void *valloc(size_t); #else - -#include +#if !defined(__APPLE__) + #include +#else + #include +#endif #endif #include #include diff --git a/src/include/byteorder.h b/src/include/byteorder.h index f49cb66..2cc5f83 100644 --- a/src/include/byteorder.h +++ b/src/include/byteorder.h @@ -6,8 +6,11 @@ #ifndef CEPH_BYTEORDER_H #define CEPH_BYTEORDER_H - -#include +#if defined(__APPLE__) + #include +#else + #include +#endif static __inline__ __u16 swab16(__u16 val) { diff --git a/src/include/inttypes.h b/src/include/inttypes.h index 50ebd4e..ed0216f 100644 --- a/src/include/inttypes.h +++ b/src/include/inttypes.h @@ -2,6 +2,9 @@ #define CEPH_INTTYPES_H #include -#include - +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #endif diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index f73afd9..2732c11 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -6,7 +6,12 @@ extern "C" { #endif #include -#include + +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include > +#endif #include #ifndef CEPH_OSD_TMAP_SET diff --git a/src/include/rbd_types.h b/src/include/rbd_types.h index 5b9c168..ff4d159 100644 --- a/src/include/rbd_types.h +++ b/src/include/rbd_types.h @@ -13,7 +13,18 @@ #ifndef CEPH_RBD_TYPES_H #define CEPH_RBD_TYPES_H -#include +#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 +#endif /* * rbd image 'foo' consists of objects diff --git a/src/mds/locks.c b/src/mds/locks.c index 8225eef..6277b98 100644 --- a/src/mds/locks.c +++ b/src/mds/locks.c @@ -5,7 +5,12 @@ typedef char bool; #define true 1 #include -#include + +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #include #include diff --git a/src/msg/SimpleMessenger.cc b/src/msg/SimpleMessenger.cc index fd44fac..995288d 100644 --- a/src/msg/SimpleMessenger.cc +++ b/src/msg/SimpleMessenger.cc @@ -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) { diff --git a/src/msg/SimpleMessenger.h b/src/msg/SimpleMessenger.h index 4cb1457..97085ae 100644 --- a/src/msg/SimpleMessenger.h +++ b/src/msg/SimpleMessenger.h @@ -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 diff --git a/src/msg/tcp.cc b/src/msg/tcp.cc index 71d85f1..e295fc8 100644 --- a/src/msg/tcp.cc +++ b/src/msg/tcp.cc @@ -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 @@ -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; diff --git a/wireshark/ceph/types.h b/wireshark/ceph/types.h index 1bcc48d..0105681 100644 --- a/wireshark/ceph/types.h +++ b/wireshark/ceph/types.h @@ -25,7 +25,11 @@ typedef __u64 __le64; #include #else #include -#include +#if defined(__APPLE__) + #include "include/mac-compat.h" +#else + #include +#endif #endif typedef int bool;