From 4a8bc1881c12f557ba5d76c7eaef9c0f887377c5 Mon Sep 17 00:00:00 2001
Message-Id: <4a8bc1881c12f557ba5d76c7eaef9c0f887377c5.1368111914.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:18:33 +0200
Subject: [PATCH 59/65] spice-qemu-char: Remove intermediate buffer

RH-Author: Amit Shah <amit.shah@redhat.com>
Message-id: <0d2a80038a924aaabe8902e9c83c34c1dafc3526.1366724981.git.amit.shah@redhat.com>
Patchwork-id: 50837
O-Subject: [RHEL6.5 qemu-kvm PATCH 59/65] spice-qemu-char: 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>

From: Alon Levy <alevy@redhat.com>

virtio-serial's buffer is valid when it calls us, and we don't
access it otherwise: vmc_read is only called in response to wakeup,
or else we set datalen=0 and throttle. Then vmc_read is called back,
we return 0 (not accessing the buffer) and set the timer to unthrottle.

Also make datalen int and not ssize_t (to fit spice_chr_write signature).

HdG: Update to apply to spice-qemu-char with new gio-channel based
flowcontrol support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit b010cec86b9a4a0b63162cd27e37c2d99e90ed66)

Signed-off-by: Amit Shah <amit.shah@redhat.com>

Conflicts:
	spice-qemu-char.c
---
 spice-qemu-char.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

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

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 658cd1c..b1d6e43 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -13,9 +13,8 @@ typedef struct SpiceCharDriver {
     char                  *subtype;
     bool                  active;
     bool                  blocked;
-    uint8_t               *buffer;
-    uint8_t               *datapos;
-    ssize_t               bufsize, datalen;
+    const uint8_t         *datapos;
+    int                   datalen;
 } SpiceCharDriver;
 
 typedef struct SpiceCharSource {
@@ -174,12 +173,7 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 
     vmc_register_interface(s);
     assert(s->datalen == 0);
-    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->datapos = buf;
     s->datalen = len;
     spice_server_char_device_wakeup(&s->sin);
     read_bytes = len - s->datalen;
-- 
1.7.11.7

