From patchwork Tue Jul 12 09:28:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 104331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7C707B6F7B for ; Tue, 12 Jul 2011 19:40:50 +1000 (EST) Received: from localhost ([::1]:52259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgZSP-0004tB-C1 for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2011 05:40:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:43074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgZHB-00035M-Ph for qemu-devel@nongnu.org; Tue, 12 Jul 2011 05:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QgZH7-0002mR-Rw for qemu-devel@nongnu.org; Tue, 12 Jul 2011 05:29:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgZH7-0002mL-Ey for qemu-devel@nongnu.org; Tue, 12 Jul 2011 05:29:05 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6C9T3ng013390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 12 Jul 2011 05:29:03 -0400 Received: from localhost (dhcp193-45.pnq.redhat.com [10.65.193.45]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6C9T1bp026625; Tue, 12 Jul 2011 05:29:02 -0400 From: Amit Shah To: qemu list Date: Tue, 12 Jul 2011 14:58:57 +0530 Message-Id: <5444cc7ab1e9654fa953e626da1a50ce54a72ac7.1310462934.git.amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Amit Shah , Gerd Hoffmann , Markus Armbruster , Juan Quintela Subject: [Qemu-devel] [PATCH v2 1/1] virtio-console: Prevent abort()s in case of host chardev close 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 A host chardev could close just before the guest sends some data to be written. This will cause an -EPIPE error. This shouldn't be propagated to virtio-serial-bus. Ideally we should close the port once -EPIPE is received, but since the chardev interface doesn't return such meaningful values to its users, all we get is -1 for any kind of error. Just return 0 for now and wait for chardevs to return better error messages to act better on the return messages. Signed-off-by: Amit Shah Reviewed-by: Markus Armbruster --- hw/virtio-console.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index b076331..9ca0dc6 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -24,8 +24,24 @@ typedef struct VirtConsole { static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len) { VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); - - return qemu_chr_write(vcon->chr, buf, len); + ssize_t ret; + + ret = qemu_chr_write(vcon->chr, buf, len); + if (ret < 0) { + /* + * 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(). + */ + ret = 0; + } + return ret; } /* Callback function that's called when the guest opens the port */