xref: /openbmc/linux/fs/btrfs/volumes.h (revision 6ba40b61)
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 
27b2117a39SMiao Xie #define BTRFS_STRIPE_LEN	(64 * 1024)
28b2117a39SMiao Xie 
29f2984462SChris Mason struct buffer_head;
30ffbd517dSChris Mason struct btrfs_pending_bios {
31ffbd517dSChris Mason 	struct bio *head;
32ffbd517dSChris Mason 	struct bio *tail;
33ffbd517dSChris Mason };
34ffbd517dSChris Mason 
350b86a832SChris Mason struct btrfs_device {
360b86a832SChris Mason 	struct list_head dev_list;
37b3075717SChris Mason 	struct list_head dev_alloc_list;
382b82032cSYan Zheng 	struct btrfs_fs_devices *fs_devices;
39d5ee37bcSMiao Xie 
400b86a832SChris Mason 	struct btrfs_root *dev_root;
41ffbd517dSChris Mason 
42d5ee37bcSMiao Xie 	struct rcu_string *name;
43d5ee37bcSMiao Xie 
44d5ee37bcSMiao Xie 	u64 generation;
45d5ee37bcSMiao Xie 
46d5ee37bcSMiao Xie 	spinlock_t io_lock ____cacheline_aligned;
47d5ee37bcSMiao Xie 	int running_pending;
48ffbd517dSChris Mason 	/* regular prio bios */
49ffbd517dSChris Mason 	struct btrfs_pending_bios pending_bios;
50ffbd517dSChris Mason 	/* WRITE_SYNC bios */
51ffbd517dSChris Mason 	struct btrfs_pending_bios pending_sync_bios;
52ffbd517dSChris Mason 
53d5ee37bcSMiao Xie 	struct block_device *bdev;
54d5ee37bcSMiao Xie 
55d5ee37bcSMiao Xie 	/* the mode sent to blkdev_get */
56d5ee37bcSMiao Xie 	fmode_t mode;
57d5ee37bcSMiao Xie 
582b82032cSYan Zheng 	int writeable;
59dfe25020SChris Mason 	int in_fs_metadata;
60cd02dca5SChris Mason 	int missing;
61d5e2003cSJosef Bacik 	int can_discard;
6263a212abSStefan Behrens 	int is_tgtdev_for_dev_replace;
63b3075717SChris Mason 
640b86a832SChris Mason 	/* the internal btrfs device id */
650b86a832SChris Mason 	u64 devid;
660b86a832SChris Mason 
676ba40b61SMiao Xie 	/* size of the device in memory */
680b86a832SChris Mason 	u64 total_bytes;
690b86a832SChris Mason 
706ba40b61SMiao Xie 	/* size of the device on disk */
71d6397baeSChris Ball 	u64 disk_total_bytes;
72d6397baeSChris Ball 
730b86a832SChris Mason 	/* bytes used */
740b86a832SChris Mason 	u64 bytes_used;
750b86a832SChris Mason 
760b86a832SChris Mason 	/* optimal io alignment for this device */
770b86a832SChris Mason 	u32 io_align;
780b86a832SChris Mason 
790b86a832SChris Mason 	/* optimal io width for this device */
800b86a832SChris Mason 	u32 io_width;
813c45bfc1SDulshani Gunawardhana 	/* type and info about this device */
823c45bfc1SDulshani Gunawardhana 	u64 type;
830b86a832SChris Mason 
840b86a832SChris Mason 	/* minimal io size for this device */
850b86a832SChris Mason 	u32 sector_size;
860b86a832SChris Mason 
870b86a832SChris Mason 	/* physical drive uuid (or lvm uuid) */
88e17cade2SChris Mason 	u8 uuid[BTRFS_UUID_SIZE];
898b712842SChris Mason 
903c45bfc1SDulshani Gunawardhana 	/* for sending down flush barriers */
913c45bfc1SDulshani Gunawardhana 	int nobarriers;
923c45bfc1SDulshani Gunawardhana 	struct bio *flush_bio;
933c45bfc1SDulshani Gunawardhana 	struct completion flush_wait;
943c45bfc1SDulshani Gunawardhana 
95a2de733cSArne Jansen 	/* per-device scrub information */
96d9d181c1SStefan Behrens 	struct scrub_ctx *scrub_device;
97a2de733cSArne Jansen 
98d458b054SQu Wenruo 	struct btrfs_work work;
991f78160cSXiao Guangrong 	struct rcu_head rcu;
1001f78160cSXiao Guangrong 	struct work_struct rcu_work;
10190519d66SArne Jansen 
10290519d66SArne Jansen 	/* readahead state */
10390519d66SArne Jansen 	spinlock_t reada_lock;
10490519d66SArne Jansen 	atomic_t reada_in_flight;
10590519d66SArne Jansen 	u64 reada_next;
10690519d66SArne Jansen 	struct reada_zone *reada_curr_zone;
10790519d66SArne Jansen 	struct radix_tree_root reada_zones;
10890519d66SArne Jansen 	struct radix_tree_root reada_extents;
109387125fcSChris Mason 
110442a4f63SStefan Behrens 	/* disk I/O failure stats. For detailed description refer to
111442a4f63SStefan Behrens 	 * enum btrfs_dev_stat_values in ioctl.h */
112733f4fbbSStefan Behrens 	int dev_stats_valid;
113addc3fa7SMiao Xie 
114addc3fa7SMiao Xie 	/* Counter to record the change of device stats */
115addc3fa7SMiao Xie 	atomic_t dev_stats_ccnt;
116442a4f63SStefan Behrens 	atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
1170b86a832SChris Mason };
1180b86a832SChris Mason 
1198a4b83ccSChris Mason struct btrfs_fs_devices {
1208a4b83ccSChris Mason 	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
1218a4b83ccSChris Mason 
122d4a78947SWu Fengguang 	/* the device with this id has the most recent copy of the super */
1238a4b83ccSChris Mason 	u64 latest_devid;
1248a4b83ccSChris Mason 	u64 latest_trans;
1258a4b83ccSChris Mason 	u64 num_devices;
126a0af469bSChris Mason 	u64 open_devices;
1272b82032cSYan Zheng 	u64 rw_devices;
128cd02dca5SChris Mason 	u64 missing_devices;
1292b82032cSYan Zheng 	u64 total_rw_bytes;
130d5e2003cSJosef Bacik 	u64 num_can_discard;
13102db0844SJosef Bacik 	u64 total_devices;
1328a4b83ccSChris Mason 	struct block_device *latest_bdev;
133e5e9a520SChris Mason 
134e5e9a520SChris Mason 	/* all of the devices in the FS, protected by a mutex
135e5e9a520SChris Mason 	 * so we can safely walk it to write out the supers without
1369b011adfSWang Shilong 	 * worrying about add/remove by the multi-device code.
1379b011adfSWang Shilong 	 * Scrubbing super can kick off supers writing by holding
1389b011adfSWang Shilong 	 * this mutex lock.
139e5e9a520SChris Mason 	 */
140e5e9a520SChris Mason 	struct mutex device_list_mutex;
1418a4b83ccSChris Mason 	struct list_head devices;
142b3075717SChris Mason 
143b3075717SChris Mason 	/* devices not currently being allocated */
144b3075717SChris Mason 	struct list_head alloc_list;
1458a4b83ccSChris Mason 	struct list_head list;
1462b82032cSYan Zheng 
1472b82032cSYan Zheng 	struct btrfs_fs_devices *seed;
1482b82032cSYan Zheng 	int seeding;
1492b82032cSYan Zheng 
1502b82032cSYan Zheng 	int opened;
151c289811cSChris Mason 
152c289811cSChris Mason 	/* set when we find or add a device that doesn't have the
153c289811cSChris Mason 	 * nonrot flag set
154c289811cSChris Mason 	 */
155c289811cSChris Mason 	int rotating;
1568a4b83ccSChris Mason };
1578a4b83ccSChris Mason 
158facc8a22SMiao Xie #define BTRFS_BIO_INLINE_CSUM_SIZE	64
159facc8a22SMiao Xie 
1609be3395bSChris Mason /*
1619be3395bSChris Mason  * we need the mirror number and stripe index to be passed around
1629be3395bSChris Mason  * the call chain while we are processing end_io (especially errors).
1639be3395bSChris Mason  * Really, what we need is a btrfs_bio structure that has this info
1649be3395bSChris Mason  * and is properly sized with its stripe array, but we're not there
1659be3395bSChris Mason  * quite yet.  We have our own btrfs bioset, and all of the bios
1669be3395bSChris Mason  * we allocate are actually btrfs_io_bios.  We'll cram as much of
1679be3395bSChris Mason  * struct btrfs_bio as we can into this over time.
1689be3395bSChris Mason  */
169facc8a22SMiao Xie typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err);
1709be3395bSChris Mason struct btrfs_io_bio {
1719be3395bSChris Mason 	unsigned long mirror_num;
1729be3395bSChris Mason 	unsigned long stripe_index;
173facc8a22SMiao Xie 	u8 *csum;
174facc8a22SMiao Xie 	u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
175facc8a22SMiao Xie 	u8 *csum_allocated;
176facc8a22SMiao Xie 	btrfs_io_bio_end_io_t *end_io;
1779be3395bSChris Mason 	struct bio bio;
1789be3395bSChris Mason };
1799be3395bSChris Mason 
1809be3395bSChris Mason static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio)
1819be3395bSChris Mason {
1829be3395bSChris Mason 	return container_of(bio, struct btrfs_io_bio, bio);
1839be3395bSChris Mason }
1849be3395bSChris Mason 
185cea9e445SChris Mason struct btrfs_bio_stripe {
186cea9e445SChris Mason 	struct btrfs_device *dev;
187cea9e445SChris Mason 	u64 physical;
188fce3bb9aSLi Dongyang 	u64 length; /* only used for discard mappings */
189cea9e445SChris Mason };
190cea9e445SChris Mason 
191a1d3c478SJan Schmidt struct btrfs_bio;
192a1d3c478SJan Schmidt typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err);
193a1d3c478SJan Schmidt 
194c55f1396SMiao Xie #define BTRFS_BIO_ORIG_BIO_SUBMITTED	0x1
195c55f1396SMiao Xie 
196a1d3c478SJan Schmidt struct btrfs_bio {
197cea9e445SChris Mason 	atomic_t stripes_pending;
198c404e0dcSMiao Xie 	struct btrfs_fs_info *fs_info;
199cea9e445SChris Mason 	bio_end_io_t *end_io;
2007d2b4daaSChris Mason 	struct bio *orig_bio;
201c55f1396SMiao Xie 	unsigned long flags;
202cea9e445SChris Mason 	void *private;
203a236aed1SChris Mason 	atomic_t error;
204a236aed1SChris Mason 	int max_errors;
205cea9e445SChris Mason 	int num_stripes;
206a1d3c478SJan Schmidt 	int mirror_num;
207cea9e445SChris Mason 	struct btrfs_bio_stripe stripes[];
208cea9e445SChris Mason };
209cea9e445SChris Mason 
210b2117a39SMiao Xie struct btrfs_device_info {
211b2117a39SMiao Xie 	struct btrfs_device *dev;
212b2117a39SMiao Xie 	u64 dev_offset;
213b2117a39SMiao Xie 	u64 max_avail;
21473c5de00SArne Jansen 	u64 total_avail;
215b2117a39SMiao Xie };
216b2117a39SMiao Xie 
21731e50229SLiu Bo struct btrfs_raid_attr {
21831e50229SLiu Bo 	int sub_stripes;	/* sub_stripes info for map */
21931e50229SLiu Bo 	int dev_stripes;	/* stripes per dev */
22031e50229SLiu Bo 	int devs_max;		/* max devs to use */
22131e50229SLiu Bo 	int devs_min;		/* min devs needed */
22231e50229SLiu Bo 	int devs_increment;	/* ndevs has to be a multiple of this */
22331e50229SLiu Bo 	int ncopies;		/* how many copies to data has */
22431e50229SLiu Bo };
22531e50229SLiu Bo 
2261abe9b8aSliubo struct map_lookup {
2271abe9b8aSliubo 	u64 type;
2281abe9b8aSliubo 	int io_align;
2291abe9b8aSliubo 	int io_width;
2301abe9b8aSliubo 	int stripe_len;
2311abe9b8aSliubo 	int sector_size;
2321abe9b8aSliubo 	int num_stripes;
2331abe9b8aSliubo 	int sub_stripes;
2341abe9b8aSliubo 	struct btrfs_bio_stripe stripes[];
2351abe9b8aSliubo };
2361abe9b8aSliubo 
237a2de733cSArne Jansen #define map_lookup_size(n) (sizeof(struct map_lookup) + \
238a2de733cSArne Jansen 			    (sizeof(struct btrfs_bio_stripe) * (n)))
239a2de733cSArne Jansen 
240f43ffb60SIlya Dryomov /*
241f43ffb60SIlya Dryomov  * Restriper's general type filter
242f43ffb60SIlya Dryomov  */
243f43ffb60SIlya Dryomov #define BTRFS_BALANCE_DATA		(1ULL << 0)
244f43ffb60SIlya Dryomov #define BTRFS_BALANCE_SYSTEM		(1ULL << 1)
245f43ffb60SIlya Dryomov #define BTRFS_BALANCE_METADATA		(1ULL << 2)
246f43ffb60SIlya Dryomov 
247f43ffb60SIlya Dryomov #define BTRFS_BALANCE_TYPE_MASK		(BTRFS_BALANCE_DATA |	    \
248f43ffb60SIlya Dryomov 					 BTRFS_BALANCE_SYSTEM |	    \
249f43ffb60SIlya Dryomov 					 BTRFS_BALANCE_METADATA)
250e4d8ec0fSIlya Dryomov 
251e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_FORCE		(1ULL << 3)
25259641015SIlya Dryomov #define BTRFS_BALANCE_RESUME		(1ULL << 4)
253e4d8ec0fSIlya Dryomov 
254ed25e9b2SIlya Dryomov /*
255ed25e9b2SIlya Dryomov  * Balance filters
256ed25e9b2SIlya Dryomov  */
257ed25e9b2SIlya Dryomov #define BTRFS_BALANCE_ARGS_PROFILES	(1ULL << 0)
2585ce5b3c0SIlya Dryomov #define BTRFS_BALANCE_ARGS_USAGE	(1ULL << 1)
259409d404bSIlya Dryomov #define BTRFS_BALANCE_ARGS_DEVID	(1ULL << 2)
26094e60d5aSIlya Dryomov #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
261ea67176aSIlya Dryomov #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
2627d824b6fSDavid Sterba #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
263f43ffb60SIlya Dryomov 
264cfa4c961SIlya Dryomov /*
265cfa4c961SIlya Dryomov  * Profile changing flags.  When SOFT is set we won't relocate chunk if
266cfa4c961SIlya Dryomov  * it already has the target profile (even though it may be
267cfa4c961SIlya Dryomov  * half-filled).
268cfa4c961SIlya Dryomov  */
269e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_ARGS_CONVERT	(1ULL << 8)
270cfa4c961SIlya Dryomov #define BTRFS_BALANCE_ARGS_SOFT		(1ULL << 9)
271e4d8ec0fSIlya Dryomov 
272c9e9f97bSIlya Dryomov struct btrfs_balance_args;
27319a39dceSIlya Dryomov struct btrfs_balance_progress;
274c9e9f97bSIlya Dryomov struct btrfs_balance_control {
275c9e9f97bSIlya Dryomov 	struct btrfs_fs_info *fs_info;
276c9e9f97bSIlya Dryomov 
277c9e9f97bSIlya Dryomov 	struct btrfs_balance_args data;
278c9e9f97bSIlya Dryomov 	struct btrfs_balance_args meta;
279c9e9f97bSIlya Dryomov 	struct btrfs_balance_args sys;
280c9e9f97bSIlya Dryomov 
281c9e9f97bSIlya Dryomov 	u64 flags;
28219a39dceSIlya Dryomov 
28319a39dceSIlya Dryomov 	struct btrfs_balance_progress stat;
284c9e9f97bSIlya Dryomov };
285c9e9f97bSIlya Dryomov 
2866d07bcecSMiao Xie int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
2876d07bcecSMiao Xie 				   u64 end, u64 *length);
2886d07bcecSMiao Xie 
289a1d3c478SJan Schmidt #define btrfs_bio_size(n) (sizeof(struct btrfs_bio) + \
290cea9e445SChris Mason 			    (sizeof(struct btrfs_bio_stripe) * (n)))
291cea9e445SChris Mason 
2923ec706c8SStefan Behrens int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
293cea9e445SChris Mason 		    u64 logical, u64 *length,
294a1d3c478SJan Schmidt 		    struct btrfs_bio **bbio_ret, int mirror_num);
295a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
296a512bbf8SYan Zheng 		     u64 chunk_start, u64 physical, u64 devid,
297a512bbf8SYan Zheng 		     u64 **logical, int *naddrs, int *stripe_len);
298e4404d6eSYan Zheng int btrfs_read_sys_array(struct btrfs_root *root);
2990b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root);
3000b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
3012b82032cSYan Zheng 		      struct btrfs_root *extent_root, u64 type);
3020b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
3030b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
304f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
3058b712842SChris Mason 		  int mirror_num, int async_submit);
3068a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
30797288f2cSChristoph Hellwig 		       fmode_t flags, void *holder);
30897288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
3098a4b83ccSChris Mason 			  struct btrfs_fs_devices **fs_devices_ret);
3108a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
3118dabb742SStefan Behrens void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info,
3128dabb742SStefan Behrens 			       struct btrfs_fs_devices *fs_devices, int step);
3137ba15b7dSStefan Behrens int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
3147ba15b7dSStefan Behrens 					 char *device_path,
3157ba15b7dSStefan Behrens 					 struct btrfs_device **device);
31612bd2fc0SIlya Dryomov struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
31712bd2fc0SIlya Dryomov 					const u64 *devid,
31812bd2fc0SIlya Dryomov 					const u8 *uuid);
319a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path);
320143bede5SJeff Mahoney void btrfs_cleanup_fs_uuids(void);
3215d964051SStefan Behrens int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
3228f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans,
3238f18cf13SChris Mason 		      struct btrfs_device *device, u64 new_size);
324aa1b8cd4SStefan Behrens struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
3252b82032cSYan Zheng 				       u8 *uuid, u8 *fsid);
3268f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
327788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path);
328e93c89c1SStefan Behrens int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
329e93c89c1SStefan Behrens 				  struct btrfs_device **device_out);
330c9e9f97bSIlya Dryomov int btrfs_balance(struct btrfs_balance_control *bctl,
331c9e9f97bSIlya Dryomov 		  struct btrfs_ioctl_balance_args *bargs);
3322b6ba629SIlya Dryomov int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
33368310a5eSIlya Dryomov int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
334837d5b6eSIlya Dryomov int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
335a7e99c69SIlya Dryomov int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
336f7a81ea4SStefan Behrens int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
33770f80175SStefan Behrens int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
3382b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
3396df9a95eSJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans,
3406df9a95eSJosef Bacik 			 struct btrfs_device *device, u64 num_bytes,
341ba1bf481SJosef Bacik 			 u64 *start, u64 *max_avail);
342442a4f63SStefan Behrens void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
343c11d2c23SStefan Behrens int btrfs_get_dev_stats(struct btrfs_root *root,
344b27f7c0cSDavid Sterba 			struct btrfs_ioctl_get_dev_stats *stats);
345cb517eabSMiao Xie void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
346733f4fbbSStefan Behrens int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
347733f4fbbSStefan Behrens int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
348733f4fbbSStefan Behrens 			struct btrfs_fs_info *fs_info);
349e93c89c1SStefan Behrens void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info,
350e93c89c1SStefan Behrens 				 struct btrfs_device *srcdev);
351e93c89c1SStefan Behrens void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
352e93c89c1SStefan Behrens 				      struct btrfs_device *tgtdev);
353e93c89c1SStefan Behrens void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
354e93c89c1SStefan Behrens 					      struct btrfs_device *tgtdev);
355a8a6dab7SStefan Behrens int btrfs_scratch_superblock(struct btrfs_device *device);
35653b381b3SDavid Woodhouse int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
35753b381b3SDavid Woodhouse 			   u64 logical, u64 len, int mirror_num);
35853b381b3SDavid Woodhouse unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
35953b381b3SDavid Woodhouse 				    struct btrfs_mapping_tree *map_tree,
36053b381b3SDavid Woodhouse 				    u64 logical);
3616df9a95eSJosef Bacik int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
3626df9a95eSJosef Bacik 				struct btrfs_root *extent_root,
3636df9a95eSJosef Bacik 				u64 chunk_offset, u64 chunk_size);
364addc3fa7SMiao Xie 
365addc3fa7SMiao Xie static inline int btrfs_dev_stats_dirty(struct btrfs_device *dev)
366addc3fa7SMiao Xie {
367addc3fa7SMiao Xie 	return atomic_read(&dev->dev_stats_ccnt);
368addc3fa7SMiao Xie }
369addc3fa7SMiao Xie 
370442a4f63SStefan Behrens static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
371442a4f63SStefan Behrens 				      int index)
372442a4f63SStefan Behrens {
373442a4f63SStefan Behrens 	atomic_inc(dev->dev_stat_values + index);
374addc3fa7SMiao Xie 	smp_mb__before_atomic();
375addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
376442a4f63SStefan Behrens }
377442a4f63SStefan Behrens 
378442a4f63SStefan Behrens static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
379442a4f63SStefan Behrens 				      int index)
380442a4f63SStefan Behrens {
381442a4f63SStefan Behrens 	return atomic_read(dev->dev_stat_values + index);
382442a4f63SStefan Behrens }
383442a4f63SStefan Behrens 
384442a4f63SStefan Behrens static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
385442a4f63SStefan Behrens 						int index)
386442a4f63SStefan Behrens {
387442a4f63SStefan Behrens 	int ret;
388442a4f63SStefan Behrens 
389442a4f63SStefan Behrens 	ret = atomic_xchg(dev->dev_stat_values + index, 0);
390addc3fa7SMiao Xie 	smp_mb__before_atomic();
391addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
392442a4f63SStefan Behrens 	return ret;
393442a4f63SStefan Behrens }
394442a4f63SStefan Behrens 
395442a4f63SStefan Behrens static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
396442a4f63SStefan Behrens 				      int index, unsigned long val)
397442a4f63SStefan Behrens {
398442a4f63SStefan Behrens 	atomic_set(dev->dev_stat_values + index, val);
399addc3fa7SMiao Xie 	smp_mb__before_atomic();
400addc3fa7SMiao Xie 	atomic_inc(&dev->dev_stats_ccnt);
401442a4f63SStefan Behrens }
402442a4f63SStefan Behrens 
403442a4f63SStefan Behrens static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
404442a4f63SStefan Behrens 					int index)
405442a4f63SStefan Behrens {
406442a4f63SStefan Behrens 	btrfs_dev_stat_set(dev, index, 0);
407442a4f63SStefan Behrens }
4080b86a832SChris Mason #endif
409