]> www.infradead.org Git - users/griffoul/linux.git/commitdiff
md/raid1: fix data lost for writemostly rdev
authorYu Kuai <yukuai3@huawei.com>
Wed, 3 Sep 2025 01:41:40 +0000 (09:41 +0800)
committerYu Kuai <yukuai3@huawei.com>
Thu, 4 Sep 2025 16:30:04 +0000 (00:30 +0800)
If writemostly is enabled, alloc_behind_master_bio() will allocate a new
bio for rdev, with bi_opf set to 0. Later, raid1_write_request() will
clone from this bio, hence bi_opf is still 0 for the cloned bio. Submit
this cloned bio will end up to be read, causing write data lost.

Fix this problem by inheriting bi_opf from original bio for
behind_mast_bio.

Fixes: e879a0d9cb08 ("md/raid1,raid10: don't ignore IO flags")
Reported-and-tested-by: Ian Dall <ian@beware.dropbear.id.au>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220507
Link: https://lore.kernel.org/linux-raid/20250903014140.3690499-1-yukuai1@huaweicloud.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Li Nan <linan122@huawei.com>
drivers/md/raid1.c

index 408c263983215e0ae1ba9e96095e07d23988e3ec..bf44878ec640e551c18b62e91929c81fa2602526 100644 (file)
@@ -1225,7 +1225,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio,
        int i = 0;
        struct bio *behind_bio = NULL;
 
-       behind_bio = bio_alloc_bioset(NULL, vcnt, 0, GFP_NOIO,
+       behind_bio = bio_alloc_bioset(NULL, vcnt, bio->bi_opf, GFP_NOIO,
                                      &r1_bio->mddev->bio_set);
 
        /* discard op, we don't support writezero/writesame yet */