From patchwork Fri Dec 3 18:03:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 74177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7B80B1007D5 for ; Sat, 4 Dec 2010 05:08:10 +1100 (EST) Received: from localhost ([127.0.0.1]:51561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POa3C-0002oK-4H for incoming@patchwork.ozlabs.org; Fri, 03 Dec 2010 13:08:06 -0500 Received: from [140.186.70.92] (port=44373 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POZzB-0001y5-Pl for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POZz9-0003C0-CP for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:03:57 -0500 Received: from e6.ny.us.ibm.com ([32.97.182.146]:36464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POZz9-0003Bs-9P for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:03:55 -0500 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oB3I5Bm8006183 for ; Fri, 3 Dec 2010 13:05:11 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 1EC164DE803B for ; Fri, 3 Dec 2010 13:02:12 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oB3I3sL7275236 for ; Fri, 3 Dec 2010 13:03:54 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oB3I3rj3013267 for ; Fri, 3 Dec 2010 13:03:54 -0500 Received: from localhost.localdomain (sig-9-65-101-53.mts.ibm.com [9.65.101.53]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oB3I3S9c011647; Fri, 3 Dec 2010 13:03:52 -0500 From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 3 Dec 2010 12:03:06 -0600 Message-Id: <1291399402-20366-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1291399402-20366-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1291399402-20366-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, mdroth@linux.vnet.ibm.com, aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, abeekhof@redhat.com Subject: [Qemu-devel] [RFC][PATCH v5 05/21] virtagent: base client definitions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Functions for managing client capabilities and creating client RPC jobs. Signed-off-by: Michael Roth --- qerror.c | 8 +++ qerror.h | 6 +++ virtagent.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ virtagent.h | 32 +++++++++++++ 4 files changed, 187 insertions(+), 0 deletions(-) create mode 100644 virtagent.c create mode 100644 virtagent.h diff --git a/qerror.c b/qerror.c index ac2cdaf..c765a57 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", + }, + { + .error_fmt = QERR_VA_FAILED, + .desc = "An error was reported by virtagent", + }, {} }; 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/virtagent.c b/virtagent.c new file mode 100644 index 0000000..34d8545 --- /dev/null +++ b/virtagent.c @@ -0,0 +1,141 @@ +/* + * 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; + va_client_data = client_data; + + 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 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_has_capability(function)) { + LOG("guest agent does not have required capability"); + ret = -1; + 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..af36b6a --- /dev/null +++ b/virtagent.h @@ -0,0 +1,32 @@ +/* + * 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 GUEST_AGENT_PATH_CLIENT "/tmp/virtagent-guest-client.sock" +#define HOST_AGENT_PATH_CLIENT "/tmp/virtagent-host-client.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; +} VAClientData; + +int va_client_init(VAClientData *client_data); + +#endif /* VIRTAGENT_H */