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

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