xref: /openbmc/linux/fs/btrfs/fs.h (revision 13bb483d)
1c7f13d42SJosef Bacik /* SPDX-License-Identifier: GPL-2.0 */
2c7f13d42SJosef Bacik 
3c7f13d42SJosef Bacik #ifndef BTRFS_FS_H
4c7f13d42SJosef Bacik #define BTRFS_FS_H
5c7f13d42SJosef Bacik 
6243cf8d1SChristoph Hellwig #include <linux/blkdev.h>
73683fbbcSJosef Bacik #include <linux/fs.h>
83683fbbcSJosef Bacik #include <linux/btrfs_tree.h>
93683fbbcSJosef Bacik #include <linux/sizes.h>
103683fbbcSJosef Bacik #include "extent-io-tree.h"
113683fbbcSJosef Bacik #include "extent_map.h"
123683fbbcSJosef Bacik #include "async-thread.h"
133683fbbcSJosef Bacik #include "block-rsv.h"
143683fbbcSJosef Bacik 
15a56159d4SJosef Bacik #define BTRFS_MAX_EXTENT_SIZE SZ_128M
16a56159d4SJosef Bacik 
17a56159d4SJosef Bacik #define BTRFS_OLDEST_GENERATION	0ULL
18a56159d4SJosef Bacik 
19a56159d4SJosef Bacik #define BTRFS_EMPTY_DIR_SIZE 0
20a56159d4SJosef Bacik 
21a56159d4SJosef Bacik #define BTRFS_DIRTY_METADATA_THRESH		SZ_32M
22a56159d4SJosef Bacik 
23a56159d4SJosef Bacik #define BTRFS_SUPER_INFO_OFFSET			SZ_64K
24a56159d4SJosef Bacik #define BTRFS_SUPER_INFO_SIZE			4096
25a56159d4SJosef Bacik static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
26a56159d4SJosef Bacik 
27a56159d4SJosef Bacik /*
285630e2bcSFilipe Manana  * Number of metadata items necessary for an unlink operation:
295630e2bcSFilipe Manana  *
305630e2bcSFilipe Manana  * 1 for the possible orphan item
315630e2bcSFilipe Manana  * 1 for the dir item
325630e2bcSFilipe Manana  * 1 for the dir index
335630e2bcSFilipe Manana  * 1 for the inode ref
345630e2bcSFilipe Manana  * 1 for the inode
355630e2bcSFilipe Manana  * 1 for the parent inode
365630e2bcSFilipe Manana  */
375630e2bcSFilipe Manana #define BTRFS_UNLINK_METADATA_UNITS		6
385630e2bcSFilipe Manana 
395630e2bcSFilipe Manana /*
40a56159d4SJosef Bacik  * The reserved space at the beginning of each device.  It covers the primary
41a56159d4SJosef Bacik  * super block and leaves space for potential use by other tools like
42a56159d4SJosef Bacik  * bootloaders or to lower potential damage of accidental overwrite.
43a56159d4SJosef Bacik  */
44a56159d4SJosef Bacik #define BTRFS_DEVICE_RANGE_RESERVED			(SZ_1M)
45ec8eb376SJosef Bacik /*
46ec8eb376SJosef Bacik  * Runtime (in-memory) states of filesystem
47ec8eb376SJosef Bacik  */
48ec8eb376SJosef Bacik enum {
49ec8eb376SJosef Bacik 	/*
50ec8eb376SJosef Bacik 	 * Filesystem is being remounted, allow to skip some operations, like
51ec8eb376SJosef Bacik 	 * defrag
52ec8eb376SJosef Bacik 	 */
53ec8eb376SJosef Bacik 	BTRFS_FS_STATE_REMOUNTING,
54ec8eb376SJosef Bacik 	/* Filesystem in RO mode */
55ec8eb376SJosef Bacik 	BTRFS_FS_STATE_RO,
56ec8eb376SJosef Bacik 	/* Track if a transaction abort has been reported on this filesystem */
57ec8eb376SJosef Bacik 	BTRFS_FS_STATE_TRANS_ABORTED,
58ec8eb376SJosef Bacik 	/*
59ec8eb376SJosef Bacik 	 * Bio operations should be blocked on this filesystem because a source
60ec8eb376SJosef Bacik 	 * or target device is being destroyed as part of a device replace
61ec8eb376SJosef Bacik 	 */
62ec8eb376SJosef Bacik 	BTRFS_FS_STATE_DEV_REPLACING,
63ec8eb376SJosef Bacik 	/* The btrfs_fs_info created for self-tests */
64ec8eb376SJosef Bacik 	BTRFS_FS_STATE_DUMMY_FS_INFO,
65ec8eb376SJosef Bacik 
66ec8eb376SJosef Bacik 	BTRFS_FS_STATE_NO_CSUMS,
67ec8eb376SJosef Bacik 
68ec8eb376SJosef Bacik 	/* Indicates there was an error cleaning up a log tree. */
69ec8eb376SJosef Bacik 	BTRFS_FS_STATE_LOG_CLEANUP_ERROR,
70ec8eb376SJosef Bacik 
71ec8eb376SJosef Bacik 	BTRFS_FS_STATE_COUNT
72ec8eb376SJosef Bacik };
73ec8eb376SJosef Bacik 
747966a6b5SJosef Bacik enum {
757966a6b5SJosef Bacik 	BTRFS_FS_CLOSING_START,
767966a6b5SJosef Bacik 	BTRFS_FS_CLOSING_DONE,
777966a6b5SJosef Bacik 	BTRFS_FS_LOG_RECOVERING,
787966a6b5SJosef Bacik 	BTRFS_FS_OPEN,
797966a6b5SJosef Bacik 	BTRFS_FS_QUOTA_ENABLED,
807966a6b5SJosef Bacik 	BTRFS_FS_UPDATE_UUID_TREE_GEN,
817966a6b5SJosef Bacik 	BTRFS_FS_CREATING_FREE_SPACE_TREE,
827966a6b5SJosef Bacik 	BTRFS_FS_BTREE_ERR,
837966a6b5SJosef Bacik 	BTRFS_FS_LOG1_ERR,
847966a6b5SJosef Bacik 	BTRFS_FS_LOG2_ERR,
857966a6b5SJosef Bacik 	BTRFS_FS_QUOTA_OVERRIDE,
867966a6b5SJosef Bacik 	/* Used to record internally whether fs has been frozen */
877966a6b5SJosef Bacik 	BTRFS_FS_FROZEN,
887966a6b5SJosef Bacik 	/*
897966a6b5SJosef Bacik 	 * Indicate that balance has been set up from the ioctl and is in the
907966a6b5SJosef Bacik 	 * main phase. The fs_info::balance_ctl is initialized.
917966a6b5SJosef Bacik 	 */
927966a6b5SJosef Bacik 	BTRFS_FS_BALANCE_RUNNING,
937966a6b5SJosef Bacik 
947966a6b5SJosef Bacik 	/*
957966a6b5SJosef Bacik 	 * Indicate that relocation of a chunk has started, it's set per chunk
967966a6b5SJosef Bacik 	 * and is toggled between chunks.
977966a6b5SJosef Bacik 	 */
987966a6b5SJosef Bacik 	BTRFS_FS_RELOC_RUNNING,
997966a6b5SJosef Bacik 
1007966a6b5SJosef Bacik 	/* Indicate that the cleaner thread is awake and doing something. */
1017966a6b5SJosef Bacik 	BTRFS_FS_CLEANER_RUNNING,
1027966a6b5SJosef Bacik 
1037966a6b5SJosef Bacik 	/*
1047966a6b5SJosef Bacik 	 * The checksumming has an optimized version and is considered fast,
1057966a6b5SJosef Bacik 	 * so we don't need to offload checksums to workqueues.
1067966a6b5SJosef Bacik 	 */
1077966a6b5SJosef Bacik 	BTRFS_FS_CSUM_IMPL_FAST,
1087966a6b5SJosef Bacik 
1097966a6b5SJosef Bacik 	/* Indicate that the discard workqueue can service discards. */
1107966a6b5SJosef Bacik 	BTRFS_FS_DISCARD_RUNNING,
1117966a6b5SJosef Bacik 
1127966a6b5SJosef Bacik 	/* Indicate that we need to cleanup space cache v1 */
1137966a6b5SJosef Bacik 	BTRFS_FS_CLEANUP_SPACE_CACHE_V1,
1147966a6b5SJosef Bacik 
1157966a6b5SJosef Bacik 	/* Indicate that we can't trust the free space tree for caching yet */
1167966a6b5SJosef Bacik 	BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
1177966a6b5SJosef Bacik 
1187966a6b5SJosef Bacik 	/* Indicate whether there are any tree modification log users */
1197966a6b5SJosef Bacik 	BTRFS_FS_TREE_MOD_LOG_USERS,
1207966a6b5SJosef Bacik 
1217966a6b5SJosef Bacik 	/* Indicate that we want the transaction kthread to commit right now. */
1227966a6b5SJosef Bacik 	BTRFS_FS_COMMIT_TRANS,
1237966a6b5SJosef Bacik 
1247966a6b5SJosef Bacik 	/* Indicate we have half completed snapshot deletions pending. */
1257966a6b5SJosef Bacik 	BTRFS_FS_UNFINISHED_DROPS,
1267966a6b5SJosef Bacik 
1277966a6b5SJosef Bacik 	/* Indicate we have to finish a zone to do next allocation. */
1287966a6b5SJosef Bacik 	BTRFS_FS_NEED_ZONE_FINISH,
1297966a6b5SJosef Bacik 
130c52cc7b7SJosef Bacik 	/* Indicate that we want to commit the transaction. */
131c52cc7b7SJosef Bacik 	BTRFS_FS_NEED_TRANS_COMMIT,
132c52cc7b7SJosef Bacik 
133bf1f1fecSJosef Bacik 	/* This is set when active zone tracking is needed. */
134bf1f1fecSJosef Bacik 	BTRFS_FS_ACTIVE_ZONE_TRACKING,
13585e79ec7SNaohiro Aota 
136b7625f46SQu Wenruo 	/*
137b7625f46SQu Wenruo 	 * Indicate if we have some features changed, this is mostly for
138b7625f46SQu Wenruo 	 * cleaner thread to update the sysfs interface.
139b7625f46SQu Wenruo 	 */
140b7625f46SQu Wenruo 	BTRFS_FS_FEATURE_CHANGED,
141b7625f46SQu Wenruo 
1427966a6b5SJosef Bacik #if BITS_PER_LONG == 32
1437966a6b5SJosef Bacik 	/* Indicate if we have error/warn message printed on 32bit systems */
1447966a6b5SJosef Bacik 	BTRFS_FS_32BIT_ERROR,
1457966a6b5SJosef Bacik 	BTRFS_FS_32BIT_WARN,
1467966a6b5SJosef Bacik #endif
1477966a6b5SJosef Bacik };
1487966a6b5SJosef Bacik 
149fc97a410SJosef Bacik /*
150fc97a410SJosef Bacik  * Flags for mount options.
151fc97a410SJosef Bacik  *
152fc97a410SJosef Bacik  * Note: don't forget to add new options to btrfs_show_options()
153fc97a410SJosef Bacik  */
154fc97a410SJosef Bacik enum {
155fc97a410SJosef Bacik 	BTRFS_MOUNT_NODATASUM			= (1UL << 0),
156fc97a410SJosef Bacik 	BTRFS_MOUNT_NODATACOW			= (1UL << 1),
157fc97a410SJosef Bacik 	BTRFS_MOUNT_NOBARRIER			= (1UL << 2),
158fc97a410SJosef Bacik 	BTRFS_MOUNT_SSD				= (1UL << 3),
159fc97a410SJosef Bacik 	BTRFS_MOUNT_DEGRADED			= (1UL << 4),
160fc97a410SJosef Bacik 	BTRFS_MOUNT_COMPRESS			= (1UL << 5),
161fc97a410SJosef Bacik 	BTRFS_MOUNT_NOTREELOG   		= (1UL << 6),
162fc97a410SJosef Bacik 	BTRFS_MOUNT_FLUSHONCOMMIT		= (1UL << 7),
163fc97a410SJosef Bacik 	BTRFS_MOUNT_SSD_SPREAD			= (1UL << 8),
164fc97a410SJosef Bacik 	BTRFS_MOUNT_NOSSD			= (1UL << 9),
165fc97a410SJosef Bacik 	BTRFS_MOUNT_DISCARD_SYNC		= (1UL << 10),
166fc97a410SJosef Bacik 	BTRFS_MOUNT_FORCE_COMPRESS      	= (1UL << 11),
167fc97a410SJosef Bacik 	BTRFS_MOUNT_SPACE_CACHE			= (1UL << 12),
168fc97a410SJosef Bacik 	BTRFS_MOUNT_CLEAR_CACHE			= (1UL << 13),
169fc97a410SJosef Bacik 	BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED	= (1UL << 14),
170fc97a410SJosef Bacik 	BTRFS_MOUNT_ENOSPC_DEBUG		= (1UL << 15),
171fc97a410SJosef Bacik 	BTRFS_MOUNT_AUTO_DEFRAG			= (1UL << 16),
172fc97a410SJosef Bacik 	BTRFS_MOUNT_USEBACKUPROOT		= (1UL << 17),
173fc97a410SJosef Bacik 	BTRFS_MOUNT_SKIP_BALANCE		= (1UL << 18),
174fc97a410SJosef Bacik 	BTRFS_MOUNT_CHECK_INTEGRITY		= (1UL << 19),
175fc97a410SJosef Bacik 	BTRFS_MOUNT_CHECK_INTEGRITY_DATA	= (1UL << 20),
176fc97a410SJosef Bacik 	BTRFS_MOUNT_PANIC_ON_FATAL_ERROR	= (1UL << 21),
177fc97a410SJosef Bacik 	BTRFS_MOUNT_RESCAN_UUID_TREE		= (1UL << 22),
178fc97a410SJosef Bacik 	BTRFS_MOUNT_FRAGMENT_DATA		= (1UL << 23),
179fc97a410SJosef Bacik 	BTRFS_MOUNT_FRAGMENT_METADATA		= (1UL << 24),
180fc97a410SJosef Bacik 	BTRFS_MOUNT_FREE_SPACE_TREE		= (1UL << 25),
181fc97a410SJosef Bacik 	BTRFS_MOUNT_NOLOGREPLAY			= (1UL << 26),
182fc97a410SJosef Bacik 	BTRFS_MOUNT_REF_VERIFY			= (1UL << 27),
183fc97a410SJosef Bacik 	BTRFS_MOUNT_DISCARD_ASYNC		= (1UL << 28),
184fc97a410SJosef Bacik 	BTRFS_MOUNT_IGNOREBADROOTS		= (1UL << 29),
185fc97a410SJosef Bacik 	BTRFS_MOUNT_IGNOREDATACSUMS		= (1UL << 30),
186fc97a410SJosef Bacik 	BTRFS_MOUNT_NODISCARD			= (1UL << 31),
187fc97a410SJosef Bacik };
188fc97a410SJosef Bacik 
189d83eb482SJosef Bacik /*
190d83eb482SJosef Bacik  * Compat flags that we support.  If any incompat flags are set other than the
191d83eb482SJosef Bacik  * ones specified below then we will fail to mount
192d83eb482SJosef Bacik  */
193d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_SUPP		0ULL
194d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_SAFE_SET		0ULL
195d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR		0ULL
196d83eb482SJosef Bacik 
197d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_RO_SUPP			\
198d83eb482SJosef Bacik 	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
199d83eb482SJosef Bacik 	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID | \
200d83eb482SJosef Bacik 	 BTRFS_FEATURE_COMPAT_RO_VERITY |		\
201d83eb482SJosef Bacik 	 BTRFS_FEATURE_COMPAT_RO_BLOCK_GROUP_TREE)
202d83eb482SJosef Bacik 
203d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET	0ULL
204d83eb482SJosef Bacik #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR	0ULL
205d83eb482SJosef Bacik 
2060f202b25SAnand Jain #define BTRFS_FEATURE_INCOMPAT_SUPP_STABLE		\
207d83eb482SJosef Bacik 	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
208d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
209d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
210d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_BIG_METADATA |		\
211d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
212d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |		\
213d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
214d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |		\
215d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
216d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_NO_HOLES	|	\
217d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID	|	\
218d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_RAID1C34	|	\
219d83eb482SJosef Bacik 	 BTRFS_FEATURE_INCOMPAT_ZONED)
2200f202b25SAnand Jain 
2210f202b25SAnand Jain #ifdef CONFIG_BTRFS_DEBUG
2220f202b25SAnand Jain 	/*
2230f202b25SAnand Jain 	 * Features under developmen like Extent tree v2 support is enabled
2240f202b25SAnand Jain 	 * only under CONFIG_BTRFS_DEBUG.
2250f202b25SAnand Jain 	 */
2260f202b25SAnand Jain #define BTRFS_FEATURE_INCOMPAT_SUPP		\
2270f202b25SAnand Jain 	(BTRFS_FEATURE_INCOMPAT_SUPP_STABLE |	\
2280f202b25SAnand Jain 	 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2)
2290f202b25SAnand Jain 
2300f202b25SAnand Jain #else
2310f202b25SAnand Jain 
2320f202b25SAnand Jain #define BTRFS_FEATURE_INCOMPAT_SUPP		\
2330f202b25SAnand Jain 	(BTRFS_FEATURE_INCOMPAT_SUPP_STABLE)
2340f202b25SAnand Jain 
235d83eb482SJosef Bacik #endif
236d83eb482SJosef Bacik 
237d83eb482SJosef Bacik #define BTRFS_FEATURE_INCOMPAT_SAFE_SET			\
238d83eb482SJosef Bacik 	(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
239d83eb482SJosef Bacik #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR		0ULL
240d83eb482SJosef Bacik 
241fc97a410SJosef Bacik #define BTRFS_DEFAULT_COMMIT_INTERVAL	(30)
242fc97a410SJosef Bacik #define BTRFS_DEFAULT_MAX_INLINE	(2048)
243fc97a410SJosef Bacik 
244a56159d4SJosef Bacik struct btrfs_dev_replace {
245a56159d4SJosef Bacik 	/* See #define above */
246a56159d4SJosef Bacik 	u64 replace_state;
247a56159d4SJosef Bacik 	/* Seconds since 1-Jan-1970 */
248a56159d4SJosef Bacik 	time64_t time_started;
249a56159d4SJosef Bacik 	/* Seconds since 1-Jan-1970 */
250a56159d4SJosef Bacik 	time64_t time_stopped;
251a56159d4SJosef Bacik 	atomic64_t num_write_errors;
252a56159d4SJosef Bacik 	atomic64_t num_uncorrectable_read_errors;
253a56159d4SJosef Bacik 
254a56159d4SJosef Bacik 	u64 cursor_left;
255a56159d4SJosef Bacik 	u64 committed_cursor_left;
256a56159d4SJosef Bacik 	u64 cursor_left_last_write_of_item;
257a56159d4SJosef Bacik 	u64 cursor_right;
258a56159d4SJosef Bacik 
259a56159d4SJosef Bacik 	/* See #define above */
260a56159d4SJosef Bacik 	u64 cont_reading_from_srcdev_mode;
261a56159d4SJosef Bacik 
262a56159d4SJosef Bacik 	int is_valid;
263a56159d4SJosef Bacik 	int item_needs_writeback;
264a56159d4SJosef Bacik 	struct btrfs_device *srcdev;
265a56159d4SJosef Bacik 	struct btrfs_device *tgtdev;
266a56159d4SJosef Bacik 
267a56159d4SJosef Bacik 	struct mutex lock_finishing_cancel_unmount;
268a56159d4SJosef Bacik 	struct rw_semaphore rwsem;
269a56159d4SJosef Bacik 
270a56159d4SJosef Bacik 	struct btrfs_scrub_progress scrub_progress;
271a56159d4SJosef Bacik 
272a56159d4SJosef Bacik 	struct percpu_counter bio_counter;
273a56159d4SJosef Bacik 	wait_queue_head_t replace_wait;
274a56159d4SJosef Bacik };
275a56159d4SJosef Bacik 
276a56159d4SJosef Bacik /*
277a56159d4SJosef Bacik  * Free clusters are used to claim free space in relatively large chunks,
278a56159d4SJosef Bacik  * allowing us to do less seeky writes. They are used for all metadata
279a56159d4SJosef Bacik  * allocations. In ssd_spread mode they are also used for data allocations.
280a56159d4SJosef Bacik  */
281a56159d4SJosef Bacik struct btrfs_free_cluster {
282a56159d4SJosef Bacik 	spinlock_t lock;
283a56159d4SJosef Bacik 	spinlock_t refill_lock;
284a56159d4SJosef Bacik 	struct rb_root root;
285a56159d4SJosef Bacik 
286a56159d4SJosef Bacik 	/* Largest extent in this cluster */
287a56159d4SJosef Bacik 	u64 max_size;
288a56159d4SJosef Bacik 
289a56159d4SJosef Bacik 	/* First extent starting offset */
290a56159d4SJosef Bacik 	u64 window_start;
291a56159d4SJosef Bacik 
292a56159d4SJosef Bacik 	/* We did a full search and couldn't create a cluster */
293a56159d4SJosef Bacik 	bool fragmented;
294a56159d4SJosef Bacik 
295a56159d4SJosef Bacik 	struct btrfs_block_group *block_group;
296a56159d4SJosef Bacik 	/*
297a56159d4SJosef Bacik 	 * When a cluster is allocated from a block group, we put the cluster
298a56159d4SJosef Bacik 	 * onto a list in the block group so that it can be freed before the
299a56159d4SJosef Bacik 	 * block group is freed.
300a56159d4SJosef Bacik 	 */
301a56159d4SJosef Bacik 	struct list_head block_group_list;
302a56159d4SJosef Bacik };
303a56159d4SJosef Bacik 
304a56159d4SJosef Bacik /* Discard control. */
305a56159d4SJosef Bacik /*
306a56159d4SJosef Bacik  * Async discard uses multiple lists to differentiate the discard filter
307a56159d4SJosef Bacik  * parameters.  Index 0 is for completely free block groups where we need to
308a56159d4SJosef Bacik  * ensure the entire block group is trimmed without being lossy.  Indices
309a56159d4SJosef Bacik  * afterwards represent monotonically decreasing discard filter sizes to
310a56159d4SJosef Bacik  * prioritize what should be discarded next.
311a56159d4SJosef Bacik  */
312a56159d4SJosef Bacik #define BTRFS_NR_DISCARD_LISTS		3
313a56159d4SJosef Bacik #define BTRFS_DISCARD_INDEX_UNUSED	0
314a56159d4SJosef Bacik #define BTRFS_DISCARD_INDEX_START	1
315a56159d4SJosef Bacik 
316a56159d4SJosef Bacik struct btrfs_discard_ctl {
317a56159d4SJosef Bacik 	struct workqueue_struct *discard_workers;
318a56159d4SJosef Bacik 	struct delayed_work work;
319a56159d4SJosef Bacik 	spinlock_t lock;
320a56159d4SJosef Bacik 	struct btrfs_block_group *block_group;
321a56159d4SJosef Bacik 	struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
322a56159d4SJosef Bacik 	u64 prev_discard;
323a56159d4SJosef Bacik 	u64 prev_discard_time;
324a56159d4SJosef Bacik 	atomic_t discardable_extents;
325a56159d4SJosef Bacik 	atomic64_t discardable_bytes;
326a56159d4SJosef Bacik 	u64 max_discard_size;
327a56159d4SJosef Bacik 	u64 delay_ms;
328a56159d4SJosef Bacik 	u32 iops_limit;
329a56159d4SJosef Bacik 	u32 kbps_limit;
330a56159d4SJosef Bacik 	u64 discard_extent_bytes;
331a56159d4SJosef Bacik 	u64 discard_bitmap_bytes;
332a56159d4SJosef Bacik 	atomic64_t discard_bytes_saved;
333a56159d4SJosef Bacik };
334a56159d4SJosef Bacik 
335a56159d4SJosef Bacik /*
336a56159d4SJosef Bacik  * Exclusive operations (device replace, resize, device add/remove, balance)
337a56159d4SJosef Bacik  */
338a56159d4SJosef Bacik enum btrfs_exclusive_operation {
339a56159d4SJosef Bacik 	BTRFS_EXCLOP_NONE,
340a56159d4SJosef Bacik 	BTRFS_EXCLOP_BALANCE_PAUSED,
341a56159d4SJosef Bacik 	BTRFS_EXCLOP_BALANCE,
342a56159d4SJosef Bacik 	BTRFS_EXCLOP_DEV_ADD,
343a56159d4SJosef Bacik 	BTRFS_EXCLOP_DEV_REMOVE,
344a56159d4SJosef Bacik 	BTRFS_EXCLOP_DEV_REPLACE,
345a56159d4SJosef Bacik 	BTRFS_EXCLOP_RESIZE,
346a56159d4SJosef Bacik 	BTRFS_EXCLOP_SWAP_ACTIVATE,
347a56159d4SJosef Bacik };
348a56159d4SJosef Bacik 
349a56159d4SJosef Bacik /* Store data about transaction commits, exported via sysfs. */
350a56159d4SJosef Bacik struct btrfs_commit_stats {
351a56159d4SJosef Bacik 	/* Total number of commits */
352a56159d4SJosef Bacik 	u64 commit_count;
353a56159d4SJosef Bacik 	/* The maximum commit duration so far in ns */
354a56159d4SJosef Bacik 	u64 max_commit_dur;
355a56159d4SJosef Bacik 	/* The last commit duration in ns */
356a56159d4SJosef Bacik 	u64 last_commit_dur;
357a56159d4SJosef Bacik 	/* The total commit duration in ns */
358a56159d4SJosef Bacik 	u64 total_commit_dur;
359a56159d4SJosef Bacik };
360a56159d4SJosef Bacik 
361a56159d4SJosef Bacik struct btrfs_fs_info {
362a56159d4SJosef Bacik 	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
363a56159d4SJosef Bacik 	unsigned long flags;
364a56159d4SJosef Bacik 	struct btrfs_root *tree_root;
365a56159d4SJosef Bacik 	struct btrfs_root *chunk_root;
366a56159d4SJosef Bacik 	struct btrfs_root *dev_root;
367a56159d4SJosef Bacik 	struct btrfs_root *fs_root;
368a56159d4SJosef Bacik 	struct btrfs_root *quota_root;
369a56159d4SJosef Bacik 	struct btrfs_root *uuid_root;
370a56159d4SJosef Bacik 	struct btrfs_root *data_reloc_root;
371a56159d4SJosef Bacik 	struct btrfs_root *block_group_root;
372a56159d4SJosef Bacik 
373a56159d4SJosef Bacik 	/* The log root tree is a directory of all the other log roots */
374a56159d4SJosef Bacik 	struct btrfs_root *log_root_tree;
375a56159d4SJosef Bacik 
376a56159d4SJosef Bacik 	/* The tree that holds the global roots (csum, extent, etc) */
377a56159d4SJosef Bacik 	rwlock_t global_root_lock;
378a56159d4SJosef Bacik 	struct rb_root global_root_tree;
379a56159d4SJosef Bacik 
380a56159d4SJosef Bacik 	spinlock_t fs_roots_radix_lock;
381a56159d4SJosef Bacik 	struct radix_tree_root fs_roots_radix;
382a56159d4SJosef Bacik 
383a56159d4SJosef Bacik 	/* Block group cache stuff */
384a56159d4SJosef Bacik 	rwlock_t block_group_cache_lock;
385a56159d4SJosef Bacik 	struct rb_root_cached block_group_cache_tree;
386a56159d4SJosef Bacik 
387a56159d4SJosef Bacik 	/* Keep track of unallocated space */
388a56159d4SJosef Bacik 	atomic64_t free_chunk_space;
389a56159d4SJosef Bacik 
390a56159d4SJosef Bacik 	/* Track ranges which are used by log trees blocks/logged data extents */
391a56159d4SJosef Bacik 	struct extent_io_tree excluded_extents;
392a56159d4SJosef Bacik 
393a56159d4SJosef Bacik 	/* logical->physical extent mapping */
394a56159d4SJosef Bacik 	struct extent_map_tree mapping_tree;
395a56159d4SJosef Bacik 
396a56159d4SJosef Bacik 	/*
397a56159d4SJosef Bacik 	 * Block reservation for extent, checksum, root tree and delayed dir
398a56159d4SJosef Bacik 	 * index item.
399a56159d4SJosef Bacik 	 */
400a56159d4SJosef Bacik 	struct btrfs_block_rsv global_block_rsv;
401a56159d4SJosef Bacik 	/* Block reservation for metadata operations */
402a56159d4SJosef Bacik 	struct btrfs_block_rsv trans_block_rsv;
403a56159d4SJosef Bacik 	/* Block reservation for chunk tree */
404a56159d4SJosef Bacik 	struct btrfs_block_rsv chunk_block_rsv;
405a56159d4SJosef Bacik 	/* Block reservation for delayed operations */
406a56159d4SJosef Bacik 	struct btrfs_block_rsv delayed_block_rsv;
407a56159d4SJosef Bacik 	/* Block reservation for delayed refs */
408a56159d4SJosef Bacik 	struct btrfs_block_rsv delayed_refs_rsv;
409a56159d4SJosef Bacik 
410a56159d4SJosef Bacik 	struct btrfs_block_rsv empty_block_rsv;
411a56159d4SJosef Bacik 
412a56159d4SJosef Bacik 	u64 generation;
413a56159d4SJosef Bacik 	u64 last_trans_committed;
414a56159d4SJosef Bacik 	/*
415a56159d4SJosef Bacik 	 * Generation of the last transaction used for block group relocation
416a56159d4SJosef Bacik 	 * since the filesystem was last mounted (or 0 if none happened yet).
417a56159d4SJosef Bacik 	 * Must be written and read while holding btrfs_fs_info::commit_root_sem.
418a56159d4SJosef Bacik 	 */
419a56159d4SJosef Bacik 	u64 last_reloc_trans;
420a56159d4SJosef Bacik 
421a56159d4SJosef Bacik 	/*
422a56159d4SJosef Bacik 	 * This is updated to the current trans every time a full commit is
423a56159d4SJosef Bacik 	 * required instead of the faster short fsync log commits
424a56159d4SJosef Bacik 	 */
425a56159d4SJosef Bacik 	u64 last_trans_log_full_commit;
426a56159d4SJosef Bacik 	unsigned long mount_opt;
427a56159d4SJosef Bacik 
428a56159d4SJosef Bacik 	unsigned long compress_type:4;
429a56159d4SJosef Bacik 	unsigned int compress_level;
430a56159d4SJosef Bacik 	u32 commit_interval;
431a56159d4SJosef Bacik 	/*
432a56159d4SJosef Bacik 	 * It is a suggestive number, the read side is safe even it gets a
433a56159d4SJosef Bacik 	 * wrong number because we will write out the data into a regular
434a56159d4SJosef Bacik 	 * extent. The write side(mount/remount) is under ->s_umount lock,
435a56159d4SJosef Bacik 	 * so it is also safe.
436a56159d4SJosef Bacik 	 */
437a56159d4SJosef Bacik 	u64 max_inline;
438a56159d4SJosef Bacik 
439a56159d4SJosef Bacik 	struct btrfs_transaction *running_transaction;
440a56159d4SJosef Bacik 	wait_queue_head_t transaction_throttle;
441a56159d4SJosef Bacik 	wait_queue_head_t transaction_wait;
442a56159d4SJosef Bacik 	wait_queue_head_t transaction_blocked_wait;
443a56159d4SJosef Bacik 	wait_queue_head_t async_submit_wait;
444a56159d4SJosef Bacik 
445a56159d4SJosef Bacik 	/*
446a56159d4SJosef Bacik 	 * Used to protect the incompat_flags, compat_flags, compat_ro_flags
447a56159d4SJosef Bacik 	 * when they are updated.
448a56159d4SJosef Bacik 	 *
449a56159d4SJosef Bacik 	 * Because we do not clear the flags for ever, so we needn't use
450a56159d4SJosef Bacik 	 * the lock on the read side.
451a56159d4SJosef Bacik 	 *
452a56159d4SJosef Bacik 	 * We also needn't use the lock when we mount the fs, because
453a56159d4SJosef Bacik 	 * there is no other task which will update the flag.
454a56159d4SJosef Bacik 	 */
455a56159d4SJosef Bacik 	spinlock_t super_lock;
456a56159d4SJosef Bacik 	struct btrfs_super_block *super_copy;
457a56159d4SJosef Bacik 	struct btrfs_super_block *super_for_commit;
458a56159d4SJosef Bacik 	struct super_block *sb;
459a56159d4SJosef Bacik 	struct inode *btree_inode;
460a56159d4SJosef Bacik 	struct mutex tree_log_mutex;
461a56159d4SJosef Bacik 	struct mutex transaction_kthread_mutex;
462a56159d4SJosef Bacik 	struct mutex cleaner_mutex;
463a56159d4SJosef Bacik 	struct mutex chunk_mutex;
464a56159d4SJosef Bacik 
465a56159d4SJosef Bacik 	/*
466a56159d4SJosef Bacik 	 * This is taken to make sure we don't set block groups ro after the
467a56159d4SJosef Bacik 	 * free space cache has been allocated on them.
468a56159d4SJosef Bacik 	 */
469a56159d4SJosef Bacik 	struct mutex ro_block_group_mutex;
470a56159d4SJosef Bacik 
471a56159d4SJosef Bacik 	/*
472a56159d4SJosef Bacik 	 * This is used during read/modify/write to make sure no two ios are
473a56159d4SJosef Bacik 	 * trying to mod the same stripe at the same time.
474a56159d4SJosef Bacik 	 */
475a56159d4SJosef Bacik 	struct btrfs_stripe_hash_table *stripe_hash_table;
476a56159d4SJosef Bacik 
477a56159d4SJosef Bacik 	/*
478a56159d4SJosef Bacik 	 * This protects the ordered operations list only while we are
479a56159d4SJosef Bacik 	 * processing all of the entries on it.  This way we make sure the
480a56159d4SJosef Bacik 	 * commit code doesn't find the list temporarily empty because another
481a56159d4SJosef Bacik 	 * function happens to be doing non-waiting preflush before jumping
482a56159d4SJosef Bacik 	 * into the main commit.
483a56159d4SJosef Bacik 	 */
484a56159d4SJosef Bacik 	struct mutex ordered_operations_mutex;
485a56159d4SJosef Bacik 
486a56159d4SJosef Bacik 	struct rw_semaphore commit_root_sem;
487a56159d4SJosef Bacik 
488a56159d4SJosef Bacik 	struct rw_semaphore cleanup_work_sem;
489a56159d4SJosef Bacik 
490a56159d4SJosef Bacik 	struct rw_semaphore subvol_sem;
491a56159d4SJosef Bacik 
492a56159d4SJosef Bacik 	spinlock_t trans_lock;
493a56159d4SJosef Bacik 	/*
494a56159d4SJosef Bacik 	 * The reloc mutex goes with the trans lock, it is taken during commit
495a56159d4SJosef Bacik 	 * to protect us from the relocation code.
496a56159d4SJosef Bacik 	 */
497a56159d4SJosef Bacik 	struct mutex reloc_mutex;
498a56159d4SJosef Bacik 
499a56159d4SJosef Bacik 	struct list_head trans_list;
500a56159d4SJosef Bacik 	struct list_head dead_roots;
501a56159d4SJosef Bacik 	struct list_head caching_block_groups;
502a56159d4SJosef Bacik 
503a56159d4SJosef Bacik 	spinlock_t delayed_iput_lock;
504a56159d4SJosef Bacik 	struct list_head delayed_iputs;
505a56159d4SJosef Bacik 	atomic_t nr_delayed_iputs;
506a56159d4SJosef Bacik 	wait_queue_head_t delayed_iputs_wait;
507a56159d4SJosef Bacik 
508a56159d4SJosef Bacik 	atomic64_t tree_mod_seq;
509a56159d4SJosef Bacik 
510a56159d4SJosef Bacik 	/* This protects tree_mod_log and tree_mod_seq_list */
511a56159d4SJosef Bacik 	rwlock_t tree_mod_log_lock;
512a56159d4SJosef Bacik 	struct rb_root tree_mod_log;
513a56159d4SJosef Bacik 	struct list_head tree_mod_seq_list;
514a56159d4SJosef Bacik 
515a56159d4SJosef Bacik 	atomic_t async_delalloc_pages;
516a56159d4SJosef Bacik 
517a56159d4SJosef Bacik 	/* This is used to protect the following list -- ordered_roots. */
518a56159d4SJosef Bacik 	spinlock_t ordered_root_lock;
519a56159d4SJosef Bacik 
520a56159d4SJosef Bacik 	/*
521a56159d4SJosef Bacik 	 * All fs/file tree roots in which there are data=ordered extents
522a56159d4SJosef Bacik 	 * pending writeback are added into this list.
523a56159d4SJosef Bacik 	 *
524a56159d4SJosef Bacik 	 * These can span multiple transactions and basically include every
525a56159d4SJosef Bacik 	 * dirty data page that isn't from nodatacow.
526a56159d4SJosef Bacik 	 */
527a56159d4SJosef Bacik 	struct list_head ordered_roots;
528a56159d4SJosef Bacik 
529a56159d4SJosef Bacik 	struct mutex delalloc_root_mutex;
530a56159d4SJosef Bacik 	spinlock_t delalloc_root_lock;
531a56159d4SJosef Bacik 	/* All fs/file tree roots that have delalloc inodes. */
532a56159d4SJosef Bacik 	struct list_head delalloc_roots;
533a56159d4SJosef Bacik 
534a56159d4SJosef Bacik 	/*
535a56159d4SJosef Bacik 	 * There is a pool of worker threads for checksumming during writes and
536a56159d4SJosef Bacik 	 * a pool for checksumming after reads.  This is because readers can
537a56159d4SJosef Bacik 	 * run with FS locks held, and the writers may be waiting for those
538a56159d4SJosef Bacik 	 * locks.  We don't want ordering in the pending list to cause
539a56159d4SJosef Bacik 	 * deadlocks, and so the two are serviced separately.
540a56159d4SJosef Bacik 	 *
541a56159d4SJosef Bacik 	 * A third pool does submit_bio to avoid deadlocking with the other two.
542a56159d4SJosef Bacik 	 */
543a56159d4SJosef Bacik 	struct btrfs_workqueue *workers;
544a56159d4SJosef Bacik 	struct btrfs_workqueue *delalloc_workers;
545a56159d4SJosef Bacik 	struct btrfs_workqueue *flush_workers;
546a56159d4SJosef Bacik 	struct workqueue_struct *endio_workers;
547a56159d4SJosef Bacik 	struct workqueue_struct *endio_meta_workers;
548a56159d4SJosef Bacik 	struct workqueue_struct *rmw_workers;
549a56159d4SJosef Bacik 	struct workqueue_struct *compressed_write_workers;
550a56159d4SJosef Bacik 	struct btrfs_workqueue *endio_write_workers;
551a56159d4SJosef Bacik 	struct btrfs_workqueue *endio_freespace_worker;
552a56159d4SJosef Bacik 	struct btrfs_workqueue *caching_workers;
553a56159d4SJosef Bacik 
554a56159d4SJosef Bacik 	/*
555a56159d4SJosef Bacik 	 * Fixup workers take dirty pages that didn't properly go through the
556a56159d4SJosef Bacik 	 * cow mechanism and make them safe to write.  It happens for the
557a56159d4SJosef Bacik 	 * sys_munmap function call path.
558a56159d4SJosef Bacik 	 */
559a56159d4SJosef Bacik 	struct btrfs_workqueue *fixup_workers;
560a56159d4SJosef Bacik 	struct btrfs_workqueue *delayed_workers;
561a56159d4SJosef Bacik 
562a56159d4SJosef Bacik 	struct task_struct *transaction_kthread;
563a56159d4SJosef Bacik 	struct task_struct *cleaner_kthread;
564a56159d4SJosef Bacik 	u32 thread_pool_size;
565a56159d4SJosef Bacik 
566a56159d4SJosef Bacik 	struct kobject *space_info_kobj;
567a56159d4SJosef Bacik 	struct kobject *qgroups_kobj;
568a56159d4SJosef Bacik 	struct kobject *discard_kobj;
569a56159d4SJosef Bacik 
570a56159d4SJosef Bacik 	/* Used to keep from writing metadata until there is a nice batch */
571a56159d4SJosef Bacik 	struct percpu_counter dirty_metadata_bytes;
572a56159d4SJosef Bacik 	struct percpu_counter delalloc_bytes;
573a56159d4SJosef Bacik 	struct percpu_counter ordered_bytes;
574a56159d4SJosef Bacik 	s32 dirty_metadata_batch;
575a56159d4SJosef Bacik 	s32 delalloc_batch;
576a56159d4SJosef Bacik 
57708eb2ad9SFilipe Manana 	/* Protected by 'trans_lock'. */
578a56159d4SJosef Bacik 	struct list_head dirty_cowonly_roots;
579a56159d4SJosef Bacik 
580a56159d4SJosef Bacik 	struct btrfs_fs_devices *fs_devices;
581a56159d4SJosef Bacik 
582a56159d4SJosef Bacik 	/*
583a56159d4SJosef Bacik 	 * The space_info list is effectively read only after initial setup.
584a56159d4SJosef Bacik 	 * It is populated at mount time and cleaned up after all block groups
585a56159d4SJosef Bacik 	 * are removed.  RCU is used to protect it.
586a56159d4SJosef Bacik 	 */
587a56159d4SJosef Bacik 	struct list_head space_info;
588a56159d4SJosef Bacik 
589a56159d4SJosef Bacik 	struct btrfs_space_info *data_sinfo;
590a56159d4SJosef Bacik 
591a56159d4SJosef Bacik 	struct reloc_control *reloc_ctl;
592a56159d4SJosef Bacik 
593a56159d4SJosef Bacik 	/* data_alloc_cluster is only used in ssd_spread mode */
594a56159d4SJosef Bacik 	struct btrfs_free_cluster data_alloc_cluster;
595a56159d4SJosef Bacik 
596a56159d4SJosef Bacik 	/* All metadata allocations go through this cluster. */
597a56159d4SJosef Bacik 	struct btrfs_free_cluster meta_alloc_cluster;
598a56159d4SJosef Bacik 
599a56159d4SJosef Bacik 	/* Auto defrag inodes go here. */
600a56159d4SJosef Bacik 	spinlock_t defrag_inodes_lock;
601a56159d4SJosef Bacik 	struct rb_root defrag_inodes;
602a56159d4SJosef Bacik 	atomic_t defrag_running;
603a56159d4SJosef Bacik 
604a56159d4SJosef Bacik 	/* Used to protect avail_{data, metadata, system}_alloc_bits */
605a56159d4SJosef Bacik 	seqlock_t profiles_lock;
606a56159d4SJosef Bacik 	/*
607a56159d4SJosef Bacik 	 * These three are in extended format (availability of single chunks is
608a56159d4SJosef Bacik 	 * denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other types are denoted
609a56159d4SJosef Bacik 	 * by corresponding BTRFS_BLOCK_GROUP_* bits)
610a56159d4SJosef Bacik 	 */
611a56159d4SJosef Bacik 	u64 avail_data_alloc_bits;
612a56159d4SJosef Bacik 	u64 avail_metadata_alloc_bits;
613a56159d4SJosef Bacik 	u64 avail_system_alloc_bits;
614a56159d4SJosef Bacik 
615a56159d4SJosef Bacik 	/* Balance state */
616a56159d4SJosef Bacik 	spinlock_t balance_lock;
617a56159d4SJosef Bacik 	struct mutex balance_mutex;
618a56159d4SJosef Bacik 	atomic_t balance_pause_req;
619a56159d4SJosef Bacik 	atomic_t balance_cancel_req;
620a56159d4SJosef Bacik 	struct btrfs_balance_control *balance_ctl;
621a56159d4SJosef Bacik 	wait_queue_head_t balance_wait_q;
622a56159d4SJosef Bacik 
623a56159d4SJosef Bacik 	/* Cancellation requests for chunk relocation */
624a56159d4SJosef Bacik 	atomic_t reloc_cancel_req;
625a56159d4SJosef Bacik 
626a56159d4SJosef Bacik 	u32 data_chunk_allocations;
627a56159d4SJosef Bacik 	u32 metadata_ratio;
628a56159d4SJosef Bacik 
629a56159d4SJosef Bacik 	void *bdev_holder;
630a56159d4SJosef Bacik 
631a56159d4SJosef Bacik 	/* Private scrub information */
632a56159d4SJosef Bacik 	struct mutex scrub_lock;
633a56159d4SJosef Bacik 	atomic_t scrubs_running;
634a56159d4SJosef Bacik 	atomic_t scrub_pause_req;
635a56159d4SJosef Bacik 	atomic_t scrubs_paused;
636a56159d4SJosef Bacik 	atomic_t scrub_cancel_req;
637a56159d4SJosef Bacik 	wait_queue_head_t scrub_pause_wait;
638a56159d4SJosef Bacik 	/*
639a56159d4SJosef Bacik 	 * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
640a56159d4SJosef Bacik 	 * running.
641a56159d4SJosef Bacik 	 */
642a56159d4SJosef Bacik 	refcount_t scrub_workers_refcnt;
643a56159d4SJosef Bacik 	struct workqueue_struct *scrub_workers;
644a56159d4SJosef Bacik 	struct btrfs_subpage_info *subpage_info;
645a56159d4SJosef Bacik 
646a56159d4SJosef Bacik 	struct btrfs_discard_ctl discard_ctl;
647a56159d4SJosef Bacik 
648a56159d4SJosef Bacik #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
649a56159d4SJosef Bacik 	u32 check_integrity_print_mask;
650a56159d4SJosef Bacik #endif
651a56159d4SJosef Bacik 	/* Is qgroup tracking in a consistent state? */
652a56159d4SJosef Bacik 	u64 qgroup_flags;
653a56159d4SJosef Bacik 
654a56159d4SJosef Bacik 	/* Holds configuration and tracking. Protected by qgroup_lock. */
655a56159d4SJosef Bacik 	struct rb_root qgroup_tree;
656a56159d4SJosef Bacik 	spinlock_t qgroup_lock;
657a56159d4SJosef Bacik 
658a56159d4SJosef Bacik 	/*
659a56159d4SJosef Bacik 	 * Used to avoid frequently calling ulist_alloc()/ulist_free()
660a56159d4SJosef Bacik 	 * when doing qgroup accounting, it must be protected by qgroup_lock.
661a56159d4SJosef Bacik 	 */
662a56159d4SJosef Bacik 	struct ulist *qgroup_ulist;
663a56159d4SJosef Bacik 
664a56159d4SJosef Bacik 	/*
665a56159d4SJosef Bacik 	 * Protect user change for quota operations. If a transaction is needed,
666a56159d4SJosef Bacik 	 * it must be started before locking this lock.
667a56159d4SJosef Bacik 	 */
668a56159d4SJosef Bacik 	struct mutex qgroup_ioctl_lock;
669a56159d4SJosef Bacik 
670a56159d4SJosef Bacik 	/* List of dirty qgroups to be written at next commit. */
671a56159d4SJosef Bacik 	struct list_head dirty_qgroups;
672a56159d4SJosef Bacik 
673a56159d4SJosef Bacik 	/* Used by qgroup for an efficient tree traversal. */
674a56159d4SJosef Bacik 	u64 qgroup_seq;
675a56159d4SJosef Bacik 
676a56159d4SJosef Bacik 	/* Qgroup rescan items. */
677a56159d4SJosef Bacik 	/* Protects the progress item */
678a56159d4SJosef Bacik 	struct mutex qgroup_rescan_lock;
679a56159d4SJosef Bacik 	struct btrfs_key qgroup_rescan_progress;
680a56159d4SJosef Bacik 	struct btrfs_workqueue *qgroup_rescan_workers;
681a56159d4SJosef Bacik 	struct completion qgroup_rescan_completion;
682a56159d4SJosef Bacik 	struct btrfs_work qgroup_rescan_work;
683a56159d4SJosef Bacik 	/* Protected by qgroup_rescan_lock */
684a56159d4SJosef Bacik 	bool qgroup_rescan_running;
685a56159d4SJosef Bacik 	u8 qgroup_drop_subtree_thres;
686a56159d4SJosef Bacik 
687ae3364e5SFilipe Manana 	/*
688ae3364e5SFilipe Manana 	 * If this is not 0, then it indicates a serious filesystem error has
689ae3364e5SFilipe Manana 	 * happened and it contains that error (negative errno value).
690ae3364e5SFilipe Manana 	 */
691ae3364e5SFilipe Manana 	int fs_error;
692ae3364e5SFilipe Manana 
693a56159d4SJosef Bacik 	/* Filesystem state */
694a56159d4SJosef Bacik 	unsigned long fs_state;
695a56159d4SJosef Bacik 
696a56159d4SJosef Bacik 	struct btrfs_delayed_root *delayed_root;
697a56159d4SJosef Bacik 
698a56159d4SJosef Bacik 	/* Extent buffer radix tree */
699a56159d4SJosef Bacik 	spinlock_t buffer_lock;
700a56159d4SJosef Bacik 	/* Entries are eb->start / sectorsize */
701a56159d4SJosef Bacik 	struct radix_tree_root buffer_radix;
702a56159d4SJosef Bacik 
703a56159d4SJosef Bacik 	/* Next backup root to be overwritten */
704a56159d4SJosef Bacik 	int backup_root_index;
705a56159d4SJosef Bacik 
706a56159d4SJosef Bacik 	/* Device replace state */
707a56159d4SJosef Bacik 	struct btrfs_dev_replace dev_replace;
708a56159d4SJosef Bacik 
709a56159d4SJosef Bacik 	struct semaphore uuid_tree_rescan_sem;
710a56159d4SJosef Bacik 
711a56159d4SJosef Bacik 	/* Used to reclaim the metadata space in the background. */
712a56159d4SJosef Bacik 	struct work_struct async_reclaim_work;
713a56159d4SJosef Bacik 	struct work_struct async_data_reclaim_work;
714a56159d4SJosef Bacik 	struct work_struct preempt_reclaim_work;
715a56159d4SJosef Bacik 
716a56159d4SJosef Bacik 	/* Reclaim partially filled block groups in the background */
717a56159d4SJosef Bacik 	struct work_struct reclaim_bgs_work;
718a56159d4SJosef Bacik 	struct list_head reclaim_bgs;
719a56159d4SJosef Bacik 	int bg_reclaim_threshold;
720a56159d4SJosef Bacik 
721a56159d4SJosef Bacik 	spinlock_t unused_bgs_lock;
722a56159d4SJosef Bacik 	struct list_head unused_bgs;
723a56159d4SJosef Bacik 	struct mutex unused_bg_unpin_mutex;
724a56159d4SJosef Bacik 	/* Protect block groups that are going to be deleted */
725a56159d4SJosef Bacik 	struct mutex reclaim_bgs_lock;
726a56159d4SJosef Bacik 
727a56159d4SJosef Bacik 	/* Cached block sizes */
728a56159d4SJosef Bacik 	u32 nodesize;
729a56159d4SJosef Bacik 	u32 sectorsize;
730a56159d4SJosef Bacik 	/* ilog2 of sectorsize, use to avoid 64bit division */
731a56159d4SJosef Bacik 	u32 sectorsize_bits;
732a56159d4SJosef Bacik 	u32 csum_size;
733a56159d4SJosef Bacik 	u32 csums_per_leaf;
734a56159d4SJosef Bacik 	u32 stripesize;
735a56159d4SJosef Bacik 
736a56159d4SJosef Bacik 	/*
737a56159d4SJosef Bacik 	 * Maximum size of an extent. BTRFS_MAX_EXTENT_SIZE on regular
738a56159d4SJosef Bacik 	 * filesystem, on zoned it depends on the device constraints.
739a56159d4SJosef Bacik 	 */
740a56159d4SJosef Bacik 	u64 max_extent_size;
741a56159d4SJosef Bacik 
742a56159d4SJosef Bacik 	/* Block groups and devices containing active swapfiles. */
743a56159d4SJosef Bacik 	spinlock_t swapfile_pins_lock;
744a56159d4SJosef Bacik 	struct rb_root swapfile_pins;
745a56159d4SJosef Bacik 
746a56159d4SJosef Bacik 	struct crypto_shash *csum_shash;
747a56159d4SJosef Bacik 
748a56159d4SJosef Bacik 	/* Type of exclusive operation running, protected by super_lock */
749a56159d4SJosef Bacik 	enum btrfs_exclusive_operation exclusive_operation;
750a56159d4SJosef Bacik 
751a56159d4SJosef Bacik 	/*
752a56159d4SJosef Bacik 	 * Zone size > 0 when in ZONED mode, otherwise it's used for a check
753a56159d4SJosef Bacik 	 * if the mode is enabled
754a56159d4SJosef Bacik 	 */
755a56159d4SJosef Bacik 	u64 zone_size;
756a56159d4SJosef Bacik 
757243cf8d1SChristoph Hellwig 	/* Constraints for ZONE_APPEND commands: */
758243cf8d1SChristoph Hellwig 	struct queue_limits limits;
759a56159d4SJosef Bacik 	u64 max_zone_append_size;
760243cf8d1SChristoph Hellwig 
761a56159d4SJosef Bacik 	struct mutex zoned_meta_io_lock;
762a56159d4SJosef Bacik 	spinlock_t treelog_bg_lock;
763a56159d4SJosef Bacik 	u64 treelog_bg;
764a56159d4SJosef Bacik 
765a56159d4SJosef Bacik 	/*
766a56159d4SJosef Bacik 	 * Start of the dedicated data relocation block group, protected by
767a56159d4SJosef Bacik 	 * relocation_bg_lock.
768a56159d4SJosef Bacik 	 */
769a56159d4SJosef Bacik 	spinlock_t relocation_bg_lock;
770a56159d4SJosef Bacik 	u64 data_reloc_bg;
771a56159d4SJosef Bacik 	struct mutex zoned_data_reloc_io_lock;
772a56159d4SJosef Bacik 
773*13bb483dSNaohiro Aota 	struct btrfs_block_group *active_meta_bg;
774*13bb483dSNaohiro Aota 	struct btrfs_block_group *active_system_bg;
775*13bb483dSNaohiro Aota 
776a56159d4SJosef Bacik 	u64 nr_global_roots;
777a56159d4SJosef Bacik 
778a56159d4SJosef Bacik 	spinlock_t zone_active_bgs_lock;
779a56159d4SJosef Bacik 	struct list_head zone_active_bgs;
780a56159d4SJosef Bacik 
781a56159d4SJosef Bacik 	/* Updates are not protected by any lock */
782a56159d4SJosef Bacik 	struct btrfs_commit_stats commit_stats;
783a56159d4SJosef Bacik 
784a56159d4SJosef Bacik 	/*
785a56159d4SJosef Bacik 	 * Last generation where we dropped a non-relocation root.
786a56159d4SJosef Bacik 	 * Use btrfs_set_last_root_drop_gen() and btrfs_get_last_root_drop_gen()
787a56159d4SJosef Bacik 	 * to change it and to read it, respectively.
788a56159d4SJosef Bacik 	 */
789a56159d4SJosef Bacik 	u64 last_root_drop_gen;
790a56159d4SJosef Bacik 
791a56159d4SJosef Bacik 	/*
792a56159d4SJosef Bacik 	 * Annotations for transaction events (structures are empty when
793a56159d4SJosef Bacik 	 * compiled without lockdep).
794a56159d4SJosef Bacik 	 */
795a56159d4SJosef Bacik 	struct lockdep_map btrfs_trans_num_writers_map;
796a56159d4SJosef Bacik 	struct lockdep_map btrfs_trans_num_extwriters_map;
797a56159d4SJosef Bacik 	struct lockdep_map btrfs_state_change_map[4];
798a56159d4SJosef Bacik 	struct lockdep_map btrfs_trans_pending_ordered_map;
799a56159d4SJosef Bacik 	struct lockdep_map btrfs_ordered_extent_map;
800a56159d4SJosef Bacik 
801a56159d4SJosef Bacik #ifdef CONFIG_BTRFS_FS_REF_VERIFY
802a56159d4SJosef Bacik 	spinlock_t ref_verify_lock;
803a56159d4SJosef Bacik 	struct rb_root block_tree;
804a56159d4SJosef Bacik #endif
805a56159d4SJosef Bacik 
806a56159d4SJosef Bacik #ifdef CONFIG_BTRFS_DEBUG
807a56159d4SJosef Bacik 	struct kobject *debug_kobj;
808a56159d4SJosef Bacik 	struct list_head allocated_roots;
809a56159d4SJosef Bacik 
810a56159d4SJosef Bacik 	spinlock_t eb_leak_lock;
811a56159d4SJosef Bacik 	struct list_head allocated_ebs;
812a56159d4SJosef Bacik #endif
813a56159d4SJosef Bacik };
814a56159d4SJosef Bacik 
btrfs_set_last_root_drop_gen(struct btrfs_fs_info * fs_info,u64 gen)815a56159d4SJosef Bacik static inline void btrfs_set_last_root_drop_gen(struct btrfs_fs_info *fs_info,
816a56159d4SJosef Bacik 						u64 gen)
817a56159d4SJosef Bacik {
818a56159d4SJosef Bacik 	WRITE_ONCE(fs_info->last_root_drop_gen, gen);
819a56159d4SJosef Bacik }
820a56159d4SJosef Bacik 
btrfs_get_last_root_drop_gen(const struct btrfs_fs_info * fs_info)821a56159d4SJosef Bacik static inline u64 btrfs_get_last_root_drop_gen(const struct btrfs_fs_info *fs_info)
822a56159d4SJosef Bacik {
823a56159d4SJosef Bacik 	return READ_ONCE(fs_info->last_root_drop_gen);
824a56159d4SJosef Bacik }
825a56159d4SJosef Bacik 
826a56159d4SJosef Bacik /*
827a56159d4SJosef Bacik  * Take the number of bytes to be checksummed and figure out how many leaves
828a56159d4SJosef Bacik  * it would require to store the csums for that many bytes.
829a56159d4SJosef Bacik  */
btrfs_csum_bytes_to_leaves(const struct btrfs_fs_info * fs_info,u64 csum_bytes)830a56159d4SJosef Bacik static inline u64 btrfs_csum_bytes_to_leaves(
831a56159d4SJosef Bacik 			const struct btrfs_fs_info *fs_info, u64 csum_bytes)
832a56159d4SJosef Bacik {
833a56159d4SJosef Bacik 	const u64 num_csums = csum_bytes >> fs_info->sectorsize_bits;
834a56159d4SJosef Bacik 
835a56159d4SJosef Bacik 	return DIV_ROUND_UP_ULL(num_csums, fs_info->csums_per_leaf);
836a56159d4SJosef Bacik }
837a56159d4SJosef Bacik 
838a56159d4SJosef Bacik /*
839a56159d4SJosef Bacik  * Use this if we would be adding new items, as we could split nodes as we cow
840a56159d4SJosef Bacik  * down the tree.
841a56159d4SJosef Bacik  */
btrfs_calc_insert_metadata_size(const struct btrfs_fs_info * fs_info,unsigned num_items)842d1085c9cSFilipe Manana static inline u64 btrfs_calc_insert_metadata_size(const struct btrfs_fs_info *fs_info,
843a56159d4SJosef Bacik 						  unsigned num_items)
844a56159d4SJosef Bacik {
845a56159d4SJosef Bacik 	return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
846a56159d4SJosef Bacik }
847a56159d4SJosef Bacik 
848a56159d4SJosef Bacik /*
849a56159d4SJosef Bacik  * Doing a truncate or a modification won't result in new nodes or leaves, just
850a56159d4SJosef Bacik  * what we need for COW.
851a56159d4SJosef Bacik  */
btrfs_calc_metadata_size(const struct btrfs_fs_info * fs_info,unsigned num_items)852d1085c9cSFilipe Manana static inline u64 btrfs_calc_metadata_size(const struct btrfs_fs_info *fs_info,
853a56159d4SJosef Bacik 						 unsigned num_items)
854a56159d4SJosef Bacik {
855a56159d4SJosef Bacik 	return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
856a56159d4SJosef Bacik }
857a56159d4SJosef Bacik 
858a56159d4SJosef Bacik #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
859a56159d4SJosef Bacik 					sizeof(struct btrfs_item))
860a56159d4SJosef Bacik 
btrfs_is_zoned(const struct btrfs_fs_info * fs_info)861a56159d4SJosef Bacik static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info)
862a56159d4SJosef Bacik {
863dd8b7b04SChristoph Hellwig 	return IS_ENABLED(CONFIG_BLK_DEV_ZONED) && fs_info->zone_size > 0;
864a56159d4SJosef Bacik }
865a56159d4SJosef Bacik 
866a56159d4SJosef Bacik /*
867a56159d4SJosef Bacik  * Count how many fs_info->max_extent_size cover the @size
868a56159d4SJosef Bacik  */
count_max_extents(struct btrfs_fs_info * fs_info,u64 size)869a56159d4SJosef Bacik static inline u32 count_max_extents(struct btrfs_fs_info *fs_info, u64 size)
870a56159d4SJosef Bacik {
871a56159d4SJosef Bacik #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
872a56159d4SJosef Bacik 	if (!fs_info)
873a56159d4SJosef Bacik 		return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
874a56159d4SJosef Bacik #endif
875a56159d4SJosef Bacik 
876a56159d4SJosef Bacik 	return div_u64(size + fs_info->max_extent_size - 1, fs_info->max_extent_size);
877a56159d4SJosef Bacik }
878a56159d4SJosef Bacik 
879a56159d4SJosef Bacik bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
880a56159d4SJosef Bacik 			enum btrfs_exclusive_operation type);
881a56159d4SJosef Bacik bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info,
882a56159d4SJosef Bacik 				 enum btrfs_exclusive_operation type);
883a56159d4SJosef Bacik void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info);
884a56159d4SJosef Bacik void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
885a56159d4SJosef Bacik void btrfs_exclop_balance(struct btrfs_fs_info *fs_info,
886a56159d4SJosef Bacik 			  enum btrfs_exclusive_operation op);
887a56159d4SJosef Bacik 
888c7f13d42SJosef Bacik /* Compatibility and incompatibility defines */
889c7f13d42SJosef Bacik void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
890c7f13d42SJosef Bacik 			     const char *name);
891c7f13d42SJosef Bacik void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
892c7f13d42SJosef Bacik 			       const char *name);
893c7f13d42SJosef Bacik void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
894c7f13d42SJosef Bacik 			      const char *name);
895c7f13d42SJosef Bacik void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
896c7f13d42SJosef Bacik 				const char *name);
897c7f13d42SJosef Bacik 
8980d3a9cf8SJosef Bacik #define __btrfs_fs_incompat(fs_info, flags)				\
8990d3a9cf8SJosef Bacik 	(!!(btrfs_super_incompat_flags((fs_info)->super_copy) & (flags)))
9000d3a9cf8SJosef Bacik 
9010d3a9cf8SJosef Bacik #define __btrfs_fs_compat_ro(fs_info, flags)				\
9020d3a9cf8SJosef Bacik 	(!!(btrfs_super_compat_ro_flags((fs_info)->super_copy) & (flags)))
9030d3a9cf8SJosef Bacik 
904c7f13d42SJosef Bacik #define btrfs_set_fs_incompat(__fs_info, opt)				\
905c7f13d42SJosef Bacik 	__btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, #opt)
906c7f13d42SJosef Bacik 
907c7f13d42SJosef Bacik #define btrfs_clear_fs_incompat(__fs_info, opt)				\
908c7f13d42SJosef Bacik 	__btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, #opt)
909c7f13d42SJosef Bacik 
910c7f13d42SJosef Bacik #define btrfs_fs_incompat(fs_info, opt)					\
911c7f13d42SJosef Bacik 	__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
912c7f13d42SJosef Bacik 
913c7f13d42SJosef Bacik #define btrfs_set_fs_compat_ro(__fs_info, opt)				\
914c7f13d42SJosef Bacik 	__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, #opt)
915c7f13d42SJosef Bacik 
916c7f13d42SJosef Bacik #define btrfs_clear_fs_compat_ro(__fs_info, opt)			\
917c7f13d42SJosef Bacik 	__btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, #opt)
918c7f13d42SJosef Bacik 
919c7f13d42SJosef Bacik #define btrfs_fs_compat_ro(fs_info, opt)				\
920c7f13d42SJosef Bacik 	__btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
921c7f13d42SJosef Bacik 
922fc97a410SJosef Bacik #define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
923fc97a410SJosef Bacik #define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
924fc97a410SJosef Bacik #define btrfs_raw_test_opt(o, opt)	((o) & BTRFS_MOUNT_##opt)
925fc97a410SJosef Bacik #define btrfs_test_opt(fs_info, opt)	((fs_info)->mount_opt & \
926fc97a410SJosef Bacik 					 BTRFS_MOUNT_##opt)
927fc97a410SJosef Bacik 
928fc97a410SJosef Bacik #define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
929fc97a410SJosef Bacik do {									\
930fc97a410SJosef Bacik 	if (!btrfs_test_opt(fs_info, opt))				\
931fc97a410SJosef Bacik 		btrfs_info(fs_info, fmt, ##args);			\
932fc97a410SJosef Bacik 	btrfs_set_opt(fs_info->mount_opt, opt);				\
933fc97a410SJosef Bacik } while (0)
934fc97a410SJosef Bacik 
935fc97a410SJosef Bacik #define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
936fc97a410SJosef Bacik do {									\
937fc97a410SJosef Bacik 	if (btrfs_test_opt(fs_info, opt))				\
938fc97a410SJosef Bacik 		btrfs_info(fs_info, fmt, ##args);			\
939fc97a410SJosef Bacik 	btrfs_clear_opt(fs_info->mount_opt, opt);			\
940fc97a410SJosef Bacik } while (0)
941fc97a410SJosef Bacik 
btrfs_fs_closing(struct btrfs_fs_info * fs_info)942c7f13d42SJosef Bacik static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
943c7f13d42SJosef Bacik {
944c7f13d42SJosef Bacik 	/* Do it this way so we only ever do one test_bit in the normal case. */
945c7f13d42SJosef Bacik 	if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) {
946c7f13d42SJosef Bacik 		if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags))
947c7f13d42SJosef Bacik 			return 2;
948c7f13d42SJosef Bacik 		return 1;
949c7f13d42SJosef Bacik 	}
950c7f13d42SJosef Bacik 	return 0;
951c7f13d42SJosef Bacik }
952c7f13d42SJosef Bacik 
953c7f13d42SJosef Bacik /*
954c7f13d42SJosef Bacik  * If we remount the fs to be R/O or umount the fs, the cleaner needn't do
955c7f13d42SJosef Bacik  * anything except sleeping. This function is used to check the status of
956c7f13d42SJosef Bacik  * the fs.
957c7f13d42SJosef Bacik  * We check for BTRFS_FS_STATE_RO to avoid races with a concurrent remount,
958c7f13d42SJosef Bacik  * since setting and checking for SB_RDONLY in the superblock's flags is not
959c7f13d42SJosef Bacik  * atomic.
960c7f13d42SJosef Bacik  */
btrfs_need_cleaner_sleep(struct btrfs_fs_info * fs_info)961c7f13d42SJosef Bacik static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
962c7f13d42SJosef Bacik {
963c7f13d42SJosef Bacik 	return test_bit(BTRFS_FS_STATE_RO, &fs_info->fs_state) ||
964c7f13d42SJosef Bacik 		btrfs_fs_closing(fs_info);
965c7f13d42SJosef Bacik }
966c7f13d42SJosef Bacik 
btrfs_wake_unfinished_drop(struct btrfs_fs_info * fs_info)9677966a6b5SJosef Bacik static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
9687966a6b5SJosef Bacik {
9697966a6b5SJosef Bacik 	clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);
9707966a6b5SJosef Bacik }
9717966a6b5SJosef Bacik 
972ae3364e5SFilipe Manana #define BTRFS_FS_ERROR(fs_info)	(READ_ONCE((fs_info)->fs_error))
973ae3364e5SFilipe Manana 
974ec8eb376SJosef Bacik #define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info)				\
975ec8eb376SJosef Bacik 	(unlikely(test_bit(BTRFS_FS_STATE_LOG_CLEANUP_ERROR,		\
976ec8eb376SJosef Bacik 			   &(fs_info)->fs_state)))
977ec8eb376SJosef Bacik 
978ec8eb376SJosef Bacik #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
9796a6b4dafSJosef Bacik 
9806a6b4dafSJosef Bacik #define EXPORT_FOR_TESTS
9816a6b4dafSJosef Bacik 
btrfs_is_testing(struct btrfs_fs_info * fs_info)982ec8eb376SJosef Bacik static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
983ec8eb376SJosef Bacik {
984ec8eb376SJosef Bacik 	return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
985ec8eb376SJosef Bacik }
9866a6b4dafSJosef Bacik 
9876a6b4dafSJosef Bacik void btrfs_test_destroy_inode(struct inode *inode);
9886a6b4dafSJosef Bacik 
989ec8eb376SJosef Bacik #else
9906a6b4dafSJosef Bacik 
9916a6b4dafSJosef Bacik #define EXPORT_FOR_TESTS static
9926a6b4dafSJosef Bacik 
btrfs_is_testing(struct btrfs_fs_info * fs_info)993ec8eb376SJosef Bacik static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
994ec8eb376SJosef Bacik {
995ec8eb376SJosef Bacik 	return 0;
996ec8eb376SJosef Bacik }
997ec8eb376SJosef Bacik #endif
998ec8eb376SJosef Bacik 
999c7f13d42SJosef Bacik #endif
1000