From patchwork Tue Feb 26 06:13:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 223116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EFC172C02B0 for ; Tue, 26 Feb 2013 17:14:32 +1100 (EST) Received: from localhost ([::1]:36848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UADo7-00077l-0i for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 01:14:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UADnt-0006vs-9F for qemu-devel@nongnu.org; Tue, 26 Feb 2013 01:14:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UADnp-0006dK-T1 for qemu-devel@nongnu.org; Tue, 26 Feb 2013 01:14:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23610) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UADnp-0006ce-KN for qemu-devel@nongnu.org; Tue, 26 Feb 2013 01:14:13 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1Q6EC4E006505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Feb 2013 01:14:12 -0500 Received: from localhost (ovpn-113-28.phx2.redhat.com [10.3.113.28]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1Q6E9qi024535; Tue, 26 Feb 2013 01:14:11 -0500 From: Amit Shah To: Anthony Liguori Date: Tue, 26 Feb 2013 11:43:50 +0530 Message-Id: <6b9f29c7dff39fe5a3a9311995021182db160e11.1361858882.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , qemu list Subject: [Qemu-devel] [PATCH 1/1] virtio-serial: make flow control explicit in virtio-console X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org virtio-console.c used to return a value less than the number of bytes asked to be written out to a chardev backend in case the backend is not writable. virtio-serial-bus.c then implicitly enabled flow control for that port. Make this explicit instead. Signed-off-by: Amit Shah --- hw/virtio-console.c | 17 +++++++++-------- hw/virtio-serial-bus.c | 19 +------------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index b3ee074..194de64 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -47,20 +47,21 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len) ret = qemu_chr_fe_write(vcon->chr, buf, len); trace_virtio_console_flush_buf(port->id, len, ret); - if (ret < 0) { + if (ret <= 0) { + VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port); + /* * Ideally we'd get a better error code than just -1, but * that's what the chardev interface gives us right now. If * we had a finer-grained message, like -EPIPE, we could close - * this connection. Absent such error messages, the most we - * can do is to return 0 here. - * - * This will prevent stray -1 values to go to - * virtio-serial-bus.c and cause abort()s in - * do_flush_queued_data(). + * this connection. */ ret = 0; - qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked, vcon); + if (!k->is_console) { + virtio_serial_throttle_port(port, true); + qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked, + vcon); + } } return ret; } diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index aa7d0d7..f76c505 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -172,24 +172,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, port->elem.out_sg[i].iov_base + port->iov_offset, buf_size); - if (ret < 0 && ret != -EAGAIN) { - /* We don't handle any other type of errors here */ - abort(); - } - if (ret == -EAGAIN || (ret >= 0 && ret < buf_size)) { - /* - * this is a temporary check until chardevs can signal to - * frontends that they are writable again. This prevents - * the console from going into throttled mode (forever) - * if virtio-console is connected to a pty without a - * listener. Otherwise the guest spins forever. - * We can revert this if - * 1: chardevs can notify frondends - * 2: the guest driver does not spin in these cases - */ - if (!vsc->is_console) { - virtio_serial_throttle_port(port, true); - } + if (port->throttled) { port->iov_idx = i; if (ret > 0) { port->iov_offset += ret;