From 2b86da69df423a90b76932bd32b7a17bd5ac2add Mon Sep 17 00:00:00 2001 From: Sanju Rakonde Date: Mon, 22 Apr 2019 19:50:19 +0530 Subject: tier/cli: remove tier code to increase code coverage in cli Change-Id: I56cc09243dab23b3be86a7faac45001dda77181f updates: bz#1693692 Signed-off-by: Sanju Rakonde --- cli/src/cli-cmd-volume.c | 414 +---------------------------------------------- 1 file changed, 1 insertion(+), 413 deletions(-) (limited to 'cli/src/cli-cmd-volume.c') 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 @@ -49,10 +49,6 @@ int 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) @@ -1118,335 +1114,6 @@ out: return ret; } -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 " - " is " - "deprecated. Use the new command \'" - "gluster volume tier detach \'\n" - "Do you want to Continue?"; - - const char *attach_question = - "gluster volume attach-tier " - "[] ... is " - "deprecated. Use the new command \'" - "gluster volume tier attach [] ... [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) { @@ -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 status", cli_cmd_volume_tier_cbk, - "Display tier status for "}, - - {"volume tier start [force]", cli_cmd_volume_tier_cbk, - "Start the tier service for "}, - - {"volume tier stop [force]", cli_cmd_volume_tier_cbk, - "Stop the tier service for "}, - - {"volume tier attach [] ... [force]", - cli_cmd_volume_tier_cbk, "Attach a hot tier to "}, - - {"volume tier detach ", - cli_cmd_volume_tier_cbk, "Detach the hot tier from "}, - - {"volume attach-tier [] ...", - cli_cmd_volume_tier_cbk, - "NOTE: this is old syntax, will be deprecated in next release. " - "Please use gluster volume tier attach " - "[] ..."}, - - {"volume detach-tier " - "", - cli_cmd_volume_tier_cbk, - "NOTE: this is old syntax, will be deprecated in next release. " - "Please use gluster volume tier detach " - "{start|stop|commit} [force]"}, - - {"volume tier status\n" - "volume tier start [force]\n" - "volume tier stop\n" - "volume tier attach [] ... [force]\n" - "volume tier detach \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 ] [list-cnt ]", cli_cmd_volume_top_cbk, "volume top operations"}, - {"volume status [all | [nfs|shd||quotad|tierd]]" + {"volume status [all | [nfs|shd||quotad]]" " [detail|clients|mem|inode|fd|callpool|tasks|client-list]", cli_cmd_volume_status_cbk, "display status of all or specified volume(s)/brick"}, @@ -3540,32 +3163,6 @@ cli_cmd_bitrot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, return 0; } -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; } -- cgit