From patchwork Wed Oct 7 01:04:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 11819503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CB7C17D2 for ; Wed, 7 Oct 2020 01:05:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08460207EA for ; Wed, 7 Oct 2020 01:05:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g4kwUCy1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbgJGBFC (ORCPT ); Tue, 6 Oct 2020 21:05:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38882 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727182AbgJGBFB (ORCPT ); Tue, 6 Oct 2020 21:05:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602032700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O6XcH4i/CDUAMLbpk3AAXzwReMyWnAPoHo6B+9Op4cw=; b=g4kwUCy1UJ4CdvxP46pAoY/R7NR0oJHmwxy7oA0kAn6lbasPxKYwXpTHOXJIK3Fieq3NrV 7KZ+MpHA7ERD8eIG78Rz4bzU11ACOazxEM5vXsggOKuWfLN0v8JCukaLRljFdFgadqdCGH dy4mFMdY0BiHfipiTw5DhIvX3thYI/U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-yFim0r8oM5a4zKr_2EwnUQ-1; Tue, 06 Oct 2020 21:04:58 -0400 X-MC-Unique: yFim0r8oM5a4zKr_2EwnUQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43E1C10BBEC0; Wed, 7 Oct 2020 01:04:56 +0000 (UTC) Received: from localhost (ovpn-12-47.pek2.redhat.com [10.72.12.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 713685C1BD; Wed, 7 Oct 2020 01:04:55 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch Cc: Ming Lei , Sagi Grimberg , Bart Van Assche , Johannes Thumshirn , Chao Leng , Hannes Reinecke Subject: [PATCH V7 1/4] block: use test_and_{clear|test}_bit to set/clear QUEUE_FLAG_QUIESCED Date: Wed, 7 Oct 2020 09:04:40 +0800 Message-Id: <20201007010443.71456-2-ming.lei@redhat.com> In-Reply-To: <20201007010443.71456-1-ming.lei@redhat.com> References: <20201007010443.71456-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Prepare for replacing srcu with percpu-refcount for implementing queue quiesce. The following patch needs to avoid duplicated quiesce action for BLK_MQ_F_BLOCKING, so use test_and_{clear|test}_bit to set/clear QUEUE_FLAG_QUIESCED. Signed-off-by: Ming Lei Cc: Sagi Grimberg Cc: Bart Van Assche Cc: Johannes Thumshirn Cc: Chao Leng Reviewed-by: Hannes Reinecke Tested-by: Sagi Grimberg Reviewed-by: Keith Busch --- block/blk-core.c | 13 +++++++++++++ block/blk-mq.c | 11 ++++++++--- block/blk.h | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 3b01e7f3c7a3..a5afe67559fe 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -107,6 +107,19 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_queue_flag_test_and_set); +/** + * blk_queue_flag_test_and_clear - atomically test and clear a queue flag + * @flag: flag to be clear + * @q: request queue + * + * Returns the previous value of @flag - 0 if the flag was not set and 1 if + * the flag was set. + */ +bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q) +{ + return test_and_clear_bit(flag, &q->queue_flags); +} + void blk_rq_init(struct request_queue *q, struct request *rq) { memset(rq, 0, sizeof(*rq)); diff --git a/block/blk-mq.c b/block/blk-mq.c index c5fefd39d0c0..3fbcf431fcf4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -199,13 +199,18 @@ void blk_mq_unfreeze_queue(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue); +static bool __blk_mq_quiesce_queue_nowait(struct request_queue *q) +{ + return blk_queue_flag_test_and_set(QUEUE_FLAG_QUIESCED, q); +} + /* * FIXME: replace the scsi_internal_device_*block_nowait() calls in the * mpt3sas driver such that this function can be removed. */ void blk_mq_quiesce_queue_nowait(struct request_queue *q) { - blk_queue_flag_set(QUEUE_FLAG_QUIESCED, q); + __blk_mq_quiesce_queue_nowait(q); } EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait); @@ -224,7 +229,7 @@ void blk_mq_quiesce_queue(struct request_queue *q) unsigned int i; bool rcu = false; - blk_mq_quiesce_queue_nowait(q); + __blk_mq_quiesce_queue_nowait(q); queue_for_each_hw_ctx(q, hctx, i) { if (hctx->flags & BLK_MQ_F_BLOCKING) @@ -246,7 +251,7 @@ EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue); */ void blk_mq_unquiesce_queue(struct request_queue *q) { - blk_queue_flag_clear(QUEUE_FLAG_QUIESCED, q); + blk_queue_flag_test_and_clear(QUEUE_FLAG_QUIESCED, q); /* dispatch requests which are inserted during quiescing */ blk_mq_run_hw_queues(q, true); diff --git a/block/blk.h b/block/blk.h index dfab98465db9..f925268ce7fd 100644 --- a/block/blk.h +++ b/block/blk.h @@ -444,4 +444,6 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset, unsigned int max_sectors, bool *same_page); +bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q); + #endif /* BLK_INTERNAL_H */