Skip to content

Commit de66e80

Browse files
tmt: Fix stale loop partition state in multi-device ESP test
The three-devices-partial-ESP scenario fails with "No device found for /dev/loop1p1" because the dual-ESP test's cleanup leaves stale kernel partition nodes and LVM device registrations. The prior cleanup called `pvremove -f $loop` on the loop device itself (e.g. /dev/loop0) instead of on the partitions where PVs actually live (e.g. /dev/loop0p2), making it a no-op. After `losetup -d`, the kernel retained busy partition nodes. When the next test reused the loop device with a different partition layout, `partx -u` tried to atomically reconcile old and new partitions — but could not remove the busy stale partition #2, so it aborted entirely without adding the new partition #1. Fix both cleanup and setup: Cleanup: - pvremove on actual partition devices (p1/p2/p3), not the loop device - wipefs -a on each partition to clear signatures holding references - udevadm settle to let udev finish processing - partx -d to remove kernel partition entries before losetup -d - Remove /etc/lvm/devices/system.devices to clear stale device IDs Setup (setup_disk_with_partitions, setup_disk_with_root): - Replace `partx -u` with `partx -d` (ignore errors) then `partx -a`, so a stuck stale partition does not block adding new ones - Replace `sleep 1sec` with `udevadm settle` for reliable synchronization Co-Authored-By: Claude Opus 4.6 Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 2789485 commit de66e80

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

tmt/tests/booted/test-multi-device-esp.nu

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ def cleanup [vg_name: string, loops: list<string>, mountpoint: string] {
4545
do { vgchange -an $vg_name } | complete | ignore
4646
do { vgremove -f $vg_name } | complete | ignore
4747

48-
# Remove PVs and detach loop devices
48+
# Remove PVs from partitions and detach loop devices
4949
for loop in $loops {
5050
if ($loop | path exists) {
51-
do { pvremove -f $loop } | complete | ignore
51+
for i in [1, 2, 3] {
52+
let part = $"($loop)p($i)"
53+
if ($part | path exists) {
54+
do { pvremove -f $part } | complete | ignore
55+
do { wipefs -a $part } | complete | ignore
56+
}
57+
}
58+
do { udevadm settle } | complete | ignore
59+
do { partx -d $loop } | complete | ignore
5260
do { losetup -d $loop } | complete | ignore
5361
}
5462
}
63+
64+
rm -f /etc/lvm/devices/system.devices
5565
}
5666

5767
# Create a disk with GPT, optional ESP, and LVM partition
@@ -72,19 +82,21 @@ def setup_disk_with_partitions [
7282
# GPT with ESP (512MB) + LVM partition
7383
$"label: gpt\nsize=512M, type=($ESP_TYPE)\ntype=($LVM_TYPE)\n" | sfdisk $loop
7484

75-
# Reload partition table (partx is part of util-linux)
76-
partx -u $loop
77-
sleep 1sec
85+
# Remove stale partition entries then add new ones; -d may fail
86+
# for busy partitions from a prior test, but -a still succeeds
87+
do { partx -d $loop } | complete | ignore
88+
partx -av $loop
89+
udevadm settle
7890

7991
# Format ESP
8092
mkfs.vfat -F 32 $"($loop)p1"
8193
} else {
8294
# GPT with only LVM partition (full disk)
8395
$"label: gpt\ntype=($LVM_TYPE)\n" | sfdisk $loop
8496

85-
# Reload partition table (partx is part of util-linux)
86-
partx -u $loop
87-
sleep 1sec
97+
do { partx -d $loop } | complete | ignore
98+
partx -av $loop
99+
udevadm settle
88100
}
89101

90102
$loop
@@ -101,8 +113,9 @@ def setup_disk_with_root [
101113

102114
# GPT with ESP (512MB) + root partition
103115
$"label: gpt\nsize=512M, type=($ESP_TYPE)\ntype=($ROOT_TYPE)\n" | sfdisk $loop
104-
partx -u $loop
105-
sleep 1sec
116+
do { partx -d $loop } | complete | ignore
117+
partx -av $loop
118+
udevadm settle
106119

107120
mkfs.vfat -F 32 $"($loop)p1"
108121
mkfs.ext4 -q $"($loop)p2"

0 commit comments

Comments
 (0)