Split out an internal helper that produces format into a
virBuffer, similar to what domain_conf.c does, and making
the next patch easier to write.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/conf/snapshot_conf.c | 103 ++++++++++++++++++++++-----------------
1 file changed, 59 insertions(+), 44 deletions(-)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 652d963f84..5cb977336a 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -700,92 +700,107 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
}
-char *
-virDomainSnapshotDefFormat(const char *uuidstr,
- virDomainSnapshotDefPtr def,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- unsigned int flags)
+static int
+virDomainSnapshotDefFormatInternal(virBufferPtr buf,
+ const char *uuidstr,
+ virDomainSnapshotDefPtr def,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ unsigned int flags)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t i;
int domainflags = VIR_DOMAIN_DEF_FORMAT_INACTIVE;
- virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
- VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL, NULL);
-
if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE)
domainflags |= VIR_DOMAIN_DEF_FORMAT_SECURE;
- virBufferAddLit(&buf, "<domainsnapshot>\n");
- virBufferAdjustIndent(&buf, 2);
+ virBufferAddLit(buf, "<domainsnapshot>\n");
+ virBufferAdjustIndent(buf, 2);
- virBufferEscapeString(&buf, "<name>%s</name>\n",
def->name);
+ virBufferEscapeString(buf, "<name>%s</name>\n", def->name);
if (def->description)
- virBufferEscapeString(&buf,
"<description>%s</description>\n",
+ virBufferEscapeString(buf,
"<description>%s</description>\n",
def->description);
- virBufferAsprintf(&buf, "<state>%s</state>\n",
+ virBufferAsprintf(buf, "<state>%s</state>\n",
virDomainSnapshotStateTypeToString(def->state));
if (def->parent) {
- virBufferAddLit(&buf, "<parent>\n");
- virBufferAdjustIndent(&buf, 2);
- virBufferEscapeString(&buf, "<name>%s</name>\n",
def->parent);
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "</parent>\n");
+ virBufferAddLit(buf, "<parent>\n");
+ virBufferAdjustIndent(buf, 2);
+ virBufferEscapeString(buf, "<name>%s</name>\n",
def->parent);
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "</parent>\n");
}
- virBufferAsprintf(&buf,
"<creationTime>%lld</creationTime>\n",
+ virBufferAsprintf(buf, "<creationTime>%lld</creationTime>\n",
def->creationTime);
if (def->memory) {
- virBufferAsprintf(&buf, "<memory snapshot='%s'",
+ virBufferAsprintf(buf, "<memory snapshot='%s'",
virDomainSnapshotLocationTypeToString(def->memory));
- virBufferEscapeString(&buf, " file='%s'", def->file);
- virBufferAddLit(&buf, "/>\n");
+ virBufferEscapeString(buf, " file='%s'", def->file);
+ virBufferAddLit(buf, "/>\n");
}
if (def->ndisks) {
- virBufferAddLit(&buf, "<disks>\n");
- virBufferAdjustIndent(&buf, 2);
+ virBufferAddLit(buf, "<disks>\n");
+ virBufferAdjustIndent(buf, 2);
for (i = 0; i < def->ndisks; i++) {
- if (virDomainSnapshotDiskDefFormat(&buf, &def->disks[i], xmlopt)
< 0)
+ if (virDomainSnapshotDiskDefFormat(buf, &def->disks[i], xmlopt) <
0)
goto error;
}
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "</disks>\n");
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "</disks>\n");
}
if (def->dom) {
- if (virDomainDefFormatInternal(def->dom, caps, domainflags, &buf,
+ if (virDomainDefFormatInternal(def->dom, caps, domainflags, buf,
xmlopt) < 0)
goto error;
} else if (uuidstr) {
- virBufferAddLit(&buf, "<domain>\n");
- virBufferAdjustIndent(&buf, 2);
- virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuidstr);
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "</domain>\n");
+ virBufferAddLit(buf, "<domain>\n");
+ virBufferAdjustIndent(buf, 2);
+ virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr);
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "</domain>\n");
}
- if (virSaveCookieFormatBuf(&buf, def->cookie,
+ if (virSaveCookieFormatBuf(buf, def->cookie,
virDomainXMLOptionGetSaveCookie(xmlopt)) < 0)
goto error;
if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL)
- virBufferAsprintf(&buf, "<active>%d</active>\n",
def->current);
+ virBufferAsprintf(buf, "<active>%d</active>\n",
def->current);
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "</domainsnapshot>\n");
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "</domainsnapshot>\n");
- if (virBufferCheckError(&buf) < 0)
- return NULL;
+ if (virBufferCheckError(buf) < 0)
+ goto error;
- return virBufferContentAndReset(&buf);
+ return 0;
error:
- virBufferFreeAndReset(&buf);
- return NULL;
+ virBufferFreeAndReset(buf);
+ return -1;
+}
+
+char *
+virDomainSnapshotDefFormat(const char *uuidstr,
+ virDomainSnapshotDefPtr def,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ unsigned int flags)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
+ VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL, NULL);
+ if (virDomainSnapshotDefFormatInternal(&buf, uuidstr, def, caps,
+ xmlopt, flags) < 0)
+ return NULL;
+
+ return virBufferContentAndReset(&buf);
}
/* Snapshot Obj functions */
--
2.20.1