Skip to content

Commit 1a02f3a

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the stable_writes flag to queue_limits
Move the stable_writes flag into the queue_limits feature field so that it can be set atomically with the queue frozen. The flag is now inherited by blk_stack_limits, which greatly simplifies the code in dm, and fixed md which previously did not pass on the flag set on lower devices. 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-18-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent cdb2497 commit 1a02f3a

File tree

12 files changed

+29
-77
lines changed

12 files changed

+29
-77
lines changed

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ static const char *const blk_queue_flag_name[] = {
8888
QUEUE_FLAG_NAME(SYNCHRONOUS),
8989
QUEUE_FLAG_NAME(SAME_FORCE),
9090
QUEUE_FLAG_NAME(INIT_DONE),
91-
QUEUE_FLAG_NAME(STABLE_WRITES),
9291
QUEUE_FLAG_NAME(POLL),
9392
QUEUE_FLAG_NAME(DAX),
9493
QUEUE_FLAG_NAME(STATS),

block/blk-sysfs.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -296,37 +296,10 @@ static ssize_t queue_##_name##_store(struct request_queue *q, \
296296
return queue_feature_store(q, page, count, _feature); \
297297
}
298298

299-
#define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \
300-
static ssize_t \
301-
queue_##name##_show(struct request_queue *q, char *page) \
302-
{ \
303-
int bit; \
304-
bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \
305-
return queue_var_show(neg ? !bit : bit, page); \
306-
} \
307-
static ssize_t \
308-
queue_##name##_store(struct request_queue *q, const char *page, size_t count) \
309-
{ \
310-
unsigned long val; \
311-
ssize_t ret; \
312-
ret = queue_var_store(&val, page, count); \
313-
if (ret < 0) \
314-
return ret; \
315-
if (neg) \
316-
val = !val; \
317-
\
318-
if (val) \
319-
blk_queue_flag_set(QUEUE_FLAG_##flag, q); \
320-
else \
321-
blk_queue_flag_clear(QUEUE_FLAG_##flag, q); \
322-
return ret; \
323-
}
324-
325299
QUEUE_SYSFS_FEATURE(rotational, BLK_FEAT_ROTATIONAL)
326300
QUEUE_SYSFS_FEATURE(add_random, BLK_FEAT_ADD_RANDOM)
327301
QUEUE_SYSFS_FEATURE(iostats, BLK_FEAT_IO_STAT)
328-
QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0);
329-
#undef QUEUE_SYSFS_BIT_FNS
302+
QUEUE_SYSFS_FEATURE(stable_writes, BLK_FEAT_STABLE_WRITES);
330303

331304
static ssize_t queue_zoned_show(struct request_queue *q, char *page)
332305
{

drivers/block/drbd/drbd_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,8 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
26982698
*/
26992699
.max_hw_sectors = DRBD_MAX_BIO_SIZE_SAFE >> 8,
27002700
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
2701-
BLK_FEAT_ROTATIONAL,
2701+
BLK_FEAT_ROTATIONAL |
2702+
BLK_FEAT_STABLE_WRITES,
27022703
};
27032704

27042705
device = minor_to_device(minor);
@@ -2737,8 +2738,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
27372738
sprintf(disk->disk_name, "drbd%d", minor);
27382739
disk->private_data = device;
27392740

2740-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
2741-
27422741
device->md_io.page = alloc_page(GFP_KERNEL);
27432742
if (!device->md_io.page)
27442743
goto out_no_io_page;

drivers/block/rbd.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4949,7 +4949,6 @@ static const struct blk_mq_ops rbd_mq_ops = {
49494949
static int rbd_init_disk(struct rbd_device *rbd_dev)
49504950
{
49514951
struct gendisk *disk;
4952-
struct request_queue *q;
49534952
unsigned int objset_bytes =
49544953
rbd_dev->layout.object_size * rbd_dev->layout.stripe_count;
49554954
struct queue_limits lim = {
@@ -4979,12 +4978,14 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
49794978
lim.max_write_zeroes_sectors = objset_bytes >> SECTOR_SHIFT;
49804979
}
49814980

4981+
if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC))
4982+
lim.features |= BLK_FEAT_STABLE_WRITES;
4983+
49824984
disk = blk_mq_alloc_disk(&rbd_dev->tag_set, &lim, rbd_dev);
49834985
if (IS_ERR(disk)) {
49844986
err = PTR_ERR(disk);
49854987
goto out_tag_set;
49864988
}
4987-
q = disk->queue;
49884989

49894990
snprintf(disk->disk_name, sizeof(disk->disk_name), RBD_DRV_NAME "%d",
49904991
rbd_dev->dev_id);
@@ -4996,10 +4997,6 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
49964997
disk->minors = RBD_MINORS_PER_MAJOR;
49974998
disk->fops = &rbd_bd_ops;
49984999
disk->private_data = rbd_dev;
4999-
5000-
if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC))
5001-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q);
5002-
50035000
rbd_dev->disk = disk;
50045001

50055002
return 0;

drivers/block/zram/zram_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,7 @@ static int zram_add(void)
22082208
#if ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE
22092209
.max_write_zeroes_sectors = UINT_MAX,
22102210
#endif
2211+
.features = BLK_FEAT_STABLE_WRITES,
22112212
};
22122213
struct zram *zram;
22132214
int ret, device_id;
@@ -2246,7 +2247,6 @@ static int zram_add(void)
22462247
/* Actual capacity set using sysfs (/sys/block/zram<id>/disksize */
22472248
set_capacity(zram->disk, 0);
22482249
blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, zram->disk->queue);
2249-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, zram->disk->queue);
22502250
ret = device_add_disk(NULL, zram->disk, zram_disk_groups);
22512251
if (ret)
22522252
goto out_cleanup_disk;

drivers/md/dm-table.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,13 +1819,6 @@ static bool dm_table_supports_secure_erase(struct dm_table *t)
18191819
return true;
18201820
}
18211821

1822-
static int device_requires_stable_pages(struct dm_target *ti,
1823-
struct dm_dev *dev, sector_t start,
1824-
sector_t len, void *data)
1825-
{
1826-
return bdev_stable_writes(dev->bdev);
1827-
}
1828-
18291822
int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18301823
struct queue_limits *limits)
18311824
{
@@ -1862,18 +1855,6 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18621855
if (dm_table_any_dev_attr(t, device_dax_write_cache_enabled, NULL))
18631856
dax_write_cache(t->md->dax_dev, true);
18641857

1865-
/*
1866-
* Some devices don't use blk_integrity but still want stable pages
1867-
* because they do their own checksumming.
1868-
* If any underlying device requires stable pages, a table must require
1869-
* them as well. Only targets that support iterate_devices are considered:
1870-
* don't want error, zero, etc to require stable pages.
1871-
*/
1872-
if (dm_table_any_dev_attr(t, device_requires_stable_pages, NULL))
1873-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q);
1874-
else
1875-
blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, q);
1876-
18771858
/*
18781859
* For a zoned target, setup the zones related queue attributes
18791860
* and resources necessary for zone append emulation if necessary.

drivers/md/raid5.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7082,12 +7082,14 @@ raid5_store_skip_copy(struct mddev *mddev, const char *page, size_t len)
70827082
err = -ENODEV;
70837083
else if (new != conf->skip_copy) {
70847084
struct request_queue *q = mddev->gendisk->queue;
7085+
struct queue_limits lim = queue_limits_start_update(q);
70857086

70867087
conf->skip_copy = new;
70877088
if (new)
7088-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q);
7089+
lim.features |= BLK_FEAT_STABLE_WRITES;
70897090
else
7090-
blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, q);
7091+
lim.features &= ~BLK_FEAT_STABLE_WRITES;
7092+
err = queue_limits_commit_update(q, &lim);
70917093
}
70927094
mddev_unlock_and_resume(mddev);
70937095
return err ?: len;

drivers/mmc/core/queue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,14 @@ static struct gendisk *mmc_alloc_disk(struct mmc_queue *mq,
378378
lim.max_segments = host->max_segs;
379379
}
380380

381+
if (mmc_host_is_spi(host) && host->use_spi_crc)
382+
lim.features |= BLK_FEAT_STABLE_WRITES;
383+
381384
disk = blk_mq_alloc_disk(&mq->tag_set, &lim, mq);
382385
if (IS_ERR(disk))
383386
return disk;
384387
mq->queue = disk->queue;
385388

386-
if (mmc_host_is_spi(host) && host->use_spi_crc)
387-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, mq->queue);
388389
blk_queue_rq_timeout(mq->queue, 60 * HZ);
389390

390391
dma_set_max_seg_size(mmc_dev(host), queue_max_segment_size(mq->queue));

drivers/nvme/host/core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,7 @@ static void nvme_ns_add_to_ctrl_list(struct nvme_ns *ns)
37243724

37253725
static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
37263726
{
3727+
struct queue_limits lim = { };
37273728
struct nvme_ns *ns;
37283729
struct gendisk *disk;
37293730
int node = ctrl->numa_node;
@@ -3732,7 +3733,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
37323733
if (!ns)
37333734
return;
37343735

3735-
disk = blk_mq_alloc_disk(ctrl->tagset, NULL, ns);
3736+
if (ctrl->opts && ctrl->opts->data_digest)
3737+
lim.features |= BLK_FEAT_STABLE_WRITES;
3738+
3739+
disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns);
37363740
if (IS_ERR(disk))
37373741
goto out_free_ns;
37383742
disk->fops = &nvme_bdev_ops;
@@ -3741,9 +3745,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
37413745
ns->disk = disk;
37423746
ns->queue = disk->queue;
37433747

3744-
if (ctrl->opts && ctrl->opts->data_digest)
3745-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue);
3746-
37473748
if (ctrl->ops->supports_pci_p2pdma &&
37483749
ctrl->ops->supports_pci_p2pdma(ctrl))
37493750
blk_queue_flag_set(QUEUE_FLAG_PCI_P2PDMA, ns->queue);

drivers/nvme/host/multipath.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,6 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
868868
nvme_mpath_set_live(ns);
869869
}
870870

871-
if (test_bit(QUEUE_FLAG_STABLE_WRITES, &ns->queue->queue_flags) &&
872-
ns->head->disk)
873-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES,
874-
ns->head->disk->queue);
875871
#ifdef CONFIG_BLK_DEV_ZONED
876872
if (blk_queue_is_zoned(ns->queue) && ns->head->disk)
877873
ns->head->disk->nr_zones = ns->disk->nr_zones;

0 commit comments

Comments
 (0)