[libvirt] [PATCH 09/23] conf: Refactor virDomainHubDefFormat

Peter Krempa posted 23 patches 6 years, 11 months ago
[libvirt] [PATCH 09/23] conf: Refactor virDomainHubDefFormat
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 | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 83e11f603f..5d745f8bce 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26976,38 +26976,23 @@ virDomainHubDefFormat(virBufferPtr buf,
                       unsigned int flags)
 {
     const char *type = virDomainHubTypeToString(def->type);
-    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 (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected hub type %d"), def->type);
-        goto cleanup;
+        return -1;
     }

     if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
-        goto cleanup;
-
-    if (virBufferCheckError(&childBuf) < 0)
-        goto cleanup;
-
-    virBufferAsprintf(buf, "<hub type='%s'", type);
-    if (virBufferUse(&childBuf)) {
-        virBufferAddLit(buf, ">\n");
-        virBufferAddBuffer(buf, &childBuf);
-        virBufferAddLit(buf, "</hub>\n");
-    } else {
-        virBufferAddLit(buf, "/>\n");
-    }
-
-    ret = 0;
+        return -1;

- cleanup:
-    virBufferFreeAndReset(&childBuf);
+    virBufferAsprintf(&attrBuf, " type='%s'", type);

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


-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 09/23] conf: Refactor virDomainHubDefFormat
Posted by Ján Tomko 6 years, 11 months ago
On Wed, Mar 06, 2019 at 09:20:34AM +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 | 27 ++++++---------------------
> 1 file changed, 6 insertions(+), 21 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