[sheepdog] [PATCH] sheep, collie: make cluster shutdown a force operation

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue May 7 17:40:53 CEST 2013


This patch makes "collie cluster shutdown" a force operation. Even if
a cluster is not in state of SD_STATUS_OK, the cluster can be
shutdowned with -f option of collie like this:
$ collie cluster shutdown -f

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 collie/cluster.c |    7 +++++--
 sheep/ops.c      |   24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 7cdbba0..83b85ca 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -211,10 +211,13 @@ static int cluster_shutdown(int argc, char **argv)
 {
 	int ret;
 	struct sd_req hdr;
+	bool force = cluster_cmd_data.force;
 
 	sd_init_req(&hdr, SD_OP_SHUTDOWN);
+	hdr.data_length = sizeof(force);
+	hdr.flags |= SD_FLAG_CMD_WRITE;
 
-	ret = send_light_req(&hdr, sdhost, sdport);
+	ret = collie_exec_req(sdhost, sdport, &hdr, (void *)&force);
 	if (ret) {
 		fprintf(stderr, "failed to execute request\n");
 		return EXIT_FAILURE;
@@ -408,7 +411,7 @@ static struct subcommand cluster_cmd[] = {
 	 NULL, SUBCMD_FLAG_NEED_NODELIST, cluster_info, cluster_options},
 	{"format", NULL, "bcmaph", "create a Sheepdog store",
 	 NULL, 0, cluster_format, cluster_options},
-	{"shutdown", NULL, "aph", "stop Sheepdog",
+	{"shutdown", NULL, "aphf", "stop Sheepdog",
 	 NULL, 0, cluster_shutdown, cluster_options},
 	{"snapshot", NULL, "aRlph", "snapshot/restore the cluster",
 	 NULL, 0, cluster_snapshot, cluster_options},
diff --git a/sheep/ops.c b/sheep/ops.c
index 90f4b00..3218cd5 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -304,7 +304,30 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
 			    void *data)
 {
+	bool force = *(bool *)data;
+
+	if (!force && sys->status != SD_STATUS_OK) {
+		switch (sys->status) {
+		case SD_STATUS_WAIT_FOR_FORMAT:
+			return SD_RES_WAIT_FOR_FORMAT;
+		case SD_STATUS_WAIT_FOR_JOIN:
+			return SD_RES_WAIT_FOR_JOIN;
+		case SD_STATUS_SHUTDOWN:
+			return SD_RES_SHUTDOWN;
+		case SD_STATUS_HALT:
+			return SD_RES_HALT;
+		case SD_STATUS_KILLED:
+			return SD_RES_KILLED;
+		default:
+			sd_eprintf("unknown state of sheep: 0x%x", sys->status);
+			return SD_RES_UNKNOWN;
+		}
+	}
+
 	sys->status = SD_STATUS_SHUTDOWN;
+	if (force)
+		sd_iprintf("force to shutdown cluster");
+
 	return SD_RES_SUCCESS;
 }
 
@@ -1035,6 +1058,7 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_SHUTDOWN] = {
 		.name = "SHUTDOWN",
 		.type = SD_OP_TYPE_CLUSTER,
+		.force = true,
 		.process_main = cluster_shutdown,
 	},
 
-- 
1.7.5.1




More information about the sheepdog mailing list