]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add crush_compat.h
authorIlya Dryomov <idryomov@gmail.com>
Thu, 11 Jun 2015 13:03:01 +0000 (16:03 +0300)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 15 Jun 2015 15:13:40 +0000 (18:13 +0300)
Move all the cruft that is necessary to compile shared files both in
kernel and userspace into a new crush_compat.h.  Also add a stub for
div64_s64() and limits for linux fixed width types.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/crush/Makefile.am
src/crush/crush.c
src/crush/crush.h
src/crush/crush_compat.h [new file with mode: 0644]
src/crush/crush_ln_table.h
src/crush/hash.c
src/crush/hash.h
src/crush/mapper.c

index 616a00a93de262058350fef40f8f4a0932be354c..5da6f17f280ec59ecd4b085dd3f217c24d09d51d 100644 (file)
@@ -16,9 +16,10 @@ noinst_HEADERS += \
        crush/CrushWrapper.i \
        crush/builder.h \
        crush/crush.h \
+       crush/crush_compat.h \
+       crush/crush_ln_table.h \
        crush/grammar.h \
        crush/hash.h \
-       crush/crush_ln_table.h \
        crush/mapper.h \
        crush/sample.txt \
        crush/types.h
index c400a410b0d892af44ec60e767dd8f3ac411bfa2..f3f7f6d4a15d191cd6ae9bd78c1c7957c78e0b5c 100644 (file)
@@ -1,16 +1,11 @@
-
 #ifdef __KERNEL__
 # include <linux/slab.h>
+# include <linux/crush/crush.h>
 #else
-# include <stdlib.h>
-# include <assert.h>
-# define kfree(x) do { if (x) free(x); } while (0)
-# define BUG_ON(x) assert(!(x))
-# include "include/int_types.h"
+# include "crush_compat.h"
+# include "crush.h"
 #endif
 
-#include "crush.h"
-
 const char *crush_bucket_alg_name(int alg)
 {
        switch (alg) {
index 3eac8f8b998295319c3efa99d056e809e7cec51b..9c9a13492070137c386635b67903de58b04d27d5 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef CEPH_CRUSH_CRUSH_H
 #define CEPH_CRUSH_CRUSH_H
 
-#include "include/int_types.h"
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else
+# include "crush_compat.h"
+#endif
 
 /*
  * CRUSH is a pseudo-random data distribution algorithm that
diff --git a/src/crush/crush_compat.h b/src/crush/crush_compat.h
new file mode 100644 (file)
index 0000000..08eb4ea
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef CEPH_CRUSH_COMPAT_H
+#define CEPH_CRUSH_COMPAT_H
+
+#include "include/int_types.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* asm-generic/bug.h */
+
+#define BUG_ON(x) assert(!(x))
+
+/* linux/kernel.h */
+
+#define U8_MAX         ((__u8)~0U)
+#define S8_MAX         ((__s8)(U8_MAX>>1))
+#define S8_MIN         ((__s8)(-S8_MAX - 1))
+#define U16_MAX                ((__u16)~0U)
+#define S16_MAX                ((__s16)(U16_MAX>>1))
+#define S16_MIN                ((__s16)(-S16_MAX - 1))
+#define U32_MAX                ((__u32)~0U)
+#define S32_MAX                ((__s32)(U32_MAX>>1))
+#define S32_MIN                ((__s32)(-S32_MAX - 1))
+#define U64_MAX                ((__u64)~0ULL)
+#define S64_MAX                ((__s64)(U64_MAX>>1))
+#define S64_MIN                ((__s64)(-S64_MAX - 1))
+
+/* linux/math64.h */
+
+#define div64_s64(dividend, divisor) ((dividend) / (divisor))
+
+/* linux/slab.h */
+
+#define kmalloc(size, flags) malloc(size)
+#define kfree(x) do { if (x) free(x); } while (0)
+
+#endif /* CEPH_CRUSH_COMPAT_H */
index e643b49446fcdb12bf20ea1100c94e156827d26e..aae534c901a43169d73a8dc8c043dab47cc69941 100644 (file)
  *
  */
 
-#include "include/int_types.h"
-
-#if defined(__linux__)
-#include <linux/types.h>
-#elif defined(__FreeBSD__)
-#include <sys/types.h>
-#endif
-
 #ifndef CEPH_CRUSH_LN_H
 #define CEPH_CRUSH_LN_H
 
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else
+# include "crush_compat.h"
+#endif
 
 /*
  * RH_LH_tbl[2*k] = 2^48/(1.0+k/128.0)
index 9b15321d783900b1ee138102318068cbac48f68f..ed123af49eba563a004d5b69e8b08c648480cb59 100644 (file)
@@ -1,13 +1,9 @@
-#include "include/int_types.h"
-
-#if defined(__linux__)
-#include <linux/types.h>
-#elif defined(__FreeBSD__)
-#include <sys/types.h>
+#ifdef __KERNEL__
+# include <linux/crush/hash.h>
+#else
+# include "hash.h"
 #endif
 
-#include "hash.h"
-
 /*
  * Robert Jenkins' function for mixing 32-bit values
  * http://burtleburtle.net/bob/hash/evahash.html
index 91e884230d5db99cbfacc478bf8acbe2d4533908..d1d90258242eef2965eb3e1e1e399132e85c8c34 100644 (file)
@@ -1,6 +1,12 @@
 #ifndef CEPH_CRUSH_HASH_H
 #define CEPH_CRUSH_HASH_H
 
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else
+# include "crush_compat.h"
+#endif
+
 #define CRUSH_HASH_RJENKINS1   0
 
 #define CRUSH_HASH_DEFAULT CRUSH_HASH_RJENKINS1
index 7ab18d82c96d6782ca3a63e702ddec1a0ffc8f82..82956586fa394edce61b475bf766ce9f5a2bf9ab 100644 (file)
 # include <linux/slab.h>
 # include <linux/bug.h>
 # include <linux/kernel.h>
-# ifndef dprintk
-#  define dprintk(args...)
-# endif
+# include <linux/crush/crush.h>
+# include <linux/crush/hash.h>
 #else
-# include <string.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <assert.h>
-# define BUG_ON(x) assert(!(x))
-# define dprintk(args...) /* printf(args) */
-# define kmalloc(x, f) malloc(x)
-# define kfree(x) free(x)
-/*# define DEBUG_INDEP*/
-# include "include/int_types.h"
+# include "crush_compat.h"
+# include "crush.h"
+# include "hash.h"
 #endif
-
-#include "crush.h"
-#include "hash.h"
 #include "crush_ln_table.h"
 
+#define dprintk(args...) /* printf(args) */
+
 /*
  * Implement the core CRUSH mapping algorithm.
  */