When domain was started its transient definition was not saved on disk, this led to the situation when CH driver dies and starts again, all transient definitions of currently running domains had been lost.
Newly all transient definitions of running domains are saved on disk and can be loaded during the CH driver initialization. Transient definitions are also removed when domain stops. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/743 Signed-off-by: Kirill Shchetiniuk <kshch...@redhat.com> --- src/ch/ch_domain.c | 15 +++++++++++++++ src/ch/ch_domain.h | 3 +++ src/ch/ch_driver.c | 8 ++++++++ src/ch/ch_process.c | 25 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index c0c9acd85b..4c9ed93b15 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -414,3 +414,18 @@ virCHDomainValidateActualNetDef(virDomainNetDef *net) return 0; } + +void +virCHDomainSaveStatus(virDomainObj *vm) +{ + virCHDomainObjPrivate *priv = vm->privateData; + virCHDriver *driver = priv->driver; + g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver); + + VIR_DEBUG("Saving status on vm %s", vm->def->name); + + if (virDomainObjIsActive(vm)) { + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) + VIR_WARN("Failed to save status on vm %s", vm->def->name); + } +} diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 69a657f6af..1a43049f91 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -79,3 +79,6 @@ virCHDomainObjFromDomain(virDomainPtr domain); int virCHDomainValidateActualNetDef(virDomainNetDef *net); + +void +virCHDomainSaveStatus(virDomainObj *vm); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index c7f357dac9..4ce68c9299 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1473,6 +1473,14 @@ chStateInitialize(bool privileged, goto cleanup; } + /* Transient domains load */ + if (virDomainObjListLoadAllConfigs(ch_driver->domains, + cfg->stateDir, + NULL, true, + ch_driver->xmlopt, + NULL, NULL) < 0) + goto cleanup; + /* Persistent domains load */ if (virDomainObjListLoadAllConfigs(ch_driver->domains, cfg->configDir, diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 31aa49b3a5..08331352a4 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -995,6 +995,8 @@ virCHProcessStart(virCHDriver *driver, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); + virCHDomainSaveStatus(vm); + return 0; cleanup: @@ -1004,6 +1006,25 @@ virCHProcessStart(virCHDriver *driver, return ret; } +static void +virCHProcessRemoveDomainStatus(virCHDriver *driver, + virDomainObj *vm) +{ + g_autofree char *file = NULL; + virCHDomainObjPrivate *priv = vm->privateData; + g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver); + + file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name); + + if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) + VIR_WARN("Failed to remove domain status XML for %s: %s", + vm->def->name, g_strerror(errno)); + + if (priv->pidfile && unlink(priv->pidfile) && errno != ENOENT) + VIR_WARN("Failed to remove PID file for %s: %s", + vm->def->name, g_strerror(errno)); +} + int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, @@ -1056,6 +1077,10 @@ virCHProcessStop(virCHDriver *driver, virHostdevReAttachDomainDevices(driver->hostdevMgr, CH_DRIVER_NAME, def, hostdev_flags); + virDomainObjRemoveTransientDef(vm); + + virCHProcessRemoveDomainStatus(driver, vm); + virErrorRestore(&orig_err); return 0; } -- 2.48.1