42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package vm
|
|
|
|
import (
|
|
"fmt"
|
|
"qvm/internal/config"
|
|
"qvm/internal/virtiofsd"
|
|
"strconv"
|
|
)
|
|
|
|
// buildQEMUCommand builds the QEMU command line for virtiofsd-based mounts.
|
|
// Uses vhost-user-fs-pci devices which support hot-plugging.
|
|
func buildQEMUCommand(cfg *config.Config, sshPort int, mounts []virtiofsd.Mount) []string {
|
|
memSize := cfg.VM.Memory
|
|
|
|
// vhost-user-fs requires shared memory backend
|
|
args := []string{
|
|
"-machine", "q35",
|
|
"-accel", "kvm",
|
|
"-cpu", "host",
|
|
"-object", fmt.Sprintf("memory-backend-memfd,id=mem,size=%s,share=on", memSize),
|
|
"-numa", "node,memdev=mem",
|
|
"-smp", strconv.Itoa(cfg.VM.CPUs),
|
|
"-display", "none",
|
|
"-daemonize",
|
|
"-pidfile", config.PIDFile,
|
|
"-drive", fmt.Sprintf("file=%s,if=virtio,format=qcow2", config.Overlay),
|
|
"-netdev", fmt.Sprintf("user,id=n0,hostfwd=tcp::%d-:22", sshPort),
|
|
"-device", "virtio-net-pci,netdev=n0",
|
|
"-serial", fmt.Sprintf("file:%s", config.SerialLog),
|
|
"-qmp", fmt.Sprintf("unix:%s,server,nowait", config.QMPSocket),
|
|
}
|
|
|
|
// Add vhost-user-fs devices for each mount
|
|
for _, mount := range mounts {
|
|
args = append(args,
|
|
"-chardev", fmt.Sprintf("socket,id=%s,path=%s", mount.Tag, mount.SocketPath),
|
|
"-device", fmt.Sprintf("vhost-user-fs-pci,queue-size=1024,chardev=%s,tag=%s", mount.Tag, mount.Tag),
|
|
)
|
|
}
|
|
|
|
return args
|
|
}
|