Skip to content

Commit 541fa2f

Browse files
committed
runtime: Add uevent queue state diagnostics
The uevent queue model now has several independent state directories: pending queues, active event batches, delayed timers and paused queues. Debugging boot delays from logs alone is difficult because these states are intentionally separate. Add ueventctl as a small read-only diagnostic tool that dumps the current filesystem-backed queue state in a stable text format. Let it use the same path variables as the runtime helpers and support --root so tests and offline analysis can inspect an alternate initramfs state tree. Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
1 parent 7316ab5 commit 541fa2f

3 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash -efu
2+
3+
srcdir="${0%/*}"
4+
5+
. "$srcdir/uevent-sh-functions"
6+
7+
root=
8+
command=dump
9+
10+
usage()
11+
{
12+
cat <<-EOF
13+
Usage: ueventctl [--root DIR] [dump|queues|events|timers|pauses]
14+
EOF
15+
}
16+
17+
while [ "$#" -gt 0 ]; do
18+
case "$1" in
19+
--root)
20+
shift
21+
[ "$#" -gt 0 ] || {
22+
usage >&2
23+
exit 2
24+
}
25+
root="$1"
26+
;;
27+
--root=*)
28+
root="${1#--root=}"
29+
;;
30+
-h|--help)
31+
usage
32+
exit 0
33+
;;
34+
dump|queues|events|timers|pauses)
35+
command="$1"
36+
;;
37+
*)
38+
usage >&2
39+
exit 2
40+
;;
41+
esac
42+
shift
43+
done
44+
45+
root="${root%/}"
46+
[ "$root" != / ] ||
47+
root=
48+
49+
print_file()
50+
{
51+
local file="$1" prefix="$2"
52+
53+
while IFS= read -r line || [ -n "$line" ]; do
54+
printf '%s%s\n' "$prefix" "$line"
55+
done < "$file"
56+
}
57+
58+
print_state_tree()
59+
{
60+
local title="$1" dir="$2" group groupdir item rel found=
61+
62+
printf '%s:\n' "$title"
63+
64+
if [ ! -d "$dir" ]; then
65+
printf ' -\n'
66+
return 0
67+
fi
68+
69+
while IFS= read -r group; do
70+
found=1
71+
groupdir="$dir/$group"
72+
printf ' %s\n' "$group"
73+
74+
while IFS= read -r item; do
75+
rel="${item#$groupdir/}"
76+
printf ' - /%s\n' "$rel"
77+
print_file "$item" ' '
78+
done < <(find "$groupdir" -mindepth 1 -type f ! -path '*/.tmp/*' -printf '%P\t%p\n' 2>/dev/null |
79+
sort -k1,1 |
80+
cut -f2-)
81+
done < <(find "$dir" -mindepth 1 -maxdepth 1 -type d ! -name .tmp -printf '%f\n' 2>/dev/null |
82+
sort)
83+
84+
[ -n "$found" ] ||
85+
printf ' -\n'
86+
}
87+
88+
show_queues()
89+
{
90+
print_state_tree 'Queues' "$root$filterdir"
91+
}
92+
93+
show_events()
94+
{
95+
print_state_tree 'Events' "$root$ueventdir"
96+
}
97+
98+
show_timers()
99+
{
100+
print_state_tree 'Timers' "$root$timerdir"
101+
}
102+
103+
show_pauses()
104+
{
105+
print_state_tree 'Paused queues' "$root$uevent_confdb/queue/pause"
106+
}
107+
108+
show_dump()
109+
{
110+
show_queues
111+
show_events
112+
show_timers
113+
show_pauses
114+
}
115+
116+
case "$command" in
117+
dump) show_dump ;;
118+
queues) show_queues ;;
119+
events) show_events ;;
120+
timers) show_timers ;;
121+
pauses) show_pauses ;;
122+
esac
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Queues:
2+
nvmf
3+
- /fc.1
4+
QUEUE=nvmf
5+
TYPE=fc
6+
Events:
7+
nvmf
8+
- /done.fc.0
9+
DONE=1
10+
Timers:
11+
nvmf
12+
- /42.retry.connect.1
13+
TYPE=retry
14+
NAME=connect
15+
Paused queues:
16+
md-raid-member
17+
rc=0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -efu
2+
3+
cwd="${0%/*}"
4+
root="$cwd/root"
5+
6+
rm -rf -- "$root"
7+
mkdir -p -- \
8+
"$root/.initrd/uevent/queues/nvmf/.tmp" \
9+
"$root/.initrd/uevent/events/nvmf" \
10+
"$root/.initrd/uevent/timers/nvmf" \
11+
"$root/.initrd/uevent/confdb/queue/pause/md-raid-member"
12+
13+
export PATH="$PWD/.build/dest/usr/bin:$PATH"
14+
15+
cat > "$root/.initrd/uevent/queues/nvmf/fc.1" <<'EOF'
16+
QUEUE=nvmf
17+
TYPE=fc
18+
EOF
19+
20+
cat > "$root/.initrd/uevent/events/nvmf/done.fc.0" <<'EOF'
21+
DONE=1
22+
EOF
23+
24+
cat > "$root/.initrd/uevent/timers/nvmf/42.retry.connect.1" <<'EOF'
25+
TYPE=retry
26+
NAME=connect
27+
EOF
28+
29+
features/runtime/data/bin/ueventctl --root "$root" dump
30+
31+
rm -rf -- "$root"

0 commit comments

Comments
 (0)