[libvirt] [PATCH 05/23] conf: Refactor virDomainWatchdogDefFormat

Peter Krempa posted 23 patches 6 years, 11 months ago
[libvirt] [PATCH 05/23] conf: Refactor virDomainWatchdogDefFormat
Posted by Peter Krempa 6 years, 11 months ago
Use virXMLFormatElement to format the internals along with simplifying
cleanup code paths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fd3f19d6ce..ed480bcf8e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -25893,46 +25893,29 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
 {
     const char *model = virDomainWatchdogModelTypeToString(def->model);
     const char *action = virDomainWatchdogActionTypeToString(def->action);
-    virBuffer childBuf = VIR_BUFFER_INITIALIZER;
-    int ret = -1;
+    VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+    VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;

     virBufferSetChildIndent(&childBuf, buf);

     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected watchdog model %d"), def->model);
-        goto cleanup;
+        return -1;
     }

     if (!action) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected watchdog action %d"), def->action);
-        goto cleanup;
-    }
-
-    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");
+        return -1;
     }

-    ret = 0;
+    virBufferAsprintf(&attrBuf, " model='%s' action='%s'", model, action);

- cleanup:
-    virBufferFreeAndReset(&childBuf);
+    if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
+        return -1;

-    return ret;
+    return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf);
 }

 static int virDomainPanicDefFormat(virBufferPtr buf,
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 05/23] conf: Refactor virDomainWatchdogDefFormat
Posted by Ján Tomko 6 years, 11 months ago
On Wed, Mar 06, 2019 at 09:20:30AM +0100, Peter Krempa wrote:
>Use virXMLFormatElement to format the internals along with simplifying
>cleanup code paths.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 33 ++++++++-------------------------
> 1 file changed, 8 insertions(+), 25 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list