ch_driver: cleanup any stale managed save dir before VM creation

There are chances that libvirt process is killed and it resulting in
stale managed save dirs. So check for it, and cleanup it there's any.

Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Purna Pavan Chandra Aekkaladevi 2024-03-11 09:44:04 +00:00 committed by Michal Privoznik
parent 53ec0fd09d
commit f2d54f42d5

View File

@ -206,6 +206,7 @@ chDomainCreateXML(virConnectPtr conn,
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
g_autofree char *managed_save_path = NULL;
virCheckFlags(VIR_DOMAIN_START_VALIDATE, NULL);
@ -228,6 +229,15 @@ chDomainCreateXML(virConnectPtr conn,
NULL)))
goto cleanup;
/* cleanup if there's any stale managedsave dir */
managed_save_path = chDomainManagedSavePath(driver, vm);
if (virFileDeleteTree(managed_save_path) < 0) {
virReportSystemError(errno,
_("Failed to cleanup stale managed save dir '%1$s'"),
managed_save_path);
goto cleanup;
}
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
goto cleanup;
@ -315,6 +325,7 @@ chDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
g_autofree char *managed_save_path = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
@ -337,6 +348,15 @@ chDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
0, NULL)))
goto cleanup;
/* cleanup if there's any stale managedsave dir */
managed_save_path = chDomainManagedSavePath(driver, vm);
if (virFileDeleteTree(managed_save_path) < 0) {
virReportSystemError(errno,
_("Failed to cleanup stale managed save dir '%1$s'"),
managed_save_path);
goto cleanup;
}
vm->persistent = 1;
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);