From patchwork Fri Oct 22 18:45:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 68925 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 089D6B70CD for ; Sat, 23 Oct 2010 06:11:25 +1100 (EST) Received: from localhost ([127.0.0.1]:33513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9N1M-000449-TN for incoming@patchwork.ozlabs.org; Fri, 22 Oct 2010 15:11:21 -0400 Received: from [140.186.70.92] (port=59959 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9MdX-00005q-LQ for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9MdT-0002dr-BX for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:40 -0400 Received: from e1.ny.us.ibm.com ([32.97.182.141]:48871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P9MdT-0002dg-7i for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:39 -0400 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by e1.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o9MIdMSA026598 for ; Fri, 22 Oct 2010 14:39:22 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9MIkcbm2068614 for ; Fri, 22 Oct 2010 14:46:38 -0400 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 o9MIkbJ1027547 for ; Fri, 22 Oct 2010 14:46:38 -0400 Received: from localhost.localdomain (sig-9-76-202-211.mts.ibm.com [9.76.202.211]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9MIkHq1025601; Fri, 22 Oct 2010 14:46:36 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 22 Oct 2010 13:45:57 -0500 Message-Id: <1287773165-24855-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1287773165-24855-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1287773165-24855-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, abeekhof@redhat.com Subject: [Qemu-devel] [RFC][PATCH 02/10] virtagent: base definitions for host/guest RPC daemon 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 Basic skeleton code for RPC daemon loop. This is shared by both the guest-side RPC server as well as the host-side one (the advertised RPCs for each by guest/host-specific arrays). Signed-off-by: Michael Roth --- virtagent-daemon.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++ virtagent-daemon.h | 20 +++++++++ 2 files changed, 138 insertions(+), 0 deletions(-) create mode 100644 virtagent-daemon.c create mode 100644 virtagent-daemon.h diff --git a/virtagent-daemon.c b/virtagent-daemon.c new file mode 100644 index 0000000..998b025 --- /dev/null +++ b/virtagent-daemon.c @@ -0,0 +1,118 @@ +/* + * virt-agent - host/guest RPC daemon 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 +#include +#include +#include +#include +#include +#include "qemu_socket.h" +#include "virtagent-daemon.h" +#include "virtagent-common.h" + +static int va_accept(int listen_fd) { + struct sockaddr_in saddr; + struct sockaddr *addr; + socklen_t len; + int fd; + + while (1) { + len = sizeof(saddr); + addr = (struct sockaddr *)&saddr; + fd = qemu_accept(listen_fd, addr, &len); + if (fd < 0 && errno != EINTR) { + LOG("accept() failed"); + break; + } else if (fd >= 0) { + TRACE("accepted connection"); + break; + } + } + return fd; +} + +typedef struct RPCFunction { + xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused); + const char *func_name; +} RPCFunction; + +static RPCFunction guest_functions[] = { + { NULL, NULL } +}; +static RPCFunction host_functions[] = { + { NULL, NULL } +}; + +static void va_register_functions(xmlrpc_env *env, xmlrpc_registry *registry, + RPCFunction *list) +{ + int i; + for (i = 0; list[i].func != NULL; ++i) { + TRACE("adding func: %s", list[i].func_name); + xmlrpc_registry_add_method(env, registry, NULL, list[i].func_name, + list[i].func, NULL); + } +} + +int va_server_loop(int listen_fd, bool is_host) +{ + xmlrpc_registry *registryP; + xmlrpc_env env; + int ret, fd; + char *rpc_request; + int rpc_request_len; + xmlrpc_mem_block *rpc_response; + RPCFunction *func_list = is_host ? host_functions : guest_functions; + + xmlrpc_env_init(&env); + registryP = xmlrpc_registry_new(&env); + va_register_functions(&env, registryP, func_list); + + while (1) { + TRACE("waiting for connection from RPC client"); + fd = va_accept(listen_fd); + if (fd < 0) { + TRACE("connection error: %s", strerror(errno)); + continue; + } + TRACE("RPC client connected, fetching RPC..."); + ret = va_get_rpc_request(fd, &rpc_request, &rpc_request_len); + if (ret != 0 || rpc_request == NULL) { + LOG("error retrieving rpc request"); + goto out; + } + TRACE("handling RPC request"); + rpc_response = xmlrpc_registry_process_call(&env, registryP, NULL, + rpc_request, + rpc_request_len); + if (rpc_response == NULL) { + LOG("error handling rpc request"); + goto out; + } + + qemu_free(rpc_request); + TRACE("sending RPC response"); + ret = va_send_rpc_response(fd, rpc_response); + if (ret != 0) { + LOG("error sending rpc response"); + goto out; + } + TRACE("RPC completed"); + XMLRPC_MEMBLOCK_FREE(char, rpc_response); +out: + closesocket(fd); + } + + return 0; +} diff --git a/virtagent-daemon.h b/virtagent-daemon.h new file mode 100644 index 0000000..bb197d0 --- /dev/null +++ b/virtagent-daemon.h @@ -0,0 +1,20 @@ +/* + * virt-agent - host/guest RPC daemon functions + * + * Copyright IBM Corp. 2010 + * + * Authors: + * 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. + * + */ +#define GUEST_AGENT_SERVICE_ID "virtagent" +#define GUEST_AGENT_PATH "/tmp/virtagent-guest.sock" +#define HOST_AGENT_SERVICE_ID "virtagent-host" +#define HOST_AGENT_PATH "/tmp/virtagent-host.sock" +#define VA_GETFILE_MAX 1 << 30 +#define VA_FILEBUF_LEN 16384 + +int va_server_loop(int listen_fd, bool is_host);