clear qcow on rebuild, update fs mounting

This commit is contained in:
Joshua Bell 2026-03-09 23:24:19 -05:00
parent cbe9b7241a
commit 08236f04a0
4 changed files with 101 additions and 15 deletions

View file

@ -196,8 +196,8 @@ func HotMountWorkspace(ws *workspace.Workspace) mo.Result[struct{}] {
client := qmpResult.MustGet()
defer client.Close()
// Hot-mount the filesystem
hotMountResult := client.HotMountFilesystem(ws.MountTag, mount.SocketPath)
// Hot-mount the filesystem onto a free PCIe hotplug root port
hotMountResult := client.HotMountFilesystem(ws.MountTag, mount.SocketPath, HotplugBusPrefix, HotplugSlots)
if hotMountResult.IsError() {
vfsManager.StopMount(mount)
return mo.Err[struct{}](fmt.Errorf("failed to hot-mount filesystem: %w", hotMountResult.Error()))

View file

@ -7,8 +7,18 @@ import (
"strconv"
)
// HotplugSlots is the number of PCIe root ports reserved for hot-plugging
// workspace mounts into a running VM. Each hot-mounted virtiofs device needs
// its own root port since pcie.0 does not support hotplug.
const HotplugSlots = 16
// HotplugBusPrefix is the bus ID prefix for hotplug-capable PCIe root ports.
// Slots are named hotplug0, hotplug1, ..., hotplugN.
const HotplugBusPrefix = "hotplug"
// buildQEMUCommand builds the QEMU command line for virtiofsd-based mounts.
// Uses vhost-user-fs-pci devices which support hot-plugging.
// Uses vhost-user-fs-pci devices for boot-time mounts and provisions empty
// PCIe root ports for hot-plugging additional mounts at runtime.
func buildQEMUCommand(cfg *config.Config, sshPort int, mounts []virtiofsd.Mount) []string {
memSize := cfg.VM.Memory
@ -31,7 +41,7 @@ func buildQEMUCommand(cfg *config.Config, sshPort int, mounts []virtiofsd.Mount)
"-qmp", fmt.Sprintf("unix:%s,server,nowait", config.QMPSocket),
}
// Add vhost-user-fs devices for each mount
// Add vhost-user-fs devices for each boot-time mount
for _, mount := range mounts {
args = append(args,
"-chardev", fmt.Sprintf("socket,id=%s,path=%s", mount.Tag, mount.SocketPath),
@ -39,5 +49,15 @@ func buildQEMUCommand(cfg *config.Config, sshPort int, mounts []virtiofsd.Mount)
)
}
// Provision empty PCIe root ports for hot-plugging workspace mounts.
// The q35 root bus (pcie.0) does not support hotplug, so we need
// dedicated root ports that accept device_add at runtime.
for i := 0; i < HotplugSlots; i++ {
busID := fmt.Sprintf("%s%d", HotplugBusPrefix, i)
args = append(args,
"-device", fmt.Sprintf("pcie-root-port,id=%s,slot=%d", busID, i+1),
)
}
return args
}