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

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