render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

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

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