d4cdad5
From 9d965c99311c6f3d5c7ba9b66a72398814175865 Mon Sep 17 00:00:00 2001
d4cdad5
From: Alon Levy <alevy@redhat.com>
d4cdad5
Date: Tue, 22 Mar 2011 12:28:00 +0200
d4cdad5
Subject: [PATCH 115/118] spice-qemu-char.c: remove intermediate buffer
d4cdad5
d4cdad5
BZ: 672191
d4cdad5
upstream: not submitted (explained below)
d4cdad5
d4cdad5
virtio-serial's buffer is valid when it calls us, and we don't
d4cdad5
access it otherwise: vmc_read is only called in response to wakeup,
d4cdad5
or else we set datalen=0 and throttle. Then vmc_read is called back,
d4cdad5
we return 0 (not accessing the buffer) and set the timer to unthrottle.
d4cdad5
d4cdad5
Also make datalen int and not ssize_t (to fit spice_chr_write signature).
d4cdad5
d4cdad5
This relied on the previous patch that introduces throttling, which
d4cdad5
can't go upstream right now as explained in that patch.
d4cdad5
---
d4cdad5
 spice-qemu-char.c |   18 ++++++------------
d4cdad5
 1 files changed, 6 insertions(+), 12 deletions(-)
d4cdad5
d4cdad5
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
d4cdad5
index eeeb32e..70a83bf 100644
d4cdad5
--- a/spice-qemu-char.c
d4cdad5
+++ b/spice-qemu-char.c
d4cdad5
@@ -23,9 +23,8 @@ typedef struct SpiceCharDriver {
d4cdad5
     SpiceCharDeviceInstance     sin;
d4cdad5
     char                  *subtype;
d4cdad5
     bool                  active;
d4cdad5
-    uint8_t               *buffer;
d4cdad5
-    uint8_t               *datapos;
d4cdad5
-    ssize_t               bufsize, datalen;
d4cdad5
+    const uint8_t         *datapos;
d4cdad5
+    int                   datalen;
d4cdad5
     uint32_t              debug;
d4cdad5
     QEMUTimer             *unblock_timer;
d4cdad5
 } SpiceCharDriver;
d4cdad5
@@ -69,7 +68,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
d4cdad5
     SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
d4cdad5
     int bytes = MIN(len, scd->datalen);
d4cdad5
d4cdad5
-    dprintf(scd, 2, "%s: %p %d/%d/%zd\n", __func__, scd->datapos, len, bytes, scd->datalen);
d4cdad5
+    dprintf(scd, 2, "%s: %p %d/%d/%d\n", __func__, scd->datapos, len, bytes, scd->datalen);
d4cdad5
     if (bytes > 0) {
d4cdad5
         memcpy(buf, scd->datapos, bytes);
d4cdad5
         scd->datapos += bytes;
d4cdad5
@@ -161,18 +160,13 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
d4cdad5
     dprintf(s, 2, "%s: %d\n", __func__, len);
d4cdad5
     vmc_register_interface(s);
d4cdad5
     assert(s->datalen == 0);
d4cdad5
-    if (s->bufsize < len) {
d4cdad5
-        s->bufsize = len;
d4cdad5
-        s->buffer = g_realloc(s->buffer, s->bufsize);
d4cdad5
-    }
d4cdad5
-    memcpy(s->buffer, buf, len);
d4cdad5
-    s->datapos = s->buffer;
d4cdad5
+    s->datapos = buf;
d4cdad5
     s->datalen = len;
d4cdad5
     spice_server_char_device_wakeup(&s->sin);
d4cdad5
     read_bytes = len - s->datalen;
d4cdad5
     if (read_bytes != len) {
d4cdad5
-        dprintf(s, 1, "%s: throttling: %d < %d (%zd)\n", __func__,
d4cdad5
-                read_bytes, len, s->bufsize);
d4cdad5
+        dprintf(s, 1, "%s: throttling: %d < %d\n", __func__,
d4cdad5
+                read_bytes, len);
d4cdad5
         s->chr->write_blocked = true;
d4cdad5
         /* We'll get passed in the unconsumed data with the next call */
d4cdad5
         s->datalen = 0;
d4cdad5
-- 
d4cdad5
1.7.7.5
d4cdad5