Skip to content

Commit 5eac3eb

Browse files
damien-lemoalaxboe
authored andcommitted
block: Remove partition support for zoned block devices
No known partitioning tool supports zoned block devices, especially the host managed flavor with strong sequential write constraints. Furthermore, there are also no known user nor use cases for partitioned zoned block devices. This patch removes partition device creation for zoned block devices, which allows simplifying the processing of zone commands for zoned block devices. A warning is added if a partition table is found on the device. For report zones operations no zone sector information remapping is necessary anymore, simplifying the code. Of note is that remapping of zone reports for DM targets is still necessary as done by dm_remap_zone_report(). Similarly, remaping of a zone reset bio is not necessary anymore. Testing for the applicability of the zone reset all request also becomes simpler and only needs to check that the number of sectors of the requested zone range is equal to the disk capacity. Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ceeb373 commit 5eac3eb

4 files changed

Lines changed: 21 additions & 124 deletions

File tree

‎block/blk-core.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,7 @@ static inline int blk_partition_remap(struct bio *bio)
851851
if (unlikely(bio_check_ro(bio, p)))
852852
goto out;
853853

854-
/*
855-
* Zone management bios do not have a sector count but they do have
856-
* a start sector filled out and need to be remapped.
857-
*/
858-
if (bio_sectors(bio) || op_is_zone_mgmt(bio_op(bio))) {
854+
if (bio_sectors(bio)) {
859855
if (bio_check_eod(bio, part_nr_sects_read(p)))
860856
goto out;
861857
bio->bi_iter.bi_sector += p->start_sect;

‎block/blk-zoned.c‎

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,10 @@ unsigned int blkdev_nr_zones(struct block_device *bdev)
9393
if (!blk_queue_is_zoned(q))
9494
return 0;
9595

96-
return __blkdev_nr_zones(q, bdev->bd_part->nr_sects);
96+
return __blkdev_nr_zones(q, get_capacity(bdev->bd_disk));
9797
}
9898
EXPORT_SYMBOL_GPL(blkdev_nr_zones);
9999

100-
/*
101-
* Check that a zone report belongs to this partition, and if yes, fix its start
102-
* sector and write pointer and return true. Return false otherwise.
103-
*/
104-
static bool blkdev_report_zone(struct block_device *bdev, struct blk_zone *rep)
105-
{
106-
sector_t offset = get_start_sect(bdev);
107-
108-
if (rep->start < offset)
109-
return false;
110-
111-
rep->start -= offset;
112-
if (rep->start + rep->len > bdev->bd_part->nr_sects)
113-
return false;
114-
115-
if (rep->type == BLK_ZONE_TYPE_CONVENTIONAL)
116-
rep->wp = rep->start + rep->len;
117-
else
118-
rep->wp -= offset;
119-
return true;
120-
}
121-
122100
/**
123101
* blkdev_report_zones - Get zones information
124102
* @bdev: Target block device
@@ -140,8 +118,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
140118
{
141119
struct request_queue *q = bdev_get_queue(bdev);
142120
struct gendisk *disk = bdev->bd_disk;
143-
unsigned int i, nrz;
144-
int ret;
121+
sector_t capacity = get_capacity(disk);
145122

146123
if (!blk_queue_is_zoned(q))
147124
return -EOPNOTSUPP;
@@ -154,27 +131,14 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
154131
if (WARN_ON_ONCE(!disk->fops->report_zones))
155132
return -EOPNOTSUPP;
156133

157-
if (!*nr_zones || sector >= bdev->bd_part->nr_sects) {
134+
if (!*nr_zones || sector >= capacity) {
158135
*nr_zones = 0;
159136
return 0;
160137
}
161138

162-
nrz = min(*nr_zones,
163-
__blkdev_nr_zones(q, bdev->bd_part->nr_sects - sector));
164-
ret = disk->fops->report_zones(disk, get_start_sect(bdev) + sector,
165-
zones, &nrz);
166-
if (ret)
167-
return ret;
139+
*nr_zones = min(*nr_zones, __blkdev_nr_zones(q, capacity - sector));
168140

169-
for (i = 0; i < nrz; i++) {
170-
if (!blkdev_report_zone(bdev, zones))
171-
break;
172-
zones++;
173-
}
174-
175-
*nr_zones = i;
176-
177-
return 0;
141+
return disk->fops->report_zones(disk, sector, zones, nr_zones);
178142
}
179143
EXPORT_SYMBOL_GPL(blkdev_report_zones);
180144

@@ -185,15 +149,11 @@ static inline bool blkdev_allow_reset_all_zones(struct block_device *bdev,
185149
if (!blk_queue_zone_resetall(bdev_get_queue(bdev)))
186150
return false;
187151

188-
if (sector || nr_sectors != part_nr_sects_read(bdev->bd_part))
189-
return false;
190152
/*
191-
* REQ_OP_ZONE_RESET_ALL can be executed only if the block device is
192-
* the entire disk, that is, if the blocks device start offset is 0 and
193-
* its capacity is the same as the entire disk.
153+
* REQ_OP_ZONE_RESET_ALL can be executed only if the number of sectors
154+
* of the applicable zone range is the entire disk.
194155
*/
195-
return get_start_sect(bdev) == 0 &&
196-
part_nr_sects_read(bdev->bd_part) == get_capacity(bdev->bd_disk);
156+
return !sector && nr_sectors == get_capacity(bdev->bd_disk);
197157
}
198158

199159
/**
@@ -218,6 +178,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
218178
{
219179
struct request_queue *q = bdev_get_queue(bdev);
220180
sector_t zone_sectors = blk_queue_zone_sectors(q);
181+
sector_t capacity = get_capacity(bdev->bd_disk);
221182
sector_t end_sector = sector + nr_sectors;
222183
struct bio *bio = NULL;
223184
int ret;
@@ -231,16 +192,15 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
231192
if (!op_is_zone_mgmt(op))
232193
return -EOPNOTSUPP;
233194

234-
if (!nr_sectors || end_sector > bdev->bd_part->nr_sects)
195+
if (!nr_sectors || end_sector > capacity)
235196
/* Out of range */
236197
return -EINVAL;
237198

238199
/* Check alignment (handle eventual smaller last zone) */
239200
if (sector & (zone_sectors - 1))
240201
return -EINVAL;
241202

242-
if ((nr_sectors & (zone_sectors - 1)) &&
243-
end_sector != bdev->bd_part->nr_sects)
203+
if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity)
244204
return -EINVAL;
245205

246206
while (sector < end_sector) {

‎block/partition-generic.c‎

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -459,56 +459,6 @@ static int drop_partitions(struct gendisk *disk, struct block_device *bdev)
459459
return 0;
460460
}
461461

462-
static bool part_zone_aligned(struct gendisk *disk,
463-
struct block_device *bdev,
464-
sector_t from, sector_t size)
465-
{
466-
unsigned int zone_sectors = bdev_zone_sectors(bdev);
467-
468-
/*
469-
* If this function is called, then the disk is a zoned block device
470-
* (host-aware or host-managed). This can be detected even if the
471-
* zoned block device support is disabled (CONFIG_BLK_DEV_ZONED not
472-
* set). In this case, however, only host-aware devices will be seen
473-
* as a block device is not created for host-managed devices. Without
474-
* zoned block device support, host-aware drives can still be used as
475-
* regular block devices (no zone operation) and their zone size will
476-
* be reported as 0. Allow this case.
477-
*/
478-
if (!zone_sectors)
479-
return true;
480-
481-
/*
482-
* Check partition start and size alignement. If the drive has a
483-
* smaller last runt zone, ignore it and allow the partition to
484-
* use it. Check the zone size too: it should be a power of 2 number
485-
* of sectors.
486-
*/
487-
if (WARN_ON_ONCE(!is_power_of_2(zone_sectors))) {
488-
u32 rem;
489-
490-
div_u64_rem(from, zone_sectors, &rem);
491-
if (rem)
492-
return false;
493-
if ((from + size) < get_capacity(disk)) {
494-
div_u64_rem(size, zone_sectors, &rem);
495-
if (rem)
496-
return false;
497-
}
498-
499-
} else {
500-
501-
if (from & (zone_sectors - 1))
502-
return false;
503-
if ((from + size) < get_capacity(disk) &&
504-
(size & (zone_sectors - 1)))
505-
return false;
506-
507-
}
508-
509-
return true;
510-
}
511-
512462
int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
513463
{
514464
struct parsed_partitions *state = NULL;
@@ -544,6 +494,14 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
544494
}
545495
return -EIO;
546496
}
497+
498+
/* Partitions are not supported on zoned block devices */
499+
if (bdev_is_zoned(bdev)) {
500+
pr_warn("%s: ignoring partition table on zoned block device\n",
501+
disk->disk_name);
502+
goto out;
503+
}
504+
547505
/*
548506
* If any partition code tried to read beyond EOD, try
549507
* unlocking native capacity even if partition table is
@@ -607,21 +565,6 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
607565
}
608566
}
609567

610-
/*
611-
* On a zoned block device, partitions should be aligned on the
612-
* device zone size (i.e. zone boundary crossing not allowed).
613-
* Otherwise, resetting the write pointer of the last zone of
614-
* one partition may impact the following partition.
615-
*/
616-
if (bdev_is_zoned(bdev) &&
617-
!part_zone_aligned(disk, bdev, from, size)) {
618-
printk(KERN_WARNING
619-
"%s: p%d start %llu+%llu is not zone aligned\n",
620-
disk->disk_name, p, (unsigned long long) from,
621-
(unsigned long long) size);
622-
continue;
623-
}
624-
625568
part = add_partition(disk, p, from, size,
626569
state->parts[p].flags,
627570
&state->parts[p].info);
@@ -635,6 +578,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
635578
md_autodetect_dev(part_to_dev(part)->devt);
636579
#endif
637580
}
581+
out:
638582
free_partitions(state);
639583
return 0;
640584
}

‎drivers/md/dm.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,9 +1211,6 @@ EXPORT_SYMBOL_GPL(dm_accept_partial_bio);
12111211
* The zone descriptors obtained with a zone report indicate
12121212
* zone positions within the underlying device of the target. The zone
12131213
* descriptors must be remapped to match their position within the dm device.
1214-
* The caller target should obtain the zones information using
1215-
* blkdev_report_zones() to ensure that remapping for partition offset is
1216-
* already handled.
12171214
*/
12181215
void dm_remap_zone_report(struct dm_target *ti, sector_t start,
12191216
struct blk_zone *zones, unsigned int *nr_zones)

0 commit comments

Comments
 (0)