[PATCH 13/26] qemu: configurable delay for shutdown before poweroff

Daniel P. Berrangé posted 26 patches 1 week, 5 days ago
[PATCH 13/26] qemu: configurable delay for shutdown before poweroff
Posted by Daniel P. Berrangé 1 week, 5 days ago
Allow users to control how many seconds libvirt waits for QEMU
shutdown before force powering off a guest.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/qemu/libvirtd_qemu.aug         | 1 +
 src/qemu/qemu.conf.in              | 4 ++++
 src/qemu/qemu_conf.c               | 4 ++++
 src/qemu/qemu_conf.h               | 1 +
 src/qemu/qemu_driver.c             | 1 +
 src/qemu/test_libvirtd_qemu.aug.in | 1 +
 6 files changed, 12 insertions(+)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index 605604a01a..8cb1b144b9 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -101,6 +101,7 @@ module Libvirtd_qemu =
                  | str_entry "auto_shutdown_try_save"
                  | str_entry "auto_shutdown_try_shutdown"
                  | str_entry "auto_shutdown_poweroff"
+                 | int_entry "auto_shutdown_wait"
 
    let process_entry = str_entry "hugetlbfs_mount"
                  | str_entry "bridge_helper"
diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in
index 82eae2eecd..9287196c42 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -677,6 +677,10 @@
 # set to 'none' for system daemons to avoid dueling actions
 #auto_shutdown_poweroff = "all"
 
+# How may seconds to wait for running VMs to gracefully shutdown
+# when 'auto_shutdown_try_shutdown' is enabled
+#auto_shutdown_wait = 30
+
 # If provided by the host and a hugetlbfs mount point is configured,
 # a guest may request huge page backing.  When this mount point is
 # unspecified here, determination of a host mount point in /proc/mounts
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 76bb3bd888..7ec682e533 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -692,6 +692,10 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *cfg,
         return -1;
     }
 
+    if (virConfGetValueInt(conf, "auto_shutdown_wait",
+                           &cfg->autoShutdownWait) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 5d9ace6dcc..b8f6be110d 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -204,6 +204,7 @@ struct _virQEMUDriverConfig {
     int autoShutdownTrySave;
     int autoShutdownTryShutdown;
     int autoShutdownPoweroff;
+    int autoShutdownWait;
 
     char *lockManagerName;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 641b45fd8f..baa0d51244 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -950,6 +950,7 @@ qemuStateStop(void)
         .trySave = cfg->autoShutdownTrySave,
         .tryShutdown = cfg->autoShutdownTryShutdown,
         .poweroff = cfg->autoShutdownPoweroff,
+        .waitShutdownSecs = cfg->autoShutdownWait,
     };
 
     virDomainDriverAutoShutdown(&ascfg);
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
index 3bc8104d7a..4c6de31199 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -79,6 +79,7 @@ module Test_libvirtd_qemu =
 { "auto_shutdown_try_save" = "persistent" }
 { "auto_shutdown_try_shutdown" = "all" }
 { "auto_shutdown_poweroff" = "all" }
+{ "auto_shutdown_wait" = "30" }
 { "hugetlbfs_mount" = "/dev/hugepages" }
 { "bridge_helper" = "qemu-bridge-helper" }
 { "set_process_name" = "1" }
-- 
2.47.1