[libvirt PATCH] qemu_snapshot: fix reverting to inactive snapshot

Pavel Hrdina posted 1 patch 5 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/bb3bdf6e6539253a18c26fd6f01b43f7d587f9e4.1698844275.git.phrdina@redhat.com
src/qemu/qemu_snapshot.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
[libvirt PATCH] qemu_snapshot: fix reverting to inactive snapshot
Posted by Pavel Hrdina 5 months, 4 weeks ago
When reverting to inactive snapshot updating the domain definition needs
to happen after the new overlays are created otherwise qemu-img will
correctly fail with error:

    Trying to create an image with the same filename as the backing file

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_snapshot.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 1962ba4027..5fc0b82e79 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2157,13 +2157,20 @@ qemuSnapshotRevertExternalInactive(virDomainObj *vm,
 {
     virQEMUDriver *driver = QEMU_DOMAIN_PRIVATE(vm)->driver;
     g_autoptr(virBitmap) created = NULL;
+    int ret = -1;
 
     created = virBitmapNew(tmpsnapdef->ndisks);
 
+    if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0)
+        goto cleanup;
+
     if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0)
-        return -1;
+        goto cleanup;
 
-    if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0) {
+    ret = 0;
+
+ cleanup:
+    if (ret < 0 && created) {
         ssize_t bit = -1;
         virErrorPtr err = NULL;
 
@@ -2180,11 +2187,9 @@ qemuSnapshotRevertExternalInactive(virDomainObj *vm,
         }
 
         virErrorRestore(&err);
-
-        return -1;
     }
 
-    return 0;
+    return ret;
 }
 
 
-- 
2.41.0
Re: [libvirt PATCH] qemu_snapshot: fix reverting to inactive snapshot
Posted by Peter Krempa 5 months, 2 weeks ago
On Wed, Nov 01, 2023 at 14:11:35 +0100, Pavel Hrdina wrote:
> When reverting to inactive snapshot updating the domain definition needs
> to happen after the new overlays are created otherwise qemu-img will
> correctly fail with error:
> 
>     Trying to create an image with the same filename as the backing file
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/qemu/qemu_snapshot.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org