Refactor orgininal qemuDomainSnapshotDelete() into a common
function qemuDomainSnapshotDeleteImpl() which is used by both
APIs SnapshotDelete() and SnapshotDeleteByName()
---
src/qemu/qemu_driver.c | 103 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 81 insertions(+), 22 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f51e766..e494a8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13387,34 +13387,20 @@ qemuDomainSnapshotReparentChildren(void *payload,
rep->cfg->snapshotDir);
}
-
-static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
- unsigned int flags)
+static int
+qemuDomainSnapshotDeleteImpl(virQEMUDriverPtr driver,
+ virDomainObjPtr *vmptr,
+ virDomainSnapshotObjPtr snap,
+ unsigned int flags)
{
- virQEMUDriverPtr driver = snapshot->domain->conn->privateData;
- virDomainObjPtr vm = NULL;
+ virDomainObjPtr vm = *vmptr;
int ret = -1;
- virDomainSnapshotObjPtr snap = NULL;
virQEMUSnapRemove rem;
virQEMUSnapReparent rep;
bool metadata_only = !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY);
int external = 0;
- virQEMUDriverConfigPtr cfg = NULL;
-
- virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
- VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
- VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, -1);
-
- if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- return -1;
-
- cfg = virQEMUDriverGetConfig(driver);
-
- if (virDomainSnapshotDeleteEnsureACL(snapshot->domain->conn, vm->def) <
0)
- goto cleanup;
- if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
- goto cleanup;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (!metadata_only) {
if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
@@ -13492,9 +13478,81 @@ endjob:
vm = NULL;
cleanup:
+ virObjectUnref(cfg);
+ return ret;
+}
+
+static
+int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
+ unsigned int flags)
+{
+ virConnectPtr conn = snapshot->domain->conn;
+ virQEMUDriverPtr driver = conn->privateData;
+ virDomainObjPtr vm = NULL;
+ virDomainSnapshotObjPtr snap = NULL;
+ int ret = -1;
+
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, -1);
+
+ if (!(vm = qemuDomObjFromSnapshot(snapshot)))
+ return -1;
+
+ if (virDomainSnapshotDeleteEnsureACL(conn, vm->def) < 0)
+ goto cleanup;
+
+ if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
+ goto cleanup;
+
+ ret = qemuDomainSnapshotDeleteImpl(driver, &vm, snap, flags);
+
+cleanup:
+ if (vm)
+ virObjectUnlock(vm);
+ return ret;
+}
+
+static int
+qemuDomainSnapshotDeleteByName(virDomainPtr domain,
+ const char *name,
+ unsigned int flags)
+{
+ virConnectPtr conn = domain->conn;
+ virQEMUDriverPtr driver = conn->privateData;
+ virDomainObjPtr vm = NULL;
+ virDomainSnapshotObjPtr snap = NULL;
+ const char *snapname = name;
+ int ret = -1;
+
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY |
+ VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY, -1);
+
+ if (!(vm = qemuDomObjFromDomain(domain)))
+ goto cleanup;
+
+ if (virDomainSnapshotDeleteByNameEnsureACL(conn, vm->def) < 0)
+ goto cleanup;
+
+ if (name == NULL) {
+ if (!vm->current_snapshot) {
+ virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
+ _("the domain does not have a current snapshot"));
+ goto cleanup;
+ }
+
+ snapname = vm->current_snapshot->def->name;
+ }
+
+ if (!(snap = qemuSnapObjFromName(vm, snapname)))
+ goto cleanup;
+
+ ret = qemuDomainSnapshotDeleteImpl(driver, &vm, snap, flags);
+
+cleanup:
if (vm)
virObjectUnlock(vm);
- virObjectUnref(cfg);
return ret;
}
@@ -16012,6 +16070,7 @@ static virDriver qemuDriver = {
.domainSnapshotHasMetadata = qemuDomainSnapshotHasMetadata, /* 0.9.13 */
.domainRevertToSnapshot = qemuDomainRevertToSnapshot, /* 0.8.0 */
.domainSnapshotDelete = qemuDomainSnapshotDelete, /* 0.8.0 */
+ .domainSnapshotDeleteByName = qemuDomainSnapshotDeleteByName, /* 1.1.1 */
.domainQemuMonitorCommand = qemuDomainQemuMonitorCommand, /* 0.8.3 */
.domainQemuAttach = qemuDomainQemuAttach, /* 0.9.4 */
.domainQemuAgentCommand = qemuDomainQemuAgentCommand, /* 0.10.0 */
--
1.8.1.4