[sheepdog] [PATCH] collie: use bit functions to traverse vdi list
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Apr 29 02:38:34 CEST 2013
This increases performance of vdi traversing.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/cluster.c | 12 ++++++------
collie/common.c | 10 ++++++----
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/collie/cluster.c b/collie/cluster.c
index 0c5ac13..715d658 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -65,6 +65,11 @@ static int list_store(void)
return EXIT_SYSFAIL;
}
+static bool no_vdi(const unsigned long *vdis)
+{
+ return find_next_bit(vdis, SD_NR_VDIS, 0) == SD_NR_VDIS;
+}
+
#define FORMAT_PRINT \
" __\n" \
" ()'`;\n" \
@@ -80,7 +85,6 @@ static int cluster_format(int argc, char **argv)
struct timeval tv;
char store_name[STORE_LEN];
static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
- unsigned long nr;
sd_init_req((struct sd_req *)&hdr, SD_OP_READ_VDIS);
hdr.data_length = sizeof(vdi_inuse);
@@ -90,11 +94,7 @@ static int cluster_format(int argc, char **argv)
if (ret < 0)
return EXIT_SYSFAIL;
- for (nr = 0; nr < SD_NR_VDIS; nr++)
- if (test_bit(nr, vdi_inuse))
- break;
-
- if (nr != SD_NR_VDIS)
+ if (!no_vdi(vdi_inuse))
confirm(FORMAT_PRINT);
gettimeofday(&tv, NULL);
diff --git a/collie/common.c b/collie/common.c
index 0642ee0..ce40822 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -113,6 +113,11 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
return SD_RES_SUCCESS;
}
+#define FOR_EACH_VDI(nr, vdis) \
+ for (nr = find_next_bit((vdis), SD_NR_VDIS, 0); \
+ nr < SD_NR_VDIS; \
+ nr = find_next_bit((vdis), SD_NR_VDIS, nr + 1))
+
int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
{
int ret;
@@ -129,13 +134,10 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
if (ret < 0)
goto out;
- for (nr = 0; nr < SD_NR_VDIS; nr++) {
+ FOR_EACH_VDI(nr, vdi_inuse) {
uint64_t oid;
uint32_t snapid;
- if (!test_bit(nr, vdi_inuse))
- continue;
-
oid = vid_to_vdi_oid(nr);
memset(&i, 0, sizeof(i));
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list