From patchwork Wed Jul 25 21:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10544845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C732C139A for ; Wed, 25 Jul 2018 21:27:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B57232AB67 for ; Wed, 25 Jul 2018 21:27:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A76362AB96; Wed, 25 Jul 2018 21:27:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4531F2AB67 for ; Wed, 25 Jul 2018 21:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731268AbeGYWkp (ORCPT ); Wed, 25 Jul 2018 18:40:45 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:52235 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730594AbeGYWko (ORCPT ); Wed, 25 Jul 2018 18:40:44 -0400 Received: from apollon.suse.de.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Wed, 25 Jul 2018 15:27:09 -0600 From: Martin Wilck To: Christoph Hellwig , Jens Axboe , Jan Kara , Ming Lei Cc: Hannes Reinecke , linux-block@vger.kernel.org, Martin Wilck Subject: [RFC PATCH] blkdev: __blkdev_direct_IO: collect async writes in error case Date: Wed, 25 Jul 2018 23:26:44 +0200 Message-Id: <20180725212644.13902-1-mwilck@suse.com> X-Mailer: git-send-email 2.17.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Christoph, Jens, Jan, all, while pondering over blkdev_direct_IO(), I found the following semantic change introduced by 542ff7b in the "normal" (i.e. not "simple") path, and came up with this patch. Please tell me what you think. Thanks Martin For the blkdev_direc_IO() path, the call to do_blockdev_direct_IO() has been replaced by __blkdev_direct_IO() in 542ff7bf18c6. do_blockdev_direct_IO() takes care not to leave async bios in flight for partial writes if an error occurs. Implement the same semantics for __blkdev_direct_IO(). Signed-off-by: Martin Wilck Fixes: 542ff7bf18c6 ("block: new direct I/O implementation") --- fs/block_dev.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index aba2541..9d17260 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -363,7 +363,8 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) ret = bio_iov_iter_get_pages(bio, iter); if (unlikely(ret)) { bio->bi_status = BLK_STS_IOERR; - bio_endio(bio); + if (!dio->multi_bio || is_sync || is_read) + bio_endio(bio); break; } @@ -397,8 +398,29 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) } blk_finish_plug(&plug); - if (!is_sync) - return -EIOCBQUEUED; + if (!is_sync) { + if (!ret || is_read) + return -EIOCBQUEUED; + + else if (dio->multi_bio) { + /* + * Special case: async, WRITE, page-pinning error, + * and at least one bio submitted already. + * In this case we return an error. We need to wait + * for already-submitted bios to finish. + */ + for (;;) { + set_current_state(TASK_UNINTERRUPTIBLE); + if (atomic_read(&dio->ref) == 1) + break; + /* Nothing to poll for here */ + io_schedule(); + } + __set_current_state(TASK_RUNNING); + bio_endio(bio); + } + return ret; + } for (;;) { set_current_state(TASK_UNINTERRUPTIBLE);