Skip to content

Commit 6a99659

Browse files
committed
Merge branch 'for-6.11/block' into for-next
* for-6.11/block: block: Remove blk_alloc_zone_bitmap() block: Remove REQ_OP_ZONE_RESET_ALL emulation dm: handle REQ_OP_ZONE_RESET_ALL dm: Refactor is_abnormal_io() null_blk: Introduce the zone_full parameter loop: remove the unused inode variable in loop_configure
2 parents e28979e + 2f20872 commit 6a99659

File tree

15 files changed

+229
-120
lines changed

15 files changed

+229
-120
lines changed

block/blk-core.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,8 @@ void submit_bio_noacct(struct bio *bio)
830830
case REQ_OP_ZONE_OPEN:
831831
case REQ_OP_ZONE_CLOSE:
832832
case REQ_OP_ZONE_FINISH:
833-
if (!bdev_is_zoned(bio->bi_bdev))
834-
goto not_supported;
835-
break;
836833
case REQ_OP_ZONE_RESET_ALL:
837-
if (!bdev_is_zoned(bio->bi_bdev) || !blk_queue_zone_resetall(q))
834+
if (!bdev_is_zoned(bio->bi_bdev))
838835
goto not_supported;
839836
break;
840837
case REQ_OP_DRV_IN:

block/blk-zoned.c

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -150,77 +150,6 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
150150
}
151151
EXPORT_SYMBOL_GPL(blkdev_report_zones);
152152

153-
static inline unsigned long *blk_alloc_zone_bitmap(int node,
154-
unsigned int nr_zones)
155-
{
156-
return kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(unsigned long),
157-
GFP_NOIO, node);
158-
}
159-
160-
static int blk_zone_need_reset_cb(struct blk_zone *zone, unsigned int idx,
161-
void *data)
162-
{
163-
/*
164-
* For an all-zones reset, ignore conventional, empty, read-only
165-
* and offline zones.
166-
*/
167-
switch (zone->cond) {
168-
case BLK_ZONE_COND_NOT_WP:
169-
case BLK_ZONE_COND_EMPTY:
170-
case BLK_ZONE_COND_READONLY:
171-
case BLK_ZONE_COND_OFFLINE:
172-
return 0;
173-
default:
174-
set_bit(idx, (unsigned long *)data);
175-
return 0;
176-
}
177-
}
178-
179-
static int blkdev_zone_reset_all_emulated(struct block_device *bdev)
180-
{
181-
struct gendisk *disk = bdev->bd_disk;
182-
sector_t capacity = bdev_nr_sectors(bdev);
183-
sector_t zone_sectors = bdev_zone_sectors(bdev);
184-
unsigned long *need_reset;
185-
struct bio *bio = NULL;
186-
sector_t sector = 0;
187-
int ret;
188-
189-
need_reset = blk_alloc_zone_bitmap(disk->queue->node, disk->nr_zones);
190-
if (!need_reset)
191-
return -ENOMEM;
192-
193-
ret = disk->fops->report_zones(disk, 0, disk->nr_zones,
194-
blk_zone_need_reset_cb, need_reset);
195-
if (ret < 0)
196-
goto out_free_need_reset;
197-
198-
ret = 0;
199-
while (sector < capacity) {
200-
if (!test_bit(disk_zone_no(disk, sector), need_reset)) {
201-
sector += zone_sectors;
202-
continue;
203-
}
204-
205-
bio = blk_next_bio(bio, bdev, 0, REQ_OP_ZONE_RESET | REQ_SYNC,
206-
GFP_KERNEL);
207-
bio->bi_iter.bi_sector = sector;
208-
sector += zone_sectors;
209-
210-
/* This may take a while, so be nice to others */
211-
cond_resched();
212-
}
213-
214-
if (bio) {
215-
ret = submit_bio_wait(bio);
216-
bio_put(bio);
217-
}
218-
219-
out_free_need_reset:
220-
kfree(need_reset);
221-
return ret;
222-
}
223-
224153
static int blkdev_zone_reset_all(struct block_device *bdev)
225154
{
226155
struct bio bio;
@@ -247,7 +176,6 @@ static int blkdev_zone_reset_all(struct block_device *bdev)
247176
int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
248177
sector_t sector, sector_t nr_sectors)
249178
{
250-
struct request_queue *q = bdev_get_queue(bdev);
251179
sector_t zone_sectors = bdev_zone_sectors(bdev);
252180
sector_t capacity = bdev_nr_sectors(bdev);
253181
sector_t end_sector = sector + nr_sectors;
@@ -275,16 +203,11 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
275203
return -EINVAL;
276204

277205
/*
278-
* In the case of a zone reset operation over all zones,
279-
* REQ_OP_ZONE_RESET_ALL can be used with devices supporting this
280-
* command. For other devices, we emulate this command behavior by
281-
* identifying the zones needing a reset.
206+
* In the case of a zone reset operation over all zones, use
207+
* REQ_OP_ZONE_RESET_ALL.
282208
*/
283-
if (op == REQ_OP_ZONE_RESET && sector == 0 && nr_sectors == capacity) {
284-
if (!blk_queue_zone_resetall(q))
285-
return blkdev_zone_reset_all_emulated(bdev);
209+
if (op == REQ_OP_ZONE_RESET && sector == 0 && nr_sectors == capacity)
286210
return blkdev_zone_reset_all(bdev);
287-
}
288211

289212
while (sector < end_sector) {
290213
bio = blk_next_bio(bio, bdev, 0, op | REQ_SYNC, GFP_KERNEL);
@@ -1555,7 +1478,7 @@ void disk_free_zone_resources(struct gendisk *disk)
15551478
mempool_destroy(disk->zone_wplugs_pool);
15561479
disk->zone_wplugs_pool = NULL;
15571480

1558-
kfree(disk->conv_zones_bitmap);
1481+
bitmap_free(disk->conv_zones_bitmap);
15591482
disk->conv_zones_bitmap = NULL;
15601483
disk->zone_capacity = 0;
15611484
disk->last_zone_capacity = 0;
@@ -1677,7 +1600,6 @@ static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx,
16771600
struct blk_revalidate_zone_args *args)
16781601
{
16791602
struct gendisk *disk = args->disk;
1680-
struct request_queue *q = disk->queue;
16811603

16821604
if (zone->capacity != zone->len) {
16831605
pr_warn("%s: Invalid conventional zone capacity\n",
@@ -1693,7 +1615,7 @@ static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx,
16931615

16941616
if (!args->conv_zones_bitmap) {
16951617
args->conv_zones_bitmap =
1696-
blk_alloc_zone_bitmap(q->node, args->nr_zones);
1618+
bitmap_zalloc(args->nr_zones, GFP_NOIO);
16971619
if (!args->conv_zones_bitmap)
16981620
return -ENOMEM;
16991621
}

drivers/block/loop.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10191019
const struct loop_config *config)
10201020
{
10211021
struct file *file = fget(config->fd);
1022-
struct inode *inode;
10231022
struct address_space *mapping;
10241023
int error;
10251024
loff_t size;
@@ -1056,7 +1055,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10561055
goto out_unlock;
10571056

10581057
mapping = file->f_mapping;
1059-
inode = mapping->host;
10601058

10611059
if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) {
10621060
error = -EINVAL;

drivers/block/null_blk/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ module_param_named(zone_append_max_sectors, g_zone_append_max_sectors, int, 0444
262262
MODULE_PARM_DESC(zone_append_max_sectors,
263263
"Maximum size of a zone append command (in 512B sectors). Specify 0 for zone append emulation");
264264

265+
static bool g_zone_full;
266+
module_param_named(zone_full, g_zone_full, bool, S_IRUGO);
267+
MODULE_PARM_DESC(zone_full, "Initialize the sequential write required zones of a zoned device to be full. Default: false");
268+
265269
static struct nullb_device *null_alloc_dev(void);
266270
static void null_free_dev(struct nullb_device *dev);
267271
static void null_del_dev(struct nullb *nullb);
@@ -458,6 +462,7 @@ NULLB_DEVICE_ATTR(zone_nr_conv, uint, NULL);
458462
NULLB_DEVICE_ATTR(zone_max_open, uint, NULL);
459463
NULLB_DEVICE_ATTR(zone_max_active, uint, NULL);
460464
NULLB_DEVICE_ATTR(zone_append_max_sectors, uint, NULL);
465+
NULLB_DEVICE_ATTR(zone_full, bool, NULL);
461466
NULLB_DEVICE_ATTR(virt_boundary, bool, NULL);
462467
NULLB_DEVICE_ATTR(no_sched, bool, NULL);
463468
NULLB_DEVICE_ATTR(shared_tags, bool, NULL);
@@ -610,6 +615,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
610615
&nullb_device_attr_zone_append_max_sectors,
611616
&nullb_device_attr_zone_readonly,
612617
&nullb_device_attr_zone_offline,
618+
&nullb_device_attr_zone_full,
613619
&nullb_device_attr_virt_boundary,
614620
&nullb_device_attr_no_sched,
615621
&nullb_device_attr_shared_tags,
@@ -700,7 +706,7 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page)
700706
"shared_tags,size,submit_queues,use_per_node_hctx,"
701707
"virt_boundary,zoned,zone_capacity,zone_max_active,"
702708
"zone_max_open,zone_nr_conv,zone_offline,zone_readonly,"
703-
"zone_size,zone_append_max_sectors\n");
709+
"zone_size,zone_append_max_sectors,zone_full\n");
704710
}
705711

706712
CONFIGFS_ATTR_RO(memb_group_, features);
@@ -781,6 +787,7 @@ static struct nullb_device *null_alloc_dev(void)
781787
dev->zone_max_open = g_zone_max_open;
782788
dev->zone_max_active = g_zone_max_active;
783789
dev->zone_append_max_sectors = g_zone_append_max_sectors;
790+
dev->zone_full = g_zone_full;
784791
dev->virt_boundary = g_virt_boundary;
785792
dev->no_sched = g_no_sched;
786793
dev->shared_tags = g_shared_tags;

drivers/block/null_blk/null_blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct nullb_device {
101101
bool memory_backed; /* if data is stored in memory */
102102
bool discard; /* if support discard */
103103
bool zoned; /* if device is zoned */
104+
bool zone_full; /* Initialize zones to be full */
104105
bool virt_boundary; /* virtual boundary on/off for the device */
105106
bool no_sched; /* no IO scheduler for the device */
106107
bool shared_tags; /* share tag set between devices for blk-mq */

drivers/block/null_blk/zoned.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,26 @@ int null_init_zoned_dev(struct nullb_device *dev,
145145
zone = &dev->zones[i];
146146

147147
null_init_zone_lock(dev, zone);
148-
zone->start = zone->wp = sector;
148+
zone->start = sector;
149149
if (zone->start + dev->zone_size_sects > dev_capacity_sects)
150150
zone->len = dev_capacity_sects - zone->start;
151151
else
152152
zone->len = dev->zone_size_sects;
153153
zone->capacity =
154154
min_t(sector_t, zone->len, zone_capacity_sects);
155155
zone->type = BLK_ZONE_TYPE_SEQWRITE_REQ;
156-
zone->cond = BLK_ZONE_COND_EMPTY;
156+
if (dev->zone_full) {
157+
zone->cond = BLK_ZONE_COND_FULL;
158+
zone->wp = zone->start + zone->capacity;
159+
} else{
160+
zone->cond = BLK_ZONE_COND_EMPTY;
161+
zone->wp = zone->start;
162+
}
157163

158164
sector += dev->zone_size_sects;
159165
}
160166

161-
lim->features |= BLK_FEAT_ZONED | BLK_FEAT_ZONE_RESETALL;
167+
lim->features |= BLK_FEAT_ZONED;
162168
lim->chunk_sectors = dev->zone_size_sects;
163169
lim->max_zone_append_sectors = dev->zone_append_max_sectors;
164170
lim->max_open_zones = dev->zone_max_open;

drivers/block/ublk_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd)
21942194
if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED))
21952195
return -EOPNOTSUPP;
21962196

2197-
lim.features |= BLK_FEAT_ZONED | BLK_FEAT_ZONE_RESETALL;
2197+
lim.features |= BLK_FEAT_ZONED;
21982198
lim.max_active_zones = p->max_active_zones;
21992199
lim.max_open_zones = p->max_open_zones;
22002200
lim.max_zone_append_sectors = p->max_zone_append_sectors;

drivers/block/virtio_blk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ static int virtblk_read_zoned_limits(struct virtio_blk *vblk,
728728

729729
dev_dbg(&vdev->dev, "probing host-managed zoned device\n");
730730

731-
lim->features |= BLK_FEAT_ZONED | BLK_FEAT_ZONE_RESETALL;
731+
lim->features |= BLK_FEAT_ZONED;
732732

733733
virtio_cread(vdev, struct virtio_blk_config,
734734
zoned.max_open_zones, &v);

drivers/md/dm-zone.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ static int device_get_zone_resource_limits(struct dm_target *ti,
292292

293293
/*
294294
* If the target does not map all sequential zones, the limits
295-
* will not be reliable.
295+
* will not be reliable and we cannot use REQ_OP_ZONE_RESET_ALL.
296296
*/
297-
if (zc.target_nr_seq_zones < zc.total_nr_seq_zones)
297+
if (zc.target_nr_seq_zones < zc.total_nr_seq_zones) {
298298
zlim->reliable_limits = false;
299+
ti->zone_reset_all_supported = false;
300+
}
299301

300302
/*
301303
* If the target maps less sequential zones than the limit values, then
@@ -353,6 +355,14 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q,
353355
for (unsigned int i = 0; i < t->num_targets; i++) {
354356
struct dm_target *ti = dm_table_get_target(t, i);
355357

358+
/*
359+
* Assume that the target can accept REQ_OP_ZONE_RESET_ALL.
360+
* device_get_zone_resource_limits() may adjust this if one of
361+
* the device used by the target does not have all its
362+
* sequential write required zones mapped.
363+
*/
364+
ti->zone_reset_all_supported = true;
365+
356366
if (!ti->type->iterate_devices ||
357367
ti->type->iterate_devices(ti,
358368
device_get_zone_resource_limits, &zlim)) {
@@ -420,3 +430,39 @@ void dm_zone_endio(struct dm_io *io, struct bio *clone)
420430

421431
return;
422432
}
433+
434+
static int dm_zone_need_reset_cb(struct blk_zone *zone, unsigned int idx,
435+
void *data)
436+
{
437+
/*
438+
* For an all-zones reset, ignore conventional, empty, read-only
439+
* and offline zones.
440+
*/
441+
switch (zone->cond) {
442+
case BLK_ZONE_COND_NOT_WP:
443+
case BLK_ZONE_COND_EMPTY:
444+
case BLK_ZONE_COND_READONLY:
445+
case BLK_ZONE_COND_OFFLINE:
446+
return 0;
447+
default:
448+
set_bit(idx, (unsigned long *)data);
449+
return 0;
450+
}
451+
}
452+
453+
int dm_zone_get_reset_bitmap(struct mapped_device *md, struct dm_table *t,
454+
sector_t sector, unsigned int nr_zones,
455+
unsigned long *need_reset)
456+
{
457+
int ret;
458+
459+
ret = dm_blk_do_report_zones(md, t, sector, nr_zones,
460+
dm_zone_need_reset_cb, need_reset);
461+
if (ret != nr_zones) {
462+
DMERR("Get %s zone reset bitmap failed\n",
463+
md->disk->disk_name);
464+
return -EIO;
465+
}
466+
467+
return 0;
468+
}

0 commit comments

Comments
 (0)