From patchwork Wed Jul 26 23:57:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 9866041 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6CD6560225 for ; Wed, 26 Jul 2017 23:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E540287B4 for ; Wed, 26 Jul 2017 23:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52DAB287DB; Wed, 26 Jul 2017 23:59:20 +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=-6.9 required=2.0 tests=BAYES_00,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 E5A72287B4 for ; Wed, 26 Jul 2017 23:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751458AbdGZX6b (ORCPT ); Wed, 26 Jul 2017 19:58:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:45979 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751078AbdGZX63 (ORCPT ); Wed, 26 Jul 2017 19:58:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 88EE9ADD2; Wed, 26 Jul 2017 23:58:28 +0000 (UTC) From: Goldwyn Rodrigues To: linux-block@vger.kernel.org Cc: hch@infradead.org, jack@suse.cz, linux-raid@vger.kernel.org, dm-devel@redhat.com, Goldwyn Rodrigues Subject: [PATCH 2/9] md: Add nowait support to md Date: Wed, 26 Jul 2017 18:57:59 -0500 Message-Id: <20170726235806.12148-3-rgoldwyn@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170726235806.12148-1-rgoldwyn@suse.de> References: <20170726235806.12148-1-rgoldwyn@suse.de> 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 From: Goldwyn Rodrigues Set queue flags to QUEUE_FLAG_NOWAIT to indicate REQ_NOWAIT will be handled. If an I/O on the md will be delayed, it would bail by calling bio_wouldblock_error(). The conditions when this could happen are: + MD is suspended + There is a change pending on the SB, and current I/O would block until that is complete. Signed-off-by: Goldwyn Rodrigues --- drivers/md/md.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8cdca0296749..d96c27d16841 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -285,6 +285,13 @@ static blk_qc_t md_make_request(struct request_queue *q, struct bio *bio) bio_endio(bio); return BLK_QC_T_NONE; } + + if (mddev->suspended && (bio->bi_opf & REQ_NOWAIT)) { + bio_wouldblock_error(bio); + rcu_read_unlock(); + return BLK_QC_T_NONE; + } + check_suspended: rcu_read_lock(); if (mddev->suspended) { @@ -5274,6 +5281,10 @@ static int md_alloc(dev_t dev, char *name) mddev->queue = NULL; goto abort; } + + /* Set the NOWAIT flags to show support */ + queue_flag_set_unlocked(QUEUE_FLAG_NOWAIT, mddev->queue); + disk->major = MAJOR(mddev->unit); disk->first_minor = unit << shift; if (name) @@ -8010,8 +8021,20 @@ bool md_write_start(struct mddev *mddev, struct bio *bi) rcu_read_unlock(); if (did_change) sysfs_notify_dirent_safe(mddev->sysfs_state); - wait_event(mddev->sb_wait, - !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) && !mddev->suspended); + + /* Don't wait for sb writes if marked with REQ_NOWAIT */ + if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) || + mddev->suspended) { + if (bi->bi_opf & REQ_NOWAIT) { + bio_wouldblock_error(bi); + percpu_ref_put(&mddev->writes_pending); + return false; + } + + wait_event(mddev->sb_wait, + !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) && !mddev->suspended); + } + if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) { percpu_ref_put(&mddev->writes_pending); return false;