diff options
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 129 | 
1 files changed, 116 insertions, 13 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index cd0370acc78..dd7b11bccd4 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -485,8 +485,12 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)          uint64_t         value   = 0;          gf_quota_type    type    = GF_QUOTA_OPTION_TYPE_NONE;          char           *opwords[] = { "enable", "disable", "limit-usage", -                                      "remove", "list", "version", NULL }; +                                      "remove", "list", "alert-time", +                                      "soft-timeout", "hard-timeout", +                                      "default-soft-limit", NULL};          char            *w       = NULL; +        uint32_t         time    = 0; +        double           percent = 0;          GF_ASSERT (words);          GF_ASSERT (options); @@ -558,7 +562,8 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)          }          if (strcmp (w, "limit-usage") == 0) { -                if (wordcount != 6) { + +                if (wordcount < 6 || wordcount > 7) {                          ret = -1;                          goto out;                  } @@ -567,8 +572,8 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)                  if (words[4][0] != '/') {                          cli_err ("Please enter absolute path"); - -                        return -2; +                        ret = -1; +                        goto out;                  }                  ret = dict_set_str (dict, "path", (char *) words[4]);                  if (ret) @@ -576,20 +581,34 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)                  if (!words[5]) {                          cli_err ("Please enter the limit value to be set"); - -                        return -2; +                        ret = -1; +                        goto out;                  }                  ret = gf_string2bytesize (words[5], &value);                  if (ret != 0) {                          cli_err ("Please enter a correct value"); -                        return -1; +                        goto out;                  } -                ret = dict_set_str (dict, "limit", (char *) words[5]); +                ret  = dict_set_str (dict, "hard-limit", (char *) words[5]);                  if (ret < 0)                          goto out; +                if (wordcount == 7) { + +                        ret = gf_string2percent (words[6], &percent); +                        if (ret != 0) { +                                cli_err ("Please enter a correct value"); +                                goto out; +                        } + +                        ret = dict_set_str (dict, "soft-limit", +                                            (char *) words[6]); +                        if (ret < 0) +                                goto out; +                } +                  goto set_type;          }          if (strcmp (w, "remove") == 0) { @@ -602,8 +621,8 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)                  if (words[4][0] != '/') {                          cli_err ("Please enter absolute path"); - -                        return -2; +                        ret = -1; +                        goto out;                  }                  ret = dict_set_str (dict, "path", (char *) words[4]); @@ -636,8 +655,75 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)                  goto set_type;          } -        if (strcmp (w, "version") == 0) { -                type = GF_QUOTA_OPTION_TYPE_VERSION; + +        if (strcmp (w, "alert-time") == 0) { +                if (wordcount != 5) { +                        ret = -1; +                        goto out; +                } +                type = GF_QUOTA_OPTION_TYPE_ALERT_TIME; + +                ret = gf_string2time (words[4], &time); +                if (ret) { +                        cli_err ("Invalid argument %s. Please enter a valid " +                                 "string", words[4]); +                        goto out; +                } + +                ret = dict_set_str (dict, "value", (char *)words[4]); +                if (ret < 0) +                        goto out; +                goto set_type; +        } +        if (strcmp (w, "soft-timeout") == 0) { +                if (wordcount != 5) { +                        ret = -1; +                        goto out; +                } +                type = GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT; + +                ret = gf_string2time (words[4], &time); +                if (ret) { +                        cli_err ("Invalid argument %s. Please enter a valid " +                                 "string", words[4]); +                        goto out; +                } + +                ret = dict_set_str (dict, "value", (char *)words[4]); +                if (ret < 0) +                        goto out; +                goto set_type; +        } +        if (strcmp (w, "hard-timeout") == 0) { +                if(wordcount != 5) { +                        ret = -1; +                        goto out; +                } +                type = GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT; + +                ret = gf_string2time (words[4], &time); +                if (ret) { +                        cli_err ("Invalid argument %s. Please enter a valid " +                                 "string", words[4]); +                        goto out; +                } + +                ret = dict_set_str (dict, "value", (char *)words[4]); +                if (ret < 0) +                        goto out; +                goto set_type; +        } +        if (strcmp (w, "default-soft-limit") == 0) { +                if(wordcount != 5) { +                        ret = -1; +                        goto out; +                } +                type = GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT; + +                ret = dict_set_str (dict, "value", (char *)words[4]); +                if (ret < 0) +                        goto out; +                goto set_type;          } else {                  GF_ASSERT (!"opword mismatch");          } @@ -2225,6 +2311,8 @@ cli_cmd_volume_status_parse (const char **words, int wordcount,                                          cmd |= GF_CLI_STATUS_NFS;                                  } else if (!strcmp (words[3], "shd")) {                                          cmd |= GF_CLI_STATUS_SHD; +                                } else if (!strcmp (words[3], "quotad")) { +                                        cmd |= GF_CLI_STATUS_QUOTAD;                                  } else {                                          cmd = GF_CLI_STATUS_BRICK;                                          ret = dict_set_str (dict, "brick", @@ -2280,6 +2368,17 @@ cli_cmd_volume_status_parse (const char **words, int wordcount,                                  goto out;                          }                          cmd |= GF_CLI_STATUS_SHD; +                } else if (!strcmp (words[3], "quotad")) { +                        if (cmd == GF_CLI_STATUS_FD || +                            cmd == GF_CLI_STATUS_CLIENTS || +                            cmd == GF_CLI_STATUS_DETAIL || +                            cmd == GF_CLI_STATUS_INODE) { +                                cli_err ("Detail/FD/Clients/Inode status not " +                                         "available for Quota Daemon"); +                                ret = -1; +                                goto out; +                        } +                        cmd |= GF_CLI_STATUS_QUOTAD;                  } else {                          if (cmd == GF_CLI_STATUS_TASKS) {                                  cli_err ("Tasks status not available for " @@ -2317,7 +2416,7 @@ cli_cmd_validate_dumpoption (const char *arg, char **option)  {          char    *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool", "priv",                                "fd", "inode", "history", "inodectx", "fdctx", -                              NULL}; +                              "quotad", NULL};          char    *w = NULL;          w = str_getunamb (arg, opwords); @@ -2349,6 +2448,10 @@ cli_cmd_volume_statedump_options_parse (const char **words, int wordcount,                  strncat (option_str, option, strlen (option));                  strncat (option_str, " ", 1);          } +        if((strstr (option_str, "nfs")) && strstr (option_str, "quotad")) { +                ret = -1; +                goto out; +        }          dict = dict_new ();          if (!dict)  | 
