From nobody Tue May 7 19:57:23 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=1615897250; cv=none; d=zohomail.com; s=zohoarc; b=bOuOImWwNqNHdZRn8IFftaTheft0+4IBE2OK+zFUFJ9Xa1XJgva5eQq+MYs0bo29QYkzb6nlFpIc3dBP1Rl6Gj+tNbXdzUDSjJidKnmO86w6UKnSlJ89P+OCWf3CCYh26sO3xS28adgJ2wWZEmNTCEXaWsKcj8bA/3bXEAl0EbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615897250; 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=c+bOdOsc1XuPLUFPs8McpXI0yX32bwHOWeX8hsgFz08=; b=Fe6lxwIinS6pa7ssuDbuynd5O2XHdGd4Y4P7ezjYW0r9VVQqjIjDY6qSRnDlWOcs4NPeaa35ZEG6CfNzygP+u2L9v0IIKuRUjdkq1Yv152+EznwUCtxkNEom2fGpJ1fTwbFJ7x9vHkg1uhqV25Oc8odZk4LWhmXrXQMIlhHULNc= 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 1615897250326396.6467835978942; Tue, 16 Mar 2021 05:20:50 -0700 (PDT) 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-507-LnW3AlwpNTSRggjSopQ1Bw-1; Tue, 16 Mar 2021 08:20:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 786A183DD20; Tue, 16 Mar 2021 12:20:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E309D1658F; Tue, 16 Mar 2021 12:20:37 +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 A04211800657; Tue, 16 Mar 2021 12:20:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12GCKYjg029495 for ; Tue, 16 Mar 2021 08:20:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0367A2166B44; Tue, 16 Mar 2021 12:20:34 +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 F0B392166BA4 for ; Tue, 16 Mar 2021 12:20:31 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 3A39C185A79C for ; Tue, 16 Mar 2021 12:20:31 +0000 (UTC) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-SHzqBmXhMGaDRdiYV572Bw-1; Tue, 16 Mar 2021 08:20:28 -0400 Received: by mail-lj1-f181.google.com with SMTP id z25so20179705lja.3 for ; Tue, 16 Mar 2021 05:20:28 -0700 (PDT) Received: from kloomba.my.domain ([31.29.247.35]) by smtp.gmail.com with ESMTPSA id l5sm3013413lfc.137.2021.03.16.05.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 05:20:25 -0700 (PDT) X-MC-Unique: LnW3AlwpNTSRggjSopQ1Bw-1 X-MC-Unique: SHzqBmXhMGaDRdiYV572Bw-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=c+bOdOsc1XuPLUFPs8McpXI0yX32bwHOWeX8hsgFz08=; b=hBwZEN1GI2YKiebF7Ar6gfJ7u9tatR8MyRQ5u/lLEb25EXPZrTRupO9ahTKwkHEDp8 TgaN+/X3sbKp+WngeiZgZCYbrhax70Z3flnVQ018pz3OwGtqSI1mMdHH3XjfGHwnlo+W wTsmKj2+0V3e6VBwOtlKDsaE2LJyKTE3xSsAWFfRIJSKGpsDq2Uxo5A6CzN7nVKzWrlS qlm5H/3nE/CavyCv2tTsZwzkbCd4tqfi0YBrNccNqFSnKqYZH/fic2Im0/PDzNa6Cnyc zs8sUUSvLTYZCGvQU+ni9nJ4cjW30LxnoYO2CH6mwAszJNOo64zzKQCd5b+unL9wlOX0 l1yA== X-Gm-Message-State: AOAM5309nS3hBH3nM+W76hy8UFg31DbUQlc9pqIQwQ/ldUp6K1f+sqbS Wcc7VM/Mik8GgZdaAoZJmx1oY6ycBuyFlg== X-Google-Smtp-Source: ABdhPJycfhPFg5bbwUTduKHFLzEO6lR4T04/yO4EIhenlTYHM/Sn81/7qUPvLRcp49310PEX0QmDUg== X-Received: by 2002:a2e:9d14:: with SMTP id t20mr2497425lji.391.1615897226664; Tue, 16 Mar 2021 05:20:26 -0700 (PDT) From: Roman Bogorodskiy To: libvir-list@redhat.com Subject: [PATCH v2] bhyve: add support Date: Tue, 16 Mar 2021 16:20:16 +0400 Message-Id: <20210316122016.31998-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.78 on 10.11.54.6 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.84 on 10.5.11.23 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 --- Changes from v1: - Fixed various leaks, - Re-implemented testing using opendir() mock. 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/bhyve_utils.h | 2 + src/bhyve/meson.build | 1 + tests/bhyvefirmwaredata/empty/.keepme | 0 .../three_firmwares/BHYVE_UEFI.fd | 0 .../three_firmwares/BHYVE_UEFI_CSM.fd | 0 .../three_firmwares/refind_x64.efi | 0 .../bhyvexml2argv-firmware-efi.args | 11 +++ .../bhyvexml2argv-firmware-efi.ldargs | 1 + .../bhyvexml2argv-firmware-efi.xml | 22 +++++ tests/bhyvexml2argvmock.c | 33 +++++++ tests/bhyvexml2argvtest.c | 52 ++++++++--- 17 files changed, 257 insertions(+), 12 deletions(-) create mode 100644 src/bhyve/bhyve_firmware.c create mode 100644 src/bhyve/bhyve_firmware.h create mode 100644 tests/bhyvefirmwaredata/empty/.keepme create mode 100644 tests/bhyvefirmwaredata/three_firmwares/BHYVE_UEFI.fd create mode 100644 tests/bhyvefirmwaredata/three_firmwares/BHYVE_UEFI_CSM.= fd create mode 100644 tests/bhyvefirmwaredata/three_firmwares/refind_x64.efi 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..2055f34288 --- /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; + g_autoptr(virBhyveDriverConfig) cfg =3D virBhyveDriverGetConfig(driver= ); + const char *firmware_dir =3D cfg->firmwareDir; + struct dirent *entry; + g_autofree char *matching_firmware =3D NULL; + g_autofree 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) > 0) { + while ((virDirRead(dir, &entry, firmware_dir)) > 0) { + if (g_str_has_prefix(entry->d_name, ".")) + continue; + + 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); + return -1; + } else { + matching_firmware =3D g_steal_pointer(&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); + + 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/bhyve_utils.h b/src/bhyve/bhyve_utils.h index f3e80b6121..3bf5ae5daf 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -43,6 +43,8 @@ struct _virBhyveDriverConfig { char *firmwareDir; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virBhyveDriverConfig, virObjectUnref); + struct _bhyveConn { virMutex lock; =20 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/bhyvefirmwaredata/empty/.keepme b/tests/bhyvefirmwaredat= a/empty/.keepme new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/bhyvefirmwaredata/three_firmwares/BHYVE_UEFI.fd b/tests/= bhyvefirmwaredata/three_firmwares/BHYVE_UEFI.fd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/bhyvefirmwaredata/three_firmwares/BHYVE_UEFI_CSM.fd b/te= sts/bhyvefirmwaredata/three_firmwares/BHYVE_UEFI_CSM.fd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/bhyvefirmwaredata/three_firmwares/refind_x64.efi b/tests= /bhyvefirmwaredata/three_firmwares/refind_x64.efi new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args b/test= s/bhyvexml2argvdata/bhyvexml2argv-firmware-efi.args new file mode 100644 index 0000000000..2f5aa4d783 --- /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,fakefirmwaredir/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/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index 25b97f5e04..af5e0fd4b9 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -1,13 +1,46 @@ #include =20 +#include + #include "viralloc.h" #include "virstring.h" #include "virnetdev.h" #include "virnetdevtap.h" +#include "virmock.h" #include "internal.h" =20 #define VIR_FROM_THIS VIR_FROM_BHYVE =20 +static DIR * (*real_opendir)(const char *name); + +static void +init_syms(void) +{ + VIR_MOCK_REAL_INIT(opendir); +} + +#define FAKEFIRMWAREDIR abs_srcdir "/bhyvefirmwaredata/three_firmwares" +#define FAKEFIRMWAREEMPTYDIR abs_srcdir "/bhyvefirmwaredata/empty" + +DIR * +opendir(const char *path) +{ + init_syms(); + + g_autofree char *path_override =3D NULL; + + if (STREQ(path, "fakefirmwaredir")) { + path_override =3D g_strdup(FAKEFIRMWAREDIR); + } else if (STREQ(path, "fakefirmwareemptydir")) { + path_override =3D g_strdup(FAKEFIRMWAREEMPTYDIR); + } + + if (!path_override) + path_override =3D g_strdup(path); + + return real_opendir(path_override); +} + void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN], virMacAddrPtr addr) { diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 197334f9c4..34e40a6438 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,8 +41,11 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(conn =3D virGetConnect())) goto out; =20 - if (!(vmdef =3D virDomainDefParseFile(xml, driver.xmlopt, - NULL, VIR_DOMAIN_DEF_PARSE_INACTIV= E))) { + if (!(vm =3D virDomainObjNew(driver.xmlopt))) + return -1; + + if (!(vm->def =3D virDomainDefParseFile(xml, driver.xmlopt, + NULL, VIR_DOMAIN_DEF_PARSE_INACT= IVE))) { if (flags & FLAG_EXPECT_PARSE_ERROR) { ret =3D 0; } else if (flags & FLAG_EXPECT_FAILURE) { @@ -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; } @@ -132,6 +147,8 @@ static int mymain(void) { int ret =3D 0; + g_autofree char *fakefirmwaredir =3D g_strdup("fakefirmwaredir"); + g_autofree char *fakefirmwareemptydir =3D g_strdup("fakefirmwareemptyd= ir"); =20 if ((driver.caps =3D virBhyveCapsBuild()) =3D=3D NULL) return EXIT_FAILURE; @@ -142,6 +159,10 @@ mymain(void) if (!(driver.remotePorts =3D virPortAllocatorRangeNew("display", 5900,= 65535))) return EXIT_FAILURE; =20 + if (!(driver.config =3D virBhyveDriverConfigNew())) + return EXIT_FAILURE; + + driver.config->firmwareDir =3D fakefirmwaredir; =20 # define DO_TEST_FULL(name, flags) \ do { \ @@ -162,6 +183,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 +233,9 @@ mymain(void) DO_TEST("sound"); DO_TEST("isa-controller"); DO_TEST_FAILURE("isa-multiple-controllers"); + DO_TEST("firmware-efi"); + driver.config->firmwareDir =3D fakefirmwareemptydir; + DO_TEST_PREPARE_ERROR("firmware-efi"); DO_TEST("fs-9p"); DO_TEST("fs-9p-readonly"); DO_TEST_FAILURE("fs-9p-unsupported-type"); @@ -267,6 +294,7 @@ mymain(void) 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