提交 1fb4c01a 编写于 作者: P Peter Krempa

conf: Refactor virDomainInputDefFormat

Use virXMLFormatElement to format the internals along with simplifying
cleanup code paths.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 af993b17
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册