From dd9e406cf48142e7fa0619d17ccf3ecc71ce36ae Mon Sep 17 00:00:00 2001 From: Anuradha Date: Thu, 5 Dec 2013 19:02:10 +0530 Subject: quota : changes in quota list command Changes are made to quota list command such that it also shows whether hard-limit and soft-limit are exceeded or not. A test case to check the same is added. Change-Id: Idb365acfc5d1f2d9f3373dd5f98573d5fe87b50f BUG: 1038598 Signed-off-by: Anuradha Signed-off-by: Anuradha Talur Reviewed-on: http://review.gluster.org/6441 Reviewed-by: Raghavendra G Tested-by: Gluster Build System --- cli/src/cli-cmd-volume.c | 6 ++-- cli/src/cli-rpc-ops.c | 85 +++++++++++++++++++++++++++++++++--------------- tests/bugs/bug-1038598.t | 76 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 tests/bugs/bug-1038598.t diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 9c29b7f3b..98e384f2f 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1115,9 +1115,11 @@ print_quota_list_header (void) { //Header cli_out (" Path Hard-limit " - "Soft-limit Used Available"); + "Soft-limit Used Available Soft-limit exceeded?" + " Hard-limit exceeded?"); cli_out ("-----------------------------------------------------" - "---------------------------"); + "-----------------------------------------------------" + "-----------------"); } int diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1da1cb90b..bef70357a 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2318,8 +2318,11 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) char *avail_str = NULL; int ret = -1; char *sl_final = NULL; - char percent_str[20] = {0,}; char *hl_str = NULL; + double sl_num = 0; + gf_boolean_t sl = _gf_false; + gf_boolean_t hl = _gf_false; + char percent_str[20] = {0}; struct quota_limit { int64_t hl; @@ -2356,8 +2359,11 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) hl_str = gf_uint64_2human_readable (existing_limits.hl); if (existing_limits.sl < 0) { + ret = gf_string2percent (default_sl, &sl_num); + sl_num = (sl_num * existing_limits.hl) / 100; sl_final = default_sl; } else { + sl_num = (existing_limits.sl * existing_limits.hl) / 100; snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%", existing_limits.sl); sl_final = percent_str; @@ -2367,26 +2373,37 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) &used_space, sizeof (used_space)); if (ret < 0) { - cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, sl_final, - "N/A", "N/A"); + cli_out ("%-40s %7s %9s %11s %7s %15s %20s", + path, hl_str, sl_final, + "N/A", "N/A", "N/A", "N/A"); } else { used_space = ntoh64 (used_space); used_str = gf_uint64_2human_readable (used_space); - if (existing_limits.hl > used_space) + if (existing_limits.hl > used_space) { avail = existing_limits.hl - used_space; - else + hl = _gf_false; + if (used_space > sl_num) + sl = _gf_true; + else + sl = _gf_false; + } else { avail = 0; + hl = sl = _gf_true; + } avail_str = gf_uint64_2human_readable (avail); - if (used_str == NULL) + if (used_str == NULL) { cli_out ("%-40s %7s %9s %11"PRIu64 - "%9"PRIu64, path, hl_str, - sl_final, used_space, avail); - else - cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, - sl_final, used_str, avail_str); + "%9"PRIu64" %15s %18s", path, hl_str, + sl_final, used_space, avail, sl? "Yes" : "No", + hl? "Yes" : "No"); + } else { + cli_out ("%-40s %7s %9s %11s %7s %15s %20s", path, hl_str, + sl_final, used_str, avail_str, sl? "Yes" : "No", + hl? "Yes" : "No"); + } } out: @@ -2425,9 +2442,11 @@ gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, } cli_out (" Path Hard-limit " - "Soft-limit Used Available"); - cli_out ("-----------------------------------------------------" - "---------------------------"); + "Soft-limit Used Available Soft-limit exceeded?" + " Hard-limit exceeded?"); + cli_out ("--------------------------------------------------------" + "--------------------------------------------------------" + "-----------"); while (count--) { snprintf (key, sizeof (key), "path%d", i++); @@ -2458,14 +2477,17 @@ print_quota_list_from_quotad (call_frame_t *frame, dict_t *rsp_dict) int64_t *limit = NULL; char *used_str = NULL; char *avail_str = NULL; - char percent_str[20]= {0}; char *hl_str = NULL; char *sl_final = NULL; char *path = NULL; - char *default_sl = NULL; + char *default_sl = NULL; int ret = -1; cli_local_t *local = NULL; dict_t *gd_rsp_dict = NULL; + double sl_num = 0; + gf_boolean_t sl = _gf_false; + gf_boolean_t hl = _gf_false; + char percent_str[20] = {0,}; local = frame->local; gd_rsp_dict = local->dict; @@ -2502,37 +2524,48 @@ print_quota_list_from_quotad (call_frame_t *frame, dict_t *rsp_dict) hl_str = gf_uint64_2human_readable (existing_limits->hl); if (existing_limits->sl < 0) { + ret = gf_string2percent (default_sl, &sl_num); + sl_num = (sl_num * existing_limits->hl) / 100; sl_final = default_sl; } else { + sl_num = (existing_limits->sl * existing_limits->hl) / 100; snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%", existing_limits->sl); - sl_final = percent_str; + sl_final = percent_str; } ret = dict_get_bin (rsp_dict, QUOTA_SIZE_KEY, (void**)&limit); if (ret < 0) { gf_log ("cli", GF_LOG_WARNING, "size key not present in dict"); - cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, sl_final, - "N/A", "N/A"); + cli_out ("%-40s %7s %9s %11s %7s %15s %20s", path, hl_str, + sl_final, "N/A", "N/A", "N/A", "N/A"); } else { used_space = *limit; used_space = ntoh64 (used_space); used_str = gf_uint64_2human_readable (used_space); - if (existing_limits->hl > used_space) + if (existing_limits->hl > used_space) { avail = existing_limits->hl - used_space; - else + hl = _gf_false; + if (used_space > sl_num) + sl = _gf_true; + else + sl = _gf_false; + } else { avail = 0; - + hl = sl = _gf_true; + } avail_str = gf_uint64_2human_readable (avail); if (used_str == NULL) cli_out ("%-40s %7s %9s %11"PRIu64 - "%9"PRIu64, path, hl_str, - sl_final, used_space, avail); + "%9"PRIu64" %15s %20s", path, hl_str, + sl_final, used_space, avail, sl? "Yes" : "No", + hl? "Yes" : "No"); else - cli_out ("%-40s %7s %9s %11s %7s", path, hl_str, - sl_final, used_str, avail_str); + cli_out ("%-40s %7s %9s %11s %7s %15s %20s", path, + hl_str, sl_final, used_str, avail_str, + sl? "Yes" : "No", hl? "Yes" : "No"); } ret = 0; diff --git a/tests/bugs/bug-1038598.t b/tests/bugs/bug-1038598.t new file mode 100644 index 000000000..22790ad04 --- /dev/null +++ b/tests/bugs/bug-1038598.t @@ -0,0 +1,76 @@ +#!/bin/bash +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info; + +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2}; + +function hard_limit() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $2}' +} + +function soft_limit() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $3}' +} + +function usage() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $4}' +} + +function sl_exceeded() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $6}' +} + +function hl_exceeded() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | grep "$QUOTA_PATH" | awk '{print $7}' + +} + +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; +EXPECT '2' brick_count $V0 + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +TEST $CLI volume quota $V0 enable +sleep 5 + +TEST glusterfs -s $H0 --volfile-id $V0 $M0; + +TEST mkdir -p $M0/test_dir +TEST $CLI volume quota $V0 limit-usage /test_dir 10MB 50 + +EXPECT "10.0MB" hard_limit "/test_dir"; +EXPECT "50%" soft_limit "/test_dir"; + +TEST dd if=/dev/zero of=$M0/test_dir/file1.txt bs=1M count=4 +EXPECT "4.0MB" usage "/test_dir"; +EXPECT 'No' sl_exceeded "/test_dir"; +EXPECT 'No' hl_exceeded "/test_dir"; + +TEST dd if=/dev/zero of=$M0/test_dir/file1.txt bs=1M count=6 +EXPECT "6.0MB" usage "/test_dir"; +EXPECT 'Yes' sl_exceeded "/test_dir"; +EXPECT 'No' hl_exceeded "/test_dir"; + +TEST ! dd if=/dev/zero of=$M0/test_dir/file1.txt bs=1M count=15 +EXPECT 'Yes' sl_exceeded "/test_dir"; +EXPECT 'Yes' hl_exceeded "/test_dir"; + +cleanup; -- cgit