mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
conf: Refactor virDomainMemballoonDefFormat
Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
6b8a31e26c
commit
afc47b7785
@ -25837,19 +25837,20 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *model = virDomainMemballoonModelTypeToString(def->model);
|
const char *model = virDomainMemballoonModelTypeToString(def->model);
|
||||||
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
|
VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
int ret = -1;
|
VIR_AUTOCLEAN(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
VIR_AUTOCLEAN(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
if (!model) {
|
if (!model) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected memballoon model %d"), def->model);
|
_("unexpected memballoon model %d"), def->model);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<memballoon model='%s'", model);
|
virBufferAsprintf(&attrBuf, " model='%s'", model);
|
||||||
|
|
||||||
if (def->autodeflate != VIR_TRISTATE_SWITCH_ABSENT)
|
if (def->autodeflate != VIR_TRISTATE_SWITCH_ABSENT)
|
||||||
virBufferAsprintf(buf, " autodeflate='%s'",
|
virBufferAsprintf(&attrBuf, " autodeflate='%s'",
|
||||||
virTristateSwitchTypeToString(def->autodeflate));
|
virTristateSwitchTypeToString(def->autodeflate));
|
||||||
|
|
||||||
virBufferSetChildIndent(&childrenBuf, buf);
|
virBufferSetChildIndent(&childrenBuf, buf);
|
||||||
@ -25858,40 +25859,14 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
|
|||||||
virBufferAsprintf(&childrenBuf, "<stats period='%i'/>\n", def->period);
|
virBufferAsprintf(&childrenBuf, "<stats period='%i'/>\n", def->period);
|
||||||
|
|
||||||
if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0)
|
if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (def->virtio) {
|
virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
|
||||||
virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
|
|
||||||
|
|
||||||
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
|
if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (virBufferCheckError(&driverBuf) < 0)
|
return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virBufferUse(&driverBuf)) {
|
|
||||||
virBufferAddLit(&childrenBuf, "<driver");
|
|
||||||
virBufferAddBuffer(&childrenBuf, &driverBuf);
|
|
||||||
virBufferAddLit(&childrenBuf, "/>\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virBufferCheckError(&childrenBuf) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!virBufferUse(&childrenBuf)) {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
virBufferAddBuffer(buf, &childrenBuf);
|
|
||||||
virBufferAddLit(buf, "</memballoon>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virBufferFreeAndReset(&childrenBuf);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user