Skip to contentSkip to conversation

btrfs: make test pass or skip them when using nodatacow

PATCH In review [email protected] 2 participants 7 messages Feb 1, 2024 – Feb 5, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: make test pass or skip them when using nodatacow

From: Filipe Manana <[email protected]>

Several test btrfs test cases fail when using "-o nodatacow" in MOUNT_OPTIONS. So fix that by either adapting the tests to pass or skip them if there's no way for them to succeed in nodatacow mode.

Filipe Manana (4):
btrfs: require no nodatacow for tests that exercise compression btrfs/173: make the test work when mounting with nodatacow btrfs/299: skip test if we were mounted with nodatacow
btrfs: require no nodatacow for tests that exercise read repair

 tests/btrfs/024 | 1 +
 tests/btrfs/048 | 1 +
 tests/btrfs/059 | 1 +
 tests/btrfs/138 | 1 +
 tests/btrfs/140 | 3 ++-
 tests/btrfs/141 | 2 ++
 tests/btrfs/157 | 2 ++
 tests/btrfs/158 | 2 ++
 tests/btrfs/173 | 5 +++++
 tests/btrfs/215 | 2 ++
 tests/btrfs/234 | 1 +
 tests/btrfs/265 | 2 ++
 tests/btrfs/266 | 2 ++
 tests/btrfs/267 | 2 ++
 tests/btrfs/268 | 2 ++
 tests/btrfs/269 | 2 ++
 tests/btrfs/281 | 1 +
 tests/btrfs/289 | 2 ++
 tests/btrfs/299 | 3 +++
 19 files changed, 36 insertions(+), 1 deletion(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/4 btrfs: require no nodatacow for tests that exercise compression

From: Filipe Manana <[email protected]>

Several test cases fail when running with MOUNT_OPTIONS="-o nodatacow" because they attempt to use compression and compression can not be enabled on nodatacow files (it fails with -EINVAL). So make sure those tests are not run if nodatacow is specified in MOUNT_OPTIONS.

---
 tests/btrfs/024 | 1 +
 tests/btrfs/048 | 1 +
 tests/btrfs/059 | 1 +
 tests/btrfs/138 | 1 +
 tests/btrfs/234 | 1 +
 tests/btrfs/281 | 1 +
 6 files changed, 6 insertions(+)
tests/btrfs/024 +1 -0
index 95c734ec..a8ca0e1d 100755
@@ -17,6 +17,7 @@ _begin_fstest auto quick compress
 # real QA test starts here
 _supported_fs btrfs
 _require_scratch
+_require_btrfs_no_nodatacow
 
 __workout()
 {
tests/btrfs/048 +1 -0
index 8a88b8cc..aa2030b1 100755
@@ -30,6 +30,7 @@ _require_test
 _require_scratch
 _require_btrfs_command "property"
 _require_btrfs_command inspect-internal dump-super
+_require_btrfs_no_nodatacow
 
 send_files_dir=$TEST_DIR/btrfs-test-$seq
 
tests/btrfs/059 +1 -0
index 76a1e76e..8b458b34 100755
@@ -28,6 +28,7 @@ _supported_fs btrfs
 _require_test
 _require_scratch
 _require_btrfs_command "property"
+_require_btrfs_no_nodatacow
 
 _scratch_mkfs >> $seqres.full 2>&1
 _scratch_mount
tests/btrfs/138 +1 -0
index f99e58e7..427fdede 100755
@@ -18,6 +18,7 @@ _begin_fstest auto compress
 _supported_fs btrfs
 _require_scratch
 _require_btrfs_command property
+_require_btrfs_no_nodatacow
 
 algos=($(_btrfs_compression_algos))
 
tests/btrfs/234 +1 -0
index c045ea6c..542515e8 100755
@@ -18,6 +18,7 @@ _begin_fstest auto quick compress rw
 _supported_fs btrfs
 _require_scratch
 _require_odirect
+_require_btrfs_no_nodatacow
 _require_chattr c
 
 _scratch_mkfs >>$seqres.full 2>&1
tests/btrfs/281 +1 -0
index 63fb89ea..64075225 100755
@@ -25,6 +25,7 @@ _require_scratch_reflink
 _require_btrfs_send_v2
 _require_xfs_io_command "fiemap"
 _require_fssum
+_require_btrfs_no_nodatacow
 
 _fixed_by_kernel_commit a11452a3709e \
 	"btrfs: send: avoid unaligned encoded writes when attempting to clone range"
Signature · 1 line
2.40.1
#2 lore raw

PATCH 2/4 btrfs/173: make the test work when mounting with nodatacow

In reply to [email protected]

From: Filipe Manana <[email protected]>

Currently btrfs/173 fails when passing "-o nodatacow" to MOUNT_OPTIONS because it assumes that when creating a file it does not have the nodatacow flag set, which is obviously not true if the fs is mounted with "-o nodatacow". To allow the test to run successfully with nodatacow, just make sure it clears the nodatacow flag from the file if the fs was mounted with "-o nodatacow".

---
 tests/btrfs/173 | 5 +++++
 1 file changed, 5 insertions(+)
tests/btrfs/173 +5 -0
index 6e78a826..42af2d26 100755
@@ -23,6 +23,11 @@ echo "COW file"
 # unset it after the swap file has been created.
 rm -f "$SCRATCH_MNT/swap"
 touch "$SCRATCH_MNT/swap"
+# Make sure we have a COW file if we were mounted with "-o nodatacow".
+if _normalize_mount_options "$MOUNT_OPTIONS" | grep -q "nodatacow"; then
+	_require_chattr C
+	$CHATTR_PROG -C "$SCRATCH_MNT/swap"
+fi
 chmod 0600 "$SCRATCH_MNT/swap"
 _pwrite_byte 0x61 0 $(($(_get_page_size) * 10)) "$SCRATCH_MNT/swap" >> $seqres.full
 $MKSWAP_PROG "$SCRATCH_MNT/swap" >> $seqres.full
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH 2/4] btrfs/173: make the test work when mounting with nodatacow

Quoted 19 lines · On Thu, 1 Feb 2024 18:03:48 +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

Currently btrfs/173 fails when passing "-o nodatacow" to MOUNT_OPTIONS because it assumes that when creating a file it does not have the nodatacow flag set, which is obviously not true if the fs is mounted with "-o nodatacow". To allow the test to run successfully with nodatacow, just make sure it clears the nodatacow flag from the file if the fs was mounted with "-o nodatacow".

---
 tests/btrfs/173 | 5 +++++
 1 file changed, 5 insertions(+)
tests/btrfs/173 +0 -0
index 6e78a826..42af2d26 100755

tests/btrfs/173 echo "COW file" · line 30

Quoted 8 lines
tests/btrfs/173 +5 -0
@@ -23,6 +23,11 @@ echo "COW file"
 # unset it after the swap file has been created.
 rm -f "$SCRATCH_MNT/swap"
 touch "$SCRATCH_MNT/swap"
+# Make sure we have a COW file if we were mounted with "-o nodatacow".
+if _normalize_mount_options "$MOUNT_OPTIONS" | grep -q "nodatacow"; then
+	_require_chattr C
+	$CHATTR_PROG -C "$SCRATCH_MNT/swap"
+fi

Nit: _format_swapfile already calls $CHATTR_PROG +C, so might as well put the _require_chattr call alongside _require_scratch_swapfile

Quoted 3 lines
tests/btrfs/173 +0 -0
 chmod 0600 "$SCRATCH_MNT/swap"
 _pwrite_byte 0x61 0 $(($(_get_page_size) * 10)) "$SCRATCH_MNT/swap" >> $seqres.full
 $MKSWAP_PROG "$SCRATCH_MNT/swap" >> $seqres.full
#4 lore raw

PATCH 3/4 btrfs/299: skip test if we were mounted with nodatacow

In reply to [email protected]

From: Filipe Manana <[email protected]>

The test requires the ability to create an inline extent in a file with a prealloced extent, created with fallocate's FALLOC_FL_KEEP_SIZE mode, which can only happen when COW is enabled. If the test is run with MOUNT_OPTIONS="-o nodatacow", then COW never happens as all writes end up using the preallocated extent. This results in the logical-resolve command to return one file path when it should return none, since the base logical address of the prealloc extent is still in use unless COW happens.

So make the test not run if nodatacow is specified in MOUNT_OPTIONS.

---
 tests/btrfs/299 | 3 +++
 1 file changed, 3 insertions(+)
tests/btrfs/299 +3 -0
index c4b1c7c5..d38bf2ac 100755
@@ -23,6 +23,9 @@ _supported_fs btrfs
 _require_scratch
 _require_xfs_io_command "falloc" "-k"
 _require_btrfs_command inspect-internal logical-resolve
+# Can't run with nodatacow because we need to be able to create an inline extent
+# in a range with a prealloc extent, which can only happen with COW enabled.
+_require_btrfs_no_nodatacow
 _fixed_by_kernel_commit 560840afc3e6 \
 	"btrfs: fix resolving backrefs for inline extent followed by prealloc"
 
Signature · 1 line
2.40.1
#5 lore raw

PATCH 4/4 btrfs: require no nodatacow for tests that exercise read repair

In reply to [email protected]

From: Filipe Manana <[email protected]>

Several test cases that exercise the ability to detect corrupted data and repair it, fail when "-o nodatacow" is passed to MOUNT_OPTIONS, because that ability requires the existence of data checksums, and those are disabled in nodatacow mode. So skip the tests when "-o nodatacow" is present.

---
 tests/btrfs/140 | 3 ++-
 tests/btrfs/141 | 2 ++
 tests/btrfs/157 | 2 ++
 tests/btrfs/158 | 2 ++
 tests/btrfs/215 | 2 ++
 tests/btrfs/265 | 2 ++
 tests/btrfs/266 | 2 ++
 tests/btrfs/267 | 2 ++
 tests/btrfs/268 | 2 ++
 tests/btrfs/269 | 2 ++
 tests/btrfs/289 | 2 ++
 11 files changed, 22 insertions(+), 1 deletion(-)
tests/btrfs/140 +2 -1
index 247a7356..5ce65886 100755
@@ -22,7 +22,8 @@ _begin_fstest auto quick read_repair fiemap
 # Modify as appropriate.
 _supported_fs btrfs
 _require_scratch_dev_pool 2
-
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_btrfs_command inspect-internal dump-tree
 _require_odirect
 # Overwriting data is forbidden on a zoned block device
tests/btrfs/141 +2 -0
index 90a90d00..e1adb91e 100755
@@ -22,6 +22,8 @@ _begin_fstest auto quick read_repair
 
 # Modify as appropriate.
 _supported_fs btrfs
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_scratch_dev_pool 2
 
 _require_btrfs_command inspect-internal dump-tree
tests/btrfs/157 +2 -0
index 022db511..648db0d0 100755
@@ -30,6 +30,8 @@ _begin_fstest auto quick raid read_repair
 
 # Modify as appropriate.
 _supported_fs btrfs
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_scratch_dev_pool 4
 _require_btrfs_command inspect-internal dump-tree
 _require_btrfs_fs_feature raid56
tests/btrfs/158 +2 -0
index aa85835a..28599d09 100755
@@ -22,6 +22,8 @@ _begin_fstest auto quick raid scrub
 
 # Modify as appropriate.
 _supported_fs btrfs
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_scratch_dev_pool 4
 _require_btrfs_command inspect-internal dump-tree
 _require_btrfs_fs_feature raid56
tests/btrfs/215 +2 -0
index 00646898..6fa226fe 100755
@@ -25,6 +25,8 @@ get_physical()
 # Modify as appropriate.
 _supported_fs btrfs
 _require_scratch
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 # Overwriting data is forbidden on a zoned block device
 _require_non_zoned_device $SCRATCH_DEV
 
tests/btrfs/265 +2 -0
index b75d9c84..127da7ad 100755
@@ -19,6 +19,8 @@ _begin_fstest auto quick read_repair
 _supported_fs btrfs
 _require_scratch_dev_pool 3
 
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_odirect
 # Overwriting data is forbidden on a zoned block device
 _require_non_zoned_device "${SCRATCH_DEV}"
tests/btrfs/266 +2 -0
index 42aff7c0..acfb1d59 100755
@@ -18,6 +18,8 @@ _begin_fstest auto quick read_repair
 # real QA test starts here
 
 _supported_fs btrfs
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_scratch_dev_pool 3
 
 _require_odirect
tests/btrfs/267 +2 -0
index 75a6fdcc..51b28d9b 100755
@@ -20,6 +20,8 @@ _begin_fstest auto quick read_repair
 _supported_fs btrfs
 _require_scratch_dev_pool 3
 
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_odirect
 # Overwriting data is forbidden on a zoned block device
 _require_non_zoned_device "${SCRATCH_DEV}"
tests/btrfs/268 +2 -0
index 9dc14a18..d122ee36 100755
@@ -16,6 +16,8 @@ _begin_fstest auto quick read_repair
 _supported_fs btrfs
 _require_scratch
 _require_odirect
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_non_zoned_device "${SCRATCH_DEV}" # no overwrites on zoned devices
 _require_scratch_dev_pool 2
 _scratch_dev_pool_get 2
tests/btrfs/269 +2 -0
index ad8f7286..7ffad125 100755
@@ -20,6 +20,8 @@ _begin_fstest auto quick read_repair
 _supported_fs btrfs
 _require_scratch
 _require_odirect
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 _require_non_zoned_device "${SCRATCH_DEV}" # no overwrites on zoned devices
 _require_scratch_dev_pool 4
 _scratch_dev_pool_get 4
tests/btrfs/289 +2 -0
index 39d8f733..f1aaf4cc 100755
@@ -16,6 +16,8 @@ _begin_fstest auto quick scrub repair
 # Modify as appropriate.
 _supported_fs btrfs
 _require_scratch
+# No data checksums for NOCOW case, so can't detect corruption and repair data.
+_require_btrfs_no_nodatacow
 
 _require_odirect
 # Overwriting data is forbidden on a zoned block device
Signature · 1 line
2.40.1
Reviewed-by on the v1 series
#6 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, 1 Feb 2024 18:03:46 +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

Several test btrfs test cases fail when using "-o nodatacow" in MOUNT_OPTIONS. So fix that by either adapting the tests to pass or skip them if there's no way for them to succeed in nodatacow mode.

Filipe Manana (4):
btrfs: require no nodatacow for tests that exercise compression btrfs/173: make the test work when mounting with nodatacow btrfs/299: skip test if we were mounted with nodatacow
btrfs: require no nodatacow for tests that exercise read repair

The double negative hurts my eyes, but these all look fine to me (one minor nit in 2/4).