Adding this was trivial compared to the previous patch for fixing
qemu snapshot deletion in the first place.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDiscard): Add
parameter.
(qemuDomainSnapshotDiscardDescendant, qemuDomainSnapshotDelete):
Update callers.
---
src/qemu/qemu_driver.c | 78 ++++++++++++++++++++++++++---------------------
1 files changed, 43 insertions(+), 35 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5101167..3b59a35 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8942,7 +8942,8 @@ cleanup:
static int qemuDomainSnapshotDiscard(struct qemud_driver *driver,
virDomainObjPtr vm,
- virDomainSnapshotObjPtr snap)
+ virDomainSnapshotObjPtr snap,
+ bool metadata_only)
{
const char *qemuimgarg[] = { NULL, "snapshot", "-d", NULL, NULL,
NULL };
char *snapFile = NULL;
@@ -8951,41 +8952,43 @@ static int qemuDomainSnapshotDiscard(struct qemud_driver *driver,
qemuDomainObjPrivatePtr priv;
virDomainSnapshotObjPtr parentsnap = NULL;
- if (!virDomainObjIsActive(vm)) {
- qemuimgarg[0] = qemuFindQemuImgBinary();
- if (qemuimgarg[0] == NULL)
- /* qemuFindQemuImgBinary set the error */
- goto cleanup;
-
- qemuimgarg[3] = snap->def->name;
-
- for (i = 0; i < vm->def->ndisks; i++) {
- /* FIXME: we also need to handle LVM here */
- if (vm->def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
- if (!vm->def->disks[i]->driverType ||
- STRNEQ(vm->def->disks[i]->driverType, "qcow2")) {
- /* we continue on even in the face of error, since other
- * disks in this VM may have this snapshot in place
- */
- continue;
- }
-
- qemuimgarg[4] = vm->def->disks[i]->src;
+ if (!metadata_only) {
+ if (!virDomainObjIsActive(vm)) {
+ qemuimgarg[0] = qemuFindQemuImgBinary();
+ if (qemuimgarg[0] == NULL)
+ /* qemuFindQemuImgBinary set the error */
+ goto cleanup;
- if (virRun(qemuimgarg, NULL) < 0) {
- /* we continue on even in the face of error, since other
- * disks in this VM may have this snapshot in place
- */
- continue;
+ qemuimgarg[3] = snap->def->name;
+
+ for (i = 0; i < vm->def->ndisks; i++) {
+ /* FIXME: we also need to handle LVM here */
+ if (vm->def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+ if (!vm->def->disks[i]->driverType ||
+ STRNEQ(vm->def->disks[i]->driverType,
"qcow2")) {
+ /* we continue on even in the face of error, since other
+ * disks in this VM may have this snapshot in place
+ */
+ continue;
+ }
+
+ qemuimgarg[4] = vm->def->disks[i]->src;
+
+ if (virRun(qemuimgarg, NULL) < 0) {
+ /* we continue on even in the face of error, since other
+ * disks in this VM may have this snapshot in place
+ */
+ continue;
+ }
}
}
+ } else {
+ priv = vm->privateData;
+ qemuDomainObjEnterMonitorWithDriver(driver, vm);
+ /* we continue on even in the face of error */
+ qemuMonitorDeleteSnapshot(priv->mon, snap->def->name);
+ qemuDomainObjExitMonitorWithDriver(driver, vm);
}
- } else {
- priv = vm->privateData;
- qemuDomainObjEnterMonitorWithDriver(driver, vm);
- /* we continue on even in the face of error */
- qemuMonitorDeleteSnapshot(priv->mon, snap->def->name);
- qemuDomainObjExitMonitorWithDriver(driver, vm);
}
if (virAsprintf(&snapFile, "%s/%s/%s.xml", driver->snapshotDir,
@@ -9031,6 +9034,7 @@ cleanup:
struct snap_remove {
struct qemud_driver *driver;
virDomainObjPtr vm;
+ bool metadata_only;
int err;
};
@@ -9043,7 +9047,8 @@ qemuDomainSnapshotDiscardDescendant(void *payload,
struct snap_remove *curr = data;
int err;
- err = qemuDomainSnapshotDiscard(curr->driver, curr->vm, snap);
+ err = qemuDomainSnapshotDiscard(curr->driver, curr->vm, snap,
+ curr->metadata_only);
if (err && !curr->err)
curr->err = err;
}
@@ -9093,8 +9098,10 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
char uuidstr[VIR_UUID_STRING_BUFLEN];
struct snap_remove rem;
struct snap_reparent rep;
+ bool metadata_only = !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY);
- virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
+ VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
qemuDriverLock(driver);
virUUIDFormat(snapshot->domain->uuid, uuidstr);
@@ -9119,6 +9126,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) {
rem.driver = driver;
rem.vm = vm;
+ rem.metadata_only = metadata_only;
rem.err = 0;
virDomainSnapshotForEachDescendant(&vm->snapshots,
snap,
@@ -9138,7 +9146,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
goto endjob;
}
- ret = qemuDomainSnapshotDiscard(driver, vm, snap);
+ ret = qemuDomainSnapshotDiscard(driver, vm, snap, metadata_only);
endjob:
if (qemuDomainObjEndJob(driver, vm) == 0)
--
1.7.4.4