xref: /openbmc/linux/fs/btrfs/volumes.h (revision af8e2d1d)
10b86a832SChris Mason /*
20b86a832SChris Mason  * Copyright (C) 2007 Oracle.  All rights reserved.
30b86a832SChris Mason  *
40b86a832SChris Mason  * This program is free software; you can redistribute it and/or
50b86a832SChris Mason  * modify it under the terms of the GNU General Public
60b86a832SChris Mason  * License v2 as published by the Free Software Foundation.
70b86a832SChris Mason  *
80b86a832SChris Mason  * This program is distributed in the hope that it will be useful,
90b86a832SChris Mason  * but WITHOUT ANY WARRANTY; without even the implied warranty of
100b86a832SChris Mason  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
110b86a832SChris Mason  * General Public License for more details.
120b86a832SChris Mason  *
130b86a832SChris Mason  * You should have received a copy of the GNU General Public
140b86a832SChris Mason  * License along with this program; if not, write to the
150b86a832SChris Mason  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
160b86a832SChris Mason  * Boston, MA 021110-1307, USA.
170b86a832SChris Mason  */
180b86a832SChris Mason 
190b86a832SChris Mason #ifndef __BTRFS_VOLUMES_
200b86a832SChris Mason #define __BTRFS_VOLUMES_
218790d502SChris Mason 
22cea9e445SChris Mason #include <linux/bio.h>
23b2117a39SMiao Xie #include <linux/sort.h>
2455e301fdSFilipe Brandenburger #include <linux/btrfs.h>
258b712842SChris Mason #include "async-thread.h"
26cea9e445SChris Mason 
2767a2c45eSMiao Xie extern struct mutex uuid_mutex;
2867a2c45eSMiao Xie 
29b2117a39SMiao Xie #define BTRFS_STRIPE_LEN	(64 * 1024)
30b2117a39SMiao Xie 
31f2984462SChris Mason struct buffer_head;
32ffbd517dSChris Mason struct btrfs_pending_bios {
33ffbd517dSChris Mason 	struct bio *head;
34ffbd517dSChris Mason 	struct bio *tail;
35ffbd517dSChris Mason };
36ffbd517dSChris Mason 
377cc8e58dSMiao Xie /*
387cc8e58dSMiao Xie  * Use sequence counter to get consistent device stat data on
397cc8e58dSMiao Xie  * 32-bit processors.
407cc8e58dSMiao Xie  */
417cc8e58dSMiao Xie #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
427cc8e58dSMiao Xie #include <linux/seqlock.h>
437cc8e58dSMiao Xie #define __BTRFS_NEED_DEVICE_DATA_ORDERED
447cc8e58dSMiao Xie #define btrfs_device_data_ordered_init(device)	\
457cc8e58dSMiao Xie 	seqcount_init(&device->data_seqcount)
467cc8e58dSMiao Xie #else
477cc8e58dSMiao Xie #define btrfs_device_data_ordered_init(device) do { } while (0)
487cc8e58dSMiao Xie #endif
497cc8e58dSMiao Xie 
500b86a832SChris Mason struct btrfs_device {
510b86a832SChris Mason 	struct list_head dev_list;
52b3075717SChris Mason 	struct list_head dev_alloc_list;
532b82032cSYan Zheng 	struct btrfs_fs_devices *fs_devices;
54d5ee37bcSMiao Xie 
550b86a832SChris Mason 	struct btrfs_root *dev_root;
56ffbd517dSChris Mason 
57d5ee37bcSMiao Xie 	struct rcu_string *name;
58d5ee37bcSMiao Xie 
59d5ee37bcSMiao Xie 	u64 generation;
60d5ee37bcSMiao Xie 
61d5ee37bcSMiao Xie 	spinlock_t io_lock ____cacheline_aligned;
62d5ee37bcSMiao Xie 	int running_pending;
63ffbd517dSChris Mason 	/* regular prio bios */
64ffbd517dSChris Mason 	struct btrfs_pending_bios pending_bios;
65ffbd517dSChris Mason 	/* WRITE_SYNC bios */
66ffbd517dSChris Mason 	struct btrfs_pending_bios pending_sync_bios;
67ffbd517dSChris Mason 
68d5ee37bcSMiao Xie 	struct block_device *bdev;
69d5ee37bcSMiao Xie 
70d5ee37bcSMiao Xie 	/* the mode sent to blkdev_get */
71d5ee37bcSMiao Xie 	fmode_t mode;
72d5ee37bcSMiao Xie 
732b82032cSYan Zheng 	int writeable;
74dfe25020SChris Mason 	int in_fs_metadata;
75cd02dca5SChris Mason 	int missing;
76d5e2003cSJosef Bacik 	int can_discard;
7763a212abSStefan Behrens 	int is_tgtdev_for_dev_replace;
78b3075717SChris Mason 
797cc8e58dSMiao Xie #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
807cc8e58dSMiao Xie 	seqcount_t data_seqcount;
817cc8e58dSMiao Xie #endif
827cc8e58dSMiao Xie 
830b86a832SChris Mason 	/* the internal btrfs device id */
840b86a832SChris Mason 	u64 devid;
850b86a832SChris Mason 
866ba40b61SMiao Xie 	/* size of the device in memory */
870b86a832SChris Mason 	u64 total_bytes;
880b86a832SChris Mason 
896ba40b61SMiao Xie 	/* size of the device on disk */
90d6397baeSChris Ball 	u64 disk_total_bytes;
91d6397baeSChris Ball 
920b86a832SChris Mason 	/* bytes used */
930b86a832SChris Mason 	u64 bytes_used;
940b86a832SChris Mason 
950b86a832SChris Mason 	/* optimal io alignment for this device */
960b86a832SChris Mason 	u32 io_align;
970b86a832SChris Mason 
980b86a832SChris Mason 	/* optimal io width for this device */
990b86a832SChris Mason 	u32 io_width;
1003c45bfc1SDulshani Gunawardhana 	/* type and info about this device */
1013c45bfc1SDulshani Gunawardhana 	u64 type;
1020b86a832SChris Mason 
1030b86a832SChris Mason 	/* minimal io size for this device */
1040b86a832SChris Mason 	u32 sector_size;
1050b86a832SChris Mason 
1060b86a832SChris Mason 	/* physical drive uuid (or lvm uuid) */
107e17cade2SChris Mason 	u8 uuid[BTRFS_UUID_SIZE];
1088b712842SChris Mason 
109935e5cc9SMiao Xie 	/*
110935e5cc9SMiao Xie 	 * size of the device on the current transaction
111935e5cc9SMiao Xie 	 *
112935e5cc9SMiao Xie 	 * This variant is update when committing the transaction,
113935e5cc9SMiao Xie 	 * and protected by device_list_mutex
114935e5cc9SMiao Xie 	 */
115935e5cc9SMiao Xie 	u64 commit_total_bytes;
116935e5cc9SMiao Xie 
117ce7213c7SMiao Xie 	/* bytes used on the current transaction */
118ce7213c7SMiao Xie 	u64 commit_bytes_used;
119935e5cc9SMiao Xie 	/*
120935e5cc9SMiao Xie 	 * used to manage the device which is resized
121935e5cc9SMiao Xie 	 *
122935e5cc9SMiao Xie 	 * It is protected by chunk_lock.
123935e5cc9SMiao Xie 	 */
124935e5cc9SMiao Xie 	struct list_head resized_list;
125935e5cc9SMiao Xie 
1263c45bfc1SDulshani Gunawardhana 	/* for sending down flush barriers */
1273c45bfc1SDulshani Gunawardhana 	int nobarriers;
1283c45bfc1SDulshani Gunawardhana 	struct bio *flush_bio;
1293c45bfc1SDulshani Gunawardhana 	struct completion flush_wait;
1303c45bfc1SDulshani Gunawardhana 
131a2de733cSArne Jansen 	/* per-device scrub information */
132d9d181c1SStefan Behrens 	struct scrub_ctx *scrub_device;
133a2de733cSArne Jansen 
134d458b054SQu Wenruo 	struct btrfs_work work;
1351f78160cSXiao Guangrong 	struct rcu_head rcu;
1361f78160cSXiao Guangrong 	struct work_struct rcu_work;
13790519d66SArne Jansen 
13890519d66SArne Jansen 	/* readahead state */
13990519d66SArne Jansen 	spinlock_t reada_lock;
14090519d66SArne Jansen 	atomic_t reada_in_flight;
14190519d66SArne Jansen 	u64 reada_next;
14290519d66SArne Jansen 	struct reada_zone *reada_curr_zone;
14390519d66SArne Jansen 	struct radix_tree_root reada_zones;
14490519d66SArne Jansen 	struct radix_tree_root reada_extents;
145387125fcSChris Mason 
146442a4f63SStefan Behrens 	/* disk I/O failure stats. For detailed description refer to
147442a4f63SStefan Behrens 	 * enum btrfs_dev_stat_values in ioctl.h */
148733f4fbbSStefan Behrens 	int dev_stats_valid;
149addc3fa7SMiao Xie 
150addc3fa7SMiao Xie 	/* Counter to record the change of device stats */
151addc3fa7SMiao Xie 	atomic_t dev_stats_ccnt;
152442a4f63SStefan Behrens 	atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
1530b86a832SChris Mason };
1540b86a832SChris Mason 
1557cc8e58dSMiao Xie /*
1567cc8e58dSMiao Xie  * If we read those variants at the context of their own lock, we needn't
1577cc8e58dSMiao Xie  * use the following helpers, reading them directly is safe.
1587cc8e58dSMiao Xie  */
1597cc8e58dSMiao Xie #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
1607cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name)					\
1617cc8e58dSMiao Xie static inline u64							\
1627cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev)			\
1637cc8e58dSMiao Xie {									\
1647cc8e58dSMiao Xie 	u64 size;							\
1657cc8e58dSMiao Xie 	unsigned int seq;						\
1667cc8e58dSMiao Xie 									\
1677cc8e58dSMiao Xie 	do {								\
1687cc8e58dSMiao Xie 		seq = read_seqcount_begin(&dev->data_seqcount);		\
1697cc8e58dSMiao Xie 		size = dev->name;					\
1707cc8e58dSMiao Xie 	} while (read_seqcount_retry(&dev->data_seqcount, seq));	\
1717cc8e58dSMiao Xie 	return size;							\
1727cc8e58dSMiao Xie }									\
1737cc8e58dSMiao Xie 									\
1747cc8e58dSMiao Xie static inline void							\
1757cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size)		\
1767cc8e58dSMiao Xie {									\
1777cc8e58dSMiao Xie 	preempt_disable();						\
1787cc8e58dSMiao Xie 	write_seqcount_begin(&dev->data_seqcount);			\
1797cc8e58dSMiao Xie 	dev->name = size;						\
1807cc8e58dSMiao Xie 	write_seqcount_end(&dev->data_seqcount);			\
1817cc8e58dSMiao Xie 	preempt_enable();						\
1827cc8e58dSMiao Xie }
1837cc8e58dSMiao Xie #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
1847cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name)					\
1857cc8e58dSMiao Xie static inline u64							\
1867cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev)			\
1877cc8e58dSMiao Xie {									\
1887cc8e58dSMiao Xie 	u64 size;							\
1897cc8e58dSMiao Xie 									\
1907cc8e58dSMiao Xie 	preempt_disable();						\
1917cc8e58dSMiao Xie 	size = dev->name;						\
1927cc8e58dSMiao Xie 	preempt_enable();						\
1937cc8e58dSMiao Xie 	return size;							\
1947cc8e58dSMiao Xie }									\
1957cc8e58dSMiao Xie 									\
1967cc8e58dSMiao Xie static inline void							\
1977cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size)		\
1987cc8e58dSMiao Xie {									\
1997cc8e58dSMiao Xie 	preempt_disable();						\
2007cc8e58dSMiao Xie 	dev->name = size;						\
2017cc8e58dSMiao Xie 	preempt_enable();						\
2027cc8e58dSMiao Xie }
2037cc8e58dSMiao Xie #else
2047cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name)					\
2057cc8e58dSMiao Xie static inline u64							\
2067cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev)			\
2077cc8e58dSMiao Xie {									\
2087cc8e58dSMiao Xie 	return dev->name;						\
2097cc8e58dSMiao Xie }									\
2107cc8e58dSMiao Xie 									\
2117cc8e58dSMiao Xie static inline void							\
2127cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size)		\
2137cc8e58dSMiao Xie {									\
2147cc8e58dSMiao Xie 	dev->name = size;						\
2157cc8e58dSMiao Xie }
2167cc8e58dSMiao Xie #endif
2177cc8e58dSMiao Xie 
2187cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(total_bytes);
2197cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
2207cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
2217cc8e58dSMiao Xie 
2228a4b83ccSChris Mason struct btrfs_fs_devices {
2238a4b83ccSChris Mason 	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
2248a4b83ccSChris Mason 
2258a4b83ccSChris Mason 	u64 num_devices;
226a0af469bSChris Mason 	u64 open_devices;
2272b82032cSYan Zheng 	u64 rw_devices;
228cd02dca5SChris Mason 	u64 missing_devices;
2292b82032cSYan Zheng 	u64 total_rw_bytes;
23002db0844SJosef Bacik 	u64 total_devices;
2318a4b83ccSChris Mason 	struct block_device *latest_bdev;
232e5e9a520SChris Mason 
233e5e9a520SChris Mason 	/* all of the devices in the FS, protected by a mutex
234e5e9a520SChris Mason 	 * so we can safely walk it to write out the supers without
2359b011adfSWang Shilong 	 * worrying about add/remove by the multi-device code.
2369b011adfSWang Shilong 	 * Scrubbing super can kick off supers writing by holding
2379b011adfSWang Shilong 	 * this mutex lock.
238e5e9a520SChris Mason 	 */
239e5e9a520SChris Mason 	struct mutex device_list_mutex;
2408a4b83ccSChris Mason 	struct list_head devices;
241b3075717SChris Mason 
242935e5cc9SMiao Xie 	struct list_head resized_devices;
243b3075717SChris Mason 	/* devices not currently being allocated */
244b3075717SChris Mason 	struct list_head alloc_list;
2458a4b83ccSChris Mason 	struct list_head list;
2462b82032cSYan Zheng 
2472b82032cSYan Zheng 	struct btrfs_fs_devices *seed;
2482b82032cSYan Zheng 	int seeding;
2492b82032cSYan Zheng 
2502b82032cSYan Zheng 	int opened;
251c289811cSChris Mason 
252c289811cSChris Mason 	/* set when we find or add a device that doesn't have the
253c289811cSChris Mason 	 * nonrot flag set
254c289811cSChris Mason 	 */
255c289811cSChris Mason 	int rotating;
2568a4b83ccSChris Mason };
2578a4b83ccSChris Mason 
258facc8a22SMiao Xie #define BTRFS_BIO_INLINE_CSUM_SIZE	64
259facc8a22SMiao Xie 
2609be3395bSChris Mason /*
2619be3395bSChris Mason  * we need the mirror number and stripe index to be passed around
2629be3395bSChris Mason  * the call chain while we are processing end_io (especially errors).
2639be3395bSChris Mason  * Really, what we need is a btrfs_bio structure that has this info
2649be3395bSChris Mason  * and is properly sized with its stripe array, but we're not there
2659be3395bSChris Mason  * quite yet.  We have our own btrfs bioset, and all of the bios
2669be3395bSChris Mason  * we allocate are actually btrfs_io_bios.  We'll cram as much of
2679be3395bSChris Mason  * struct btrfs_bio as we can into this over time.
2689be3395bSChris Mason  */
269facc8a22SMiao Xie typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err);
2709be3395bSChris Mason struct btrfs_io_bio {
271c1dc0896SMiao Xie 	unsigned int mirror_num;
272c1dc0896SMiao Xie 	unsigned int stripe_index;
273c1dc0896SMiao Xie 	u64 logical;
274facc8a22SMiao Xie 	u8 *csum;
275facc8a22SMiao Xie 	u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
276facc8a22SMiao Xie 	u8 *csum_allocated;
277facc8a22SMiao Xie 	btrfs_io_bio_end_io_t *end_io;
2789be3395bSChris Mason 	struct bio bio;
2799be3395bSChris Mason };
2809be3395bSChris Mason 
2819be3395bSChris Mason static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio)
2829be3395bSChris Mason {
2839be3395bSChris Mason 	return container_of(bio, struct btrfs_io_bio, bio);
2849be3395bSChris Mason }
2859be3395bSChris Mason 
286cea9e445SChris Mason struct btrfs_bio_stripe {
287cea9e445SChris Mason 	struct btrfs_device *dev;
288cea9e445SChris Mason 	u64 physical;
289fce3bb9aSLi Dongyang 	u64 length; /* only used for discard mappings */
290cea9e445SChris Mason };
291cea9e445SChris Mason 
292a1d3c478SJan Schmidt struct btrfs_bio;
293a1d3c478SJan Schmidt typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err);
294a1d3c478SJan Schmidt 
295c55f1396SMiao Xie #define BTRFS_BIO_ORIG_BIO_SUBMITTED	0x1
296c55f1396SMiao Xie 
297a1d3c478SJan Schmidt struct btrfs_bio {
298cea9e445SChris Mason 	atomic_t stripes_pending;
299c404e0dcSMiao Xie 	struct btrfs_fs_info *fs_info;
300cea9e445SChris Mason 	bio_end_io_t *end_io;
3017d2b4daaSChris Mason 	struct bio *orig_bio;
302c55f1396SMiao Xie 	unsigned long flags;
303cea9e445SChris Mason 	void *private;
304a236aed1SChris Mason 	atomic_t error;
305a236aed1SChris Mason 	int max_errors;
306cea9e445SChris Mason 	int num_stripes;
307a1d3c478SJan Schmidt 	int mirror_num;
308cea9e445SChris Mason 	struct btrfs_bio_stripe stripes[];
309cea9e445SChris Mason };
310cea9e445SChris Mason 
311b2117a39SMiao Xie struct btrfs_device_info {
312b2117a39SMiao Xie 	struct btrfs_device *dev;
313b2117a39SMiao Xie 	u64 dev_offset;
314b2117a39SMiao Xie 	u64 max_avail;
31573c5de00SArne Jansen 	u64 total_avail;
316b2117a39SMiao Xie };
317b2117a39SMiao Xie 
31831e50229SLiu Bo struct btrfs_raid_attr {
31931e50229SLiu Bo 	int sub_stripes;	/* sub_stripes info for map */
32031e50229SLiu Bo 	int dev_stripes;	/* stripes per dev */
32131e50229SLiu Bo 	int devs_max;		/* max devs to use */
32231e50229SLiu Bo 	int devs_min;		/* min devs needed */
32331e50229SLiu Bo 	int devs_increment;	/* ndevs has to be a multiple of this */
32431e50229SLiu Bo 	int ncopies;		/* how many copies to data has */
32531e50229SLiu Bo };
32631e50229SLiu Bo 
3271abe9b8aSliubo struct map_lookup {
3281abe9b8aSliubo 	u64 type;
3291abe9b8aSliubo 	int io_align;
3301abe9b8aSliubo 	int io_width;
3311abe9b8aSliubo 	int stripe_len;
3321abe9b8aSliubo 	int sector_size;
3331abe9b8aSliubo 	int num_stripes;
3341abe9b8aSliubo 	int sub_stripes;
3351abe9b8aSliubo 	struct btrfs_bio_stripe stripes[];
3361abe9b8aSliubo };
3371abe9b8aSliubo 
338a2de733cSArne Jansen #define map_lookup_size(n) (sizeof(struct map_lookup) + \
339a2de733cSArne Jansen 			    (sizeof(struct btrfs_bio_stripe) * (n)))
340a2de733cSArne Jansen 
341f43ffb60SIlya Dryomov /*
342f43ffb60SIlya Dryomov  * Restriper's general type filter
343f43ffb60SIlya Dryomov  */
344f43ffb60SIlya Dryomov #define BTRFS_BALANCE_DATA		(1ULL << 0)
345f43ffb60SIlya Dryomov #define BTRFS_BALANCE_SYSTEM		(1ULL << 1)
346f43ffb60SIlya Dryomov #define BTRFS_BALANCE_METADATA		(1ULL << 2)
347f43ffb60SIlya Dryomov 
348f43ffb60SIlya Dryomov #define BTRFS_BALANCE_TYPE_MASK		(BTRFS_BALANCE_DATA |	    \
349f43ffb60SIlya Dryomov 					 BTRFS_BALANCE_SYSTEM |	    \
350f43ffb60SIlya Dryomov 					 BTRFS_BALANCE_METADATA)
351e4d8ec0fSIlya Dryomov 
352e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_FORCE		(1ULL << 3)
35359641015SIlya Dryomov #define BTRFS_BALANCE_RESUME		(1ULL << 4)
354e4d8ec0fSIlya Dryomov 
355ed25e9b2SIlya Dryomov /*
356ed25e9b2SIlya Dryomov  * Balance filters
357ed25e9b2SIlya Dryomov  */
358ed25e9b2SIlya Dryomov #define BTRFS_BALANCE_ARGS_PROFILES	(1ULL << 0)
3595ce5b3c0SIlya Dryomov #define BTRFS_BALANCE_ARGS_USAGE	(1ULL << 1)
360409d404bSIlya Dryomov #define BTRFS_BALANCE_ARGS_DEVID	(1ULL << 2)
36194e60d5aSIlya Dryomov #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
362ea67176aSIlya Dryomov #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
3637d824b6fSDavid Sterba #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
364f43ffb60SIlya Dryomov 
365cfa4c961SIlya Dryomov /*
366cfa4c961SIlya Dryomov  * Profile changing flags.  When SOFT is set we won't relocate chunk if
367cfa4c961SIlya Dryomov  * it already has the target profile (even though it may be
368cfa4c961SIlya Dryomov  * half-filled).
369cfa4c961SIlya Dryomov  */
370e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_ARGS_CONVERT	(1ULL << 8)
371cfa4c961SIlya Dryomov #define BTRFS_BALANCE_ARGS_SOFT		(1ULL << 9)
372e4d8ec0fSIlya Dryomov 
373c9e9f97bSIlya Dryomov struct btrfs_balance_args;
37419a39dceSIlya Dryomov struct btrfs_balance_progress;
375c9e9f97bSIlya Dryomov struct btrfs_balance_control {
376c9e9f97bSIlya Dryomov 	struct btrfs_fs_info *fs_info;
377c9e9f97bSIlya Dryomov 
378c9e9f97bSIlya Dryomov 	struct btrfs_balance_args data;
379c9e9f97bSIlya Dryomov 	struct btrfs_balance_args meta;
380c9e9f97bSIlya Dryomov 	struct btrfs_balance_args sys;
381c9e9f97bSIlya Dryomov 
382c9e9f97bSIlya Dryomov 	u64 flags;
38319a39dceSIlya Dryomov 
38419a39dceSIlya Dryomov 	struct btrfs_balance_progress stat;
385c9e9f97bSIlya Dryomov };
386c9e9f97bSIlya Dryomov 
3876d07bcecSMiao Xie int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
3886d07bcecSMiao Xie 				   u64 end, u64 *length);
3896d07bcecSMiao Xie 
390a1d3c478SJan Schmidt #define btrfs_bio_size(n) (sizeof(struct btrfs_bio) + \
391cea9e445SChris Mason 			    (sizeof(struct btrfs_bio_stripe) * (n)))
392cea9e445SChris Mason 
3933ec706c8SStefan Behrens int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
394cea9e445SChris Mason 		    u64 logical, u64 *length,
395a1d3c478SJan Schmidt 		    struct btrfs_bio **bbio_ret, int mirror_num);
396af8e2d1dSMiao Xie int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int rw,
397af8e2d1dSMiao Xie 		     u64 logical, u64 *length,
398af8e2d1dSMiao Xie 		     struct btrfs_bio **bbio_ret, int mirror_num,
399af8e2d1dSMiao Xie 		     u64 **raid_map_ret);
400a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
401a512bbf8SYan Zheng 		     u64 chunk_start, u64 physical, u64 devid,
402a512bbf8SYan Zheng 		     u64 **logical, int *naddrs, int *stripe_len);
403e4404d6eSYan Zheng int btrfs_read_sys_array(struct btrfs_root *root);
4040b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root);
4050b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4062b82032cSYan Zheng 		      struct btrfs_root *extent_root, u64 type);
4070b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
4080b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
409f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
4108b712842SChris Mason 		  int mirror_num, int async_submit);
4118a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
41297288f2cSChristoph Hellwig 		       fmode_t flags, void *holder);
41397288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
4148a4b83ccSChris Mason 			  struct btrfs_fs_devices **fs_devices_ret);
4158a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
4168dabb742SStefan Behrens void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info,
4178dabb742SStefan Behrens 			       struct btrfs_fs_devices *fs_devices, int step);
4187ba15b7dSStefan Behrens int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
4197ba15b7dSStefan Behrens 					 char *device_path,
4207ba15b7dSStefan Behrens 					 struct btrfs_device **device);
42112bd2fc0SIlya Dryomov struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
42212bd2fc0SIlya Dryomov 					const u64 *devid,
42312bd2fc0SIlya Dryomov 					const u8 *uuid);
424a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path);
425143bede5SJeff Mahoney void btrfs_cleanup_fs_uuids(void);
4265d964051SStefan Behrens int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
4278f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans,
4288f18cf13SChris Mason 		      struct btrfs_device *device, u64 new_size);
429aa1b8cd4SStefan Behrens struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
4302b82032cSYan Zheng 				       u8 *uuid, u8 *fsid);
4318f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
432788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path);
433e93c89c1SStefan Behrens int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
4341c43366dSMiao Xie 				  struct btrfs_device *srcdev,
435e93c89c1SStefan Behrens 				  struct btrfs_device **device_out);
436c9e9f97bSIlya Dryomov int btrfs_balance(struct btrfs_balance_control *bctl,
437c9e9f97bSIlya Dryomov 		  struct btrfs_ioctl_balance_args *bargs);
4382b6ba629SIlya Dryomov int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
43968310a5eSIlya Dryomov int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
440837d5b6eSIlya Dryomov int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
441a7e99c69SIlya Dryomov int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
442f7a81ea4SStefan Behrens int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
44370f80175SStefan Behrens int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
4442b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
4456df9a95eSJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans,
4466df9a95eSJosef Bacik 			 struct btrfs_device *device, u64 num_bytes,
447ba1bf481SJosef Bacik 			 u64 *start, u64 *max_avail);
448442a4f63SStefan Behrens void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
449c11d2c23SStefan Behrens int btrfs_get_dev_stats(struct btrfs_root *root,
450b27f7c0cSDavid Sterba 			struct btrfs_ioctl_get_dev_stats *stats);
451cb517eabSMiao Xie void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
452733f4fbbSStefan Behrens int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
453733f4fbbSStefan Behrens int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
454733f4fbbSStefan Behrens 			struct btrfs_fs_info *fs_info);
455e93c89c1SStefan Behrens void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info,
456e93c89c1SStefan Behrens 				 struct btrfs_device *srcdev);
457e93c89c1SStefan Behrens void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
458e93c89c1SStefan Behrens 				      struct btrfs_device *tgtdev);
459e93c89c1SStefan Behrens void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
460e93c89c1SStefan Behrens 					      struct btrfs_device *tgtdev);
461a8a6dab7SStefan Behrens int btrfs_scratch_superblock(struct btrfs_device *device);
46253b381b3SDavid Woodhouse int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
46353b381b3SDavid Woodhouse 			   u64 logical, u64 len, int mirror_num);
46453b381b3SDavid Woodhouse unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
46553b381b3SDavid Woodhouse 				    struct btrfs_mapping_tree *map_tree,
46653b381b3SDavid Woodhouse 				    u64 logical);
4676df9a95eSJosef Bacik int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
4686df9a95eSJosef Bacik 				struct btrfs_root *extent_root,
4696df9a95eSJosef Bacik 				u64 chunk_offset, u64 chunk_size);
47047ab2a6cSJosef Bacik int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
47147ab2a6cSJosef Bacik 		       struct btrfs_root *root, u64 chunk_offset);
472addc3fa7SMiao Xie 
473addc3fa7SMiao Xie static inline int btrfs_dev_stats_dirty(struct btrfs_device *dev)
474addc3fa7SMiao Xie {
475addc3fa7SMiao Xie 	return atomic_read(&dev->dev_stats_ccnt);
476addc3fa7SMiao Xie }
477addc3fa7SMiao Xie 
478442a4f63SStefan Behrens static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
479442a4f63SStefan Behrens 				      int index)
480442a4f63SStefan Behrens {
481442a4f63SStefan Behrens 	atomic_inc(dev->dev_stat_values + index);
482addc3fa7SMiao Xie 	smp_mb__before_atomic();
483addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
484442a4f63SStefan Behrens }
485442a4f63SStefan Behrens 
486442a4f63SStefan Behrens static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
487442a4f63SStefan Behrens 				      int index)
488442a4f63SStefan Behrens {
489442a4f63SStefan Behrens 	return atomic_read(dev->dev_stat_values + index);
490442a4f63SStefan Behrens }
491442a4f63SStefan Behrens 
492442a4f63SStefan Behrens static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
493442a4f63SStefan Behrens 						int index)
494442a4f63SStefan Behrens {
495442a4f63SStefan Behrens 	int ret;
496442a4f63SStefan Behrens 
497442a4f63SStefan Behrens 	ret = atomic_xchg(dev->dev_stat_values + index, 0);
498addc3fa7SMiao Xie 	smp_mb__before_atomic();
499addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
500442a4f63SStefan Behrens 	return ret;
501442a4f63SStefan Behrens }
502442a4f63SStefan Behrens 
503442a4f63SStefan Behrens static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
504442a4f63SStefan Behrens 				      int index, unsigned long val)
505442a4f63SStefan Behrens {
506442a4f63SStefan Behrens 	atomic_set(dev->dev_stat_values + index, val);
507addc3fa7SMiao Xie 	smp_mb__before_atomic();
508addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
509442a4f63SStefan Behrens }
510442a4f63SStefan Behrens 
511442a4f63SStefan Behrens static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
512442a4f63SStefan Behrens 					int index)
513442a4f63SStefan Behrens {
514442a4f63SStefan Behrens 	btrfs_dev_stat_set(dev, index, 0);
515442a4f63SStefan Behrens }
516935e5cc9SMiao Xie 
517935e5cc9SMiao Xie void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info);
518ce7213c7SMiao Xie void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
519ce7213c7SMiao Xie 					struct btrfs_transaction *transaction);
5200b86a832SChris Mason #endif
521