Declare the capabilities as enum values and store them in an array. This makes adding new features more straightforward and simplifies the formatter which now doesn't require changing. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_capabilities.c | 30 +++++++++++++++++++++++------- src/conf/domain_capabilities.h | 13 ++++++++++--- src/qemu/qemu_capabilities.c | 6 +++--- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 39acad00f1..1993a22cc5 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -33,6 +33,15 @@ VIR_ENUM_IMPL(virDomainCapsCPUUsable, "unknown", "yes", "no", ); + +VIR_ENUM_DECL(virDomainCapsFeature); +VIR_ENUM_IMPL(virDomainCapsFeature, + VIR_DOMAIN_CAPS_FEATURE_LAST, + "iothreads", + "vmcoreinfo", + "genid", +); + static virClassPtr virDomainCapsClass; static virClassPtr virDomainCapsCPUModelsClass; @@ -324,9 +333,10 @@ virDomainCapsEnumClear(virDomainCapsEnumPtr capsEnum) void virDomainCapsFeaturesInitUnsupported(virDomainCapsPtr caps) { - caps->iothreads = VIR_TRISTATE_BOOL_NO; - caps->vmcoreinfo = VIR_TRISTATE_BOOL_NO; - caps->genid = VIR_TRISTATE_BOOL_NO; + size_t i; + + for (i = 0; i < VIR_DOMAIN_CAPS_FEATURE_LAST; i++) + caps->features[i] = VIR_TRISTATE_BOOL_NO; } @@ -619,11 +629,16 @@ virDomainCapsFormatFeatures(const virDomainCaps *caps, virBufferPtr buf) { g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + size_t i; virDomainCapsFeatureGICFormat(&childBuf, &caps->gic); - qemuDomainCapsFeatureFormatSimple(&childBuf, "iothreads", caps->iothreads); - qemuDomainCapsFeatureFormatSimple(&childBuf, "vmcoreinfo", caps->vmcoreinfo); - qemuDomainCapsFeatureFormatSimple(&childBuf, "genid", caps->genid); + + for (i = 0; i < VIR_DOMAIN_CAPS_FEATURE_LAST; i++) { + qemuDomainCapsFeatureFormatSimple(&childBuf, + virDomainCapsFeatureTypeToString(i), + caps->features[i]); + } + virDomainCapsFeatureSEVFormat(&childBuf, caps->sev); virXMLFormatElement(buf, "features", NULL, &childBuf); @@ -649,7 +664,8 @@ virDomainCapsFormat(const virDomainCaps *caps) if (caps->maxvcpus) virBufferAsprintf(&buf, "<vcpu max='%d'/>\n", caps->maxvcpus); - qemuDomainCapsFeatureFormatSimple(&buf, "iothreads", caps->iothreads); + qemuDomainCapsFeatureFormatSimple(&buf, "iothreads", + caps->features[VIR_DOMAIN_CAPS_FEATURE_IOTHREADS]); virDomainCapsOSFormat(&buf, &caps->os); virDomainCapsCPUFormat(&buf, &caps->cpu); diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index 9baaea8f60..83a9713a8b 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -156,6 +156,14 @@ struct _virSEVCapability { unsigned int reduced_phys_bits; }; +typedef enum { + VIR_DOMAIN_CAPS_FEATURE_IOTHREADS = 0, + VIR_DOMAIN_CAPS_FEATURE_VMCOREINFO, + VIR_DOMAIN_CAPS_FEATURE_GENID, + + VIR_DOMAIN_CAPS_FEATURE_LAST +} virDomainCapsFeature; + struct _virDomainCaps { virObjectLockable parent; @@ -166,7 +174,6 @@ struct _virDomainCaps { /* Some machine specific info */ int maxvcpus; - virTristateBool iothreads; /* Whether I/O threads are supported or not. */ virDomainCapsOS os; virDomainCapsCPU cpu; @@ -178,10 +185,10 @@ struct _virDomainCaps { /* add new domain devices here */ virDomainCapsFeatureGIC gic; - virTristateBool vmcoreinfo; - virTristateBool genid; virSEVCapabilityPtr sev; /* add new domain features here */ + + virTristateBool features[VIR_DOMAIN_CAPS_FEATURE_LAST]; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCaps, virObjectUnref); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 23a358bf91..a1fbf0da34 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5285,7 +5285,7 @@ static void virQEMUCapsFillDomainIOThreadCaps(virQEMUCapsPtr qemuCaps, virDomainCapsPtr domCaps) { - domCaps->iothreads = virTristateBoolFromBool( + domCaps->features[VIR_DOMAIN_CAPS_FEATURE_IOTHREADS] = virTristateBoolFromBool( virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_IOTHREAD)); } @@ -5584,10 +5584,10 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps, domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus); } - domCaps->vmcoreinfo = virTristateBoolFromBool( + domCaps->features[VIR_DOMAIN_CAPS_FEATURE_VMCOREINFO] = virTristateBoolFromBool( virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMCOREINFO)); - domCaps->genid = virTristateBoolFromBool( + domCaps->features[VIR_DOMAIN_CAPS_FEATURE_GENID] = virTristateBoolFromBool( virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMGENID)); if (virQEMUCapsFillDomainOSCaps(os, -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list