diff options
author | Pranith Kumar K <pkarampu@redhat.com> | 2014-12-29 15:32:28 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2015-01-20 02:24:24 -0800 |
commit | 7510d8edf4e7bea50e0c1f041202f063a5d138af (patch) | |
tree | 77814773e915cedccbcb9149ff8c86ca704514fa /cli/src | |
parent | 1ee8ce725f0e70f45419aa0e2f4d85db7223d766 (diff) |
mgmt/glusterd: Implement Volume heal enable/disable
For volumes with replicate, disperse xlators, self-heal daemon should do
healing. This patch provides enable/disable functionality for the xlators to be
part of self-heal-daemon. Replicate already had this functionality with
'gluster volume set cluster.self-heal-daemon on/off'. But this patch makes it
uniform for both types of volumes. Internally it still does 'volume set' based
on the volume type.
Change-Id: Ie0f3799b74c2afef9ac658ef3d50dce3e8072b29
BUG: 1177601
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/9358
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Xavier Hernandez <xhernandez@datalab.es>
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 52 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 9 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 56 |
3 files changed, 86 insertions, 31 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 53b14d27708..d7c1ddeb041 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2964,7 +2964,36 @@ set_hostname_path_in_dict (const char *token, dict_t *dict, int heal_op) out: return ret; +} + +static int +heal_command_type_get (const char *command) +{ + int i = 0; + /* subcommands are set as NULL */ + char *heal_cmds[GF_AFR_OP_HEAL_DISABLE + 1] = { + [GF_AFR_OP_INVALID] = NULL, + [GF_AFR_OP_HEAL_INDEX] = NULL, + [GF_AFR_OP_HEAL_FULL] = "full", + [GF_AFR_OP_INDEX_SUMMARY] = "info", + [GF_AFR_OP_HEALED_FILES] = NULL, + [GF_AFR_OP_HEAL_FAILED_FILES] = NULL, + [GF_AFR_OP_SPLIT_BRAIN_FILES] = NULL, + [GF_AFR_OP_STATISTICS] = "statistics", + [GF_AFR_OP_STATISTICS_HEAL_COUNT] = NULL, + [GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA] = NULL, + [GF_AFR_OP_SBRAIN_HEAL_FROM_BIGGER_FILE] = "split-brain", + [GF_AFR_OP_SBRAIN_HEAL_FROM_BRICK] = "split-brain", + [GF_AFR_OP_HEAL_ENABLE] = "enable", + [GF_AFR_OP_HEAL_DISABLE] = "disable", + }; + + for (i = 0; i <= GF_AFR_OP_HEAL_DISABLE; i++) { + if (heal_cmds[i] && (strcmp (heal_cmds[i], command) == 0)) + return i; + } + return GF_AFR_OP_INVALID; } int @@ -2973,6 +3002,9 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, { int ret = 0; dict_t *dict = NULL; + char *hostname = NULL; + char *path = NULL; + gf_xl_afr_op_t op = GF_AFR_OP_INVALID; dict = dict_new (); if (!dict) @@ -2990,24 +3022,16 @@ cli_cmd_volume_heal_options_parse (const char **words, int wordcount, } if (wordcount == 4) { - if (!strcmp (words[3], "full")) { - ret = dict_set_int32 (dict, "heal-op", - GF_AFR_OP_HEAL_FULL); - goto done; - } else if (!strcmp (words[3], "statistics")) { - ret = dict_set_int32 (dict, "heal-op", - GF_AFR_OP_STATISTICS); - goto done; - - } else if (!strcmp (words[3], "info")) { - ret = dict_set_int32 (dict, "heal-op", - GF_AFR_OP_INDEX_SUMMARY); - goto done; - } else { + op = heal_command_type_get (words[3]); + if (op == GF_AFR_OP_INVALID) { ret = -1; goto out; } + + ret = dict_set_int32 (dict, "heal-op", op); + goto done; } + if (wordcount == 5) { if (strcmp (words[3], "info") && strcmp (words[3], "statistics")) { diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 501b5776dec..3035ad4d566 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -2356,10 +2356,11 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_status_cbk, "display status of all or specified volume(s)/brick"}, - { "volume heal <VOLNAME> [full | statistics [heal-count "\ - "[replica <HOSTNAME:BRICKNAME>]] |info [healed | heal-failed | "\ - "split-brain]| split-brain {bigger-file <FILE> |source-brick "\ - "<HOSTNAME:BRICKNAME> [<FILE>]}]", + { "volume heal <VOLNAME> [enable | disable | full |" + "statistics [heal-count [replica <HOSTNAME:BRICKNAME>]] |" + "info [healed | heal-failed | split-brain] |" + "split-brain {bigger-file <FILE> |" + "source-brick <HOSTNAME:BRICKNAME> [<FILE>]}]", cli_cmd_volume_heal_cbk, "self-heal commands on volume specified by <VOLNAME>"}, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 72ffaf4129a..4184bc161eb 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7270,6 +7270,30 @@ out: return; } +int +gf_is_cli_heal_get_command (gf_xl_afr_op_t heal_op) +{ + /* If the command is get command value is 1 otherwise 0, for + invalid commands -1 */ + int get_cmds[GF_AFR_OP_HEAL_DISABLE + 1] = { + [GF_AFR_OP_INVALID] = -1, + [GF_AFR_OP_HEAL_INDEX] = 0, + [GF_AFR_OP_HEAL_FULL] = 0, + [GF_AFR_OP_INDEX_SUMMARY] = 1, + [GF_AFR_OP_HEALED_FILES] = 1, + [GF_AFR_OP_HEAL_FAILED_FILES] = 1, + [GF_AFR_OP_SPLIT_BRAIN_FILES] = 1, + [GF_AFR_OP_STATISTICS] = 1, + [GF_AFR_OP_STATISTICS_HEAL_COUNT] = 1, + [GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA] = 1, + [GF_AFR_OP_HEAL_ENABLE] = 0, + [GF_AFR_OP_HEAL_DISABLE] = 0, + }; + + if (heal_op > GF_AFR_OP_INVALID && heal_op <= GF_AFR_OP_HEAL_DISABLE) + return get_cmds[heal_op] == 1; + return _gf_false; +} int gf_cli_heal_volume_cbk (struct rpc_req *req, struct iovec *iov, @@ -7330,12 +7354,20 @@ gf_cli_heal_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_INFO, "Received resp to heal volume"); + operation = "Gathering "; + substr = ""; switch (heal_op) { case GF_AFR_OP_HEAL_INDEX: + operation = "Launching heal operation "; heal_op_str = "to perform index self heal"; + substr = "\nUse heal info commands to check" + " status"; break; case GF_AFR_OP_HEAL_FULL: + operation = "Launching heal operation "; heal_op_str = "to perform full self heal"; + substr = "\nUse heal info commands to check" + " status"; break; case GF_AFR_OP_INDEX_SUMMARY: heal_op_str = "list of entries to be healed"; @@ -7367,35 +7399,33 @@ gf_cli_heal_volume_cbk (struct rpc_req *req, struct iovec *iov, case GF_AFR_OP_INVALID: heal_op_str = "invalid heal op"; break; - } - - if ((heal_op == GF_AFR_OP_HEAL_FULL) || - (heal_op == GF_AFR_OP_HEAL_INDEX)) { - operation = "Launching heal operation"; - substr = "\nUse heal info commands to check status"; - } else { - operation = "Gathering"; - substr = ""; + case GF_AFR_OP_HEAL_ENABLE: + operation = ""; + heal_op_str = "Enable heal"; + break; + case GF_AFR_OP_HEAL_DISABLE: + operation = ""; + heal_op_str = "Disable heal"; + break; } if (rsp.op_ret) { if (strcmp (rsp.op_errstr, "")) { cli_err ("%s", rsp.op_errstr); } else { - cli_err ("%s %s on volume %s has been unsuccessful", + cli_err ("%s%s on volume %s has been unsuccessful", operation, heal_op_str, volname); } ret = rsp.op_ret; goto out; } else { - cli_out ("%s %s on volume %s has been successful %s", operation, + cli_out ("%s%s on volume %s has been successful %s", operation, heal_op_str, volname, substr); } ret = rsp.op_ret; - if ((heal_op == GF_AFR_OP_HEAL_FULL) || - (heal_op == GF_AFR_OP_HEAL_INDEX)) + if (!gf_is_cli_heal_get_command (heal_op)) goto out; dict = dict_new (); |