From patchwork Fri Oct 22 18:46:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 68937 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 C19EEB70CC for ; Sat, 23 Oct 2010 06:36:26 +1100 (EST) Received: from localhost ([127.0.0.1]:47685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9NMQ-0006RN-UP for incoming@patchwork.ozlabs.org; Fri, 22 Oct 2010 15:33:06 -0400 Received: from [140.186.70.92] (port=60199 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9Mdf-0000C9-9n for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9Mda-0002iW-2G for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:51 -0400 Received: from e1.ny.us.ibm.com ([32.97.182.141]:48902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P9MdZ-0002iP-Ul for qemu-devel@nongnu.org; Fri, 22 Oct 2010 14:46:45 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e1.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o9MIdTcg026790 for ; Fri, 22 Oct 2010 14:39:29 -0400 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 o9MIkjji167922 for ; Fri, 22 Oct 2010 14:46:45 -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 o9MIkidB027966 for ; Fri, 22 Oct 2010 14:46:45 -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 o9MIkHq6025601; Fri, 22 Oct 2010 14:46:43 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 22 Oct 2010 13:46:02 -0500 Message-Id: <1287773165-24855-8-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 07/10] virtagent: add getdmesg 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 view guest dmesg output. Signed-off-by: Michael Roth --- virtagent-daemon.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ virtagent-daemon.h | 1 + 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/virtagent-daemon.c b/virtagent-daemon.c index fad0f64..6aaa987 100644 --- a/virtagent-daemon.c +++ b/virtagent-daemon.c @@ -72,6 +72,48 @@ EXIT_CLOSE_BAD: return result; } +/* getdmesg(): return dmesg output + * rpc return values: + * - dmesg output as a string + */ +static xmlrpc_value *getdmesg(xmlrpc_env *env, + xmlrpc_value *param, + void *user_data) +{ + char *dmesg_buf = NULL, cmd[256]; + char c; + int pos = 0; + xmlrpc_value *result = NULL; + FILE *pipe; + + dmesg_buf = qemu_mallocz(VA_DMESG_LEN + 2048); + sprintf(cmd, "dmesg -s %d", VA_DMESG_LEN); + + //pipe = popen(cmd, "r"); + pipe = popen("dmesg -s 16000", "r"); + if (pipe == NULL) { + LOG("popen failed: %s", strerror(errno)); + xmlrpc_faultf(env, "popen failed: %s", strerror(errno)); + goto EXIT_NOCLOSE; + } + + while ((c = fgetc(pipe)) != EOF && pos < VA_DMESG_LEN) { + dmesg_buf[pos] = c; + pos++; + } + dmesg_buf[pos++] = '\0'; + TRACE("dmesg:\n%s", dmesg_buf); + + result = xmlrpc_build_value(env, "s", dmesg_buf); + pclose(pipe); +EXIT_NOCLOSE: + if (dmesg_buf) { + qemu_free(dmesg_buf); + } + + return result; +} + static int va_accept(int listen_fd) { struct sockaddr_in saddr; struct sockaddr *addr; @@ -101,6 +143,8 @@ typedef struct RPCFunction { static RPCFunction guest_functions[] = { { .func = getfile, .func_name = "getfile" }, + { .func = getdmesg, + .func_name = "getdmesg" }, { NULL, NULL } }; static RPCFunction host_functions[] = { @@ -165,6 +209,7 @@ int va_server_loop(int listen_fd, bool is_host) XMLRPC_MEMBLOCK_FREE(char, rpc_response); out: closesocket(fd); + xmlrpc_env_clean(&env); } return 0; diff --git a/virtagent-daemon.h b/virtagent-daemon.h index bb197d0..adcbc9a 100644 --- a/virtagent-daemon.h +++ b/virtagent-daemon.h @@ -16,5 +16,6 @@ #define HOST_AGENT_PATH "/tmp/virtagent-host.sock" #define VA_GETFILE_MAX 1 << 30 #define VA_FILEBUF_LEN 16384 +#define VA_DMESG_LEN 16384 int va_server_loop(int listen_fd, bool is_host);