Merge tag 'devicetree-fixes-for-5.6' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / fs / btrfs / extent-io-tree.h
bloba3febe746c790fb2d0f30816e96460124299c3c4
1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_EXTENT_IO_TREE_H
4 #define BTRFS_EXTENT_IO_TREE_H
6 struct extent_changeset;
7 struct io_failure_record;
9 /* Bits for the extent state */
10 #define EXTENT_DIRTY (1U << 0)
11 #define EXTENT_UPTODATE (1U << 1)
12 #define EXTENT_LOCKED (1U << 2)
13 #define EXTENT_NEW (1U << 3)
14 #define EXTENT_DELALLOC (1U << 4)
15 #define EXTENT_DEFRAG (1U << 5)
16 #define EXTENT_BOUNDARY (1U << 6)
17 #define EXTENT_NODATASUM (1U << 7)
18 #define EXTENT_CLEAR_META_RESV (1U << 8)
19 #define EXTENT_NEED_WAIT (1U << 9)
20 #define EXTENT_DAMAGED (1U << 10)
21 #define EXTENT_NORESERVE (1U << 11)
22 #define EXTENT_QGROUP_RESERVED (1U << 12)
23 #define EXTENT_CLEAR_DATA_RESV (1U << 13)
24 #define EXTENT_DELALLOC_NEW (1U << 14)
25 #define EXTENT_DO_ACCOUNTING (EXTENT_CLEAR_META_RESV | \
26 EXTENT_CLEAR_DATA_RESV)
27 #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING)
30 * Redefined bits above which are used only in the device allocation tree,
31 * shouldn't be using EXTENT_LOCKED / EXTENT_BOUNDARY / EXTENT_CLEAR_META_RESV
32 * / EXTENT_CLEAR_DATA_RESV because they have special meaning to the bit
33 * manipulation functions
35 #define CHUNK_ALLOCATED EXTENT_DIRTY
36 #define CHUNK_TRIMMED EXTENT_DEFRAG
38 enum {
39 IO_TREE_FS_INFO_FREED_EXTENTS0,
40 IO_TREE_FS_INFO_FREED_EXTENTS1,
41 IO_TREE_INODE_IO,
42 IO_TREE_INODE_IO_FAILURE,
43 IO_TREE_RELOC_BLOCKS,
44 IO_TREE_TRANS_DIRTY_PAGES,
45 IO_TREE_ROOT_DIRTY_LOG_PAGES,
46 IO_TREE_SELFTEST,
49 struct extent_io_tree {
50 struct rb_root state;
51 struct btrfs_fs_info *fs_info;
52 void *private_data;
53 u64 dirty_bytes;
54 bool track_uptodate;
56 /* Who owns this io tree, should be one of IO_TREE_* */
57 u8 owner;
59 spinlock_t lock;
60 const struct extent_io_ops *ops;
63 struct extent_state {
64 u64 start;
65 u64 end; /* inclusive */
66 struct rb_node rb_node;
68 /* ADD NEW ELEMENTS AFTER THIS */
69 wait_queue_head_t wq;
70 refcount_t refs;
71 unsigned state;
73 struct io_failure_record *failrec;
75 #ifdef CONFIG_BTRFS_DEBUG
76 struct list_head leak_list;
77 #endif
80 int __init extent_state_cache_init(void);
81 void __cold extent_state_cache_exit(void);
83 void extent_io_tree_init(struct btrfs_fs_info *fs_info,
84 struct extent_io_tree *tree, unsigned int owner,
85 void *private_data);
86 void extent_io_tree_release(struct extent_io_tree *tree);
88 int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
89 struct extent_state **cached);
91 static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end)
93 return lock_extent_bits(tree, start, end, NULL);
96 int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
98 int __init extent_io_init(void);
99 void __cold extent_io_exit(void);
101 u64 count_range_bits(struct extent_io_tree *tree,
102 u64 *start, u64 search_end,
103 u64 max_bytes, unsigned bits, int contig);
105 void free_extent_state(struct extent_state *state);
106 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
107 unsigned bits, int filled,
108 struct extent_state *cached_state);
109 int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
110 unsigned bits, struct extent_changeset *changeset);
111 int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
112 unsigned bits, int wake, int delete,
113 struct extent_state **cached);
114 int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
115 unsigned bits, int wake, int delete,
116 struct extent_state **cached, gfp_t mask,
117 struct extent_changeset *changeset);
119 static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end)
121 return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL);
124 static inline int unlock_extent_cached(struct extent_io_tree *tree, u64 start,
125 u64 end, struct extent_state **cached)
127 return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached,
128 GFP_NOFS, NULL);
131 static inline int unlock_extent_cached_atomic(struct extent_io_tree *tree,
132 u64 start, u64 end, struct extent_state **cached)
134 return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached,
135 GFP_ATOMIC, NULL);
138 static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start,
139 u64 end, unsigned bits)
141 int wake = 0;
143 if (bits & EXTENT_LOCKED)
144 wake = 1;
146 return clear_extent_bit(tree, start, end, bits, wake, 0, NULL);
149 int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
150 unsigned bits, struct extent_changeset *changeset);
151 int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
152 unsigned bits, u64 *failed_start,
153 struct extent_state **cached_state, gfp_t mask);
154 int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end,
155 unsigned bits);
157 static inline int set_extent_bits(struct extent_io_tree *tree, u64 start,
158 u64 end, unsigned bits)
160 return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS);
163 static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
164 u64 end, struct extent_state **cached_state)
166 return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0,
167 cached_state, GFP_NOFS, NULL);
170 static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start,
171 u64 end, gfp_t mask)
173 return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL,
174 NULL, mask);
177 static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
178 u64 end, struct extent_state **cached)
180 return clear_extent_bit(tree, start, end,
181 EXTENT_DIRTY | EXTENT_DELALLOC |
182 EXTENT_DO_ACCOUNTING, 0, 0, cached);
185 int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
186 unsigned bits, unsigned clear_bits,
187 struct extent_state **cached_state);
189 static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start,
190 u64 end, unsigned int extra_bits,
191 struct extent_state **cached_state)
193 return set_extent_bit(tree, start, end,
194 EXTENT_DELALLOC | EXTENT_UPTODATE | extra_bits,
195 NULL, cached_state, GFP_NOFS);
198 static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start,
199 u64 end, struct extent_state **cached_state)
201 return set_extent_bit(tree, start, end,
202 EXTENT_DELALLOC | EXTENT_UPTODATE | EXTENT_DEFRAG,
203 NULL, cached_state, GFP_NOFS);
206 static inline int set_extent_new(struct extent_io_tree *tree, u64 start,
207 u64 end)
209 return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, NULL,
210 GFP_NOFS);
213 static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start,
214 u64 end, struct extent_state **cached_state, gfp_t mask)
216 return set_extent_bit(tree, start, end, EXTENT_UPTODATE, NULL,
217 cached_state, mask);
220 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
221 u64 *start_ret, u64 *end_ret, unsigned bits,
222 struct extent_state **cached_state);
223 void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
224 u64 *start_ret, u64 *end_ret, unsigned bits);
225 int extent_invalidatepage(struct extent_io_tree *tree,
226 struct page *page, unsigned long offset);
227 bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
228 u64 *end, u64 max_bytes,
229 struct extent_state **cached_state);
231 /* This should be reworked in the future and put elsewhere. */
232 int get_state_failrec(struct extent_io_tree *tree, u64 start,
233 struct io_failure_record **failrec);
234 int set_state_failrec(struct extent_io_tree *tree, u64 start,
235 struct io_failure_record *failrec);
236 void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,
237 u64 end);
238 int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end,
239 struct io_failure_record **failrec_ret);
240 int free_io_failure(struct extent_io_tree *failure_tree,
241 struct extent_io_tree *io_tree,
242 struct io_failure_record *rec);
243 int clean_io_failure(struct btrfs_fs_info *fs_info,
244 struct extent_io_tree *failure_tree,
245 struct extent_io_tree *io_tree, u64 start,
246 struct page *page, u64 ino, unsigned int pg_offset);
248 #endif /* BTRFS_EXTENT_IO_TREE_H */