a81953e
From c8fa37e075cf59e8b21af9211f6a6348c92ed098 Mon Sep 17 00:00:00 2001
a81953e
From: Alon Levy <alevy@redhat.com>
a81953e
Date: Mon, 12 Jul 2010 22:48:59 +0300
a81953e
Subject: [PATCH 25/39] spice-vmc: two bugfixes in vmc_read
a81953e
a81953e
 * throttling with no discard means possible recursion, make
a81953e
  vmc_read handle that.
a81953e
 * zero datapos when data is done (from rhel6 version)
a81953e
---
a81953e
 hw/spice-vmc.c |   13 ++++++++-----
a81953e
 1 files changed, 8 insertions(+), 5 deletions(-)
a81953e
a81953e
diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
a81953e
index 3f6a2bb..06e30e6 100644
a81953e
--- a/hw/spice-vmc.c
a81953e
+++ b/hw/spice-vmc.c
a81953e
@@ -45,7 +45,7 @@ static int vmc_write(SpiceVDIPortInstance *sin, const uint8_t *buf, int len)
a81953e
     ssize_t out;
a81953e
a81953e
     out = virtio_serial_write(&svc->port, buf, len);
a81953e
-    dprintf(svc, 2, "%s: %lu/%d\n", __func__, out, len);
a81953e
+    dprintf(svc, 3, "%s: %lu/%d\n", __func__, out, len);
a81953e
     return out;
a81953e
 }
a81953e
a81953e
@@ -54,13 +54,16 @@ static int vmc_read(SpiceVDIPortInstance *sin, uint8_t *buf, int len)
a81953e
     SpiceVirtualChannel *svc = container_of(sin, SpiceVirtualChannel, sin);
a81953e
     int bytes = MIN(len, svc->datalen);
a81953e
a81953e
-    dprintf(svc, 2, "%s: %d/%zd\n", __func__, bytes, svc->datalen);
a81953e
-    if (bytes) {
a81953e
+    dprintf(svc, 2, "%s: %p %d/%d/%zd\n", __func__, svc->datapos, len, bytes, svc->datalen);
a81953e
+    if (bytes > 0) {
a81953e
         memcpy(buf, svc->datapos, bytes);
a81953e
         svc->datapos += bytes;
a81953e
         svc->datalen -= bytes;
a81953e
-        if (0 == svc->datalen) {
a81953e
+        assert(svc->datalen >= 0);
a81953e
+        if (svc->datalen == 0) {
a81953e
+            svc->datapos = 0;
a81953e
             virtio_serial_throttle_port(&svc->port, false);
a81953e
+            // ^^^ !!! may call vmc_have_data, so don't touch svc after it!
a81953e
         }
a81953e
     }
a81953e
     return bytes;
a81953e
@@ -140,7 +143,7 @@ static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len
a81953e
     SpiceVirtualChannel *svc = DO_UPCAST(SpiceVirtualChannel, port, port);
a81953e
a81953e
     dprintf(svc, 2, "%s: %zd\n", __func__, len);
a81953e
-    assert(svc->datapos == 0);
a81953e
+    assert(svc->datalen == 0);
a81953e
     if (svc->bufsize < len) {
a81953e
         svc->bufsize = len;
a81953e
         svc->buffer = qemu_realloc(svc->buffer, svc->bufsize);
a81953e
-- 
a81953e
1.7.2.3
a81953e