btrfs: add test case for logical-resolve
cover btrfs: add test case for logical-resolve
From: Filipe Manana <[email protected]>
Add a test case for btrfs' logical to ino ioctls (v1 and v2). More details on the changelogs.
Filipe Manana (3):
common/btrfs: add helper to get the bytenr for a file extent item
btrfs: add a test case for the logical to ino ioctl
groups: add logical_resolve group for btrfs
common/btrfs | 52 +++++++++++++++ doc/group-names.txt | 1 + tests/btrfs/004 | 2 +- tests/btrfs/287 | 154 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/287.out | 95 +++++++++++++++++++++++++++ tests/btrfs/299 | 20 +----- 6 files changed, 305 insertions(+), 19 deletions(-) create mode 100755 tests/btrfs/287 create mode 100644 tests/btrfs/287.out
Signature · 1 line
2.35.1
PATCH 1/3 common/btrfs: add helper to get the bytenr for a file extent item
From: Filipe Manana <[email protected]>
In upcoming changes there will be the need to find out the logical disk address (bytenr) that a particular file extent item points to. This is already implemented as local functions in the test btrfs/299, which is a bit limited but works fine for that test. Some important or subtle details why it works for this test:
1) It dumps all trees of the filesystem;
2) It relies on fsync'ing a file and then finding the desired file extent item in the log tree from the dump;
3) There's a single subvolume, so it always finds the correct file extent item. In case there were multiple subvolumes, it could pick the wrong file extent item in case we have inodes with the same number on multiple subvolumes (inode numbers are unique only within a subvolume, they are not unique across an entire filesystem).
So add a helper to get the bytenr associated to a file extent item to common/btrfs and use it at btrfs/299 and the upcoming changes.
This helper will dump only the tree of the default subvolume, will sync the filesystem to commit any open transaction and works only in case the filesystem is using the scratch device. This is explicitly documented.
--- common/btrfs | 23 +++++++++++++++++++++++ tests/btrfs/299 | 18 +----------------- 2 files changed, 24 insertions(+), 17 deletions(-)
common/btrfs +23 -0
@@ -624,3 +624,26 @@ _require_btrfs_send_v2() [ $(cat /sys/fs/btrfs/features/send_stream_version) -gt 1 ] || \ _notrun "kernel does not support send stream v2" } + +# Get the bytenr associated to a file extent item at a given file offset. +# +# NOTE: At the moment this only works if the file is on a filesystem on top of +# the scratch device and the file is in the default subvolume (tree id 5). +_btrfs_get_file_extent_item_bytenr() +{ + local file="$1" + local offset="$2" + local ino=$(stat -c "%i" "$file") + local file_extent_key="($ino EXTENT_DATA $offset)" + + _require_btrfs_command inspect-internal dump-tree + + # The tree dump command below works on committed roots, by reading from + # a device directly, so we have to sync the filesystem to commit any + # open transaction. + $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT + + $BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV | \ + grep -A4 "$file_extent_key" | grep "disk byte" | \ + $AWK_PROG '{ print $5 }' +}
tests/btrfs/299 +1 -17
@@ -22,25 +22,10 @@ _begin_fstest auto quick preallocrw _supported_fs btrfs _require_scratch _require_xfs_io_command "falloc" "-k" -_require_btrfs_command inspect-internal dump-tree _require_btrfs_command inspect-internal logical-resolve _fixed_by_kernel_commit 560840afc3e6 \ "btrfs: fix resolving backrefs for inline extent followed by prealloc" -dump_tree() { - $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV -} - -get_extent_data() { - local ino=$1 - dump_tree $SCRATCH_DEV | grep -A4 "($ino EXTENT_DATA " -} - -get_prealloc_offset() { - local ino=$1 - get_extent_data $ino | grep "disk byte" | $AWK_PROG '{print $5}' -} - # This test needs to create conditions s.t. the special inode's inline extent # is the first item in a leaf. Therefore, fix a leaf size and add # items that are otherwise not necessary to reproduce the inline-prealloc
@@ -81,8 +66,7 @@ done # grab the prealloc offset from dump tree while it's still the only # extent data item for the inode -ino=$(stat -c '%i' $f.evil) -logical=$(get_prealloc_offset $ino) +logical=$(_btrfs_get_file_extent_item_bytenr $f.evil 0) # do the "small write; fsync; small write" pattern which reproduces the desired # item pattern of an inline extent followed by a preallocated extent. The 23
Signature · 1 line
2.35.1
PATCH 2/3 btrfs: add a test case for the logical to ino ioctl
In reply to [email protected]From: Filipe Manana <[email protected]>
Add a test case to exercise the logical to ino ioctl, including the v2 version (which adds the ignore offset option). This is motivated by the fact that we have no test cases giving full coverage to that ioctl, only two test cases partially exercise it (btrfs/004 and btrfs/299) and absolutely no coverage for the v2 ioctl. This resulted in a recent regression fixed by the patch mentioned in the _fixed_by_kernel_commit tag of the introduced test case.
--- common/btrfs | 29 +++++++++ tests/btrfs/287 | 154 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/287.out | 95 +++++++++++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100755 tests/btrfs/287 create mode 100644 tests/btrfs/287.out
common/btrfs +29 -0
@@ -647,3 +647,32 @@ _btrfs_get_file_extent_item_bytenr() grep -A4 "$file_extent_key" | grep "disk byte" | \ $AWK_PROG '{ print $5 }' } + +# Check that btrfs-progs has support for the logical-resolve command, with the +# -o option, and that the kernel supports the logical to ino ioctl v2 (which +# adds the ignore offset parameter). +_require_btrfs_scratch_logical_resolve_v2() +{ + local bytenr + + # First check if we have support for calling the v2 logical resolve + # ioctl in btrfs-progs. Check if the -o options exists, which makes + # btrfs-progs call v2 of the ioctl (because the flag + # BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET is only supported in v2). + _require_btrfs_command inspect-internal logical-resolve -o + _require_scratch + + _scratch_mkfs > /dev/null || \ + _fail "_require_btrfs_scratch_logical_resolve_v2: mkfs failed" + _scratch_mount + + $XFS_IO_PROG -f -c "pwrite -q 0 128K" "$SCRATCH_MNT/file1" + bytenr=$(_btrfs_get_file_extent_item_bytenr "$SCRATCH_MNT/file1" 0) + $BTRFS_UTIL_PROG inspect-internal logical-resolve -o $bytenr \ + $SCRATCH_MNT > /dev/null + if [ $? -ne 0 ]; then + _scratch_unmount + _notrun "Logical resolve ioctl v2 not supported in the kernel" + fi + _scratch_unmount +}
tests/btrfs/287 new file +154 -0
154 lines not on this page · raw message
tests/btrfs/287.out new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH 3/3 groups: add logical_resolve group for btrfs
In reply to [email protected]From: Filipe Manana <[email protected]>
Add a 'logical_resolve' group to identify tests that use the btrfs logical-resolve command, which exercises btrfs' logical to ino ioctl.
--- doc/group-names.txt | 1 + tests/btrfs/004 | 2 +- tests/btrfs/287 | 2 +- tests/btrfs/299 | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-)
doc/group-names.txt +1 -0
@@ -70,6 +70,7 @@ label filesystem labelling limit resource limits locks file locking log metadata logging +logical_resolve btrfs logical to ino ioctl (logical-resolve command) logprint xfs_logprint functional tests long_rw long-soak read write IO path exercisers metacopy overlayfs metadata-only copy-up
tests/btrfs/004 +1 -1
@@ -10,7 +10,7 @@ # We check to end up back at the original file with the correct offset. # . ./common/preamble -_begin_fstest auto rw metadata fiemap +_begin_fstest auto rw metadata fiemap logical_resolve noise_pid=0
tests/btrfs/287 +1 -1
@@ -7,7 +7,7 @@ # Test btrfs' logical to inode ioctls (v1 and v2). # . ./common/preamble -_begin_fstest auto quick snapshot clone punch +_begin_fstest auto quick snapshot clone punch logical_resolve . ./common/filter . ./common/reflink
tests/btrfs/299 +1 -1
@@ -15,7 +15,7 @@ # resolution is still successful. # . ./common/preamble -_begin_fstest auto quick preallocrw +_begin_fstest auto quick preallocrw logical_resolve # real QA test starts here # Modify as appropriate.
Signature · 1 line
2.35.1
Re: [PATCH 3/3] groups: add logical_resolve group for btrfs
Thanks.
Re: [PATCH 2/3] btrfs: add a test case for the logical to ino ioctl
In reply to [email protected]Looks good.
Re: [PATCH 1/3] common/btrfs: add helper to get the bytenr for a file extent item
In reply to [email protected]Looks good.