[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/3] Introduce two new methods for triggering controlled shutdown/reboot



From: "Daniel P. Berrange" <berrange redhat com>

The virDomainShutdownFlags and virDomainReboot APIs allow the caller
to request the operation is implemented via either acpi button press
or a guest agent. For containers, a couple of other methods make
sense, a message to /dev/initctl, and direct kill(SIGTERM|HUP) of
the container init process.

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 include/libvirt/libvirt.h.in |  4 ++++
 tools/virsh-domain.c         | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 84dcde1..1859165 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1385,6 +1385,8 @@ typedef enum {
     VIR_DOMAIN_SHUTDOWN_DEFAULT        = 0,        /* hypervisor choice */
     VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1 << 0), /* Send ACPI event */
     VIR_DOMAIN_SHUTDOWN_GUEST_AGENT    = (1 << 1), /* Use guest agent */
+    VIR_DOMAIN_SHUTDOWN_INITCTL        = (1 << 2), /* Use initctl */
+    VIR_DOMAIN_SHUTDOWN_SIGNAL         = (1 << 3), /* Send a signal */
 } virDomainShutdownFlagValues;
 
 int                     virDomainShutdown       (virDomainPtr domain);
@@ -1395,6 +1397,8 @@ typedef enum {
     VIR_DOMAIN_REBOOT_DEFAULT        = 0,        /* hypervisor choice */
     VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1 << 0), /* Send ACPI event */
     VIR_DOMAIN_REBOOT_GUEST_AGENT    = (1 << 1), /* Use guest agent */
+    VIR_DOMAIN_REBOOT_INITCTL        = (1 << 2), /* Use initctl */
+    VIR_DOMAIN_REBOOT_SIGNAL         = (1 << 3), /* Send a signal */
 } virDomainRebootFlagValues;
 
 int                     virDomainReboot         (virDomainPtr domain,
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index cc47383..ff6a9a0 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4046,8 +4046,13 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
             flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
         } else if (STREQ(mode, "agent")) {
             flags |= VIR_DOMAIN_SHUTDOWN_GUEST_AGENT;
+        } else if (STREQ(mode, "initctl")) {
+            flags |= VIR_DOMAIN_SHUTDOWN_INITCTL;
+        } else if (STREQ(mode, "signal")) {
+            flags |= VIR_DOMAIN_SHUTDOWN_SIGNAL;
         } else {
-            vshError(ctl, _("Unknown mode %s value, expecting 'acpi' or 'agent'"), mode);
+            vshError(ctl, _("Unknown mode %s value, expecting "
+                            "'acpi', 'agent', 'initctl' or 'signal'"), mode);
             return false;
         }
     }
@@ -4101,11 +4106,16 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
 
     if (mode) {
         if (STREQ(mode, "acpi")) {
-            flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
+            flags |= VIR_DOMAIN_REBOOT_ACPI_POWER_BTN;
         } else if (STREQ(mode, "agent")) {
-            flags |= VIR_DOMAIN_SHUTDOWN_GUEST_AGENT;
+            flags |= VIR_DOMAIN_REBOOT_GUEST_AGENT;
+        } else if (STREQ(mode, "initctl")) {
+            flags |= VIR_DOMAIN_REBOOT_INITCTL;
+        } else if (STREQ(mode, "signal")) {
+            flags |= VIR_DOMAIN_REBOOT_SIGNAL;
         } else {
-            vshError(ctl, _("Unknown mode %s value, expecting 'acpi' or 'agent'"), mode);
+            vshError(ctl, _("Unknown mode %s value, expecting "
+                            "'acpi', 'agent', 'initctl' or 'signal'"), mode);
             return false;
         }
     }
-- 
1.7.11.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]