1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

conf: Turn virDomainDef.kvm_features into a struct

In future commits we will need to store not just an array of
VIR_TRISTATE_SWITCH_* but also an additional integer. Follow the
example of TCG and introduce a structure where both the array an
integer can live.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2021-12-14 10:24:30 +01:00
parent dacf616b78
commit a8e0f9c682
3 changed files with 23 additions and 12 deletions

View File

@ -3713,6 +3713,7 @@ void virDomainDefFree(virDomainDef *def)
g_free(def->emulator); g_free(def->emulator);
g_free(def->description); g_free(def->description);
g_free(def->title); g_free(def->title);
g_free(def->kvm_features);
g_free(def->hyperv_vendor_id); g_free(def->hyperv_vendor_id);
g_free(def->tcg_features); g_free(def->tcg_features);
@ -17532,7 +17533,9 @@ static int
virDomainFeaturesKVMDefParse(virDomainDef *def, virDomainFeaturesKVMDefParse(virDomainDef *def,
xmlNodePtr node) xmlNodePtr node)
{ {
def->features[VIR_DOMAIN_FEATURE_KVM] = VIR_TRISTATE_SWITCH_ON; g_autofree virDomainFeatureKVM *kvm = NULL;
kvm = g_new0(virDomainFeatureKVM, 1);
node = xmlFirstElementChild(node); node = xmlFirstElementChild(node);
while (node) { while (node) {
@ -17551,11 +17554,14 @@ virDomainFeaturesKVMDefParse(virDomainDef *def,
&value) < 0) &value) < 0)
return -1; return -1;
def->kvm_features[feature] = value; kvm->features[feature] = value;
node = xmlNextElementSibling(node); node = xmlNextElementSibling(node);
} }
def->features[VIR_DOMAIN_FEATURE_KVM] = VIR_TRISTATE_SWITCH_ON;
def->kvm_features = g_steal_pointer(&kvm);
return 0; return 0;
} }
@ -21803,13 +21809,13 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src,
case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_DEDICATED:
case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_POLLCONTROL:
case VIR_DOMAIN_KVM_PVIPI: case VIR_DOMAIN_KVM_PVIPI:
if (src->kvm_features[i] != dst->kvm_features[i]) { if (src->kvm_features->features[i] != dst->kvm_features->features[i]) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("State of KVM feature '%s' differs: " _("State of KVM feature '%s' differs: "
"source: '%s', destination: '%s'"), "source: '%s', destination: '%s'"),
virDomainKVMTypeToString(i), virDomainKVMTypeToString(i),
virTristateSwitchTypeToString(src->kvm_features[i]), virTristateSwitchTypeToString(src->kvm_features->features[i]),
virTristateSwitchTypeToString(dst->kvm_features[i])); virTristateSwitchTypeToString(dst->kvm_features->features[i]));
return false; return false;
} }
@ -27873,11 +27879,11 @@ virDomainDefFormatFeatures(virBuffer *buf,
case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_DEDICATED:
case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_POLLCONTROL:
case VIR_DOMAIN_KVM_PVIPI: case VIR_DOMAIN_KVM_PVIPI:
if (def->kvm_features[j]) if (def->kvm_features->features[j])
virBufferAsprintf(&childBuf, "<%s state='%s'/>\n", virBufferAsprintf(&childBuf, "<%s state='%s'/>\n",
virDomainKVMTypeToString(j), virDomainKVMTypeToString(j),
virTristateSwitchTypeToString( virTristateSwitchTypeToString(
def->kvm_features[j])); def->kvm_features->features[j]));
break; break;
case VIR_DOMAIN_KVM_LAST: case VIR_DOMAIN_KVM_LAST:

View File

@ -2263,6 +2263,11 @@ typedef enum {
VIR_ENUM_DECL(virDomainIBS); VIR_ENUM_DECL(virDomainIBS);
typedef struct _virDomainFeatureKVM virDomainFeatureKVM;
struct _virDomainFeatureKVM {
int features[VIR_DOMAIN_KVM_LAST];
};
typedef struct _virDomainFeatureTCG virDomainFeatureTCG; typedef struct _virDomainFeatureTCG virDomainFeatureTCG;
struct _virDomainFeatureTCG { struct _virDomainFeatureTCG {
unsigned long long tb_cache; /* Stored in KiB */ unsigned long long tb_cache; /* Stored in KiB */
@ -2819,7 +2824,7 @@ struct _virDomainDef {
int features[VIR_DOMAIN_FEATURE_LAST]; int features[VIR_DOMAIN_FEATURE_LAST];
int caps_features[VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST]; int caps_features[VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST];
int hyperv_features[VIR_DOMAIN_HYPERV_LAST]; int hyperv_features[VIR_DOMAIN_HYPERV_LAST];
int kvm_features[VIR_DOMAIN_KVM_LAST]; virDomainFeatureKVM *kvm_features;
int msrs_features[VIR_DOMAIN_MSRS_LAST]; int msrs_features[VIR_DOMAIN_MSRS_LAST];
int xen_features[VIR_DOMAIN_XEN_LAST]; int xen_features[VIR_DOMAIN_XEN_LAST];
virDomainXenPassthroughMode xen_passthrough_mode; virDomainXenPassthroughMode xen_passthrough_mode;

View File

@ -6765,22 +6765,22 @@ qemuBuildCpuCommandLine(virCommand *cmd,
for (i = 0; i < VIR_DOMAIN_KVM_LAST; i++) { for (i = 0; i < VIR_DOMAIN_KVM_LAST; i++) {
switch ((virDomainKVM) i) { switch ((virDomainKVM) i) {
case VIR_DOMAIN_KVM_HIDDEN: case VIR_DOMAIN_KVM_HIDDEN:
if (def->kvm_features[i] == VIR_TRISTATE_SWITCH_ON) if (def->kvm_features->features[i] == VIR_TRISTATE_SWITCH_ON)
virBufferAddLit(&buf, ",kvm=off"); virBufferAddLit(&buf, ",kvm=off");
break; break;
case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_DEDICATED:
if (def->kvm_features[i] == VIR_TRISTATE_SWITCH_ON) if (def->kvm_features->features[i] == VIR_TRISTATE_SWITCH_ON)
virBufferAddLit(&buf, ",kvm-hint-dedicated=on"); virBufferAddLit(&buf, ",kvm-hint-dedicated=on");
break; break;
case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_POLLCONTROL:
if (def->kvm_features[i] == VIR_TRISTATE_SWITCH_ON) if (def->kvm_features->features[i] == VIR_TRISTATE_SWITCH_ON)
virBufferAddLit(&buf, ",kvm-poll-control=on"); virBufferAddLit(&buf, ",kvm-poll-control=on");
break; break;
case VIR_DOMAIN_KVM_PVIPI: case VIR_DOMAIN_KVM_PVIPI:
if (def->kvm_features[i] == VIR_TRISTATE_SWITCH_OFF) if (def->kvm_features->features[i] == VIR_TRISTATE_SWITCH_OFF)
virBufferAddLit(&buf, ",kvm-pv-ipi=off"); virBufferAddLit(&buf, ",kvm-pv-ipi=off");
break; break;