Skip to contentSkip to conversation

fstests: btrfs/049: add regression test for compress-force mount options

PATCH In review Qu Wenruo 2 participants 2 messages Nov 25, 2021 – Nov 26, 2021 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v3 1/1 fstests: btrfs/049: add regression test for compress-force mount options

Since kernel commit d4088803f511 ("btrfs: subpage: make lzo_compress_pages() compatible"), lzo compression no longer respects the max compressed page limit, and can cause kernel crash.

The upstream fix is 6f019c0e0193 ("btrfs: fix a out-of-bound access in copy_compressed_data_to_page()").

This patch will add such regression test for all possible compress-force mount options, including lzo, zstd and zlib.

And since we're here, also make sure the content of the file matches after a mount cycle.

---
Changelog:
v2:
- Also test zlib and zstd
- Add file content verification check
v3:
- Use $tmp.good as a known good file source
- Also make sure we didn't get short read for the good copy

---
 tests/btrfs/049     | 67 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/049.out |  6 ++++
 2 files changed, 73 insertions(+)
 create mode 100755 tests/btrfs/049
tests/btrfs/049 new file +67 -0
new file mode 100755
index 00000000..c1f35dc9
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 049
+#
+# Test if btrfs will crash when using compress-force mount option against
+# incompressible data
+#
+. ./common/preamble
+_begin_fstest auto quick compress dangerous
+
+# Override the default cleanup function.
+_cleanup()
+{
+	cd /
+ 	rm -r -f $tmp.*
+}
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_require_scratch
+
+pagesize=$(get_page_size)
+
+# Read the content from urandom to a known safe location
+$XFS_IO_PROG -f -c "pwrite -i /dev/urandom 0 $pagesize" "$tmp.good" > /dev/null
+
+# Make sure we didn't get short read
+if [ $(_get_filesize "$tmp.good") != "$pagesize" ]; then
+	_fail "Got a short read from /dev/urandom"
+fi
+
+workload()
+{
+	local compression=$1
+
+	echo "=== Testing compress-force=$compression ==="
+	_scratch_mkfs -s "$pagesize">> $seqres.full
+	_scratch_mount -o compress-force="$compression"
+	cp "$tmp.good" "$SCRATCH_MNT/$compression"
+
+	# When unpatched, compress-force=lzo would crash at data writeback
+	_scratch_cycle_mount
+
+	# Make sure the content matches
+	if [ "$(_md5_checksum $tmp.good)" != \
+	     "$(_md5_checksum $SCRATCH_MNT/$compression)" ]; then
+		_fail "Content of '$SCRATCH_MNT/file' mismatch with known good copy"
+	else
+		echo "OK"
+	fi
+	_scratch_unmount
+}
+
+workload lzo
+workload zstd
+workload zlib
+
+# success, all done
+status=0
+exit
tests/btrfs/049.out +6 -0
index cb0061b3..41bffeaa 100644
@@ -1 +1,7 @@
 QA output created by 049
+=== Testing compress-force=lzo ===
+OK
+=== Testing compress-force=zstd ===
+OK
+=== Testing compress-force=zlib ===
+OK
Signature · 1 line
2.34.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 59 lines · Qu Wenruo

Since kernel commit d4088803f511 ("btrfs: subpage: make lzo_compress_pages() compatible"), lzo compression no longer respects the max compressed page limit, and can cause kernel crash.

The upstream fix is 6f019c0e0193 ("btrfs: fix a out-of-bound access in copy_compressed_data_to_page()").

This patch will add such regression test for all possible compress-force mount options, including lzo, zstd and zlib.

And since we're here, also make sure the content of the file matches after a mount cycle.

---
Changelog:
v2:
- Also test zlib and zstd
- Add file content verification check
v3:
- Use $tmp.good as a known good file source
- Also make sure we didn't get short read for the good copy

---
 tests/btrfs/049     | 67 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/049.out |  6 ++++
 2 files changed, 73 insertions(+)
 create mode 100755 tests/btrfs/049
tests/btrfs/049 new file +24 -0
new file mode 100755
index 00000000..c1f35dc9
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 049
+#
+# Test if btrfs will crash when using compress-force mount option against
+# incompressible data
+#
+. ./common/preamble
+_begin_fstest auto quick compress dangerous
+
+# Override the default cleanup function.
+_cleanup()
+{
+       cd /
+       rm -r -f $tmp.*
+}
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+

tests/btrfs/049 line 34

Quoted 10 lines
tests/btrfs/049 new file +10 -0
+# Modify as appropriate.
+_supported_fs btrfs
+_require_scratch
+
+pagesize=$(get_page_size)
+
+# Read the content from urandom to a known safe location
+$XFS_IO_PROG -f -c "pwrite -i /dev/urandom 0 $pagesize" "$tmp.good" > /dev/null
+
+# Make sure we didn't get short read

s/read/write/

Quoted 10 lines
tests/btrfs/049 new file +10 -0
+if [ $(_get_filesize "$tmp.good") != "$pagesize" ]; then
+       _fail "Got a short read from /dev/urandom"
+fi
+
+workload()
+{
+       local compression=$1
+
+       echo "=== Testing compress-force=$compression ==="
+       _scratch_mkfs -s "$pagesize">> $seqres.full

tests/btrfs/049 line 54

Quoted 10 lines
tests/btrfs/049 new file +10 -0
+       _scratch_mount -o compress-force="$compression"
+       cp "$tmp.good" "$SCRATCH_MNT/$compression"
+
+       # When unpatched, compress-force=lzo would crash at data writeback
+       _scratch_cycle_mount
+
+       # Make sure the content matches
+       if [ "$(_md5_checksum $tmp.good)" != \
+            "$(_md5_checksum $SCRATCH_MNT/$compression)" ]; then
+               _fail "Content of '$SCRATCH_MNT/file' mismatch with known good copy"

We could just 'echo' instead of '_fail' and let the test continue with the remaining compression algorithms.
That's usually the approach preferred for fstests, _fail is for cases where the test can't proceed and must stop immediately.

Anyway, those are two minor things that maybe Eryu can fixup when he picks the patch.
So I won't ask you to send yet another version.

Thanks!

Quoted 28 lines
tests/btrfs/049 new file +13 -0
+       else
+               echo "OK"
+       fi
+       _scratch_unmount
+}
+
+workload lzo
+workload zstd
+workload zlib
+
+# success, all done
+status=0
+exit
tests/btrfs/049.out +6 -1
index cb0061b3..41bffeaa 100644
@@ -1 +1,7 @@
 QA output created by 049
+=== Testing compress-force=lzo ===
+OK
+=== Testing compress-force=zstd ===
+OK
+=== Testing compress-force=zlib ===
+OK
--

2.34.0

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”