Use virXMLFormatElement to format the internals along with simplifying
cleanup code paths.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 54 +++++++++++++-----------------------------
1 file changed, 16 insertions(+), 38 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 71e0c8679b..83e11f603f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26244,9 +26244,9 @@ virDomainInputDefFormat(virBufferPtr buf,
{
const char *type = virDomainInputTypeToString(def->type);
const char *bus = virDomainInputBusTypeToString(def->bus);
- virBuffer childbuf = VIR_BUFFER_INITIALIZER;
- virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
- int ret = -1;
+ VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+ VIR_AUTOCLEAN(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
/* don't format keyboard into migratable XML for backward compatibility */
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
@@ -26258,16 +26258,15 @@ virDomainInputDefFormat(virBufferPtr buf,
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected input type %d"), def->type);
- goto cleanup;
+ return -1;
}
if (!bus) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected input bus type %d"), def->bus);
- goto cleanup;
+ return -1;
}
- virBufferAsprintf(buf, "<input type='%s' bus='%s'",
- type, bus);
+ virBufferAsprintf(&attrBuf, " type='%s' bus='%s'",
type, bus);
if (def->model) {
const char *model = virDomainInputModelTypeToString(def->model);
@@ -26275,44 +26274,23 @@ virDomainInputDefFormat(virBufferPtr buf,
if (!model) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected input model %d"), def->model);
- goto cleanup;
+ return -1;
}
- virBufferAsprintf(buf, " model='%s'", model);
+ virBufferAsprintf(&attrBuf, " model='%s'", model);
}
- virBufferSetChildIndent(&childbuf, buf);
- virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
- if (virBufferCheckError(&driverBuf) < 0)
- goto cleanup;
-
- if (virBufferUse(&driverBuf)) {
- virBufferAddLit(&childbuf, "<driver");
- virBufferAddBuffer(&childbuf, &driverBuf);
- virBufferAddLit(&childbuf, "/>\n");
- }
- virBufferEscapeString(&childbuf, "<source
evdev='%s'/>\n", def->source.evdev);
- if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0)
- goto cleanup;
-
- if (virBufferCheckError(&childbuf) < 0)
- goto cleanup;
-
- if (!virBufferUse(&childbuf)) {
- virBufferAddLit(buf, "/>\n");
- } else {
- virBufferAddLit(buf, ">\n");
- virBufferAddBuffer(buf, &childbuf);
- virBufferAddLit(buf, "</input>\n");
- }
+ virBufferSetChildIndent(&childBuf, buf);
+ virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
- ret = 0;
+ if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL)
< 0)
+ return -1;
- cleanup:
- virBufferFreeAndReset(&childbuf);
- virBufferFreeAndReset(&driverBuf);
+ virBufferEscapeString(&childBuf, "<source
evdev='%s'/>\n", def->source.evdev);
+ if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
+ return -1;
- return ret;
+ return virXMLFormatElement(buf, "input", &attrBuf, &childBuf);
}
--
2.20.1