提交 4a08acd7 编写于 作者: P Peter Krempa

conf: Refactor virDomainWatchdogDefFormat

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>
上级 afc47b77
...@@ -25893,46 +25893,29 @@ virDomainWatchdogDefFormat(virBufferPtr buf, ...@@ -25893,46 +25893,29 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
{ {
const char *model = virDomainWatchdogModelTypeToString(def->model); const char *model = virDomainWatchdogModelTypeToString(def->model);
const char *action = virDomainWatchdogActionTypeToString(def->action); const char *action = virDomainWatchdogActionTypeToString(def->action);
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 (!model) { if (!model) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected watchdog model %d"), def->model); _("unexpected watchdog model %d"), def->model);
goto cleanup; return -1;
} }
if (!action) { if (!action) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected watchdog action %d"), def->action); _("unexpected watchdog action %d"), def->action);
goto cleanup; return -1;
}
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
goto cleanup;
if (virBufferCheckError(&childBuf) < 0)
goto cleanup;
virBufferAsprintf(buf, "<watchdog model='%s' action='%s'",
model, action);
if (virBufferUse(&childBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childBuf);
virBufferAddLit(buf, "</watchdog>\n");
} else {
virBufferAddLit(buf, "/>\n");
} }
ret = 0; virBufferAsprintf(&attrBuf, " model='%s' action='%s'", model, action);
cleanup: if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
virBufferFreeAndReset(&childBuf); return -1;
return ret; return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf);
} }
static int virDomainPanicDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册