From 3e34ad9388e3cf2493f3d75a760e6943f59dc55c Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 20 Jul 2010 02:40:58 +0000 Subject: add port as an optional argument to 'probe' command * there will be just 'one' glusterd per machine, but in case if its run on different port, then this option is useful to probe. Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 1074 (port related issues in 'gluster probe' command) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1074 --- cli/src/cli-cmd-probe.c | 51 +++++++++++++++++++++++++++++++++++++----------- cli/src/cli-cmd-volume.c | 3 +++ cli/src/cli3_1-cops.c | 46 +++++++++++++++++++++++++++++++++---------- 3 files changed, 79 insertions(+), 21 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-probe.c b/cli/src/cli-cmd-probe.c index a9f15a423bf..9f7a1da7758 100644 --- a/cli/src/cli-cmd-probe.c +++ b/cli/src/cli-cmd-probe.c @@ -40,19 +40,19 @@ extern rpc_clnt_prog_t *cli_rpc_prog; void cli_cmd_probe_usage () { - cli_out ("Usage: probe \n"); + cli_out ("Usage: probe [port]\n"); } void cli_cmd_deprobe_usage () { - cli_out ("Usage: detach \n"); + cli_out ("Usage: detach [port]\n"); } void cli_cmd_peer_status_usage () { - cli_out ("Usage: peer status \n"); + cli_out ("Usage: peer status [port]\n"); } int @@ -62,8 +62,9 @@ cli_cmd_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; + dict_t *dict = NULL; - if (wordcount != 2) { + if (!((wordcount == 3) || (wordcount == 2))) { cli_cmd_probe_usage (); goto out; } @@ -74,8 +75,22 @@ cli_cmd_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; + dict = dict_new (); + if (!dict) + goto out; + + ret = dict_set_str (dict, "hostname", (char *)words[1]); + if (ret) + goto out; + + if (words[2]) { + ret = dict_set_str (dict, "port", (char *)words[2]); + if (ret) + goto out; + } + if (proc->fn) { - ret = proc->fn (frame, THIS, (char *)words[1] ); + ret = proc->fn (frame, THIS, dict); } out: @@ -89,11 +104,12 @@ int cli_cmd_deprobe_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; + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *dict = NULL; - if (wordcount != 2) { + if (!((wordcount == 2) || (wordcount == 3))) { cli_cmd_deprobe_usage (); goto out; } @@ -104,13 +120,26 @@ cli_cmd_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; + dict = dict_new (); + + ret = dict_set_str (dict, "hostname", (char *)words[1]); + if (ret) + goto out; + + if (words[2]) { + ret = dict_set_str (dict, "port", (char *)words[2]); + if (ret) + goto out; + } + if (proc->fn) { - ret = proc->fn (frame, THIS, (char *)words[1] ); + ret = proc->fn (frame, THIS, dict); } out: if (ret) cli_out ("Detach failed\n"); + return ret; } @@ -144,7 +173,7 @@ out: } struct cli_cmd cli_probe_cmds[] = { - { "probe ", + { "probe [PORT]", cli_cmd_probe_cbk }, { "detach ", diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index af06d89614a..7aafddccc4c 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -91,6 +91,9 @@ out: char *volname = (char *) words[2]; cli_out ("Creating Volume %s failed",volname ); } + if (options) + dict_destroy (options); + return ret; } diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index f0d20ec6bb5..1f9feeac0b8 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -106,6 +106,7 @@ gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov, int32_t i = 1; char key[256] = {0,}; int32_t state = 0; + int32_t port = 0; if (-1 == req->rpc_status) { goto out; @@ -167,13 +168,18 @@ gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov, if (ret) goto out; + snprintf (key, 256, "friend%d.port", i); + ret = dict_get_int32 (dict, key, &port); + if (ret) + goto out; + snprintf (key, 256, "friend%d.state", i); ret = dict_get_int32 (dict, key, &state); if (ret) goto out; - cli_out ("hostname:%s, uuid:%s, state:%d\n", - hostname_buf, uuid_buf, state); + cli_out ("hostname:%s, port:%d, uuid:%s, state:%d\n", + hostname_buf, port, uuid_buf, state); i++; } } else { @@ -586,18 +592,28 @@ int32_t gf_cli3_1_probe (call_frame_t *frame, xlator_t *this, void *data) { - gf1_cli_probe_req req = {0,}; - int ret = 0; - char *hostname = NULL; + gf1_cli_probe_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + char *hostname = NULL; + int port = 0; if (!frame || !this || !data) { ret = -1; goto out; } - hostname = data; + dict = data; + ret = dict_get_str (dict, "hostname", &hostname); + if (ret) + goto out; + + ret = dict_get_int32 (dict, "port", &port); + if (ret) + port = CLI_GLUSTERD_PORT; req.hostname = hostname; + req.port = port; ret = cli_submit_request (&req, frame, cli_rpc_prog, GD_MGMT_CLI_PROBE, NULL, gf_xdr_from_cli_probe_req, @@ -615,18 +631,28 @@ int32_t gf_cli3_1_deprobe (call_frame_t *frame, xlator_t *this, void *data) { - gf1_cli_deprobe_req req = {0,}; - int ret = 0; - char *hostname = NULL; + gf1_cli_deprobe_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + char *hostname = NULL; + int port = 0; if (!frame || !this || !data) { ret = -1; goto out; } - hostname = data; + dict = data; + ret = dict_get_str (dict, "hostname", &hostname); + if (ret) + goto out; + + ret = dict_get_int32 (dict, "port", &port); + if (ret) + port = CLI_GLUSTERD_PORT; req.hostname = hostname; + req.port = port; ret = cli_submit_request (&req, frame, cli_rpc_prog, GD_MGMT_CLI_DEPROBE, NULL, -- cgit