From patchwork Tue Jul 24 02:37:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro YUNOMAE X-Patchwork-Id: 172775 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 99D2B2C008E for ; Tue, 24 Jul 2012 12:38:00 +1000 (EST) Received: from localhost ([::1]:40687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StV0Y-0003Fm-N0 for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 22:37:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StV0J-00037m-Ab for qemu-devel@nongnu.org; Mon, 23 Jul 2012 22:37:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StV0I-0008Uz-4g for qemu-devel@nongnu.org; Mon, 23 Jul 2012 22:37:43 -0400 Received: from mail7.hitachi.co.jp ([133.145.228.42]:56374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StV0H-0008UI-MD for qemu-devel@nongnu.org; Mon, 23 Jul 2012 22:37:42 -0400 Received: from mlsv3.hitachi.co.jp (unknown [133.144.234.166]) by mail7.hitachi.co.jp (Postfix) with ESMTP id D997A37ACA; Tue, 24 Jul 2012 11:37:40 +0900 (JST) Received: from mfilter04.hitachi.co.jp by mlsv3.hitachi.co.jp (8.13.1/8.13.1) id q6O2beR1023141; Tue, 24 Jul 2012 11:37:40 +0900 Received: from vshuts4.hitachi.co.jp (vshuts4.hitachi.co.jp [10.201.6.80]) by mfilter04.hitachi.co.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id q6O2bd1H009477; Tue, 24 Jul 2012 11:37:40 +0900 X-AuditID: b753bd60-91ec3ba0000047ca-85-500e0a73a7d0 Received: from hsdlmain.sdl.hitachi.co.jp (unknown [133.144.14.194]) by vshuts4.hitachi.co.jp (Symantec Mail Security) with ESMTP id 173B32043E2; Tue, 24 Jul 2012 11:37:39 +0900 (JST) Received: from hsdlvgate2.sdl.hitachi.co.jp by hsdlmain.sdl.hitachi.co.jp (8.13.8/3.7W11021512) id q6O2bcRW027951; Tue, 24 Jul 2012 11:37:38 +0900 X-AuditID: b753bd60-91ec3ba0000047ca-85-500e0a73a7d0 Received: from sdl99w.sdl.hitachi.co.jp (sdl99w.sdl.hitachi.co.jp [133.144.14.250]) by hsdlvgate2.sdl.hitachi.co.jp (Symantec Mail Security) with ESMTP id ADAF6236561; Tue, 24 Jul 2012 11:37:37 +0900 (JST) Received: from maild.sdl.hitachi.co.jp (sdl99d.sdl.hitachi.co.jp [133.144.14.199]) by sdl99w.sdl.hitachi.co.jp (Postfix) with ESMTP id BF90C53C1FA; Tue, 24 Jul 2012 11:37:38 +0900 (JST) Received: from ltc189.sdl.hitachi.co.jp (unknown [10.232.28.60]) by maild.sdl.hitachi.co.jp (Postfix) with ESMTP id 81887495B93; Tue, 24 Jul 2012 11:37:38 +0900 (JST) From: Yoshihiro YUNOMAE To: linux-kernel@vger.kernel.org Date: Tue, 24 Jul 2012 11:37:28 +0900 Message-ID: <20120724023728.6600.36390.stgit@ltc189.sdl.hitachi.co.jp> In-Reply-To: <20120724023657.6600.52706.stgit@ltc189.sdl.hitachi.co.jp> References: <20120724023657.6600.52706.stgit@ltc189.sdl.hitachi.co.jp> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Brightmail-Tracker: AAAAAA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 133.145.228.42 Cc: Herbert Xu , Arnd Bergmann , Frederic Weisbecker , yrl.pp-manager.tt@hitachi.com, qemu-devel@nongnu.org, Borislav Petkov , virtualization@lists.linux-foundation.org, Masami Hiramatsu , "Franch Ch. Eigler" , Ingo Molnar , Mathieu Desnoyers , Steven Rostedt , Anthony Liguori , Greg Kroah-Hartman , Amit Shah Subject: [Qemu-devel] [RFC PATCH 3/6] virtio/console: Wait until the port is ready on splice 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 From: Masami Hiramatsu Wait if the port is not connected or full on splice like as write is doing. Signed-off-by: Masami Hiramatsu Cc: Amit Shah Cc: Arnd Bergmann Cc: Greg Kroah-Hartman --- drivers/char/virtio_console.c | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 911cb3e..e49d435 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -724,6 +724,26 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf, return fill_readbuf(port, ubuf, count, true); } +static int wait_port_writable(struct port *port, bool nonblock) +{ + int ret; + + if (will_write_block(port)) { + if (nonblock) + return -EAGAIN; + + ret = wait_event_freezable(port->waitqueue, + !will_write_block(port)); + if (ret < 0) + return ret; + } + /* Port got hot-unplugged. */ + if (!port->guest_connected) + return -ENODEV; + + return 0; +} + static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, size_t count, loff_t *offp) { @@ -740,18 +760,9 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, nonblock = filp->f_flags & O_NONBLOCK; - if (will_write_block(port)) { - if (nonblock) - return -EAGAIN; - - ret = wait_event_freezable(port->waitqueue, - !will_write_block(port)); - if (ret < 0) - return ret; - } - /* Port got hot-unplugged. */ - if (!port->guest_connected) - return -ENODEV; + ret = wait_port_writable(port, nonblock); + if (ret < 0) + return ret; count = min((size_t)(32 * 1024), count); @@ -851,6 +862,10 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe, .u.data = &sgl, }; + ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); + if (ret < 0) + return ret; + sgl.n = 0; sgl.len = 0; sgl.sg = kmalloc(sizeof(struct scatterlist) * MAX_SPLICE_PAGES,