From patchwork Wed Jan 31 13:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13539423 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83C4E5A7A1; Wed, 31 Jan 2024 13:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706279; cv=none; b=OToort80tEGpr/hh/CCKo7jkV6csRkjzx9p9YA/H32Jw8+RTM3UOGVrgmL+d2JutR52OJxA4sOPzPWpUIQnf+5wCynGL7ULnSDIQRhsxhGD/tMH+Gg7bvEUGPKI5vh7j9LKKUdlrEN7Z3t/e/sQiI8m7NJXfg+7xQeFCuBL38/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706279; c=relaxed/simple; bh=cqGHQfSw3MgECjK4rxpgrHskV170ZGleXLsDPG/oFik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YUpxOVjKTtF6x4NEL/EYUBXKiCtiDr63g7NAZyjkR8NlNsSPK6m6bcmP4OBgg91MVXQ3GvQ60d1QjwI7A5xUsQWpMKYRVCDOkSDI0/BxhSd7dYEzOYnkfH2KHbCjcc7LjS7wM/LI4QsNsfm3Si+v1TVgzN3VHqmcprG87vX+1Yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=pyqVcRdq; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="pyqVcRdq" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=LZFoBknjyaDiVcyRevDVi5h74a0C6ddm5joTLFDHcus=; b=pyqVcRdqwPByd7ZDqXV1RNYQgQ 2/3SsEs8g81Yafh6tDXmdrrHngDUbmt+MtAbIKeJ2RtEyn8eNaVuicAgFYOguiYaFFq/x9wRIT0PI 3cU/dRfka96TLB0ZPuZcnXtzXLJyJtNV6pDTPB5D1kez7jVF13P/FHZKPMfjA5+eQyfHiSoVGNwRO e5H/6vypcCTm+8pfVQIy9qszys85mDLD0hx8IbjV4c/GuClJf6rA24Eko7Qb8D7iwSF/Ix4MoqZJw INAePfQpOzh4vVAVqnMIiEx1mlX4Gs0EZsgWfkjSO1Ljhg1I+Cv7s8BpLglEbqz+lw80HZbRuZdlX YjJwD9mw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVAGT-00000003VFh-3sYR; Wed, 31 Jan 2024 13:04:30 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Paolo Bonzini , Stefan Hajnoczi , "Martin K. Petersen" , Damien Le Moal , Keith Busch , Sagi Grimberg , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, virtualization@lists.linux.dev, John Garry , Hannes Reinecke Subject: [PATCH 07/14] block: pass a queue_limits argument to blk_alloc_queue Date: Wed, 31 Jan 2024 14:03:53 +0100 Message-Id: <20240131130400.625836-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240131130400.625836-1-hch@lst.de> References: <20240131130400.625836-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Pass a queue_limits to blk_alloc_queue and apply it if non-NULL. This will allow allocating queues with valid queue limits instead of setting the values one at a time later. Signed-off-by: Christoph Hellwig Reviewed-by: John Garry Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Chaitanya Kulkarni --- block/blk-core.c | 30 ++++++++++++++++++++++-------- block/blk-mq.c | 6 +++--- block/blk.h | 2 +- block/genhd.c | 4 ++-- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 09f4a44a4aa3cc..26d3be06bcc0fd 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -393,24 +393,38 @@ static void blk_timeout_work(struct work_struct *work) { } -struct request_queue *blk_alloc_queue(int node_id) +struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id) { struct request_queue *q; + int error; q = kmem_cache_alloc_node(blk_requestq_cachep, GFP_KERNEL | __GFP_ZERO, node_id); if (!q) - return NULL; + return ERR_PTR(-ENOMEM); q->last_merge = NULL; + if (lim) { + error = blk_validate_limits(lim); + if (error) + goto fail_q; + q->limits = *lim; + } else { + blk_set_default_limits(&q->limits); + } + q->id = ida_alloc(&blk_queue_ida, GFP_KERNEL); - if (q->id < 0) + if (q->id < 0) { + error = q->id; goto fail_q; + } q->stats = blk_alloc_queue_stats(); - if (!q->stats) + if (!q->stats) { + error = -ENOMEM; goto fail_id; + } q->node = node_id; @@ -435,12 +449,12 @@ struct request_queue *blk_alloc_queue(int node_id) * Init percpu_ref in atomic mode so that it's faster to shutdown. * See blk_register_queue() for details. */ - if (percpu_ref_init(&q->q_usage_counter, + error = percpu_ref_init(&q->q_usage_counter, blk_queue_usage_counter_release, - PERCPU_REF_INIT_ATOMIC, GFP_KERNEL)) + PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); + if (error) goto fail_stats; - blk_set_default_limits(&q->limits); q->nr_requests = BLKDEV_DEFAULT_RQ; return q; @@ -451,7 +465,7 @@ struct request_queue *blk_alloc_queue(int node_id) ida_free(&blk_queue_ida, q->id); fail_q: kmem_cache_free(blk_requestq_cachep, q); - return NULL; + return ERR_PTR(error); } /** diff --git a/block/blk-mq.c b/block/blk-mq.c index aa87fcfda1ecfc..2ddbefdeae93e4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4092,9 +4092,9 @@ static struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set, struct request_queue *q; int ret; - q = blk_alloc_queue(set->numa_node); - if (!q) - return ERR_PTR(-ENOMEM); + q = blk_alloc_queue(NULL, set->numa_node); + if (IS_ERR(q)) + return q; q->queuedata = queuedata; ret = blk_mq_init_allocated_queue(set, q); if (ret) { diff --git a/block/blk.h b/block/blk.h index 58b5dbac2a487d..100c7a02854bfd 100644 --- a/block/blk.h +++ b/block/blk.h @@ -448,7 +448,7 @@ static inline void bio_release_page(struct bio *bio, struct page *page) } int blk_validate_limits(struct queue_limits *lim); -struct request_queue *blk_alloc_queue(int node_id); +struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id); int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode); diff --git a/block/genhd.c b/block/genhd.c index d74fb5b4ae6818..defcd35b421bdd 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1396,8 +1396,8 @@ struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass) struct request_queue *q; struct gendisk *disk; - q = blk_alloc_queue(node); - if (!q) + q = blk_alloc_queue(NULL, node); + if (IS_ERR(q)) return NULL; disk = __alloc_disk_node(q, node, lkclass);