*
* Delete the snapshot.
*
- * If @flags is 0, then just this snapshot is deleted, and changes from
- * this snapshot are automatically merged into children snapshots. If
- * @flags includes VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, then this snapshot
- * and any children snapshots are deleted. If @flags includes
- * VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, then any snapshot metadata
- * tracked by libvirt is removed while keeping the snapshot contents
- * intact; if a hypervisor does not require any libvirt metadata to
- * track snapshots, then this flag is silently ignored.
+ * If @flags is 0, then just this snapshot is deleted, and changes
+ * from this snapshot are automatically merged into children
+ * snapshots. If @flags includes VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN,
+ * then this snapshot and any descendant snapshots are deleted. If
+ * @flags includes VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, then any
+ * descendant snapshots are deleted, but this snapshot remains. These
+ * two flags are mutually exclusive.
+ *
+ * If @flags includes VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, then
+ * any snapshot metadata tracked by libvirt is removed while keeping
+ * the snapshot contents intact; if a hypervisor does not require any
+ * libvirt metadata to track snapshots, then this flag is silently
+ * ignored.
*
- * Returns 0 if the snapshot was successfully deleted, -1 on error.
+ * Returns 0 if the selected snapshot(s) were successfully deleted,
+ * -1 on error.
*/
int
virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
goto error;
}
+ if ((flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) &&
+ (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
+ virLibDomainError(VIR_ERR_INVALID_ARG,
+ _("children and children_only flags are "
+ "mutually exclusive"));
+ goto error;
+ }
+
if (conn->driver->domainSnapshotDelete) {
int ret = conn->driver->domainSnapshotDelete(snapshot, flags);
if (ret < 0)
bool metadata_only = !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY);
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
- VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
+ VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, -1);
qemuDriverLock(driver);
virUUIDFormat(snapshot->domain->uuid, uuidstr);
if (qemuDomainObjBeginJobWithDriver(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
- if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) {
+ if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
rem.driver = driver;
rem.vm = vm;
rem.metadata_only = metadata_only;
&rem);
if (rem.err < 0)
goto endjob;
- if (rem.current)
+ if (rem.current) {
+ if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) {
+ snap->def->current = true;
+ if (qemuDomainSnapshotWriteMetadata(vm, snap,
+ driver->snapshotDir) < 0) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to set snapshot '%s' as current"),
+ snap->def->name);
+ snap->def->current = false;
+ goto endjob;
+ }
+ }
vm->current_snapshot = snap;
+ }
} else {
rep.driver = driver;
rep.parent = snap->def->parent;
goto endjob;
}
- ret = qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only);
+ if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)
+ ret = 0;
+ else
+ ret = qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only);
endjob:
if (qemuDomainObjEndJob(driver, vm) == 0)