Whamcloud - gitweb
EX-8042 lipe: Fix size calculation when using -blocks option
authorVitaliy Kuznetsov <vkuznetsov@ddn.com>
Thu, 18 Jan 2024 11:31:36 +0000 (12:31 +0100)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 23 Jan 2024 02:03:43 +0000 (02:03 +0000)
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 <vkuznetsov@ddn.com>
Change-Id: I5dd0ce69cef20ab9a9632798f350cf4c9f96cf25
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53723
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/src/lipe_find3/lf3_parse.y

index 7e4fdc3..c9abddf 100644 (file)
@@ -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[] = {