Commit bd4a633b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20240617060532.127975-15-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 1122c0c1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
{
	struct queue_limits lim = {
		.logical_block_size	= bsize,
		.features		= BLK_FEAT_ROTATIONAL,
	};
	struct nfhd_device *dev;
	int dev_id = id - NFHD_DEV_OFFSET;
+0 −1
Original line number Diff line number Diff line
@@ -882,7 +882,6 @@ static int ubd_add(int n, char **error_out)
		goto out_cleanup_tags;
	}

	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
	disk->major = UBD_MAJOR;
	disk->first_minor = n << UBD_SHIFT;
	disk->minors = 1 << UBD_SHIFT;
+4 −1
Original line number Diff line number Diff line
@@ -263,6 +263,9 @@ static const struct proc_ops simdisk_proc_ops = {
static int __init simdisk_setup(struct simdisk *dev, int which,
		struct proc_dir_entry *procdir)
{
	struct queue_limits lim = {
		.features		= BLK_FEAT_ROTATIONAL,
	};
	char tmp[2] = { '0' + which, 0 };
	int err;

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

	dev->gd = blk_alloc_disk(NULL, NUMA_NO_NODE);
	dev->gd = blk_alloc_disk(&lim, NUMA_NO_NODE);
	if (IS_ERR(dev->gd)) {
		err = PTR_ERR(dev->gd);
		goto out;
+0 −1
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ static const char *const blk_queue_flag_name[] = {
	QUEUE_FLAG_NAME(NOMERGES),
	QUEUE_FLAG_NAME(SAME_COMP),
	QUEUE_FLAG_NAME(FAIL_IO),
	QUEUE_FLAG_NAME(NONROT),
	QUEUE_FLAG_NAME(IO_STAT),
	QUEUE_FLAG_NAME(NOXMERGES),
	QUEUE_FLAG_NAME(ADD_RANDOM),
+36 −3
Original line number Diff line number Diff line
@@ -263,6 +263,39 @@ static ssize_t queue_dma_alignment_show(struct request_queue *q, char *page)
	return queue_var_show(queue_dma_alignment(q), page);
}

static ssize_t queue_feature_store(struct request_queue *q, const char *page,
		size_t count, unsigned int feature)
{
	struct queue_limits lim;
	unsigned long val;
	ssize_t ret;

	ret = queue_var_store(&val, page, count);
	if (ret < 0)
		return ret;

	lim = queue_limits_start_update(q);
	if (val)
		lim.features |= feature;
	else
		lim.features &= ~feature;
	ret = queue_limits_commit_update(q, &lim);
	if (ret)
		return ret;
	return count;
}

#define QUEUE_SYSFS_FEATURE(_name, _feature)				 \
static ssize_t queue_##_name##_show(struct request_queue *q, char *page) \
{									 \
	return sprintf(page, "%u\n", !!(q->limits.features & _feature)); \
}									 \
static ssize_t queue_##_name##_store(struct request_queue *q,		 \
		const char *page, size_t count)				 \
{									 \
	return queue_feature_store(q, page, count, _feature);		 \
}

#define QUEUE_SYSFS_BIT_FNS(name, flag, neg)				\
static ssize_t								\
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) \
	return ret;							\
}

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

QUEUE_RW_ENTRY(queue_nonrot, "rotational");
QUEUE_RW_ENTRY(queue_rotational, "rotational");
QUEUE_RW_ENTRY(queue_iostats, "iostats");
QUEUE_RW_ENTRY(queue_random, "add_random");
QUEUE_RW_ENTRY(queue_stable_writes, "stable_writes");
@@ -624,7 +657,7 @@ static struct attribute *queue_attrs[] = {
	&queue_write_zeroes_max_entry.attr,
	&queue_zone_append_max_entry.attr,
	&queue_zone_write_granularity_entry.attr,
	&queue_nonrot_entry.attr,
	&queue_rotational_entry.attr,
	&queue_zoned_entry.attr,
	&queue_nr_zones_entry.attr,
	&queue_max_open_zones_entry.attr,
Loading