From 499a4627b70d8b5fabd7e4cf2119a5c99bed4282 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Tue, 26 Nov 2013 22:27:01 -0500 Subject: [PATCH] LU-4028 quota: fix output of 'lfs quota' Fix the output of 'lfs quota' when '-h' option is specified: - total allocated block limit should be converted after calculation; - show 1~3 digit after the decimal point; Lustre-commit: 69dda0cf5fb34a1a7ff93468ca1c155dd3a53060 Lustre-change: http://review.whamcloud.com/8407 Signed-off-by: Niu Yawei Signed-off-by: Bob Glossman Reviewed-by: Johann Lombardi Reviewed-by: Andreas Dilger Change-Id: Ibed84a73b87cf741c9122216dc8c45f3a33a78d8 Reviewed-on: http://review.whamcloud.com/10412 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/tests/sanity-quota.sh | 12 ++++++++++-- lustre/utils/lfs.c | 10 +++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 284ea45..b7d36e9 100644 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -2017,9 +2017,17 @@ test_27c() { error "lfs setquota failed" limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}') - [ $limit != "30M" ] && error "softlimit isn't human-readable" + [ $limit != "30M" ] && error "softlimit $limit isn't human-readable" limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}') - [ $limit != "3T" ] && error "hardlimit isn't human-readable" + [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable" + + $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR || + error "lfs setquota for $TSTID failed" + + limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}') + [ $limit != "1.465G" ] && error "wrong softlimit $limit" + limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}') + [ $limit != "18.07T" ] && error "wrong hardlimit $limit" $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" || error "total allocated inode/block limit not printed" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index f5ac562..0698744 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2572,13 +2572,13 @@ static void kbytes2str(__u64 num, char *buf, bool h) sprintf(buf, LPU64, num); } else { if (num >> 30) - sprintf(buf, LPU64"%s", num >> 30, "T"); + sprintf(buf, "%5.4gT", (double)num / (1 << 30)); else if (num >> 20) - sprintf(buf, LPU64"%s", num >> 20, "G"); + sprintf(buf, "%5.4gG", (double)num / (1 << 20)); else if (num >> 10) - sprintf(buf, LPU64"%s", num >> 10, "M"); + sprintf(buf, "%5.4gM", (double)num / (1 << 10)); else - sprintf(buf, LPU64"%s", num, "K"); + sprintf(buf, LPU64"%s", num, "k"); } } @@ -2869,11 +2869,11 @@ ug_output: verbose) { char strbuf[32]; - kbytes2str(total_balloc, strbuf, human_readable); rc2 = print_obd_quota(mnt, &qctl, 1, human_readable, &total_ialloc); rc3 = print_obd_quota(mnt, &qctl, 0, human_readable, &total_balloc); + kbytes2str(total_balloc, strbuf, human_readable); printf("Total allocated inode limit: "LPU64", total " "allocated block limit: %s\n", total_ialloc, strbuf); } -- 1.8.3.1