Skip to contentSkip to conversation

btrfs: Add test for the single-dev feature

PATCH Superseded Guilherme G. Piccoli 3 participants 4 messages Sep 5, 2023 – Sep 7, 2023 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: Add test for the single-dev feature

The SINGLE_DEV btrfs feature allows to mount the same filesystem multiple times, at the same time. This is the fstests counter-part, which checks both mkfs/btrfstune (by mounting the FS twice), and also unsupported scenarios, like device replace / remove.

---

V2:
- Rebased against v2023.09.03 / changed test number to 301;

- Implemented the great suggestions from Anand, which definitely made the test more clear and concise;

-Cc'ing linux-btrfs as well.

Thanks in advance for reviews / comments!
Cheers,

Guilherme

 tests/btrfs/301     | 94 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/301.out |  5 +++
 2 files changed, 99 insertions(+)
 create mode 100755 tests/btrfs/301
 create mode 100644 tests/btrfs/301.out
tests/btrfs/301 new file +94 -0
new file mode 100755
index 000000000000..5f8abdbe157a
@@ -0,0 +1,94 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Guilherme G. Piccoli (Igalia S.L.).  All Rights Reserved.
+#
+# FS QA Test 301
+#
+# Test for the btrfs single-dev feature - both mkfs and btrfstune are
+# validated, as well as explicitly unsupported commands, like device
+# removal / replacement.
+#
+. ./common/preamble
+_begin_fstest auto mkfs quick
+. ./common/filter
+_supported_fs btrfs
+
+_require_btrfs_mkfs_feature single-dev
+_require_btrfs_fs_feature single_dev
+
+_require_scratch_dev_pool 2
+_scratch_dev_pool_get 1
+_spare_dev_get
+
+_require_command "$BTRFS_TUNE_PROG" btrfstune
+_require_command "$WIPEFS_PROG" wipefs
+
+# Helper to mount a btrfs fs
+# Arg 1: device
+# Arg 2: mount point
+mount_btrfs()
+{
+	$MOUNT_PROG -t btrfs $1 $2
+	[ $? -ne 0 ] && _fail "mounting $1 on $2 failed"
+}
+
+SPARE_MNT="${TEST_DIR}/${seq}/spare_mnt"
+mkdir -p $SPARE_MNT
+
+
+# Part 1
+# First test involves a mkfs with single-dev feature enabled.
+# If it succeeds and mounting that FS *twice* also succeeds,
+# we're good and continue.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M -O single-dev" >> $seqres.full 2>&1
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT
+mount_btrfs $SPARE_DEV $SPARE_MNT
+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT
+
+
+# Part 2
+# Second test is similar to the first with the difference we
+# run mkfs with no single-dev mention, and make use of btrfstune
+# to set such feature.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M" >> $seqres.full 2>&1
+$BTRFS_TUNE_PROG --convert-to-single-device $SCRATCH_DEV
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT
+mount_btrfs $SPARE_DEV $SPARE_MNT
+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT
+
+
+# Part 3
+# Final part attempts to run some single-dev unsupported commands,
+# like device replace/remove - it they fail, test succeeds!
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT
+
+$BTRFS_UTIL_PROG device replace start $SCRATCH_DEV $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$BTRFS_UTIL_PROG device remove $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$UMOUNT_PROG $SCRATCH_MNT
+
+_spare_dev_put
+_scratch_dev_pool_put 1
+
+# success, all done
+status=0
+echo "Finished"
+
+exit
tests/btrfs/301.out new file +5 -0
new file mode 100644
index 000000000000..c65604fecc5f
@@ -0,0 +1,5 @@
+QA output created by 301
+ERROR: ioctl(DEV_REPLACE_STATUS) failed on "SCRATCH_MNT": Invalid argument
+
+ERROR: error removing device 'SCRATCH_DEV': Invalid argument
+Finished
Signature · 1 line
2.42.0
#1 lore raw
Quoted 39 lines · Guilherme G. Piccoli

The SINGLE_DEV btrfs feature allows to mount the same filesystem multiple times, at the same time. This is the fstests counter-part, which checks both mkfs/btrfstune (by mounting the FS twice), and also unsupported scenarios, like device replace / remove.

---

V2:
- Rebased against v2023.09.03 / changed test number to 301;

- Implemented the great suggestions from Anand, which definitely made the test more clear and concise;

-Cc'ing linux-btrfs as well.

Thanks in advance for reviews / comments!
Cheers,

Guilherme

 tests/btrfs/301     | 94 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/301.out |  5 +++
 2 files changed, 99 insertions(+)
 create mode 100755 tests/btrfs/301
 create mode 100644 tests/btrfs/301.out
tests/btrfs/301 new file +3 -0
new file mode 100755
index 000000000000..5f8abdbe157a
@@ -0,0 +1,94 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Guilherme G. Piccoli (Igalia S.L.).  All Rights Reserved.

tests/btrfs/301 line 13

Quoted 10 lines
tests/btrfs/301 new file +10 -0
+#
+# FS QA Test 301
+#
+# Test for the btrfs single-dev feature - both mkfs and btrfstune are
+# validated, as well as explicitly unsupported commands, like device
+# removal / replacement.
+#
+. ./common/preamble
+_begin_fstest auto mkfs quick
+. ./common/filter

Normally we group all the require'd stuff together

Quoted 26 lines
tests/btrfs/301 new file +26 -0
+_supported_fs btrfs
+
+_require_btrfs_mkfs_feature single-dev
+_require_btrfs_fs_feature single_dev
+
+_require_scratch_dev_pool 2
+_scratch_dev_pool_get 1
+_spare_dev_get
+
+_require_command "$BTRFS_TUNE_PROG" btrfstune
+_require_command "$WIPEFS_PROG" wipefs
+
+# Helper to mount a btrfs fs
+# Arg 1: device
+# Arg 2: mount point
+mount_btrfs()
+{
+	$MOUNT_PROG -t btrfs $1 $2
+	[ $? -ne 0 ] && _fail "mounting $1 on $2 failed"
+}
+
+SPARE_MNT="${TEST_DIR}/${seq}/spare_mnt"
+mkdir -p $SPARE_MNT
+
+
+# Part 1

tests/btrfs/301 line 49

Quoted 10 lines
tests/btrfs/301 new file +10 -0
+# First test involves a mkfs with single-dev feature enabled.
+# If it succeeds and mounting that FS *twice* also succeeds,
+# we're good and continue.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M -O single-dev" >> $seqres.full 2>&1
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

You can just use _scratch_mount here, since you want to handle failures just

_scratch_mount || _fail "failed to mount scratch mount"

tests/btrfs/301 line 50

Quoted 1 line
tests/btrfs/301 new file +1 -0
+mount_btrfs $SPARE_DEV $SPARE_MNT

Instead use _mount here

_mount $SPARE_DEV $SPARE_MNT || _fail "failed to mount spare dev"

tests/btrfs/301 line 53

Quoted 3 lines
tests/btrfs/301 new file +3 -0
+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

Quoted 4 lines
tests/btrfs/301 new file +4 -0
+
+
+# Part 2
+# Second test is similar to the first with the difference we

tests/btrfs/301 line 67

Quoted 10 lines
tests/btrfs/301 new file +10 -0
+# run mkfs with no single-dev mention, and make use of btrfstune
+# to set such feature.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M" >> $seqres.full 2>&1
+$BTRFS_TUNE_PROG --convert-to-single-device $SCRATCH_DEV
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

_scratch_mount

tests/btrfs/301 line 68

Quoted 1 line
tests/btrfs/301 new file +1 -0
+mount_btrfs $SPARE_DEV $SPARE_MNT

_mount

tests/btrfs/301 line 53

Quoted 3 lines
tests/btrfs/301 new file +3 -0
+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

tests/btrfs/301 line 77

Quoted 6 lines
tests/btrfs/301 new file +6 -0
+
+
+# Part 3
+# Final part attempts to run some single-dev unsupported commands,
+# like device replace/remove - it they fail, test succeeds!
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

_scratch_mount

tests/btrfs/301 line 85

Quoted 8 lines
tests/btrfs/301 new file +8 -0
+
+$BTRFS_UTIL_PROG device replace start $SCRATCH_DEV $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$BTRFS_UTIL_PROG device remove $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

tests/btrfs/301 line 92

Quoted 7 lines
tests/btrfs/301 new file +7 -0
+
+_spare_dev_put
+_scratch_dev_pool_put 1
+
+# success, all done
+status=0
+echo "Finished"

Don't need this bit. Thanks,

Josef

#2 lore raw

Further to Josef's review.

Quoted 13 lines
Quoted 13 lines
tests/btrfs/301 new file +7 -0
new file mode 100755
index 000000000000..5f8abdbe157a
@@ -0,0 +1,94 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Guilherme G. Piccoli (Igalia S.L.).  All Rights Reserved.
+#
+# FS QA Test 301
+#
+# Test for the btrfs single-dev feature - both mkfs and btrfstune are
Quoted 33 lines

tests/btrfs/301 line 13

Quoted 6 lines
tests/btrfs/301 new file +6 -0
+# validated, as well as explicitly unsupported commands, like device
+# removal / replacement.
+#
+. ./common/preamble
+_begin_fstest auto mkfs quick
+. ./common/filter

Normally we group all the require'd stuff together

Quoted 25 lines
tests/btrfs/301 new file +22 -0
+_supported_fs btrfs
+
 
+_require_btrfs_mkfs_feature single-dev
+_require_btrfs_fs_feature single_dev
 
+
+_require_scratch_dev_pool 2
+_scratch_dev_pool_get 1
+_spare_dev_get
+
+_require_command "$BTRFS_TUNE_PROG" btrfstune
+_require_command "$WIPEFS_PROG" wipefs
+
+# Helper to mount a btrfs fs
+# Arg 1: device
+# Arg 2: mount point
+mount_btrfs()
+{
+	$MOUNT_PROG -t btrfs $1 $2
+	[ $? -ne 0 ] && _fail "mounting $1 on $2 failed"
+}
+
 
+SPARE_MNT="${TEST_DIR}/${seq}/spare_mnt"

Please use small case for test local variables.

spare_mnt=="${TEST_DIR}/${seq}/spare_mnt"

Thanks, Anand

Quoted 94 lines
Quoted 5 lines
tests/btrfs/301 new file +5 -0
+mkdir -p $SPARE_MNT
+
+
+# Part 1
+# First test involves a mkfs with single-dev feature enabled.

tests/btrfs/301 line 49

Quoted 10 lines
tests/btrfs/301 new file +9 -0
+# If it succeeds and mounting that FS *twice* also succeeds,
+# we're good and continue.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M -O single-dev" >> $seqres.full 2>&1
 
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

You can just use _scratch_mount here, since you want to handle failures just

_scratch_mount || _fail "failed to mount scratch mount"

Quoted 1 line

+mount_btrfs $SPARE_DEV $SPARE_MNT

Instead use _mount here

_mount $SPARE_DEV $SPARE_MNT || _fail "failed to mount spare dev"

Quoted 3 lines

+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

Quoted 4 lines
tests/btrfs/301 new file +4 -0
+
+
+# Part 2
+# Second test is similar to the first with the difference we

tests/btrfs/301 line 67

Quoted 10 lines
tests/btrfs/301 new file +10 -0
+# run mkfs with no single-dev mention, and make use of btrfstune
+# to set such feature.
+$WIPEFS_PROG -a $SCRATCH_DEV >> $seqres.full 2>&1
+$WIPEFS_PROG -a $SPARE_DEV >> $seqres.full 2>&1
+
+_scratch_mkfs "-b 300M" >> $seqres.full 2>&1
+$BTRFS_TUNE_PROG --convert-to-single-device $SCRATCH_DEV
+dd if=$SCRATCH_DEV of=$SPARE_DEV bs=300M count=1 conv=fsync >> $seqres.full 2>&1
+
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

_scratch_mount

Quoted 1 line

+mount_btrfs $SPARE_DEV $SPARE_MNT

_mount

Quoted 3 lines

+
+$UMOUNT_PROG $SPARE_MNT
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

tests/btrfs/301 line 77

Quoted 6 lines
tests/btrfs/301 new file +6 -0
+
+
+# Part 3
+# Final part attempts to run some single-dev unsupported commands,
+# like device replace/remove - it they fail, test succeeds!
+mount_btrfs $SCRATCH_DEV $SCRATCH_MNT

_scratch_mount

tests/btrfs/301 line 85

Quoted 8 lines
tests/btrfs/301 new file +8 -0
+
+$BTRFS_UTIL_PROG device replace start $SCRATCH_DEV $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$BTRFS_UTIL_PROG device remove $SCRATCH_DEV $SCRATCH_MNT 2>&1 \
+	| _filter_scratch
+
+$UMOUNT_PROG $SCRATCH_MNT

_scratch_unmount

tests/btrfs/301 line 92

Quoted 7 lines
tests/btrfs/301 new file +7 -0
+
+_spare_dev_put
+_scratch_dev_pool_put 1
+
+# success, all done
+status=0
+echo "Finished"

Don't need this bit. Thanks,

Josef

#3 lore raw
Quoted 3 lines · Anand Jain

Further to Josef's review.

Thanks both Anand and Josef, I'll implement all the changes in the next iteration, hopefully having then the proper name for the feature (instead of single-dev heh).

Cheers,

Guilherme