[sheepdog] [PATCH 3/4] dog: caliculate a number of zones

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Fri Jan 10 07:20:44 CET 2014


New "dog vdi check" requires a number of zones. This patch lets dog
caliculate a number of zones when a subcommand has a flag
CMD_NEED_NODELIST.

Reported-by: Marcin Mirosław <marcin at mejor.pl>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 dog/dog.c |   13 +++++++++++++
 dog/dog.h |    1 +
 2 files changed, 14 insertions(+)

diff --git a/dog/dog.c b/dog/dog.c
index 8e3c4d4..54360b5 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -53,6 +53,9 @@ uint32_t sd_epoch;
 int sd_nodes_nr;
 struct rb_root sd_vroot = RB_ROOT;
 struct rb_root sd_nroot = RB_ROOT;
+int zones_nr;
+ /* a number of zones never exceeds a number of nodes */
+static uint32_t occured_zones[SD_MAX_NODES];
 
 int update_node_list(int max_nodes)
 {
@@ -95,11 +98,21 @@ int update_node_list(int max_nodes)
 
 	for (int i = 0; i < sd_nodes_nr; i++) {
 		struct sd_node *n = xmalloc(sizeof(*n));
+		int j;
 
 		*n = buf[i];
 		rb_insert(&sd_nroot, n, rb, node_cmp);
+
+		for (j = 0; j < zones_nr; j++) {
+			if (occured_zones[j] == n->zone)
+				break;
+		}
+
+		if (j == zones_nr)
+			occured_zones[zones_nr++] = n->zone;
 	}
 
+
 	nodes_to_vnodes(&sd_nroot, &sd_vroot);
 	sd_epoch = hdr.epoch;
 out:
diff --git a/dog/dog.h b/dog/dog.h
index 12dfc52..368350f 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -63,6 +63,7 @@ extern uint32_t sd_epoch;
 extern struct rb_root sd_vroot;
 extern struct rb_root sd_nroot;
 extern int sd_nodes_nr;
+extern int zones_nr;
 
 bool is_current(const struct sd_inode *i);
 char *strnumber(uint64_t _size);
-- 
1.7.10.4




More information about the sheepdog mailing list