From patchwork Tue Mar 23 14:30:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 48351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D75BB7D26 for ; Wed, 24 Mar 2010 01:53:18 +1100 (EST) Received: from localhost ([127.0.0.1]:34850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nu5R7-0006nM-U5 for incoming@patchwork.ozlabs.org; Tue, 23 Mar 2010 10:50:29 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nu5AO-0001kM-TJ for qemu-devel@nongnu.org; Tue, 23 Mar 2010 10:33:13 -0400 Received: from [199.232.76.173] (port=35907 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nu5AN-0001jO-W5 for qemu-devel@nongnu.org; Tue, 23 Mar 2010 10:33:12 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nu5AM-0001Zp-MJ for qemu-devel@nongnu.org; Tue, 23 Mar 2010 10:33:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52135) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nu5AM-0001Zj-AB for qemu-devel@nongnu.org; Tue, 23 Mar 2010 10:33:10 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2NEX9Ia024722 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Mar 2010 10:33:09 -0400 Received: from localhost (vpn-235-214.phx2.redhat.com [10.3.235.214]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2NEX7ai003279; Tue, 23 Mar 2010 10:33:08 -0400 From: Amit Shah To: qemu list Date: Tue, 23 Mar 2010 20:00:19 +0530 Message-Id: <1269354619-10201-10-git-send-email-amit.shah@redhat.com> In-Reply-To: <1269354619-10201-9-git-send-email-amit.shah@redhat.com> References: <1269354619-10201-1-git-send-email-amit.shah@redhat.com> <1269354619-10201-2-git-send-email-amit.shah@redhat.com> <1269354619-10201-3-git-send-email-amit.shah@redhat.com> <1269354619-10201-4-git-send-email-amit.shah@redhat.com> <1269354619-10201-5-git-send-email-amit.shah@redhat.com> <1269354619-10201-6-git-send-email-amit.shah@redhat.com> <1269354619-10201-7-git-send-email-amit.shah@redhat.com> <1269354619-10201-8-git-send-email-amit.shah@redhat.com> <1269354619-10201-9-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Avi Kivity , quintela@redhat.com, Gerd Hoffmann , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 9/9] virtio-serial: Handle scatter/gather input from the guest X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Current guests don't send more than one iov but it can change later. Ensure we handle that case. Signed-off-by: Amit Shah CC: Avi Kivity --- hw/virtio-serial-bus.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index fe976ec..2ca3c0a 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -355,11 +355,12 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq) while (virtqueue_pop(vq, &elem)) { VirtIOSerialPort *port; - size_t ret; + size_t len; + unsigned int i; + len = 0; port = find_port_by_vq(vser, vq); if (!port) { - ret = 0; goto next_buf; } @@ -369,16 +370,23 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq) * with it. Just ignore the data in that case. */ if (!port->info->have_data) { - ret = 0; goto next_buf; } - /* The guest always sends only one sg */ - ret = port->info->have_data(port, elem.out_sg[0].iov_base, - elem.out_sg[0].iov_len); + for (i = 0; i < elem.out_num; i++) { + size_t ret; + + ret = port->info->have_data(port, elem.out_sg[0].iov_base, + elem.out_sg[0].iov_len); + if (ret < elem.out_sg[0].iov_len) { + /* We couldn't write the entire iov; stop processing now */ + break; + } + len += ret; + } next_buf: - virtqueue_push(vq, &elem, ret); + virtqueue_push(vq, &elem, len); } virtio_notify(vdev, vq); }