Skip to content

Commit 7f91ccd

Browse files
damien-lemoalaxboe
authored andcommitted
dm: Call dm_revalidate_zones() after setting the queue limits
dm_revalidate_zones() is called from dm_set_zone_restrictions() when the mapped device queue limits are not yet set. However, dm_revalidate_zones() calls blk_revalidate_disk_zones() and this function consults and modifies the mapped device queue limits. Thus, currently, blk_revalidate_disk_zones() operates on limits that are not yet initialized. Fix this by moving the call to dm_revalidate_zones() out of dm_set_zone_restrictions() and into dm_table_set_restrictions() after executing queue_limits_set(). To further cleanup dm_set_zones_restrictions(), the message about the type of zone append (native or emulated) is also moved inside dm_revalidate_zones(). Fixes: 1c0e720 ("dm: use queue_limits_set") Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Benjamin Marzinski <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e21d12c commit 7f91ccd

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

drivers/md/dm-table.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,10 +1921,7 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
19211921
dm_table_any_dev_attr(t, device_is_not_random, NULL))
19221922
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
19231923

1924-
/*
1925-
* For a zoned target, setup the zones related queue attributes
1926-
* and resources necessary for zone append emulation if necessary.
1927-
*/
1924+
/* For a zoned table, setup the zone related queue attributes. */
19281925
if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && limits->zoned) {
19291926
r = dm_set_zones_restrictions(t, q, limits);
19301927
if (r)
@@ -1935,6 +1932,16 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
19351932
if (r)
19361933
return r;
19371934

1935+
/*
1936+
* Now that the limits are set, check the zones mapped by the table
1937+
* and setup the resources for zone append emulation if necessary.
1938+
*/
1939+
if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && limits->zoned) {
1940+
r = dm_revalidate_zones(t, q);
1941+
if (r)
1942+
return r;
1943+
}
1944+
19381945
dm_update_crypto_profile(q, t);
19391946

19401947
/*

drivers/md/dm-zone.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,22 @@ static int dm_check_zoned_cb(struct blk_zone *zone, unsigned int idx,
166166
* blk_revalidate_disk_zones() function here as the mapped device is suspended
167167
* (this is called from __bind() context).
168168
*/
169-
static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t)
169+
int dm_revalidate_zones(struct dm_table *t, struct request_queue *q)
170170
{
171+
struct mapped_device *md = t->md;
171172
struct gendisk *disk = md->disk;
172173
int ret;
173174

175+
if (!get_capacity(disk))
176+
return 0;
177+
174178
/* Revalidate only if something changed. */
175-
if (!disk->nr_zones || disk->nr_zones != md->nr_zones)
179+
if (!disk->nr_zones || disk->nr_zones != md->nr_zones) {
180+
DMINFO("%s using %s zone append",
181+
disk->disk_name,
182+
queue_emulates_zone_append(q) ? "emulated" : "native");
176183
md->nr_zones = 0;
184+
}
177185

178186
if (md->nr_zones)
179187
return 0;
@@ -240,9 +248,6 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q,
240248
lim->max_zone_append_sectors = 0;
241249
}
242250

243-
if (!get_capacity(md->disk))
244-
return 0;
245-
246251
/*
247252
* Count conventional zones to check that the mapped device will indeed
248253
* have sequential write required zones.
@@ -269,16 +274,6 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q,
269274
return 0;
270275
}
271276

272-
if (!md->disk->nr_zones) {
273-
DMINFO("%s using %s zone append",
274-
md->disk->disk_name,
275-
queue_emulates_zone_append(q) ? "emulated" : "native");
276-
}
277-
278-
ret = dm_revalidate_zones(md, t);
279-
if (ret < 0)
280-
return ret;
281-
282277
if (!static_key_enabled(&zoned_enabled.key))
283278
static_branch_enable(&zoned_enabled);
284279
return 0;

drivers/md/dm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
103103
*/
104104
int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q,
105105
struct queue_limits *lim);
106+
int dm_revalidate_zones(struct dm_table *t, struct request_queue *q);
106107
void dm_zone_endio(struct dm_io *io, struct bio *clone);
107108
#ifdef CONFIG_BLK_DEV_ZONED
108109
int dm_blk_report_zones(struct gendisk *disk, sector_t sector,

0 commit comments

Comments
 (0)