diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 92 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 215 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 175 | ||||
-rw-r--r-- | cli/src/cli.h | 4 |
4 files changed, 200 insertions, 286 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 3b81792dc..4181e6c81 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2339,3 +2339,95 @@ out: return ret; } + +int +cli_cmd_volume_defrag_parse (const char **words, int wordcount, + dict_t **options) +{ + dict_t *dict = NULL; + int ret = -1; + char *option = NULL; + char *volname = NULL; + char *command = NULL; + gf_cli_defrag_type cmd = 0; + + GF_ASSERT (words); + GF_ASSERT (options); + + dict = dict_new (); + if (!dict) + goto out; + + if (!((wordcount == 4) || (wordcount == 5))) + goto out; + + if (wordcount == 4) { + if (strcmp (words[3], "start") && strcmp (words[3], "stop") && + strcmp (words[3], "status")) + goto out; + } else { + if (strcmp (words[3], "fix-layout") && + strcmp (words[3], "start")) + goto out; + } + + volname = (char *) words[2]; + + if (wordcount == 4) { + command = (char *) words[3]; + } + if (wordcount == 5) { + if ((strcmp (words[3], "fix-layout") || + strcmp (words[4], "start")) && + (strcmp (words[3], "start") || + strcmp (words[4], "force"))) { + ret = -1; + goto out; + } + command = (char *) words[3]; + option = (char *) words[4]; + } + + if (strcmp (command, "start") == 0) { + cmd = GF_DEFRAG_CMD_START; + if (option && strcmp (option, "force") == 0) { + cmd = GF_DEFRAG_CMD_START_FORCE; + } + goto done; + } + + if (strcmp (command, "fix-layout") == 0) { + cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX; + goto done; + } + if (strcmp (command, "stop") == 0) { + cmd = GF_DEFRAG_CMD_STOP; + goto done; + } + if (strcmp (command, "status") == 0) { + cmd = GF_DEFRAG_CMD_STATUS; + } + +done: + ret = dict_set_str (dict, "volname", volname); + + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } + + ret = dict_set_int32 (dict, "rebalance-command", (int32_t) cmd); + + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } + + *options = dict; + +out: + if (ret && dict) + dict_destroy (dict); + + return ret; +} diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index b9bed82e1..ac70cd5c0 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -29,15 +29,17 @@ #include "cli1-xdr.h" #include "run.h" -#define SAVE_WORDS_IN_LOCAL(local, words, frame) \ - do { \ - local = cli_local_get (); \ - \ - if (local) { \ - local->words = words; \ - if (frame) \ - frame->local = local; \ - } \ +#define CLI_LOCAL_INIT(local, words, frame, dictionary) \ + do { \ + local = cli_local_get (); \ + \ + if (local) { \ + local->words = words; \ + if (dictionary) \ + local->dict = dictionary; \ + if (frame) \ + frame->local = local; \ + } \ } while (0) extern struct rpc_clnt *global_rpc; @@ -163,7 +165,7 @@ cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); + CLI_LOCAL_INIT (local, words, frame, dict); if (proc->fn) { ret = proc->fn (frame, THIS, dict); @@ -176,9 +178,6 @@ out: cli_out ("Volume sync failed"); } - if (dict) - dict_unref (dict); - CLI_STACK_DESTROY (frame); return ret; @@ -348,15 +347,12 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, int32_t type = GF_CLUSTER_TYPE_NONE; cli_local_t *local = NULL; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CREATE_VOLUME]; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_create_parse (words, wordcount, &options); if (ret) { @@ -395,13 +391,14 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } } + + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -427,6 +424,7 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, int sent = 0; int parse_error = 0; cli_local_t *local = NULL; + dict_t *dict = NULL; question = "Deleting volume will erase all information about the volume. " "Do you want to continue?"; @@ -436,7 +434,9 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); + dict = dict_new (); + if (!dict) + goto out; if (wordcount != 3) { cli_usage_out (word->pattern); @@ -453,8 +453,17 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, volname = (char *)words[2]; + ret = dict_set_str (dict, "volname", volname); + + if (ret) { + gf_log (THIS->name, GF_LOG_WARNING, "dict set failed"); + goto out; + } + + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { - ret = proc->fn (frame, THIS, volname); + ret = proc->fn (frame, THIS, dict); } out: @@ -492,8 +501,6 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } - SAVE_WORDS_IN_LOCAL (local, words, frame); - dict = dict_new (); if (!dict) { goto out; @@ -533,13 +540,13 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, proc = &cli_rpc_prog->proctable[GLUSTER_CLI_START_VOLUME]; + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: - if (dict) - dict_unref (dict); if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -615,8 +622,6 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - if (wordcount < 3 || wordcount > 4) { cli_usage_out (word->pattern); parse_error = 1; @@ -658,6 +663,8 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STOP_VOLUME]; + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } @@ -668,8 +675,6 @@ out: if ((sent == 0) && (parse_error == 0)) cli_out ("Volume stop on '%s' failed", volname); } - if (dict) - dict_unref (dict); CLI_STACK_DESTROY (frame); @@ -754,72 +759,22 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - - dict = dict_new (); - if (!dict) - goto out; + ret = cli_cmd_volume_defrag_parse (words, wordcount, &dict); - if (!((wordcount == 4) || (wordcount == 5))) { + if (ret) { cli_usage_out (word->pattern); parse_error = 1; - goto out; - } - - if (wordcount == 4) { - if (strcmp (words[3], "start") && strcmp (words[3], "stop") && - strcmp (words[3], "status")) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - } else { - if (strcmp (words[3], "fix-layout") && - strcmp (words[3], "start")) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - } - - ret = dict_set_str (dict, "volname", (char *)words[2]); - if (ret) - goto out; - - if (wordcount == 4) { - ret = dict_set_str (dict, "command", (char *)words[3]); - if (ret) - goto out; - } - if (wordcount == 5) { - if ((strcmp (words[3], "fix-layout") || - strcmp (words[4], "start")) && - (strcmp (words[3], "start") || - strcmp (words[4], "force"))) { - cli_usage_out (word->pattern); - parse_error = 1; - ret = -1; - goto out; - } - - ret = dict_set_str (dict, "option", (char *)words[4]); - if (ret) - goto out; - ret = dict_set_str (dict, "command", (char *)words[3]); - if (ret) - goto out; } proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEFRAG_VOLUME]; + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: - if (dict) - dict_destroy (dict); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -837,7 +792,6 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, { int sent = 0; int parse_error = 0; - int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; @@ -850,24 +804,20 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_reset_parse (words, wordcount, &options); - if (ret) { cli_usage_out (word->pattern); parse_error = 1; goto out; } + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -907,16 +857,13 @@ cli_cmd_volume_profile_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); + CLI_LOCAL_INIT (local, words, frame, options); if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -948,24 +895,20 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_set_parse (words, wordcount, &options); - if (ret) { cli_usage_out (word->pattern); parse_error = 1; goto out; } + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -1002,10 +945,7 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options); - if (ret) { cli_usage_out (word->pattern); parse_error = 1; @@ -1025,14 +965,13 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_BRICK]; + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -1072,9 +1011,8 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_quota_parse (words, wordcount, &options); + if (ret < 0) { cli_usage_out (word->pattern); parse_err = 1; @@ -1086,13 +1024,12 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) ret = proc->fn (frame, THIS, options); out: - if (options) - dict_unref (options); - if (ret && parse_err == 0) cli_out ("Quota command failed"); @@ -1124,11 +1061,8 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options, &need_question); - if (ret) { cli_usage_out (word->pattern); parse_error = 1; @@ -1146,6 +1080,8 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REMOVE_BRICK]; + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } @@ -1157,9 +1093,6 @@ out: cli_out ("Volume remove-brick failed"); } - if (options) - dict_unref (options); - CLI_STACK_DESTROY (frame); return ret; @@ -1190,8 +1123,6 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_volume_replace_brick_parse (words, wordcount, &options); if (ret) { @@ -1200,14 +1131,13 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, goto out; } + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -1256,16 +1186,13 @@ cli_cmd_volume_top_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); + CLI_LOCAL_INIT (local, words, frame, options); if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -1303,20 +1230,17 @@ cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_log_rotate_parse (words, wordcount, &options); if (ret) goto out; + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } out: - if (options) - dict_unref (options); - if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) @@ -1410,8 +1334,6 @@ cli_cmd_volume_gsync_set_cbk (struct cli_state *state, struct cli_cmd_word *word goto out; } - SAVE_WORDS_IN_LOCAL (local, words, frame); - ret = cli_cmd_gsync_set_parse (words, wordcount, &options); if (ret) { cli_usage_out (word->pattern); @@ -1419,13 +1341,12 @@ cli_cmd_volume_gsync_set_cbk (struct cli_state *state, struct cli_cmd_word *word goto out; } + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) ret = proc->fn (frame, THIS, options); out: - if (options) - dict_unref (options); - if (ret && parse_err == 0) cli_out (GEOREP" command failed"); @@ -1472,14 +1393,11 @@ cli_cmd_volume_status_cbk (struct cli_state *state, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); + CLI_LOCAL_INIT (local, words, frame, dict); ret = proc->fn (frame, THIS, dict); - out: - if (dict) - dict_unref (dict); - +out: CLI_STACK_DESTROY (frame); return ret; @@ -1680,8 +1598,6 @@ cli_cmd_volume_heal_cbk (struct cli_state *state, struct cli_cmd_word *word, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - if (wordcount < 3) { cli_usage_out (word->pattern); parse_error = 1; @@ -1697,6 +1613,8 @@ cli_cmd_volume_heal_cbk (struct cli_state *state, struct cli_cmd_word *word, proc = &cli_rpc_prog->proctable[GLUSTER_CLI_HEAL_VOLUME]; + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } @@ -1708,9 +1626,6 @@ out: cli_out ("Volume heal failed"); } - if (options) - dict_unref (options); - CLI_STACK_DESTROY (frame); return ret; @@ -1732,8 +1647,6 @@ cli_cmd_volume_statedump_cbk (struct cli_state *state, struct cli_cmd_word *word if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - if (wordcount < 3) { cli_usage_out (word->pattern); parse_error = 1; @@ -1757,6 +1670,9 @@ cli_cmd_volume_statedump_cbk (struct cli_state *state, struct cli_cmd_word *word goto out; proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATEDUMP_VOLUME]; + + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } @@ -1820,8 +1736,6 @@ cli_cmd_volume_clearlocks_cbk (struct cli_state *state, if (!frame) goto out; - SAVE_WORDS_IN_LOCAL (local, words, frame); - if (wordcount < 7 || wordcount > 8) { cli_usage_out (word->pattern); parse_error = 1; @@ -1846,6 +1760,9 @@ cli_cmd_volume_clearlocks_cbk (struct cli_state *state, goto out; proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CLRLOCKS_VOLUME]; + + CLI_LOCAL_INIT (local, words, frame, options); + if (proc->fn) { ret = proc->fn (frame, THIS, options); } diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 368a03cc0..104bca1ec 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -776,7 +776,6 @@ gf_cli_create_volume_cbk (struct rpc_req *req, struct iovec *iov, } local = ((call_frame_t *) (myframe))->local; - ((call_frame_t *) (myframe))->local = NULL; ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp); if (ret < 0) { @@ -814,10 +813,6 @@ gf_cli_create_volume_cbk (struct rpc_req *req, struct iovec *iov, out: cli_cmd_broadcast_response (ret); - if (dict) - dict_unref (dict); - if (local) - cli_local_wipe (local); free (rsp.dict.dict_val); free (rsp.op_errstr); return ret; @@ -846,7 +841,6 @@ gf_cli_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, frame = myframe; local = frame->local; - frame->local = NULL; if (local) dict = local->dict; @@ -882,10 +876,7 @@ gf_cli_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, out: cli_cmd_broadcast_response (ret); - cli_local_wipe (local); free (rsp.dict.dict_val); - if (dict) - dict_unref (dict); gf_log ("", GF_LOG_INFO, "Returning with %d", ret); return ret; @@ -914,10 +905,8 @@ gf_cli_start_volume_cbk (struct rpc_req *req, struct iovec *iov, frame = myframe; - if (frame) { + if (frame) local = frame->local; - frame->local = NULL; - } if (local) dict = local->dict; @@ -953,12 +942,8 @@ gf_cli_start_volume_cbk (struct rpc_req *req, struct iovec *iov, out: cli_cmd_broadcast_response (ret); - if (local) - cli_local_wipe (local); free (rsp.dict.dict_val); free (rsp.op_errstr); - if (dict) - dict_unref (dict); return ret; } @@ -985,10 +970,8 @@ gf_cli_stop_volume_cbk (struct rpc_req *req, struct iovec *iov, frame = myframe; - if (frame) { + if (frame) local = frame->local; - frame->local = NULL; - } if (local) { dict = local->dict; @@ -1026,8 +1009,6 @@ out: cli_cmd_broadcast_response (ret); free (rsp.op_errstr); free (rsp.dict.dict_val); - if (local) - cli_local_wipe (local); return ret; } @@ -1071,14 +1052,11 @@ gf_cli_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov, frame = myframe; - if (frame) { + if (frame) local = frame->local; - frame->local = NULL; - } - if (local) { + if (local) local_dict = local->dict; - } ret = dict_get_str (local_dict, "volname", &volname); if (ret) { @@ -1260,10 +1238,6 @@ out: free (rsp.dict.dict_val); //malloced by xdr if (dict) dict_unref (dict); - if (local_dict) - dict_unref (local_dict); - if (local) - cli_local_wipe (local); cli_cmd_broadcast_response (ret); return ret; } @@ -1424,6 +1398,8 @@ gf_cli_set_volume_cbk (struct rpc_req *req, struct iovec *iov, ret = rsp.op_ret; out: + if (dict) + dict_unref (dict); cli_cmd_broadcast_response (ret); return ret; } @@ -1722,14 +1698,6 @@ gf_cli_remove_brick_cbk (struct rpc_req *req, struct iovec *iov, ret = rsp.op_ret; out: - if (frame) - frame->local = NULL; - - if (local) { - dict_unref (local->dict); - cli_local_wipe (local); - } - cli_cmd_broadcast_response (ret); free (rsp.dict.dict_val); free (rsp.op_errstr); @@ -1889,14 +1857,6 @@ gf_cli_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, ret = rsp.op_ret; out: - if (frame) - frame->local = NULL; - - if (local) { - dict_unref (local->dict); - cli_local_wipe (local); - } - cli_cmd_broadcast_response (ret); free (rsp.dict.dict_val); if (rsp_dict) @@ -2237,6 +2197,8 @@ xml_output: ret = rsp.op_ret; out: cli_cmd_broadcast_response (ret); + if (dict) + dict_unref (dict); free (rsp.dict.dict_val); @@ -2543,7 +2505,7 @@ gf_cli_create_volume (call_frame_t *frame, xlator_t *this, goto out; } - dict = dict_ref ((dict_t *)data); + dict = data; ret = cli_to_glusterd (&req, frame, gf_cli_create_volume_cbk, (xdrproc_t) xdr_gf_cli_req, dict, @@ -2571,12 +2533,7 @@ gf_cli_delete_volume (call_frame_t *frame, xlator_t *this, goto out; } - dict = dict_new (); - ret = dict_set_str (dict, "volname", data); - if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, "dict set failed"); - goto out; - } + dict = data; ret = cli_to_glusterd (&req, frame, gf_cli_delete_volume_cbk, (xdrproc_t) xdr_gf_cli_req, dict, @@ -2648,11 +2605,7 @@ gf_cli_defrag_volume (call_frame_t *frame, xlator_t *this, { gf_cli_req req = {{0,}}; int ret = 0; - char *volname = NULL; - char *cmd_str = NULL; dict_t *dict = NULL; - gf_cli_defrag_type cmd = 0; - dict_t *req_dict = NULL; if (!frame || !this || !data) { ret = -1; @@ -2661,63 +2614,8 @@ gf_cli_defrag_volume (call_frame_t *frame, xlator_t *this, dict = data; - ret = dict_get_str (dict, "volname", &volname); - if (ret) - gf_log ("", GF_LOG_DEBUG, "error"); - - ret = dict_get_str (dict, "command", &cmd_str); - if (ret) { - gf_log ("", GF_LOG_DEBUG, "error"); - goto out; - } - - if (strcmp (cmd_str, "start") == 0) { - cmd = GF_DEFRAG_CMD_START; - ret = dict_get_str (dict, "option", &cmd_str); - if (!ret) { - if (strcmp (cmd_str, "force") == 0) { - cmd = GF_DEFRAG_CMD_START_FORCE; - } - } - goto done; - } - - if (strcmp (cmd_str, "fix-layout") == 0) { - cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX; - goto done; - } - if (strcmp (cmd_str, "stop") == 0) { - cmd = GF_DEFRAG_CMD_STOP; - goto done; - } - if (strcmp (cmd_str, "status") == 0) { - cmd = GF_DEFRAG_CMD_STATUS; - } - -done: - - req_dict = dict_new (); - if (!req_dict) { - ret = -1; - goto out; - } - - ret = dict_set_str (req_dict, "volname", volname); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "Failed to set dict"); - goto out; - } - - ret = dict_set_int32 (req_dict, "rebalance-command", (int32_t) cmd); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "Failed to set dict"); - goto out; - } - ret = cli_to_glusterd (&req, frame, gf_cli_defrag_volume_cbk, - (xdrproc_t) xdr_gf_cli_req, req_dict, + (xdrproc_t) xdr_gf_cli_req, dict, GLUSTER_CLI_DEFRAG_VOLUME, this, cli_rpc_prog, NULL); @@ -2840,7 +2738,6 @@ gf_cli_add_brick (call_frame_t *frame, xlator_t *this, if (ret) goto out; - ret = cli_to_glusterd (&req, frame, gf_cli_add_brick_cbk, (xdrproc_t) xdr_gf_cli_req, dict, GLUSTER_CLI_ADD_BRICK, this, cli_rpc_prog, NULL); @@ -2925,6 +2822,8 @@ gf_cli_remove_brick (call_frame_t *frame, xlator_t *this, } out: + if (req_dict) + dict_unref (req_dict); gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); GF_FREE (req.dict.dict_val); @@ -3019,7 +2918,6 @@ gf_cli_log_rotate (call_frame_t *frame, xlator_t *this, GLUSTER_CLI_LOG_ROTATE, this, cli_rpc_prog, NULL); - out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -3442,7 +3340,8 @@ gf_cli_gsync_set_cbk (struct rpc_req *req, struct iovec *iov, } out: - + if (dict) + dict_unref (dict); cli_cmd_broadcast_response (ret); free (rsp.dict.dict_val); @@ -5204,8 +5103,9 @@ gf_cli_status_cbk (struct rpc_req *req, struct iovec *iov, goto out; if ((cmd & GF_CLI_STATUS_ALL)) { - if (local) { - local->dict = dict; + if (local && local->dict) { + dict_ref (dict); + ret = dict_set_static_ptr (local->dict, "rsp-dict", dict); ret = 0; } else { gf_log ("cli", GF_LOG_ERROR, "local not found"); @@ -5352,6 +5252,8 @@ cont: ret = rsp.op_ret; out: + if (dict) + dict_unref (dict); GF_FREE (status.brick); cli_cmd_broadcast_response (ret); @@ -5389,27 +5291,29 @@ gf_cli_status_volume_all (call_frame_t *frame, xlator_t *this, void *data) uint32_t cmd = 0; char key[1024] = {0}; char *volname = NULL; - dict_t *vol_dict = NULL; + void *vol_dict = NULL; dict_t *dict = NULL; cli_local_t *local = NULL; - dict = (dict_t *)data; - ret = dict_get_uint32 (dict, "cmd", &cmd); - if (ret) - goto out; - if (frame->local) { local = frame->local; local->all = _gf_true; } + ret = dict_get_uint32 (local->dict, "cmd", &cmd); + if (ret) + goto out; + + ret = gf_cli_status_volume (frame, this, data); if (ret) goto out; - vol_dict = local->dict; + ret = dict_get_ptr (local->dict, "rsp-dict", &vol_dict); + if (ret) + goto out; - ret = dict_get_int32 (vol_dict, "vol_count", &vol_count); + ret = dict_get_int32 ((dict_t *)vol_dict, "vol_count", &vol_count); if (ret) { cli_err ("Failed to get names of volumes"); goto out; @@ -5437,7 +5341,7 @@ gf_cli_status_volume_all (call_frame_t *frame, xlator_t *this, void *data) if (ret) goto out; - ret = dict_set_dynstr (dict, "volname", volname); + ret = dict_set_str (dict, "volname", volname); if (ret) goto out; @@ -5455,10 +5359,12 @@ gf_cli_status_volume_all (call_frame_t *frame, xlator_t *this, void *data) out: if (ret) gf_log ("cli", GF_LOG_ERROR, "status all failed"); + + if (vol_dict) + dict_unref (vol_dict); + if (ret && dict) dict_unref (dict); - if (frame) - frame->local = NULL; return ret; } @@ -5673,10 +5579,8 @@ gf_cli_heal_volume_cbk (struct rpc_req *req, struct iovec *iov, frame = myframe; - if (frame) { + if (frame) local = frame->local; - frame->local = NULL; - } if (local) { input_dict = local->dict; @@ -5764,8 +5668,6 @@ gf_cli_heal_volume_cbk (struct rpc_req *req, struct iovec *iov, out: cli_cmd_broadcast_response (ret); - if (local) - cli_local_wipe (local); free (rsp.op_errstr); if (dict) dict_unref (dict); @@ -6029,6 +5931,8 @@ gf_cli_clearlocks_volume_cbk (struct rpc_req *req, struct iovec *iov, ret = rsp.op_ret; out: + if (dict) + dict_unref (dict); cli_cmd_broadcast_response (ret); return ret; } @@ -6088,7 +5992,6 @@ cli_to_glusterd (gf_cli_req *req, call_frame_t *frame, } words = local->words; - local->dict = dict_ref (dict); while (words[i]) len += strlen (words[i++]) + 1; @@ -6124,8 +6027,6 @@ cli_to_glusterd (gf_cli_req *req, call_frame_t *frame, cbkfn, (xdrproc_t) xdrproc); out: - if (dict) - dict_unref (dict); return ret; } diff --git a/cli/src/cli.h b/cli/src/cli.h index 0299220ce..7aa2148f4 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -273,6 +273,10 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, dict_t **options); int +cli_cmd_volume_defrag_parse (const char **words, int wordcount, + dict_t **options); + +int cli_print_brick_status (cli_volume_status_t *status); void |