Blob Blame History Raw
From d1adb920ad7f460e32b1cc68e68120b3c655bc18 Mon Sep 17 00:00:00 2001
Message-Id: <d1adb920ad7f460e32b1cc68e68120b3c655bc18@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Thu, 1 Jun 2017 15:57:55 +0200
Subject: [PATCH] conf: Make virDomainSnapshotDefFormat easier to read

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 00968dca967f4bf9d4f496e5c971bff3f8147ed8)

https://bugzilla.redhat.com/show_bug.cgi?id=1441662

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/snapshot_conf.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index b6cba5ac38..7daa9b22ad 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -686,11 +686,13 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
     virBufferAddLit(buf, "</disk>\n");
 }
 
-char *virDomainSnapshotDefFormat(const char *domain_uuid,
-                                 virDomainSnapshotDefPtr def,
-                                 virCapsPtr caps,
-                                 unsigned int flags,
-                                 int internal)
+
+char *
+virDomainSnapshotDefFormat(const char *domain_uuid,
+                           virDomainSnapshotDefPtr def,
+                           virCapsPtr caps,
+                           unsigned int flags,
+                           int internal)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     size_t i;
@@ -702,12 +704,14 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
 
     virBufferAddLit(&buf, "<domainsnapshot>\n");
     virBufferAdjustIndent(&buf, 2);
+
     virBufferEscapeString(&buf, "<name>%s</name>\n", def->name);
     if (def->description)
         virBufferEscapeString(&buf, "<description>%s</description>\n",
                               def->description);
     virBufferAsprintf(&buf, "<state>%s</state>\n",
                       virDomainSnapshotStateTypeToString(def->state));
+
     if (def->parent) {
         virBufferAddLit(&buf, "<parent>\n");
         virBufferAdjustIndent(&buf, 2);
@@ -715,14 +719,17 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
         virBufferAdjustIndent(&buf, -2);
         virBufferAddLit(&buf, "</parent>\n");
     }
+
     virBufferAsprintf(&buf, "<creationTime>%lld</creationTime>\n",
                       def->creationTime);
+
     if (def->memory) {
         virBufferAsprintf(&buf, "<memory snapshot='%s'",
                           virDomainSnapshotLocationTypeToString(def->memory));
         virBufferEscapeString(&buf, " file='%s'", def->file);
         virBufferAddLit(&buf, "/>\n");
     }
+
     if (def->ndisks) {
         virBufferAddLit(&buf, "<disks>\n");
         virBufferAdjustIndent(&buf, 2);
@@ -731,11 +738,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
         virBufferAdjustIndent(&buf, -2);
         virBufferAddLit(&buf, "</disks>\n");
     }
+
     if (def->dom) {
-        if (virDomainDefFormatInternal(def->dom, caps, flags, &buf) < 0) {
-            virBufferFreeAndReset(&buf);
-            return NULL;
-        }
+        if (virDomainDefFormatInternal(def->dom, caps, flags, &buf) < 0)
+            goto error;
     } else if (domain_uuid) {
         virBufferAddLit(&buf, "<domain>\n");
         virBufferAdjustIndent(&buf, 2);
@@ -743,8 +749,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
         virBufferAdjustIndent(&buf, -2);
         virBufferAddLit(&buf, "</domain>\n");
     }
+
     if (internal)
         virBufferAsprintf(&buf, "<active>%d</active>\n", def->current);
+
     virBufferAdjustIndent(&buf, -2);
     virBufferAddLit(&buf, "</domainsnapshot>\n");
 
@@ -752,6 +760,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
         return NULL;
 
     return virBufferContentAndReset(&buf);
+
+ error:
+    virBufferFreeAndReset(&buf);
+    return NULL;
 }
 
 /* Snapshot Obj functions */
-- 
2.13.1