18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Facebook.  All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef BTRFS_FREE_SPACE_TREE_H
78c2ecf20Sopenharmony_ci#define BTRFS_FREE_SPACE_TREE_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistruct btrfs_caching_control;
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * The default size for new free space bitmap items. The last bitmap in a block
138c2ecf20Sopenharmony_ci * group may be truncated, and none of the free space tree code assumes that
148c2ecf20Sopenharmony_ci * existing bitmaps are this size.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#define BTRFS_FREE_SPACE_BITMAP_SIZE 256
178c2ecf20Sopenharmony_ci#define BTRFS_FREE_SPACE_BITMAP_BITS (BTRFS_FREE_SPACE_BITMAP_SIZE * BITS_PER_BYTE)
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_civoid set_free_space_tree_thresholds(struct btrfs_block_group *block_group);
208c2ecf20Sopenharmony_ciint btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info);
218c2ecf20Sopenharmony_ciint btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info);
228c2ecf20Sopenharmony_ciint load_free_space_tree(struct btrfs_caching_control *caching_ctl);
238c2ecf20Sopenharmony_ciint add_block_group_free_space(struct btrfs_trans_handle *trans,
248c2ecf20Sopenharmony_ci			       struct btrfs_block_group *block_group);
258c2ecf20Sopenharmony_ciint remove_block_group_free_space(struct btrfs_trans_handle *trans,
268c2ecf20Sopenharmony_ci				  struct btrfs_block_group *block_group);
278c2ecf20Sopenharmony_ciint add_to_free_space_tree(struct btrfs_trans_handle *trans,
288c2ecf20Sopenharmony_ci			   u64 start, u64 size);
298c2ecf20Sopenharmony_ciint remove_from_free_space_tree(struct btrfs_trans_handle *trans,
308c2ecf20Sopenharmony_ci				u64 start, u64 size);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
338c2ecf20Sopenharmony_cistruct btrfs_free_space_info *
348c2ecf20Sopenharmony_cisearch_free_space_info(struct btrfs_trans_handle *trans,
358c2ecf20Sopenharmony_ci		       struct btrfs_block_group *block_group,
368c2ecf20Sopenharmony_ci		       struct btrfs_path *path, int cow);
378c2ecf20Sopenharmony_ciint __add_to_free_space_tree(struct btrfs_trans_handle *trans,
388c2ecf20Sopenharmony_ci			     struct btrfs_block_group *block_group,
398c2ecf20Sopenharmony_ci			     struct btrfs_path *path, u64 start, u64 size);
408c2ecf20Sopenharmony_ciint __remove_from_free_space_tree(struct btrfs_trans_handle *trans,
418c2ecf20Sopenharmony_ci				  struct btrfs_block_group *block_group,
428c2ecf20Sopenharmony_ci				  struct btrfs_path *path, u64 start, u64 size);
438c2ecf20Sopenharmony_ciint convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
448c2ecf20Sopenharmony_ci				  struct btrfs_block_group *block_group,
458c2ecf20Sopenharmony_ci				  struct btrfs_path *path);
468c2ecf20Sopenharmony_ciint convert_free_space_to_extents(struct btrfs_trans_handle *trans,
478c2ecf20Sopenharmony_ci				  struct btrfs_block_group *block_group,
488c2ecf20Sopenharmony_ci				  struct btrfs_path *path);
498c2ecf20Sopenharmony_ciint free_space_test_bit(struct btrfs_block_group *block_group,
508c2ecf20Sopenharmony_ci			struct btrfs_path *path, u64 offset);
518c2ecf20Sopenharmony_ci#endif
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif
54