From: Yunkai Zhang <[email protected]>

V4:
- this patch can't passed checkpatch.sh checking, but I don't
  think there are coding style problems, maybe it's checkpatch.sh's bug.

V3:
- change comand's output, so user can differ
  it with 'collie node recovery' command.
----------------------------------------- >8

Show the status of recovery to user:
 $ collie cluster recover info
 Status: disable
 Joining nodes in inner temporary list:
 --------------------------------------
 Id               Host:Port
  0               127.0.0.1:7002
  1               127.0.0.1:7003
  2               127.0.0.1:7004

Signed-off-by: Yunkai Zhang <[email protected]>
---
 collie/cluster.c         | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/internal_proto.h |  1 +
 sheep/ops.c              | 15 ++++++++++++
 3 files changed, 77 insertions(+)

diff --git a/collie/cluster.c b/collie/cluster.c
index 6043578..d94c89a 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -348,6 +348,65 @@ 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: %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("Joining nodes in inner temporary list:\n"
+              "--------------------------------------\n"
+              "Id               Host:Port\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 +473,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 af8d373..0df47a1 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_joining_nodes * sizeof(struct sd_node);
+       memcpy(data, joining_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

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to