~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/btrfs/ctree.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/btrfs/ctree.h (Version linux-6.12-rc7) and /fs/btrfs/ctree.h (Version linux-6.10.14)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php