[PATCHv2 11/26] snapshot: let qemu discard only snapshot metadata

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 9134fc3..568cb37 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8934,7 +8934,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;
@@ -8943,41 +8944,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,
@@ -9023,6 +9026,7 @@ cleanup:
 struct snap_remove {
     struct qemud_driver *driver;
     virDomainObjPtr vm;
+    bool metadata_only;
     int err;
 };

@@ -9035,7 +9039,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;
 }
@@ -9085,8 +9090,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);
@@ -9111,6 +9118,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,
@@ -9130,7 +9138,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]