提交 1ab05da2 编写于 作者: E Eric Blake

snapshot: Switch type of virDomainSnapshotObj.def

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 in the previous patch, and
the bulk of the patch is mechanical. But there was one spot where I
had to unroll a VIR_STEAL_PTR to work around changed types.
Signed-off-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 ffc0fbeb
...@@ -985,7 +985,8 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain, ...@@ -985,7 +985,8 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
* child relations by reusing snap. */ * child relations by reusing snap. */
virDomainSnapshotDropParent(other); virDomainSnapshotDropParent(other);
virDomainSnapshotDefFree(otherdef); virDomainSnapshotDefFree(otherdef);
VIR_STEAL_PTR(other->def, *defptr); other->def = &(*defptr)->common;
*defptr = NULL;
*snap = other; *snap = other;
} }
......
...@@ -45,7 +45,7 @@ virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot, ...@@ -45,7 +45,7 @@ virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
while (child) { while (child) {
virDomainSnapshotObjPtr next = child->sibling; virDomainSnapshotObjPtr next = child->sibling;
(iter)(child, child->def->common.name, data); (iter)(child, child->def->name, data);
child = next; child = next;
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
# include "virhash.h" # include "virhash.h"
struct _virDomainSnapshotObj { struct _virDomainSnapshotObj {
virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */ virDomainMomentDefPtr def; /* non-NULL except for metaroot */
virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before
virDomainSnapshotUpdateRelations, or virDomainSnapshotUpdateRelations, or
......
...@@ -249,11 +249,11 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s ...@@ -249,11 +249,11 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s
if (!(snap = virDomainSnapshotObjNew())) if (!(snap = virDomainSnapshotObjNew()))
return NULL; return NULL;
if (virHashAddEntry(snapshots->objs, snap->def->common.name, snap) < 0) { if (virHashAddEntry(snapshots->objs, snap->def->name, snap) < 0) {
VIR_FREE(snap); VIR_FREE(snap);
return NULL; return NULL;
} }
snap->def = def; snap->def = &def->common;
return snap; return snap;
} }
...@@ -353,7 +353,7 @@ static int virDomainSnapshotObjListCopyNames(void *payload, ...@@ -353,7 +353,7 @@ static int virDomainSnapshotObjListCopyNames(void *payload,
return 0; return 0;
if (data->names && data->count < data->maxnames && 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; data->error = true;
return 0; return 0;
} }
...@@ -474,7 +474,7 @@ const char * ...@@ -474,7 +474,7 @@ const char *
virDomainSnapshotGetCurrentName(virDomainSnapshotObjListPtr snapshots) virDomainSnapshotGetCurrentName(virDomainSnapshotObjListPtr snapshots)
{ {
if (snapshots->current) if (snapshots->current)
return snapshots->current->def->common.name; return snapshots->current->def->name;
return NULL; return NULL;
} }
...@@ -484,8 +484,7 @@ bool ...@@ -484,8 +484,7 @@ bool
virDomainSnapshotIsCurrentName(virDomainSnapshotObjListPtr snapshots, virDomainSnapshotIsCurrentName(virDomainSnapshotObjListPtr snapshots,
const char *name) const char *name)
{ {
return snapshots->current && STREQ(snapshots->current->def->common.name, return snapshots->current && STREQ(snapshots->current->def->name, name);
name);
} }
...@@ -504,7 +503,7 @@ virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots, ...@@ -504,7 +503,7 @@ virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
virDomainSnapshotObjPtr snapshot) virDomainSnapshotObjPtr snapshot)
{ {
bool ret = snapshots->current == snapshot; bool ret = snapshots->current == snapshot;
virHashRemoveEntry(snapshots->objs, snapshot->def->common.name); virHashRemoveEntry(snapshots->objs, snapshot->def->name);
if (ret) if (ret)
snapshots->current = NULL; snapshots->current = NULL;
return ret; return ret;
...@@ -548,18 +547,18 @@ virDomainSnapshotSetRelations(void *payload, ...@@ -548,18 +547,18 @@ virDomainSnapshotSetRelations(void *payload,
virDomainSnapshotObjPtr tmp; virDomainSnapshotObjPtr tmp;
virDomainSnapshotObjPtr parent; virDomainSnapshotObjPtr parent;
parent = virDomainSnapshotFindByName(curr->snapshots, obj->def->common.parent); parent = virDomainSnapshotFindByName(curr->snapshots, obj->def->parent);
if (!parent) { if (!parent) {
curr->err = -1; curr->err = -1;
parent = &curr->snapshots->metaroot; parent = &curr->snapshots->metaroot;
VIR_WARN("snapshot %s lacks parent", obj->def->common.name); VIR_WARN("snapshot %s lacks parent", obj->def->name);
} else { } else {
tmp = parent; tmp = parent;
while (tmp && tmp->def) { while (tmp && tmp->def) {
if (tmp == obj) { if (tmp == obj) {
curr->err = -1; curr->err = -1;
parent = &curr->snapshots->metaroot; 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; break;
} }
tmp = tmp->parent; tmp = tmp->parent;
......
...@@ -107,7 +107,7 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, ...@@ -107,7 +107,7 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
static inline virDomainSnapshotDefPtr static inline virDomainSnapshotDefPtr
virDomainSnapshotObjGetDef(virDomainSnapshotObjPtr obj) virDomainSnapshotObjGetDef(virDomainSnapshotObjPtr obj)
{ {
return obj->def; return (virDomainSnapshotDefPtr) obj->def;
} }
#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */ #endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */
...@@ -10859,7 +10859,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, ...@@ -10859,7 +10859,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
goto error; goto error;
if (snapshot) if (snapshot)
virCommandAddArgList(cmd, "-loadvm", snapshot->def->common.name, NULL); virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
if (def->namespaceData) { if (def->namespaceData) {
qemuDomainCmdlineDefPtr qemucmd; qemuDomainCmdlineDefPtr qemucmd;
......
...@@ -8573,11 +8573,11 @@ qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver, ...@@ -8573,11 +8573,11 @@ qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
/* Prefer action on the disks in use at the time the snapshot was /* Prefer action on the disks in use at the time the snapshot was
* created; but fall back to current definition if dealing with a * created; but fall back to current definition if dealing with a
* snapshot created prior to libvirt 0.9.5. */ * snapshot created prior to libvirt 0.9.5. */
virDomainDefPtr def = snap->def->common.dom; virDomainDefPtr def = snap->def->dom;
if (!def) if (!def)
def = vm->def; def = vm->def;
return qemuDomainSnapshotForEachQcow2Raw(driver, def, snap->def->common.name, return qemuDomainSnapshotForEachQcow2Raw(driver, def, snap->def->name,
op, try_all, def->ndisks); op, try_all, def->ndisks);
} }
...@@ -8605,30 +8605,30 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, ...@@ -8605,30 +8605,30 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
priv = vm->privateData; priv = vm->privateData;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
/* we continue on even in the face of error */ /* 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)); ignore_value(qemuDomainObjExitMonitor(driver, vm));
} }
} }
if (virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir, 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; goto cleanup;
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) { if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
virDomainSnapshotSetCurrent(vm->snapshots, NULL); virDomainSnapshotSetCurrent(vm->snapshots, NULL);
if (update_parent && snap->def->common.parent) { if (update_parent && snap->def->parent) {
parentsnap = virDomainSnapshotFindByName(vm->snapshots, parentsnap = virDomainSnapshotFindByName(vm->snapshots,
snap->def->common.parent); snap->def->parent);
if (!parentsnap) { if (!parentsnap) {
VIR_WARN("missing parent snapshot matching name '%s'", VIR_WARN("missing parent snapshot matching name '%s'",
snap->def->common.parent); snap->def->parent);
} else { } else {
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->caps, if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->caps,
driver->xmlopt, driver->xmlopt,
cfg->snapshotDir) < 0) { cfg->snapshotDir) < 0) {
VIR_WARN("failed to set parent snapshot '%s' as current", VIR_WARN("failed to set parent snapshot '%s' as current",
snap->def->common.parent); snap->def->parent);
virDomainSnapshotSetCurrent(vm->snapshots, NULL); virDomainSnapshotSetCurrent(vm->snapshots, NULL);
} }
} }
......
...@@ -14535,19 +14535,20 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, ...@@ -14535,19 +14535,20 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1; int ret = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
if (!(qemuImgPath = qemuFindQemuImgBinary(driver))) if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
goto cleanup; goto cleanup;
if (!(created = virBitmapNew(snap->def->ndisks))) if (!(created = virBitmapNew(snapdef->ndisks)))
goto cleanup; goto cleanup;
/* If reuse is true, then qemuDomainSnapshotPrepare already /* If reuse is true, then qemuDomainSnapshotPrepare already
* ensured that the new files exist, and it was up to the user to * ensured that the new files exist, and it was up to the user to
* create them correctly. */ * create them correctly. */
for (i = 0; i < snap->def->ndisks && !reuse; i++) { for (i = 0; i < snapdef->ndisks && !reuse; i++) {
snapdisk = &(snap->def->disks[i]); snapdisk = &(snapdef->disks[i]);
defdisk = snap->def->common.dom->disks[snapdisk->idx]; defdisk = snapdef->common.dom->disks[snapdisk->idx];
if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
continue; continue;
...@@ -14585,8 +14586,8 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, ...@@ -14585,8 +14586,8 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
} }
/* update disk definitions */ /* update disk definitions */
for (i = 0; i < snap->def->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
snapdisk = &(snap->def->disks[i]); snapdisk = &(snapdef->disks[i]);
defdisk = vm->def->disks[snapdisk->idx]; defdisk = vm->def->disks[snapdisk->idx];
if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
...@@ -14612,7 +14613,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, ...@@ -14612,7 +14613,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
if (ret < 0 && created) { if (ret < 0 && created) {
ssize_t bit = -1; ssize_t bit = -1;
while ((bit = virBitmapNextSetBit(created, bit)) >= 0) { while ((bit = virBitmapNextSetBit(created, bit)) >= 0) {
snapdisk = &(snap->def->disks[bit]); snapdisk = &(snapdef->disks[bit]);
if (unlink(snapdisk->src->path) < 0) if (unlink(snapdisk->src->path) < 0)
VIR_WARN("Failed to remove snapshot image '%s'", VIR_WARN("Failed to remove snapshot image '%s'",
snapdisk->src->path); snapdisk->src->path);
...@@ -14635,6 +14636,7 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver, ...@@ -14635,6 +14636,7 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
bool resume = false; bool resume = false;
virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
int ret = -1; int ret = -1;
if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0)) if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
...@@ -14663,13 +14665,13 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver, ...@@ -14663,13 +14665,13 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
ret = qemuMonitorCreateSnapshot(priv->mon, snap->def->common.name); ret = qemuMonitorCreateSnapshot(priv->mon, snap->def->name);
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1; ret = -1;
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
if (!(snap->def->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm))) if (!(snapdef->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
goto cleanup; goto cleanup;
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) { if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) {
...@@ -15181,19 +15183,20 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver, ...@@ -15181,19 +15183,20 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
qemuDomainSnapshotDiskDataPtr ret; qemuDomainSnapshotDiskDataPtr ret;
qemuDomainSnapshotDiskDataPtr dd; qemuDomainSnapshotDiskDataPtr dd;
char *backingStoreStr; 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; return NULL;
for (i = 0; i < snap->def->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
if (snap->def->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_NONE) if (snapdef->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_NONE)
continue; continue;
dd = ret + i; dd = ret + i;
dd->disk = vm->def->disks[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; goto error;
if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false) < 0) if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false) < 0)
...@@ -15237,7 +15240,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver, ...@@ -15237,7 +15240,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
return ret; return ret;
error: error:
qemuDomainSnapshotDiskDataFree(ret, snap->def->ndisks, driver, vm); qemuDomainSnapshotDiskDataFree(ret, snapdef->ndisks, driver, vm);
return NULL; return NULL;
} }
...@@ -15344,6 +15347,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15344,6 +15347,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg = NULL; virQEMUDriverConfigPtr cfg = NULL;
qemuDomainSnapshotDiskDataPtr diskdata = NULL; qemuDomainSnapshotDiskDataPtr diskdata = NULL;
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
if (virDomainObjCheckActive(vm) < 0) if (virDomainObjCheckActive(vm) < 0)
return -1; return -1;
...@@ -15362,7 +15366,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15362,7 +15366,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
* now either VIR_DOMAIN_SNAPSHOT_LOCATION_NONE, or * now either VIR_DOMAIN_SNAPSHOT_LOCATION_NONE, or
* VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and * VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and
* qcow2 format. */ * qcow2 format. */
for (i = 0; i < snap->def->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
if (!diskdata[i].src) if (!diskdata[i].src)
continue; continue;
...@@ -15385,7 +15389,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15385,7 +15389,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1; ret = -1;
for (i = 0; i < snap->def->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
qemuDomainSnapshotDiskDataPtr dd = &diskdata[i]; qemuDomainSnapshotDiskDataPtr dd = &diskdata[i];
if (!dd->src) if (!dd->src)
...@@ -15404,7 +15408,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15404,7 +15408,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
error: error:
if (ret < 0) { if (ret < 0) {
orig_err = virSaveLastError(); orig_err = virSaveLastError();
for (i = 0; i < snap->def->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
if (!diskdata[i].src) if (!diskdata[i].src)
continue; continue;
...@@ -15421,7 +15425,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15421,7 +15425,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
* stopped using them*/ * stopped using them*/
bool paused = virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING; 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) if (!diskdata[i].disk)
continue; continue;
...@@ -15442,7 +15446,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, ...@@ -15442,7 +15446,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
} }
cleanup: cleanup:
qemuDomainSnapshotDiskDataFree(diskdata, snap->def->ndisks, driver, vm); qemuDomainSnapshotDiskDataFree(diskdata, snapdef->ndisks, driver, vm);
virJSONValueFree(actions); virJSONValueFree(actions);
virObjectUnref(cfg); virObjectUnref(cfg);
...@@ -15466,7 +15470,8 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver, ...@@ -15466,7 +15470,8 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
int ret = -1; int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char *xml = NULL; 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; bool memory_unlink = false;
int thaw = 0; /* 1 if freeze succeeded, -1 if freeze failed */ int thaw = 0; /* 1 if freeze succeeded, -1 if freeze failed */
bool pmsuspended = false; bool pmsuspended = false;
...@@ -15557,16 +15562,16 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver, ...@@ -15557,16 +15562,16 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
if (!(xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, if (!(xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU,
true, true)) || true, true)) ||
!(snap->def->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm))) !(snapdef->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
goto cleanup; goto cleanup;
if (!(data = virQEMUSaveDataNew(xml, if (!(data = virQEMUSaveDataNew(xml,
(qemuDomainSaveCookiePtr) snap->def->cookie, (qemuDomainSaveCookiePtr) snapdef->cookie,
resume, compressed, driver->xmlopt))) resume, compressed, driver->xmlopt)))
goto cleanup; goto cleanup;
xml = NULL; xml = NULL;
if ((ret = qemuDomainSaveMemory(driver, vm, snap->def->file, data, if ((ret = qemuDomainSaveMemory(driver, vm, snapdef->file, data,
compressedpath, 0, compressedpath, 0,
QEMU_ASYNC_JOB_SNAPSHOT)) < 0) QEMU_ASYNC_JOB_SNAPSHOT)) < 0)
goto cleanup; goto cleanup;
...@@ -15641,7 +15646,7 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver, ...@@ -15641,7 +15646,7 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
VIR_FREE(compressedpath); VIR_FREE(compressedpath);
virObjectUnref(cfg); virObjectUnref(cfg);
if (memory_unlink && ret < 0) if (memory_unlink && ret < 0)
unlink(snap->def->file); unlink(snapdef->file);
return ret; return ret;
} }
...@@ -15857,7 +15862,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -15857,7 +15862,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
current = virDomainSnapshotGetCurrent(vm->snapshots); current = virDomainSnapshotGetCurrent(vm->snapshots);
if (current) { if (current) {
if (!redefine && if (!redefine &&
VIR_STRDUP(snap->def->common.parent, current->def->common.name) < 0) VIR_STRDUP(snap->def->parent, current->def->name) < 0)
goto endjob; goto endjob;
if (update_current) { if (update_current) {
virDomainSnapshotSetCurrent(vm->snapshots, NULL); virDomainSnapshotSetCurrent(vm->snapshots, NULL);
...@@ -15875,7 +15880,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -15875,7 +15880,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
* snapshot name in at least one of the domain's disks? */ * snapshot name in at least one of the domain's disks? */
} else if (virDomainObjIsActive(vm)) { } else if (virDomainObjIsActive(vm)) {
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY || 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 */ /* external full system or disk snapshot */
if (qemuDomainSnapshotCreateActiveExternal(driver, if (qemuDomainSnapshotCreateActiveExternal(driver,
vm, snap, flags) < 0) vm, snap, flags) < 0)
...@@ -15906,7 +15911,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -15906,7 +15911,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
* do; we've successfully taken the snapshot, and we are now running * do; we've successfully taken the snapshot, and we are now running
* on it, so we have to go forward the best we can * 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: endjob:
if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) {
...@@ -15921,11 +15926,11 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -15921,11 +15926,11 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
snapshot = NULL; snapshot = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to save metadata for snapshot %s"), _("unable to save metadata for snapshot %s"),
snap->def->common.name); snap->def->name);
virDomainSnapshotObjListRemove(vm->snapshots, snap); virDomainSnapshotObjListRemove(vm->snapshots, snap);
} else { } else {
other = virDomainSnapshotFindByName(vm->snapshots, other = virDomainSnapshotFindByName(vm->snapshots,
snap->def->common.parent); snap->def->parent);
virDomainSnapshotSetParent(snap, other); virDomainSnapshotSetParent(snap, other);
} }
} else if (snap) { } else if (snap) {
...@@ -16135,7 +16140,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain, ...@@ -16135,7 +16140,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
if (!(snap = qemuSnapObjFromName(vm, name))) if (!(snap = qemuSnapObjFromName(vm, name)))
goto cleanup; goto cleanup;
snapshot = virGetDomainSnapshot(domain, snap->def->common.name); snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -16185,14 +16190,14 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, ...@@ -16185,14 +16190,14 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot))) if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
goto cleanup; goto cleanup;
if (!snap->def->common.parent) { if (!snap->def->parent) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("snapshot '%s' does not have a parent"), _("snapshot '%s' does not have a parent"),
snap->def->common.name); snap->def->name);
goto cleanup; goto cleanup;
} }
parent = virGetDomainSnapshot(snapshot->domain, snap->def->common.parent); parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -16252,7 +16257,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, ...@@ -16252,7 +16257,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virUUIDFormat(snapshot->domain->uuid, uuidstr); virUUIDFormat(snapshot->domain->uuid, uuidstr);
xml = virDomainSnapshotDefFormat(uuidstr, snap->def, xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap),
driver->caps, driver->xmlopt, driver->caps, driver->xmlopt,
virDomainSnapshotFormatConvertXMLFlags(flags)); virDomainSnapshotFormatConvertXMLFlags(flags));
...@@ -16340,6 +16345,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16340,6 +16345,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
int ret = -1; int ret = -1;
virDomainSnapshotObjPtr snap = NULL; virDomainSnapshotObjPtr snap = NULL;
virDomainSnapshotObjPtr current = NULL; virDomainSnapshotObjPtr current = NULL;
virDomainSnapshotDefPtr snapdef;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL; virObjectEventPtr event2 = NULL;
int detail; int detail;
...@@ -16398,10 +16404,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16398,10 +16404,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot))) if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
goto endjob; goto endjob;
snapdef = virDomainSnapshotObjGetDef(snap);
if (!vm->persistent && if (!vm->persistent &&
snap->def->state != VIR_DOMAIN_SNAPSHOT_RUNNING && snapdef->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
snap->def->state != VIR_DOMAIN_SNAPSHOT_PAUSED && snapdef->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) { VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
...@@ -16417,15 +16424,15 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16417,15 +16424,15 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
} }
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) { if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
if (!snap->def->common.dom) { if (!snap->def->dom) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
_("snapshot '%s' lacks domain '%s' rollback info"), _("snapshot '%s' lacks domain '%s' rollback info"),
snap->def->common.name, vm->def->name); snap->def->name, vm->def->name);
goto endjob; goto endjob;
} }
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
!(snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING || !(snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) && snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) { VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s", virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
...@@ -16450,16 +16457,16 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16450,16 +16457,16 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
* *
* XXX Should domain snapshots track live xml rather * XXX Should domain snapshots track live xml rather
* than inactive xml? */ * than inactive xml? */
if (snap->def->common.dom) { if (snap->def->dom) {
config = virDomainDefCopy(snap->def->common.dom, caps, config = virDomainDefCopy(snap->def->dom, caps,
driver->xmlopt, NULL, true); driver->xmlopt, NULL, true);
if (!config) if (!config)
goto endjob; 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_RUNNING:
case VIR_DOMAIN_SNAPSHOT_PAUSED: case VIR_DOMAIN_SNAPSHOT_PAUSED:
...@@ -16557,7 +16564,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16557,7 +16564,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (qemuDomainObjEnterMonitorAsync(driver, vm, if (qemuDomainObjEnterMonitorAsync(driver, vm,
QEMU_ASYNC_JOB_START) < 0) QEMU_ASYNC_JOB_START) < 0)
goto endjob; goto endjob;
rc = qemuMonitorLoadSnapshot(priv->mon, snap->def->common.name); rc = qemuMonitorLoadSnapshot(priv->mon, snap->def->name);
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto endjob; goto endjob;
if (rc < 0) { if (rc < 0) {
...@@ -16600,7 +16607,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16600,7 +16607,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
/* Touch up domain state. */ /* Touch up domain state. */
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) && 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))) { (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
/* Transitions 3, 6, 9 */ /* Transitions 3, 6, 9 */
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
...@@ -16709,7 +16716,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -16709,7 +16716,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid target domain state '%s'. Refusing " _("Invalid target domain state '%s'. Refusing "
"snapshot reversion"), "snapshot reversion"),
virDomainSnapshotStateTypeToString(snap->def->state)); virDomainSnapshotStateTypeToString(snapdef->state));
goto endjob; goto endjob;
} }
...@@ -16774,10 +16781,10 @@ qemuDomainSnapshotReparentChildren(void *payload, ...@@ -16774,10 +16781,10 @@ qemuDomainSnapshotReparentChildren(void *payload,
if (rep->err < 0) if (rep->err < 0)
return 0; return 0;
VIR_FREE(snap->def->common.parent); VIR_FREE(snap->def->parent);
if (rep->parent->def && 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; rep->err = -1;
return 0; return 0;
} }
...@@ -16858,7 +16865,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, ...@@ -16858,7 +16865,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
cfg->snapshotDir) < 0) { cfg->snapshotDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to set snapshot '%s' as current"), _("failed to set snapshot '%s' as current"),
snap->def->common.name); snap->def->name);
virDomainSnapshotSetCurrent(vm->snapshots, NULL); virDomainSnapshotSetCurrent(vm->snapshots, NULL);
goto endjob; goto endjob;
} }
......
...@@ -6132,7 +6132,7 @@ testDomainSnapshotLookupByName(virDomainPtr domain, ...@@ -6132,7 +6132,7 @@ testDomainSnapshotLookupByName(virDomainPtr domain,
if (!(snap = testSnapObjFromName(vm, name))) if (!(snap = testSnapObjFromName(vm, name)))
goto cleanup; goto cleanup;
snapshot = virGetDomainSnapshot(domain, snap->def->common.name); snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -6173,14 +6173,14 @@ testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, ...@@ -6173,14 +6173,14 @@ testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
if (!(snap = testSnapObjFromSnapshot(vm, snapshot))) if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
goto cleanup; goto cleanup;
if (!snap->def->common.parent) { if (!snap->def->parent) {
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
_("snapshot '%s' does not have a parent"), _("snapshot '%s' does not have a parent"),
snap->def->common.name); snap->def->name);
goto cleanup; goto cleanup;
} }
parent = virGetDomainSnapshot(snapshot->domain, snap->def->common.parent); parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -6207,7 +6207,7 @@ testDomainSnapshotCurrent(virDomainPtr domain, ...@@ -6207,7 +6207,7 @@ testDomainSnapshotCurrent(virDomainPtr domain,
goto cleanup; goto cleanup;
} }
snapshot = virGetDomainSnapshot(domain, current->def->common.name); snapshot = virGetDomainSnapshot(domain, current->def->name);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -6234,8 +6234,8 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, ...@@ -6234,8 +6234,8 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virUUIDFormat(snapshot->domain->uuid, uuidstr); virUUIDFormat(snapshot->domain->uuid, uuidstr);
xml = virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->caps, xml = virDomainSnapshotDefFormat(uuidstr, virDomainSnapshotObjGetDef(snap),
privconn->xmlopt, privconn->caps, privconn->xmlopt,
virDomainSnapshotFormatConvertXMLFlags(flags)); virDomainSnapshotFormatConvertXMLFlags(flags));
cleanup: cleanup:
...@@ -6394,7 +6394,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -6394,7 +6394,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
} }
if (!redefine) { if (!redefine) {
if (VIR_STRDUP(snap->def->common.parent, if (VIR_STRDUP(snap->def->parent,
virDomainSnapshotGetCurrentName(vm->snapshots)) < 0) virDomainSnapshotGetCurrentName(vm->snapshots)) < 0)
goto cleanup; goto cleanup;
...@@ -6407,7 +6407,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -6407,7 +6407,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
} }
} }
snapshot = virGetDomainSnapshot(domain, snap->def->common.name); snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup: cleanup:
if (vm) { if (vm) {
if (snapshot) { if (snapshot) {
...@@ -6415,7 +6415,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -6415,7 +6415,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
if (update_current) if (update_current)
virDomainSnapshotSetCurrent(vm->snapshots, snap); virDomainSnapshotSetCurrent(vm->snapshots, snap);
other = virDomainSnapshotFindByName(vm->snapshots, other = virDomainSnapshotFindByName(vm->snapshots,
snap->def->common.parent); snap->def->parent);
virDomainSnapshotSetParent(snap, other); virDomainSnapshotSetParent(snap, other);
} }
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
...@@ -6464,10 +6464,10 @@ testDomainSnapshotReparentChildren(void *payload, ...@@ -6464,10 +6464,10 @@ testDomainSnapshotReparentChildren(void *payload,
if (rep->err < 0) if (rep->err < 0)
return 0; return 0;
VIR_FREE(snap->def->common.parent); VIR_FREE(snap->def->parent);
if (rep->parent->def && 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; rep->err = -1;
return 0; return 0;
} }
...@@ -6522,12 +6522,12 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot, ...@@ -6522,12 +6522,12 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
} else { } else {
virDomainSnapshotDropParent(snap); virDomainSnapshotDropParent(snap);
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) { if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
if (snap->def->common.parent) { if (snap->def->parent) {
parentsnap = virDomainSnapshotFindByName(vm->snapshots, parentsnap = virDomainSnapshotFindByName(vm->snapshots,
snap->def->common.parent); snap->def->parent);
if (!parentsnap) if (!parentsnap)
VIR_WARN("missing parent snapshot matching name '%s'", VIR_WARN("missing parent snapshot matching name '%s'",
snap->def->common.parent); snap->def->parent);
} }
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
} }
...@@ -6550,6 +6550,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -6550,6 +6550,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
virObjectEventPtr event2 = NULL; virObjectEventPtr event2 = NULL;
virDomainDefPtr config = NULL; virDomainDefPtr config = NULL;
virDomainSnapshotDefPtr snapdef;
int ret = -1; int ret = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
...@@ -6575,10 +6576,11 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -6575,10 +6576,11 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(snap = testSnapObjFromSnapshot(vm, snapshot))) if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
goto cleanup; goto cleanup;
snapdef = virDomainSnapshotObjGetDef(snap);
if (!vm->persistent && if (!vm->persistent &&
snap->def->state != VIR_DOMAIN_SNAPSHOT_RUNNING && snapdef->state != VIR_DOMAIN_SNAPSHOT_RUNNING &&
snap->def->state != VIR_DOMAIN_SNAPSHOT_PAUSED && snapdef->state != VIR_DOMAIN_SNAPSHOT_PAUSED &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) { VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) == 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
...@@ -6588,15 +6590,15 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -6588,15 +6590,15 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
} }
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) { if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
if (!snap->def->common.dom) { if (!snap->def->dom) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
_("snapshot '%s' lacks domain '%s' rollback info"), _("snapshot '%s' lacks domain '%s' rollback info"),
snap->def->common.name, vm->def->name); snap->def->name, vm->def->name);
goto cleanup; goto cleanup;
} }
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
!(snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING || !(snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) && snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) &&
(flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) { VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s", virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
...@@ -6607,13 +6609,13 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -6607,13 +6609,13 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virDomainSnapshotSetCurrent(vm->snapshots, NULL); virDomainSnapshotSetCurrent(vm->snapshots, NULL);
config = virDomainDefCopy(snap->def->common.dom, privconn->caps, config = virDomainDefCopy(snap->def->dom, privconn->caps,
privconn->xmlopt, NULL, true); privconn->xmlopt, NULL, true);
if (!config) if (!config)
goto cleanup; goto cleanup;
if (snap->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING || if (snapdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
snap->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) { snapdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) {
/* Transitions 2, 3, 5, 6, 8, 9 */ /* Transitions 2, 3, 5, 6, 8, 9 */
bool was_running = false; bool was_running = false;
bool was_stopped = false; bool was_stopped = false;
...@@ -6672,7 +6674,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -6672,7 +6674,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
/* Touch up domain state. */ /* Touch up domain state. */
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) && 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))) { (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
/* Transitions 3, 6, 9 */ /* Transitions 3, 6, 9 */
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册