From nobody Tue Apr 30 22:34:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1614400486; cv=none; d=zohomail.com; s=zohoarc; b=eCfZcPX0LzGvIAZX4RM1tJc0vjDPi5qMEgcu0Lii7SJUqABmBclDdfRJm89OtIHzaJ5wiwn7l8NBZ60BmASswJdk+7G0VygQVlaNok3TXE2VHpv3/mC1Z9oy3tVCh3zmsr4QVx5ExfrQXk+IQaRQQnCDZvB98SGd9CQ2prPcSQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614400486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Pyd/IptiNnuyJ8Kb33oEMeOX3Pk6f2joFcy7v1SUYQ8=; b=j7h/NLzX/2dhum1kMS+tyD8A/2zlGa3g0SzCSpAKTTnJ7uzUxxMTNaYOqQ2ThkuvH6YU+5oAEwm8Mg/hX0VJa0GSgOWH1tpsiFpqjZfL5voNxVIK8vUP5byi6SUUf2eAiG6wrv/Hypzq3WpvM59O1e4h6sfnJvX4ZW0wxY9/R4E= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614400485995784.1744214100148; Fri, 26 Feb 2021 20:34:45 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-1I71cIiKOYqEd1xu1_4NpA-1; Fri, 26 Feb 2021 23:34:36 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59135107ACE4; Sat, 27 Feb 2021 04:34:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3B2D5D9CA; Sat, 27 Feb 2021 04:34:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BDDD54EEF6; Sat, 27 Feb 2021 04:34:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11R4YRE1002220 for ; Fri, 26 Feb 2021 23:34:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id ADC331649DC; Sat, 27 Feb 2021 04:34:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A76391649F4 for ; Sat, 27 Feb 2021 04:34:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE733185A7BC for ; Sat, 27 Feb 2021 04:34:24 +0000 (UTC) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-37-EBcxeulwM6K3ZIw--rUYag-1; Fri, 26 Feb 2021 23:34:21 -0500 Received: by mail-lf1-f48.google.com with SMTP id p21so16919654lfu.11 for ; Fri, 26 Feb 2021 20:34:21 -0800 (PST) Received: from kloomba.my.domain ([95.104.143.160]) by smtp.gmail.com with ESMTPSA id x192sm1229979lff.257.2021.02.26.20.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Feb 2021 20:34:18 -0800 (PST) X-MC-Unique: 1I71cIiKOYqEd1xu1_4NpA-1 X-MC-Unique: EBcxeulwM6K3ZIw--rUYag-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pyd/IptiNnuyJ8Kb33oEMeOX3Pk6f2joFcy7v1SUYQ8=; b=coBBCWI14zZcDdzDnhM1mz9IFjh0YC+GTnvJmEZPW3uSKY4qEF6tC35Af+k4ggLlbU i3114g3uN8YKu5aFxGRxuJy2nhFSN3EkeT3on3vsc95CAtNTYm2OC7TVi2kcFp6iiigi 00WeQUn+iFiBl+iBTrROp7cxFjR9raEPTtruC2D9U/GK3AYa+cNLudHnaKLkv6BX8f+3 jl71sZjBTlQuPO1nagEU7112dlSuStU18bf0vdYf7wV8SHkmIxmidzXqbVhqchA/iq8E BxVvNpJQxggYUY38x2QmTXrEbdu6GOCmkP80eU/31ISkLZV0YbI+aKcotWF89KCByJ2Q 7HEQ== X-Gm-Message-State: AOAM5336d7qlTmWYZYV3EGC4dxXTBUBJUeljcEDl97tMdNDl/eZWEB87 WJqFtyhbV5/FOjZhrqsK81+itNN9Oid5vQ== X-Google-Smtp-Source: ABdhPJwhldOqhvfy6N6f0Aq7w4enyzHC8g2gSKSy217RA7tLsHKkaNSnLrzM6apwO9TjPj9J5aAFuw== X-Received: by 2002:ac2:5e9b:: with SMTP id b27mr3419148lfq.502.1614400459596; Fri, 26 Feb 2021 20:34:19 -0800 (PST) From: Roman Bogorodskiy To: libvir-list@redhat.com Subject: [PATCH] bhyve: add support Date: Sat, 27 Feb 2021 08:34:08 +0400 Message-Id: <20210227043408.8922-1-bogorodskiy@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Roman Bogorodskiy X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement "" support for bhyve driver. As there are not really lot of options, try to find "BHYVE_UEFI.fd" firmware which is installed by the sysutils/uefi-edk2-bhyve FreeBSD port. If not found, just use the first found firmware in the firmwares directory (which is configurable via config file). Signed-off-by: Roman Bogorodskiy Reviewed-by: Michal Privoznik --- Not extremely happy about the LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE knob, but not sure how to test this otherwise. po/POTFILES.in | 1 + src/bhyve/bhyve_domain.c | 5 + src/bhyve/bhyve_firmware.c | 91 +++++++++++++++++++ src/bhyve/bhyve_firmware.h | 30 ++++++ src/bhyve/bhyve_process.c | 15 +++ src/bhyve/bhyve_process.h | 5 + src/bhyve/meson.build | 1 + .../bhyvexml2argv-firmware-efi.args | 11 +++ .../bhyvexml2argv-firmware-efi.ldargs | 1 + .../bhyvexml2argv-firmware-efi.xml | 22 +++++ tests/bhyvexml2argvtest.c | 83 ++++++++++++++--- 11 files changed, 254 insertions(+), 11 deletions(-) create mode 100644 src/bhyve/bhyve_firmware.c create mode 100644 src/bhyve/bhyve_firmware.h create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.ldar= gs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.xml diff --git a/po/POTFILES.in b/po/POTFILES.in index 80c5f145be..413783ee35 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -14,6 +14,7 @@ @SRCDIR@src/bhyve/bhyve_command.c @SRCDIR@src/bhyve/bhyve_domain.c @SRCDIR@src/bhyve/bhyve_driver.c +@SRCDIR@src/bhyve/bhyve_firmware.c @SRCDIR@src/bhyve/bhyve_monitor.c @SRCDIR@src/bhyve/bhyve_parse_command.c @SRCDIR@src/bhyve/bhyve_process.c diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 8fbc554a0a..209e4d3905 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -64,6 +64,9 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def) if (def->os.bootloader =3D=3D NULL && def->os.loader) return true; =20 + if (def->os.firmware =3D=3D VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) + return true; + if (def->nserials || def->nconsoles) return true; =20 @@ -230,6 +233,8 @@ virDomainDefParserConfig virBhyveDriverDomainDefParserC= onfig =3D { .domainPostParseCallback =3D bhyveDomainDefPostParse, .assignAddressesCallback =3D bhyveDomainDefAssignAddresses, .deviceValidateCallback =3D bhyveDomainDeviceDefValidate, + + .features =3D VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT, }; =20 static void diff --git a/src/bhyve/bhyve_firmware.c b/src/bhyve/bhyve_firmware.c new file mode 100644 index 0000000000..ccc3a5ffc8 --- /dev/null +++ b/src/bhyve/bhyve_firmware.c @@ -0,0 +1,91 @@ +/* + * bhyve_firmware.c: bhyve firmware management + * + * Copyright (C) 2021 Roman Bogorodskiy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#include +#include + +#include "viralloc.h" +#include "virlog.h" +#include "virfile.h" +#include "bhyve_conf.h" +#include "bhyve_firmware.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_firmware"); + + +#define BHYVE_DEFAULT_FIRMWARE "BHYVE_UEFI.fd" + +int +bhyveFirmwareFillDomain(bhyveConnPtr driver, + virDomainDefPtr def, + unsigned int flags) +{ + g_autoptr(DIR) dir =3D NULL; + virBhyveDriverConfigPtr cfg =3D virBhyveDriverGetConfig(driver); + const char *firmware_dir_cfg =3D cfg->firmwareDir; + const char *firmware_dir_env =3D NULL, *firmware_dir =3D NULL; + struct dirent *entry; + char *matching_firmware =3D NULL; + char *first_found =3D NULL; + + virCheckFlags(0, -1); + + if (def->os.firmware =3D=3D VIR_DOMAIN_OS_DEF_FIRMWARE_NONE) + return 0; + + if (virDirOpenIfExists(&dir, firmware_dir_cfg) > 0) { + while ((virDirRead(dir, &entry, firmware_dir)) > 0) { + if (STREQ(entry->d_name, BHYVE_DEFAULT_FIRMWARE)) { + matching_firmware =3D g_strdup(entry->d_name); + break; + } + if (!first_found) + first_found =3D g_strdup(entry->d_name); + } + } + + if (!matching_firmware) { + if (!first_found) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("no firmwares found in %s"), + firmware_dir_cfg); + return -1; + } else { + matching_firmware =3D first_found; + } + } + + if (!def->os.loader) + def->os.loader =3D g_new0(virDomainLoaderDef, 1); + + def->os.loader->type =3D VIR_DOMAIN_LOADER_TYPE_PFLASH; + def->os.loader->readonly =3D VIR_TRISTATE_BOOL_YES; + + VIR_FREE(def->os.loader->path); + + firmware_dir_env =3D g_getenv("LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE"); + firmware_dir =3D firmware_dir_env ? firmware_dir_env : firmware_dir_cf= g; + def->os.loader->path =3D g_build_filename(firmware_dir, matching_firmw= are, NULL); + + return 0; +} diff --git a/src/bhyve/bhyve_firmware.h b/src/bhyve/bhyve_firmware.h new file mode 100644 index 0000000000..ae4bc98676 --- /dev/null +++ b/src/bhyve/bhyve_firmware.h @@ -0,0 +1,30 @@ +/* + * bhyve_firmware.h: bhyve firmware management + * + * Copyright (C) 2021 Roman Bogorodskiy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#pragma once + +#include "domain_conf.h" +#include "bhyve_utils.h" + +int +bhyveFirmwareFillDomain(bhyveConnPtr driver, + virDomainDefPtr def, + unsigned int flags); diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 060018bc70..0cfe69688c 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -33,6 +33,7 @@ #include "bhyve_device.h" #include "bhyve_driver.h" #include "bhyve_command.h" +#include "bhyve_firmware.h" #include "bhyve_monitor.h" #include "bhyve_process.h" #include "datatypes.h" @@ -251,6 +252,17 @@ virBhyveProcessStartImpl(bhyveConnPtr driver, return ret; } =20 +int +bhyveProcessPrepareDomain(bhyveConnPtr driver, + virDomainObjPtr vm, + unsigned int flags) +{ + if (bhyveFirmwareFillDomain(driver, vm->def, flags) < 0) + return -1; + + return 0; +} + int virBhyveProcessStart(virConnectPtr conn, virDomainObjPtr vm, @@ -268,6 +280,9 @@ virBhyveProcessStart(virConnectPtr conn, conn, bhyveProcessAutoDestroy) < 0) return -1; =20 + if (bhyveProcessPrepareDomain(driver, vm, flags) < 0) + return -1; + return virBhyveProcessStartImpl(driver, vm, reason); } =20 diff --git a/src/bhyve/bhyve_process.h b/src/bhyve/bhyve_process.h index d7b4e0bd4e..133863c1e0 100644 --- a/src/bhyve/bhyve_process.h +++ b/src/bhyve/bhyve_process.h @@ -23,6 +23,11 @@ =20 #include "bhyve_utils.h" =20 +int +bhyveProcessPrepareDomain(bhyveConnPtr driver, + virDomainObjPtr vm, + unsigned int flags); + int virBhyveProcessStart(virConnectPtr conn, virDomainObjPtr vm, virDomainRunningReason reason, diff --git a/src/bhyve/meson.build b/src/bhyve/meson.build index 2b65eecf5e..b3551477b7 100644 --- a/src/bhyve/meson.build +++ b/src/bhyve/meson.build @@ -2,6 +2,7 @@ bhyve_sources =3D files( 'bhyve_capabilities.c', 'bhyve_command.c', 'bhyve_conf.c', + 'bhyve_firmware.c', 'bhyve_parse_command.c', 'bhyve_device.c', 'bhyve_domain.c', diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args b/test= s/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args new file mode 100644 index 0000000000..40bc84ef27 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args @@ -0,0 +1,11 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-l bootrom,test_firmware_dir/BHYVE_UEFI.fd \ +-s 1:0,lpc \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,virtio-net,faketapdev,mac=3D52:54:00:00:00:00 bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.ldargs b/te= sts/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.ldargs new file mode 100644 index 0000000000..421376db9e --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.ldargs @@ -0,0 +1 @@ +dummy diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.xml b/tests= /bhyvexml2argvdata/bhyvexml2argv-firmware-efi.xml new file mode 100644 index 0000000000..302326cb26 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.xml @@ -0,0 +1,22 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + +
+ + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 197334f9c4..13b8e34c2b 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -7,17 +7,20 @@ # include "datatypes.h" =20 # include "bhyve/bhyve_capabilities.h" +# include "bhyve/bhyve_conf.h" # include "bhyve/bhyve_domain.h" # include "bhyve/bhyve_utils.h" # include "bhyve/bhyve_command.h" +# include "bhyve/bhyve_process.h" =20 # define VIR_FROM_THIS VIR_FROM_BHYVE =20 static bhyveConn driver; =20 typedef enum { - FLAG_EXPECT_FAILURE =3D 1 << 0, - FLAG_EXPECT_PARSE_ERROR =3D 1 << 1, + FLAG_EXPECT_FAILURE =3D 1 << 0, + FLAG_EXPECT_PARSE_ERROR =3D 1 << 1, + FLAG_EXPECT_PREPARE_ERROR =3D 1 << 2, } virBhyveXMLToArgvTestFlags; =20 static int testCompareXMLToArgvFiles(const char *xml, @@ -29,7 +32,7 @@ static int testCompareXMLToArgvFiles(const char *xml, g_autofree char *actualargv =3D NULL; g_autofree char *actualld =3D NULL; g_autofree char *actualdm =3D NULL; - g_autoptr(virDomainDef) vmdef =3D NULL; + g_autoptr(virDomainObj) vm =3D NULL; g_autoptr(virCommand) cmd =3D NULL; g_autoptr(virCommand) ldcmd =3D NULL; g_autoptr(virConnect) conn =3D NULL; @@ -38,7 +41,10 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(conn =3D virGetConnect())) goto out; =20 - if (!(vmdef =3D virDomainDefParseFile(xml, driver.xmlopt, + if (!(vm =3D virDomainObjNew(driver.xmlopt))) + return -1; + + if (!(vm->def =3D virDomainDefParseFile(xml, driver.xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIV= E))) { if (flags & FLAG_EXPECT_PARSE_ERROR) { ret =3D 0; @@ -54,11 +60,20 @@ static int testCompareXMLToArgvFiles(const char *xml, =20 conn->privateData =3D &driver; =20 - cmd =3D virBhyveProcessBuildBhyveCmd(&driver, vmdef, false); - if (vmdef->os.loader) + if (bhyveProcessPrepareDomain(&driver, vm, 0) < 0) { + if (flags & FLAG_EXPECT_PREPARE_ERROR) { + ret =3D 0; + VIR_TEST_DEBUG("Got expected error: %s", + virGetLastErrorMessage()); + } + goto out; + } + + cmd =3D virBhyveProcessBuildBhyveCmd(&driver, vm->def, false); + if (vm->def->os.loader) ldcmd =3D virCommandNew("dummy"); else - ldcmd =3D virBhyveProcessBuildLoadCmd(&driver, vmdef, "", + ldcmd =3D virBhyveProcessBuildLoadCmd(&driver, vm->def, "", &actualdm); =20 if ((cmd =3D=3D NULL) || (ldcmd =3D=3D NULL)) { @@ -94,10 +109,10 @@ static int testCompareXMLToArgvFiles(const char *xml, ret =3D 0; =20 out: - if (vmdef && - vmdef->ngraphics =3D=3D 1 && - vmdef->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) - virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); + if (vm && vm->def && + vm->def->ngraphics =3D=3D 1 && + vm->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) + virPortAllocatorRelease(vm->def->graphics[0]->data.vnc.port); =20 return ret; } @@ -128,10 +143,16 @@ testCompareXMLToArgvHelper(const void *data) return testCompareXMLToArgvFiles(xml, args, ldargs, dmargs, info->flag= s); } =20 +# define FAKEFIRMWAREDIRTEMPLATE abs_builddir "/bhyvefakefirmwaredir-XXXXX= X" + static int mymain(void) { int ret =3D 0; + g_autofree char *fakefirmwaredir =3D NULL; + g_autofree char *emptyfirmwaredir =3D NULL; + const char *firmwares[] =3D {"BHYVE_UEFI.fd", "BHYVE_UEFI_CSM.fd", "re= find_x64.efi", NULL}; + size_t i; =20 if ((driver.caps =3D virBhyveCapsBuild()) =3D=3D NULL) return EXIT_FAILURE; @@ -142,6 +163,35 @@ mymain(void) if (!(driver.remotePorts =3D virPortAllocatorRangeNew("display", 5900,= 65535))) return EXIT_FAILURE; =20 + if (!(driver.config =3D virBhyveDriverConfigNew())) + return EXIT_FAILURE; + + fakefirmwaredir =3D g_strdup(FAKEFIRMWAREDIRTEMPLATE); + + if (!g_mkdtemp(fakefirmwaredir)) { + fprintf(stderr, "Cannot create fakefirmwaredir"); + abort(); + } + driver.config->firmwareDir =3D fakefirmwaredir; + + emptyfirmwaredir =3D g_strdup(FAKEFIRMWAREDIRTEMPLATE); + + if (!g_mkdtemp(emptyfirmwaredir)) { + fprintf(stderr, "Cannot create emptyfirmwaredir"); + abort(); + } + + i =3D 0; + while (firmwares[i]) { + g_autofree char *firmware_path =3D g_strdup_printf("%s/%s", fakefi= rmwaredir, firmwares[i++]); + + if (virFileTouch(firmware_path, 0600) < 0) { + fprintf(stderr, "Cannot create firmware file"); + abort(); + } + } + + g_setenv("LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE", "test_firmware_dir", T= RUE); =20 # define DO_TEST_FULL(name, flags) \ do { \ @@ -162,6 +212,9 @@ mymain(void) # define DO_TEST_PARSE_ERROR(name) \ DO_TEST_FULL(name, FLAG_EXPECT_PARSE_ERROR) =20 +# define DO_TEST_PREPARE_ERROR(name) \ + DO_TEST_FULL(name, FLAG_EXPECT_PREPARE_ERROR) + driver.grubcaps =3D BHYVE_GRUB_CAP_CONSDEV; driver.bhyvecaps =3D BHYVE_CAP_RTC_UTC | BHYVE_CAP_AHCI32SLOT | \ BHYVE_CAP_NET_E1000 | BHYVE_CAP_LPC_BOOTROM | \ @@ -209,6 +262,10 @@ mymain(void) DO_TEST("sound"); DO_TEST("isa-controller"); DO_TEST_FAILURE("isa-multiple-controllers"); + DO_TEST("firmware-efi"); + g_unsetenv("LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE"); + driver.config->firmwareDir =3D emptyfirmwaredir; + DO_TEST_PREPARE_ERROR("firmware-efi"); DO_TEST("fs-9p"); DO_TEST("fs-9p-readonly"); DO_TEST_FAILURE("fs-9p-unsupported-type"); @@ -264,9 +321,13 @@ mymain(void) driver.bhyvecaps &=3D ~BHYVE_CAP_VNC_PASSWORD; DO_TEST_FAILURE("vnc-password"); =20 + virFileDeleteTree(fakefirmwaredir); + virFileDeleteTree(emptyfirmwaredir); + virObjectUnref(driver.caps); virObjectUnref(driver.xmlopt); virPortAllocatorRangeFree(driver.remotePorts); + virObjectUnref(driver.config); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.30.0