Skip to content

Commit a9ad4d8

Browse files
adam900710kdave
authored andcommitted
btrfs: raid56: make error_bitmap update atomic
In the rework of raid56 code, there is very limited concurrency in the endio context. Most of the work is done inside the sectors arrays, which different bios will never touch the same sector. But there is a concurrency here for error_bitmap. Both read and write endio functions need to touch them, and we can have multiple write bios touching the same error bitmap if they all hit some errors. Here we fix the unprotected bitmap operation by going set_bit() in a loop. Since we have a very small ceiling of the sectors (at most 16 sectors), such set_bit() in a loop should be very acceptable. Fixes: 2942a50 ("btrfs: raid56: introduce btrfs_raid_bio::error_bitmap") Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 33e17b3 commit a9ad4d8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/btrfs/raid56.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,12 +1426,20 @@ static void rbio_update_error_bitmap(struct btrfs_raid_bio *rbio, struct bio *bi
14261426
u32 bio_size = 0;
14271427
struct bio_vec *bvec;
14281428
struct bvec_iter_all iter_all;
1429+
int i;
14291430

14301431
bio_for_each_segment_all(bvec, bio, iter_all)
14311432
bio_size += bvec->bv_len;
14321433

1433-
bitmap_set(rbio->error_bitmap, total_sector_nr,
1434-
bio_size >> rbio->bioc->fs_info->sectorsize_bits);
1434+
/*
1435+
* Since we can have multiple bios touching the error_bitmap, we cannot
1436+
* call bitmap_set() without protection.
1437+
*
1438+
* Instead use set_bit() for each bit, as set_bit() itself is atomic.
1439+
*/
1440+
for (i = total_sector_nr; i < total_sector_nr +
1441+
(bio_size >> rbio->bioc->fs_info->sectorsize_bits); i++)
1442+
set_bit(i, rbio->error_bitmap);
14351443
}
14361444

14371445
/* Verify the data sectors at read time. */

0 commit comments

Comments
 (0)