From patchwork Fri Dec 3 18:03:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 74198 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 7C1D7B70AA for ; Sat, 4 Dec 2010 05:48:59 +1100 (EST) Received: from localhost ([127.0.0.1]:43581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POa73-0005SU-Kv for incoming@patchwork.ozlabs.org; Fri, 03 Dec 2010 13:12:05 -0500 Received: from [140.186.70.92] (port=44430 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POZzF-00020a-0u for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POZzC-0003D4-BX for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:00 -0500 Received: from e1.ny.us.ibm.com ([32.97.182.141]:36002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POZzC-0003Cu-8z for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:03:58 -0500 Received: from d01dlp01.pok.ibm.com (d01dlp01.pok.ibm.com [9.56.224.56]) by e1.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oB3HtowO014804 for ; Fri, 3 Dec 2010 12:55:54 -0500 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 996C7728051 for ; Fri, 3 Dec 2010 13:03:57 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oB3I3vZK147282 for ; Fri, 3 Dec 2010 13:03:57 -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 oB3I3tEQ013443 for ; Fri, 3 Dec 2010 13:03:57 -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 oB3I3S9e011647; Fri, 3 Dec 2010 13:03:55 -0500 From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 3 Dec 2010 12:03:08 -0600 Message-Id: <1291399402-20366-8-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 07/21] virtagent: add va.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. This interface is intended for smaller reads like peeking at logs and /proc and such. Signed-off-by: Michael Roth --- virtagent-server.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/virtagent-server.c b/virtagent-server.c index 36fbae2..a430b58 100644 --- a/virtagent-server.c +++ b/virtagent-server.c @@ -26,12 +26,71 @@ static bool va_enable_syslog = false; /* enable syslog'ing of RPCs */ syslog(LOG_INFO, "virtagent, %s", msg_buf); \ } while(0) +/* RPC functions common to guest/host daemons */ + +/* va_getfile(): return file contents + * rpc return values: + * - base64-encoded file contents + */ +static xmlrpc_value *va_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; + } + + SLOG("va_getfile(), path:%s", path); + + 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; +} + typedef struct RPCFunction { xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused); const char *func_name; } RPCFunction; static RPCFunction guest_functions[] = { + { .func = va_getfile, + .func_name = "va.getfile" }, { NULL, NULL } }; static RPCFunction host_functions[] = {