From afc47b77856cd5a8ef989f7e4f2f9651e0b20d7f Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 5 Mar 2019 10:17:31 +0100 Subject: [PATCH] conf: Refactor virDomainMemballoonDefFormat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 47 ++++++++++-------------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cbefa7749b..fd3f19d6ce 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25837,19 +25837,20 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); - virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; - int ret = -1; + VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected memballoon model %d"), def->model); - goto cleanup; + return -1; } - virBufferAsprintf(buf, "autodeflate != VIR_TRISTATE_SWITCH_ABSENT) - virBufferAsprintf(buf, " autodeflate='%s'", + virBufferAsprintf(&attrBuf, " autodeflate='%s'", virTristateSwitchTypeToString(def->autodeflate)); virBufferSetChildIndent(&childrenBuf, buf); @@ -25858,40 +25859,14 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAsprintf(&childrenBuf, "\n", def->period); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) - goto cleanup; + return -1; - if (def->virtio) { - virBuffer driverBuf = VIR_BUFFER_INITIALIZER; + virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - virDomainVirtioOptionsFormat(&driverBuf, def->virtio); + if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) < 0) + return -1; - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; - - if (virBufferUse(&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, "\n"); - } - - ret = 0; - - cleanup: - virBufferFreeAndReset(&childrenBuf); - - return ret; + return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf); } static int