mirror of https://gitee.com/openkylin/libvirt.git
domaincaps: Store domain capability features in an array
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ae92101be4
commit
caa6dc3b31
|
@ -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;
|
||||
|
||||
|
@ -317,9 +326,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -612,10 +622,19 @@ virDomainCapsFormatFeatures(const virDomainCaps *caps,
|
|||
virBufferPtr buf)
|
||||
{
|
||||
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||
size_t i;
|
||||
|
||||
virDomainCapsFeatureGICFormat(&childBuf, &caps->gic);
|
||||
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;
|
||||
|
||||
qemuDomainCapsFeatureFormatSimple(&childBuf,
|
||||
virDomainCapsFeatureTypeToString(i),
|
||||
caps->features[i]);
|
||||
}
|
||||
|
||||
virDomainCapsFeatureSEVFormat(&childBuf, caps->sev);
|
||||
|
||||
virXMLFormatElement(buf, "features", NULL, &childBuf);
|
||||
|
@ -641,7 +660,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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue