Skip to content

Commit 4544d1f

Browse files
committed
fix: correct virtiofsd lifecycle — forking, iso check ordering, and fallback
virtiofsd forks after startup; check socket existence rather than parent PID to detect success, and use pgrep to track the daemon child for cleanup. Move start_virtiofsd() call to after configure_storage() so $iso is correctly cleared before the installer check runs. Clear VIRTIOFSD on early return so configure_file_sharing() falls back to 9p instructions when virtiofsd is not started.
1 parent 058e229 commit 4544d1f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

quickemu

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,15 @@ function start_virtiofsd() {
16271627
return
16281628
fi
16291629

1630+
# Skip virtiofs when booting from an ISO (installation). By this point in
1631+
# vm_boot(), quickemu has already cleared $iso when the disk is in use, so
1632+
# a non-empty $iso reliably means we are booting the installer. The
1633+
# shared-memory NUMA backend required for virtiofs can cause installer hangs.
1634+
if [ -n "${iso}" ]; then
1635+
VIRTIOFSD=""
1636+
return
1637+
fi
1638+
16301639
VIRTIOFSD_SOCKET="${VMDIR}/${VMNAME}.virtiofsd-sock"
16311640
# Remove any stale socket left by an unclean shutdown. quickemu already
16321641
# checks the PID file and refuses to start if the VM is running, so a
@@ -1644,10 +1653,11 @@ function start_virtiofsd() {
16441653
virtiofsd_stderr=$(mktemp)
16451654
echo "${VIRTIOFSD} ${virtiofsd_args[*]} &" >> "${VMDIR}/${VMNAME}.sh"
16461655
${VIRTIOFSD} "${virtiofsd_args[@]}" >> "${VMDIR}/${VMNAME}.log" 2>"${virtiofsd_stderr}" &
1647-
VIRTIOFSD_PID=$!
1648-
sleep 0.25
1656+
sleep 0.5
16491657

1650-
if ! kill -0 "${VIRTIOFSD_PID}" 2>/dev/null; then
1658+
# virtiofsd forks: the shell child we spawned exits once the daemon child
1659+
# is running. Check the socket rather than the parent PID to detect success.
1660+
if [ ! -S "${VIRTIOFSD_SOCKET}" ]; then
16511661
if grep -q "Operation not permitted" "${virtiofsd_stderr}" 2>/dev/null; then
16521662
echo " - WARNING! virtiofsd failed to start (insufficient permissions); falling back to 9p."
16531663
echo " Install the standalone virtiofsd package to enable virtiofs support."
@@ -1664,6 +1674,8 @@ function start_virtiofsd() {
16641674
cat "${virtiofsd_stderr}" >> "${VMDIR}/${VMNAME}.log"
16651675
rm -f "${virtiofsd_stderr}"
16661676

1677+
# The parent exits after forking the daemon child; find the child by socket.
1678+
VIRTIOFSD_PID=$(pgrep -f "virtiofsd.*${VIRTIOFSD_SOCKET}" 2>/dev/null | head -1)
16671679
echo "${VIRTIOFSD_PID}" > "${VMDIR}/${VMNAME}.virtiofsd-pid"
16681680
echo " - virtiofsd: ${VIRTIOFSD_SOCKET} (${VIRTIOFSD_PID})"
16691681
}
@@ -1752,7 +1764,6 @@ function vm_boot() {
17521764

17531765
echo "Quickemu ${VERSION} using ${QEMU} v${QEMU_VER_LONG}"
17541766
echo " - Host: ${OS_RELEASE} running ${KERNEL_NAME} ${KERNEL_VER} ${KERNEL_NODE}"
1755-
start_virtiofsd
17561767

17571768
# Force to lowercase.
17581769
boot=${boot,,}
@@ -1769,6 +1780,7 @@ function vm_boot() {
17691780
configure_bios
17701781
configure_os_quirks
17711782
configure_storage
1783+
start_virtiofsd
17721784
configure_display
17731785
configure_audio
17741786
configure_ports
@@ -2575,9 +2587,7 @@ function fileshare_param_check() {
25752587
# NOTE: only the standalone virtiofsd (Rust) is supported — the legacy
25762588
# QEMU-bundled C daemon (/usr/lib/qemu/virtiofsd) uses incompatible CLI
25772589
# syntax and requires root, so it is intentionally ignored here.
2578-
# Skip virtiofs during OS installation: the required shared-memory NUMA
2579-
# backend can confuse installers and cause hangs. 9p is used instead.
2580-
if [ -n "${PUBLIC}" ] && [ "${guest_os}" == "linux" ] && [ -z "${iso}" ]; then
2590+
if [ -n "${PUBLIC}" ] && [ "${guest_os}" == "linux" ]; then
25812591
VIRTIOFSD=$(command -v virtiofsd 2>/dev/null)
25822592
if [ ! -x "${VIRTIOFSD}" ]; then
25832593
VIRTIOFSD=""

0 commit comments

Comments
 (0)