Re: [libvirt] [PATCH 3/5] qemu_firmware: Extend qemuFirmwareGetSupported to return FW paths

2019-09-11 Thread Cole Robinson
On 8/5/19 12:14 PM, Michal Privoznik wrote:
> The qemuFirmwareGetSupported() function is called from qemu
> driver to generate domain capabilities XML based on FW descriptor
> files. However, the function currently reports only some features
> from domcapabilities XML and not actual FW image paths. The paths
> reported in the domcapabilities XML still from from pre-FW

s/still from from/are still from/

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/5] qemu_firmware: Extend qemuFirmwareGetSupported to return FW paths

2019-08-05 Thread Michal Privoznik
The qemuFirmwareGetSupported() function is called from qemu
driver to generate domain capabilities XML based on FW descriptor
files. However, the function currently reports only some features
from domcapabilities XML and not actual FW image paths. The paths
reported in the domcapabilities XML still from from pre-FW
descriptor era and therefore the XML might be a bit confusing.
For instance, it may say that secure boot is supported but
secboot enabled FW is not in the listed FW image paths.

To resolve this problem, change qemuFirmwareGetSupported() so
that it also returns a list of FW images (we have the list
anyway). Luckily, we already have a structure to represent a FW
image - virFirmware.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1733940

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_capabilities.c |  3 +-
 src/qemu/qemu_firmware.c | 62 +++-
 src/qemu/qemu_firmware.h |  5 ++-
 tests/qemufirmwaretest.c |  2 +-
 4 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2388f145af..db1fc31cd9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -5165,7 +5165,8 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os,
 os->supported = VIR_TRISTATE_BOOL_YES;
 os->firmware.report = true;
 
-if (qemuFirmwareGetSupported(machine, arch, privileged, &autoFirmwares, 
&secure) < 0)
+if (qemuFirmwareGetSupported(machine, arch, privileged,
+ &autoFirmwares, &secure, NULL, NULL) < 0)
 return -1;
 
 if (autoFirmwares & (1ULL << VIR_DOMAIN_OS_DEF_FIRMWARE_BIOS))
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index 8fbe8952ba..9ba38477cc 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -1420,6 +1420,8 @@ qemuFirmwareFillDomain(virQEMUDriverPtr driver,
  * @privileged: whether running as privileged user
  * @supported: returned bitmap of supported interfaces
  * @secure: true if at least one secure boot enabled FW was found
+ * @fws: (optional) list of found firmwares
+ * @nfws: (optional) number of members in @fws
  *
  * Parse all FW descriptors (depending whether running as @privileged this may
  * or may not include user's $HOME) and for given combination of @machine and
@@ -1429,6 +1431,15 @@ qemuFirmwareFillDomain(virQEMUDriverPtr driver,
  * FW descriptor signalizes secure boot (although, this is checked against SMM
  * rather than SECURE_BOOT because reasons).
  *
+ * If @fws and @nfws are not NULL, then @fws is allocated (must be freed by
+ * caller when no longer needed) and contains list of firmwares found in form
+ * of virFirmware. This can be useful if caller wants to know the paths to
+ * firmware images (e.g. to present them in domain capabilities XML).
+ * Moreover, to allow the caller distinguish between no FW descriptors found
+ * and no matching FW descriptors found (nfws == 0 in both cases), the @fws is
+ * going to be allocated in case of the latter anyway (with no real content
+ * though).
+ *
  * Returns: 0 on success,
  * -1 otherwise.
  */
@@ -1437,7 +1448,9 @@ qemuFirmwareGetSupported(const char *machine,
  virArch arch,
  bool privileged,
  uint64_t *supported,
- bool *secure)
+ bool *secure,
+ virFirmwarePtr **fws,
+ size_t *nfws)
 {
 qemuFirmwarePtr *firmwares = NULL;
 ssize_t nfirmwares = 0;
@@ -1446,12 +1459,21 @@ qemuFirmwareGetSupported(const char *machine,
 *supported = VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
 *secure = false;
 
+if (fws) {
+*fws = NULL;
+*nfws = 0;
+}
+
 if ((nfirmwares = qemuFirmwareFetchParsedConfigs(privileged,
  &firmwares, NULL)) < 0)
 return -1;
 
 for (i = 0; i < nfirmwares; i++) {
 qemuFirmwarePtr fw = firmwares[i];
+const qemuFirmwareMappingFlash *flash = &fw->mapping.data.flash;
+const qemuFirmwareMappingMemory *memory = &fw->mapping.data.memory;
+const char *fwpath = NULL;
+const char *nvrampath = NULL;
 size_t j;
 
 if (!qemuFirmwareMatchesMachineArch(fw, machine, arch))
@@ -1491,8 +1513,46 @@ qemuFirmwareGetSupported(const char *machine,
 break;
 }
 }
+
+switch (fw->mapping.device) {
+case QEMU_FIRMWARE_DEVICE_FLASH:
+fwpath = flash->executable.filename;
+nvrampath = flash->nvram_template.filename;
+break;
+
+case QEMU_FIRMWARE_DEVICE_MEMORY:
+fwpath = memory->filename;
+break;
+
+case QEMU_FIRMWARE_DEVICE_KERNEL:
+case QEMU_FIRMWARE_DEVICE_NONE:
+case QEMU_FIRMWARE_DEVICE_LAST:
+break;
+}
+
+if (fws && fwp