mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests: clean up loopback devices properly
If an error occurs during a test which sets up loopback devices, the loopback device is not freed. Since most systems have very conservative limits on the number of loopback devices, re-running a failing test locally to debug it often ends up erroring out due to loopback device exhaustion. So let's just move the "losetup -d" to teardown, where it belongs. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
@@ -4,6 +4,7 @@ load helpers
|
||||
|
||||
function teardown() {
|
||||
teardown_bundle
|
||||
teardown_loopdevs
|
||||
}
|
||||
|
||||
function setup() {
|
||||
@@ -153,13 +154,11 @@ function setup() {
|
||||
@test "runc run (per-device io weight for bfq)" {
|
||||
requires root # to create a loop device
|
||||
|
||||
dd if=/dev/zero of=backing.img bs=4096 count=1
|
||||
dev=$(losetup --find --show backing.img) || skip "unable to create a loop device"
|
||||
dev="$(setup_loopdev)"
|
||||
|
||||
# See if BFQ scheduler is available.
|
||||
if ! { grep -qw bfq "/sys/block/${dev#/dev/}/queue/scheduler" &&
|
||||
echo bfq >"/sys/block/${dev#/dev/}/queue/scheduler"; }; then
|
||||
losetup -d "$dev"
|
||||
skip "BFQ scheduler not available"
|
||||
fi
|
||||
|
||||
@@ -198,9 +197,6 @@ function setup() {
|
||||
EOF
|
||||
weights2=$(get_cgroup_value $file)
|
||||
|
||||
# The loop device itself is no longer needed.
|
||||
losetup -d "$dev"
|
||||
|
||||
# Check original values.
|
||||
grep '^default 333$' <<<"$weights1"
|
||||
grep "^$major:$minor 444$" <<<"$weights1"
|
||||
@@ -213,12 +209,8 @@ EOF
|
||||
@test "runc run (per-device multiple iops via unified)" {
|
||||
requires root cgroups_v2
|
||||
|
||||
dd if=/dev/zero of=backing1.img bs=4096 count=1
|
||||
dev1=$(losetup --find --show backing1.img) || skip "unable to create a loop device"
|
||||
|
||||
# Second device.
|
||||
dd if=/dev/zero of=backing2.img bs=4096 count=1
|
||||
dev2=$(losetup --find --show backing2.img) || skip "unable to create a loop device"
|
||||
dev1="$(setup_loopdev)"
|
||||
dev2="$(setup_loopdev)"
|
||||
|
||||
set_cgroups_path
|
||||
|
||||
@@ -233,10 +225,6 @@ EOF
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_dev_weight
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# The loop devices are no longer needed.
|
||||
losetup -d "$dev1"
|
||||
losetup -d "$dev2"
|
||||
|
||||
weights=$(get_cgroup_value "io.max")
|
||||
grep "^$major1:$minor1 .* riops=333 wiops=444$" <<<"$weights"
|
||||
grep "^$major2:$minor2 .* riops=555 wiops=666$" <<<"$weights"
|
||||
|
||||
@@ -791,6 +791,29 @@ function teardown_seccompagent() {
|
||||
rm -f "$SECCCOMP_AGENT_SOCKET"
|
||||
}
|
||||
|
||||
LOOPBACK_DEVICE_LIST="$(mktemp "$BATS_TMPDIR/losetup.XXXXXX")"
|
||||
|
||||
function setup_loopdev() {
|
||||
local backing dev
|
||||
backing="$(mktemp "$BATS_RUN_TMPDIR/backing.img.XXXXXX")"
|
||||
truncate --size=4K "$backing"
|
||||
|
||||
dev="$(losetup --find --show "$backing")" || skip "unable to create a loop device"
|
||||
echo "$dev" >>"$LOOPBACK_DEVICE_LIST"
|
||||
|
||||
unlink "$backing"
|
||||
echo "$dev"
|
||||
}
|
||||
|
||||
function teardown_loopdevs() {
|
||||
[ -s "$LOOPBACK_DEVICE_LIST" ] || return 0
|
||||
while IFS= read -r dev; do
|
||||
echo "losetup -d '$dev'" >&2
|
||||
losetup -d "$dev"
|
||||
done <"$LOOPBACK_DEVICE_LIST"
|
||||
truncate --size=0 "$LOOPBACK_DEVICE_LIST"
|
||||
}
|
||||
|
||||
function setup_bundle() {
|
||||
local image="$1"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user