diff options
-rw-r--r-- | cli/src/cli-cmd-peer.c | 36 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 211 | ||||
-rw-r--r-- | cli/src/cli-cmd.c | 35 | ||||
-rw-r--r-- | cli/src/cli-cmd.h | 1 | ||||
-rw-r--r-- | cli/src/cli3_1-cops.c | 104 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 12 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.c | 4 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.h | 1 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.x | 1 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 13 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 289 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 8 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 1 | ||||
-rw-r--r-- | xlators/protocol/server/src/server.c | 14 |
14 files changed, 505 insertions, 225 deletions
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index dc361f539..ca89592d6 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -48,9 +48,12 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; if (!(wordcount == 3)) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -79,8 +82,11 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("Probe failed"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer probe failed"); + } return ret; } @@ -93,9 +99,12 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; if (!(wordcount == 3) ) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -122,6 +131,12 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer detach failed"); + } + return ret; } @@ -132,9 +147,12 @@ cli_cmd_peer_status_cbk (struct cli_state *state, struct cli_cmd_word *word, int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; + int sent = 0; + int parse_error = 0; if (wordcount != 2) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -149,8 +167,11 @@ cli_cmd_peer_status_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("Command Execution failed"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Peer status failed"); + } return ret; } @@ -166,11 +187,10 @@ struct cli_cmd cli_probe_cmds[] = { { "peer status", cli_cmd_peer_status_cbk, "list status of peers"}, - - { "peer help", - cli_cmd_peer_help_cbk, - "Help command for peer "}, + { "peer help", + cli_cmd_peer_help_cbk, + "Help command for peer "}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 3f671a63a..0b6e2dd36 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -50,6 +50,8 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, call_frame_t *frame = NULL; cli_cmd_volume_get_ctx_t ctx = {0,}; cli_local_t *local = NULL; + int sent = 0; + int parse_error = 0; proc = &cli_rpc_prog->proctable[GF1_CLI_GET_VOLUME]; @@ -71,6 +73,7 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, proc = &cli_rpc_prog->proctable[GF1_CLI_GET_VOLUME]; } else { cli_usage_out (word->pattern); + parse_error = 1; return -1; } @@ -90,8 +93,12 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("Getting Volume information failed!"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Getting Volume information failed!"); + } + return ret; } @@ -104,10 +111,13 @@ cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; gf1_cli_sync_volume_req req = {0,}; + int sent = 0; + int parse_error = 0; if ((wordcount < 3) || (wordcount > 4)) { - cli_usage_out (word->pattern); - goto out; + cli_usage_out (word->pattern); + parse_error = 1; + goto out; } if ((wordcount == 3) || !strcmp(words[3], "all")) { @@ -130,8 +140,11 @@ cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("Volume sync failed"); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume sync failed"); + } return ret; } @@ -144,6 +157,8 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; proc = &cli_rpc_prog->proctable[GF1_CLI_CREATE_VOLUME]; @@ -155,6 +170,7 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -165,6 +181,11 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, out: if (options) dict_unref (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume create failed"); + } return ret; } @@ -179,9 +200,12 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, call_frame_t *frame = NULL; char *volname = NULL; gf_answer_t answer = GF_ANSWER_NO; - const char *question = "Deleting volume will erase all information about the volume." - "Do you want to continue?"; + const char *question = NULL; + int sent = 0; + int parse_error = 0; + question = "Deleting volume will erase all information about the volume." + "Do you want to continue?"; proc = &cli_rpc_prog->proctable[GF1_CLI_DELETE_VOLUME]; frame = create_frame (THIS, THIS->ctx->pool); @@ -190,6 +214,7 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, if (wordcount != 3) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -207,8 +232,11 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret && volname) - cli_out ("Deleting Volume %s failed", volname); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume delete failed"); + } return ret; } @@ -221,6 +249,8 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; gf1_cli_start_vol_req req = {0,}; + int sent = 0; + int parse_error = 0; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -228,6 +258,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, if (wordcount < 3 || wordcount > 4) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -241,6 +272,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, } else { ret = -1; cli_usage_out (word->pattern); + parse_error = 1; goto out; } } @@ -252,8 +284,11 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (!proc && ret && req.volname) - cli_out ("Starting Volume %s failed", req.volname); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume start failed"); + } return ret; } @@ -307,6 +342,8 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, int flags = 0; gf1_cli_stop_vol_req req = {0,}; gf_answer_t answer = GF_ANSWER_NO; + int sent = 0; + int parse_error = 0; const char *question = "Stopping volume will make its data inaccessible. " "Do you want to Continue?"; @@ -316,8 +353,9 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; if (wordcount < 3 || wordcount > 4) { - cli_usage_out (word->pattern); - goto out; + cli_usage_out (word->pattern); + parse_error = 1; + goto out; } req.volname = (char *)words[2]; @@ -330,6 +368,7 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, } else { ret = -1; cli_usage_out (word->pattern); + parse_error = 1; goto out; } } @@ -349,8 +388,11 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (!proc && ret && req.volname) - cli_out ("Stopping Volume %s failed", req.volname); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume stop failed", req.volname); + } return ret; } @@ -364,6 +406,8 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; frame = create_frame (THIS, THIS->ctx->pool); @@ -376,6 +420,7 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, if (wordcount != 4) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -396,11 +441,13 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (!proc && ret) { - if (dict) - dict_destroy (dict); - if (wordcount > 2) - cli_out ("Renaming Volume %s failed", (char *)words[2]); + if (dict) + dict_destroy (dict); + + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume rename failed", (char *)words[2]); } return ret; @@ -414,6 +461,8 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -425,6 +474,7 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, if (wordcount != 4) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -443,22 +493,24 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (!proc && ret) { - if (dict) - dict_destroy (dict); + if (dict) + dict_destroy (dict); - if (wordcount > 2) - cli_out ("Rebalance of Volume %s failed", - (char *)words[2]); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume rebalance failed"); } - return 0; + return ret; } int -cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, +cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { + int sent = 0; + int parse_error = 0; int ret = -1; rpc_clnt_procedure_t *proc = NULL; @@ -475,6 +527,7 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -483,9 +536,15 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (options) + if (options) dict_unref (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume reset failed"); + } + return ret; } @@ -495,6 +554,8 @@ int cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { + int sent = 0; + int parse_error = 0; int ret = -1; rpc_clnt_procedure_t *proc = NULL; @@ -511,6 +572,7 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -522,6 +584,12 @@ out: if (options) dict_unref (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume set failed"); + } + return ret; } @@ -535,6 +603,8 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -544,6 +614,7 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -554,14 +625,15 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, } out: - if (!proc && ret) { - if (wordcount > 2) { - char *volname = (char *) words[2]; - cli_out ("Adding brick to Volume %s failed",volname ); - } - } if (options) dict_unref (options); + + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume add-brick failed"); + } + return ret; } @@ -576,6 +648,8 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, call_frame_t *frame = NULL; dict_t *options = NULL; gf_answer_t answer = GF_ANSWER_NO; + int sent = 0; + int parse_error = 0; const char *question = "Removing brick(s) can result in data loss. " "Do you want to Continue?"; @@ -588,6 +662,7 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -605,12 +680,12 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, } out: - if (!proc && ret) { - if (wordcount > 2) { - char *volname = (char *) words[2]; - cli_out ("Removing brick from Volume %s failed",volname ); - } + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume remove-brick failed"); } + if (options) dict_unref (options); return ret; @@ -627,6 +702,8 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; proc = &cli_rpc_prog->proctable[GF1_CLI_REPLACE_BRICK]; @@ -638,6 +715,7 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, if (ret) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -646,14 +724,16 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, } out: + if (options) + dict_unref (options); + if (ret) { - if (wordcount > 2) { - char *volname = (char *) words[2]; - cli_out ("Replacing brick from Volume %s failed",volname ); - } + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume replace-brick failed"); } - return ret; + return ret; } @@ -674,9 +754,12 @@ cli_cmd_log_filename_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; if (!((wordcount == 5) || (wordcount == 6))) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -695,12 +778,15 @@ cli_cmd_log_filename_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("setting log filename failed"); - if (options) dict_destroy (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume log filename failed"); + } + return ret; } @@ -713,9 +799,12 @@ cli_cmd_log_locate_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; if (!((wordcount == 4) || (wordcount == 5))) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -734,12 +823,14 @@ cli_cmd_log_locate_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("getting log file location information failed"); - if (options) dict_destroy (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("getting log file location information failed"); + } return ret; } @@ -752,9 +843,12 @@ cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; + int sent = 0; + int parse_error = 0; if (!((wordcount == 4) || (wordcount == 5))) { cli_usage_out (word->pattern); + parse_error = 1; goto out; } @@ -773,12 +867,15 @@ cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) - cli_out ("log rotate failed"); - if (options) dict_destroy (options); + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out ("Volume log rotate failed"); + } + return ret; } @@ -851,10 +948,10 @@ struct cli_cmd volume_cmds[] = { { "volume sync <HOSTNAME> [all|<VOLNAME>]", cli_cmd_sync_volume_cbk, "sync the volume information from a peer"}, - + { "volume reset <VOLNAME> ", cli_cmd_volume_reset_cbk, - "reset all the reconfigured options"}, + "reset all the reconfigured options"}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index f09c62106..2b9aea191 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -60,6 +60,38 @@ cli_cmd_needs_connection (struct cli_cmd_word *word) } int +cli_cmd_status_reset (void) +{ + int ret = 0; + + ret = cli_cmd_lock (); + { + if (ret == 0) { + cmd_sent = 0; + cmd_done = 0; + } + } + ret = cli_cmd_unlock (); + return ret; + +} + +int +cli_cmd_sent_status_get (int *status) +{ + int ret = 0; + GF_ASSERT (status); + + ret = cli_cmd_lock (); + { + if (ret == 0) + *status = cmd_sent; + } + ret = cli_cmd_unlock (); + return ret; +} + +int cli_cmd_process (struct cli_state *state, int argc, char **argv) { int ret = 0; @@ -112,11 +144,10 @@ cli_cmd_process (struct cli_state *state, int argc, char **argv) callback: ret = word->cbkfn (state, word, (const char **)argv, argc); - + (void) cli_cmd_status_reset (); return ret; } - int cli_cmd_input_token_count (const char *text) { diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index 1655c3a31..4daf7fae3 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -76,4 +76,5 @@ cli_cmd_submit (void *req, call_frame_t *frame, gf_answer_t cli_cmd_get_confirmation (struct cli_state *state, const char *question); +int cli_cmd_sent_status_get (int *status); #endif /* __CLI_CMD_H__ */ diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index ba780e993..3003469cb 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -133,11 +133,10 @@ gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov, break; default: - cli_out ("Probe returned with unknown errno %d", - rsp.op_errno); + cli_out ("Probe unsuccessful\nProbe returned " + "with unknown errno %d", rsp.op_errno); break; } - cli_out ("Probe unsuccessful"); gf_log ("glusterd",GF_LOG_ERROR,"Probe failed with op_ret %d" " and op_errno %d", rsp.op_ret, rsp.op_errno); } @@ -183,11 +182,11 @@ gf_cli3_1_deprobe_cbk (struct rpc_req *req, struct iovec *iov, "cluster", rsp.hostname); break; default: - cli_out ("Detach returned with unknown errno %d", + cli_out ("Detach unsuccessful\nDetach returned " + "with unknown errno %d", rsp.op_errno); break; } - cli_out ("Detach unsuccessful"); gf_log ("glusterd",GF_LOG_ERROR,"Detach failed with op_ret %d" " and op_errno %d", rsp.op_ret, rsp.op_errno); } else { @@ -606,13 +605,13 @@ gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov, ret = dict_get_str (dict, "volname", &volname); gf_log ("cli", GF_LOG_NORMAL, "Received resp to create volume"); - cli_out ("Creation of volume %s has been %s", volname, - (rsp.op_ret) ? "unsuccessful": - "successful. Please start the volume to " - "access data."); - if (rsp.op_ret && rsp.op_errstr) - cli_out ("%s", rsp.op_errstr); - + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) + cli_out ("%s", rsp.op_errstr); + else + cli_out ("Creation of volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": + "successful. Please start the volume to " + "access data."); ret = rsp.op_ret; out: @@ -657,9 +656,12 @@ gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to delete volume"); - cli_out ("Deleting volume %s has been %s", volname, - (rsp.op_ret) ? "unsuccessful": "successful"); + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) + cli_out (rsp.op_errstr); + else + cli_out ("Deleting volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); ret = rsp.op_ret; out: @@ -702,11 +704,12 @@ gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov, volname = local->u.start_vol.volname; gf_log ("cli", GF_LOG_NORMAL, "Received resp to start volume"); - cli_out ("Starting volume %s has been %s", volname, - (rsp.op_ret) ? "unsuccessful": "successful"); - if (rsp.op_ret && rsp.op_errstr) + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out ("%s", rsp.op_errstr); + else + cli_out ("Starting volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); ret = rsp.op_ret; @@ -750,12 +753,12 @@ gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov, volname = local->u.start_vol.volname; gf_log ("cli", GF_LOG_NORMAL, "Received resp to stop volume"); - cli_out ("Stopping volume %s has been %s", volname, - (rsp.op_ret) ? "unsuccessful": "successful"); - - if (rsp.op_ret && rsp.op_errstr) - cli_out ("%s", rsp.op_errstr); + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) + cli_out (rsp.op_errstr); + else + cli_out ("Stopping volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); ret = rsp.op_ret; out: @@ -901,11 +904,12 @@ gf_cli3_1_reset_volume_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_NORMAL, "Received resp to reset"); - cli_out ("reset volume %s", (rsp.op_ret) ? "unsuccessful": - "successful"); - if (rsp.op_ret && rsp.op_errstr) + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out ("%s", rsp.op_errstr); + else + cli_out ("reset volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); ret = rsp.op_ret; @@ -917,7 +921,7 @@ out: void _cli_out_options (dict_t *this, char *key, data_t *value, void *count) { - + (*((int *) count))++; cli_out ("%s - %s", key, value->data); } @@ -940,7 +944,7 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("", GF_LOG_ERROR, "error"); goto out; } - + if (rsp.op_ret == 1) { // if the command was volume set <vol> history if (!rsp.dict.dict_len) { @@ -975,11 +979,12 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); - cli_out ("Set volume %s", (rsp.op_ret) ? "unsuccessful": - "successful"); - - if (rsp.op_ret && rsp.op_errstr) + + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out ("%s", rsp.op_errstr); + else + cli_out ("Set volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); ret = rsp.op_ret; @@ -1007,11 +1012,12 @@ gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to add brick"); - cli_out ("Add Brick %s", (rsp.op_ret) ? "unsuccessful": - "successful"); - if (rsp.op_ret && rsp.op_errstr) + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out ("%s", rsp.op_errstr); + else + cli_out ("Add Brick %s", (rsp.op_ret) ? "unsuccessful": + "successful"); ret = rsp.op_ret; out: @@ -1042,10 +1048,12 @@ gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick"); - cli_out ("Remove Brick %s", (rsp.op_ret) ? "unsuccessful": - "successful"); - if (rsp.op_ret && rsp.op_errstr) + + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out ("%s", rsp.op_errstr); + else + cli_out ("Remove Brick %s", (rsp.op_ret) ? "unsuccessful": + "successful"); ret = rsp.op_ret; @@ -1199,8 +1207,12 @@ gf_cli3_1_log_filename_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_DEBUG, "Received resp to log filename"); - cli_out ("log filename : %s", - (rsp.op_ret) ? "unsuccessful": "successful"); + + if (rsp.op_ret && strcmp (rsp.errstr, "")) + cli_out (rsp.errstr); + else + cli_out ("log filename : %s", + (rsp.op_ret) ? "unsuccessful": "successful"); ret = rsp.op_ret; @@ -1254,7 +1266,12 @@ gf_cli3_1_log_rotate_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_DEBUG, "Received resp to log rotate"); - cli_out ("log rotate %s", (rsp.op_ret) ? "unsuccessful": "successful"); + + if (rsp.op_ret && strcmp (rsp.errstr, "")) + cli_out (rsp.errstr); + else + cli_out ("log rotate %s", (rsp.op_ret) ? "unsuccessful": + "successful"); ret = rsp.op_ret; @@ -1281,11 +1298,12 @@ gf_cli3_1_sync_volume_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_DEBUG, "Received resp to sync"); - cli_out ("volume sync: %s", - (rsp.op_ret) ? "unsuccessful": "successful"); - if (rsp.op_ret && rsp.op_errstr) + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) cli_out (rsp.op_errstr); + else + cli_out ("volume sync: %s", + (rsp.op_ret) ? "unsuccessful": "successful"); ret = rsp.op_ret; out: diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index dcdf40f71..67ee32874 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -993,7 +993,7 @@ int xlator_validate_rec (xlator_t *xlator, char **op_errstr) { xlator_list_t *trav = NULL; - + if (xlator == NULL ) { gf_log ("xlator", GF_LOG_DEBUG, "invalid argument"); return -1; @@ -1007,27 +1007,27 @@ xlator_validate_rec (xlator_t *xlator, char **op_errstr) trav = trav->next; } - + if (xlator_dynload (xlator)) gf_log ("", GF_LOG_DEBUG, "Did not load the symbols"); if (xlator->validate_options) { - if (xlator->validate_options (xlator, xlator->options, + if (xlator->validate_options (xlator, xlator->options, op_errstr)) { gf_log ("", GF_LOG_DEBUG, *op_errstr); return -1; } gf_log (xlator->name, GF_LOG_DEBUG, "Validated option"); - + } - + gf_log (xlator->name, GF_LOG_DEBUG, "No validate_options() found"); return 0; } int -graph_reconf_validateopt (glusterfs_graph_t *graph, +graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr) { xlator_t *xlator = NULL; diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index aff0edc35..084aa8b7b 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -94,7 +94,7 @@ xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp) bool_t xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp) { - register int32_t *buf; + register int32_t *buf; if (xdrs->x_op == XDR_ENCODE) { @@ -267,6 +267,8 @@ xdr_gf1_cli_delete_vol_rsp (XDR *xdrs, gf1_cli_delete_vol_rsp *objp) return FALSE; if (!xdr_string (xdrs, &objp->volname, ~0)) return FALSE; + if (!xdr_string (xdrs, &objp->op_errstr, ~0)) + return FALSE; return TRUE; } diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index 5611f283d..c2ccb3237 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -167,6 +167,7 @@ struct gf1_cli_delete_vol_rsp { int op_ret; int op_errno; char *volname; + char *op_errstr; }; typedef struct gf1_cli_delete_vol_rsp gf1_cli_delete_vol_rsp; diff --git a/rpc/xdr/src/cli1.x b/rpc/xdr/src/cli1.x index 6c9f70dff..4a0bd7163 100644 --- a/rpc/xdr/src/cli1.x +++ b/rpc/xdr/src/cli1.x @@ -99,6 +99,7 @@ struct gf1_cli_get_vol_rsp { int op_ret; int op_errno; string volname<>; + string op_errstr<>; } ; struct gf1_cli_start_vol_req { diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index ab0a6831f..42b0efcd5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -133,7 +133,6 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, event->ctx = ctx; ret = glusterd_friend_sm_inject_event (event); - if (ret) { gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); @@ -810,8 +809,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) gf_cmd_log ("Volume create", "on volname: %s attempted", volname); if ((ret = glusterd_check_volume_exists (volname))) { - snprintf(err_str, 2048, "Volname %s already exists", - volname); + snprintf(err_str, 2048, "Volume %s already exists", volname); gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); err_ret = 1; goto out; @@ -1074,8 +1072,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) } if (!(ret = glusterd_check_volume_exists (volname))) { - snprintf(err_str, 2048, "Volname %s does not exist", - volname); + snprintf(err_str, 2048, "Volume %s does not exist", volname); gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); err_ret = -1; goto out; @@ -1338,7 +1335,7 @@ glusterd_handle_reset_volume (rpcsvc_request_t *req) ret = glusterd_reset_volume (req, dict); out: - if (cli_req.volname) + if (cli_req.volname) free (cli_req.volname);//malloced by xdr return ret; @@ -1454,7 +1451,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) ret = glusterd_volinfo_find (cli_req.volname, &volinfo); if (ret) { - snprintf (err_str, 2048, "volname %s not found", + snprintf (err_str, 2048, "Volume %s does not exist", cli_req.volname); gf_log ("", GF_LOG_ERROR, "%s", err_str); err_ret = 1; @@ -1514,7 +1511,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) ret = glusterd_volume_brickinfo_get_by_brick(brick, volinfo, &brickinfo); if (ret) { - snprintf(err_str, 2048," Incorrect brick %s for volname" + snprintf(err_str, 2048," Incorrect brick %s for volume" " %s", brick, cli_req.volname); gf_log ("", GF_LOG_ERROR, "%s", err_str); err_ret = 1; diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index b2f247a06..f0336c7b1 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -332,6 +332,7 @@ glusterd_op_stage_create_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) char cmd_str[1024]; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; + char msg[2048] = {0}; GF_ASSERT (req); @@ -370,9 +371,12 @@ glusterd_op_stage_create_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) exists = glusterd_check_volume_exists (volname); if (exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s exists", - volname); + snprintf (msg, sizeof (msg), "Volume %s already exists", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; + goto out; } else { ret = 0; } @@ -504,7 +508,7 @@ glusterd_op_stage_start_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) exists = glusterd_check_volume_exists (volname); if (!exists) { - snprintf (msg, 2048, "Volume with name %s does not exist", volname); + snprintf (msg, 2048, "Volume %s does not exist", volname); gf_log ("", GF_LOG_ERROR, "%s", msg); *op_errstr = gf_strdup (msg); @@ -521,9 +525,9 @@ glusterd_op_stage_start_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { ret = glusterd_resolve_brick (brickinfo); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to resolve brick" - " with hostname: %s, export: %s", - brickinfo->hostname,brickinfo->path); + gf_log ("", GF_LOG_ERROR, + "Unable to resolve brick %s:%s", + brickinfo->hostname, brickinfo->path); goto out; } @@ -567,7 +571,7 @@ glusterd_op_stage_stop_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) int flags = 0; gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; - char msg[2048] = {0,}; + char msg[2048] = {0}; dict = dict_new (); if (!dict) @@ -580,11 +584,11 @@ glusterd_op_stage_stop_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) exists = glusterd_check_volume_exists (volname); if (!exists) { - snprintf (msg, 2048, "Volume with name %s does not exist", volname); - gf_log ("", GF_LOG_ERROR, "%s", - msg); + snprintf (msg, sizeof (msg), "Volume %s does not exist", volname); + gf_log ("", GF_LOG_ERROR, msg); *op_errstr = gf_strdup (msg); ret = -1; + goto out; } else { ret = 0; } @@ -618,12 +622,13 @@ out: } static int -glusterd_op_stage_delete_volume (gd1_mgmt_stage_op_req *req) +glusterd_op_stage_delete_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) { int ret = 0; char volname [1024] = {0,}; gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; + char msg[2048] = {0}; GF_ASSERT (req); @@ -632,8 +637,10 @@ glusterd_op_stage_delete_volume (gd1_mgmt_stage_op_req *req) exists = glusterd_check_volume_exists (volname); if (!exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name %s does not exist", - volname); + snprintf (msg, sizeof (msg), "Volume %s does not exist", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; goto out; } else { @@ -648,9 +655,11 @@ glusterd_op_stage_delete_volume (gd1_mgmt_stage_op_req *req) ret = glusterd_is_volume_started (volinfo); if (!ret) { - gf_log ("", GF_LOG_ERROR, "Volume %s has been started." - "Volume needs to be stopped before deletion.", - volname); + snprintf (msg, sizeof (msg), "Volume %s has been started." + "Volume needs to be stopped before deletion.", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; goto out; } @@ -769,7 +778,7 @@ glusterd_op_stage_add_brick (gd1_mgmt_stage_op_req *req, char **op_errstr) ret = glusterd_brickinfo_from_brick (brick, &brickinfo); if (ret) { gf_log ("", GF_LOG_ERROR, "Add-brick: Unable" - " to get brickinfo"); + " to get brickinfo"); goto out; } brick_alloc = _gf_true; @@ -992,8 +1001,8 @@ glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req, char **op_errstr, break; case GF_REPLACE_OP_PAUSE: if (glusterd_is_rb_paused (volinfo)) { - gf_log ("", GF_LOG_ERROR, "Replace brick is already" - " paused for volume "); + gf_log ("", GF_LOG_ERROR, "Replace brick is already " + "paused for volume "); ret = -1; goto out; } else if (!glusterd_is_rb_started(volinfo)) { @@ -1032,7 +1041,7 @@ glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req, char **op_errstr, } ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo, - &src_brickinfo); + &src_brickinfo); if (ret) { snprintf (msg, sizeof (msg), "brick: %s does not exist in " "volume: %s", src_brick, volname); @@ -1136,12 +1145,17 @@ out: } static int -glusterd_op_stage_log_filename (gd1_mgmt_stage_op_req *req) +glusterd_op_stage_log_filename (gd1_mgmt_stage_op_req *req, char **op_errstr) { int ret = -1; dict_t *dict = NULL; char *volname = NULL; gf_boolean_t exists = _gf_false; + char msg[2048] = {0}; + char *path = NULL; + char hostname[2048] = {0}; + char *brick = NULL; + glusterd_volinfo_t *volinfo = NULL; GF_ASSERT (req); @@ -1162,13 +1176,50 @@ glusterd_op_stage_log_filename (gd1_mgmt_stage_op_req *req) } exists = glusterd_check_volume_exists (volname); - if (!exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s not exists", - volname); + ret = glusterd_volinfo_find (volname, &volinfo); + if (!exists || ret) { + snprintf (msg, sizeof (msg), "Volume %s does not exist", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; goto out; } + ret = dict_get_str (dict, "brick", &brick); + if (ret) + goto out; + + if (strchr (brick, ':')) { + ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, + NULL); + if (ret) { + snprintf (msg, sizeof (msg), "Incorrect brick %s " + "for volume %s", brick, volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); + goto out; + } + } + + ret = dict_get_str (dict, "path", &path); + if (ret) { + gf_log ("", GF_LOG_ERROR, "path not found"); + goto out; + } + + ret = gethostname (hostname, sizeof (hostname)); + if (ret) { + snprintf (msg, sizeof (msg), "Failed to get hostname, error:%s", + strerror (errno)); + gf_log ("glusterd", GF_LOG_ERROR, "%s"); + *op_errstr = gf_strdup (msg); + goto out; + } + + ret = glusterd_brick_create_path (hostname, path, 0777, op_errstr); + if (ret) + goto out; out: if (dict) dict_unref (dict); @@ -1178,12 +1229,15 @@ out: } static int -glusterd_op_stage_log_rotate (gd1_mgmt_stage_op_req *req) +glusterd_op_stage_log_rotate (gd1_mgmt_stage_op_req *req, char **op_errstr) { int ret = -1; dict_t *dict = NULL; char *volname = NULL; + glusterd_volinfo_t *volinfo = NULL; gf_boolean_t exists = _gf_false; + char msg[2048] = {0}; + char *brick = NULL; GF_ASSERT (req); @@ -1204,13 +1258,42 @@ glusterd_op_stage_log_rotate (gd1_mgmt_stage_op_req *req) } exists = glusterd_check_volume_exists (volname); + ret = glusterd_volinfo_find (volname, &volinfo); if (!exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s not exists", - volname); + snprintf (msg, sizeof (msg), "Volume %s does not exist", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); + ret = -1; + goto out; + } + + ret = glusterd_is_volume_started (volinfo); + + if (ret) { + snprintf (msg, sizeof (msg), "Volume %s needs to be started before" + " log rotate.", volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; goto out; } + ret = dict_get_str (dict, "brick", &brick); + if (ret) + goto out; + + if (strchr (brick, ':')) { + ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, + NULL); + if (ret) { + snprintf (msg, sizeof (msg), "Incorrect brick %s " + "for volume %s", brick, volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); + goto out; + } + } out: if (dict) dict_unref (dict); @@ -1235,9 +1318,9 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) char errstr[2048] = {0, }; glusterd_volinfo_t *volinfo = NULL; dict_t *val_dict = NULL; - + GF_ASSERT (req); - + dict = dict_new (); if (!dict) goto out; @@ -1245,7 +1328,7 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) val_dict = dict_new(); if (!val_dict) goto out; - + ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict); if (ret) { @@ -1263,10 +1346,9 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) exists = glusterd_check_volume_exists (volname); if (!exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s " - "does not exist", volname); - snprintf (errstr, 2048, "Volume : %s does not exist", + snprintf (errstr, sizeof (errstr), "Volume %s does not exist", volname); + gf_log ("", GF_LOG_ERROR, errstr); *op_errstr = gf_strdup (errstr); ret = -1; goto out; @@ -1304,19 +1386,18 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) sprintf (str, "key%d", count); ret = dict_get_str (dict, str, &key); - - if (ret) + + if (ret) break; - exists = glusterd_check_option_exists (key, &key_fixed); if (exists == -1) { ret = -1; goto out; } if (!exists) { - gf_log ("", GF_LOG_ERROR, "Option with name: %s " - "does not exist", key); + gf_log ("", GF_LOG_ERROR, "Option with name: %s " + "does not exist", key); ret = snprintf (errstr, 2048, "option : %s does not exist", key); @@ -1324,17 +1405,16 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) snprintf (errstr + ret, 2048 - ret, "\nDid you mean %s?", key_fixed); *op_errstr = gf_strdup (errstr); - - ret = -1; - goto out; + ret = -1; + goto out; } sprintf (str, "value%d", count); ret = dict_get_str (dict, str, &value); - + if (ret) { - gf_log ("", GF_LOG_ERROR, "invalid key,value pair" - "in 'volume set'"); + gf_log ("", GF_LOG_ERROR, + "invalid key,value pair in 'volume set'"); ret = -1; goto out; } @@ -1344,8 +1424,8 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) ret = dict_set_str (val_dict, key, value); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to set the options" - "in 'volume set'"); + gf_log ("", GF_LOG_ERROR, + "Unable to set the options in 'volume set'"); ret = -1; goto out; } @@ -1359,9 +1439,8 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) *op_errstr = NULL; ret = glusterd_validate_reconfopts (volinfo, val_dict, op_errstr); if (ret) { - gf_log ("glsuterd", GF_LOG_DEBUG, - "Could not create temp volfile, some option failed: %s", - *op_errstr); + gf_log ("glusterd", GF_LOG_DEBUG, "Could not create temp " + "volfile, some option failed: %s", *op_errstr); goto out; } @@ -1384,21 +1463,22 @@ out: gf_log ("glsuterd", GF_LOG_DEBUG, "Error, Cannot Validate option :%s", *op_errstr); - } - else + } else { gf_log ("glsuterd", GF_LOG_DEBUG, - "Error, Cannot Validate option"); + "Error, Cannot Validate option"); + } } return ret; } static int -glusterd_op_stage_reset_volume (gd1_mgmt_stage_op_req *req) +glusterd_op_stage_reset_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) { int ret = 0; dict_t *dict = NULL; char *volname = NULL; gf_boolean_t exists = _gf_false; + char msg[2048] = {0}; GF_ASSERT (req); @@ -1423,16 +1503,17 @@ glusterd_op_stage_reset_volume (gd1_mgmt_stage_op_req *req) exists = glusterd_check_volume_exists (volname); if (!exists) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s " - "does not exist", - volname); + snprintf (msg, sizeof (msg), "Volume %s does not " + "exist", volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); ret = -1; goto out; } out: - if (dict) + if (dict) dict_unref (dict); gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); @@ -1768,8 +1849,8 @@ glusterd_op_stage_sync_volume (gd1_mgmt_stage_op_req *req, char **op_errstr) if (!ret) { exists = glusterd_check_volume_exists (volname); if (!exists) { - snprintf (msg, sizeof (msg), "volume: %s, " - "doesn't exist", volname); + snprintf (msg, sizeof (msg), "Volume %s " + "does not exist", volname); *op_errstr = gf_strdup (msg); ret = -1; goto out; @@ -2376,7 +2457,8 @@ rb_mountpoint_mkdir (glusterd_volinfo_t *volinfo, ret = mkdir (mount_point_path, 0777); if (ret && (errno != EEXIST)) { - gf_log ("", GF_LOG_DEBUG, "mkdir failed, errno: %d", errno); + gf_log ("", GF_LOG_DEBUG, "mkdir failed, errno: %d", + errno); goto out; } @@ -3104,16 +3186,16 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req, dict_t *rsp_dict) } if (ret) { - gf_log ("", GF_LOG_CRITICAL, "Unable to cleanup " - "dst brick"); + gf_log ("", GF_LOG_CRITICAL, + "Unable to cleanup dst brick"); goto out; } ret = glusterd_nfs_server_stop (); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to stop nfs" - "server, ret: %d", ret); + gf_log ("", GF_LOG_ERROR, + "Unable to stop nfs server, ret: %d", ret); } ret = glusterd_op_perform_replace_brick (volinfo, src_brick, @@ -3131,8 +3213,8 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req, dict_t *rsp_dict) ret = glusterd_check_generate_start_nfs (volinfo); if (ret) { - gf_log ("", GF_LOG_CRITICAL, "Failed to generate " - " nfs volume file"); + gf_log ("", GF_LOG_CRITICAL, + "Failed to generate nfs volume file"); } ret = glusterd_store_update_volume (volinfo); @@ -3157,7 +3239,8 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req, dict_t *rsp_dict) "Recieved pause - doing nothing"); ctx = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); if (ctx) { - ret = rb_do_operation_pause (volinfo, src_brickinfo, dst_brickinfo); + ret = rb_do_operation_pause (volinfo, src_brickinfo, + dst_brickinfo); if (ret) { gf_log ("", GF_LOG_ERROR, "Pause operation failed"); @@ -3263,7 +3346,7 @@ glusterd_options_reset (glusterd_volinfo_t *volinfo) if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to create volfile for" - " 'volume set'"); + " 'volume set'"); ret = -1; goto out; } @@ -3284,7 +3367,7 @@ glusterd_options_reset (glusterd_volinfo_t *volinfo) ret = 0; out: - gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; } @@ -3296,7 +3379,7 @@ glusterd_op_reset_volume (gd1_mgmt_stage_op_req *req) int ret = -1; char *volname = NULL; dict_t *dict = NULL; - + dict = dict_new (); if (!dict) goto out; @@ -3319,13 +3402,15 @@ glusterd_op_reset_volume (gd1_mgmt_stage_op_req *req) gf_log ("", GF_LOG_ERROR, "Unable to allocate memory"); goto out; } - + ret = glusterd_options_reset (volinfo); out: + if (dict) + dict_unref (dict); gf_log ("", GF_LOG_DEBUG, "'volume reset' returning %d", ret); return ret; - + } static int @@ -3395,8 +3480,8 @@ glusterd_op_set_volume (gd1_mgmt_stage_op_req *req) ret = dict_get_str (dict, str, &value); if (ret) { - gf_log ("", GF_LOG_ERROR, "invalid key,value pair" - "in 'volume set'"); + gf_log ("", GF_LOG_ERROR, + "invalid key,value pair in 'volume set'"); ret = -1; goto out; } @@ -3410,8 +3495,8 @@ glusterd_op_set_volume (gd1_mgmt_stage_op_req *req) ret = -1; if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to set the options" - "in 'volume set'"); + gf_log ("", GF_LOG_ERROR, + "Unable to set the options in 'volume set'"); ret = -1; goto out; } @@ -3432,7 +3517,7 @@ glusterd_op_set_volume (gd1_mgmt_stage_op_req *req) if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to create volfile for" - " 'volume set'"); + " 'volume set'"); ret = -1; goto out; } @@ -3648,6 +3733,7 @@ glusterd_op_log_filename (gd1_mgmt_stage_op_req *req) struct stat stbuf = {0,}; int valid_brick = 0; glusterd_brickinfo_t *tmpbrkinfo = NULL; + char* new_logdir = NULL; GF_ASSERT (req); @@ -3673,6 +3759,7 @@ glusterd_op_log_filename (gd1_mgmt_stage_op_req *req) gf_log ("", GF_LOG_ERROR, "volname not found"); goto out; } + ret = dict_get_str (dict, "path", &path); if (ret) { gf_log ("", GF_LOG_ERROR, "path not found"); @@ -3695,7 +3782,15 @@ glusterd_op_log_filename (gd1_mgmt_stage_op_req *req) gf_log ("", GF_LOG_ERROR, "not a directory"); goto out; } - volinfo->logdir = gf_strdup (path); + new_logdir = gf_strdup (path); + if (!new_logdir) { + ret = -1; + gf_log ("", GF_LOG_ERROR, "Out of memory"); + goto out; + } + if (volinfo->logdir) + GF_FREE (volinfo->logdir); + volinfo->logdir = new_logdir; } else { ret = glusterd_brickinfo_from_brick (brick, &tmpbrkinfo); if (ret) { @@ -3711,15 +3806,15 @@ glusterd_op_log_filename (gd1_mgmt_stage_op_req *req) if (uuid_is_null (brickinfo->uuid)) { ret = glusterd_resolve_brick (brickinfo); + if (ret) + goto out; } /* check if the brickinfo belongs to the 'this' machine */ if (uuid_compare (brickinfo->uuid, priv->uuid)) continue; - if (brick && - (strcmp (tmpbrkinfo->hostname, brickinfo->hostname) || - strcmp (tmpbrkinfo->path,brickinfo->path))) + if (brick && strcmp (tmpbrkinfo->path,brickinfo->path)) continue; valid_brick = 1; @@ -3998,8 +4093,10 @@ glusterd_op_sync_volume (gd1_mgmt_stage_op_req *req, char **op_errstr, if (!ret) { ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { - gf_log ("", GF_LOG_ERROR, "Volume with name: %s " - "not exists", volname); + snprintf (msg, sizeof (msg), "Volume %s does not exist", + volname); + gf_log ("", GF_LOG_ERROR, msg); + *op_errstr = gf_strdup (msg); goto out; } } @@ -4561,6 +4658,10 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret, rsp.op_ret = op_ret; rsp.op_errno = op_errno; rsp.volname = ""; + if (op_errstr) + rsp.op_errstr = op_errstr; + else + rsp.op_errstr = ""; cli_rsp = &rsp; sfunc = gf_xdr_serialize_cli_delete_vol_rsp; break; @@ -4640,7 +4741,7 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret, sfunc = gf_xdr_serialize_cli_set_vol_rsp; break; } - + case GD_MGMT_CLI_RESET_VOLUME: { gf_log ("", GF_LOG_DEBUG, "Return value to CLI"); @@ -4662,7 +4763,10 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret, gf1_cli_log_filename_rsp rsp = {0,}; rsp.op_ret = op_ret; rsp.op_errno = op_errno; - rsp.errstr = ""; + if (op_errstr) + rsp.errstr = op_errstr; + else + rsp.errstr = ""; cli_rsp = &rsp; sfunc = gf_xdr_serialize_cli_log_filename_rsp; break; @@ -4672,7 +4776,10 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret, gf1_cli_log_rotate_rsp rsp = {0,}; rsp.op_ret = op_ret; rsp.op_errno = op_errno; - rsp.errstr = ""; + if (op_errstr) + rsp.errstr = op_errstr; + else + rsp.errstr = ""; cli_rsp = &rsp; sfunc = gf_xdr_serialize_cli_log_rotate_rsp; break; @@ -4945,7 +5052,7 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr, break; case GD_OP_DELETE_VOLUME: - ret = glusterd_op_stage_delete_volume (req); + ret = glusterd_op_stage_delete_volume (req, op_errstr); break; case GD_OP_ADD_BRICK: @@ -4962,7 +5069,7 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr, break; case GD_OP_RESET_VOLUME: - ret = glusterd_op_stage_reset_volume (req); + ret = glusterd_op_stage_reset_volume (req, op_errstr); break; case GD_OP_REMOVE_BRICK: @@ -4970,11 +5077,11 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr, break; case GD_OP_LOG_FILENAME: - ret = glusterd_op_stage_log_filename (req); + ret = glusterd_op_stage_log_filename (req, op_errstr); break; case GD_OP_LOG_ROTATE: - ret = glusterd_op_stage_log_rotate (req); + ret = glusterd_op_stage_log_rotate (req, op_errstr); break; case GD_OP_SYNC_VOLUME: @@ -5466,12 +5573,14 @@ glusterd_op_free_ctx (glusterd_op_t op, void *ctx, gf_boolean_t ctx_free) case GD_OP_SYNC_VOLUME: case GD_OP_SET_VOLUME: case GD_OP_START_VOLUME: + case GD_OP_RESET_VOLUME: dict_unref (ctx); break; case GD_OP_DELETE_VOLUME: GF_FREE (ctx); break; default: + GF_ASSERT (0); break; } } diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 27acaf271..5224a91d4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -1566,7 +1566,7 @@ validate_clientopts (glusterd_volinfo_t *volinfo, } int -validate_brickopts (glusterd_volinfo_t *volinfo, +validate_brickopts (glusterd_volinfo_t *volinfo, char *brickinfo_path, dict_t *val_dict, char **op_errstr) @@ -1595,12 +1595,12 @@ glusterd_validate_brickreconf (glusterd_volinfo_t *volinfo, { glusterd_brickinfo_t *brickinfo = NULL; int ret = -1; - + list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { gf_log ("", GF_LOG_DEBUG, "Validating %s", brickinfo->hostname); - ret = validate_brickopts (volinfo, brickinfo->path, val_dict, + ret = validate_brickopts (volinfo, brickinfo->path, val_dict, op_errstr); if (ret) goto out; @@ -1609,7 +1609,7 @@ glusterd_validate_brickreconf (glusterd_volinfo_t *volinfo, ret = 0; out: - return ret; + return ret; } int diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 8853db813..9914e7be7 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -50,6 +50,7 @@ #define GLUSTERD_MAX_VOLUME_NAME 1000 #define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs" #define GLUSTERD_TR_LOG_SIZE 50 +#define GLUSTERD_NAME "glusterd" typedef enum glusterd_op_ { diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index 6c763e7fb..7c92441ea 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -503,8 +503,12 @@ validate_options (xlator_t *this, dict_t *options, char **op_errstr) } } - if (!auth_modules) - auth_modules = dict_new (); + auth_modules = dict_new (); + if (!auth_modules) { + gf_log (this->name, GF_LOG_ERROR, "Out of memory"); + ret = -1; + goto out; + } dict_foreach (options, get_auth_types, auth_modules); ret = validate_auth_options (this, options); @@ -516,11 +520,9 @@ validate_options (xlator_t *this, dict_t *options, char **op_errstr) } ret = gf_auth_init (this, auth_modules); - if (ret) { - dict_unref (auth_modules); - goto out; - } out: + if (auth_modules) + dict_unref (auth_modules); return ret; } |