Skip to content

Commit a8d1b16

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: initialize device's zone info for seeding
When performing seeding on a zoned filesystem it is necessary to initialize each zoned device's btrfs_zoned_device_info structure, otherwise mounting the filesystem will cause a NULL pointer dereference. This was uncovered by fstests' testcase btrfs/163. CC: [email protected] # 5.15+ Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 21e61ec commit a8d1b16

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

fs/btrfs/disk-io.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,9 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
25512551
fs_info->dev_root = root;
25522552
}
25532553
/* Initialize fs_info for all devices in any case */
2554-
btrfs_init_devices_late(fs_info);
2554+
ret = btrfs_init_devices_late(fs_info);
2555+
if (ret)
2556+
goto out;
25552557

25562558
/*
25572559
* This tree can share blocks with some other fs tree during relocation

fs/btrfs/volumes.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7756,10 +7756,11 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
77567756
return ret;
77577757
}
77587758

7759-
void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
7759+
int btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
77607760
{
77617761
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
77627762
struct btrfs_device *device;
7763+
int ret = 0;
77637764

77647765
fs_devices->fs_info = fs_info;
77657766

@@ -7768,12 +7769,18 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
77687769
device->fs_info = fs_info;
77697770

77707771
list_for_each_entry(seed_devs, &fs_devices->seed_list, seed_list) {
7771-
list_for_each_entry(device, &seed_devs->devices, dev_list)
7772+
list_for_each_entry(device, &seed_devs->devices, dev_list) {
77727773
device->fs_info = fs_info;
7774+
ret = btrfs_get_dev_zone_info(device, false);
7775+
if (ret)
7776+
break;
7777+
}
77737778

77747779
seed_devs->fs_info = fs_info;
77757780
}
77767781
mutex_unlock(&fs_devices->device_list_mutex);
7782+
7783+
return ret;
77777784
}
77787785

77797786
static u64 btrfs_dev_stats_value(const struct extent_buffer *eb,

fs/btrfs/volumes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
671671
void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
672672
int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
673673
struct btrfs_ioctl_get_dev_stats *stats);
674-
void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
674+
int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
675675
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
676676
int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
677677
void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);

0 commit comments

Comments
 (0)