From d1adb920ad7f460e32b1cc68e68120b3c655bc18 Mon Sep 17 00:00:00 2001 Message-Id: From: Jiri Denemark Date: Thu, 1 Jun 2017 15:57:55 +0200 Subject: [PATCH] conf: Make virDomainSnapshotDefFormat easier to read Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina (cherry picked from commit 00968dca967f4bf9d4f496e5c971bff3f8147ed8) https://bugzilla.redhat.com/show_bug.cgi?id=1441662 Signed-off-by: Jiri Denemark --- 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, "\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, "\n"); virBufferAdjustIndent(&buf, 2); + virBufferEscapeString(&buf, "%s\n", def->name); if (def->description) virBufferEscapeString(&buf, "%s\n", def->description); virBufferAsprintf(&buf, "%s\n", virDomainSnapshotStateTypeToString(def->state)); + if (def->parent) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -715,14 +719,17 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } + virBufferAsprintf(&buf, "%lld\n", def->creationTime); + if (def->memory) { virBufferAsprintf(&buf, "memory)); virBufferEscapeString(&buf, " file='%s'", def->file); virBufferAddLit(&buf, "/>\n"); } + if (def->ndisks) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -731,11 +738,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\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, "\n"); virBufferAdjustIndent(&buf, 2); @@ -743,8 +749,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } + if (internal) virBufferAsprintf(&buf, "%d\n", def->current); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\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