btrfs: zoned: initialize device's zone info for seeding
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Fri, 4 Nov 2022 14:12:34 +0000 (07:12 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 7 Nov 2022 13:35:24 +0000 (14:35 +0100)
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: stable@vger.kernel.org # 5.15+
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index 4b28263c3d3296ef6513fe4f7ce2b67d14dbb124..d99bf7c6461108bbb995f625045964bacc1a0234 100644 (file)
@@ -2551,7 +2551,9 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
                fs_info->dev_root = root;
        }
        /* Initialize fs_info for all devices in any case */
-       btrfs_init_devices_late(fs_info);
+       ret = btrfs_init_devices_late(fs_info);
+       if (ret)
+               goto out;
 
        /*
         * This tree can share blocks with some other fs tree during relocation
index 3cb968ede6759b9b8d25b5e741dd55ce5ab47b88..635f45f1a2ef80508f850ee593b8375786d1fc25 100644 (file)
@@ -7756,10 +7756,11 @@ error:
        return ret;
 }
 
-void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
+int btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
 {
        struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
        struct btrfs_device *device;
+       int ret = 0;
 
        fs_devices->fs_info = fs_info;
 
@@ -7768,12 +7769,18 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
                device->fs_info = fs_info;
 
        list_for_each_entry(seed_devs, &fs_devices->seed_list, seed_list) {
-               list_for_each_entry(device, &seed_devs->devices, dev_list)
+               list_for_each_entry(device, &seed_devs->devices, dev_list) {
                        device->fs_info = fs_info;
+                       ret = btrfs_get_dev_zone_info(device, false);
+                       if (ret)
+                               break;
+               }
 
                seed_devs->fs_info = fs_info;
        }
        mutex_unlock(&fs_devices->device_list_mutex);
+
+       return ret;
 }
 
 static u64 btrfs_dev_stats_value(const struct extent_buffer *eb,
index f8b668dc8bf81cad2688770c86d6851b97aeea61..099def5613b875a3cdae1997f4cc34faef898919 100644 (file)
@@ -671,7 +671,7 @@ int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
 void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
 int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
                        struct btrfs_ioctl_get_dev_stats *stats);
-void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
+int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
 int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
 int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
 void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);