render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0009-spice-qemu-char.c-remove-intermediate-buffer.patch

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