From e8e673ed709c2049fda96914567f0a3318670337 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 22 Mar 2011 10:28:00 -0300 Subject: [PATCH 07/16] spice-qemu-char.c: remove intermediate buffer RH-Author: Alon Levy Message-id: <1300789680-18535-3-git-send-email-alevy@redhat.com> Patchwork-id: 20378 O-Subject: [PATCH RHEL6.1 v2 2/2] spice-qemu-char.c: remove intermediate buffer Bugzilla: 672191 RH-Acked-by: Amit Shah RH-Acked-by: Uri Lublin RH-Acked-by: Hans de Goede BZ: 672191 upstream: not submitted (explained below) 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). This relied on the previous patch that introduces throttling, which can't go upstream right now as explained in that patch. --- spice-qemu-char.c | 18 ++++++------------ 1 files changed, 6 insertions(+), 12 deletions(-) Signed-off-by: Luiz Capitulino --- spice-qemu-char.c | 18 ++++++------------ 1 files changed, 6 insertions(+), 12 deletions(-) diff --git a/spice-qemu-char.c b/spice-qemu-char.c index cc2aff7..0e49cf1 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -22,9 +22,8 @@ typedef struct SpiceCharDriver { SpiceCharDeviceInstance sin; char *subtype; bool active; - uint8_t *buffer; - uint8_t *datapos; - ssize_t bufsize, datalen; + const uint8_t *datapos; + int datalen; uint32_t debug; QEMUTimer *unblock_timer; } SpiceCharDriver; @@ -68,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/%zd\n", __func__, scd->datapos, len, bytes, scd->datalen); + dprintf(scd, 2, "%s: %p %d/%d/%d\n", __func__, scd->datapos, len, bytes, scd->datalen); if (bytes > 0) { memcpy(buf, scd->datapos, bytes); scd->datapos += bytes; @@ -128,18 +127,13 @@ 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); - 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; if (read_bytes != len) { - dprintf(s, 1, "%s: throttling: %d < %d (%zd)\n", __func__, - read_bytes, len, s->bufsize); + dprintf(s, 1, "%s: throttling: %d < %d\n", __func__, + read_bytes, len); s->chr->write_blocked = true; /* We'll get passed in the unconsumed data with the next call */ s->datalen = 0; -- 1.7.4.1.230.gae447