[sheepdog] [PATCH v3 1/9] sheep: some macro preparation for sbd kernem modual

Liu Yuan namei.unix at gmail.com
Mon May 26 07:18:34 CEST 2014


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 include/sheepdog_proto.h | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 9361bad..29007b0 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -11,15 +11,20 @@
 #ifndef __SHEEPDOG_PROTO_H__
 #define __SHEEPDOG_PROTO_H__
 
-#include <inttypes.h>
-#include <stdint.h>
+#ifdef __KERNEL__
+# define UINT64_MAX (18446744073709551615ULL)
+# define UINT64_C(x) ((x) + (UINT64_MAX - UINT64_MAX))
+#else
+# include <inttypes.h>
+# include <stdint.h>
+# include <string.h>
+# include "compiler.h"
+# include "bitops.h"
+#endif
+
 #include <stdbool.h>
-#include <string.h>
 #include <linux/limits.h>
 
-#include "compiler.h"
-#include "bitops.h"
-
 #define SD_PROTO_VER 0x02
 
 /* This or later version supports trimming zero sectors from read response */
@@ -297,8 +302,9 @@ void sd_inode_index_walk(const struct sd_inode *inode, index_cb_fn, void *);
 static inline uint64_t fnv_64a_buf(const void *buf, size_t len, uint64_t hval)
 {
 	const unsigned char *p = (const unsigned char *) buf;
+	int i;
 
-	for (int i = 0; i < len; i++) {
+	for (i = 0; i < len; i++) {
 		hval ^= (uint64_t) p[i];
 		hval *= FNV_64_PRIME;
 	}
@@ -371,10 +377,12 @@ static inline uint32_t sd_hash_vdi(const char *name)
 	return (uint32_t)(hval & (SD_NR_VDIS - 1));
 }
 
+#ifndef __KERNEL__
 static inline uint64_t hash_64(uint64_t val, unsigned int bits)
 {
 	return sd_hash_64(val) >> (64 - bits);
 }
+#endif
 
 static inline bool is_vdi_obj(uint64_t oid)
 {
-- 
1.8.1.2




More information about the sheepdog mailing list