1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-30 18:50:18 +03:00

hypervisor: wire up support for auto restore of running domains

When performing auto-shutdown of running domains, there is now the
option to mark them as "autostart once",  so that their state is
restored on next boot. This applies on top of the traditional
autostart flag.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2024-12-20 11:38:01 +00:00
parent c6018e5f87
commit 602f2e60ca
2 changed files with 18 additions and 2 deletions

View File

@ -739,12 +739,12 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
virDomainPtr *domains = NULL;
g_autofree bool *transient = NULL;
VIR_DEBUG("Run autoshutdown uri=%s trySave=%s tryShutdown=%s poweroff=%s waitShutdownSecs=%u saveBypassCache=%d",
VIR_DEBUG("Run autoshutdown uri=%s trySave=%s tryShutdown=%s poweroff=%s waitShutdownSecs=%u saveBypassCache=%d autoRestore=%d",
cfg->uri,
virDomainDriverAutoShutdownScopeTypeToString(cfg->trySave),
virDomainDriverAutoShutdownScopeTypeToString(cfg->tryShutdown),
virDomainDriverAutoShutdownScopeTypeToString(cfg->poweroff),
cfg->waitShutdownSecs, cfg->saveBypassCache);
cfg->waitShutdownSecs, cfg->saveBypassCache, cfg->autoRestore);
/*
* Ideally guests will shutdown in a few seconds, but it would
@ -793,6 +793,21 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
for (i = 0; i < numDomains; i++) {
if (virDomainIsPersistent(domains[i]) == 0)
transient[i] = true;
if (cfg->autoRestore) {
if (transient[i]) {
VIR_DEBUG("Cannot auto-restore transient VM %s",
virDomainGetName(domains[i]));
} else {
VIR_DEBUG("Mark %s for autostart on next boot",
virDomainGetName(domains[i]));
if (virDomainSetAutostartOnce(domains[i], 1) < 0) {
VIR_WARN("Unable to mark domain '%s' for auto restore: %s",
virDomainGetName(domains[i]),
virGetLastErrorMessage());
}
}
}
}
if (cfg->trySave != VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) {

View File

@ -113,6 +113,7 @@ typedef struct _virDomainDriverAutoShutdownConfig {
* If 0 a default is used (currently 30 secs)
*/
bool saveBypassCache;
bool autoRestore;
} virDomainDriverAutoShutdownConfig;
void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg);