On Wed, Nov 13, 2019 at 05:05:25PM +0100, Peter Krempa wrote:
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++) {
if (i == VIR_DOMAIN_CAPS_FEATURE_IOTHREADS) continue; or leave the iothreads feature stored separately (unless it's really okay to output the feature in two places)
+ qemuDomainCapsFeatureFormatSimple(&childBuf, + virDomainCapsFeatureTypeToString(i), + caps->features[i]); + } + virDomainCapsFeatureSEVFormat(&childBuf, caps->sev); virXMLFormatElement(buf, "features", NULL, &childBuf);
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list