linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, dm-devel@lists.linux.dev,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>
Subject: [PATCH 1/4] null_blk: Do not allow runt zone with zone capacity smaller then zone size
Date: Thu, 30 May 2024 14:40:32 +0900	[thread overview]
Message-ID: <20240530054035.491497-2-dlemoal@kernel.org> (raw)
In-Reply-To: <20240530054035.491497-1-dlemoal@kernel.org>

A zoned device with a smaller last zone together with a zone capacity
smaller than the zone size does make any sense as that does not
correspond to any possible setup for a real device:
1) For ZNS and zoned UFS devices, all zones are always the same size.
2) For SMR HDDs, all zones always have the same capacity.
In other words, if we have a smaller last runt zone, then this zone
capacity should always be equal to the zone size.

Add a check in null_init_zoned_dev() to prevent a configuration to have
both a smaller zone size and a zone capacity smaller than the zone size.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/block/null_blk/zoned.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index 79c8e5e99f7f..f118d304f310 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -74,6 +74,17 @@ int null_init_zoned_dev(struct nullb_device *dev,
 		return -EINVAL;
 	}
 
+	/*
+	 * If a smaller zone capacity was requested, do not allow a smaller last
+	 * zone at the same time as such zone configuration does not correspond
+	 * to any real zoned device.
+	 */
+	if (dev->zone_capacity != dev->zone_size &&
+	    dev->size & (dev->zone_size - 1)) {
+		pr_err("A smaller last zone is not allowed with zone capacity smaller than zone size.\n");
+		return -EINVAL;
+	}
+
 	zone_capacity_sects = mb_to_sects(dev->zone_capacity);
 	dev_capacity_sects = mb_to_sects(dev->size);
 	dev->zone_size_sects = mb_to_sects(dev->zone_size);
-- 
2.45.1


  reply	other threads:[~2024-05-30  5:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30  5:40 [PATCH 0/4] Zone write plugging and DM zone fixes Damien Le Moal
2024-05-30  5:40 ` Damien Le Moal [this message]
2024-05-30  7:37   ` [PATCH 1/4] null_blk: Do not allow runt zone with zone capacity smaller then zone size Niklas Cassel
2024-05-30 20:34   ` Bart Van Assche
2024-06-01  5:25   ` Christoph Hellwig
2024-06-03  6:53   ` Hannes Reinecke
2024-05-30  5:40 ` [PATCH 2/4] block: Fix validation of zoned device with a runt zone Damien Le Moal
2024-05-30  7:37   ` Niklas Cassel
2024-05-30 20:37   ` Bart Van Assche
2024-06-01  5:26   ` Christoph Hellwig
2024-06-03  6:55   ` Hannes Reinecke
2024-05-30  5:40 ` [PATCH 3/4] block: Fix zone write plugging handling of devices " Damien Le Moal
2024-05-30  7:37   ` Niklas Cassel
2024-05-30 11:09     ` Damien Le Moal
2024-05-30 12:51   ` Niklas Cassel
2024-05-30 20:40   ` Bart Van Assche
2024-06-01  5:26   ` Christoph Hellwig
2024-06-03  6:56   ` Hannes Reinecke
2024-05-30  5:40 ` [PATCH 4/4] dm: Improve zone resource limits handling Damien Le Moal
2024-05-30  7:37   ` Niklas Cassel
2024-05-31 19:26   ` Benjamin Marzinski
2024-06-01  5:29     ` Christoph Hellwig
2024-06-01  5:33       ` Christoph Hellwig
2024-06-03  0:44         ` Damien Le Moal
2024-06-01  5:29   ` Christoph Hellwig
2024-06-03  6:58   ` Hannes Reinecke
2024-05-30 21:03 ` [PATCH 0/4] Zone write plugging and DM zone fixes Jens Axboe
2024-05-30 23:58   ` Damien Le Moal
2024-05-30 21:04 ` (subset) " Jens Axboe

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=20240530054035.491497-2-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@lists.linux.dev \
    --cc=linux-block@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).