]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/filter: add _filter_filefrag
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 17 May 2017 22:36:06 +0000 (16:36 -0600)
committerEryu Guan <eguan@redhat.com>
Fri, 19 May 2017 07:06:30 +0000 (15:06 +0800)
_filter_filefrag is a helper function to filter filefrag's output
and it can be used to get a file's file offset and physical offset.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/filter

index 5fd71a887a77b61beba8ffcfdb93614dc332e1bc..1ef342b59726e2b31fc19be13e26a8d550f68b74 100644 (file)
@@ -418,5 +418,24 @@ _filter_ovl_dirs()
            -e "s,$OVL_WORK,OVL_WORK,g"
 }
 
+# interpret filefrag output,
+# eg. "physical 1234, length 10, logical 5678" -> "1234#10#5678"
+_filter_filefrag()
+{
+       perl -ne '
+       if (/blocks? of (\d+) bytes/) {
+               $blocksize = $1;
+               next
+       }
+       ($ext, $logical, $physical, $length) =
+               (/^\s*(\d+):\s+(\d+)..\s+\d+:\s+(\d+)..\s+\d+:\s+(\d+):/)
+       or next;
+       ($flags) = /.*:\s*(\S*)$/;
+       print $physical * $blocksize, "#",
+             $length * $blocksize, "#",
+             $logical * $blocksize, "#",
+             $flags, "\n"'
+}
+
 # make sure this script returns success
 /bin/true