From 0cbd9f7446f414067fb1b19e8fd53cb357c6c609 Mon Sep 17 00:00:00 2001
Message-Id: <0cbd9f7446f414067fb1b19e8fd53cb357c6c609.1368111913.git.minovotn@redhat.com>
In-Reply-To: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com>
References: <405603258af5154387bea676be1f904b6713f6ae.1368111913.git.minovotn@redhat.com>
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 24 Apr 2013 08:17:36 +0200
Subject: [PATCH 02/65] Revert "spice-qemu-char.c: remove intermediate buffer"

RH-Author: Amit Shah <amit.shah@redhat.com>
Message-id: <137de6109bf6379e8490eca1f7af24587cf6fef8.1366724981.git.amit.shah@redhat.com>
Patchwork-id: 50780
O-Subject: [RHEL6.5 qemu-kvm PATCH 02/65] Revert "spice-qemu-char.c: remove intermediate buffer"
Bugzilla: 909059
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>

This reverts commit e8e673ed709c2049fda96914567f0a3318670337.
---
 spice-qemu-char.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 spice-qemu-char.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 773c5be..c55bc8a 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -22,8 +22,9 @@ typedef struct SpiceCharDriver {
     SpiceCharDeviceInstance     sin;
     char                  *subtype;
     bool                  active;
-    const uint8_t         *datapos;
-    int                   datalen;
+    uint8_t               *buffer;
+    uint8_t               *datapos;
+    ssize_t               bufsize, datalen;
     uint32_t              debug;
     QEMUTimer             *unblock_timer;
 } SpiceCharDriver;
@@ -66,7 +67,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
     SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
     int bytes = MIN(len, scd->datalen);
 
-    dprintf(scd, 2, "%s: %p %d/%d/%d\n", __func__, scd->datapos, len, bytes, scd->datalen);
+    dprintf(scd, 2, "%s: %p %d/%d/%zd\n", __func__, scd->datapos, len, bytes, scd->datalen);
     if (bytes > 0) {
         memcpy(buf, scd->datapos, bytes);
         scd->datapos += bytes;
@@ -155,13 +156,18 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
     dprintf(s, 2, "%s: %d\n", __func__, len);
     vmc_register_interface(s);
     assert(s->datalen == 0);
-    s->datapos = buf;
+    if (s->bufsize < len) {
+        s->bufsize = len;
+        s->buffer = qemu_realloc(s->buffer, s->bufsize);
+    }
+    memcpy(s->buffer, buf, len);
+    s->datapos = s->buffer;
     s->datalen = len;
     spice_server_char_device_wakeup(&s->sin);
     read_bytes = len - s->datalen;
     if (read_bytes != len) {
-        dprintf(s, 1, "%s: throttling: %d < %d\n", __func__,
-                read_bytes, len);
+        dprintf(s, 1, "%s: throttling: %d < %d (%zd)\n", __func__,
+                read_bytes, len, s->bufsize);
         s->chr->write_blocked = true;
         /* We'll get passed in the unconsumed data with the next call */
         s->datalen = 0;
-- 
1.7.11.7

