All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Damien Le Moal <dlemoal@kernel.org>,
	Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
	linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
	virtualization@lists.linux.dev, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 14/14] loop: use the atomic queue limits update API
Date: Sun, 28 Jan 2024 17:58:13 +0100	[thread overview]
Message-ID: <20240128165813.3213508-15-hch@lst.de> (raw)
In-Reply-To: <20240128165813.3213508-1-hch@lst.de>

Pass the default limits to blk_mq_alloc_disk and then use the
queue_limits_{start,commit}_update API to change the limits in an
atomic way on existing loop gendisks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 drivers/block/loop.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 26c8ea79086798..28a95fd366fea5 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -750,11 +750,11 @@ static void loop_sysfs_exit(struct loop_device *lo)
 				   &loop_attribute_group);
 }
 
-static void loop_config_discard(struct loop_device *lo)
+static void loop_config_discard(struct loop_device *lo,
+		struct queue_limits *lim)
 {
 	struct file *file = lo->lo_backing_file;
 	struct inode *inode = file->f_mapping->host;
-	struct request_queue *q = lo->lo_queue;
 	u32 granularity = 0, max_discard_sectors = 0;
 	struct kstatfs sbuf;
 
@@ -781,12 +781,12 @@ static void loop_config_discard(struct loop_device *lo)
 		granularity = sbuf.f_bsize;
 	}
 
-	blk_queue_max_discard_sectors(q, max_discard_sectors);
-	blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
+	lim->max_hw_discard_sectors = max_discard_sectors;
+	lim->max_write_zeroes_sectors = max_discard_sectors;
 	if (max_discard_sectors)
-		q->limits.discard_granularity = granularity;
+		lim->discard_granularity = granularity;
 	else
-		q->limits.discard_granularity = 0;
+		lim->discard_granularity = 0;
 }
 
 struct loop_worker {
@@ -975,6 +975,20 @@ loop_set_status_from_info(struct loop_device *lo,
 	return 0;
 }
 
+static int loop_reconfigure_limits(struct loop_device *lo, unsigned short bsize,
+		bool update_discard_settings)
+{
+	struct queue_limits lim;
+
+	lim = queue_limits_start_update(lo->lo_queue);
+	lim.logical_block_size = bsize;
+	lim.physical_block_size = bsize;
+	lim.io_min = bsize;
+	if (update_discard_settings)
+		loop_config_discard(lo, &lim);
+	return queue_limits_commit_update(lo->lo_queue, &lim);
+}
+
 static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 			  struct block_device *bdev,
 			  const struct loop_config *config)
@@ -1072,11 +1086,10 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 	else
 		bsize = 512;
 
-	blk_queue_logical_block_size(lo->lo_queue, bsize);
-	blk_queue_physical_block_size(lo->lo_queue, bsize);
-	blk_queue_io_min(lo->lo_queue, bsize);
+	error = loop_reconfigure_limits(lo, bsize, true);
+	if (WARN_ON_ONCE(error))
+		goto out_unlock;
 
-	loop_config_discard(lo);
 	loop_update_rotational(lo);
 	loop_update_dio(lo);
 	loop_sysfs_init(lo);
@@ -1143,9 +1156,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
 	lo->lo_offset = 0;
 	lo->lo_sizelimit = 0;
 	memset(lo->lo_file_name, 0, LO_NAME_SIZE);
-	blk_queue_logical_block_size(lo->lo_queue, 512);
-	blk_queue_physical_block_size(lo->lo_queue, 512);
-	blk_queue_io_min(lo->lo_queue, 512);
+	loop_reconfigure_limits(lo, 512, false);
 	invalidate_disk(lo->lo_disk);
 	loop_sysfs_exit(lo);
 	/* let user-space know about this change */
@@ -1477,9 +1488,7 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
 	invalidate_bdev(lo->lo_device);
 
 	blk_mq_freeze_queue(lo->lo_queue);
-	blk_queue_logical_block_size(lo->lo_queue, arg);
-	blk_queue_physical_block_size(lo->lo_queue, arg);
-	blk_queue_io_min(lo->lo_queue, arg);
+	err = loop_reconfigure_limits(lo, arg, false);
 	loop_update_dio(lo);
 	blk_mq_unfreeze_queue(lo->lo_queue);
 
-- 
2.39.2


  parent reply	other threads:[~2024-01-28 16:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-28 16:57 atomic queue limits updates v2 Christoph Hellwig
2024-01-28 16:58 ` [PATCH 01/14] block: move max_{open,active}_zones to struct queue_limits Christoph Hellwig
2024-01-28 23:32   ` Bart Van Assche
2024-01-29  6:15     ` Christoph Hellwig
2024-01-28 16:58 ` [PATCH 02/14] block: refactor disk_update_readahead Christoph Hellwig
2024-01-29  2:59   ` Bart Van Assche
2024-01-29  6:16     ` Christoph Hellwig
2024-01-28 16:58 ` [PATCH 03/14] block: add an API to atomically update queue limits Christoph Hellwig
2024-01-29  6:11   ` Hannes Reinecke
2024-01-30 11:46   ` John Garry
2024-01-30 14:41     ` Christoph Hellwig
2024-01-30 15:05       ` John Garry
2024-01-28 16:58 ` [PATCH 04/14] block: use queue_limits_commit_update in queue_max_sectors_store Christoph Hellwig
2024-01-30 12:14   ` John Garry
2024-01-30 14:43     ` Christoph Hellwig
2024-01-28 16:58 ` [PATCH 05/14] block: add a max_user_discard_sectors queue limit Christoph Hellwig
2024-01-29  6:13   ` Hannes Reinecke
2024-01-28 16:58 ` [PATCH 06/14] block: use queue_limits_commit_update in queue_discard_max_store Christoph Hellwig
2024-01-28 16:58 ` [PATCH 07/14] block: pass a queue_limits argument to blk_alloc_queue Christoph Hellwig
2024-01-30 12:48   ` John Garry
2024-01-28 16:58 ` [PATCH 08/14] block: pass a queue_limits argument to blk_mq_init_queue Christoph Hellwig
2024-01-30 12:38   ` John Garry
2024-01-28 16:58 ` [PATCH 09/14] block: pass a queue_limits argument to blk_mq_alloc_disk Christoph Hellwig
2024-01-30 12:52   ` John Garry
2024-01-28 16:58 ` [PATCH 10/14] virtio_blk: split virtblk_probe Christoph Hellwig
2024-01-28 16:58 ` [PATCH 11/14] virtio_blk: pass queue_limits to blk_mq_alloc_disk Christoph Hellwig
2024-01-28 16:58 ` [PATCH 12/14] loop: cleanup loop_config_discard Christoph Hellwig
2024-01-28 16:58 ` [PATCH 13/14] loop: pass queue_limits to blk_mq_alloc_disk Christoph Hellwig
2024-01-28 16:58 ` Christoph Hellwig [this message]
2024-01-31 13:03 atomic queue limits updates v3 Christoph Hellwig
2024-01-31 13:04 ` [PATCH 14/14] loop: use the atomic queue limits update API Christoph Hellwig
2024-01-31 23:38   ` Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240128165813.3213508-15-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=dlemoal@kernel.org \
    --cc=hare@suse.de \
    --cc=jasowang@redhat.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=martin.petersen@oracle.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sagi@grimberg.me \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.