Skip to content

Commit b4469a5

Browse files
authored
Merge pull request #200 from yizhanglinux/loop-010-fix
loop/010: fix the flood udev events during the test Detailed discussions are recorded in the GitHub issue 181: #181 As the GitHub issue recorded, I confirmed that this change does not affect the purpose of the test case loop/010.
2 parents 8ac6c4f + 32a8e41 commit b4469a5

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

common/rc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,37 @@ _systemctl_stop() {
544544
done
545545
}
546546

547-
_drain_udev_events() {
547+
_systemctl_unit_is_active() {
548+
local unit="$1"
549+
548550
if command -v systemctl &>/dev/null &&
549-
systemctl is-active --quiet systemd-udevd; then
550-
systemctl restart systemd-udevd.service
551+
systemctl is-active --quiet "$unit"; then
552+
return 0
553+
fi
554+
return 1
555+
}
556+
557+
_systemd_stop_udevd() {
558+
if _systemctl_unit_is_active "systemd-udevd"; then
559+
systemctl --quiet stop systemd-udevd
560+
systemctl --quiet mask systemd-udevd
551561
else
552-
udevadm settle --timeout=900
562+
echo "WARNING: systemd-udevd is not active"
553563
fi
554564
}
555565

566+
_systemd_start_udevd() {
567+
if ! _systemctl_unit_is_active "systemd-udevd"; then
568+
systemctl --quiet unmask systemd-udevd
569+
systemctl --quiet start systemd-udevd
570+
fi
571+
if ! _systemctl_unit_is_active "systemd-udevd"; then
572+
echo "WARNING: systemd-udevd not started"
573+
return 1
574+
fi
575+
return 0
576+
}
577+
556578
# Run the given command as NORMAL_USER
557579
_run_user() {
558580
su "$NORMAL_USER" -c "$1"

tests/loop/010

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# stale loop partitions when one process opens the loop partition and
77
# another process detaches the loop device.
88
#
9+
# Regression test for commit:
10+
# 18048c1af783 loop: Fix a race between loop detach and loop open
11+
912
. tests/loop/rc
1013
DESCRIPTION="check stale loop partition"
1114
TIMED=1
@@ -60,6 +63,11 @@ test() {
6063
mkfs.xfs --force "${loop_device}p1" >& /dev/null
6164
losetup --detach "${loop_device}" >& /dev/null
6265

66+
# This test generates udev events faster than the rate at which udevd
67+
# can process events. Stop systemd-udevd to prevent future test cases
68+
# fail.
69+
_systemd_stop_udevd
70+
6371
create_loop "${loop_device}" &
6472
create_pid=$!
6573
detach_loop "${loop_device}" &
@@ -68,8 +76,9 @@ test() {
6876
sleep "${TIMEOUT:-90}"
6977
{
7078
kill -9 $create_pid
79+
wait $create_pid
7180
kill -9 $detach_pid
72-
wait
81+
wait $detach_pid
7382
sleep 1
7483
} 2>/dev/null
7584

@@ -79,10 +88,7 @@ test() {
7988
echo "Fail"
8089
fi
8190

82-
# This test generates udev events faster than the rate at which udevd
83-
# can process events. Drain udev events to prevent future test cases
84-
# fail.
85-
_drain_udev_events
91+
_systemd_start_udevd
8692

8793
echo "Test complete"
8894
}

0 commit comments

Comments
 (0)