/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*,
* whereas the public version cannot. Also, it appends to an existing
- * buffer, rather than flattening to string. Return -1 on failure. */
-static int
+ * buffer (possibly with auto-indent), rather than flattening to string.
+ * Return -1 on failure. */
+int
virDomainDefFormatInternal(virDomainDefPtr def,
unsigned int flags,
virBufferPtr buf)
{
- /* XXX Also need to take an indentation parameter - either int or
- * string prefix, so that snapshot xml gets uniform indentation. */
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
const char *type = NULL;
((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0)
goto error;
+ virBufferAdjustIndent(&buf, 2);
if (virDomainDefFormatInternal(obj->def, flags, &buf) < 0)
goto error;
+ virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domstatus>\n");
virBufferAddLit(&buf, " </disks>\n");
}
if (def->dom) {
- virDomainDefFormatInternal(def->dom, flags, &buf);
+ virBufferAdjustIndent(&buf, 2);
+ if (virDomainDefFormatInternal(def->dom, flags, &buf) < 0) {
+ virBufferFreeAndReset(&buf);
+ return NULL;
+ }
+ virBufferAdjustIndent(&buf, -2);
} else {
virBufferAddLit(&buf, " <domain>\n");
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
char *virDomainDefFormat(virDomainDefPtr def,
unsigned int flags);
+int virDomainDefFormatInternal(virDomainDefPtr def,
+ unsigned int flags,
+ virBufferPtr buf);
int virDomainCpuSetParse(const char **str,
char sep,
virDomainDefClearDeviceAliases;
virDomainDefClearPCIAddresses;
virDomainDefFormat;
+virDomainDefFormatInternal;
virDomainDefFree;
virDomainDefParseFile;
virDomainDefParseNode;
}
-static void qemuMigrationCookieXMLFormat(virBufferPtr buf,
- qemuMigrationCookiePtr mig)
+static int
+qemuMigrationCookieXMLFormat(virBufferPtr buf,
+ qemuMigrationCookiePtr mig)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
char hostuuidstr[VIR_UUID_STRING_BUFLEN];
- char *domXML;
int i;
virUUIDFormat(mig->uuid, uuidstr);
if ((mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) &&
mig->persistent) {
- domXML = virDomainDefFormat(mig->persistent,
- VIR_DOMAIN_XML_INACTIVE |
- VIR_DOMAIN_XML_SECURE);
- virBufferAdd(buf, domXML, -1);
- VIR_FREE(domXML);
+ virBufferAdjustIndent(buf, 2);
+ if (virDomainDefFormatInternal(mig->persistent,
+ VIR_DOMAIN_XML_INACTIVE |
+ VIR_DOMAIN_XML_SECURE,
+ buf) < 0)
+ return -1;
+ virBufferAdjustIndent(buf, -2);
}
virBufferAddLit(buf, "</qemu-migration>\n");
+ return 0;
}
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- qemuMigrationCookieXMLFormat(&buf, mig);
+ if (qemuMigrationCookieXMLFormat(&buf, mig) < 0) {
+ virBufferFreeAndReset(&buf);
+ return NULL;
+ }
if (virBufferError(&buf)) {
virReportOOMError();
+ virBufferFreeAndReset(&buf);
return NULL;
}