]>
Commit | Line | Data |
---|---|---|
6cbd5570 CM |
1 | /* |
2 | * Copyright (C) 2007 Oracle. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public | |
6 | * License v2 as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public | |
14 | * License along with this program; if not, write to the | |
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
16 | * Boston, MA 021110-1307, USA. | |
17 | */ | |
18 | ||
dc17ff8f CM |
19 | #ifndef __BTRFS_CTREE__ |
20 | #define __BTRFS_CTREE__ | |
eb60ceac | 21 | |
810191ff CM |
22 | #include <linux/mm.h> |
23 | #include <linux/highmem.h> | |
e20d96d6 | 24 | #include <linux/fs.h> |
a2de733c | 25 | #include <linux/rwsem.h> |
803b2f54 | 26 | #include <linux/semaphore.h> |
58176a96 | 27 | #include <linux/completion.h> |
04160088 | 28 | #include <linux/backing-dev.h> |
e6dcd2dc | 29 | #include <linux/wait.h> |
5a0e3ad6 | 30 | #include <linux/slab.h> |
f8b18087 | 31 | #include <linux/kobject.h> |
1abe9b8a | 32 | #include <trace/events/btrfs.h> |
479965d6 | 33 | #include <asm/kmap_types.h> |
3b16a4e3 | 34 | #include <linux/pagemap.h> |
55e301fd | 35 | #include <linux/btrfs.h> |
21c7e756 | 36 | #include <linux/workqueue.h> |
f667aef6 | 37 | #include <linux/security.h> |
ee22184b | 38 | #include <linux/sizes.h> |
d1310b2e | 39 | #include "extent_io.h" |
5f39d397 | 40 | #include "extent_map.h" |
8b712842 | 41 | #include "async-thread.h" |
e20d96d6 | 42 | |
e089f05c | 43 | struct btrfs_trans_handle; |
79154b1b | 44 | struct btrfs_transaction; |
a22285a6 | 45 | struct btrfs_pending_snapshot; |
35b7e476 CM |
46 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
47 | extern struct kmem_cache *btrfs_transaction_cachep; | |
48 | extern struct kmem_cache *btrfs_bit_radix_cachep; | |
2c90e5d6 | 49 | extern struct kmem_cache *btrfs_path_cachep; |
dc89e982 | 50 | extern struct kmem_cache *btrfs_free_space_cachep; |
e6dcd2dc | 51 | struct btrfs_ordered_sum; |
e089f05c | 52 | |
294e30fe JB |
53 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
54 | #define STATIC noinline | |
55 | #else | |
56 | #define STATIC static noinline | |
57 | #endif | |
58 | ||
cdb4c574 | 59 | #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */ |
eb60ceac | 60 | |
72d7aefc | 61 | #define BTRFS_MAX_MIRRORS 3 |
94598ba8 | 62 | |
4008c04a | 63 | #define BTRFS_MAX_LEVEL 8 |
0b86a832 | 64 | |
5d4f98a2 YZ |
65 | #define BTRFS_COMPAT_EXTENT_TREE_V0 |
66 | ||
0b86a832 | 67 | /* holds pointers to all of the tree roots */ |
6407bf6d | 68 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
0b86a832 CM |
69 | |
70 | /* stores information about which extents are in use, and reference counts */ | |
0cf6c620 | 71 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL |
0b86a832 | 72 | |
0b86a832 CM |
73 | /* |
74 | * chunk tree stores translations from logical -> physical block numbering | |
75 | * the super block points to the chunk tree | |
76 | */ | |
e085def2 | 77 | #define BTRFS_CHUNK_TREE_OBJECTID 3ULL |
0b86a832 CM |
78 | |
79 | /* | |
80 | * stores information about which areas of a given device are in use. | |
81 | * one per device. The tree of tree roots points to the device tree | |
82 | */ | |
e085def2 CM |
83 | #define BTRFS_DEV_TREE_OBJECTID 4ULL |
84 | ||
85 | /* one per subvolume, storing files and directories */ | |
86 | #define BTRFS_FS_TREE_OBJECTID 5ULL | |
87 | ||
88 | /* directory objectid inside the root tree */ | |
89 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL | |
0b86a832 | 90 | |
d20f7043 CM |
91 | /* holds checksums of all the data extents */ |
92 | #define BTRFS_CSUM_TREE_OBJECTID 7ULL | |
93 | ||
630dc772 AJ |
94 | /* holds quota configuration and tracking */ |
95 | #define BTRFS_QUOTA_TREE_OBJECTID 8ULL | |
96 | ||
07b30a49 SB |
97 | /* for storing items that use the BTRFS_UUID_KEY* types */ |
98 | #define BTRFS_UUID_TREE_OBJECTID 9ULL | |
99 | ||
208acb8c OS |
100 | /* tracks free space in block groups. */ |
101 | #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL | |
102 | ||
60b62978 DS |
103 | /* for storing balance parameters in the root tree */ |
104 | #define BTRFS_BALANCE_OBJECTID -4ULL | |
105 | ||
7b128766 JB |
106 | /* orhpan objectid for tracking unlinked/truncated files */ |
107 | #define BTRFS_ORPHAN_OBJECTID -5ULL | |
108 | ||
e02119d5 CM |
109 | /* does write ahead logging to speed up fsyncs */ |
110 | #define BTRFS_TREE_LOG_OBJECTID -6ULL | |
111 | #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL | |
112 | ||
e4657689 ZY |
113 | /* for space balancing */ |
114 | #define BTRFS_TREE_RELOC_OBJECTID -8ULL | |
115 | #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL | |
116 | ||
d20f7043 CM |
117 | /* |
118 | * extent checksums all have this objectid | |
119 | * this allows them to share the logging tree | |
120 | * for fsyncs | |
121 | */ | |
122 | #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL | |
123 | ||
0af3d00b JB |
124 | /* For storing free space cache */ |
125 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL | |
126 | ||
82d5902d | 127 | /* |
527a1361 | 128 | * The inode number assigned to the special inode for storing |
82d5902d LZ |
129 | * free ino cache |
130 | */ | |
131 | #define BTRFS_FREE_INO_OBJECTID -12ULL | |
132 | ||
31840ae1 ZY |
133 | /* dummy objectid represents multiple objectids */ |
134 | #define BTRFS_MULTIPLE_OBJECTIDS -255ULL | |
135 | ||
0b86a832 | 136 | /* |
6527cdbe | 137 | * All files have objectids in this range. |
0b86a832 | 138 | */ |
f6dbff55 | 139 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL |
6527cdbe | 140 | #define BTRFS_LAST_FREE_OBJECTID -256ULL |
e17cade2 | 141 | #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL |
3768f368 | 142 | |
0b86a832 CM |
143 | |
144 | /* | |
145 | * the device items go into the chunk tree. The key is in the form | |
146 | * [ 1 BTRFS_DEV_ITEM_KEY device_id ] | |
147 | */ | |
148 | #define BTRFS_DEV_ITEMS_OBJECTID 1ULL | |
149 | ||
4df27c4d YZ |
150 | #define BTRFS_BTREE_INODE_OBJECTID 1 |
151 | ||
152 | #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2 | |
153 | ||
6e71c47a | 154 | #define BTRFS_DEV_REPLACE_DEVID 0ULL |
e93c89c1 | 155 | |
727011e0 CM |
156 | /* |
157 | * the max metadata block size. This limit is somewhat artificial, | |
158 | * but the memmove costs go through the roof for larger blocks. | |
159 | */ | |
160 | #define BTRFS_MAX_METADATA_BLOCKSIZE 65536 | |
161 | ||
e20d96d6 CM |
162 | /* |
163 | * we can actually store much bigger names, but lets not confuse the rest | |
164 | * of linux | |
165 | */ | |
166 | #define BTRFS_NAME_LEN 255 | |
167 | ||
f186373f MF |
168 | /* |
169 | * Theoretical limit is larger, but we keep this down to a sane | |
170 | * value. That should limit greatly the possibility of collisions on | |
171 | * inode ref items. | |
172 | */ | |
173 | #define BTRFS_LINK_MAX 65535U | |
174 | ||
f254e52c CM |
175 | /* 32 bytes in various csum fields */ |
176 | #define BTRFS_CSUM_SIZE 32 | |
607d432d JB |
177 | |
178 | /* csum types */ | |
179 | #define BTRFS_CSUM_TYPE_CRC32 0 | |
180 | ||
4d4ab6d6 | 181 | static const int btrfs_csum_sizes[] = { 4 }; |
607d432d | 182 | |
509659cd | 183 | /* four bytes for CRC32 */ |
3954401f | 184 | #define BTRFS_EMPTY_DIR_SIZE 0 |
f254e52c | 185 | |
29a8d9a0 SB |
186 | /* spefic to btrfs_map_block(), therefore not in include/linux/blk_types.h */ |
187 | #define REQ_GET_READ_MIRRORS (1 << 30) | |
188 | ||
fabb5681 CM |
189 | #define BTRFS_FT_UNKNOWN 0 |
190 | #define BTRFS_FT_REG_FILE 1 | |
191 | #define BTRFS_FT_DIR 2 | |
192 | #define BTRFS_FT_CHRDEV 3 | |
193 | #define BTRFS_FT_BLKDEV 4 | |
194 | #define BTRFS_FT_FIFO 5 | |
195 | #define BTRFS_FT_SOCK 6 | |
196 | #define BTRFS_FT_SYMLINK 7 | |
5103e947 JB |
197 | #define BTRFS_FT_XATTR 8 |
198 | #define BTRFS_FT_MAX 9 | |
fabb5681 | 199 | |
3d136a11 SB |
200 | /* ioprio of readahead is set to idle */ |
201 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) | |
202 | ||
ee22184b | 203 | #define BTRFS_DIRTY_METADATA_THRESH SZ_32M |
e2d84521 | 204 | |
ee22184b | 205 | #define BTRFS_MAX_EXTENT_SIZE SZ_128M |
dcab6a3b | 206 | |
fec577fb | 207 | /* |
d4a78947 WF |
208 | * The key defines the order in the tree, and so it also defines (optimal) |
209 | * block layout. | |
210 | * | |
211 | * objectid corresponds to the inode number. | |
212 | * | |
213 | * type tells us things about the object, and is a kind of stream selector. | |
214 | * so for a given inode, keys with type of 1 might refer to the inode data, | |
215 | * type of 2 may point to file data in the btree and type == 3 may point to | |
216 | * extents. | |
fec577fb CM |
217 | * |
218 | * offset is the starting byte offset for this key in the stream. | |
e2fa7227 CM |
219 | * |
220 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | |
221 | * in cpu native order. Otherwise they are identical and their sizes | |
222 | * should be the same (ie both packed) | |
fec577fb | 223 | */ |
e2fa7227 CM |
224 | struct btrfs_disk_key { |
225 | __le64 objectid; | |
5f39d397 | 226 | u8 type; |
70b2befd | 227 | __le64 offset; |
e2fa7227 CM |
228 | } __attribute__ ((__packed__)); |
229 | ||
230 | struct btrfs_key { | |
eb60ceac | 231 | u64 objectid; |
5f39d397 | 232 | u8 type; |
70b2befd | 233 | u64 offset; |
eb60ceac CM |
234 | } __attribute__ ((__packed__)); |
235 | ||
0b86a832 CM |
236 | struct btrfs_mapping_tree { |
237 | struct extent_map_tree map_tree; | |
238 | }; | |
239 | ||
0b86a832 CM |
240 | struct btrfs_dev_item { |
241 | /* the internal btrfs device id */ | |
242 | __le64 devid; | |
243 | ||
244 | /* size of the device */ | |
245 | __le64 total_bytes; | |
246 | ||
247 | /* bytes used */ | |
248 | __le64 bytes_used; | |
249 | ||
250 | /* optimal io alignment for this device */ | |
251 | __le32 io_align; | |
252 | ||
253 | /* optimal io width for this device */ | |
254 | __le32 io_width; | |
255 | ||
256 | /* minimal io size for this device */ | |
257 | __le32 sector_size; | |
258 | ||
0b86a832 CM |
259 | /* type and info about this device */ |
260 | __le64 type; | |
261 | ||
2b82032c YZ |
262 | /* expected generation for this device */ |
263 | __le64 generation; | |
264 | ||
c3027eb5 CM |
265 | /* |
266 | * starting byte of this partition on the device, | |
d4a78947 | 267 | * to allow for stripe alignment in the future |
c3027eb5 CM |
268 | */ |
269 | __le64 start_offset; | |
270 | ||
e17cade2 CM |
271 | /* grouping information for allocation decisions */ |
272 | __le32 dev_group; | |
273 | ||
274 | /* seek speed 0-100 where 100 is fastest */ | |
275 | u8 seek_speed; | |
276 | ||
277 | /* bandwidth 0-100 where 100 is fastest */ | |
278 | u8 bandwidth; | |
279 | ||
0d81ba5d | 280 | /* btrfs generated uuid for this device */ |
e17cade2 | 281 | u8 uuid[BTRFS_UUID_SIZE]; |
2b82032c YZ |
282 | |
283 | /* uuid of FS who owns this device */ | |
284 | u8 fsid[BTRFS_UUID_SIZE]; | |
0b86a832 CM |
285 | } __attribute__ ((__packed__)); |
286 | ||
287 | struct btrfs_stripe { | |
288 | __le64 devid; | |
289 | __le64 offset; | |
e17cade2 | 290 | u8 dev_uuid[BTRFS_UUID_SIZE]; |
0b86a832 CM |
291 | } __attribute__ ((__packed__)); |
292 | ||
293 | struct btrfs_chunk { | |
e17cade2 CM |
294 | /* size of this chunk in bytes */ |
295 | __le64 length; | |
296 | ||
297 | /* objectid of the root referencing this chunk */ | |
0b86a832 | 298 | __le64 owner; |
e17cade2 | 299 | |
0b86a832 CM |
300 | __le64 stripe_len; |
301 | __le64 type; | |
302 | ||
303 | /* optimal io alignment for this chunk */ | |
304 | __le32 io_align; | |
305 | ||
306 | /* optimal io width for this chunk */ | |
307 | __le32 io_width; | |
308 | ||
309 | /* minimal io size for this chunk */ | |
310 | __le32 sector_size; | |
311 | ||
312 | /* 2^16 stripes is quite a lot, a second limit is the size of a single | |
313 | * item in the btree | |
314 | */ | |
315 | __le16 num_stripes; | |
321aecc6 CM |
316 | |
317 | /* sub stripes only matter for raid10 */ | |
318 | __le16 sub_stripes; | |
0b86a832 CM |
319 | struct btrfs_stripe stripe; |
320 | /* additional stripes go here */ | |
321 | } __attribute__ ((__packed__)); | |
322 | ||
0af3d00b JB |
323 | #define BTRFS_FREE_SPACE_EXTENT 1 |
324 | #define BTRFS_FREE_SPACE_BITMAP 2 | |
325 | ||
326 | struct btrfs_free_space_entry { | |
327 | __le64 offset; | |
328 | __le64 bytes; | |
329 | u8 type; | |
330 | } __attribute__ ((__packed__)); | |
331 | ||
332 | struct btrfs_free_space_header { | |
333 | struct btrfs_disk_key location; | |
334 | __le64 generation; | |
335 | __le64 num_entries; | |
336 | __le64 num_bitmaps; | |
337 | } __attribute__ ((__packed__)); | |
338 | ||
0b86a832 CM |
339 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
340 | { | |
341 | BUG_ON(num_stripes == 0); | |
342 | return sizeof(struct btrfs_chunk) + | |
343 | sizeof(struct btrfs_stripe) * (num_stripes - 1); | |
344 | } | |
345 | ||
5d4f98a2 YZ |
346 | #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) |
347 | #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) | |
acce952b | 348 | |
349 | /* | |
350 | * File system states | |
351 | */ | |
87533c47 | 352 | #define BTRFS_FS_STATE_ERROR 0 |
dc81cdc5 | 353 | #define BTRFS_FS_STATE_REMOUNTING 1 |
08748810 | 354 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 |
c404e0dc | 355 | #define BTRFS_FS_STATE_DEV_REPLACING 3 |
acce952b | 356 | |
87533c47 | 357 | /* Super block flags */ |
acce952b | 358 | /* Errors detected */ |
359 | #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2) | |
360 | ||
5d4f98a2 YZ |
361 | #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32) |
362 | #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33) | |
363 | ||
364 | #define BTRFS_BACKREF_REV_MAX 256 | |
365 | #define BTRFS_BACKREF_REV_SHIFT 56 | |
366 | #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ | |
367 | BTRFS_BACKREF_REV_SHIFT) | |
368 | ||
369 | #define BTRFS_OLD_BACKREF_REV 0 | |
370 | #define BTRFS_MIXED_BACKREF_REV 1 | |
63b10fc4 | 371 | |
fec577fb CM |
372 | /* |
373 | * every tree block (leaf or node) starts with this header. | |
374 | */ | |
bb492bb0 | 375 | struct btrfs_header { |
e17cade2 | 376 | /* these first four must match the super block */ |
f254e52c | 377 | u8 csum[BTRFS_CSUM_SIZE]; |
5f39d397 | 378 | u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ |
db94535d | 379 | __le64 bytenr; /* which block this node is supposed to live in */ |
63b10fc4 | 380 | __le64 flags; |
e17cade2 CM |
381 | |
382 | /* allowed to be different from the super from here on down */ | |
383 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; | |
7f5c1516 | 384 | __le64 generation; |
4d775673 | 385 | __le64 owner; |
5f39d397 | 386 | __le32 nritems; |
9a6f11ed | 387 | u8 level; |
eb60ceac CM |
388 | } __attribute__ ((__packed__)); |
389 | ||
5f39d397 | 390 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \ |
d397712b CM |
391 | sizeof(struct btrfs_header)) / \ |
392 | sizeof(struct btrfs_key_ptr)) | |
123abc88 | 393 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
707e8a07 | 394 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize)) |
7ec20afb DS |
395 | #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ |
396 | (offsetof(struct btrfs_file_extent_item, disk_bytenr)) | |
236454df CM |
397 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
398 | sizeof(struct btrfs_item) - \ | |
7ec20afb | 399 | BTRFS_FILE_EXTENT_INLINE_DATA_START) |
f34f57a3 YZ |
400 | #define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
401 | sizeof(struct btrfs_item) -\ | |
402 | sizeof(struct btrfs_dir_item)) | |
eb60ceac | 403 | |
0b86a832 CM |
404 | |
405 | /* | |
406 | * this is a very generous portion of the super block, giving us | |
407 | * room to translate 14 chunks with 3 stripes each. | |
408 | */ | |
409 | #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 | |
7ae9c09d | 410 | #define BTRFS_LABEL_SIZE 256 |
0b86a832 | 411 | |
af31f5e5 CM |
412 | /* |
413 | * just in case we somehow lose the roots and are not able to mount, | |
414 | * we store an array of the roots from previous transactions | |
415 | * in the super. | |
416 | */ | |
417 | #define BTRFS_NUM_BACKUP_ROOTS 4 | |
418 | struct btrfs_root_backup { | |
419 | __le64 tree_root; | |
420 | __le64 tree_root_gen; | |
421 | ||
422 | __le64 chunk_root; | |
423 | __le64 chunk_root_gen; | |
424 | ||
425 | __le64 extent_root; | |
426 | __le64 extent_root_gen; | |
427 | ||
428 | __le64 fs_root; | |
429 | __le64 fs_root_gen; | |
430 | ||
431 | __le64 dev_root; | |
432 | __le64 dev_root_gen; | |
433 | ||
434 | __le64 csum_root; | |
435 | __le64 csum_root_gen; | |
436 | ||
437 | __le64 total_bytes; | |
438 | __le64 bytes_used; | |
439 | __le64 num_devices; | |
440 | /* future */ | |
d1423248 | 441 | __le64 unused_64[4]; |
af31f5e5 CM |
442 | |
443 | u8 tree_root_level; | |
444 | u8 chunk_root_level; | |
445 | u8 extent_root_level; | |
446 | u8 fs_root_level; | |
447 | u8 dev_root_level; | |
448 | u8 csum_root_level; | |
449 | /* future and to align */ | |
450 | u8 unused_8[10]; | |
451 | } __attribute__ ((__packed__)); | |
452 | ||
fec577fb CM |
453 | /* |
454 | * the super block basically lists the main trees of the FS | |
455 | * it currently lacks any block count etc etc | |
456 | */ | |
234b63a0 | 457 | struct btrfs_super_block { |
f254e52c | 458 | u8 csum[BTRFS_CSUM_SIZE]; |
63b10fc4 | 459 | /* the first 4 fields must match struct btrfs_header */ |
2b82032c | 460 | u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ |
db94535d | 461 | __le64 bytenr; /* this block number */ |
63b10fc4 | 462 | __le64 flags; |
e17cade2 CM |
463 | |
464 | /* allowed to be different from the btrfs_header from here own down */ | |
3768f368 | 465 | __le64 magic; |
3768f368 CM |
466 | __le64 generation; |
467 | __le64 root; | |
0b86a832 | 468 | __le64 chunk_root; |
e02119d5 | 469 | __le64 log_root; |
c3027eb5 CM |
470 | |
471 | /* this will help find the new super based on the log root */ | |
472 | __le64 log_root_transid; | |
db94535d CM |
473 | __le64 total_bytes; |
474 | __le64 bytes_used; | |
2e635a27 | 475 | __le64 root_dir_objectid; |
8a4b83cc | 476 | __le64 num_devices; |
5f39d397 CM |
477 | __le32 sectorsize; |
478 | __le32 nodesize; | |
707e8a07 | 479 | __le32 __unused_leafsize; |
87ee04eb | 480 | __le32 stripesize; |
0b86a832 | 481 | __le32 sys_chunk_array_size; |
84234f3a | 482 | __le64 chunk_root_generation; |
f2b636e8 JB |
483 | __le64 compat_flags; |
484 | __le64 compat_ro_flags; | |
485 | __le64 incompat_flags; | |
607d432d | 486 | __le16 csum_type; |
db94535d | 487 | u8 root_level; |
0b86a832 | 488 | u8 chunk_root_level; |
e02119d5 | 489 | u8 log_root_level; |
0d81ba5d | 490 | struct btrfs_dev_item dev_item; |
c3027eb5 | 491 | |
7ae9c09d | 492 | char label[BTRFS_LABEL_SIZE]; |
c3027eb5 | 493 | |
0af3d00b | 494 | __le64 cache_generation; |
26432799 | 495 | __le64 uuid_tree_generation; |
0af3d00b | 496 | |
c3027eb5 | 497 | /* future expansion */ |
26432799 | 498 | __le64 reserved[30]; |
0b86a832 | 499 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; |
af31f5e5 | 500 | struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS]; |
cfaa7295 CM |
501 | } __attribute__ ((__packed__)); |
502 | ||
f2b636e8 JB |
503 | /* |
504 | * Compat flags that we support. If any incompat flags are set other than the | |
505 | * ones specified below then we will fail to mount | |
506 | */ | |
208acb8c OS |
507 | #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0) |
508 | ||
5d4f98a2 | 509 | #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) |
0af3d00b | 510 | #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1) |
67377734 | 511 | #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2) |
a6fa6fae | 512 | #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3) |
727011e0 CM |
513 | /* |
514 | * some patches floated around with a second compression method | |
515 | * lets save that incompat here for when they do get in | |
516 | * Note we don't actually support it, we're just reserving the | |
517 | * number | |
518 | */ | |
519 | #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4) | |
520 | ||
521 | /* | |
522 | * older kernels tried to do bigger metadata blocks, but the | |
523 | * code was pretty buggy. Lets not let them try anymore. | |
524 | */ | |
525 | #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5) | |
5d4f98a2 | 526 | |
f186373f | 527 | #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6) |
53b381b3 | 528 | #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7) |
3173a18f | 529 | #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8) |
16e7549f | 530 | #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) |
f186373f | 531 | |
5d4f98a2 | 532 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL |
2eaa055f JM |
533 | #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL |
534 | #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL | |
70f6d82e OS |
535 | |
536 | #define BTRFS_FEATURE_COMPAT_RO_SUPP \ | |
537 | (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE) | |
538 | ||
2eaa055f JM |
539 | #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL |
540 | #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL | |
541 | ||
0af3d00b JB |
542 | #define BTRFS_FEATURE_INCOMPAT_SUPP \ |
543 | (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ | |
67377734 | 544 | BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \ |
a6fa6fae | 545 | BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \ |
727011e0 | 546 | BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \ |
f186373f | 547 | BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \ |
53b381b3 | 548 | BTRFS_FEATURE_INCOMPAT_RAID56 | \ |
3173a18f | 549 | BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \ |
16e7549f JB |
550 | BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \ |
551 | BTRFS_FEATURE_INCOMPAT_NO_HOLES) | |
f2b636e8 | 552 | |
2eaa055f JM |
553 | #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \ |
554 | (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF) | |
555 | #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL | |
f2b636e8 | 556 | |
fec577fb | 557 | /* |
62e2749e | 558 | * A leaf is full of items. offset and size tell us where to find |
fec577fb CM |
559 | * the item in the leaf (relative to the start of the data area) |
560 | */ | |
0783fcfc | 561 | struct btrfs_item { |
e2fa7227 | 562 | struct btrfs_disk_key key; |
123abc88 | 563 | __le32 offset; |
5f39d397 | 564 | __le32 size; |
eb60ceac CM |
565 | } __attribute__ ((__packed__)); |
566 | ||
fec577fb CM |
567 | /* |
568 | * leaves have an item area and a data area: | |
569 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
570 | * | |
571 | * The data is separate from the items to get the keys closer together | |
572 | * during searches. | |
573 | */ | |
234b63a0 | 574 | struct btrfs_leaf { |
bb492bb0 | 575 | struct btrfs_header header; |
123abc88 | 576 | struct btrfs_item items[]; |
eb60ceac CM |
577 | } __attribute__ ((__packed__)); |
578 | ||
fec577fb CM |
579 | /* |
580 | * all non-leaf blocks are nodes, they hold only keys and pointers to | |
581 | * other blocks | |
582 | */ | |
123abc88 CM |
583 | struct btrfs_key_ptr { |
584 | struct btrfs_disk_key key; | |
585 | __le64 blockptr; | |
74493f7a | 586 | __le64 generation; |
123abc88 CM |
587 | } __attribute__ ((__packed__)); |
588 | ||
234b63a0 | 589 | struct btrfs_node { |
bb492bb0 | 590 | struct btrfs_header header; |
123abc88 | 591 | struct btrfs_key_ptr ptrs[]; |
eb60ceac CM |
592 | } __attribute__ ((__packed__)); |
593 | ||
fec577fb | 594 | /* |
234b63a0 CM |
595 | * btrfs_paths remember the path taken from the root down to the leaf. |
596 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | |
fec577fb CM |
597 | * to any other levels that are present. |
598 | * | |
599 | * The slots array records the index of the item or block pointer | |
600 | * used while walking the tree. | |
601 | */ | |
e4058b54 | 602 | enum { READA_NONE = 0, READA_BACK, READA_FORWARD }; |
234b63a0 | 603 | struct btrfs_path { |
5f39d397 | 604 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
234b63a0 | 605 | int slots[BTRFS_MAX_LEVEL]; |
925baedd | 606 | /* if there is real range locking, this locks field will change */ |
4fb72bf2 | 607 | u8 locks[BTRFS_MAX_LEVEL]; |
dccabfad | 608 | u8 reada; |
925baedd | 609 | /* keep some upper locks as we walk down */ |
7853f15b | 610 | u8 lowest_level; |
459931ec CM |
611 | |
612 | /* | |
613 | * set by btrfs_split_item, tells search_slot to keep all locks | |
614 | * and to force calls to keep space in the nodes | |
615 | */ | |
b9473439 CM |
616 | unsigned int search_for_split:1; |
617 | unsigned int keep_locks:1; | |
618 | unsigned int skip_locking:1; | |
619 | unsigned int leave_spinning:1; | |
5d4f98a2 | 620 | unsigned int search_commit_root:1; |
3f8a18cc | 621 | unsigned int need_commit_sem:1; |
5f5bc6b1 | 622 | unsigned int skip_release_on_error:1; |
eb60ceac | 623 | }; |
5de08d7d | 624 | |
62e2749e CM |
625 | /* |
626 | * items in the extent btree are used to record the objectid of the | |
627 | * owner of the block and the number of references | |
628 | */ | |
5d4f98a2 | 629 | |
62e2749e | 630 | struct btrfs_extent_item { |
5d4f98a2 YZ |
631 | __le64 refs; |
632 | __le64 generation; | |
633 | __le64 flags; | |
634 | } __attribute__ ((__packed__)); | |
635 | ||
636 | struct btrfs_extent_item_v0 { | |
62e2749e | 637 | __le32 refs; |
74493f7a CM |
638 | } __attribute__ ((__packed__)); |
639 | ||
5d4f98a2 YZ |
640 | #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \ |
641 | sizeof(struct btrfs_item)) | |
642 | ||
643 | #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0) | |
644 | #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1) | |
645 | ||
646 | /* following flags only apply to tree blocks */ | |
647 | ||
648 | /* use full backrefs for extent pointers in the block */ | |
649 | #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) | |
650 | ||
a2de733c AJ |
651 | /* |
652 | * this flag is only used internally by scrub and may be changed at any time | |
653 | * it is only declared here to avoid collisions | |
654 | */ | |
655 | #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48) | |
656 | ||
5d4f98a2 YZ |
657 | struct btrfs_tree_block_info { |
658 | struct btrfs_disk_key key; | |
659 | u8 level; | |
660 | } __attribute__ ((__packed__)); | |
661 | ||
662 | struct btrfs_extent_data_ref { | |
663 | __le64 root; | |
664 | __le64 objectid; | |
665 | __le64 offset; | |
666 | __le32 count; | |
667 | } __attribute__ ((__packed__)); | |
668 | ||
669 | struct btrfs_shared_data_ref { | |
670 | __le32 count; | |
671 | } __attribute__ ((__packed__)); | |
672 | ||
673 | struct btrfs_extent_inline_ref { | |
674 | u8 type; | |
1bec1aed | 675 | __le64 offset; |
5d4f98a2 YZ |
676 | } __attribute__ ((__packed__)); |
677 | ||
678 | /* old style backrefs item */ | |
679 | struct btrfs_extent_ref_v0 { | |
74493f7a CM |
680 | __le64 root; |
681 | __le64 generation; | |
682 | __le64 objectid; | |
5d4f98a2 | 683 | __le32 count; |
62e2749e CM |
684 | } __attribute__ ((__packed__)); |
685 | ||
5d4f98a2 | 686 | |
0b86a832 CM |
687 | /* dev extents record free space on individual devices. The owner |
688 | * field points back to the chunk allocation mapping tree that allocated | |
e17cade2 | 689 | * the extent. The chunk tree uuid field is a way to double check the owner |
0b86a832 CM |
690 | */ |
691 | struct btrfs_dev_extent { | |
e17cade2 CM |
692 | __le64 chunk_tree; |
693 | __le64 chunk_objectid; | |
694 | __le64 chunk_offset; | |
0b86a832 | 695 | __le64 length; |
e17cade2 | 696 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
0b86a832 CM |
697 | } __attribute__ ((__packed__)); |
698 | ||
3954401f | 699 | struct btrfs_inode_ref { |
aec7477b | 700 | __le64 index; |
3954401f CM |
701 | __le16 name_len; |
702 | /* name goes here */ | |
703 | } __attribute__ ((__packed__)); | |
704 | ||
f186373f MF |
705 | struct btrfs_inode_extref { |
706 | __le64 parent_objectid; | |
707 | __le64 index; | |
708 | __le16 name_len; | |
709 | __u8 name[0]; | |
710 | /* name goes here */ | |
711 | } __attribute__ ((__packed__)); | |
712 | ||
0b86a832 | 713 | struct btrfs_timespec { |
f254e52c | 714 | __le64 sec; |
1e1d2701 CM |
715 | __le32 nsec; |
716 | } __attribute__ ((__packed__)); | |
717 | ||
95029d7d | 718 | enum btrfs_compression_type { |
261507a0 LZ |
719 | BTRFS_COMPRESS_NONE = 0, |
720 | BTRFS_COMPRESS_ZLIB = 1, | |
a6fa6fae LZ |
721 | BTRFS_COMPRESS_LZO = 2, |
722 | BTRFS_COMPRESS_TYPES = 2, | |
723 | BTRFS_COMPRESS_LAST = 3, | |
95029d7d | 724 | }; |
c8b97818 | 725 | |
1e1d2701 | 726 | struct btrfs_inode_item { |
e02119d5 | 727 | /* nfs style generation number */ |
1e1d2701 | 728 | __le64 generation; |
e02119d5 CM |
729 | /* transid that last touched this inode */ |
730 | __le64 transid; | |
1e1d2701 | 731 | __le64 size; |
a76a3cd4 | 732 | __le64 nbytes; |
31f3c99b | 733 | __le64 block_group; |
1e1d2701 CM |
734 | __le32 nlink; |
735 | __le32 uid; | |
736 | __le32 gid; | |
737 | __le32 mode; | |
0b86a832 | 738 | __le64 rdev; |
f2b636e8 | 739 | __le64 flags; |
c8b97818 | 740 | |
c3027eb5 CM |
741 | /* modification sequence number for NFS */ |
742 | __le64 sequence; | |
743 | ||
744 | /* | |
745 | * a little future expansion, for more than this we can | |
746 | * just grow the inode item and version it | |
747 | */ | |
748 | __le64 reserved[4]; | |
0b86a832 CM |
749 | struct btrfs_timespec atime; |
750 | struct btrfs_timespec ctime; | |
751 | struct btrfs_timespec mtime; | |
752 | struct btrfs_timespec otime; | |
1e1d2701 CM |
753 | } __attribute__ ((__packed__)); |
754 | ||
e02119d5 CM |
755 | struct btrfs_dir_log_item { |
756 | __le64 end; | |
757 | } __attribute__ ((__packed__)); | |
758 | ||
62e2749e | 759 | struct btrfs_dir_item { |
d6e4a428 | 760 | struct btrfs_disk_key location; |
e02119d5 | 761 | __le64 transid; |
5103e947 | 762 | __le16 data_len; |
a8a2ee0c | 763 | __le16 name_len; |
62e2749e CM |
764 | u8 type; |
765 | } __attribute__ ((__packed__)); | |
766 | ||
b83cc969 LZ |
767 | #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) |
768 | ||
521e0546 DS |
769 | /* |
770 | * Internal in-memory flag that a subvolume has been marked for deletion but | |
771 | * still visible as a directory | |
772 | */ | |
773 | #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48) | |
774 | ||
62e2749e | 775 | struct btrfs_root_item { |
d6e4a428 | 776 | struct btrfs_inode_item inode; |
84234f3a | 777 | __le64 generation; |
d6e4a428 | 778 | __le64 root_dirid; |
db94535d CM |
779 | __le64 bytenr; |
780 | __le64 byte_limit; | |
781 | __le64 bytes_used; | |
80ff3856 | 782 | __le64 last_snapshot; |
f2b636e8 | 783 | __le64 flags; |
62e2749e | 784 | __le32 refs; |
5eda7b5e CM |
785 | struct btrfs_disk_key drop_progress; |
786 | u8 drop_level; | |
db94535d | 787 | u8 level; |
8ea05e3a AB |
788 | |
789 | /* | |
790 | * The following fields appear after subvol_uuids+subvol_times | |
791 | * were introduced. | |
792 | */ | |
793 | ||
794 | /* | |
795 | * This generation number is used to test if the new fields are valid | |
796 | * and up to date while reading the root item. Everytime the root item | |
797 | * is written out, the "generation" field is copied into this field. If | |
798 | * anyone ever mounted the fs with an older kernel, we will have | |
799 | * mismatching generation values here and thus must invalidate the | |
800 | * new fields. See btrfs_update_root and btrfs_find_last_root for | |
801 | * details. | |
802 | * the offset of generation_v2 is also used as the start for the memset | |
803 | * when invalidating the fields. | |
804 | */ | |
805 | __le64 generation_v2; | |
806 | u8 uuid[BTRFS_UUID_SIZE]; | |
807 | u8 parent_uuid[BTRFS_UUID_SIZE]; | |
808 | u8 received_uuid[BTRFS_UUID_SIZE]; | |
809 | __le64 ctransid; /* updated when an inode changes */ | |
810 | __le64 otransid; /* trans when created */ | |
811 | __le64 stransid; /* trans when sent. non-zero for received subvol */ | |
812 | __le64 rtransid; /* trans when received. non-zero for received subvol */ | |
813 | struct btrfs_timespec ctime; | |
814 | struct btrfs_timespec otime; | |
815 | struct btrfs_timespec stime; | |
816 | struct btrfs_timespec rtime; | |
817 | __le64 reserved[8]; /* for future */ | |
9f5fae2f | 818 | } __attribute__ ((__packed__)); |
62e2749e | 819 | |
0660b5af CM |
820 | /* |
821 | * this is used for both forward and backward root refs | |
822 | */ | |
823 | struct btrfs_root_ref { | |
824 | __le64 dirid; | |
825 | __le64 sequence; | |
826 | __le16 name_len; | |
827 | } __attribute__ ((__packed__)); | |
828 | ||
0940ebf6 ID |
829 | struct btrfs_disk_balance_args { |
830 | /* | |
831 | * profiles to operate on, single is denoted by | |
832 | * BTRFS_AVAIL_ALLOC_BIT_SINGLE | |
833 | */ | |
834 | __le64 profiles; | |
835 | ||
bc309467 DS |
836 | /* |
837 | * usage filter | |
838 | * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' | |
839 | * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max | |
840 | */ | |
841 | union { | |
842 | __le64 usage; | |
843 | struct { | |
844 | __le32 usage_min; | |
845 | __le32 usage_max; | |
846 | }; | |
847 | }; | |
0940ebf6 ID |
848 | |
849 | /* devid filter */ | |
850 | __le64 devid; | |
851 | ||
852 | /* devid subset filter [pstart..pend) */ | |
853 | __le64 pstart; | |
854 | __le64 pend; | |
855 | ||
856 | /* btrfs virtual address space subset filter [vstart..vend) */ | |
857 | __le64 vstart; | |
858 | __le64 vend; | |
859 | ||
860 | /* | |
861 | * profile to convert to, single is denoted by | |
862 | * BTRFS_AVAIL_ALLOC_BIT_SINGLE | |
863 | */ | |
864 | __le64 target; | |
865 | ||
866 | /* BTRFS_BALANCE_ARGS_* */ | |
867 | __le64 flags; | |
868 | ||
12907fc7 DS |
869 | /* |
870 | * BTRFS_BALANCE_ARGS_LIMIT with value 'limit' | |
871 | * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum | |
872 | * and maximum | |
873 | */ | |
874 | union { | |
875 | __le64 limit; | |
876 | struct { | |
877 | __le32 limit_min; | |
878 | __le32 limit_max; | |
879 | }; | |
880 | }; | |
7d824b6f | 881 | |
dee32d0a GAP |
882 | /* |
883 | * Process chunks that cross stripes_min..stripes_max devices, | |
884 | * BTRFS_BALANCE_ARGS_STRIPES_RANGE | |
885 | */ | |
886 | __le32 stripes_min; | |
887 | __le32 stripes_max; | |
888 | ||
889 | __le64 unused[6]; | |
0940ebf6 ID |
890 | } __attribute__ ((__packed__)); |
891 | ||
892 | /* | |
893 | * store balance parameters to disk so that balance can be properly | |
894 | * resumed after crash or unmount | |
895 | */ | |
896 | struct btrfs_balance_item { | |
897 | /* BTRFS_BALANCE_* */ | |
898 | __le64 flags; | |
899 | ||
900 | struct btrfs_disk_balance_args data; | |
901 | struct btrfs_disk_balance_args meta; | |
902 | struct btrfs_disk_balance_args sys; | |
903 | ||
904 | __le64 unused[4]; | |
905 | } __attribute__ ((__packed__)); | |
906 | ||
d899e052 YZ |
907 | #define BTRFS_FILE_EXTENT_INLINE 0 |
908 | #define BTRFS_FILE_EXTENT_REG 1 | |
909 | #define BTRFS_FILE_EXTENT_PREALLOC 2 | |
236454df | 910 | |
9f5fae2f | 911 | struct btrfs_file_extent_item { |
c8b97818 CM |
912 | /* |
913 | * transaction id that created this extent | |
914 | */ | |
71951f35 | 915 | __le64 generation; |
c8b97818 CM |
916 | /* |
917 | * max number of bytes to hold this extent in ram | |
918 | * when we split a compressed extent we can't know how big | |
919 | * each of the resulting pieces will be. So, this is | |
920 | * an upper limit on the size of the extent in ram instead of | |
921 | * an exact limit. | |
922 | */ | |
923 | __le64 ram_bytes; | |
924 | ||
925 | /* | |
926 | * 32 bits for the various ways we might encode the data, | |
927 | * including compression and encryption. If any of these | |
928 | * are set to something a given disk format doesn't understand | |
929 | * it is treated like an incompat flag for reading and writing, | |
930 | * but not for stat. | |
931 | */ | |
932 | u8 compression; | |
933 | u8 encryption; | |
934 | __le16 other_encoding; /* spare for later use */ | |
935 | ||
936 | /* are we inline data or a real extent? */ | |
236454df | 937 | u8 type; |
c8b97818 | 938 | |
9f5fae2f CM |
939 | /* |
940 | * disk space consumed by the extent, checksum blocks are included | |
941 | * in these numbers | |
7ec20afb DS |
942 | * |
943 | * At this offset in the structure, the inline extent data start. | |
9f5fae2f | 944 | */ |
db94535d CM |
945 | __le64 disk_bytenr; |
946 | __le64 disk_num_bytes; | |
9f5fae2f | 947 | /* |
dee26a9f | 948 | * the logical offset in file blocks (no csums) |
9f5fae2f CM |
949 | * this extent record is for. This allows a file extent to point |
950 | * into the middle of an existing extent on disk, sharing it | |
951 | * between two snapshots (useful if some bytes in the middle of the | |
952 | * extent have changed | |
953 | */ | |
954 | __le64 offset; | |
955 | /* | |
c8b97818 CM |
956 | * the logical number of file blocks (no csums included). This |
957 | * always reflects the size uncompressed and without encoding. | |
9f5fae2f | 958 | */ |
db94535d | 959 | __le64 num_bytes; |
c8b97818 | 960 | |
9f5fae2f CM |
961 | } __attribute__ ((__packed__)); |
962 | ||
f254e52c | 963 | struct btrfs_csum_item { |
509659cd | 964 | u8 csum; |
f254e52c CM |
965 | } __attribute__ ((__packed__)); |
966 | ||
733f4fbb SB |
967 | struct btrfs_dev_stats_item { |
968 | /* | |
969 | * grow this item struct at the end for future enhancements and keep | |
970 | * the existing values unchanged | |
971 | */ | |
972 | __le64 values[BTRFS_DEV_STAT_VALUES_MAX]; | |
973 | } __attribute__ ((__packed__)); | |
974 | ||
e922e087 SB |
975 | #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0 |
976 | #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1 | |
977 | #define BTRFS_DEV_REPLACE_ITEM_STATE_NEVER_STARTED 0 | |
978 | #define BTRFS_DEV_REPLACE_ITEM_STATE_STARTED 1 | |
979 | #define BTRFS_DEV_REPLACE_ITEM_STATE_SUSPENDED 2 | |
980 | #define BTRFS_DEV_REPLACE_ITEM_STATE_FINISHED 3 | |
981 | #define BTRFS_DEV_REPLACE_ITEM_STATE_CANCELED 4 | |
982 | ||
983 | struct btrfs_dev_replace { | |
984 | u64 replace_state; /* see #define above */ | |
985 | u64 time_started; /* seconds since 1-Jan-1970 */ | |
986 | u64 time_stopped; /* seconds since 1-Jan-1970 */ | |
987 | atomic64_t num_write_errors; | |
988 | atomic64_t num_uncorrectable_read_errors; | |
989 | ||
990 | u64 cursor_left; | |
991 | u64 committed_cursor_left; | |
992 | u64 cursor_left_last_write_of_item; | |
993 | u64 cursor_right; | |
994 | ||
995 | u64 cont_reading_from_srcdev_mode; /* see #define above */ | |
996 | ||
997 | int is_valid; | |
998 | int item_needs_writeback; | |
999 | struct btrfs_device *srcdev; | |
1000 | struct btrfs_device *tgtdev; | |
1001 | ||
1002 | pid_t lock_owner; | |
1003 | atomic_t nesting_level; | |
1004 | struct mutex lock_finishing_cancel_unmount; | |
73beece9 LB |
1005 | rwlock_t lock; |
1006 | atomic_t read_locks; | |
1007 | atomic_t blocking_readers; | |
1008 | wait_queue_head_t read_lock_wq; | |
e922e087 SB |
1009 | |
1010 | struct btrfs_scrub_progress scrub_progress; | |
1011 | }; | |
1012 | ||
a2bff640 SB |
1013 | struct btrfs_dev_replace_item { |
1014 | /* | |
1015 | * grow this item struct at the end for future enhancements and keep | |
1016 | * the existing values unchanged | |
1017 | */ | |
1018 | __le64 src_devid; | |
1019 | __le64 cursor_left; | |
1020 | __le64 cursor_right; | |
1021 | __le64 cont_reading_from_srcdev_mode; | |
1022 | ||
1023 | __le64 replace_state; | |
1024 | __le64 time_started; | |
1025 | __le64 time_stopped; | |
1026 | __le64 num_write_errors; | |
1027 | __le64 num_uncorrectable_read_errors; | |
1028 | } __attribute__ ((__packed__)); | |
1029 | ||
0b86a832 | 1030 | /* different types of block groups (and chunks) */ |
52ba6929 ID |
1031 | #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) |
1032 | #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) | |
1033 | #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2) | |
1034 | #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3) | |
1035 | #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4) | |
1036 | #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5) | |
1037 | #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6) | |
1c89cdd1 AP |
1038 | #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7) |
1039 | #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) | |
36523e95 DS |
1040 | #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ |
1041 | BTRFS_SPACE_INFO_GLOBAL_RSV) | |
e6ec716f MX |
1042 | |
1043 | enum btrfs_raid_types { | |
1044 | BTRFS_RAID_RAID10, | |
1045 | BTRFS_RAID_RAID1, | |
1046 | BTRFS_RAID_DUP, | |
1047 | BTRFS_RAID_RAID0, | |
1048 | BTRFS_RAID_SINGLE, | |
e942f883 CM |
1049 | BTRFS_RAID_RAID5, |
1050 | BTRFS_RAID_RAID6, | |
e6ec716f MX |
1051 | BTRFS_NR_RAID_TYPES |
1052 | }; | |
52ba6929 ID |
1053 | |
1054 | #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ | |
1055 | BTRFS_BLOCK_GROUP_SYSTEM | \ | |
1056 | BTRFS_BLOCK_GROUP_METADATA) | |
1057 | ||
1058 | #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ | |
1059 | BTRFS_BLOCK_GROUP_RAID1 | \ | |
53b381b3 DW |
1060 | BTRFS_BLOCK_GROUP_RAID5 | \ |
1061 | BTRFS_BLOCK_GROUP_RAID6 | \ | |
52ba6929 ID |
1062 | BTRFS_BLOCK_GROUP_DUP | \ |
1063 | BTRFS_BLOCK_GROUP_RAID10) | |
ffe2d203 ZL |
1064 | #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \ |
1065 | BTRFS_BLOCK_GROUP_RAID6) | |
1066 | ||
a46d11a8 ID |
1067 | /* |
1068 | * We need a bit for restriper to be able to tell when chunks of type | |
1069 | * SINGLE are available. This "extended" profile format is used in | |
1070 | * fs_info->avail_*_alloc_bits (in-memory) and balance item fields | |
1071 | * (on-disk). The corresponding on-disk bit in chunk.type is reserved | |
1072 | * to avoid remappings between two formats in future. | |
1073 | */ | |
1074 | #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48) | |
1075 | ||
36523e95 DS |
1076 | /* |
1077 | * A fake block group type that is used to communicate global block reserve | |
1078 | * size to userspace via the SPACE_INFO ioctl. | |
1079 | */ | |
1080 | #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49) | |
1081 | ||
899c81ea ID |
1082 | #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \ |
1083 | BTRFS_AVAIL_ALLOC_BIT_SINGLE) | |
1084 | ||
1085 | static inline u64 chunk_to_extended(u64 flags) | |
1086 | { | |
1087 | if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0) | |
1088 | flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE; | |
1089 | ||
1090 | return flags; | |
1091 | } | |
1092 | static inline u64 extended_to_chunk(u64 flags) | |
1093 | { | |
1094 | return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; | |
1095 | } | |
1096 | ||
9078a3e1 CM |
1097 | struct btrfs_block_group_item { |
1098 | __le64 used; | |
0b86a832 CM |
1099 | __le64 chunk_objectid; |
1100 | __le64 flags; | |
9078a3e1 CM |
1101 | } __attribute__ ((__packed__)); |
1102 | ||
208acb8c OS |
1103 | struct btrfs_free_space_info { |
1104 | __le32 extent_count; | |
1105 | __le32 flags; | |
1106 | } __attribute__ ((__packed__)); | |
1107 | ||
1108 | #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0) | |
1109 | ||
8465ecec QW |
1110 | #define BTRFS_QGROUP_LEVEL_SHIFT 48 |
1111 | static inline u64 btrfs_qgroup_level(u64 qgroupid) | |
1112 | { | |
1113 | return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT; | |
1114 | } | |
1115 | ||
630dc772 AJ |
1116 | /* |
1117 | * is subvolume quota turned on? | |
1118 | */ | |
1119 | #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) | |
1120 | /* | |
2f232036 | 1121 | * RESCAN is set during the initialization phase |
630dc772 | 1122 | */ |
2f232036 | 1123 | #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1) |
630dc772 AJ |
1124 | /* |
1125 | * Some qgroup entries are known to be out of date, | |
1126 | * either because the configuration has changed in a way that | |
1127 | * makes a rescan necessary, or because the fs has been mounted | |
1128 | * with a non-qgroup-aware version. | |
1129 | * Turning qouta off and on again makes it inconsistent, too. | |
1130 | */ | |
1131 | #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) | |
1132 | ||
1133 | #define BTRFS_QGROUP_STATUS_VERSION 1 | |
1134 | ||
1135 | struct btrfs_qgroup_status_item { | |
1136 | __le64 version; | |
1137 | /* | |
1138 | * the generation is updated during every commit. As older | |
1139 | * versions of btrfs are not aware of qgroups, it will be | |
1140 | * possible to detect inconsistencies by checking the | |
1141 | * generation on mount time | |
1142 | */ | |
1143 | __le64 generation; | |
1144 | ||
1145 | /* flag definitions see above */ | |
1146 | __le64 flags; | |
1147 | ||
1148 | /* | |
1149 | * only used during scanning to record the progress | |
1150 | * of the scan. It contains a logical address | |
1151 | */ | |
2f232036 | 1152 | __le64 rescan; |
630dc772 AJ |
1153 | } __attribute__ ((__packed__)); |
1154 | ||
1155 | struct btrfs_qgroup_info_item { | |
1156 | __le64 generation; | |
1157 | __le64 rfer; | |
1158 | __le64 rfer_cmpr; | |
1159 | __le64 excl; | |
1160 | __le64 excl_cmpr; | |
1161 | } __attribute__ ((__packed__)); | |
1162 | ||
1163 | /* flags definition for qgroup limits */ | |
1164 | #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) | |
1165 | #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) | |
1166 | #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) | |
1167 | #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) | |
1168 | #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) | |
1169 | #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) | |
1170 | ||
1171 | struct btrfs_qgroup_limit_item { | |
1172 | /* | |
1173 | * only updated when any of the other values change | |
1174 | */ | |
1175 | __le64 flags; | |
1176 | __le64 max_rfer; | |
1177 | __le64 max_excl; | |
1178 | __le64 rsv_rfer; | |
1179 | __le64 rsv_excl; | |
1180 | } __attribute__ ((__packed__)); | |
1181 | ||
c1895442 JM |
1182 | /* For raid type sysfs entries */ |
1183 | struct raid_kobject { | |
1184 | int raid_type; | |
1185 | struct kobject kobj; | |
1186 | }; | |
1187 | ||
6324fbf3 | 1188 | struct btrfs_space_info { |
26b47ff6 | 1189 | spinlock_t lock; |
6a63209f | 1190 | |
89a55897 JB |
1191 | u64 total_bytes; /* total bytes in the space, |
1192 | this doesn't take mirrors into account */ | |
b742bb82 | 1193 | u64 bytes_used; /* total bytes used, |
e9c54999 | 1194 | this doesn't take mirrors into account */ |
6a63209f JB |
1195 | u64 bytes_pinned; /* total bytes pinned, will be freed when the |
1196 | transaction finishes */ | |
1197 | u64 bytes_reserved; /* total bytes the allocator has reserved for | |
1198 | current allocations */ | |
6a63209f | 1199 | u64 bytes_may_use; /* number of bytes that may be used for |
9ed74f2d | 1200 | delalloc/allocations */ |
26b47ff6 MX |
1201 | u64 bytes_readonly; /* total bytes that are read only */ |
1202 | ||
4f4db217 JB |
1203 | u64 max_extent_size; /* This will hold the maximum extent size of |
1204 | the space info if we had an ENOSPC in the | |
1205 | allocator. */ | |
1206 | ||
26b47ff6 MX |
1207 | unsigned int full:1; /* indicates that we cannot allocate any more |
1208 | chunks for this space */ | |
1209 | unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ | |
1210 | ||
1211 | unsigned int flush:1; /* set if we are trying to make space */ | |
1212 | ||
1213 | unsigned int force_alloc; /* set if we need to force a chunk | |
1214 | alloc for this space */ | |
1215 | ||
b742bb82 | 1216 | u64 disk_used; /* total bytes used on disk */ |
89a55897 JB |
1217 | u64 disk_total; /* total bytes on disk, takes mirrors into |
1218 | account */ | |
6a63209f | 1219 | |
26b47ff6 MX |
1220 | u64 flags; |
1221 | ||
b150a4f1 JB |
1222 | /* |
1223 | * bytes_pinned is kept in line with what is actually pinned, as in | |
1224 | * we've called update_block_group and dropped the bytes_used counter | |
1225 | * and increased the bytes_pinned counter. However this means that | |
1226 | * bytes_pinned does not reflect the bytes that will be pinned once the | |
1227 | * delayed refs are flushed, so this counter is inc'ed everytime we call | |
1228 | * btrfs_free_extent so it is a realtime count of what will be freed | |
1229 | * once the transaction is committed. It will be zero'ed everytime the | |
1230 | * transaction commits. | |
1231 | */ | |
1232 | struct percpu_counter total_bytes_pinned; | |
1233 | ||
6324fbf3 | 1234 | struct list_head list; |
75c68e9f | 1235 | /* Protected by the spinlock 'lock'. */ |
633c0aad | 1236 | struct list_head ro_bgs; |
0f9dd46c | 1237 | |
26b47ff6 | 1238 | struct rw_semaphore groups_sem; |
0f9dd46c | 1239 | /* for block groups in our same type */ |
b742bb82 | 1240 | struct list_head block_groups[BTRFS_NR_RAID_TYPES]; |
fdb5effd | 1241 | wait_queue_head_t wait; |
6ab0a202 JM |
1242 | |
1243 | struct kobject kobj; | |
c1895442 | 1244 | struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; |
0f9dd46c JB |
1245 | }; |
1246 | ||
66d8f3dd MX |
1247 | #define BTRFS_BLOCK_RSV_GLOBAL 1 |
1248 | #define BTRFS_BLOCK_RSV_DELALLOC 2 | |
1249 | #define BTRFS_BLOCK_RSV_TRANS 3 | |
1250 | #define BTRFS_BLOCK_RSV_CHUNK 4 | |
1251 | #define BTRFS_BLOCK_RSV_DELOPS 5 | |
1252 | #define BTRFS_BLOCK_RSV_EMPTY 6 | |
1253 | #define BTRFS_BLOCK_RSV_TEMP 7 | |
1254 | ||
f0486c68 YZ |
1255 | struct btrfs_block_rsv { |
1256 | u64 size; | |
1257 | u64 reserved; | |
f0486c68 | 1258 | struct btrfs_space_info *space_info; |
f0486c68 | 1259 | spinlock_t lock; |
66d8f3dd MX |
1260 | unsigned short full; |
1261 | unsigned short type; | |
1262 | unsigned short failfast; | |
f0486c68 YZ |
1263 | }; |
1264 | ||
fa9c0d79 CM |
1265 | /* |
1266 | * free clusters are used to claim free space in relatively large chunks, | |
1267 | * allowing us to do less seeky writes. They are used for all metadata | |
1268 | * allocations and data allocations in ssd mode. | |
1269 | */ | |
1270 | struct btrfs_free_cluster { | |
1271 | spinlock_t lock; | |
1272 | spinlock_t refill_lock; | |
1273 | struct rb_root root; | |
1274 | ||
1275 | /* largest extent in this cluster */ | |
1276 | u64 max_size; | |
1277 | ||
1278 | /* first extent starting offset */ | |
1279 | u64 window_start; | |
1280 | ||
c759c4e1 JB |
1281 | /* We did a full search and couldn't create a cluster */ |
1282 | bool fragmented; | |
1283 | ||
fa9c0d79 CM |
1284 | struct btrfs_block_group_cache *block_group; |
1285 | /* | |
1286 | * when a cluster is allocated from a block group, we put the | |
1287 | * cluster onto a list in the block group so that it can | |
1288 | * be freed before the block group is freed. | |
1289 | */ | |
1290 | struct list_head block_group_list; | |
6324fbf3 CM |
1291 | }; |
1292 | ||
817d52f8 JB |
1293 | enum btrfs_caching_type { |
1294 | BTRFS_CACHE_NO = 0, | |
1295 | BTRFS_CACHE_STARTED = 1, | |
291c7d2f JB |
1296 | BTRFS_CACHE_FAST = 2, |
1297 | BTRFS_CACHE_FINISHED = 3, | |
36cce922 | 1298 | BTRFS_CACHE_ERROR = 4, |
817d52f8 JB |
1299 | }; |
1300 | ||
0af3d00b JB |
1301 | enum btrfs_disk_cache_state { |
1302 | BTRFS_DC_WRITTEN = 0, | |
1303 | BTRFS_DC_ERROR = 1, | |
1304 | BTRFS_DC_CLEAR = 2, | |
1305 | BTRFS_DC_SETUP = 3, | |
0af3d00b JB |
1306 | }; |
1307 | ||
11833d66 YZ |
1308 | struct btrfs_caching_control { |
1309 | struct list_head list; | |
1310 | struct mutex mutex; | |
1311 | wait_queue_head_t wait; | |
bab39bf9 | 1312 | struct btrfs_work work; |
11833d66 YZ |
1313 | struct btrfs_block_group_cache *block_group; |
1314 | u64 progress; | |
1315 | atomic_t count; | |
1316 | }; | |
1317 | ||
73fa48b6 OS |
1318 | /* Once caching_thread() finds this much free space, it will wake up waiters. */ |
1319 | #define CACHING_CTL_WAKE_UP (1024 * 1024 * 2) | |
1320 | ||
4c6d1d85 CM |
1321 | struct btrfs_io_ctl { |
1322 | void *cur, *orig; | |
1323 | struct page *page; | |
1324 | struct page **pages; | |
1325 | struct btrfs_root *root; | |
c9dc4c65 | 1326 | struct inode *inode; |
4c6d1d85 CM |
1327 | unsigned long size; |
1328 | int index; | |
1329 | int num_pages; | |
c9dc4c65 CM |
1330 | int entries; |
1331 | int bitmaps; | |
4c6d1d85 CM |
1332 | unsigned check_crcs:1; |
1333 | }; | |
1334 | ||
9078a3e1 CM |
1335 | struct btrfs_block_group_cache { |
1336 | struct btrfs_key key; | |
1337 | struct btrfs_block_group_item item; | |
817d52f8 | 1338 | struct btrfs_fs_info *fs_info; |
0af3d00b | 1339 | struct inode *inode; |
c286ac48 | 1340 | spinlock_t lock; |
324ae4df | 1341 | u64 pinned; |
e8569813 | 1342 | u64 reserved; |
e570fd27 | 1343 | u64 delalloc_bytes; |
1b2da372 | 1344 | u64 bytes_super; |
0b86a832 | 1345 | u64 flags; |
5b0e95bf | 1346 | u64 cache_generation; |
a5ed9182 OS |
1347 | u32 sectorsize; |
1348 | ||
1349 | /* | |
1350 | * If the free space extent count exceeds this number, convert the block | |
1351 | * group to bitmaps. | |
1352 | */ | |
1353 | u32 bitmap_high_thresh; | |
1354 | ||
1355 | /* | |
1356 | * If the free space extent count drops below this number, convert the | |
1357 | * block group back to extents. | |
1358 | */ | |
1359 | u32 bitmap_low_thresh; | |
53b381b3 | 1360 | |
e570fd27 MX |
1361 | /* |
1362 | * It is just used for the delayed data space allocation because | |
1363 | * only the data space allocation and the relative metadata update | |
1364 | * can be done cross the transaction. | |
1365 | */ | |
1366 | struct rw_semaphore data_rwsem; | |
1367 | ||
53b381b3 DW |
1368 | /* for raid56, this is a full stripe, without parity */ |
1369 | unsigned long full_stripe_len; | |
1370 | ||
868f401a | 1371 | unsigned int ro; |
0410c94a | 1372 | unsigned int iref:1; |
4f69cb98 | 1373 | unsigned int has_caching_ctl:1; |
04216820 | 1374 | unsigned int removed:1; |
0af3d00b JB |
1375 | |
1376 | int disk_cache_state; | |
0f9dd46c | 1377 | |
817d52f8 | 1378 | /* cache tracking stuff */ |
817d52f8 | 1379 | int cached; |
11833d66 YZ |
1380 | struct btrfs_caching_control *caching_ctl; |
1381 | u64 last_byte_to_unpin; | |
817d52f8 | 1382 | |
0f9dd46c JB |
1383 | struct btrfs_space_info *space_info; |
1384 | ||
1385 | /* free space cache stuff */ | |
34d52cb6 | 1386 | struct btrfs_free_space_ctl *free_space_ctl; |
0f9dd46c JB |
1387 | |
1388 | /* block group cache stuff */ | |
1389 | struct rb_node cache_node; | |
1390 | ||
1391 | /* for block groups in the same raid type */ | |
1392 | struct list_head list; | |
d2fb3437 YZ |
1393 | |
1394 | /* usage count */ | |
1395 | atomic_t count; | |
fa9c0d79 CM |
1396 | |
1397 | /* List of struct btrfs_free_clusters for this block group. | |
1398 | * Today it will only have one thing on it, but that may change | |
1399 | */ | |
1400 | struct list_head cluster_list; | |
ea658bad | 1401 | |
47ab2a6c JB |
1402 | /* For delayed block group creation or deletion of empty block groups */ |
1403 | struct list_head bg_list; | |
633c0aad JB |
1404 | |
1405 | /* For read-only block groups */ | |
1406 | struct list_head ro_list; | |
04216820 FM |
1407 | |
1408 | atomic_t trimming; | |
ce93ec54 JB |
1409 | |
1410 | /* For dirty block groups */ | |
1411 | struct list_head dirty_list; | |
c9dc4c65 CM |
1412 | struct list_head io_list; |
1413 | ||
1414 | struct btrfs_io_ctl io_ctl; | |
a5ed9182 OS |
1415 | |
1416 | /* Lock for free space tree operations. */ | |
1417 | struct mutex free_space_lock; | |
1418 | ||
1419 | /* | |
1420 | * Does the block group need to be added to the free space tree? | |
1421 | * Protected by free_space_lock. | |
1422 | */ | |
1423 | int needs_free_space; | |
9078a3e1 | 1424 | }; |
0b86a832 | 1425 | |
097b8a7c JS |
1426 | /* delayed seq elem */ |
1427 | struct seq_list { | |
1428 | struct list_head list; | |
1429 | u64 seq; | |
1430 | }; | |
1431 | ||
3284da7b DS |
1432 | #define SEQ_LIST_INIT(name) { .list = LIST_HEAD_INIT((name).list), .seq = 0 } |
1433 | ||
5d80366e JB |
1434 | enum btrfs_orphan_cleanup_state { |
1435 | ORPHAN_CLEANUP_STARTED = 1, | |
1436 | ORPHAN_CLEANUP_DONE = 2, | |
1437 | }; | |
1438 | ||
53b381b3 DW |
1439 | /* used by the raid56 code to lock stripes for read/modify/write */ |
1440 | struct btrfs_stripe_hash { | |
1441 | struct list_head hash_list; | |
1442 | wait_queue_head_t wait; | |
1443 | spinlock_t lock; | |
1444 | }; | |
1445 | ||
1446 | /* used by the raid56 code to lock stripes for read/modify/write */ | |
1447 | struct btrfs_stripe_hash_table { | |
4ae10b3a CM |
1448 | struct list_head stripe_cache; |
1449 | spinlock_t cache_lock; | |
1450 | int cache_size; | |
1451 | struct btrfs_stripe_hash table[]; | |
53b381b3 DW |
1452 | }; |
1453 | ||
1454 | #define BTRFS_STRIPE_HASH_TABLE_BITS 11 | |
1455 | ||
21c7e756 MX |
1456 | void btrfs_init_async_reclaim_work(struct work_struct *work); |
1457 | ||
097b8a7c | 1458 | /* fs_info */ |
5d4f98a2 | 1459 | struct reloc_control; |
0b86a832 | 1460 | struct btrfs_device; |
8a4b83cc | 1461 | struct btrfs_fs_devices; |
c9e9f97b | 1462 | struct btrfs_balance_control; |
16cdcec7 | 1463 | struct btrfs_delayed_root; |
9f5fae2f | 1464 | struct btrfs_fs_info { |
5f39d397 | 1465 | u8 fsid[BTRFS_FSID_SIZE]; |
e17cade2 | 1466 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
62e2749e CM |
1467 | struct btrfs_root *extent_root; |
1468 | struct btrfs_root *tree_root; | |
0b86a832 CM |
1469 | struct btrfs_root *chunk_root; |
1470 | struct btrfs_root *dev_root; | |
3de4586c | 1471 | struct btrfs_root *fs_root; |
d20f7043 | 1472 | struct btrfs_root *csum_root; |
416ac51d | 1473 | struct btrfs_root *quota_root; |
f7a81ea4 | 1474 | struct btrfs_root *uuid_root; |
a5ed9182 | 1475 | struct btrfs_root *free_space_root; |
e02119d5 CM |
1476 | |
1477 | /* the log root tree is a directory of all the other log roots */ | |
1478 | struct btrfs_root *log_root_tree; | |
4df27c4d YZ |
1479 | |
1480 | spinlock_t fs_roots_radix_lock; | |
0f7d52f4 | 1481 | struct radix_tree_root fs_roots_radix; |
1a5bc167 | 1482 | |
0f9dd46c JB |
1483 | /* block group cache stuff */ |
1484 | spinlock_t block_group_cache_lock; | |
a1897fdd | 1485 | u64 first_logical_byte; |
0f9dd46c JB |
1486 | struct rb_root block_group_cache_tree; |
1487 | ||
2bf64758 JB |
1488 | /* keep track of unallocated space */ |
1489 | spinlock_t free_chunk_lock; | |
1490 | u64 free_chunk_space; | |
1491 | ||
11833d66 YZ |
1492 | struct extent_io_tree freed_extents[2]; |
1493 | struct extent_io_tree *pinned_extents; | |
1a5bc167 | 1494 | |
0b86a832 CM |
1495 | /* logical->physical extent mapping */ |
1496 | struct btrfs_mapping_tree mapping_tree; | |
1497 | ||
16cdcec7 MX |
1498 | /* |
1499 | * block reservation for extent, checksum, root tree and | |
1500 | * delayed dir index item | |
1501 | */ | |
f0486c68 YZ |
1502 | struct btrfs_block_rsv global_block_rsv; |
1503 | /* block reservation for delay allocation */ | |
1504 | struct btrfs_block_rsv delalloc_block_rsv; | |
1505 | /* block reservation for metadata operations */ | |
1506 | struct btrfs_block_rsv trans_block_rsv; | |
1507 | /* block reservation for chunk tree */ | |
1508 | struct btrfs_block_rsv chunk_block_rsv; | |
6d668dda JB |
1509 | /* block reservation for delayed operations */ |
1510 | struct btrfs_block_rsv delayed_block_rsv; | |
f0486c68 YZ |
1511 | |
1512 | struct btrfs_block_rsv empty_block_rsv; | |
1513 | ||
293ffd5f | 1514 | u64 generation; |
15ee9bc7 | 1515 | u64 last_trans_committed; |
0a2b2a84 | 1516 | u64 avg_delayed_ref_runtime; |
12fcfd22 CM |
1517 | |
1518 | /* | |
1519 | * this is updated to the current trans every time a full commit | |
1520 | * is required instead of the faster short fsync log commits | |
1521 | */ | |
1522 | u64 last_trans_log_full_commit; | |
25cd999e | 1523 | unsigned long mount_opt; |
572d9ab7 DS |
1524 | /* |
1525 | * Track requests for actions that need to be done during transaction | |
1526 | * commit (like for some mount options). | |
1527 | */ | |
1528 | unsigned long pending_changes; | |
261507a0 | 1529 | unsigned long compress_type:4; |
8b87dc17 | 1530 | int commit_interval; |
8c6a3ee6 MX |
1531 | /* |
1532 | * It is a suggestive number, the read side is safe even it gets a | |
1533 | * wrong number because we will write out the data into a regular | |
1534 | * extent. The write side(mount/remount) is under ->s_umount lock, | |
1535 | * so it is also safe. | |
1536 | */ | |
6f568d35 | 1537 | u64 max_inline; |
c018daec MX |
1538 | /* |
1539 | * Protected by ->chunk_mutex and sb->s_umount. | |
1540 | * | |
1541 | * The reason that we use two lock to protect it is because only | |
1542 | * remount and mount operations can change it and these two operations | |
1543 | * are under sb->s_umount, but the read side (chunk allocation) can not | |
1544 | * acquire sb->s_umount or the deadlock would happen. So we use two | |
1545 | * locks to protect it. On the write side, we must acquire two locks, | |
1546 | * and on the read side, we just need acquire one of them. | |
1547 | */ | |
8f662a76 | 1548 | u64 alloc_start; |
79154b1b | 1549 | struct btrfs_transaction *running_transaction; |
e6dcd2dc | 1550 | wait_queue_head_t transaction_throttle; |
f9295749 | 1551 | wait_queue_head_t transaction_wait; |
bb9c12c9 | 1552 | wait_queue_head_t transaction_blocked_wait; |
771ed689 | 1553 | wait_queue_head_t async_submit_wait; |
e02119d5 | 1554 | |
ceda0864 MX |
1555 | /* |
1556 | * Used to protect the incompat_flags, compat_flags, compat_ro_flags | |
1557 | * when they are updated. | |
1558 | * | |
1559 | * Because we do not clear the flags for ever, so we needn't use | |
1560 | * the lock on the read side. | |
1561 | * | |
1562 | * We also needn't use the lock when we mount the fs, because | |
1563 | * there is no other task which will update the flag. | |
1564 | */ | |
1565 | spinlock_t super_lock; | |
6c41761f DS |
1566 | struct btrfs_super_block *super_copy; |
1567 | struct btrfs_super_block *super_for_commit; | |
0b86a832 | 1568 | struct block_device *__bdev; |
e20d96d6 | 1569 | struct super_block *sb; |
d98237b3 | 1570 | struct inode *btree_inode; |
04160088 | 1571 | struct backing_dev_info bdi; |
e02119d5 | 1572 | struct mutex tree_log_mutex; |
a74a4b97 CM |
1573 | struct mutex transaction_kthread_mutex; |
1574 | struct mutex cleaner_mutex; | |
925baedd | 1575 | struct mutex chunk_mutex; |
7d9eb12c | 1576 | struct mutex volume_mutex; |
53b381b3 | 1577 | |
1bbc621e CM |
1578 | /* |
1579 | * this is taken to make sure we don't set block groups ro after | |
1580 | * the free space cache has been allocated on them | |
1581 | */ | |
1582 | struct mutex ro_block_group_mutex; | |
1583 | ||
53b381b3 DW |
1584 | /* this is used during read/modify/write to make sure |
1585 | * no two ios are trying to mod the same stripe at the same | |
1586 | * time | |
1587 | */ | |
1588 | struct btrfs_stripe_hash_table *stripe_hash_table; | |
1589 | ||
5a3f23d5 CM |
1590 | /* |
1591 | * this protects the ordered operations list only while we are | |
1592 | * processing all of the entries on it. This way we make | |
1593 | * sure the commit code doesn't find the list temporarily empty | |
1594 | * because another function happens to be doing non-waiting preflush | |
1595 | * before jumping into the main commit. | |
1596 | */ | |
1597 | struct mutex ordered_operations_mutex; | |
9ffba8cd | 1598 | |
9e351cc8 | 1599 | struct rw_semaphore commit_root_sem; |
5a3f23d5 | 1600 | |
c71bf099 | 1601 | struct rw_semaphore cleanup_work_sem; |
76dda93c | 1602 | |
c71bf099 | 1603 | struct rw_semaphore subvol_sem; |
76dda93c YZ |
1604 | struct srcu_struct subvol_srcu; |
1605 | ||
a4abeea4 | 1606 | spinlock_t trans_lock; |
7585717f CM |
1607 | /* |
1608 | * the reloc mutex goes with the trans lock, it is taken | |
1609 | * during commit to protect us from the relocation code | |
1610 | */ | |
1611 | struct mutex reloc_mutex; | |
1612 | ||
8fd17795 | 1613 | struct list_head trans_list; |
facda1e7 | 1614 | struct list_head dead_roots; |
11833d66 | 1615 | struct list_head caching_block_groups; |
e02119d5 | 1616 | |
24bbcf04 YZ |
1617 | spinlock_t delayed_iput_lock; |
1618 | struct list_head delayed_iputs; | |
c2d6cb16 | 1619 | struct mutex cleaner_delayed_iput_mutex; |
24bbcf04 | 1620 | |
f29021b2 JS |
1621 | /* this protects tree_mod_seq_list */ |
1622 | spinlock_t tree_mod_seq_lock; | |
fc36ed7e | 1623 | atomic64_t tree_mod_seq; |
f29021b2 JS |
1624 | struct list_head tree_mod_seq_list; |
1625 | ||
1626 | /* this protects tree_mod_log */ | |
1627 | rwlock_t tree_mod_log_lock; | |
1628 | struct rb_root tree_mod_log; | |
1629 | ||
cb03c743 | 1630 | atomic_t nr_async_submits; |
8c8bee1d | 1631 | atomic_t async_submit_draining; |
0986fe9e | 1632 | atomic_t nr_async_bios; |
771ed689 | 1633 | atomic_t async_delalloc_pages; |
a4abeea4 | 1634 | atomic_t open_ioctl_trans; |
ce9adaa5 | 1635 | |
3eaa2885 | 1636 | /* |
199c2a9c | 1637 | * this is used to protect the following list -- ordered_roots. |
3eaa2885 | 1638 | */ |
199c2a9c | 1639 | spinlock_t ordered_root_lock; |
5a3f23d5 CM |
1640 | |
1641 | /* | |
199c2a9c MX |
1642 | * all fs/file tree roots in which there are data=ordered extents |
1643 | * pending writeback are added into this list. | |
1644 | * | |
5a3f23d5 CM |
1645 | * these can span multiple transactions and basically include |
1646 | * every dirty data page that isn't from nodatacow | |
1647 | */ | |
199c2a9c | 1648 | struct list_head ordered_roots; |
5a3f23d5 | 1649 | |
573bfb72 | 1650 | struct mutex delalloc_root_mutex; |
eb73c1b7 MX |
1651 | spinlock_t delalloc_root_lock; |
1652 | /* all fs/file tree roots that have delalloc inodes. */ | |
1653 | struct list_head delalloc_roots; | |
3eaa2885 | 1654 | |
8b712842 CM |
1655 | /* |
1656 | * there is a pool of worker threads for checksumming during writes | |
1657 | * and a pool for checksumming after reads. This is because readers | |
1658 | * can run with FS locks held, and the writers may be waiting for | |
1659 | * those locks. We don't want ordering in the pending list to cause | |
1660 | * deadlocks, and so the two are serviced separately. | |
1cc127b5 CM |
1661 | * |
1662 | * A third pool does submit_bio to avoid deadlocking with the other | |
1663 | * two | |
8b712842 | 1664 | */ |
d458b054 QW |
1665 | struct btrfs_workqueue *workers; |
1666 | struct btrfs_workqueue *delalloc_workers; | |
1667 | struct btrfs_workqueue *flush_workers; | |
1668 | struct btrfs_workqueue *endio_workers; | |
1669 | struct btrfs_workqueue *endio_meta_workers; | |
1670 | struct btrfs_workqueue *endio_raid56_workers; | |
8b110e39 | 1671 | struct btrfs_workqueue *endio_repair_workers; |
d458b054 QW |
1672 | struct btrfs_workqueue *rmw_workers; |
1673 | struct btrfs_workqueue *endio_meta_write_workers; | |
1674 | struct btrfs_workqueue *endio_write_workers; | |
1675 | struct btrfs_workqueue *endio_freespace_worker; | |
1676 | struct btrfs_workqueue *submit_workers; | |
1677 | struct btrfs_workqueue *caching_workers; | |
1678 | struct btrfs_workqueue *readahead_workers; | |
bab39bf9 | 1679 | |
247e743c CM |
1680 | /* |
1681 | * fixup workers take dirty pages that didn't properly go through | |
1682 | * the cow mechanism and make them safe to write. It happens | |
1683 | * for the sys_munmap function call path | |
1684 | */ | |
d458b054 QW |
1685 | struct btrfs_workqueue *fixup_workers; |
1686 | struct btrfs_workqueue *delayed_workers; | |
a79b7d4b CM |
1687 | |
1688 | /* the extent workers do delayed refs on the extent allocation tree */ | |
1689 | struct btrfs_workqueue *extent_workers; | |
a74a4b97 CM |
1690 | struct task_struct *transaction_kthread; |
1691 | struct task_struct *cleaner_kthread; | |
4543df7e | 1692 | int thread_pool_size; |
8b712842 | 1693 | |
6ab0a202 | 1694 | struct kobject *space_info_kobj; |
e66f709b | 1695 | int do_barriers; |
facda1e7 | 1696 | int closing; |
e02119d5 | 1697 | int log_root_recovering; |
47ab2a6c | 1698 | int open; |
9f5fae2f | 1699 | |
324ae4df | 1700 | u64 total_pinned; |
b9473439 | 1701 | |
e2d84521 MX |
1702 | /* used to keep from writing metadata until there is a nice batch */ |
1703 | struct percpu_counter dirty_metadata_bytes; | |
963d678b | 1704 | struct percpu_counter delalloc_bytes; |
e2d84521 | 1705 | s32 dirty_metadata_batch; |
963d678b MX |
1706 | s32 delalloc_batch; |
1707 | ||
0b86a832 CM |
1708 | struct list_head dirty_cowonly_roots; |
1709 | ||
8a4b83cc | 1710 | struct btrfs_fs_devices *fs_devices; |
4184ea7f CM |
1711 | |
1712 | /* | |
1713 | * the space_info list is almost entirely read only. It only changes | |
1714 | * when we add a new raid type to the FS, and that happens | |
1715 | * very rarely. RCU is used to protect it. | |
1716 | */ | |
6324fbf3 | 1717 | struct list_head space_info; |
4184ea7f | 1718 | |
b4d7c3c9 LZ |
1719 | struct btrfs_space_info *data_sinfo; |
1720 | ||
5d4f98a2 YZ |
1721 | struct reloc_control *reloc_ctl; |
1722 | ||
fa9c0d79 CM |
1723 | /* data_alloc_cluster is only used in ssd mode */ |
1724 | struct btrfs_free_cluster data_alloc_cluster; | |
1725 | ||
1726 | /* all metadata allocations go through this cluster */ | |
1727 | struct btrfs_free_cluster meta_alloc_cluster; | |
d18a2c44 | 1728 | |
4cb5300b CM |
1729 | /* auto defrag inodes go here */ |
1730 | spinlock_t defrag_inodes_lock; | |
1731 | struct rb_root defrag_inodes; | |
1732 | atomic_t defrag_running; | |
1733 | ||
de98ced9 MX |
1734 | /* Used to protect avail_{data, metadata, system}_alloc_bits */ |
1735 | seqlock_t profiles_lock; | |
a46d11a8 ID |
1736 | /* |
1737 | * these three are in extended format (availability of single | |
1738 | * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other | |
1739 | * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits) | |
1740 | */ | |
d18a2c44 CM |
1741 | u64 avail_data_alloc_bits; |
1742 | u64 avail_metadata_alloc_bits; | |
1743 | u64 avail_system_alloc_bits; | |
788f20eb | 1744 | |
c9e9f97b ID |
1745 | /* restriper state */ |
1746 | spinlock_t balance_lock; | |
1747 | struct mutex balance_mutex; | |
837d5b6e ID |
1748 | atomic_t balance_running; |
1749 | atomic_t balance_pause_req; | |
a7e99c69 | 1750 | atomic_t balance_cancel_req; |
c9e9f97b | 1751 | struct btrfs_balance_control *balance_ctl; |
837d5b6e | 1752 | wait_queue_head_t balance_wait_q; |
c9e9f97b | 1753 | |
97e728d4 JB |
1754 | unsigned data_chunk_allocations; |
1755 | unsigned metadata_ratio; | |
1756 | ||
788f20eb | 1757 | void *bdev_holder; |
acce952b | 1758 | |
a2de733c AJ |
1759 | /* private scrub information */ |
1760 | struct mutex scrub_lock; | |
1761 | atomic_t scrubs_running; | |
1762 | atomic_t scrub_pause_req; | |
1763 | atomic_t scrubs_paused; | |
1764 | atomic_t scrub_cancel_req; | |
1765 | wait_queue_head_t scrub_pause_wait; | |
a2de733c | 1766 | int scrub_workers_refcnt; |
d458b054 QW |
1767 | struct btrfs_workqueue *scrub_workers; |
1768 | struct btrfs_workqueue *scrub_wr_completion_workers; | |
1769 | struct btrfs_workqueue *scrub_nocow_workers; | |
20b2e302 | 1770 | struct btrfs_workqueue *scrub_parity_workers; |
a2de733c | 1771 | |
21adbd5c SB |
1772 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
1773 | u32 check_integrity_print_mask; | |
1774 | #endif | |
416ac51d AJ |
1775 | /* |
1776 | * quota information | |
1777 | */ | |
1778 | unsigned int quota_enabled:1; | |
1779 | ||
1780 | /* | |
1781 | * quota_enabled only changes state after a commit. This holds the | |
1782 | * next state. | |
1783 | */ | |
1784 | unsigned int pending_quota_state:1; | |
1785 | ||
1786 | /* is qgroup tracking in a consistent state? */ | |
1787 | u64 qgroup_flags; | |
1788 | ||
1789 | /* holds configuration and tracking. Protected by qgroup_lock */ | |
1790 | struct rb_root qgroup_tree; | |
fcebe456 | 1791 | struct rb_root qgroup_op_tree; |
416ac51d | 1792 | spinlock_t qgroup_lock; |
fcebe456 JB |
1793 | spinlock_t qgroup_op_lock; |
1794 | atomic_t qgroup_op_seq; | |
416ac51d | 1795 | |
1e8f9158 WS |
1796 | /* |
1797 | * used to avoid frequently calling ulist_alloc()/ulist_free() | |
1798 | * when doing qgroup accounting, it must be protected by qgroup_lock. | |
1799 | */ | |
1800 | struct ulist *qgroup_ulist; | |
1801 | ||
f2f6ed3d WS |
1802 | /* protect user change for quota operations */ |
1803 | struct mutex qgroup_ioctl_lock; | |
1804 | ||
416ac51d AJ |
1805 | /* list of dirty qgroups to be written at next commit */ |
1806 | struct list_head dirty_qgroups; | |
1807 | ||
e69bcee3 | 1808 | /* used by qgroup for an efficient tree traversal */ |
416ac51d | 1809 | u64 qgroup_seq; |
21adbd5c | 1810 | |
2f232036 JS |
1811 | /* qgroup rescan items */ |
1812 | struct mutex qgroup_rescan_lock; /* protects the progress item */ | |
1813 | struct btrfs_key qgroup_rescan_progress; | |
d458b054 | 1814 | struct btrfs_workqueue *qgroup_rescan_workers; |
57254b6e | 1815 | struct completion qgroup_rescan_completion; |
b382a324 | 1816 | struct btrfs_work qgroup_rescan_work; |
2f232036 | 1817 | |
acce952b | 1818 | /* filesystem state */ |
87533c47 | 1819 | unsigned long fs_state; |
16cdcec7 MX |
1820 | |
1821 | struct btrfs_delayed_root *delayed_root; | |
af31f5e5 | 1822 | |
90519d66 AJ |
1823 | /* readahead tree */ |
1824 | spinlock_t reada_lock; | |
1825 | struct radix_tree_root reada_tree; | |
531f4b1a | 1826 | |
f28491e0 JB |
1827 | /* Extent buffer radix tree */ |
1828 | spinlock_t buffer_lock; | |
1829 | struct radix_tree_root buffer_radix; | |
1830 | ||
af31f5e5 CM |
1831 | /* next backup root to be overwritten */ |
1832 | int backup_root_index; | |
5af3e8cc SB |
1833 | |
1834 | int num_tolerated_disk_barrier_failures; | |
e922e087 SB |
1835 | |
1836 | /* device replace state */ | |
1837 | struct btrfs_dev_replace dev_replace; | |
5ac00add SB |
1838 | |
1839 | atomic_t mutually_exclusive_operation_running; | |
803b2f54 | 1840 | |
c404e0dc MX |
1841 | struct percpu_counter bio_counter; |
1842 | wait_queue_head_t replace_wait; | |
1843 | ||
803b2f54 | 1844 | struct semaphore uuid_tree_rescan_sem; |
70f80175 | 1845 | unsigned int update_uuid_tree_gen:1; |
21c7e756 MX |
1846 | |
1847 | /* Used to reclaim the metadata space in the background. */ | |
1848 | struct work_struct async_reclaim_work; | |
47ab2a6c JB |
1849 | |
1850 | spinlock_t unused_bgs_lock; | |
1851 | struct list_head unused_bgs; | |
d4b450cd | 1852 | struct mutex unused_bg_unpin_mutex; |
67c5e7d4 | 1853 | struct mutex delete_unused_bgs_mutex; |
f667aef6 QW |
1854 | |
1855 | /* For btrfs to record security options */ | |
1856 | struct security_mnt_opts security_opts; | |
04216820 FM |
1857 | |
1858 | /* | |
1859 | * Chunks that can't be freed yet (under a trim/discard operation) | |
1860 | * and will be latter freed. Protected by fs_info->chunk_mutex. | |
1861 | */ | |
1862 | struct list_head pinned_chunks; | |
511711af CM |
1863 | |
1864 | int creating_free_space_tree; | |
324ae4df | 1865 | }; |
0b86a832 | 1866 | |
8257b2dc MX |
1867 | struct btrfs_subvolume_writers { |
1868 | struct percpu_counter counter; | |
1869 | wait_queue_head_t wait; | |
1870 | }; | |
1871 | ||
27cdeb70 MX |
1872 | /* |
1873 | * The state of btrfs root | |
1874 | */ | |
1875 | /* | |
1876 | * btrfs_record_root_in_trans is a multi-step process, | |
1877 | * and it can race with the balancing code. But the | |
1878 | * race is very small, and only the first time the root | |
1879 | * is added to each transaction. So IN_TRANS_SETUP | |
1880 | * is used to tell us when more checks are required | |
1881 | */ | |
1882 | #define BTRFS_ROOT_IN_TRANS_SETUP 0 | |
1883 | #define BTRFS_ROOT_REF_COWS 1 | |
1884 | #define BTRFS_ROOT_TRACK_DIRTY 2 | |
1885 | #define BTRFS_ROOT_IN_RADIX 3 | |
1886 | #define BTRFS_ROOT_DUMMY_ROOT 4 | |
1887 | #define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 5 | |
1888 | #define BTRFS_ROOT_DEFRAG_RUNNING 6 | |
1889 | #define BTRFS_ROOT_FORCE_COW 7 | |
1890 | #define BTRFS_ROOT_MULTI_LOG_TASKS 8 | |
e7070be1 | 1891 | #define BTRFS_ROOT_DIRTY 9 |
27cdeb70 | 1892 | |
9f5fae2f CM |
1893 | /* |
1894 | * in ram representation of the tree. extent_root is used for all allocations | |
f2458e1d | 1895 | * and for the extent tree extent_root root. |
9f5fae2f CM |
1896 | */ |
1897 | struct btrfs_root { | |
5f39d397 | 1898 | struct extent_buffer *node; |
925baedd | 1899 | |
5f39d397 | 1900 | struct extent_buffer *commit_root; |
e02119d5 | 1901 | struct btrfs_root *log_root; |
1a40e23b | 1902 | struct btrfs_root *reloc_root; |
31153d81 | 1903 | |
27cdeb70 | 1904 | unsigned long state; |
62e2749e CM |
1905 | struct btrfs_root_item root_item; |
1906 | struct btrfs_key root_key; | |
9f5fae2f | 1907 | struct btrfs_fs_info *fs_info; |
d0c803c4 CM |
1908 | struct extent_io_tree dirty_log_pages; |
1909 | ||
a2135011 | 1910 | struct mutex objectid_mutex; |
7237f183 | 1911 | |
f0486c68 YZ |
1912 | spinlock_t accounting_lock; |
1913 | struct btrfs_block_rsv *block_rsv; | |
1914 | ||
581bb050 | 1915 | /* free ino cache stuff */ |
581bb050 | 1916 | struct btrfs_free_space_ctl *free_ino_ctl; |
57cdc8db DS |
1917 | enum btrfs_caching_type ino_cache_state; |
1918 | spinlock_t ino_cache_lock; | |
1919 | wait_queue_head_t ino_cache_wait; | |
581bb050 | 1920 | struct btrfs_free_space_ctl *free_ino_pinned; |
57cdc8db DS |
1921 | u64 ino_cache_progress; |
1922 | struct inode *ino_cache_inode; | |
581bb050 | 1923 | |
e02119d5 | 1924 | struct mutex log_mutex; |
7237f183 YZ |
1925 | wait_queue_head_t log_writer_wait; |
1926 | wait_queue_head_t log_commit_wait[2]; | |
8b050d35 | 1927 | struct list_head log_ctxs[2]; |
7237f183 YZ |
1928 | atomic_t log_writers; |
1929 | atomic_t log_commit[2]; | |
2ecb7923 | 1930 | atomic_t log_batch; |
bb14a59b | 1931 | int log_transid; |
d1433deb MX |
1932 | /* No matter the commit succeeds or not*/ |
1933 | int log_transid_committed; | |
1934 | /* Just be updated when the commit succeeds. */ | |
bb14a59b | 1935 | int last_log_commit; |
ff782e0a | 1936 | pid_t log_start_pid; |
ea8c2819 | 1937 | |
0f7d52f4 CM |
1938 | u64 objectid; |
1939 | u64 last_trans; | |
5f39d397 CM |
1940 | |
1941 | /* data allocations are done in sectorsize units */ | |
1942 | u32 sectorsize; | |
1943 | ||
1944 | /* node allocations are done in nodesize units */ | |
1945 | u32 nodesize; | |
1946 | ||
87ee04eb CM |
1947 | u32 stripesize; |
1948 | ||
9f5fae2f | 1949 | u32 type; |
13a8a7c8 YZ |
1950 | |
1951 | u64 highest_objectid; | |
7585717f | 1952 | |
0d4cf4e6 | 1953 | /* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */ |
faa2dbf0 | 1954 | u64 alloc_bytenr; |
faa2dbf0 | 1955 | |
3f157a2f | 1956 | u64 defrag_trans_start; |
6702ed49 | 1957 | struct btrfs_key defrag_progress; |
0ef3e66b | 1958 | struct btrfs_key defrag_max; |
58176a96 | 1959 | char *name; |
0b86a832 CM |
1960 | |
1961 | /* the dirty list is only used by non-reference counted roots */ | |
1962 | struct list_head dirty_list; | |
7b128766 | 1963 | |
5d4f98a2 YZ |
1964 | struct list_head root_list; |
1965 | ||
2ab28f32 JB |
1966 | spinlock_t log_extents_lock[2]; |
1967 | struct list_head logged_list[2]; | |
1968 | ||
d68fc57b | 1969 | spinlock_t orphan_lock; |
8a35d95f | 1970 | atomic_t orphan_inodes; |
d68fc57b | 1971 | struct btrfs_block_rsv *orphan_block_rsv; |
d68fc57b | 1972 | int orphan_cleanup_state; |
3394e160 | 1973 | |
5d4f98a2 YZ |
1974 | spinlock_t inode_lock; |
1975 | /* red-black tree that keeps track of in-memory inodes */ | |
1976 | struct rb_root inode_tree; | |
1977 | ||
16cdcec7 MX |
1978 | /* |
1979 | * radix tree that keeps track of delayed nodes of every inode, | |
1980 | * protected by inode_lock | |
1981 | */ | |
1982 | struct radix_tree_root delayed_nodes_tree; | |
3394e160 CM |
1983 | /* |
1984 | * right now this just gets used so that a root has its own devid | |
1985 | * for stat. It may be used for more later | |
1986 | */ | |
0ee5dc67 | 1987 | dev_t anon_dev; |
f1ebcc74 | 1988 | |
5f3ab90a | 1989 | spinlock_t root_item_lock; |
b0feb9d9 | 1990 | atomic_t refs; |
eb73c1b7 | 1991 | |
573bfb72 | 1992 | struct mutex delalloc_mutex; |
eb73c1b7 MX |
1993 | spinlock_t delalloc_lock; |
1994 | /* | |
1995 | * all of the inodes that have delalloc bytes. It is possible for | |
1996 | * this list to be empty even when there is still dirty data=ordered | |
1997 | * extents waiting to finish IO. | |
1998 | */ | |
1999 | struct list_head delalloc_inodes; | |
2000 | struct list_head delalloc_root; | |
2001 | u64 nr_delalloc_inodes; | |
31f3d255 MX |
2002 | |
2003 | struct mutex ordered_extent_mutex; | |
199c2a9c MX |
2004 | /* |
2005 | * this is used by the balancing code to wait for all the pending | |
2006 | * ordered extents | |
2007 | */ | |
2008 | spinlock_t ordered_extent_lock; | |
2009 | ||
2010 | /* | |
2011 | * all of the data=ordered extents pending writeback | |
2012 | * these can span multiple transactions and basically include | |
2013 | * every dirty data page that isn't from nodatacow | |
2014 | */ | |
2015 | struct list_head ordered_extents; | |
2016 | struct list_head ordered_root; | |
2017 | u64 nr_ordered_extents; | |
2c686537 DS |
2018 | |
2019 | /* | |
2020 | * Number of currently running SEND ioctls to prevent | |
2021 | * manipulation with the read-only status via SUBVOL_SETFLAGS | |
2022 | */ | |
2023 | int send_in_progress; | |
8257b2dc MX |
2024 | struct btrfs_subvolume_writers *subv_writers; |
2025 | atomic_t will_be_snapshoted; | |
55eeaf05 QW |
2026 | |
2027 | /* For qgroup metadata space reserve */ | |
2028 | atomic_t qgroup_meta_rsv; | |
62e2749e CM |
2029 | }; |
2030 | ||
4cb5300b CM |
2031 | struct btrfs_ioctl_defrag_range_args { |
2032 | /* start of the defrag operation */ | |
2033 | __u64 start; | |
2034 | ||
2035 | /* number of bytes to defrag, use (u64)-1 to say all */ | |
2036 | __u64 len; | |
2037 | ||
2038 | /* | |
2039 | * flags for the operation, which can include turning | |
2040 | * on compression for this one defrag | |
2041 | */ | |
2042 | __u64 flags; | |
2043 | ||
2044 | /* | |
2045 | * any extent bigger than this will be considered | |
2046 | * already defragged. Use 0 to take the kernel default | |
2047 | * Use 1 to say every single extent must be rewritten | |
2048 | */ | |
2049 | __u32 extent_thresh; | |
2050 | ||
2051 | /* | |
2052 | * which compression method to use if turning on compression | |
2053 | * for this defrag operation. If unspecified, zlib will | |
2054 | * be used | |
2055 | */ | |
2056 | __u32 compress_type; | |
2057 | ||
2058 | /* spare for later */ | |
2059 | __u32 unused[4]; | |
2060 | }; | |
2061 | ||
2062 | ||
1e1d2701 CM |
2063 | /* |
2064 | * inode items have the data typically returned from stat and store other | |
2065 | * info about object characteristics. There is one for every file and dir in | |
2066 | * the FS | |
2067 | */ | |
9078a3e1 | 2068 | #define BTRFS_INODE_ITEM_KEY 1 |
0660b5af | 2069 | #define BTRFS_INODE_REF_KEY 12 |
f186373f | 2070 | #define BTRFS_INODE_EXTREF_KEY 13 |
0660b5af CM |
2071 | #define BTRFS_XATTR_ITEM_KEY 24 |
2072 | #define BTRFS_ORPHAN_ITEM_KEY 48 | |
9078a3e1 | 2073 | /* reserve 2-15 close to the inode for later flexibility */ |
1e1d2701 CM |
2074 | |
2075 | /* | |
2076 | * dir items are the name -> inode pointers in a directory. There is one | |
2077 | * for every name in a directory. | |
2078 | */ | |
0660b5af CM |
2079 | #define BTRFS_DIR_LOG_ITEM_KEY 60 |
2080 | #define BTRFS_DIR_LOG_INDEX_KEY 72 | |
2081 | #define BTRFS_DIR_ITEM_KEY 84 | |
2082 | #define BTRFS_DIR_INDEX_KEY 96 | |
1e1d2701 | 2083 | /* |
9078a3e1 | 2084 | * extent data is for file data |
1e1d2701 | 2085 | */ |
0660b5af | 2086 | #define BTRFS_EXTENT_DATA_KEY 108 |
d20f7043 | 2087 | |
f254e52c | 2088 | /* |
d20f7043 CM |
2089 | * extent csums are stored in a separate tree and hold csums for |
2090 | * an entire extent on disk. | |
f254e52c | 2091 | */ |
d20f7043 | 2092 | #define BTRFS_EXTENT_CSUM_KEY 128 |
f254e52c | 2093 | |
1e1d2701 | 2094 | /* |
d4a78947 | 2095 | * root items point to tree roots. They are typically in the root |
1e1d2701 CM |
2096 | * tree used by the super block to find all the other trees |
2097 | */ | |
0660b5af CM |
2098 | #define BTRFS_ROOT_ITEM_KEY 132 |
2099 | ||
2100 | /* | |
2101 | * root backrefs tie subvols and snapshots to the directory entries that | |
2102 | * reference them | |
2103 | */ | |
2104 | #define BTRFS_ROOT_BACKREF_KEY 144 | |
2105 | ||
2106 | /* | |
2107 | * root refs make a fast index for listing all of the snapshots and | |
2108 | * subvolumes referenced by a given root. They point directly to the | |
2109 | * directory item in the root that references the subvol | |
2110 | */ | |
2111 | #define BTRFS_ROOT_REF_KEY 156 | |
2112 | ||
1e1d2701 CM |
2113 | /* |
2114 | * extent items are in the extent map tree. These record which blocks | |
2115 | * are used, and how many references there are to each block | |
2116 | */ | |
0660b5af | 2117 | #define BTRFS_EXTENT_ITEM_KEY 168 |
5d4f98a2 | 2118 | |
3173a18f JB |
2119 | /* |
2120 | * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know | |
2121 | * the length, so we save the level in key->offset instead of the length. | |
2122 | */ | |
2123 | #define BTRFS_METADATA_ITEM_KEY 169 | |
2124 | ||
5d4f98a2 YZ |
2125 | #define BTRFS_TREE_BLOCK_REF_KEY 176 |
2126 | ||
2127 | #define BTRFS_EXTENT_DATA_REF_KEY 178 | |
2128 | ||
2129 | #define BTRFS_EXTENT_REF_V0_KEY 180 | |
2130 | ||
2131 | #define BTRFS_SHARED_BLOCK_REF_KEY 182 | |
2132 | ||
2133 | #define BTRFS_SHARED_DATA_REF_KEY 184 | |
9078a3e1 CM |
2134 | |
2135 | /* | |
2136 | * block groups give us hints into the extent allocation trees. Which | |
2137 | * blocks are free etc etc | |
2138 | */ | |
0660b5af | 2139 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 192 |
9f5fae2f | 2140 | |
208acb8c OS |
2141 | /* |
2142 | * Every block group is represented in the free space tree by a free space info | |
2143 | * item, which stores some accounting information. It is keyed on | |
2144 | * (block_group_start, FREE_SPACE_INFO, block_group_length). | |
2145 | */ | |
2146 | #define BTRFS_FREE_SPACE_INFO_KEY 198 | |
2147 | ||
2148 | /* | |
2149 | * A free space extent tracks an extent of space that is free in a block group. | |
2150 | * It is keyed on (start, FREE_SPACE_EXTENT, length). | |
2151 | */ | |
2152 | #define BTRFS_FREE_SPACE_EXTENT_KEY 199 | |
2153 | ||
2154 | /* | |
2155 | * When a block group becomes very fragmented, we convert it to use bitmaps | |
2156 | * instead of extents. A free space bitmap is keyed on | |
2157 | * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with | |
2158 | * (length / sectorsize) bits. | |
2159 | */ | |
2160 | #define BTRFS_FREE_SPACE_BITMAP_KEY 200 | |
2161 | ||
0660b5af CM |
2162 | #define BTRFS_DEV_EXTENT_KEY 204 |
2163 | #define BTRFS_DEV_ITEM_KEY 216 | |
2164 | #define BTRFS_CHUNK_ITEM_KEY 228 | |
0b86a832 | 2165 | |
630dc772 AJ |
2166 | /* |
2167 | * Records the overall state of the qgroups. | |
2168 | * There's only one instance of this key present, | |
2169 | * (0, BTRFS_QGROUP_STATUS_KEY, 0) | |
2170 | */ | |
2171 | #define BTRFS_QGROUP_STATUS_KEY 240 | |
2172 | /* | |
2173 | * Records the currently used space of the qgroup. | |
2174 | * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). | |
2175 | */ | |
2176 | #define BTRFS_QGROUP_INFO_KEY 242 | |
2177 | /* | |
2178 | * Contains the user configured limits for the qgroup. | |
2179 | * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). | |
2180 | */ | |
2181 | #define BTRFS_QGROUP_LIMIT_KEY 244 | |
2182 | /* | |
2183 | * Records the child-parent relationship of qgroups. For | |
2184 | * each relation, 2 keys are present: | |
2185 | * (childid, BTRFS_QGROUP_RELATION_KEY, parentid) | |
2186 | * (parentid, BTRFS_QGROUP_RELATION_KEY, childid) | |
2187 | */ | |
2188 | #define BTRFS_QGROUP_RELATION_KEY 246 | |
2189 | ||
0940ebf6 ID |
2190 | #define BTRFS_BALANCE_ITEM_KEY 248 |
2191 | ||
733f4fbb SB |
2192 | /* |
2193 | * Persistantly stores the io stats in the device tree. | |
2194 | * One key for all stats, (0, BTRFS_DEV_STATS_KEY, devid). | |
2195 | */ | |
2196 | #define BTRFS_DEV_STATS_KEY 249 | |
2197 | ||
a2bff640 SB |
2198 | /* |
2199 | * Persistantly stores the device replace state in the device tree. | |
2200 | * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0). | |
2201 | */ | |
2202 | #define BTRFS_DEV_REPLACE_KEY 250 | |
2203 | ||
07b30a49 SB |
2204 | /* |
2205 | * Stores items that allow to quickly map UUIDs to something else. | |
2206 | * These items are part of the filesystem UUID tree. | |
2207 | * The key is built like this: | |
2208 | * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits). | |
2209 | */ | |
2210 | #if BTRFS_UUID_SIZE != 16 | |
2211 | #error "UUID items require BTRFS_UUID_SIZE == 16!" | |
2212 | #endif | |
2213 | #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */ | |
2214 | #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to | |
2215 | * received subvols */ | |
2216 | ||
1e1d2701 CM |
2217 | /* |
2218 | * string items are for debugging. They just store a short string of | |
2219 | * data in the FS | |
2220 | */ | |
9078a3e1 CM |
2221 | #define BTRFS_STRING_ITEM_KEY 253 |
2222 | ||
0942caa3 DS |
2223 | /* |
2224 | * Flags for mount options. | |
2225 | * | |
2226 | * Note: don't forget to add new options to btrfs_show_options() | |
2227 | */ | |
21ad10cf CM |
2228 | #define BTRFS_MOUNT_NODATASUM (1 << 0) |
2229 | #define BTRFS_MOUNT_NODATACOW (1 << 1) | |
2230 | #define BTRFS_MOUNT_NOBARRIER (1 << 2) | |
e18e4809 | 2231 | #define BTRFS_MOUNT_SSD (1 << 3) |
dfe25020 | 2232 | #define BTRFS_MOUNT_DEGRADED (1 << 4) |
c8b97818 | 2233 | #define BTRFS_MOUNT_COMPRESS (1 << 5) |
3a5e1404 | 2234 | #define BTRFS_MOUNT_NOTREELOG (1 << 6) |
dccae999 | 2235 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) |
451d7585 | 2236 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) |
c289811c | 2237 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
e244a0ae | 2238 | #define BTRFS_MOUNT_DISCARD (1 << 10) |
a555f810 | 2239 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) |
0af3d00b | 2240 | #define BTRFS_MOUNT_SPACE_CACHE (1 << 12) |
88c2ba3b | 2241 | #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13) |
4260f7c7 | 2242 | #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14) |
91435650 | 2243 | #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15) |
4cb5300b | 2244 | #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16) |
4b9465cb | 2245 | #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17) |
af31f5e5 | 2246 | #define BTRFS_MOUNT_RECOVERY (1 << 18) |
9555c6c1 | 2247 | #define BTRFS_MOUNT_SKIP_BALANCE (1 << 19) |
c126dea7 CM |
2248 | #define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20) |
2249 | #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21) | |
8c342930 | 2250 | #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22) |
f420ee1e | 2251 | #define BTRFS_MOUNT_RESCAN_UUID_TREE (1 << 23) |
d0bd4560 JB |
2252 | #define BTRFS_MOUNT_FRAGMENT_DATA (1 << 24) |
2253 | #define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25) | |
f7d3d2f9 | 2254 | #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26) |
b6cda9bc | 2255 | |
8b87dc17 | 2256 | #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) |
95ac567a | 2257 | #define BTRFS_DEFAULT_MAX_INLINE (8192) |
8b87dc17 | 2258 | |
b6cda9bc CM |
2259 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
2260 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | |
dc81cdc5 | 2261 | #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt) |
b6cda9bc CM |
2262 | #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \ |
2263 | BTRFS_MOUNT_##opt) | |
572d9ab7 | 2264 | |
9d89ce65 WS |
2265 | #define btrfs_set_and_info(root, opt, fmt, args...) \ |
2266 | { \ | |
2267 | if (!btrfs_test_opt(root, opt)) \ | |
2268 | btrfs_info(root->fs_info, fmt, ##args); \ | |
2269 | btrfs_set_opt(root->fs_info->mount_opt, opt); \ | |
2270 | } | |
2271 | ||
2272 | #define btrfs_clear_and_info(root, opt, fmt, args...) \ | |
2273 | { \ | |
2274 | if (btrfs_test_opt(root, opt)) \ | |
2275 | btrfs_info(root->fs_info, fmt, ##args); \ | |
2276 | btrfs_clear_opt(root->fs_info->mount_opt, opt); \ | |
2277 | } | |
2278 | ||
d0bd4560 JB |
2279 | #ifdef CONFIG_BTRFS_DEBUG |
2280 | static inline int | |
2281 | btrfs_should_fragment_free_space(struct btrfs_root *root, | |
2282 | struct btrfs_block_group_cache *block_group) | |
2283 | { | |
2284 | return (btrfs_test_opt(root, FRAGMENT_METADATA) && | |
2285 | block_group->flags & BTRFS_BLOCK_GROUP_METADATA) || | |
2286 | (btrfs_test_opt(root, FRAGMENT_DATA) && | |
2287 | block_group->flags & BTRFS_BLOCK_GROUP_DATA); | |
2288 | } | |
2289 | #endif | |
2290 | ||
572d9ab7 DS |
2291 | /* |
2292 | * Requests for changes that need to be done during transaction commit. | |
2293 | * | |
2294 | * Internal mount options that are used for special handling of the real | |
2295 | * mount options (eg. cannot be set during remount and have to be set during | |
2296 | * transaction commit) | |
2297 | */ | |
2298 | ||
7e1876ac DS |
2299 | #define BTRFS_PENDING_SET_INODE_MAP_CACHE (0) |
2300 | #define BTRFS_PENDING_CLEAR_INODE_MAP_CACHE (1) | |
d51033d0 | 2301 | #define BTRFS_PENDING_COMMIT (2) |
7e1876ac | 2302 | |
572d9ab7 DS |
2303 | #define btrfs_test_pending(info, opt) \ |
2304 | test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) | |
2305 | #define btrfs_set_pending(info, opt) \ | |
2306 | set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) | |
2307 | #define btrfs_clear_pending(info, opt) \ | |
2308 | clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes) | |
2309 | ||
2310 | /* | |
2311 | * Helpers for setting pending mount option changes. | |
2312 | * | |
2313 | * Expects corresponding macros | |
2314 | * BTRFS_PENDING_SET_ and CLEAR_ + short mount option name | |
2315 | */ | |
2316 | #define btrfs_set_pending_and_info(info, opt, fmt, args...) \ | |
2317 | do { \ | |
2318 | if (!btrfs_raw_test_opt((info)->mount_opt, opt)) { \ | |
2319 | btrfs_info((info), fmt, ##args); \ | |
2320 | btrfs_set_pending((info), SET_##opt); \ | |
2321 | btrfs_clear_pending((info), CLEAR_##opt); \ | |
2322 | } \ | |
2323 | } while(0) | |
2324 | ||
2325 | #define btrfs_clear_pending_and_info(info, opt, fmt, args...) \ | |
2326 | do { \ | |
2327 | if (btrfs_raw_test_opt((info)->mount_opt, opt)) { \ | |
2328 | btrfs_info((info), fmt, ##args); \ | |
2329 | btrfs_set_pending((info), CLEAR_##opt); \ | |
2330 | btrfs_clear_pending((info), SET_##opt); \ | |
2331 | } \ | |
2332 | } while(0) | |
2333 | ||
b98b6767 Y |
2334 | /* |
2335 | * Inode flags | |
2336 | */ | |
fdebe2bd Y |
2337 | #define BTRFS_INODE_NODATASUM (1 << 0) |
2338 | #define BTRFS_INODE_NODATACOW (1 << 1) | |
2339 | #define BTRFS_INODE_READONLY (1 << 2) | |
c8b97818 | 2340 | #define BTRFS_INODE_NOCOMPRESS (1 << 3) |
d899e052 | 2341 | #define BTRFS_INODE_PREALLOC (1 << 4) |
6cbff00f CH |
2342 | #define BTRFS_INODE_SYNC (1 << 5) |
2343 | #define BTRFS_INODE_IMMUTABLE (1 << 6) | |
2344 | #define BTRFS_INODE_APPEND (1 << 7) | |
2345 | #define BTRFS_INODE_NODUMP (1 << 8) | |
2346 | #define BTRFS_INODE_NOATIME (1 << 9) | |
2347 | #define BTRFS_INODE_DIRSYNC (1 << 10) | |
75e7cb7f | 2348 | #define BTRFS_INODE_COMPRESS (1 << 11) |
6cbff00f | 2349 | |
08fe4db1 LZ |
2350 | #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31) |
2351 | ||
cfed81a0 CM |
2352 | struct btrfs_map_token { |
2353 | struct extent_buffer *eb; | |
2354 | char *kaddr; | |
2355 | unsigned long offset; | |
2356 | }; | |
2357 | ||
2358 | static inline void btrfs_init_map_token (struct btrfs_map_token *token) | |
2359 | { | |
ad914559 | 2360 | token->kaddr = NULL; |
cfed81a0 CM |
2361 | } |
2362 | ||
5f39d397 CM |
2363 | /* some macros to generate set/get funcs for the struct fields. This |
2364 | * assumes there is a lefoo_to_cpu for every type, so lets make a simple | |
2365 | * one for u8: | |
2366 | */ | |
2367 | #define le8_to_cpu(v) (v) | |
2368 | #define cpu_to_le8(v) (v) | |
2369 | #define __le8 u8 | |
2370 | ||
2371 | #define read_eb_member(eb, ptr, type, member, result) ( \ | |
2372 | read_extent_buffer(eb, (char *)(result), \ | |
2373 | ((unsigned long)(ptr)) + \ | |
2374 | offsetof(type, member), \ | |
2375 | sizeof(((type *)0)->member))) | |
2376 | ||
2377 | #define write_eb_member(eb, ptr, type, member, result) ( \ | |
2378 | write_extent_buffer(eb, (char *)(result), \ | |
2379 | ((unsigned long)(ptr)) + \ | |
2380 | offsetof(type, member), \ | |
2381 | sizeof(((type *)0)->member))) | |
2382 | ||
18077bb4 LZ |
2383 | #define DECLARE_BTRFS_SETGET_BITS(bits) \ |
2384 | u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \ | |
2385 | unsigned long off, \ | |
2386 | struct btrfs_map_token *token); \ | |
2387 | void btrfs_set_token_##bits(struct extent_buffer *eb, void *ptr, \ | |
2388 | unsigned long off, u##bits val, \ | |
2389 | struct btrfs_map_token *token); \ | |
2390 | static inline u##bits btrfs_get_##bits(struct extent_buffer *eb, void *ptr, \ | |
2391 | unsigned long off) \ | |
2392 | { \ | |
2393 | return btrfs_get_token_##bits(eb, ptr, off, NULL); \ | |
2394 | } \ | |
2395 | static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \ | |
2396 | unsigned long off, u##bits val) \ | |
2397 | { \ | |
2398 | btrfs_set_token_##bits(eb, ptr, off, val, NULL); \ | |
2399 | } | |
2400 | ||
2401 | DECLARE_BTRFS_SETGET_BITS(8) | |
2402 | DECLARE_BTRFS_SETGET_BITS(16) | |
2403 | DECLARE_BTRFS_SETGET_BITS(32) | |
2404 | DECLARE_BTRFS_SETGET_BITS(64) | |
2405 | ||
5f39d397 | 2406 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
18077bb4 LZ |
2407 | static inline u##bits btrfs_##name(struct extent_buffer *eb, type *s) \ |
2408 | { \ | |
2409 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ | |
2410 | return btrfs_get_##bits(eb, s, offsetof(type, member)); \ | |
2411 | } \ | |
2412 | static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \ | |
2413 | u##bits val) \ | |
2414 | { \ | |
2415 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ | |
2416 | btrfs_set_##bits(eb, s, offsetof(type, member), val); \ | |
2417 | } \ | |
2418 | static inline u##bits btrfs_token_##name(struct extent_buffer *eb, type *s, \ | |
2419 | struct btrfs_map_token *token) \ | |
2420 | { \ | |
2421 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ | |
2422 | return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \ | |
2423 | } \ | |
2424 | static inline void btrfs_set_token_##name(struct extent_buffer *eb, \ | |
2425 | type *s, u##bits val, \ | |
2426 | struct btrfs_map_token *token) \ | |
2427 | { \ | |
2428 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ | |
2429 | btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \ | |
2430 | } | |
5f39d397 CM |
2431 | |
2432 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ | |
2433 | static inline u##bits btrfs_##name(struct extent_buffer *eb) \ | |
2434 | { \ | |
727011e0 | 2435 | type *p = page_address(eb->pages[0]); \ |
df68b8a7 | 2436 | u##bits res = le##bits##_to_cpu(p->member); \ |
810191ff | 2437 | return res; \ |
5f39d397 CM |
2438 | } \ |
2439 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ | |
2440 | u##bits val) \ | |
2441 | { \ | |
727011e0 | 2442 | type *p = page_address(eb->pages[0]); \ |
df68b8a7 | 2443 | p->member = cpu_to_le##bits(val); \ |
5f39d397 | 2444 | } |
9078a3e1 | 2445 | |
5f39d397 CM |
2446 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
2447 | static inline u##bits btrfs_##name(type *s) \ | |
2448 | { \ | |
2449 | return le##bits##_to_cpu(s->member); \ | |
2450 | } \ | |
2451 | static inline void btrfs_set_##name(type *s, u##bits val) \ | |
2452 | { \ | |
2453 | s->member = cpu_to_le##bits(val); \ | |
1e1d2701 CM |
2454 | } |
2455 | ||
0b86a832 CM |
2456 | BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); |
2457 | BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64); | |
2458 | BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); | |
2459 | BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); | |
2460 | BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); | |
c3027eb5 CM |
2461 | BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, |
2462 | start_offset, 64); | |
0b86a832 CM |
2463 | BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); |
2464 | BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); | |
e17cade2 CM |
2465 | BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); |
2466 | BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); | |
2467 | BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); | |
2b82032c | 2468 | BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); |
0b86a832 | 2469 | |
8a4b83cc CM |
2470 | BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); |
2471 | BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, | |
2472 | total_bytes, 64); | |
2473 | BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, | |
2474 | bytes_used, 64); | |
2475 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, | |
2476 | io_align, 32); | |
2477 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, | |
2478 | io_width, 32); | |
2479 | BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, | |
2480 | sector_size, 32); | |
2481 | BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); | |
e17cade2 CM |
2482 | BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, |
2483 | dev_group, 32); | |
2484 | BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, | |
2485 | seek_speed, 8); | |
2486 | BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, | |
2487 | bandwidth, 8); | |
2b82032c YZ |
2488 | BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, |
2489 | generation, 64); | |
8a4b83cc | 2490 | |
410ba3a2 | 2491 | static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d) |
0b86a832 | 2492 | { |
410ba3a2 | 2493 | return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid); |
0b86a832 CM |
2494 | } |
2495 | ||
1473b24e | 2496 | static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d) |
2b82032c | 2497 | { |
1473b24e | 2498 | return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid); |
2b82032c YZ |
2499 | } |
2500 | ||
e17cade2 | 2501 | BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); |
0b86a832 CM |
2502 | BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); |
2503 | BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); | |
2504 | BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); | |
2505 | BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); | |
2506 | BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); | |
2507 | BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); | |
2508 | BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); | |
321aecc6 | 2509 | BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); |
0b86a832 CM |
2510 | BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); |
2511 | BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); | |
2512 | ||
e17cade2 CM |
2513 | static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) |
2514 | { | |
2515 | return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); | |
2516 | } | |
2517 | ||
2518 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); | |
0b86a832 CM |
2519 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); |
2520 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, | |
2521 | stripe_len, 64); | |
2522 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, | |
2523 | io_align, 32); | |
2524 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, | |
2525 | io_width, 32); | |
2526 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, | |
2527 | sector_size, 32); | |
2528 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); | |
2529 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, | |
2530 | num_stripes, 16); | |
321aecc6 CM |
2531 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, |
2532 | sub_stripes, 16); | |
0b86a832 CM |
2533 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); |
2534 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); | |
2535 | ||
2536 | static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, | |
2537 | int nr) | |
2538 | { | |
2539 | unsigned long offset = (unsigned long)c; | |
2540 | offset += offsetof(struct btrfs_chunk, stripe); | |
2541 | offset += nr * sizeof(struct btrfs_stripe); | |
2542 | return (struct btrfs_stripe *)offset; | |
2543 | } | |
2544 | ||
a443755f CM |
2545 | static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) |
2546 | { | |
2547 | return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); | |
2548 | } | |
2549 | ||
0b86a832 CM |
2550 | static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb, |
2551 | struct btrfs_chunk *c, int nr) | |
2552 | { | |
2553 | return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); | |
2554 | } | |
2555 | ||
0b86a832 CM |
2556 | static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, |
2557 | struct btrfs_chunk *c, int nr) | |
2558 | { | |
2559 | return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); | |
2560 | } | |
2561 | ||
5f39d397 CM |
2562 | /* struct btrfs_block_group_item */ |
2563 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, | |
2564 | used, 64); | |
2565 | BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, | |
2566 | used, 64); | |
0b86a832 CM |
2567 | BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid, |
2568 | struct btrfs_block_group_item, chunk_objectid, 64); | |
e17cade2 CM |
2569 | |
2570 | BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid, | |
0b86a832 CM |
2571 | struct btrfs_block_group_item, chunk_objectid, 64); |
2572 | BTRFS_SETGET_FUNCS(disk_block_group_flags, | |
2573 | struct btrfs_block_group_item, flags, 64); | |
2574 | BTRFS_SETGET_STACK_FUNCS(block_group_flags, | |
2575 | struct btrfs_block_group_item, flags, 64); | |
1e1d2701 | 2576 | |
208acb8c OS |
2577 | /* struct btrfs_free_space_info */ |
2578 | BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, | |
2579 | extent_count, 32); | |
2580 | BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); | |
2581 | ||
3954401f CM |
2582 | /* struct btrfs_inode_ref */ |
2583 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); | |
aec7477b | 2584 | BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); |
3954401f | 2585 | |
f186373f MF |
2586 | /* struct btrfs_inode_extref */ |
2587 | BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, | |
2588 | parent_objectid, 64); | |
2589 | BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, | |
2590 | name_len, 16); | |
2591 | BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); | |
2592 | ||
5f39d397 CM |
2593 | /* struct btrfs_inode_item */ |
2594 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); | |
c3027eb5 | 2595 | BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); |
e02119d5 | 2596 | BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); |
5f39d397 | 2597 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); |
a76a3cd4 | 2598 | BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); |
5f39d397 CM |
2599 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); |
2600 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); | |
2601 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); | |
2602 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); | |
2603 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); | |
0b86a832 | 2604 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); |
f2b636e8 | 2605 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); |
3cae210f QW |
2606 | BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item, |
2607 | generation, 64); | |
2608 | BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item, | |
2609 | sequence, 64); | |
2610 | BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item, | |
2611 | transid, 64); | |
2612 | BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64); | |
2613 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, | |
2614 | nbytes, 64); | |
2615 | BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item, | |
2616 | block_group, 64); | |
2617 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32); | |
2618 | BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32); | |
2619 | BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32); | |
2620 | BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32); | |
2621 | BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64); | |
2622 | BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64); | |
0b86a832 CM |
2623 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); |
2624 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); | |
3cae210f QW |
2625 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); |
2626 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); | |
e20d96d6 | 2627 | |
0b86a832 | 2628 | /* struct btrfs_dev_extent */ |
e17cade2 CM |
2629 | BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, |
2630 | chunk_tree, 64); | |
2631 | BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, | |
2632 | chunk_objectid, 64); | |
2633 | BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, | |
2634 | chunk_offset, 64); | |
0b86a832 CM |
2635 | BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); |
2636 | ||
231e88f4 | 2637 | static inline unsigned long btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev) |
e17cade2 CM |
2638 | { |
2639 | unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid); | |
231e88f4 | 2640 | return (unsigned long)dev + ptr; |
e17cade2 CM |
2641 | } |
2642 | ||
5d4f98a2 YZ |
2643 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); |
2644 | BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, | |
2645 | generation, 64); | |
2646 | BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); | |
74493f7a | 2647 | |
5d4f98a2 YZ |
2648 | BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32); |
2649 | ||
2650 | ||
2651 | BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); | |
2652 | ||
2653 | static inline void btrfs_tree_block_key(struct extent_buffer *eb, | |
2654 | struct btrfs_tree_block_info *item, | |
2655 | struct btrfs_disk_key *key) | |
2656 | { | |
2657 | read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); | |
2658 | } | |
2659 | ||
2660 | static inline void btrfs_set_tree_block_key(struct extent_buffer *eb, | |
2661 | struct btrfs_tree_block_info *item, | |
2662 | struct btrfs_disk_key *key) | |
2663 | { | |
2664 | write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); | |
2665 | } | |
e20d96d6 | 2666 | |
5d4f98a2 YZ |
2667 | BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, |
2668 | root, 64); | |
2669 | BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, | |
2670 | objectid, 64); | |
2671 | BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, | |
2672 | offset, 64); | |
2673 | BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, | |
2674 | count, 32); | |
2675 | ||
2676 | BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, | |
2677 | count, 32); | |
2678 | ||
2679 | BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, | |
2680 | type, 8); | |
2681 | BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, | |
2682 | offset, 64); | |
2683 | ||
2684 | static inline u32 btrfs_extent_inline_ref_size(int type) | |
2685 | { | |
2686 | if (type == BTRFS_TREE_BLOCK_REF_KEY || | |
2687 | type == BTRFS_SHARED_BLOCK_REF_KEY) | |
2688 | return sizeof(struct btrfs_extent_inline_ref); | |
2689 | if (type == BTRFS_SHARED_DATA_REF_KEY) | |
2690 | return sizeof(struct btrfs_shared_data_ref) + | |
2691 | sizeof(struct btrfs_extent_inline_ref); | |
2692 | if (type == BTRFS_EXTENT_DATA_REF_KEY) | |
2693 | return sizeof(struct btrfs_extent_data_ref) + | |
2694 | offsetof(struct btrfs_extent_inline_ref, offset); | |
2695 | BUG(); | |
2696 | return 0; | |
2697 | } | |
2698 | ||
2699 | BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64); | |
2700 | BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0, | |
2701 | generation, 64); | |
2702 | BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64); | |
2703 | BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32); | |
e20d96d6 | 2704 | |
5f39d397 CM |
2705 | /* struct btrfs_node */ |
2706 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); | |
74493f7a | 2707 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
3cae210f QW |
2708 | BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, |
2709 | blockptr, 64); | |
2710 | BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, | |
2711 | generation, 64); | |
e20d96d6 | 2712 | |
5f39d397 | 2713 | static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
cf27e1ee | 2714 | { |
5f39d397 CM |
2715 | unsigned long ptr; |
2716 | ptr = offsetof(struct btrfs_node, ptrs) + | |
2717 | sizeof(struct btrfs_key_ptr) * nr; | |
2718 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); | |
cf27e1ee CM |
2719 | } |
2720 | ||
5f39d397 CM |
2721 | static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
2722 | int nr, u64 val) | |
cf27e1ee | 2723 | { |
5f39d397 CM |
2724 | unsigned long ptr; |
2725 | ptr = offsetof(struct btrfs_node, ptrs) + | |
2726 | sizeof(struct btrfs_key_ptr) * nr; | |
2727 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); | |
cf27e1ee CM |
2728 | } |
2729 | ||
74493f7a CM |
2730 | static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
2731 | { | |
2732 | unsigned long ptr; | |
2733 | ptr = offsetof(struct btrfs_node, ptrs) + | |
2734 | sizeof(struct btrfs_key_ptr) * nr; | |
2735 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); | |
2736 | } | |
2737 | ||
2738 | static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, | |
2739 | int nr, u64 val) | |
2740 | { | |
2741 | unsigned long ptr; | |
2742 | ptr = offsetof(struct btrfs_node, ptrs) + | |
2743 | sizeof(struct btrfs_key_ptr) * nr; | |
2744 | btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); | |
2745 | } | |
2746 | ||
810191ff | 2747 | static inline unsigned long btrfs_node_key_ptr_offset(int nr) |
4d775673 | 2748 | { |
5f39d397 CM |
2749 | return offsetof(struct btrfs_node, ptrs) + |
2750 | sizeof(struct btrfs_key_ptr) * nr; | |
4d775673 CM |
2751 | } |
2752 | ||
e644d021 CM |
2753 | void btrfs_node_key(struct extent_buffer *eb, |
2754 | struct btrfs_disk_key *disk_key, int nr); | |
2755 | ||
5f39d397 CM |
2756 | static inline void btrfs_set_node_key(struct extent_buffer *eb, |
2757 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f8a0c | 2758 | { |
5f39d397 CM |
2759 | unsigned long ptr; |
2760 | ptr = btrfs_node_key_ptr_offset(nr); | |
2761 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, | |
2762 | struct btrfs_key_ptr, key, disk_key); | |
1d4f8a0c CM |
2763 | } |
2764 | ||
5f39d397 CM |
2765 | /* struct btrfs_item */ |
2766 | BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); | |
2767 | BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); | |
3cae210f QW |
2768 | BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); |
2769 | BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); | |
4d775673 | 2770 | |
5f39d397 | 2771 | static inline unsigned long btrfs_item_nr_offset(int nr) |
1d4f8a0c | 2772 | { |
5f39d397 CM |
2773 | return offsetof(struct btrfs_leaf, items) + |
2774 | sizeof(struct btrfs_item) * nr; | |
1d4f8a0c CM |
2775 | } |
2776 | ||
dd3cc16b | 2777 | static inline struct btrfs_item *btrfs_item_nr(int nr) |
0783fcfc | 2778 | { |
5f39d397 | 2779 | return (struct btrfs_item *)btrfs_item_nr_offset(nr); |
0783fcfc CM |
2780 | } |
2781 | ||
5f39d397 CM |
2782 | static inline u32 btrfs_item_end(struct extent_buffer *eb, |
2783 | struct btrfs_item *item) | |
0783fcfc | 2784 | { |
5f39d397 | 2785 | return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); |
0783fcfc CM |
2786 | } |
2787 | ||
5f39d397 | 2788 | static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 2789 | { |
dd3cc16b | 2790 | return btrfs_item_end(eb, btrfs_item_nr(nr)); |
0783fcfc CM |
2791 | } |
2792 | ||
5f39d397 | 2793 | static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 2794 | { |
dd3cc16b | 2795 | return btrfs_item_offset(eb, btrfs_item_nr(nr)); |
0783fcfc CM |
2796 | } |
2797 | ||
5f39d397 | 2798 | static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 2799 | { |
dd3cc16b | 2800 | return btrfs_item_size(eb, btrfs_item_nr(nr)); |
0783fcfc CM |
2801 | } |
2802 | ||
5f39d397 CM |
2803 | static inline void btrfs_item_key(struct extent_buffer *eb, |
2804 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 2805 | { |
dd3cc16b | 2806 | struct btrfs_item *item = btrfs_item_nr(nr); |
5f39d397 | 2807 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); |
1d4f6404 CM |
2808 | } |
2809 | ||
5f39d397 CM |
2810 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
2811 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 2812 | { |
dd3cc16b | 2813 | struct btrfs_item *item = btrfs_item_nr(nr); |
5f39d397 | 2814 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); |
1d4f6404 CM |
2815 | } |
2816 | ||
e02119d5 CM |
2817 | BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); |
2818 | ||
0660b5af CM |
2819 | /* |
2820 | * struct btrfs_root_ref | |
2821 | */ | |
2822 | BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); | |
2823 | BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); | |
2824 | BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); | |
2825 | ||
5f39d397 | 2826 | /* struct btrfs_dir_item */ |
5103e947 | 2827 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
5f39d397 CM |
2828 | BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); |
2829 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); | |
e02119d5 | 2830 | BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); |
3cae210f QW |
2831 | BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8); |
2832 | BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, | |
2833 | data_len, 16); | |
2834 | BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, | |
2835 | name_len, 16); | |
2836 | BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, | |
2837 | transid, 64); | |
1d4f6404 | 2838 | |
5f39d397 CM |
2839 | static inline void btrfs_dir_item_key(struct extent_buffer *eb, |
2840 | struct btrfs_dir_item *item, | |
2841 | struct btrfs_disk_key *key) | |
1d4f6404 | 2842 | { |
5f39d397 | 2843 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
1d4f6404 CM |
2844 | } |
2845 | ||
5f39d397 CM |
2846 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
2847 | struct btrfs_dir_item *item, | |
2848 | struct btrfs_disk_key *key) | |
a8a2ee0c | 2849 | { |
5f39d397 | 2850 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
a8a2ee0c CM |
2851 | } |
2852 | ||
0af3d00b JB |
2853 | BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, |
2854 | num_entries, 64); | |
2855 | BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, | |
2856 | num_bitmaps, 64); | |
2857 | BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, | |
2858 | generation, 64); | |
2859 | ||
2860 | static inline void btrfs_free_space_key(struct extent_buffer *eb, | |
2861 | struct btrfs_free_space_header *h, | |
2862 | struct btrfs_disk_key *key) | |
2863 | { | |
2864 | read_eb_member(eb, h, struct btrfs_free_space_header, location, key); | |
2865 | } | |
2866 | ||
2867 | static inline void btrfs_set_free_space_key(struct extent_buffer *eb, | |
2868 | struct btrfs_free_space_header *h, | |
2869 | struct btrfs_disk_key *key) | |
2870 | { | |
2871 | write_eb_member(eb, h, struct btrfs_free_space_header, location, key); | |
2872 | } | |
2873 | ||
5f39d397 CM |
2874 | /* struct btrfs_disk_key */ |
2875 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, | |
2876 | objectid, 64); | |
2877 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); | |
2878 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); | |
1d4f6404 | 2879 | |
e2fa7227 CM |
2880 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
2881 | struct btrfs_disk_key *disk) | |
2882 | { | |
2883 | cpu->offset = le64_to_cpu(disk->offset); | |
5f39d397 | 2884 | cpu->type = disk->type; |
e2fa7227 CM |
2885 | cpu->objectid = le64_to_cpu(disk->objectid); |
2886 | } | |
2887 | ||
2888 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
2889 | struct btrfs_key *cpu) | |
2890 | { | |
2891 | disk->offset = cpu_to_le64(cpu->offset); | |
5f39d397 | 2892 | disk->type = cpu->type; |
e2fa7227 CM |
2893 | disk->objectid = cpu_to_le64(cpu->objectid); |
2894 | } | |
2895 | ||
5f39d397 CM |
2896 | static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb, |
2897 | struct btrfs_key *key, int nr) | |
7f5c1516 | 2898 | { |
5f39d397 CM |
2899 | struct btrfs_disk_key disk_key; |
2900 | btrfs_node_key(eb, &disk_key, nr); | |
2901 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
2902 | } |
2903 | ||
5f39d397 CM |
2904 | static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, |
2905 | struct btrfs_key *key, int nr) | |
7f5c1516 | 2906 | { |
5f39d397 CM |
2907 | struct btrfs_disk_key disk_key; |
2908 | btrfs_item_key(eb, &disk_key, nr); | |
2909 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
2910 | } |
2911 | ||
5f39d397 CM |
2912 | static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, |
2913 | struct btrfs_dir_item *item, | |
2914 | struct btrfs_key *key) | |
4d775673 | 2915 | { |
5f39d397 CM |
2916 | struct btrfs_disk_key disk_key; |
2917 | btrfs_dir_item_key(eb, item, &disk_key); | |
2918 | btrfs_disk_key_to_cpu(key, &disk_key); | |
4d775673 CM |
2919 | } |
2920 | ||
58176a96 | 2921 | |
5f39d397 | 2922 | static inline u8 btrfs_key_type(struct btrfs_key *key) |
3768f368 | 2923 | { |
5f39d397 | 2924 | return key->type; |
3768f368 CM |
2925 | } |
2926 | ||
5f39d397 | 2927 | static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) |
3768f368 | 2928 | { |
5f39d397 | 2929 | key->type = val; |
3768f368 CM |
2930 | } |
2931 | ||
5f39d397 | 2932 | /* struct btrfs_header */ |
db94535d | 2933 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
5f39d397 CM |
2934 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, |
2935 | generation, 64); | |
2936 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); | |
2937 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); | |
63b10fc4 | 2938 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); |
5f39d397 | 2939 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); |
3cae210f QW |
2940 | BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, |
2941 | generation, 64); | |
2942 | BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); | |
2943 | BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, | |
2944 | nritems, 32); | |
2945 | BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); | |
0f7d52f4 | 2946 | |
63b10fc4 CM |
2947 | static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag) |
2948 | { | |
2949 | return (btrfs_header_flags(eb) & flag) == flag; | |
2950 | } | |
2951 | ||
2952 | static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) | |
2953 | { | |
2954 | u64 flags = btrfs_header_flags(eb); | |
2955 | btrfs_set_header_flags(eb, flags | flag); | |
2956 | return (flags & flag) == flag; | |
2957 | } | |
2958 | ||
2959 | static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) | |
2960 | { | |
2961 | u64 flags = btrfs_header_flags(eb); | |
2962 | btrfs_set_header_flags(eb, flags & ~flag); | |
2963 | return (flags & flag) == flag; | |
2964 | } | |
2965 | ||
5d4f98a2 YZ |
2966 | static inline int btrfs_header_backref_rev(struct extent_buffer *eb) |
2967 | { | |
2968 | u64 flags = btrfs_header_flags(eb); | |
2969 | return flags >> BTRFS_BACKREF_REV_SHIFT; | |
2970 | } | |
2971 | ||
2972 | static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, | |
2973 | int rev) | |
2974 | { | |
2975 | u64 flags = btrfs_header_flags(eb); | |
2976 | flags &= ~BTRFS_BACKREF_REV_MASK; | |
2977 | flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; | |
2978 | btrfs_set_header_flags(eb, flags); | |
2979 | } | |
2980 | ||
0a4e5586 | 2981 | static inline unsigned long btrfs_header_fsid(void) |
0f7d52f4 | 2982 | { |
fba6aa75 | 2983 | return offsetof(struct btrfs_header, fsid); |
0f7d52f4 CM |
2984 | } |
2985 | ||
b308bc2f | 2986 | static inline unsigned long btrfs_header_chunk_tree_uuid(struct extent_buffer *eb) |
e17cade2 | 2987 | { |
b308bc2f | 2988 | return offsetof(struct btrfs_header, chunk_tree_uuid); |
e17cade2 CM |
2989 | } |
2990 | ||
5f39d397 | 2991 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
3768f368 | 2992 | { |
d397712b | 2993 | return btrfs_header_level(eb) == 0; |
3768f368 CM |
2994 | } |
2995 | ||
5f39d397 | 2996 | /* struct btrfs_root_item */ |
84234f3a YZ |
2997 | BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, |
2998 | generation, 64); | |
5f39d397 | 2999 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); |
db94535d CM |
3000 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
3001 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); | |
3768f368 | 3002 | |
84234f3a YZ |
3003 | BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, |
3004 | generation, 64); | |
db94535d CM |
3005 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
3006 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); | |
5f39d397 CM |
3007 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
3008 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); | |
f2b636e8 | 3009 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); |
db94535d CM |
3010 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
3011 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); | |
80ff3856 YZ |
3012 | BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, |
3013 | last_snapshot, 64); | |
8ea05e3a AB |
3014 | BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, |
3015 | generation_v2, 64); | |
3016 | BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, | |
3017 | ctransid, 64); | |
3018 | BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, | |
3019 | otransid, 64); | |
3020 | BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, | |
3021 | stransid, 64); | |
3022 | BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, | |
3023 | rtransid, 64); | |
123abc88 | 3024 | |
b83cc969 LZ |
3025 | static inline bool btrfs_root_readonly(struct btrfs_root *root) |
3026 | { | |
6ed3cf2c | 3027 | return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0; |
b83cc969 LZ |
3028 | } |
3029 | ||
521e0546 DS |
3030 | static inline bool btrfs_root_dead(struct btrfs_root *root) |
3031 | { | |
3032 | return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_DEAD)) != 0; | |
3033 | } | |
3034 | ||
af31f5e5 CM |
3035 | /* struct btrfs_root_backup */ |
3036 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, | |
3037 | tree_root, 64); | |
3038 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, | |
3039 | tree_root_gen, 64); | |
3040 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, | |
3041 | tree_root_level, 8); | |
3042 | ||
3043 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, | |
3044 | chunk_root, 64); | |
3045 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, | |
3046 | chunk_root_gen, 64); | |
3047 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, | |
3048 | chunk_root_level, 8); | |
3049 | ||
3050 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, | |
3051 | extent_root, 64); | |
3052 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, | |
3053 | extent_root_gen, 64); | |
3054 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, | |
3055 | extent_root_level, 8); | |
3056 | ||
3057 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, | |
3058 | fs_root, 64); | |
3059 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, | |
3060 | fs_root_gen, 64); | |
3061 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, | |
3062 | fs_root_level, 8); | |
3063 | ||
3064 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, | |
3065 | dev_root, 64); | |
3066 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, | |
3067 | dev_root_gen, 64); | |
3068 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, | |
3069 | dev_root_level, 8); | |
3070 | ||
3071 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, | |
3072 | csum_root, 64); | |
3073 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, | |
3074 | csum_root_gen, 64); | |
3075 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, | |
3076 | csum_root_level, 8); | |
3077 | BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, | |
3078 | total_bytes, 64); | |
3079 | BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, | |
3080 | bytes_used, 64); | |
3081 | BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, | |
3082 | num_devices, 64); | |
3083 | ||
0940ebf6 ID |
3084 | /* struct btrfs_balance_item */ |
3085 | BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); | |
607d432d | 3086 | |
0940ebf6 ID |
3087 | static inline void btrfs_balance_data(struct extent_buffer *eb, |
3088 | struct btrfs_balance_item *bi, | |
3089 | struct btrfs_disk_balance_args *ba) | |
3090 | { | |
3091 | read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); | |
3092 | } | |
3093 | ||
3094 | static inline void btrfs_set_balance_data(struct extent_buffer *eb, | |
3095 | struct btrfs_balance_item *bi, | |
3096 | struct btrfs_disk_balance_args *ba) | |
3097 | { | |
3098 | write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); | |
3099 | } | |
3100 | ||
3101 | static inline void btrfs_balance_meta(struct extent_buffer *eb, | |
3102 | struct btrfs_balance_item *bi, | |
3103 | struct btrfs_disk_balance_args *ba) | |
3104 | { | |
3105 | read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); | |
3106 | } | |
3107 | ||
3108 | static inline void btrfs_set_balance_meta(struct extent_buffer *eb, | |
3109 | struct btrfs_balance_item *bi, | |
3110 | struct btrfs_disk_balance_args *ba) | |
3111 | { | |
3112 | write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); | |
3113 | } | |
3114 | ||
3115 | static inline void btrfs_balance_sys(struct extent_buffer *eb, | |
3116 | struct btrfs_balance_item *bi, | |
3117 | struct btrfs_disk_balance_args *ba) | |
3118 | { | |
3119 | read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); | |
3120 | } | |
3121 | ||
3122 | static inline void btrfs_set_balance_sys(struct extent_buffer *eb, | |
3123 | struct btrfs_balance_item *bi, | |
3124 | struct btrfs_disk_balance_args *ba) | |
3125 | { | |
3126 | write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); | |
3127 | } | |
3128 | ||
3129 | static inline void | |
3130 | btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, | |
3131 | struct btrfs_disk_balance_args *disk) | |
3132 | { | |
3133 | memset(cpu, 0, sizeof(*cpu)); | |
3134 | ||
3135 | cpu->profiles = le64_to_cpu(disk->profiles); | |
3136 | cpu->usage = le64_to_cpu(disk->usage); | |
3137 | cpu->devid = le64_to_cpu(disk->devid); | |
3138 | cpu->pstart = le64_to_cpu(disk->pstart); | |
3139 | cpu->pend = le64_to_cpu(disk->pend); | |
3140 | cpu->vstart = le64_to_cpu(disk->vstart); | |
3141 | cpu->vend = le64_to_cpu(disk->vend); | |
3142 | cpu->target = le64_to_cpu(disk->target); | |
3143 | cpu->flags = le64_to_cpu(disk->flags); | |
7d824b6f | 3144 | cpu->limit = le64_to_cpu(disk->limit); |
0940ebf6 ID |
3145 | } |
3146 | ||
3147 | static inline void | |
3148 | btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk, | |
3149 | struct btrfs_balance_args *cpu) | |
3150 | { | |
3151 | memset(disk, 0, sizeof(*disk)); | |
3152 | ||
3153 | disk->profiles = cpu_to_le64(cpu->profiles); | |
3154 | disk->usage = cpu_to_le64(cpu->usage); | |
3155 | disk->devid = cpu_to_le64(cpu->devid); | |
3156 | disk->pstart = cpu_to_le64(cpu->pstart); | |
3157 | disk->pend = cpu_to_le64(cpu->pend); | |
3158 | disk->vstart = cpu_to_le64(cpu->vstart); | |
3159 | disk->vend = cpu_to_le64(cpu->vend); | |
3160 | disk->target = cpu_to_le64(cpu->target); | |
3161 | disk->flags = cpu_to_le64(cpu->flags); | |
7d824b6f | 3162 | disk->limit = cpu_to_le64(cpu->limit); |
0940ebf6 ID |
3163 | } |
3164 | ||
3165 | /* struct btrfs_super_block */ | |
db94535d | 3166 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
a061fc8d | 3167 | BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); |
5f39d397 CM |
3168 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
3169 | generation, 64); | |
3170 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); | |
0b86a832 CM |
3171 | BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, |
3172 | struct btrfs_super_block, sys_chunk_array_size, 32); | |
84234f3a YZ |
3173 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, |
3174 | struct btrfs_super_block, chunk_root_generation, 64); | |
db94535d CM |
3175 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
3176 | root_level, 8); | |
0b86a832 CM |
3177 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, |
3178 | chunk_root, 64); | |
3179 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, | |
e02119d5 CM |
3180 | chunk_root_level, 8); |
3181 | BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, | |
3182 | log_root, 64); | |
c3027eb5 CM |
3183 | BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block, |
3184 | log_root_transid, 64); | |
e02119d5 CM |
3185 | BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, |
3186 | log_root_level, 8); | |
db94535d CM |
3187 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, |
3188 | total_bytes, 64); | |
3189 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, | |
3190 | bytes_used, 64); | |
5f39d397 CM |
3191 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
3192 | sectorsize, 32); | |
3193 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, | |
3194 | nodesize, 32); | |
87ee04eb CM |
3195 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
3196 | stripesize, 32); | |
5f39d397 CM |
3197 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
3198 | root_dir_objectid, 64); | |
8a4b83cc CM |
3199 | BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, |
3200 | num_devices, 64); | |
f2b636e8 JB |
3201 | BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, |
3202 | compat_flags, 64); | |
3203 | BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, | |
12534832 | 3204 | compat_ro_flags, 64); |
f2b636e8 JB |
3205 | BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, |
3206 | incompat_flags, 64); | |
607d432d JB |
3207 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, |
3208 | csum_type, 16); | |
0af3d00b JB |
3209 | BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, |
3210 | cache_generation, 64); | |
3cae210f | 3211 | BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); |
26432799 SB |
3212 | BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, |
3213 | uuid_tree_generation, 64); | |
607d432d JB |
3214 | |
3215 | static inline int btrfs_super_csum_size(struct btrfs_super_block *s) | |
3216 | { | |
1104a885 DS |
3217 | u16 t = btrfs_super_csum_type(s); |
3218 | /* | |
3219 | * csum type is validated at mount time | |
3220 | */ | |
607d432d JB |
3221 | return btrfs_csum_sizes[t]; |
3222 | } | |
2e635a27 | 3223 | |
5f39d397 | 3224 | static inline unsigned long btrfs_leaf_data(struct extent_buffer *l) |
2e635a27 | 3225 | { |
5f39d397 | 3226 | return offsetof(struct btrfs_leaf, items); |
2e635a27 CM |
3227 | } |
3228 | ||
5f39d397 CM |
3229 | /* struct btrfs_file_extent_item */ |
3230 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); | |
3cae210f QW |
3231 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, |
3232 | struct btrfs_file_extent_item, disk_bytenr, 64); | |
3233 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, | |
3234 | struct btrfs_file_extent_item, offset, 64); | |
3235 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, | |
3236 | struct btrfs_file_extent_item, generation, 64); | |
3237 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, | |
3238 | struct btrfs_file_extent_item, num_bytes, 64); | |
e20d6c5b JB |
3239 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, |
3240 | struct btrfs_file_extent_item, disk_num_bytes, 64); | |
3241 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, | |
3242 | struct btrfs_file_extent_item, compression, 8); | |
9f5fae2f | 3243 | |
d397712b CM |
3244 | static inline unsigned long |
3245 | btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e) | |
236454df | 3246 | { |
7ec20afb | 3247 | return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START; |
236454df CM |
3248 | } |
3249 | ||
3250 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) | |
3251 | { | |
7ec20afb | 3252 | return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; |
9f5fae2f CM |
3253 | } |
3254 | ||
db94535d CM |
3255 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
3256 | disk_bytenr, 64); | |
5f39d397 CM |
3257 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
3258 | generation, 64); | |
db94535d CM |
3259 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
3260 | disk_num_bytes, 64); | |
5f39d397 CM |
3261 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
3262 | offset, 64); | |
db94535d CM |
3263 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
3264 | num_bytes, 64); | |
c8b97818 CM |
3265 | BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, |
3266 | ram_bytes, 64); | |
3267 | BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, | |
3268 | compression, 8); | |
3269 | BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, | |
3270 | encryption, 8); | |
3271 | BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, | |
3272 | other_encoding, 16); | |
3273 | ||
c8b97818 CM |
3274 | /* |
3275 | * this returns the number of bytes used by the item on disk, minus the | |
3276 | * size of any extent headers. If a file is compressed on disk, this is | |
3277 | * the compressed size | |
3278 | */ | |
3279 | static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb, | |
3280 | struct btrfs_item *e) | |
3281 | { | |
7ec20afb | 3282 | return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START; |
c8b97818 | 3283 | } |
9f5fae2f | 3284 | |
514ac8ad CM |
3285 | /* this returns the number of file bytes represented by the inline item. |
3286 | * If an item is compressed, this is the uncompressed size | |
3287 | */ | |
3288 | static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb, | |
3289 | int slot, | |
3290 | struct btrfs_file_extent_item *fi) | |
3291 | { | |
3292 | struct btrfs_map_token token; | |
3293 | ||
3294 | btrfs_init_map_token(&token); | |
3295 | /* | |
3296 | * return the space used on disk if this item isn't | |
3297 | * compressed or encoded | |
3298 | */ | |
3299 | if (btrfs_token_file_extent_compression(eb, fi, &token) == 0 && | |
3300 | btrfs_token_file_extent_encryption(eb, fi, &token) == 0 && | |
3301 | btrfs_token_file_extent_other_encoding(eb, fi, &token) == 0) { | |
3302 | return btrfs_file_extent_inline_item_len(eb, | |
3303 | btrfs_item_nr(slot)); | |
3304 | } | |
3305 | ||
3306 | /* otherwise use the ram bytes field */ | |
3307 | return btrfs_token_file_extent_ram_bytes(eb, fi, &token); | |
3308 | } | |
3309 | ||
3310 | ||
733f4fbb SB |
3311 | /* btrfs_dev_stats_item */ |
3312 | static inline u64 btrfs_dev_stats_value(struct extent_buffer *eb, | |
3313 | struct btrfs_dev_stats_item *ptr, | |
3314 | int index) | |
3315 | { | |
3316 | u64 val; | |
3317 | ||
3318 | read_extent_buffer(eb, &val, | |
3319 | offsetof(struct btrfs_dev_stats_item, values) + | |
3320 | ((unsigned long)ptr) + (index * sizeof(u64)), | |
3321 | sizeof(val)); | |
3322 | return val; | |
3323 | } | |
3324 | ||
3325 | static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb, | |
3326 | struct btrfs_dev_stats_item *ptr, | |
3327 | int index, u64 val) | |
3328 | { | |
3329 | write_extent_buffer(eb, &val, | |
3330 | offsetof(struct btrfs_dev_stats_item, values) + | |
3331 | ((unsigned long)ptr) + (index * sizeof(u64)), | |
3332 | sizeof(val)); | |
3333 | } | |
3334 | ||
630dc772 AJ |
3335 | /* btrfs_qgroup_status_item */ |
3336 | BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, | |
3337 | generation, 64); | |
3338 | BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, | |
3339 | version, 64); | |
3340 | BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, | |
3341 | flags, 64); | |
2f232036 JS |
3342 | BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, |
3343 | rescan, 64); | |
630dc772 AJ |
3344 | |
3345 | /* btrfs_qgroup_info_item */ | |
3346 | BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, | |
3347 | generation, 64); | |
3348 | BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); | |
3349 | BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, | |
3350 | rfer_cmpr, 64); | |
3351 | BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); | |
3352 | BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, | |
3353 | excl_cmpr, 64); | |
3354 | ||
3355 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, | |
3356 | struct btrfs_qgroup_info_item, generation, 64); | |
3357 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, | |
3358 | rfer, 64); | |
3359 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, | |
3360 | struct btrfs_qgroup_info_item, rfer_cmpr, 64); | |
3361 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, | |
3362 | excl, 64); | |
3363 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, | |
3364 | struct btrfs_qgroup_info_item, excl_cmpr, 64); | |
3365 | ||
3366 | /* btrfs_qgroup_limit_item */ | |
3367 | BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, | |
3368 | flags, 64); | |
3369 | BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, | |
3370 | max_rfer, 64); | |
3371 | BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, | |
3372 | max_excl, 64); | |
3373 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, | |
3374 | rsv_rfer, 64); | |
3375 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, | |
3376 | rsv_excl, 64); | |
3377 | ||
a2bff640 SB |
3378 | /* btrfs_dev_replace_item */ |
3379 | BTRFS_SETGET_FUNCS(dev_replace_src_devid, | |
3380 | struct btrfs_dev_replace_item, src_devid, 64); | |
3381 | BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, | |
3382 | struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, | |
3383 | 64); | |
3384 | BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, | |
3385 | replace_state, 64); | |
3386 | BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, | |
3387 | time_started, 64); | |
3388 | BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, | |
3389 | time_stopped, 64); | |
3390 | BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, | |
3391 | num_write_errors, 64); | |
3392 | BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, | |
3393 | struct btrfs_dev_replace_item, num_uncorrectable_read_errors, | |
3394 | 64); | |
3395 | BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, | |
3396 | cursor_left, 64); | |
3397 | BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, | |
3398 | cursor_right, 64); | |
3399 | ||
3400 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, | |
3401 | struct btrfs_dev_replace_item, src_devid, 64); | |
3402 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, | |
3403 | struct btrfs_dev_replace_item, | |
3404 | cont_reading_from_srcdev_mode, 64); | |
3405 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, | |
3406 | struct btrfs_dev_replace_item, replace_state, 64); | |
3407 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, | |
3408 | struct btrfs_dev_replace_item, time_started, 64); | |
3409 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, | |
3410 | struct btrfs_dev_replace_item, time_stopped, 64); | |
3411 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, | |
3412 | struct btrfs_dev_replace_item, num_write_errors, 64); | |
3413 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, | |
3414 | struct btrfs_dev_replace_item, | |
3415 | num_uncorrectable_read_errors, 64); | |
3416 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, | |
3417 | struct btrfs_dev_replace_item, cursor_left, 64); | |
3418 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, | |
3419 | struct btrfs_dev_replace_item, cursor_right, 64); | |
3420 | ||
815745cf | 3421 | static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) |
e20d96d6 CM |
3422 | { |
3423 | return sb->s_fs_info; | |
3424 | } | |
3425 | ||
4beb1b8b CM |
3426 | /* helper function to cast into the data area of the leaf. */ |
3427 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 | 3428 | ((type *)(btrfs_leaf_data(leaf) + \ |
5f39d397 CM |
3429 | btrfs_item_offset_nr(leaf, slot))) |
3430 | ||
3431 | #define btrfs_item_ptr_offset(leaf, slot) \ | |
3432 | ((unsigned long)(btrfs_leaf_data(leaf) + \ | |
3433 | btrfs_item_offset_nr(leaf, slot))) | |
4beb1b8b | 3434 | |
67377734 JB |
3435 | static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) |
3436 | { | |
3437 | return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) && | |
3438 | (space_info->flags & BTRFS_BLOCK_GROUP_DATA)); | |
3439 | } | |
3440 | ||
3b16a4e3 JB |
3441 | static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) |
3442 | { | |
c62d2555 | 3443 | return mapping_gfp_constraint(mapping, ~__GFP_FS); |
3b16a4e3 JB |
3444 | } |
3445 | ||
b18c6685 | 3446 | /* extent-tree.c */ |
28f75a0e CM |
3447 | |
3448 | u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes); | |
3449 | ||
16cdcec7 | 3450 | static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root, |
9e0baf60 | 3451 | unsigned num_items) |
16cdcec7 | 3452 | { |
707e8a07 | 3453 | return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) * |
c4fbb430 | 3454 | 2 * num_items; |
07127184 JB |
3455 | } |
3456 | ||
3457 | /* | |
3458 | * Doing a truncate won't result in new nodes or leaves, just what we need for | |
3459 | * COW. | |
3460 | */ | |
3461 | static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root, | |
3462 | unsigned num_items) | |
3463 | { | |
707e8a07 | 3464 | return root->nodesize * BTRFS_MAX_LEVEL * num_items; |
16cdcec7 MX |
3465 | } |
3466 | ||
1be41b78 JB |
3467 | int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, |
3468 | struct btrfs_root *root); | |
0a2b2a84 JB |
3469 | int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, |
3470 | struct btrfs_root *root); | |
fa9c0d79 | 3471 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
56bec294 CM |
3472 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, |
3473 | struct btrfs_root *root, unsigned long count); | |
a79b7d4b CM |
3474 | int btrfs_async_run_delayed_refs(struct btrfs_root *root, |
3475 | unsigned long count, int wait); | |
1a4ed8fd | 3476 | int btrfs_lookup_data_extent(struct btrfs_root *root, u64 start, u64 len); |
a22285a6 YZ |
3477 | int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, |
3478 | struct btrfs_root *root, u64 bytenr, | |
3173a18f | 3479 | u64 offset, int metadata, u64 *refs, u64 *flags); |
11833d66 YZ |
3480 | int btrfs_pin_extent(struct btrfs_root *root, |
3481 | u64 bytenr, u64 num, int reserved); | |
dcfac415 | 3482 | int btrfs_pin_extent_for_log_replay(struct btrfs_root *root, |
e688b725 | 3483 | u64 bytenr, u64 num_bytes); |
8c2a1a30 JB |
3484 | int btrfs_exclude_logged_extents(struct btrfs_root *root, |
3485 | struct extent_buffer *eb); | |
80ff3856 | 3486 | int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, |
5d4f98a2 YZ |
3487 | struct btrfs_root *root, |
3488 | u64 objectid, u64 offset, u64 bytenr); | |
d397712b CM |
3489 | struct btrfs_block_group_cache *btrfs_lookup_block_group( |
3490 | struct btrfs_fs_info *info, | |
3491 | u64 bytenr); | |
758f2dfc | 3492 | void btrfs_get_block_group(struct btrfs_block_group_cache *cache); |
5d4f98a2 | 3493 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
6ab0a202 | 3494 | int get_block_group_index(struct btrfs_block_group_cache *cache); |
4d75f8a9 DS |
3495 | struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, |
3496 | struct btrfs_root *root, u64 parent, | |
3497 | u64 root_objectid, | |
5d4f98a2 | 3498 | struct btrfs_disk_key *key, int level, |
5581a51a | 3499 | u64 hint, u64 empty_size); |
f0486c68 YZ |
3500 | void btrfs_free_tree_block(struct btrfs_trans_handle *trans, |
3501 | struct btrfs_root *root, | |
3502 | struct extent_buffer *buf, | |
5581a51a | 3503 | u64 parent, int last_ref); |
5d4f98a2 YZ |
3504 | int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, |
3505 | struct btrfs_root *root, | |
3506 | u64 root_objectid, u64 owner, | |
5846a3c2 QW |
3507 | u64 offset, u64 ram_bytes, |
3508 | struct btrfs_key *ins); | |
5d4f98a2 YZ |
3509 | int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, |
3510 | struct btrfs_root *root, | |
3511 | u64 root_objectid, u64 owner, u64 offset, | |
3512 | struct btrfs_key *ins); | |
00361589 JB |
3513 | int btrfs_reserve_extent(struct btrfs_root *root, u64 num_bytes, |
3514 | u64 min_alloc_size, u64 empty_size, u64 hint_byte, | |
e570fd27 | 3515 | struct btrfs_key *ins, int is_data, int delalloc); |
e089f05c | 3516 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
e339a6b0 | 3517 | struct extent_buffer *buf, int full_backref); |
5d4f98a2 | 3518 | int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
e339a6b0 | 3519 | struct extent_buffer *buf, int full_backref); |
5d4f98a2 YZ |
3520 | int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, |
3521 | struct btrfs_root *root, | |
3522 | u64 bytenr, u64 num_bytes, u64 flags, | |
b1c79e09 | 3523 | int level, int is_data); |
31840ae1 ZY |
3524 | int btrfs_free_extent(struct btrfs_trans_handle *trans, |
3525 | struct btrfs_root *root, | |
66d7e7f0 | 3526 | u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid, |
b06c4bf5 | 3527 | u64 owner, u64 offset); |
5d4f98a2 | 3528 | |
e570fd27 MX |
3529 | int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len, |
3530 | int delalloc); | |
e688b725 CM |
3531 | int btrfs_free_and_pin_reserved_extent(struct btrfs_root *root, |
3532 | u64 start, u64 len); | |
143bede5 JM |
3533 | void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, |
3534 | struct btrfs_root *root); | |
ccd467d6 | 3535 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, |
11833d66 | 3536 | struct btrfs_root *root); |
b18c6685 | 3537 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
31840ae1 ZY |
3538 | struct btrfs_root *root, |
3539 | u64 bytenr, u64 num_bytes, u64 parent, | |
b06c4bf5 | 3540 | u64 root_objectid, u64 owner, u64 offset); |
5d4f98a2 | 3541 | |
1bbc621e CM |
3542 | int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans, |
3543 | struct btrfs_root *root); | |
9078a3e1 CM |
3544 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
3545 | struct btrfs_root *root); | |
dcdf7f6d JB |
3546 | int btrfs_setup_space_cache(struct btrfs_trans_handle *trans, |
3547 | struct btrfs_root *root); | |
d2fb3437 | 3548 | int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr); |
9078a3e1 CM |
3549 | int btrfs_free_block_groups(struct btrfs_fs_info *info); |
3550 | int btrfs_read_block_groups(struct btrfs_root *root); | |
ba1bf481 | 3551 | int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr); |
0b86a832 CM |
3552 | int btrfs_make_block_group(struct btrfs_trans_handle *trans, |
3553 | struct btrfs_root *root, u64 bytes_used, | |
e17cade2 | 3554 | u64 type, u64 chunk_objectid, u64 chunk_offset, |
0b86a832 | 3555 | u64 size); |
8eab77ff | 3556 | struct btrfs_trans_handle *btrfs_start_trans_remove_block_group( |
7fd01182 FM |
3557 | struct btrfs_fs_info *fs_info, |
3558 | const u64 chunk_offset); | |
1a40e23b | 3559 | int btrfs_remove_block_group(struct btrfs_trans_handle *trans, |
04216820 FM |
3560 | struct btrfs_root *root, u64 group_start, |
3561 | struct extent_map *em); | |
47ab2a6c | 3562 | void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info); |
e33e17ee JM |
3563 | void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache); |
3564 | void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *cache); | |
ea658bad JB |
3565 | void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans, |
3566 | struct btrfs_root *root); | |
6d07bcec | 3567 | u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data); |
4184ea7f | 3568 | void btrfs_clear_space_info_full(struct btrfs_fs_info *info); |
08e007d2 MX |
3569 | |
3570 | enum btrfs_reserve_flush_enum { | |
3571 | /* If we are in the transaction, we can't flush anything.*/ | |
3572 | BTRFS_RESERVE_NO_FLUSH, | |
3573 | /* | |
3574 | * Flushing delalloc may cause deadlock somewhere, in this | |
3575 | * case, use FLUSH LIMIT | |
3576 | */ | |
3577 | BTRFS_RESERVE_FLUSH_LIMIT, | |
3578 | BTRFS_RESERVE_FLUSH_ALL, | |
3579 | }; | |
3580 | ||
7cf5b976 | 3581 | int btrfs_check_data_free_space(struct inode *inode, u64 start, u64 len); |
4ceff079 | 3582 | int btrfs_alloc_data_chunk_ondemand(struct inode *inode, u64 bytes); |
7cf5b976 | 3583 | void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len); |
51773bec QW |
3584 | void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, |
3585 | u64 len); | |
a22285a6 YZ |
3586 | void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, |
3587 | struct btrfs_root *root); | |
4fbcdf66 | 3588 | void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans); |
d68fc57b YZ |
3589 | int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans, |
3590 | struct inode *inode); | |
3591 | void btrfs_orphan_release_metadata(struct inode *inode); | |
d5c12070 MX |
3592 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
3593 | struct btrfs_block_rsv *rsv, | |
3594 | int nitems, | |
ee3441b4 | 3595 | u64 *qgroup_reserved, bool use_global_rsv); |
d5c12070 MX |
3596 | void btrfs_subvolume_release_metadata(struct btrfs_root *root, |
3597 | struct btrfs_block_rsv *rsv, | |
3598 | u64 qgroup_reserved); | |
0ca1f7ce YZ |
3599 | int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes); |
3600 | void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); | |
7cf5b976 QW |
3601 | int btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len); |
3602 | void btrfs_delalloc_release_space(struct inode *inode, u64 start, u64 len); | |
66d8f3dd MX |
3603 | void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type); |
3604 | struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root, | |
3605 | unsigned short type); | |
f0486c68 YZ |
3606 | void btrfs_free_block_rsv(struct btrfs_root *root, |
3607 | struct btrfs_block_rsv *rsv); | |
cdfb080e | 3608 | void __btrfs_free_block_rsv(struct btrfs_block_rsv *rsv); |
4a92b1b8 | 3609 | int btrfs_block_rsv_add(struct btrfs_root *root, |
08e007d2 MX |
3610 | struct btrfs_block_rsv *block_rsv, u64 num_bytes, |
3611 | enum btrfs_reserve_flush_enum flush); | |
4a92b1b8 | 3612 | int btrfs_block_rsv_check(struct btrfs_root *root, |
36ba022a JB |
3613 | struct btrfs_block_rsv *block_rsv, int min_factor); |
3614 | int btrfs_block_rsv_refill(struct btrfs_root *root, | |
08e007d2 MX |
3615 | struct btrfs_block_rsv *block_rsv, u64 min_reserved, |
3616 | enum btrfs_reserve_flush_enum flush); | |
f0486c68 YZ |
3617 | int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, |
3618 | struct btrfs_block_rsv *dst_rsv, | |
3619 | u64 num_bytes); | |
d52be818 JB |
3620 | int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info, |
3621 | struct btrfs_block_rsv *dest, u64 num_bytes, | |
3622 | int min_factor); | |
f0486c68 YZ |
3623 | void btrfs_block_rsv_release(struct btrfs_root *root, |
3624 | struct btrfs_block_rsv *block_rsv, | |
3625 | u64 num_bytes); | |
868f401a | 3626 | int btrfs_inc_block_group_ro(struct btrfs_root *root, |
f0486c68 | 3627 | struct btrfs_block_group_cache *cache); |
868f401a | 3628 | void btrfs_dec_block_group_ro(struct btrfs_root *root, |
143bede5 | 3629 | struct btrfs_block_group_cache *cache); |
0af3d00b | 3630 | void btrfs_put_block_group_cache(struct btrfs_fs_info *info); |
6d07bcec | 3631 | u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); |
acce952b | 3632 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, |
3633 | u64 start, u64 end); | |
1edb647b FM |
3634 | int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, |
3635 | u64 num_bytes, u64 *actual_bytes); | |
c87f08ca CM |
3636 | int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, |
3637 | struct btrfs_root *root, u64 type); | |
f7039b1d | 3638 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); |
acce952b | 3639 | |
c59021f8 | 3640 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info); |
bed92eae AJ |
3641 | int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans, |
3642 | struct btrfs_fs_info *fs_info); | |
31e50229 | 3643 | int __get_raid_index(u64 flags); |
9ea24bbe FM |
3644 | int btrfs_start_write_no_snapshoting(struct btrfs_root *root); |
3645 | void btrfs_end_write_no_snapshoting(struct btrfs_root *root); | |
0bc19f90 | 3646 | void btrfs_wait_for_snapshot_creation(struct btrfs_root *root); |
39c2d7fa FM |
3647 | void check_system_chunk(struct btrfs_trans_handle *trans, |
3648 | struct btrfs_root *root, | |
4617ea3a | 3649 | const u64 type); |
a5ed9182 OS |
3650 | u64 add_new_free_space(struct btrfs_block_group_cache *block_group, |
3651 | struct btrfs_fs_info *info, u64 start, u64 end); | |
3652 | ||
dee26a9f | 3653 | /* ctree.c */ |
5d4f98a2 YZ |
3654 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, |
3655 | int level, int *slot); | |
3656 | int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2); | |
0b86a832 CM |
3657 | int btrfs_previous_item(struct btrfs_root *root, |
3658 | struct btrfs_path *path, u64 min_objectid, | |
3659 | int type); | |
ade2e0b3 WS |
3660 | int btrfs_previous_extent_item(struct btrfs_root *root, |
3661 | struct btrfs_path *path, u64 min_objectid); | |
b7a0365e DD |
3662 | void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, |
3663 | struct btrfs_path *path, | |
143bede5 | 3664 | struct btrfs_key *new_key); |
925baedd CM |
3665 | struct extent_buffer *btrfs_root_node(struct btrfs_root *root); |
3666 | struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); | |
e7a84565 | 3667 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, |
3f157a2f | 3668 | struct btrfs_key *key, int lowest_level, |
de78b51a | 3669 | u64 min_trans); |
3f157a2f | 3670 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, |
de78b51a | 3671 | struct btrfs_path *path, |
3f157a2f | 3672 | u64 min_trans); |
7069830a AB |
3673 | enum btrfs_compare_tree_result { |
3674 | BTRFS_COMPARE_TREE_NEW, | |
3675 | BTRFS_COMPARE_TREE_DELETED, | |
3676 | BTRFS_COMPARE_TREE_CHANGED, | |
ba5e8f2e | 3677 | BTRFS_COMPARE_TREE_SAME, |
7069830a AB |
3678 | }; |
3679 | typedef int (*btrfs_changed_cb_t)(struct btrfs_root *left_root, | |
3680 | struct btrfs_root *right_root, | |
3681 | struct btrfs_path *left_path, | |
3682 | struct btrfs_path *right_path, | |
3683 | struct btrfs_key *key, | |
3684 | enum btrfs_compare_tree_result result, | |
3685 | void *ctx); | |
3686 | int btrfs_compare_trees(struct btrfs_root *left_root, | |
3687 | struct btrfs_root *right_root, | |
3688 | btrfs_changed_cb_t cb, void *ctx); | |
5f39d397 CM |
3689 | int btrfs_cow_block(struct btrfs_trans_handle *trans, |
3690 | struct btrfs_root *root, struct extent_buffer *buf, | |
3691 | struct extent_buffer *parent, int parent_slot, | |
9fa8cfe7 | 3692 | struct extent_buffer **cow_ret); |
be20aa9d CM |
3693 | int btrfs_copy_root(struct btrfs_trans_handle *trans, |
3694 | struct btrfs_root *root, | |
3695 | struct extent_buffer *buf, | |
3696 | struct extent_buffer **cow_ret, u64 new_root_objectid); | |
5d4f98a2 YZ |
3697 | int btrfs_block_can_be_shared(struct btrfs_root *root, |
3698 | struct extent_buffer *buf); | |
4b90c680 | 3699 | void btrfs_extend_item(struct btrfs_root *root, struct btrfs_path *path, |
143bede5 | 3700 | u32 data_size); |
afe5fea7 | 3701 | void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path, |
143bede5 | 3702 | u32 new_size, int from_end); |
459931ec CM |
3703 | int btrfs_split_item(struct btrfs_trans_handle *trans, |
3704 | struct btrfs_root *root, | |
3705 | struct btrfs_path *path, | |
3706 | struct btrfs_key *new_key, | |
3707 | unsigned long split_offset); | |
ad48fd75 YZ |
3708 | int btrfs_duplicate_item(struct btrfs_trans_handle *trans, |
3709 | struct btrfs_root *root, | |
3710 | struct btrfs_path *path, | |
3711 | struct btrfs_key *new_key); | |
e33d5c3d KN |
3712 | int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, |
3713 | u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); | |
e089f05c CM |
3714 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
3715 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
3716 | ins_len, int cow); | |
5d9e75c4 JS |
3717 | int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, |
3718 | struct btrfs_path *p, u64 time_seq); | |
2f38b3e1 AJ |
3719 | int btrfs_search_slot_for_read(struct btrfs_root *root, |
3720 | struct btrfs_key *key, struct btrfs_path *p, | |
3721 | int find_higher, int return_any); | |
6702ed49 | 3722 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
5f39d397 | 3723 | struct btrfs_root *root, struct extent_buffer *parent, |
de78b51a | 3724 | int start_slot, u64 *last_ret, |
a6b6e75e | 3725 | struct btrfs_key *progress); |
b3b4aa74 | 3726 | void btrfs_release_path(struct btrfs_path *p); |
2c90e5d6 CM |
3727 | struct btrfs_path *btrfs_alloc_path(void); |
3728 | void btrfs_free_path(struct btrfs_path *p); | |
b4ce94de | 3729 | void btrfs_set_path_blocking(struct btrfs_path *p); |
16cdcec7 | 3730 | void btrfs_clear_path_blocking(struct btrfs_path *p, |
bd681513 | 3731 | struct extent_buffer *held, int held_rw); |
b4ce94de CM |
3732 | void btrfs_unlock_up_safe(struct btrfs_path *p, int level); |
3733 | ||
85e21bac CM |
3734 | int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
3735 | struct btrfs_path *path, int slot, int nr); | |
85e21bac CM |
3736 | static inline int btrfs_del_item(struct btrfs_trans_handle *trans, |
3737 | struct btrfs_root *root, | |
3738 | struct btrfs_path *path) | |
3739 | { | |
3740 | return btrfs_del_items(trans, root, path, path->slots[0], 1); | |
3741 | } | |
3742 | ||
afe5fea7 | 3743 | void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, |
143bede5 JM |
3744 | struct btrfs_key *cpu_key, u32 *data_size, |
3745 | u32 total_data, u32 total_size, int nr); | |
e089f05c CM |
3746 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root |
3747 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
9c58309d CM |
3748 | int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, |
3749 | struct btrfs_root *root, | |
3750 | struct btrfs_path *path, | |
3751 | struct btrfs_key *cpu_key, u32 *data_size, int nr); | |
3752 | ||
3753 | static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, | |
3754 | struct btrfs_root *root, | |
3755 | struct btrfs_path *path, | |
3756 | struct btrfs_key *key, | |
3757 | u32 data_size) | |
3758 | { | |
3759 | return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1); | |
3760 | } | |
3761 | ||
234b63a0 | 3762 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
16e7549f | 3763 | int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
3d7806ec JS |
3764 | int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, |
3765 | u64 time_seq); | |
1c8f52a5 AB |
3766 | static inline int btrfs_next_old_item(struct btrfs_root *root, |
3767 | struct btrfs_path *p, u64 time_seq) | |
c7d22a3c JS |
3768 | { |
3769 | ++p->slots[0]; | |
3770 | if (p->slots[0] >= btrfs_header_nritems(p->nodes[0])) | |
1c8f52a5 | 3771 | return btrfs_next_old_leaf(root, p, time_seq); |
c7d22a3c JS |
3772 | return 0; |
3773 | } | |
1c8f52a5 AB |
3774 | static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) |
3775 | { | |
3776 | return btrfs_next_old_item(root, p, 0); | |
3777 | } | |
5f39d397 | 3778 | int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); |
2c536799 JM |
3779 | int __must_check btrfs_drop_snapshot(struct btrfs_root *root, |
3780 | struct btrfs_block_rsv *block_rsv, | |
3781 | int update_ref, int for_reloc); | |
f82d02d9 YZ |
3782 | int btrfs_drop_subtree(struct btrfs_trans_handle *trans, |
3783 | struct btrfs_root *root, | |
3784 | struct extent_buffer *node, | |
3785 | struct extent_buffer *parent); | |
7841cb28 DS |
3786 | static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info) |
3787 | { | |
3788 | /* | |
3789 | * Get synced with close_ctree() | |
3790 | */ | |
3791 | smp_mb(); | |
3792 | return fs_info->closing; | |
3793 | } | |
babbf170 MX |
3794 | |
3795 | /* | |
3796 | * If we remount the fs to be R/O or umount the fs, the cleaner needn't do | |
3797 | * anything except sleeping. This function is used to check the status of | |
3798 | * the fs. | |
3799 | */ | |
3800 | static inline int btrfs_need_cleaner_sleep(struct btrfs_root *root) | |
3801 | { | |
3802 | return (root->fs_info->sb->s_flags & MS_RDONLY || | |
3803 | btrfs_fs_closing(root->fs_info)); | |
3804 | } | |
3805 | ||
6c41761f DS |
3806 | static inline void free_fs_info(struct btrfs_fs_info *fs_info) |
3807 | { | |
837d5b6e | 3808 | kfree(fs_info->balance_ctl); |
6c41761f DS |
3809 | kfree(fs_info->delayed_root); |
3810 | kfree(fs_info->extent_root); | |
3811 | kfree(fs_info->tree_root); | |
3812 | kfree(fs_info->chunk_root); | |
3813 | kfree(fs_info->dev_root); | |
3814 | kfree(fs_info->csum_root); | |
bcef60f2 | 3815 | kfree(fs_info->quota_root); |
d8f98039 | 3816 | kfree(fs_info->uuid_root); |
70f6d82e | 3817 | kfree(fs_info->free_space_root); |
6c41761f DS |
3818 | kfree(fs_info->super_copy); |
3819 | kfree(fs_info->super_for_commit); | |
f667aef6 | 3820 | security_free_mnt_opts(&fs_info->security_opts); |
6c41761f DS |
3821 | kfree(fs_info); |
3822 | } | |
7841cb28 | 3823 | |
097b8a7c JS |
3824 | /* tree mod log functions from ctree.c */ |
3825 | u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info, | |
3826 | struct seq_list *elem); | |
3827 | void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, | |
3828 | struct seq_list *elem); | |
5b6602e7 | 3829 | int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq); |
097b8a7c | 3830 | |
dee26a9f | 3831 | /* root-item.c */ |
ea9e8b11 | 3832 | int btrfs_find_root_ref(struct btrfs_root *tree_root, |
4df27c4d YZ |
3833 | struct btrfs_path *path, |
3834 | u64 root_id, u64 ref_id); | |
0660b5af CM |
3835 | int btrfs_add_root_ref(struct btrfs_trans_handle *trans, |
3836 | struct btrfs_root *tree_root, | |
4df27c4d YZ |
3837 | u64 root_id, u64 ref_id, u64 dirid, u64 sequence, |
3838 | const char *name, int name_len); | |
3839 | int btrfs_del_root_ref(struct btrfs_trans_handle *trans, | |
3840 | struct btrfs_root *tree_root, | |
3841 | u64 root_id, u64 ref_id, u64 dirid, u64 *sequence, | |
0660b5af | 3842 | const char *name, int name_len); |
e089f05c CM |
3843 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
3844 | struct btrfs_key *key); | |
3845 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
3846 | *root, struct btrfs_key *key, struct btrfs_root_item | |
3847 | *item); | |
b45a9d8b JM |
3848 | int __must_check btrfs_update_root(struct btrfs_trans_handle *trans, |
3849 | struct btrfs_root *root, | |
3850 | struct btrfs_key *key, | |
3851 | struct btrfs_root_item *item); | |
cb517eab MX |
3852 | int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key, |
3853 | struct btrfs_path *path, struct btrfs_root_item *root_item, | |
3854 | struct btrfs_key *root_key); | |
76dda93c | 3855 | int btrfs_find_orphan_roots(struct btrfs_root *tree_root); |
bf5f32ec MF |
3856 | void btrfs_set_root_node(struct btrfs_root_item *item, |
3857 | struct extent_buffer *node); | |
08fe4db1 | 3858 | void btrfs_check_and_init_root_item(struct btrfs_root_item *item); |
8ea05e3a AB |
3859 | void btrfs_update_root_times(struct btrfs_trans_handle *trans, |
3860 | struct btrfs_root *root); | |
08fe4db1 | 3861 | |
07b30a49 SB |
3862 | /* uuid-tree.c */ |
3863 | int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, | |
3864 | struct btrfs_root *uuid_root, u8 *uuid, u8 type, | |
3865 | u64 subid); | |
3866 | int btrfs_uuid_tree_rem(struct btrfs_trans_handle *trans, | |
3867 | struct btrfs_root *uuid_root, u8 *uuid, u8 type, | |
3868 | u64 subid); | |
70f80175 SB |
3869 | int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info, |
3870 | int (*check_func)(struct btrfs_fs_info *, u8 *, u8, | |
3871 | u64)); | |
07b30a49 | 3872 | |
dee26a9f | 3873 | /* dir-item.c */ |
9c52057c CM |
3874 | int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir, |
3875 | const char *name, int name_len); | |
d397712b CM |
3876 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, |
3877 | struct btrfs_root *root, const char *name, | |
16cdcec7 | 3878 | int name_len, struct inode *dir, |
aec7477b | 3879 | struct btrfs_key *location, u8 type, u64 index); |
7e38180e CM |
3880 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
3881 | struct btrfs_root *root, | |
3882 | struct btrfs_path *path, u64 dir, | |
3883 | const char *name, int name_len, | |
3884 | int mod); | |
3885 | struct btrfs_dir_item * | |
3886 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, | |
3887 | struct btrfs_root *root, | |
3888 | struct btrfs_path *path, u64 dir, | |
3889 | u64 objectid, const char *name, int name_len, | |
3890 | int mod); | |
4df27c4d YZ |
3891 | struct btrfs_dir_item * |
3892 | btrfs_search_dir_index_item(struct btrfs_root *root, | |
3893 | struct btrfs_path *path, u64 dirid, | |
3894 | const char *name, int name_len); | |
7e38180e CM |
3895 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
3896 | struct btrfs_root *root, | |
3897 | struct btrfs_path *path, | |
3898 | struct btrfs_dir_item *di); | |
5103e947 | 3899 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
f34f57a3 YZ |
3900 | struct btrfs_root *root, |
3901 | struct btrfs_path *path, u64 objectid, | |
3902 | const char *name, u16 name_len, | |
3903 | const void *data, u16 data_len); | |
5103e947 JB |
3904 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, |
3905 | struct btrfs_root *root, | |
3906 | struct btrfs_path *path, u64 dir, | |
3907 | const char *name, u16 name_len, | |
3908 | int mod); | |
22a94d44 JB |
3909 | int verify_dir_item(struct btrfs_root *root, |
3910 | struct extent_buffer *leaf, | |
3911 | struct btrfs_dir_item *dir_item); | |
5f5bc6b1 FM |
3912 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, |
3913 | struct btrfs_path *path, | |
3914 | const char *name, | |
3915 | int name_len); | |
7b128766 JB |
3916 | |
3917 | /* orphan.c */ | |
3918 | int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, | |
3919 | struct btrfs_root *root, u64 offset); | |
3920 | int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, | |
3921 | struct btrfs_root *root, u64 offset); | |
4df27c4d | 3922 | int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset); |
7b128766 | 3923 | |
dee26a9f | 3924 | /* inode-item.c */ |
3954401f CM |
3925 | int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, |
3926 | struct btrfs_root *root, | |
3927 | const char *name, int name_len, | |
aec7477b | 3928 | u64 inode_objectid, u64 ref_objectid, u64 index); |
3954401f CM |
3929 | int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, |
3930 | struct btrfs_root *root, | |
3931 | const char *name, int name_len, | |
aec7477b | 3932 | u64 inode_objectid, u64 ref_objectid, u64 *index); |
5f39d397 CM |
3933 | int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, |
3934 | struct btrfs_root *root, | |
3935 | struct btrfs_path *path, u64 objectid); | |
293ffd5f | 3936 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
3937 | *root, struct btrfs_path *path, |
3938 | struct btrfs_key *location, int mod); | |
dee26a9f | 3939 | |
f186373f MF |
3940 | struct btrfs_inode_extref * |
3941 | btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans, | |
3942 | struct btrfs_root *root, | |
3943 | struct btrfs_path *path, | |
3944 | const char *name, int name_len, | |
3945 | u64 inode_objectid, u64 ref_objectid, int ins_len, | |
3946 | int cow); | |
3947 | ||
3948 | int btrfs_find_name_in_ext_backref(struct btrfs_path *path, | |
3949 | u64 ref_objectid, const char *name, | |
3950 | int name_len, | |
3951 | struct btrfs_inode_extref **extref_ret); | |
3952 | ||
dee26a9f | 3953 | /* file-item.c */ |
facc8a22 | 3954 | struct btrfs_dio_private; |
459931ec CM |
3955 | int btrfs_del_csums(struct btrfs_trans_handle *trans, |
3956 | struct btrfs_root *root, u64 bytenr, u64 len); | |
61b49440 | 3957 | int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode, |
d20f7043 | 3958 | struct bio *bio, u32 *dst); |
4b46fce2 | 3959 | int btrfs_lookup_bio_sums_dio(struct btrfs_root *root, struct inode *inode, |
23ea8e5a | 3960 | struct bio *bio, u64 logical_offset); |
b18c6685 | 3961 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
c8b97818 CM |
3962 | struct btrfs_root *root, |
3963 | u64 objectid, u64 pos, | |
3964 | u64 disk_offset, u64 disk_num_bytes, | |
3965 | u64 num_bytes, u64 offset, u64 ram_bytes, | |
3966 | u8 compression, u8 encryption, u16 other_encoding); | |
dee26a9f CM |
3967 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
3968 | struct btrfs_root *root, | |
3969 | struct btrfs_path *path, u64 objectid, | |
db94535d | 3970 | u64 bytenr, int mod); |
065631f6 | 3971 | int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, |
d20f7043 | 3972 | struct btrfs_root *root, |
e6dcd2dc | 3973 | struct btrfs_ordered_sum *sums); |
3edf7d33 | 3974 | int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, |
d20f7043 | 3975 | struct bio *bio, u64 file_start, int contig); |
a2de733c AJ |
3976 | int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, |
3977 | struct list_head *list, int search_commit); | |
7ffbb598 FM |
3978 | void btrfs_extent_item_to_extent_map(struct inode *inode, |
3979 | const struct btrfs_path *path, | |
3980 | struct btrfs_file_extent_item *fi, | |
3981 | const bool new_inline, | |
3982 | struct extent_map *em); | |
3983 | ||
39279cc3 | 3984 | /* inode.c */ |
8ccf6f19 MX |
3985 | struct btrfs_delalloc_work { |
3986 | struct inode *inode; | |
8ccf6f19 MX |
3987 | int delay_iput; |
3988 | struct completion completion; | |
3989 | struct list_head list; | |
3990 | struct btrfs_work work; | |
3991 | }; | |
3992 | ||
3993 | struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, | |
651d494a | 3994 | int delay_iput); |
8ccf6f19 MX |
3995 | void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work); |
3996 | ||
b2675157 JB |
3997 | struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *page, |
3998 | size_t pg_offset, u64 start, u64 len, | |
3999 | int create); | |
00361589 | 4000 | noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, |
7ee9e440 JB |
4001 | u64 *orig_start, u64 *orig_block_len, |
4002 | u64 *ram_bytes); | |
4881ee5a CM |
4003 | |
4004 | /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */ | |
5036f538 | 4005 | #if defined(ClearPageFsMisc) && !defined(ClearPageChecked) |
4881ee5a CM |
4006 | #define ClearPageChecked ClearPageFsMisc |
4007 | #define SetPageChecked SetPageFsMisc | |
4008 | #define PageChecked PageFsMisc | |
4009 | #endif | |
4010 | ||
b6973aa6 LZ |
4011 | /* This forces readahead on a given range of bytes in an inode */ |
4012 | static inline void btrfs_force_ra(struct address_space *mapping, | |
4013 | struct file_ra_state *ra, struct file *file, | |
4014 | pgoff_t offset, unsigned long req_size) | |
4015 | { | |
4016 | page_cache_sync_readahead(mapping, ra, file, offset, req_size); | |
4017 | } | |
4018 | ||
3de4586c CM |
4019 | struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); |
4020 | int btrfs_set_inode_index(struct inode *dir, u64 *index); | |
e02119d5 CM |
4021 | int btrfs_unlink_inode(struct btrfs_trans_handle *trans, |
4022 | struct btrfs_root *root, | |
4023 | struct inode *dir, struct inode *inode, | |
4024 | const char *name, int name_len); | |
4025 | int btrfs_add_link(struct btrfs_trans_handle *trans, | |
4026 | struct inode *parent_inode, struct inode *inode, | |
4027 | const char *name, int name_len, int add_backref, u64 index); | |
4df27c4d YZ |
4028 | int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, |
4029 | struct btrfs_root *root, | |
4030 | struct inode *dir, u64 objectid, | |
4031 | const char *name, int name_len); | |
2aaa6655 JB |
4032 | int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, |
4033 | int front); | |
e02119d5 CM |
4034 | int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, |
4035 | struct btrfs_root *root, | |
4036 | struct inode *inode, u64 new_size, | |
4037 | u32 min_type); | |
4038 | ||
24bbcf04 | 4039 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); |
6c255e67 MX |
4040 | int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput, |
4041 | int nr); | |
2ac55d41 JB |
4042 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, |
4043 | struct extent_state **cached_state); | |
d2fb3437 | 4044 | int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, |
63541927 FDBM |
4045 | struct btrfs_root *new_root, |
4046 | struct btrfs_root *parent_root, | |
4047 | u64 new_dirid); | |
64a16701 DW |
4048 | int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset, |
4049 | size_t size, struct bio *bio, | |
4050 | unsigned long bio_flags); | |
c2ec175c | 4051 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); |
9ebefb18 | 4052 | int btrfs_readpage(struct file *file, struct page *page); |
bd555975 | 4053 | void btrfs_evict_inode(struct inode *inode); |
a9185b41 | 4054 | int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); |
39279cc3 CM |
4055 | struct inode *btrfs_alloc_inode(struct super_block *sb); |
4056 | void btrfs_destroy_inode(struct inode *inode); | |
45321ac5 | 4057 | int btrfs_drop_inode(struct inode *inode); |
39279cc3 CM |
4058 | int btrfs_init_cachep(void); |
4059 | void btrfs_destroy_cachep(void); | |
6bf13c0c | 4060 | long btrfs_ioctl_trans_end(struct file *file); |
1a54ef8c | 4061 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, |
73f73415 | 4062 | struct btrfs_root *root, int *was_new); |
a52d9a80 | 4063 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, |
306e16ce | 4064 | size_t pg_offset, u64 start, u64 end, |
a52d9a80 CM |
4065 | int create); |
4066 | int btrfs_update_inode(struct btrfs_trans_handle *trans, | |
4067 | struct btrfs_root *root, | |
4068 | struct inode *inode); | |
be6aef60 JB |
4069 | int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, |
4070 | struct btrfs_root *root, struct inode *inode); | |
5b21f2ed | 4071 | int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode); |
66b4ffd1 | 4072 | int btrfs_orphan_cleanup(struct btrfs_root *root); |
d68fc57b YZ |
4073 | void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, |
4074 | struct btrfs_root *root); | |
a41ad394 | 4075 | int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size); |
143bede5 | 4076 | void btrfs_invalidate_inodes(struct btrfs_root *root); |
24bbcf04 YZ |
4077 | void btrfs_add_delayed_iput(struct inode *inode); |
4078 | void btrfs_run_delayed_iputs(struct btrfs_root *root); | |
efa56464 YZ |
4079 | int btrfs_prealloc_file_range(struct inode *inode, int mode, |
4080 | u64 start, u64 num_bytes, u64 min_size, | |
4081 | loff_t actual_len, u64 *alloc_hint); | |
0af3d00b JB |
4082 | int btrfs_prealloc_file_range_trans(struct inode *inode, |
4083 | struct btrfs_trans_handle *trans, int mode, | |
4084 | u64 start, u64 num_bytes, u64 min_size, | |
4085 | loff_t actual_len, u64 *alloc_hint); | |
b38ef71c | 4086 | int btrfs_inode_check_errors(struct inode *inode); |
82d339d9 | 4087 | extern const struct dentry_operations btrfs_dentry_operations; |
6a3891c5 JB |
4088 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
4089 | void btrfs_test_inode_set_ops(struct inode *inode); | |
4090 | #endif | |
f46b5a66 CH |
4091 | |
4092 | /* ioctl.c */ | |
4093 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
6cbff00f CH |
4094 | void btrfs_update_iflags(struct inode *inode); |
4095 | void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); | |
dd5f9615 | 4096 | int btrfs_is_empty_uuid(u8 *uuid); |
4cb5300b CM |
4097 | int btrfs_defrag_file(struct inode *inode, struct file *file, |
4098 | struct btrfs_ioctl_defrag_range_args *range, | |
4099 | u64 newer_than, unsigned long max_pages); | |
5af3e8cc SB |
4100 | void btrfs_get_block_group_info(struct list_head *groups_list, |
4101 | struct btrfs_ioctl_space_info *space); | |
35a3621b SB |
4102 | void update_ioctl_balance_args(struct btrfs_fs_info *fs_info, int lock, |
4103 | struct btrfs_ioctl_balance_args *bargs); | |
2b3909f8 DW |
4104 | ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, |
4105 | struct file *dst_file, u64 dst_loff); | |
35a3621b | 4106 | |
39279cc3 | 4107 | /* file.c */ |
9247f317 MX |
4108 | int btrfs_auto_defrag_init(void); |
4109 | void btrfs_auto_defrag_exit(void); | |
4cb5300b CM |
4110 | int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, |
4111 | struct inode *inode); | |
4112 | int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); | |
26176e7c | 4113 | void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info); |
02c24a82 | 4114 | int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); |
7014cdb4 JB |
4115 | void btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, |
4116 | int skip_pinned); | |
828c0950 | 4117 | extern const struct file_operations btrfs_file_operations; |
5dc562c5 JB |
4118 | int __btrfs_drop_extents(struct btrfs_trans_handle *trans, |
4119 | struct btrfs_root *root, struct inode *inode, | |
4120 | struct btrfs_path *path, u64 start, u64 end, | |
1acae57b FDBM |
4121 | u64 *drop_end, int drop_cache, |
4122 | int replace_extent, | |
4123 | u32 extent_item_size, | |
4124 | int *key_inserted); | |
5dc562c5 JB |
4125 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
4126 | struct btrfs_root *root, struct inode *inode, u64 start, | |
2671485d | 4127 | u64 end, int drop_cache); |
d899e052 | 4128 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
d899e052 | 4129 | struct inode *inode, u64 start, u64 end); |
6bf13c0c | 4130 | int btrfs_release_file(struct inode *inode, struct file *file); |
be1a12a0 JB |
4131 | int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, |
4132 | struct page **pages, size_t num_pages, | |
4133 | loff_t pos, size_t write_bytes, | |
4134 | struct extent_state **cached); | |
728404da | 4135 | int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); |
3db11b2e ZB |
4136 | ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in, |
4137 | struct file *file_out, loff_t pos_out, | |
4138 | size_t len, unsigned int flags); | |
04b38d60 CH |
4139 | int btrfs_clone_file_range(struct file *file_in, loff_t pos_in, |
4140 | struct file *file_out, loff_t pos_out, u64 len); | |
6bf13c0c | 4141 | |
6702ed49 CM |
4142 | /* tree-defrag.c */ |
4143 | int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |
de78b51a | 4144 | struct btrfs_root *root); |
58176a96 JB |
4145 | |
4146 | /* sysfs.c */ | |
4147 | int btrfs_init_sysfs(void); | |
4148 | void btrfs_exit_sysfs(void); | |
96f3136e | 4149 | int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info); |
6618a59b | 4150 | void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info); |
58176a96 | 4151 | |
5103e947 JB |
4152 | /* xattr.c */ |
4153 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | |
6099afe8 | 4154 | |
edbd8d4e | 4155 | /* super.c */ |
edf24abe | 4156 | int btrfs_parse_options(struct btrfs_root *root, char *options); |
6bf13c0c | 4157 | int btrfs_sync_fs(struct super_block *sb, int wait); |
533574c6 JP |
4158 | |
4159 | #ifdef CONFIG_PRINTK | |
4160 | __printf(2, 3) | |
c2cf52eb | 4161 | void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...); |
533574c6 JP |
4162 | #else |
4163 | static inline __printf(2, 3) | |
c2cf52eb | 4164 | void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) |
533574c6 JP |
4165 | { |
4166 | } | |
4167 | #endif | |
4168 | ||
c2cf52eb SK |
4169 | #define btrfs_emerg(fs_info, fmt, args...) \ |
4170 | btrfs_printk(fs_info, KERN_EMERG fmt, ##args) | |
4171 | #define btrfs_alert(fs_info, fmt, args...) \ | |
4172 | btrfs_printk(fs_info, KERN_ALERT fmt, ##args) | |
4173 | #define btrfs_crit(fs_info, fmt, args...) \ | |
4174 | btrfs_printk(fs_info, KERN_CRIT fmt, ##args) | |
4175 | #define btrfs_err(fs_info, fmt, args...) \ | |
4176 | btrfs_printk(fs_info, KERN_ERR fmt, ##args) | |
4177 | #define btrfs_warn(fs_info, fmt, args...) \ | |
4178 | btrfs_printk(fs_info, KERN_WARNING fmt, ##args) | |
4179 | #define btrfs_notice(fs_info, fmt, args...) \ | |
4180 | btrfs_printk(fs_info, KERN_NOTICE fmt, ##args) | |
4181 | #define btrfs_info(fs_info, fmt, args...) \ | |
4182 | btrfs_printk(fs_info, KERN_INFO fmt, ##args) | |
27a0dd61 | 4183 | |
08a84e25 DS |
4184 | /* |
4185 | * Wrappers that use printk_in_rcu | |
4186 | */ | |
4187 | #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \ | |
4188 | btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args) | |
4189 | #define btrfs_alert_in_rcu(fs_info, fmt, args...) \ | |
4190 | btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args) | |
4191 | #define btrfs_crit_in_rcu(fs_info, fmt, args...) \ | |
4192 | btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args) | |
4193 | #define btrfs_err_in_rcu(fs_info, fmt, args...) \ | |
4194 | btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args) | |
4195 | #define btrfs_warn_in_rcu(fs_info, fmt, args...) \ | |
4196 | btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args) | |
4197 | #define btrfs_notice_in_rcu(fs_info, fmt, args...) \ | |
4198 | btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args) | |
4199 | #define btrfs_info_in_rcu(fs_info, fmt, args...) \ | |
4200 | btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args) | |
4201 | ||
24aa6b41 DS |
4202 | /* |
4203 | * Wrappers that use a ratelimited printk_in_rcu | |
4204 | */ | |
4205 | #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \ | |
4206 | btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args) | |
4207 | #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \ | |
4208 | btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args) | |
4209 | #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \ | |
4210 | btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args) | |
4211 | #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \ | |
4212 | btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args) | |
4213 | #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \ | |
4214 | btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args) | |
4215 | #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \ | |
4216 | btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args) | |
4217 | #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \ | |
4218 | btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args) | |
4219 | ||
1dd6d7ca DS |
4220 | /* |
4221 | * Wrappers that use a ratelimited printk | |
4222 | */ | |
4223 | #define btrfs_emerg_rl(fs_info, fmt, args...) \ | |
4224 | btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args) | |
4225 | #define btrfs_alert_rl(fs_info, fmt, args...) \ | |
4226 | btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args) | |
4227 | #define btrfs_crit_rl(fs_info, fmt, args...) \ | |
4228 | btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args) | |
4229 | #define btrfs_err_rl(fs_info, fmt, args...) \ | |
4230 | btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args) | |
4231 | #define btrfs_warn_rl(fs_info, fmt, args...) \ | |
4232 | btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args) | |
4233 | #define btrfs_notice_rl(fs_info, fmt, args...) \ | |
4234 | btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args) | |
4235 | #define btrfs_info_rl(fs_info, fmt, args...) \ | |
4236 | btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args) | |
27a0dd61 | 4237 | #ifdef DEBUG |
c2cf52eb SK |
4238 | #define btrfs_debug(fs_info, fmt, args...) \ |
4239 | btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) | |
08a84e25 DS |
4240 | #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ |
4241 | btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) | |
24aa6b41 DS |
4242 | #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ |
4243 | btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args) | |
1dd6d7ca DS |
4244 | #define btrfs_debug_rl(fs_info, fmt, args...) \ |
4245 | btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args) | |
27a0dd61 FH |
4246 | #else |
4247 | #define btrfs_debug(fs_info, fmt, args...) \ | |
4248 | no_printk(KERN_DEBUG fmt, ##args) | |
08a84e25 DS |
4249 | #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ |
4250 | no_printk(KERN_DEBUG fmt, ##args) | |
24aa6b41 DS |
4251 | #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ |
4252 | no_printk(KERN_DEBUG fmt, ##args) | |
1dd6d7ca DS |
4253 | #define btrfs_debug_rl(fs_info, fmt, args...) \ |
4254 | no_printk(KERN_DEBUG fmt, ##args) | |
27a0dd61 | 4255 | #endif |
c2cf52eb | 4256 | |
08a84e25 DS |
4257 | #define btrfs_printk_in_rcu(fs_info, fmt, args...) \ |
4258 | do { \ | |
4259 | rcu_read_lock(); \ | |
4260 | btrfs_printk(fs_info, fmt, ##args); \ | |
4261 | rcu_read_unlock(); \ | |
4262 | } while (0) | |
4263 | ||
24aa6b41 DS |
4264 | #define btrfs_printk_ratelimited(fs_info, fmt, args...) \ |
4265 | do { \ | |
4266 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
4267 | DEFAULT_RATELIMIT_INTERVAL, \ | |
4268 | DEFAULT_RATELIMIT_BURST); \ | |
4269 | if (__ratelimit(&_rs)) \ | |
4270 | btrfs_printk(fs_info, fmt, ##args); \ | |
4271 | } while (0) | |
4272 | ||
4273 | #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \ | |
4274 | do { \ | |
4275 | rcu_read_lock(); \ | |
4276 | btrfs_printk_ratelimited(fs_info, fmt, ##args); \ | |
4277 | rcu_read_unlock(); \ | |
4278 | } while (0) | |
4279 | ||
2e17c7c6 JB |
4280 | #ifdef CONFIG_BTRFS_ASSERT |
4281 | ||
c0d19e2b | 4282 | __cold |
2e17c7c6 JB |
4283 | static inline void assfail(char *expr, char *file, int line) |
4284 | { | |
efe120a0 | 4285 | pr_err("BTRFS: assertion failed: %s, file: %s, line: %d", |
2e17c7c6 JB |
4286 | expr, file, line); |
4287 | BUG(); | |
4288 | } | |
4289 | ||
4290 | #define ASSERT(expr) \ | |
4291 | (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) | |
4292 | #else | |
4293 | #define ASSERT(expr) ((void)0) | |
4294 | #endif | |
4295 | ||
4296 | #define btrfs_assert() | |
533574c6 | 4297 | __printf(5, 6) |
c0d19e2b | 4298 | __cold |
acce952b | 4299 | void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function, |
4da35113 | 4300 | unsigned int line, int errno, const char *fmt, ...); |
acce952b | 4301 | |
e33e17ee | 4302 | const char *btrfs_decode_error(int errno); |
533574c6 | 4303 | |
c0d19e2b | 4304 | __cold |
49b25e05 JM |
4305 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, |
4306 | struct btrfs_root *root, const char *function, | |
4307 | unsigned int line, int errno); | |
4308 | ||
2b0ce2c2 MH |
4309 | #define btrfs_set_fs_incompat(__fs_info, opt) \ |
4310 | __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) | |
4311 | ||
4312 | static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, | |
4313 | u64 flag) | |
4314 | { | |
4315 | struct btrfs_super_block *disk_super; | |
4316 | u64 features; | |
4317 | ||
4318 | disk_super = fs_info->super_copy; | |
4319 | features = btrfs_super_incompat_flags(disk_super); | |
4320 | if (!(features & flag)) { | |
ceda0864 MX |
4321 | spin_lock(&fs_info->super_lock); |
4322 | features = btrfs_super_incompat_flags(disk_super); | |
4323 | if (!(features & flag)) { | |
4324 | features |= flag; | |
4325 | btrfs_set_super_incompat_flags(disk_super, features); | |
efe120a0 | 4326 | btrfs_info(fs_info, "setting %llu feature flag", |
ceda0864 MX |
4327 | flag); |
4328 | } | |
4329 | spin_unlock(&fs_info->super_lock); | |
2b0ce2c2 MH |
4330 | } |
4331 | } | |
4332 | ||
1abfbcdf OS |
4333 | #define btrfs_clear_fs_incompat(__fs_info, opt) \ |
4334 | __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) | |
4335 | ||
4336 | static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, | |
4337 | u64 flag) | |
4338 | { | |
4339 | struct btrfs_super_block *disk_super; | |
4340 | u64 features; | |
4341 | ||
4342 | disk_super = fs_info->super_copy; | |
4343 | features = btrfs_super_incompat_flags(disk_super); | |
4344 | if (features & flag) { | |
4345 | spin_lock(&fs_info->super_lock); | |
4346 | features = btrfs_super_incompat_flags(disk_super); | |
4347 | if (features & flag) { | |
4348 | features &= ~flag; | |
4349 | btrfs_set_super_incompat_flags(disk_super, features); | |
4350 | btrfs_info(fs_info, "clearing %llu feature flag", | |
4351 | flag); | |
4352 | } | |
4353 | spin_unlock(&fs_info->super_lock); | |
4354 | } | |
4355 | } | |
4356 | ||
3173a18f JB |
4357 | #define btrfs_fs_incompat(fs_info, opt) \ |
4358 | __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) | |
4359 | ||
9780c497 | 4360 | static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag) |
3173a18f JB |
4361 | { |
4362 | struct btrfs_super_block *disk_super; | |
4363 | disk_super = fs_info->super_copy; | |
4364 | return !!(btrfs_super_incompat_flags(disk_super) & flag); | |
4365 | } | |
4366 | ||
1abfbcdf OS |
4367 | #define btrfs_set_fs_compat_ro(__fs_info, opt) \ |
4368 | __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) | |
4369 | ||
4370 | static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, | |
4371 | u64 flag) | |
4372 | { | |
4373 | struct btrfs_super_block *disk_super; | |
4374 | u64 features; | |
4375 | ||
4376 | disk_super = fs_info->super_copy; | |
4377 | features = btrfs_super_compat_ro_flags(disk_super); | |
4378 | if (!(features & flag)) { | |
4379 | spin_lock(&fs_info->super_lock); | |
4380 | features = btrfs_super_compat_ro_flags(disk_super); | |
4381 | if (!(features & flag)) { | |
4382 | features |= flag; | |
4383 | btrfs_set_super_compat_ro_flags(disk_super, features); | |
4384 | btrfs_info(fs_info, "setting %llu ro feature flag", | |
4385 | flag); | |
4386 | } | |
4387 | spin_unlock(&fs_info->super_lock); | |
4388 | } | |
4389 | } | |
4390 | ||
4391 | #define btrfs_clear_fs_compat_ro(__fs_info, opt) \ | |
4392 | __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) | |
4393 | ||
4394 | static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, | |
4395 | u64 flag) | |
4396 | { | |
4397 | struct btrfs_super_block *disk_super; | |
4398 | u64 features; | |
4399 | ||
4400 | disk_super = fs_info->super_copy; | |
4401 | features = btrfs_super_compat_ro_flags(disk_super); | |
4402 | if (features & flag) { | |
4403 | spin_lock(&fs_info->super_lock); | |
4404 | features = btrfs_super_compat_ro_flags(disk_super); | |
4405 | if (features & flag) { | |
4406 | features &= ~flag; | |
4407 | btrfs_set_super_compat_ro_flags(disk_super, features); | |
4408 | btrfs_info(fs_info, "clearing %llu ro feature flag", | |
4409 | flag); | |
4410 | } | |
4411 | spin_unlock(&fs_info->super_lock); | |
4412 | } | |
4413 | } | |
4414 | ||
4415 | #define btrfs_fs_compat_ro(fs_info, opt) \ | |
4416 | __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) | |
4417 | ||
4418 | static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag) | |
4419 | { | |
4420 | struct btrfs_super_block *disk_super; | |
4421 | disk_super = fs_info->super_copy; | |
4422 | return !!(btrfs_super_compat_ro_flags(disk_super) & flag); | |
4423 | } | |
4424 | ||
005d6427 DS |
4425 | /* |
4426 | * Call btrfs_abort_transaction as early as possible when an error condition is | |
4427 | * detected, that way the exact line number is reported. | |
4428 | */ | |
49b25e05 JM |
4429 | #define btrfs_abort_transaction(trans, root, errno) \ |
4430 | do { \ | |
1a9a8a71 DS |
4431 | /* Report first abort since mount */ \ |
4432 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ | |
4433 | &((root)->fs_info->fs_state))) { \ | |
4434 | WARN(1, KERN_DEBUG \ | |
4435 | "BTRFS: Transaction aborted (error %d)\n", \ | |
4436 | (errno)); \ | |
4437 | } \ | |
4438 | __btrfs_abort_transaction((trans), (root), __func__, \ | |
4439 | __LINE__, (errno)); \ | |
49b25e05 | 4440 | } while (0) |
acce952b | 4441 | |
a4553fef | 4442 | #define btrfs_std_error(fs_info, errno, fmt, args...) \ |
4da35113 JM |
4443 | do { \ |
4444 | __btrfs_std_error((fs_info), __func__, __LINE__, \ | |
4445 | (errno), fmt, ##args); \ | |
acce952b | 4446 | } while (0) |
33268eaf | 4447 | |
533574c6 | 4448 | __printf(5, 6) |
c0d19e2b | 4449 | __cold |
8c342930 JM |
4450 | void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, |
4451 | unsigned int line, int errno, const char *fmt, ...); | |
4452 | ||
aa43a17c ES |
4453 | /* |
4454 | * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic | |
4455 | * will panic(). Otherwise we BUG() here. | |
4456 | */ | |
8c342930 JM |
4457 | #define btrfs_panic(fs_info, errno, fmt, args...) \ |
4458 | do { \ | |
aa43a17c ES |
4459 | __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ |
4460 | BUG(); \ | |
acce952b | 4461 | } while (0) |
33268eaf JB |
4462 | |
4463 | /* acl.c */ | |
0eda294d | 4464 | #ifdef CONFIG_BTRFS_FS_POSIX_ACL |
4e34e719 | 4465 | struct posix_acl *btrfs_get_acl(struct inode *inode, int type); |
996a710d | 4466 | int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type); |
f34f57a3 YZ |
4467 | int btrfs_init_acl(struct btrfs_trans_handle *trans, |
4468 | struct inode *inode, struct inode *dir); | |
9b89d95a | 4469 | #else |
ed8f3737 | 4470 | #define btrfs_get_acl NULL |
996a710d | 4471 | #define btrfs_set_acl NULL |
9b89d95a LZ |
4472 | static inline int btrfs_init_acl(struct btrfs_trans_handle *trans, |
4473 | struct inode *inode, struct inode *dir) | |
4474 | { | |
4475 | return 0; | |
4476 | } | |
9b89d95a | 4477 | #endif |
0f9dd46c | 4478 | |
5d4f98a2 YZ |
4479 | /* relocation.c */ |
4480 | int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start); | |
4481 | int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, | |
4482 | struct btrfs_root *root); | |
4483 | int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, | |
4484 | struct btrfs_root *root); | |
4485 | int btrfs_recover_relocation(struct btrfs_root *root); | |
4486 | int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len); | |
83d4cfd4 JB |
4487 | int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, |
4488 | struct btrfs_root *root, struct extent_buffer *buf, | |
4489 | struct extent_buffer *cow); | |
147d256e | 4490 | void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending, |
3fd0a558 | 4491 | u64 *bytes_to_reserve); |
49b25e05 | 4492 | int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, |
3fd0a558 | 4493 | struct btrfs_pending_snapshot *pending); |
a2de733c AJ |
4494 | |
4495 | /* scrub.c */ | |
aa1b8cd4 SB |
4496 | int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, |
4497 | u64 end, struct btrfs_scrub_progress *progress, | |
63a212ab | 4498 | int readonly, int is_dev_replace); |
143bede5 | 4499 | void btrfs_scrub_pause(struct btrfs_root *root); |
143bede5 | 4500 | void btrfs_scrub_continue(struct btrfs_root *root); |
aa1b8cd4 SB |
4501 | int btrfs_scrub_cancel(struct btrfs_fs_info *info); |
4502 | int btrfs_scrub_cancel_dev(struct btrfs_fs_info *info, | |
4503 | struct btrfs_device *dev); | |
a2de733c AJ |
4504 | int btrfs_scrub_progress(struct btrfs_root *root, u64 devid, |
4505 | struct btrfs_scrub_progress *progress); | |
c404e0dc MX |
4506 | |
4507 | /* dev-replace.c */ | |
4508 | void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info); | |
4509 | void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info); | |
4245215d MX |
4510 | void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount); |
4511 | ||
4512 | static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info) | |
4513 | { | |
4514 | btrfs_bio_counter_sub(fs_info, 1); | |
4515 | } | |
a2de733c | 4516 | |
7414a03f AJ |
4517 | /* reada.c */ |
4518 | struct reada_control { | |
4519 | struct btrfs_root *root; /* tree to prefetch */ | |
4520 | struct btrfs_key key_start; | |
4521 | struct btrfs_key key_end; /* exclusive */ | |
4522 | atomic_t elems; | |
4523 | struct kref refcnt; | |
4524 | wait_queue_head_t wait; | |
4525 | }; | |
4526 | struct reada_control *btrfs_reada_add(struct btrfs_root *root, | |
4527 | struct btrfs_key *start, struct btrfs_key *end); | |
4528 | int btrfs_reada_wait(void *handle); | |
4529 | void btrfs_reada_detach(void *handle); | |
4530 | int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, | |
4531 | u64 start, int err); | |
4532 | ||
95a06077 JS |
4533 | static inline int is_fstree(u64 rootid) |
4534 | { | |
4535 | if (rootid == BTRFS_FS_TREE_OBJECTID || | |
e09fe2d2 QW |
4536 | ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID && |
4537 | !btrfs_qgroup_level(rootid))) | |
95a06077 JS |
4538 | return 1; |
4539 | return 0; | |
4540 | } | |
210549eb DS |
4541 | |
4542 | static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) | |
4543 | { | |
4544 | return signal_pending(current); | |
4545 | } | |
4546 | ||
aaedb55b JB |
4547 | /* Sanity test specific functions */ |
4548 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | |
4549 | void btrfs_test_destroy_inode(struct inode *inode); | |
4550 | #endif | |
210549eb | 4551 | |
fccb84c9 DS |
4552 | static inline int btrfs_test_is_dummy_root(struct btrfs_root *root) |
4553 | { | |
4554 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS | |
4555 | if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state))) | |
4556 | return 1; | |
4557 | #endif | |
4558 | return 0; | |
4559 | } | |
4560 | ||
eb60ceac | 4561 | #endif |