From 36080e1b57026c7e1a580278966d2dee3e56bebf Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 18 Oct 2024 16:13:15 +0200 Subject: [PATCH] qemu: snapshot: Delete leftover overlay files for disks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé --- src/qemu/qemu_snapshot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1187ebf276..795522da21 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -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);