diff options
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/cli-cmd-volume.c | 61 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 145 | ||||
-rw-r--r-- | cli/src/cli-xml-output.c | 78 | ||||
-rw-r--r-- | cli/src/cli.h | 3 |
4 files changed, 285 insertions, 2 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index c743b8bc9f0..52b5adb6129 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -2347,6 +2347,60 @@ out: return ret; } + +int +cli_cmd_volume_getopt_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; + int sent = 0; + int parse_err = 0; + cli_local_t *local = NULL; + + if (wordcount != 4) { + cli_usage_out (word->pattern); + parse_err = 1; + goto out; + } + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + options = dict_new (); + if (!options) + goto out; + + ret = dict_set_str (options, "volname", (char *)words[2]); + if (ret) + goto out; + + ret = dict_set_str (options, "key", (char *)words[3]); + if (ret) + goto out; + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOL_OPT]; + + CLI_LOCAL_INIT (local, words, frame, options); + + if (proc->fn) + ret = proc->fn (frame, THIS, options); + +out: + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_err == 0)) + cli_err ("Volume get option failed"); + } + CLI_STACK_DESTROY (frame); + if (options) + dict_unref (options); + return ret; +} + struct cli_cmd volume_cmds[] = { { "volume info [all|<VOLNAME>]", cli_cmd_volume_info_cbk, @@ -2473,8 +2527,11 @@ struct cli_cmd volume_cmds[] = { }, {"volume barrier <VOLNAME> {enable|disable}", cli_cmd_volume_barrier_cbk, - "Barrier/unbarrier file operations on a volume"}, - + "Barrier/unbarrier file operations on a volume" + }, + {"volume get <VOLNAME> <key|all>", + cli_cmd_volume_getopt_cbk, + "Get the value of the all options or given option for volume <VOLNAME>"}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index bbb7e56590a..ed3faf70c39 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -9272,6 +9272,7 @@ out: cli_cmd_broadcast_response (ret); return ret; } + int gf_cli_barrier_volume (call_frame_t *frame, xlator_t *this, void *data) { @@ -9295,6 +9296,149 @@ out: return ret; } +int32_t +gf_cli_get_vol_opt_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gf_cli_rsp rsp = {0,}; + int ret = -1; + dict_t *dict = NULL; + char *key = NULL; + char *value = NULL; + char msg[1024] = {0,}; + int i = 0; + char dict_key[50] = {0,}; + + if (-1 == req->rpc_status) + goto out; + ret = xdr_to_generic (*iov, &rsp, + (xdrproc_t)xdr_gf_cli_rsp); + if (ret < 0) { + gf_log (((call_frame_t *) myframe)->this->name, GF_LOG_ERROR, + "Failed to decode xdr response"); + goto out; + } + gf_log ("cli", GF_LOG_DEBUG, "Received response to get volume option"); + + if (rsp.op_ret) { + if (strcmp (rsp.op_errstr, "")) + snprintf (msg, sizeof (msg), "volume get option: " + "failed: %s", rsp.op_errstr); + else + snprintf (msg, sizeof (msg), "volume get option: " + "failed"); + + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_xml_output_str ("volGetopts", msg, rsp.op_ret, + rsp.op_errno, rsp.op_errstr); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, + "Error outputting to xml"); + } + } else { + cli_err (msg); + } + ret = 0; /* setting ret to 0 ensures we do not end up displaying + double error messages */ + 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 ("cli", GF_LOG_ERROR, + "Failed rsp_dict unserialization"); + goto out; + } + + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_xml_output_vol_getopts (dict, rsp.op_ret, + rsp.op_errno, + rsp.op_errstr); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "xml output generation " + "failed"); + ret = 0; + } + goto out; + } + + ret = dict_get_int32 (dict, "count", &count); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to retrieve count " + "from the dictionary"); + goto out; + } + if (count <= 0) { + gf_log ("cli", GF_LOG_ERROR, "Value of count :%d is " + "invalid", count); + ret = -1; + goto out; + } + + cli_out ("%-40s%-40s", "Option", "Value"); + cli_out ("%-40s%-40s", "------", "-----"); + for (i=1; i<=count; i++) { + sprintf (dict_key, "key%d", i); + ret = dict_get_str (dict, dict_key, &key); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to" + " retrieve %s from the " + "dictionary", dict_key); + goto out; + } + sprintf (dict_key, "value%d", i); + ret = dict_get_str (dict, dict_key, &value); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to " + "retrieve key value for %s from" + "the dictionary", dict_key); + goto out; + } + cli_out ("%-40s%-40s", key, value); + } + +out: + if (ret) { + cli_out ("volume get option failed. Check the cli/glusterd log " + "file for more details"); + } + if (dict) + dict_unref (dict); + free (rsp.op_errstr); + free (rsp.dict.dict_val); + cli_cmd_broadcast_response (ret); + return ret; +} + +int +gf_cli_get_vol_opt (call_frame_t *frame, xlator_t *this, void *data) +{ + gf_cli_req req = {{0,}}; + dict_t *options = NULL; + int ret = -1; + + if (!frame || !this || !data) + goto out; + + options = data; + + ret = cli_to_glusterd (&req, frame, gf_cli_get_vol_opt_cbk, + (xdrproc_t)xdr_gf_cli_req, options, + GLUSTER_CLI_GET_VOL_OPT, this, cli_rpc_prog, + NULL); +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + GF_FREE (req.dict.dict_val); + return ret; +} + int cli_to_glusterd (gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn, xdrproc_t xdrproc, dict_t *dict, @@ -9408,6 +9552,7 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_SYS_EXEC] = {"SYS_EXEC", gf_cli_sys_exec}, [GLUSTER_CLI_SNAP] = {"SNAP", gf_cli_snapshot}, [GLUSTER_CLI_BARRIER_VOLUME] = {"BARRIER VOLUME", gf_cli_barrier_volume}, + [GLUSTER_CLI_GET_VOL_OPT] = {"GET_VOL_OPT", gf_cli_get_vol_opt}, }; struct rpc_clnt_program cli_prog = { diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index da178d903e8..840ff32e52b 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -5693,3 +5693,81 @@ out: #endif /* HAVE_LIB_XML */ } +int +cli_xml_output_vol_getopts (dict_t *dict, int op_ret, int op_errno, + char *op_errstr) +{ +#if (HAVE_LIB_XML) + int i = 0; + int ret = -1; + int count = 0; + xmlTextWriterPtr writer = NULL; + xmlDocPtr doc = NULL; + char *key = NULL; + char *value = NULL; + char dict_key[50] = {0,}; + + ret = cli_begin_xml_output (&writer, &doc); + if (ret) + goto out; + + ret = cli_xml_output_common (writer, op_ret, op_errno, op_errstr); + if (ret) + goto out; + + ret = xmlTextWriterStartElement (writer, (xmlChar *)"volGetopts"); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = dict_get_int32 (dict, "count", &count); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to retrieve count " + "from the dictionary"); + goto out; + } + if (count <= 0) { + gf_log ("cli", GF_LOG_ERROR, "Value of count :%d is " + "invalid", count); + ret = -1; + goto out; + } + ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"count", + "%d", count); + + XML_RET_CHECK_AND_GOTO (ret, out); + + for (i=1; i<=count; i++) { + sprintf (dict_key, "key%d", i); + ret = dict_get_str (dict, dict_key, &key); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to" + " retrieve %s from the " + "dictionary", dict_key); + goto out; + } + sprintf (dict_key, "value%d", i); + ret = dict_get_str (dict, dict_key, &value); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to " + "retrieve key value for %s from" + "the dictionary", dict_key); + goto out; + } + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"Option", + "%s", key); + XML_RET_CHECK_AND_GOTO (ret, out); + + ret = xmlTextWriterWriteFormatElement (writer, + (xmlChar *)"Value", + "%s", value); + XML_RET_CHECK_AND_GOTO (ret, out); + } + ret = cli_end_xml_output (writer, doc); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +#else + return 0; +#endif /* HAVE_LIB_XML */ +} diff --git a/cli/src/cli.h b/cli/src/cli.h index b49cced70f0..89aedc5697d 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -408,4 +408,7 @@ int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, struct cli_state *state); +int +cli_xml_output_vol_getopts (dict_t *dict, int op_ret, int op_errno, + char *op_errstr); #endif /* __CLI_H__ */ |