diff options
author | Manikandan Selvaganesh <mselvaga@redhat.com> | 2015-11-25 00:04:39 +0530 |
---|---|---|
committer | Kaushal M <kaushal@redhat.com> | 2015-12-10 06:14:53 -0800 |
commit | e0b2bcf34b57f75a244ef88341b0f3d5990c768b (patch) | |
tree | 6dbf6c2ead2c1795b4659c8334541c8492a565c4 /cli | |
parent | fe96043b80c647513c2d3a7d63ef9548f92ce11c (diff) |
quota: show used_space,(file,dir) count even when quota limit is not set
Problem:
As of now quota 'list/list-objects' will list the usage only if limit is
set for every directory else it will fail with ENOATTR(If inode/inode-quota
is already configured for the first time).
Feature:
With the patch we are enhancing this command to list the usage even
if quota limit is not set but still the user has to configure
inode/inode-quota for the first time.
Example:
Consider we have /client/dir and /client1(absolute path from mount point):
Quota limit is set only on /client. when we try listing /client/dir or /client1,
it shows "Limit not set".
Fix:
The patch fixes this by showing "used space" in case of list command and
shows "file_count" & "dir_count" in case of list-objects command. This works
fine with xml output as well.
Backport of http://review.gluster.org/#/c/12741/
Cherry-picked from commit 608c646cc00e2c1c0b9c87e9fd7cb9e1eb271db2
> Change-Id: I68b08ec77a583b3c7f39fe4d6b15d3d77adb095a
> BUG: 1284752
> Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
Change-Id: I68b08ec77a583b3c7f39fe4d6b15d3d77adb095a
BUG: 1289063
Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
Reviewed-on: http://review.gluster.org/12893
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-rpc-ops.c | 134 | ||||
-rw-r--r-- | cli/src/cli-xml-output.c | 21 | ||||
-rw-r--r-- | cli/src/cli.h | 5 |
3 files changed, 105 insertions, 55 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1c0eeaf60aa..110cba44704 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2989,7 +2989,8 @@ static int print_quota_list_usage_output (cli_local_t *local, char *path, int64_t avail, char *sl_str, quota_limits_t *limits, quota_meta_t *used_space, gf_boolean_t sl, - gf_boolean_t hl, double sl_num) + gf_boolean_t hl, double sl_num, + gf_boolean_t limit_set) { int32_t ret = -1; char *used_str = NULL; @@ -2997,17 +2998,20 @@ print_quota_list_usage_output (cli_local_t *local, char *path, int64_t avail, char *hl_str = NULL; char *sl_val = NULL; - hl_str = gf_uint64_2human_readable (limits->hl); used_str = gf_uint64_2human_readable (used_space->size); - avail_str = gf_uint64_2human_readable (avail); - sl_val = gf_uint64_2human_readable (sl_num); + if (limit_set) { + hl_str = gf_uint64_2human_readable (limits->hl); + avail_str = gf_uint64_2human_readable (avail); + + sl_val = gf_uint64_2human_readable (sl_num); + } if (global_state->mode & GLUSTER_MODE_XML) { ret = cli_quota_xml_output (local, path, limits->hl, sl_str, sl_num, used_space->size, avail, sl ? "Yes" : "No", - hl ? "Yes" : "No"); + hl ? "Yes" : "No", limit_set); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to " "output in xml format for quota " @@ -3016,14 +3020,22 @@ print_quota_list_usage_output (cli_local_t *local, char *path, int64_t avail, goto out; } - if (!used_str) { - cli_out ("%-40s %7s %7s(%s) %8"PRIu64 "%9"PRIu64" %15s %18s", - path, hl_str, sl_str, sl_val, used_space->size, avail, - sl ? "Yes" : "No", hl ? "Yes" : "No"); + if (limit_set) { + if (!used_str) { + cli_out ("%-40s %7s %7s(%s) %8"PRIu64 "%9"PRIu64"" + "%15s %18s", path, hl_str, sl_str, sl_val, + used_space->size, avail, + sl ? "Yes" : "No", hl ? "Yes" : "No"); + } else { + cli_out ("%-40s %7s %7s(%s) %8s %7s %15s %20s", + path, hl_str, sl_str, sl_val, used_str, + avail_str, sl ? "Yes" : "No", + hl ? "Yes" : "No"); + } } else { - cli_out ("%-40s %7s %7s(%s) %8s %7s %15s %20s", path, hl_str, - sl_str, sl_val, used_str, avail_str, sl ? "Yes" : "No", - hl ? "Yes" : "No"); + cli_out ("%-36s %10s %10s %14s %9s %15s %18s", + path, "N/A", "N/A", used_str, "N/A", + "N/A", "N/A"); } ret = 0; @@ -3040,7 +3052,8 @@ static int print_quota_list_object_output (cli_local_t *local, char *path, int64_t avail, char *sl_str, quota_limits_t *limits, quota_meta_t *used_space, gf_boolean_t sl, - gf_boolean_t hl, double sl_num) + gf_boolean_t hl, double sl_num, + gf_boolean_t limit_set) { int32_t ret = -1; int64_t sl_val = sl_num; @@ -3049,7 +3062,8 @@ print_quota_list_object_output (cli_local_t *local, char *path, int64_t avail, ret = cli_quota_object_xml_output (local, path, sl_str, sl_val, limits, used_space, avail, sl ? "Yes" : "No", - hl ? "Yes" : "No"); + hl ? "Yes" : "No", + limit_set); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to " "output in xml format for quota " @@ -3058,11 +3072,17 @@ print_quota_list_object_output (cli_local_t *local, char *path, int64_t avail, goto out; } - cli_out ("%-40s %9"PRIu64" %9s(%"PRId64") %10"PRIu64" %10"PRIu64 - "%11"PRIu64" %15s %20s", path, limits->hl, sl_str, sl_val, - used_space->file_count, used_space->dir_count, - avail, sl ? "Yes" : "No", hl ? "Yes" : "No"); - + if (limit_set) { + cli_out ("%-40s %9"PRIu64" %9s(%"PRId64") %10"PRIu64"" + "%10"PRIu64" %11"PRIu64" %15s %20s", + path, limits->hl, sl_str, sl_val, + used_space->file_count, used_space->dir_count, + avail, sl ? "Yes" : "No", hl ? "Yes" : "No"); + } else { + cli_out ("%-40s %9s %9s %10"PRIu64" %10"PRIu64" %11s %15s %20s", + path, "N/A", "N/A", used_space->file_count, + used_space->dir_count, "N/A", "N/A", "N/A"); + } ret = 0; out: @@ -3073,7 +3093,7 @@ out: static int print_quota_list_output (cli_local_t *local, char *path, char *default_sl, quota_limits_t *limits, quota_meta_t *used_space, - int type) + int type, gf_boolean_t limit_set) { int64_t avail = 0; char percent_str[20] = {0}; @@ -3087,43 +3107,45 @@ print_quota_list_output (cli_local_t *local, char *path, char *default_sl, GF_ASSERT (local); GF_ASSERT (path); - if (limits->sl < 0) { - ret = gf_string2percent (default_sl, &sl_num); - sl_num = (sl_num * limits->hl) / 100; - sl_final = default_sl; - } else { - sl_num = (limits->sl * limits->hl) / 100; - snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%", - limits->sl); - sl_final = percent_str; - } - if (type == GF_QUOTA_OPTION_TYPE_LIST) - used_size = used_space->size; - else - used_size = used_space->file_count + used_space->dir_count; - - if (limits->hl > used_size) { - avail = limits->hl - used_size; - hl = _gf_false; - if (used_size > sl_num) - sl = _gf_true; + if (limit_set) { + if (limits->sl < 0) { + ret = gf_string2percent (default_sl, &sl_num); + sl_num = (sl_num * limits->hl) / 100; + sl_final = default_sl; + } else { + sl_num = (limits->sl * limits->hl) / 100; + snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%", + limits->sl); + sl_final = percent_str; + } + if (type == GF_QUOTA_OPTION_TYPE_LIST) + used_size = used_space->size; else - sl = _gf_false; - } else { - avail = 0; - hl = sl = _gf_true; + used_size = used_space->file_count + used_space->dir_count; + + if (limits->hl > used_size) { + avail = limits->hl - used_size; + hl = _gf_false; + if (used_size > sl_num) + sl = _gf_true; + else + sl = _gf_false; + } else { + avail = 0; + hl = sl = _gf_true; + } } if (type == GF_QUOTA_OPTION_TYPE_LIST) ret = print_quota_list_usage_output (local, path, avail, sl_final, limits, used_space, sl, hl, - sl_num); + sl_num, limit_set); else ret = print_quota_list_object_output (local, path, avail, sl_final, limits, used_space, sl, hl, - sl_num); + sl_num, limit_set); return ret; } @@ -3137,6 +3159,7 @@ print_quota_list_from_mountdir (cli_local_t *local, char *mountdir, quota_limits_t limits = {0,}; quota_meta_t used_space = {0,}; char *key = NULL; + gf_boolean_t limit_set = _gf_true; GF_ASSERT (local); GF_ASSERT (mountdir); @@ -3160,8 +3183,20 @@ print_quota_list_from_mountdir (cli_local_t *local, char *mountdir, #if defined(ENOATTR) && (ENOATTR != ENODATA) case ENOATTR: #endif - cli_err ("%-40s %s", path, "Limit not set"); + /* If it's an ENOATTR, quota/inode-quota is + * configured(limit is set atleast for one directory). + * The user is trying to issue 'list/list-objects' + * command for a directory on which quota limit is + * not set and we are showing the used-space in case + * of list-usage and showing (dir_count, file_count) + * in case of list-objects. Other labels are + * shown "N/A". + */ + + limit_set = _gf_false; + goto enoattr; break; + default: cli_err ("%-40s %s", path, strerror (errno)); break; @@ -3173,6 +3208,7 @@ print_quota_list_from_mountdir (cli_local_t *local, char *mountdir, limits.hl = ntoh64 (limits.hl); limits.sl = ntoh64 (limits.sl); +enoattr: xattr_size = sys_lgetxattr (mountdir, QUOTA_SIZE_KEY, NULL, 0); if (xattr_size < (sizeof (int64_t) * 2) && type == GF_QUOTA_OPTION_TYPE_LIST_OBJECTS) { @@ -3208,7 +3244,7 @@ print_quota_list_from_mountdir (cli_local_t *local, char *mountdir, used_space.dir_count = ntoh64 (used_space.dir_count); ret = print_quota_list_output (local, path, default_sl, &limits, - &used_space, type); + &used_space, type, limit_set); out: return ret; } @@ -3409,7 +3445,7 @@ print_quota_list_from_quotad (call_frame_t *frame, dict_t *rsp_dict) } ret = print_quota_list_output (local, path, default_sl, &limits, - &used_space, type); + &used_space, type, _gf_true); out: return ret; } diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 9fa13c8279b..0801d61eeea 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -6187,7 +6187,8 @@ out: int cli_quota_xml_output (cli_local_t *local, char *path, int64_t hl_str, char *sl_final, int64_t sl_num, int64_t used, - int64_t avail, char *sl, char *hl) + int64_t avail, char *sl, char *hl, + gf_boolean_t limit_set) { #if (HAVE_LIB_XML) int ret = -1; @@ -6202,16 +6203,19 @@ cli_quota_xml_output (cli_local_t *local, char *path, int64_t hl_str, ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"hard_limit", + !limit_set ? "N/A" : "%"PRIu64, hl_str); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"soft_limit_percent", + !limit_set ? "N/A" : "%s", sl_final); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"soft_limit_value", + !limit_set ? "N/A" : "%"PRIu64, sl_num); XML_RET_CHECK_AND_GOTO (ret, out); @@ -6222,16 +6226,19 @@ cli_quota_xml_output (cli_local_t *local, char *path, int64_t hl_str, ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"avail_space", + !limit_set ? "N/A" : "%"PRIu64, avail); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"sl_exceeded", + !limit_set ? "N/A" : "%s", sl); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"hl_exceeded", + !limit_set ? "N/A" : "%s", hl); XML_RET_CHECK_AND_GOTO (ret, out); @@ -6250,7 +6257,7 @@ int cli_quota_object_xml_output (cli_local_t *local, char *path, char *sl_str, int64_t sl_val, quota_limits_t *limits, quota_meta_t *used_space, int64_t avail, - char *sl, char *hl) + char *sl, char *hl, gf_boolean_t limit_set) { #if (HAVE_LIB_XML) int ret = -1; @@ -6265,16 +6272,19 @@ cli_quota_object_xml_output (cli_local_t *local, char *path, char *sl_str, ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"hard_limit", + !limit_set ? "N/A" : "%"PRIu64, limits->hl); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"soft_limit_percent", + !limit_set ? "N/A" : "%s", sl_str); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"soft_limit_value", + !limit_set ? "N/A" : "%"PRIu64, sl_val); XML_RET_CHECK_AND_GOTO (ret, out); @@ -6293,18 +6303,21 @@ cli_quota_object_xml_output (cli_local_t *local, char *path, char *sl_str, ret = xmlTextWriterWriteFormatElement (local->writer, - (xmlChar *)"available", "%"PRIu64, - avail); + (xmlChar *)"available", + !limit_set ? "N/A" : + "%"PRIu64, avail); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"sl_exceeded", + !limit_set ? "N/A" : "%s", sl); XML_RET_CHECK_AND_GOTO (ret, out); ret = xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"hl_exceeded", + !limit_set ? "N/A" : "%s", hl); XML_RET_CHECK_AND_GOTO (ret, out); diff --git a/cli/src/cli.h b/cli/src/cli.h index 59315797eef..1f5704fd25a 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -405,13 +405,14 @@ cli_quota_list_xml_error (cli_local_t *local, char *path, int cli_quota_xml_output (cli_local_t *local, char *path, int64_t hl_str, char *sl_final, int64_t sl_num, int64_t used, - int64_t avail, char *sl, char *hl); + int64_t avail, char *sl, char *hl, + gf_boolean_t limit_set); int cli_quota_object_xml_output (cli_local_t *local, char *path, char *sl_str, int64_t sl_val, quota_limits_t *limits, quota_meta_t *used_space, int64_t avail, - char *sl, char *hl); + char *sl, char *hl, gf_boolean_t limit_set); int cli_xml_output_peer_status (dict_t *dict, int op_ret, int op_errno, |