carlwgeorge / rpms / qemu

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