Skip to content

Commit 46669e8

Browse files
committed
md/raid1: fix missing bitmap update w/o WriteMostly devices
commit [1] causes missing bitmap updates when there isn't any WriteMostly devices. Detailed steps to reproduce by Norbert (which somehow didn't make to lore): # setup md10 (raid1) with two drives (1 GByte sparse files) dd if=/dev/zero of=disk1 bs=1024k seek=1024 count=0 dd if=/dev/zero of=disk2 bs=1024k seek=1024 count=0 losetup /dev/loop11 disk1 losetup /dev/loop12 disk2 mdadm --create /dev/md10 --level=1 --raid-devices=2 /dev/loop11 /dev/loop12 # add bitmap (aka write-intent log) mdadm /dev/md10 --grow --bitmap=internal echo check > /sys/block/md10/md/sync_action root:# cat /sys/block/md10/md/mismatch_cnt 0 root:# # remove member drive disk2 (loop12) mdadm /dev/md10 -f loop12 ; mdadm /dev/md10 -r loop12 # modify degraded md device dd if=/dev/urandom of=/dev/md10 bs=512 count=1 # no blocks recorded as out of sync on the remaining member disk1/loop11 root:# mdadm -X /dev/loop11 | grep Bitmap Bitmap : 16 bits (chunks), 0 dirty (0.0%) root:# # re-add disk2, nothing synced because of empty bitmap mdadm /dev/md10 --re-add /dev/loop12 # check integrity again echo check > /sys/block/md10/md/sync_action # disk1 and disk2 are no longer in sync, reads return differend data root:# cat /sys/block/md10/md/mismatch_cnt 128 root:# # clean up mdadm -S /dev/md10 losetup -d /dev/loop11 losetup -d /dev/loop12 rm disk1 disk2 Fix this by moving the WriteMostly check to the if condition for alloc_behind_master_bio(). [1] commit fd3b697 ("md/raid1: only allocate write behind bio for WriteMostly device") Fixes: fd3b697 ("md/raid1: only allocate write behind bio for WriteMostly device") Cc: [email protected] # v5.12+ Cc: Guoqing Jiang <[email protected]> Cc: Jens Axboe <[email protected]> Reported-by: Norbert Warmuth <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 87959fa commit 46669e8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/md/raid1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,12 +1496,13 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
14961496
if (!r1_bio->bios[i])
14971497
continue;
14981498

1499-
if (first_clone && test_bit(WriteMostly, &rdev->flags)) {
1499+
if (first_clone) {
15001500
/* do behind I/O ?
15011501
* Not if there are too many, or cannot
15021502
* allocate memory, or a reader on WriteMostly
15031503
* is waiting for behind writes to flush */
15041504
if (bitmap &&
1505+
test_bit(WriteMostly, &rdev->flags) &&
15051506
(atomic_read(&bitmap->behind_writes)
15061507
< mddev->bitmap_info.max_write_behind) &&
15071508
!waitqueue_active(&bitmap->behind_wait)) {

0 commit comments

Comments
 (0)