diff options
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 10 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-bitrot.c | 111 | 
2 files changed, 117 insertions, 4 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 0584b1edbbd..1c2e14c7a5e 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -4859,12 +4859,14 @@ cli_cmd_bitrot_parse (const char **words, int wordcount, dict_t **options)          char               *opwords[]             = {"enable", "disable",                                                       "scrub-throttle",                                                       "scrub-frequency", -                                                     "scrub"}; +                                                     "scrub", NULL};          char               *scrub_throt_values[]  = {"frozen", "lazy", "normal", -                                                     "aggressive"}; +                                                     "aggressive", NULL};          char               *scrub_freq_values[]   = {"daily", "weekly", -                                                     "biweekly", "monthly"}; -        char               *scrub_values[]        = {"pause", "resume"}; +                                                     "biweekly", "monthly", +                                                      NULL}; +        char               *scrub_values[]        = {"pause", "resume", +                                                      NULL};          dict_t             *dict                  = NULL;          gf_bitrot_type     type                   = GF_BITROT_OPTION_TYPE_NONE; diff --git a/xlators/mgmt/glusterd/src/glusterd-bitrot.c b/xlators/mgmt/glusterd/src/glusterd-bitrot.c index 5bd906312a4..a0de7a35998 100644 --- a/xlators/mgmt/glusterd/src/glusterd-bitrot.c +++ b/xlators/mgmt/glusterd/src/glusterd-bitrot.c @@ -128,6 +128,99 @@ glusterd_handle_bitrot (rpcsvc_request_t *req)  }  static int +glusterd_bitrot_scrub_throttle (glusterd_volinfo_t *volinfo, dict_t *dict, +                                char *key, char **op_errstr) +{ +        int32_t        ret                  = -1; +        char           *scrub_throttle      = NULL; +        char           *option              = NULL; +        xlator_t       *this                = NULL; + +        this = THIS; +        GF_ASSERT (this); + +        ret = dict_get_str (dict, "scrub-throttle-value", &scrub_throttle); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch scrub-" +                        "throttle value"); +                goto out; +        } + +        option = gf_strdup (scrub_throttle); +        ret = dict_set_dynstr (volinfo->dict, key, option); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Failed to set option %s", +                        key); +                goto out; +        } + +out: +        return ret; +} + +static int +glusterd_bitrot_scrub_freq (glusterd_volinfo_t *volinfo, dict_t *dict, +                            char *key, char **op_errstr) +{ +        int32_t        ret                  = -1; +        char           *scrub_freq          = NULL; +        xlator_t       *this                = NULL; +        char           *option              = NULL; + +        this = THIS; +        GF_ASSERT (this); + +        ret = dict_get_str (dict, "scrub-frequency-value", &scrub_freq); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch scrub-" +                        "freq value"); +                goto out; +        } + +        option = gf_strdup (scrub_freq); +        ret = dict_set_dynstr (volinfo->dict, key, option); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Failed to set option %s", +                        key); +                goto out; +        } + +out: +        return ret; +} + +static int +glusterd_bitrot_scrub (glusterd_volinfo_t *volinfo, dict_t *dict, +                       char *key, char **op_errstr) +{ +        int32_t        ret                  = -1; +        char           *scrub_value         = NULL; +        xlator_t       *this                = NULL; +        char           *option              = NULL; + +        this = THIS; +        GF_ASSERT (this); + +        ret = dict_get_str (dict, "scrub-value", &scrub_value); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Unable to fetch scrub" +                        "value"); +                goto out; +        } + +        option = gf_strdup (scrub_value); +        ret = dict_set_dynstr (volinfo->dict, key, option); +        if (ret) { +                gf_log (this->name, GF_LOG_ERROR, "Failed to set option %s", +                        key); +                goto out; +        } + +out: +        return ret; +} + +static int  glusterd_bitrot_enable (glusterd_volinfo_t *volinfo, char **op_errstr)  {          int32_t         ret             = -1; @@ -295,6 +388,24 @@ glusterd_op_bitrot (dict_t *dict, char **op_errstr, dict_t *rsp_dict)                          goto out;                  break; + +        case GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE: +                ret = glusterd_bitrot_scrub_throttle (volinfo, dict, +                                                      "features.scrub-throttle", +                                                      op_errstr); +                goto out; + +        case GF_BITROT_OPTION_TYPE_SCRUB_FREQ: +                ret = glusterd_bitrot_scrub_freq (volinfo, dict, +                                                  "features.scrub-freq", +                                                  op_errstr); +                goto out; + +        case GF_BITROT_OPTION_TYPE_SCRUB: +                ret = glusterd_bitrot_scrub (volinfo, dict, "features.scrub", +                                             op_errstr); +                goto out; +          default:                  gf_asprintf (op_errstr, "Bitrot command failed. Invalid "                               "opcode");  | 
