From 609a89ceace25a0a81d0a9cafde3a4d1afd1b916 Mon Sep 17 00:00:00 2001 From: Kaushik BV Date: Sun, 3 Oct 2010 02:41:29 +0000 Subject: mgmt/Glusterd: new command volume reset , volume set enhancements - Write the reconfigured options in 'info' file to make it persistant - Implementation of volume set history - Implementation of volume reset Signed-off-by: Kaushik BV Signed-off-by: Vijay Bellur BUG: 1159 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1159 --- cli/src/cli-cmd-parser.c | 56 +++++++++++++++++++++++ cli/src/cli-cmd-volume.c | 45 +++++++++++++++++++ cli/src/cli.h | 3 ++ cli/src/cli3_1-cops.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 875ead064..a6f9cf915 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -288,6 +288,49 @@ out: return ret; } +int32_t +cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) +{ + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + + GF_ASSERT (words); + GF_ASSERT (options); + + GF_ASSERT ((strcmp (words[0], "volume")) == 0); + GF_ASSERT ((strcmp (words[1], "reset")) == 0); + + dict = dict_new (); + + if (!dict) + goto out; + + if (wordcount < 3) + goto out; + + volname = (char *)words[2]; + + if (!volname) { + ret = -1; + goto out; + } + + ret = dict_set_str (dict, "volname", volname); + + if (ret) + goto out; + + *options = dict; + +out: + if (ret) { + if (dict) + dict_destroy (dict); + } + + return ret; +} int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) @@ -329,6 +372,19 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) key = (char *) words[i]; value = (char *) words[i+1]; + if ( key && !value ) { + if ( !strcmp (key, "history")) { + ret = dict_set_str (dict, key, "history"); + if (ret) + goto out; + ret = dict_set_int32 (dict, "count", 1); + if (ret) + goto out; + *options = dict; + goto out; + } + } + if ( !key || !value) { ret = -1; cli_out ("Usage: volume set "); diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 8d846d873..3c433c523 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -71,6 +71,12 @@ cli_cmd_volume_info_usage () cli_out ("Usage: volume info [all|]"); } +void +cli_cmd_volume_reset_usage () +{ + cli_out ("Usage: volume reset "); +} + void cli_cmd_volume_set_usage () { @@ -481,6 +487,41 @@ out: return 0; } +int +cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) +{ + + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *options = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_RESET_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_reset_parse (words, wordcount, &options); + + if (ret) { + cli_cmd_volume_reset_usage (); + goto out; + } + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (options) + dict_unref (options); + + return ret; + +} + int cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -886,6 +927,10 @@ struct cli_cmd volume_cmds[] = { { "volume sync [all|]", cli_cmd_sync_volume_cbk, "sync the volume information from a peer"}, + + { "volume reset ", + cli_cmd_volume_reset_cbk, + "reset all the reconfigured options"}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli.h b/cli/src/cli.h index 216b743fd..f3ea92828 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -171,6 +171,9 @@ int32_t cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options); +int32_t +cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **opt); + int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options); diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index 8a775e974..0eb1ef77a 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -745,12 +745,53 @@ out: return ret; } +int +gf_cli3_1_reset_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_reset_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_reset_vol_rsp (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to reset"); + cli_out ("reset volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); + + if (rsp.op_ret && rsp.op_errstr) + cli_out ("%s", rsp.op_errstr); + + ret = rsp.op_ret; + +out: + cli_cmd_broadcast_response (ret); + return ret; +} + +void +_cli_out_options (dict_t *this, char *key, data_t *value, void *count) +{ + + (*((int *) count))++; + cli_out ("%s - %s", key, value->data); +} + int gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { gf1_cli_set_vol_rsp rsp = {0,}; int ret = 0; + dict_t *dict = NULL; + int dict_count = 0; if (-1 == req->rpc_status) { goto out; @@ -761,6 +802,38 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("", GF_LOG_ERROR, "error"); goto out; } + + if (rsp.op_ret == 1) { // if the command was volume set history + + if (!rsp.dict.dict_len) { + cli_out ("No volumes present"); + ret = 0; + goto out; + } + + dict = dict_new (); + + if (!dict) { + ret = -1; + goto out; + } + + ret = dict_unserialize (rsp.dict.dict_val, + rsp.dict.dict_len, + &dict); + + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Unable to allocate memory"); + goto out; + } + cli_out ("Options:"); + dict_foreach (dict, _cli_out_options, &dict_count); + if (!dict_count) + cli_out ("No Options Reconfigured!!"); + goto out; + } + gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); @@ -1571,6 +1644,47 @@ out: return ret; } +int32_t +gf_cli3_1_reset_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_reset_vol_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.dict.dict_val, + (size_t *)&req.dict.dict_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + + ret = cli_cmd_submit (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_RESET_VOLUME, NULL, + gf_xdr_from_cli_reset_vol_req, + this, gf_cli3_1_reset_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + int32_t gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this, void *data) @@ -2022,6 +2136,7 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = { [GF1_CLI_GETSPEC] = {"GETSPEC", gf_cli3_1_getspec}, [GF1_CLI_PMAP_PORTBYBRICK] = {"PMAP PORTBYBRICK", gf_cli3_1_pmap_b2p}, [GF1_CLI_SYNC_VOLUME] = {"SYNC_VOLUME", gf_cli3_1_sync_volume}, + [GF1_CLI_RESET_VOLUME] = {"RESET_VOLUME", gf_cli3_1_reset_volume} }; struct rpc_clnt_program cli3_1_prog = { -- cgit