diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -1062,7 +1062,7 @@ do_open(const char *vmname) { struct vmctx *ctx; - int error; + int fd, error; bool reinit, romboot; #ifndef WITHOUT_CAPSICUM cap_rights_t rights; @@ -1075,29 +1075,33 @@ if (lpc_bootrom()) romboot = true; - error = vm_create(vmname); - if (error) { - if (errno == EEXIST) { - if (romboot) { + if (romboot) { + fd = vmmctl_open(); + error = vm_fcreate(fd, vmname); + if (error) { + if (errno == EEXIST) { reinit = true; } else { - /* - * The virtual machine has been setup by the - * userspace bootloader. - */ + perror("vm_create"); + exit(4); } - } else { - perror("vm_create"); - exit(4); } } else { - if (!romboot) { + /* + * In this case, expect that the virtual machine has been setup + * by the userspace bootloader. + */ + error = vm_create(vmname); + if (!error) { /* * If the virtual machine was just created then a * bootrom must be configured to boot it. */ fprintf(stderr, "virtual machine cannot be booted\n"); exit(4); + } else if (errno != EEXIST) { + perror("vm_create"); + exit(4); } }