[sheepdog] [PATCH v4 2/3] modify implemention of functions to build sheepdog on rhel5 environment

Robin Dong robin.k.dong at gmail.com
Thu Aug 22 05:19:02 CEST 2013


From: Robin Dong <sanbai at taobao.com>

For using timerfd, eventfd, signalfd, it need to use syscall() instead of glibc's
standard fucntions on rhel5.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 include/compiler.h        |   85 +++++++++++++++++++++++++++++++++++++++++++++
 include/util.h            |    1 -
 lib/event.c               |    1 -
 lib/util.c                |    3 --
 lib/work.c                |    1 -
 sheep/cluster/local.c     |    1 -
 sheep/cluster/shepherd.c  |    1 -
 sheep/cluster/zookeeper.c |    1 -
 sheep/sheep.c             |    1 -
 shepherd/shepherd.c       |    1 -
 10 files changed, 85 insertions(+), 11 deletions(-)

diff --git a/include/compiler.h b/include/compiler.h
index 58ea3ca..f495819 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -12,6 +12,13 @@
 #ifndef SD_COMPILER_H
 #define SD_COMPILER_H
 
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <time.h>
+#include <signal.h>
+
+#include "config.h"
+
 #define likely(x)       __builtin_expect(!!(x), 1)
 #define unlikely(x)     __builtin_expect(!!(x), 0)
 
@@ -22,4 +29,82 @@
 /* Force a compilation error if the condition is true */
 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int: -!!(condition); }))
 
+#ifdef HAVE_SYS_SIGNALFD_H
+#include <sys/signalfd.h>
+#else
+#define SFD_NONBLOCK	(04000)
+struct signalfd_siginfo {
+	uint32_t ssi_signo;
+	int32_t ssi_errno;
+	int32_t ssi_code;
+	uint32_t ssi_pid;
+	uint32_t ssi_uid;
+	int32_t ssi_fd;
+	uint32_t ssi_tid;
+	uint32_t ssi_band;
+	uint32_t ssi_overrun;
+	uint32_t ssi_trapno;
+	int32_t ssi_status;
+	int32_t ssi_int;
+	uint64_t ssi_ptr;
+	uint64_t ssi_utime;
+	uint64_t ssi_stime;
+	uint64_t ssi_addr;
+	uint16_t ssi_addr_lsb;
+	uint8_t __pad[46];
+};
+
+static inline int signalfd(int __fd, const sigset_t *__mask, int __flags)
+{
+	return syscall(__NR_signalfd4, __fd, __mask, _NSIG / 8, __flags);
+}
+#endif
+
+#ifdef HAVE_SYS_EVENTFD_H
+#include <sys/eventfd.h>
+#else
+#define EFD_SEMAPHORE	(1)
+#define EFD_NONBLOCK	(04000)
+#define eventfd_t	uint64_t
+static inline int eventfd_write(int fd, eventfd_t value)
+{
+	return write(fd, &value, sizeof(eventfd_t)) !=
+			sizeof(eventfd_t) ? -1 : 0;
+}
+
+static inline int eventfd_read(int fd, eventfd_t *value)
+{
+	return read(fd, value, sizeof(eventfd_t)) !=
+			sizeof(eventfd_t) ? -1 : 0;
+}
+
+static inline int eventfd(unsigned int initval, int flags)
+{
+	return syscall(__NR_eventfd2, initval, flags);
+}
+#endif
+
+#ifdef HAVE_SYS_TIMERFD_H
+#include <sys/timerfd.h>
+#else
+#define TFD_NONBLOCK (04000)
+static inline int timerfd_create(clockid_t __clock_id, int __flags)
+{
+	return syscall(__NR_timerfd_create, __clock_id, __flags);
+}
+
+static inline int timerfd_settime(int __ufd, int __flags,
+		__const struct itimerspec *__utmr, struct itimerspec *__otmr)
+{
+	return syscall(__NR_timerfd_settime, __ufd, __flags, __utmr, __otmr);
+}
+#endif
+
+#ifndef HAVE_FALLOCATE
+static inline int fallocate(int fd, int mode, __off_t offset, __off_t len)
+{
+	return syscall(__NR_fallocate, fd, mode, offset, len);
+}
+#endif
+
 #endif	/* SD_COMPILER_H */
diff --git a/include/util.h b/include/util.h
index 9e6b959..b04f758 100644
--- a/include/util.h
+++ b/include/util.h
@@ -10,7 +10,6 @@
 #include <unistd.h>
 #include <search.h>
 #include <urcu/uatomic.h>
-#include <sys/eventfd.h>
 #include <pthread.h>
 #include <errno.h>
 
diff --git a/lib/event.c b/lib/event.c
index 2143c5e..55f94a2 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -14,7 +14,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/epoll.h>
-#include <sys/timerfd.h>
 
 #include "list.h"
 #include "util.h"
diff --git a/lib/util.c b/lib/util.c
index 5c57449..346b6bd 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -12,14 +12,11 @@
 #include <unistd.h>
 #include <errno.h>
 #include <stdlib.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <ctype.h>
-#include <signal.h>
 #include <sys/xattr.h>
 #include <fcntl.h>
 
diff --git a/lib/work.c b/lib/work.c
index bf9252e..6933e1a 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -23,7 +23,6 @@
 #include <stdlib.h>
 #include <syscall.h>
 #include <sys/types.h>
-#include <sys/eventfd.h>
 #include <sys/time.h>
 #include <linux/types.h>
 #include <signal.h>
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index b4adf87..de3dfb1 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -13,7 +13,6 @@
 #include <unistd.h>
 #include <sys/epoll.h>
 #include <sys/mman.h>
-#include <sys/signalfd.h>
 #include <sys/file.h>
 #include <signal.h>
 #include <fcntl.h>
diff --git a/sheep/cluster/shepherd.c b/sheep/cluster/shepherd.c
index f61f659..9453ff8 100644
--- a/sheep/cluster/shepherd.c
+++ b/sheep/cluster/shepherd.c
@@ -19,7 +19,6 @@
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/epoll.h>
-#include <sys/eventfd.h>
 
 #include "cluster.h"
 #include "event.h"
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 475d0f6..02149ec 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -14,7 +14,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/epoll.h>
-#include <sys/eventfd.h>
 #include <zookeeper/zookeeper.h>
 #include <pthread.h>
 
diff --git a/sheep/sheep.c b/sheep/sheep.c
index dacedff..47eb131 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -9,7 +9,6 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <sys/signalfd.h>
 #include <sys/resource.h>
 #include <malloc.h>
 
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index 4ad4944..33670d5 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -21,7 +21,6 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/epoll.h>
-#include <sys/eventfd.h>
 
 #include <sys/un.h>
 #include <netinet/in.h>
-- 
1.7.3.2




More information about the sheepdog mailing list