From: Filipe Manana Date: Tue, 5 Nov 2019 14:56:40 +0000 (+0000) Subject: common: add helper to count number of exclusive extents in a file X-Git-Tag: v2022.05.01~959 X-Git-Url: http://git.apps.os.sepia.ceph.com/?p=xfstests-dev.git;a=commitdiff_plain;h=6fb111ab6089922ba94e83b888f57b2fe999fdbf common: add helper to count number of exclusive extents in a file Add a new helper that is similar to _count_extents() except that extents that are shared several times by the file with itself (reflinked at different file offsets) are accounted 1 time only, instead of N times. This is motivated by a subsequent test for btrfs that will use this new helper, to verify that send streams are issuing reflink operations. Signed-off-by: Filipe Manana Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/common/rc b/common/rc index 238ffef9..3c412178 100644 --- a/common/rc +++ b/common/rc @@ -3202,6 +3202,15 @@ _count_extents() $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l } +# Similar to _count_extents() but if any extent is shared multiples times in +# the file (reflinked to different file offsets), it is accounted as 1 extent +# instead of N extents. +_count_exclusive_extents() +{ + $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep -v hole | \ + cut -d ' ' -f 3 | sort | uniq | wc -l +} + _count_holes() { $XFS_IO_PROG -r -c "fiemap" $1 | tail -n +2 | grep hole | wc -l