1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Copyright (C) 2007 Oracle. All rights rese 3 * Copyright (C) 2007 Oracle. All rights reserved. 4 */ 4 */ 5 5 6 #ifndef BTRFS_CTREE_H 6 #ifndef BTRFS_CTREE_H 7 #define BTRFS_CTREE_H 7 #define BTRFS_CTREE_H 8 8 9 #include "linux/cleanup.h" !! 9 #include <linux/mm.h> 10 #include <linux/pagemap.h> !! 10 #include <linux/sched/signal.h> 11 #include <linux/spinlock.h> !! 11 #include <linux/highmem.h> 12 #include <linux/rbtree.h> !! 12 #include <linux/fs.h> 13 #include <linux/mutex.h> !! 13 #include <linux/rwsem.h> >> 14 #include <linux/semaphore.h> >> 15 #include <linux/completion.h> >> 16 #include <linux/backing-dev.h> 14 #include <linux/wait.h> 17 #include <linux/wait.h> 15 #include <linux/list.h> !! 18 #include <linux/slab.h> 16 #include <linux/atomic.h> !! 19 #include <trace/events/btrfs.h> 17 #include <linux/xarray.h> !! 20 #include <asm/unaligned.h> >> 21 #include <linux/pagemap.h> >> 22 #include <linux/btrfs.h> >> 23 #include <linux/btrfs_tree.h> >> 24 #include <linux/workqueue.h> >> 25 #include <linux/security.h> >> 26 #include <linux/sizes.h> >> 27 #include <linux/dynamic_debug.h> 18 #include <linux/refcount.h> 28 #include <linux/refcount.h> 19 #include <uapi/linux/btrfs_tree.h> !! 29 #include <linux/crc32c.h> >> 30 #include <linux/iomap.h> >> 31 #include <linux/fscrypt.h> >> 32 #include "extent-io-tree.h" >> 33 #include "extent_io.h" >> 34 #include "extent_map.h" >> 35 #include "async-thread.h" >> 36 #include "block-rsv.h" 20 #include "locking.h" 37 #include "locking.h" >> 38 #include "misc.h" 21 #include "fs.h" 39 #include "fs.h" 22 #include "accessors.h" << 23 #include "extent-io-tree.h" << 24 40 25 struct extent_buffer; << 26 struct btrfs_block_rsv; << 27 struct btrfs_trans_handle; 41 struct btrfs_trans_handle; >> 42 struct btrfs_transaction; >> 43 struct btrfs_pending_snapshot; >> 44 struct btrfs_delayed_ref_root; >> 45 struct btrfs_space_info; 28 struct btrfs_block_group; 46 struct btrfs_block_group; >> 47 struct btrfs_ordered_sum; >> 48 struct btrfs_ref; >> 49 struct btrfs_bio; >> 50 struct btrfs_ioctl_encoded_io_args; >> 51 struct btrfs_device; >> 52 struct btrfs_fs_devices; >> 53 struct btrfs_balance_control; >> 54 struct btrfs_delayed_root; >> 55 struct reloc_control; 29 56 30 /* Read ahead values for struct btrfs_path.rea 57 /* Read ahead values for struct btrfs_path.reada */ 31 enum { 58 enum { 32 READA_NONE, 59 READA_NONE, 33 READA_BACK, 60 READA_BACK, 34 READA_FORWARD, 61 READA_FORWARD, 35 /* 62 /* 36 * Similar to READA_FORWARD but unlike 63 * Similar to READA_FORWARD but unlike it: 37 * 64 * 38 * 1) It will trigger readahead even f 65 * 1) It will trigger readahead even for leaves that are not close to 39 * each other on disk; 66 * each other on disk; 40 * 2) It also triggers readahead for n 67 * 2) It also triggers readahead for nodes; 41 * 3) During a search, even when a nod 68 * 3) During a search, even when a node or leaf is already in memory, it 42 * will still trigger readahead for 69 * will still trigger readahead for other nodes and leaves that follow 43 * it. 70 * it. 44 * 71 * 45 * This is meant to be used only when 72 * This is meant to be used only when we know we are iterating over the 46 * entire tree or a very large part of 73 * entire tree or a very large part of it. 47 */ 74 */ 48 READA_FORWARD_ALWAYS, 75 READA_FORWARD_ALWAYS, 49 }; 76 }; 50 77 51 /* 78 /* 52 * btrfs_paths remember the path taken from th 79 * btrfs_paths remember the path taken from the root down to the leaf. 53 * level 0 is always the leaf, and nodes[1...B 80 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point 54 * to any other levels that are present. 81 * to any other levels that are present. 55 * 82 * 56 * The slots array records the index of the it 83 * The slots array records the index of the item or block pointer 57 * used while walking the tree. 84 * used while walking the tree. 58 */ 85 */ 59 struct btrfs_path { 86 struct btrfs_path { 60 struct extent_buffer *nodes[BTRFS_MAX_ 87 struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; 61 int slots[BTRFS_MAX_LEVEL]; 88 int slots[BTRFS_MAX_LEVEL]; 62 /* if there is real range locking, thi 89 /* if there is real range locking, this locks field will change */ 63 u8 locks[BTRFS_MAX_LEVEL]; 90 u8 locks[BTRFS_MAX_LEVEL]; 64 u8 reada; 91 u8 reada; 65 /* keep some upper locks as we walk do 92 /* keep some upper locks as we walk down */ 66 u8 lowest_level; 93 u8 lowest_level; 67 94 68 /* 95 /* 69 * set by btrfs_split_item, tells sear 96 * set by btrfs_split_item, tells search_slot to keep all locks 70 * and to force calls to keep space in 97 * and to force calls to keep space in the nodes 71 */ 98 */ 72 unsigned int search_for_split:1; 99 unsigned int search_for_split:1; 73 unsigned int keep_locks:1; 100 unsigned int keep_locks:1; 74 unsigned int skip_locking:1; 101 unsigned int skip_locking:1; 75 unsigned int search_commit_root:1; 102 unsigned int search_commit_root:1; 76 unsigned int need_commit_sem:1; 103 unsigned int need_commit_sem:1; 77 unsigned int skip_release_on_error:1; 104 unsigned int skip_release_on_error:1; 78 /* 105 /* 79 * Indicate that new item (btrfs_searc 106 * Indicate that new item (btrfs_search_slot) is extending already 80 * existing item and ins_len contains 107 * existing item and ins_len contains only the data size and not item 81 * header (ie. sizeof(struct btrfs_ite 108 * header (ie. sizeof(struct btrfs_item) is not included). 82 */ 109 */ 83 unsigned int search_for_extension:1; 110 unsigned int search_for_extension:1; 84 /* Stop search if any locks need to be 111 /* Stop search if any locks need to be taken (for read) */ 85 unsigned int nowait:1; 112 unsigned int nowait:1; 86 }; 113 }; 87 114 88 #define BTRFS_PATH_AUTO_FREE(path_name) << 89 struct btrfs_path *path_name __free(bt << 90 << 91 /* 115 /* 92 * The state of btrfs root 116 * The state of btrfs root 93 */ 117 */ 94 enum { 118 enum { 95 /* 119 /* 96 * btrfs_record_root_in_trans is a mul 120 * btrfs_record_root_in_trans is a multi-step process, and it can race 97 * with the balancing code. But the 121 * with the balancing code. But the race is very small, and only the 98 * first time the root is added to eac 122 * first time the root is added to each transaction. So IN_TRANS_SETUP 99 * is used to tell us when more checks 123 * is used to tell us when more checks are required 100 */ 124 */ 101 BTRFS_ROOT_IN_TRANS_SETUP, 125 BTRFS_ROOT_IN_TRANS_SETUP, 102 126 103 /* 127 /* 104 * Set if tree blocks of this root can 128 * Set if tree blocks of this root can be shared by other roots. 105 * Only subvolume trees and their relo 129 * Only subvolume trees and their reloc trees have this bit set. 106 * Conflicts with TRACK_DIRTY bit. 130 * Conflicts with TRACK_DIRTY bit. 107 * 131 * 108 * This affects two things: 132 * This affects two things: 109 * 133 * 110 * - How balance works 134 * - How balance works 111 * For shareable roots, we need to u 135 * For shareable roots, we need to use reloc tree and do path 112 * replacement for balance, and need 136 * replacement for balance, and need various pre/post hooks for 113 * snapshot creation to handle them. 137 * snapshot creation to handle them. 114 * 138 * 115 * While for non-shareable trees, we 139 * While for non-shareable trees, we just simply do a tree search 116 * with COW. 140 * with COW. 117 * 141 * 118 * - How dirty roots are tracked 142 * - How dirty roots are tracked 119 * For shareable roots, btrfs_record 143 * For shareable roots, btrfs_record_root_in_trans() is needed to 120 * track them, while non-subvolume r 144 * track them, while non-subvolume roots have TRACK_DIRTY bit, they 121 * don't need to set this manually. 145 * don't need to set this manually. 122 */ 146 */ 123 BTRFS_ROOT_SHAREABLE, 147 BTRFS_ROOT_SHAREABLE, 124 BTRFS_ROOT_TRACK_DIRTY, 148 BTRFS_ROOT_TRACK_DIRTY, 125 BTRFS_ROOT_IN_RADIX, 149 BTRFS_ROOT_IN_RADIX, 126 BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 150 BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 127 BTRFS_ROOT_DEFRAG_RUNNING, 151 BTRFS_ROOT_DEFRAG_RUNNING, 128 BTRFS_ROOT_FORCE_COW, 152 BTRFS_ROOT_FORCE_COW, 129 BTRFS_ROOT_MULTI_LOG_TASKS, 153 BTRFS_ROOT_MULTI_LOG_TASKS, 130 BTRFS_ROOT_DIRTY, 154 BTRFS_ROOT_DIRTY, 131 BTRFS_ROOT_DELETING, 155 BTRFS_ROOT_DELETING, 132 156 133 /* 157 /* 134 * Reloc tree is orphan, only kept her 158 * Reloc tree is orphan, only kept here for qgroup delayed subtree scan 135 * 159 * 136 * Set for the subvolume tree owning t 160 * Set for the subvolume tree owning the reloc tree. 137 */ 161 */ 138 BTRFS_ROOT_DEAD_RELOC_TREE, 162 BTRFS_ROOT_DEAD_RELOC_TREE, 139 /* Mark dead root stored on device who 163 /* Mark dead root stored on device whose cleanup needs to be resumed */ 140 BTRFS_ROOT_DEAD_TREE, 164 BTRFS_ROOT_DEAD_TREE, 141 /* The root has a log tree. Used for s 165 /* The root has a log tree. Used for subvolume roots and the tree root. */ 142 BTRFS_ROOT_HAS_LOG_TREE, 166 BTRFS_ROOT_HAS_LOG_TREE, 143 /* Qgroup flushing is in progress */ 167 /* Qgroup flushing is in progress */ 144 BTRFS_ROOT_QGROUP_FLUSHING, 168 BTRFS_ROOT_QGROUP_FLUSHING, 145 /* We started the orphan cleanup for t 169 /* We started the orphan cleanup for this root. */ 146 BTRFS_ROOT_ORPHAN_CLEANUP, 170 BTRFS_ROOT_ORPHAN_CLEANUP, 147 /* This root has a drop operation that 171 /* This root has a drop operation that was started previously. */ 148 BTRFS_ROOT_UNFINISHED_DROP, 172 BTRFS_ROOT_UNFINISHED_DROP, 149 /* This reloc root needs to have its b 173 /* This reloc root needs to have its buffers lockdep class reset. */ 150 BTRFS_ROOT_RESET_LOCKDEP_CLASS, 174 BTRFS_ROOT_RESET_LOCKDEP_CLASS, 151 }; 175 }; 152 176 153 /* 177 /* 154 * Record swapped tree blocks of a subvolume t 178 * Record swapped tree blocks of a subvolume tree for delayed subtree trace 155 * code. For detail check comment in fs/btrfs/ 179 * code. For detail check comment in fs/btrfs/qgroup.c. 156 */ 180 */ 157 struct btrfs_qgroup_swapped_blocks { 181 struct btrfs_qgroup_swapped_blocks { 158 spinlock_t lock; 182 spinlock_t lock; 159 /* RM_EMPTY_ROOT() of above blocks[] * 183 /* RM_EMPTY_ROOT() of above blocks[] */ 160 bool swapped; 184 bool swapped; 161 struct rb_root blocks[BTRFS_MAX_LEVEL] 185 struct rb_root blocks[BTRFS_MAX_LEVEL]; 162 }; 186 }; 163 187 164 /* 188 /* 165 * in ram representation of the tree. extent_ 189 * in ram representation of the tree. extent_root is used for all allocations 166 * and for the extent tree extent_root root. 190 * and for the extent tree extent_root root. 167 */ 191 */ 168 struct btrfs_root { 192 struct btrfs_root { 169 struct rb_node rb_node; 193 struct rb_node rb_node; 170 194 171 struct extent_buffer *node; 195 struct extent_buffer *node; 172 196 173 struct extent_buffer *commit_root; 197 struct extent_buffer *commit_root; 174 struct btrfs_root *log_root; 198 struct btrfs_root *log_root; 175 struct btrfs_root *reloc_root; 199 struct btrfs_root *reloc_root; 176 200 177 unsigned long state; 201 unsigned long state; 178 struct btrfs_root_item root_item; 202 struct btrfs_root_item root_item; 179 struct btrfs_key root_key; 203 struct btrfs_key root_key; 180 struct btrfs_fs_info *fs_info; 204 struct btrfs_fs_info *fs_info; 181 struct extent_io_tree dirty_log_pages; 205 struct extent_io_tree dirty_log_pages; 182 206 183 struct mutex objectid_mutex; 207 struct mutex objectid_mutex; 184 208 185 spinlock_t accounting_lock; 209 spinlock_t accounting_lock; 186 struct btrfs_block_rsv *block_rsv; 210 struct btrfs_block_rsv *block_rsv; 187 211 188 struct mutex log_mutex; 212 struct mutex log_mutex; 189 wait_queue_head_t log_writer_wait; 213 wait_queue_head_t log_writer_wait; 190 wait_queue_head_t log_commit_wait[2]; 214 wait_queue_head_t log_commit_wait[2]; 191 struct list_head log_ctxs[2]; 215 struct list_head log_ctxs[2]; 192 /* Used only for log trees of subvolum 216 /* Used only for log trees of subvolumes, not for the log root tree */ 193 atomic_t log_writers; 217 atomic_t log_writers; 194 atomic_t log_commit[2]; 218 atomic_t log_commit[2]; 195 /* Used only for log trees of subvolum 219 /* Used only for log trees of subvolumes, not for the log root tree */ 196 atomic_t log_batch; 220 atomic_t log_batch; 197 /* << 198 * Protected by the 'log_mutex' lock b << 199 * that lock to avoid unnecessary lock << 200 * should be read using btrfs_get_root << 201 * log tree in which case it can be di << 202 * field should always use btrfs_set_r << 203 * trees where the field can be update << 204 */ << 205 int log_transid; 221 int log_transid; 206 /* No matter the commit succeeds or no 222 /* No matter the commit succeeds or not*/ 207 int log_transid_committed; 223 int log_transid_committed; 208 /* !! 224 /* Just be updated when the commit succeeds. */ 209 * Just be updated when the commit suc << 210 * btrfs_get_root_last_log_commit() an << 211 * to access this field. << 212 */ << 213 int last_log_commit; 225 int last_log_commit; 214 pid_t log_start_pid; 226 pid_t log_start_pid; 215 227 216 u64 last_trans; 228 u64 last_trans; 217 229 >> 230 u32 type; >> 231 218 u64 free_objectid; 232 u64 free_objectid; 219 233 220 struct btrfs_key defrag_progress; 234 struct btrfs_key defrag_progress; 221 struct btrfs_key defrag_max; 235 struct btrfs_key defrag_max; 222 236 223 /* The dirty list is only used by non- 237 /* The dirty list is only used by non-shareable roots */ 224 struct list_head dirty_list; 238 struct list_head dirty_list; 225 239 226 struct list_head root_list; 240 struct list_head root_list; 227 241 228 /* !! 242 spinlock_t log_extents_lock[2]; 229 * Xarray that keeps track of in-memor !! 243 struct list_head logged_list[2]; 230 * @inode_lock. !! 244 231 */ !! 245 spinlock_t inode_lock; 232 struct xarray inodes; !! 246 /* red-black tree that keeps track of in-memory inodes */ >> 247 struct rb_root inode_tree; 233 248 234 /* 249 /* 235 * Xarray that keeps track of delayed !! 250 * radix tree that keeps track of delayed nodes of every inode, 236 * by @inode_lock. !! 251 * protected by inode_lock 237 */ 252 */ 238 struct xarray delayed_nodes; !! 253 struct radix_tree_root delayed_nodes_tree; 239 /* 254 /* 240 * right now this just gets used so th 255 * right now this just gets used so that a root has its own devid 241 * for stat. It may be used for more 256 * for stat. It may be used for more later 242 */ 257 */ 243 dev_t anon_dev; 258 dev_t anon_dev; 244 259 245 spinlock_t root_item_lock; 260 spinlock_t root_item_lock; 246 refcount_t refs; 261 refcount_t refs; 247 262 248 struct mutex delalloc_mutex; 263 struct mutex delalloc_mutex; 249 spinlock_t delalloc_lock; 264 spinlock_t delalloc_lock; 250 /* 265 /* 251 * all of the inodes that have delallo 266 * all of the inodes that have delalloc bytes. It is possible for 252 * this list to be empty even when the 267 * this list to be empty even when there is still dirty data=ordered 253 * extents waiting to finish IO. 268 * extents waiting to finish IO. 254 */ 269 */ 255 struct list_head delalloc_inodes; 270 struct list_head delalloc_inodes; 256 struct list_head delalloc_root; 271 struct list_head delalloc_root; 257 u64 nr_delalloc_inodes; 272 u64 nr_delalloc_inodes; 258 273 259 struct mutex ordered_extent_mutex; 274 struct mutex ordered_extent_mutex; 260 /* 275 /* 261 * this is used by the balancing code 276 * this is used by the balancing code to wait for all the pending 262 * ordered extents 277 * ordered extents 263 */ 278 */ 264 spinlock_t ordered_extent_lock; 279 spinlock_t ordered_extent_lock; 265 280 266 /* 281 /* 267 * all of the data=ordered extents pen 282 * all of the data=ordered extents pending writeback 268 * these can span multiple transaction 283 * these can span multiple transactions and basically include 269 * every dirty data page that isn't fr 284 * every dirty data page that isn't from nodatacow 270 */ 285 */ 271 struct list_head ordered_extents; 286 struct list_head ordered_extents; 272 struct list_head ordered_root; 287 struct list_head ordered_root; 273 u64 nr_ordered_extents; 288 u64 nr_ordered_extents; 274 289 275 /* 290 /* 276 * Not empty if this subvolume root ha 291 * Not empty if this subvolume root has gone through tree block swap 277 * (relocation) 292 * (relocation) 278 * 293 * 279 * Will be used by reloc_control::dirt 294 * Will be used by reloc_control::dirty_subvol_roots. 280 */ 295 */ 281 struct list_head reloc_dirty_list; 296 struct list_head reloc_dirty_list; 282 297 283 /* 298 /* 284 * Number of currently running SEND io 299 * Number of currently running SEND ioctls to prevent 285 * manipulation with the read-only sta 300 * manipulation with the read-only status via SUBVOL_SETFLAGS 286 */ 301 */ 287 int send_in_progress; 302 int send_in_progress; 288 /* 303 /* 289 * Number of currently running dedupli 304 * Number of currently running deduplication operations that have a 290 * destination inode belonging to this 305 * destination inode belonging to this root. Protected by the lock 291 * root_item_lock. 306 * root_item_lock. 292 */ 307 */ 293 int dedupe_in_progress; 308 int dedupe_in_progress; 294 /* For exclusion of snapshot creation 309 /* For exclusion of snapshot creation and nocow writes */ 295 struct btrfs_drew_lock snapshot_lock; 310 struct btrfs_drew_lock snapshot_lock; 296 311 297 atomic_t snapshot_force_cow; 312 atomic_t snapshot_force_cow; 298 313 299 /* For qgroup metadata reserved space 314 /* For qgroup metadata reserved space */ 300 spinlock_t qgroup_meta_rsv_lock; 315 spinlock_t qgroup_meta_rsv_lock; 301 u64 qgroup_meta_rsv_pertrans; 316 u64 qgroup_meta_rsv_pertrans; 302 u64 qgroup_meta_rsv_prealloc; 317 u64 qgroup_meta_rsv_prealloc; 303 wait_queue_head_t qgroup_flush_wait; 318 wait_queue_head_t qgroup_flush_wait; 304 319 305 /* Number of active swapfiles */ 320 /* Number of active swapfiles */ 306 atomic_t nr_swapfiles; 321 atomic_t nr_swapfiles; 307 322 308 /* Record pairs of swapped blocks for 323 /* Record pairs of swapped blocks for qgroup */ 309 struct btrfs_qgroup_swapped_blocks swa 324 struct btrfs_qgroup_swapped_blocks swapped_blocks; 310 325 311 /* Used only by log trees, when loggin 326 /* Used only by log trees, when logging csum items */ 312 struct extent_io_tree log_csum_range; 327 struct extent_io_tree log_csum_range; 313 328 314 /* Used in simple quotas, track root d << 315 u64 relocation_src_root; << 316 << 317 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 329 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 318 u64 alloc_bytenr; 330 u64 alloc_bytenr; 319 #endif 331 #endif 320 332 321 #ifdef CONFIG_BTRFS_DEBUG 333 #ifdef CONFIG_BTRFS_DEBUG 322 struct list_head leak_list; 334 struct list_head leak_list; 323 #endif 335 #endif 324 }; 336 }; 325 337 326 static inline bool btrfs_root_readonly(const s 338 static inline bool btrfs_root_readonly(const struct btrfs_root *root) 327 { 339 { 328 /* Byte-swap the constant at compile t 340 /* Byte-swap the constant at compile time, root_item::flags is LE */ 329 return (root->root_item.flags & cpu_to 341 return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0; 330 } 342 } 331 343 332 static inline bool btrfs_root_dead(const struc 344 static inline bool btrfs_root_dead(const struct btrfs_root *root) 333 { 345 { 334 /* Byte-swap the constant at compile t 346 /* Byte-swap the constant at compile time, root_item::flags is LE */ 335 return (root->root_item.flags & cpu_to 347 return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_DEAD)) != 0; 336 } 348 } 337 349 338 static inline u64 btrfs_root_id(const struct b 350 static inline u64 btrfs_root_id(const struct btrfs_root *root) 339 { 351 { 340 return root->root_key.objectid; 352 return root->root_key.objectid; 341 } 353 } 342 354 343 static inline int btrfs_get_root_log_transid(c << 344 { << 345 return READ_ONCE(root->log_transid); << 346 } << 347 << 348 static inline void btrfs_set_root_log_transid( << 349 { << 350 WRITE_ONCE(root->log_transid, log_tran << 351 } << 352 << 353 static inline int btrfs_get_root_last_log_comm << 354 { << 355 return READ_ONCE(root->last_log_commit << 356 } << 357 << 358 static inline void btrfs_set_root_last_log_com << 359 { << 360 WRITE_ONCE(root->last_log_commit, comm << 361 } << 362 << 363 static inline u64 btrfs_get_root_last_trans(co << 364 { << 365 return READ_ONCE(root->last_trans); << 366 } << 367 << 368 static inline void btrfs_set_root_last_trans(s << 369 { << 370 WRITE_ONCE(root->last_trans, transid); << 371 } << 372 << 373 /* 355 /* 374 * Structure that conveys information about an 356 * Structure that conveys information about an extent that is going to replace 375 * all the extents in a file range. 357 * all the extents in a file range. 376 */ 358 */ 377 struct btrfs_replace_extent_info { 359 struct btrfs_replace_extent_info { 378 u64 disk_offset; 360 u64 disk_offset; 379 u64 disk_len; 361 u64 disk_len; 380 u64 data_offset; 362 u64 data_offset; 381 u64 data_len; 363 u64 data_len; 382 u64 file_offset; 364 u64 file_offset; 383 /* Pointer to a file extent item of ty 365 /* Pointer to a file extent item of type regular or prealloc. */ 384 char *extent_buf; 366 char *extent_buf; 385 /* 367 /* 386 * Set to true when attempting to repl 368 * Set to true when attempting to replace a file range with a new extent 387 * described by this structure, set to 369 * described by this structure, set to false when attempting to clone an 388 * existing extent into a file range. 370 * existing extent into a file range. 389 */ 371 */ 390 bool is_new_extent; 372 bool is_new_extent; 391 /* Indicate if we should update the in 373 /* Indicate if we should update the inode's mtime and ctime. */ 392 bool update_times; 374 bool update_times; 393 /* Meaningful only if is_new_extent is 375 /* Meaningful only if is_new_extent is true. */ 394 int qgroup_reserved; 376 int qgroup_reserved; 395 /* 377 /* 396 * Meaningful only if is_new_extent is 378 * Meaningful only if is_new_extent is true. 397 * Used to track how many extent items 379 * Used to track how many extent items we have already inserted in a 398 * subvolume tree that refer to the ex 380 * subvolume tree that refer to the extent described by this structure, 399 * so that we know when to create a ne 381 * so that we know when to create a new delayed ref or update an existing 400 * one. 382 * one. 401 */ 383 */ 402 int insertions; 384 int insertions; 403 }; 385 }; 404 386 405 /* Arguments for btrfs_drop_extents() */ 387 /* Arguments for btrfs_drop_extents() */ 406 struct btrfs_drop_extents_args { 388 struct btrfs_drop_extents_args { 407 /* Input parameters */ 389 /* Input parameters */ 408 390 409 /* 391 /* 410 * If NULL, btrfs_drop_extents() will 392 * If NULL, btrfs_drop_extents() will allocate and free its own path. 411 * If 'replace_extent' is true, this m 393 * If 'replace_extent' is true, this must not be NULL. Also the path 412 * is always released except if 'repla 394 * is always released except if 'replace_extent' is true and 413 * btrfs_drop_extents() sets 'extent_i 395 * btrfs_drop_extents() sets 'extent_inserted' to true, in which case 414 * the path is kept locked. 396 * the path is kept locked. 415 */ 397 */ 416 struct btrfs_path *path; 398 struct btrfs_path *path; 417 /* Start offset of the range to drop e 399 /* Start offset of the range to drop extents from */ 418 u64 start; 400 u64 start; 419 /* End (exclusive, last byte + 1) of t 401 /* End (exclusive, last byte + 1) of the range to drop extents from */ 420 u64 end; 402 u64 end; 421 /* If true drop all the extent maps in 403 /* If true drop all the extent maps in the range */ 422 bool drop_cache; 404 bool drop_cache; 423 /* 405 /* 424 * If true it means we want to insert 406 * If true it means we want to insert a new extent after dropping all 425 * the extents in the range. If this i 407 * the extents in the range. If this is true, the 'extent_item_size' 426 * parameter must be set as well and t 408 * parameter must be set as well and the 'extent_inserted' field will 427 * be set to true by btrfs_drop_extent 409 * be set to true by btrfs_drop_extents() if it could insert the new 428 * extent. 410 * extent. 429 * Note: when this is set to true the 411 * Note: when this is set to true the path must not be NULL. 430 */ 412 */ 431 bool replace_extent; 413 bool replace_extent; 432 /* 414 /* 433 * Used if 'replace_extent' is true. S 415 * Used if 'replace_extent' is true. Size of the file extent item to 434 * insert after dropping all existing 416 * insert after dropping all existing extents in the range 435 */ 417 */ 436 u32 extent_item_size; 418 u32 extent_item_size; 437 419 438 /* Output parameters */ 420 /* Output parameters */ 439 421 440 /* 422 /* 441 * Set to the minimum between the inpu 423 * Set to the minimum between the input parameter 'end' and the end 442 * (exclusive, last byte + 1) of the l 424 * (exclusive, last byte + 1) of the last dropped extent. This is always 443 * set even if btrfs_drop_extents() re 425 * set even if btrfs_drop_extents() returns an error. 444 */ 426 */ 445 u64 drop_end; 427 u64 drop_end; 446 /* 428 /* 447 * The number of allocated bytes found 429 * The number of allocated bytes found in the range. This can be smaller 448 * than the range's length when there 430 * than the range's length when there are holes in the range. 449 */ 431 */ 450 u64 bytes_found; 432 u64 bytes_found; 451 /* 433 /* 452 * Only set if 'replace_extent' is tru 434 * Only set if 'replace_extent' is true. Set to true if we were able 453 * to insert a replacement extent afte 435 * to insert a replacement extent after dropping all extents in the 454 * range, otherwise set to false by bt 436 * range, otherwise set to false by btrfs_drop_extents(). 455 * Also, if btrfs_drop_extents() has s 437 * Also, if btrfs_drop_extents() has set this to true it means it 456 * returned with the path locked, othe 438 * returned with the path locked, otherwise if it has set this to 457 * false it has returned with the path 439 * false it has returned with the path released. 458 */ 440 */ 459 bool extent_inserted; 441 bool extent_inserted; 460 }; 442 }; 461 443 462 struct btrfs_file_private { 444 struct btrfs_file_private { 463 void *filldir_buf; 445 void *filldir_buf; 464 u64 last_index; 446 u64 last_index; 465 struct extent_state *llseek_cached_sta 447 struct extent_state *llseek_cached_state; 466 /* Task that allocated this structure. << 467 struct task_struct *owner_task; << 468 }; 448 }; 469 449 470 static inline u32 BTRFS_LEAF_DATA_SIZE(const s 450 static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info) 471 { 451 { 472 return info->nodesize - sizeof(struct 452 return info->nodesize - sizeof(struct btrfs_header); 473 } 453 } 474 454 475 static inline u32 BTRFS_MAX_ITEM_SIZE(const st 455 static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) 476 { 456 { 477 return BTRFS_LEAF_DATA_SIZE(info) - si 457 return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); 478 } 458 } 479 459 480 static inline u32 BTRFS_NODEPTRS_PER_BLOCK(con 460 static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) 481 { 461 { 482 return BTRFS_LEAF_DATA_SIZE(info) / si 462 return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); 483 } 463 } 484 464 485 static inline u32 BTRFS_MAX_XATTR_SIZE(const s 465 static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) 486 { 466 { 487 return BTRFS_MAX_ITEM_SIZE(info) - siz 467 return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); 488 } 468 } 489 469 490 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ 470 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ 491 ((bytes) >> (f 471 ((bytes) >> (fs_info)->sectorsize_bits) 492 472 >> 473 static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length) >> 474 { >> 475 return crc32c(crc, address, length); >> 476 } >> 477 >> 478 static inline void btrfs_crc32c_final(u32 crc, u8 *result) >> 479 { >> 480 put_unaligned_le32(~crc, result); >> 481 } >> 482 >> 483 static inline u64 btrfs_name_hash(const char *name, int len) >> 484 { >> 485 return crc32c((u32)~1, name, len); >> 486 } >> 487 >> 488 /* >> 489 * Figure the key offset of an extended inode ref >> 490 */ >> 491 static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, >> 492 int len) >> 493 { >> 494 return (u64) crc32c(parent_objectid, name, len); >> 495 } >> 496 493 static inline gfp_t btrfs_alloc_write_mask(str 497 static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) 494 { 498 { 495 return mapping_gfp_constraint(mapping, 499 return mapping_gfp_constraint(mapping, ~__GFP_FS); 496 } 500 } 497 501 498 void btrfs_error_unpin_extent_range(struct btr !! 502 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, >> 503 u64 start, u64 end); 499 int btrfs_discard_extent(struct btrfs_fs_info 504 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, 500 u64 num_bytes, u64 *a 505 u64 num_bytes, u64 *actual_bytes); 501 int btrfs_trim_fs(struct btrfs_fs_info *fs_inf 506 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); 502 507 503 /* ctree.c */ 508 /* ctree.c */ 504 int __init btrfs_ctree_init(void); 509 int __init btrfs_ctree_init(void); 505 void __cold btrfs_ctree_exit(void); 510 void __cold btrfs_ctree_exit(void); 506 511 507 int btrfs_bin_search(struct extent_buffer *eb, 512 int btrfs_bin_search(struct extent_buffer *eb, int first_slot, 508 const struct btrfs_key *k 513 const struct btrfs_key *key, int *slot); 509 514 510 int __pure btrfs_comp_cpu_keys(const struct bt 515 int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); 511 << 512 #ifdef __LITTLE_ENDIAN << 513 << 514 /* << 515 * Compare two keys, on little-endian the disk << 516 * we can avoid the conversion. << 517 */ << 518 static inline int btrfs_comp_keys(const struct << 519 const struct << 520 { << 521 const struct btrfs_key *k1 = (const st << 522 << 523 return btrfs_comp_cpu_keys(k1, k2); << 524 } << 525 << 526 #else << 527 << 528 /* Compare two keys in a memcmp fashion. */ << 529 static inline int btrfs_comp_keys(const struct << 530 const struct << 531 { << 532 struct btrfs_key k1; << 533 << 534 btrfs_disk_key_to_cpu(&k1, disk); << 535 << 536 return btrfs_comp_cpu_keys(&k1, k2); << 537 } << 538 << 539 #endif << 540 << 541 int btrfs_previous_item(struct btrfs_root *roo 516 int btrfs_previous_item(struct btrfs_root *root, 542 struct btrfs_path *pat 517 struct btrfs_path *path, u64 min_objectid, 543 int type); 518 int type); 544 int btrfs_previous_extent_item(struct btrfs_ro 519 int btrfs_previous_extent_item(struct btrfs_root *root, 545 struct btrfs_path *pat 520 struct btrfs_path *path, u64 min_objectid); 546 void btrfs_set_item_key_safe(struct btrfs_tran !! 521 void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, 547 const struct btrf !! 522 struct btrfs_path *path, 548 const struct btrf 523 const struct btrfs_key *new_key); 549 struct extent_buffer *btrfs_root_node(struct b 524 struct extent_buffer *btrfs_root_node(struct btrfs_root *root); 550 int btrfs_find_next_key(struct btrfs_root *roo 525 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, 551 struct btrfs_key *key, 526 struct btrfs_key *key, int lowest_level, 552 u64 min_trans); 527 u64 min_trans); 553 int btrfs_search_forward(struct btrfs_root *ro 528 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, 554 struct btrfs_path *pa 529 struct btrfs_path *path, 555 u64 min_trans); 530 u64 min_trans); 556 struct extent_buffer *btrfs_read_node_slot(str 531 struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent, 557 int 532 int slot); 558 533 559 int btrfs_cow_block(struct btrfs_trans_handle 534 int btrfs_cow_block(struct btrfs_trans_handle *trans, 560 struct btrfs_root *root, s 535 struct btrfs_root *root, struct extent_buffer *buf, 561 struct extent_buffer *pare 536 struct extent_buffer *parent, int parent_slot, 562 struct extent_buffer **cow 537 struct extent_buffer **cow_ret, 563 enum btrfs_lock_nesting ne 538 enum btrfs_lock_nesting nest); 564 int btrfs_force_cow_block(struct btrfs_trans_h << 565 struct btrfs_root *r << 566 struct extent_buffer << 567 struct extent_buffer << 568 struct extent_buffer << 569 u64 search_start, u6 << 570 enum btrfs_lock_nest << 571 int btrfs_copy_root(struct btrfs_trans_handle 539 int btrfs_copy_root(struct btrfs_trans_handle *trans, 572 struct btrfs_root *root, 540 struct btrfs_root *root, 573 struct extent_buffer *bu 541 struct extent_buffer *buf, 574 struct extent_buffer **c 542 struct extent_buffer **cow_ret, u64 new_root_objectid); 575 bool btrfs_block_can_be_shared(struct btrfs_tr !! 543 int btrfs_block_can_be_shared(struct btrfs_root *root, 576 struct btrfs_ro !! 544 struct extent_buffer *buf); 577 struct extent_b !! 545 void btrfs_extend_item(struct btrfs_path *path, u32 data_size); 578 int btrfs_del_ptr(struct btrfs_trans_handle *t !! 546 void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end); 579 struct btrfs_path *path, int << 580 void btrfs_extend_item(struct btrfs_trans_hand << 581 const struct btrfs_path << 582 void btrfs_truncate_item(struct btrfs_trans_ha << 583 const struct btrfs_pa << 584 int btrfs_split_item(struct btrfs_trans_handle 547 int btrfs_split_item(struct btrfs_trans_handle *trans, 585 struct btrfs_root *root, 548 struct btrfs_root *root, 586 struct btrfs_path *path, 549 struct btrfs_path *path, 587 const struct btrfs_key *n 550 const struct btrfs_key *new_key, 588 unsigned long split_offse 551 unsigned long split_offset); 589 int btrfs_duplicate_item(struct btrfs_trans_ha 552 int btrfs_duplicate_item(struct btrfs_trans_handle *trans, 590 struct btrfs_root *ro 553 struct btrfs_root *root, 591 struct btrfs_path *pa 554 struct btrfs_path *path, 592 const struct btrfs_ke 555 const struct btrfs_key *new_key); 593 int btrfs_find_item(struct btrfs_root *fs_root 556 int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, 594 u64 inum, u64 ioff, u8 key_typ 557 u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); 595 int btrfs_search_slot(struct btrfs_trans_handl 558 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, 596 const struct btrfs_key * 559 const struct btrfs_key *key, struct btrfs_path *p, 597 int ins_len, int cow); 560 int ins_len, int cow); 598 int btrfs_search_old_slot(struct btrfs_root *r 561 int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key, 599 struct btrfs_path *p 562 struct btrfs_path *p, u64 time_seq); 600 int btrfs_search_slot_for_read(struct btrfs_ro 563 int btrfs_search_slot_for_read(struct btrfs_root *root, 601 const struct bt 564 const struct btrfs_key *key, 602 struct btrfs_pa 565 struct btrfs_path *p, int find_higher, 603 int return_any) 566 int return_any); >> 567 int btrfs_realloc_node(struct btrfs_trans_handle *trans, >> 568 struct btrfs_root *root, struct extent_buffer *parent, >> 569 int start_slot, u64 *last_ret, >> 570 struct btrfs_key *progress); 604 void btrfs_release_path(struct btrfs_path *p); 571 void btrfs_release_path(struct btrfs_path *p); 605 struct btrfs_path *btrfs_alloc_path(void); 572 struct btrfs_path *btrfs_alloc_path(void); 606 void btrfs_free_path(struct btrfs_path *p); 573 void btrfs_free_path(struct btrfs_path *p); 607 DEFINE_FREE(btrfs_free_path, struct btrfs_path << 608 574 609 int btrfs_del_items(struct btrfs_trans_handle 575 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, 610 struct btrfs_path *path, in 576 struct btrfs_path *path, int slot, int nr); 611 static inline int btrfs_del_item(struct btrfs_ 577 static inline int btrfs_del_item(struct btrfs_trans_handle *trans, 612 struct btrfs_ 578 struct btrfs_root *root, 613 struct btrfs_ 579 struct btrfs_path *path) 614 { 580 { 615 return btrfs_del_items(trans, root, pa 581 return btrfs_del_items(trans, root, path, path->slots[0], 1); 616 } 582 } 617 583 618 /* 584 /* 619 * Describes a batch of items to insert in a b 585 * Describes a batch of items to insert in a btree. This is used by 620 * btrfs_insert_empty_items(). 586 * btrfs_insert_empty_items(). 621 */ 587 */ 622 struct btrfs_item_batch { 588 struct btrfs_item_batch { 623 /* 589 /* 624 * Pointer to an array containing the 590 * Pointer to an array containing the keys of the items to insert (in 625 * sorted order). 591 * sorted order). 626 */ 592 */ 627 const struct btrfs_key *keys; 593 const struct btrfs_key *keys; 628 /* Pointer to an array containing the 594 /* Pointer to an array containing the data size for each item to insert. */ 629 const u32 *data_sizes; 595 const u32 *data_sizes; 630 /* 596 /* 631 * The sum of data sizes for all items 597 * The sum of data sizes for all items. The caller can compute this while 632 * setting up the data_sizes array, so 598 * setting up the data_sizes array, so it ends up being more efficient 633 * than having btrfs_insert_empty_item 599 * than having btrfs_insert_empty_items() or setup_item_for_insert() 634 * doing it, as it would avoid an extr 600 * doing it, as it would avoid an extra loop over a potentially large 635 * array, and in the case of setup_ite 601 * array, and in the case of setup_item_for_insert(), we would be doing 636 * it while holding a write lock on a 602 * it while holding a write lock on a leaf and often on upper level nodes 637 * too, unnecessarily increasing the s 603 * too, unnecessarily increasing the size of a critical section. 638 */ 604 */ 639 u32 total_data_size; 605 u32 total_data_size; 640 /* Size of the keys and data_sizes arr 606 /* Size of the keys and data_sizes arrays (number of items in the batch). */ 641 int nr; 607 int nr; 642 }; 608 }; 643 609 644 void btrfs_setup_item_for_insert(struct btrfs_ !! 610 void btrfs_setup_item_for_insert(struct btrfs_root *root, 645 struct btrfs_ << 646 struct btrfs_ 611 struct btrfs_path *path, 647 const struct 612 const struct btrfs_key *key, 648 u32 data_size 613 u32 data_size); 649 int btrfs_insert_item(struct btrfs_trans_handl 614 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, 650 const struct btrfs_key * 615 const struct btrfs_key *key, void *data, u32 data_size); 651 int btrfs_insert_empty_items(struct btrfs_tran 616 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, 652 struct btrfs_root 617 struct btrfs_root *root, 653 struct btrfs_path 618 struct btrfs_path *path, 654 const struct btrf 619 const struct btrfs_item_batch *batch); 655 620 656 static inline int btrfs_insert_empty_item(stru 621 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, 657 stru 622 struct btrfs_root *root, 658 stru 623 struct btrfs_path *path, 659 cons 624 const struct btrfs_key *key, 660 u32 625 u32 data_size) 661 { 626 { 662 struct btrfs_item_batch batch; 627 struct btrfs_item_batch batch; 663 628 664 batch.keys = key; 629 batch.keys = key; 665 batch.data_sizes = &data_size; 630 batch.data_sizes = &data_size; 666 batch.total_data_size = data_size; 631 batch.total_data_size = data_size; 667 batch.nr = 1; 632 batch.nr = 1; 668 633 669 return btrfs_insert_empty_items(trans, 634 return btrfs_insert_empty_items(trans, root, path, &batch); 670 } 635 } 671 636 >> 637 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); 672 int btrfs_next_old_leaf(struct btrfs_root *roo 638 int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path, 673 u64 time_seq); 639 u64 time_seq); 674 640 675 int btrfs_search_backwards(struct btrfs_root * 641 int btrfs_search_backwards(struct btrfs_root *root, struct btrfs_key *key, 676 struct btrfs_path * 642 struct btrfs_path *path); 677 643 678 int btrfs_get_next_valid_item(struct btrfs_roo 644 int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key, 679 struct btrfs_pat 645 struct btrfs_path *path); 680 646 681 /* 647 /* 682 * Search in @root for a given @key, and store 648 * Search in @root for a given @key, and store the slot found in @found_key. 683 * 649 * 684 * @root: The root node of the tree. 650 * @root: The root node of the tree. 685 * @key: The key we are looking for. 651 * @key: The key we are looking for. 686 * @found_key: Will hold the found item. 652 * @found_key: Will hold the found item. 687 * @path: Holds the current slot/leaf. 653 * @path: Holds the current slot/leaf. 688 * @iter_ret: Contains the value returned fr 654 * @iter_ret: Contains the value returned from btrfs_search_slot or 689 * btrfs_get_next_valid_item, whi 655 * btrfs_get_next_valid_item, whichever was executed last. 690 * 656 * 691 * The @iter_ret is an output variable that wi 657 * The @iter_ret is an output variable that will contain the return value of 692 * btrfs_search_slot, if it encountered an err 658 * btrfs_search_slot, if it encountered an error, or the value returned from 693 * btrfs_get_next_valid_item otherwise. That r 659 * btrfs_get_next_valid_item otherwise. That return value can be 0, if a valid 694 * slot was found, 1 if there were no more lea 660 * slot was found, 1 if there were no more leaves, and <0 if there was an error. 695 * 661 * 696 * It's recommended to use a separate variable 662 * It's recommended to use a separate variable for iter_ret and then use it to 697 * set the function return value so there's no 663 * set the function return value so there's no confusion of the 0/1/errno 698 * values stemming from btrfs_search_slot. 664 * values stemming from btrfs_search_slot. 699 */ 665 */ 700 #define btrfs_for_each_slot(root, key, found_k 666 #define btrfs_for_each_slot(root, key, found_key, path, iter_ret) \ 701 for (iter_ret = btrfs_search_slot(NULL 667 for (iter_ret = btrfs_search_slot(NULL, (root), (key), (path), 0, 0); \ 702 (iter_ret) >= 0 && 668 (iter_ret) >= 0 && \ 703 (iter_ret = btrfs_get_next_val 669 (iter_ret = btrfs_get_next_valid_item((root), (found_key), (path))) == 0; \ 704 (path)->slots[0]++ 670 (path)->slots[0]++ \ 705 ) 671 ) 706 672 707 int btrfs_next_old_item(struct btrfs_root *roo 673 int btrfs_next_old_item(struct btrfs_root *root, struct btrfs_path *path, u64 time_seq); 708 674 709 /* 675 /* 710 * Search the tree again to find a leaf with g 676 * Search the tree again to find a leaf with greater keys. 711 * 677 * 712 * Returns 0 if it found something or 1 if the 678 * Returns 0 if it found something or 1 if there are no greater leaves. 713 * Returns < 0 on error. 679 * Returns < 0 on error. 714 */ 680 */ 715 static inline int btrfs_next_leaf(struct btrfs 681 static inline int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path) 716 { 682 { 717 return btrfs_next_old_leaf(root, path, 683 return btrfs_next_old_leaf(root, path, 0); 718 } 684 } 719 685 720 static inline int btrfs_next_item(struct btrfs 686 static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) 721 { 687 { 722 return btrfs_next_old_item(root, p, 0) 688 return btrfs_next_old_item(root, p, 0); 723 } 689 } 724 int btrfs_leaf_free_space(const struct extent_ !! 690 int btrfs_leaf_free_space(struct extent_buffer *leaf); 725 691 726 static inline int is_fstree(u64 rootid) 692 static inline int is_fstree(u64 rootid) 727 { 693 { 728 if (rootid == BTRFS_FS_TREE_OBJECTID | 694 if (rootid == BTRFS_FS_TREE_OBJECTID || 729 ((s64)rootid >= (s64)BTRFS_FIRST_F 695 ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID && 730 !btrfs_qgroup_level(rootid))) 696 !btrfs_qgroup_level(rootid))) 731 return 1; 697 return 1; 732 return 0; 698 return 0; 733 } 699 } 734 700 735 static inline bool btrfs_is_data_reloc_root(co 701 static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) 736 { 702 { 737 return root->root_key.objectid == BTRF 703 return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; 738 } 704 } 739 705 740 u16 btrfs_csum_type_size(u16 type); << 741 int btrfs_super_csum_size(const struct btrfs_s 706 int btrfs_super_csum_size(const struct btrfs_super_block *s); 742 const char *btrfs_super_csum_name(u16 csum_typ 707 const char *btrfs_super_csum_name(u16 csum_type); 743 const char *btrfs_super_csum_driver(u16 csum_t 708 const char *btrfs_super_csum_driver(u16 csum_type); 744 size_t __attribute_const__ btrfs_get_num_csums 709 size_t __attribute_const__ btrfs_get_num_csums(void); 745 710 746 /* 711 /* 747 * We use page status Private2 to indicate the 712 * We use page status Private2 to indicate there is an ordered extent with 748 * unfinished IO. 713 * unfinished IO. 749 * 714 * 750 * Rename the Private2 accessors to Ordered, t 715 * Rename the Private2 accessors to Ordered, to improve readability. 751 */ 716 */ 752 #define PageOrdered(page) PagePr 717 #define PageOrdered(page) PagePrivate2(page) 753 #define SetPageOrdered(page) SetPag 718 #define SetPageOrdered(page) SetPagePrivate2(page) 754 #define ClearPageOrdered(page) ClearP 719 #define ClearPageOrdered(page) ClearPagePrivate2(page) 755 #define folio_test_ordered(folio) folio_ 720 #define folio_test_ordered(folio) folio_test_private_2(folio) 756 #define folio_set_ordered(folio) folio_ 721 #define folio_set_ordered(folio) folio_set_private_2(folio) 757 #define folio_clear_ordered(folio) folio_ 722 #define folio_clear_ordered(folio) folio_clear_private_2(folio) 758 723 759 #endif 724 #endif 760 725
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.