From aa1355f971287932e2ba09dfb04a6122ecc3951f Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Fri, 10 Jun 2011 10:47:03 +0200 Subject: tools: merge several bitop functions into xc_bitops.h Bitmaps are used in save/restore, xenpaging and blktap2. Merge the code into a private xc_bitops.h file. All users are single threaded, so locking is not an issue. The array of bits is handled as volatile because the x86 save/restore code passes the bitmap to the hypervisor which in turn modifies the bitmap. blktap2 uses a private bitmap. There was a possible overflow in the bitmap_size() function, the remainder was not considered. ia64 save/restore uses a bitmap to send the number of vcpus to the host. x86 save/restore uses a bitmap to track dirty pages. This bitmap is shared with the hypervisor. An unused function count_bits() was removed and a new bitmap_size() function is now used. xenpaging uses 3 private bitmaps to track the gfns which are in paged-out state. It had a copy of some Linux bitops.h, which is now obsolete. Also the BITS_PER_LONG macro was hardcoded to 64 which made it impossible to run 32bit tools on a 64bit host. Wether this works at all has to be tested, yet. Signed-off-by: Olaf Hering Committed-by: Ian Jackson --- tools/blktap2/drivers/block-log.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'tools/blktap2') diff --git a/tools/blktap2/drivers/block-log.c b/tools/blktap2/drivers/block-log.c index c9612a4b9b..6a63729eca 100644 --- a/tools/blktap2/drivers/block-log.c +++ b/tools/blktap2/drivers/block-log.c @@ -47,6 +47,7 @@ #include #include +#include "xc_bitops.h" #include "log.h" #include "tapdisk.h" #include "tapdisk-server.h" @@ -89,31 +90,6 @@ static void ctl_request(event_id_t, char, void *); /* large flat bitmaps don't scale particularly well either in size or scan * time, but they'll do for now */ -#define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define BITS_TO_LONGS(bits) (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) - -#define BITMAP_ENTRY(_nr, _bmap) ((unsigned long*)(_bmap))[(_nr)/BITS_PER_LONG] -#define BITMAP_SHIFT(_nr) ((_nr) % BITS_PER_LONG) - -static inline int test_bit(int nr, void* bmap) -{ - return (BITMAP_ENTRY(nr, bmap) >> BITMAP_SHIFT(nr)) & 1; -} - -static inline void clear_bit(int nr, void* bmap) -{ - BITMAP_ENTRY(nr, bmap) &= ~(1UL << BITMAP_SHIFT(nr)); -} - -static inline void set_bit(int nr, void* bmap) -{ - BITMAP_ENTRY(nr, bmap) |= (1UL << BITMAP_SHIFT(nr)); -} - -static inline int bitmap_size(uint64_t sz) -{ - return sz >> 3; -} static int writelog_create(struct tdlog_state *s) { @@ -123,7 +99,8 @@ static int writelog_create(struct tdlog_state *s) BDPRINTF("allocating %"PRIu64" bytes for dirty bitmap", bmsize); - if (!(s->writelog = calloc(bmsize, 1))) { + s->writelog = bitmap_alloc(s->size); + if (!s->writelog) { BWPRINTF("could not allocate dirty bitmap of size %"PRIu64, bmsize); return -1; } -- cgit v1.2.3