free-space-cache.h 4.2 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4 5
/*
 * Copyright (C) 2009 Oracle.  All rights reserved.
 */

6 7
#ifndef BTRFS_FREE_SPACE_CACHE_H
#define BTRFS_FREE_SPACE_CACHE_H
8

9 10 11 12
struct btrfs_free_space {
	struct rb_node offset_index;
	u64 offset;
	u64 bytes;
13
	u64 max_extent_size;
14 15 16 17
	unsigned long *bitmap;
	struct list_head list;
};

18 19 20 21 22 23 24 25 26
struct btrfs_free_space_ctl {
	spinlock_t tree_lock;
	struct rb_root free_space_offset;
	u64 free_space;
	int extents_thresh;
	int free_extents;
	int total_bitmaps;
	int unit;
	u64 start;
27
	const struct btrfs_free_space_op *op;
28
	void *private;
29 30
	struct mutex cache_writeout_mutex;
	struct list_head trimming_ranges;
31 32 33 34 35 36 37 38
};

struct btrfs_free_space_op {
	void (*recalc_thresholds)(struct btrfs_free_space_ctl *ctl);
	bool (*use_bitmap)(struct btrfs_free_space_ctl *ctl,
			   struct btrfs_free_space *info);
};

39 40 41 42 43 44 45 46 47 48 49 50 51
struct btrfs_io_ctl {
	void *cur, *orig;
	struct page *page;
	struct page **pages;
	struct btrfs_fs_info *fs_info;
	struct inode *inode;
	unsigned long size;
	int index;
	int num_pages;
	int entries;
	int bitmaps;
	unsigned check_crcs:1;
};
52

53 54 55
struct inode *lookup_free_space_inode(
		struct btrfs_block_group_cache *block_group,
		struct btrfs_path *path);
56
int create_free_space_inode(struct btrfs_trans_handle *trans,
57 58
			    struct btrfs_block_group_cache *block_group,
			    struct btrfs_path *path);
J
Josef Bacik 已提交
59

60
int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
61
				       struct btrfs_block_rsv *rsv);
62
int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
63
				    struct btrfs_block_group_cache *block_group,
64
				    struct inode *inode);
65
int load_free_space_cache(struct btrfs_block_group_cache *block_group);
66
int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
67
			struct btrfs_block_group_cache *block_group,
68
			struct btrfs_path *path);
69
int btrfs_write_out_cache(struct btrfs_trans_handle *trans,
J
Josef Bacik 已提交
70 71
			  struct btrfs_block_group_cache *block_group,
			  struct btrfs_path *path);
72 73 74 75 76 77 78 79 80
struct inode *lookup_free_ino_inode(struct btrfs_root *root,
				    struct btrfs_path *path);
int create_free_ino_inode(struct btrfs_root *root,
			  struct btrfs_trans_handle *trans,
			  struct btrfs_path *path);
int load_free_ino_cache(struct btrfs_fs_info *fs_info,
			struct btrfs_root *root);
int btrfs_write_out_ino_cache(struct btrfs_root *root,
			      struct btrfs_trans_handle *trans,
81 82
			      struct btrfs_path *path,
			      struct inode *inode);
83

84
void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group);
85 86
int __btrfs_add_free_space(struct btrfs_fs_info *fs_info,
			   struct btrfs_free_space_ctl *ctl,
87
			   u64 bytenr, u64 size);
88 89
int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
			 u64 bytenr, u64 size);
90 91
int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
			    u64 bytenr, u64 size);
92
void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl);
93
void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
94
				     *block_group);
95
u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
96 97
			       u64 offset, u64 bytes, u64 empty_size,
			       u64 *max_extent_size);
98
u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root);
99 100
void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
			   u64 bytes);
101
int btrfs_find_space_cluster(struct btrfs_block_group_cache *block_group,
102 103 104 105 106
			     struct btrfs_free_cluster *cluster,
			     u64 offset, u64 bytes, u64 empty_size);
void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster);
u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
			     struct btrfs_free_cluster *cluster, u64 bytes,
107
			     u64 min_start, u64 *max_extent_size);
108 109 110
int btrfs_return_cluster_to_free_space(
			       struct btrfs_block_group_cache *block_group,
			       struct btrfs_free_cluster *cluster);
111 112
int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group,
			   u64 *trimmed, u64 start, u64 end, u64 minlen);
113

114
/* Support functions for running our sanity tests */
115 116 117 118 119 120
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
int test_add_free_space_entry(struct btrfs_block_group_cache *cache,
			      u64 offset, u64 bytes, bool bitmap);
int test_check_exists(struct btrfs_block_group_cache *cache,
		      u64 offset, u64 bytes);
#endif
121

122
#endif