diff mbox

[RFC,v7,13/16] virtagent: add va_shutdown HMP/QMP command

Message ID 1299528642-23631-14-git-send-email-mdroth@linux.vnet.ibm.com
State New
Headers show

Commit Message

Michael Roth March 7, 2011, 8:10 p.m. UTC
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hmp-commands.hx |   16 ++++++++++++++++
 qmp-commands.hx |   32 ++++++++++++++++++++++++++++++++
 virtagent.c     |   24 ++++++++++++++++++++++++
 virtagent.h     |    2 ++
 4 files changed, 74 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index f22117a..982ba25 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1396,6 +1396,22 @@  STEXI
 Ping the guest agent
 ETEXI
 
+    {
+        .name       = "va_shutdown",
+        .args_type  = "shutdown_mode:s",
+        .params     = "shutdown_mode",
+        .help       = "Start guest-initiated reboot/halt/powerdown",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_async = do_va_shutdown,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item va_shutdown
+@findex va_shutdown
+Start guest-initiated reboot/halt/powerdown
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0379b61..dc25021 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -923,6 +923,38 @@  Example:
 EQMP
 
     {
+        .name       = "va_shutdown",
+        .args_type  = "shutdown_mode:s",
+        .params     = "shutdown_mode",
+        .help       = "reboot|halt|powerdown the guest",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_async = do_va_shutdown,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item va_shutdown
+@findex va_shutdown
+reboot|halt|powerdown the guest
+ETEXI
+SQMP
+va_shutdown
+--------
+
+reboot|halt|powerdown the guest
+
+Arguments:
+
+- "shutdown_mode": "reboot"|"halt"|"powerdown"
+
+Example:
+
+-> { "execute": "va_shutdown", "arguments": { "shutdown_mode": "reboot" } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "qmp_capabilities",
         .args_type  = "",
         .params     = "",
diff --git a/virtagent.c b/virtagent.c
index baf3c0e..7d2566e 100644
--- a/virtagent.c
+++ b/virtagent.c
@@ -476,6 +476,30 @@  int do_va_ping(Monitor *mon, const QDict *params,
     return ret;
 }
 
+static void do_va_shutdown_cb(QDict *resp,
+                              MonitorCompletion *mon_cb,
+                              void *mon_data)
+{
+    TRACE("called");
+    va_check_response_ok(resp, NULL);
+    if (mon_cb) {
+        mon_cb(mon_data, NULL);
+    }
+}
+
+/*
+ * do_va_shutdown(): shutdown/powerdown/reboot the guest
+ */
+int do_va_shutdown(Monitor *mon, const QDict *params,
+                   MonitorCompletion cb, void *opaque)
+{
+    int ret = va_do_rpc("shutdown", params, do_va_shutdown_cb, cb, opaque);
+    if (ret) {
+        qerror_report(QERR_VA_FAILED, ret, strerror(-ret));
+    }
+    return ret;
+}
+
 /* RPC client functions called outside of HMP/QMP */
 
 int va_client_init_capabilities(void)
diff --git a/virtagent.h b/virtagent.h
index a58d8ba..08c1004 100644
--- a/virtagent.h
+++ b/virtagent.h
@@ -45,5 +45,7 @@  int do_va_capabilities(Monitor *mon, const QDict *mon_params,
 void do_va_ping_print(Monitor *mon, const QObject *qobject);
 int do_va_ping(Monitor *mon, const QDict *mon_params,
                MonitorCompletion cb, void *opaque);
+int do_va_shutdown(Monitor *mon, const QDict *params,
+                   MonitorCompletion cb, void *opaque);
 
 #endif /* VIRTAGENT_H */