snapshot: Add virDomainSnapshotObjListFormat
Add a new function to output all of the domain's snapshots in one buffer. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
cae6619ad5
commit
86c0ed6f70
@ -809,6 +809,67 @@ virDomainSnapshotDefFormat(const char *uuidstr,
|
|||||||
return virBufferContentAndReset(&buf);
|
return virBufferContentAndReset(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Struct and callback function used as a hash table callback; each call
|
||||||
|
* appends another snapshot XML to buf, with the caller clearing the
|
||||||
|
* buffer if any callback fails. */
|
||||||
|
struct virDomainSnapshotFormatData {
|
||||||
|
virBufferPtr buf;
|
||||||
|
const char *uuidstr;
|
||||||
|
virCapsPtr caps;
|
||||||
|
virDomainXMLOptionPtr xmlopt;
|
||||||
|
unsigned int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
virDomainSnapshotFormatOne(void *payload,
|
||||||
|
const void *name ATTRIBUTE_UNUSED,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
virDomainSnapshotObjPtr snap = payload;
|
||||||
|
struct virDomainSnapshotFormatData *data = opaque;
|
||||||
|
return virDomainSnapshotDefFormatInternal(data->buf, data->uuidstr,
|
||||||
|
snap->def, data->caps,
|
||||||
|
data->xmlopt, data->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Format the XML for all snapshots in the list into buf. On error,
|
||||||
|
* clear the buffer and return -1. */
|
||||||
|
int
|
||||||
|
virDomainSnapshotObjListFormat(virBufferPtr buf,
|
||||||
|
const char *uuidstr,
|
||||||
|
virDomainSnapshotObjListPtr snapshots,
|
||||||
|
virDomainSnapshotObjPtr current_snapshot,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
struct virDomainSnapshotFormatData data = {
|
||||||
|
.buf = buf,
|
||||||
|
.uuidstr = uuidstr,
|
||||||
|
.caps = caps,
|
||||||
|
.xmlopt = xmlopt,
|
||||||
|
.flags = flags,
|
||||||
|
};
|
||||||
|
|
||||||
|
virBufferAddLit(buf, "<snapshots");
|
||||||
|
if (current_snapshot)
|
||||||
|
virBufferEscapeString(buf, " current='%s'",
|
||||||
|
current_snapshot->def->name);
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
if (virDomainSnapshotForEach(snapshots, virDomainSnapshotFormatOne,
|
||||||
|
&data) < 0) {
|
||||||
|
virBufferFreeAndReset(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
virBufferAdjustIndent(buf, -2);
|
||||||
|
virBufferAddLit(buf, "</snapshots>\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Snapshot Obj functions */
|
/* Snapshot Obj functions */
|
||||||
static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void)
|
static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void)
|
||||||
{
|
{
|
||||||
|
@ -138,6 +138,13 @@ char *virDomainSnapshotDefFormat(const char *uuidstr,
|
|||||||
virCapsPtr caps,
|
virCapsPtr caps,
|
||||||
virDomainXMLOptionPtr xmlopt,
|
virDomainXMLOptionPtr xmlopt,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
int virDomainSnapshotObjListFormat(virBufferPtr buf,
|
||||||
|
const char *uuidstr,
|
||||||
|
virDomainSnapshotObjListPtr snapshots,
|
||||||
|
virDomainSnapshotObjPtr current_snapshot,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int flags);
|
||||||
int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
|
int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
|
||||||
int default_snapshot,
|
int default_snapshot,
|
||||||
bool require_match);
|
bool require_match);
|
||||||
|
@ -895,6 +895,7 @@ virDomainSnapshotFormatConvertXMLFlags;
|
|||||||
virDomainSnapshotIsExternal;
|
virDomainSnapshotIsExternal;
|
||||||
virDomainSnapshotLocationTypeFromString;
|
virDomainSnapshotLocationTypeFromString;
|
||||||
virDomainSnapshotLocationTypeToString;
|
virDomainSnapshotLocationTypeToString;
|
||||||
|
virDomainSnapshotObjListFormat;
|
||||||
virDomainSnapshotObjListFree;
|
virDomainSnapshotObjListFree;
|
||||||
virDomainSnapshotObjListGetNames;
|
virDomainSnapshotObjListGetNames;
|
||||||
virDomainSnapshotObjListNew;
|
virDomainSnapshotObjListNew;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user