From patchwork Thu Aug 9 12:31:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro YUNOMAE X-Patchwork-Id: 176071 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 7FD122C00D1 for ; Thu, 9 Aug 2012 22:31:37 +1000 (EST) Received: from localhost ([::1]:33076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRtn-00005V-HR for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2012 08:31:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRtY-0008JA-Rj for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzRtS-0004bU-QA for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:20 -0400 Received: from mail9.hitachi.co.jp ([133.145.228.44]:47190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRtS-0004WG-B7 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:14 -0400 Received: from mlsv6.hitachi.co.jp (unknown [133.144.234.166]) by mail9.hitachi.co.jp (Postfix) with ESMTP id DF4FA37C86; Thu, 9 Aug 2012 21:31:12 +0900 (JST) Received: from mfilter06.hitachi.co.jp by mlsv6.hitachi.co.jp (8.13.1/8.13.1) id q79CVCtK000990; Thu, 9 Aug 2012 21:31:12 +0900 Received: from vshuts3.hitachi.co.jp (vshuts3.hitachi.co.jp [10.201.6.72]) by mfilter06.hitachi.co.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id q79CVBwL025971; Thu, 9 Aug 2012 21:31:12 +0900 X-AuditID: b753bd60-9fe84ba000000655-f0-5023ad8f4da3 Received: from hsdlmain.sdl.hitachi.co.jp (unknown [133.144.14.194]) by vshuts3.hitachi.co.jp (Symantec Mail Security) with ESMTP id 00FED774255; Thu, 9 Aug 2012 21:31:10 +0900 (JST) Received: from hsdlvgate2.sdl.hitachi.co.jp by hsdlmain.sdl.hitachi.co.jp (8.13.8/3.7W11021512) id q79CVA1O010533; Thu, 9 Aug 2012 21:31:10 +0900 X-AuditID: b753bd60-9fe84ba000000655-f0-5023ad8f4da3 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 76B36236561; Thu, 9 Aug 2012 21:31:10 +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 161C853C158; Thu, 9 Aug 2012 21:31:11 +0900 (JST) Received: from ltc189.sdl.hitachi.co.jp (unknown [10.232.28.60]) by maild.sdl.hitachi.co.jp (Postfix) with ESMTP id 6FD0C495B83; Thu, 9 Aug 2012 21:31:10 +0900 (JST) From: Yoshihiro YUNOMAE To: linux-kernel@vger.kernel.org Date: Thu, 09 Aug 2012 21:31:00 +0900 Message-ID: <20120809123100.8542.63507.stgit@ltc189.sdl.hitachi.co.jp> In-Reply-To: <20120809123029.8542.38311.stgit@ltc189.sdl.hitachi.co.jp> References: <20120809123029.8542.38311.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.44 Cc: Herbert Xu , Arnd Bergmann , Frederic Weisbecker , Rusty Russell , 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 , yrl.pp-manager.tt@hitachi.com Subject: [Qemu-devel] [PATCH V2 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 --- 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 22b7373..b2fc2ab 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,