1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2007 Oracle. All rights reserved.
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #ifndef BTRFS_CTREE_H
7*4882a593Smuzhiyun #define BTRFS_CTREE_H
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/mm.h>
10*4882a593Smuzhiyun #include <linux/sched/signal.h>
11*4882a593Smuzhiyun #include <linux/highmem.h>
12*4882a593Smuzhiyun #include <linux/fs.h>
13*4882a593Smuzhiyun #include <linux/rwsem.h>
14*4882a593Smuzhiyun #include <linux/semaphore.h>
15*4882a593Smuzhiyun #include <linux/completion.h>
16*4882a593Smuzhiyun #include <linux/backing-dev.h>
17*4882a593Smuzhiyun #include <linux/wait.h>
18*4882a593Smuzhiyun #include <linux/slab.h>
19*4882a593Smuzhiyun #include <trace/events/btrfs.h>
20*4882a593Smuzhiyun #include <asm/kmap_types.h>
21*4882a593Smuzhiyun #include <asm/unaligned.h>
22*4882a593Smuzhiyun #include <linux/pagemap.h>
23*4882a593Smuzhiyun #include <linux/btrfs.h>
24*4882a593Smuzhiyun #include <linux/btrfs_tree.h>
25*4882a593Smuzhiyun #include <linux/workqueue.h>
26*4882a593Smuzhiyun #include <linux/security.h>
27*4882a593Smuzhiyun #include <linux/sizes.h>
28*4882a593Smuzhiyun #include <linux/dynamic_debug.h>
29*4882a593Smuzhiyun #include <linux/refcount.h>
30*4882a593Smuzhiyun #include <linux/crc32c.h>
31*4882a593Smuzhiyun #include "extent-io-tree.h"
32*4882a593Smuzhiyun #include "extent_io.h"
33*4882a593Smuzhiyun #include "extent_map.h"
34*4882a593Smuzhiyun #include "async-thread.h"
35*4882a593Smuzhiyun #include "block-rsv.h"
36*4882a593Smuzhiyun #include "locking.h"
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun struct btrfs_trans_handle;
39*4882a593Smuzhiyun struct btrfs_transaction;
40*4882a593Smuzhiyun struct btrfs_pending_snapshot;
41*4882a593Smuzhiyun struct btrfs_delayed_ref_root;
42*4882a593Smuzhiyun struct btrfs_space_info;
43*4882a593Smuzhiyun struct btrfs_block_group;
44*4882a593Smuzhiyun extern struct kmem_cache *btrfs_trans_handle_cachep;
45*4882a593Smuzhiyun extern struct kmem_cache *btrfs_bit_radix_cachep;
46*4882a593Smuzhiyun extern struct kmem_cache *btrfs_path_cachep;
47*4882a593Smuzhiyun extern struct kmem_cache *btrfs_free_space_cachep;
48*4882a593Smuzhiyun extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
49*4882a593Smuzhiyun struct btrfs_ordered_sum;
50*4882a593Smuzhiyun struct btrfs_ref;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun * Maximum number of mirrors that can be available for all profiles counting
56*4882a593Smuzhiyun * the target device of dev-replace as one. During an active device replace
57*4882a593Smuzhiyun * procedure, the target device of the copy operation is a mirror for the
58*4882a593Smuzhiyun * filesystem data as well that can be used to read data in order to repair
59*4882a593Smuzhiyun * read errors on other disks.
60*4882a593Smuzhiyun *
61*4882a593Smuzhiyun * Current value is derived from RAID1C4 with 4 copies.
62*4882a593Smuzhiyun */
63*4882a593Smuzhiyun #define BTRFS_MAX_MIRRORS (4 + 1)
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun #define BTRFS_MAX_LEVEL 8
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #define BTRFS_OLDEST_GENERATION 0ULL
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun * the max metadata block size. This limit is somewhat artificial,
71*4882a593Smuzhiyun * but the memmove costs go through the roof for larger blocks.
72*4882a593Smuzhiyun */
73*4882a593Smuzhiyun #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun * we can actually store much bigger names, but lets not confuse the rest
77*4882a593Smuzhiyun * of linux
78*4882a593Smuzhiyun */
79*4882a593Smuzhiyun #define BTRFS_NAME_LEN 255
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun /*
82*4882a593Smuzhiyun * Theoretical limit is larger, but we keep this down to a sane
83*4882a593Smuzhiyun * value. That should limit greatly the possibility of collisions on
84*4882a593Smuzhiyun * inode ref items.
85*4882a593Smuzhiyun */
86*4882a593Smuzhiyun #define BTRFS_LINK_MAX 65535U
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #define BTRFS_EMPTY_DIR_SIZE 0
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /* ioprio of readahead is set to idle */
91*4882a593Smuzhiyun #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #define BTRFS_DIRTY_METADATA_THRESH SZ_32M
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun * Use large batch size to reduce overhead of metadata updates. On the reader
97*4882a593Smuzhiyun * side, we only read it when we are close to ENOSPC and the read overhead is
98*4882a593Smuzhiyun * mostly related to the number of CPUs, so it is OK to use arbitrary large
99*4882a593Smuzhiyun * value here.
100*4882a593Smuzhiyun */
101*4882a593Smuzhiyun #define BTRFS_TOTAL_BYTES_PINNED_BATCH SZ_128M
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #define BTRFS_MAX_EXTENT_SIZE SZ_128M
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * Deltas are an effective way to populate global statistics. Give macro names
107*4882a593Smuzhiyun * to make it clear what we're doing. An example is discard_extents in
108*4882a593Smuzhiyun * btrfs_free_space_ctl.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun #define BTRFS_STAT_NR_ENTRIES 2
111*4882a593Smuzhiyun #define BTRFS_STAT_CURR 0
112*4882a593Smuzhiyun #define BTRFS_STAT_PREV 1
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /*
115*4882a593Smuzhiyun * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
116*4882a593Smuzhiyun */
count_max_extents(u64 size)117*4882a593Smuzhiyun static inline u32 count_max_extents(u64 size)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
btrfs_chunk_item_size(int num_stripes)122*4882a593Smuzhiyun static inline unsigned long btrfs_chunk_item_size(int num_stripes)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun BUG_ON(num_stripes == 0);
125*4882a593Smuzhiyun return sizeof(struct btrfs_chunk) +
126*4882a593Smuzhiyun sizeof(struct btrfs_stripe) * (num_stripes - 1);
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /*
130*4882a593Smuzhiyun * Runtime (in-memory) states of filesystem
131*4882a593Smuzhiyun */
132*4882a593Smuzhiyun enum {
133*4882a593Smuzhiyun /* Global indicator of serious filesystem errors */
134*4882a593Smuzhiyun BTRFS_FS_STATE_ERROR,
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun * Filesystem is being remounted, allow to skip some operations, like
137*4882a593Smuzhiyun * defrag
138*4882a593Smuzhiyun */
139*4882a593Smuzhiyun BTRFS_FS_STATE_REMOUNTING,
140*4882a593Smuzhiyun /* Track if a transaction abort has been reported on this filesystem */
141*4882a593Smuzhiyun BTRFS_FS_STATE_TRANS_ABORTED,
142*4882a593Smuzhiyun /*
143*4882a593Smuzhiyun * Bio operations should be blocked on this filesystem because a source
144*4882a593Smuzhiyun * or target device is being destroyed as part of a device replace
145*4882a593Smuzhiyun */
146*4882a593Smuzhiyun BTRFS_FS_STATE_DEV_REPLACING,
147*4882a593Smuzhiyun /* The btrfs_fs_info created for self-tests */
148*4882a593Smuzhiyun BTRFS_FS_STATE_DUMMY_FS_INFO,
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun #define BTRFS_BACKREF_REV_MAX 256
152*4882a593Smuzhiyun #define BTRFS_BACKREF_REV_SHIFT 56
153*4882a593Smuzhiyun #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
154*4882a593Smuzhiyun BTRFS_BACKREF_REV_SHIFT)
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun #define BTRFS_OLD_BACKREF_REV 0
157*4882a593Smuzhiyun #define BTRFS_MIXED_BACKREF_REV 1
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun * every tree block (leaf or node) starts with this header.
161*4882a593Smuzhiyun */
162*4882a593Smuzhiyun struct btrfs_header {
163*4882a593Smuzhiyun /* these first four must match the super block */
164*4882a593Smuzhiyun u8 csum[BTRFS_CSUM_SIZE];
165*4882a593Smuzhiyun u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
166*4882a593Smuzhiyun __le64 bytenr; /* which block this node is supposed to live in */
167*4882a593Smuzhiyun __le64 flags;
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /* allowed to be different from the super from here on down */
170*4882a593Smuzhiyun u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
171*4882a593Smuzhiyun __le64 generation;
172*4882a593Smuzhiyun __le64 owner;
173*4882a593Smuzhiyun __le32 nritems;
174*4882a593Smuzhiyun u8 level;
175*4882a593Smuzhiyun } __attribute__ ((__packed__));
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /*
178*4882a593Smuzhiyun * this is a very generous portion of the super block, giving us
179*4882a593Smuzhiyun * room to translate 14 chunks with 3 stripes each.
180*4882a593Smuzhiyun */
181*4882a593Smuzhiyun #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun /*
184*4882a593Smuzhiyun * just in case we somehow lose the roots and are not able to mount,
185*4882a593Smuzhiyun * we store an array of the roots from previous transactions
186*4882a593Smuzhiyun * in the super.
187*4882a593Smuzhiyun */
188*4882a593Smuzhiyun #define BTRFS_NUM_BACKUP_ROOTS 4
189*4882a593Smuzhiyun struct btrfs_root_backup {
190*4882a593Smuzhiyun __le64 tree_root;
191*4882a593Smuzhiyun __le64 tree_root_gen;
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun __le64 chunk_root;
194*4882a593Smuzhiyun __le64 chunk_root_gen;
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun __le64 extent_root;
197*4882a593Smuzhiyun __le64 extent_root_gen;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun __le64 fs_root;
200*4882a593Smuzhiyun __le64 fs_root_gen;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun __le64 dev_root;
203*4882a593Smuzhiyun __le64 dev_root_gen;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun __le64 csum_root;
206*4882a593Smuzhiyun __le64 csum_root_gen;
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun __le64 total_bytes;
209*4882a593Smuzhiyun __le64 bytes_used;
210*4882a593Smuzhiyun __le64 num_devices;
211*4882a593Smuzhiyun /* future */
212*4882a593Smuzhiyun __le64 unused_64[4];
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun u8 tree_root_level;
215*4882a593Smuzhiyun u8 chunk_root_level;
216*4882a593Smuzhiyun u8 extent_root_level;
217*4882a593Smuzhiyun u8 fs_root_level;
218*4882a593Smuzhiyun u8 dev_root_level;
219*4882a593Smuzhiyun u8 csum_root_level;
220*4882a593Smuzhiyun /* future and to align */
221*4882a593Smuzhiyun u8 unused_8[10];
222*4882a593Smuzhiyun } __attribute__ ((__packed__));
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun /*
225*4882a593Smuzhiyun * the super block basically lists the main trees of the FS
226*4882a593Smuzhiyun * it currently lacks any block count etc etc
227*4882a593Smuzhiyun */
228*4882a593Smuzhiyun struct btrfs_super_block {
229*4882a593Smuzhiyun /* the first 4 fields must match struct btrfs_header */
230*4882a593Smuzhiyun u8 csum[BTRFS_CSUM_SIZE];
231*4882a593Smuzhiyun /* FS specific UUID, visible to user */
232*4882a593Smuzhiyun u8 fsid[BTRFS_FSID_SIZE];
233*4882a593Smuzhiyun __le64 bytenr; /* this block number */
234*4882a593Smuzhiyun __le64 flags;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /* allowed to be different from the btrfs_header from here own down */
237*4882a593Smuzhiyun __le64 magic;
238*4882a593Smuzhiyun __le64 generation;
239*4882a593Smuzhiyun __le64 root;
240*4882a593Smuzhiyun __le64 chunk_root;
241*4882a593Smuzhiyun __le64 log_root;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun /* this will help find the new super based on the log root */
244*4882a593Smuzhiyun __le64 log_root_transid;
245*4882a593Smuzhiyun __le64 total_bytes;
246*4882a593Smuzhiyun __le64 bytes_used;
247*4882a593Smuzhiyun __le64 root_dir_objectid;
248*4882a593Smuzhiyun __le64 num_devices;
249*4882a593Smuzhiyun __le32 sectorsize;
250*4882a593Smuzhiyun __le32 nodesize;
251*4882a593Smuzhiyun __le32 __unused_leafsize;
252*4882a593Smuzhiyun __le32 stripesize;
253*4882a593Smuzhiyun __le32 sys_chunk_array_size;
254*4882a593Smuzhiyun __le64 chunk_root_generation;
255*4882a593Smuzhiyun __le64 compat_flags;
256*4882a593Smuzhiyun __le64 compat_ro_flags;
257*4882a593Smuzhiyun __le64 incompat_flags;
258*4882a593Smuzhiyun __le16 csum_type;
259*4882a593Smuzhiyun u8 root_level;
260*4882a593Smuzhiyun u8 chunk_root_level;
261*4882a593Smuzhiyun u8 log_root_level;
262*4882a593Smuzhiyun struct btrfs_dev_item dev_item;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun char label[BTRFS_LABEL_SIZE];
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun __le64 cache_generation;
267*4882a593Smuzhiyun __le64 uuid_tree_generation;
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /* the UUID written into btree blocks */
270*4882a593Smuzhiyun u8 metadata_uuid[BTRFS_FSID_SIZE];
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun /* future expansion */
273*4882a593Smuzhiyun __le64 reserved[28];
274*4882a593Smuzhiyun u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
275*4882a593Smuzhiyun struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
276*4882a593Smuzhiyun } __attribute__ ((__packed__));
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun /*
279*4882a593Smuzhiyun * Compat flags that we support. If any incompat flags are set other than the
280*4882a593Smuzhiyun * ones specified below then we will fail to mount
281*4882a593Smuzhiyun */
282*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
283*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
284*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_RO_SUPP \
287*4882a593Smuzhiyun (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
288*4882a593Smuzhiyun BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
291*4882a593Smuzhiyun #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun #define BTRFS_FEATURE_INCOMPAT_SUPP \
294*4882a593Smuzhiyun (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
295*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
296*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
297*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
298*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
299*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
300*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_RAID56 | \
301*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
302*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
303*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
304*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
305*4882a593Smuzhiyun BTRFS_FEATURE_INCOMPAT_RAID1C34)
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
308*4882a593Smuzhiyun (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
309*4882a593Smuzhiyun #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun /*
312*4882a593Smuzhiyun * A leaf is full of items. offset and size tell us where to find
313*4882a593Smuzhiyun * the item in the leaf (relative to the start of the data area)
314*4882a593Smuzhiyun */
315*4882a593Smuzhiyun struct btrfs_item {
316*4882a593Smuzhiyun struct btrfs_disk_key key;
317*4882a593Smuzhiyun __le32 offset;
318*4882a593Smuzhiyun __le32 size;
319*4882a593Smuzhiyun } __attribute__ ((__packed__));
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun /*
322*4882a593Smuzhiyun * leaves have an item area and a data area:
323*4882a593Smuzhiyun * [item0, item1....itemN] [free space] [dataN...data1, data0]
324*4882a593Smuzhiyun *
325*4882a593Smuzhiyun * The data is separate from the items to get the keys closer together
326*4882a593Smuzhiyun * during searches.
327*4882a593Smuzhiyun */
328*4882a593Smuzhiyun struct btrfs_leaf {
329*4882a593Smuzhiyun struct btrfs_header header;
330*4882a593Smuzhiyun struct btrfs_item items[];
331*4882a593Smuzhiyun } __attribute__ ((__packed__));
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun /*
334*4882a593Smuzhiyun * all non-leaf blocks are nodes, they hold only keys and pointers to
335*4882a593Smuzhiyun * other blocks
336*4882a593Smuzhiyun */
337*4882a593Smuzhiyun struct btrfs_key_ptr {
338*4882a593Smuzhiyun struct btrfs_disk_key key;
339*4882a593Smuzhiyun __le64 blockptr;
340*4882a593Smuzhiyun __le64 generation;
341*4882a593Smuzhiyun } __attribute__ ((__packed__));
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun struct btrfs_node {
344*4882a593Smuzhiyun struct btrfs_header header;
345*4882a593Smuzhiyun struct btrfs_key_ptr ptrs[];
346*4882a593Smuzhiyun } __attribute__ ((__packed__));
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun /*
349*4882a593Smuzhiyun * btrfs_paths remember the path taken from the root down to the leaf.
350*4882a593Smuzhiyun * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
351*4882a593Smuzhiyun * to any other levels that are present.
352*4882a593Smuzhiyun *
353*4882a593Smuzhiyun * The slots array records the index of the item or block pointer
354*4882a593Smuzhiyun * used while walking the tree.
355*4882a593Smuzhiyun */
356*4882a593Smuzhiyun enum { READA_NONE, READA_BACK, READA_FORWARD };
357*4882a593Smuzhiyun struct btrfs_path {
358*4882a593Smuzhiyun struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
359*4882a593Smuzhiyun int slots[BTRFS_MAX_LEVEL];
360*4882a593Smuzhiyun /* if there is real range locking, this locks field will change */
361*4882a593Smuzhiyun u8 locks[BTRFS_MAX_LEVEL];
362*4882a593Smuzhiyun u8 reada;
363*4882a593Smuzhiyun /* keep some upper locks as we walk down */
364*4882a593Smuzhiyun u8 lowest_level;
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun /*
367*4882a593Smuzhiyun * set by btrfs_split_item, tells search_slot to keep all locks
368*4882a593Smuzhiyun * and to force calls to keep space in the nodes
369*4882a593Smuzhiyun */
370*4882a593Smuzhiyun unsigned int search_for_split:1;
371*4882a593Smuzhiyun unsigned int keep_locks:1;
372*4882a593Smuzhiyun unsigned int skip_locking:1;
373*4882a593Smuzhiyun unsigned int leave_spinning:1;
374*4882a593Smuzhiyun unsigned int search_commit_root:1;
375*4882a593Smuzhiyun unsigned int need_commit_sem:1;
376*4882a593Smuzhiyun unsigned int skip_release_on_error:1;
377*4882a593Smuzhiyun unsigned int recurse:1;
378*4882a593Smuzhiyun };
379*4882a593Smuzhiyun #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
380*4882a593Smuzhiyun sizeof(struct btrfs_item))
381*4882a593Smuzhiyun struct btrfs_dev_replace {
382*4882a593Smuzhiyun u64 replace_state; /* see #define above */
383*4882a593Smuzhiyun time64_t time_started; /* seconds since 1-Jan-1970 */
384*4882a593Smuzhiyun time64_t time_stopped; /* seconds since 1-Jan-1970 */
385*4882a593Smuzhiyun atomic64_t num_write_errors;
386*4882a593Smuzhiyun atomic64_t num_uncorrectable_read_errors;
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun u64 cursor_left;
389*4882a593Smuzhiyun u64 committed_cursor_left;
390*4882a593Smuzhiyun u64 cursor_left_last_write_of_item;
391*4882a593Smuzhiyun u64 cursor_right;
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun u64 cont_reading_from_srcdev_mode; /* see #define above */
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun int is_valid;
396*4882a593Smuzhiyun int item_needs_writeback;
397*4882a593Smuzhiyun struct btrfs_device *srcdev;
398*4882a593Smuzhiyun struct btrfs_device *tgtdev;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun struct mutex lock_finishing_cancel_unmount;
401*4882a593Smuzhiyun struct rw_semaphore rwsem;
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun struct btrfs_scrub_progress scrub_progress;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun struct percpu_counter bio_counter;
406*4882a593Smuzhiyun wait_queue_head_t replace_wait;
407*4882a593Smuzhiyun };
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun /*
410*4882a593Smuzhiyun * free clusters are used to claim free space in relatively large chunks,
411*4882a593Smuzhiyun * allowing us to do less seeky writes. They are used for all metadata
412*4882a593Smuzhiyun * allocations. In ssd_spread mode they are also used for data allocations.
413*4882a593Smuzhiyun */
414*4882a593Smuzhiyun struct btrfs_free_cluster {
415*4882a593Smuzhiyun spinlock_t lock;
416*4882a593Smuzhiyun spinlock_t refill_lock;
417*4882a593Smuzhiyun struct rb_root root;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun /* largest extent in this cluster */
420*4882a593Smuzhiyun u64 max_size;
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun /* first extent starting offset */
423*4882a593Smuzhiyun u64 window_start;
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun /* We did a full search and couldn't create a cluster */
426*4882a593Smuzhiyun bool fragmented;
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun struct btrfs_block_group *block_group;
429*4882a593Smuzhiyun /*
430*4882a593Smuzhiyun * when a cluster is allocated from a block group, we put the
431*4882a593Smuzhiyun * cluster onto a list in the block group so that it can
432*4882a593Smuzhiyun * be freed before the block group is freed.
433*4882a593Smuzhiyun */
434*4882a593Smuzhiyun struct list_head block_group_list;
435*4882a593Smuzhiyun };
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun enum btrfs_caching_type {
438*4882a593Smuzhiyun BTRFS_CACHE_NO,
439*4882a593Smuzhiyun BTRFS_CACHE_STARTED,
440*4882a593Smuzhiyun BTRFS_CACHE_FAST,
441*4882a593Smuzhiyun BTRFS_CACHE_FINISHED,
442*4882a593Smuzhiyun BTRFS_CACHE_ERROR,
443*4882a593Smuzhiyun };
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /*
446*4882a593Smuzhiyun * Tree to record all locked full stripes of a RAID5/6 block group
447*4882a593Smuzhiyun */
448*4882a593Smuzhiyun struct btrfs_full_stripe_locks_tree {
449*4882a593Smuzhiyun struct rb_root root;
450*4882a593Smuzhiyun struct mutex lock;
451*4882a593Smuzhiyun };
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun /* Discard control. */
454*4882a593Smuzhiyun /*
455*4882a593Smuzhiyun * Async discard uses multiple lists to differentiate the discard filter
456*4882a593Smuzhiyun * parameters. Index 0 is for completely free block groups where we need to
457*4882a593Smuzhiyun * ensure the entire block group is trimmed without being lossy. Indices
458*4882a593Smuzhiyun * afterwards represent monotonically decreasing discard filter sizes to
459*4882a593Smuzhiyun * prioritize what should be discarded next.
460*4882a593Smuzhiyun */
461*4882a593Smuzhiyun #define BTRFS_NR_DISCARD_LISTS 3
462*4882a593Smuzhiyun #define BTRFS_DISCARD_INDEX_UNUSED 0
463*4882a593Smuzhiyun #define BTRFS_DISCARD_INDEX_START 1
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun struct btrfs_discard_ctl {
466*4882a593Smuzhiyun struct workqueue_struct *discard_workers;
467*4882a593Smuzhiyun struct delayed_work work;
468*4882a593Smuzhiyun spinlock_t lock;
469*4882a593Smuzhiyun struct btrfs_block_group *block_group;
470*4882a593Smuzhiyun struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
471*4882a593Smuzhiyun u64 prev_discard;
472*4882a593Smuzhiyun atomic_t discardable_extents;
473*4882a593Smuzhiyun atomic64_t discardable_bytes;
474*4882a593Smuzhiyun u64 max_discard_size;
475*4882a593Smuzhiyun unsigned long delay;
476*4882a593Smuzhiyun u32 iops_limit;
477*4882a593Smuzhiyun u32 kbps_limit;
478*4882a593Smuzhiyun u64 discard_extent_bytes;
479*4882a593Smuzhiyun u64 discard_bitmap_bytes;
480*4882a593Smuzhiyun atomic64_t discard_bytes_saved;
481*4882a593Smuzhiyun };
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun /* delayed seq elem */
484*4882a593Smuzhiyun struct seq_list {
485*4882a593Smuzhiyun struct list_head list;
486*4882a593Smuzhiyun u64 seq;
487*4882a593Smuzhiyun };
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun #define SEQ_LIST_INIT(name) { .list = LIST_HEAD_INIT((name).list), .seq = 0 }
490*4882a593Smuzhiyun
491*4882a593Smuzhiyun #define SEQ_LAST ((u64)-1)
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun enum btrfs_orphan_cleanup_state {
494*4882a593Smuzhiyun ORPHAN_CLEANUP_STARTED = 1,
495*4882a593Smuzhiyun ORPHAN_CLEANUP_DONE = 2,
496*4882a593Smuzhiyun };
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun /* fs_info */
501*4882a593Smuzhiyun struct reloc_control;
502*4882a593Smuzhiyun struct btrfs_device;
503*4882a593Smuzhiyun struct btrfs_fs_devices;
504*4882a593Smuzhiyun struct btrfs_balance_control;
505*4882a593Smuzhiyun struct btrfs_delayed_root;
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun /*
508*4882a593Smuzhiyun * Block group or device which contains an active swapfile. Used for preventing
509*4882a593Smuzhiyun * unsafe operations while a swapfile is active.
510*4882a593Smuzhiyun *
511*4882a593Smuzhiyun * These are sorted on (ptr, inode) (note that a block group or device can
512*4882a593Smuzhiyun * contain more than one swapfile). We compare the pointer values because we
513*4882a593Smuzhiyun * don't actually care what the object is, we just need a quick check whether
514*4882a593Smuzhiyun * the object exists in the rbtree.
515*4882a593Smuzhiyun */
516*4882a593Smuzhiyun struct btrfs_swapfile_pin {
517*4882a593Smuzhiyun struct rb_node node;
518*4882a593Smuzhiyun void *ptr;
519*4882a593Smuzhiyun struct inode *inode;
520*4882a593Smuzhiyun /*
521*4882a593Smuzhiyun * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
522*4882a593Smuzhiyun * points to a struct btrfs_device.
523*4882a593Smuzhiyun */
524*4882a593Smuzhiyun bool is_block_group;
525*4882a593Smuzhiyun /*
526*4882a593Smuzhiyun * Only used when 'is_block_group' is true and it is the number of
527*4882a593Smuzhiyun * extents used by a swapfile for this block group ('ptr' field).
528*4882a593Smuzhiyun */
529*4882a593Smuzhiyun int bg_extent_count;
530*4882a593Smuzhiyun };
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun enum {
535*4882a593Smuzhiyun BTRFS_FS_BARRIER,
536*4882a593Smuzhiyun BTRFS_FS_CLOSING_START,
537*4882a593Smuzhiyun BTRFS_FS_CLOSING_DONE,
538*4882a593Smuzhiyun BTRFS_FS_LOG_RECOVERING,
539*4882a593Smuzhiyun BTRFS_FS_OPEN,
540*4882a593Smuzhiyun BTRFS_FS_QUOTA_ENABLED,
541*4882a593Smuzhiyun BTRFS_FS_UPDATE_UUID_TREE_GEN,
542*4882a593Smuzhiyun BTRFS_FS_CREATING_FREE_SPACE_TREE,
543*4882a593Smuzhiyun BTRFS_FS_BTREE_ERR,
544*4882a593Smuzhiyun BTRFS_FS_LOG1_ERR,
545*4882a593Smuzhiyun BTRFS_FS_LOG2_ERR,
546*4882a593Smuzhiyun BTRFS_FS_QUOTA_OVERRIDE,
547*4882a593Smuzhiyun /* Used to record internally whether fs has been frozen */
548*4882a593Smuzhiyun BTRFS_FS_FROZEN,
549*4882a593Smuzhiyun /*
550*4882a593Smuzhiyun * Indicate that balance has been set up from the ioctl and is in the
551*4882a593Smuzhiyun * main phase. The fs_info::balance_ctl is initialized.
552*4882a593Smuzhiyun * Set and cleared while holding fs_info::balance_mutex.
553*4882a593Smuzhiyun */
554*4882a593Smuzhiyun BTRFS_FS_BALANCE_RUNNING,
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun /* Indicate that the cleaner thread is awake and doing something. */
557*4882a593Smuzhiyun BTRFS_FS_CLEANER_RUNNING,
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun /*
560*4882a593Smuzhiyun * The checksumming has an optimized version and is considered fast,
561*4882a593Smuzhiyun * so we don't need to offload checksums to workqueues.
562*4882a593Smuzhiyun */
563*4882a593Smuzhiyun BTRFS_FS_CSUM_IMPL_FAST,
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun /* Indicate that the discard workqueue can service discards. */
566*4882a593Smuzhiyun BTRFS_FS_DISCARD_RUNNING,
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun /* Indicate that we can't trust the free space tree for caching yet */
569*4882a593Smuzhiyun BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
570*4882a593Smuzhiyun };
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun /*
573*4882a593Smuzhiyun * Exclusive operations (device replace, resize, device add/remove, balance)
574*4882a593Smuzhiyun */
575*4882a593Smuzhiyun enum btrfs_exclusive_operation {
576*4882a593Smuzhiyun BTRFS_EXCLOP_NONE,
577*4882a593Smuzhiyun BTRFS_EXCLOP_BALANCE,
578*4882a593Smuzhiyun BTRFS_EXCLOP_DEV_ADD,
579*4882a593Smuzhiyun BTRFS_EXCLOP_DEV_REMOVE,
580*4882a593Smuzhiyun BTRFS_EXCLOP_DEV_REPLACE,
581*4882a593Smuzhiyun BTRFS_EXCLOP_RESIZE,
582*4882a593Smuzhiyun BTRFS_EXCLOP_SWAP_ACTIVATE,
583*4882a593Smuzhiyun };
584*4882a593Smuzhiyun
585*4882a593Smuzhiyun struct btrfs_fs_info {
586*4882a593Smuzhiyun u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
587*4882a593Smuzhiyun unsigned long flags;
588*4882a593Smuzhiyun struct btrfs_root *extent_root;
589*4882a593Smuzhiyun struct btrfs_root *tree_root;
590*4882a593Smuzhiyun struct btrfs_root *chunk_root;
591*4882a593Smuzhiyun struct btrfs_root *dev_root;
592*4882a593Smuzhiyun struct btrfs_root *fs_root;
593*4882a593Smuzhiyun struct btrfs_root *csum_root;
594*4882a593Smuzhiyun struct btrfs_root *quota_root;
595*4882a593Smuzhiyun struct btrfs_root *uuid_root;
596*4882a593Smuzhiyun struct btrfs_root *free_space_root;
597*4882a593Smuzhiyun struct btrfs_root *data_reloc_root;
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun /* the log root tree is a directory of all the other log roots */
600*4882a593Smuzhiyun struct btrfs_root *log_root_tree;
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun spinlock_t fs_roots_radix_lock;
603*4882a593Smuzhiyun struct radix_tree_root fs_roots_radix;
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun /* block group cache stuff */
606*4882a593Smuzhiyun spinlock_t block_group_cache_lock;
607*4882a593Smuzhiyun u64 first_logical_byte;
608*4882a593Smuzhiyun struct rb_root block_group_cache_tree;
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun /* keep track of unallocated space */
611*4882a593Smuzhiyun atomic64_t free_chunk_space;
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun /* Track ranges which are used by log trees blocks/logged data extents */
614*4882a593Smuzhiyun struct extent_io_tree excluded_extents;
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun /* logical->physical extent mapping */
617*4882a593Smuzhiyun struct extent_map_tree mapping_tree;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun /*
620*4882a593Smuzhiyun * block reservation for extent, checksum, root tree and
621*4882a593Smuzhiyun * delayed dir index item
622*4882a593Smuzhiyun */
623*4882a593Smuzhiyun struct btrfs_block_rsv global_block_rsv;
624*4882a593Smuzhiyun /* block reservation for metadata operations */
625*4882a593Smuzhiyun struct btrfs_block_rsv trans_block_rsv;
626*4882a593Smuzhiyun /* block reservation for chunk tree */
627*4882a593Smuzhiyun struct btrfs_block_rsv chunk_block_rsv;
628*4882a593Smuzhiyun /* block reservation for delayed operations */
629*4882a593Smuzhiyun struct btrfs_block_rsv delayed_block_rsv;
630*4882a593Smuzhiyun /* block reservation for delayed refs */
631*4882a593Smuzhiyun struct btrfs_block_rsv delayed_refs_rsv;
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun struct btrfs_block_rsv empty_block_rsv;
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun u64 generation;
636*4882a593Smuzhiyun u64 last_trans_committed;
637*4882a593Smuzhiyun u64 avg_delayed_ref_runtime;
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun /*
640*4882a593Smuzhiyun * this is updated to the current trans every time a full commit
641*4882a593Smuzhiyun * is required instead of the faster short fsync log commits
642*4882a593Smuzhiyun */
643*4882a593Smuzhiyun u64 last_trans_log_full_commit;
644*4882a593Smuzhiyun unsigned long mount_opt;
645*4882a593Smuzhiyun /*
646*4882a593Smuzhiyun * Track requests for actions that need to be done during transaction
647*4882a593Smuzhiyun * commit (like for some mount options).
648*4882a593Smuzhiyun */
649*4882a593Smuzhiyun unsigned long pending_changes;
650*4882a593Smuzhiyun unsigned long compress_type:4;
651*4882a593Smuzhiyun unsigned int compress_level;
652*4882a593Smuzhiyun u32 commit_interval;
653*4882a593Smuzhiyun /*
654*4882a593Smuzhiyun * It is a suggestive number, the read side is safe even it gets a
655*4882a593Smuzhiyun * wrong number because we will write out the data into a regular
656*4882a593Smuzhiyun * extent. The write side(mount/remount) is under ->s_umount lock,
657*4882a593Smuzhiyun * so it is also safe.
658*4882a593Smuzhiyun */
659*4882a593Smuzhiyun u64 max_inline;
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun struct btrfs_transaction *running_transaction;
662*4882a593Smuzhiyun wait_queue_head_t transaction_throttle;
663*4882a593Smuzhiyun wait_queue_head_t transaction_wait;
664*4882a593Smuzhiyun wait_queue_head_t transaction_blocked_wait;
665*4882a593Smuzhiyun wait_queue_head_t async_submit_wait;
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun /*
668*4882a593Smuzhiyun * Used to protect the incompat_flags, compat_flags, compat_ro_flags
669*4882a593Smuzhiyun * when they are updated.
670*4882a593Smuzhiyun *
671*4882a593Smuzhiyun * Because we do not clear the flags for ever, so we needn't use
672*4882a593Smuzhiyun * the lock on the read side.
673*4882a593Smuzhiyun *
674*4882a593Smuzhiyun * We also needn't use the lock when we mount the fs, because
675*4882a593Smuzhiyun * there is no other task which will update the flag.
676*4882a593Smuzhiyun */
677*4882a593Smuzhiyun spinlock_t super_lock;
678*4882a593Smuzhiyun struct btrfs_super_block *super_copy;
679*4882a593Smuzhiyun struct btrfs_super_block *super_for_commit;
680*4882a593Smuzhiyun struct super_block *sb;
681*4882a593Smuzhiyun struct inode *btree_inode;
682*4882a593Smuzhiyun struct mutex tree_log_mutex;
683*4882a593Smuzhiyun struct mutex transaction_kthread_mutex;
684*4882a593Smuzhiyun struct mutex cleaner_mutex;
685*4882a593Smuzhiyun struct mutex chunk_mutex;
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun /*
688*4882a593Smuzhiyun * this is taken to make sure we don't set block groups ro after
689*4882a593Smuzhiyun * the free space cache has been allocated on them
690*4882a593Smuzhiyun */
691*4882a593Smuzhiyun struct mutex ro_block_group_mutex;
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun /* this is used during read/modify/write to make sure
694*4882a593Smuzhiyun * no two ios are trying to mod the same stripe at the same
695*4882a593Smuzhiyun * time
696*4882a593Smuzhiyun */
697*4882a593Smuzhiyun struct btrfs_stripe_hash_table *stripe_hash_table;
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun /*
700*4882a593Smuzhiyun * this protects the ordered operations list only while we are
701*4882a593Smuzhiyun * processing all of the entries on it. This way we make
702*4882a593Smuzhiyun * sure the commit code doesn't find the list temporarily empty
703*4882a593Smuzhiyun * because another function happens to be doing non-waiting preflush
704*4882a593Smuzhiyun * before jumping into the main commit.
705*4882a593Smuzhiyun */
706*4882a593Smuzhiyun struct mutex ordered_operations_mutex;
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun struct rw_semaphore commit_root_sem;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun struct rw_semaphore cleanup_work_sem;
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun struct rw_semaphore subvol_sem;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun spinlock_t trans_lock;
715*4882a593Smuzhiyun /*
716*4882a593Smuzhiyun * the reloc mutex goes with the trans lock, it is taken
717*4882a593Smuzhiyun * during commit to protect us from the relocation code
718*4882a593Smuzhiyun */
719*4882a593Smuzhiyun struct mutex reloc_mutex;
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun struct list_head trans_list;
722*4882a593Smuzhiyun struct list_head dead_roots;
723*4882a593Smuzhiyun struct list_head caching_block_groups;
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun spinlock_t delayed_iput_lock;
726*4882a593Smuzhiyun struct list_head delayed_iputs;
727*4882a593Smuzhiyun atomic_t nr_delayed_iputs;
728*4882a593Smuzhiyun wait_queue_head_t delayed_iputs_wait;
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun atomic64_t tree_mod_seq;
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun /* this protects tree_mod_log and tree_mod_seq_list */
733*4882a593Smuzhiyun rwlock_t tree_mod_log_lock;
734*4882a593Smuzhiyun struct rb_root tree_mod_log;
735*4882a593Smuzhiyun struct list_head tree_mod_seq_list;
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun atomic_t async_delalloc_pages;
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun /*
740*4882a593Smuzhiyun * this is used to protect the following list -- ordered_roots.
741*4882a593Smuzhiyun */
742*4882a593Smuzhiyun spinlock_t ordered_root_lock;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun /*
745*4882a593Smuzhiyun * all fs/file tree roots in which there are data=ordered extents
746*4882a593Smuzhiyun * pending writeback are added into this list.
747*4882a593Smuzhiyun *
748*4882a593Smuzhiyun * these can span multiple transactions and basically include
749*4882a593Smuzhiyun * every dirty data page that isn't from nodatacow
750*4882a593Smuzhiyun */
751*4882a593Smuzhiyun struct list_head ordered_roots;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun struct mutex delalloc_root_mutex;
754*4882a593Smuzhiyun spinlock_t delalloc_root_lock;
755*4882a593Smuzhiyun /* all fs/file tree roots that have delalloc inodes. */
756*4882a593Smuzhiyun struct list_head delalloc_roots;
757*4882a593Smuzhiyun
758*4882a593Smuzhiyun /*
759*4882a593Smuzhiyun * there is a pool of worker threads for checksumming during writes
760*4882a593Smuzhiyun * and a pool for checksumming after reads. This is because readers
761*4882a593Smuzhiyun * can run with FS locks held, and the writers may be waiting for
762*4882a593Smuzhiyun * those locks. We don't want ordering in the pending list to cause
763*4882a593Smuzhiyun * deadlocks, and so the two are serviced separately.
764*4882a593Smuzhiyun *
765*4882a593Smuzhiyun * A third pool does submit_bio to avoid deadlocking with the other
766*4882a593Smuzhiyun * two
767*4882a593Smuzhiyun */
768*4882a593Smuzhiyun struct btrfs_workqueue *workers;
769*4882a593Smuzhiyun struct btrfs_workqueue *delalloc_workers;
770*4882a593Smuzhiyun struct btrfs_workqueue *flush_workers;
771*4882a593Smuzhiyun struct btrfs_workqueue *endio_workers;
772*4882a593Smuzhiyun struct btrfs_workqueue *endio_meta_workers;
773*4882a593Smuzhiyun struct btrfs_workqueue *endio_raid56_workers;
774*4882a593Smuzhiyun struct btrfs_workqueue *rmw_workers;
775*4882a593Smuzhiyun struct btrfs_workqueue *endio_meta_write_workers;
776*4882a593Smuzhiyun struct btrfs_workqueue *endio_write_workers;
777*4882a593Smuzhiyun struct btrfs_workqueue *endio_freespace_worker;
778*4882a593Smuzhiyun struct btrfs_workqueue *caching_workers;
779*4882a593Smuzhiyun struct btrfs_workqueue *readahead_workers;
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun /*
782*4882a593Smuzhiyun * fixup workers take dirty pages that didn't properly go through
783*4882a593Smuzhiyun * the cow mechanism and make them safe to write. It happens
784*4882a593Smuzhiyun * for the sys_munmap function call path
785*4882a593Smuzhiyun */
786*4882a593Smuzhiyun struct btrfs_workqueue *fixup_workers;
787*4882a593Smuzhiyun struct btrfs_workqueue *delayed_workers;
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun struct task_struct *transaction_kthread;
790*4882a593Smuzhiyun struct task_struct *cleaner_kthread;
791*4882a593Smuzhiyun u32 thread_pool_size;
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun struct kobject *space_info_kobj;
794*4882a593Smuzhiyun struct kobject *qgroups_kobj;
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun u64 total_pinned;
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun /* used to keep from writing metadata until there is a nice batch */
799*4882a593Smuzhiyun struct percpu_counter dirty_metadata_bytes;
800*4882a593Smuzhiyun struct percpu_counter delalloc_bytes;
801*4882a593Smuzhiyun struct percpu_counter dio_bytes;
802*4882a593Smuzhiyun s32 dirty_metadata_batch;
803*4882a593Smuzhiyun s32 delalloc_batch;
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun struct list_head dirty_cowonly_roots;
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun struct btrfs_fs_devices *fs_devices;
808*4882a593Smuzhiyun
809*4882a593Smuzhiyun /*
810*4882a593Smuzhiyun * The space_info list is effectively read only after initial
811*4882a593Smuzhiyun * setup. It is populated at mount time and cleaned up after
812*4882a593Smuzhiyun * all block groups are removed. RCU is used to protect it.
813*4882a593Smuzhiyun */
814*4882a593Smuzhiyun struct list_head space_info;
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun struct btrfs_space_info *data_sinfo;
817*4882a593Smuzhiyun
818*4882a593Smuzhiyun struct reloc_control *reloc_ctl;
819*4882a593Smuzhiyun
820*4882a593Smuzhiyun /* data_alloc_cluster is only used in ssd_spread mode */
821*4882a593Smuzhiyun struct btrfs_free_cluster data_alloc_cluster;
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun /* all metadata allocations go through this cluster */
824*4882a593Smuzhiyun struct btrfs_free_cluster meta_alloc_cluster;
825*4882a593Smuzhiyun
826*4882a593Smuzhiyun /* auto defrag inodes go here */
827*4882a593Smuzhiyun spinlock_t defrag_inodes_lock;
828*4882a593Smuzhiyun struct rb_root defrag_inodes;
829*4882a593Smuzhiyun atomic_t defrag_running;
830*4882a593Smuzhiyun
831*4882a593Smuzhiyun /* Used to protect avail_{data, metadata, system}_alloc_bits */
832*4882a593Smuzhiyun seqlock_t profiles_lock;
833*4882a593Smuzhiyun /*
834*4882a593Smuzhiyun * these three are in extended format (availability of single
835*4882a593Smuzhiyun * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other
836*4882a593Smuzhiyun * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits)
837*4882a593Smuzhiyun */
838*4882a593Smuzhiyun u64 avail_data_alloc_bits;
839*4882a593Smuzhiyun u64 avail_metadata_alloc_bits;
840*4882a593Smuzhiyun u64 avail_system_alloc_bits;
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun /* restriper state */
843*4882a593Smuzhiyun spinlock_t balance_lock;
844*4882a593Smuzhiyun struct mutex balance_mutex;
845*4882a593Smuzhiyun atomic_t balance_pause_req;
846*4882a593Smuzhiyun atomic_t balance_cancel_req;
847*4882a593Smuzhiyun struct btrfs_balance_control *balance_ctl;
848*4882a593Smuzhiyun wait_queue_head_t balance_wait_q;
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun u32 data_chunk_allocations;
851*4882a593Smuzhiyun u32 metadata_ratio;
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun void *bdev_holder;
854*4882a593Smuzhiyun
855*4882a593Smuzhiyun /* private scrub information */
856*4882a593Smuzhiyun struct mutex scrub_lock;
857*4882a593Smuzhiyun atomic_t scrubs_running;
858*4882a593Smuzhiyun atomic_t scrub_pause_req;
859*4882a593Smuzhiyun atomic_t scrubs_paused;
860*4882a593Smuzhiyun atomic_t scrub_cancel_req;
861*4882a593Smuzhiyun wait_queue_head_t scrub_pause_wait;
862*4882a593Smuzhiyun /*
863*4882a593Smuzhiyun * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
864*4882a593Smuzhiyun * running.
865*4882a593Smuzhiyun */
866*4882a593Smuzhiyun refcount_t scrub_workers_refcnt;
867*4882a593Smuzhiyun struct btrfs_workqueue *scrub_workers;
868*4882a593Smuzhiyun struct btrfs_workqueue *scrub_wr_completion_workers;
869*4882a593Smuzhiyun struct btrfs_workqueue *scrub_parity_workers;
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun struct btrfs_discard_ctl discard_ctl;
872*4882a593Smuzhiyun
873*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
874*4882a593Smuzhiyun u32 check_integrity_print_mask;
875*4882a593Smuzhiyun #endif
876*4882a593Smuzhiyun /* is qgroup tracking in a consistent state? */
877*4882a593Smuzhiyun u64 qgroup_flags;
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun /* holds configuration and tracking. Protected by qgroup_lock */
880*4882a593Smuzhiyun struct rb_root qgroup_tree;
881*4882a593Smuzhiyun spinlock_t qgroup_lock;
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun /*
884*4882a593Smuzhiyun * used to avoid frequently calling ulist_alloc()/ulist_free()
885*4882a593Smuzhiyun * when doing qgroup accounting, it must be protected by qgroup_lock.
886*4882a593Smuzhiyun */
887*4882a593Smuzhiyun struct ulist *qgroup_ulist;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun /*
890*4882a593Smuzhiyun * Protect user change for quota operations. If a transaction is needed,
891*4882a593Smuzhiyun * it must be started before locking this lock.
892*4882a593Smuzhiyun */
893*4882a593Smuzhiyun struct mutex qgroup_ioctl_lock;
894*4882a593Smuzhiyun
895*4882a593Smuzhiyun /* list of dirty qgroups to be written at next commit */
896*4882a593Smuzhiyun struct list_head dirty_qgroups;
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun /* used by qgroup for an efficient tree traversal */
899*4882a593Smuzhiyun u64 qgroup_seq;
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun /* qgroup rescan items */
902*4882a593Smuzhiyun struct mutex qgroup_rescan_lock; /* protects the progress item */
903*4882a593Smuzhiyun struct btrfs_key qgroup_rescan_progress;
904*4882a593Smuzhiyun struct btrfs_workqueue *qgroup_rescan_workers;
905*4882a593Smuzhiyun struct completion qgroup_rescan_completion;
906*4882a593Smuzhiyun struct btrfs_work qgroup_rescan_work;
907*4882a593Smuzhiyun bool qgroup_rescan_running; /* protected by qgroup_rescan_lock */
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun /* filesystem state */
910*4882a593Smuzhiyun unsigned long fs_state;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun struct btrfs_delayed_root *delayed_root;
913*4882a593Smuzhiyun
914*4882a593Smuzhiyun /* readahead tree */
915*4882a593Smuzhiyun spinlock_t reada_lock;
916*4882a593Smuzhiyun struct radix_tree_root reada_tree;
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun /* readahead works cnt */
919*4882a593Smuzhiyun atomic_t reada_works_cnt;
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun /* Extent buffer radix tree */
922*4882a593Smuzhiyun spinlock_t buffer_lock;
923*4882a593Smuzhiyun struct radix_tree_root buffer_radix;
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun /* next backup root to be overwritten */
926*4882a593Smuzhiyun int backup_root_index;
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* device replace state */
929*4882a593Smuzhiyun struct btrfs_dev_replace dev_replace;
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun struct semaphore uuid_tree_rescan_sem;
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun /* Used to reclaim the metadata space in the background. */
934*4882a593Smuzhiyun struct work_struct async_reclaim_work;
935*4882a593Smuzhiyun struct work_struct async_data_reclaim_work;
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun spinlock_t unused_bgs_lock;
938*4882a593Smuzhiyun struct list_head unused_bgs;
939*4882a593Smuzhiyun struct mutex unused_bg_unpin_mutex;
940*4882a593Smuzhiyun struct mutex delete_unused_bgs_mutex;
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun /* Cached block sizes */
943*4882a593Smuzhiyun u32 nodesize;
944*4882a593Smuzhiyun u32 sectorsize;
945*4882a593Smuzhiyun u32 stripesize;
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun /* Block groups and devices containing active swapfiles. */
948*4882a593Smuzhiyun spinlock_t swapfile_pins_lock;
949*4882a593Smuzhiyun struct rb_root swapfile_pins;
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun struct crypto_shash *csum_shash;
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /*
954*4882a593Smuzhiyun * Number of send operations in progress.
955*4882a593Smuzhiyun * Updated while holding fs_info::balance_mutex.
956*4882a593Smuzhiyun */
957*4882a593Smuzhiyun int send_in_progress;
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun /* Type of exclusive operation running */
960*4882a593Smuzhiyun unsigned long exclusive_operation;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_FS_REF_VERIFY
963*4882a593Smuzhiyun spinlock_t ref_verify_lock;
964*4882a593Smuzhiyun struct rb_root block_tree;
965*4882a593Smuzhiyun #endif
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_DEBUG
968*4882a593Smuzhiyun struct kobject *debug_kobj;
969*4882a593Smuzhiyun struct kobject *discard_debug_kobj;
970*4882a593Smuzhiyun struct list_head allocated_roots;
971*4882a593Smuzhiyun
972*4882a593Smuzhiyun spinlock_t eb_leak_lock;
973*4882a593Smuzhiyun struct list_head allocated_ebs;
974*4882a593Smuzhiyun #endif
975*4882a593Smuzhiyun };
976*4882a593Smuzhiyun
btrfs_sb(struct super_block * sb)977*4882a593Smuzhiyun static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
978*4882a593Smuzhiyun {
979*4882a593Smuzhiyun return sb->s_fs_info;
980*4882a593Smuzhiyun }
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun /*
983*4882a593Smuzhiyun * The state of btrfs root
984*4882a593Smuzhiyun */
985*4882a593Smuzhiyun enum {
986*4882a593Smuzhiyun /*
987*4882a593Smuzhiyun * btrfs_record_root_in_trans is a multi-step process, and it can race
988*4882a593Smuzhiyun * with the balancing code. But the race is very small, and only the
989*4882a593Smuzhiyun * first time the root is added to each transaction. So IN_TRANS_SETUP
990*4882a593Smuzhiyun * is used to tell us when more checks are required
991*4882a593Smuzhiyun */
992*4882a593Smuzhiyun BTRFS_ROOT_IN_TRANS_SETUP,
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun /*
995*4882a593Smuzhiyun * Set if tree blocks of this root can be shared by other roots.
996*4882a593Smuzhiyun * Only subvolume trees and their reloc trees have this bit set.
997*4882a593Smuzhiyun * Conflicts with TRACK_DIRTY bit.
998*4882a593Smuzhiyun *
999*4882a593Smuzhiyun * This affects two things:
1000*4882a593Smuzhiyun *
1001*4882a593Smuzhiyun * - How balance works
1002*4882a593Smuzhiyun * For shareable roots, we need to use reloc tree and do path
1003*4882a593Smuzhiyun * replacement for balance, and need various pre/post hooks for
1004*4882a593Smuzhiyun * snapshot creation to handle them.
1005*4882a593Smuzhiyun *
1006*4882a593Smuzhiyun * While for non-shareable trees, we just simply do a tree search
1007*4882a593Smuzhiyun * with COW.
1008*4882a593Smuzhiyun *
1009*4882a593Smuzhiyun * - How dirty roots are tracked
1010*4882a593Smuzhiyun * For shareable roots, btrfs_record_root_in_trans() is needed to
1011*4882a593Smuzhiyun * track them, while non-subvolume roots have TRACK_DIRTY bit, they
1012*4882a593Smuzhiyun * don't need to set this manually.
1013*4882a593Smuzhiyun */
1014*4882a593Smuzhiyun BTRFS_ROOT_SHAREABLE,
1015*4882a593Smuzhiyun BTRFS_ROOT_TRACK_DIRTY,
1016*4882a593Smuzhiyun BTRFS_ROOT_IN_RADIX,
1017*4882a593Smuzhiyun BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
1018*4882a593Smuzhiyun BTRFS_ROOT_DEFRAG_RUNNING,
1019*4882a593Smuzhiyun BTRFS_ROOT_FORCE_COW,
1020*4882a593Smuzhiyun BTRFS_ROOT_MULTI_LOG_TASKS,
1021*4882a593Smuzhiyun BTRFS_ROOT_DIRTY,
1022*4882a593Smuzhiyun BTRFS_ROOT_DELETING,
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun /*
1025*4882a593Smuzhiyun * Reloc tree is orphan, only kept here for qgroup delayed subtree scan
1026*4882a593Smuzhiyun *
1027*4882a593Smuzhiyun * Set for the subvolume tree owning the reloc tree.
1028*4882a593Smuzhiyun */
1029*4882a593Smuzhiyun BTRFS_ROOT_DEAD_RELOC_TREE,
1030*4882a593Smuzhiyun /* Mark dead root stored on device whose cleanup needs to be resumed */
1031*4882a593Smuzhiyun BTRFS_ROOT_DEAD_TREE,
1032*4882a593Smuzhiyun /* The root has a log tree. Used only for subvolume roots. */
1033*4882a593Smuzhiyun BTRFS_ROOT_HAS_LOG_TREE,
1034*4882a593Smuzhiyun /* Qgroup flushing is in progress */
1035*4882a593Smuzhiyun BTRFS_ROOT_QGROUP_FLUSHING,
1036*4882a593Smuzhiyun };
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun /*
1039*4882a593Smuzhiyun * Record swapped tree blocks of a subvolume tree for delayed subtree trace
1040*4882a593Smuzhiyun * code. For detail check comment in fs/btrfs/qgroup.c.
1041*4882a593Smuzhiyun */
1042*4882a593Smuzhiyun struct btrfs_qgroup_swapped_blocks {
1043*4882a593Smuzhiyun spinlock_t lock;
1044*4882a593Smuzhiyun /* RM_EMPTY_ROOT() of above blocks[] */
1045*4882a593Smuzhiyun bool swapped;
1046*4882a593Smuzhiyun struct rb_root blocks[BTRFS_MAX_LEVEL];
1047*4882a593Smuzhiyun };
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun /*
1050*4882a593Smuzhiyun * in ram representation of the tree. extent_root is used for all allocations
1051*4882a593Smuzhiyun * and for the extent tree extent_root root.
1052*4882a593Smuzhiyun */
1053*4882a593Smuzhiyun struct btrfs_root {
1054*4882a593Smuzhiyun struct extent_buffer *node;
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun struct extent_buffer *commit_root;
1057*4882a593Smuzhiyun struct btrfs_root *log_root;
1058*4882a593Smuzhiyun struct btrfs_root *reloc_root;
1059*4882a593Smuzhiyun
1060*4882a593Smuzhiyun unsigned long state;
1061*4882a593Smuzhiyun struct btrfs_root_item root_item;
1062*4882a593Smuzhiyun struct btrfs_key root_key;
1063*4882a593Smuzhiyun struct btrfs_fs_info *fs_info;
1064*4882a593Smuzhiyun struct extent_io_tree dirty_log_pages;
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun struct mutex objectid_mutex;
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun spinlock_t accounting_lock;
1069*4882a593Smuzhiyun struct btrfs_block_rsv *block_rsv;
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun /* free ino cache stuff */
1072*4882a593Smuzhiyun struct btrfs_free_space_ctl *free_ino_ctl;
1073*4882a593Smuzhiyun enum btrfs_caching_type ino_cache_state;
1074*4882a593Smuzhiyun spinlock_t ino_cache_lock;
1075*4882a593Smuzhiyun wait_queue_head_t ino_cache_wait;
1076*4882a593Smuzhiyun struct btrfs_free_space_ctl *free_ino_pinned;
1077*4882a593Smuzhiyun u64 ino_cache_progress;
1078*4882a593Smuzhiyun struct inode *ino_cache_inode;
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun struct mutex log_mutex;
1081*4882a593Smuzhiyun wait_queue_head_t log_writer_wait;
1082*4882a593Smuzhiyun wait_queue_head_t log_commit_wait[2];
1083*4882a593Smuzhiyun struct list_head log_ctxs[2];
1084*4882a593Smuzhiyun /* Used only for log trees of subvolumes, not for the log root tree */
1085*4882a593Smuzhiyun atomic_t log_writers;
1086*4882a593Smuzhiyun atomic_t log_commit[2];
1087*4882a593Smuzhiyun /* Used only for log trees of subvolumes, not for the log root tree */
1088*4882a593Smuzhiyun atomic_t log_batch;
1089*4882a593Smuzhiyun int log_transid;
1090*4882a593Smuzhiyun /* No matter the commit succeeds or not*/
1091*4882a593Smuzhiyun int log_transid_committed;
1092*4882a593Smuzhiyun /* Just be updated when the commit succeeds. */
1093*4882a593Smuzhiyun int last_log_commit;
1094*4882a593Smuzhiyun pid_t log_start_pid;
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun u64 last_trans;
1097*4882a593Smuzhiyun
1098*4882a593Smuzhiyun u32 type;
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun u64 highest_objectid;
1101*4882a593Smuzhiyun
1102*4882a593Smuzhiyun struct btrfs_key defrag_progress;
1103*4882a593Smuzhiyun struct btrfs_key defrag_max;
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun /* The dirty list is only used by non-shareable roots */
1106*4882a593Smuzhiyun struct list_head dirty_list;
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun struct list_head root_list;
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun spinlock_t log_extents_lock[2];
1111*4882a593Smuzhiyun struct list_head logged_list[2];
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun int orphan_cleanup_state;
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun spinlock_t inode_lock;
1116*4882a593Smuzhiyun /* red-black tree that keeps track of in-memory inodes */
1117*4882a593Smuzhiyun struct rb_root inode_tree;
1118*4882a593Smuzhiyun
1119*4882a593Smuzhiyun /*
1120*4882a593Smuzhiyun * radix tree that keeps track of delayed nodes of every inode,
1121*4882a593Smuzhiyun * protected by inode_lock
1122*4882a593Smuzhiyun */
1123*4882a593Smuzhiyun struct radix_tree_root delayed_nodes_tree;
1124*4882a593Smuzhiyun /*
1125*4882a593Smuzhiyun * right now this just gets used so that a root has its own devid
1126*4882a593Smuzhiyun * for stat. It may be used for more later
1127*4882a593Smuzhiyun */
1128*4882a593Smuzhiyun dev_t anon_dev;
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun spinlock_t root_item_lock;
1131*4882a593Smuzhiyun refcount_t refs;
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun struct mutex delalloc_mutex;
1134*4882a593Smuzhiyun spinlock_t delalloc_lock;
1135*4882a593Smuzhiyun /*
1136*4882a593Smuzhiyun * all of the inodes that have delalloc bytes. It is possible for
1137*4882a593Smuzhiyun * this list to be empty even when there is still dirty data=ordered
1138*4882a593Smuzhiyun * extents waiting to finish IO.
1139*4882a593Smuzhiyun */
1140*4882a593Smuzhiyun struct list_head delalloc_inodes;
1141*4882a593Smuzhiyun struct list_head delalloc_root;
1142*4882a593Smuzhiyun u64 nr_delalloc_inodes;
1143*4882a593Smuzhiyun
1144*4882a593Smuzhiyun struct mutex ordered_extent_mutex;
1145*4882a593Smuzhiyun /*
1146*4882a593Smuzhiyun * this is used by the balancing code to wait for all the pending
1147*4882a593Smuzhiyun * ordered extents
1148*4882a593Smuzhiyun */
1149*4882a593Smuzhiyun spinlock_t ordered_extent_lock;
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun /*
1152*4882a593Smuzhiyun * all of the data=ordered extents pending writeback
1153*4882a593Smuzhiyun * these can span multiple transactions and basically include
1154*4882a593Smuzhiyun * every dirty data page that isn't from nodatacow
1155*4882a593Smuzhiyun */
1156*4882a593Smuzhiyun struct list_head ordered_extents;
1157*4882a593Smuzhiyun struct list_head ordered_root;
1158*4882a593Smuzhiyun u64 nr_ordered_extents;
1159*4882a593Smuzhiyun
1160*4882a593Smuzhiyun /*
1161*4882a593Smuzhiyun * Not empty if this subvolume root has gone through tree block swap
1162*4882a593Smuzhiyun * (relocation)
1163*4882a593Smuzhiyun *
1164*4882a593Smuzhiyun * Will be used by reloc_control::dirty_subvol_roots.
1165*4882a593Smuzhiyun */
1166*4882a593Smuzhiyun struct list_head reloc_dirty_list;
1167*4882a593Smuzhiyun
1168*4882a593Smuzhiyun /*
1169*4882a593Smuzhiyun * Number of currently running SEND ioctls to prevent
1170*4882a593Smuzhiyun * manipulation with the read-only status via SUBVOL_SETFLAGS
1171*4882a593Smuzhiyun */
1172*4882a593Smuzhiyun int send_in_progress;
1173*4882a593Smuzhiyun /*
1174*4882a593Smuzhiyun * Number of currently running deduplication operations that have a
1175*4882a593Smuzhiyun * destination inode belonging to this root. Protected by the lock
1176*4882a593Smuzhiyun * root_item_lock.
1177*4882a593Smuzhiyun */
1178*4882a593Smuzhiyun int dedupe_in_progress;
1179*4882a593Smuzhiyun /* For exclusion of snapshot creation and nocow writes */
1180*4882a593Smuzhiyun struct btrfs_drew_lock snapshot_lock;
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun atomic_t snapshot_force_cow;
1183*4882a593Smuzhiyun
1184*4882a593Smuzhiyun /* For qgroup metadata reserved space */
1185*4882a593Smuzhiyun spinlock_t qgroup_meta_rsv_lock;
1186*4882a593Smuzhiyun u64 qgroup_meta_rsv_pertrans;
1187*4882a593Smuzhiyun u64 qgroup_meta_rsv_prealloc;
1188*4882a593Smuzhiyun wait_queue_head_t qgroup_flush_wait;
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun /* Number of active swapfiles */
1191*4882a593Smuzhiyun atomic_t nr_swapfiles;
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun /* Record pairs of swapped blocks for qgroup */
1194*4882a593Smuzhiyun struct btrfs_qgroup_swapped_blocks swapped_blocks;
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun /* Used only by log trees, when logging csum items */
1197*4882a593Smuzhiyun struct extent_io_tree log_csum_range;
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1200*4882a593Smuzhiyun u64 alloc_bytenr;
1201*4882a593Smuzhiyun #endif
1202*4882a593Smuzhiyun
1203*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_DEBUG
1204*4882a593Smuzhiyun struct list_head leak_list;
1205*4882a593Smuzhiyun #endif
1206*4882a593Smuzhiyun };
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun /*
1209*4882a593Smuzhiyun * Structure that conveys information about an extent that is going to replace
1210*4882a593Smuzhiyun * all the extents in a file range.
1211*4882a593Smuzhiyun */
1212*4882a593Smuzhiyun struct btrfs_replace_extent_info {
1213*4882a593Smuzhiyun u64 disk_offset;
1214*4882a593Smuzhiyun u64 disk_len;
1215*4882a593Smuzhiyun u64 data_offset;
1216*4882a593Smuzhiyun u64 data_len;
1217*4882a593Smuzhiyun u64 file_offset;
1218*4882a593Smuzhiyun /* Pointer to a file extent item of type regular or prealloc. */
1219*4882a593Smuzhiyun char *extent_buf;
1220*4882a593Smuzhiyun /*
1221*4882a593Smuzhiyun * Set to true when attempting to replace a file range with a new extent
1222*4882a593Smuzhiyun * described by this structure, set to false when attempting to clone an
1223*4882a593Smuzhiyun * existing extent into a file range.
1224*4882a593Smuzhiyun */
1225*4882a593Smuzhiyun bool is_new_extent;
1226*4882a593Smuzhiyun /* Meaningful only if is_new_extent is true. */
1227*4882a593Smuzhiyun int qgroup_reserved;
1228*4882a593Smuzhiyun /*
1229*4882a593Smuzhiyun * Meaningful only if is_new_extent is true.
1230*4882a593Smuzhiyun * Used to track how many extent items we have already inserted in a
1231*4882a593Smuzhiyun * subvolume tree that refer to the extent described by this structure,
1232*4882a593Smuzhiyun * so that we know when to create a new delayed ref or update an existing
1233*4882a593Smuzhiyun * one.
1234*4882a593Smuzhiyun */
1235*4882a593Smuzhiyun int insertions;
1236*4882a593Smuzhiyun };
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun struct btrfs_file_private {
1239*4882a593Smuzhiyun void *filldir_buf;
1240*4882a593Smuzhiyun };
1241*4882a593Smuzhiyun
1242*4882a593Smuzhiyun
BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info * info)1243*4882a593Smuzhiyun static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
1244*4882a593Smuzhiyun {
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun return info->nodesize - sizeof(struct btrfs_header);
1247*4882a593Smuzhiyun }
1248*4882a593Smuzhiyun
1249*4882a593Smuzhiyun #define BTRFS_LEAF_DATA_OFFSET offsetof(struct btrfs_leaf, items)
1250*4882a593Smuzhiyun
BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info * info)1251*4882a593Smuzhiyun static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info)
1252*4882a593Smuzhiyun {
1253*4882a593Smuzhiyun return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item);
1254*4882a593Smuzhiyun }
1255*4882a593Smuzhiyun
BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info * info)1256*4882a593Smuzhiyun static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info)
1257*4882a593Smuzhiyun {
1258*4882a593Smuzhiyun return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr);
1259*4882a593Smuzhiyun }
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun #define BTRFS_FILE_EXTENT_INLINE_DATA_START \
1262*4882a593Smuzhiyun (offsetof(struct btrfs_file_extent_item, disk_bytenr))
BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info * info)1263*4882a593Smuzhiyun static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
1264*4882a593Smuzhiyun {
1265*4882a593Smuzhiyun return BTRFS_MAX_ITEM_SIZE(info) -
1266*4882a593Smuzhiyun BTRFS_FILE_EXTENT_INLINE_DATA_START;
1267*4882a593Smuzhiyun }
1268*4882a593Smuzhiyun
BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info * info)1269*4882a593Smuzhiyun static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
1270*4882a593Smuzhiyun {
1271*4882a593Smuzhiyun return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
1272*4882a593Smuzhiyun }
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun /*
1275*4882a593Smuzhiyun * Flags for mount options.
1276*4882a593Smuzhiyun *
1277*4882a593Smuzhiyun * Note: don't forget to add new options to btrfs_show_options()
1278*4882a593Smuzhiyun */
1279*4882a593Smuzhiyun #define BTRFS_MOUNT_NODATASUM (1 << 0)
1280*4882a593Smuzhiyun #define BTRFS_MOUNT_NODATACOW (1 << 1)
1281*4882a593Smuzhiyun #define BTRFS_MOUNT_NOBARRIER (1 << 2)
1282*4882a593Smuzhiyun #define BTRFS_MOUNT_SSD (1 << 3)
1283*4882a593Smuzhiyun #define BTRFS_MOUNT_DEGRADED (1 << 4)
1284*4882a593Smuzhiyun #define BTRFS_MOUNT_COMPRESS (1 << 5)
1285*4882a593Smuzhiyun #define BTRFS_MOUNT_NOTREELOG (1 << 6)
1286*4882a593Smuzhiyun #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7)
1287*4882a593Smuzhiyun #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
1288*4882a593Smuzhiyun #define BTRFS_MOUNT_NOSSD (1 << 9)
1289*4882a593Smuzhiyun #define BTRFS_MOUNT_DISCARD_SYNC (1 << 10)
1290*4882a593Smuzhiyun #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
1291*4882a593Smuzhiyun #define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
1292*4882a593Smuzhiyun #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
1293*4882a593Smuzhiyun #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
1294*4882a593Smuzhiyun #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15)
1295*4882a593Smuzhiyun #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16)
1296*4882a593Smuzhiyun #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17)
1297*4882a593Smuzhiyun #define BTRFS_MOUNT_USEBACKUPROOT (1 << 18)
1298*4882a593Smuzhiyun #define BTRFS_MOUNT_SKIP_BALANCE (1 << 19)
1299*4882a593Smuzhiyun #define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20)
1300*4882a593Smuzhiyun #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1301*4882a593Smuzhiyun #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
1302*4882a593Smuzhiyun #define BTRFS_MOUNT_RESCAN_UUID_TREE (1 << 23)
1303*4882a593Smuzhiyun #define BTRFS_MOUNT_FRAGMENT_DATA (1 << 24)
1304*4882a593Smuzhiyun #define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25)
1305*4882a593Smuzhiyun #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)
1306*4882a593Smuzhiyun #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)
1307*4882a593Smuzhiyun #define BTRFS_MOUNT_REF_VERIFY (1 << 28)
1308*4882a593Smuzhiyun #define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29)
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
1311*4882a593Smuzhiyun #define BTRFS_DEFAULT_MAX_INLINE (2048)
1312*4882a593Smuzhiyun
1313*4882a593Smuzhiyun #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1314*4882a593Smuzhiyun #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1315*4882a593Smuzhiyun #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1316*4882a593Smuzhiyun #define btrfs_test_opt(fs_info, opt) ((fs_info)->mount_opt & \
1317*4882a593Smuzhiyun BTRFS_MOUNT_##opt)
1318*4882a593Smuzhiyun
1319*4882a593Smuzhiyun #define btrfs_set_and_info(fs_info, opt, fmt, args...) \
1320*4882a593Smuzhiyun do { \
1321*4882a593Smuzhiyun if (!btrfs_test_opt(fs_info, opt)) \
1322*4882a593Smuzhiyun btrfs_info(fs_info, fmt, ##args); \
1323*4882a593Smuzhiyun btrfs_set_opt(fs_info->mount_opt, opt); \
1324*4882a593Smuzhiyun } while (0)
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \
1327*4882a593Smuzhiyun do { \
1328*4882a593Smuzhiyun if (btrfs_test_opt(fs_info, opt)) \
1329*4882a593Smuzhiyun btrfs_info(fs_info, fmt, ##args); \
1330*4882a593Smuzhiyun btrfs_clear_opt(fs_info->mount_opt, opt); \
1331*4882a593Smuzhiyun } while (0)
1332*4882a593Smuzhiyun
1333*4882a593Smuzhiyun /*
1334*4882a593Smuzhiyun * Requests for changes that need to be done during transaction commit.
1335*4882a593Smuzhiyun *
1336*4882a593Smuzhiyun * Internal mount options that are used for special handling of the real
1337*4882a593Smuzhiyun * mount options (eg. cannot be set during remount and have to be set during
1338*4882a593Smuzhiyun * transaction commit)
1339*4882a593Smuzhiyun */
1340*4882a593Smuzhiyun
1341*4882a593Smuzhiyun #define BTRFS_PENDING_SET_INODE_MAP_CACHE (0)
1342*4882a593Smuzhiyun #define BTRFS_PENDING_CLEAR_INODE_MAP_CACHE (1)
1343*4882a593Smuzhiyun #define BTRFS_PENDING_COMMIT (2)
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun #define btrfs_test_pending(info, opt) \
1346*4882a593Smuzhiyun test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
1347*4882a593Smuzhiyun #define btrfs_set_pending(info, opt) \
1348*4882a593Smuzhiyun set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
1349*4882a593Smuzhiyun #define btrfs_clear_pending(info, opt) \
1350*4882a593Smuzhiyun clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
1351*4882a593Smuzhiyun
1352*4882a593Smuzhiyun /*
1353*4882a593Smuzhiyun * Helpers for setting pending mount option changes.
1354*4882a593Smuzhiyun *
1355*4882a593Smuzhiyun * Expects corresponding macros
1356*4882a593Smuzhiyun * BTRFS_PENDING_SET_ and CLEAR_ + short mount option name
1357*4882a593Smuzhiyun */
1358*4882a593Smuzhiyun #define btrfs_set_pending_and_info(info, opt, fmt, args...) \
1359*4882a593Smuzhiyun do { \
1360*4882a593Smuzhiyun if (!btrfs_raw_test_opt((info)->mount_opt, opt)) { \
1361*4882a593Smuzhiyun btrfs_info((info), fmt, ##args); \
1362*4882a593Smuzhiyun btrfs_set_pending((info), SET_##opt); \
1363*4882a593Smuzhiyun btrfs_clear_pending((info), CLEAR_##opt); \
1364*4882a593Smuzhiyun } \
1365*4882a593Smuzhiyun } while(0)
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun #define btrfs_clear_pending_and_info(info, opt, fmt, args...) \
1368*4882a593Smuzhiyun do { \
1369*4882a593Smuzhiyun if (btrfs_raw_test_opt((info)->mount_opt, opt)) { \
1370*4882a593Smuzhiyun btrfs_info((info), fmt, ##args); \
1371*4882a593Smuzhiyun btrfs_set_pending((info), CLEAR_##opt); \
1372*4882a593Smuzhiyun btrfs_clear_pending((info), SET_##opt); \
1373*4882a593Smuzhiyun } \
1374*4882a593Smuzhiyun } while(0)
1375*4882a593Smuzhiyun
1376*4882a593Smuzhiyun /*
1377*4882a593Smuzhiyun * Inode flags
1378*4882a593Smuzhiyun */
1379*4882a593Smuzhiyun #define BTRFS_INODE_NODATASUM (1 << 0)
1380*4882a593Smuzhiyun #define BTRFS_INODE_NODATACOW (1 << 1)
1381*4882a593Smuzhiyun #define BTRFS_INODE_READONLY (1 << 2)
1382*4882a593Smuzhiyun #define BTRFS_INODE_NOCOMPRESS (1 << 3)
1383*4882a593Smuzhiyun #define BTRFS_INODE_PREALLOC (1 << 4)
1384*4882a593Smuzhiyun #define BTRFS_INODE_SYNC (1 << 5)
1385*4882a593Smuzhiyun #define BTRFS_INODE_IMMUTABLE (1 << 6)
1386*4882a593Smuzhiyun #define BTRFS_INODE_APPEND (1 << 7)
1387*4882a593Smuzhiyun #define BTRFS_INODE_NODUMP (1 << 8)
1388*4882a593Smuzhiyun #define BTRFS_INODE_NOATIME (1 << 9)
1389*4882a593Smuzhiyun #define BTRFS_INODE_DIRSYNC (1 << 10)
1390*4882a593Smuzhiyun #define BTRFS_INODE_COMPRESS (1 << 11)
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
1393*4882a593Smuzhiyun
1394*4882a593Smuzhiyun #define BTRFS_INODE_FLAG_MASK \
1395*4882a593Smuzhiyun (BTRFS_INODE_NODATASUM | \
1396*4882a593Smuzhiyun BTRFS_INODE_NODATACOW | \
1397*4882a593Smuzhiyun BTRFS_INODE_READONLY | \
1398*4882a593Smuzhiyun BTRFS_INODE_NOCOMPRESS | \
1399*4882a593Smuzhiyun BTRFS_INODE_PREALLOC | \
1400*4882a593Smuzhiyun BTRFS_INODE_SYNC | \
1401*4882a593Smuzhiyun BTRFS_INODE_IMMUTABLE | \
1402*4882a593Smuzhiyun BTRFS_INODE_APPEND | \
1403*4882a593Smuzhiyun BTRFS_INODE_NODUMP | \
1404*4882a593Smuzhiyun BTRFS_INODE_NOATIME | \
1405*4882a593Smuzhiyun BTRFS_INODE_DIRSYNC | \
1406*4882a593Smuzhiyun BTRFS_INODE_COMPRESS | \
1407*4882a593Smuzhiyun BTRFS_INODE_ROOT_ITEM_INIT)
1408*4882a593Smuzhiyun
1409*4882a593Smuzhiyun struct btrfs_map_token {
1410*4882a593Smuzhiyun struct extent_buffer *eb;
1411*4882a593Smuzhiyun char *kaddr;
1412*4882a593Smuzhiyun unsigned long offset;
1413*4882a593Smuzhiyun };
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
1416*4882a593Smuzhiyun ((bytes) >> (fs_info)->sb->s_blocksize_bits)
1417*4882a593Smuzhiyun
btrfs_init_map_token(struct btrfs_map_token * token,struct extent_buffer * eb)1418*4882a593Smuzhiyun static inline void btrfs_init_map_token(struct btrfs_map_token *token,
1419*4882a593Smuzhiyun struct extent_buffer *eb)
1420*4882a593Smuzhiyun {
1421*4882a593Smuzhiyun token->eb = eb;
1422*4882a593Smuzhiyun token->kaddr = page_address(eb->pages[0]);
1423*4882a593Smuzhiyun token->offset = 0;
1424*4882a593Smuzhiyun }
1425*4882a593Smuzhiyun
1426*4882a593Smuzhiyun /* some macros to generate set/get functions for the struct fields. This
1427*4882a593Smuzhiyun * assumes there is a lefoo_to_cpu for every type, so lets make a simple
1428*4882a593Smuzhiyun * one for u8:
1429*4882a593Smuzhiyun */
1430*4882a593Smuzhiyun #define le8_to_cpu(v) (v)
1431*4882a593Smuzhiyun #define cpu_to_le8(v) (v)
1432*4882a593Smuzhiyun #define __le8 u8
1433*4882a593Smuzhiyun
get_unaligned_le8(const void * p)1434*4882a593Smuzhiyun static inline u8 get_unaligned_le8(const void *p)
1435*4882a593Smuzhiyun {
1436*4882a593Smuzhiyun return *(u8 *)p;
1437*4882a593Smuzhiyun }
1438*4882a593Smuzhiyun
put_unaligned_le8(u8 val,void * p)1439*4882a593Smuzhiyun static inline void put_unaligned_le8(u8 val, void *p)
1440*4882a593Smuzhiyun {
1441*4882a593Smuzhiyun *(u8 *)p = val;
1442*4882a593Smuzhiyun }
1443*4882a593Smuzhiyun
1444*4882a593Smuzhiyun #define read_eb_member(eb, ptr, type, member, result) (\
1445*4882a593Smuzhiyun read_extent_buffer(eb, (char *)(result), \
1446*4882a593Smuzhiyun ((unsigned long)(ptr)) + \
1447*4882a593Smuzhiyun offsetof(type, member), \
1448*4882a593Smuzhiyun sizeof(((type *)0)->member)))
1449*4882a593Smuzhiyun
1450*4882a593Smuzhiyun #define write_eb_member(eb, ptr, type, member, result) (\
1451*4882a593Smuzhiyun write_extent_buffer(eb, (char *)(result), \
1452*4882a593Smuzhiyun ((unsigned long)(ptr)) + \
1453*4882a593Smuzhiyun offsetof(type, member), \
1454*4882a593Smuzhiyun sizeof(((type *)0)->member)))
1455*4882a593Smuzhiyun
1456*4882a593Smuzhiyun #define DECLARE_BTRFS_SETGET_BITS(bits) \
1457*4882a593Smuzhiyun u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
1458*4882a593Smuzhiyun const void *ptr, unsigned long off); \
1459*4882a593Smuzhiyun void btrfs_set_token_##bits(struct btrfs_map_token *token, \
1460*4882a593Smuzhiyun const void *ptr, unsigned long off, \
1461*4882a593Smuzhiyun u##bits val); \
1462*4882a593Smuzhiyun u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
1463*4882a593Smuzhiyun const void *ptr, unsigned long off); \
1464*4882a593Smuzhiyun void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
1465*4882a593Smuzhiyun unsigned long off, u##bits val);
1466*4882a593Smuzhiyun
1467*4882a593Smuzhiyun DECLARE_BTRFS_SETGET_BITS(8)
1468*4882a593Smuzhiyun DECLARE_BTRFS_SETGET_BITS(16)
1469*4882a593Smuzhiyun DECLARE_BTRFS_SETGET_BITS(32)
1470*4882a593Smuzhiyun DECLARE_BTRFS_SETGET_BITS(64)
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
1473*4882a593Smuzhiyun static inline u##bits btrfs_##name(const struct extent_buffer *eb, \
1474*4882a593Smuzhiyun const type *s) \
1475*4882a593Smuzhiyun { \
1476*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1477*4882a593Smuzhiyun return btrfs_get_##bits(eb, s, offsetof(type, member)); \
1478*4882a593Smuzhiyun } \
1479*4882a593Smuzhiyun static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
1480*4882a593Smuzhiyun u##bits val) \
1481*4882a593Smuzhiyun { \
1482*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1483*4882a593Smuzhiyun btrfs_set_##bits(eb, s, offsetof(type, member), val); \
1484*4882a593Smuzhiyun } \
1485*4882a593Smuzhiyun static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
1486*4882a593Smuzhiyun const type *s) \
1487*4882a593Smuzhiyun { \
1488*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1489*4882a593Smuzhiyun return btrfs_get_token_##bits(token, s, offsetof(type, member));\
1490*4882a593Smuzhiyun } \
1491*4882a593Smuzhiyun static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
1492*4882a593Smuzhiyun type *s, u##bits val) \
1493*4882a593Smuzhiyun { \
1494*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1495*4882a593Smuzhiyun btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
1496*4882a593Smuzhiyun }
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
1499*4882a593Smuzhiyun static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
1500*4882a593Smuzhiyun { \
1501*4882a593Smuzhiyun const type *p = page_address(eb->pages[0]); \
1502*4882a593Smuzhiyun return get_unaligned_le##bits(&p->member); \
1503*4882a593Smuzhiyun } \
1504*4882a593Smuzhiyun static inline void btrfs_set_##name(const struct extent_buffer *eb, \
1505*4882a593Smuzhiyun u##bits val) \
1506*4882a593Smuzhiyun { \
1507*4882a593Smuzhiyun type *p = page_address(eb->pages[0]); \
1508*4882a593Smuzhiyun put_unaligned_le##bits(val, &p->member); \
1509*4882a593Smuzhiyun }
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
1512*4882a593Smuzhiyun static inline u##bits btrfs_##name(const type *s) \
1513*4882a593Smuzhiyun { \
1514*4882a593Smuzhiyun return get_unaligned_le##bits(&s->member); \
1515*4882a593Smuzhiyun } \
1516*4882a593Smuzhiyun static inline void btrfs_set_##name(type *s, u##bits val) \
1517*4882a593Smuzhiyun { \
1518*4882a593Smuzhiyun put_unaligned_le##bits(val, &s->member); \
1519*4882a593Smuzhiyun }
1520*4882a593Smuzhiyun
btrfs_device_total_bytes(const struct extent_buffer * eb,struct btrfs_dev_item * s)1521*4882a593Smuzhiyun static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
1522*4882a593Smuzhiyun struct btrfs_dev_item *s)
1523*4882a593Smuzhiyun {
1524*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u64) !=
1525*4882a593Smuzhiyun sizeof(((struct btrfs_dev_item *)0))->total_bytes);
1526*4882a593Smuzhiyun return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
1527*4882a593Smuzhiyun total_bytes));
1528*4882a593Smuzhiyun }
btrfs_set_device_total_bytes(const struct extent_buffer * eb,struct btrfs_dev_item * s,u64 val)1529*4882a593Smuzhiyun static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
1530*4882a593Smuzhiyun struct btrfs_dev_item *s,
1531*4882a593Smuzhiyun u64 val)
1532*4882a593Smuzhiyun {
1533*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(u64) !=
1534*4882a593Smuzhiyun sizeof(((struct btrfs_dev_item *)0))->total_bytes);
1535*4882a593Smuzhiyun WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize));
1536*4882a593Smuzhiyun btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
1537*4882a593Smuzhiyun }
1538*4882a593Smuzhiyun
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
1541*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
1542*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
1543*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
1544*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
1545*4882a593Smuzhiyun start_offset, 64);
1546*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
1547*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
1548*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
1549*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
1550*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
1551*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
1552*4882a593Smuzhiyun
1553*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
1554*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
1555*4882a593Smuzhiyun total_bytes, 64);
1556*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
1557*4882a593Smuzhiyun bytes_used, 64);
1558*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
1559*4882a593Smuzhiyun io_align, 32);
1560*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
1561*4882a593Smuzhiyun io_width, 32);
1562*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
1563*4882a593Smuzhiyun sector_size, 32);
1564*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
1565*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
1566*4882a593Smuzhiyun dev_group, 32);
1567*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
1568*4882a593Smuzhiyun seek_speed, 8);
1569*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
1570*4882a593Smuzhiyun bandwidth, 8);
1571*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
1572*4882a593Smuzhiyun generation, 64);
1573*4882a593Smuzhiyun
btrfs_device_uuid(struct btrfs_dev_item * d)1574*4882a593Smuzhiyun static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d)
1575*4882a593Smuzhiyun {
1576*4882a593Smuzhiyun return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid);
1577*4882a593Smuzhiyun }
1578*4882a593Smuzhiyun
btrfs_device_fsid(struct btrfs_dev_item * d)1579*4882a593Smuzhiyun static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d)
1580*4882a593Smuzhiyun {
1581*4882a593Smuzhiyun return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid);
1582*4882a593Smuzhiyun }
1583*4882a593Smuzhiyun
1584*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
1585*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
1586*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
1587*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
1588*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
1589*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
1590*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
1591*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
1592*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
1593*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
1594*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
1595*4882a593Smuzhiyun
btrfs_stripe_dev_uuid(struct btrfs_stripe * s)1596*4882a593Smuzhiyun static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
1597*4882a593Smuzhiyun {
1598*4882a593Smuzhiyun return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
1599*4882a593Smuzhiyun }
1600*4882a593Smuzhiyun
1601*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
1602*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
1603*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
1604*4882a593Smuzhiyun stripe_len, 64);
1605*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
1606*4882a593Smuzhiyun io_align, 32);
1607*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
1608*4882a593Smuzhiyun io_width, 32);
1609*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
1610*4882a593Smuzhiyun sector_size, 32);
1611*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
1612*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
1613*4882a593Smuzhiyun num_stripes, 16);
1614*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
1615*4882a593Smuzhiyun sub_stripes, 16);
1616*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
1617*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
1618*4882a593Smuzhiyun
btrfs_stripe_nr(struct btrfs_chunk * c,int nr)1619*4882a593Smuzhiyun static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
1620*4882a593Smuzhiyun int nr)
1621*4882a593Smuzhiyun {
1622*4882a593Smuzhiyun unsigned long offset = (unsigned long)c;
1623*4882a593Smuzhiyun offset += offsetof(struct btrfs_chunk, stripe);
1624*4882a593Smuzhiyun offset += nr * sizeof(struct btrfs_stripe);
1625*4882a593Smuzhiyun return (struct btrfs_stripe *)offset;
1626*4882a593Smuzhiyun }
1627*4882a593Smuzhiyun
btrfs_stripe_dev_uuid_nr(struct btrfs_chunk * c,int nr)1628*4882a593Smuzhiyun static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
1629*4882a593Smuzhiyun {
1630*4882a593Smuzhiyun return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
1631*4882a593Smuzhiyun }
1632*4882a593Smuzhiyun
btrfs_stripe_offset_nr(const struct extent_buffer * eb,struct btrfs_chunk * c,int nr)1633*4882a593Smuzhiyun static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
1634*4882a593Smuzhiyun struct btrfs_chunk *c, int nr)
1635*4882a593Smuzhiyun {
1636*4882a593Smuzhiyun return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
1637*4882a593Smuzhiyun }
1638*4882a593Smuzhiyun
btrfs_stripe_devid_nr(const struct extent_buffer * eb,struct btrfs_chunk * c,int nr)1639*4882a593Smuzhiyun static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
1640*4882a593Smuzhiyun struct btrfs_chunk *c, int nr)
1641*4882a593Smuzhiyun {
1642*4882a593Smuzhiyun return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
1643*4882a593Smuzhiyun }
1644*4882a593Smuzhiyun
1645*4882a593Smuzhiyun /* struct btrfs_block_group_item */
1646*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
1647*4882a593Smuzhiyun used, 64);
1648*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item,
1649*4882a593Smuzhiyun used, 64);
1650*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
1651*4882a593Smuzhiyun struct btrfs_block_group_item, chunk_objectid, 64);
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(block_group_chunk_objectid,
1654*4882a593Smuzhiyun struct btrfs_block_group_item, chunk_objectid, 64);
1655*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(block_group_flags,
1656*4882a593Smuzhiyun struct btrfs_block_group_item, flags, 64);
1657*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
1658*4882a593Smuzhiyun struct btrfs_block_group_item, flags, 64);
1659*4882a593Smuzhiyun
1660*4882a593Smuzhiyun /* struct btrfs_free_space_info */
1661*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info,
1662*4882a593Smuzhiyun extent_count, 32);
1663*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32);
1664*4882a593Smuzhiyun
1665*4882a593Smuzhiyun /* struct btrfs_inode_ref */
1666*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
1667*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
1668*4882a593Smuzhiyun
1669*4882a593Smuzhiyun /* struct btrfs_inode_extref */
1670*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref,
1671*4882a593Smuzhiyun parent_objectid, 64);
1672*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref,
1673*4882a593Smuzhiyun name_len, 16);
1674*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64);
1675*4882a593Smuzhiyun
1676*4882a593Smuzhiyun /* struct btrfs_inode_item */
1677*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
1678*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
1679*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
1680*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
1681*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
1682*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
1683*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1684*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1685*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1686*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1687*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1688*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1689*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item,
1690*4882a593Smuzhiyun generation, 64);
1691*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item,
1692*4882a593Smuzhiyun sequence, 64);
1693*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item,
1694*4882a593Smuzhiyun transid, 64);
1695*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64);
1696*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item,
1697*4882a593Smuzhiyun nbytes, 64);
1698*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item,
1699*4882a593Smuzhiyun block_group, 64);
1700*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32);
1701*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32);
1702*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32);
1703*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32);
1704*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64);
1705*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64);
1706*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
1707*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
1708*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64);
1709*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32);
1710*4882a593Smuzhiyun
1711*4882a593Smuzhiyun /* struct btrfs_dev_extent */
1712*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
1713*4882a593Smuzhiyun chunk_tree, 64);
1714*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
1715*4882a593Smuzhiyun chunk_objectid, 64);
1716*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
1717*4882a593Smuzhiyun chunk_offset, 64);
1718*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
1719*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
1720*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
1721*4882a593Smuzhiyun generation, 64);
1722*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1725*4882a593Smuzhiyun
btrfs_tree_block_key(const struct extent_buffer * eb,struct btrfs_tree_block_info * item,struct btrfs_disk_key * key)1726*4882a593Smuzhiyun static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
1727*4882a593Smuzhiyun struct btrfs_tree_block_info *item,
1728*4882a593Smuzhiyun struct btrfs_disk_key *key)
1729*4882a593Smuzhiyun {
1730*4882a593Smuzhiyun read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
1731*4882a593Smuzhiyun }
1732*4882a593Smuzhiyun
btrfs_set_tree_block_key(const struct extent_buffer * eb,struct btrfs_tree_block_info * item,struct btrfs_disk_key * key)1733*4882a593Smuzhiyun static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
1734*4882a593Smuzhiyun struct btrfs_tree_block_info *item,
1735*4882a593Smuzhiyun struct btrfs_disk_key *key)
1736*4882a593Smuzhiyun {
1737*4882a593Smuzhiyun write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
1738*4882a593Smuzhiyun }
1739*4882a593Smuzhiyun
1740*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref,
1741*4882a593Smuzhiyun root, 64);
1742*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref,
1743*4882a593Smuzhiyun objectid, 64);
1744*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref,
1745*4882a593Smuzhiyun offset, 64);
1746*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref,
1747*4882a593Smuzhiyun count, 32);
1748*4882a593Smuzhiyun
1749*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref,
1750*4882a593Smuzhiyun count, 32);
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref,
1753*4882a593Smuzhiyun type, 8);
1754*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref,
1755*4882a593Smuzhiyun offset, 64);
1756*4882a593Smuzhiyun
btrfs_extent_inline_ref_size(int type)1757*4882a593Smuzhiyun static inline u32 btrfs_extent_inline_ref_size(int type)
1758*4882a593Smuzhiyun {
1759*4882a593Smuzhiyun if (type == BTRFS_TREE_BLOCK_REF_KEY ||
1760*4882a593Smuzhiyun type == BTRFS_SHARED_BLOCK_REF_KEY)
1761*4882a593Smuzhiyun return sizeof(struct btrfs_extent_inline_ref);
1762*4882a593Smuzhiyun if (type == BTRFS_SHARED_DATA_REF_KEY)
1763*4882a593Smuzhiyun return sizeof(struct btrfs_shared_data_ref) +
1764*4882a593Smuzhiyun sizeof(struct btrfs_extent_inline_ref);
1765*4882a593Smuzhiyun if (type == BTRFS_EXTENT_DATA_REF_KEY)
1766*4882a593Smuzhiyun return sizeof(struct btrfs_extent_data_ref) +
1767*4882a593Smuzhiyun offsetof(struct btrfs_extent_inline_ref, offset);
1768*4882a593Smuzhiyun return 0;
1769*4882a593Smuzhiyun }
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun /* struct btrfs_node */
1772*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
1773*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
1774*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr,
1775*4882a593Smuzhiyun blockptr, 64);
1776*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
1777*4882a593Smuzhiyun generation, 64);
1778*4882a593Smuzhiyun
btrfs_node_blockptr(const struct extent_buffer * eb,int nr)1779*4882a593Smuzhiyun static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
1780*4882a593Smuzhiyun {
1781*4882a593Smuzhiyun unsigned long ptr;
1782*4882a593Smuzhiyun ptr = offsetof(struct btrfs_node, ptrs) +
1783*4882a593Smuzhiyun sizeof(struct btrfs_key_ptr) * nr;
1784*4882a593Smuzhiyun return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
1785*4882a593Smuzhiyun }
1786*4882a593Smuzhiyun
btrfs_set_node_blockptr(const struct extent_buffer * eb,int nr,u64 val)1787*4882a593Smuzhiyun static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
1788*4882a593Smuzhiyun int nr, u64 val)
1789*4882a593Smuzhiyun {
1790*4882a593Smuzhiyun unsigned long ptr;
1791*4882a593Smuzhiyun ptr = offsetof(struct btrfs_node, ptrs) +
1792*4882a593Smuzhiyun sizeof(struct btrfs_key_ptr) * nr;
1793*4882a593Smuzhiyun btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
1794*4882a593Smuzhiyun }
1795*4882a593Smuzhiyun
btrfs_node_ptr_generation(const struct extent_buffer * eb,int nr)1796*4882a593Smuzhiyun static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
1797*4882a593Smuzhiyun {
1798*4882a593Smuzhiyun unsigned long ptr;
1799*4882a593Smuzhiyun ptr = offsetof(struct btrfs_node, ptrs) +
1800*4882a593Smuzhiyun sizeof(struct btrfs_key_ptr) * nr;
1801*4882a593Smuzhiyun return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
1802*4882a593Smuzhiyun }
1803*4882a593Smuzhiyun
btrfs_set_node_ptr_generation(const struct extent_buffer * eb,int nr,u64 val)1804*4882a593Smuzhiyun static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
1805*4882a593Smuzhiyun int nr, u64 val)
1806*4882a593Smuzhiyun {
1807*4882a593Smuzhiyun unsigned long ptr;
1808*4882a593Smuzhiyun ptr = offsetof(struct btrfs_node, ptrs) +
1809*4882a593Smuzhiyun sizeof(struct btrfs_key_ptr) * nr;
1810*4882a593Smuzhiyun btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
1811*4882a593Smuzhiyun }
1812*4882a593Smuzhiyun
btrfs_node_key_ptr_offset(int nr)1813*4882a593Smuzhiyun static inline unsigned long btrfs_node_key_ptr_offset(int nr)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun return offsetof(struct btrfs_node, ptrs) +
1816*4882a593Smuzhiyun sizeof(struct btrfs_key_ptr) * nr;
1817*4882a593Smuzhiyun }
1818*4882a593Smuzhiyun
1819*4882a593Smuzhiyun void btrfs_node_key(const struct extent_buffer *eb,
1820*4882a593Smuzhiyun struct btrfs_disk_key *disk_key, int nr);
1821*4882a593Smuzhiyun
btrfs_set_node_key(const struct extent_buffer * eb,struct btrfs_disk_key * disk_key,int nr)1822*4882a593Smuzhiyun static inline void btrfs_set_node_key(const struct extent_buffer *eb,
1823*4882a593Smuzhiyun struct btrfs_disk_key *disk_key, int nr)
1824*4882a593Smuzhiyun {
1825*4882a593Smuzhiyun unsigned long ptr;
1826*4882a593Smuzhiyun ptr = btrfs_node_key_ptr_offset(nr);
1827*4882a593Smuzhiyun write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1828*4882a593Smuzhiyun struct btrfs_key_ptr, key, disk_key);
1829*4882a593Smuzhiyun }
1830*4882a593Smuzhiyun
1831*4882a593Smuzhiyun /* struct btrfs_item */
1832*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1833*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1834*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
1835*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
1836*4882a593Smuzhiyun
btrfs_item_nr_offset(int nr)1837*4882a593Smuzhiyun static inline unsigned long btrfs_item_nr_offset(int nr)
1838*4882a593Smuzhiyun {
1839*4882a593Smuzhiyun return offsetof(struct btrfs_leaf, items) +
1840*4882a593Smuzhiyun sizeof(struct btrfs_item) * nr;
1841*4882a593Smuzhiyun }
1842*4882a593Smuzhiyun
btrfs_item_nr(int nr)1843*4882a593Smuzhiyun static inline struct btrfs_item *btrfs_item_nr(int nr)
1844*4882a593Smuzhiyun {
1845*4882a593Smuzhiyun return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1846*4882a593Smuzhiyun }
1847*4882a593Smuzhiyun
btrfs_item_end(const struct extent_buffer * eb,struct btrfs_item * item)1848*4882a593Smuzhiyun static inline u32 btrfs_item_end(const struct extent_buffer *eb,
1849*4882a593Smuzhiyun struct btrfs_item *item)
1850*4882a593Smuzhiyun {
1851*4882a593Smuzhiyun return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1852*4882a593Smuzhiyun }
1853*4882a593Smuzhiyun
btrfs_item_end_nr(const struct extent_buffer * eb,int nr)1854*4882a593Smuzhiyun static inline u32 btrfs_item_end_nr(const struct extent_buffer *eb, int nr)
1855*4882a593Smuzhiyun {
1856*4882a593Smuzhiyun return btrfs_item_end(eb, btrfs_item_nr(nr));
1857*4882a593Smuzhiyun }
1858*4882a593Smuzhiyun
btrfs_item_offset_nr(const struct extent_buffer * eb,int nr)1859*4882a593Smuzhiyun static inline u32 btrfs_item_offset_nr(const struct extent_buffer *eb, int nr)
1860*4882a593Smuzhiyun {
1861*4882a593Smuzhiyun return btrfs_item_offset(eb, btrfs_item_nr(nr));
1862*4882a593Smuzhiyun }
1863*4882a593Smuzhiyun
btrfs_item_size_nr(const struct extent_buffer * eb,int nr)1864*4882a593Smuzhiyun static inline u32 btrfs_item_size_nr(const struct extent_buffer *eb, int nr)
1865*4882a593Smuzhiyun {
1866*4882a593Smuzhiyun return btrfs_item_size(eb, btrfs_item_nr(nr));
1867*4882a593Smuzhiyun }
1868*4882a593Smuzhiyun
btrfs_item_key(const struct extent_buffer * eb,struct btrfs_disk_key * disk_key,int nr)1869*4882a593Smuzhiyun static inline void btrfs_item_key(const struct extent_buffer *eb,
1870*4882a593Smuzhiyun struct btrfs_disk_key *disk_key, int nr)
1871*4882a593Smuzhiyun {
1872*4882a593Smuzhiyun struct btrfs_item *item = btrfs_item_nr(nr);
1873*4882a593Smuzhiyun read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1874*4882a593Smuzhiyun }
1875*4882a593Smuzhiyun
btrfs_set_item_key(struct extent_buffer * eb,struct btrfs_disk_key * disk_key,int nr)1876*4882a593Smuzhiyun static inline void btrfs_set_item_key(struct extent_buffer *eb,
1877*4882a593Smuzhiyun struct btrfs_disk_key *disk_key, int nr)
1878*4882a593Smuzhiyun {
1879*4882a593Smuzhiyun struct btrfs_item *item = btrfs_item_nr(nr);
1880*4882a593Smuzhiyun write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1881*4882a593Smuzhiyun }
1882*4882a593Smuzhiyun
1883*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
1884*4882a593Smuzhiyun
1885*4882a593Smuzhiyun /*
1886*4882a593Smuzhiyun * struct btrfs_root_ref
1887*4882a593Smuzhiyun */
1888*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
1889*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
1890*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
1891*4882a593Smuzhiyun
1892*4882a593Smuzhiyun /* struct btrfs_dir_item */
1893*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1894*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1895*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1896*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1897*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8);
1898*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item,
1899*4882a593Smuzhiyun data_len, 16);
1900*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item,
1901*4882a593Smuzhiyun name_len, 16);
1902*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item,
1903*4882a593Smuzhiyun transid, 64);
1904*4882a593Smuzhiyun
btrfs_dir_item_key(const struct extent_buffer * eb,const struct btrfs_dir_item * item,struct btrfs_disk_key * key)1905*4882a593Smuzhiyun static inline void btrfs_dir_item_key(const struct extent_buffer *eb,
1906*4882a593Smuzhiyun const struct btrfs_dir_item *item,
1907*4882a593Smuzhiyun struct btrfs_disk_key *key)
1908*4882a593Smuzhiyun {
1909*4882a593Smuzhiyun read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1910*4882a593Smuzhiyun }
1911*4882a593Smuzhiyun
btrfs_set_dir_item_key(struct extent_buffer * eb,struct btrfs_dir_item * item,const struct btrfs_disk_key * key)1912*4882a593Smuzhiyun static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1913*4882a593Smuzhiyun struct btrfs_dir_item *item,
1914*4882a593Smuzhiyun const struct btrfs_disk_key *key)
1915*4882a593Smuzhiyun {
1916*4882a593Smuzhiyun write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1917*4882a593Smuzhiyun }
1918*4882a593Smuzhiyun
1919*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header,
1920*4882a593Smuzhiyun num_entries, 64);
1921*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header,
1922*4882a593Smuzhiyun num_bitmaps, 64);
1923*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header,
1924*4882a593Smuzhiyun generation, 64);
1925*4882a593Smuzhiyun
btrfs_free_space_key(const struct extent_buffer * eb,const struct btrfs_free_space_header * h,struct btrfs_disk_key * key)1926*4882a593Smuzhiyun static inline void btrfs_free_space_key(const struct extent_buffer *eb,
1927*4882a593Smuzhiyun const struct btrfs_free_space_header *h,
1928*4882a593Smuzhiyun struct btrfs_disk_key *key)
1929*4882a593Smuzhiyun {
1930*4882a593Smuzhiyun read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
1931*4882a593Smuzhiyun }
1932*4882a593Smuzhiyun
btrfs_set_free_space_key(struct extent_buffer * eb,struct btrfs_free_space_header * h,const struct btrfs_disk_key * key)1933*4882a593Smuzhiyun static inline void btrfs_set_free_space_key(struct extent_buffer *eb,
1934*4882a593Smuzhiyun struct btrfs_free_space_header *h,
1935*4882a593Smuzhiyun const struct btrfs_disk_key *key)
1936*4882a593Smuzhiyun {
1937*4882a593Smuzhiyun write_eb_member(eb, h, struct btrfs_free_space_header, location, key);
1938*4882a593Smuzhiyun }
1939*4882a593Smuzhiyun
1940*4882a593Smuzhiyun /* struct btrfs_disk_key */
1941*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1942*4882a593Smuzhiyun objectid, 64);
1943*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1944*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1945*4882a593Smuzhiyun
1946*4882a593Smuzhiyun #ifdef __LITTLE_ENDIAN
1947*4882a593Smuzhiyun
1948*4882a593Smuzhiyun /*
1949*4882a593Smuzhiyun * Optimized helpers for little-endian architectures where CPU and on-disk
1950*4882a593Smuzhiyun * structures have the same endianness and we can skip conversions.
1951*4882a593Smuzhiyun */
1952*4882a593Smuzhiyun
btrfs_disk_key_to_cpu(struct btrfs_key * cpu_key,const struct btrfs_disk_key * disk_key)1953*4882a593Smuzhiyun static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
1954*4882a593Smuzhiyun const struct btrfs_disk_key *disk_key)
1955*4882a593Smuzhiyun {
1956*4882a593Smuzhiyun memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
1957*4882a593Smuzhiyun }
1958*4882a593Smuzhiyun
btrfs_cpu_key_to_disk(struct btrfs_disk_key * disk_key,const struct btrfs_key * cpu_key)1959*4882a593Smuzhiyun static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
1960*4882a593Smuzhiyun const struct btrfs_key *cpu_key)
1961*4882a593Smuzhiyun {
1962*4882a593Smuzhiyun memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
1963*4882a593Smuzhiyun }
1964*4882a593Smuzhiyun
btrfs_node_key_to_cpu(const struct extent_buffer * eb,struct btrfs_key * cpu_key,int nr)1965*4882a593Smuzhiyun static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
1966*4882a593Smuzhiyun struct btrfs_key *cpu_key, int nr)
1967*4882a593Smuzhiyun {
1968*4882a593Smuzhiyun struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1969*4882a593Smuzhiyun
1970*4882a593Smuzhiyun btrfs_node_key(eb, disk_key, nr);
1971*4882a593Smuzhiyun }
1972*4882a593Smuzhiyun
btrfs_item_key_to_cpu(const struct extent_buffer * eb,struct btrfs_key * cpu_key,int nr)1973*4882a593Smuzhiyun static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
1974*4882a593Smuzhiyun struct btrfs_key *cpu_key, int nr)
1975*4882a593Smuzhiyun {
1976*4882a593Smuzhiyun struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1977*4882a593Smuzhiyun
1978*4882a593Smuzhiyun btrfs_item_key(eb, disk_key, nr);
1979*4882a593Smuzhiyun }
1980*4882a593Smuzhiyun
btrfs_dir_item_key_to_cpu(const struct extent_buffer * eb,const struct btrfs_dir_item * item,struct btrfs_key * cpu_key)1981*4882a593Smuzhiyun static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
1982*4882a593Smuzhiyun const struct btrfs_dir_item *item,
1983*4882a593Smuzhiyun struct btrfs_key *cpu_key)
1984*4882a593Smuzhiyun {
1985*4882a593Smuzhiyun struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1986*4882a593Smuzhiyun
1987*4882a593Smuzhiyun btrfs_dir_item_key(eb, item, disk_key);
1988*4882a593Smuzhiyun }
1989*4882a593Smuzhiyun
1990*4882a593Smuzhiyun #else
1991*4882a593Smuzhiyun
btrfs_disk_key_to_cpu(struct btrfs_key * cpu,const struct btrfs_disk_key * disk)1992*4882a593Smuzhiyun static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1993*4882a593Smuzhiyun const struct btrfs_disk_key *disk)
1994*4882a593Smuzhiyun {
1995*4882a593Smuzhiyun cpu->offset = le64_to_cpu(disk->offset);
1996*4882a593Smuzhiyun cpu->type = disk->type;
1997*4882a593Smuzhiyun cpu->objectid = le64_to_cpu(disk->objectid);
1998*4882a593Smuzhiyun }
1999*4882a593Smuzhiyun
btrfs_cpu_key_to_disk(struct btrfs_disk_key * disk,const struct btrfs_key * cpu)2000*4882a593Smuzhiyun static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
2001*4882a593Smuzhiyun const struct btrfs_key *cpu)
2002*4882a593Smuzhiyun {
2003*4882a593Smuzhiyun disk->offset = cpu_to_le64(cpu->offset);
2004*4882a593Smuzhiyun disk->type = cpu->type;
2005*4882a593Smuzhiyun disk->objectid = cpu_to_le64(cpu->objectid);
2006*4882a593Smuzhiyun }
2007*4882a593Smuzhiyun
btrfs_node_key_to_cpu(const struct extent_buffer * eb,struct btrfs_key * key,int nr)2008*4882a593Smuzhiyun static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
2009*4882a593Smuzhiyun struct btrfs_key *key, int nr)
2010*4882a593Smuzhiyun {
2011*4882a593Smuzhiyun struct btrfs_disk_key disk_key;
2012*4882a593Smuzhiyun btrfs_node_key(eb, &disk_key, nr);
2013*4882a593Smuzhiyun btrfs_disk_key_to_cpu(key, &disk_key);
2014*4882a593Smuzhiyun }
2015*4882a593Smuzhiyun
btrfs_item_key_to_cpu(const struct extent_buffer * eb,struct btrfs_key * key,int nr)2016*4882a593Smuzhiyun static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
2017*4882a593Smuzhiyun struct btrfs_key *key, int nr)
2018*4882a593Smuzhiyun {
2019*4882a593Smuzhiyun struct btrfs_disk_key disk_key;
2020*4882a593Smuzhiyun btrfs_item_key(eb, &disk_key, nr);
2021*4882a593Smuzhiyun btrfs_disk_key_to_cpu(key, &disk_key);
2022*4882a593Smuzhiyun }
2023*4882a593Smuzhiyun
btrfs_dir_item_key_to_cpu(const struct extent_buffer * eb,const struct btrfs_dir_item * item,struct btrfs_key * key)2024*4882a593Smuzhiyun static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
2025*4882a593Smuzhiyun const struct btrfs_dir_item *item,
2026*4882a593Smuzhiyun struct btrfs_key *key)
2027*4882a593Smuzhiyun {
2028*4882a593Smuzhiyun struct btrfs_disk_key disk_key;
2029*4882a593Smuzhiyun btrfs_dir_item_key(eb, item, &disk_key);
2030*4882a593Smuzhiyun btrfs_disk_key_to_cpu(key, &disk_key);
2031*4882a593Smuzhiyun }
2032*4882a593Smuzhiyun
2033*4882a593Smuzhiyun #endif
2034*4882a593Smuzhiyun
2035*4882a593Smuzhiyun /* struct btrfs_header */
2036*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
2037*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
2038*4882a593Smuzhiyun generation, 64);
2039*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
2040*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
2041*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
2042*4882a593Smuzhiyun BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
2043*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
2044*4882a593Smuzhiyun generation, 64);
2045*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
2046*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
2047*4882a593Smuzhiyun nritems, 32);
2048*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
2049*4882a593Smuzhiyun
btrfs_header_flag(const struct extent_buffer * eb,u64 flag)2050*4882a593Smuzhiyun static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
2051*4882a593Smuzhiyun {
2052*4882a593Smuzhiyun return (btrfs_header_flags(eb) & flag) == flag;
2053*4882a593Smuzhiyun }
2054*4882a593Smuzhiyun
btrfs_set_header_flag(struct extent_buffer * eb,u64 flag)2055*4882a593Smuzhiyun static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
2056*4882a593Smuzhiyun {
2057*4882a593Smuzhiyun u64 flags = btrfs_header_flags(eb);
2058*4882a593Smuzhiyun btrfs_set_header_flags(eb, flags | flag);
2059*4882a593Smuzhiyun }
2060*4882a593Smuzhiyun
btrfs_clear_header_flag(struct extent_buffer * eb,u64 flag)2061*4882a593Smuzhiyun static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
2062*4882a593Smuzhiyun {
2063*4882a593Smuzhiyun u64 flags = btrfs_header_flags(eb);
2064*4882a593Smuzhiyun btrfs_set_header_flags(eb, flags & ~flag);
2065*4882a593Smuzhiyun }
2066*4882a593Smuzhiyun
btrfs_header_backref_rev(const struct extent_buffer * eb)2067*4882a593Smuzhiyun static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
2068*4882a593Smuzhiyun {
2069*4882a593Smuzhiyun u64 flags = btrfs_header_flags(eb);
2070*4882a593Smuzhiyun return flags >> BTRFS_BACKREF_REV_SHIFT;
2071*4882a593Smuzhiyun }
2072*4882a593Smuzhiyun
btrfs_set_header_backref_rev(struct extent_buffer * eb,int rev)2073*4882a593Smuzhiyun static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
2074*4882a593Smuzhiyun int rev)
2075*4882a593Smuzhiyun {
2076*4882a593Smuzhiyun u64 flags = btrfs_header_flags(eb);
2077*4882a593Smuzhiyun flags &= ~BTRFS_BACKREF_REV_MASK;
2078*4882a593Smuzhiyun flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
2079*4882a593Smuzhiyun btrfs_set_header_flags(eb, flags);
2080*4882a593Smuzhiyun }
2081*4882a593Smuzhiyun
btrfs_is_leaf(const struct extent_buffer * eb)2082*4882a593Smuzhiyun static inline int btrfs_is_leaf(const struct extent_buffer *eb)
2083*4882a593Smuzhiyun {
2084*4882a593Smuzhiyun return btrfs_header_level(eb) == 0;
2085*4882a593Smuzhiyun }
2086*4882a593Smuzhiyun
2087*4882a593Smuzhiyun /* struct btrfs_root_item */
2088*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
2089*4882a593Smuzhiyun generation, 64);
2090*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
2091*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
2092*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
2093*4882a593Smuzhiyun
2094*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
2095*4882a593Smuzhiyun generation, 64);
2096*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
2097*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
2098*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
2099*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
2100*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
2101*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
2102*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
2103*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
2104*4882a593Smuzhiyun last_snapshot, 64);
2105*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item,
2106*4882a593Smuzhiyun generation_v2, 64);
2107*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item,
2108*4882a593Smuzhiyun ctransid, 64);
2109*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item,
2110*4882a593Smuzhiyun otransid, 64);
2111*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item,
2112*4882a593Smuzhiyun stransid, 64);
2113*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item,
2114*4882a593Smuzhiyun rtransid, 64);
2115*4882a593Smuzhiyun
btrfs_root_readonly(const struct btrfs_root * root)2116*4882a593Smuzhiyun static inline bool btrfs_root_readonly(const struct btrfs_root *root)
2117*4882a593Smuzhiyun {
2118*4882a593Smuzhiyun return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0;
2119*4882a593Smuzhiyun }
2120*4882a593Smuzhiyun
btrfs_root_dead(const struct btrfs_root * root)2121*4882a593Smuzhiyun static inline bool btrfs_root_dead(const struct btrfs_root *root)
2122*4882a593Smuzhiyun {
2123*4882a593Smuzhiyun return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_DEAD)) != 0;
2124*4882a593Smuzhiyun }
2125*4882a593Smuzhiyun
2126*4882a593Smuzhiyun /* struct btrfs_root_backup */
2127*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
2128*4882a593Smuzhiyun tree_root, 64);
2129*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup,
2130*4882a593Smuzhiyun tree_root_gen, 64);
2131*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup,
2132*4882a593Smuzhiyun tree_root_level, 8);
2133*4882a593Smuzhiyun
2134*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup,
2135*4882a593Smuzhiyun chunk_root, 64);
2136*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup,
2137*4882a593Smuzhiyun chunk_root_gen, 64);
2138*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup,
2139*4882a593Smuzhiyun chunk_root_level, 8);
2140*4882a593Smuzhiyun
2141*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup,
2142*4882a593Smuzhiyun extent_root, 64);
2143*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup,
2144*4882a593Smuzhiyun extent_root_gen, 64);
2145*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup,
2146*4882a593Smuzhiyun extent_root_level, 8);
2147*4882a593Smuzhiyun
2148*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup,
2149*4882a593Smuzhiyun fs_root, 64);
2150*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup,
2151*4882a593Smuzhiyun fs_root_gen, 64);
2152*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup,
2153*4882a593Smuzhiyun fs_root_level, 8);
2154*4882a593Smuzhiyun
2155*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup,
2156*4882a593Smuzhiyun dev_root, 64);
2157*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup,
2158*4882a593Smuzhiyun dev_root_gen, 64);
2159*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup,
2160*4882a593Smuzhiyun dev_root_level, 8);
2161*4882a593Smuzhiyun
2162*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup,
2163*4882a593Smuzhiyun csum_root, 64);
2164*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup,
2165*4882a593Smuzhiyun csum_root_gen, 64);
2166*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup,
2167*4882a593Smuzhiyun csum_root_level, 8);
2168*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup,
2169*4882a593Smuzhiyun total_bytes, 64);
2170*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
2171*4882a593Smuzhiyun bytes_used, 64);
2172*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
2173*4882a593Smuzhiyun num_devices, 64);
2174*4882a593Smuzhiyun
2175*4882a593Smuzhiyun /* struct btrfs_balance_item */
2176*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
2177*4882a593Smuzhiyun
btrfs_balance_data(const struct extent_buffer * eb,const struct btrfs_balance_item * bi,struct btrfs_disk_balance_args * ba)2178*4882a593Smuzhiyun static inline void btrfs_balance_data(const struct extent_buffer *eb,
2179*4882a593Smuzhiyun const struct btrfs_balance_item *bi,
2180*4882a593Smuzhiyun struct btrfs_disk_balance_args *ba)
2181*4882a593Smuzhiyun {
2182*4882a593Smuzhiyun read_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
2183*4882a593Smuzhiyun }
2184*4882a593Smuzhiyun
btrfs_set_balance_data(struct extent_buffer * eb,struct btrfs_balance_item * bi,const struct btrfs_disk_balance_args * ba)2185*4882a593Smuzhiyun static inline void btrfs_set_balance_data(struct extent_buffer *eb,
2186*4882a593Smuzhiyun struct btrfs_balance_item *bi,
2187*4882a593Smuzhiyun const struct btrfs_disk_balance_args *ba)
2188*4882a593Smuzhiyun {
2189*4882a593Smuzhiyun write_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
2190*4882a593Smuzhiyun }
2191*4882a593Smuzhiyun
btrfs_balance_meta(const struct extent_buffer * eb,const struct btrfs_balance_item * bi,struct btrfs_disk_balance_args * ba)2192*4882a593Smuzhiyun static inline void btrfs_balance_meta(const struct extent_buffer *eb,
2193*4882a593Smuzhiyun const struct btrfs_balance_item *bi,
2194*4882a593Smuzhiyun struct btrfs_disk_balance_args *ba)
2195*4882a593Smuzhiyun {
2196*4882a593Smuzhiyun read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
2197*4882a593Smuzhiyun }
2198*4882a593Smuzhiyun
btrfs_set_balance_meta(struct extent_buffer * eb,struct btrfs_balance_item * bi,const struct btrfs_disk_balance_args * ba)2199*4882a593Smuzhiyun static inline void btrfs_set_balance_meta(struct extent_buffer *eb,
2200*4882a593Smuzhiyun struct btrfs_balance_item *bi,
2201*4882a593Smuzhiyun const struct btrfs_disk_balance_args *ba)
2202*4882a593Smuzhiyun {
2203*4882a593Smuzhiyun write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
2204*4882a593Smuzhiyun }
2205*4882a593Smuzhiyun
btrfs_balance_sys(const struct extent_buffer * eb,const struct btrfs_balance_item * bi,struct btrfs_disk_balance_args * ba)2206*4882a593Smuzhiyun static inline void btrfs_balance_sys(const struct extent_buffer *eb,
2207*4882a593Smuzhiyun const struct btrfs_balance_item *bi,
2208*4882a593Smuzhiyun struct btrfs_disk_balance_args *ba)
2209*4882a593Smuzhiyun {
2210*4882a593Smuzhiyun read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
2211*4882a593Smuzhiyun }
2212*4882a593Smuzhiyun
btrfs_set_balance_sys(struct extent_buffer * eb,struct btrfs_balance_item * bi,const struct btrfs_disk_balance_args * ba)2213*4882a593Smuzhiyun static inline void btrfs_set_balance_sys(struct extent_buffer *eb,
2214*4882a593Smuzhiyun struct btrfs_balance_item *bi,
2215*4882a593Smuzhiyun const struct btrfs_disk_balance_args *ba)
2216*4882a593Smuzhiyun {
2217*4882a593Smuzhiyun write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
2218*4882a593Smuzhiyun }
2219*4882a593Smuzhiyun
2220*4882a593Smuzhiyun static inline void
btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args * cpu,const struct btrfs_disk_balance_args * disk)2221*4882a593Smuzhiyun btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu,
2222*4882a593Smuzhiyun const struct btrfs_disk_balance_args *disk)
2223*4882a593Smuzhiyun {
2224*4882a593Smuzhiyun memset(cpu, 0, sizeof(*cpu));
2225*4882a593Smuzhiyun
2226*4882a593Smuzhiyun cpu->profiles = le64_to_cpu(disk->profiles);
2227*4882a593Smuzhiyun cpu->usage = le64_to_cpu(disk->usage);
2228*4882a593Smuzhiyun cpu->devid = le64_to_cpu(disk->devid);
2229*4882a593Smuzhiyun cpu->pstart = le64_to_cpu(disk->pstart);
2230*4882a593Smuzhiyun cpu->pend = le64_to_cpu(disk->pend);
2231*4882a593Smuzhiyun cpu->vstart = le64_to_cpu(disk->vstart);
2232*4882a593Smuzhiyun cpu->vend = le64_to_cpu(disk->vend);
2233*4882a593Smuzhiyun cpu->target = le64_to_cpu(disk->target);
2234*4882a593Smuzhiyun cpu->flags = le64_to_cpu(disk->flags);
2235*4882a593Smuzhiyun cpu->limit = le64_to_cpu(disk->limit);
2236*4882a593Smuzhiyun cpu->stripes_min = le32_to_cpu(disk->stripes_min);
2237*4882a593Smuzhiyun cpu->stripes_max = le32_to_cpu(disk->stripes_max);
2238*4882a593Smuzhiyun }
2239*4882a593Smuzhiyun
2240*4882a593Smuzhiyun static inline void
btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args * disk,const struct btrfs_balance_args * cpu)2241*4882a593Smuzhiyun btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
2242*4882a593Smuzhiyun const struct btrfs_balance_args *cpu)
2243*4882a593Smuzhiyun {
2244*4882a593Smuzhiyun memset(disk, 0, sizeof(*disk));
2245*4882a593Smuzhiyun
2246*4882a593Smuzhiyun disk->profiles = cpu_to_le64(cpu->profiles);
2247*4882a593Smuzhiyun disk->usage = cpu_to_le64(cpu->usage);
2248*4882a593Smuzhiyun disk->devid = cpu_to_le64(cpu->devid);
2249*4882a593Smuzhiyun disk->pstart = cpu_to_le64(cpu->pstart);
2250*4882a593Smuzhiyun disk->pend = cpu_to_le64(cpu->pend);
2251*4882a593Smuzhiyun disk->vstart = cpu_to_le64(cpu->vstart);
2252*4882a593Smuzhiyun disk->vend = cpu_to_le64(cpu->vend);
2253*4882a593Smuzhiyun disk->target = cpu_to_le64(cpu->target);
2254*4882a593Smuzhiyun disk->flags = cpu_to_le64(cpu->flags);
2255*4882a593Smuzhiyun disk->limit = cpu_to_le64(cpu->limit);
2256*4882a593Smuzhiyun disk->stripes_min = cpu_to_le32(cpu->stripes_min);
2257*4882a593Smuzhiyun disk->stripes_max = cpu_to_le32(cpu->stripes_max);
2258*4882a593Smuzhiyun }
2259*4882a593Smuzhiyun
2260*4882a593Smuzhiyun /* struct btrfs_super_block */
2261*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
2262*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
2263*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
2264*4882a593Smuzhiyun generation, 64);
2265*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
2266*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
2267*4882a593Smuzhiyun struct btrfs_super_block, sys_chunk_array_size, 32);
2268*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
2269*4882a593Smuzhiyun struct btrfs_super_block, chunk_root_generation, 64);
2270*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
2271*4882a593Smuzhiyun root_level, 8);
2272*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
2273*4882a593Smuzhiyun chunk_root, 64);
2274*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
2275*4882a593Smuzhiyun chunk_root_level, 8);
2276*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
2277*4882a593Smuzhiyun log_root, 64);
2278*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
2279*4882a593Smuzhiyun log_root_transid, 64);
2280*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
2281*4882a593Smuzhiyun log_root_level, 8);
2282*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
2283*4882a593Smuzhiyun total_bytes, 64);
2284*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
2285*4882a593Smuzhiyun bytes_used, 64);
2286*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
2287*4882a593Smuzhiyun sectorsize, 32);
2288*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
2289*4882a593Smuzhiyun nodesize, 32);
2290*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
2291*4882a593Smuzhiyun stripesize, 32);
2292*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
2293*4882a593Smuzhiyun root_dir_objectid, 64);
2294*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
2295*4882a593Smuzhiyun num_devices, 64);
2296*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
2297*4882a593Smuzhiyun compat_flags, 64);
2298*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
2299*4882a593Smuzhiyun compat_ro_flags, 64);
2300*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
2301*4882a593Smuzhiyun incompat_flags, 64);
2302*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
2303*4882a593Smuzhiyun csum_type, 16);
2304*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
2305*4882a593Smuzhiyun cache_generation, 64);
2306*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
2307*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
2308*4882a593Smuzhiyun uuid_tree_generation, 64);
2309*4882a593Smuzhiyun
2310*4882a593Smuzhiyun int btrfs_super_csum_size(const struct btrfs_super_block *s);
2311*4882a593Smuzhiyun const char *btrfs_super_csum_name(u16 csum_type);
2312*4882a593Smuzhiyun const char *btrfs_super_csum_driver(u16 csum_type);
2313*4882a593Smuzhiyun size_t __attribute_const__ btrfs_get_num_csums(void);
2314*4882a593Smuzhiyun
2315*4882a593Smuzhiyun
2316*4882a593Smuzhiyun /*
2317*4882a593Smuzhiyun * The leaf data grows from end-to-front in the node.
2318*4882a593Smuzhiyun * this returns the address of the start of the last item,
2319*4882a593Smuzhiyun * which is the stop of the leaf data stack
2320*4882a593Smuzhiyun */
leaf_data_end(const struct extent_buffer * leaf)2321*4882a593Smuzhiyun static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
2322*4882a593Smuzhiyun {
2323*4882a593Smuzhiyun u32 nr = btrfs_header_nritems(leaf);
2324*4882a593Smuzhiyun
2325*4882a593Smuzhiyun if (nr == 0)
2326*4882a593Smuzhiyun return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
2327*4882a593Smuzhiyun return btrfs_item_offset_nr(leaf, nr - 1);
2328*4882a593Smuzhiyun }
2329*4882a593Smuzhiyun
2330*4882a593Smuzhiyun /* struct btrfs_file_extent_item */
2331*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
2332*4882a593Smuzhiyun type, 8);
2333*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
2334*4882a593Smuzhiyun struct btrfs_file_extent_item, disk_bytenr, 64);
2335*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
2336*4882a593Smuzhiyun struct btrfs_file_extent_item, offset, 64);
2337*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation,
2338*4882a593Smuzhiyun struct btrfs_file_extent_item, generation, 64);
2339*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
2340*4882a593Smuzhiyun struct btrfs_file_extent_item, num_bytes, 64);
2341*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
2342*4882a593Smuzhiyun struct btrfs_file_extent_item, ram_bytes, 64);
2343*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
2344*4882a593Smuzhiyun struct btrfs_file_extent_item, disk_num_bytes, 64);
2345*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
2346*4882a593Smuzhiyun struct btrfs_file_extent_item, compression, 8);
2347*4882a593Smuzhiyun
2348*4882a593Smuzhiyun static inline unsigned long
btrfs_file_extent_inline_start(const struct btrfs_file_extent_item * e)2349*4882a593Smuzhiyun btrfs_file_extent_inline_start(const struct btrfs_file_extent_item *e)
2350*4882a593Smuzhiyun {
2351*4882a593Smuzhiyun return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START;
2352*4882a593Smuzhiyun }
2353*4882a593Smuzhiyun
btrfs_file_extent_calc_inline_size(u32 datasize)2354*4882a593Smuzhiyun static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
2355*4882a593Smuzhiyun {
2356*4882a593Smuzhiyun return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
2357*4882a593Smuzhiyun }
2358*4882a593Smuzhiyun
2359*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
2360*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
2361*4882a593Smuzhiyun disk_bytenr, 64);
2362*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
2363*4882a593Smuzhiyun generation, 64);
2364*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
2365*4882a593Smuzhiyun disk_num_bytes, 64);
2366*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
2367*4882a593Smuzhiyun offset, 64);
2368*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
2369*4882a593Smuzhiyun num_bytes, 64);
2370*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
2371*4882a593Smuzhiyun ram_bytes, 64);
2372*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
2373*4882a593Smuzhiyun compression, 8);
2374*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
2375*4882a593Smuzhiyun encryption, 8);
2376*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
2377*4882a593Smuzhiyun other_encoding, 16);
2378*4882a593Smuzhiyun
2379*4882a593Smuzhiyun /*
2380*4882a593Smuzhiyun * this returns the number of bytes used by the item on disk, minus the
2381*4882a593Smuzhiyun * size of any extent headers. If a file is compressed on disk, this is
2382*4882a593Smuzhiyun * the compressed size
2383*4882a593Smuzhiyun */
btrfs_file_extent_inline_item_len(const struct extent_buffer * eb,struct btrfs_item * e)2384*4882a593Smuzhiyun static inline u32 btrfs_file_extent_inline_item_len(
2385*4882a593Smuzhiyun const struct extent_buffer *eb,
2386*4882a593Smuzhiyun struct btrfs_item *e)
2387*4882a593Smuzhiyun {
2388*4882a593Smuzhiyun return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
2389*4882a593Smuzhiyun }
2390*4882a593Smuzhiyun
2391*4882a593Smuzhiyun /* btrfs_qgroup_status_item */
2392*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
2393*4882a593Smuzhiyun generation, 64);
2394*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
2395*4882a593Smuzhiyun version, 64);
2396*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
2397*4882a593Smuzhiyun flags, 64);
2398*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item,
2399*4882a593Smuzhiyun rescan, 64);
2400*4882a593Smuzhiyun
2401*4882a593Smuzhiyun /* btrfs_qgroup_info_item */
2402*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
2403*4882a593Smuzhiyun generation, 64);
2404*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64);
2405*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item,
2406*4882a593Smuzhiyun rfer_cmpr, 64);
2407*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64);
2408*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item,
2409*4882a593Smuzhiyun excl_cmpr, 64);
2410*4882a593Smuzhiyun
2411*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
2412*4882a593Smuzhiyun struct btrfs_qgroup_info_item, generation, 64);
2413*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item,
2414*4882a593Smuzhiyun rfer, 64);
2415*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr,
2416*4882a593Smuzhiyun struct btrfs_qgroup_info_item, rfer_cmpr, 64);
2417*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item,
2418*4882a593Smuzhiyun excl, 64);
2419*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr,
2420*4882a593Smuzhiyun struct btrfs_qgroup_info_item, excl_cmpr, 64);
2421*4882a593Smuzhiyun
2422*4882a593Smuzhiyun /* btrfs_qgroup_limit_item */
2423*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item,
2424*4882a593Smuzhiyun flags, 64);
2425*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item,
2426*4882a593Smuzhiyun max_rfer, 64);
2427*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item,
2428*4882a593Smuzhiyun max_excl, 64);
2429*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item,
2430*4882a593Smuzhiyun rsv_rfer, 64);
2431*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item,
2432*4882a593Smuzhiyun rsv_excl, 64);
2433*4882a593Smuzhiyun
2434*4882a593Smuzhiyun /* btrfs_dev_replace_item */
2435*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_src_devid,
2436*4882a593Smuzhiyun struct btrfs_dev_replace_item, src_devid, 64);
2437*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode,
2438*4882a593Smuzhiyun struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode,
2439*4882a593Smuzhiyun 64);
2440*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item,
2441*4882a593Smuzhiyun replace_state, 64);
2442*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item,
2443*4882a593Smuzhiyun time_started, 64);
2444*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item,
2445*4882a593Smuzhiyun time_stopped, 64);
2446*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item,
2447*4882a593Smuzhiyun num_write_errors, 64);
2448*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors,
2449*4882a593Smuzhiyun struct btrfs_dev_replace_item, num_uncorrectable_read_errors,
2450*4882a593Smuzhiyun 64);
2451*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item,
2452*4882a593Smuzhiyun cursor_left, 64);
2453*4882a593Smuzhiyun BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item,
2454*4882a593Smuzhiyun cursor_right, 64);
2455*4882a593Smuzhiyun
2456*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid,
2457*4882a593Smuzhiyun struct btrfs_dev_replace_item, src_devid, 64);
2458*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode,
2459*4882a593Smuzhiyun struct btrfs_dev_replace_item,
2460*4882a593Smuzhiyun cont_reading_from_srcdev_mode, 64);
2461*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state,
2462*4882a593Smuzhiyun struct btrfs_dev_replace_item, replace_state, 64);
2463*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started,
2464*4882a593Smuzhiyun struct btrfs_dev_replace_item, time_started, 64);
2465*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped,
2466*4882a593Smuzhiyun struct btrfs_dev_replace_item, time_stopped, 64);
2467*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors,
2468*4882a593Smuzhiyun struct btrfs_dev_replace_item, num_write_errors, 64);
2469*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors,
2470*4882a593Smuzhiyun struct btrfs_dev_replace_item,
2471*4882a593Smuzhiyun num_uncorrectable_read_errors, 64);
2472*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left,
2473*4882a593Smuzhiyun struct btrfs_dev_replace_item, cursor_left, 64);
2474*4882a593Smuzhiyun BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right,
2475*4882a593Smuzhiyun struct btrfs_dev_replace_item, cursor_right, 64);
2476*4882a593Smuzhiyun
2477*4882a593Smuzhiyun /* helper function to cast into the data area of the leaf. */
2478*4882a593Smuzhiyun #define btrfs_item_ptr(leaf, slot, type) \
2479*4882a593Smuzhiyun ((type *)(BTRFS_LEAF_DATA_OFFSET + \
2480*4882a593Smuzhiyun btrfs_item_offset_nr(leaf, slot)))
2481*4882a593Smuzhiyun
2482*4882a593Smuzhiyun #define btrfs_item_ptr_offset(leaf, slot) \
2483*4882a593Smuzhiyun ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
2484*4882a593Smuzhiyun btrfs_item_offset_nr(leaf, slot)))
2485*4882a593Smuzhiyun
btrfs_crc32c(u32 crc,const void * address,unsigned length)2486*4882a593Smuzhiyun static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
2487*4882a593Smuzhiyun {
2488*4882a593Smuzhiyun return crc32c(crc, address, length);
2489*4882a593Smuzhiyun }
2490*4882a593Smuzhiyun
btrfs_crc32c_final(u32 crc,u8 * result)2491*4882a593Smuzhiyun static inline void btrfs_crc32c_final(u32 crc, u8 *result)
2492*4882a593Smuzhiyun {
2493*4882a593Smuzhiyun put_unaligned_le32(~crc, result);
2494*4882a593Smuzhiyun }
2495*4882a593Smuzhiyun
btrfs_name_hash(const char * name,int len)2496*4882a593Smuzhiyun static inline u64 btrfs_name_hash(const char *name, int len)
2497*4882a593Smuzhiyun {
2498*4882a593Smuzhiyun return crc32c((u32)~1, name, len);
2499*4882a593Smuzhiyun }
2500*4882a593Smuzhiyun
2501*4882a593Smuzhiyun /*
2502*4882a593Smuzhiyun * Figure the key offset of an extended inode ref
2503*4882a593Smuzhiyun */
btrfs_extref_hash(u64 parent_objectid,const char * name,int len)2504*4882a593Smuzhiyun static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name,
2505*4882a593Smuzhiyun int len)
2506*4882a593Smuzhiyun {
2507*4882a593Smuzhiyun return (u64) crc32c(parent_objectid, name, len);
2508*4882a593Smuzhiyun }
2509*4882a593Smuzhiyun
btrfs_alloc_write_mask(struct address_space * mapping)2510*4882a593Smuzhiyun static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
2511*4882a593Smuzhiyun {
2512*4882a593Smuzhiyun return mapping_gfp_constraint(mapping, ~__GFP_FS);
2513*4882a593Smuzhiyun }
2514*4882a593Smuzhiyun
2515*4882a593Smuzhiyun /* extent-tree.c */
2516*4882a593Smuzhiyun
2517*4882a593Smuzhiyun enum btrfs_inline_ref_type {
2518*4882a593Smuzhiyun BTRFS_REF_TYPE_INVALID,
2519*4882a593Smuzhiyun BTRFS_REF_TYPE_BLOCK,
2520*4882a593Smuzhiyun BTRFS_REF_TYPE_DATA,
2521*4882a593Smuzhiyun BTRFS_REF_TYPE_ANY,
2522*4882a593Smuzhiyun };
2523*4882a593Smuzhiyun
2524*4882a593Smuzhiyun int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
2525*4882a593Smuzhiyun struct btrfs_extent_inline_ref *iref,
2526*4882a593Smuzhiyun enum btrfs_inline_ref_type is_data);
2527*4882a593Smuzhiyun u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
2528*4882a593Smuzhiyun
2529*4882a593Smuzhiyun u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes);
2530*4882a593Smuzhiyun
2531*4882a593Smuzhiyun /*
2532*4882a593Smuzhiyun * Use this if we would be adding new items, as we could split nodes as we cow
2533*4882a593Smuzhiyun * down the tree.
2534*4882a593Smuzhiyun */
btrfs_calc_insert_metadata_size(struct btrfs_fs_info * fs_info,unsigned num_items)2535*4882a593Smuzhiyun static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info,
2536*4882a593Smuzhiyun unsigned num_items)
2537*4882a593Smuzhiyun {
2538*4882a593Smuzhiyun return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
2539*4882a593Smuzhiyun }
2540*4882a593Smuzhiyun
2541*4882a593Smuzhiyun /*
2542*4882a593Smuzhiyun * Doing a truncate or a modification won't result in new nodes or leaves, just
2543*4882a593Smuzhiyun * what we need for COW.
2544*4882a593Smuzhiyun */
btrfs_calc_metadata_size(struct btrfs_fs_info * fs_info,unsigned num_items)2545*4882a593Smuzhiyun static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info,
2546*4882a593Smuzhiyun unsigned num_items)
2547*4882a593Smuzhiyun {
2548*4882a593Smuzhiyun return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
2549*4882a593Smuzhiyun }
2550*4882a593Smuzhiyun
2551*4882a593Smuzhiyun int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info,
2552*4882a593Smuzhiyun u64 start, u64 num_bytes);
2553*4882a593Smuzhiyun void btrfs_free_excluded_extents(struct btrfs_block_group *cache);
2554*4882a593Smuzhiyun int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2555*4882a593Smuzhiyun unsigned long count);
2556*4882a593Smuzhiyun void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2557*4882a593Smuzhiyun struct btrfs_delayed_ref_root *delayed_refs,
2558*4882a593Smuzhiyun struct btrfs_delayed_ref_head *head);
2559*4882a593Smuzhiyun int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
2560*4882a593Smuzhiyun int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
2561*4882a593Smuzhiyun struct btrfs_fs_info *fs_info, u64 bytenr,
2562*4882a593Smuzhiyun u64 offset, int metadata, u64 *refs, u64 *flags);
2563*4882a593Smuzhiyun int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
2564*4882a593Smuzhiyun int reserved);
2565*4882a593Smuzhiyun int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
2566*4882a593Smuzhiyun u64 bytenr, u64 num_bytes);
2567*4882a593Smuzhiyun int btrfs_exclude_logged_extents(struct extent_buffer *eb);
2568*4882a593Smuzhiyun int btrfs_cross_ref_exist(struct btrfs_root *root,
2569*4882a593Smuzhiyun u64 objectid, u64 offset, u64 bytenr, bool strict);
2570*4882a593Smuzhiyun struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
2571*4882a593Smuzhiyun struct btrfs_root *root,
2572*4882a593Smuzhiyun u64 parent, u64 root_objectid,
2573*4882a593Smuzhiyun const struct btrfs_disk_key *key,
2574*4882a593Smuzhiyun int level, u64 hint,
2575*4882a593Smuzhiyun u64 empty_size,
2576*4882a593Smuzhiyun enum btrfs_lock_nesting nest);
2577*4882a593Smuzhiyun void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
2578*4882a593Smuzhiyun struct btrfs_root *root,
2579*4882a593Smuzhiyun struct extent_buffer *buf,
2580*4882a593Smuzhiyun u64 parent, int last_ref);
2581*4882a593Smuzhiyun int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
2582*4882a593Smuzhiyun struct btrfs_root *root, u64 owner,
2583*4882a593Smuzhiyun u64 offset, u64 ram_bytes,
2584*4882a593Smuzhiyun struct btrfs_key *ins);
2585*4882a593Smuzhiyun int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
2586*4882a593Smuzhiyun u64 root_objectid, u64 owner, u64 offset,
2587*4882a593Smuzhiyun struct btrfs_key *ins);
2588*4882a593Smuzhiyun int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes,
2589*4882a593Smuzhiyun u64 min_alloc_size, u64 empty_size, u64 hint_byte,
2590*4882a593Smuzhiyun struct btrfs_key *ins, int is_data, int delalloc);
2591*4882a593Smuzhiyun int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2592*4882a593Smuzhiyun struct extent_buffer *buf, int full_backref);
2593*4882a593Smuzhiyun int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2594*4882a593Smuzhiyun struct extent_buffer *buf, int full_backref);
2595*4882a593Smuzhiyun int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
2596*4882a593Smuzhiyun struct extent_buffer *eb, u64 flags,
2597*4882a593Smuzhiyun int level, int is_data);
2598*4882a593Smuzhiyun int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
2599*4882a593Smuzhiyun
2600*4882a593Smuzhiyun int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
2601*4882a593Smuzhiyun u64 start, u64 len, int delalloc);
2602*4882a593Smuzhiyun int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start,
2603*4882a593Smuzhiyun u64 len);
2604*4882a593Smuzhiyun int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
2605*4882a593Smuzhiyun int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
2606*4882a593Smuzhiyun struct btrfs_ref *generic_ref);
2607*4882a593Smuzhiyun
2608*4882a593Smuzhiyun int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
2609*4882a593Smuzhiyun void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
2610*4882a593Smuzhiyun
2611*4882a593Smuzhiyun /*
2612*4882a593Smuzhiyun * Different levels for to flush space when doing space reservations.
2613*4882a593Smuzhiyun *
2614*4882a593Smuzhiyun * The higher the level, the more methods we try to reclaim space.
2615*4882a593Smuzhiyun */
2616*4882a593Smuzhiyun enum btrfs_reserve_flush_enum {
2617*4882a593Smuzhiyun /* If we are in the transaction, we can't flush anything.*/
2618*4882a593Smuzhiyun BTRFS_RESERVE_NO_FLUSH,
2619*4882a593Smuzhiyun
2620*4882a593Smuzhiyun /*
2621*4882a593Smuzhiyun * Flush space by:
2622*4882a593Smuzhiyun * - Running delayed inode items
2623*4882a593Smuzhiyun * - Allocating a new chunk
2624*4882a593Smuzhiyun */
2625*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_LIMIT,
2626*4882a593Smuzhiyun
2627*4882a593Smuzhiyun /*
2628*4882a593Smuzhiyun * Flush space by:
2629*4882a593Smuzhiyun * - Running delayed inode items
2630*4882a593Smuzhiyun * - Running delayed refs
2631*4882a593Smuzhiyun * - Running delalloc and waiting for ordered extents
2632*4882a593Smuzhiyun * - Allocating a new chunk
2633*4882a593Smuzhiyun */
2634*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_EVICT,
2635*4882a593Smuzhiyun
2636*4882a593Smuzhiyun /*
2637*4882a593Smuzhiyun * Flush space by above mentioned methods and by:
2638*4882a593Smuzhiyun * - Running delayed iputs
2639*4882a593Smuzhiyun * - Commiting transaction
2640*4882a593Smuzhiyun *
2641*4882a593Smuzhiyun * Can be interruped by fatal signal.
2642*4882a593Smuzhiyun */
2643*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_DATA,
2644*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE,
2645*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_ALL,
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun /*
2648*4882a593Smuzhiyun * Pretty much the same as FLUSH_ALL, but can also steal space from
2649*4882a593Smuzhiyun * global rsv.
2650*4882a593Smuzhiyun *
2651*4882a593Smuzhiyun * Can be interruped by fatal signal.
2652*4882a593Smuzhiyun */
2653*4882a593Smuzhiyun BTRFS_RESERVE_FLUSH_ALL_STEAL,
2654*4882a593Smuzhiyun };
2655*4882a593Smuzhiyun
2656*4882a593Smuzhiyun enum btrfs_flush_state {
2657*4882a593Smuzhiyun FLUSH_DELAYED_ITEMS_NR = 1,
2658*4882a593Smuzhiyun FLUSH_DELAYED_ITEMS = 2,
2659*4882a593Smuzhiyun FLUSH_DELAYED_REFS_NR = 3,
2660*4882a593Smuzhiyun FLUSH_DELAYED_REFS = 4,
2661*4882a593Smuzhiyun FLUSH_DELALLOC = 5,
2662*4882a593Smuzhiyun FLUSH_DELALLOC_WAIT = 6,
2663*4882a593Smuzhiyun ALLOC_CHUNK = 7,
2664*4882a593Smuzhiyun ALLOC_CHUNK_FORCE = 8,
2665*4882a593Smuzhiyun RUN_DELAYED_IPUTS = 9,
2666*4882a593Smuzhiyun COMMIT_TRANS = 10,
2667*4882a593Smuzhiyun };
2668*4882a593Smuzhiyun
2669*4882a593Smuzhiyun int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
2670*4882a593Smuzhiyun struct btrfs_block_rsv *rsv,
2671*4882a593Smuzhiyun int nitems, bool use_global_rsv);
2672*4882a593Smuzhiyun void btrfs_subvolume_release_metadata(struct btrfs_root *root,
2673*4882a593Smuzhiyun struct btrfs_block_rsv *rsv);
2674*4882a593Smuzhiyun void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
2675*4882a593Smuzhiyun
2676*4882a593Smuzhiyun int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes);
2677*4882a593Smuzhiyun u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
2678*4882a593Smuzhiyun int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
2679*4882a593Smuzhiyun u64 start, u64 end);
2680*4882a593Smuzhiyun int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
2681*4882a593Smuzhiyun u64 num_bytes, u64 *actual_bytes);
2682*4882a593Smuzhiyun int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
2683*4882a593Smuzhiyun
2684*4882a593Smuzhiyun int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
2685*4882a593Smuzhiyun int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans,
2686*4882a593Smuzhiyun struct btrfs_fs_info *fs_info);
2687*4882a593Smuzhiyun int btrfs_start_write_no_snapshotting(struct btrfs_root *root);
2688*4882a593Smuzhiyun void btrfs_end_write_no_snapshotting(struct btrfs_root *root);
2689*4882a593Smuzhiyun void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);
2690*4882a593Smuzhiyun
2691*4882a593Smuzhiyun /* ctree.c */
2692*4882a593Smuzhiyun int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
2693*4882a593Smuzhiyun int *slot);
2694*4882a593Smuzhiyun int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
2695*4882a593Smuzhiyun int btrfs_previous_item(struct btrfs_root *root,
2696*4882a593Smuzhiyun struct btrfs_path *path, u64 min_objectid,
2697*4882a593Smuzhiyun int type);
2698*4882a593Smuzhiyun int btrfs_previous_extent_item(struct btrfs_root *root,
2699*4882a593Smuzhiyun struct btrfs_path *path, u64 min_objectid);
2700*4882a593Smuzhiyun void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
2701*4882a593Smuzhiyun struct btrfs_path *path,
2702*4882a593Smuzhiyun const struct btrfs_key *new_key);
2703*4882a593Smuzhiyun struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
2704*4882a593Smuzhiyun int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
2705*4882a593Smuzhiyun struct btrfs_key *key, int lowest_level,
2706*4882a593Smuzhiyun u64 min_trans);
2707*4882a593Smuzhiyun int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
2708*4882a593Smuzhiyun struct btrfs_path *path,
2709*4882a593Smuzhiyun u64 min_trans);
2710*4882a593Smuzhiyun struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
2711*4882a593Smuzhiyun int slot);
2712*4882a593Smuzhiyun
2713*4882a593Smuzhiyun int btrfs_cow_block(struct btrfs_trans_handle *trans,
2714*4882a593Smuzhiyun struct btrfs_root *root, struct extent_buffer *buf,
2715*4882a593Smuzhiyun struct extent_buffer *parent, int parent_slot,
2716*4882a593Smuzhiyun struct extent_buffer **cow_ret,
2717*4882a593Smuzhiyun enum btrfs_lock_nesting nest);
2718*4882a593Smuzhiyun int btrfs_copy_root(struct btrfs_trans_handle *trans,
2719*4882a593Smuzhiyun struct btrfs_root *root,
2720*4882a593Smuzhiyun struct extent_buffer *buf,
2721*4882a593Smuzhiyun struct extent_buffer **cow_ret, u64 new_root_objectid);
2722*4882a593Smuzhiyun int btrfs_block_can_be_shared(struct btrfs_root *root,
2723*4882a593Smuzhiyun struct extent_buffer *buf);
2724*4882a593Smuzhiyun void btrfs_extend_item(struct btrfs_path *path, u32 data_size);
2725*4882a593Smuzhiyun void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
2726*4882a593Smuzhiyun int btrfs_split_item(struct btrfs_trans_handle *trans,
2727*4882a593Smuzhiyun struct btrfs_root *root,
2728*4882a593Smuzhiyun struct btrfs_path *path,
2729*4882a593Smuzhiyun const struct btrfs_key *new_key,
2730*4882a593Smuzhiyun unsigned long split_offset);
2731*4882a593Smuzhiyun int btrfs_duplicate_item(struct btrfs_trans_handle *trans,
2732*4882a593Smuzhiyun struct btrfs_root *root,
2733*4882a593Smuzhiyun struct btrfs_path *path,
2734*4882a593Smuzhiyun const struct btrfs_key *new_key);
2735*4882a593Smuzhiyun int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
2736*4882a593Smuzhiyun u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key);
2737*4882a593Smuzhiyun int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2738*4882a593Smuzhiyun const struct btrfs_key *key, struct btrfs_path *p,
2739*4882a593Smuzhiyun int ins_len, int cow);
2740*4882a593Smuzhiyun int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
2741*4882a593Smuzhiyun struct btrfs_path *p, u64 time_seq);
2742*4882a593Smuzhiyun int btrfs_search_slot_for_read(struct btrfs_root *root,
2743*4882a593Smuzhiyun const struct btrfs_key *key,
2744*4882a593Smuzhiyun struct btrfs_path *p, int find_higher,
2745*4882a593Smuzhiyun int return_any);
2746*4882a593Smuzhiyun int btrfs_realloc_node(struct btrfs_trans_handle *trans,
2747*4882a593Smuzhiyun struct btrfs_root *root, struct extent_buffer *parent,
2748*4882a593Smuzhiyun int start_slot, u64 *last_ret,
2749*4882a593Smuzhiyun struct btrfs_key *progress);
2750*4882a593Smuzhiyun void btrfs_release_path(struct btrfs_path *p);
2751*4882a593Smuzhiyun struct btrfs_path *btrfs_alloc_path(void);
2752*4882a593Smuzhiyun void btrfs_free_path(struct btrfs_path *p);
2753*4882a593Smuzhiyun
2754*4882a593Smuzhiyun int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2755*4882a593Smuzhiyun struct btrfs_path *path, int slot, int nr);
btrfs_del_item(struct btrfs_trans_handle * trans,struct btrfs_root * root,struct btrfs_path * path)2756*4882a593Smuzhiyun static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
2757*4882a593Smuzhiyun struct btrfs_root *root,
2758*4882a593Smuzhiyun struct btrfs_path *path)
2759*4882a593Smuzhiyun {
2760*4882a593Smuzhiyun return btrfs_del_items(trans, root, path, path->slots[0], 1);
2761*4882a593Smuzhiyun }
2762*4882a593Smuzhiyun
2763*4882a593Smuzhiyun void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
2764*4882a593Smuzhiyun const struct btrfs_key *cpu_key, u32 *data_size,
2765*4882a593Smuzhiyun int nr);
2766*4882a593Smuzhiyun int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2767*4882a593Smuzhiyun const struct btrfs_key *key, void *data, u32 data_size);
2768*4882a593Smuzhiyun int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
2769*4882a593Smuzhiyun struct btrfs_root *root,
2770*4882a593Smuzhiyun struct btrfs_path *path,
2771*4882a593Smuzhiyun const struct btrfs_key *cpu_key, u32 *data_size,
2772*4882a593Smuzhiyun int nr);
2773*4882a593Smuzhiyun
btrfs_insert_empty_item(struct btrfs_trans_handle * trans,struct btrfs_root * root,struct btrfs_path * path,const struct btrfs_key * key,u32 data_size)2774*4882a593Smuzhiyun static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
2775*4882a593Smuzhiyun struct btrfs_root *root,
2776*4882a593Smuzhiyun struct btrfs_path *path,
2777*4882a593Smuzhiyun const struct btrfs_key *key,
2778*4882a593Smuzhiyun u32 data_size)
2779*4882a593Smuzhiyun {
2780*4882a593Smuzhiyun return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
2781*4882a593Smuzhiyun }
2782*4882a593Smuzhiyun
2783*4882a593Smuzhiyun int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
2784*4882a593Smuzhiyun int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
2785*4882a593Smuzhiyun int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
2786*4882a593Smuzhiyun u64 time_seq);
btrfs_next_old_item(struct btrfs_root * root,struct btrfs_path * p,u64 time_seq)2787*4882a593Smuzhiyun static inline int btrfs_next_old_item(struct btrfs_root *root,
2788*4882a593Smuzhiyun struct btrfs_path *p, u64 time_seq)
2789*4882a593Smuzhiyun {
2790*4882a593Smuzhiyun ++p->slots[0];
2791*4882a593Smuzhiyun if (p->slots[0] >= btrfs_header_nritems(p->nodes[0]))
2792*4882a593Smuzhiyun return btrfs_next_old_leaf(root, p, time_seq);
2793*4882a593Smuzhiyun return 0;
2794*4882a593Smuzhiyun }
btrfs_next_item(struct btrfs_root * root,struct btrfs_path * p)2795*4882a593Smuzhiyun static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p)
2796*4882a593Smuzhiyun {
2797*4882a593Smuzhiyun return btrfs_next_old_item(root, p, 0);
2798*4882a593Smuzhiyun }
2799*4882a593Smuzhiyun int btrfs_leaf_free_space(struct extent_buffer *leaf);
2800*4882a593Smuzhiyun int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
2801*4882a593Smuzhiyun int for_reloc);
2802*4882a593Smuzhiyun int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
2803*4882a593Smuzhiyun struct btrfs_root *root,
2804*4882a593Smuzhiyun struct extent_buffer *node,
2805*4882a593Smuzhiyun struct extent_buffer *parent);
btrfs_fs_closing(struct btrfs_fs_info * fs_info)2806*4882a593Smuzhiyun static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
2807*4882a593Smuzhiyun {
2808*4882a593Smuzhiyun /*
2809*4882a593Smuzhiyun * Do it this way so we only ever do one test_bit in the normal case.
2810*4882a593Smuzhiyun */
2811*4882a593Smuzhiyun if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) {
2812*4882a593Smuzhiyun if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags))
2813*4882a593Smuzhiyun return 2;
2814*4882a593Smuzhiyun return 1;
2815*4882a593Smuzhiyun }
2816*4882a593Smuzhiyun return 0;
2817*4882a593Smuzhiyun }
2818*4882a593Smuzhiyun
2819*4882a593Smuzhiyun /*
2820*4882a593Smuzhiyun * If we remount the fs to be R/O or umount the fs, the cleaner needn't do
2821*4882a593Smuzhiyun * anything except sleeping. This function is used to check the status of
2822*4882a593Smuzhiyun * the fs.
2823*4882a593Smuzhiyun */
btrfs_need_cleaner_sleep(struct btrfs_fs_info * fs_info)2824*4882a593Smuzhiyun static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
2825*4882a593Smuzhiyun {
2826*4882a593Smuzhiyun return fs_info->sb->s_flags & SB_RDONLY || btrfs_fs_closing(fs_info);
2827*4882a593Smuzhiyun }
2828*4882a593Smuzhiyun
2829*4882a593Smuzhiyun /* tree mod log functions from ctree.c */
2830*4882a593Smuzhiyun u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
2831*4882a593Smuzhiyun struct seq_list *elem);
2832*4882a593Smuzhiyun void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
2833*4882a593Smuzhiyun struct seq_list *elem);
2834*4882a593Smuzhiyun int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq);
2835*4882a593Smuzhiyun
2836*4882a593Smuzhiyun /* root-item.c */
2837*4882a593Smuzhiyun int btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
2838*4882a593Smuzhiyun u64 ref_id, u64 dirid, u64 sequence, const char *name,
2839*4882a593Smuzhiyun int name_len);
2840*4882a593Smuzhiyun int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
2841*4882a593Smuzhiyun u64 ref_id, u64 dirid, u64 *sequence, const char *name,
2842*4882a593Smuzhiyun int name_len);
2843*4882a593Smuzhiyun int btrfs_del_root(struct btrfs_trans_handle *trans,
2844*4882a593Smuzhiyun const struct btrfs_key *key);
2845*4882a593Smuzhiyun int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2846*4882a593Smuzhiyun const struct btrfs_key *key,
2847*4882a593Smuzhiyun struct btrfs_root_item *item);
2848*4882a593Smuzhiyun int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
2849*4882a593Smuzhiyun struct btrfs_root *root,
2850*4882a593Smuzhiyun struct btrfs_key *key,
2851*4882a593Smuzhiyun struct btrfs_root_item *item);
2852*4882a593Smuzhiyun int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
2853*4882a593Smuzhiyun struct btrfs_path *path, struct btrfs_root_item *root_item,
2854*4882a593Smuzhiyun struct btrfs_key *root_key);
2855*4882a593Smuzhiyun int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
2856*4882a593Smuzhiyun void btrfs_set_root_node(struct btrfs_root_item *item,
2857*4882a593Smuzhiyun struct extent_buffer *node);
2858*4882a593Smuzhiyun void btrfs_check_and_init_root_item(struct btrfs_root_item *item);
2859*4882a593Smuzhiyun void btrfs_update_root_times(struct btrfs_trans_handle *trans,
2860*4882a593Smuzhiyun struct btrfs_root *root);
2861*4882a593Smuzhiyun
2862*4882a593Smuzhiyun /* uuid-tree.c */
2863*4882a593Smuzhiyun int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
2864*4882a593Smuzhiyun u64 subid);
2865*4882a593Smuzhiyun int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
2866*4882a593Smuzhiyun u64 subid);
2867*4882a593Smuzhiyun int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
2868*4882a593Smuzhiyun
2869*4882a593Smuzhiyun /* dir-item.c */
2870*4882a593Smuzhiyun int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
2871*4882a593Smuzhiyun const char *name, int name_len);
2872*4882a593Smuzhiyun int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
2873*4882a593Smuzhiyun int name_len, struct btrfs_inode *dir,
2874*4882a593Smuzhiyun struct btrfs_key *location, u8 type, u64 index);
2875*4882a593Smuzhiyun struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
2876*4882a593Smuzhiyun struct btrfs_root *root,
2877*4882a593Smuzhiyun struct btrfs_path *path, u64 dir,
2878*4882a593Smuzhiyun const char *name, int name_len,
2879*4882a593Smuzhiyun int mod);
2880*4882a593Smuzhiyun struct btrfs_dir_item *
2881*4882a593Smuzhiyun btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
2882*4882a593Smuzhiyun struct btrfs_root *root,
2883*4882a593Smuzhiyun struct btrfs_path *path, u64 dir,
2884*4882a593Smuzhiyun u64 objectid, const char *name, int name_len,
2885*4882a593Smuzhiyun int mod);
2886*4882a593Smuzhiyun struct btrfs_dir_item *
2887*4882a593Smuzhiyun btrfs_search_dir_index_item(struct btrfs_root *root,
2888*4882a593Smuzhiyun struct btrfs_path *path, u64 dirid,
2889*4882a593Smuzhiyun const char *name, int name_len);
2890*4882a593Smuzhiyun int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
2891*4882a593Smuzhiyun struct btrfs_root *root,
2892*4882a593Smuzhiyun struct btrfs_path *path,
2893*4882a593Smuzhiyun struct btrfs_dir_item *di);
2894*4882a593Smuzhiyun int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
2895*4882a593Smuzhiyun struct btrfs_root *root,
2896*4882a593Smuzhiyun struct btrfs_path *path, u64 objectid,
2897*4882a593Smuzhiyun const char *name, u16 name_len,
2898*4882a593Smuzhiyun const void *data, u16 data_len);
2899*4882a593Smuzhiyun struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
2900*4882a593Smuzhiyun struct btrfs_root *root,
2901*4882a593Smuzhiyun struct btrfs_path *path, u64 dir,
2902*4882a593Smuzhiyun const char *name, u16 name_len,
2903*4882a593Smuzhiyun int mod);
2904*4882a593Smuzhiyun struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
2905*4882a593Smuzhiyun struct btrfs_path *path,
2906*4882a593Smuzhiyun const char *name,
2907*4882a593Smuzhiyun int name_len);
2908*4882a593Smuzhiyun
2909*4882a593Smuzhiyun /* orphan.c */
2910*4882a593Smuzhiyun int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
2911*4882a593Smuzhiyun struct btrfs_root *root, u64 offset);
2912*4882a593Smuzhiyun int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
2913*4882a593Smuzhiyun struct btrfs_root *root, u64 offset);
2914*4882a593Smuzhiyun int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset);
2915*4882a593Smuzhiyun
2916*4882a593Smuzhiyun /* inode-item.c */
2917*4882a593Smuzhiyun int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
2918*4882a593Smuzhiyun struct btrfs_root *root,
2919*4882a593Smuzhiyun const char *name, int name_len,
2920*4882a593Smuzhiyun u64 inode_objectid, u64 ref_objectid, u64 index);
2921*4882a593Smuzhiyun int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
2922*4882a593Smuzhiyun struct btrfs_root *root,
2923*4882a593Smuzhiyun const char *name, int name_len,
2924*4882a593Smuzhiyun u64 inode_objectid, u64 ref_objectid, u64 *index);
2925*4882a593Smuzhiyun int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
2926*4882a593Smuzhiyun struct btrfs_root *root,
2927*4882a593Smuzhiyun struct btrfs_path *path, u64 objectid);
2928*4882a593Smuzhiyun int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
2929*4882a593Smuzhiyun *root, struct btrfs_path *path,
2930*4882a593Smuzhiyun struct btrfs_key *location, int mod);
2931*4882a593Smuzhiyun
2932*4882a593Smuzhiyun struct btrfs_inode_extref *
2933*4882a593Smuzhiyun btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
2934*4882a593Smuzhiyun struct btrfs_root *root,
2935*4882a593Smuzhiyun struct btrfs_path *path,
2936*4882a593Smuzhiyun const char *name, int name_len,
2937*4882a593Smuzhiyun u64 inode_objectid, u64 ref_objectid, int ins_len,
2938*4882a593Smuzhiyun int cow);
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
2941*4882a593Smuzhiyun int slot, const char *name,
2942*4882a593Smuzhiyun int name_len);
2943*4882a593Smuzhiyun struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
2944*4882a593Smuzhiyun struct extent_buffer *leaf, int slot, u64 ref_objectid,
2945*4882a593Smuzhiyun const char *name, int name_len);
2946*4882a593Smuzhiyun /* file-item.c */
2947*4882a593Smuzhiyun struct btrfs_dio_private;
2948*4882a593Smuzhiyun int btrfs_del_csums(struct btrfs_trans_handle *trans,
2949*4882a593Smuzhiyun struct btrfs_root *root, u64 bytenr, u64 len);
2950*4882a593Smuzhiyun blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
2951*4882a593Smuzhiyun u64 offset, u8 *dst);
2952*4882a593Smuzhiyun int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
2953*4882a593Smuzhiyun struct btrfs_root *root,
2954*4882a593Smuzhiyun u64 objectid, u64 pos,
2955*4882a593Smuzhiyun u64 disk_offset, u64 disk_num_bytes,
2956*4882a593Smuzhiyun u64 num_bytes, u64 offset, u64 ram_bytes,
2957*4882a593Smuzhiyun u8 compression, u8 encryption, u16 other_encoding);
2958*4882a593Smuzhiyun int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
2959*4882a593Smuzhiyun struct btrfs_root *root,
2960*4882a593Smuzhiyun struct btrfs_path *path, u64 objectid,
2961*4882a593Smuzhiyun u64 bytenr, int mod);
2962*4882a593Smuzhiyun int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
2963*4882a593Smuzhiyun struct btrfs_root *root,
2964*4882a593Smuzhiyun struct btrfs_ordered_sum *sums);
2965*4882a593Smuzhiyun blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
2966*4882a593Smuzhiyun u64 file_start, int contig);
2967*4882a593Smuzhiyun int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
2968*4882a593Smuzhiyun struct list_head *list, int search_commit);
2969*4882a593Smuzhiyun void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
2970*4882a593Smuzhiyun const struct btrfs_path *path,
2971*4882a593Smuzhiyun struct btrfs_file_extent_item *fi,
2972*4882a593Smuzhiyun const bool new_inline,
2973*4882a593Smuzhiyun struct extent_map *em);
2974*4882a593Smuzhiyun int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
2975*4882a593Smuzhiyun u64 len);
2976*4882a593Smuzhiyun int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start,
2977*4882a593Smuzhiyun u64 len);
2978*4882a593Smuzhiyun void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size);
2979*4882a593Smuzhiyun u64 btrfs_file_extent_end(const struct btrfs_path *path);
2980*4882a593Smuzhiyun
2981*4882a593Smuzhiyun /* inode.c */
2982*4882a593Smuzhiyun blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
2983*4882a593Smuzhiyun int mirror_num, unsigned long bio_flags);
2984*4882a593Smuzhiyun int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
2985*4882a593Smuzhiyun struct page *page, u64 start, u64 end, int mirror);
2986*4882a593Smuzhiyun struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
2987*4882a593Smuzhiyun u64 start, u64 len);
2988*4882a593Smuzhiyun noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
2989*4882a593Smuzhiyun u64 *orig_start, u64 *orig_block_len,
2990*4882a593Smuzhiyun u64 *ram_bytes, bool strict);
2991*4882a593Smuzhiyun
2992*4882a593Smuzhiyun void __btrfs_del_delalloc_inode(struct btrfs_root *root,
2993*4882a593Smuzhiyun struct btrfs_inode *inode);
2994*4882a593Smuzhiyun struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
2995*4882a593Smuzhiyun int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index);
2996*4882a593Smuzhiyun int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
2997*4882a593Smuzhiyun struct btrfs_root *root,
2998*4882a593Smuzhiyun struct btrfs_inode *dir, struct btrfs_inode *inode,
2999*4882a593Smuzhiyun const char *name, int name_len);
3000*4882a593Smuzhiyun int btrfs_add_link(struct btrfs_trans_handle *trans,
3001*4882a593Smuzhiyun struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
3002*4882a593Smuzhiyun const char *name, int name_len, int add_backref, u64 index);
3003*4882a593Smuzhiyun int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry);
3004*4882a593Smuzhiyun int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
3005*4882a593Smuzhiyun int front);
3006*4882a593Smuzhiyun int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
3007*4882a593Smuzhiyun struct btrfs_root *root,
3008*4882a593Smuzhiyun struct inode *inode, u64 new_size,
3009*4882a593Smuzhiyun u32 min_type);
3010*4882a593Smuzhiyun
3011*4882a593Smuzhiyun int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
3012*4882a593Smuzhiyun int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,
3013*4882a593Smuzhiyun bool in_reclaim_context);
3014*4882a593Smuzhiyun int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
3015*4882a593Smuzhiyun unsigned int extra_bits,
3016*4882a593Smuzhiyun struct extent_state **cached_state);
3017*4882a593Smuzhiyun int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
3018*4882a593Smuzhiyun struct btrfs_root *new_root,
3019*4882a593Smuzhiyun struct btrfs_root *parent_root,
3020*4882a593Smuzhiyun u64 new_dirid);
3021*4882a593Smuzhiyun void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
3022*4882a593Smuzhiyun unsigned *bits);
3023*4882a593Smuzhiyun void btrfs_clear_delalloc_extent(struct inode *inode,
3024*4882a593Smuzhiyun struct extent_state *state, unsigned *bits);
3025*4882a593Smuzhiyun void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
3026*4882a593Smuzhiyun struct extent_state *other);
3027*4882a593Smuzhiyun void btrfs_split_delalloc_extent(struct inode *inode,
3028*4882a593Smuzhiyun struct extent_state *orig, u64 split);
3029*4882a593Smuzhiyun int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
3030*4882a593Smuzhiyun unsigned long bio_flags);
3031*4882a593Smuzhiyun void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
3032*4882a593Smuzhiyun vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
3033*4882a593Smuzhiyun int btrfs_readpage(struct file *file, struct page *page);
3034*4882a593Smuzhiyun void btrfs_evict_inode(struct inode *inode);
3035*4882a593Smuzhiyun int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
3036*4882a593Smuzhiyun struct inode *btrfs_alloc_inode(struct super_block *sb);
3037*4882a593Smuzhiyun void btrfs_destroy_inode(struct inode *inode);
3038*4882a593Smuzhiyun void btrfs_free_inode(struct inode *inode);
3039*4882a593Smuzhiyun int btrfs_drop_inode(struct inode *inode);
3040*4882a593Smuzhiyun int __init btrfs_init_cachep(void);
3041*4882a593Smuzhiyun void __cold btrfs_destroy_cachep(void);
3042*4882a593Smuzhiyun struct inode *btrfs_iget_path(struct super_block *s, u64 ino,
3043*4882a593Smuzhiyun struct btrfs_root *root, struct btrfs_path *path);
3044*4882a593Smuzhiyun struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root);
3045*4882a593Smuzhiyun struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
3046*4882a593Smuzhiyun struct page *page, size_t pg_offset,
3047*4882a593Smuzhiyun u64 start, u64 end);
3048*4882a593Smuzhiyun int btrfs_update_inode(struct btrfs_trans_handle *trans,
3049*4882a593Smuzhiyun struct btrfs_root *root,
3050*4882a593Smuzhiyun struct inode *inode);
3051*4882a593Smuzhiyun int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans,
3052*4882a593Smuzhiyun struct btrfs_root *root, struct inode *inode);
3053*4882a593Smuzhiyun int btrfs_orphan_add(struct btrfs_trans_handle *trans,
3054*4882a593Smuzhiyun struct btrfs_inode *inode);
3055*4882a593Smuzhiyun int btrfs_orphan_cleanup(struct btrfs_root *root);
3056*4882a593Smuzhiyun int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
3057*4882a593Smuzhiyun void btrfs_add_delayed_iput(struct inode *inode);
3058*4882a593Smuzhiyun void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
3059*4882a593Smuzhiyun int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
3060*4882a593Smuzhiyun int btrfs_prealloc_file_range(struct inode *inode, int mode,
3061*4882a593Smuzhiyun u64 start, u64 num_bytes, u64 min_size,
3062*4882a593Smuzhiyun loff_t actual_len, u64 *alloc_hint);
3063*4882a593Smuzhiyun int btrfs_prealloc_file_range_trans(struct inode *inode,
3064*4882a593Smuzhiyun struct btrfs_trans_handle *trans, int mode,
3065*4882a593Smuzhiyun u64 start, u64 num_bytes, u64 min_size,
3066*4882a593Smuzhiyun loff_t actual_len, u64 *alloc_hint);
3067*4882a593Smuzhiyun int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page,
3068*4882a593Smuzhiyun u64 start, u64 end, int *page_started, unsigned long *nr_written,
3069*4882a593Smuzhiyun struct writeback_control *wbc);
3070*4882a593Smuzhiyun int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
3071*4882a593Smuzhiyun void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
3072*4882a593Smuzhiyun u64 end, int uptodate);
3073*4882a593Smuzhiyun extern const struct dentry_operations btrfs_dentry_operations;
3074*4882a593Smuzhiyun ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
3075*4882a593Smuzhiyun
3076*4882a593Smuzhiyun /* ioctl.c */
3077*4882a593Smuzhiyun long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
3078*4882a593Smuzhiyun long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
3079*4882a593Smuzhiyun int btrfs_ioctl_get_supported_features(void __user *arg);
3080*4882a593Smuzhiyun void btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
3081*4882a593Smuzhiyun int __pure btrfs_is_empty_uuid(u8 *uuid);
3082*4882a593Smuzhiyun int btrfs_defrag_file(struct inode *inode, struct file *file,
3083*4882a593Smuzhiyun struct btrfs_ioctl_defrag_range_args *range,
3084*4882a593Smuzhiyun u64 newer_than, unsigned long max_pages);
3085*4882a593Smuzhiyun void btrfs_get_block_group_info(struct list_head *groups_list,
3086*4882a593Smuzhiyun struct btrfs_ioctl_space_info *space);
3087*4882a593Smuzhiyun void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
3088*4882a593Smuzhiyun struct btrfs_ioctl_balance_args *bargs);
3089*4882a593Smuzhiyun bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
3090*4882a593Smuzhiyun enum btrfs_exclusive_operation type);
3091*4882a593Smuzhiyun void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
3092*4882a593Smuzhiyun
3093*4882a593Smuzhiyun /* file.c */
3094*4882a593Smuzhiyun int __init btrfs_auto_defrag_init(void);
3095*4882a593Smuzhiyun void __cold btrfs_auto_defrag_exit(void);
3096*4882a593Smuzhiyun int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
3097*4882a593Smuzhiyun struct btrfs_inode *inode);
3098*4882a593Smuzhiyun int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
3099*4882a593Smuzhiyun void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
3100*4882a593Smuzhiyun int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
3101*4882a593Smuzhiyun void btrfs_drop_extent_cache(struct btrfs_inode *inode, u64 start, u64 end,
3102*4882a593Smuzhiyun int skip_pinned);
3103*4882a593Smuzhiyun extern const struct file_operations btrfs_file_operations;
3104*4882a593Smuzhiyun int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
3105*4882a593Smuzhiyun struct btrfs_root *root, struct btrfs_inode *inode,
3106*4882a593Smuzhiyun struct btrfs_path *path, u64 start, u64 end,
3107*4882a593Smuzhiyun u64 *drop_end, int drop_cache,
3108*4882a593Smuzhiyun int replace_extent,
3109*4882a593Smuzhiyun u32 extent_item_size,
3110*4882a593Smuzhiyun int *key_inserted);
3111*4882a593Smuzhiyun int btrfs_drop_extents(struct btrfs_trans_handle *trans,
3112*4882a593Smuzhiyun struct btrfs_root *root, struct inode *inode, u64 start,
3113*4882a593Smuzhiyun u64 end, int drop_cache);
3114*4882a593Smuzhiyun int btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path,
3115*4882a593Smuzhiyun const u64 start, const u64 end,
3116*4882a593Smuzhiyun struct btrfs_replace_extent_info *extent_info,
3117*4882a593Smuzhiyun struct btrfs_trans_handle **trans_out);
3118*4882a593Smuzhiyun int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
3119*4882a593Smuzhiyun struct btrfs_inode *inode, u64 start, u64 end);
3120*4882a593Smuzhiyun int btrfs_release_file(struct inode *inode, struct file *file);
3121*4882a593Smuzhiyun int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
3122*4882a593Smuzhiyun size_t num_pages, loff_t pos, size_t write_bytes,
3123*4882a593Smuzhiyun struct extent_state **cached);
3124*4882a593Smuzhiyun int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
3125*4882a593Smuzhiyun int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
3126*4882a593Smuzhiyun size_t *write_bytes);
3127*4882a593Smuzhiyun void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
3128*4882a593Smuzhiyun
3129*4882a593Smuzhiyun /* tree-defrag.c */
3130*4882a593Smuzhiyun int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
3131*4882a593Smuzhiyun struct btrfs_root *root);
3132*4882a593Smuzhiyun
3133*4882a593Smuzhiyun /* super.c */
3134*4882a593Smuzhiyun int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
3135*4882a593Smuzhiyun unsigned long new_flags);
3136*4882a593Smuzhiyun int btrfs_sync_fs(struct super_block *sb, int wait);
3137*4882a593Smuzhiyun char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
3138*4882a593Smuzhiyun u64 subvol_objectid);
3139*4882a593Smuzhiyun
3140*4882a593Smuzhiyun static inline __printf(2, 3) __cold
btrfs_no_printk(const struct btrfs_fs_info * fs_info,const char * fmt,...)3141*4882a593Smuzhiyun void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
3142*4882a593Smuzhiyun {
3143*4882a593Smuzhiyun }
3144*4882a593Smuzhiyun
3145*4882a593Smuzhiyun #ifdef CONFIG_PRINTK
3146*4882a593Smuzhiyun __printf(2, 3)
3147*4882a593Smuzhiyun __cold
3148*4882a593Smuzhiyun void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
3149*4882a593Smuzhiyun #else
3150*4882a593Smuzhiyun #define btrfs_printk(fs_info, fmt, args...) \
3151*4882a593Smuzhiyun btrfs_no_printk(fs_info, fmt, ##args)
3152*4882a593Smuzhiyun #endif
3153*4882a593Smuzhiyun
3154*4882a593Smuzhiyun #define btrfs_emerg(fs_info, fmt, args...) \
3155*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
3156*4882a593Smuzhiyun #define btrfs_alert(fs_info, fmt, args...) \
3157*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
3158*4882a593Smuzhiyun #define btrfs_crit(fs_info, fmt, args...) \
3159*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
3160*4882a593Smuzhiyun #define btrfs_err(fs_info, fmt, args...) \
3161*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_ERR fmt, ##args)
3162*4882a593Smuzhiyun #define btrfs_warn(fs_info, fmt, args...) \
3163*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
3164*4882a593Smuzhiyun #define btrfs_notice(fs_info, fmt, args...) \
3165*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
3166*4882a593Smuzhiyun #define btrfs_info(fs_info, fmt, args...) \
3167*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_INFO fmt, ##args)
3168*4882a593Smuzhiyun
3169*4882a593Smuzhiyun /*
3170*4882a593Smuzhiyun * Wrappers that use printk_in_rcu
3171*4882a593Smuzhiyun */
3172*4882a593Smuzhiyun #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
3173*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
3174*4882a593Smuzhiyun #define btrfs_alert_in_rcu(fs_info, fmt, args...) \
3175*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
3176*4882a593Smuzhiyun #define btrfs_crit_in_rcu(fs_info, fmt, args...) \
3177*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
3178*4882a593Smuzhiyun #define btrfs_err_in_rcu(fs_info, fmt, args...) \
3179*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
3180*4882a593Smuzhiyun #define btrfs_warn_in_rcu(fs_info, fmt, args...) \
3181*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
3182*4882a593Smuzhiyun #define btrfs_notice_in_rcu(fs_info, fmt, args...) \
3183*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
3184*4882a593Smuzhiyun #define btrfs_info_in_rcu(fs_info, fmt, args...) \
3185*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
3186*4882a593Smuzhiyun
3187*4882a593Smuzhiyun /*
3188*4882a593Smuzhiyun * Wrappers that use a ratelimited printk_in_rcu
3189*4882a593Smuzhiyun */
3190*4882a593Smuzhiyun #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
3191*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
3192*4882a593Smuzhiyun #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
3193*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
3194*4882a593Smuzhiyun #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
3195*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
3196*4882a593Smuzhiyun #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
3197*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
3198*4882a593Smuzhiyun #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
3199*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
3200*4882a593Smuzhiyun #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
3201*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
3202*4882a593Smuzhiyun #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
3203*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
3204*4882a593Smuzhiyun
3205*4882a593Smuzhiyun /*
3206*4882a593Smuzhiyun * Wrappers that use a ratelimited printk
3207*4882a593Smuzhiyun */
3208*4882a593Smuzhiyun #define btrfs_emerg_rl(fs_info, fmt, args...) \
3209*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
3210*4882a593Smuzhiyun #define btrfs_alert_rl(fs_info, fmt, args...) \
3211*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
3212*4882a593Smuzhiyun #define btrfs_crit_rl(fs_info, fmt, args...) \
3213*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
3214*4882a593Smuzhiyun #define btrfs_err_rl(fs_info, fmt, args...) \
3215*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
3216*4882a593Smuzhiyun #define btrfs_warn_rl(fs_info, fmt, args...) \
3217*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
3218*4882a593Smuzhiyun #define btrfs_notice_rl(fs_info, fmt, args...) \
3219*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
3220*4882a593Smuzhiyun #define btrfs_info_rl(fs_info, fmt, args...) \
3221*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
3222*4882a593Smuzhiyun
3223*4882a593Smuzhiyun #if defined(CONFIG_DYNAMIC_DEBUG)
3224*4882a593Smuzhiyun #define btrfs_debug(fs_info, fmt, args...) \
3225*4882a593Smuzhiyun _dynamic_func_call_no_desc(fmt, btrfs_printk, \
3226*4882a593Smuzhiyun fs_info, KERN_DEBUG fmt, ##args)
3227*4882a593Smuzhiyun #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3228*4882a593Smuzhiyun _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
3229*4882a593Smuzhiyun fs_info, KERN_DEBUG fmt, ##args)
3230*4882a593Smuzhiyun #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
3231*4882a593Smuzhiyun _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
3232*4882a593Smuzhiyun fs_info, KERN_DEBUG fmt, ##args)
3233*4882a593Smuzhiyun #define btrfs_debug_rl(fs_info, fmt, args...) \
3234*4882a593Smuzhiyun _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
3235*4882a593Smuzhiyun fs_info, KERN_DEBUG fmt, ##args)
3236*4882a593Smuzhiyun #elif defined(DEBUG)
3237*4882a593Smuzhiyun #define btrfs_debug(fs_info, fmt, args...) \
3238*4882a593Smuzhiyun btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
3239*4882a593Smuzhiyun #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3240*4882a593Smuzhiyun btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3241*4882a593Smuzhiyun #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
3242*4882a593Smuzhiyun btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3243*4882a593Smuzhiyun #define btrfs_debug_rl(fs_info, fmt, args...) \
3244*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
3245*4882a593Smuzhiyun #else
3246*4882a593Smuzhiyun #define btrfs_debug(fs_info, fmt, args...) \
3247*4882a593Smuzhiyun btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
3248*4882a593Smuzhiyun #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3249*4882a593Smuzhiyun btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3250*4882a593Smuzhiyun #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
3251*4882a593Smuzhiyun btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3252*4882a593Smuzhiyun #define btrfs_debug_rl(fs_info, fmt, args...) \
3253*4882a593Smuzhiyun btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
3254*4882a593Smuzhiyun #endif
3255*4882a593Smuzhiyun
3256*4882a593Smuzhiyun #define btrfs_printk_in_rcu(fs_info, fmt, args...) \
3257*4882a593Smuzhiyun do { \
3258*4882a593Smuzhiyun rcu_read_lock(); \
3259*4882a593Smuzhiyun btrfs_printk(fs_info, fmt, ##args); \
3260*4882a593Smuzhiyun rcu_read_unlock(); \
3261*4882a593Smuzhiyun } while (0)
3262*4882a593Smuzhiyun
3263*4882a593Smuzhiyun #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \
3264*4882a593Smuzhiyun do { \
3265*4882a593Smuzhiyun rcu_read_lock(); \
3266*4882a593Smuzhiyun btrfs_no_printk(fs_info, fmt, ##args); \
3267*4882a593Smuzhiyun rcu_read_unlock(); \
3268*4882a593Smuzhiyun } while (0)
3269*4882a593Smuzhiyun
3270*4882a593Smuzhiyun #define btrfs_printk_ratelimited(fs_info, fmt, args...) \
3271*4882a593Smuzhiyun do { \
3272*4882a593Smuzhiyun static DEFINE_RATELIMIT_STATE(_rs, \
3273*4882a593Smuzhiyun DEFAULT_RATELIMIT_INTERVAL, \
3274*4882a593Smuzhiyun DEFAULT_RATELIMIT_BURST); \
3275*4882a593Smuzhiyun if (__ratelimit(&_rs)) \
3276*4882a593Smuzhiyun btrfs_printk(fs_info, fmt, ##args); \
3277*4882a593Smuzhiyun } while (0)
3278*4882a593Smuzhiyun
3279*4882a593Smuzhiyun #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
3280*4882a593Smuzhiyun do { \
3281*4882a593Smuzhiyun rcu_read_lock(); \
3282*4882a593Smuzhiyun btrfs_printk_ratelimited(fs_info, fmt, ##args); \
3283*4882a593Smuzhiyun rcu_read_unlock(); \
3284*4882a593Smuzhiyun } while (0)
3285*4882a593Smuzhiyun
3286*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_ASSERT
3287*4882a593Smuzhiyun __cold __noreturn
assertfail(const char * expr,const char * file,int line)3288*4882a593Smuzhiyun static inline void assertfail(const char *expr, const char *file, int line)
3289*4882a593Smuzhiyun {
3290*4882a593Smuzhiyun pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
3291*4882a593Smuzhiyun BUG();
3292*4882a593Smuzhiyun }
3293*4882a593Smuzhiyun
3294*4882a593Smuzhiyun #define ASSERT(expr) \
3295*4882a593Smuzhiyun (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
3296*4882a593Smuzhiyun
3297*4882a593Smuzhiyun #else
assertfail(const char * expr,const char * file,int line)3298*4882a593Smuzhiyun static inline void assertfail(const char *expr, const char* file, int line) { }
3299*4882a593Smuzhiyun #define ASSERT(expr) (void)(expr)
3300*4882a593Smuzhiyun #endif
3301*4882a593Smuzhiyun
3302*4882a593Smuzhiyun /*
3303*4882a593Smuzhiyun * Use that for functions that are conditionally exported for sanity tests but
3304*4882a593Smuzhiyun * otherwise static
3305*4882a593Smuzhiyun */
3306*4882a593Smuzhiyun #ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3307*4882a593Smuzhiyun #define EXPORT_FOR_TESTS static
3308*4882a593Smuzhiyun #else
3309*4882a593Smuzhiyun #define EXPORT_FOR_TESTS
3310*4882a593Smuzhiyun #endif
3311*4882a593Smuzhiyun
3312*4882a593Smuzhiyun __cold
btrfs_print_v0_err(struct btrfs_fs_info * fs_info)3313*4882a593Smuzhiyun static inline void btrfs_print_v0_err(struct btrfs_fs_info *fs_info)
3314*4882a593Smuzhiyun {
3315*4882a593Smuzhiyun btrfs_err(fs_info,
3316*4882a593Smuzhiyun "Unsupported V0 extent filesystem detected. Aborting. Please re-create your filesystem with a newer kernel");
3317*4882a593Smuzhiyun }
3318*4882a593Smuzhiyun
3319*4882a593Smuzhiyun __printf(5, 6)
3320*4882a593Smuzhiyun __cold
3321*4882a593Smuzhiyun void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
3322*4882a593Smuzhiyun unsigned int line, int errno, const char *fmt, ...);
3323*4882a593Smuzhiyun
3324*4882a593Smuzhiyun const char * __attribute_const__ btrfs_decode_error(int errno);
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun __cold
3327*4882a593Smuzhiyun void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
3328*4882a593Smuzhiyun const char *function,
3329*4882a593Smuzhiyun unsigned int line, int errno);
3330*4882a593Smuzhiyun
3331*4882a593Smuzhiyun /*
3332*4882a593Smuzhiyun * Call btrfs_abort_transaction as early as possible when an error condition is
3333*4882a593Smuzhiyun * detected, that way the exact line number is reported.
3334*4882a593Smuzhiyun */
3335*4882a593Smuzhiyun #define btrfs_abort_transaction(trans, errno) \
3336*4882a593Smuzhiyun do { \
3337*4882a593Smuzhiyun /* Report first abort since mount */ \
3338*4882a593Smuzhiyun if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \
3339*4882a593Smuzhiyun &((trans)->fs_info->fs_state))) { \
3340*4882a593Smuzhiyun if ((errno) != -EIO && (errno) != -EROFS) { \
3341*4882a593Smuzhiyun WARN(1, KERN_DEBUG \
3342*4882a593Smuzhiyun "BTRFS: Transaction aborted (error %d)\n", \
3343*4882a593Smuzhiyun (errno)); \
3344*4882a593Smuzhiyun } else { \
3345*4882a593Smuzhiyun btrfs_debug((trans)->fs_info, \
3346*4882a593Smuzhiyun "Transaction aborted (error %d)", \
3347*4882a593Smuzhiyun (errno)); \
3348*4882a593Smuzhiyun } \
3349*4882a593Smuzhiyun } \
3350*4882a593Smuzhiyun __btrfs_abort_transaction((trans), __func__, \
3351*4882a593Smuzhiyun __LINE__, (errno)); \
3352*4882a593Smuzhiyun } while (0)
3353*4882a593Smuzhiyun
3354*4882a593Smuzhiyun #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \
3355*4882a593Smuzhiyun do { \
3356*4882a593Smuzhiyun __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \
3357*4882a593Smuzhiyun (errno), fmt, ##args); \
3358*4882a593Smuzhiyun } while (0)
3359*4882a593Smuzhiyun
3360*4882a593Smuzhiyun __printf(5, 6)
3361*4882a593Smuzhiyun __cold
3362*4882a593Smuzhiyun void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
3363*4882a593Smuzhiyun unsigned int line, int errno, const char *fmt, ...);
3364*4882a593Smuzhiyun /*
3365*4882a593Smuzhiyun * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
3366*4882a593Smuzhiyun * will panic(). Otherwise we BUG() here.
3367*4882a593Smuzhiyun */
3368*4882a593Smuzhiyun #define btrfs_panic(fs_info, errno, fmt, args...) \
3369*4882a593Smuzhiyun do { \
3370*4882a593Smuzhiyun __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
3371*4882a593Smuzhiyun BUG(); \
3372*4882a593Smuzhiyun } while (0)
3373*4882a593Smuzhiyun
3374*4882a593Smuzhiyun
3375*4882a593Smuzhiyun /* compatibility and incompatibility defines */
3376*4882a593Smuzhiyun
3377*4882a593Smuzhiyun #define btrfs_set_fs_incompat(__fs_info, opt) \
3378*4882a593Smuzhiyun __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3379*4882a593Smuzhiyun #opt)
3380*4882a593Smuzhiyun
__btrfs_set_fs_incompat(struct btrfs_fs_info * fs_info,u64 flag,const char * name)3381*4882a593Smuzhiyun static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
3382*4882a593Smuzhiyun u64 flag, const char* name)
3383*4882a593Smuzhiyun {
3384*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3385*4882a593Smuzhiyun u64 features;
3386*4882a593Smuzhiyun
3387*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3388*4882a593Smuzhiyun features = btrfs_super_incompat_flags(disk_super);
3389*4882a593Smuzhiyun if (!(features & flag)) {
3390*4882a593Smuzhiyun spin_lock(&fs_info->super_lock);
3391*4882a593Smuzhiyun features = btrfs_super_incompat_flags(disk_super);
3392*4882a593Smuzhiyun if (!(features & flag)) {
3393*4882a593Smuzhiyun features |= flag;
3394*4882a593Smuzhiyun btrfs_set_super_incompat_flags(disk_super, features);
3395*4882a593Smuzhiyun btrfs_info(fs_info,
3396*4882a593Smuzhiyun "setting incompat feature flag for %s (0x%llx)",
3397*4882a593Smuzhiyun name, flag);
3398*4882a593Smuzhiyun }
3399*4882a593Smuzhiyun spin_unlock(&fs_info->super_lock);
3400*4882a593Smuzhiyun }
3401*4882a593Smuzhiyun }
3402*4882a593Smuzhiyun
3403*4882a593Smuzhiyun #define btrfs_clear_fs_incompat(__fs_info, opt) \
3404*4882a593Smuzhiyun __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3405*4882a593Smuzhiyun #opt)
3406*4882a593Smuzhiyun
__btrfs_clear_fs_incompat(struct btrfs_fs_info * fs_info,u64 flag,const char * name)3407*4882a593Smuzhiyun static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
3408*4882a593Smuzhiyun u64 flag, const char* name)
3409*4882a593Smuzhiyun {
3410*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3411*4882a593Smuzhiyun u64 features;
3412*4882a593Smuzhiyun
3413*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3414*4882a593Smuzhiyun features = btrfs_super_incompat_flags(disk_super);
3415*4882a593Smuzhiyun if (features & flag) {
3416*4882a593Smuzhiyun spin_lock(&fs_info->super_lock);
3417*4882a593Smuzhiyun features = btrfs_super_incompat_flags(disk_super);
3418*4882a593Smuzhiyun if (features & flag) {
3419*4882a593Smuzhiyun features &= ~flag;
3420*4882a593Smuzhiyun btrfs_set_super_incompat_flags(disk_super, features);
3421*4882a593Smuzhiyun btrfs_info(fs_info,
3422*4882a593Smuzhiyun "clearing incompat feature flag for %s (0x%llx)",
3423*4882a593Smuzhiyun name, flag);
3424*4882a593Smuzhiyun }
3425*4882a593Smuzhiyun spin_unlock(&fs_info->super_lock);
3426*4882a593Smuzhiyun }
3427*4882a593Smuzhiyun }
3428*4882a593Smuzhiyun
3429*4882a593Smuzhiyun #define btrfs_fs_incompat(fs_info, opt) \
3430*4882a593Smuzhiyun __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3431*4882a593Smuzhiyun
__btrfs_fs_incompat(struct btrfs_fs_info * fs_info,u64 flag)3432*4882a593Smuzhiyun static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
3433*4882a593Smuzhiyun {
3434*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3435*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3436*4882a593Smuzhiyun return !!(btrfs_super_incompat_flags(disk_super) & flag);
3437*4882a593Smuzhiyun }
3438*4882a593Smuzhiyun
3439*4882a593Smuzhiyun #define btrfs_set_fs_compat_ro(__fs_info, opt) \
3440*4882a593Smuzhiyun __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3441*4882a593Smuzhiyun #opt)
3442*4882a593Smuzhiyun
__btrfs_set_fs_compat_ro(struct btrfs_fs_info * fs_info,u64 flag,const char * name)3443*4882a593Smuzhiyun static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info,
3444*4882a593Smuzhiyun u64 flag, const char *name)
3445*4882a593Smuzhiyun {
3446*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3447*4882a593Smuzhiyun u64 features;
3448*4882a593Smuzhiyun
3449*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3450*4882a593Smuzhiyun features = btrfs_super_compat_ro_flags(disk_super);
3451*4882a593Smuzhiyun if (!(features & flag)) {
3452*4882a593Smuzhiyun spin_lock(&fs_info->super_lock);
3453*4882a593Smuzhiyun features = btrfs_super_compat_ro_flags(disk_super);
3454*4882a593Smuzhiyun if (!(features & flag)) {
3455*4882a593Smuzhiyun features |= flag;
3456*4882a593Smuzhiyun btrfs_set_super_compat_ro_flags(disk_super, features);
3457*4882a593Smuzhiyun btrfs_info(fs_info,
3458*4882a593Smuzhiyun "setting compat-ro feature flag for %s (0x%llx)",
3459*4882a593Smuzhiyun name, flag);
3460*4882a593Smuzhiyun }
3461*4882a593Smuzhiyun spin_unlock(&fs_info->super_lock);
3462*4882a593Smuzhiyun }
3463*4882a593Smuzhiyun }
3464*4882a593Smuzhiyun
3465*4882a593Smuzhiyun #define btrfs_clear_fs_compat_ro(__fs_info, opt) \
3466*4882a593Smuzhiyun __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3467*4882a593Smuzhiyun #opt)
3468*4882a593Smuzhiyun
__btrfs_clear_fs_compat_ro(struct btrfs_fs_info * fs_info,u64 flag,const char * name)3469*4882a593Smuzhiyun static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
3470*4882a593Smuzhiyun u64 flag, const char *name)
3471*4882a593Smuzhiyun {
3472*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3473*4882a593Smuzhiyun u64 features;
3474*4882a593Smuzhiyun
3475*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3476*4882a593Smuzhiyun features = btrfs_super_compat_ro_flags(disk_super);
3477*4882a593Smuzhiyun if (features & flag) {
3478*4882a593Smuzhiyun spin_lock(&fs_info->super_lock);
3479*4882a593Smuzhiyun features = btrfs_super_compat_ro_flags(disk_super);
3480*4882a593Smuzhiyun if (features & flag) {
3481*4882a593Smuzhiyun features &= ~flag;
3482*4882a593Smuzhiyun btrfs_set_super_compat_ro_flags(disk_super, features);
3483*4882a593Smuzhiyun btrfs_info(fs_info,
3484*4882a593Smuzhiyun "clearing compat-ro feature flag for %s (0x%llx)",
3485*4882a593Smuzhiyun name, flag);
3486*4882a593Smuzhiyun }
3487*4882a593Smuzhiyun spin_unlock(&fs_info->super_lock);
3488*4882a593Smuzhiyun }
3489*4882a593Smuzhiyun }
3490*4882a593Smuzhiyun
3491*4882a593Smuzhiyun #define btrfs_fs_compat_ro(fs_info, opt) \
3492*4882a593Smuzhiyun __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3493*4882a593Smuzhiyun
__btrfs_fs_compat_ro(struct btrfs_fs_info * fs_info,u64 flag)3494*4882a593Smuzhiyun static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
3495*4882a593Smuzhiyun {
3496*4882a593Smuzhiyun struct btrfs_super_block *disk_super;
3497*4882a593Smuzhiyun disk_super = fs_info->super_copy;
3498*4882a593Smuzhiyun return !!(btrfs_super_compat_ro_flags(disk_super) & flag);
3499*4882a593Smuzhiyun }
3500*4882a593Smuzhiyun
3501*4882a593Smuzhiyun /* acl.c */
3502*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_FS_POSIX_ACL
3503*4882a593Smuzhiyun struct posix_acl *btrfs_get_acl(struct inode *inode, int type);
3504*4882a593Smuzhiyun int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
3505*4882a593Smuzhiyun int btrfs_init_acl(struct btrfs_trans_handle *trans,
3506*4882a593Smuzhiyun struct inode *inode, struct inode *dir);
3507*4882a593Smuzhiyun #else
3508*4882a593Smuzhiyun #define btrfs_get_acl NULL
3509*4882a593Smuzhiyun #define btrfs_set_acl NULL
btrfs_init_acl(struct btrfs_trans_handle * trans,struct inode * inode,struct inode * dir)3510*4882a593Smuzhiyun static inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
3511*4882a593Smuzhiyun struct inode *inode, struct inode *dir)
3512*4882a593Smuzhiyun {
3513*4882a593Smuzhiyun return 0;
3514*4882a593Smuzhiyun }
3515*4882a593Smuzhiyun #endif
3516*4882a593Smuzhiyun
3517*4882a593Smuzhiyun /* relocation.c */
3518*4882a593Smuzhiyun int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start);
3519*4882a593Smuzhiyun int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
3520*4882a593Smuzhiyun struct btrfs_root *root);
3521*4882a593Smuzhiyun int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
3522*4882a593Smuzhiyun struct btrfs_root *root);
3523*4882a593Smuzhiyun int btrfs_recover_relocation(struct btrfs_root *root);
3524*4882a593Smuzhiyun int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len);
3525*4882a593Smuzhiyun int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
3526*4882a593Smuzhiyun struct btrfs_root *root, struct extent_buffer *buf,
3527*4882a593Smuzhiyun struct extent_buffer *cow);
3528*4882a593Smuzhiyun void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending,
3529*4882a593Smuzhiyun u64 *bytes_to_reserve);
3530*4882a593Smuzhiyun int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
3531*4882a593Smuzhiyun struct btrfs_pending_snapshot *pending);
3532*4882a593Smuzhiyun int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info);
3533*4882a593Smuzhiyun struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info,
3534*4882a593Smuzhiyun u64 bytenr);
3535*4882a593Smuzhiyun int btrfs_should_ignore_reloc_root(struct btrfs_root *root);
3536*4882a593Smuzhiyun
3537*4882a593Smuzhiyun /* scrub.c */
3538*4882a593Smuzhiyun int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3539*4882a593Smuzhiyun u64 end, struct btrfs_scrub_progress *progress,
3540*4882a593Smuzhiyun int readonly, int is_dev_replace);
3541*4882a593Smuzhiyun void btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
3542*4882a593Smuzhiyun void btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
3543*4882a593Smuzhiyun int btrfs_scrub_cancel(struct btrfs_fs_info *info);
3544*4882a593Smuzhiyun int btrfs_scrub_cancel_dev(struct btrfs_device *dev);
3545*4882a593Smuzhiyun int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
3546*4882a593Smuzhiyun struct btrfs_scrub_progress *progress);
btrfs_init_full_stripe_locks_tree(struct btrfs_full_stripe_locks_tree * locks_root)3547*4882a593Smuzhiyun static inline void btrfs_init_full_stripe_locks_tree(
3548*4882a593Smuzhiyun struct btrfs_full_stripe_locks_tree *locks_root)
3549*4882a593Smuzhiyun {
3550*4882a593Smuzhiyun locks_root->root = RB_ROOT;
3551*4882a593Smuzhiyun mutex_init(&locks_root->lock);
3552*4882a593Smuzhiyun }
3553*4882a593Smuzhiyun
3554*4882a593Smuzhiyun /* dev-replace.c */
3555*4882a593Smuzhiyun void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info);
3556*4882a593Smuzhiyun void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info);
3557*4882a593Smuzhiyun void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount);
3558*4882a593Smuzhiyun
btrfs_bio_counter_dec(struct btrfs_fs_info * fs_info)3559*4882a593Smuzhiyun static inline void btrfs_bio_counter_dec(struct btrfs_fs_info *fs_info)
3560*4882a593Smuzhiyun {
3561*4882a593Smuzhiyun btrfs_bio_counter_sub(fs_info, 1);
3562*4882a593Smuzhiyun }
3563*4882a593Smuzhiyun
3564*4882a593Smuzhiyun /* reada.c */
3565*4882a593Smuzhiyun struct reada_control {
3566*4882a593Smuzhiyun struct btrfs_fs_info *fs_info; /* tree to prefetch */
3567*4882a593Smuzhiyun struct btrfs_key key_start;
3568*4882a593Smuzhiyun struct btrfs_key key_end; /* exclusive */
3569*4882a593Smuzhiyun atomic_t elems;
3570*4882a593Smuzhiyun struct kref refcnt;
3571*4882a593Smuzhiyun wait_queue_head_t wait;
3572*4882a593Smuzhiyun };
3573*4882a593Smuzhiyun struct reada_control *btrfs_reada_add(struct btrfs_root *root,
3574*4882a593Smuzhiyun struct btrfs_key *start, struct btrfs_key *end);
3575*4882a593Smuzhiyun int btrfs_reada_wait(void *handle);
3576*4882a593Smuzhiyun void btrfs_reada_detach(void *handle);
3577*4882a593Smuzhiyun int btree_readahead_hook(struct extent_buffer *eb, int err);
3578*4882a593Smuzhiyun void btrfs_reada_remove_dev(struct btrfs_device *dev);
3579*4882a593Smuzhiyun void btrfs_reada_undo_remove_dev(struct btrfs_device *dev);
3580*4882a593Smuzhiyun
is_fstree(u64 rootid)3581*4882a593Smuzhiyun static inline int is_fstree(u64 rootid)
3582*4882a593Smuzhiyun {
3583*4882a593Smuzhiyun if (rootid == BTRFS_FS_TREE_OBJECTID ||
3584*4882a593Smuzhiyun ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID &&
3585*4882a593Smuzhiyun !btrfs_qgroup_level(rootid)))
3586*4882a593Smuzhiyun return 1;
3587*4882a593Smuzhiyun return 0;
3588*4882a593Smuzhiyun }
3589*4882a593Smuzhiyun
btrfs_defrag_cancelled(struct btrfs_fs_info * fs_info)3590*4882a593Smuzhiyun static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
3591*4882a593Smuzhiyun {
3592*4882a593Smuzhiyun return signal_pending(current);
3593*4882a593Smuzhiyun }
3594*4882a593Smuzhiyun
3595*4882a593Smuzhiyun #define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
3596*4882a593Smuzhiyun
3597*4882a593Smuzhiyun /* Sanity test specific functions */
3598*4882a593Smuzhiyun #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3599*4882a593Smuzhiyun void btrfs_test_destroy_inode(struct inode *inode);
btrfs_is_testing(struct btrfs_fs_info * fs_info)3600*4882a593Smuzhiyun static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
3601*4882a593Smuzhiyun {
3602*4882a593Smuzhiyun return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
3603*4882a593Smuzhiyun }
3604*4882a593Smuzhiyun #else
btrfs_is_testing(struct btrfs_fs_info * fs_info)3605*4882a593Smuzhiyun static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
3606*4882a593Smuzhiyun {
3607*4882a593Smuzhiyun return 0;
3608*4882a593Smuzhiyun }
3609*4882a593Smuzhiyun #endif
3610*4882a593Smuzhiyun
3611*4882a593Smuzhiyun #endif
3612