Skip to content

Commit f2a38ab

Browse files
johnpgarryaxboe
authored andcommitted
md/raid1: Atomic write support
Set BLK_FEAT_ATOMIC_WRITES_STACKED to enable atomic writes. For an attempt to atomic write to a region which has bad blocks, error the write as we just cannot do this. It is unlikely to find devices which support atomic writes and bad blocks. Reviewed-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20241118105018.1870052-5-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fa6fec8 commit f2a38ab

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/md/raid1.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,21 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
15711571
continue;
15721572
}
15731573
if (is_bad) {
1574-
int good_sectors = first_bad - r1_bio->sector;
1574+
int good_sectors;
1575+
1576+
/*
1577+
* We cannot atomically write this, so just
1578+
* error in that case. It could be possible to
1579+
* atomically write other mirrors, but the
1580+
* complexity of supporting that is not worth
1581+
* the benefit.
1582+
*/
1583+
if (bio->bi_opf & REQ_ATOMIC) {
1584+
error = -EIO;
1585+
goto err_handle;
1586+
}
1587+
1588+
good_sectors = first_bad - r1_bio->sector;
15751589
if (good_sectors < max_sectors)
15761590
max_sectors = good_sectors;
15771591
}
@@ -1657,7 +1671,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
16571671

16581672
mbio->bi_iter.bi_sector = (r1_bio->sector + rdev->data_offset);
16591673
mbio->bi_end_io = raid1_end_write_request;
1660-
mbio->bi_opf = bio_op(bio) | (bio->bi_opf & (REQ_SYNC | REQ_FUA));
1674+
mbio->bi_opf = bio_op(bio) |
1675+
(bio->bi_opf & (REQ_SYNC | REQ_FUA | REQ_ATOMIC));
16611676
if (test_bit(FailFast, &rdev->flags) &&
16621677
!test_bit(WriteMostly, &rdev->flags) &&
16631678
conf->raid_disks - mddev->degraded > 1)
@@ -3224,6 +3239,7 @@ static int raid1_set_limits(struct mddev *mddev)
32243239

32253240
md_init_stacking_limits(&lim);
32263241
lim.max_write_zeroes_sectors = 0;
3242+
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
32273243
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
32283244
if (err) {
32293245
queue_limits_cancel_update(mddev->gendisk->queue);

0 commit comments

Comments
 (0)