Re: [PATCH 2/2] btrfs: return error if we're unable to read device stats

David Sterba
2020-09-22T17:30:13Z

On Fri, Sep 18, 2020 at 04:44:33PM -0400, Josef Bacik wrote:
> @@ -7270,22 +7271,30 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
> struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
> struct btrfs_device *device;
> struct btrfs_path *path = NULL;
> + int ret = 0;
>
> path = btrfs_alloc_path();
> if (!path)
> return -ENOMEM;
>
> mutex_lock(&fs_devices->device_list_mutex);
> - list_for_each_entry(device, &fs_devices->devices, dev_list)
> - __btrfs_init_dev_stats(fs_info, device, path);
> + list_for_each_entry(device, &fs_devices->devices, dev_list) {
> + ret = __btrfs_init_dev_stats(fs_info, device, path);
> + if (ret)
> + goto out;
> + }
> list_for_each_entry(seed_devs, &fs_devices->seed_list, seed_list) {
> - list_for_each_entry(device, &seed_devs->devices, dev_list)
> - __btrfs_init_dev_stats(fs_info, device, path);
> + list_for_each_entry(device, &seed_devs->devices, dev_list) {
> + ret = __btrfs_init_dev_stats(fs_info, device, path);
> + if (ret)
> + break;

This jumps out of the inner list_for_each and continues traversing the
seed_list, is that intentional? Or goto out should be here as well.

> + }
> }
> +out:
> mutex_unlock(&fs_devices->device_list_mutex);
>
> btrfs_free_path(path);
> - return 0;
> + return ret;
> }