[sheepdog] [PATCH 2/2] dog: check nr_copies before format cluster

Robin Dong robin.k.dong at gmail.com
Wed Dec 4 10:21:26 CET 2013


From: Robin Dong <sanbai at taobao.com>

If we use erasure-code for "4:2" and there are only 4 nodes in cluster, it will
format cluster successly but crash when writing data into vdi.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/cluster.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 05e98d2..da6091f 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -81,6 +81,12 @@ static int cluster_format(int argc, char **argv)
 	char store_name[STORE_LEN];
 	static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
 
+	if (cluster_cmd_data.copies > sd_nodes_nr) {
+		printf("Number of copies (%d) can't be larger than number of "
+		       "nodes (%d)\n", cluster_cmd_data.copies, sd_nodes_nr);
+		return EXIT_FAILURE;
+	}
+
 	sd_init_req(&hdr, SD_OP_READ_VDIS);
 	hdr.data_length = sizeof(vdi_inuse);
 
@@ -541,7 +547,7 @@ static struct subcommand cluster_cmd[] = {
 	{"info", NULL, "aprhs", "show cluster information",
 	 NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
 	{"format", NULL, "bcaph", "create a Sheepdog store",
-	 NULL, 0, cluster_format, cluster_options},
+	 NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
 	{"shutdown", NULL, "aph", "stop Sheepdog",
 	 NULL, 0, cluster_shutdown, cluster_options},
 	{"snapshot", "<tag|idx> <path>", "aph", "snapshot/restore the cluster",
-- 
1.7.12.4




More information about the sheepdog mailing list