1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemu: prepare cleanup for <transient/> disk overlays

Later patches will implement support for <transient/> disks in libvirt
by installing an overlay on top of the configured image. This will
require cleanup after the VM will be stopped so that the state is
correctly discarded.

Since the overlay will be installed only during the startup phase of the
VM we need to ensure that qemuProcessStop doesn't delete the original
file on some previous failure. This is solved by adding
'inhibitDiskTransientDelete' VM private data member which is set prior
to any startup step and will be cleared once transient disk overlays are
established.

Based on that we can then delete the overlays for any <transient/> disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-09-22 14:39:27 +02:00
parent 797ee40b21
commit afc25e8553
3 changed files with 28 additions and 0 deletions

View File

@ -1792,6 +1792,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
priv->dbusVMStateIds = NULL;
priv->dbusVMState = false;
priv->inhibitDiskTransientDelete = false;
}

View File

@ -263,6 +263,10 @@ struct _qemuDomainObjPrivate {
char **dbusVMStateIds;
/* true if -object dbus-vmstate was added */
bool dbusVMState;
/* prevent deletion of <transient> disk overlay files between startup and
* succesful setup of the overlays */
bool inhibitDiskTransientDelete;
};
#define QEMU_DOMAIN_PRIVATE(vm) \

View File

@ -5616,6 +5616,9 @@ qemuProcessInit(virQEMUDriverPtr driver,
if (virDomainObjSetDefTransient(driver->xmlopt, vm, priv->qemuCaps) < 0)
goto cleanup;
/* don't clean up files for <transient> disks until we set them up */
priv->inhibitDiskTransientDelete = true;
if (flags & VIR_QEMU_PROCESS_START_PRETEND) {
if (qemuDomainSetPrivatePaths(driver, vm) < 0) {
virDomainObjRemoveTransientDef(vm);
@ -7710,6 +7713,18 @@ void qemuProcessStop(virQEMUDriverPtr driver,
}
qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->src);
/* for now transient disks are forbidden with migration so they
* can be handled here */
if (disk->transient &&
!priv->inhibitDiskTransientDelete) {
VIR_DEBUG("Removing transient overlay '%s' of disk '%s'",
disk->src->path, disk->dst);
if (qemuDomainStorageFileInit(driver, vm, disk->src, NULL) >= 0) {
virStorageFileUnlink(disk->src);
virStorageFileDeinit(disk->src);
}
}
}
}
@ -8125,6 +8140,10 @@ qemuProcessReconnect(void *opaque)
cfg = virQEMUDriverGetConfig(driver);
priv = obj->privateData;
/* expect that libvirt might have crashed during VM start, so prevent
* cleanup of transient disks */
priv->inhibitDiskTransientDelete = true;
if (qemuDomainObjBeginJob(driver, obj, QEMU_JOB_MODIFY) < 0)
goto error;
jobStarted = true;
@ -8228,6 +8247,9 @@ qemuProcessReconnect(void *opaque)
goto error;
}
/* vm startup complete, we can remove transient disks if required */
priv->inhibitDiskTransientDelete = false;
/* In case the domain shutdown while we were not running,
* we need to finish the shutdown process. And we need to do it after
* we have virQEMUCaps filled in.