@@ -1402,6 +1402,41 @@ static bool dm_table_supports_zoned_model(struct dm_table *t,
return true;
}
+static int device_matches_zone_sectors(struct dm_target *ti, struct dm_dev *dev,
+ sector_t start, sector_t len, void *data)
+{
+ struct request_queue *q = bdev_get_queue(dev->bdev);
+ unsigned int zone_sectors = *data;
+
+ return q && blk_queue_zone_sectors(q) == zone_sectors;
+}
+
+static int validate_hardware_zoned_model(struct dm_table *table,
+ enum blk_zoned_model zoned_model,
+ unsigned int zone_sectors)
+{
+ if (!dm_table_supports_zoned_model(table, zoned_model)) {
+ DMERR("%s: zoned model is inconsistent across all devices",
+ dm_device_name(table->md));
+ return -EINVAL;
+ }
+
+ if (zoned_model != BLK_ZONED_NONE) {
+ /* Check zone size validity and compatibility */
+ if (!zone_sectors || !is_power_of_2(zone_sectors))
+ return -EINVAL;
+
+ if (!ti->type->iterate_devices ||
+ !ti->type->iterate_devices(ti, device_matches_zone_sectors, &zone_sectors)) {
+ DMERR("%s: zone sectors is inconsistent across all devices",
+ dm_device_name(table->md));
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
/*
* Establish the new table's queue_limits and validate them.
*/
@@ -1412,6 +1447,7 @@ int dm_calculate_queue_limits(struct dm_table *table,
struct queue_limits ti_limits;
unsigned i;
enum blk_zoned_model zoned_model = BLK_ZONED_NONE;
+ unsigned int zone_sectors;
blk_set_stacking_limits(limits);
@@ -1432,9 +1468,10 @@ int dm_calculate_queue_limits(struct dm_table *table,
if (zoned_model == BLK_ZONED_NONE && ti_limits.zoned != BLK_ZONED_NONE) {
/*
* After stacking all limits, validate all devices
- * in table support this zoned model.
+ * in table support this zoned model and zone sectors.
*/
zoned_model = ti_limits.zoned;
+ zone_sectors = ti_limits.chunk_sectors;
}
/* Set I/O hints portion of queue limits */
@@ -1464,17 +1501,18 @@ int dm_calculate_queue_limits(struct dm_table *table,
}
/*
- * Verify that the zoned model, as determined before any .io_hints
- * override, is the same across all devices in the table.
+ * Verify that the zoned model and zone sectors, as determined before
+ * any .io_hints override, are the same across all devices in the table.
* - but if limits->zoned is not BLK_ZONED_NONE validate match for it
+ * - simillarly, check all devices conform to limits->chunk_sectors if
+ * .io_hints altered them
*/
if (limits->zoned != BLK_ZONED_NONE)
zoned_model = limits->zoned;
- if (!dm_table_supports_zoned_model(table, zoned_model)) {
- DMERR("%s: zoned model is inconsistent across all devices"
- dm_device_name(table->md));
+ if (limits->chunk_sectors != zone_sectors)
+ zone_sectors = limits->chunk_sectors;
+ if (validate_hardware_zoned_model(table, zoned_model, zone_sectors))
return -EINVAL;
- }
return validate_hardware_logical_block_alignment(table, limits);
}