Patchwork [RFC,v5,20/21] virtagent: integrate virtagent server/client via chardev

login
register
mail settings
Submitter Michael Roth
Date Dec. 3, 2010, 6:03 p.m.
Message ID <1291399402-20366-21-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/74201/
State New
Headers show

Comments

Michael Roth - Dec. 3, 2010, 6:03 p.m.
This adds a new chardev, virtagent, which actually just passes back a
socket chardev after connecting to it and initializing the agent.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qemu-char.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
Jes Sorensen - Dec. 7, 2010, 2:44 p.m.
On 12/03/10 19:03, Michael Roth wrote:
> +#include "virtagent-common.h"
> +
> +static CharDriverState *qemu_chr_open_virtagent(QemuOpts *opts)
> +{
> +    CharDriverState *chr;
> +    int fd, ret;
> +
> +    /* revert to/enforce default socket chardev options for virtagent */
> +    if (qemu_opt_get(opts, "path") == NULL) {
> +        qemu_opt_set(opts, "path", "/tmp/virtagent-client.sock");
> +    }

More hardcoded paths, which you defined somewhere in a header already.
Again, please make it configurable.

> +    //qemu_opt_set(opts, "id", "virtagent");

If it isn't needed, please remove it.

Cheers,
Jes

Patch

diff --git a/qemu-char.c b/qemu-char.c
index 88997f9..5e83e09 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2399,6 +2399,54 @@  fail:
     return NULL;
 }
 
+#include "virtagent-common.h"
+
+static CharDriverState *qemu_chr_open_virtagent(QemuOpts *opts)
+{
+    CharDriverState *chr;
+    int fd, ret;
+
+    /* revert to/enforce default socket chardev options for virtagent */
+    if (qemu_opt_get(opts, "path") == NULL) {
+        qemu_opt_set(opts, "path", "/tmp/virtagent-client.sock");
+    }
+    //qemu_opt_set(opts, "id", "virtagent");
+    qemu_opt_set(opts, "server", "on");
+    qemu_opt_set(opts, "wait", "off");
+    qemu_opt_set(opts, "telnet", "off");
+
+    chr = qemu_chr_open_socket(opts);
+    if (chr == NULL) {
+        goto err;
+    }
+
+    /* connect immediately to the socket we set up.
+     * TODO: perhaps we should cut out the socket for the virtagent
+     * chardev case and use a couple pipe pairs for i/o?
+     */
+    fd = unix_connect_opts(opts);
+    if (fd == -1) {
+        fprintf(stderr, "error connecting to virtagent socket: %s",
+                strerror(errno));
+    }
+    socket_set_nonblock(fd);
+
+    /* pass fd to virtagent */
+    ret = va_init(VA_CTX_HOST, fd);
+    if (ret != 0) {
+        fprintf(stderr, "error initializing virtagent");
+        goto err;
+    }
+
+    return chr;
+
+err:
+    if (chr) {
+        qemu_free(chr);
+    }
+    return NULL;
+}
+
 static const struct {
     const char *name;
     CharDriverState *(*open)(QemuOpts *opts);
@@ -2408,6 +2456,7 @@  static const struct {
     { .name = "udp",       .open = qemu_chr_open_udp },
     { .name = "msmouse",   .open = qemu_chr_open_msmouse },
     { .name = "vc",        .open = text_console_init },
+    { .name = "virtagent", .open = qemu_chr_open_virtagent },
 #ifdef _WIN32
     { .name = "file",      .open = qemu_chr_open_win_file_out },
     { .name = "pipe",      .open = qemu_chr_open_win_pipe },