Skip to content

Commit bd4a633

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the nonrot flag to queue_limits
Move the nonrot flag into the queue_limits feature field so that it can be set atomically with the queue frozen. Use the chance to switch to defaulting to non-rotational and require the driver to opt into rotational, which matches the polarity of the sysfs interface. For the z2ram, ps3vram, 2x memstick, ubiblock and dcssblk the new rotational flag is not set as they clearly are not rotational despite this being a behavior change. There are some other drivers that unconditionally set the rotational flag to keep the existing behavior as they arguably can be used on rotational devices even if that is probably not their main use today (e.g. virtio_blk and drbd). The flag is automatically inherited in blk_stack_limits matching the existing behavior in dm and md. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240617060532.127975-15-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1122c0c commit bd4a633

41 files changed

Lines changed: 83 additions & 88 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/m68k/emu/nfblock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
9898
{
9999
struct queue_limits lim = {
100100
.logical_block_size = bsize,
101+
.features = BLK_FEAT_ROTATIONAL,
101102
};
102103
struct nfhd_device *dev;
103104
int dev_id = id - NFHD_DEV_OFFSET;

arch/um/drivers/ubd_kern.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,6 @@ static int ubd_add(int n, char **error_out)
882882
goto out_cleanup_tags;
883883
}
884884

885-
blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
886885
disk->major = UBD_MAJOR;
887886
disk->first_minor = n << UBD_SHIFT;
888887
disk->minors = 1 << UBD_SHIFT;

arch/xtensa/platforms/iss/simdisk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ static const struct proc_ops simdisk_proc_ops = {
263263
static int __init simdisk_setup(struct simdisk *dev, int which,
264264
struct proc_dir_entry *procdir)
265265
{
266+
struct queue_limits lim = {
267+
.features = BLK_FEAT_ROTATIONAL,
268+
};
266269
char tmp[2] = { '0' + which, 0 };
267270
int err;
268271

@@ -271,7 +274,7 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
271274
spin_lock_init(&dev->lock);
272275
dev->users = 0;
273276

274-
dev->gd = blk_alloc_disk(NULL, NUMA_NO_NODE);
277+
dev->gd = blk_alloc_disk(&lim, NUMA_NO_NODE);
275278
if (IS_ERR(dev->gd)) {
276279
err = PTR_ERR(dev->gd);
277280
goto out;

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static const char *const blk_queue_flag_name[] = {
8484
QUEUE_FLAG_NAME(NOMERGES),
8585
QUEUE_FLAG_NAME(SAME_COMP),
8686
QUEUE_FLAG_NAME(FAIL_IO),
87-
QUEUE_FLAG_NAME(NONROT),
8887
QUEUE_FLAG_NAME(IO_STAT),
8988
QUEUE_FLAG_NAME(NOXMERGES),
9089
QUEUE_FLAG_NAME(ADD_RANDOM),

block/blk-sysfs.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,39 @@ static ssize_t queue_dma_alignment_show(struct request_queue *q, char *page)
263263
return queue_var_show(queue_dma_alignment(q), page);
264264
}
265265

266+
static ssize_t queue_feature_store(struct request_queue *q, const char *page,
267+
size_t count, unsigned int feature)
268+
{
269+
struct queue_limits lim;
270+
unsigned long val;
271+
ssize_t ret;
272+
273+
ret = queue_var_store(&val, page, count);
274+
if (ret < 0)
275+
return ret;
276+
277+
lim = queue_limits_start_update(q);
278+
if (val)
279+
lim.features |= feature;
280+
else
281+
lim.features &= ~feature;
282+
ret = queue_limits_commit_update(q, &lim);
283+
if (ret)
284+
return ret;
285+
return count;
286+
}
287+
288+
#define QUEUE_SYSFS_FEATURE(_name, _feature) \
289+
static ssize_t queue_##_name##_show(struct request_queue *q, char *page) \
290+
{ \
291+
return sprintf(page, "%u\n", !!(q->limits.features & _feature)); \
292+
} \
293+
static ssize_t queue_##_name##_store(struct request_queue *q, \
294+
const char *page, size_t count) \
295+
{ \
296+
return queue_feature_store(q, page, count, _feature); \
297+
}
298+
266299
#define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \
267300
static ssize_t \
268301
queue_##name##_show(struct request_queue *q, char *page) \
@@ -289,7 +322,7 @@ queue_##name##_store(struct request_queue *q, const char *page, size_t count) \
289322
return ret; \
290323
}
291324

292-
QUEUE_SYSFS_BIT_FNS(nonrot, NONROT, 1);
325+
QUEUE_SYSFS_FEATURE(rotational, BLK_FEAT_ROTATIONAL)
293326
QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0);
294327
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
295328
QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0);
@@ -526,7 +559,7 @@ static struct queue_sysfs_entry queue_hw_sector_size_entry = {
526559
.show = queue_logical_block_size_show,
527560
};
528561

529-
QUEUE_RW_ENTRY(queue_nonrot, "rotational");
562+
QUEUE_RW_ENTRY(queue_rotational, "rotational");
530563
QUEUE_RW_ENTRY(queue_iostats, "iostats");
531564
QUEUE_RW_ENTRY(queue_random, "add_random");
532565
QUEUE_RW_ENTRY(queue_stable_writes, "stable_writes");
@@ -624,7 +657,7 @@ static struct attribute *queue_attrs[] = {
624657
&queue_write_zeroes_max_entry.attr,
625658
&queue_zone_append_max_entry.attr,
626659
&queue_zone_write_granularity_entry.attr,
627-
&queue_nonrot_entry.attr,
660+
&queue_rotational_entry.attr,
628661
&queue_zoned_entry.attr,
629662
&queue_nr_zones_entry.attr,
630663
&queue_max_open_zones_entry.attr,

drivers/block/amiflop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,10 +1776,13 @@ static const struct blk_mq_ops amiflop_mq_ops = {
17761776

17771777
static int fd_alloc_disk(int drive, int system)
17781778
{
1779+
struct queue_limits lim = {
1780+
.features = BLK_FEAT_ROTATIONAL,
1781+
};
17791782
struct gendisk *disk;
17801783
int err;
17811784

1782-
disk = blk_mq_alloc_disk(&unit[drive].tag_set, NULL, NULL);
1785+
disk = blk_mq_alloc_disk(&unit[drive].tag_set, &lim, NULL);
17831786
if (IS_ERR(disk))
17841787
return PTR_ERR(disk);
17851788

drivers/block/aoe/aoeblk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ aoeblk_gdalloc(void *vp)
337337
struct queue_limits lim = {
338338
.max_hw_sectors = aoe_maxsectors,
339339
.io_opt = SZ_2M,
340+
.features = BLK_FEAT_ROTATIONAL,
340341
};
341342
ulong flags;
342343
int late = 0;

drivers/block/ataflop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,9 +1992,12 @@ static const struct blk_mq_ops ataflop_mq_ops = {
19921992

19931993
static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
19941994
{
1995+
struct queue_limits lim = {
1996+
.features = BLK_FEAT_ROTATIONAL,
1997+
};
19951998
struct gendisk *disk;
19961999

1997-
disk = blk_mq_alloc_disk(&unit[drive].tag_set, NULL, NULL);
2000+
disk = blk_mq_alloc_disk(&unit[drive].tag_set, &lim, NULL);
19982001
if (IS_ERR(disk))
19992002
return PTR_ERR(disk);
20002003

drivers/block/brd.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ static int brd_alloc(int i)
366366
strscpy(disk->disk_name, buf, DISK_NAME_LEN);
367367
set_capacity(disk, rd_size * 2);
368368

369-
/* Tell the block layer that this is not a rotational device */
370-
blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
371369
blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, disk->queue);
372370
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, disk->queue);
373371
err = add_disk(disk);

drivers/block/drbd/drbd_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,8 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
26972697
* connect.
26982698
*/
26992699
.max_hw_sectors = DRBD_MAX_BIO_SIZE_SAFE >> 8,
2700-
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA,
2700+
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
2701+
BLK_FEAT_ROTATIONAL,
27012702
};
27022703

27032704
device = minor_to_device(minor);

0 commit comments

Comments
 (0)