From: Yunkai Zhang <qiushu.zyk at taobao.com> Show the status of recovery to user: $ collie cluster recover info Status: disable ------------------------------------- Id Joining nodes in recovery list 0 127.0.0.1:7002 1 127.0.0.1:7003 2 127.0.0.1:7004 Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com> --- collie/cluster.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ include/internal_proto.h | 1 + sheep/ops.c | 15 ++++++++++++ 3 files changed, 78 insertions(+) diff --git a/collie/cluster.c b/collie/cluster.c index 9e18a37..0cbd15b 100644 --- a/collie/cluster.c +++ b/collie/cluster.c @@ -348,6 +348,66 @@ The cluster may need to be force recovered if:\n\ - some nodes fail to start after a cluster shutdown.\n\n\ Are you sure you want to continue? [yes/no]: " +static int cluster_info_recover(int argc, char **argv) +{ + int fd, ret = EXIT_SYSFAIL; + struct sd_req hdr; + struct sd_rsp *rsp = (struct sd_rsp *)&hdr; + unsigned rlen, wlen; + void *buf; + int i, nr_nodes; + const char *status[] = {"enable", "disable"}; + + wlen = 0; + rlen = SD_MAX_NODES * sizeof(struct sd_node); + + buf = malloc(rlen); + if (!buf) + return EXIT_SYSFAIL; + + fd = connect_to(sdhost, sdport); + if (fd < 0) + goto out; + + sd_init_req(&hdr, SD_OP_INFO_RECOVER); + hdr.data_length = rlen; + + ret = exec_req(fd, &hdr, buf, &wlen, &rlen); + close(fd); + + if (ret) { + fprintf(stderr, "Failed to connect\n"); + goto out; + } + + if (rsp->result != SD_RES_SUCCESS) { + fprintf(stderr, "failed to get delay_recovery info: %s\n", + sd_strerror(rsp->result)); + ret = EXIT_FAILURE; + goto out; + } + nr_nodes = rsp->data_length/sizeof(struct sd_node); + + printf("Status: %s\n", status[rsp->__pad[0]]); + printf("-------------------------------------\n"); + printf("Id Joining nodes in recovery list\n"); + + for (i = 0; i < nr_nodes; i++) { + char ipaddr[128]; + struct sd_node *rnodes; + + rnodes = (struct sd_node *)buf; + addr_to_str(ipaddr, sizeof(ipaddr), rnodes[i].nid.addr, + rnodes[i].nid.port); + printf("%2d %s\n", i, ipaddr); + } + + +out: + free(buf); + return EXIT_SUCCESS; +} + static int cluster_force_recover(int argc, char **argv) { int ret; @@ -414,6 +474,8 @@ static int cluster_enable_recover(int argc, char **argv) /* Subcommand list of recover */ static struct subcommand cluster_recover_cmd[] = { + {"info", NULL, NULL, "show the status of recovery to user", + NULL, 0, cluster_info_recover}, {"force", NULL, NULL, "force recover cluster immediately", NULL, 0, cluster_force_recover}, {"enable", NULL, NULL, "enable automatic recovery and " diff --git a/include/internal_proto.h b/include/internal_proto.h index 9819b08..4f1b0a0 100644 --- a/include/internal_proto.h +++ b/include/internal_proto.h @@ -63,6 +63,7 @@ #define SD_OP_SET_CACHE_SIZE 0xA7 #define SD_OP_ENABLE_RECOVER 0xA8 #define SD_OP_DISABLE_RECOVER 0xA9 +#define SD_OP_INFO_RECOVER 0xAA /* 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 ef77765..0a3d9b2 100644 --- a/sheep/ops.c +++ b/sheep/ops.c @@ -303,6 +303,16 @@ static int cluster_disable_recover(const struct sd_req *req, return SD_RES_SUCCESS; } +static int local_info_recover(const struct sd_req *req, + struct sd_rsp *rsp, void *data) +{ + rsp->__pad[0] = sys->disable_recovery; + rsp->data_length = nr_recovery_nodes * sizeof(struct sd_node); + memcpy(data, recovery_nodes, rsp->data_length); + + return SD_RES_SUCCESS; +} + static int cluster_get_vdi_attr(struct request *req) { const struct sd_req *hdr = &req->rq; @@ -1074,6 +1084,11 @@ static struct sd_op_template sd_ops[] = { .type = SD_OP_TYPE_CLUSTER, .process_main = cluster_disable_recover, }, + [SD_OP_INFO_RECOVER] = { + .name = "INFO_RECOVER", + .type = SD_OP_TYPE_LOCAL, + .process_main = local_info_recover, + }, }; struct sd_op_template *get_sd_op(uint8_t opcode) -- 1.7.11.2 |