Patchwork [RFC,v5,14/21] virtagent: add agent_ping qmp/hmp commands

login
register
mail settings
Submitter Michael Roth
Date Dec. 3, 2010, 6:03 p.m.
Message ID <1291399402-20366-15-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/74196/
State New
Headers show

Comments

Michael Roth - Dec. 3, 2010, 6:03 p.m.
Monitor command to ping the RPC server.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hmp-commands.hx |   16 ++++++++++++
 qmp-commands.hx |   32 +++++++++++++++++++++++
 virtagent.c     |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 virtagent.h     |    3 ++
 4 files changed, 125 insertions(+), 0 deletions(-)

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3250e41..d3f642f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1260,6 +1260,22 @@  STEXI
 Shutdown/reboot a guest locally
 ETEXI
 
+    {
+        .name       = "agent_ping",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Ping a guest",
+        .user_print = do_agent_ping_print,
+        .mhandler.cmd_async = do_agent_ping,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item agent_ping
+@findex agent_ping
+Ping a guest
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0f983cc..1e798f5 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -838,6 +838,38 @@  Example:
 EQMP
 
     {
+        .name       = "agent_ping",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Ping a guest",
+        .user_print = do_agent_ping_print,
+        .mhandler.cmd_async = do_agent_ping,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item agent_ping
+@findex agent_ping
+Ping a guest
+ETEXI
+SQMP
+agent_ping
+--------
+
+Ping a guest
+
+Arguments:
+
+(none)
+
+Example:
+
+-> { "execute": "agent_ping" }
+<- { "return": { "response":"ok" } }
+
+EQMP
+
+    {
         .name       = "qmp_capabilities",
         .args_type  = "",
         .params     = "",
diff --git a/virtagent.c b/virtagent.c
index 1f66787..93329e3 100644
--- a/virtagent.c
+++ b/virtagent.c
@@ -386,3 +386,77 @@  int do_agent_shutdown(Monitor *mon, const QDict *mon_params,
     xmlrpc_DECREF(params);
     return ret;
 }
+
+void do_agent_ping_print(Monitor *mon, const QObject *data)
+{
+    QDict *qdict;
+    const char *response;
+
+    TRACE("called");
+
+    qdict = qobject_to_qdict(data);
+    response = qdict_get_str(qdict, "response");
+    if (qdict_haskey(qdict, "response")) {
+        monitor_printf(mon, "%s", response);
+    }
+
+    monitor_printf(mon, "\n");
+}
+
+static void do_agent_ping_cb(const char *resp_data,
+                                     size_t resp_data_len,
+                                     MonitorCompletion *mon_cb,
+                                     void *mon_data)
+{
+    xmlrpc_value *resp = NULL;
+    xmlrpc_env env;
+    QDict *qdict = qdict_new();
+
+    TRACE("called");
+
+    if (resp_data == NULL) {
+        LOG("error handling RPC request");
+        qdict_put(qdict, "response", qstring_from_str("error"));
+        goto out_no_resp;
+    }
+
+    xmlrpc_env_init(&env);
+    resp = xmlrpc_parse_response(&env, resp_data, resp_data_len);
+    if (va_rpc_has_error(&env)) {
+        qdict_put(qdict, "response", qstring_from_str("error"));
+        goto out_no_resp;
+    }
+    qdict_put(qdict, "response", qstring_from_str("ok"));
+
+    xmlrpc_DECREF(resp);
+out_no_resp:
+    if (mon_cb) {
+        mon_cb(mon_data, QOBJECT(qdict));
+    }
+    qobject_decref(QOBJECT(qdict));
+}
+
+/*
+ * do_agent_ping(): Ping a guest
+ */
+int do_agent_ping(Monitor *mon, const QDict *mon_params,
+                      MonitorCompletion cb, void *opaque)
+{
+    xmlrpc_env env;
+    xmlrpc_value *params;
+    int ret;
+
+    xmlrpc_env_init(&env);
+
+    params = xmlrpc_build_value(&env, "(n)");
+    if (va_rpc_has_error(&env)) {
+        return -1;
+    }
+
+    ret = va_do_rpc(&env, "va.ping", params, do_agent_ping_cb, cb, opaque);
+    if (ret) {
+        qerror_report(QERR_VA_FAILED, ret, strerror(ret));
+    }
+    xmlrpc_DECREF(params);
+    return ret;
+}
diff --git a/virtagent.h b/virtagent.h
index 60af1d8..f420c8b 100644
--- a/virtagent.h
+++ b/virtagent.h
@@ -36,5 +36,8 @@  int do_agent_viewdmesg(Monitor *mon, const QDict *mon_params,
                       MonitorCompletion cb, void *opaque);
 int do_agent_shutdown(Monitor *mon, const QDict *mon_params,
                       MonitorCompletion cb, void *opaque);
+void do_agent_ping_print(Monitor *mon, const QObject *qobject);
+int do_agent_ping(Monitor *mon, const QDict *mon_params,
+                  MonitorCompletion cb, void *opaque);
 
 #endif /* VIRTAGENT_H */