Skip to content

Commit 6a7e17b

Browse files
johnpgarryaxboe
authored andcommitted
block: Add common atomic writes enable flag
Currently only stacked devices need to explicitly enable atomic writes by setting BLK_FEAT_ATOMIC_WRITES_STACKED flag. This does not work well for device mapper stacking devices, as there many sets of limits are stacked and what is the 'bottom' and 'top' device can swapped. This means that BLK_FEAT_ATOMIC_WRITES_STACKED needs to be set for many queue limits, which is messy. Generalize enabling atomic writes enabling by ensuring that all devices must explicitly set a flag - that includes NVMe, SCSI sd, and md raid. Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Mike Snitzer <snitzer@kernel.org> Link: https://lore.kernel.org/r/20250116170301.474130-2-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 63492a2 commit 6a7e17b

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

block/blk-settings.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
175175
{
176176
unsigned int boundary_sectors;
177177

178+
if (!(lim->features & BLK_FEAT_ATOMIC_WRITES))
179+
goto unsupported;
180+
178181
if (!lim->atomic_write_hw_max)
179182
goto unsupported;
180183

@@ -611,7 +614,7 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
611614
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
612615
struct queue_limits *b, sector_t start)
613616
{
614-
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
617+
if (!(b->features & BLK_FEAT_ATOMIC_WRITES))
615618
goto unsupported;
616619

617620
if (!b->atomic_write_hw_unit_min)
@@ -639,7 +642,6 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
639642
t->atomic_write_hw_unit_max = 0;
640643
t->atomic_write_hw_unit_min = 0;
641644
t->atomic_write_hw_boundary = 0;
642-
t->features &= ~BLK_FEAT_ATOMIC_WRITES_STACKED;
643645
}
644646

645647
/**

drivers/md/raid0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int raid0_set_limits(struct mddev *mddev)
384384
lim.max_write_zeroes_sectors = mddev->chunk_sectors;
385385
lim.io_min = mddev->chunk_sectors << 9;
386386
lim.io_opt = lim.io_min * mddev->raid_disks;
387-
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
387+
lim.features |= BLK_FEAT_ATOMIC_WRITES;
388388
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
389389
if (err) {
390390
queue_limits_cancel_update(mddev->gendisk->queue);

drivers/md/raid1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3217,7 +3217,7 @@ static int raid1_set_limits(struct mddev *mddev)
32173217

32183218
md_init_stacking_limits(&lim);
32193219
lim.max_write_zeroes_sectors = 0;
3220-
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
3220+
lim.features |= BLK_FEAT_ATOMIC_WRITES;
32213221
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
32223222
if (err) {
32233223
queue_limits_cancel_update(mddev->gendisk->queue);

drivers/md/raid10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4018,7 +4018,7 @@ static int raid10_set_queue_limits(struct mddev *mddev)
40184018
lim.max_write_zeroes_sectors = 0;
40194019
lim.io_min = mddev->chunk_sectors << 9;
40204020
lim.io_opt = lim.io_min * raid10_nr_stripes(conf);
4021-
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
4021+
lim.features |= BLK_FEAT_ATOMIC_WRITES;
40224022
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
40234023
if (err) {
40244024
queue_limits_cancel_update(mddev->gendisk->queue);

drivers/nvme/host/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,7 @@ static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns,
20022002
lim->atomic_write_hw_boundary = boundary;
20032003
lim->atomic_write_hw_unit_min = bs;
20042004
lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs);
2005+
lim->features |= BLK_FEAT_ATOMIC_WRITES;
20052006
}
20062007

20072008
static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl)

drivers/scsi/sd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
991991
lim->atomic_write_hw_boundary = 0;
992992
lim->atomic_write_hw_unit_min = unit_min * logical_block_size;
993993
lim->atomic_write_hw_unit_max = unit_max * logical_block_size;
994+
lim->features |= BLK_FEAT_ATOMIC_WRITES;
994995
}
995996

996997
static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,

include/linux/blkdev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ typedef unsigned int __bitwise blk_features_t;
331331
#define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \
332332
((__force blk_features_t)(1u << 15))
333333

334-
/* stacked device can/does support atomic writes */
335-
#define BLK_FEAT_ATOMIC_WRITES_STACKED \
334+
/* atomic writes enabled */
335+
#define BLK_FEAT_ATOMIC_WRITES \
336336
((__force blk_features_t)(1u << 16))
337337

338338
/*

0 commit comments

Comments
 (0)