A hacky try at supporting OS X (for archival purpose)
Hi,
Spent a couple of hours on Sunday to try to get Ceph to work on OS X. (I'm mostly interested in the FUSE client but I thought I'd give it a whirl in general)
It still doesn't compile fully but this should get it to go a bit further. Current blocker is the fact that pthread_t is a pointer on OS X while the current code expects it to be unsigned long (like on Linux)
Many of the changes in this patch aren't directly suitable for going into the main tree without polishing but I'm sending this as is for archival purposes. (or in case somebody else wants to follow the same idea)
I may eventually get back to hacking this if I find some time and nobody's beat me to it.. *nudge*
Some notes I made during hacking
--clip--
./msg/SimpleMessenger.h: In member function 'void SimpleMessenger::DispatchQueue::local_delivery(Message*, int)':./msg/SimpleMessenger.h:139: error: 'Connection* SimpleMessenger::Pipe::connection_state' is protected ./msg/SimpleMessenger.h:372: error: within this context
make[2]: *** [MonClient.o] Error 1
make[1]: *** [all-recursive] Error 1
Made the connection_state variable public.
--------------osd/osd_types.h: In member function 'bool pg_t::parse(const char*)':osd/osd_types.h:163: warning: passing negative value '-0x00000000000000001' for argument 1 to 'ceph_le16& ceph_le16::operator=(__u16)' config.cc: At global scope:
config.cc:59: warning: passing negative value '-0x00000000000000001' for argument 1 to '__u32 swab32(__u32)' config.cc:60: warning: passing negative value '-0x00000000000000001' for argument 1 to '__u32 swab32(__u32)'
mv -f .deps/config.Tpo .deps/config.Po
Didn't touch them but looked weird
--
g++ -DHAVE_CONFIG_H -I. -I/opt/local/include/ -Wall -D__CEPH__ -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic -g -O2 -MT lockdep.o -MD -MP -MF .deps/lockdep.Tpo -c -o lockdep.o test -f 'common/lockdep.cc' || echo './'common/lockdep.cc/usr/include/c++/4.0.0/ext/hashtable.h: In member function 'size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num_key(const _Key&, size_t) const [with _Val = std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >, _Key = _opaque_pthread_t*, _HashFcn = __gnu_cxx::hash<_opaque_pthread_t*>, _ExtractKey = std::_Select1st<std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > > >, _EqualKey = std::equal_to<_opaque_pthread_t*>, _Alloc = std::allocator<std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >]':
/usr/include/c++/4.0.0/ext/hashtable.h:588: instantiated from 'size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num_key(const _Key&) const [with _Val = std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >, _Key = _opaque_pthread_t*, _HashFcn = __gnu_cxx::hash<_opaque_pthread_t*>, _ExtractKey = std::_Select1st<std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > > >, _EqualKey = std::equal_to<_opaque_pthread_t*>, _Alloc = std::allocator<std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >]' /usr/include/c++/4.0.0/ext/hashtable.h:592: instantiated from 'size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num(const _Val&) const [with _Val = std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >, _Key = _opaque_pthread_t*, _HashFcn = __gnu_cxx::hash<_opaque_pthread_t*>, _ExtractKey = std::_Select1st<std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > > >, _EqualKey = std::equal_to<_opaque_pthread_t*>, _Alloc = std::allocator<std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >]' /usr/include/c++/4.0.0/ext/hashtable.h:646: instantiated from '__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>& __gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::operator++() [with _Val = std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >, _Key = _opaque_pthread_t*, _HashFcn = __gnu_cxx::hash<_opaque_pthread_t*>, _ExtractKey = std::_Select1st<std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > > >, _EqualKey = std::equal_to<_opaque_pthread_t*>, _Alloc = std::allocator<std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >]' /usr/include/c++/4.0.0/ext/hashtable.h:660: instantiated from '__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc> __gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::operator++(int) [with _Val = std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >, _Key = _opaque_pthread_t*, _HashFcn = __gnu_cxx::hash<_opaque_pthread_t*>, _ExtractKey = std::_Select1st<std::pair<_opaque_pthread_t* const, std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > > >, _EqualKey = std::equal_to<_opaque_pthread_t*>, _Alloc = std::allocator<std::map<int, ceph::BackTrace*, std::less<int>, std::allocator<std::pair<const int, ceph::BackTrace*> > > >]'
common/lockdep.cc:50: instantiated from here/usr/include/c++/4.0.0/ext/hashtable.h:596: error: no match for call to '(const __gnu_cxx::hash<_opaque_pthread_t*>) (_opaque_pthread_t* const&)' make[2]: *** [lockdep.o] Error 1
make[1]: *** [all-recursive] Error 1
Probably related to pthread_t being a pointer on os x
---------rbd_types.h if I use include/mac-compat.h __le32 etc designations will blow up.
src/include/mac-compat.h new file +21 -0
@@ -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 ; +
autogen.sh +2 -1
@@ -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
src/auth/Crypto.h +7 -0
@@ -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
src/client/ioctl.h +6 -1
@@ -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
src/common/MemoryModel.cc +11 -2
@@ -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 + }
src/common/armor.c +5 -2
@@ -1,5 +1,8 @@ - -#include <linux/errno.h> +#if defined(__APPLE__) +#include <sys/errno.h> +#else +#include <linux/errno.h> +#endif /* * base64 encode/decode.
src/common/sctp_crc32.c +5 -2
@@ -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
src/crush/crush.h +5 -2
@@ -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)
src/crush/hash.c +5 -2
@@ -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" /*
src/crush/types.h +6 -2
@@ -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))
src/include/Spinlock.h +9 -6
@@ -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 ); }
src/include/assert.h +11 -7
@@ -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);
src/include/buffer.h +10 -4
@@ -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>
src/include/byteorder.h +5 -2
@@ -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) {
src/include/inttypes.h +5 -2
@@ -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
src/include/rados/librados.h +6 -1
@@ -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
src/include/rbd_types.h +12 -1
@@ -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
src/mds/locks.c +6 -1
@@ -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>
src/msg/SimpleMessenger.cc +5 -2
@@ -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) {
src/msg/SimpleMessenger.h +1 -1
@@ -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
src/msg/tcp.cc +21 -4
@@ -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;
wireshark/ceph/types.h +5 -1
@@ -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 ;