[sheepdog] [PATCH] sheep: add a kill node operation
Liu Yuan
namei.unix at gmail.com
Fri Jul 20 05:24:27 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
This command is supposed to shut down the specified node correctly
usage:
$ collie node kill node_id
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
collie/node.c | 37 +++++++++++++++++++++++++++++++++++++
include/internal_proto.h | 1 +
sheep/ops.c | 14 ++++++++++++++
sheep/request.c | 1 +
4 files changed, 53 insertions(+)
diff --git a/collie/node.c b/collie/node.c
index a778605..e8e6cac 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -157,7 +157,44 @@ static int node_recovery(int argc, char **argv)
return EXIT_SUCCESS;
}
+static int node_kill(int argc, char **argv)
+{
+ char host[128];
+ int fd, node_id, ret;
+ unsigned wlen, rlen;
+ struct sd_node_req req;
+ struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
+
+ node_id = strtol(argv[optind++], NULL, 10);
+ if (node_id < 0 || node_id >= sd_nodes_nr) {
+ fprintf(stderr, "Invalid node id '%d'\n", node_id);
+ exit(EXIT_USAGE);
+ }
+
+ addr_to_str(host, sizeof(host), sd_nodes[node_id].nid.addr, 0);
+
+ fd = connect_to(host, sd_nodes[node_id].nid.port);
+ if (fd < 0)
+ return EXIT_FAILURE;
+
+ sd_init_req((struct sd_req *)&req, SD_OP_KILL);
+
+ wlen = 0;
+ rlen = 0;
+ ret = exec_req(fd, (struct sd_req *)&req, NULL, &wlen, &rlen);
+ close(fd);
+
+ if (ret || rsp->result != SD_RES_SUCCESS) {
+ fprintf(stderr, "Failed to execute request\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return EXIT_SUCCESS;
+}
+
static struct subcommand node_cmd[] = {
+ {"kill", "<node id>", "aprh", "kill node",
+ SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, node_kill},
{"list", NULL, "aprh", "list nodes",
SUBCMD_FLAG_NEED_NODELIST, node_list},
{"info", NULL, "aprh", "show information about each node",
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 584f41e..ff37b48 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -52,6 +52,7 @@
#define SD_OP_TRACE_CAT 0x96
#define SD_OP_STAT_RECOVERY 0x97
#define SD_OP_FLUSH_DEL_CACHE 0x98
+#define SD_OP_KILL 0x99
#define SD_OP_GET_OBJ_LIST 0xA1
#define SD_OP_GET_EPOCH 0xA2
#define SD_OP_CREATE_AND_WRITE_PEER 0xA3
diff --git a/sheep/ops.c b/sheep/ops.c
index 27dbdfa..b7346d1 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -548,6 +548,13 @@ static int local_trace_cat_ops(const struct sd_req *req, struct sd_rsp *rsp, voi
return SD_RES_SUCCESS;
}
+static int local_kill(const struct sd_req *req, struct sd_rsp *rsp, void *data)
+{
+ sys_stat_set(SD_STATUS_SHUTDOWN);
+
+ return SD_RES_SUCCESS;
+}
+
static int read_copy_from_replica(struct vnode_info *vnodes, uint32_t epoch,
uint64_t oid, char *buf)
{
@@ -921,6 +928,13 @@ static struct sd_op_template sd_ops[] = {
.process_main = local_trace_cat_ops,
},
+ [SD_OP_KILL] = {
+ .name = "KILL",
+ .type = SD_OP_TYPE_LOCAL,
+ .force = 1,
+ .process_main = local_kill,
+ },
+
/* gateway I/O operations */
[SD_OP_CREATE_AND_WRITE_OBJ] = {
.name = "CREATE_AND_WRITE_OBJ",
diff --git a/sheep/request.c b/sheep/request.c
index 35ac488..a61819b 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -77,6 +77,7 @@ static void gateway_op_done(struct work *work)
case SD_RES_NETWORK_ERROR:
case SD_RES_WAIT_FOR_JOIN:
case SD_RES_WAIT_FOR_FORMAT:
+ case SD_RES_SHUTDOWN:
dprintf("retrying failed I/O request "
"op %s result %d epoch %d, sys epoch %d\n",
op_name(req->op),
--
1.7.10.2
More information about the sheepdog
mailing list