diff options
author | Krutika Dhananjay <kdhananj@redhat.com> | 2013-08-07 18:38:17 +0530 |
---|---|---|
committer | Krutika Dhananjay <kdhananj@redhat.com> | 2013-08-09 15:20:17 +0530 |
commit | c804a1c5ac6c5e3b50c2d4d3e092142d7a15338e (patch) | |
tree | 7c5b70a5e90babf5871ee051cab241896e8a65f7 | |
parent | bd8e5775cf79e66dc5909f4a6a8df598f8691496 (diff) |
glusterd,cli: changes to quota list <path> ...
Change-Id: Ia37020c3aa11af6eed3af09cfe390b848b028b6a
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
-rw-r--r-- | cli/src/cli-rpc-ops.c | 325 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 78 |
2 files changed, 82 insertions, 321 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index ae31ddef..05b254c1 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -41,6 +41,7 @@ #include "syscall.h" #include "glusterfs3.h" #include "portmap-xdr.h" +#include "byte-order.h" #include "run.h" @@ -2322,238 +2323,121 @@ out: return ret; } -static void -print_quota_output_for_version_1 (char *path, char *hl, char *mountdir) +static int +print_quota_list_output (char *mountdir, char *default_sl, char *path) { uint64_t used_space = 0; - uint64_t limit_value = 0; + uint64_t avail = 0; char *used_str = NULL; - char abspath[PATH_MAX] = {0,}; - char ret_str[1024] = {0,}; + char *avail_str = NULL; int ret = -1; - - snprintf (abspath, sizeof (abspath) - 1, "%s/%s", mountdir, path); - - ret = sys_lgetxattr (abspath, "trusted.limit.list", (void *) ret_str, - 4096); + char *sl_final = NULL; + char percent_str[20] = {0,}; + char *hl_str = NULL; + + struct { + uint64_t hl; + uint64_t sl; + } existing_limits; + + ret = sys_lgetxattr (mountdir, "trusted.glusterfs.quota.limit-set", + (void *)&existing_limits, + sizeof (existing_limits)); if (ret < 0) { - cli_out ("%-20s %10s", path, hl); - } else { - sscanf (ret_str, "%"PRIu64",%"PRIu64, &used_space, - &limit_value); - - used_str = gf_uint64_2human_readable (used_space); - - if (used_str == NULL) - cli_out ("%-20s %10s %20"PRIu64, path, hl, - used_space); - else - cli_out ("%-20s %10s %20s", path, hl, used_str); + gf_log ("cli", GF_LOG_ERROR, "Failed to get the xattr " + "trusted.glusterfs.quota.limit-set on %s. Reason : %s", + mountdir, strerror (errno)); + goto out; } - GF_FREE (used_str); - return; -} - -static void -print_quota_output_for_version_2 (char *path, char *hl, char *sl, - char *mountdir) -{ - uint64_t used_space = 0; - uint64_t limit_value = 0; - uint64_t hard_limit = 0; - uint64_t avail = 0; - char *used_str = NULL; - char *avail_str = NULL; - char abspath[PATH_MAX] = {0,}; - char ret_str[1024] = {0,}; - int ret = -1; + existing_limits.hl = ntoh64 (existing_limits.hl); + existing_limits.sl = ntoh64 (existing_limits.sl); + hl_str = gf_uint64_2human_readable (existing_limits.hl); - snprintf (abspath, sizeof (abspath) - 1, "%s/%s", mountdir, path); + if (existing_limits.sl == 0) { + sl_final = default_sl; + } else { + snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%", + existing_limits.sl); + sl_final = percent_str; + } - ret = sys_lgetxattr (abspath, "trusted.limit.list", (void *) ret_str, - 4096); + ret = sys_lgetxattr (mountdir, "trusted.glusterfs.quota.size", + &used_space, sizeof (used_space)); if (ret < 0) { - cli_out ("%-40s %7s %9s %11s %7s", path, hl, sl, "N/A", "N/A"); + cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, sl_final, + "N/A", "N/A"); } else { - sscanf (ret_str, "%"PRIu64",%"PRIu64, &used_space, - &limit_value); + used_space = ntoh64 (used_space); used_str = gf_uint64_2human_readable (used_space); - ret = gf_string2bytesize (hl, &hard_limit); - - if (hard_limit > used_space) - avail = hard_limit - used_space; + if (existing_limits.hl > used_space) + avail = existing_limits.hl - used_space; else avail = 0; avail_str = gf_uint64_2human_readable (avail); if (used_str == NULL) cli_out ("%-40s %7s %9s %11"PRIu64 - "%9"PRIu64, path, hl, - sl, used_space, avail); + "%9"PRIu64, path, hl_str, + sl_final, used_space, avail); else - cli_out ("%-40s %7s %9s %11s %7s", path, hl, sl, - used_str, avail_str); + cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, + sl_final, used_str, avail_str); } +out: GF_FREE (used_str); GF_FREE (avail_str); - return; -} - -static void -gf_quota_print_limit_list (char *path, char *hl, char *sl, char *mountdir, - uint32_t op_version) -{ - if (op_version == 1) - print_quota_output_for_version_1 (path, hl, mountdir); - else - print_quota_output_for_version_2 (path, hl, sl, mountdir); -} - -void -gf_cli_quota_print_first_row (uint32_t op_version) -{ - if (op_version == 1) { - cli_out ("\tpath\t\t limit_set \t\t size"); - cli_out ("-----------------------------------------------------" - "-----------------------------"); - } else { - cli_out (" Path Hard-limit " - "Soft-limit Used Available"); - cli_out ("-----------------------------------------------------" - "---------------------------"); - } + GF_FREE (hl_str); + return ret; } int -gf_cli_print_limit_list_from_dict (char *volname, uint32_t op_version, - dict_t *dict, char *default_sl, int count, - char *mountdir, int entry_count, - char *op_errstr) +gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, + char *default_sl, int count, char *op_errstr) { int ret = -1; int i = 0; - int j = 0; char key[1024] = {0,}; - char *limit = NULL; - char path[PATH_MAX] = {0,}; - char *hl = NULL; - char *sl = NULL; - char *sl_final = NULL; + char mountdir[PATH_MAX] = {0,}; + char *path = NULL; if (!dict|| count <= 0) goto out; - if (entry_count == 0) { - if (strlen (op_errstr) == 0) - cli_err ("Limit not set on specified directories"); - goto out; - } + /*To-Do: + * Proper error reporting to handle the case where none of the given + * path arguments are present or have their limits set. + */ - gf_cli_quota_print_first_row (op_version); + cli_out (" Path Hard-limit " + "Soft-limit Used Available"); + cli_out ("-----------------------------------------------------" + "---------------------------"); while (count--) { - j = 0; - sl = NULL; - hl = NULL; snprintf (key, sizeof (key), "path%d", i++); - ret = dict_get_str (dict, key, &limit); + ret = dict_get_str (dict, key, &path); if (ret < 0) { gf_log ("cli", GF_LOG_DEBUG, "Path not present in limit" " list"); continue; } - if (!strcmp (limit, "Not set")) - continue; - - ret = gf_get_hard_limit (limit, &hl); - - ret = gf_get_soft_limit (limit, &sl); - if (ret == 1) - sl_final = sl; - else - sl_final = default_sl; - - while (limit[j] != ':') { - path[j] = limit[j]; - j = j + 1; - } - - path[j] = '\0'; ret = gf_canonicalize_path (path); if (ret) goto out; + snprintf (mountdir, sizeof (mountdir), "/tmp/%s%s", volname, + path); - gf_quota_print_limit_list (path, hl, sl_final, mountdir, - op_version); - - GF_FREE (hl); - GF_FREE (sl); - } -out: - return ret; -} - -int32_t -gf_cli_print_limit_list_from_string (char *volname, char *limit_list, - uint32_t op_version, char *default_sl, - char *mountdir) -{ - int32_t i = 0; - int32_t j = 0; - int32_t len = 0; - int ret = -1; - char path[PATH_MAX] = {0,}; - char *colon_ptr = NULL; - char *sl_final = NULL; - char *hl = NULL; - char *sl = NULL; - - len = strlen (limit_list); - if (len == 0) { - ret = -1; - goto out; - } - - gf_cli_quota_print_first_row (op_version); + ret = print_quota_list_output (mountdir, default_sl, path); - while (i < len) { - j = 0; - sl = hl = NULL; - - while (limit_list [i] != ',' && limit_list [i] != '\0') { - path [j++] = limit_list[i++]; - } - path [j] = '\0'; - //here path[] contains both path and limit value - - ret = gf_get_hard_limit (path, &hl); - ret = gf_get_soft_limit (path, &sl); - - if (ret == 1) - sl_final = sl; - else - sl_final = default_sl; - - colon_ptr = strchr (path, ':'); - *colon_ptr = '\0'; - - gf_quota_print_limit_list (path, hl, sl_final, mountdir, - op_version); - - i++; - - GF_FREE (hl); - GF_FREE (sl); } - out: return ret; } @@ -2612,69 +2496,20 @@ gf_cli_remove_auxiliary_mount (char *volname) } -int -gf_cli_quota_list_run_crawler (char *volname, char *limit_list, dict_t *dict, - int count, char *op_errstr, uint32_t op_version, - char *default_sl, int entry_count) +void +gf_cli_quota_list (char *volname, dict_t *dict, int count, char *op_errstr, + char *default_sl) { - int ret = -1; - runner_t runner = {0,}; - char mountdir [] = "/tmp/mntXXXXXX"; - GF_VALIDATE_OR_GOTO ("cli", volname, out); if (!connected) goto out; - if ((!limit_list) && (count <= 0)) - goto out; - - if (mkdtemp (mountdir) == NULL) { - gf_log ("cli", GF_LOG_WARNING, "failed to create a temporary " - "mount directory"); - ret = -1; - goto out; - } - - /* Mount a temporary client to fetch the disk usage - * of the directory on which the limit is set. - */ - ret = runcmd (SBIN_DIR"/glusterfs", "-s", - "localhost", "--volfile-id", volname, "-l", - DEFAULT_LOG_FILE_DIRECTORY"/quota-list.log", - mountdir, NULL); - if (ret) { - gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs " - "client"); - ret = -1; - goto rm_dir; - } - - if (limit_list) - gf_cli_print_limit_list_from_string (volname, limit_list, - op_version, default_sl, - mountdir); - else if (count > 0) - gf_cli_print_limit_list_from_dict (volname, op_version, dict, - default_sl, count, mountdir, - entry_count, op_errstr); - - runinit (&runner); - runner_add_args (&runner, "umount", -#if GF_LINUX_HOST_OS - "-l", -#endif - mountdir, NULL); - ret = runner_run_reuse (&runner); - if (ret) - runner_log (&runner, "cli", GF_LOG_WARNING, "error executing"); - runner_end (&runner); - -rm_dir: - rmdir (mountdir); + if (count > 0) + gf_cli_print_limit_list_from_dict (volname, dict, default_sl, + count, op_errstr); out: - return ret; - + return; } int @@ -2685,12 +2520,10 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, int ret = -1; dict_t *dict = NULL; char *volname = NULL; - char *limit_list = NULL; int32_t type = 0; call_frame_t *frame = NULL; - uint32_t op_version = 1; char *default_sl = NULL; - int entry_count = 0; + char *limit_list = NULL; if (-1 == req->rpc_status) { goto out; @@ -2736,16 +2569,6 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, gf_log (frame->this->name, GF_LOG_TRACE, "failed to get volname"); - ret = dict_get_str (dict, "limit_list", &limit_list); - if (ret) - gf_log (frame->this->name, GF_LOG_TRACE, - "failed to get limit_list"); - - ret = dict_get_uint32 (dict, "op-version", &op_version); - if (ret) - gf_log (frame->this->name, GF_LOG_TRACE, "failed to get " - "op-version"); - ret = dict_get_str (dict, "default-soft-limit", &default_sl); if (ret) gf_log (frame->this->name, GF_LOG_TRACE, "failed to get " @@ -2760,11 +2583,6 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, if (ret) gf_log (frame->this->name, GF_LOG_TRACE, "failed to get count"); - ret = dict_get_int32 (dict, "entry-count", &entry_count); - if (ret) - gf_log (frame->this->name, GF_LOG_TRACE, "failed to get entry " - "count"); - if (type == GF_QUOTA_OPTION_TYPE_ENABLE) { ret = gf_cli_create_auxiliary_mount (volname); if (ret) @@ -2786,9 +2604,8 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, goto out; } - gf_cli_quota_list_run_crawler (volname, limit_list, dict, count, - rsp.op_errstr, op_version, - default_sl, entry_count); + gf_cli_quota_list (volname, dict, count, rsp.op_errstr, + default_sl); } xml_output: diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index 0db26f4b..9f0fd90c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -395,84 +395,23 @@ _glusterd_quota_get_limit_usages (glusterd_volinfo_t *volinfo, } int32_t -glusterd_quota_get_limit_usages (glusterd_conf_t *priv, - glusterd_volinfo_t *volinfo, char *volname, - dict_t *dict, char **op_errstr, - dict_t *rsp_dict) +glusterd_quota_get_default_soft_limit (glusterd_volinfo_t *volinfo, + dict_t *rsp_dict) { - int32_t i = 0; int32_t ret = 0; - int32_t count = 0; - int entry_count = 0; - char *path = NULL; - char cmd_str [1024] = {0, }; - char *ret_str = NULL; xlator_t *this = NULL; glusterd_conf_t *conf = NULL; char *default_limit = NULL; char *val = NULL; if (rsp_dict == NULL) - return 0; + return -1; this = THIS; GF_ASSERT (this); conf = this->private; GF_ASSERT (conf); - ret = dict_get_int32 (dict, "count", &count); - if (ret < 0) - goto out; - - if (count == 0) { - ret_str = _glusterd_quota_get_limit_usages (volinfo, NULL, - op_errstr); - ret = dict_set_dynstr (rsp_dict, "limit_list", ret_str); - if (ret) - goto out; - } else { - i = 0; - while (count--) { - snprintf (cmd_str, sizeof (cmd_str), "path%d", i++); - - ret = dict_get_str (dict, cmd_str, &path); - if (ret < 0) - goto out; - ret = gf_canonicalize_path (path); - if (ret) { - goto out; - } - - ret_str = _glusterd_quota_get_limit_usages (volinfo, - path, - op_errstr); - /* Despite quota limits being absent on @path, we go - * ahead and place it in @rsp_dict with - * value = "Not set". This is because after commit op, - * as part of aggregation of @rsp_dict with @op_ctx, - * when we copy the rsp_dict into op_ctx, op_ctx would - * still be containing the old key (same as @cmd_str) - * with the old value. In order to overwrite the old - * value, we replace it with "Not set", something that - * the cli can easily interpret as a case of quota - * limits not having been set on the given path. - */ - if (!ret_str) { - ret = dict_set_str (rsp_dict, cmd_str, - "Not set"); - } else { - ret = dict_set_dynstr (rsp_dict, cmd_str, - ret_str); - entry_count = entry_count + 1; - } - } - } - ret = dict_set_int32 (rsp_dict, "entry-count", entry_count); - if (ret) - goto out; - - ret = dict_set_uint32 (rsp_dict, "op-version", conf->op_version); - ret = glusterd_volinfo_get (volinfo, "features.default-soft-limit", &default_limit); if (default_limit) @@ -481,6 +420,13 @@ glusterd_quota_get_limit_usages (glusterd_conf_t *priv, val = gf_strdup ("90%"); ret = dict_set_dynstr (rsp_dict, "default-soft-limit", val); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to set default " + "soft-limit into dict"); + goto out; + } + ret = 0; + out: return ret; } @@ -956,9 +902,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) "quota is disabled"); goto out; } - ret = glusterd_quota_get_limit_usages (priv, volinfo, - volname, dict, - op_errstr, + ret = glusterd_quota_get_default_soft_limit (volinfo, rsp_dict); goto out; |