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