From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60978 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeowQ-0006ur-Im for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PeowN-0006E1-Tz for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:14 -0500 Received: from e3.ny.us.ibm.com ([32.97.182.143]:59012) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PeowN-0006Dx-Nu for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:11 -0500 Received: from d01dlp01.pok.ibm.com (d01dlp01.pok.ibm.com [9.56.224.56]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0HCvCJd021706 for ; Mon, 17 Jan 2011 07:57:13 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id D9662728059 for ; Mon, 17 Jan 2011 08:16:10 -0500 (EST) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0HDGAjf261322 for ; Mon, 17 Jan 2011 08:16:10 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0HDG97p030389 for ; Mon, 17 Jan 2011 08:16:10 -0500 From: Michael Roth Date: Mon, 17 Jan 2011 07:15:00 -0600 Message-Id: <1295270117-24760-7-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1295270117-24760-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1295270117-24760-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC][PATCH v6 06/23] virtagent: base client definitions List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, marcel.mittelstaedt@de.ibm.com, mdroth@linux.vnet.ibm.com, markus_mueller@de.ibm.com, aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, abeekhof@redhat.com Functions for managing client capabilities and creating client RPC jobs. Signed-off-by: Michael Roth --- qerror.c | 8 +++ qerror.h | 6 ++ roms/seabios | 2 +- virtagent.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ virtagent.h | 34 ++++++++++++ 5 files changed, 207 insertions(+), 1 deletions(-) create mode 100644 virtagent.c create mode 100644 virtagent.h diff --git a/qerror.c b/qerror.c index ac2cdaf..dea8c5f 100644 --- a/qerror.c +++ b/qerror.c @@ -200,6 +200,14 @@ static const QErrorStringTable qerror_table[] = { .error_fmt = QERR_VNC_SERVER_FAILED, .desc = "Could not start VNC server on %(target)", }, + { + .error_fmt = QERR_RPC_FAILED, + .desc = "An RPC error has occurred: %(message)", + }, + { + .error_fmt = QERR_VA_FAILED, + .desc = "An error was reported by virtagent: %(message)", + }, {} }; diff --git a/qerror.h b/qerror.h index 943a24b..059c0dc 100644 --- a/qerror.h +++ b/qerror.h @@ -165,4 +165,10 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_VNC_SERVER_FAILED \ "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" +#define QERR_RPC_FAILED \ + "{ 'class': 'RPCFailed', 'data': { 'code': %i, 'message': %s } }" + +#define QERR_VA_FAILED \ + "{ 'class': 'VirtagentFailed', 'data': { 'code': %i, 'message': %s } }" + #endif /* QERROR_H */ diff --git a/roms/seabios b/roms/seabios index 0ff9051..17d3e46 160000 --- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit 0ff9051f756ba739bc2edca77925191c3c6cbc2f +Subproject commit 17d3e46511aeedc9f09a8216d194d749187b80aa diff --git a/virtagent.c b/virtagent.c new file mode 100644 index 0000000..00eccb5 --- /dev/null +++ b/virtagent.c @@ -0,0 +1,158 @@ +/* + * virtagent - host/guest RPC client functions + * + * Copyright IBM Corp. 2010 + * + * Authors: + * Adam Litke + * Michael Roth + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu_socket.h" +#include "virtagent-common.h" + +static VAClientData *va_client_data; + +static void va_set_capabilities(QList *qlist) +{ + TRACE("called"); + + if (va_client_data == NULL) { + LOG("client is uninitialized, unable to set capabilities"); + return; + } + + if (va_client_data->supported_methods != NULL) { + qobject_decref(QOBJECT(va_client_data->supported_methods)); + va_client_data->supported_methods = NULL; + TRACE("capabilities reset"); + } + + if (qlist != NULL) { + va_client_data->supported_methods = qlist_copy(qlist); + TRACE("capabilities set"); + } +} + +typedef struct VACmpState { + const char *method; + bool found; +} VACmpState; + +static void va_cmp_capability_iter(QObject *obj, void *opaque) +{ + QString *method = qobject_to_qstring(obj); + const char *method_str = NULL; + VACmpState *cmp_state = opaque; + + if (method) { + method_str = qstring_get_str(method); + } + + if (method_str && opaque) { + if (strcmp(method_str, cmp_state->method) == 0) { + cmp_state->found = 1; + } + } +} + +static bool va_has_capability(const char *method) +{ + VACmpState cmp_state; + + if (method == NULL) { + return false; + } + + /* we can assume method introspection is available */ + if (strcmp(method, "system.listMethods") == 0) { + return true; + } + /* assume hello is available to we can probe for/notify the host + * rpc server + */ + if (strcmp(method, "va.hello") == 0) { + return true; + } + + /* compare method against the last retrieved supported method list */ + cmp_state.method = method; + cmp_state.found = false; + if (va_client_data->supported_methods) { + qlist_iter(va_client_data->supported_methods, + va_cmp_capability_iter, + (void *)&cmp_state); + } + + return cmp_state.found; +} + +int va_client_init(VAClientData *client_data) +{ + client_data->supported_methods = NULL; + client_data->enabled = true; + va_client_data = client_data; + + return 0; +} + +int va_client_close(void) +{ + va_client_data = NULL; + return 0; +} + +static int va_rpc_has_error(xmlrpc_env *env) +{ + if (env->fault_occurred) { + qerror_report(QERR_RPC_FAILED, env->fault_code, env->fault_string); + return -1; + } + return 0; +} + +static bool va_is_enabled(void) +{ + return va_client_data && va_client_data->enabled; +} + +static int va_do_rpc(xmlrpc_env *const env, const char *function, + xmlrpc_value *params, VAClientCallback *cb, + MonitorCompletion *mon_cb, void *mon_data) +{ + xmlrpc_mem_block *req_xml; + int ret; + + if (!va_is_enabled()) { + LOG("virtagent not initialized"); + ret = -ENOTCONN; + } + + if (!va_has_capability(function)) { + LOG("guest agent does not have required capability"); + ret = -ENOSYS; + goto out; + } + + req_xml = XMLRPC_MEMBLOCK_NEW(char, env, 0); + xmlrpc_serialize_call(env, req_xml, function, params); + if (va_rpc_has_error(env)) { + ret = -EINVAL; + goto out_free; + } + + ret = va_client_job_add(req_xml, cb, mon_cb, mon_data); + if (ret) { + goto out_free; + } + + return ret; +out_free: + XMLRPC_MEMBLOCK_FREE(char, req_xml); +out: + return ret; +} diff --git a/virtagent.h b/virtagent.h new file mode 100644 index 0000000..3e4d4fb --- /dev/null +++ b/virtagent.h @@ -0,0 +1,34 @@ +/* + * virt-agent - host/guest RPC client functions + * + * Copyright IBM Corp. 2010 + * + * Authors: + * Adam Litke + * Michael Roth + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VIRTAGENT_H +#define VIRTAGENT_H + +#include "monitor.h" + +#define VA_GUEST_PATH_VIRTIO_DEFAULT "/dev/virtio-ports/org.qemu.virtagent" +#define VA_HOST_PATH_DEFAULT "/tmp/virtagent.sock" +#define VA_MAX_CHUNK_SIZE 4096 /* max bytes at a time for get/send file */ + +typedef void (VAClientCallback)(const char *resp_data, size_t resp_data_len, + MonitorCompletion *mon_cb, void *mon_data); +typedef struct VAClientData { + QList *supported_methods; + bool enabled; +} VAClientData; + +int va_client_init(VAClientData *client_data); +int va_client_close(void); + +#endif /* VIRTAGENT_H */ -- 1.7.0.4