qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
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 v4 05/18] virtagent: add getfile RPC
Date: Tue, 16 Nov 2010 10:01:47 -0600	[thread overview]
Message-ID: <1289923320-5638-6-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1289923320-5638-1-git-send-email-mdroth@linux.vnet.ibm.com>

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 <mdroth@linux.vnet.ibm.com>
---
 virtagent-daemon.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/virtagent-daemon.c b/virtagent-daemon.c
index 78d550f..44c0754 100644
--- a/virtagent-daemon.c
+++ b/virtagent-daemon.c
@@ -28,6 +28,59 @@ 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 */
+
+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;
+    }
+
+    SLOG("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;
+}
+
 static int va_accept(int listen_fd) {
     struct sockaddr_in saddr;
     struct sockaddr *addr;
@@ -55,6 +108,8 @@ typedef struct RPCFunction {
 } RPCFunction;
 
 static RPCFunction guest_functions[] = {
+    { .func = getfile,
+      .func_name = "getfile" },
     { NULL, NULL }
 };
 static RPCFunction host_functions[] = {
-- 
1.7.0.4

  parent reply	other threads:[~2010-11-16 16:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 16:01 [Qemu-devel] [RFC][PATCH v4 00/18] virtagent: host/guest RPC communication agent Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 01/18] virtagent: add common rpc transport defs Michael Roth
2010-11-18 13:53   ` Jes Sorensen
2010-11-18 16:33     ` Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 02/18] virtagent: base definitions for host/guest RPC server Michael Roth
2010-11-18 13:57   ` Jes Sorensen
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 03/18] virtagent: qemu-vp, integrate virtagent server Michael Roth
2010-11-18 14:02   ` Jes Sorensen
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 04/18] virtagent: base RPC client definitions Michael Roth
2010-11-18 14:10   ` Jes Sorensen
2010-11-16 16:01 ` Michael Roth [this message]
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 06/18] virtagent: add agent_viewfile command Michael Roth
2010-11-18 14:13   ` Jes Sorensen
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 07/18] virtagent: add getdmesg RPC Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 08/18] virtagent: add agent_viewdmesg command Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 09/18] virtagent: add va_shutdown RPC Michael Roth
2010-11-18 14:17   ` Jes Sorensen
2010-11-18 15:35     ` Anthony Liguori
2010-11-18 15:41       ` Jes Sorensen
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 10/18] virtagent: add agent_shutdown monitor command Michael Roth
2010-11-18 14:19   ` Jes Sorensen
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 11/18] virtagent: add va_ping RPC Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 12/18] virtagent: add agent_ping monitor command Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 13/18] virtagent: add agent_capabilities monitor function Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 14/18] virtagent: add client capabilities init function Michael Roth
2010-11-18 14:22   ` Jes Sorensen
2010-11-18 16:43     ` Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 15/18] virtagent: add va_hello RPC function Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 16/18] virtagent: add va_send_hello() client function Michael Roth
2010-11-16 16:01 ` [Qemu-devel] [RFC][PATCH v4 17/18] virtagent: qemu-vp, va_send_hello() on startup Michael Roth
2010-11-18 14:22   ` Jes Sorensen
2010-11-16 16:02 ` [Qemu-devel] [RFC][PATCH v4 18/18] virtagent: Makefile/configure changes to build virtagent bits Michael Roth
2010-11-18 13:50 ` [Qemu-devel] [RFC][PATCH v4 00/18] virtagent: host/guest RPC communication agent Jes Sorensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289923320-5638-6-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=abeekhof@redhat.com \
    --cc=agl@linux.vnet.ibm.com \
    --cc=aliguori@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ryanh@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).