]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: snapshot: Delete leftover overlay files for <transient/> disks
authorPeter Krempa <pkrempa@redhat.com>
Fri, 18 Oct 2024 14:13:15 +0000 (16:13 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 Oct 2024 06:15:36 +0000 (08:15 +0200)
When a VM is terminated by host reboot libvirt doesn't get to cleaning
out the temporary overlay file used for transient disks. Since we create
those files with a very specific suffix it's almost guaranteed that if
it exists it's a leftover from a libvirt run. Delete them instead of
complaining to preserve functionality.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/684
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_snapshot.c

index 1187ebf276b33ccefd128379a484d6848a80f849..795522da21548e57cfd0705482c3fa0d95e935c4 100644 (file)
@@ -1287,10 +1287,12 @@ qemuSnapshotGetTransientDiskDef(virDomainDiskDef *domdisk,
                                           domdisk->src->path, suffix);
 
     if (virFileExists(snapdisk->src->path)) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
-                       _("Overlay file '%1$s' for transient disk '%2$s' already exists"),
-                       snapdisk->src->path, domdisk->dst);
-        return NULL;
+        if (unlink(snapdisk->src->path) != 0) {
+            virReportSystemError(errno,
+                                 _("Failed to delete overlay file '%1$s' for transient disk '%2$s'"),
+                                 snapdisk->src->path, domdisk->dst);
+            return NULL;
+        }
     }
 
     return g_steal_pointer(&snapdisk);