domaincaps: Expose UEFI binary path, if it exists

Check to see if the UEFI binary mentioned in qemu.conf actually
exists, and if so expose it in domcapabilities like

<loader ...>
  <value>/path/to/ovmf</value>
</loader>

We introduce some generic domcaps infrastructure for handling
a dynamic list of string values, it may be of use for future bits.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik
2014-09-16 19:52:54 -04:00
parent 2b2e4a7acf
commit f05b6a918e
10 changed files with 140 additions and 17 deletions

View File

@@ -6,6 +6,8 @@
<vcpu max='255'/>
<os supported='yes'>
<loader supported='yes'>
<value>/foo/bar</value>
<value>/tmp/my_path</value>
<enum name='type'>
<value>rom</value>
<value>pflash</value>

View File

@@ -5,6 +5,7 @@
<arch>x86_64</arch>
<os supported='yes'>
<loader supported='yes'>
<value>/usr/share/OVMF/OVMF_CODE.fd</value>
<enum name='type'>
<value>rom</value>
<value>pflash</value>

View File

@@ -34,6 +34,27 @@ typedef int (*virDomainCapsFill)(virDomainCapsPtr domCaps,
#define SET_ALL_BITS(x) \
memset(&(x.values), 0xff, sizeof(x.values))
static int ATTRIBUTE_SENTINEL
fillStringValues(virDomainCapsStringValuesPtr values, ...)
{
int ret = 0;
va_list list;
const char *str;
va_start(list, values);
while ((str = va_arg(list, const char *))) {
if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0 ||
VIR_STRDUP(values->values[values->nvalues], str) < 0) {
ret = -1;
break;
}
values->nvalues++;
}
va_end(list);
return ret;
}
static int
fillAll(virDomainCapsPtr domCaps,
void *opaque ATTRIBUTE_UNUSED)
@@ -49,6 +70,11 @@ fillAll(virDomainCapsPtr domCaps,
loader->device.supported = true;
SET_ALL_BITS(loader->type);
SET_ALL_BITS(loader->readonly);
if (fillStringValues(&loader->values,
"/foo/bar",
"/tmp/my_path",
NULL) < 0)
return -1;
disk->device.supported = true;
SET_ALL_BITS(disk->diskDevice);
@@ -66,13 +92,21 @@ fillAll(virDomainCapsPtr domCaps,
#ifdef WITH_QEMU
# include "testutilsqemu.h"
struct fillQemuCapsData {
virQEMUCapsPtr qemuCaps;
virQEMUDriverConfigPtr cfg;
};
static int
fillQemuCaps(virDomainCapsPtr domCaps,
void *opaque)
{
virQEMUCapsPtr qemuCaps = (virQEMUCapsPtr) opaque;
struct fillQemuCapsData *data = (struct fillQemuCapsData *) opaque;
virQEMUCapsPtr qemuCaps = data->qemuCaps;
virQEMUDriverConfigPtr cfg = data->cfg;
if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps) < 0)
if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps, cfg) < 0)
return -1;
/* The function above tries to query host's KVM & VFIO capabilities by
@@ -97,7 +131,7 @@ buildVirDomainCaps(const char *emulatorbin,
virDomainCapsFill fillFunc,
void *opaque)
{
virDomainCapsPtr domCaps;
virDomainCapsPtr domCaps, ret = NULL;
if (!(domCaps = virDomainCapsNew(emulatorbin, machine, arch, type)))
goto cleanup;
@@ -107,8 +141,9 @@ buildVirDomainCaps(const char *emulatorbin,
domCaps = NULL;
}
ret = domCaps;
cleanup:
return domCaps;
return ret;
}
struct test_virDomainCapsFormatData {
@@ -182,13 +217,16 @@ mymain(void)
#ifdef WITH_QEMU
virQEMUDriverConfigPtr cfg = virQEMUDriverConfigNew(false);
# define DO_TEST_QEMU(Filename, QemuCapsFile, Emulatorbin, Machine, Arch, Type, ...) \
do { \
const char *capsPath = abs_srcdir "/qemucapabilitiesdata/" QemuCapsFile ".caps"; \
virQEMUCapsPtr qemuCaps = qemuTestParseCapabilities(capsPath); \
struct fillQemuCapsData fillData = {.qemuCaps = qemuCaps, .cfg = cfg}; \
struct test_virDomainCapsFormatData data = {.filename = Filename, \
.emulatorbin = Emulatorbin, .machine = Machine, .arch = Arch, \
.type = Type, .fillFunc = fillQemuCaps, .opaque = qemuCaps}; \
.type = Type, .fillFunc = fillQemuCaps, .opaque = &fillData}; \
if (!qemuCaps) { \
fprintf(stderr, "Unable to build qemu caps from %s\n", capsPath); \
ret = -1; \
@@ -199,6 +237,7 @@ mymain(void)
DO_TEST_QEMU("qemu_1.6.50-1", "caps_1.6.50-1", "/usr/bin/qemu-system-x86_64",
"pc-1.2", VIR_ARCH_X86_64, VIR_DOMAIN_VIRT_KVM);
virObjectUnref(cfg);
#endif /* WITH_QEMU */
return ret;