@@ -4,6 +4,7 @@ load helpers
44
55function teardown() {
66 teardown_bundle
7+ teardown_loopdevs
78}
89
910function setup() {
@@ -153,16 +154,28 @@ function setup() {
153154@test " runc run (per-device io weight for bfq)" {
154155 requires root # to create a loop device
155156
156- dd if=/dev/zero of=backing.img bs=4096 count=1
157- dev=$( losetup --find --show backing.img) || skip " unable to create a loop device"
157+ dev=" $( setup_loopdev) "
158+
159+ # Some distributions (like openSUSE) have udev configured to forcefully
160+ # reset the scheduler for loopN devices to be "none", which breaks this
161+ # test. We cannot modify the udev behaviour of the host, but since this is
162+ # usually triggered by the "change" event from losetup, we can wait for a
163+ # little bit before continuing the test. For more details, see
164+ # <https://github.com/opencontainers/runc/issues/4781>.
165+ sleep 2s
158166
159167 # See if BFQ scheduler is available.
160168 if ! { grep -qw bfq " /sys/block/${dev#/ dev/ } /queue/scheduler" &&
161169 echo bfq > " /sys/block/${dev#/ dev/ } /queue/scheduler" ; }; then
162- losetup -d " $dev "
163170 skip " BFQ scheduler not available"
164171 fi
165172
173+ # Check that the device still has the right scheduler, in case we lost the
174+ # race above...
175+ if ! grep -qw ' \[bfq\]' " /sys/block/${dev#/ dev/ } /queue/scheduler" ; then
176+ skip " udev is configured to reset loop device io scheduler"
177+ fi
178+
166179 set_cgroups_path
167180
168181 IFS=$' \t :' read -r major minor <<< " $(lsblk -nd -o MAJ:MIN " $dev " )"
@@ -198,9 +211,6 @@ function setup() {
198211EOF
199212 weights2=$( get_cgroup_value $file )
200213
201- # The loop device itself is no longer needed.
202- losetup -d " $dev "
203-
204214 # Check original values.
205215 grep ' ^default 333$' <<< " $weights1"
206216 grep " ^$major :$minor 444$" <<< " $weights1"
213223@test " runc run (per-device multiple iops via unified)" {
214224 requires root cgroups_v2
215225
216- dd if=/dev/zero of=backing1.img bs=4096 count=1
217- dev1=$( losetup --find --show backing1.img) || skip " unable to create a loop device"
218-
219- # Second device.
220- dd if=/dev/zero of=backing2.img bs=4096 count=1
221- dev2=$( losetup --find --show backing2.img) || skip " unable to create a loop device"
226+ dev1=" $( setup_loopdev) "
227+ dev2=" $( setup_loopdev) "
222228
223229 set_cgroups_path
224230
233239 runc run -d --console-socket " $CONSOLE_SOCKET " test_dev_weight
234240 [ " $status " -eq 0 ]
235241
236- # The loop devices are no longer needed.
237- losetup -d " $dev1 "
238- losetup -d " $dev2 "
239-
240242 weights=$( get_cgroup_value " io.max" )
241243 grep " ^$major1 :$minor1 .* riops=333 wiops=444$" <<< " $weights"
242244 grep " ^$major2 :$minor2 .* riops=555 wiops=666$" <<< " $weights"
0 commit comments