diff options
author | Krutika Dhananjay <kdhananj@redhat.com> | 2013-07-31 13:19:19 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2013-08-12 00:48:15 +0530 |
commit | cadba04360c88c87dc6ffdf8e15ec70e81a943c8 (patch) | |
tree | 447afeeca763c81bd8b29777157e4fde58ffb80d /cli | |
parent | 2da625ddd39ea3818da60c625cd578cb65c904aa (diff) |
glusterd: club limit-usage and soft-limit into a single command
Change-Id: I5f680675576aeec584b497eb25dd804a9dd6d690
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 59 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 2 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 85 |
3 files changed, 96 insertions, 50 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index a50e4b3c..9b9c0cf2 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -532,10 +532,9 @@ 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", "soft-limit", - "alert-time", "soft-timeout", - "hard-timeout", "default-soft-limit", - NULL}; + "remove", "list", "alert-time", + "soft-timeout", "hard-timeout", + "default-soft-limit", NULL}; char *w = NULL; uint32_t time = 0; double percent = 0; @@ -610,7 +609,7 @@ 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; } @@ -638,10 +637,24 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) 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) { @@ -688,41 +701,7 @@ cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) goto set_type; } - if (strcmp (w, "soft-limit") == 0) { - if (wordcount != 6) { - ret = -1; - goto out; - } - type = GF_QUOTA_OPTION_TYPE_SOFT_LIMIT; - if (words[4][0] != '/') { - cli_err ("Please enter absolute path"); - ret = -1; - goto out; - } - ret = dict_set_str (dict, "path", (char *) words[4]); - if (ret) - goto out; - - if (!words[5]) { - cli_err ("Please enter the limit value to be set"); - ret = -1; - goto out; - } - - ret = gf_string2percent (words[5], &percent); - if (ret != 0) { - cli_err ("Please enter a correct value"); - goto out; - } - - ret = dict_set_str (dict, "limit", (char *) words[5]); - if (ret < 0) - goto out; - - goto set_type; - - } if (strcmp (w, "alert-time") == 0) { if (wordcount != 5) { ret = -1; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 189d36c0..51cfa251 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1905,7 +1905,7 @@ struct cli_cmd volume_cmds[] = { "volume profile operations"}, { "volume quota <VOLNAME> {enable|disable|list [<path> ...]|remove <path>| default-soft-limit <percent>} |\n" - "volume quota <VOLNAME> {limit-usage <path> <size> |soft-limit <path> <percent>} |\n" + "volume quota <VOLNAME> {limit-usage <path> <size> [<percent>]} |\n" "volume quota <VOLNAME> {alert-time|soft-timeout|hard-timeout} {<time>}", cli_cmd_quota_cbk, "quota translator specific operations"}, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 49949f54..cd1e0047 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2570,6 +2570,60 @@ out: return ret; } +static int +gf_cli_create_auxiliary_mount (char *volname) +{ + int ret = -1; + char mountdir[PATH_MAX] = {0,}; + + snprintf (mountdir, sizeof (mountdir)-1, "/tmp/%s", volname); + ret = mkdir (mountdir, 0777); + if (ret && errno != EEXIST) + goto out; + + ret = runcmd (SBIN_DIR"/glusterfs", "-s", + "localhost", "--volfile-id", volname, "-l", + DEFAULT_LOG_FILE_DIRECTORY"/quota-enable.log", + mountdir, "--client-pid", "-42", NULL); + if (ret) { + gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs " + "client"); + ret = -1; + goto out; + } + ret = 0; + +out: + return ret; +} + +static int +gf_cli_remove_auxiliary_mount (char *volname) +{ + int ret = -1; + runner_t runner = {0,}; + char mountdir [PATH_MAX] = {0,}; + + snprintf (mountdir, sizeof (mountdir)-1, "/tmp/%s", volname); + + runinit (&runner); + runner_add_args (&runner, "umount", + +#if GF_LINUX_HOST_OS + "-l", +#endif + mountdir, NULL); + ret = runner_run_reuse (&runner); + if (ret) + gf_log ("cli", GF_LOG_WARNING, "umount on %s failed, " + "reason : %s", mountdir, strerror (errno)); + runner_end (&runner); + + rmdir (mountdir); + return ret; + +} + int gf_cli_quota_list_run_crawler (char *volname, char *limit_list, dict_t *dict, int count, char *op_errstr, uint32_t op_version, @@ -2723,7 +2777,17 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, gf_log (frame->this->name, GF_LOG_TRACE, "failed to get entry " "count"); - if (type == GF_QUOTA_OPTION_TYPE_LIST) { + if (type == GF_QUOTA_OPTION_TYPE_ENABLE) { + ret = gf_cli_create_auxiliary_mount (volname); + if (ret) + goto out; + + } else if (type == GF_QUOTA_OPTION_TYPE_DISABLE) { + ret = gf_cli_remove_auxiliary_mount (volname); + if (ret) + goto out; + + } else if (type == GF_QUOTA_OPTION_TYPE_LIST) { if (global_state->mode & GLUSTER_MODE_XML) { ret = cli_xml_output_vol_quota_limit_list (volname, limit_list, rsp.op_ret, @@ -2732,22 +2796,25 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_ERROR, "Error outputting to xml"); goto out; - } - gf_log ("cli", GF_LOG_INFO, "Received resp to quota command"); - gf_cli_quota_list_run_crawler (volname, limit_list, dict, count, rsp.op_errstr, op_version, default_sl, entry_count); if (rsp.op_errstr) - snprintf (msg, sizeof (msg), "%s", rsp.op_errstr); + snprintf (msg, sizeof (msg)-1, "%s", rsp.op_errstr); + } + + gf_log ("cli", GF_LOG_DEBUG, "Received resp to quota command"); + + if (rsp.op_errstr) { + snprintf (msg, sizeof (msg)-1, "%s", rsp.op_errstr); } else { - gf_log ("cli", GF_LOG_INFO, "Received resp to quota command"); - if (rsp.op_errstr) - snprintf (msg, sizeof (msg), "%s", rsp.op_errstr); + if (!rsp.op_ret) + snprintf (msg, sizeof (msg)-1, "Quota command " + "successful"); else - snprintf (msg, sizeof (msg), "successful"); + snprintf (msg, sizeof (msg)-1, "Quota command failed"); } xml_output: |