From ffd151d17be1d99794bcd972bcc568dc73c8bf64 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 30 Oct 2019 16:40:03 +0100 Subject: [PATCH] qemu: domcaps: Simplify adding new domaincaps based on qemu caps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper which converts qemu emulator capabilities to the domain capability XML. This will simplify future additions of new features. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_capabilities.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index dc86f28b12..033dd42541 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5281,12 +5281,32 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps, } +struct virQEMUCapsDomainFeatureCapabilityTuple { + virDomainCapsFeature domcap; + virQEMUCapsFlags qemucap; +}; + +/** + * This maps the qemu features to the entries in of the domain + * capability XML. + * */ +static const struct virQEMUCapsDomainFeatureCapabilityTuple domCapsTuples[] = { + { VIR_DOMAIN_CAPS_FEATURE_IOTHREADS, QEMU_CAPS_OBJECT_IOTHREAD }, + { VIR_DOMAIN_CAPS_FEATURE_VMCOREINFO, QEMU_CAPS_DEVICE_VMCOREINFO }, + { VIR_DOMAIN_CAPS_FEATURE_GENID, QEMU_CAPS_DEVICE_VMGENID }, +}; + + static void -virQEMUCapsFillDomainIOThreadCaps(virQEMUCapsPtr qemuCaps, - virDomainCapsPtr domCaps) +virQEMUCapsFillDomainFeaturesFromQEMUCaps(virQEMUCapsPtr qemuCaps, + virDomainCapsPtr domCaps) { - domCaps->features[VIR_DOMAIN_CAPS_FEATURE_IOTHREADS] = virTristateBoolFromBool( - virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_IOTHREAD)); + size_t i; + + for (i = 0; i < G_N_ELEMENTS(domCapsTuples); i++) { + if (virQEMUCapsGet(qemuCaps, domCapsTuples[i].qemucap)) + domCaps->features[domCapsTuples[i].domcap] = VIR_TRISTATE_BOOL_YES; + } } @@ -5572,6 +5592,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps, virDomainCapsDeviceRNGPtr rng = &domCaps->rng; virDomainCapsFeaturesInitUnsupported(domCaps); + virQEMUCapsFillDomainFeaturesFromQEMUCaps(qemuCaps, domCaps); domCaps->maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, domCaps->machine); @@ -5584,12 +5605,6 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps, domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus); } - domCaps->features[VIR_DOMAIN_CAPS_FEATURE_VMCOREINFO] = virTristateBoolFromBool( - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMCOREINFO)); - - domCaps->features[VIR_DOMAIN_CAPS_FEATURE_GENID] = virTristateBoolFromBool( - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMGENID)); - if (virQEMUCapsFillDomainOSCaps(os, domCaps->machine, domCaps->arch, @@ -5598,7 +5613,6 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps, return -1; virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps); - virQEMUCapsFillDomainIOThreadCaps(qemuCaps, domCaps); virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps, domCaps->machine, disk); virQEMUCapsFillDomainDeviceGraphicsCaps(qemuCaps, graphics); virQEMUCapsFillDomainDeviceVideoCaps(qemuCaps, video);