Skip to contentSkip to conversation

common/btrfs: handle dmdust as mounted device in _btrfs_buffered_read_on_mirror()

PATCH In review Qu Wenruo 2 participants 2 messages Jun 29, 2023 – Jul 7, 2023 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v2 1/1 common/btrfs: handle dmdust as mounted device in _btrfs_buffered_read_on_mirror()

[BUG]
After commit ab41f0bddb73 ("common/btrfs: use _scratch_cycle_mount to ensure all page caches are dropped"), the test case btrfs/143 can fail like below:

btrfs/143 6s ... [failed, exit status 1]- output mismatch (see ~/xfstests/results//btrfs/143.out.bad)

    --- tests/btrfs/143.out 2020-06-10 19:29:03.818519162 +0100
    +++ ~/xfstests/results//btrfs/143.out.bad 2023-06-19 17:04:00.575033899 +0100
    @@ -1,37 +1,6 @@
     QA output created by 143
     wrote 131072/131072 bytes
     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
    -XXXXXXXX:  aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa

................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................

[CAUSE]
Test case btrfs/143 uses dm-dust device to emulate read errors, this means we can not use _scratch_cycle_mount to cycle mount $SCRATCH_MNT.

As it would go mount $SCRATCH_DEV, not the dm-dust device to $SCRATCH_MNT.
This prevents us to trigger read-repair (since no error would be hit) thus fail the test.

[FIX]
Since we can mount whatever device at $SCRATCH_MNT, we can not use _scratch_cycle_mount in this case.

Instead implement a small helper to grab the mounted device and its mount options, and use the same device and mount options to cycle $SCRATCH_MNT mount.

This would fix btrfs/143 and hopefully future test cases which use dm devices.

---
Changelog:
v2:
- Use findmnt command to grab mount options and source device

---
 common/btrfs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
common/btrfs +11 -2
index 175b33ae..0fec093d 100644
@@ -601,8 +601,17 @@ _btrfs_buffered_read_on_mirror()
 	# The drop_caches doesn't seem to drop every pages on aarch64 with
 	# 64K page size.
 	# So here as another workaround, cycle mount the SCRATCH_MNT to ensure
-	# the cache are dropped.
-	_scratch_cycle_mount
+	# the cache are dropped, but we can not use _scratch_cycle_mount, as
+	# we may mount whatever dm device at SCRATCH_MNT.
+	# So here we grab the mounted block device and its mount options, then
+	# unmount and re-mount with the same device and options.
+	local dev=$(findmnt -n -T $SCRATCH_MNT -o SOURCE)
+	local opts=$(findmnt -n -T $SCRATCH_MNT -o OPTIONS)
+	if [ -z "$dev" -o -z "$opts" ]; then
+		_fail "failed to grab mount info of $SCRATCH_MNT"
+	fi
+	_scratch_unmount
+	_mount $dev -o $opts $SCRATCH_MNT
 	while [[ -z $( (( BASHPID % nr_mirrors == mirror )) &&
 		exec $XFS_IO_PROG \
 			-c "pread -b $size $offset $size" $file) ]]; do
Signature · 1 line
2.39.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 41 lines · Qu Wenruo

[BUG]
After commit ab41f0bddb73 ("common/btrfs: use _scratch_cycle_mount to ensure all page caches are dropped"), the test case btrfs/143 can fail like below:

btrfs/143 6s ... [failed, exit status 1]- output mismatch (see ~/xfstests/results//btrfs/143.out.bad)

    --- tests/btrfs/143.out 2020-06-10 19:29:03.818519162 +0100
    +++ ~/xfstests/results//btrfs/143.out.bad 2023-06-19 17:04:00.575033899 +0100
    @@ -1,37 +1,6 @@
     QA output created by 143
     wrote 131072/131072 bytes
     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
    -XXXXXXXX:  aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa

................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................
-XXXXXXXX: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
................

[CAUSE]
Test case btrfs/143 uses dm-dust device to emulate read errors, this means we can not use _scratch_cycle_mount to cycle mount $SCRATCH_MNT.

As it would go mount $SCRATCH_DEV, not the dm-dust device to $SCRATCH_MNT.
This prevents us to trigger read-repair (since no error would be hit) thus fail the test.

[FIX]
Since we can mount whatever device at $SCRATCH_MNT, we can not use _scratch_cycle_mount in this case.

Instead implement a small helper to grab the mounted device and its mount options, and use the same device and mount options to cycle $SCRATCH_MNT mount.

This would fix btrfs/143 and hopefully future test cases which use dm devices.

Quoted 8 lines

---
Changelog:
v2:
- Use findmnt command to grab mount options and source device
---

This version looks good to me. Although the "_mount $dev -o $opts $SCRATCH_MNT" is a little odd, but as this's a btrfs only helper, so I think it's fine for btrfs at least.

Quoted 30 lines
 common/btrfs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
common/btrfs +11 -2
index 175b33ae..0fec093d 100644
@@ -601,8 +601,17 @@ _btrfs_buffered_read_on_mirror()
 	# The drop_caches doesn't seem to drop every pages on aarch64 with
 	# 64K page size.
 	# So here as another workaround, cycle mount the SCRATCH_MNT to ensure
-	# the cache are dropped.
-	_scratch_cycle_mount
+	# the cache are dropped, but we can not use _scratch_cycle_mount, as
+	# we may mount whatever dm device at SCRATCH_MNT.
+	# So here we grab the mounted block device and its mount options, then
+	# unmount and re-mount with the same device and options.
+	local dev=$(findmnt -n -T $SCRATCH_MNT -o SOURCE)
+	local opts=$(findmnt -n -T $SCRATCH_MNT -o OPTIONS)
+	if [ -z "$dev" -o -z "$opts" ]; then
+		_fail "failed to grab mount info of $SCRATCH_MNT"
+	fi
+	_scratch_unmount
+	_mount $dev -o $opts $SCRATCH_MNT
 	while [[ -z $( (( BASHPID % nr_mirrors == mirror )) &&
 		exec $XFS_IO_PROG \
 			-c "pread -b $size $offset $size" $file) ]]; do
Signature · 1 line
2.39.0