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 02/10] virtagent: base definitions for host/guest RPC daemon
Date: Fri, 22 Oct 2010 13:45:57 -0500 [thread overview]
Message-ID: <1287773165-24855-3-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1287773165-24855-1-git-send-email-mdroth@linux.vnet.ibm.com>
Basic skeleton code for RPC daemon loop. This is shared by both the
guest-side RPC server as well as the host-side one (the advertised RPCs
for each by guest/host-specific arrays).
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
virtagent-daemon.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++
virtagent-daemon.h | 20 +++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
create mode 100644 virtagent-daemon.c
create mode 100644 virtagent-daemon.h
diff --git a/virtagent-daemon.c b/virtagent-daemon.c
new file mode 100644
index 0000000..998b025
--- /dev/null
+++ b/virtagent-daemon.c
@@ -0,0 +1,118 @@
+/*
+ * virt-agent - host/guest RPC daemon functions
+ *
+ * Copyright IBM Corp. 2010
+ *
+ * Authors:
+ * Adam Litke <aglitke@linux.vnet.ibm.com>
+ * Michael Roth <mdroth@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <xmlrpc-c/base.h>
+#include <xmlrpc-c/server.h>
+#include <xmlrpc-c/server_abyss.h>
+#include "qemu_socket.h"
+#include "virtagent-daemon.h"
+#include "virtagent-common.h"
+
+static int va_accept(int listen_fd) {
+ struct sockaddr_in saddr;
+ struct sockaddr *addr;
+ socklen_t len;
+ int fd;
+
+ while (1) {
+ len = sizeof(saddr);
+ addr = (struct sockaddr *)&saddr;
+ fd = qemu_accept(listen_fd, addr, &len);
+ if (fd < 0 && errno != EINTR) {
+ LOG("accept() failed");
+ break;
+ } else if (fd >= 0) {
+ TRACE("accepted connection");
+ break;
+ }
+ }
+ return fd;
+}
+
+typedef struct RPCFunction {
+ xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused);
+ const char *func_name;
+} RPCFunction;
+
+static RPCFunction guest_functions[] = {
+ { NULL, NULL }
+};
+static RPCFunction host_functions[] = {
+ { NULL, NULL }
+};
+
+static void va_register_functions(xmlrpc_env *env, xmlrpc_registry *registry,
+ RPCFunction *list)
+{
+ int i;
+ for (i = 0; list[i].func != NULL; ++i) {
+ TRACE("adding func: %s", list[i].func_name);
+ xmlrpc_registry_add_method(env, registry, NULL, list[i].func_name,
+ list[i].func, NULL);
+ }
+}
+
+int va_server_loop(int listen_fd, bool is_host)
+{
+ xmlrpc_registry *registryP;
+ xmlrpc_env env;
+ int ret, fd;
+ char *rpc_request;
+ int rpc_request_len;
+ xmlrpc_mem_block *rpc_response;
+ RPCFunction *func_list = is_host ? host_functions : guest_functions;
+
+ xmlrpc_env_init(&env);
+ registryP = xmlrpc_registry_new(&env);
+ va_register_functions(&env, registryP, func_list);
+
+ while (1) {
+ TRACE("waiting for connection from RPC client");
+ fd = va_accept(listen_fd);
+ if (fd < 0) {
+ TRACE("connection error: %s", strerror(errno));
+ continue;
+ }
+ TRACE("RPC client connected, fetching RPC...");
+ ret = va_get_rpc_request(fd, &rpc_request, &rpc_request_len);
+ if (ret != 0 || rpc_request == NULL) {
+ LOG("error retrieving rpc request");
+ goto out;
+ }
+ TRACE("handling RPC request");
+ rpc_response = xmlrpc_registry_process_call(&env, registryP, NULL,
+ rpc_request,
+ rpc_request_len);
+ if (rpc_response == NULL) {
+ LOG("error handling rpc request");
+ goto out;
+ }
+
+ qemu_free(rpc_request);
+ TRACE("sending RPC response");
+ ret = va_send_rpc_response(fd, rpc_response);
+ if (ret != 0) {
+ LOG("error sending rpc response");
+ goto out;
+ }
+ TRACE("RPC completed");
+ XMLRPC_MEMBLOCK_FREE(char, rpc_response);
+out:
+ closesocket(fd);
+ }
+
+ return 0;
+}
diff --git a/virtagent-daemon.h b/virtagent-daemon.h
new file mode 100644
index 0000000..bb197d0
--- /dev/null
+++ b/virtagent-daemon.h
@@ -0,0 +1,20 @@
+/*
+ * virt-agent - host/guest RPC daemon functions
+ *
+ * Copyright IBM Corp. 2010
+ *
+ * Authors:
+ * Michael Roth <mdroth@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#define GUEST_AGENT_SERVICE_ID "virtagent"
+#define GUEST_AGENT_PATH "/tmp/virtagent-guest.sock"
+#define HOST_AGENT_SERVICE_ID "virtagent-host"
+#define HOST_AGENT_PATH "/tmp/virtagent-host.sock"
+#define VA_GETFILE_MAX 1 << 30
+#define VA_FILEBUF_LEN 16384
+
+int va_server_loop(int listen_fd, bool is_host);
--
1.7.0.4
next prev parent reply other threads:[~2010-10-22 18:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-22 18:45 [Qemu-devel] [RFC][PATCH 00/10] virtagent: host/guest RPC communication agent Michael Roth
2010-10-22 18:45 ` [Qemu-devel] [RFC][PATCH 01/10] virtagent: add common rpc transport defs Michael Roth
2010-10-25 21:39 ` Anthony Liguori
2010-10-25 21:54 ` malc
2010-10-25 22:02 ` Anthony Liguori
2010-10-25 22:32 ` malc
2010-10-22 18:45 ` Michael Roth [this message]
2010-10-22 18:45 ` [Qemu-devel] [RFC][PATCH 03/10] virtagent: qemu-vp, integrate virtagent daemon Michael Roth
2010-10-22 18:45 ` [Qemu-devel] [RFC][PATCH 04/10] virtagent: base RPC client definitions Michael Roth
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 05/10] virtagent: add getfile RPC Michael Roth
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 06/10] virtagent: add agent_viewfile command Michael Roth
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 07/10] virtagent: add getdmesg RPC Michael Roth
2010-10-25 21:42 ` Anthony Liguori
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 08/10] virtagent: add agent_viewdmesg command Michael Roth
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 09/10] virtagent: Makefile/configure changes to build virtagent bits Michael Roth
2010-10-22 18:46 ` [Qemu-devel] [RFC][PATCH 10/10] virtproxy: add compat defs for linking against vl.c Michael Roth
2010-10-23 11:31 ` [Qemu-devel] Re: [RFC][PATCH 00/10] virtagent: host/guest RPC communication agent Andrew Beekhof
2010-10-23 14:41 ` Michael Roth
2010-10-25 9:46 ` Andrew Beekhof
2010-10-25 10:30 ` Andrew Beekhof
2010-10-25 17:06 ` Michael Roth
2010-10-26 7:14 ` Andrew Beekhof
2010-10-25 21:28 ` Anthony Liguori
2010-10-26 7:27 ` Andrew Beekhof
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=1287773165-24855-3-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).