Blame view

fs/btrfs/free-space-cache.h 4.28 KB
9888c3402   David Sterba   btrfs: replace GP...
1
  /* SPDX-License-Identifier: GPL-2.0 */
fa9c0d795   Chris Mason   Btrfs: rework all...
2
3
  /*
   * Copyright (C) 2009 Oracle.  All rights reserved.
fa9c0d795   Chris Mason   Btrfs: rework all...
4
   */
9888c3402   David Sterba   btrfs: replace GP...
5
6
  #ifndef BTRFS_FREE_SPACE_CACHE_H
  #define BTRFS_FREE_SPACE_CACHE_H
fa9c0d795   Chris Mason   Btrfs: rework all...
7

963030817   Josef Bacik   Btrfs: use hybrid...
8
9
10
11
  struct btrfs_free_space {
  	struct rb_node offset_index;
  	u64 offset;
  	u64 bytes;
cef404837   Josef Bacik   Btrfs: keep track...
12
  	u64 max_extent_size;
963030817   Josef Bacik   Btrfs: use hybrid...
13
14
15
  	unsigned long *bitmap;
  	struct list_head list;
  };
34d52cb6c   Li Zefan   Btrfs: Make free ...
16
17
18
19
20
21
22
23
24
  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;
20e5506ba   David Sterba   btrfs: constify r...
25
  	const struct btrfs_free_space_op *op;
34d52cb6c   Li Zefan   Btrfs: Make free ...
26
  	void *private;
55507ce36   Filipe Manana   Btrfs: fix race b...
27
28
  	struct mutex cache_writeout_mutex;
  	struct list_head trimming_ranges;
34d52cb6c   Li Zefan   Btrfs: Make free ...
29
30
31
32
33
34
35
  };
  
  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);
  };
c9dc4c657   Chris Mason   Btrfs: two stage ...
36
  struct btrfs_io_ctl;
77ab86bf1   Jeff Mahoney   btrfs: free-space...
37
  struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
0af3d00ba   Josef Bacik   Btrfs: create spe...
38
39
  				      struct btrfs_block_group_cache
  				      *block_group, struct btrfs_path *path);
77ab86bf1   Jeff Mahoney   btrfs: free-space...
40
  int create_free_space_inode(struct btrfs_fs_info *fs_info,
0af3d00ba   Josef Bacik   Btrfs: create spe...
41
42
43
  			    struct btrfs_trans_handle *trans,
  			    struct btrfs_block_group_cache *block_group,
  			    struct btrfs_path *path);
0cb59c995   Josef Bacik   Btrfs: write out ...
44

2ff7e61e0   Jeff Mahoney   btrfs: take an fs...
45
  int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
7b61cd922   Miao Xie   Btrfs: don't use ...
46
  				       struct btrfs_block_rsv *rsv);
77ab86bf1   Jeff Mahoney   btrfs: free-space...
47
  int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
1bbc621ef   Chris Mason   Btrfs: allow bloc...
48
  				    struct btrfs_block_group_cache *block_group,
0af3d00ba   Josef Bacik   Btrfs: create spe...
49
  				    struct inode *inode);
9d66e233c   Josef Bacik   Btrfs: load free ...
50
51
  int load_free_space_cache(struct btrfs_fs_info *fs_info,
  			  struct btrfs_block_group_cache *block_group);
afdb57189   Jeff Mahoney   btrfs: simplify b...
52
  int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
c9dc4c657   Chris Mason   Btrfs: two stage ...
53
  			struct btrfs_block_group_cache *block_group,
afdb57189   Jeff Mahoney   btrfs: simplify b...
54
  			struct btrfs_path *path);
5b4aacefb   Jeff Mahoney   btrfs: call funct...
55
  int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
0cb59c995   Josef Bacik   Btrfs: write out ...
56
57
58
  			  struct btrfs_trans_handle *trans,
  			  struct btrfs_block_group_cache *block_group,
  			  struct btrfs_path *path);
82d5902d9   Li Zefan   Btrfs: Support re...
59
60
61
62
63
64
65
66
67
  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,
53645a91f   Filipe David Borba Manana   Btrfs: remove dup...
68
69
  			      struct btrfs_path *path,
  			      struct inode *inode);
82d5902d9   Li Zefan   Btrfs: Support re...
70

34d52cb6c   Li Zefan   Btrfs: Make free ...
71
  void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group);
ab8d0fc48   Jeff Mahoney   btrfs: convert pr...
72
73
  int __btrfs_add_free_space(struct btrfs_fs_info *fs_info,
  			   struct btrfs_free_space_ctl *ctl,
581bb0509   Li Zefan   Btrfs: Cache free...
74
75
76
77
78
  			   u64 bytenr, u64 size);
  static inline int
  btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
  		     u64 bytenr, u64 size)
  {
ab8d0fc48   Jeff Mahoney   btrfs: convert pr...
79
80
  	return __btrfs_add_free_space(block_group->fs_info,
  				      block_group->free_space_ctl,
581bb0509   Li Zefan   Btrfs: Cache free...
81
82
  				      bytenr, size);
  }
fa9c0d795   Chris Mason   Btrfs: rework all...
83
84
  int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
  			    u64 bytenr, u64 size);
581bb0509   Li Zefan   Btrfs: Cache free...
85
  void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl);
fa9c0d795   Chris Mason   Btrfs: rework all...
86
  void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
581bb0509   Li Zefan   Btrfs: Cache free...
87
  				     *block_group);
fa9c0d795   Chris Mason   Btrfs: rework all...
88
  u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
a48203988   Miao Xie   Btrfs: allocate t...
89
90
  			       u64 offset, u64 bytes, u64 empty_size,
  			       u64 *max_extent_size);
581bb0509   Li Zefan   Btrfs: Cache free...
91
  u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root);
fa9c0d795   Chris Mason   Btrfs: rework all...
92
93
  void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
  			   u64 bytes);
2ff7e61e0   Jeff Mahoney   btrfs: take an fs...
94
  int btrfs_find_space_cluster(struct btrfs_fs_info *fs_info,
fa9c0d795   Chris Mason   Btrfs: rework all...
95
96
97
98
99
100
  			     struct btrfs_block_group_cache *block_group,
  			     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,
a48203988   Miao Xie   Btrfs: allocate t...
101
  			     u64 min_start, u64 *max_extent_size);
fa9c0d795   Chris Mason   Btrfs: rework all...
102
103
104
  int btrfs_return_cluster_to_free_space(
  			       struct btrfs_block_group_cache *block_group,
  			       struct btrfs_free_cluster *cluster);
f7039b1d5   Li Dongyang   Btrfs: add btrfs_...
105
106
  int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group,
  			   u64 *trimmed, u64 start, u64 end, u64 minlen);
74255aa07   Josef Bacik   Btrfs: add some f...
107

013276101   Nicholas D Steeves   btrfs: fix string...
108
  /* Support functions for running our sanity tests */
dc11dd5d7   Josef Bacik   Btrfs: separate o...
109
110
111
112
113
114
  #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
74255aa07   Josef Bacik   Btrfs: add some f...
115

fa9c0d795   Chris Mason   Btrfs: rework all...
116
  #endif