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 with share=on // We must specify memory size only via the memory backend and attach it to NUMA // The -m flag must match the memory backend size for QEMU to be happy args := []string{ "-machine", "q35,memory-backend=mem", "-accel", "kvm", "-cpu", "host", "-object", fmt.Sprintf("memory-backend-memfd,id=mem,size=%s,share=on", memSize), "-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 }