From patchwork Wed Nov 3 11:35:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 69973 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 1A500B70DF for ; Wed, 3 Nov 2010 22:38:14 +1100 (EST) Received: from localhost ([127.0.0.1]:33122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDbfN-0006q1-9n for incoming@patchwork.ozlabs.org; Wed, 03 Nov 2010 07:38:09 -0400 Received: from [140.186.70.92] (port=48312 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDbdf-0006kb-6i for qemu-devel@nongnu.org; Wed, 03 Nov 2010 07:36:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDbdb-0005RI-Vd for qemu-devel@nongnu.org; Wed, 03 Nov 2010 07:36:22 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:45879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDbdb-0005Qw-T3 for qemu-devel@nongnu.org; Wed, 03 Nov 2010 07:36:19 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oA3BJBlN023178 for ; Wed, 3 Nov 2010 07:19:11 -0400 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 oA3BaIP0263280 for ; Wed, 3 Nov 2010 07:36:18 -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 oA3BaIF9013738 for ; Wed, 3 Nov 2010 07:36:18 -0400 Received: from localhost.localdomain (sig-9-76-99-21.mts.ibm.com [9.76.99.21]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oA3Ba4ik013140; Wed, 3 Nov 2010 07:36:17 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 3 Nov 2010 06:35:34 -0500 Message-Id: <1288784139-1110-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1288784139-1110-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1288784139-1110-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, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC][PATCH v2 05/10] virtagent: add getfile RPC 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 Add RPC to retrieve a guest file. A size limit of some sort will eventually be needed else we can block the monitor for arbitrarily long periods of time. This interface is intended for smaller reads like peeking at logs and /proc and such. Signed-off-by: Michael Roth --- virtagent-daemon.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/virtagent-daemon.c b/virtagent-daemon.c index 71a36d4..bf28be2 100644 --- a/virtagent-daemon.c +++ b/virtagent-daemon.c @@ -15,6 +15,57 @@ #include "virtagent-daemon.h" #include "virtagent-common.h" +/* RPC functions common to guest/host daemons */ + +static xmlrpc_value *getfile(xmlrpc_env *env, + xmlrpc_value *param, + void *user_data) +{ + const char *path; + char *file_contents = NULL; + char buf[VA_FILEBUF_LEN]; + int fd, ret, count = 0; + xmlrpc_value *result = NULL; + + /* parse argument array */ + xmlrpc_decompose_value(env, param, "(s)", &path); + if (env->fault_occurred) { + return NULL; + } + + fd = open(path, O_RDONLY); + if (fd == -1) { + LOG("open failed: %s", strerror(errno)); + xmlrpc_faultf(env, "open failed: %s", strerror(errno)); + return NULL; + } + + while ((ret = read(fd, buf, VA_FILEBUF_LEN)) > 0) { + file_contents = qemu_realloc(file_contents, count + VA_FILEBUF_LEN); + memcpy(file_contents + count, buf, ret); + count += ret; + if (count > VA_GETFILE_MAX) { + xmlrpc_faultf(env, "max file size (%d bytes) exceeded", + VA_GETFILE_MAX); + goto EXIT_CLOSE_BAD; + } + } + if (ret == -1) { + LOG("read failed: %s", strerror(errno)); + xmlrpc_faultf(env, "read failed: %s", strerror(errno)); + goto EXIT_CLOSE_BAD; + } + + result = xmlrpc_build_value(env, "6", file_contents, count); + +EXIT_CLOSE_BAD: + if (file_contents) { + qemu_free(file_contents); + } + close(fd); + return result; +} + static int va_accept(int listen_fd) { struct sockaddr_in saddr; struct sockaddr *addr; @@ -42,6 +93,8 @@ typedef struct RPCFunction { } RPCFunction; static RPCFunction guest_functions[] = { + { .func = getfile, + .func_name = "getfile" }, { NULL, NULL } }; static RPCFunction host_functions[] = {