linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] common: add helper to count number of exclusive extents in a file
@ 2019-11-05 14:56 fdmanana
  0 siblings, 0 replies; only message in thread
From: fdmanana @ 2019-11-05 14:56 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

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 <fdmanana@suse.com>
---
 common/rc | 9 +++++++++
 1 file changed, 9 insertions(+)

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
-- 
2.11.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-05 14:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05 14:56 [PATCH 2/3] common: add helper to count number of exclusive extents in a file fdmanana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).