From patchwork Mon Jan 8 18:50:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10150315 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 0B58960210 for ; Mon, 8 Jan 2018 18:50:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18284289D7 for ; Mon, 8 Jan 2018 18:50:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CD1A289DD; Mon, 8 Jan 2018 18:50:34 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 7847C289D7 for ; Mon, 8 Jan 2018 18:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756010AbeAHSua (ORCPT ); Mon, 8 Jan 2018 13:50:30 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:60235 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755985AbeAHSuS (ORCPT ); Mon, 8 Jan 2018 13:50:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1515437419; x=1546973419; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=egvIOVwbXoUrcFJK0MiGowl/8Ae0lnJwmIVdRH45aM8=; b=nfP2uaKIyuQHOHnI5FK18GfXmqKwUBRBnEufVDmD2rn8QIw0igBY9G9+ 4rU+nquV0hsWKAGLcw/hz0f6YakFmRSLwPTxBTiX/4NTV9QpExTX7zOea Ezy6iuB8rFIkLy6vce3YZfuXM/puBW3FHPAMNq3sncn5k3C86B+BOkj+O 6PWktlH3+lTQ5rCQttRBeqDiCQLYsZ5hhJZLOojUg0poKQAW7PcQHfU5O 3oFFSN1SHMCmZtLM5DTH3HVabCK7WodYcR0ZSXjoGdZ0PUtY0UZrbWnD7 xhtNM4FrqNx0xsI5Ng2QvjDi0qva3/+TLMlh/RmcyuWbKlvFIWWhaBGXM w==; X-IronPort-AV: E=Sophos;i="5.46,332,1511798400"; d="scan'208";a="68074219" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jan 2018 02:50:13 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 08 Jan 2018 10:45:47 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2018 10:50:13 -0800 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Jason Gunthorpe , Doug Ledford , linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Ming Lei Subject: [PATCH 2/4] block: Introduce blk_wait_if_quiesced() and blk_finish_wait_if_quiesced() Date: Mon, 8 Jan 2018 10:50:09 -0800 Message-Id: <20180108185011.30018-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180108185011.30018-1-bart.vanassche@wdc.com> References: <20180108185011.30018-1-bart.vanassche@wdc.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce functions that allow block drivers to wait while a request queue is in the quiesced state (blk-mq) or in the stopped state (legacy block layer). The next patch will add calls to these functions in the SCSI core. Signed-off-by: Bart Van Assche Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Ming Lei --- block/blk-core.c | 1 + block/blk-mq.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 3 files changed, 64 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 605599a2ab3b..d70ff53e6505 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -285,6 +285,7 @@ void blk_start_queue(struct request_queue *q) WARN_ON_ONCE(q->mq_ops); queue_flag_clear(QUEUE_FLAG_STOPPED, q); + wake_up_all(&q->mq_wq); __blk_run_queue(q); } EXPORT_SYMBOL(blk_start_queue); diff --git a/block/blk-mq.c b/block/blk-mq.c index 8118890fb66f..c79b102680fe 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -248,11 +248,72 @@ void blk_mq_unquiesce_queue(struct request_queue *q) queue_flag_clear(QUEUE_FLAG_QUIESCED, q); spin_unlock_irqrestore(q->queue_lock, flags); + wake_up_all(&q->mq_wq); + /* dispatch requests which are inserted during quiescing */ blk_mq_run_hw_queues(q, true); } EXPORT_SYMBOL_GPL(blk_mq_unquiesce_queue); +/** + * blk_wait_if_quiesced() - wait if a queue is quiesced (blk-mq) or stopped (legacy block layer) + * @q: Request queue pointer. + * + * Some block drivers, e.g. the SCSI core, can bypass the block layer core + * request submission mechanism. Surround such code with blk_wait_if_quiesced() + * / blk_finish_wait_if_quiesced() to avoid that request submission can happen + * while a queue is quiesced or stopped. + * + * Returns with the RCU read lock held (blk-mq) or with q->queue_lock held + * (legacy block layer). + * + * Note: this function does not support block drivers whose .queue_rq() + * implementation can sleep (BLK_MQ_F_BLOCKING). + */ +int blk_wait_if_quiesced(struct request_queue *q) +{ + struct blk_mq_hw_ctx *hctx; + unsigned int i; + + might_sleep(); + + if (q->mq_ops) { + queue_for_each_hw_ctx(q, hctx, i) + WARN_ON(hctx->flags & BLK_MQ_F_BLOCKING); + + rcu_read_lock(); + while (!blk_queue_dying(q) && blk_queue_quiesced(q)) { + rcu_read_unlock(); + wait_event(q->mq_wq, blk_queue_dying(q) || + !blk_queue_quiesced(q)); + rcu_read_lock(); + } + } else { + spin_lock_irq(q->queue_lock); + wait_event_lock_irq(q->mq_wq, + blk_queue_dying(q) || !blk_queue_stopped(q), + *q->queue_lock); + q->request_fn_active++; + } + return blk_queue_dying(q) ? -ENODEV : 0; +} +EXPORT_SYMBOL(blk_wait_if_quiesced); + +/** + * blk_finish_wait_if_quiesced() - counterpart of blk_wait_if_quiesced() + * @q: Request queue pointer. + */ +void blk_finish_wait_if_quiesced(struct request_queue *q) +{ + if (q->mq_ops) { + rcu_read_unlock(); + } else { + q->request_fn_active--; + spin_unlock_irq(q->queue_lock); + } +} +EXPORT_SYMBOL(blk_finish_wait_if_quiesced); + void blk_mq_wake_waiters(struct request_queue *q) { struct blk_mq_hw_ctx *hctx; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 95c9a5c862e2..f6b787bd244e 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -266,6 +266,8 @@ void blk_mq_start_stopped_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async); void blk_mq_quiesce_queue(struct request_queue *q); void blk_mq_unquiesce_queue(struct request_queue *q); +int blk_wait_if_quiesced(struct request_queue *q); +void blk_finish_wait_if_quiesced(struct request_queue *q); void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs); bool blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); void blk_mq_run_hw_queues(struct request_queue *q, bool async);