[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC][PATCH v6 16/23] virtagent: add agent_capabilities qmp
From: |
Michael Roth |
Subject: |
[Qemu-devel] [RFC][PATCH v6 16/23] virtagent: add agent_capabilities qmp/hmp commands |
Date: |
Mon, 17 Jan 2011 07:15:10 -0600 |
Call guest agent's built-in introspection functions to get a list of
supported RPCs, and re-negotiate guest agent capabilities to determine
what agent_* commands are supported.
Signed-off-by: Michael Roth <address@hidden>
---
hmp-commands.hx | 16 +++++++++
qmp-commands.hx | 32 ++++++++++++++++++
virtagent.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
virtagent.h | 3 ++
4 files changed, 149 insertions(+), 0 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 6679771..52d4821 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1392,6 +1392,22 @@ STEXI
Ping a guest
ETEXI
+ {
+ .name = "agent_capabilities",
+ .args_type = "",
+ .params = "",
+ .help = "Fetch and re-negotiate guest agent capabilities",
+ .user_print = do_agent_capabilities_print,
+ .mhandler.cmd_async = do_agent_capabilities,
+ .flags = MONITOR_CMD_ASYNC,
+ },
+
+STEXI
address@hidden agent_capabilities
address@hidden agent_capabilities
+Fetch and re-negotiate guest agent capabilties
+ETEXI
+
STEXI
@end table
ETEXI
diff --git a/qmp-commands.hx b/qmp-commands.hx
index be6f485..5a14191 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -927,6 +927,38 @@ Example:
EQMP
{
+ .name = "agent_capabilities",
+ .args_type = "",
+ .params = "",
+ .help = "Fetch and re-negotiate guest agent capabilities",
+ .user_print = do_agent_capabilities_print,
+ .mhandler.cmd_async = do_agent_capabilities,
+ .flags = MONITOR_CMD_ASYNC,
+ },
+
+STEXI
address@hidden agent_capabilities
address@hidden agent_capabilities
+Fetch and re-negotiate guest agent capabilties
+ETEXI
+SQMP
+agent_capabilities
+--------
+
+Fetch and re-negotiate guest agent capabilities
+
+Arguments:
+
+(none)
+
+Example:
+
+-> { "execute": "agent_capabilities" }
+<- { "return":["va.shutdown", "va.getdmesg", "va.getfile", ... ] }
+
+EQMP
+
+ {
.name = "qmp_capabilities",
.args_type = "",
.params = "",
diff --git a/virtagent.c b/virtagent.c
index 4b6b7d1..99efe2b 100644
--- a/virtagent.c
+++ b/virtagent.c
@@ -477,3 +477,101 @@ int do_agent_ping(Monitor *mon, const QDict *mon_params,
xmlrpc_DECREF(params);
return ret;
}
+
+static void va_print_capability_iter(QObject *obj, void *opaque)
+{
+ Monitor *mon = opaque;
+ QString *method = qobject_to_qstring(obj);
+ const char *method_str;
+
+ if (method) {
+ method_str = qstring_get_str(method);
+ monitor_printf(mon, "%s\n", method_str);
+ }
+}
+
+void do_agent_capabilities_print(Monitor *mon, const QObject *data)
+{
+ QList *qlist;
+
+ TRACE("called");
+
+ monitor_printf(mon, "the following RPC methods are supported by the guest
agent:\n");
+ qlist = qobject_to_qlist(data);
+ qlist_iter(qlist, va_print_capability_iter, mon);
+}
+
+static void do_agent_capabilities_cb(const char *resp_data,
+ size_t resp_data_len,
+ MonitorCompletion *mon_cb,
+ void *mon_data)
+{
+ xmlrpc_value *resp = NULL;
+ xmlrpc_value *cur_val = NULL;
+ const char *cur_method = NULL;
+ xmlrpc_env env;
+ QList *qlist = qlist_new();
+ int i;
+
+ TRACE("called");
+
+ if (resp_data == NULL) {
+ LOG("error handling RPC request");
+ goto out_no_resp;
+ }
+
+ TRACE("resp = %s\n", resp_data);
+
+ xmlrpc_env_init(&env);
+ resp = xmlrpc_parse_response(&env, resp_data, resp_data_len);
+ if (va_rpc_has_error(&env)) {
+ goto out_no_resp;
+ }
+
+ /* extract the list of supported RPCs */
+ for (i = 0; i < xmlrpc_array_size(&env, resp); i++) {
+ xmlrpc_array_read_item(&env, resp, i, &cur_val);
+ xmlrpc_read_string(&env, cur_val, &cur_method);
+ if (cur_method) {
+ TRACE("cur_method: %s", cur_method);
+ qlist_append_obj(qlist, QOBJECT(qstring_from_str(cur_method)));
+ }
+ xmlrpc_DECREF(cur_val);
+ }
+
+ /* set our client capabilities accordingly */
+ va_set_capabilities(qlist);
+
+ xmlrpc_DECREF(resp);
+out_no_resp:
+ if (mon_cb) {
+ mon_cb(mon_data, QOBJECT(qlist));
+ }
+ qobject_decref(QOBJECT(qlist));
+}
+
+/*
+ * do_agent_capabilities(): Fetch/re-negotiate guest agent capabilities
+ */
+int do_agent_capabilities(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, "()");
+ if (va_rpc_has_error(&env)) {
+ return -1;
+ }
+
+ ret = va_do_rpc(&env, "system.listMethods", params,
+ do_agent_capabilities_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 7d3a122..da70317 100644
--- a/virtagent.h
+++ b/virtagent.h
@@ -41,5 +41,8 @@ int do_agent_shutdown(Monitor *mon, const QDict *mon_params,
void do_agent_ping_print(Monitor *mon, const QObject *qobject);
int do_agent_ping(Monitor *mon, const QDict *mon_params,
MonitorCompletion cb, void *opaque);
+void do_agent_capabilities_print(Monitor *mon, const QObject *qobject);
+int do_agent_capabilities(Monitor *mon, const QDict *mon_params,
+ MonitorCompletion cb, void *opaque);
#endif /* VIRTAGENT_H */
--
1.7.0.4
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, (continued)
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, Anthony Liguori, 2011/01/24
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, Richard W.M. Jones, 2011/01/25
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, Anthony Liguori, 2011/01/25
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, Richard W.M. Jones, 2011/01/25
- Re: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC, Richard W.M. Jones, 2011/01/26
[Qemu-devel] [RFC][PATCH v6 14/23] virtagent: add va.ping RPC, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 10/23] virtagent: add va.getdmesg RPC, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 15/23] virtagent: add agent_ping qmp/hmp commands, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 18/23] virtagent: add va.hello RPC, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 13/23] virtagent: add agent_shutdown qmp/hmp commands, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 16/23] virtagent: add agent_capabilities qmp/hmp commands,
Michael Roth <=
[Qemu-devel] [RFC][PATCH v6 19/23] virtagent: add "hello" notification function for guest agent, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 17/23] virtagent: add client capabilities init function, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 21/23] virtagent: add virtagent guest daemon, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 20/23] virtagent: add va.capabilities RPC, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 23/23] virtagent: various bits to build QEMU with virtagent, Michael Roth, 2011/01/17
[Qemu-devel] [RFC][PATCH v6 22/23] virtagent: integrate virtagent server/client via chardev, Michael Roth, 2011/01/17
Re: [Qemu-devel] [RFC][PATCH v6 00/23] virtagent: host/guest RPC communication agent, Gerd Hoffmann, 2011/01/17