On 05/05/2020 01:58, Qu Wenruo wrote:
> int btrfs_read_block_groups(struct btrfs_fs_info *info)
> {
> struct btrfs_path *path;
> @@ -2022,20 +2124,27 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
> if (btrfs_test_opt(info, CLEAR_CACHE))
> need_clear = 1;
>
> - while (1) {
> - ret = find_first_block_group(info, path, &key);
> - if (ret > 0)
> - break;
> - if (ret != 0)
> - goto error;
> + if (btrfs_fs_incompat(info, SKINNY_BG_TREE)) {
> + path->reada = READA_FORWARD;
> + ret = read_skinny_block_groups(info, path, need_clear);
> + } else {
> + while (1) {
> + ret = find_first_block_group(info, path, &key);
> + if (ret > 0)
> + break;
> + if (ret != 0)
> + goto error;
>
> - btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
> - ret = read_one_block_group(info, path, &key, need_clear);
> - if (ret < 0)
> - goto error;
> - key.objectid += key.offset;
> - key.offset = 0;
> - btrfs_release_path(path);
> + btrfs_item_key_to_cpu(path->nodes[0], &key,
> + path->slots[0]);
> + ret = read_one_block_group(info, path, &key,
> + need_clear);
> + if (ret < 0)
> + goto error;
> + key.objectid += key.offset;
> + key.offset = 0;
> + btrfs_release_path(path);
> + }
> }
>
It might be worth considering to move the 'else' path into a function on
it's own, similar what you did with read_skinny_block_groups().