render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

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

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