blob: dc2463e4cfe3c9a78a73d83f7aa05b2953531ccf [file] [log] [blame]
David Sterba9888c342018-04-03 19:16:55 +02001/* SPDX-License-Identifier: GPL-2.0 */
Omar Sandovala5ed9182015-09-29 20:50:35 -07002/*
3 * Copyright (C) 2015 Facebook. All rights reserved.
Omar Sandovala5ed9182015-09-29 20:50:35 -07004 */
5
David Sterba9888c342018-04-03 19:16:55 +02006#ifndef BTRFS_FREE_SPACE_TREE_H
7#define BTRFS_FREE_SPACE_TREE_H
Omar Sandovala5ed9182015-09-29 20:50:35 -07008
Josef Bacikaac00232019-06-20 15:37:44 -04009struct btrfs_caching_control;
10
Omar Sandovala5ed9182015-09-29 20:50:35 -070011/*
12 * The default size for new free space bitmap items. The last bitmap in a block
13 * group may be truncated, and none of the free space tree code assumes that
14 * existing bitmaps are this size.
15 */
16#define BTRFS_FREE_SPACE_BITMAP_SIZE 256
17#define BTRFS_FREE_SPACE_BITMAP_BITS (BTRFS_FREE_SPACE_BITMAP_SIZE * BITS_PER_BYTE)
18
David Sterba32da53862019-10-29 19:20:18 +010019void set_free_space_tree_thresholds(struct btrfs_block_group *block_group);
Omar Sandovala5ed9182015-09-29 20:50:35 -070020int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info);
21int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info);
22int load_free_space_tree(struct btrfs_caching_control *caching_ctl);
23int add_block_group_free_space(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010024 struct btrfs_block_group *block_group);
Omar Sandovala5ed9182015-09-29 20:50:35 -070025int remove_block_group_free_space(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010026 struct btrfs_block_group *block_group);
Omar Sandovala5ed9182015-09-29 20:50:35 -070027int add_to_free_space_tree(struct btrfs_trans_handle *trans,
Omar Sandovala5ed9182015-09-29 20:50:35 -070028 u64 start, u64 size);
29int remove_from_free_space_tree(struct btrfs_trans_handle *trans,
Omar Sandovala5ed9182015-09-29 20:50:35 -070030 u64 start, u64 size);
31
Nikolay Borisov2d77ab32017-08-16 18:15:23 +030032#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
Omar Sandovala5ed9182015-09-29 20:50:35 -070033struct btrfs_free_space_info *
34search_free_space_info(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010035 struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070036 struct btrfs_path *path, int cow);
37int __add_to_free_space_tree(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010038 struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070039 struct btrfs_path *path, u64 start, u64 size);
40int __remove_from_free_space_tree(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010041 struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070042 struct btrfs_path *path, u64 start, u64 size);
43int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010044 struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070045 struct btrfs_path *path);
46int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
David Sterba32da53862019-10-29 19:20:18 +010047 struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070048 struct btrfs_path *path);
David Sterba32da53862019-10-29 19:20:18 +010049int free_space_test_bit(struct btrfs_block_group *block_group,
Omar Sandovala5ed9182015-09-29 20:50:35 -070050 struct btrfs_path *path, u64 offset);
Nikolay Borisov2d77ab32017-08-16 18:15:23 +030051#endif
Omar Sandovala5ed9182015-09-29 20:50:35 -070052
53#endif