Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/qemu/qemu_snapshot.c | 61 ++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index ce16236224..d22f0522ed 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1715,6 +1715,48 @@ qemuSnapshotCreateWriteMetadata(virDomainObj *vm, } +static virDomainSnapshotPtr +qemuSnapshotRedefine(virDomainObj *vm, + virDomainPtr domain, + virDomainSnapshotDef *def, + virQEMUDriver *driver, + virQEMUDriverConfig *cfg, + unsigned int flags) +{ + virDomainMomentObj *snap = NULL; + virDomainSnapshotPtr ret = NULL; + + if (virDomainSnapshotRedefinePrep(vm, &def, &snap, + driver->xmlopt, + flags) < 0) + return NULL; + + if (!snap) { + if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def))) + return NULL; + } + /* XXX Should we validate that the redefined snapshot even + * makes sense, such as checking that qemu-img recognizes the + * snapshot name in at least one of the domain's disks? */ + + if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT) + qemuSnapshotSetCurrent(vm, snap); + + if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) + goto error; + + ret = virGetDomainSnapshot(domain, snap->def->name); + if (!ret) + goto error; + + return ret; + + error: + virDomainSnapshotObjListRemove(vm->snapshots, snap); + return NULL; +} + + virDomainSnapshotPtr qemuSnapshotCreateXML(virDomainPtr domain, virDomainObj *vm, @@ -1772,15 +1814,8 @@ qemuSnapshotCreateXML(virDomainPtr domain, qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE); if (redefine) { - if (virDomainSnapshotRedefinePrep(vm, &def, &snap, - driver->xmlopt, - flags) < 0) - goto endjob; - - if (!snap) { - if (!(snap = virDomainSnapshotAssignDef(vm->snapshots, def))) - goto endjob; - } + snapshot = qemuSnapshotRedefine(vm, domain, def, driver, cfg, flags); + goto endjob; } else { virDomainMomentObj *current = NULL; @@ -1802,11 +1837,7 @@ qemuSnapshotCreateXML(virDomainPtr domain, } /* actually do the snapshot */ - if (redefine) { - /* XXX Should we validate that the redefined snapshot even - * makes sense, such as checking that qemu-img recognizes the - * snapshot name in at least one of the domain's disks? */ - } else if (virDomainObjIsActive(vm)) { + if (virDomainObjIsActive(vm)) { if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY || virDomainSnapshotObjGetDef(snap)->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { /* external full system or disk snapshot */ @@ -1840,7 +1871,7 @@ qemuSnapshotCreateXML(virDomainPtr domain, goto endjob; if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { - if (!redefine || (flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) + if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) qemuSnapshotSetCurrent(vm, snap); if (qemuSnapshotCreateWriteMetadata(vm, snap, driver, cfg) < 0) { -- 2.31.1