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 04/10] virtagent: base RPC client definitions
Date: Fri, 22 Oct 2010 13:45:59 -0500 [thread overview]
Message-ID: <1287773165-24855-5-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1287773165-24855-1-git-send-email-mdroth@linux.vnet.ibm.com>
Base skeleton and helpers for executing RPC commands. Monitor commands
will result in a connect() being issued to the virtagent service socket,
which will then be transported to the listening RPC server in the guest
via the virtproxy layer, RPC requests are then sent/recieved via http
over the resulting connection.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
monitor.c | 1 +
qerror.c | 4 ++
qerror.h | 3 ++
virtagent.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
virtagent.h | 25 +++++++++++++++
5 files changed, 129 insertions(+), 0 deletions(-)
create mode 100644 virtagent.c
create mode 100644 virtagent.h
diff --git a/monitor.c b/monitor.c
index 260cc02..6c99206 100644
--- a/monitor.c
+++ b/monitor.c
@@ -42,6 +42,7 @@
#include "audio/audio.h"
#include "disas.h"
#include "balloon.h"
+#include "virtagent.h"
#include "qemu-timer.h"
#include "migration.h"
#include "kvm.h"
diff --git a/qerror.c b/qerror.c
index ac2cdaf..2f111a9 100644
--- a/qerror.c
+++ b/qerror.c
@@ -200,6 +200,10 @@ static const QErrorStringTable qerror_table[] = {
.error_fmt = QERR_VNC_SERVER_FAILED,
.desc = "Could not start VNC server on %(target)",
},
+ {
+ .error_fmt = QERR_RPC_FAILED,
+ .desc = "An RPC error has occurred",
+ },
{}
};
diff --git a/qerror.h b/qerror.h
index 943a24b..43cce4a 100644
--- a/qerror.h
+++ b/qerror.h
@@ -165,4 +165,7 @@ QError *qobject_to_qerror(const QObject *obj);
#define QERR_VNC_SERVER_FAILED \
"{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }"
+#define QERR_RPC_FAILED \
+ "{ 'class': 'RPCFailed', 'data': { 'code': %i, 'message': %s } }"
+
#endif /* QERROR_H */
diff --git a/virtagent.c b/virtagent.c
new file mode 100644
index 0000000..2234bef
--- /dev/null
+++ b/virtagent.c
@@ -0,0 +1,96 @@
+/*
+ * virt-agent - host/guest RPC client 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 "sysemu.h"
+#include "monitor.h"
+#include "qjson.h"
+#include "qint.h"
+#include "cpu-common.h"
+#include "kvm.h"
+#include "trace.h"
+#include "qemu_socket.h"
+#include "xmlrpc.h"
+#include "xmlrpc_client.h"
+#include "virtagent-daemon.h"
+#include "virtagent-common.h"
+#include "virtagent.h"
+
+static int rpc_has_error(xmlrpc_env *env)
+{
+ if (env->fault_occurred) {
+ LOG("An RPC error has occurred (%i): %s\n", env->fault_code, env->fault_string);
+ //qerror_report(QERR_RPC_FAILED, env->fault_code, env->fault_string);
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * Get a connected socket that can be used to make an RPC call
+ * This interface will eventually return the connected virtproxy socket for the
+ * virt-agent channel
+ */
+static int get_transport_fd(void)
+{
+ /* TODO: eventually this will need a path that is unique to other
+ * instances of qemu-vp/qemu. for the integrated qemu-vp we should
+ * explore the possiblity of not requiring a unix socket under the
+ * covers, as well as having client init code set up the oforward
+ * for the service rather than qemu-vp
+ */
+ int ret;
+ int fd = unix_connect(GUEST_AGENT_PATH_CLIENT);
+ if (fd < 0) {
+ LOG("failed to connect to virtagent service");
+ }
+ ret = fcntl(fd, F_GETFL);
+ ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
+ return fd;
+}
+
+static int rpc_execute(xmlrpc_env *const env, const char *function,
+ xmlrpc_value *params, RPCRequest *rpc_data)
+{
+ xmlrpc_mem_block *call_xml;
+ int fd, ret;
+
+ fd = get_transport_fd();
+ if (fd < 0) {
+ LOG("invalid fd");
+ ret = -1;
+ goto out;
+ }
+
+ call_xml = XMLRPC_MEMBLOCK_NEW(char, env, 0);
+ xmlrpc_serialize_call(env, call_xml, function, params);
+ if (rpc_has_error(env)) {
+ ret = -EREMOTE;
+ goto out_callxml;
+ }
+
+ rpc_data->req_xml = call_xml;
+ ret = va_transport_rpc_call(fd, rpc_data);
+ if (ret != 0) {
+ ret = -1;
+ goto out_callxml;
+ } else {
+ ret = 0;
+ goto out;
+ }
+
+out_callxml:
+ XMLRPC_MEMBLOCK_FREE(char, call_xml);
+out:
+ return ret;
+}
diff --git a/virtagent.h b/virtagent.h
new file mode 100644
index 0000000..abdb32a
--- /dev/null
+++ b/virtagent.h
@@ -0,0 +1,25 @@
+/*
+ * virt-agent - host/guest RPC client 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.
+ *
+ */
+
+#ifndef VIRTAGENT_H
+#define VIRTAGENT_H
+
+#include "monitor.h"
+#include "virtagent-common.h"
+
+#define GUEST_AGENT_PATH_CLIENT "/tmp/virtagent-guest-client.sock"
+#define HOST_AGENT_PATH_CLIENT "/tmp/virtagent-host-client.sock"
+#define VA_MAX_CHUNK_SIZE 4096 /* max bytes at a time for get/send file */
+
+#endif /* VIRTAGENT_H */
--
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 ` [Qemu-devel] [RFC][PATCH 02/10] virtagent: base definitions for host/guest RPC daemon Michael Roth
2010-10-22 18:45 ` [Qemu-devel] [RFC][PATCH 03/10] virtagent: qemu-vp, integrate virtagent daemon Michael Roth
2010-10-22 18:45 ` Michael Roth [this message]
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-5-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).