[PATCH v2 22/22] hypervisor: emit systemd status & log messages while saving

Daniel P. Berrangé posted 22 patches 2 months, 1 week ago
[PATCH v2 22/22] hypervisor: emit systemd status & log messages while saving
Posted by Daniel P. Berrangé 2 months, 1 week ago
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).

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/hypervisor/domain_driver.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 1105d36388..c7ffd21f05 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -30,6 +30,7 @@
 #include "datatypes.h"
 #include "driver.h"
 #include "virlog.h"
+#include "virsystemd.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -814,6 +815,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
@@ -832,6 +837,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("Unable to perform managed save of '%s': %s",
                          virDomainGetName(domains[i]),
@@ -855,6 +864,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("Unable to request graceful shutdown of '%s': %s",
                          virDomainGetName(domains[i]),
@@ -864,6 +877,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++) {
@@ -900,6 +916,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,
@@ -912,6 +931,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
-- 
2.48.1
Re: [PATCH v2 22/22] hypervisor: emit systemd status & log messages while saving
Posted by Peter Krempa 2 months, 1 week ago
On Wed, Mar 12, 2025 at 17:18:02 +0000, Daniel P. Berrangé wrote:
> 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).
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/hypervisor/domain_driver.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>