From 1f02429a7aa520fd2f9f212d73d102e3fa55f2c0 Mon Sep 17 00:00:00 2001 From: Vitaliy Kuznetsov Date: Thu, 18 Jan 2024 12:31:36 +0100 Subject: [PATCH] EX-8042 lipe: Fix size calculation when using -blocks option This patch fixes the size calculation in the "-blocks" option when specifying the exact size value "n[bkMG]". Test-Parameters: trivial testlist=sanity-lipe-find3 Signed-off-by: Vitaliy Kuznetsov Change-Id: I5dd0ce69cef20ab9a9632798f350cf4c9f96cf25 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53723 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lipe/src/lipe_find3/lf3_parse.y | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lipe/src/lipe_find3/lf3_parse.y b/lipe/src/lipe_find3/lf3_parse.y index 7e4fdc3..c9abddf 100644 --- a/lipe/src/lipe_find3/lf3_parse.y +++ b/lipe/src/lipe_find3/lf3_parse.y @@ -39,6 +39,8 @@ static unsigned long long lf3_now = -1; # define LF3_SCAN_PROGRAM "lipe_scan3" #endif +#define LF3_SCAN_BLOCK_SIZE 512 + static const char LF3_SCAN_COMMAND[] = LF3_SCAN_PROGRAM " --script=/dev/stdin"; static const char LF3_SCM_SCAN_PROC[] = "lipe-scan"; static char *lf3_policy_body; @@ -324,6 +326,7 @@ static char *lf3_size_expr(const char *which, int begin, int end) char cmp; __ull val; __ull unit; + __ull tmp_val; int rc; /* @which should be "size" or "blocks" @@ -337,6 +340,15 @@ static char *lf3_size_expr(const char *which, int begin, int end) if (rc < 0) LF3_FATAL_AT(begin + 1, "invalid size '%s'\n", size_str); + /* When the "-blocks" option comes with a size "n[bkMG]", the size + * should be calculated correctly. */ + if (strcmp(which, "blocks") == 0 && unit != 1 && unit != 2) { + tmp_val = val * (unit / LF3_SCAN_BLOCK_SIZE); + unit = LF3_SCAN_BLOCK_SIZE; + } else { + tmp_val = unit * val; + } + /* From find(1): The + and - prefixes signify greater than and * less than, as usual; i.e., an exact size of n units does * not match. Bear in mind that the size is rounded up to the @@ -351,13 +363,13 @@ static char *lf3_size_expr(const char *which, int begin, int end) cmp, which, unit, - unit * val); + tmp_val); else return xsprintf("(%c (round-up (%s) %llu) %llu)", cmp, which, unit, - unit * val); + tmp_val); } static const struct lf3_unit lf3_time_units[] = { -- 1.8.3.1