From patchwork Wed May 16 04:03:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10402497 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 3EC9A602C2 for ; Wed, 16 May 2018 04:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F8742864A for ; Wed, 16 May 2018 04:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2318128721; Wed, 16 May 2018 04:03:46 +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 6EFC92864A for ; Wed, 16 May 2018 04:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750810AbeEPEDo (ORCPT ); Wed, 16 May 2018 00:03:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34414 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750775AbeEPEDo (ORCPT ); Wed, 16 May 2018 00:03:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD4B6401EF07; Wed, 16 May 2018 04:03:43 +0000 (UTC) Received: from localhost (ovpn-12-64.pek2.redhat.com [10.72.12.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9657106A75B; Wed, 16 May 2018 04:03:34 +0000 (UTC) From: Ming Lei To: Keith Busch Cc: Jens Axboe , linux-block@vger.kernel.org, Ming Lei , James Smart , Bart Van Assche , Jianchao Wang , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, Laurence Oberman Subject: [PATCH V6 01/11] block: introduce blk_quiesce_timeout() and blk_unquiesce_timeout() Date: Wed, 16 May 2018 12:03:03 +0800 Message-Id: <20180516040313.13596-2-ming.lei@redhat.com> In-Reply-To: <20180516040313.13596-1-ming.lei@redhat.com> References: <20180516040313.13596-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 16 May 2018 04:03:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 16 May 2018 04:03:43 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' 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 Turns out the current way can't drain timout completely because mod_timer() can be triggered in the work func, which can be just run inside the synced timeout work: del_timer_sync(&q->timeout); cancel_work_sync(&q->timeout_work); This patch introduces one flag of 'timeout_off' for fixing this issue, turns out this simple way does work. Also blk_quiesce_timeout() and blk_unquiesce_timeout() are introduced for draining timeout, which is needed by NVMe. Cc: James Smart Cc: Bart Van Assche Cc: Jianchao Wang Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: linux-nvme@lists.infradead.org Cc: Laurence Oberman Signed-off-by: Ming Lei --- block/blk-core.c | 21 +++++++++++++++++++-- block/blk-mq.c | 9 +++++++++ block/blk-timeout.c | 5 ++++- include/linux/blkdev.h | 13 +++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 85909b431eb0..c277f1023703 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -392,6 +392,22 @@ void blk_stop_queue(struct request_queue *q) } EXPORT_SYMBOL(blk_stop_queue); +void blk_unquiesce_timeout(struct request_queue *q) +{ + blk_mark_timeout_quiesce(q, false); + mod_timer(&q->timeout, jiffies + q->rq_timeout); +} +EXPORT_SYMBOL(blk_unquiesce_timeout); + +void blk_quiesce_timeout(struct request_queue *q) +{ + blk_mark_timeout_quiesce(q, true); + + del_timer_sync(&q->timeout); + cancel_work_sync(&q->timeout_work); +} +EXPORT_SYMBOL(blk_quiesce_timeout); + /** * blk_sync_queue - cancel any pending callbacks on a queue * @q: the queue @@ -412,8 +428,7 @@ EXPORT_SYMBOL(blk_stop_queue); */ void blk_sync_queue(struct request_queue *q) { - del_timer_sync(&q->timeout); - cancel_work_sync(&q->timeout_work); + blk_quiesce_timeout(q); if (q->mq_ops) { struct blk_mq_hw_ctx *hctx; @@ -425,6 +440,8 @@ void blk_sync_queue(struct request_queue *q) } else { cancel_delayed_work_sync(&q->delay_work); } + + blk_mark_timeout_quiesce(q, false); } EXPORT_SYMBOL(blk_sync_queue); diff --git a/block/blk-mq.c b/block/blk-mq.c index 9ce9cac16c3f..173f1723e48f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -917,6 +917,15 @@ static void blk_mq_timeout_work(struct work_struct *work) }; struct blk_mq_hw_ctx *hctx; int i; + bool timeout_off; + unsigned long flags; + + spin_lock_irqsave(q->queue_lock, flags); + timeout_off = q->timeout_off; + spin_unlock_irqrestore(q->queue_lock, flags); + + if (timeout_off) + return; /* A deadlock might occur if a request is stuck requiring a * timeout at the same time a queue freeze is waiting diff --git a/block/blk-timeout.c b/block/blk-timeout.c index 652d4d4d3e97..ffd0b609091e 100644 --- a/block/blk-timeout.c +++ b/block/blk-timeout.c @@ -136,12 +136,15 @@ void blk_timeout_work(struct work_struct *work) spin_lock_irqsave(q->queue_lock, flags); + if (q->timeout_off) + goto exit; + list_for_each_entry_safe(rq, tmp, &q->timeout_list, timeout_list) blk_rq_check_expired(rq, &next, &next_set); if (next_set) mod_timer(&q->timeout, round_jiffies_up(next)); - +exit: spin_unlock_irqrestore(q->queue_lock, flags); } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 5c4eee043191..a2cc4aaecf50 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -584,6 +584,7 @@ struct request_queue { struct timer_list timeout; struct work_struct timeout_work; struct list_head timeout_list; + bool timeout_off; struct list_head icq_list; #ifdef CONFIG_BLK_CGROUP @@ -1017,6 +1018,18 @@ extern void blk_execute_rq(struct request_queue *, struct gendisk *, extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, struct request *, int, rq_end_io_fn *); +static inline void blk_mark_timeout_quiesce(struct request_queue *q, bool quiesce) +{ + unsigned long flags; + + spin_lock_irqsave(q->queue_lock, flags); + q->timeout_off = quiesce; + spin_unlock_irqrestore(q->queue_lock, flags); +} + +extern void blk_quiesce_timeout(struct request_queue *q); +extern void blk_unquiesce_timeout(struct request_queue *q); + int blk_status_to_errno(blk_status_t status); blk_status_t errno_to_blk_status(int errno);