diff mbox series

[blktests,2/3] block/011: skip when mounted block devices are affected

Message ID 20230526045843.168739-3-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series improve block/011 | expand

Commit Message

Shinichiro Kawasaki May 26, 2023, 4:58 a.m. UTC
The test case disables PCI device of the test target block device. When
the PCI device has other block devices mounted, those block devices are
disabled also. If the mounted device is the system disk, the test screws
up the system. To avoid such dangerous operation, check if the target
PCI device has mounted block devices. In that case, skip the test.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 tests/block/011 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/tests/block/011 b/tests/block/011
index 4f331b4..0699936 100755
--- a/tests/block/011
+++ b/tests/block/011
@@ -10,12 +10,29 @@  DESCRIPTION="disable PCI device while doing I/O"
 TIMED=1
 CAN_BE_ZONED=1
 
+pci_dev_mounted() {
+	local d dev p pdev
+
+	pdev="$(_get_pci_dev_from_blkdev)"
+	for d in /sys/block/*; do
+		dev=${d##*/}
+		p=$(_get_pci_from_dev_sysfs "$d")
+		[[ $p != "$pdev" ]] && continue
+		grep -qe "/dev/$dev" /proc/mounts && return 0
+	done
+	return 1
+}
+
 requires() {
 	_have_fio && _have_program setpci
 }
 
 device_requires() {
 	_require_test_dev_is_pci
+	if pci_dev_mounted; then
+		SKIP_REASONS+=("mounted block device exists on test target PCI device")
+		return 1
+	fi
 }
 
 test_device() {