From 915adb9c1291d140e57765b7fad0c5bb0e7d5ed5 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 8 Jul 2010 08:16:13 +0000 Subject: gluster-CLI-and-mgmt-glusterd-added-to-codebase Signed-off-by: Vijay Bellur Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971 --- cli/src/cli-cmd-volume.c | 485 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 485 insertions(+) create mode 100644 cli/src/cli-cmd-volume.c (limited to 'cli/src/cli-cmd-volume.c') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c new file mode 100644 index 00000000000..227438db479 --- /dev/null +++ b/cli/src/cli-cmd-volume.c @@ -0,0 +1,485 @@ +/* + Copyright (c) 2010 Gluster, Inc. + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ + +#include +#include +#include +#include +#include + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "cli.h" +#include "cli-cmd.h" +#include "cli-mem-types.h" + +extern struct rpc_clnt *global_rpc; + +extern rpc_clnt_prog_t *cli_rpc_prog; + +int +cli_cmd_volume_info_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; + + proc = &cli_rpc_prog->proctable[GF1_CLI_GET_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, "localhost"); + } + +out: + if (ret) + cli_out ("Probe failed!"); + return ret; + +} + + +int +cli_cmd_volume_create_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_CREATE_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_create_parse (words, wordcount, &options); + + if (ret) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (ret) { + char *volname = (char *) words[2]; + cli_out ("Creating Volume %s failed",volname ); + } + return ret; +} + + +int +cli_cmd_volume_delete_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; + char *volname = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_DELETE_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + //TODO: Build validation here + volname = (char *)words[2]; + GF_ASSERT (volname); + + if (proc->fn) { + ret = proc->fn (frame, THIS, volname); + } + +out: + if (ret) + cli_out ("Deleting Volume %s failed", volname); + + return ret; +} + + +int +cli_cmd_volume_start_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; + char *volname = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_START_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + //TODO: Build validation here + volname = (char *)words[2]; + GF_ASSERT (volname); + + if (proc->fn) { + ret = proc->fn (frame, THIS, volname); + } + +out: + if (ret) + cli_out ("Starting Volume %s failed", volname); + + return ret; +} + + +int +cli_cmd_volume_stop_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; + char *volname = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_STOP_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + //TODO: Build validation here + volname = (char *)words[2]; + GF_ASSERT (volname); + + if (proc->fn) { + ret = proc->fn (frame, THIS, volname); + } + +out: + if (ret) + cli_out ("Stopping Volume %s failed", volname); + + return ret; +} + + +int +cli_cmd_volume_rename_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 *dict = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_RENAME_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + dict = dict_new (); + + if (dict) + goto out; + + GF_ASSERT (words[2]); + GF_ASSERT (words[3]); + + //TODO: Build validation here + ret = dict_set_str (dict, "old-volname", (char *)words[2]); + + if (ret) + goto out; + + ret = dict_set_str (dict, "new-volname", (char *)words[3]); + + if (ret) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, dict); + } + +out: + if (ret) { + char *volname = (char *) words[2]; + if (dict) + dict_destroy (dict); + cli_out ("Renaming Volume %s failed", volname ); + } + + return ret; +} + + +int +cli_cmd_volume_defrag_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; + char *volname = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_DEFRAG_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + //TODO: Build validation here + volname = (char *)words[2]; + GF_ASSERT (volname); + + if (proc->fn) { + ret = proc->fn (frame, THIS, volname); + } + +out: + if (ret) + cli_out ("Defrag of Volume %s failed", volname); + + return 0; +} + + +int +cli_cmd_volume_set_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; + char *volname = NULL; + dict_t *dict = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_SET_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + volname = (char *)words[2]; + GF_ASSERT (volname); + + GF_ASSERT (words[3]); + + ret = cli_cmd_volume_set_parse (words, wordcount, &dict); + + if (ret) + goto out; + + //TODO: Build validation here + if (proc->fn) { + ret = proc->fn (frame, THIS, dict); + } + +out: + if (ret) { + if (dict) + dict_destroy (dict); + cli_out ("Changing option on Volume %s failed", volname); + } + + return 0; +} + + +int +cli_cmd_volume_add_brick_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_ADD_BRICK]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options); + + if (ret) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (ret) { + char *volname = (char *) words[2]; + cli_out ("Adding brick to Volume %s failed",volname ); + } + return ret; +} + + +int +cli_cmd_volume_remove_brick_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_REMOVE_BRICK]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options); + + if (ret) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (ret) { + char *volname = (char *) words[2]; + cli_out ("Removing brick from Volume %s failed",volname ); + } + return ret; + +} + + + + +int +cli_cmd_volume_replace_brick_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_REPLACE_BRICK]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_replace_brick_parse (words, wordcount, &options); + + if (ret) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (ret) { + char *volname = (char *) words[2]; + cli_out ("Replacing brick from Volume %s failed",volname ); + } + return ret; + +} + + +int +cli_cmd_volume_set_transport_cbk (struct cli_state *state, + struct cli_cmd_word *word, + const char **words, int wordcount) +{ + cli_out ("volume set-transport not implemented\n"); + return 0; +} + + +struct cli_cmd volume_cmds[] = { + { "volume info [all|]", + cli_cmd_volume_info_cbk }, + + { "volume create [stripe ] [replicate ] ...", + cli_cmd_volume_create_cbk }, + + { "volume delete ", + cli_cmd_volume_delete_cbk }, + + { "volume start ", + cli_cmd_volume_start_cbk }, + + { "volume stop ", + cli_cmd_volume_stop_cbk }, + + { "volume rename ", + cli_cmd_volume_rename_cbk }, + + { "volume add-brick [(replica )|(stripe )] ...", + cli_cmd_volume_add_brick_cbk }, + + { "volume remove-brick [(replica )|(stripe )] ...", + cli_cmd_volume_remove_brick_cbk }, + + { "volume defrag ", + cli_cmd_volume_defrag_cbk }, + + { "volume replace-brick ( )|pause|abort|start|status", + cli_cmd_volume_replace_brick_cbk }, + + { "volume set-transport [] ...", + cli_cmd_volume_set_transport_cbk }, + + { "volume set ", + cli_cmd_volume_set_cbk }, + + { NULL, NULL } +}; + + +int +cli_cmd_volume_register (struct cli_state *state) +{ + int ret = 0; + struct cli_cmd *cmd = NULL; + + for (cmd = volume_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk); + if (ret) + goto out; + } +out: + return ret; +} -- cgit