mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 06:35:24 +00:00
virDomainControllerDefFormatPCI: Refactor formatting of '<target>' subelement
Rewrite the code to use virXMLFormat element so that we can avoid a bunch of unnecessary checks. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
66728854d1
commit
f9da823afe
@ -22676,6 +22676,8 @@ virDomainControllerDefFormatPCI(virBuffer *buf,
|
|||||||
virDomainControllerDef *def,
|
virDomainControllerDef *def,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
g_auto(virBuffer) targetAttrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
g_auto(virBuffer) targetChildBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
bool formatModelName = true;
|
bool formatModelName = true;
|
||||||
|
|
||||||
if (def->opts.pciopts.modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
|
if (def->opts.pciopts.modelName == VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
|
||||||
@ -22710,45 +22712,25 @@ virDomainControllerDefFormatPCI(virBuffer *buf,
|
|||||||
virBufferAsprintf(buf, "<model name='%s'/>\n", modelName);
|
virBufferAsprintf(buf, "<model name='%s'/>\n", modelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->opts.pciopts.chassisNr != -1 ||
|
if (def->opts.pciopts.chassisNr != -1)
|
||||||
def->opts.pciopts.chassis != -1 ||
|
virBufferAsprintf(&targetAttrBuf, " chassisNr='%d'", def->opts.pciopts.chassisNr);
|
||||||
def->opts.pciopts.port != -1 ||
|
if (def->opts.pciopts.chassis != -1)
|
||||||
def->opts.pciopts.busNr != -1 ||
|
virBufferAsprintf(&targetAttrBuf, " chassis='%d'", def->opts.pciopts.chassis);
|
||||||
def->opts.pciopts.targetIndex != -1 ||
|
if (def->opts.pciopts.port != -1)
|
||||||
def->opts.pciopts.numaNode != -1 ||
|
virBufferAsprintf(&targetAttrBuf, " port='0x%x'", def->opts.pciopts.port);
|
||||||
def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
|
if (def->opts.pciopts.busNr != -1)
|
||||||
virBufferAddLit(buf, "<target");
|
virBufferAsprintf(&targetAttrBuf, " busNr='%d'", def->opts.pciopts.busNr);
|
||||||
if (def->opts.pciopts.chassisNr != -1)
|
if (def->opts.pciopts.targetIndex != -1)
|
||||||
virBufferAsprintf(buf, " chassisNr='%d'",
|
virBufferAsprintf(&targetAttrBuf, " index='%d'", def->opts.pciopts.targetIndex);
|
||||||
def->opts.pciopts.chassisNr);
|
if (def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
|
||||||
if (def->opts.pciopts.chassis != -1)
|
virBufferAsprintf(&targetAttrBuf, " hotplug='%s'",
|
||||||
virBufferAsprintf(buf, " chassis='%d'",
|
virTristateSwitchTypeToString(def->opts.pciopts.hotplug));
|
||||||
def->opts.pciopts.chassis);
|
|
||||||
if (def->opts.pciopts.port != -1)
|
|
||||||
virBufferAsprintf(buf, " port='0x%x'",
|
|
||||||
def->opts.pciopts.port);
|
|
||||||
if (def->opts.pciopts.busNr != -1)
|
|
||||||
virBufferAsprintf(buf, " busNr='%d'",
|
|
||||||
def->opts.pciopts.busNr);
|
|
||||||
if (def->opts.pciopts.targetIndex != -1)
|
|
||||||
virBufferAsprintf(buf, " index='%d'",
|
|
||||||
def->opts.pciopts.targetIndex);
|
|
||||||
if (def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
|
|
||||||
virBufferAsprintf(buf, " hotplug='%s'",
|
|
||||||
virTristateSwitchTypeToString(def->opts.pciopts.hotplug));
|
|
||||||
}
|
|
||||||
if (def->opts.pciopts.numaNode == -1) {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
virBufferAdjustIndent(buf, 2);
|
|
||||||
virBufferAsprintf(buf, "<node>%d</node>\n",
|
|
||||||
def->opts.pciopts.numaNode);
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
|
||||||
virBufferAddLit(buf, "</target>\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (def->opts.pciopts.numaNode != -1)
|
||||||
|
virBufferAsprintf(&targetChildBuf, "<node>%d</node>\n", def->opts.pciopts.numaNode);
|
||||||
|
|
||||||
|
virXMLFormatElement(buf, "target", &targetAttrBuf, &targetChildBuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user