[sheepdog] [PATCH] sheep, collie: add a new subcommand of cluster "kill"
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Tue May 7 04:34:08 CEST 2013
From: Hitoshi Mitake <mitake.hitoshi at gmail.com>
Currently only one way to stop every sheep process joining a cluster
is cluster shutdown. But this doesn't work well when a state of the
cluster is not SD_STATUS_OK. This patch adds a new subcommand "kill"
to collie cluster. It is defined as a force operation, so even if the
cluster is not in a state of SD_STATUS_OK, the operation force to stop
the cluster.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
collie/cluster.c | 18 ++++++++++++++++++
include/internal_proto.h | 1 +
sheep/ops.c | 14 ++++++++++++++
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/collie/cluster.c b/collie/cluster.c
index 7cdbba0..faa2ed6 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -223,6 +223,22 @@ static int cluster_shutdown(int argc, char **argv)
return EXIT_SUCCESS;
}
+static int cluster_kill(int argc, char **argv)
+{
+ int ret;
+ struct sd_req hdr;
+
+ sd_init_req(&hdr, SD_OP_KILL);
+
+ ret = send_light_req(&hdr, sdhost, sdport);
+ if (ret) {
+ fprintf(stderr, "failed to execute request\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
static int restore_snap(uint32_t epoch)
{
int ret;
@@ -410,6 +426,8 @@ static struct subcommand cluster_cmd[] = {
NULL, 0, cluster_format, cluster_options},
{"shutdown", NULL, "aph", "stop Sheepdog",
NULL, 0, cluster_shutdown, cluster_options},
+ {"kill", NULL, "aph", "force to stop Sheepdog",
+ NULL, 0, cluster_kill, cluster_options},
{"snapshot", NULL, "aRlph", "snapshot/restore the cluster",
NULL, 0, cluster_snapshot, cluster_options},
{"recover", NULL, "afph",
diff --git a/include/internal_proto.h b/include/internal_proto.h
index f124b9e..6210f0f 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -72,6 +72,7 @@
#define SD_OP_MD_INFO 0xB1
#define SD_OP_MD_PLUG 0xB2
#define SD_OP_MD_UNPLUG 0xB3
+#define SD_OP_KILL 0xB4
/* internal flags for hdr.flags, must be above 0x80 */
#define SD_FLAG_CMD_RECOVERY 0x0080
diff --git a/sheep/ops.c b/sheep/ops.c
index 90f4b00..c278407 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -308,6 +308,13 @@ static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
return SD_RES_SUCCESS;
}
+static int cluster_kill(const struct sd_req *req, struct sd_rsp *rsp,
+ void *data)
+{
+ sys->status = SD_STATUS_SHUTDOWN;
+ return SD_RES_SUCCESS;
+}
+
static int cluster_enable_recover(const struct sd_req *req,
struct sd_rsp *rsp, void *data)
{
@@ -1038,6 +1045,13 @@ static struct sd_op_template sd_ops[] = {
.process_main = cluster_shutdown,
},
+ [SD_OP_KILL] = {
+ .name = "KILL",
+ .type = SD_OP_TYPE_CLUSTER,
+ .force = true,
+ .process_main = cluster_kill,
+ },
+
[SD_OP_GET_VDI_ATTR] = {
.name = "GET_VDI_ATTR",
.type = SD_OP_TYPE_CLUSTER,
--
1.7.2.5
More information about the sheepdog
mailing list