[PATCH 26/26] hypervisor: send systemd status messages while saving

Daniel P. Berrangé posted 26 patches 1 year, 1 month ago
There is a newer version of this series
[PATCH 26/26] hypervisor: send systemd status messages while saving
Posted by Daniel P. Berrangé 1 year, 1 month ago
Since processing running VMs on OS shutdown can take a while, it is
beneficial to send systemd status messages about the progress.

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

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 2f89b8c841..421cc16574 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
 
@@ -791,6 +792,8 @@ 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);
             /*
              * Pause all VMs to make them stop dirtying pages,
              * so save is quicker. We remember if any VMs were
@@ -808,6 +811,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
         }
 
         for (i = 0; i < numDomains; i++) {
+            virSystemdNotifyStatus("Saving '%s' (%zu of %d)",
+                                   virDomainGetName(domains[i]), i + 1, numDomains);
+
             if (virDomainManagedSave(domains[i], flags[i]) < 0) {
                 VIR_WARN("Unable to perform managed save of '%s': %s",
                          virDomainGetName(domains[i]),
@@ -829,6 +835,9 @@ 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);
+
             if (virDomainShutdown(domains[i]) < 0) {
                 VIR_WARN("Unable to perform graceful shutdown of '%s': %s",
                          virDomainGetName(domains[i]),
@@ -838,6 +847,8 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
         }
 
         timer = g_timer_new();
+        virSystemdNotifyStatus("Waiting %d secs for VM shutdown completion",
+                               cfg->waitShutdownSecs);
         while (1) {
             bool anyRunning = false;
             for (i = 0; i < numDomains; i++) {
@@ -874,10 +885,14 @@ 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);
             virDomainDestroy(domains[i]);
         }
     }
 
+    virSystemdNotifyStatus("Processed %d domains", numDomains);
+
  cleanup:
     if (domains) {
         for (i = 0; i < numDomains; i++) {
-- 
2.47.1
Re: [PATCH 26/26] hypervisor: send systemd status messages while saving
Posted by Peter Krempa 1 year ago
On Wed, Jan 08, 2025 at 19:42:59 +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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/hypervisor/domain_driver.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
> index 2f89b8c841..421cc16574 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
>  
> @@ -791,6 +792,8 @@ 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);

As discussed in other sub-thread these messages are what I wanted, but
you'll need to make sure that they end up in the system log, otherwise
they won't help much.

Also specifically for suspend I'm not sure if this message makes too
much sense separately as it's just a sub-step of the 'save' operation.

>              /*
>               * Pause all VMs to make them stop dirtying pages,
>               * so save is quicker. We remember if any VMs were
> @@ -808,6 +811,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
>          }
>  
>          for (i = 0; i < numDomains; i++) {
> +            virSystemdNotifyStatus("Saving '%s' (%zu of %d)",
> +                                   virDomainGetName(domains[i]), i + 1, numDomains);
> +
>              if (virDomainManagedSave(domains[i], flags[i]) < 0) {
>                  VIR_WARN("Unable to perform managed save of '%s': %s",

Also these should IMO be delivered using exactly the same mechanism as
the success messages as well (in addition to being a warning perhaps).