[sheepdog] [PATCH stable-0.7 2/3] dog: caliculate a number of zones
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Mon Jan 27 09:51:11 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>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
Conflicts:
dog/dog.c
dog/dog.h
Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
dog/dog.c | 17 +++++++++++++++++
dog/dog.h | 1 +
2 files changed, 18 insertions(+)
diff --git a/dog/dog.c b/dog/dog.c
index 1efcdfb..88b7436 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -52,6 +52,10 @@ struct sd_node sd_nodes[SD_MAX_NODES];
struct sd_vnode sd_vnodes[SD_MAX_VNODES];
int sd_nodes_nr, sd_vnodes_nr;
+/* a number of zones never exceeds a number of nodes */
+static uint32_t sd_zones[SD_MAX_NODES];
+int sd_zones_nr;
+
int update_node_list(int max_nodes)
{
int ret;
@@ -94,6 +98,19 @@ int update_node_list(int max_nodes)
memcpy(sd_nodes, buf, size);
sd_vnodes_nr = nodes_to_vnodes(sd_nodes, sd_nodes_nr, sd_vnodes);
sd_epoch = hdr.epoch;
+
+ for (int i = 0; i < sd_nodes_nr; i++) {
+ int j;
+
+ for (j = 0; j < i; j++) {
+ if (sd_zones[j] == sd_nodes[i].zone)
+ break;
+ }
+
+ if (j == i)
+ sd_zones[sd_zones_nr++] = sd_nodes[i].zone;
+ }
+
out:
if (buf)
free(buf);
diff --git a/dog/dog.h b/dog/dog.h
index d115e13..1bbbcf4 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -64,6 +64,7 @@ extern uint32_t sd_epoch;
extern struct sd_node sd_nodes[SD_MAX_NODES];
extern struct sd_vnode sd_vnodes[SD_MAX_VNODES];
extern int sd_nodes_nr, sd_vnodes_nr;
+extern int sd_zones_nr;
bool is_current(const struct sd_inode *i);
char *size_to_str(uint64_t _size, char *str, int str_size);
--
1.7.10.4
More information about the sheepdog
mailing list