mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-03 02:15:23 +00:00
conf: Refactor virDomainHubDefFormat
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
1fb4c01a8e
commit
b6f32c9ec2
@ -26976,38 +26976,23 @@ virDomainHubDefFormat(virBufferPtr buf,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *type = virDomainHubTypeToString(def->type);
|
const char *type = virDomainHubTypeToString(def->type);
|
||||||
virBuffer childBuf = VIR_BUFFER_INITIALIZER;
|
VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
int ret = -1;
|
VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
virBufferSetChildIndent(&childBuf, buf);
|
virBufferSetChildIndent(&childBuf, buf);
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected hub type %d"), def->type);
|
_("unexpected hub type %d"), def->type);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
|
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virBufferCheckError(&childBuf) < 0)
|
virBufferAsprintf(&attrBuf, " type='%s'", type);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<hub type='%s'", type);
|
return virXMLFormatElement(buf, "hub", &attrBuf, &childBuf);
|
||||||
if (virBufferUse(&childBuf)) {
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
virBufferAddBuffer(buf, &childBuf);
|
|
||||||
virBufferAddLit(buf, "</hub>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virBufferFreeAndReset(&childBuf);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user