mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 14:05:18 +00:00
snapshot: indent domain xml when nesting
<domainsnapshot> is the first public instance of <domain> being used as a sub-element, although we have two other private uses (runtime state, and migration cookie). Although indentation has no effect on XML parsing, using it makes the output more consistent. This uses virBuffer auto-indentation to obtain the effect, for all but the portions of <domain> that are not generated a line at a time into the same virBuffer. Further patches will clean up the remaining problems. * src/conf/domain_conf.h (virDomainDefFormatInternal): New prototype. * src/conf/domain_conf.c (virDomainDefFormatInternal): Export. (virDomainObjFormat, virDomainSnapshotDefFormat): Update callers. * src/libvirt_private.syms (domain_conf.h): Add new export. * src/qemu/qemu_migration.c (qemuMigrationCookieXMLFormat): Use new function. (qemuMigrationCookieXMLFormatStr): Update caller.
This commit is contained in:
parent
fd9c052e6d
commit
9cba392768
@ -10559,14 +10559,13 @@ verify(((VIR_DOMAIN_XML_INTERNAL_STATUS |
|
|||||||
|
|
||||||
/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*,
|
/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*,
|
||||||
* whereas the public version cannot. Also, it appends to an existing
|
* whereas the public version cannot. Also, it appends to an existing
|
||||||
* buffer, rather than flattening to string. Return -1 on failure. */
|
* buffer (possibly with auto-indent), rather than flattening to string.
|
||||||
static int
|
* Return -1 on failure. */
|
||||||
|
int
|
||||||
virDomainDefFormatInternal(virDomainDefPtr def,
|
virDomainDefFormatInternal(virDomainDefPtr def,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
virBufferPtr buf)
|
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;
|
unsigned char *uuid;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
@ -11056,8 +11055,10 @@ static char *virDomainObjFormat(virCapsPtr caps,
|
|||||||
((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0)
|
((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
virBufferAdjustIndent(&buf, 2);
|
||||||
if (virDomainDefFormatInternal(obj->def, flags, &buf) < 0)
|
if (virDomainDefFormatInternal(obj->def, flags, &buf) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
virBufferAdjustIndent(&buf, -2);
|
||||||
|
|
||||||
virBufferAddLit(&buf, "</domstatus>\n");
|
virBufferAddLit(&buf, "</domstatus>\n");
|
||||||
|
|
||||||
@ -12074,7 +12075,12 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
|
|||||||
virBufferAddLit(&buf, " </disks>\n");
|
virBufferAddLit(&buf, " </disks>\n");
|
||||||
}
|
}
|
||||||
if (def->dom) {
|
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 {
|
} else {
|
||||||
virBufferAddLit(&buf, " <domain>\n");
|
virBufferAddLit(&buf, " <domain>\n");
|
||||||
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
|
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", domain_uuid);
|
||||||
|
@ -1683,6 +1683,9 @@ int virDomainDefAddImplicitControllers(virDomainDefPtr def);
|
|||||||
|
|
||||||
char *virDomainDefFormat(virDomainDefPtr def,
|
char *virDomainDefFormat(virDomainDefPtr def,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
int virDomainDefFormatInternal(virDomainDefPtr def,
|
||||||
|
unsigned int flags,
|
||||||
|
virBufferPtr buf);
|
||||||
|
|
||||||
int virDomainCpuSetParse(const char **str,
|
int virDomainCpuSetParse(const char **str,
|
||||||
char sep,
|
char sep,
|
||||||
|
@ -267,6 +267,7 @@ virDomainDefCheckABIStability;
|
|||||||
virDomainDefClearDeviceAliases;
|
virDomainDefClearDeviceAliases;
|
||||||
virDomainDefClearPCIAddresses;
|
virDomainDefClearPCIAddresses;
|
||||||
virDomainDefFormat;
|
virDomainDefFormat;
|
||||||
|
virDomainDefFormatInternal;
|
||||||
virDomainDefFree;
|
virDomainDefFree;
|
||||||
virDomainDefParseFile;
|
virDomainDefParseFile;
|
||||||
virDomainDefParseNode;
|
virDomainDefParseNode;
|
||||||
|
@ -384,12 +384,12 @@ static void qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void qemuMigrationCookieXMLFormat(virBufferPtr buf,
|
static int
|
||||||
qemuMigrationCookiePtr mig)
|
qemuMigrationCookieXMLFormat(virBufferPtr buf,
|
||||||
|
qemuMigrationCookiePtr mig)
|
||||||
{
|
{
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char hostuuidstr[VIR_UUID_STRING_BUFLEN];
|
char hostuuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *domXML;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
virUUIDFormat(mig->uuid, uuidstr);
|
virUUIDFormat(mig->uuid, uuidstr);
|
||||||
@ -422,14 +422,17 @@ static void qemuMigrationCookieXMLFormat(virBufferPtr buf,
|
|||||||
|
|
||||||
if ((mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) &&
|
if ((mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) &&
|
||||||
mig->persistent) {
|
mig->persistent) {
|
||||||
domXML = virDomainDefFormat(mig->persistent,
|
virBufferAdjustIndent(buf, 2);
|
||||||
VIR_DOMAIN_XML_INACTIVE |
|
if (virDomainDefFormatInternal(mig->persistent,
|
||||||
VIR_DOMAIN_XML_SECURE);
|
VIR_DOMAIN_XML_INACTIVE |
|
||||||
virBufferAdd(buf, domXML, -1);
|
VIR_DOMAIN_XML_SECURE,
|
||||||
VIR_FREE(domXML);
|
buf) < 0)
|
||||||
|
return -1;
|
||||||
|
virBufferAdjustIndent(buf, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAddLit(buf, "</qemu-migration>\n");
|
virBufferAddLit(buf, "</qemu-migration>\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -437,10 +440,14 @@ static char *qemuMigrationCookieXMLFormatStr(qemuMigrationCookiePtr mig)
|
|||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
qemuMigrationCookieXMLFormat(&buf, mig);
|
if (qemuMigrationCookieXMLFormat(&buf, mig) < 0) {
|
||||||
|
virBufferFreeAndReset(&buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
|
virBufferFreeAndReset(&buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user