fix: wait for domain to run before cpuid watcher reads its tap

This commit is contained in:
2026-09-06 11:36:25 +02:00
parent 0c3425e5af
commit 4e0df16271

View File

@@ -23,9 +23,6 @@ PARAM=/sys/module/kvm_amd/parameters
V="virsh -c qemu:///system"
running() { [ "$($V domstate "$DOMAIN" 2>/dev/null)" = running ]; }
tap=$($V domiflist "$DOMAIN" 2>/dev/null | awk '$1 ~ /^(vnet|tap|macvtap)/ {print $1; exit}')
RX="/sys/class/net/$tap/statistics/rx_packets"
rx() { cat "$RX" 2>/dev/null || echo 0; }
set_N() { echo N > "$PARAM/cpuid_passthrough"; }
@@ -46,6 +43,14 @@ wait_net_up() {
return 0
}
# The hook arms this watcher at prepare, before QEMU starts, so the domain is not
# yet running and its tap does not exist. Wait for the domain, then read the tap;
# otherwise the first running check in wait_net_up bails and the flip never happens.
for _ in $(seq 1 120); do running && break; sleep 1; done
running || exit 0
tap=$($V domiflist "$DOMAIN" 2>/dev/null | awk '$1 ~ /^(vnet|tap|macvtap)/ {print $1; exit}')
RX="/sys/class/net/$tap/statistics/rx_packets"
# initial cold boot: wait for the network, then harden
wait_net_up 0
running || exit 0