summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorKaushik BV <kaushikbv@gluster.com>2010-10-03 02:41:29 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-03 03:05:03 -0700
commit609a89ceace25a0a81d0a9cafde3a4d1afd1b916 (patch)
tree0205b67be6e1e2f33e9a0c9c1ca4ea0737ebff05 /cli
parent53b8c7470f9e40c60c5eebd1fbad5c6d274f7ee5 (diff)
mgmt/Glusterd: new command volume reset <volname>, volume set enhancementsv3.1.0qa39
- Write the reconfigured options in 'info' file to make it persistant - Implementation of volume set <volname> history - Implementation of volume reset <volname> Signed-off-by: Kaushik BV <kaushikbv@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1159 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1159
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c56
-rw-r--r--cli/src/cli-cmd-volume.c45
-rw-r--r--cli/src/cli.h3
-rw-r--r--cli/src/cli3_1-cops.c115
4 files changed, 219 insertions, 0 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 875ead0642e..a6f9cf915a1 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 <VOLNAME> <KEY> <VALUE>");
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 8d846d8732c..3c433c523e0 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -72,6 +72,12 @@ cli_cmd_volume_info_usage ()
}
void
+cli_cmd_volume_reset_usage ()
+{
+ cli_out ("Usage: volume reset <VOLNAME> ");
+}
+
+void
cli_cmd_volume_set_usage ()
{
cli_out ("Usage: volume set <VOLNAME> <KEY> <VALUE>");
@@ -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 <HOSTNAME> [all|<VOLNAME>]",
cli_cmd_sync_volume_cbk,
"sync the volume information from a peer"},
+
+ { "volume reset <VOLNAME> ",
+ 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 216b743fdd1..f3ea9282873 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -172,6 +172,9 @@ 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 8a775e974a6..0eb1ef77a33 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -746,11 +746,52 @@ out:
}
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 <vol> 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");
@@ -1572,6 +1645,47 @@ out:
}
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 = {