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

Hitoshi Mitake mitake.hitoshi at gmail.com
Sat Jan 11 15:44:28 CET 2014


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

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>
---

v2: renameing, zones_nr -> sd_zones_nr, occured_zones -> sd_zones

 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..c39086f 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 sd_zones_nr;
+ /* a number of zones never exceeds a number of nodes */
+static uint32_t sd_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 < sd_zones_nr; j++) {
+			if (sd_zones[j] == n->zone)
+				break;
+		}
+
+		if (j == sd_zones_nr)
+			sd_zones[sd_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..383df30 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 sd_zones_nr;
 
 bool is_current(const struct sd_inode *i);
 char *strnumber(uint64_t _size);
-- 
1.8.1.2



More information about the sheepdog mailing list