public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     cbbfd20384a3ec91a2123b3526f38689d5cfc07b
Author:     Amit Shah <amit.shah <AT> redhat <DOT> com>
AuthorDate: Mon Mar 21 19:32:58 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:16:53 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=cbbfd203

iohandlers: Add enable/disable_write_fd_handler() functions

These will be used to provide a cleaner API for the nonblocking case.

Signed-off-by: Amit Shah <amit.shah <AT> redhat.com>

---
 qemu-char.h |    3 +++
 vl.c        |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/qemu-char.h b/qemu-char.h
index 7a1924c..185377c 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -116,6 +116,9 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr);
 
 /* async I/O support */
 
+void enable_write_fd_handler(int fd, IOHandler *fd_write);
+void disable_write_fd_handler(int fd);
+
 int qemu_set_fd_handler2(int fd,
                          IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,

diff --git a/vl.c b/vl.c
index 6da06bb..0f50e6c 100644
--- a/vl.c
+++ b/vl.c
@@ -1044,6 +1044,41 @@ typedef struct IOHandlerRecord {
 static QLIST_HEAD(, IOHandlerRecord) io_handlers =
     QLIST_HEAD_INITIALIZER(io_handlers);
 
+static IOHandlerRecord *find_iohandler(int fd)
+{
+    IOHandlerRecord *ioh;
+
+    QLIST_FOREACH(ioh, &io_handlers, next) {
+        if (ioh->fd == fd) {
+            return ioh;
+        }
+    }
+    return NULL;
+}
+
+void enable_write_fd_handler(int fd, IOHandler *fd_write)
+{
+    IOHandlerRecord *ioh;
+
+    ioh = find_iohandler(fd);
+    if (!ioh) {
+        return;
+    }
+
+    ioh->fd_write = fd_write;
+}
+
+void disable_write_fd_handler(int fd)
+{
+    IOHandlerRecord *ioh;
+
+    ioh = find_iohandler(fd);
+    if (!ioh) {
+        return;
+    }
+
+    ioh->fd_write = NULL;
+}
 
 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     2a4c10d4fe8cbaba9d59410931e082f2c0844dbc
Author:     Amit Shah <amit.shah <AT> redhat <DOT> com>
AuthorDate: Mon Mar 21 20:41:42 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:17:06 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=2a4c10d4

char: Add framework for a 'write unblocked' callback

The char layer can let users know that the driver will block on further
input.  For users interested in not blocking, they can assign a function
pointer that will be called back when the driver becomes writable.  This
patch just adds the function pointers to the CharDriverState structure,
future patches will enable the nonblocking and callback functionality.

Signed-off-by: Amit Shah <amit.shah <AT> redhat.com>

---
 qemu-char.c |    3 +++
 qemu-char.h |    5 +++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 3a31d8b..ce76411 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -206,11 +206,14 @@ void qemu_chr_add_handlers(CharDriverState *s,
     }
     s->chr_can_read = handlers->fd_can_read;
     s->chr_read = handlers->fd_read;
+    s->chr_write_unblocked = handlers->fd_write_unblocked;
     s->chr_event = handlers->fd_event;
     s->handler_opaque = opaque;
     if (s->chr_update_read_handler)
         s->chr_update_read_handler(s);
 
+    s->write_blocked = false;
+
     /* We're connecting to an already opened device, so let's make sure we
        also get the open event */
     if (s->opened) {

diff --git a/qemu-char.h b/qemu-char.h
index 185377c..bf06da0 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -61,6 +61,9 @@ struct CharDriverState {
     IOEventHandler *chr_event;
     IOCanReadHandler *chr_can_read;
     IOReadHandler *chr_read;
+    IOHandler *chr_write_unblocked;
+    void (*chr_enable_write_fd_handler)(struct CharDriverState *chr);
+    void (*chr_disable_write_fd_handler)(struct CharDriverState *chr);
     void *handler_opaque;
     void (*chr_send_event)(struct CharDriverState *chr, int event);
     void (*chr_close)(struct CharDriverState *chr);
@@ -71,6 +74,8 @@ struct CharDriverState {
     char *label;
     char *filename;
     int opened;
+    /* Are we in a blocked state? */
+    bool write_blocked;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     c39468c92c0c80ebeabf83241a4e45c1c2177e37
Author:     Amit Shah <amit.shah <AT> redhat <DOT> com>
AuthorDate: Mon Mar 21 20:57:47 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:16:29 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=c39468c9

char: Split out tcp socket close code in a separate function

Signed-off-by: Amit Shah <amit.shah <AT> redhat.com>

---
 qemu-char.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index bd4e944..4b57af9 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1911,6 +1911,21 @@ typedef struct {
 
 static void tcp_chr_accept(void *opaque);
 
+static void tcp_closed(void *opaque)
+{
+    CharDriverState *chr = opaque;
+    TCPCharDriver *s = chr->opaque;
+
+    s->connected = 0;
+    if (s->listen_fd >= 0) {
+        qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
+    }
+    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    closesocket(s->fd);
+    s->fd = -1;
+    qemu_chr_event(chr, CHR_EVENT_CLOSED);
+}
+
 static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     TCPCharDriver *s = chr->opaque;
@@ -2061,15 +2076,7 @@ static void tcp_chr_read(void *opaque)
         len = s->max_size;
     size = tcp_chr_recv(chr, (void *)buf, len);
     if (size == 0) {
-        /* connection closed */
-        s->connected = 0;
-        if (s->listen_fd >= 0) {
-            qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
-        }
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
-        closesocket(s->fd);
-        s->fd = -1;
-        qemu_chr_event(chr, CHR_EVENT_CLOSED);
+        tcp_closed(chr);
     } else if (size > 0) {
         if (s->do_telnetopt)
             tcp_chr_process_IAC_bytes(chr, s, buf, &size);



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     993738bf3450002fda0198c72113fc9b6aa15b56
Author:     Alon Levy <alevy <AT> redhat <DOT> com>
AuthorDate: Tue Mar 22 10:27:59 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:18:13 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=993738bf

spice-qemu-char.c: add throttling

BZ: 672191

upstream: not submitted (explained below)

Adds throttling support to spicevmc chardev. Uses a timer to avoid recursing:
1. spice-server: reds.c:            read_from_vdi_port
2. qemu:         spice-qemu-char.c: vmc_read
3.                                  chr_write_unblocked
                                (calls virtio_serial_throttle_port(port, false))
4. qemu:         virtio ...
5. qemu:         spice-qemu-char.c: spice_chr_write
6. qemu:         spice-qemu-char.c: wakeup (calls into spice-server)
7. spice-server: ...
8. qemu:         spice-qemu-char.c: vmc_read

Instead, in vmc_read if we were throttled and we are just about to return
all the bytes we will set a timer to be triggered immediately to call
chr_write_unblocked. Then we return after 2 above, and 3 is called from the
timer callback. This also means we can later remove some ugly recursion protection
from spice-server.

The other tricky point in this patch is not returning the leftover chunk twice.
When we throttle, by definition we have data that spice server didn't consume.
It is being kept by virtio-serial, and by us. The next vmc_read callback needs
to not return it, but just do unthrottling. Then virtio will give us the remaining
chunk as usual in spice_chr_write, and we will pass it to spice server in the
next vmc_read.

This patch relies on Amit's series to expose throttling to chardev's, which
was not accepted upstream, and will not be accepted upstream until the mainloop
is reworked to use glib.

---
 spice-qemu-char.c |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 517f337..91467d5 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -1,4 +1,6 @@
 #include "config-host.h"
+#include "qemu-common.h"
+#include "qemu-timer.h"
 #include "trace.h"
 #include "ui/qemu-spice.h"
 #include <spice.h>
@@ -25,6 +27,7 @@ typedef struct SpiceCharDriver {
     uint8_t               *datapos;
     ssize_t               bufsize, datalen;
     uint32_t              debug;
+    QEMUTimer             *unblock_timer;
 } SpiceCharDriver;
 
 static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
@@ -51,6 +54,17 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
     return out;
 }
 
+static void spice_chr_unblock(void *opaque)
+{
+    SpiceCharDriver *scd = opaque;
+
+    if (scd->chr->chr_write_unblocked == NULL) {
+        dprintf(scd, 1, "%s: backend doesn't support unthrottling.\n", __func__);
+        return;
+    }
+    scd->chr->chr_write_unblocked(scd->chr->handler_opaque);
+}
+
 static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
 {
     SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
@@ -62,9 +76,16 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
         scd->datapos += bytes;
         scd->datalen -= bytes;
         assert(scd->datalen >= 0);
-        if (scd->datalen == 0) {
-            scd->datapos = 0;
-        }
+    }
+    if (scd->datalen == 0 && scd->chr->write_blocked) {
+        dprintf(scd, 1, "%s: unthrottling (%d)\n", __func__, bytes);
+        scd->chr->write_blocked = false;
+        /*
+         * set a timer instead of calling scd->chr->chr_write_unblocked directly,
+         * because that will call back into spice_chr_write (see
+         * virtio-console.c:chr_write_unblocked), which is unwanted.
+         */
+        qemu_mod_timer(scd->unblock_timer, 0);
     }
     trace_spice_vmc_read(bytes, len);
     return bytes;
@@ -107,6 +128,7 @@ static void vmc_unregister_interface(SpiceCharDriver *scd)
 static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     SpiceCharDriver *s = chr->opaque;
+    int read_bytes;
 
     dprintf(s, 2, "%s: %d\n", __func__, len);
     vmc_register_interface(s);
@@ -119,7 +141,15 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     s->datapos = s->buffer;
     s->datalen = len;
     spice_server_char_device_wakeup(&s->sin);
-    return len;
+    read_bytes = len - s->datalen;
+    if (read_bytes != len) {
+        dprintf(s, 1, "%s: throttling: %d < %d (%zd)\n", __func__,
+                read_bytes, len, s->bufsize);
+        s->chr->write_blocked = true;
+        /* We'll get passed in the unconsumed data with the next call */
+        s->datalen = 0;
+    }
+    return read_bytes;
 }
 
 static void spice_chr_close(struct CharDriverState *chr)
@@ -183,6 +213,7 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts)
     chr->opaque = s;
     chr->chr_write = spice_chr_write;
     chr->chr_close = spice_chr_close;
+    s->unblock_timer = qemu_new_timer(vm_clock, spice_chr_unblock, s);
 
     qemu_chr_generic_open(chr);
 



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     94c25ccc6ccd5e2f44d98f31cdaa65c3848404c5
Author:     Amit Shah <amit.shah <AT> redhat <DOT> com>
AuthorDate: Mon Mar 21 21:02:47 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:17:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=94c25ccc

char: Equip the unix/tcp backend to handle nonblocking writes#

Now that the infrastructure is in place to return -EAGAIN to callers,
individual char drivers can set their update_fd_handlers() function to
set or remove an fd's write handler.  This handler checks if the driver
became writable.

A generic callback routine is used for unblocking writes and letting
users of chardevs know that a driver became writable again.

Signed-off-by: Amit Shah <amit.shah <AT> redhat.com>

---
 qemu-char.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index eed61d6..7517f64 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -107,6 +107,19 @@
 static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
     QTAILQ_HEAD_INITIALIZER(chardevs);
 
+/*
+ * Generic routine that gets called when chardev becomes writable.
+ * Lets chardev user know it's OK to send more data.
+ */
+static void char_write_unblocked(void *opaque)
+{
+    CharDriverState *chr = opaque;
+
+    chr->write_blocked = false;
+    chr->chr_disable_write_fd_handler(chr);
+    chr->chr_write_unblocked(chr->handler_opaque);
+}
+
 static void qemu_chr_event(CharDriverState *s, int event)
 {
     /* Keep track if the char device is open */
@@ -2261,6 +2274,25 @@ static void tcp_chr_close(CharDriverState *chr)
     qemu_chr_event(chr, CHR_EVENT_CLOSED);
 }
 
+static void tcp_enable_write_fd_handler(CharDriverState *chr)
+{
+    TCPCharDriver *s = chr->opaque;
+
+    /*
+     * This function is called only after tcp_chr_connect() is called
+     * (either in 'server' mode or client mode.  So we're sure of
+     * s->fd being initialised.
+     */
+    enable_write_fd_handler(s->fd, char_write_unblocked);
+}
+
+static void tcp_disable_write_fd_handler(CharDriverState *chr)
+{
+    TCPCharDriver *s = chr->opaque;
+
+    disable_write_fd_handler(s->fd);
+}
+
 static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
 {
     CharDriverState *chr = NULL;
@@ -2313,6 +2345,8 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
     chr->chr_write = tcp_chr_write;
     chr->chr_close = tcp_chr_close;
     chr->get_msgfd = tcp_get_msgfd;
+    chr->chr_enable_write_fd_handler = tcp_enable_write_fd_handler;
+    chr->chr_disable_write_fd_handler = tcp_disable_write_fd_handler;
 
     if (is_listen) {
         s->listen_fd = fd;



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     23b8806eb8c9310ea46504740b2cb1fb9331c727
Author:     Amit Shah <amit.shah <AT> redhat <DOT> com>
AuthorDate: Mon Mar 21 21:05:10 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:17:50 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=23b8806e

char: Throttle when host connection is down#

When the host-side connection goes down, throttle the virtio-serial bus
and later unthrottle when a connection gets established.  This helps
prevent any lost IO (guest->host) while the host connection was down.

Bugzilla: 621484

This commit actually helps the bug mentioned above as no writes will now
get lost because of the throttling done here.  With just the patches
sent earlier for that bug, one write will end up getting lost in the
worst case (host d/c, guest write, host connect).

Signed-off-by: Amit Shah <amit.shah <AT> redhat.com>

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 7517f64..2ef972f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -141,6 +141,9 @@ static void qemu_chr_generic_open_bh(void *opaque)
 {
     CharDriverState *s = opaque;
     qemu_chr_event(s, CHR_EVENT_OPENED);
+    if (s->write_blocked) {
+        char_write_unblocked(s);
+    }
     qemu_bh_delete(s->bh);
     s->bh = NULL;
 }
@@ -2025,6 +2028,17 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
         ret = send_all(chr, s->fd, buf, len);
         if (ret == -1 && errno == EPIPE) {
             tcp_closed(chr);
+
+            if (chr->chr_enable_write_fd_handler && chr->chr_write_unblocked) {
+                /*
+                 * Since we haven't written out anything, let's say
+                 * we're throttled.  This will prevent any output from
+                 * the guest getting lost if host-side chardev goes
+                 * down.  Unthrottle when we re-connect.
+                 */
+                chr->write_blocked = true;
+                return 0;
+            }
         }
     } else {
         /* XXX: indicate an error ? */



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     fda9ea74f542acd928633387b2632a3d96a5a0bb
Author:     Alon Levy <alevy <AT> redhat <DOT> com>
AuthorDate: Tue Mar 22 10:28:00 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:18:24 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=fda9ea74

spice-qemu-char.c: remove intermediate buffer

BZ: 672191
upstream: not submitted (explained below)

virtio-serial's buffer is valid when it calls us, and we don't
access it otherwise: vmc_read is only called in response to wakeup,
or else we set datalen=0 and throttle. Then vmc_read is called back,
we return 0 (not accessing the buffer) and set the timer to unthrottle.

Also make datalen int and not ssize_t (to fit spice_chr_write signature).

This relied on the previous patch that introduces throttling, which
can't go upstream right now as explained in that patch.

---
 spice-qemu-char.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 91467d5..ed7851e 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -23,9 +23,8 @@ typedef struct SpiceCharDriver {
     SpiceCharDeviceInstance     sin;
     char                  *subtype;
     bool                  active;
-    uint8_t               *buffer;
-    uint8_t               *datapos;
-    ssize_t               bufsize, datalen;
+    const uint8_t         *datapos;
+    int                   datalen;
     uint32_t              debug;
     QEMUTimer             *unblock_timer;
 } SpiceCharDriver;
@@ -70,7 +69,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
     SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
     int bytes = MIN(len, scd->datalen);
 
-    dprintf(scd, 2, "%s: %p %d/%d/%zd\n", __func__, scd->datapos, len, bytes, scd->datalen);
+    dprintf(scd, 2, "%s: %p %d/%d/%d\n", __func__, scd->datapos, len, bytes, scd->datalen);
     if (bytes > 0) {
         memcpy(buf, scd->datapos, bytes);
         scd->datapos += bytes;
@@ -133,18 +132,13 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     dprintf(s, 2, "%s: %d\n", __func__, len);
     vmc_register_interface(s);
     assert(s->datalen == 0);
-    if (s->bufsize < len) {
-        s->bufsize = len;
-        s->buffer = qemu_realloc(s->buffer, s->bufsize);
-    }
-    memcpy(s->buffer, buf, len);
-    s->datapos = s->buffer;
+    s->datapos = buf;
     s->datalen = len;
     spice_server_char_device_wakeup(&s->sin);
     read_bytes = len - s->datalen;
     if (read_bytes != len) {
-        dprintf(s, 1, "%s: throttling: %d < %d (%zd)\n", __func__,
-                read_bytes, len, s->bufsize);
+        dprintf(s, 1, "%s: throttling: %d < %d\n", __func__,
+                read_bytes, len);
         s->chr->write_blocked = true;
         /* We'll get passed in the unconsumed data with the next call */
         s->datalen = 0;



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     db387ffd31776d9f902fd295ffc961e631ed4fa4
Author:     Hans de Goede <hdegoede <AT> redhat <DOT> com>
AuthorDate: Fri Mar 18 14:23:21 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:18:34 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=db387ffd

chardev: Allow frontends to notify backends of guest open / close

Some frontends know when the guest has opened the "channel" and is actively
listening to it, for example virtio-serial. This patch adds 2 new qemu-chardev
functions which can be used by frontends to signal guest open / close, and
allows interested backends to listen to this.

Signed-off-by: Hans de Goede <hdegoede <AT> redhat.com>

---
 qemu-char.c |   17 +++++++++++++++++
 qemu-char.h |    4 ++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 2ef972f..d52eb51 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -507,6 +507,9 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
+    /* Frontend guest-open / -close notification is not support with muxes */
+    chr->chr_guest_open = NULL;
+    chr->chr_guest_close = NULL;
 
     /* Muxes are always open on creation */
     qemu_chr_generic_open(chr);
@@ -2712,6 +2715,20 @@ void qemu_chr_set_echo(struct CharDriverState *chr, bool echo)
     }
 }
 
+void qemu_chr_guest_open(struct CharDriverState *chr)
+{
+    if (chr->chr_guest_open) {
+        chr->chr_guest_open(chr);
+    }
+}
+
+void qemu_chr_guest_close(struct CharDriverState *chr)
+{
+    if (chr->chr_guest_close) {
+        chr->chr_guest_close(chr);
+    }
+}
+
 void qemu_chr_close(CharDriverState *chr)
 {
     QTAILQ_REMOVE(&chardevs, chr, next);

diff --git a/qemu-char.h b/qemu-char.h
index bf06da0..f3b9bf4 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -69,6 +69,8 @@ struct CharDriverState {
     void (*chr_close)(struct CharDriverState *chr);
     void (*chr_accept_input)(struct CharDriverState *chr);
     void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
+    void (*chr_guest_open)(struct CharDriverState *chr);
+    void (*chr_guest_close)(struct CharDriverState *chr);
     void *opaque;
     QEMUBH *bh;
     char *label;
@@ -91,6 +93,8 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
                                     void (*init)(struct CharDriverState *s));
 CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s));
 void qemu_chr_set_echo(struct CharDriverState *chr, bool echo);
+void qemu_chr_guest_open(struct CharDriverState *chr);
+void qemu_chr_guest_close(struct CharDriverState *chr);
 void qemu_chr_close(CharDriverState *chr);
 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     7525703fbbae309f4e1a745934530ae3d21834aa
Author:     Hans de Goede <hdegoede <AT> redhat <DOT> com>
AuthorDate: Fri Mar 18 14:35:27 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:18:53 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=7525703f

spice-chardev: listen to frontend guest open / close

Note the vmc_register_interface() in spice_chr_write is left in place
in case someone uses spice-chardev with a frontend which does not have
guest open / close notification.

Signed-off-by: Hans de Goede <hdegoede <AT> redhat.com>

---
 spice-qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index ed7851e..343146c 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -155,6 +155,18 @@ static void spice_chr_close(struct CharDriverState *chr)
     qemu_free(s);
 }
 
+static void spice_chr_guest_open(struct CharDriverState *chr)
+{
+    SpiceCharDriver *s = chr->opaque;
+    vmc_register_interface(s);
+}
+
+static void spice_chr_guest_close(struct CharDriverState *chr)
+{
+    SpiceCharDriver *s = chr->opaque;
+    vmc_unregister_interface(s);
+}
+
 static void print_allowed_subtypes(void)
 {
     const char** psubtype;
@@ -207,6 +219,8 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts)
     chr->opaque = s;
     chr->chr_write = spice_chr_write;
     chr->chr_close = spice_chr_close;
+    chr->chr_guest_open = spice_chr_guest_open;
+    chr->chr_guest_close = spice_chr_guest_close;
     s->unblock_timer = qemu_new_timer(vm_clock, spice_chr_unblock, s);
 
     qemu_chr_generic_open(chr);



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-21 20:19 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-21 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     4d2c1d53b9ca086ea9c583581684a84b889e6469
Author:     Hans de Goede <hdegoede <AT> redhat <DOT> com>
AuthorDate: Tue Mar 22 15:28:41 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Thu Jul 21 20:19:02 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=4d2c1d53

spice-qemu-char: Fix flow control in client -> guest direction

In the old spice-vmc device we used to have:
last_out = virtio_serial_write(&svc->port, p, MIN(len, VMC_MAX_HOST_WRITE));
if (last_out > 0)
   ...

Now in the chardev backend we have:
last_out = MIN(len, VMC_MAX_HOST_WRITE);
qemu_chr_read(scd->chr, p, last_out);
if (last_out > 0) {
   ...

Which causes us to no longer detect if the virtio port is not ready
to receive data from us. chardev actually has a mechanism to detect this,
but it requires a separate call to qemu_chr_can_read, before calling
qemu_chr_read (which return void).

This patch uses qemu_chr_can_read to fix the flow control from client to
guest.

Signed-off-by: Hans de Goede <hdegoede <AT> redhat.com>

---
 spice-qemu-char.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 343146c..def713a 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -38,14 +38,13 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
 
     while (len > 0) {
         last_out = MIN(len, VMC_MAX_HOST_WRITE);
-        qemu_chr_read(scd->chr, p, last_out);
-        if (last_out > 0) {
-            out += last_out;
-            len -= last_out;
-            p += last_out;
-        } else {
+        if (qemu_chr_can_read(scd->chr) < last_out) {
             break;
         }
+        qemu_chr_read(scd->chr, p, last_out);
+        out += last_out;
+        len -= last_out;
+        p += last_out;
     }
 
     dprintf(scd, 3, "%s: %lu/%zd\n", __func__, out, len + out);



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: /
@ 2011-07-26 17:16 Doug Goldstein
  0 siblings, 0 replies; 11+ messages in thread
From: Doug Goldstein @ 2011-07-26 17:16 UTC (permalink / raw
  To: gentoo-commits

commit:     e9cd593a7782ca07b2412b8d27ca01743212fb71
Author:     Doug Goldstein <cardoe <AT> cardoe <DOT> com>
AuthorDate: Fri Jul 22 14:02:29 2011 +0000
Commit:     Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Fri Jul 22 14:02:29 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=e9cd593a

Merge branch 'qemu-kvm-0.14.1-gentoo' of git+ssh://git.overlays.gentoo.org/proj/qemu-kvm into qemu-kvm-0.14.1-gentoo

Conflicts:
	hw/virtio.c




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-07-26 17:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-21 20:19 [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.14.1-gentoo commit in: / Doug Goldstein
  -- strict thread matches above, loose matches on Subject: below --
2011-07-26 17:16 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein
2011-07-21 20:19 Doug Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox