diff options
Diffstat (limited to 'cli/src/cli-cmd-peer.c')
| -rw-r--r-- | cli/src/cli-cmd-peer.c | 191 |
1 files changed, 131 insertions, 60 deletions
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index 5ae2007f3..551312411 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -1,22 +1,12 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2010-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -31,6 +21,7 @@ #include "cli.h" #include "cli-cmd.h" #include "cli-mem-types.h" +#include "cli1-xdr.h" #include "protocol-common.h" extern struct rpc_clnt *global_rpc; @@ -40,24 +31,6 @@ extern rpc_clnt_prog_t *cli_rpc_prog; int cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount); -void -cli_cmd_probe_usage () -{ - cli_out ("Usage: probe <hostname>"); -} - -void -cli_cmd_deprobe_usage () -{ - cli_out ("Usage: detach <hostname>"); -} - -void -cli_cmd_peer_status_usage () -{ - cli_out ("Usage: peer status"); -} - int cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) @@ -66,13 +39,17 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; + cli_local_t *local = NULL; if (!(wordcount == 3)) { - cli_cmd_probe_usage (); + cli_usage_out (word->pattern); + parse_error = 1; goto out; } - proc = &cli_rpc_prog->proctable[GF1_CLI_PROBE]; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROBE]; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -86,19 +63,38 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, if (ret) goto out; + ret = valid_internet_address ((char *) words[2], _gf_false); + if (ret == 1) { + ret = 0; + } else { + cli_out ("%s is an invalid address", words[2]); + cli_usage_out (word->pattern); + parse_error = 1; + ret = -1; + goto out; + } /* if (words[3]) { ret = dict_set_str (dict, "port", (char *)words[3]); if (ret) goto out; } */ + + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: - if (ret) - cli_out ("Probe failed"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer probe failed"); + } + + CLI_STACK_DESTROY (frame); + return ret; } @@ -111,13 +107,18 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; - - if (!(wordcount == 3) ) { - cli_cmd_deprobe_usage (); + int flags = 0; + int sent = 0; + int parse_error = 0; + cli_local_t *local = NULL; + + if ((wordcount < 3) || (wordcount > 4)) { + cli_usage_out (word->pattern); + parse_error = 1; goto out; } - proc = &cli_rpc_prog->proctable[GF1_CLI_DEPROBE]; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEPROBE]; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -135,11 +136,35 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } */ + if (wordcount == 4) { + if (!strcmp("force", words[3])) + flags |= GF_CLI_FLAG_OP_FORCE; + else { + ret = -1; + cli_usage_out (word->pattern); + parse_error = 1; + goto out; + } + } + ret = dict_set_int32 (dict, "flags", flags); + if (ret) + goto out; + + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer detach failed"); + } + + CLI_STACK_DESTROY (frame); + return ret; } @@ -150,25 +175,73 @@ cli_cmd_peer_status_cbk (struct cli_state *state, struct cli_cmd_word *word, int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; + int sent = 0; + int parse_error = 0; if (wordcount != 2) { - cli_cmd_peer_status_usage (); + cli_usage_out (word->pattern); + parse_error = 1; goto out; } - proc = &cli_rpc_prog->proctable[GF1_CLI_LIST_FRIENDS]; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; if (proc->fn) { - ret = proc->fn (frame, THIS, (char *)words[1] ); + ret = proc->fn (frame, THIS, (void *)GF_CLI_LIST_PEERS); } out: - if (ret) - cli_out ("Command Execution failed"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer status failed"); + } + + CLI_STACK_DESTROY (frame); + + return ret; +} + +int +cli_cmd_pool_list_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 sent = 0; + int parse_error = 0; + + if (wordcount != 2) { + cli_usage_out (word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, + (void *)GF_CLI_LIST_POOL_NODES); + } + +out: + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_err ("pool list: command execution failed"); + } + + CLI_STACK_DESTROY (frame); + return ret; } @@ -177,18 +250,21 @@ struct cli_cmd cli_probe_cmds[] = { cli_cmd_peer_probe_cbk, "probe peer specified by <HOSTNAME>"}, - { "peer detach <HOSTNAME>", + { "peer detach <HOSTNAME> [force]", cli_cmd_peer_deprobe_cbk, "detach peer specified by <HOSTNAME>"}, { "peer status", cli_cmd_peer_status_cbk, "list status of peers"}, - - { "peer help", - cli_cmd_peer_help_cbk, + + { "peer help", + cli_cmd_peer_help_cbk, "Help command for peer "}, + { "pool list", + cli_cmd_pool_list_cbk, + "list all the nodes in the pool (including localhost)"}, { NULL, NULL, NULL } }; @@ -199,16 +275,11 @@ cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, { struct cli_cmd *cmd = NULL; - + for (cmd = cli_probe_cmds; cmd->pattern; cmd++) cli_out ("%s - %s", cmd->pattern, cmd->desc); - - - if (!state->rl_enabled) - exit (0); - return 0; } @@ -219,8 +290,8 @@ cli_cmd_probe_register (struct cli_state *state) struct cli_cmd *cmd = NULL; for (cmd = cli_probe_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk, - cmd->desc); + + ret = cli_cmd_register (&state->tree, cmd); if (ret) goto out; } |
