Skip to contentSkip to conversation

block: two fixes for the zone report ioctls

PATCH Superseded Shashank Mohan Jain 3 participants 16 messages Oct 11 – Oct 12

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover block: two fixes for the zone report ioctls

Two problems in the zone report code added in v6.19:

- BLKREPORTZONEV2 does not look at BLK_ZONE_REP_CACHED and returns the cached report also when the flag is not set (patch 1).

- blkdev_get_zone_info() gives a smaller last zone the length of a full zone, so the cached report describes a zone that ends behind the end of the device (patch 2).

Both were found by reading the code and then confirmed with zoned null_blk devices in qemu (x86_64). The test program opens one zone explicitly, writes to a second zone and closes it, and compares the reports of BLKREPORTZONE, BLKREPORTZONEV2 with flags 0 and BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED. On mainline it finds both problems. With patch 1 only the length of the last zone in the cached report is left, and with both patches there is no difference apart from the zone conditions and the write pointer of conventional zones in the cached report, which are as documented.

For patch 1 there is a choice between the code and the documentation. The changelog of b30ffcdc0c15 and the comments in the uapi header both say that without BLK_ZONE_REP_CACHED the report comes from the device, and BLKREPORTZONE is marked as deprecated in favour of the new ioctl, so I changed the code. If the cached report is meant to be the only mode of BLKREPORTZONEV2, the header needs to say so instead.

The series is based on mainline (a5ebb76233b7, v7.3-rc6+). Patch 1 applies to next-20261009 as is. Patch 2 needs its context adjusted there, because blkdev_get_zone_info() tests the zone type instead of the zone condition in for-7.4/block.

Shashank Mohan Jain (2):
block: only use the cached zone report if BLK_ZONE_REP_CACHED is set
block: fix the length of a smaller last zone in blkdev_get_zone_info()

 block/blk-zoned.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 block: only use the cached zone report if BLK_ZONE_REP_CACHED is set

BLKREPORTZONEV2 takes the flags field of struct blk_zone_report as an input. With BLK_ZONE_REP_CACHED the report is built from the zone information cached by the block layer. Without it, BLKREPORTZONEV2 is documented to behave like BLKREPORTZONE and to get the report from the
device: this is what the changelog of the commit that added the ioctl and the comments in include/uapi/linux/blkzoned.h say.

blkdev_report_zones_ioctl() only uses the flag to validate the input and calls blkdev_report_zones_cached() for every BLKREPORTZONEV2 request. A caller that passes flags == 0 gets the cached report, in which implicitly open, explicitly open and closed zones all have the condition BLK_ZONE_COND_ACTIVE, and an explicitly opened empty zone is reported as empty.

Example with a zoned null_blk device (10 MiB, 4 MiB zones) after BLKOPENZONE on zone 0, and a write of 8 sectors to zone 1 followed by BLKCLOSEZONE:

BLKREPORTZONE: zone 0 cond 0x3 (EXP_OPEN)

                             zone 1 cond 0x4 (CLOSED)
  BLKREPORTZONEV2, flags 0:  zone 0 cond 0x1 (EMPTY)
                             zone 1 cond 0xff (ACTIVE)

The uapi header marks BLKREPORTZONE as deprecated in favour of BLKREPORTZONEV2. A program that follows this and does not ask for cached information can no longer tell open zones from closed ones, and is handed BLK_ZONE_COND_ACTIVE, which is only defined for the cached report.

Call blkdev_report_zones_cached() only if BLK_ZONE_REP_CACHED is set, and blkdev_report_zones() otherwise.

Tested with zoned null_blk devices in qemu: a program that compares the reports of BLKREPORTZONE and BLKREPORTZONEV2 with flags 0 after the sequence above finds the differences before this change and none with it. The report with BLK_ZONE_REP_CACHED is unchanged.

Fixes b30ffcdc0c15 ("block: introduce BLKREPORTZONESV2 ioctl")
Assisted-by LLM

---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5).

 block/blk-zoned.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/blk-zoned.c +7 -0
index 475aa16bc4..9555eae91a 100644
@@ -400,6 +400,13 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
 	case BLKREPORTZONEV2:
 		if (rep.flags & ~BLK_ZONE_REPV2_INPUT_FLAGS)
 			return -EINVAL;
+		if (!(rep.flags & BLK_ZONE_REP_CACHED)) {
+			ret = blkdev_report_zones(bdev, rep.sector,
+						  rep.nr_zones,
+						  blkdev_copy_zone_to_user,
+						  &args);
+			break;
+		}
 		ret = blkdev_report_zones_cached(bdev, rep.sector, rep.nr_zones,
 					 blkdev_copy_zone_to_user, &args);
 		break;
Signature · 1 line
2.43.0
#5 lore raw

PATCH 2/2 block: fix the length of a smaller last zone in blkdev_get_zone_info()

In reply to Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Limit the length to what is left of the device. disk_zone_is_last() still recognises the last zone, as start + len is then equal to the capacity of the device. The capacity of a conventional zone is equal to its length, which blk_revalidate_conv_zone() checks, so use the length there.

Tested with zoned null_blk devices in qemu (all zones sequential, and two conventional zones followed by sequential ones, both with a smaller last zone): the start, length and capacity of all zones in the cached report are the same as in the report from the device with this change. null_blk cannot create a device with a conventional last zone, so that case is not tested.

Fixes f2284eec5053 ("block: introduce blkdev_get_zone_info()")
Assisted-by LLM

---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5).

 block/blk-zoned.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-zoned.c +2 -2
index 9555eae91a..ca0950be3e 100644
@@ -971,7 +971,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 	rcu_read_unlock();
 
 	zone->start = sector;
-	zone->len = zone_sectors;
+	zone->len = min(zone_sectors, get_capacity(disk) - sector);
 
 	/*
 	 * If this is a conventional zone, we do not have a zone write plug and
@@ -979,7 +979,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 	 */
 	if (zone->cond == BLK_ZONE_COND_NOT_WP) {
 		zone->type = BLK_ZONE_TYPE_CONVENTIONAL;
-		zone->capacity = zone_sectors;
+		zone->capacity = zone->len;
 		zone->wp = ULLONG_MAX;
 		return 0;
 	}
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/2] block: only use the cached zone report if BLK_ZONE_REP_CACHED is set

In reply to Shashank Mohan Jain
Quoted 55 lines · Shashank Mohan Jain

BLKREPORTZONEV2 takes the flags field of struct blk_zone_report as an input. With BLK_ZONE_REP_CACHED the report is built from the zone information cached by the block layer. Without it, BLKREPORTZONEV2 is documented to behave like BLKREPORTZONE and to get the report from the
device: this is what the changelog of the commit that added the ioctl and the comments in include/uapi/linux/blkzoned.h say.

blkdev_report_zones_ioctl() only uses the flag to validate the input and calls blkdev_report_zones_cached() for every BLKREPORTZONEV2 request. A caller that passes flags == 0 gets the cached report, in which implicitly open, explicitly open and closed zones all have the condition BLK_ZONE_COND_ACTIVE, and an explicitly opened empty zone is reported as empty.

Example with a zoned null_blk device (10 MiB, 4 MiB zones) after BLKOPENZONE on zone 0, and a write of 8 sectors to zone 1 followed by BLKCLOSEZONE:

BLKREPORTZONE: zone 0 cond 0x3 (EXP_OPEN)

                             zone 1 cond 0x4 (CLOSED)
  BLKREPORTZONEV2, flags 0:  zone 0 cond 0x1 (EMPTY)
                             zone 1 cond 0xff (ACTIVE)

The uapi header marks BLKREPORTZONE as deprecated in favour of BLKREPORTZONEV2. A program that follows this and does not ask for cached information can no longer tell open zones from closed ones, and is handed BLK_ZONE_COND_ACTIVE, which is only defined for the cached report.

Call blkdev_report_zones_cached() only if BLK_ZONE_REP_CACHED is set, and blkdev_report_zones() otherwise.

Tested with zoned null_blk devices in qemu: a program that compares the reports of BLKREPORTZONE and BLKREPORTZONEV2 with flags 0 after the sequence above finds the differences before this change and none with it. The report with BLK_ZONE_REP_CACHED is unchanged.

Fixes b30ffcdc0c15 ("block: introduce BLKREPORTZONESV2 ioctl")
Assisted-by LLM

---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5).

 block/blk-zoned.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/blk-zoned.c +0 -0
index 475aa16bc4..9555eae91a 100644
@@ -400,6 +400,13 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
 	case BLKREPORTZONEV2:
 		if (rep.flags & ~BLK_ZONE_REPV2_INPUT_FLAGS)

block/blk-zoned.c int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd, · line 411

Quoted 10 lines
block/blk-zoned.c +7 -0
 			return -EINVAL;
+		if (!(rep.flags & BLK_ZONE_REP_CACHED)) {
+			ret = blkdev_report_zones(bdev, rep.sector,
+						  rep.nr_zones,
+						  blkdev_copy_zone_to_user,
+						  &args);
+			break;
+		}
 		ret = blkdev_report_zones_cached(bdev, rep.sector, rep.nr_zones,
 					 blkdev_copy_zone_to_user, &args);

Can you reverse this if to be "if (rep.flags & BLK_ZONE_REP_CACHED) {" and to call blkdev_report_zones_cached if the condition is true? That would be a lot more logical.

Also, the condition should probably be:

	if ((rep.flags & BLK_ZONE_REP_CACHED) &&
	    blkdev_has_cached_report_zones(bdev))

to be more efficient and avoid a call to blkdev_report_zones_cached() which will turn into a regular device report zones.

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

In reply to Shashank Mohan Jain
Quoted 28 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Limit the length to what is left of the device. disk_zone_is_last() still recognises the last zone, as start + len is then equal to the capacity of the device. The capacity of a conventional zone is equal to its length, which blk_revalidate_conv_zone() checks, so use the length there.

Tested with zoned null_blk devices in qemu (all zones sequential, and two conventional zones followed by sequential ones, both with a smaller last zone): the start, length and capacity of all zones in the cached report are the same as in the report from the device with this change. null_blk cannot create a device with a conventional last zone, so that case is not tested.

Quoted 4 lines
Fixes f2284eec5053 ("block: introduce blkdev_get_zone_info()")
Assisted-by LLM

Doh! Good catch.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH 1/2] block: only use the cached zone report if BLK_ZONE_REP_CACHED is set

In reply to Damien Le Moal
Quoted 4 lines · Damien Le Moal

Can you reverse this if to be "if (rep.flags & BLK_ZONE_REP_CACHED) {" ... Also, the condition should probably be:

        if ((rep.flags & BLK_ZONE_REP_CACHED) &&
            blkdev_has_cached_report_zones(bdev))

Reworked exactly as suggested and reposted as v2:
https://lore.kernel.org/all/[email protected]/

blkdev_has_cached_report_zones() is now used from the ioctl, so I moved it (with its comment) above blkdev_report_zones_ioctl(). Patch 2 is unchanged and carries your Reviewed-by. Retested on zoned null_blk.

Thanks,
Shashank

Quoted 84 lines · Damien Le Moal
Quoted 55 lines · Shashank Mohan Jain

BLKREPORTZONEV2 takes the flags field of struct blk_zone_report as an input. With BLK_ZONE_REP_CACHED the report is built from the zone information cached by the block layer. Without it, BLKREPORTZONEV2 is documented to behave like BLKREPORTZONE and to get the report from the
device: this is what the changelog of the commit that added the ioctl and the comments in include/uapi/linux/blkzoned.h say.

blkdev_report_zones_ioctl() only uses the flag to validate the input and calls blkdev_report_zones_cached() for every BLKREPORTZONEV2 request. A caller that passes flags == 0 gets the cached report, in which implicitly open, explicitly open and closed zones all have the condition BLK_ZONE_COND_ACTIVE, and an explicitly opened empty zone is reported as empty.

Example with a zoned null_blk device (10 MiB, 4 MiB zones) after BLKOPENZONE on zone 0, and a write of 8 sectors to zone 1 followed by BLKCLOSEZONE:

BLKREPORTZONE: zone 0 cond 0x3 (EXP_OPEN)

                             zone 1 cond 0x4 (CLOSED)
  BLKREPORTZONEV2, flags 0:  zone 0 cond 0x1 (EMPTY)
                             zone 1 cond 0xff (ACTIVE)

The uapi header marks BLKREPORTZONE as deprecated in favour of BLKREPORTZONEV2. A program that follows this and does not ask for cached information can no longer tell open zones from closed ones, and is handed BLK_ZONE_COND_ACTIVE, which is only defined for the cached report.

Call blkdev_report_zones_cached() only if BLK_ZONE_REP_CACHED is set, and blkdev_report_zones() otherwise.

Tested with zoned null_blk devices in qemu: a program that compares the reports of BLKREPORTZONE and BLKREPORTZONEV2 with flags 0 after the sequence above finds the differences before this change and none with it. The report with BLK_ZONE_REP_CACHED is unchanged.

Fixes b30ffcdc0c15 ("block: introduce BLKREPORTZONESV2 ioctl")
Assisted-by LLM

---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5).

 block/blk-zoned.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/blk-zoned.c +0 -0
index 475aa16bc4..9555eae91a 100644
@@ -400,6 +400,13 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
      case BLKREPORTZONEV2:
              if (rep.flags & ~BLK_ZONE_REPV2_INPUT_FLAGS)

block/blk-zoned.c int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd, · line 411

Quoted 10 lines
block/blk-zoned.c +7 -0
                      return -EINVAL;
+             if (!(rep.flags & BLK_ZONE_REP_CACHED)) {
+                     ret = blkdev_report_zones(bdev, rep.sector,
+                                               rep.nr_zones,
+                                               blkdev_copy_zone_to_user,
+                                               &args);
+                     break;
+             }
              ret = blkdev_report_zones_cached(bdev, rep.sector, rep.nr_zones,
                                       blkdev_copy_zone_to_user, &args);

Can you reverse this if to be "if (rep.flags & BLK_ZONE_REP_CACHED) {" and to call blkdev_report_zones_cached if the condition is true? That would be a lot more logical.

Also, the condition should probably be:

        if ((rep.flags & BLK_ZONE_REP_CACHED) &&
            blkdev_has_cached_report_zones(bdev))

to be more efficient and avoid a call to blkdev_report_zones_cached() which will turn into a regular device report zones.

--
Damien Le Moal
Western Digital Research

#4 lore raw

Re: [PATCH 1/2] block: only use the cached zone report if BLK_ZONE_REP_CACHED is set

In reply to Damien Le Moal
Quoted 4 lines · Damien Le Moal

Can you reverse this if to be "if (rep.flags & BLK_ZONE_REP_CACHED) {" ... Also, the condition should probably be:

        if ((rep.flags & BLK_ZONE_REP_CACHED) &&
            blkdev_has_cached_report_zones(bdev))

Reworked exactly as suggested and reposted as v2:
https://lore.kernel.org/all/[email protected]/

blkdev_has_cached_report_zones() is now used from the ioctl, so I moved it (with its comment) above blkdev_report_zones_ioctl(). Patch 2 is unchanged and carries your Reviewed-by. Retested on zoned null_blk.

Thanks,
Shashank

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

In reply to Shashank Mohan Jain
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

#8 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

maintainer
#9 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

Signature · 2 lines
Damien Le Moal
Western Digital Research
#10 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.
- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Thanks,
Shashank

Quoted 47 lines · Damien Le Moal
Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

--
Damien Le Moal
Western Digital Research

maintainer
#11 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 9 lines · shashank Jain
Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.

We should leave "blkzone report" to get the device report as before, to avoid breaking anything for user with the "active" condition being returned. I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.

If you want to take on such patch, go ahead. CC me on it and I will review. The patches I need to send to add depop support will take some more time.

Quoted 58 lines

- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Thanks,
Shashank

Quoted 47 lines · Damien Le Moal
Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

--
Damien Le Moal
Western Digital Research

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#15 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

In reply to shashank Jain
Quoted 13 lines · shashank Jain
Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.
- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

Quoted 2 lines

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Yes, let's avoid the small helper. Having access to the cached report with blkzone will be useful for many things anyway, and the patch should be easy.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#12 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

In reply to Damien Le Moal
Quoted 3 lines · Damien Le Moal

I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.
If you want to take on such patch, go ahead. CC me on it and I will review.

Thanks - yes, I will take it: a "--cached" option to "blkzone report" that selects BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED, leaving the default report via the device (BLKREPORTZONE) unchanged. I will post it to util-linux and CC you. The blktests reproducer will then use "blkzone report --cached" rather than a bundled helper.

Thanks,
Shashank

Quoted 83 lines · Damien Le Moal
Quoted 9 lines · shashank Jain
Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.

We should leave "blkzone report" to get the device report as before, to avoid breaking anything for user with the "active" condition being returned. I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.

If you want to take on such patch, go ahead. CC me on it and I will review. The patches I need to send to add depop support will take some more time.

Quoted 4 lines

- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

Quoted 54 lines

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Thanks,
Shashank

Quoted 47 lines · Damien Le Moal
Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

--
Damien Le Moal
Western Digital Research

--
Damien Le Moal
Western Digital Research

maintainer
#13 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 10 lines · shashank Jain
Quoted 3 lines · Damien Le Moal

I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.
If you want to take on such patch, go ahead. CC me on it and I will review.

Thanks - yes, I will take it: a "--cached" option to "blkzone report" that selects BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED, leaving the default report via the device (BLKREPORTZONE) unchanged. I will post it to util-linux and CC you. The blktests reproducer will then use "blkzone report --cached" rather than a bundled helper.

Maybe add a prep patch that defaults to BLKREPORTZONEV2 (without BLK_ZONE_REP_CACHED) if BLKREPORTZONEV2 is defined.

And a second patch that adds the --cached option for BLK_ZONE_REP_CACHED.

Quoted 88 lines

Thanks,
Shashank

Quoted 83 lines · Damien Le Moal
Quoted 9 lines · shashank Jain
Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.

We should leave "blkzone report" to get the device report as before, to avoid breaking anything for user with the "active" condition being returned. I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.

If you want to take on such patch, go ahead. CC me on it and I will review. The patches I need to send to add depop support will take some more time.

Quoted 4 lines

- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

Quoted 54 lines

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Thanks,
Shashank

Quoted 47 lines · Damien Le Moal
Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

--
Damien Le Moal
Western Digital Research

--
Damien Le Moal
Western Digital Research

Signature · 2 lines
Damien Le Moal
Western Digital Research
#14 lore raw

Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

Quoted 3 lines · Damien Le Moal

Maybe add a prep patch that defaults to BLKREPORTZONEV2 (without BLK_ZONE_REP_CACHED) if BLKREPORTZONEV2 is defined.
And a second patch that adds the --cached option for BLK_ZONE_REP_CACHED.

Will do - a 2-patch series: 1/2 makes "blkzone report" use BLKREPORTZONEV2 (without BLK_ZONE_REP_CACHED) when the ioctl is defined in the headers, keeping the current device-report behaviour; 2/2 adds "--cached" for BLK_ZONE_REP_CACHED. I will CC you.

Thanks,
Shashank

Quoted 111 lines · Damien Le Moal
Quoted 10 lines · shashank Jain
Quoted 3 lines · Damien Le Moal

I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.
If you want to take on such patch, go ahead. CC me on it and I will review.

Thanks - yes, I will take it: a "--cached" option to "blkzone report" that selects BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED, leaving the default report via the device (BLKREPORTZONE) unchanged. I will post it to util-linux and CC you. The blktests reproducer will then use "blkzone report --cached" rather than a bundled helper.

Maybe add a prep patch that defaults to BLKREPORTZONEV2 (without BLK_ZONE_REP_CACHED) if BLKREPORTZONEV2 is defined.

And a second patch that adds the --cached option for BLK_ZONE_REP_CACHED.

Quoted 88 lines

Thanks,
Shashank

Quoted 83 lines · Damien Le Moal
Quoted 9 lines · shashank Jain
Quoted 2 lines · Damien Le Moal

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Good point. Two options, and I am happy to follow your preference:

- Use "blkzone report" with the cached flag once your util-linux patch lands - that matches the existing zbd tests and avoids a bundled tool. I would hold the blktests submission until it is available.

We should leave "blkzone report" to get the device report as before, to avoid breaking anything for user with the "active" condition being returned. I was thinking on adding a "--cached" option to control the use of BLK_ZONE_REP_CACHED.

If you want to take on such patch, go ahead. CC me on it and I will review. The patches I need to send to add depop support will take some more time.

Quoted 4 lines

- Or carry a small C helper in the blktests src/ directory that issues BLKREPORTZONEV2 with BLK_ZONE_REP_CACHED directly, so the test is self-contained and does not depend on the util-linux version.

Quoted 54 lines

I lean towards the first, to match the zbd conventions and your blkzone work; tell me which you prefer and I will align the test with it.

Thanks,
Shashank

Quoted 47 lines · Damien Le Moal
Quoted 8 lines · shashank Jain
Quoted 1 line · Christoph Hellwig

Can you add this to blktests as a reproducer?

Will do. I'll send a blktests test under tests/zbd/ that sets up a zoned null_blk device with a smaller last zone and checks that BLKREPORTZONEV2 without BLK_ZONE_REP_CACHED matches BLKREPORTZONE, and that the cached report's last-zone length does not extend past the device. I'll post it to the blktests project separately and reference this series.

How do you plan to issue a BLK_ZONE_REP_CACHED report? "blkzone report" does not have that yet. I am planning to send a patch for it.

Quoted 28 lines

Thanks,
Shashank

Quoted 23 lines · Christoph Hellwig
Quoted 8 lines · Shashank Mohan Jain

blkdev_get_zone_info() sets the length of every zone to the zone size of the device. The last zone of a zoned block device may be smaller than the others: blk_revalidate_zone_cb() accepts that and remembers the capacity of that zone in disk->last_zone_capacity. For such a zone the length reported from the cached information is too large, and start + len is beyond the end of the device. A conventional last zone is also given the capacity of a full zone.

Quoted 6 lines

Example with a zoned null_blk device of 10 MiB (20480 sectors) with 4 MiB zones, last zone:

BLKREPORTZONE: start 16384 len 4096 capacity 4096
BLKREPORTZONEV2 with
BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096

Can you add this to blktests as a reproducer?

The patch looks good:

--
Damien Le Moal
Western Digital Research

--
Damien Le Moal
Western Digital Research

--
Damien Le Moal
Western Digital Research