Skip to content

Commit 911773f

Browse files
committed
block: Add common atomic writes enable flag
JIRA: https://issues.redhat.com/browse/RHEL-73514 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> (cherry picked from commit 6a7e17b) Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
1 parent 0b93b92 commit 911773f

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
@@ -176,6 +176,9 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
176176
{
177177
unsigned int boundary_sectors;
178178

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

@@ -589,7 +592,7 @@ static bool blk_stack_atomic_writes_head(struct queue_limits *t,
589592
static void blk_stack_atomic_writes_limits(struct queue_limits *t,
590593
struct queue_limits *b, sector_t start)
591594
{
592-
if (!(t->features & BLK_FEAT_ATOMIC_WRITES_STACKED))
595+
if (!(b->features & BLK_FEAT_ATOMIC_WRITES))
593596
goto unsupported;
594597

595598
if (!b->atomic_write_unit_min)
@@ -617,7 +620,6 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
617620
t->atomic_write_hw_unit_max = 0;
618621
t->atomic_write_hw_unit_min = 0;
619622
t->atomic_write_hw_boundary = 0;
620-
t->features &= ~BLK_FEAT_ATOMIC_WRITES_STACKED;
621623
}
622624

623625
/**

drivers/md/raid0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int raid0_set_limits(struct mddev *mddev)
389389
lim.max_write_zeroes_sectors = mddev->chunk_sectors;
390390
lim.io_min = mddev->chunk_sectors << 9;
391391
lim.io_opt = lim.io_min * mddev->raid_disks;
392-
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
392+
lim.features |= BLK_FEAT_ATOMIC_WRITES;
393393
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
394394
if (err)
395395
return err;

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
return err;

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
return err;

drivers/nvme/host/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,7 @@ static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns,
19861986
lim->atomic_write_hw_boundary = boundary;
19871987
lim->atomic_write_hw_unit_min = bs;
19881988
lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs);
1989+
lim->features |= BLK_FEAT_ATOMIC_WRITES;
19891990
}
19901991

19911992
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
@@ -997,6 +997,7 @@ static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
997997
lim->atomic_write_hw_boundary = 0;
998998
lim->atomic_write_hw_unit_min = unit_min * logical_block_size;
999999
lim->atomic_write_hw_unit_max = unit_max * logical_block_size;
1000+
lim->features |= BLK_FEAT_ATOMIC_WRITES;
10001001
}
10011002

10021003
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
@@ -338,8 +338,8 @@ typedef unsigned int __bitwise blk_features_t;
338338
#define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \
339339
((__force blk_features_t)(1u << 15))
340340

341-
/* stacked device can/does support atomic writes */
342-
#define BLK_FEAT_ATOMIC_WRITES_STACKED \
341+
/* atomic writes enabled */
342+
#define BLK_FEAT_ATOMIC_WRITES \
343343
((__force blk_features_t)(1u << 16))
344344

345345
/*

0 commit comments

Comments
 (0)