From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60833 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PgK2y-0000y8-C7 for qemu-devel@nongnu.org; Fri, 21 Jan 2011 11:41:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PgK2w-0001xM-5G for qemu-devel@nongnu.org; Fri, 21 Jan 2011 11:41:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PgK2v-0001x5-UT for qemu-devel@nongnu.org; Fri, 21 Jan 2011 11:41:10 -0500 Message-ID: <4D39B716.1010400@redhat.com> Date: Fri, 21 Jan 2011 17:40:54 +0100 From: Jes Sorensen MIME-Version: 1.0 References: <1295270117-24760-1-git-send-email-mdroth@linux.vnet.ibm.com> <1295270117-24760-9-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1295270117-24760-9-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [RFC][PATCH v6 08/23] virtagent: add va.getfile RPC List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, abeekhof@redhat.com, marcel.mittelstaedt@de.ibm.com, qemu-devel@nongnu.org, aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, markus_mueller@de.ibm.com On 01/17/11 14:15, Michael Roth wrote: > 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 c38a9e0..af4b940 100644 > --- a/virtagent-server.c > +++ b/virtagent-server.c > @@ -62,12 +62,71 @@ out: > return ret; > } > > +/* 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 *params, > + void *user_data) > +{ > + const char *path; > + char *file_contents = NULL; > + char buf[VA_FILEBUF_LEN]; malloc()! > + int fd, ret, count = 0; > + xmlrpc_value *result = NULL; > + > + /* parse argument array */ > + xmlrpc_decompose_value(env, params, "(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); Sorry, I brought this up before. This realloc() stuff is a disaster waiting to happen. Please remove it from the patch series, until you have an implementation that copies over a page of the time. > + count += ret; Cheers, Jes