The test case dm/002 rarely fails with the message below: dm/002 => nvme0n1 (dm-dust general functionality test) [failed] runtime 0.204s ... 0.174s --- tests/dm/002.out 2024-06-14 14:37:40.480794693 +0900 +++ /home/shin/Blktests/blktests/results/nvme0n1/dm/002.out.bad 2024-06-14 21:38:18.588976499 +0900 @@ -7,4 +7,6 @@ countbadblocks: 0 badblock(s) found countbadblocks: 3 badblock(s) found countbadblocks: 0 badblock(s) found +device-mapper: remove ioctl on dust1 failed: Device or resource busy +Command failed. Test complete modprobe: FATAL: Module dm_dust is in use. This failure happens at "dmsetup remove" command, when the previous operation on the dm device is still ongoing. In this case, dm_open_count() is non-zero, then IOCTL for device remove fails and EBUSY is returned. To avoid the failure, retry the "dmsetup remove" command when it fails with EBUSY. Introduce the helper function _dm_remove for this purpose. Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- This patch addresses a failure found during the debug work for another dm/002 failure [1]. [1] https://lore.kernel.org/linux-block/42ecobcsduvlqh77iavjj2p3ewdh7u4opdz4xruauz4u5ddljz@yr7ye4fq72tr/ tests/dm/002 | 2 +- tests/dm/rc | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/dm/002 b/tests/dm/002 index fae3986..8ae8438 100755 --- a/tests/dm/002 +++ b/tests/dm/002 @@ -37,7 +37,7 @@ test_device() { sync dmsetup message dust1 0 countbadblocks sync - dmsetup remove dust1 + _dm_remove dust1 echo "Test complete" } diff --git a/tests/dm/rc b/tests/dm/rc index 0486db0..21a35f6 100644 --- a/tests/dm/rc +++ b/tests/dm/rc @@ -11,3 +11,26 @@ group_requires() { _have_program dmsetup _have_driver dm-mod } + +_dm_remove() { + local dm_dev=${1} + local i out + + # Retry dmsetup remove command in case it fails with EBUSY because of + # non-zero dm open count. + for ((i = 0; i < 10; i++)); do + if out=$(dmsetup remove "${dm_dev}" 2>&1); then + break + fi + echo "$out" >> "$FULL" + if ! [[ $out =~ "Device or resource busy" ]]; then + echo "$out" + break + fi + sleep 1 + done + if ((i == 10)); then + echo "dmsetup remove failed with EBUSY" + fi + +} -- 2.45.2