Skip to content

Commit 8bbfa36

Browse files
KangNing Liaoadam900710
authored andcommitted
btrfs: protect sb_write_pointer() with invalidate lock
sb_write_pointer() reads the super block from the block device page cache using read_cache_page_gfp(). This has the same race with BLKBSZSET as the one fixed by commit 3f29d66 ("btrfs: sync read disk super and set block size"). Take the mapping invalidate lock around read_cache_page_gfp() to serialize the read against block size changes. Signed-off-by: KangNing Liao <lkangn.kernel@gmail.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
1 parent 7915e1c commit 8bbfa36

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/btrfs/zoned.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
131131
u64 bytenr = ALIGN_DOWN(zone_end, BTRFS_SUPER_INFO_SIZE) -
132132
BTRFS_SUPER_INFO_SIZE;
133133

134+
filemap_invalidate_lock(mapping);
134135
page[i] = read_cache_page_gfp(mapping,
135136
bytenr >> PAGE_SHIFT, GFP_NOFS);
137+
filemap_invalidate_unlock(mapping);
136138
if (IS_ERR(page[i])) {
137139
if (i == 1)
138140
btrfs_release_disk_super(super[0]);

0 commit comments

Comments
 (0)