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

hypervisor: emit systemd status & log messages while saving

Since processing running VMs on OS shutdown can take a while, it is
beneficial to send systemd status messages about the progress.

The systemd status is a point-in-time message, with no ability to
look at the history of received messages. So in the systemd status
we include the progress information. For the same reason there is
no benefit in sending failure messages, as they'll disappear as soon
as a status is sent for the subsequent VM to be processed.

The libvirt log statements can be viewed as a complete log record
so don't need progress info, but do include warnings about failures
(present from earlier commits).

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2025-01-07 15:25:33 +00:00
parent 364977b94a
commit 563d3cfb86

View File

@ -30,6 +30,7 @@
#include "datatypes.h"
#include "driver.h"
#include "virlog.h"
#include "virsystemd.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN
@ -819,6 +820,10 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
(!transient[i] && cfg->trySave == VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT))
continue;
virSystemdNotifyStatus("Suspending '%s' (%zu of %d)",
virDomainGetName(domains[i]), i + 1, numDomains);
VIR_INFO("Suspending '%s'", virDomainGetName(domains[i]));
/*
* Pause all VMs to make them stop dirtying pages,
* so save is quicker. We remember if any VMs were
@ -837,6 +842,10 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
}
for (i = 0; i < numDomains; i++) {
virSystemdNotifyStatus("Saving '%s' (%zu of %d)",
virDomainGetName(domains[i]), i + 1, numDomains);
VIR_INFO("Saving '%s'", virDomainGetName(domains[i]));
if (virDomainManagedSave(domains[i], flags[i]) < 0) {
VIR_WARN("auto-shutdown: unable to perform managed save of '%s': %s",
domains[i]->name,
@ -860,6 +869,10 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
(!transient[i] && cfg->tryShutdown == VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT))
continue;
virSystemdNotifyStatus("Shutting down '%s' (%zu of %d)",
virDomainGetName(domains[i]), i + 1, numDomains);
VIR_INFO("Shutting down '%s'", virDomainGetName(domains[i]));
if (virDomainShutdown(domains[i]) < 0) {
VIR_WARN("auto-shutdown: unable to request graceful shutdown of '%s': %s",
domains[i]->name,
@ -869,6 +882,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
}
timer = g_timer_new();
virSystemdNotifyStatus("Waiting %d secs for VM shutdown completion",
cfg->waitShutdownSecs);
VIR_INFO("Waiting %d secs for VM shutdown completion", cfg->waitShutdownSecs);
while (1) {
bool anyRunning = false;
for (i = 0; i < numDomains; i++) {
@ -905,6 +921,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
(!transient[i] && cfg->poweroff == VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT))
continue;
virSystemdNotifyStatus("Destroying '%s' (%zu of %d)",
virDomainGetName(domains[i]), i + 1, numDomains);
VIR_INFO("Destroying '%s'", virDomainGetName(domains[i]));
/*
* NB might fail if we gave up on waiting for
* virDomainShutdown, but it then completed anyway,
@ -917,6 +936,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
}
}
virSystemdNotifyStatus("Processed %d domains", numDomains);
VIR_INFO("Processed %d domains", numDomains);
cleanup:
if (domains) {
/* Anything non-NULL in this list indicates none of