Synopsis:      vmd fails to load config when boot kernel is used
Category:      system
Environment:
        System      : OpenBSD 7.5
Details : OpenBSD 7.5 (GENERIC.MP) #82: Wed Mar 20 15:48:40 MDT 2024 dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

        Architecture: OpenBSD.amd64
        Machine     : amd64

Description:
I run a vmd(8) server where I will build OpenBSD images to test different setups. The process for building the base setup uses a configuration
        similar to the one below.

        === vm-build.conf
        RD_PATH="/home/vms/_http/htdocs/pub/OpenBSD/7.5/amd64"
        switch "build" {
                interface bridge1
                rdomain 5
                group VMS
                enable
        }
        vm "build-host" {
                memory 512M
                boot $RD_PATH "/bsd.rd"
                interfaces 1
                interface { switch "build" lladdr fe:e1:ba:00:00:01 }
                disable
        }
        ===

This configuration creates a "template" image which I then extend when I
        build the actual OpenBSD image using a command like.

        vmctl start -c -B net -d `pwd`/vm.qcow2 \
                -b /home/vms/_http/htdocs/pub/OpenBSD/7.5/amd64/bsd.rd
                -t build-host newVM-build

However when I try to load the vm-build.conf config file I receive the
        following errors.

Jun 30 17:46:56 vmbsd vmd[34669]: no kernel or disk/cdrom specified

How-To-Repeat:
Using the provided vm-build.conf and the vmctl(8) command from OpenBSD
        7.5 run the following command.

        vmctl load `pwd`/vm-build.conf

Fix:
        Reviewing changes to vmd/vmd.c 1.146 appears a change to how the
presence of a kernel load was tested for (line 1385). Originally it was testing for the presence of a kernel string, but change to check for the file descriptor. This change might be in conjunction with change vmd/parse.y 1.67. After the initial load of the config by parse.y, vm_register() is called. As part of the vm_register() function the disk, cdrom and kernel are checked (line 1421). However the kernel file has not been opened at this point so the file handle
        stored in vmc.vmc_kernel is still set to -1.

I am not sure if this change is correct as I am sure my summary of what I think is happening is missing plenty of understanding. The patch below changes the check in vm_register() to make sure the a boot option (kernel, disk, cdrom) was configured. With this patch
        I am again able to load the example config.

--- vmd.c.orig  Tue Jul  2 14:42:39 2024
+++ vmd.c       Tue Jul  2 14:46:13 2024
@@ -1418,8 +1418,7 @@
        } else if (vmc->vmc_nnics > VM_MAX_NICS_PER_VM) {
                log_warnx("invalid number of interfaces");
                goto fail;
-       } else if (vmc->vmc_kernel == -1 && vmc->vmc_ndisks == 0
-           && strlen(vmc->vmc_cdrom) == 0) {
+ } else if ((vmc->vmc_flags & (VMOP_CREATE_KERNEL|VMOP_CREATE_DISK|VMOP_CREATE_CDROM)) == 0) {
                log_warnx("no kernel or disk/cdrom specified");
                goto fail;
        } else if (strlen(vcp->vcp_name) == 0) {

Reply via email to