Skip to contentSkip to conversation

fstests: test device reappearance with new maj:min

PATCH In review Anand Jain 3 participants 6 messages Sep 18, 2025 – Sep 30, 2025 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover fstests: test device reappearance with new maj:min

From: Anand Jain <[email protected]>

Tests filesystem behavior when a device reappears with a different MAJ:MIN after a block layer transport failure.

Anand Jain (2):
common/rc: helper functions to handle block devices via sysfs
generic: test case for reappearing device

 common/rc             | 26 ++++++++++++++++
 tests/generic/809     | 72 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/809.out |  2 ++
 3 files changed, 100 insertions(+)
 create mode 100755 tests/generic/809
 create mode 100644 tests/generic/809.out
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 1/2 common/rc: helper functions to handle block devices via sysfs

From: Anand Jain <[email protected]>

_bdev_handle(dev)
get sysfs handle for a given block device.

_has_bdev_sysfs_delete(dev_path)
Checks if the block device supports sysfs-based delete.

_require_scratch_bdev_delete()
Test if the scratch device does not support sysfs delete.

---
 common/rc | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
common/rc +26 -0
index 81587dad500c..627ddcc02fb8 100644
@@ -4388,6 +4388,32 @@ _get_file_extent_sector()
 	echo "$result"
 }
 
+_bdev_handle()
+{
+	local device=$(echo $1 | rev | cut -d"/" -f1 | rev)
+
+	test -e /sys/class/block/${device}/device/scsi_disk/ || \
+			_notrun "Failed to obtain sys block handle"
+
+	ls /sys/class/block/${device}/device/scsi_disk/
+}
+
+_has_bdev_sysfs_delete()
+{
+	local dev_path=$1
+	local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev)
+	local delete_path=/sys/class/block/${device}/device/delete
+
+	test -e $delete_path
+}
+
+_require_scratch_bdev_delete()
+{
+	if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then
+		_notrun "require scratch device sys delete support"
+	fi
+}
+
 # arg 1 is dev to remove and is output of the below eg.
 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
 _devmgt_remove()
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs

Quoted 21 lines · Anand Jain

From: Anand Jain <[email protected]>

_bdev_handle(dev)
get sysfs handle for a given block device.

_has_bdev_sysfs_delete(dev_path)
Checks if the block device supports sysfs-based delete.

_require_scratch_bdev_delete()
Test if the scratch device does not support sysfs delete.

---
 common/rc | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
common/rc +0 -0
index 81587dad500c..627ddcc02fb8 100644

common/rc _get_file_extent_sector() · line 4393

Quoted 6 lines
common/rc +3 -0
@@ -4388,6 +4388,32 @@ _get_file_extent_sector()
 	echo "$result"
 }
 
+_bdev_handle()
+{
+	local device=$(echo $1 | rev | cut -d"/" -f1 | rev)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

basename $1 ?

if you hope to make sure it's not link, you can

basename $(_real_dev $1)

Quoted 8 lines
common/rc +8 -0
+
+	test -e /sys/class/block/${device}/device/scsi_disk/ || \
+			_notrun "Failed to obtain sys block handle"
+
+	ls /sys/class/block/${device}/device/scsi_disk/
+}
+
+_has_bdev_sysfs_delete()

common/rc _get_file_extent_sector() · line 4411

Quoted 10 lines
common/rc +10 -0
+{
+	local dev_path=$1
+	local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev)
+	local delete_path=/sys/class/block/${device}/device/delete
+
+	test -e $delete_path
+}
+
+_require_scratch_bdev_delete()
+{

I'm wondering if it's better to call "_require_block_device" at first, before checking the /sys ?

Quoted 12 lines
common/rc +5 -0
+	if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then
+		_notrun "require scratch device sys delete support"
+	fi
+}
+
 # arg 1 is dev to remove and is output of the below eg.
 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
 _devmgt_remove()
Signature · 1 line
2.51.0
author
#3 lore raw

Re: [PATCH 1/2] common/rc: helper functions to handle block devices via sysfs

Quoted 30 lines · Zorro Lang
Quoted 21 lines · Anand Jain

From: Anand Jain <[email protected]>

_bdev_handle(dev)
get sysfs handle for a given block device.

_has_bdev_sysfs_delete(dev_path)
Checks if the block device supports sysfs-based delete.

_require_scratch_bdev_delete()
Test if the scratch device does not support sysfs delete.

---
  common/rc | 26 ++++++++++++++++++++++++++
  1 file changed, 26 insertions(+)
common/rc +0 -0
index 81587dad500c..627ddcc02fb8 100644

common/rc _get_file_extent_sector() · line 4393

Quoted 6 lines
common/rc +3 -0
@@ -4388,6 +4388,32 @@ _get_file_extent_sector()
     echo "$result"
  }
 
+_bdev_handle()
+{
+    local device=$(echo $1 | rev | cut -d"/" -f1 | rev)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 6 lines

basename $1 ?

if you hope to make sure it's not link, you can

basename $(_real_dev $1)

Whoops, not sure what I was thinking. There's actually a helper for this, _short_dev().
The changes below will fix it. I can send v2 if needed, unless it can be fixed at merge
time. Let me know what works best.
-----------------------------------

$ git diff
common/rc +2 -2
index 627ddcc02fb8..085fab6e34f0 100644
@@ -4390,7 +4390,7 @@ _get_file_extent_sector()
 
 _bdev_handle()
 {
-       local device=$(echo $1 | rev | cut -d"/" -f1 | rev)
+       local device=$(_short_dev $1)
 
        test -e /sys/class/block/${device}/device/scsi_disk/ || \
                        _notrun "Failed to obtain sys block handle"
@@ -4401,7 +4401,7 @@ _bdev_handle()
 _has_bdev_sysfs_delete()
 {
        local dev_path=$1
-       local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev)
+       local device=$(_short_dev $1)
        local delete_path=/sys/class/block/${device}/device/delete
 
        test -e $delete_path

---------------------------------------------

Quoted 13 lines
Quoted 13 lines
common/rc +13 -0
+
+    test -e /sys/class/block/${device}/device/scsi_disk/ || \
+                    _notrun "Failed to obtain sys block handle"
+
+    ls /sys/class/block/${device}/device/scsi_disk/
+}
+
+_has_bdev_sysfs_delete()
+{
+    local dev_path=$1
+    local device=$(echo $dev_path | rev | cut -d"/" -f1 | rev)
+    local delete_path=/sys/class/block/${device}/device/delete
+
Quoted 8 lines

common/rc _get_file_extent_sector() · line 4411

Quoted 5 lines
common/rc +5 -0
+    test -e $delete_path
+}
+
+_require_scratch_bdev_delete()
+{

I'm wondering if it's better to call "_require_block_device" at first, before checking the /sys ?

There’s no harm in using _require_block_device() here, but I don’t think it will help,
a non block device won't reach this place anyway.
config: _check_device() will fail for non-block devices.

Thanks, Anand

Quoted 13 lines
Quoted 12 lines
common/rc +5 -1
+    if ! _has_bdev_sysfs_delete $SCRATCH_DEV; then
+            _notrun "require scratch device sys delete support"
+    fi
+}
+
  # arg 1 is dev to remove and is output of the below eg.
  # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
  _devmgt_remove()
--

2.51.0

author
#4 lore raw

PATCH 2/2 generic: test case for reappearing device

In reply to Anand Jain

From: Anand Jain <[email protected]>

Tests how the filesystem handles a device that reappears with a different MAJ:MIN due to a block layer transport failure.

---
 tests/generic/809     | 72 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/809.out |  2 ++
 2 files changed, 74 insertions(+)
 create mode 100755 tests/generic/809
 create mode 100644 tests/generic/809.out
tests/generic/809 new file +72 -0
new file mode 100755
index 000000000000..3e9943f9ac85
@@ -0,0 +1,72 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024 Oracle.  All Rights Reserved.
+#
+# FS QA Test 809
+#
+# Tests how the filesystem handles a device that reappears with a different
+# MAJ:MIN while the old MAJ:MIN is still mounted and in use, due to a block
+# layer transport failure.
+
+. ./common/preamble
+
+_begin_fstest auto quick tempfsid shutdown
+
+_cleanup()
+{
+	local new_blk_handle
+
+	cd /
+	rm -r -f $tmp.*
+	$UMOUNT_PROG $mnt1 &> /dev/null
+	$UMOUNT_PROG $SCRATCH_MNT &> /dev/null
+
+	if [[ ! -b $new_scratch_dev ]]; then
+		echo "_cleanup: failed to restore the scratch device."
+		return
+	fi
+	new_blk_handle=$(_bdev_handle $new_scratch_dev)
+	_devmgt_remove  $new_blk_handle $new_scratch_dev
+	_devmgt_add $new_blk_handle
+
+	[[ -b $SCRATCH_DEV ]] || \
+		echo "_cleanup: failed to restore scratch device."
+}
+
+_require_test
+_require_scratch
+_require_scratch_bdev_delete
+
+mnt1=$TEST_DIR/$seq/mnt1
+rm -r -f $mnt1
+mkdir -p $mnt1
+
+_scratch_mkfs >> /dev/null
+_scratch_mount
+
+$XFS_IO_PROG -fc 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/foo >> $seqres.full
+_mount $SCRATCH_DEV $mnt1
+$UMOUNT_PROG $mnt1
+
+# Ensure data is flushed to disk before the device disappears
+sync
+
+id1=$(lsblk -ndo MAJ:MIN $SCRATCH_DEV)
+scratch_fsid=$(blkid --probe --match-tag UUID $SCRATCH_DEV | \
+	$AWK_PROG '{print $2}' | sed -e 's/UUID=//g' | sed -e 's/\"//g')
+blk_handle=$(_bdev_handle $SCRATCH_DEV)
+_devmgt_remove  $blk_handle $SCRATCH_DEV
+_devmgt_add $blk_handle
+new_scratch_dev=$(blkid -l -o device -t UUID=$scratch_fsid)
+id2=$(lsblk -ndo MAJ:MIN $new_scratch_dev)
+[[ -b $new_scratch_dev ]] || _fail "Device failed to reappear"
+[[ "$id1" != "$id2" ]] || \
+		_not_run "Device cannot reappear with a different major:minor"
+
+# Mount the reappeared device while the old node is still mounted
+# (not supported on XFS).
+[[ $FSTYP == "xfs" ]] && $UMOUNT_PROG $SCRATCH_MNT
+_mount $new_scratch_dev $mnt1
+echo Silence is golden
+status=0
+exit
tests/generic/809.out new file +2 -0
new file mode 100644
index 000000000000..e90865ca8f8c
@@ -0,0 +1,2 @@
+QA output created by 809
+Silence is golden
Signature · 1 line
2.51.0
Reviewed-by on the v1 series
#5 lore raw
In reply to Anand Jain
Quoted 17 lines · Anand Jain

From: Anand Jain <[email protected]>

Tests filesystem behavior when a device reappears with a different MAJ:MIN after a block layer transport failure.

Anand Jain (2):
common/rc: helper functions to handle block devices via sysfs
generic: test case for reappearing device

 common/rc             | 26 ++++++++++++++++
 tests/generic/809     | 72 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/809.out |  2 ++
 3 files changed, 100 insertions(+)
 create mode 100755 tests/generic/809
 create mode 100644 tests/generic/809.out
Quoted 3 lines

--
2.51.0

This series looks good to me.

Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!