162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2015 Facebook.  All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef BTRFS_FREE_SPACE_TREE_H
762306a36Sopenharmony_ci#define BTRFS_FREE_SPACE_TREE_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_cistruct btrfs_caching_control;
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci * The default size for new free space bitmap items. The last bitmap in a block
1362306a36Sopenharmony_ci * group may be truncated, and none of the free space tree code assumes that
1462306a36Sopenharmony_ci * existing bitmaps are this size.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci#define BTRFS_FREE_SPACE_BITMAP_SIZE 256
1762306a36Sopenharmony_ci#define BTRFS_FREE_SPACE_BITMAP_BITS (BTRFS_FREE_SPACE_BITMAP_SIZE * BITS_PER_BYTE)
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_civoid set_free_space_tree_thresholds(struct btrfs_block_group *block_group);
2062306a36Sopenharmony_ciint btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info);
2162306a36Sopenharmony_ciint btrfs_delete_free_space_tree(struct btrfs_fs_info *fs_info);
2262306a36Sopenharmony_ciint btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info);
2362306a36Sopenharmony_ciint load_free_space_tree(struct btrfs_caching_control *caching_ctl);
2462306a36Sopenharmony_ciint add_block_group_free_space(struct btrfs_trans_handle *trans,
2562306a36Sopenharmony_ci			       struct btrfs_block_group *block_group);
2662306a36Sopenharmony_ciint remove_block_group_free_space(struct btrfs_trans_handle *trans,
2762306a36Sopenharmony_ci				  struct btrfs_block_group *block_group);
2862306a36Sopenharmony_ciint add_to_free_space_tree(struct btrfs_trans_handle *trans,
2962306a36Sopenharmony_ci			   u64 start, u64 size);
3062306a36Sopenharmony_ciint remove_from_free_space_tree(struct btrfs_trans_handle *trans,
3162306a36Sopenharmony_ci				u64 start, u64 size);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3462306a36Sopenharmony_cistruct btrfs_free_space_info *
3562306a36Sopenharmony_cisearch_free_space_info(struct btrfs_trans_handle *trans,
3662306a36Sopenharmony_ci		       struct btrfs_block_group *block_group,
3762306a36Sopenharmony_ci		       struct btrfs_path *path, int cow);
3862306a36Sopenharmony_ciint __add_to_free_space_tree(struct btrfs_trans_handle *trans,
3962306a36Sopenharmony_ci			     struct btrfs_block_group *block_group,
4062306a36Sopenharmony_ci			     struct btrfs_path *path, u64 start, u64 size);
4162306a36Sopenharmony_ciint __remove_from_free_space_tree(struct btrfs_trans_handle *trans,
4262306a36Sopenharmony_ci				  struct btrfs_block_group *block_group,
4362306a36Sopenharmony_ci				  struct btrfs_path *path, u64 start, u64 size);
4462306a36Sopenharmony_ciint convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
4562306a36Sopenharmony_ci				  struct btrfs_block_group *block_group,
4662306a36Sopenharmony_ci				  struct btrfs_path *path);
4762306a36Sopenharmony_ciint convert_free_space_to_extents(struct btrfs_trans_handle *trans,
4862306a36Sopenharmony_ci				  struct btrfs_block_group *block_group,
4962306a36Sopenharmony_ci				  struct btrfs_path *path);
5062306a36Sopenharmony_ciint free_space_test_bit(struct btrfs_block_group *block_group,
5162306a36Sopenharmony_ci			struct btrfs_path *path, u64 offset);
5262306a36Sopenharmony_ci#endif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#endif
55