From: levin li <[email protected]>

Signed-off-by: levin li <[email protected]>
---
 collie/node.c            |   45 +++++++++++++++++++++++++++++++++++++++++++++
 include/internal_proto.h |    1 +
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/collie/node.c b/collie/node.c
index df841a0..0192dba 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -139,6 +139,49 @@ static int node_recovery(int argc, char **argv)
        return EXIT_SUCCESS;
 }
 
+static int node_cache(int argc, char **argv)
+{
+       char *p;
+       int fd, ret, cache_size;
+       unsigned int wlen, rlen = 0;
+       struct sd_req hdr;
+       struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
+
+       cache_size = strtol(argv[optind], &p, 10);
+       if (argv[optind] == p || cache_size < 0) {
+               fprintf(stderr, "Invalid cache size %s\n", argv[optind]);
+               return EXIT_FAILURE;
+       }
+
+       fd = connect_to(sdhost, sdport);
+       if (fd < 0)
+               return EXIT_FAILURE;
+
+       wlen = sizeof(cache_size);
+
+       sd_init_req(&hdr, SD_OP_SET_CACHE_SIZE);
+       hdr.flags = SD_FLAG_CMD_WRITE;
+       hdr.data_length = wlen;
+
+       ret = exec_req(fd, &hdr, (void *)&cache_size, &wlen, &rlen);
+       close(fd);
+
+       if (ret) {
+               fprintf(stderr, "Failed to connect\n");
+               return EXIT_FAILURE;
+       }
+
+       if (rsp->result != SD_RES_SUCCESS) {
+               fprintf(stderr, "specify max cache size failed: %s\n",
+                               sd_strerror(rsp->result));
+               return EXIT_FAILURE;
+       }
+
+       printf("Max cache size set to %dM\n", cache_size);
+
+       return EXIT_SUCCESS;
+}
+
 static int node_kill(int argc, char **argv)
 {
        char host[128];
@@ -174,6 +217,8 @@ static struct subcommand node_cmd[] = {
         SUBCMD_FLAG_NEED_NODELIST, node_info},
        {"recovery", NULL, "aprh", "show nodes in recovery",
         SUBCMD_FLAG_NEED_NODELIST, node_recovery},
+       {"cache", "<cache size>", "aprh", "specify max cache size",
+        SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, node_cache},
        {NULL,},
 };
 
diff --git a/include/internal_proto.h b/include/internal_proto.h
index a296217..3e22124 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -60,6 +60,7 @@
 #define SD_OP_READ_PEER      0xA4
 #define SD_OP_WRITE_PEER     0xA5
 #define SD_OP_REMOVE_PEER    0xA6
+#define SD_OP_SET_CACHE_SIZE 0xA7
 
 /* internal flags for hdr.flags, must be above 0x80 */
 #define SD_FLAG_CMD_RECOVERY 0x0080
-- 
1.7.1

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

Reply via email to