mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 06:47:45 +00:00
conf: refactor hyperv features formatting
Add a nested buffer for whatever sub-elements a particular hyperv feature might have. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
91bb41a8b7
commit
ad6b4d1fef
@ -27954,13 +27954,15 @@ virDomainDefFormatFeatures(virBuffer *buf,
|
|||||||
|
|
||||||
virBufferAsprintf(&childBuf, "<hyperv mode='%s'>\n",
|
virBufferAsprintf(&childBuf, "<hyperv mode='%s'>\n",
|
||||||
virDomainHyperVModeTypeToString(def->features[i]));
|
virDomainHyperVModeTypeToString(def->features[i]));
|
||||||
virBufferAdjustIndent(&childBuf, 2);
|
|
||||||
for (j = 0; j < VIR_DOMAIN_HYPERV_LAST; j++) {
|
for (j = 0; j < VIR_DOMAIN_HYPERV_LAST; j++) {
|
||||||
|
g_auto(virBuffer) hypervAttrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
g_auto(virBuffer) hypervChildBuf = VIR_BUFFER_INIT_CHILD(&tmpChildBuf);
|
||||||
|
|
||||||
if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ABSENT)
|
if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ABSENT)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
virBufferAsprintf(&childBuf, "<%s state='%s'",
|
virBufferAsprintf(&hypervAttrBuf, " state='%s'",
|
||||||
virDomainHypervTypeToString(j),
|
|
||||||
virTristateSwitchTypeToString(def->hyperv_features[j]));
|
virTristateSwitchTypeToString(def->hyperv_features[j]));
|
||||||
|
|
||||||
switch ((virDomainHyperv) j) {
|
switch ((virDomainHyperv) j) {
|
||||||
@ -27978,49 +27980,39 @@ virDomainDefFormatFeatures(virBuffer *buf,
|
|||||||
case VIR_DOMAIN_HYPERV_AVIC:
|
case VIR_DOMAIN_HYPERV_AVIC:
|
||||||
case VIR_DOMAIN_HYPERV_EMSR_BITMAP:
|
case VIR_DOMAIN_HYPERV_EMSR_BITMAP:
|
||||||
case VIR_DOMAIN_HYPERV_XMM_INPUT:
|
case VIR_DOMAIN_HYPERV_XMM_INPUT:
|
||||||
virBufferAddLit(&childBuf, "/>\n");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_HYPERV_SPINLOCKS:
|
case VIR_DOMAIN_HYPERV_SPINLOCKS:
|
||||||
if (def->hyperv_features[j] != VIR_TRISTATE_SWITCH_ON) {
|
if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ON) {
|
||||||
virBufferAddLit(&childBuf, "/>\n");
|
virBufferAsprintf(&hypervAttrBuf,
|
||||||
break;
|
" retries='%d'", def->hyperv_spinlocks);
|
||||||
}
|
}
|
||||||
virBufferAsprintf(&childBuf, " retries='%d'/>\n",
|
|
||||||
def->hyperv_spinlocks);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_HYPERV_STIMER:
|
case VIR_DOMAIN_HYPERV_STIMER:
|
||||||
if (def->hyperv_features[j] != VIR_TRISTATE_SWITCH_ON) {
|
if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ON &&
|
||||||
virBufferAddLit(&childBuf, "/>\n");
|
def->hyperv_stimer_direct == VIR_TRISTATE_SWITCH_ON) {
|
||||||
break;
|
virBufferAddLit(&hypervChildBuf, "<direct state='on'/>\n");
|
||||||
}
|
|
||||||
if (def->hyperv_stimer_direct == VIR_TRISTATE_SWITCH_ON) {
|
|
||||||
virBufferAddLit(&childBuf, ">\n");
|
|
||||||
virBufferAdjustIndent(&childBuf, 2);
|
|
||||||
virBufferAddLit(&childBuf, "<direct state='on'/>\n");
|
|
||||||
virBufferAdjustIndent(&childBuf, -2);
|
|
||||||
virBufferAddLit(&childBuf, "</stimer>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(&childBuf, "/>\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_HYPERV_VENDOR_ID:
|
case VIR_DOMAIN_HYPERV_VENDOR_ID:
|
||||||
if (def->hyperv_features[j] != VIR_TRISTATE_SWITCH_ON) {
|
if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ON) {
|
||||||
virBufferAddLit(&childBuf, "/>\n");
|
virBufferEscapeString(&hypervAttrBuf, " value='%s'",
|
||||||
break;
|
def->hyperv_vendor_id);
|
||||||
}
|
}
|
||||||
virBufferEscapeString(&childBuf, " value='%s'/>\n",
|
|
||||||
def->hyperv_vendor_id);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_HYPERV_LAST:
|
case VIR_DOMAIN_HYPERV_LAST:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virXMLFormatElement(&tmpChildBuf, virDomainHypervTypeToString(j),
|
||||||
|
&hypervAttrBuf, &hypervChildBuf);
|
||||||
}
|
}
|
||||||
virBufferAdjustIndent(&childBuf, -2);
|
|
||||||
|
virBufferAddBuffer(&childBuf, &tmpChildBuf);
|
||||||
virBufferAddLit(&childBuf, "</hyperv>\n");
|
virBufferAddLit(&childBuf, "</hyperv>\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user