[sheepdog] [PATCH 3/4] sheep: add set_bit_64() for uint64_t type
Robin Dong
robin.k.dong at gmail.com
Fri Dec 27 10:14:04 CET 2013
From: Robin Dong <sanbai at taobao.com>
When building sheepdog in 32bit machie, the gcc report:
object_cache.c: In function ‘calc_object_bmap’:
object_cache.c:146:3: warning: passing argument 2 of ‘set_bit’ from incompatible pointer type [enabled by default]
../include/bitops.h:133:20: note: expected ‘long unsigned int *’ but argument is of type ‘uint64_t *’
object_cache.c: In function ‘push_cache_object’:
object_cache.c:475:16: warning: comparison of distinct pointer types lacks a cast [enabled by default]
because 'long unsigned int' is different to 'uint64_t' in 32bit environment. So we
add a new function set_bit_64() for uint64_t argument.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
include/bitops.h | 6 ++++++
sheep/object_cache.c | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/bitops.h b/include/bitops.h
index 6063af5..86a8ac1 100644
--- a/include/bitops.h
+++ b/include/bitops.h
@@ -11,6 +11,7 @@
#define DECLARE_BITMAP(name, bits) \
unsigned long name[BITS_TO_LONGS(bits)]
#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
+#define BITS_PER_UINT64 (BITS_PER_BYTE * sizeof(uint64_t))
#define __ffs(x) (x ? __builtin_ffsl(x) - 1 : 0)
#define ffz(x) __ffs(~(x))
@@ -135,6 +136,11 @@ static inline void set_bit(int nr, unsigned long *addr)
addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
}
+static inline void set_bit_64(int nr, uint64_t *addr)
+{
+ addr[nr / BITS_PER_UINT64] |= 1ULL << (nr % BITS_PER_UINT64);
+}
+
static inline void atomic_set_bit(int nr, unsigned long *addr)
{
uatomic_or(addr + nr / BITS_PER_LONG, 1UL << (nr % BITS_PER_LONG));
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 6262c01..09d3950 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -143,7 +143,7 @@ static uint64_t calc_object_bmap(uint64_t oid, size_t len, off_t offset)
nr = end - start;
while (nr--)
- set_bit(start + nr, &bmap);
+ set_bit_64(start + nr, &bmap);
return bmap;
}
@@ -473,7 +473,7 @@ static int push_cache_object(uint32_t vid, uint64_t idx, uint64_t bmap,
oid, bsize, bmap, first_bit, last_bit);
offset = first_bit * bsize;
data_length = min((last_bit - first_bit + 1) * bsize,
- get_objsize(oid) - offset);
+ get_objsize(oid) - (size_t)offset);
buf = xvalloc(data_length);
ret = read_cache_object_noupdate(vid, idx, buf, data_length, offset);
--
1.7.12.4
More information about the sheepdog
mailing list