summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-volume.c
diff options
context:
space:
mode:
authorSanju Rakonde <srakonde@redhat.com>2019-04-22 19:50:19 +0530
committerAtin Mukherjee <amukherj@redhat.com>2019-04-25 10:38:20 +0000
commit2b86da69df423a90b76932bd32b7a17bd5ac2add (patch)
treea74ddd6609d4ea2cffc7595efd428ab86a8d07d6 /cli/src/cli-cmd-volume.c
parentc827682e4df44ec6aaae3780c325568fb43053ff (diff)
tier/cli: remove tier code to increase code coverage in cli
Change-Id: I56cc09243dab23b3be86a7faac45001dda77181f updates: bz#1693692 Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-volume.c')
-rw-r--r--cli/src/cli-cmd-volume.c414
1 files changed, 1 insertions, 413 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 975536f9f69..e711608ed80 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -50,10 +50,6 @@ cli_cmd_quota_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
int
-cli_cmd_tier_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount);
-
-int
cli_cmd_volume_info_cbk(struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
{
@@ -1119,335 +1115,6 @@ out:
}
int
-cli_tier_validate_replica_type(dict_t *dict, int type)
-{
- int brick_count = -1;
- int replica_count = 1;
- int ret = -1;
-
- ret = dict_get_int32(dict, "count", &brick_count);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to get brick count");
- goto out;
- }
-
- ret = dict_get_int32(dict, "replica-count", &replica_count);
- if (ret) {
- gf_log("cli", GF_LOG_DEBUG,
- "Failed to get replica count. "
- "Defaulting to one");
- replica_count = 1;
- }
-
- /*
- * Change the calculation of sub_count once attach-tier support
- * disperse volume.
- * sub_count = disperse_count for disperse volume
- * */
-
- if (brick_count % replica_count) {
- if (type == GF_CLUSTER_TYPE_REPLICATE)
- cli_err(
- "number of bricks is not a multiple of "
- "replica count");
- else if (type == GF_CLUSTER_TYPE_DISPERSE)
- cli_err(
- "number of bricks is not a multiple of "
- "disperse count");
- else
- cli_err(
- "number of bricks given doesn't match "
- "required count");
-
- ret = -1;
- goto out;
- }
- ret = 0;
-out:
- return ret;
-}
-
-int
-do_cli_cmd_volume_attach_tier(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_error = 0;
- cli_local_t *local = NULL;
- int type = 0;
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- ret = cli_cmd_volume_add_brick_parse(state, words, wordcount, &options,
- &type);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- /*
- * Merge this check when attach-tier has it's own cli parse function.
- */
- ret = cli_tier_validate_replica_type(options, type);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- if (state->mode & GLUSTER_MODE_WIGNORE) {
- ret = dict_set_int32(options, "force", _gf_true);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to set force "
- "option");
- goto out;
- }
- }
-
- ret = dict_set_int32(options, "attach-tier", 1);
- if (ret)
- goto out;
-
- ret = dict_set_int32(options, "hot-type", type);
- if (ret)
- goto out;
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_TIER_BRICK];
-
- 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_error == 0))
- cli_out("attach-tier failed");
- }
-
- CLI_STACK_DESTROY(frame);
-
- return ret;
-}
-
-int
-do_cli_cmd_volume_detach_tier(struct cli_state *state,
- struct cli_cmd_word *word, const char **words,
- int wordcount, gf_boolean_t *aborted)
-{
- int ret = -1;
- rpc_clnt_procedure_t *proc = NULL;
- call_frame_t *frame = NULL;
- dict_t *options = NULL;
- int sent = 0;
- int parse_error = 0;
- gf_answer_t answer = GF_ANSWER_NO;
- cli_local_t *local = NULL;
- int need_question = 0;
-
- const char *question =
- "Removing tier can result in data loss. "
- "Do you want to Continue?";
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- ret = cli_cmd_volume_detach_tier_parse(words, wordcount, &options,
- &need_question);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- ret = dict_set_int32(options, "force", 1);
- if (ret)
- goto out;
-
- ret = dict_set_int32(options, "count", 0);
- if (ret)
- goto out;
-
- *aborted = _gf_false;
-
- if (!(state->mode & GLUSTER_MODE_SCRIPT) && need_question) {
- /* we need to ask question only in case of 'commit or force' */
- answer = cli_cmd_get_confirmation(state, question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- *aborted = _gf_true;
- goto out;
- }
- }
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REMOVE_TIER_BRICK];
-
- 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_error == 0))
- cli_out("Volume detach tier failed");
- }
-
- CLI_STACK_DESTROY(frame);
-
- return ret;
-}
-
-int
-cli_cmd_volume_tier_cbk(struct cli_state *state, struct cli_cmd_word *word,
- const char **words, int wordcount)
-{
- int ret = -1;
- call_frame_t *frame = NULL;
- dict_t *options = NULL;
- rpc_clnt_procedure_t *proc = NULL;
- cli_local_t *local = NULL;
- int i = 0;
- eventtypes_t event = EVENT_LAST;
- gf_boolean_t aborted = _gf_false;
- gf_answer_t answer = GF_ANSWER_NO;
-
- const char *detach_question =
- "gluster volume detach-tier <VOLNAME> "
- "<start|stop|status|commit|force> is "
- "deprecated. Use the new command \'"
- "gluster volume tier <VOLNAME> detach <start|"
- "stop|status|commit|force>\'\n"
- "Do you want to Continue?";
-
- const char *attach_question =
- "gluster volume attach-tier <VOLNAME> "
- "[<replica COUNT>] <NEW-BRICK>... is "
- "deprecated. Use the new command \'"
- "gluster volume tier <VOLNAME> attach [<replica"
- " COUNT>] <NEW-BRICK>... [force]\'\n"
- "Do you want to Continue?";
-
- if (wordcount < 4) {
- if (wordcount == 3 && !strcmp(words[2], "help")) {
- cli_cmd_tier_help_cbk(state, word, words, wordcount);
- ret = 0;
- } else {
- cli_usage_out(word->pattern);
- }
- goto out;
- }
-
- if (!strcmp(words[1], "detach-tier")) {
- /* we need to ask question when older command is used */
- answer = cli_cmd_get_confirmation(state, detach_question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- goto out;
- }
- ret = do_cli_cmd_volume_detach_tier(state, word, words, wordcount,
- &aborted);
- goto out;
- } else if (!strcmp(words[3], "detach")) {
- for (i = 3; i < wordcount; i++)
- words[i] = words[i + 1];
-
- ret = do_cli_cmd_volume_detach_tier(state, word, words, wordcount - 1,
- &aborted);
- if (!aborted) {
- if (!strcmp(words[wordcount - 2], "commit")) {
- event = EVENT_TIER_DETACH_COMMIT;
- } else if (!strcmp(words[wordcount - 2], "start")) {
- event = EVENT_TIER_DETACH_START;
- } else if (!strcmp(words[wordcount - 2], "stop")) {
- event = EVENT_TIER_DETACH_STOP;
- } else if (!strcmp(words[wordcount - 2], "force")) {
- event = EVENT_TIER_DETACH_FORCE;
- }
- }
- goto out;
-
- } else if (!strcmp(words[1], "attach-tier")) {
- /* we need to ask question when the older command is used */
- answer = cli_cmd_get_confirmation(state, attach_question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- goto out;
- }
- ret = do_cli_cmd_volume_attach_tier(state, word, words, wordcount);
- goto out;
- } else if (!strcmp(words[3], "attach")) {
- for (i = 3; i < wordcount; i++)
- words[i] = words[i + 1];
-
- ret = do_cli_cmd_volume_attach_tier(state, word, words, wordcount - 1);
- if (!strcmp(words[wordcount - 2], "force")) {
- event = EVENT_TIER_ATTACH_FORCE;
- } else {
- event = EVENT_TIER_ATTACH;
- }
- goto out;
- }
-
- ret = cli_cmd_volume_tier_parse(words, wordcount, &options);
- if (ret) {
- cli_usage_out(word->pattern);
- goto out;
- }
-
- if (!strcmp(words[wordcount - 1], "start")) {
- event = EVENT_TIER_START;
- } else {
- if (!strcmp(words[wordcount - 2], "start") &&
- !strcmp(words[wordcount - 1], "force")) {
- event = EVENT_TIER_START_FORCE;
- }
- }
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TIER];
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame) {
- gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
- ret = -1;
- goto out;
- }
-
- CLI_LOCAL_INIT(local, words, frame, options);
-
- if (proc->fn) {
- ret = proc->fn(frame, THIS, options);
- }
-
-out:
- if (ret) {
- cli_out("Tier command failed");
- } else {
- if (event != EVENT_LAST) {
- gf_event(event, "vol=%s", words[2]);
- }
- }
- if (options)
- dict_unref(options);
-
- return ret;
-}
-
-int
cli_get_soft_limit(dict_t *options, const char **words, dict_t *xdata)
{
call_frame_t *frame = NULL;
@@ -3317,50 +2984,6 @@ struct cli_cmd quota_cmds[] = {
{NULL, NULL, NULL}};
-struct cli_cmd tier_cmds[] = {
-
- {"volume tier help", cli_cmd_tier_help_cbk,
- "display help for volume tier commands"},
-
- {"volume tier <VOLNAME> status", cli_cmd_volume_tier_cbk,
- "Display tier status for <VOLNAME>"},
-
- {"volume tier <VOLNAME> start [force]", cli_cmd_volume_tier_cbk,
- "Start the tier service for <VOLNAME>"},
-
- {"volume tier <VOLNAME> stop [force]", cli_cmd_volume_tier_cbk,
- "Stop the tier service for <VOLNAME>"},
-
- {"volume tier <VOLNAME> attach [<replica COUNT>] <NEW-BRICK>... [force]",
- cli_cmd_volume_tier_cbk, "Attach a hot tier to <VOLNAME>"},
-
- {"volume tier <VOLNAME> detach <start|stop|status|commit|[force]>",
- cli_cmd_volume_tier_cbk, "Detach the hot tier from <VOLNAME>"},
-
- {"volume attach-tier <VOLNAME> [<replica COUNT>] <NEW-BRICK>...",
- cli_cmd_volume_tier_cbk,
- "NOTE: this is old syntax, will be deprecated in next release. "
- "Please use gluster volume tier <vol> attach "
- "[<replica COUNT>] <NEW-BRICK>..."},
-
- {"volume detach-tier <VOLNAME> "
- "<start|stop|status|commit|force>",
- cli_cmd_volume_tier_cbk,
- "NOTE: this is old syntax, will be deprecated in next release. "
- "Please use gluster volume tier <vol> detach "
- "{start|stop|commit} [force]"},
-
- {"volume tier <VOLNAME> status\n"
- "volume tier <VOLNAME> start [force]\n"
- "volume tier <VOLNAME> stop\n"
- "volume tier <VOLNAME> attach [<replica COUNT>] <NEW-BRICK>... [force]\n"
- "volume tier <VOLNAME> detach <start|stop|status|commit|[force]>\n",
- cli_cmd_volume_tier_cbk, NULL},
-
- {NULL, NULL, NULL}
-
-};
-
struct cli_cmd volume_cmds[] = {
{"volume help", cli_cmd_volume_help_cbk,
"display help for volume commands"},
@@ -3452,7 +3075,7 @@ struct cli_cmd volume_cmds[] = {
"[brick <brick>] [list-cnt <value>]",
cli_cmd_volume_top_cbk, "volume top operations"},
- {"volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad|tierd]]"
+ {"volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad]]"
" [detail|clients|mem|inode|fd|callpool|tasks|client-list]",
cli_cmd_volume_status_cbk,
"display status of all or specified volume(s)/brick"},
@@ -3541,32 +3164,6 @@ cli_cmd_bitrot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
}
int
-cli_cmd_tier_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount)
-{
- struct cli_cmd *cmd = NULL;
- struct cli_cmd *tier_cmd = NULL;
- int count = 0;
-
- cmd = GF_MALLOC(sizeof(tier_cmds), cli_mt_cli_cmd);
- memcpy(cmd, tier_cmds, sizeof(tier_cmds));
- count = (sizeof(tier_cmds) / sizeof(struct cli_cmd));
- cli_cmd_sort(cmd, count);
-
- cli_out("\ngluster tier commands");
- cli_out("======================\n");
-
- for (tier_cmd = cmd; tier_cmd->pattern; tier_cmd++) {
- if ((_gf_false == tier_cmd->disable) && tier_cmd->desc) {
- cli_out("%s - %s", tier_cmd->pattern, tier_cmd->desc);
- }
- }
- cli_out("\n");
- GF_FREE(cmd);
- return 0;
-}
-
-int
cli_cmd_volume_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount)
{
@@ -3615,15 +3212,6 @@ cli_cmd_volume_register(struct cli_state *state)
goto out;
}
-#if !defined(__NetBSD__)
- for (cmd = tier_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register(&state->tree, cmd);
- if (ret)
- goto out;
- }
-
-#endif
-
out:
return ret;
}