* [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches
@ 2013-03-13 13:59 Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 1/7] virtio-console: Also throttle when less was written then requested Hans de Goede
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Amit Shah, Marc-André Lureau, Gerd Hoffmann
Here is a series adding watch support to the spicevmc chardev backend
and flowcontrol support to the usb-redir device. It begins with a few
chardev related bugfixes which were found during the development of this
series.
Note that this series is based *on top of* Gerd Hoffmann's chardev.4 series
to avoid conflicts with that series.
Regards,
Hans
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 1/7] virtio-console: Also throttle when less was written then requested
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
This is necessary so that we get properly woken up to write the rest.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Amit Shah <amit.shah@redhat.com>
---
hw/virtio-console.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index e2d1c58..1d87c5b 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -47,7 +47,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
ret = qemu_chr_fe_write(vcon->chr, buf, len);
trace_virtio_console_flush_buf(port->id, len, ret);
- if (ret <= 0) {
+ if (ret < len) {
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
/*
@@ -56,7 +56,8 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
* we had a finer-grained message, like -EPIPE, we could close
* this connection.
*/
- ret = 0;
+ if (ret < 0)
+ ret = 0;
if (!k->is_console) {
virtio_serial_throttle_port(port, true);
qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 1/7] virtio-console: Also throttle when less was written then requested Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-14 7:35 ` Amit Shah
2013-03-13 13:59 ` [Qemu-devel] [PATCH 3/7] spice-qemu-char: Fix name parameter issues after qapi-ifying Hans de Goede
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/virtio-console.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 1d87c5b..ec0f91b 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -18,6 +18,7 @@
typedef struct VirtConsole {
VirtIOSerialPort port;
CharDriverState *chr;
+ guint watch;
} VirtConsole;
/*
@@ -29,6 +30,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
{
VirtConsole *vcon = opaque;
+ vcon->watch = 0;
virtio_serial_throttle_port(&vcon->port, false);
return FALSE;
}
@@ -60,8 +62,10 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
ret = 0;
if (!k->is_console) {
virtio_serial_throttle_port(port, true);
- qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
- vcon);
+ if (!vcon->watch) {
+ vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
+ chr_write_unblocked, vcon);
+ }
}
}
return ret;
@@ -86,6 +90,10 @@ static void guest_close(VirtIOSerialPort *port)
if (!vcon->chr) {
return;
}
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ vcon->watch = 0;
+ }
qemu_chr_fe_close(vcon->chr);
}
@@ -116,6 +124,10 @@ static void chr_event(void *opaque, int event)
virtio_serial_open(&vcon->port);
break;
case CHR_EVENT_CLOSED:
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ vcon->watch = 0;
+ }
virtio_serial_close(&vcon->port);
break;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 3/7] spice-qemu-char: Fix name parameter issues after qapi-ifying
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 1/7] virtio-console: Also throttle when less was written then requested Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 4/7] spice-qemu-char: Remove dead debugging code Hans de Goede
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
The strings passed in through the qapi calls are dynamic memory, since
we want to have them stick around longer then just the call to
qemu_chr_open_spice_* we need to strdup them.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
spice-qemu-char.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 0c92ca8..a94f76b 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -185,6 +185,11 @@ static void spice_chr_close(struct CharDriverState *chr)
printf("%s\n", __func__);
vmc_unregister_interface(s);
QLIST_REMOVE(s, next);
+
+ g_free((char *)s->sin.subtype);
+#if SPICE_SERVER_VERSION >= 0x000c02
+ g_free((char *)s->sin.portname);
+#endif
g_free(s);
}
@@ -226,7 +231,7 @@ static CharDriverState *chr_open(const char *subtype)
s = g_malloc0(sizeof(SpiceCharDriver));
s->chr = chr;
s->active = false;
- s->sin.subtype = subtype;
+ s->sin.subtype = g_strdup(subtype);
chr->opaque = s;
chr->chr_write = spice_chr_write;
chr->chr_close = spice_chr_close;
@@ -284,7 +289,7 @@ CharDriverState *qemu_chr_open_spice_port(const char *name)
chr = chr_open("port");
s = chr->opaque;
- s->sin.portname = name;
+ s->sin.portname = g_strdup(name);
return chr;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 4/7] spice-qemu-char: Remove dead debugging code
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
` (2 preceding siblings ...)
2013-03-13 13:59 ` [Qemu-devel] [PATCH 3/7] spice-qemu-char: Fix name parameter issues after qapi-ifying Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 5/7] spice-qemu-char: Add watch support Hans de Goede
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
Since commit d62e5f7036a018b2ad09f17ebd481bd28953d783
"chardev: add spice support to qapi"
It is impossible to set the debug parameter, so all the dprintf calls
are essentially nops. Since we've not needed the debug parameter in ages this
is not a problem, if it later turns out we do need some more debugging options
we can add more trace-points.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
spice-qemu-char.c | 17 -----------------
1 file changed, 17 deletions(-)
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index a94f76b..8a9236d 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -8,14 +8,6 @@
#include "qemu/osdep.h"
-#define dprintf(_scd, _level, _fmt, ...) \
- do { \
- static unsigned __dprintf_counter = 0; \
- if (_scd->debug >= _level) { \
- fprintf(stderr, "scd: %3d: " _fmt, ++__dprintf_counter, ## __VA_ARGS__);\
- } \
- } while (0)
-
typedef struct SpiceCharDriver {
CharDriverState* chr;
SpiceCharDeviceInstance sin;
@@ -24,7 +16,6 @@ typedef struct SpiceCharDriver {
uint8_t *buffer;
uint8_t *datapos;
ssize_t bufsize, datalen;
- uint32_t debug;
QLIST_ENTRY(SpiceCharDriver) next;
} SpiceCharDriver;
@@ -49,7 +40,6 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
p += last_out;
}
- dprintf(scd, 3, "%s: %zu/%zd\n", __func__, out, len + out);
trace_spice_vmc_write(out, len + out);
return out;
}
@@ -59,7 +49,6 @@ 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);
if (bytes > 0) {
memcpy(buf, scd->datapos, bytes);
scd->datapos += bytes;
@@ -84,11 +73,9 @@ static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event)
chr_event = CHR_EVENT_BREAK;
break;
default:
- dprintf(scd, 2, "%s: unknown %d\n", __func__, event);
return;
}
- dprintf(scd, 2, "%s: %d\n", __func__, event);
trace_spice_vmc_event(chr_event);
qemu_chr_be_event(scd->chr, chr_event);
}
@@ -141,7 +128,6 @@ static void vmc_register_interface(SpiceCharDriver *scd)
if (scd->active) {
return;
}
- dprintf(scd, 1, "%s\n", __func__);
scd->sin.base.sif = &vmc_interface.base;
qemu_spice_add_interface(&scd->sin.base);
scd->active = true;
@@ -153,7 +139,6 @@ static void vmc_unregister_interface(SpiceCharDriver *scd)
if (!scd->active) {
return;
}
- dprintf(scd, 1, "%s\n", __func__);
spice_server_remove_interface(&scd->sin.base);
scd->active = false;
trace_spice_vmc_unregister_interface(scd);
@@ -164,7 +149,6 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
SpiceCharDriver *s = chr->opaque;
- dprintf(s, 2, "%s: %d\n", __func__, len);
vmc_register_interface(s);
assert(s->datalen == 0);
if (s->bufsize < len) {
@@ -182,7 +166,6 @@ static void spice_chr_close(struct CharDriverState *chr)
{
SpiceCharDriver *s = chr->opaque;
- printf("%s\n", __func__);
vmc_unregister_interface(s);
QLIST_REMOVE(s, next);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 5/7] spice-qemu-char: Add watch support
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
` (3 preceding siblings ...)
2013-03-13 13:59 ` [Qemu-devel] [PATCH 4/7] spice-qemu-char: Remove dead debugging code Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 6/7] spice-qemu-char.c: Remove intermediate buffer Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 7/7] usb-redir: Add flow control support Hans de Goede
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
spice-qemu-char.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 63 insertions(+), 4 deletions(-)
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 8a9236d..e9eea0d 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -13,12 +13,18 @@ typedef struct SpiceCharDriver {
SpiceCharDeviceInstance sin;
char *subtype;
bool active;
+ bool blocked;
uint8_t *buffer;
uint8_t *datapos;
ssize_t bufsize, datalen;
QLIST_ENTRY(SpiceCharDriver) next;
} SpiceCharDriver;
+typedef struct SpiceCharSource {
+ GSource source;
+ SpiceCharDriver *scd;
+} SpiceCharSource;
+
static QLIST_HEAD(, SpiceCharDriver) spice_chars =
QLIST_HEAD_INITIALIZER(spice_chars);
@@ -54,9 +60,10 @@ 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->datapos = 0;
+ scd->blocked = false;
}
trace_spice_vmc_read(bytes, len);
return bytes;
@@ -144,10 +151,54 @@ static void vmc_unregister_interface(SpiceCharDriver *scd)
trace_spice_vmc_unregister_interface(scd);
}
+static gboolean spice_char_source_prepare(GSource *source, gint *timeout)
+{
+ SpiceCharSource *src = (SpiceCharSource *)source;
+
+ *timeout = -1;
+
+ return !src->scd->blocked;
+}
+
+static gboolean spice_char_source_check(GSource *source)
+{
+ SpiceCharSource *src = (SpiceCharSource *)source;
+
+ return !src->scd->blocked;
+}
+
+static gboolean spice_char_source_dispatch(GSource *source,
+ GSourceFunc callback, gpointer user_data)
+{
+ GIOFunc func = (GIOFunc)callback;
+
+ return func(NULL, G_IO_OUT, user_data);
+}
+
+GSourceFuncs SpiceCharSourceFuncs = {
+ .prepare = spice_char_source_prepare,
+ .check = spice_char_source_check,
+ .dispatch = spice_char_source_dispatch,
+};
+
+static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)
+{
+ SpiceCharDriver *scd = chr->opaque;
+ SpiceCharSource *src;
+
+ assert(cond == G_IO_OUT);
+
+ src = (SpiceCharSource *)g_source_new(&SpiceCharSourceFuncs,
+ sizeof(SpiceCharSource));
+ src->scd = scd;
+
+ return (GSource *)src;
+}
static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
SpiceCharDriver *s = chr->opaque;
+ int read_bytes;
vmc_register_interface(s);
assert(s->datalen == 0);
@@ -159,7 +210,14 @@ 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) {
+ /* We'll get passed in the unconsumed data with the next call */
+ s->datalen = 0;
+ s->datapos = NULL;
+ s->blocked = true;
+ }
+ return read_bytes;
}
static void spice_chr_close(struct CharDriverState *chr)
@@ -217,6 +275,7 @@ static CharDriverState *chr_open(const char *subtype)
s->sin.subtype = g_strdup(subtype);
chr->opaque = s;
chr->chr_write = spice_chr_write;
+ chr->chr_add_watch = spice_chr_add_watch;
chr->chr_close = spice_chr_close;
chr->chr_guest_open = spice_chr_guest_open;
chr->chr_guest_close = spice_chr_guest_close;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 6/7] spice-qemu-char.c: Remove intermediate buffer
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
` (4 preceding siblings ...)
2013-03-13 13:59 ` [Qemu-devel] [PATCH 5/7] spice-qemu-char: Add watch support Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 7/7] usb-redir: Add flow control support Hans de Goede
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Alon Levy, Marc-André Lureau, Gerd Hoffmann,
Hans de Goede
From: Alon Levy <alevy@redhat.com>
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).
HdG: Update to apply to spice-qemu-char with new gio-channel based
flowcontrol support.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
spice-qemu-char.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index e9eea0d..99cb315 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -14,9 +14,8 @@ typedef struct SpiceCharDriver {
char *subtype;
bool active;
bool blocked;
- uint8_t *buffer;
- uint8_t *datapos;
- ssize_t bufsize, datalen;
+ const uint8_t *datapos;
+ int datalen;
QLIST_ENTRY(SpiceCharDriver) next;
} SpiceCharDriver;
@@ -202,12 +201,7 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
vmc_register_interface(s);
assert(s->datalen == 0);
- if (s->bufsize < len) {
- s->bufsize = len;
- s->buffer = g_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;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 7/7] usb-redir: Add flow control support
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
` (5 preceding siblings ...)
2013-03-13 13:59 ` [Qemu-devel] [PATCH 6/7] spice-qemu-char.c: Remove intermediate buffer Hans de Goede
@ 2013-03-13 13:59 ` Hans de Goede
6 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-13 13:59 UTC (permalink / raw)
To: qemu-devel
Cc: Amit Shah, Hans de Goede, Marc-André Lureau, Gerd Hoffmann
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/usb/redirect.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index c519b9b..9ba714d 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -104,6 +104,8 @@ struct USBRedirDevice {
/* Data passed from chardev the fd_read cb to the usbredirparser read cb */
const uint8_t *read_buf;
int read_buf_size;
+ /* Active chardev-watch-tag */
+ guint watch;
/* For async handling of close */
QEMUBH *chardev_close_bh;
/* To delay the usb attach in case of quick chardev close + open */
@@ -254,9 +256,21 @@ static int usbredir_read(void *priv, uint8_t *data, int count)
return count;
}
+static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,
+ void *opaque)
+{
+ USBRedirDevice *dev = opaque;
+
+ dev->watch = 0;
+ usbredirparser_do_write(dev->parser);
+
+ return FALSE;
+}
+
static int usbredir_write(void *priv, uint8_t *data, int count)
{
USBRedirDevice *dev = priv;
+ int r;
if (!dev->cs->opened) {
return 0;
@@ -267,7 +281,16 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
return 0;
}
- return qemu_chr_fe_write(dev->cs, data, count);
+ r = qemu_chr_fe_write(dev->cs, data, count);
+ if (r < count) {
+ if (!dev->watch) {
+ dev->watch = qemu_chr_fe_add_watch(dev->cs, G_IO_OUT,
+ usbredir_write_unblocked, dev);
+ }
+ if (r < 0)
+ r = 0;
+ }
+ return r;
}
/*
@@ -1085,6 +1108,10 @@ static void usbredir_chardev_close_bh(void *opaque)
usbredirparser_destroy(dev->parser);
dev->parser = NULL;
}
+ if (dev->watch) {
+ g_source_remove(dev->watch);
+ dev->watch = 0;
+ }
}
static void usbredir_create_parser(USBRedirDevice *dev)
@@ -1319,6 +1346,9 @@ static void usbredir_handle_destroy(USBDevice *udev)
if (dev->parser) {
usbredirparser_destroy(dev->parser);
}
+ if (dev->watch) {
+ g_source_remove(dev->watch);
+ }
free(dev->filter_rules);
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close
2013-03-13 13:59 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
@ 2013-03-14 7:35 ` Amit Shah
2013-03-14 13:32 ` Hans de Goede
0 siblings, 1 reply; 12+ messages in thread
From: Amit Shah @ 2013-03-14 7:35 UTC (permalink / raw)
To: Hans de Goede; +Cc: Marc-André Lureau, qemu-devel, Gerd Hoffmann
On (Wed) 13 Mar 2013 [14:59:42], Hans de Goede wrote:
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> hw/virtio-console.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio-console.c b/hw/virtio-console.c
> index 1d87c5b..ec0f91b 100644
> --- a/hw/virtio-console.c
> +++ b/hw/virtio-console.c
> @@ -18,6 +18,7 @@
> typedef struct VirtConsole {
> VirtIOSerialPort port;
> CharDriverState *chr;
> + guint watch;
> } VirtConsole;
>
> /*
> @@ -29,6 +30,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
> {
> VirtConsole *vcon = opaque;
>
> + vcon->watch = 0;
> virtio_serial_throttle_port(&vcon->port, false);
> return FALSE;
> }
> @@ -60,8 +62,10 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
> ret = 0;
> if (!k->is_console) {
> virtio_serial_throttle_port(port, true);
> - qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
> - vcon);
> + if (!vcon->watch) {
> + vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
> + chr_write_unblocked, vcon);
> + }
> }
> }
> return ret;
> @@ -86,6 +90,10 @@ static void guest_close(VirtIOSerialPort *port)
> if (!vcon->chr) {
> return;
> }
> + if (vcon->watch) {
> + g_source_remove(vcon->watch);
> + vcon->watch = 0;
> + }
> qemu_chr_fe_close(vcon->chr);
> }
Even if a guest closed the connection, we want the data the guest sent
before the close to go out.
What's the reason to not do that?
> @@ -116,6 +124,10 @@ static void chr_event(void *opaque, int event)
> virtio_serial_open(&vcon->port);
> break;
> case CHR_EVENT_CLOSED:
> + if (vcon->watch) {
> + g_source_remove(vcon->watch);
> + vcon->watch = 0;
> + }
> virtio_serial_close(&vcon->port);
> break;
> }
Agreed with the rest.
Amit
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close
2013-03-14 7:35 ` Amit Shah
@ 2013-03-14 13:32 ` Hans de Goede
0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-14 13:32 UTC (permalink / raw)
To: Amit Shah; +Cc: Marc-André Lureau, qemu-devel, Gerd Hoffmann
Hi,
On 03/14/2013 08:35 AM, Amit Shah wrote:
> On (Wed) 13 Mar 2013 [14:59:42], Hans de Goede wrote:
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> hw/virtio-console.c | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/virtio-console.c b/hw/virtio-console.c
>> index 1d87c5b..ec0f91b 100644
>> --- a/hw/virtio-console.c
>> +++ b/hw/virtio-console.c
>> @@ -18,6 +18,7 @@
>> typedef struct VirtConsole {
>> VirtIOSerialPort port;
>> CharDriverState *chr;
>> + guint watch;
>> } VirtConsole;
>>
>> /*
>> @@ -29,6 +30,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
>> {
>> VirtConsole *vcon = opaque;
>>
>> + vcon->watch = 0;
>> virtio_serial_throttle_port(&vcon->port, false);
>> return FALSE;
>> }
>> @@ -60,8 +62,10 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
>> ret = 0;
>> if (!k->is_console) {
>> virtio_serial_throttle_port(port, true);
>> - qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
>> - vcon);
>> + if (!vcon->watch) {
>> + vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
>> + chr_write_unblocked, vcon);
>> + }
>> }
>> }
>> return ret;
>> @@ -86,6 +90,10 @@ static void guest_close(VirtIOSerialPort *port)
>> if (!vcon->chr) {
>> return;
>> }
>> + if (vcon->watch) {
>> + g_source_remove(vcon->watch);
>> + vcon->watch = 0;
>> + }
>> qemu_chr_fe_close(vcon->chr);
>> }
>
> Even if a guest closed the connection, we want the data the guest sent
> before the close to go out.
>
> What's the reason to not do that?
There is no reason, this was a bad attempt by me to deal with closing
the watch on virtio-port hot-unplug. I've removed this in my
local version of the patchset and instead added an exit callback
to deal with virtio-port hot-unplug the proper way.
I still have a few other patches for spice-qemu-char.c I'm working on,
once those are finished, I'll resend the series with this fixed and
rebased on top of Gerd Hoffman's chardev.v5 tree.
Regards,
Hans
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close
2013-03-28 13:28 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches v3 Hans de Goede
@ 2013-03-28 13:28 ` Hans de Goede
0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-03-28 13:28 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Amit Shah, Hans de Goede, qemu-devel
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/virtio-console.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 015947c..e28c54f 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -18,6 +18,7 @@
typedef struct VirtConsole {
VirtIOSerialPort port;
CharDriverState *chr;
+ guint watch;
} VirtConsole;
/*
@@ -29,6 +30,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
{
VirtConsole *vcon = opaque;
+ vcon->watch = 0;
virtio_serial_throttle_port(&vcon->port, false);
return FALSE;
}
@@ -60,8 +62,10 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
ret = 0;
if (!k->is_console) {
virtio_serial_throttle_port(port, true);
- qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
- vcon);
+ if (!vcon->watch) {
+ vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
+ chr_write_unblocked, vcon);
+ }
}
}
return ret;
@@ -105,6 +109,10 @@ static void chr_event(void *opaque, int event)
virtio_serial_open(&vcon->port);
break;
case CHR_EVENT_CLOSED:
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ vcon->watch = 0;
+ }
virtio_serial_close(&vcon->port);
break;
}
@@ -129,6 +137,17 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
return 0;
}
+static int virtconsole_exitfn(VirtIOSerialPort *port)
+{
+ VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ }
+
+ return 0;
+}
+
static Property virtconsole_properties[] = {
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
DEFINE_PROP_END_OF_LIST(),
@@ -141,6 +160,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
k->is_console = true;
k->init = virtconsole_initfn;
+ k->exit = virtconsole_exitfn;
k->have_data = flush_buf;
k->set_guest_connected = set_guest_connected;
dc->props = virtconsole_properties;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close
2013-04-05 9:30 [Qemu-devel] [PATCH 0/7] usb-redir chardev flowcontrol patches v4 Hans de Goede
@ 2013-04-05 9:30 ` Hans de Goede
0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2013-04-05 9:30 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Hans de Goede, qemu-devel
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
hw/virtio-console.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 61f9ff5..908ec17 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -18,6 +18,7 @@
typedef struct VirtConsole {
VirtIOSerialPort port;
CharDriverState *chr;
+ guint watch;
} VirtConsole;
/*
@@ -29,6 +30,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
{
VirtConsole *vcon = opaque;
+ vcon->watch = 0;
virtio_serial_throttle_port(&vcon->port, false);
return FALSE;
}
@@ -61,8 +63,10 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
ret = 0;
if (!k->is_console) {
virtio_serial_throttle_port(port, true);
- qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
- vcon);
+ if (!vcon->watch) {
+ vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
+ chr_write_unblocked, vcon);
+ }
}
}
return ret;
@@ -106,6 +110,10 @@ static void chr_event(void *opaque, int event)
virtio_serial_open(&vcon->port);
break;
case CHR_EVENT_CLOSED:
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ vcon->watch = 0;
+ }
virtio_serial_close(&vcon->port);
break;
}
@@ -130,6 +138,17 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
return 0;
}
+static int virtconsole_exitfn(VirtIOSerialPort *port)
+{
+ VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+
+ if (vcon->watch) {
+ g_source_remove(vcon->watch);
+ }
+
+ return 0;
+}
+
static Property virtconsole_properties[] = {
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
DEFINE_PROP_END_OF_LIST(),
@@ -142,6 +161,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
k->is_console = true;
k->init = virtconsole_initfn;
+ k->exit = virtconsole_exitfn;
k->have_data = flush_buf;
k->set_guest_connected = set_guest_connected;
dc->props = virtconsole_properties;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-04-05 9:27 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-13 13:59 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 1/7] virtio-console: Also throttle when less was written then requested Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
2013-03-14 7:35 ` Amit Shah
2013-03-14 13:32 ` Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 3/7] spice-qemu-char: Fix name parameter issues after qapi-ifying Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 4/7] spice-qemu-char: Remove dead debugging code Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 5/7] spice-qemu-char: Add watch support Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 6/7] spice-qemu-char.c: Remove intermediate buffer Hans de Goede
2013-03-13 13:59 ` [Qemu-devel] [PATCH 7/7] usb-redir: Add flow control support Hans de Goede
-- strict thread matches above, loose matches on Subject: below --
2013-03-28 13:28 [Qemu-devel] [PATCH 0/7] Spice / usb-redir chardev flowcontrol patches v3 Hans de Goede
2013-03-28 13:28 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
2013-04-05 9:30 [Qemu-devel] [PATCH 0/7] usb-redir chardev flowcontrol patches v4 Hans de Goede
2013-04-05 9:30 ` [Qemu-devel] [PATCH 2/7] virtio-console: Remove any pending watches on close Hans de Goede
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).