diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 100 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 36 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 130 | ||||
-rw-r--r-- | cli/src/cli-xml-output.c | 106 | ||||
-rw-r--r-- | cli/src/cli.h | 4 |
5 files changed, 41 insertions, 335 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 99ef7014d2d..310c5f06033 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1891,44 +1891,36 @@ out: int32_t cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, - dict_t **options) + dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - int op_index = 0; - char *delimiter = NULL; - gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE; - char *opwords[] = { "start", "commit", "pause", "abort", "status", - NULL }; - char *w = NULL; - gf_boolean_t is_force = _gf_false; + int ret = -1; + char *volname = NULL; + char *delimiter = NULL; + dict_t *dict = NULL; GF_ASSERT (words); GF_ASSERT (options); - dict = dict_new (); - - if (!dict) + if (wordcount != 7) { + ret = -1; goto out; + } - if (wordcount < 3) + dict = dict_new (); + + if (!dict) { + gf_log ("cli", GF_LOG_ERROR, "Failed to allocate dictionary"); goto out; + } volname = (char *)words[2]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); - if (ret) goto out; - if (wordcount < 4) { - ret = -1; - goto out; - } - if (validate_brick_name ((char *)words[3])) { cli_err ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[3]); @@ -1940,16 +1932,11 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, if (ret) goto out; } - ret = dict_set_str (dict, "src-brick", (char *)words[3]); + ret = dict_set_str (dict, "src-brick", (char *)words[3]); if (ret) goto out; - if (wordcount < 5) { - ret = -1; - goto out; - } - if (validate_brick_name ((char *)words[4])) { cli_err ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[4]); @@ -1962,69 +1949,20 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "dst-brick", (char *)words[4]); - if (ret) goto out; - op_index = 5; - if ((wordcount < (op_index + 1))) { - ret = -1; - goto out; - } - - w = str_getunamb (words[op_index], opwords); - - if (!w) { - } else if (!strcmp ("start", w)) { - replace_op = GF_REPLACE_OP_START; - } else if (!strcmp ("commit", w)) { - replace_op = GF_REPLACE_OP_COMMIT; - } else if (!strcmp ("pause", w)) { - replace_op = GF_REPLACE_OP_PAUSE; - } else if (!strcmp ("abort", w)) { - replace_op = GF_REPLACE_OP_ABORT; - } else if (!strcmp ("status", w)) { - replace_op = GF_REPLACE_OP_STATUS; - } else - GF_ASSERT (!"opword mismatch"); - /* commit force option */ - - op_index = 6; - - if (wordcount > (op_index + 1)) { + if (strcmp ("commit", words[5]) || strcmp ("force", words[6])) { + cli_err ("Invalid option '%s' '%s' for replace-brick. Please " + "enter valid replace-brick command", words[5], + words[6]); ret = -1; goto out; } - if (wordcount == (op_index + 1)) { - if ((replace_op != GF_REPLACE_OP_COMMIT) && - (replace_op != GF_REPLACE_OP_START)) { - ret = -1; - goto out; - } - if (!strcmp ("force", words[op_index])) { - if (replace_op == GF_REPLACE_OP_COMMIT) - replace_op = GF_REPLACE_OP_COMMIT_FORCE; - - else if (replace_op == GF_REPLACE_OP_START) - is_force = _gf_true; - } - } - - if (replace_op == GF_REPLACE_OP_NONE) { - ret = -1; - goto out; - } - - ret = dict_set_int32 (dict, "operation", (int32_t) replace_op); - - if (ret) - goto out; - - ret = dict_set_int32 (dict, "force", is_force); + ret = dict_set_str (dict, "operation", "GF_REPLACE_OP_COMMIT_FORCE"); if (ret) goto out; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 0dfb647b92c..d121ac94739 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1655,18 +1655,13 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; + 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; + int sent = 0; + int parse_error = 0; cli_local_t *local = NULL; - int replace_op = 0; - char *q = "All replace-brick commands except " - "commit force are deprecated. " - "Do you want to continue?"; - gf_answer_t answer = GF_ANSWER_NO; #ifdef GF_SOLARIS_HOST_OS cli_out ("Command not supported on Solaris"); @@ -1686,24 +1681,6 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, goto out; } - ret = dict_get_int32 (options, "operation", &replace_op); - if (replace_op != GF_REPLACE_OP_COMMIT_FORCE) { - answer = cli_cmd_get_confirmation (state, q); - if (GF_ANSWER_NO == answer) { - ret = 0; - 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; - } - } - CLI_LOCAL_INIT (local, words, frame, options); if (proc->fn) { @@ -2604,7 +2581,8 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_defrag_cbk, "rebalance operations"}, - { "volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> {start [force]|pause|abort|status|commit [force]}", + { "volume replace-brick <VOLNAME> <SOURCE-BRICK> <NEW-BRICK> " + "{commit force}", cli_cmd_volume_replace_brick_cbk, "replace-brick operations"}, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 5504515fd5e..2b84aa6b060 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2316,8 +2316,6 @@ out: return ret; } - - int gf_cli_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) @@ -2330,11 +2328,11 @@ gf_cli_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, char *src_brick = NULL; char *dst_brick = NULL; char *status_reply = NULL; - gf1_cli_replace_op replace_op = 0; char *rb_operation_str = NULL; dict_t *rsp_dict = NULL; char msg[1024] = {0,}; char *task_id_str = NULL; + char *replace_op = 0; if (-1 == req->rpc_status) { goto out; @@ -2353,9 +2351,9 @@ gf_cli_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, GF_ASSERT (local); dict = local->dict; - ret = dict_get_int32 (dict, "operation", (int32_t *)&replace_op); + ret = dict_get_str (dict, "operation", &replace_op); if (ret) { - gf_log ("", GF_LOG_DEBUG, + gf_log (frame->this->name, GF_LOG_ERROR, "dict_get on operation failed"); goto out; } @@ -2368,101 +2366,23 @@ gf_cli_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, rsp.dict.dict_len, &rsp_dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize rsp buffer to dictionary"); + gf_log (frame->this->name, GF_LOG_ERROR, "failed to " + "unserialize rsp buffer to dictionary"); goto out; } } - switch (replace_op) { - case GF_REPLACE_OP_START: - if (rsp.op_ret) { - rb_operation_str = gf_strdup ("replace-brick failed to" - " start"); - } else { - ret = dict_get_str (rsp_dict, GF_REPLACE_BRICK_TID_KEY, - &task_id_str); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to get " - "\"replace-brick-id\" from dict"); - goto out; - } - ret = gf_asprintf (&rb_operation_str, - "replace-brick started successfully" - "\nID: %s", task_id_str); - if (ret < 0) - goto out; - } - break; - - case GF_REPLACE_OP_STATUS: - - if (rsp.op_ret || ret) { - rb_operation_str = gf_strdup ("replace-brick status " - "unknown"); - } else { - ret = dict_get_str (rsp_dict, "status-reply", - &status_reply); - if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, "failed to" - "get status"); - goto out; - } - - rb_operation_str = gf_strdup (status_reply); - } - - break; - - case GF_REPLACE_OP_PAUSE: - if (rsp.op_ret) - rb_operation_str = gf_strdup ("replace-brick pause " - "failed"); - else - rb_operation_str = gf_strdup ("replace-brick paused " - "successfully"); - break; - - case GF_REPLACE_OP_ABORT: - if (rsp.op_ret) - rb_operation_str = gf_strdup ("replace-brick abort " - "failed"); - else - rb_operation_str = gf_strdup ("replace-brick aborted " - "successfully"); - break; - - case GF_REPLACE_OP_COMMIT: - case GF_REPLACE_OP_COMMIT_FORCE: - ret = dict_get_str (dict, "src-brick", &src_brick); - if (ret) { - gf_log ("", GF_LOG_DEBUG, - "dict_get on src-brick failed"); - goto out; - } - - ret = dict_get_str (dict, "dst-brick", &dst_brick); - if (ret) { - gf_log ("", GF_LOG_DEBUG, - "dict_get on dst-brick failed"); - goto out; - } - + if (!strcmp(replace_op, "GF_REPLACE_OP_COMMIT_FORCE")) { if (rsp.op_ret || ret) rb_operation_str = gf_strdup ("replace-brick commit " - "failed"); + "force operation failed"); else rb_operation_str = gf_strdup ("replace-brick commit " + "force operation " "successful"); - - break; - - default: - gf_log ("", GF_LOG_DEBUG, - "Unknown operation"); - break; + } else { + gf_log (frame->this->name, GF_LOG_DEBUG, "Unknown operation"); } if (rsp.op_ret && (strcmp (rsp.op_errstr, ""))) { @@ -6928,35 +6848,7 @@ cli_print_volume_status_tasks (dict_t *dict) snprintf (task, sizeof (task), "task%d", i); - /* - Replace brick only has two states - In progress and Complete - Ref: xlators/mgmt/glusterd/src/glusterd-replace-brick.c - */ - - if (!strcmp (op, "Replace brick")) { - if (status) - status = GF_DEFRAG_STATUS_COMPLETE; - else - status = GF_DEFRAG_STATUS_STARTED; - - memset (key, 0, sizeof (key)); - snprintf (key, sizeof (key), "%s.src-brick", task); - ret = dict_get_str (dict, key, &src_brick); - if (ret) - goto out; - - cli_out ("%-20s : %-20s", "Source Brick", src_brick); - - memset (key, 0, sizeof (key)); - snprintf (key, sizeof (key), "%s.dst-brick", task); - ret = dict_get_str (dict, key, &dest_brick); - if (ret) - goto out; - - cli_out ("%-20s : %-20s", "Destination Brick", - dest_brick); - - } else if (!strcmp (op, "Remove brick")) { + if (!strcmp (op, "Remove brick")) { memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "%s.count", task); ret = dict_get_int32 (dict, key, &count); diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index d7322d5bb0d..f9013ed2726 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -1480,46 +1480,6 @@ out: } int -cli_xml_output_replace_brick_task_params (xmlTextWriterPtr writer, dict_t *dict, - char *prefix) -{ - - int ret = -1; - char key[1024] = {0,}; - char *brick = NULL; - - /* <params> */ - ret = xmlTextWriterStartElement (writer, (xmlChar *)"params"); - XML_RET_CHECK_AND_GOTO (ret, out); - - snprintf (key, sizeof (key), "%s.src-brick", prefix); - ret = dict_get_str (dict, key, &brick); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"srcBrick", - "%s", brick); - XML_RET_CHECK_AND_GOTO (ret, out); - - - memset (key, 0, sizeof (key)); - snprintf (key, sizeof (key), "%s.dst-brick", prefix); - ret = dict_get_str (dict, key, &brick); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"dstBrick", - "%s", brick); - XML_RET_CHECK_AND_GOTO (ret, out); - - - /* </param> */ - ret = xmlTextWriterEndElement (writer); - -out: - gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); - return ret; -} - -int cli_xml_output_vol_status_tasks (cli_local_t *local, dict_t *dict) { int ret = -1; char *task_type = NULL; @@ -1573,14 +1533,6 @@ cli_xml_output_vol_status_tasks (cli_local_t *local, dict_t *dict) { "%d", status); XML_RET_CHECK_AND_GOTO (ret, out); - if (!strcmp (task_type, "Replace brick")) { - if (status) { - status = GF_DEFRAG_STATUS_COMPLETE; - } else { - status = GF_DEFRAG_STATUS_STARTED; - } - } - ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"statusStr", "%s", @@ -1590,12 +1542,7 @@ cli_xml_output_vol_status_tasks (cli_local_t *local, dict_t *dict) { memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "task%d", i); - if (!strcmp (task_type, "Replace brick")) { - ret = cli_xml_output_replace_brick_task_params - (local->writer, dict, key); - if (ret) - goto out; - } else if (!strcmp (task_type, "Remove brick")) { + if (!strcmp (task_type, "Remove brick")) { ret = cli_xml_output_remove_brick_task_params (local->writer, dict, key); if (ret) @@ -3476,7 +3423,7 @@ out: } int -cli_xml_output_vol_replace_brick (gf1_cli_replace_op op, dict_t *dict, +cli_xml_output_vol_replace_brick (char *op, dict_t *dict, int op_ret, int op_errno, char *op_errstr) { #if (HAVE_LIB_XML) @@ -3496,55 +3443,6 @@ cli_xml_output_vol_replace_brick (gf1_cli_replace_op op, dict_t *dict, if (ret) goto out; - /* <volReplaceBrick> */ - ret = xmlTextWriterStartElement (writer, (xmlChar *)"volReplaceBrick"); - XML_RET_CHECK_AND_GOTO (ret, out); - - ret = dict_get_str (dict, GF_REPLACE_BRICK_TID_KEY, &task_id_str); - if (ret == 0) { - ret = xmlTextWriterWriteFormatElement (writer, - (xmlChar *)"task-id", - "%s", task_id_str); - XML_RET_CHECK_AND_GOTO (ret, out); - } - - ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"op", - "%d", op); - XML_RET_CHECK_AND_GOTO (ret, out); - - if (GF_REPLACE_OP_STATUS == op) { - ret = dict_get_int32 (dict, "status", &status); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, - (xmlChar *)"status", - "%d", status); - XML_RET_CHECK_AND_GOTO (ret, out); - - ret = dict_get_uint64 (dict, "files", &files); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, - (xmlChar *)"files", - "%"PRIu64, files); - XML_RET_CHECK_AND_GOTO (ret, out); - - if (status) - goto cont; - - ret = dict_get_str (dict, "current_file", ¤t_file); - if (ret) - goto out; - ret = xmlTextWriterWriteFormatElement (writer, - (xmlChar *)"currentFile", - "%s", current_file); - XML_RET_CHECK_AND_GOTO (ret, out); - } -cont: - /* </volReplaceBrick> */ - ret = xmlTextWriterEndElement (writer); - XML_RET_CHECK_AND_GOTO (ret, out); - ret = cli_end_xml_output (writer, doc); out: diff --git a/cli/src/cli.h b/cli/src/cli.h index 27558a7830c..3da58dd22d8 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -407,8 +407,8 @@ cli_xml_output_vol_remove_brick (gf_boolean_t status_op, dict_t *dict, int op_ret, int op_errno, char *op_errstr); int -cli_xml_output_vol_replace_brick (gf1_cli_replace_op op, dict_t *dict, - int op_ret, int op_errno, char *op_errstr); +cli_xml_output_vol_replace_brick (char *op, dict_t *dict, int op_ret, + int op_errno, char *op_errstr); int cli_xml_output_vol_create (dict_t *dict, int op_ret, int op_errno, |