diff options
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 52 | 
1 files changed, 38 insertions, 14 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")) {  | 
