From 5ef0cd25c4c90e44b556e0420005e128b8fcc6e0 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 5 Nov 2024 01:37:16 +0000 Subject: [PATCH] bhyve: Convert to using vm_openf() Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D47032 --- usr.sbin/bhyve/bhyverun.c | 51 ++++++++++----------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 41655a188bf9..be9cd1611700 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -521,41 +521,23 @@ do_open(const char *vmname) { struct vmctx *ctx; int error; - bool reinit, romboot; - - reinit = false; + bool romboot; romboot = bootrom_boot(); - error = vm_create(vmname); - if (error) { - if (errno == EEXIST) { - if (romboot) { - reinit = true; - } else { - /* - * The virtual machine has been setup by the - * userspace bootloader. - */ - } - } else { - perror("vm_create"); - exit(4); - } - } else { - if (!romboot) { - /* - * 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); - } - } - ctx = vm_open(vmname); + /* + * If we don't have a boot ROM, the guest context must have been + * initialized by bhyveload(8) or equivalent. + */ + ctx = vm_openf(vmname, romboot ? VMMAPI_OPEN_REINIT : 0); if (ctx == NULL) { - perror("vm_open"); - exit(4); + if (errno != ENOENT) + err(4, "vm_openf"); + if (!romboot) + errx(4, "no bootrom was configured"); + ctx = vm_openf(vmname, VMMAPI_OPEN_CREATE); + if (ctx == NULL) + err(4, "vm_openf"); } #ifndef WITHOUT_CAPSICUM @@ -563,13 +545,6 @@ do_open(const char *vmname) err(EX_OSERR, "vm_limit_rights"); #endif - if (reinit) { - error = vm_reinit(ctx); - if (error) { - perror("vm_reinit"); - exit(4); - } - } error = vm_set_topology(ctx, cpu_sockets, cpu_cores, cpu_threads, 0); if (error) errx(EX_OSERR, "vm_set_topology");