Skip to content

Commit 39a9f1c

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the add_random flag to queue_limits
Move the add_random flag into the queue_limits feature field so that it can be set atomically with the queue frozen. Note that this also removes code from dm to clear the flag based on the underlying devices, which can't be reached as dm devices will always start out without the flag set. 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-16-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bd4a633 commit 39a9f1c

10 files changed

Lines changed: 10 additions & 44 deletions

File tree

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ static const char *const blk_queue_flag_name[] = {
8686
QUEUE_FLAG_NAME(FAIL_IO),
8787
QUEUE_FLAG_NAME(IO_STAT),
8888
QUEUE_FLAG_NAME(NOXMERGES),
89-
QUEUE_FLAG_NAME(ADD_RANDOM),
9089
QUEUE_FLAG_NAME(SYNCHRONOUS),
9190
QUEUE_FLAG_NAME(SAME_FORCE),
9291
QUEUE_FLAG_NAME(INIT_DONE),

block/blk-sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ queue_##name##_store(struct request_queue *q, const char *page, size_t count) \
323323
}
324324

325325
QUEUE_SYSFS_FEATURE(rotational, BLK_FEAT_ROTATIONAL)
326-
QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0);
326+
QUEUE_SYSFS_FEATURE(add_random, BLK_FEAT_ADD_RANDOM)
327327
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
328328
QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0);
329329
#undef QUEUE_SYSFS_BIT_FNS
@@ -561,7 +561,7 @@ static struct queue_sysfs_entry queue_hw_sector_size_entry = {
561561

562562
QUEUE_RW_ENTRY(queue_rotational, "rotational");
563563
QUEUE_RW_ENTRY(queue_iostats, "iostats");
564-
QUEUE_RW_ENTRY(queue_random, "add_random");
564+
QUEUE_RW_ENTRY(queue_add_random, "add_random");
565565
QUEUE_RW_ENTRY(queue_stable_writes, "stable_writes");
566566

567567
#ifdef CONFIG_BLK_WBT
@@ -665,7 +665,7 @@ static struct attribute *queue_attrs[] = {
665665
&queue_nomerges_entry.attr,
666666
&queue_iostats_entry.attr,
667667
&queue_stable_writes_entry.attr,
668-
&queue_random_entry.attr,
668+
&queue_add_random_entry.attr,
669669
&queue_poll_entry.attr,
670670
&queue_wc_entry.attr,
671671
&queue_fua_entry.attr,

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3485,7 +3485,6 @@ static int mtip_block_initialize(struct driver_data *dd)
34853485
goto start_service_thread;
34863486

34873487
/* Set device limits. */
3488-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, dd->queue);
34893488
dma_set_max_seg_size(&dd->pdev->dev, 0x400000);
34903489

34913490
/* Set the capacity of the device in 512 byte sectors. */

drivers/md/dm-table.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,14 +1716,6 @@ static int device_dax_write_cache_enabled(struct dm_target *ti,
17161716
return false;
17171717
}
17181718

1719-
static int device_is_not_random(struct dm_target *ti, struct dm_dev *dev,
1720-
sector_t start, sector_t len, void *data)
1721-
{
1722-
struct request_queue *q = bdev_get_queue(dev->bdev);
1723-
1724-
return !blk_queue_add_random(q);
1725-
}
1726-
17271719
static int device_not_write_zeroes_capable(struct dm_target *ti, struct dm_dev *dev,
17281720
sector_t start, sector_t len, void *data)
17291721
{
@@ -1876,16 +1868,6 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18761868
else
18771869
blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, q);
18781870

1879-
/*
1880-
* Determine whether or not this queue's I/O timings contribute
1881-
* to the entropy pool, Only request-based targets use this.
1882-
* Clear QUEUE_FLAG_ADD_RANDOM if any underlying device does not
1883-
* have it set.
1884-
*/
1885-
if (blk_queue_add_random(q) &&
1886-
dm_table_any_dev_attr(t, device_is_not_random, NULL))
1887-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
1888-
18891871
/*
18901872
* For a zoned target, setup the zones related queue attributes
18911873
* and resources necessary for zone append emulation if necessary.

drivers/mmc/core/queue.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ static struct gendisk *mmc_alloc_disk(struct mmc_queue *mq,
387387
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, mq->queue);
388388
blk_queue_rq_timeout(mq->queue, 60 * HZ);
389389

390-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, mq->queue);
391-
392390
dma_set_max_seg_size(mmc_dev(host), queue_max_segment_size(mq->queue));
393391

394392
INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);

drivers/mtd/mtd_blkdevs.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,6 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
374374
/* Create the request queue */
375375
spin_lock_init(&new->queue_lock);
376376
INIT_LIST_HEAD(&new->rq_list);
377-
378-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, new->rq);
379-
380377
gd->queue = new->rq;
381378

382379
if (new->readonly)

drivers/s390/block/scm_blk.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
439439
.logical_block_size = 1 << 12,
440440
};
441441
unsigned int devindex;
442-
struct request_queue *rq;
443442
int len, ret;
444443

445444
lim.max_segments = min(scmdev->nr_max_block,
@@ -474,9 +473,6 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
474473
ret = PTR_ERR(bdev->gendisk);
475474
goto out_tag;
476475
}
477-
rq = bdev->rq = bdev->gendisk->queue;
478-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, rq);
479-
480476
bdev->gendisk->private_data = scmdev;
481477
bdev->gendisk->fops = &scm_blk_devops;
482478
bdev->gendisk->major = scm_major;

drivers/scsi/scsi_lib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
631631
if (blk_update_request(req, error, bytes))
632632
return true;
633633

634-
// XXX:
635-
if (blk_queue_add_random(q))
634+
if (q->limits.features & BLK_FEAT_ADD_RANDOM)
636635
add_disk_randomness(req->q->disk);
637636

638637
WARN_ON_ONCE(!blk_rq_is_passthrough(req) &&

drivers/scsi/sd.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,7 +3301,6 @@ static void sd_read_block_limits_ext(struct scsi_disk *sdkp)
33013301
static void sd_read_block_characteristics(struct scsi_disk *sdkp,
33023302
struct queue_limits *lim)
33033303
{
3304-
struct request_queue *q = sdkp->disk->queue;
33053304
struct scsi_vpd *vpd;
33063305
u16 rot;
33073306

@@ -3317,10 +3316,8 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp,
33173316
sdkp->zoned = (vpd->data[8] >> 4) & 3;
33183317
rcu_read_unlock();
33193318

3320-
if (rot == 1) {
3321-
lim->features &= ~BLK_FEAT_ROTATIONAL;
3322-
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
3323-
}
3319+
if (rot == 1)
3320+
lim->features &= ~(BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
33243321

33253322
if (!sdkp->first_scan)
33263323
return;
@@ -3599,7 +3596,6 @@ static int sd_revalidate_disk(struct gendisk *disk)
35993596
{
36003597
struct scsi_disk *sdkp = scsi_disk(disk);
36013598
struct scsi_device *sdp = sdkp->device;
3602-
struct request_queue *q = sdkp->disk->queue;
36033599
sector_t old_capacity = sdkp->capacity;
36043600
struct queue_limits lim;
36053601
unsigned char *buffer;
@@ -3646,8 +3642,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
36463642
* cause this to be updated correctly and any device which
36473643
* doesn't support it should be treated as rotational.
36483644
*/
3649-
lim.features |= BLK_FEAT_ROTATIONAL;
3650-
blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
3645+
lim.features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
36513646

36523647
if (scsi_device_supports_vpd(sdp)) {
36533648
sd_read_block_provisioning(sdkp);

include/linux/blkdev.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ enum {
292292

293293
/* rotational device (hard drive or floppy) */
294294
BLK_FEAT_ROTATIONAL = (1u << 2),
295+
296+
/* contributes to the random number pool */
297+
BLK_FEAT_ADD_RANDOM = (1u << 3),
295298
};
296299

297300
/*
@@ -557,7 +560,6 @@ struct request_queue {
557560
#define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */
558561
#define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */
559562
#define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */
560-
#define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */
561563
#define QUEUE_FLAG_SYNCHRONOUS 11 /* always completes in submit context */
562564
#define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
563565
#define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
@@ -591,7 +593,6 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
591593
test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
592594
#define blk_queue_nonrot(q) ((q)->limits.features & BLK_FEAT_ROTATIONAL)
593595
#define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
594-
#define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
595596
#define blk_queue_zone_resetall(q) \
596597
test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags)
597598
#define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)

0 commit comments

Comments
 (0)