Another step towards making the object list reusable for both
snapshots and checkpoints: the list code only ever needs items that
are in the common virDomainMomentDef base type. This undoes a lot of
the churn in accessing common members added the earlier patch.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/conf/virdomainsnapshotobj.h | 4 +-
src/conf/virdomainsnapshotobj.c | 2 +-
src/conf/virdomainsnapshotobjlist.c | 19 +++--
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_domain.c | 16 ++---
src/qemu/qemu_driver.c | 107 +++++++++++++++-------------
src/test/test_driver.c | 52 +++++++-------
7 files changed, 105 insertions(+), 97 deletions(-)
diff --git a/src/conf/virdomainsnapshotobj.h b/src/conf/virdomainsnapshotobj.h
index 8f96bfded9..ed2884e976 100644
--- a/src/conf/virdomainsnapshotobj.h
+++ b/src/conf/virdomainsnapshotobj.h
@@ -28,7 +28,7 @@
# include "virhash.h"
struct _virDomainSnapshotObj {
- virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */
+ virDomainMomentDefPtr def; /* non-NULL except for metaroot */
virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before
virDomainSnapshotUpdateRelations, or
@@ -55,7 +55,7 @@ void virDomainSnapshotSetParent(virDomainSnapshotObjPtr snapshot,
static inline virDomainSnapshotDefPtr
virDomainSnapshotObjGetDef(virDomainSnapshotObjPtr obj)
{
- return obj->def;
+ return (virDomainSnapshotDefPtr) obj->def;
}
#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H */
diff --git a/src/conf/virdomainsnapshotobj.c b/src/conf/virdomainsnapshotobj.c
index 0e3ee012fc..d6b216c7b2 100644
--- a/src/conf/virdomainsnapshotobj.c
+++ b/src/conf/virdomainsnapshotobj.c
@@ -45,7 +45,7 @@ virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
while (child) {
virDomainSnapshotObjPtr next = child->sibling;
- (iter)(child, child->def->common.name, data);
+ (iter)(child, child->def->name, data);
child = next;
}
diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapshotobjlist.c
index 58f094fa02..a55448c887 100644
--- a/src/conf/virdomainsnapshotobjlist.c
+++ b/src/conf/virdomainsnapshotobjlist.c
@@ -249,9 +249,9 @@ virDomainSnapshotObjPtr
virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s
if (!(snap = virDomainSnapshotObjNew()))
return NULL;
- snap->def = def;
+ snap->def = &def->common;
- if (virHashAddEntry(snapshots->objs, snap->def->common.name, snap) < 0)
{
+ if (virHashAddEntry(snapshots->objs, snap->def->name, snap) < 0) {
VIR_FREE(snap);
return NULL;
}
@@ -354,7 +354,7 @@ static int virDomainSnapshotObjListCopyNames(void *payload,
return 0;
if (data->names && data->count < data->maxnames &&
- VIR_STRDUP(data->names[data->count], obj->def->common.name) < 0)
{
+ VIR_STRDUP(data->names[data->count], obj->def->name) < 0) {
data->error = true;
return 0;
}
@@ -475,7 +475,7 @@ const char *
virDomainSnapshotGetCurrentName(virDomainSnapshotObjListPtr snapshots)
{
if (snapshots->current)
- return snapshots->current->def->common.name;
+ return snapshots->current->def->name;
return NULL;
}
@@ -485,8 +485,7 @@ bool
virDomainSnapshotIsCurrentName(virDomainSnapshotObjListPtr snapshots,
const char *name)
{
- return snapshots->current &&
STREQ(snapshots->current->def->common.name,
- name);
+ return snapshots->current && STREQ(snapshots->current->def->name,
name);
}
@@ -504,7 +503,7 @@ bool virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr
snapshots,
virDomainSnapshotObjPtr snapshot)
{
bool ret = snapshots->current == snapshot;
- virHashRemoveEntry(snapshots->objs, snapshot->def->common.name);
+ virHashRemoveEntry(snapshots->objs, snapshot->def->name);
if (ret)
snapshots->current = NULL;
return ret;
@@ -548,18 +547,18 @@ virDomainSnapshotSetRelations(void *payload,
virDomainSnapshotObjPtr tmp;
virDomainSnapshotObjPtr parent;
- parent = virDomainSnapshotFindByName(curr->snapshots,
obj->def->common.parent);
+ parent = virDomainSnapshotFindByName(curr->snapshots, obj->def->parent);
if (!parent) {
curr->err = -1;
parent = &curr->snapshots->metaroot;
- VIR_WARN("snapshot %s lacks parent", obj->def->common.name);
+ VIR_WARN("snapshot %s lacks parent", obj->def->name);
} else {
tmp = parent;
while (tmp && tmp->def) {
if (tmp == obj) {
curr->err = -1;
parent = &curr->snapshots->metaroot;
- VIR_WARN("snapshot %s in circular chain",
obj->def->common.name);
+ VIR_WARN("snapshot %s in circular chain",
obj->def->name);
break;
}
tmp = tmp->parent;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 000da64d0e..bc02362495 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10859,7 +10859,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
goto error;
if (snapshot)
- virCommandAddArgList(cmd, "-loadvm", snapshot->def->common.name,
NULL);
+ virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
if (def->namespaceData) {
qemuDomainCmdlineDefPtr qemucmd;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8e02f05c3c..3219ac5e48 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8573,11 +8573,11 @@ qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
/* Prefer action on the disks in use at the time the snapshot was
* created; but fall back to current definition if dealing with a
* snapshot created prior to libvirt 0.9.5. */
- virDomainDefPtr def = snap->def->common.dom;
+ virDomainDefPtr def = snap->def->dom;
if (!def)
def = vm->def;
- return qemuDomainSnapshotForEachQcow2Raw(driver, def, snap->def->common.name,
+ return qemuDomainSnapshotForEachQcow2Raw(driver, def, snap->def->name,
op, try_all, def->ndisks);
}
@@ -8605,30 +8605,30 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
priv = vm->privateData;
qemuDomainObjEnterMonitor(driver, vm);
/* we continue on even in the face of error */
- qemuMonitorDeleteSnapshot(priv->mon, snap->def->common.name);
+ qemuMonitorDeleteSnapshot(priv->mon, snap->def->name);
ignore_value(qemuDomainObjExitMonitor(driver, vm));
}
}
if (virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir,
- vm->def->name, snap->def->common.name) < 0)
+ vm->def->name, snap->def->name) < 0)
goto cleanup;
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
- if (update_parent && snap->def->common.parent) {
+ if (update_parent && snap->def->parent) {
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
- snap->def->common.parent);
+ snap->def->parent);
if (!parentsnap) {
VIR_WARN("missing parent snapshot matching name '%s'",
- snap->def->common.parent);
+ snap->def->parent);
} else {
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->caps,
driver->xmlopt,
cfg->snapshotDir) < 0) {
VIR_WARN("failed to set parent snapshot '%s' as
current",
- snap->def->common.parent);
+ snap->def->parent);
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
}
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ece9c9329e..9ad7be5718 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14535,19 +14535,20 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr
driver,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
goto cleanup;
- if (!(created = virBitmapNew(snap->def->ndisks)))
+ if (!(created = virBitmapNew(snapdef->ndisks)))
goto cleanup;
/* If reuse is true, then qemuDomainSnapshotPrepare already
* ensured that the new files exist, and it was up to the user to
* create them correctly. */
- for (i = 0; i < snap->def->ndisks && !reuse; i++) {
- snapdisk = &(snap->def->disks[i]);
- defdisk = snap->def->common.dom->disks[snapdisk->idx];
+ for (i = 0; i < snapdef->ndisks && !reuse; i++) {
+ snapdisk = &(snapdef->disks[i]);
+ defdisk = snapdef->common.dom->disks[snapdisk->idx];
if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
continue;
@@ -14585,8 +14586,8 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
}
/* update disk definitions */
- for (i = 0; i < snap->def->ndisks; i++) {
- snapdisk = &(snap->def->disks[i]);
+ for (i = 0; i < snapdef->ndisks; i++) {
+ snapdisk = &(snapdef->disks[i]);
defdisk = vm->def->disks[snapdisk->idx];
if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
@@ -14612,7 +14613,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
if (ret < 0 && created) {
ssize_t bit = -1;
while ((bit = virBitmapNextSetBit(created, bit)) >= 0) {
- snapdisk = &(snap->def->disks[bit]);
+ snapdisk = &(snapdef->disks[bit]);
if (unlink(snapdisk->src->path) < 0)
VIR_WARN("Failed to remove snapshot image '%s'",
snapdisk->src->path);
@@ -14635,6 +14636,7 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
virObjectEventPtr event = NULL;
bool resume = false;
+ virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
int ret = -1;
if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
@@ -14663,13 +14665,13 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver,
goto cleanup;
}
- ret = qemuMonitorCreateSnapshot(priv->mon, snap->def->common.name);
+ ret = qemuMonitorCreateSnapshot(priv->mon, snap->def->name);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1;
if (ret < 0)
goto cleanup;
- if (!(snap->def->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
+ if (!(snapdef->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
goto cleanup;
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) {
@@ -15181,19 +15183,20 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
qemuDomainSnapshotDiskDataPtr ret;
qemuDomainSnapshotDiskDataPtr dd;
char *backingStoreStr;
+ virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
- if (VIR_ALLOC_N(ret, snap->def->ndisks) < 0)
+ if (VIR_ALLOC_N(ret, snapdef->ndisks) < 0)
return NULL;
- for (i = 0; i < snap->def->ndisks; i++) {
- if (snap->def->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_NONE)
+ for (i = 0; i < snapdef->ndisks; i++) {
+ if (snapdef->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_NONE)
continue;
dd = ret + i;
dd->disk = vm->def->disks[i];
- if (!(dd->src = virStorageSourceCopy(snap->def->disks[i].src, false)))
+ if (!(dd->src = virStorageSourceCopy(snapdef->disks[i].src, false)))
goto error;
if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false) <
0)
@@ -15237,7 +15240,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
return ret;
error:
- qemuDomainSnapshotDiskDataFree(ret, snap->def->ndisks, driver, vm);
+ qemuDomainSnapshotDiskDataFree(ret, snapdef->ndisks, driver, vm);
return NULL;
}
@@ -15344,6 +15347,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg = NULL;
qemuDomainSnapshotDiskDataPtr diskdata = NULL;
virErrorPtr orig_err = NULL;
+ virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
if (virDomainObjCheckActive(vm) < 0)
return -1;
@@ -15362,7 +15366,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
* now either VIR_DOMAIN_SNAPSHOT_LOCATION_NONE, or
* VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and
* qcow2 format. */
- for (i = 0; i < snap->def->ndisks; i++) {
+ for (i = 0; i < snapdef->ndisks; i++) {
if (!diskdata[i].src)
continue;
@@ -15385,7 +15389,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1;
- for (i = 0; i < snap->def->ndisks; i++) {
+ for (i = 0; i < snapdef->ndisks; i++) {
qemuDomainSnapshotDiskDataPtr dd = &diskdata[i];
if (!dd->src)
@@ -15404,7 +15408,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
error:
if (ret < 0) {
orig_err = virSaveLastError();
- for (i = 0; i < snap->def->ndisks; i++) {
+ for (i = 0; i < snapdef->ndisks; i++) {
if (!diskdata[i].src)
continue;
@@ -15421,7 +15425,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
* stopped using them*/
bool paused = virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING;
- for (i = 0; i < snap->def->ndisks; i++) {
+ for (i = 0; i < snapdef->ndisks; i++) {
if (!diskdata[i].disk)
continue;
@@ -15442,7 +15446,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
}
cleanup:
- qemuDomainSnapshotDiskDataFree(diskdata, snap->def->ndisks, driver, vm);
+ qemuDomainSnapshotDiskDataFree(diskdata, snapdef->ndisks, driver, vm);
virJSONValueFree(actions);
virObjectUnref(cfg);
@@ -15466,7 +15470,8 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
char *xml = NULL;
- bool memory = snap->def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
+ virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
+ bool memory = snapdef->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
bool memory_unlink = false;
int thaw = 0; /* 1 if freeze succeeded, -1 if freeze failed */
bool pmsuspended = false;
@@ -15557,16 +15562,16 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
if (!(xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU,
true, true)) ||
- !(snap->def->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
+ !(snapdef->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
goto cleanup;
if (!(data = virQEMUSaveDataNew(xml,
- (qemuDomainSaveCookiePtr)
snap->def->cookie,
+ (qemuDomainSaveCookiePtr) snapdef->cookie,
resume, compressed, driver->xmlopt)))
goto cleanup;
xml = NULL;
- if ((ret = qemuDomainSaveMemory(driver, vm, snap->def->file, data,
+ if ((ret = qemuDomainSaveMemory(driver, vm, snapdef->file, data,
compressedpath, 0,
QEMU_ASYNC_JOB_SNAPSHOT)) < 0)
goto cleanup;
@@ -15641,7 +15646,7 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
VIR_FREE(compressedpath);
virObjectUnref(cfg);
if (memory_unlink && ret < 0)
- unlink(snap->def->file);
+ unlink(snapdef->file);
return ret;
}
@@ -15857,7 +15862,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
current = virDomainSnapshotGetCurrent(vm->snapshots);
if (current) {
if (!redefine &&
- VIR_STRDUP(snap->def->common.parent, current->def->common.name)
< 0)
+ VIR_STRDUP(snap->def->parent, current->def->name) < 0)
goto endjob;
if (update_current) {
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
@@ -15875,7 +15880,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
* snapshot name in at least one of the domain's disks? */
} else if (virDomainObjIsActive(vm)) {
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY ||
- snap->def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
+ virDomainSnapshotObjGetDef(snap)->memory ==
VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
/* external full system or disk snapshot */
if (qemuDomainSnapshotCreateActiveExternal(driver,
vm, snap, flags) < 0)
@@ -15906,7 +15911,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
* do; we've successfully taken the snapshot, and we are now running
* on it, so we have to go forward the best we can
*/
- snapshot = virGetDomainSnapshot(domain, snap->def->common.name);
+ snapshot = virGetDomainSnapshot(domain, snap->def->name);
endjob:
if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) {
@@ -15921,11 +15926,11 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
snapshot = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to save metadata for snapshot %s"),
- snap->def->common.name);
+ snap->def->name);
virDomainSnapshotObjListRemove(vm->snapshots, snap);
} else {
other = virDomainSnapshotFindByName(vm->snapshots,
- snap->def->common.parent);
+ snap->def->parent);
virDomainSnapshotSetParent(snap, other);
}
} else if (snap) {
@@ -16135,7 +16140,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
if (!(snap = qemuSnapObjFromName(vm, name)))
goto cleanup;
- snapshot = virGetDomainSnapshot(domain, snap->def->common.name);
+ snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup:
virDomainObjEndAPI(&vm);
@@ -16185,14 +16190,14 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
goto cleanup;
- if (!snap->def->common.parent) {
+ if (!snap->def->parent) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("snapshot '%s' does not have a parent"),
- snap->def->common.name);
+ snap->def->name);
goto cleanup;
}
- parent = virGetDomainSnapshot(virSnapDom(snapshot), snap->def->common.parent);
+ parent = virGetDomainSnapshot(virSnapDom(snapshot), snap->def->parent);
cleanup:
virDomainObjEndAPI(&vm);
@@ -16252,7 +16257,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virUUIDFormat(virSnapDom(snapshot)->uuid, uuidstr);
- xml = virDomainSnapshotDefFormat(uuidstr, snap->def,
+ xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap),
driver->caps, driver->xmlopt,
virDomainSnapshotFormatConvertXMLFlags(flags));
@@ -16340,6 +16345,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
int ret = -1;
virDomainSnapshotObjPtr snap = NULL;
virDomainSnapshotObjPtr current = NULL;
+ virDomainSnapshotDefPtr snapdef;
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
int detail;
@@ -16398,10 +16404,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
goto endjob;
+ snapdef = virDomainSnapshotObjGetDef(snap);
if (!vm->persistent &&
- snap->def->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
- snap->def->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
+ snapdef->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
+ snapdef->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -16417,15 +16424,15 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
}
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
- if (!snap->def->common.dom) {
+ if (!snap->def->dom) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
_("snapshot '%s' lacks domain '%s'
rollback info"),
- snap->def->common.name, vm->def->name);
+ snap->def->name, vm->def->name);
goto endjob;
}
if (virDomainObjIsActive(vm) &&
- !(snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
- snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
+ !(snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
+ snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
@@ -16450,16 +16457,16 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
*
* XXX Should domain snapshots track live xml rather
* than inactive xml? */
- if (snap->def->common.dom) {
- config = virDomainDefCopy(snap->def->common.dom, caps,
+ if (snap->def->dom) {
+ config = virDomainDefCopy(snap->def->dom, caps,
driver->xmlopt, NULL, true);
if (!config)
goto endjob;
}
- cookie = (qemuDomainSaveCookiePtr) snap->def->cookie;
+ cookie = (qemuDomainSaveCookiePtr) snapdef->cookie;
- switch ((virDomainSnapshotState) snap->def->state) {
+ switch ((virDomainSnapshotState) snapdef->state) {
case VIR_DOMAIN_SNAPSHOT_RUNNING:
case VIR_DOMAIN_SNAPSHOT_PAUSED:
@@ -16557,7 +16564,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (qemuDomainObjEnterMonitorAsync(driver, vm,
QEMU_ASYNC_JOB_START) < 0)
goto endjob;
- rc = qemuMonitorLoadSnapshot(priv->mon, snap->def->common.name);
+ rc = qemuMonitorLoadSnapshot(priv->mon, snap->def->name);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto endjob;
if (rc < 0) {
@@ -16600,7 +16607,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
/* Touch up domain state. */
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) &&
- (snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED ||
+ (snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED ||
(flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
/* Transitions 3, 6, 9 */
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
@@ -16709,7 +16716,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid target domain state '%s'. Refusing "
"snapshot reversion"),
- virDomainSnapshotStateTypeToString(snap->def->state));
+ virDomainSnapshotStateTypeToString(snapdef->state));
goto endjob;
}
@@ -16774,10 +16781,10 @@ qemuDomainSnapshotReparentChildren(void *payload,
if (rep->err < 0)
return 0;
- VIR_FREE(snap->def->common.parent);
+ VIR_FREE(snap->def->parent);
if (rep->parent->def &&
- VIR_STRDUP(snap->def->common.parent,
rep->parent->def->common.name) < 0) {
+ VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
rep->err = -1;
return 0;
}
@@ -16858,7 +16865,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
cfg->snapshotDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to set snapshot '%s' as
current"),
- snap->def->common.name);
+ snap->def->name);
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
goto endjob;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0caed1de19..eac6160532 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -6132,7 +6132,7 @@ testDomainSnapshotLookupByName(virDomainPtr domain,
if (!(snap = testSnapObjFromName(vm, name)))
goto cleanup;
- snapshot = virGetDomainSnapshot(domain, snap->def->common.name);
+ snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup:
virDomainObjEndAPI(&vm);
@@ -6173,14 +6173,14 @@ testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
goto cleanup;
- if (!snap->def->common.parent) {
+ if (!snap->def->parent) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("snapshot '%s' does not have a parent"),
- snap->def->common.name);
+ snap->def->name);
goto cleanup;
}
- parent = virGetDomainSnapshot(virSnapDom(snapshot), snap->def->common.parent);
+ parent = virGetDomainSnapshot(virSnapDom(snapshot), snap->def->parent);
cleanup:
virDomainObjEndAPI(&vm);
@@ -6207,7 +6207,7 @@ testDomainSnapshotCurrent(virDomainPtr domain,
goto cleanup;
}
- snapshot = virGetDomainSnapshot(domain, current->def->common.name);
+ snapshot = virGetDomainSnapshot(domain, current->def->name);
cleanup:
virDomainObjEndAPI(&vm);
@@ -6234,8 +6234,8 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virUUIDFormat(virSnapDom(snapshot)->uuid, uuidstr);
- xml = virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->caps,
- privconn->xmlopt,
+ xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap),
+ privconn->caps, privconn->xmlopt,
virDomainSnapshotFormatConvertXMLFlags(flags));
cleanup:
@@ -6394,7 +6394,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
}
if (!redefine) {
- if (VIR_STRDUP(snap->def->common.parent,
+ if (VIR_STRDUP(snap->def->parent,
virDomainSnapshotGetCurrentName(vm->snapshots)) < 0)
goto cleanup;
@@ -6407,7 +6407,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
}
}
- snapshot = virGetDomainSnapshot(domain, snap->def->common.name);
+ snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup:
if (vm) {
if (snapshot) {
@@ -6415,7 +6415,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
if (update_current)
virDomainSnapshotSetCurrent(vm->snapshots, snap);
other = virDomainSnapshotFindByName(vm->snapshots,
- snap->def->common.parent);
+ snap->def->parent);
virDomainSnapshotSetParent(snap, other);
}
virDomainObjEndAPI(&vm);
@@ -6464,10 +6464,10 @@ testDomainSnapshotReparentChildren(void *payload,
if (rep->err < 0)
return 0;
- VIR_FREE(snap->def->common.parent);
+ VIR_FREE(snap->def->parent);
if (rep->parent->def &&
- VIR_STRDUP(snap->def->common.parent,
rep->parent->def->common.name) < 0) {
+ VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
rep->err = -1;
return 0;
}
@@ -6522,12 +6522,12 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
} else {
virDomainSnapshotDropParent(snap);
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
- if (snap->def->common.parent) {
+ if (snap->def->parent) {
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
-
snap->def->common.parent);
+ snap->def->parent);
if (!parentsnap)
VIR_WARN("missing parent snapshot matching name
'%s'",
- snap->def->common.parent);
+ snap->def->parent);
}
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
}
@@ -6550,6 +6550,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL;
virDomainDefPtr config = NULL;
+ virDomainSnapshotDefPtr snapdef;
int ret = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
@@ -6575,10 +6576,11 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
goto cleanup;
+ snapdef = virDomainSnapshotObjGetDef(snap);
if (!vm->persistent &&
- snap->def->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
- snap->def->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
+ snapdef->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
+ snapdef->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -6588,15 +6590,15 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
}
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
- if (!snap->def->common.dom) {
+ if (!snap->def->dom) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
_("snapshot '%s' lacks domain '%s'
rollback info"),
- snap->def->common.name, vm->def->name);
+ snap->def->name, vm->def->name);
goto cleanup;
}
if (virDomainObjIsActive(vm) &&
- !(snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
- snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
+ !(snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
+ snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
@@ -6607,13 +6609,13 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
- config = virDomainDefCopy(snap->def->common.dom, privconn->caps,
+ config = virDomainDefCopy(snap->def->dom, privconn->caps,
privconn->xmlopt, NULL, true);
if (!config)
goto cleanup;
- if (snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
- snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) {
+ if (snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
+ snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) {
/* Transitions 2, 3, 5, 6, 8, 9 */
bool was_running = false;
bool was_stopped = false;
@@ -6672,7 +6674,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
/* Touch up domain state. */
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) &&
- (snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED ||
+ (snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED ||
(flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
/* Transitions 3, 6, 9 */
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
--
2.20.1