common/punch: Filter fiemap output by FS block size
authorChandan Rajendra <chandan@linux.vnet.ibm.com>
Mon, 24 Sep 2018 15:19:36 +0000 (20:49 +0530)
committerEryu Guan <guaneryu@gmail.com>
Sun, 30 Sep 2018 05:57:50 +0000 (13:57 +0800)
When testing FS instances of block size other than 4k, the output of
fiemap command will not match those in *.out files. This commit adds
an optional "block size" argument to _filter_fiemap() which prints
fiemap output in units of block size.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Tested-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/punch

index 108bad8ec14df9746930bfe7ed9b540411a93b0d..391d439490be683476fceb227c738f58644197d9 100644 (file)
@@ -165,7 +165,11 @@ _test_punch() {
 
 _coalesce_extents()
 {
-       awk -F: '
+       block_size=$1
+
+       [[ -z $block_size ]] && block_size=512
+
+       awk -v block_size="$block_size" -F: '
        {
                range = $2;
                type = $3;
@@ -176,19 +180,24 @@ _coalesce_extents()
 
                if (type != prev_type) {
                        if (prev_type != "")
-                               printf("%u]:%s\n", low - 1, prev_type);
-                       printf("%u: [%u..", out_count++, low);
+                               printf("%u]:%s\n", (low * 512 / block_size) - 1,
+                                       prev_type);
+                       printf("%u: [%u..", out_count++,
+                               (low * 512) / block_size);
                        prev_type = type;
                }
        }
        END {
                if (prev_type != "")
-                       printf("%u]:%s\n", high, prev_type);
+                       printf("%u]:%s\n", ((high + 1) * 512 / block_size) - 1,
+                               prev_type);
        }'
 }
 
 _filter_fiemap()
 {
+       block_size=$1
+
        $AWK_PROG '
                $3 ~ /hole/ {
                        print $1, $2, $3;
@@ -201,7 +210,7 @@ _filter_fiemap()
                $5 ~ /0x[[:xdigit:]]+/ {
                        print $1, $2, "data";
                }' |
-       _coalesce_extents
+       _coalesce_extents $block_size
 }
 
 _filter_fiemap_flags()