mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-26 14:03:49 +03:00
conf: Refactor virDomainInputDefFormat
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
af993b172c
commit
1fb4c01a8e
@ -26244,9 +26244,9 @@ virDomainInputDefFormat(virBufferPtr buf,
|
|||||||
{
|
{
|
||||||
const char *type = virDomainInputTypeToString(def->type);
|
const char *type = virDomainInputTypeToString(def->type);
|
||||||
const char *bus = virDomainInputBusTypeToString(def->bus);
|
const char *bus = virDomainInputBusTypeToString(def->bus);
|
||||||
virBuffer childbuf = VIR_BUFFER_INITIALIZER;
|
VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
|
VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
|
||||||
int ret = -1;
|
VIR_AUTOCLEAN(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
/* don't format keyboard into migratable XML for backward compatibility */
|
/* don't format keyboard into migratable XML for backward compatibility */
|
||||||
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
|
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
|
||||||
@ -26258,16 +26258,15 @@ virDomainInputDefFormat(virBufferPtr buf,
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected input type %d"), def->type);
|
_("unexpected input type %d"), def->type);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!bus) {
|
if (!bus) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected input bus type %d"), def->bus);
|
_("unexpected input bus type %d"), def->bus);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<input type='%s' bus='%s'",
|
virBufferAsprintf(&attrBuf, " type='%s' bus='%s'", type, bus);
|
||||||
type, bus);
|
|
||||||
|
|
||||||
if (def->model) {
|
if (def->model) {
|
||||||
const char *model = virDomainInputModelTypeToString(def->model);
|
const char *model = virDomainInputModelTypeToString(def->model);
|
||||||
@ -26275,44 +26274,23 @@ virDomainInputDefFormat(virBufferPtr buf,
|
|||||||
if (!model) {
|
if (!model) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected input model %d"), def->model);
|
_("unexpected input model %d"), def->model);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(buf, " model='%s'", model);
|
virBufferAsprintf(&attrBuf, " model='%s'", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferSetChildIndent(&childbuf, buf);
|
virBufferSetChildIndent(&childBuf, buf);
|
||||||
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
|
virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
|
||||||
if (virBufferCheckError(&driverBuf) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virBufferUse(&driverBuf)) {
|
if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0)
|
||||||
virBufferAddLit(&childbuf, "<driver");
|
return -1;
|
||||||
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)
|
virBufferEscapeString(&childBuf, "<source evdev='%s'/>\n", def->source.evdev);
|
||||||
goto cleanup;
|
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (!virBufferUse(&childbuf)) {
|
return virXMLFormatElement(buf, "input", &attrBuf, &childBuf);
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
virBufferAddBuffer(buf, &childbuf);
|
|
||||||
virBufferAddLit(buf, "</input>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virBufferFreeAndReset(&childbuf);
|
|
||||||
virBufferFreeAndReset(&driverBuf);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user