Skip to content

Commit a1d9b4f

Browse files
johnpgarryaxboe
authored andcommitted
md/raid10: 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 <[email protected]> Signed-off-by: John Garry <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f2a38ab commit a1d9b4f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/md/raid10.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
12551255
const enum req_op op = bio_op(bio);
12561256
const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
12571257
const blk_opf_t do_fua = bio->bi_opf & REQ_FUA;
1258+
const blk_opf_t do_atomic = bio->bi_opf & REQ_ATOMIC;
12581259
unsigned long flags;
12591260
struct r10conf *conf = mddev->private;
12601261
struct md_rdev *rdev;
@@ -1273,7 +1274,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
12731274
mbio->bi_iter.bi_sector = (r10_bio->devs[n_copy].addr +
12741275
choose_data_offset(r10_bio, rdev));
12751276
mbio->bi_end_io = raid10_end_write_request;
1276-
mbio->bi_opf = op | do_sync | do_fua;
1277+
mbio->bi_opf = op | do_sync | do_fua | do_atomic;
12771278
if (!replacement && test_bit(FailFast,
12781279
&conf->mirrors[devnum].rdev->flags)
12791280
&& enough(conf, devnum))
@@ -1468,7 +1469,21 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
14681469
continue;
14691470
}
14701471
if (is_bad) {
1471-
int good_sectors = first_bad - dev_sector;
1472+
int good_sectors;
1473+
1474+
/*
1475+
* We cannot atomically write this, so just
1476+
* error in that case. It could be possible to
1477+
* atomically write other mirrors, but the
1478+
* complexity of supporting that is not worth
1479+
* the benefit.
1480+
*/
1481+
if (bio->bi_opf & REQ_ATOMIC) {
1482+
error = -EIO;
1483+
goto err_handle;
1484+
}
1485+
1486+
good_sectors = first_bad - dev_sector;
14721487
if (good_sectors < max_sectors)
14731488
max_sectors = good_sectors;
14741489
}
@@ -4025,6 +4040,7 @@ static int raid10_set_queue_limits(struct mddev *mddev)
40254040
lim.max_write_zeroes_sectors = 0;
40264041
lim.io_min = mddev->chunk_sectors << 9;
40274042
lim.io_opt = lim.io_min * raid10_nr_stripes(conf);
4043+
lim.features |= BLK_FEAT_ATOMIC_WRITES_STACKED;
40284044
err = mddev_stack_rdev_limits(mddev, &lim, MDDEV_STACK_INTEGRITY);
40294045
if (err) {
40304046
queue_limits_cancel_update(mddev->gendisk->queue);

0 commit comments

Comments
 (0)