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 29ee22184bSByongho Lee #define BTRFS_STRIPE_LEN SZ_64K 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; 54fb456252SJeff Mahoney struct btrfs_fs_info *fs_info; 55ffbd517dSChris Mason 56d5ee37bcSMiao Xie struct rcu_string *name; 57d5ee37bcSMiao Xie 58d5ee37bcSMiao Xie u64 generation; 59d5ee37bcSMiao Xie 60d5ee37bcSMiao Xie spinlock_t io_lock ____cacheline_aligned; 61d5ee37bcSMiao Xie int running_pending; 62ffbd517dSChris Mason /* regular prio bios */ 63ffbd517dSChris Mason struct btrfs_pending_bios pending_bios; 64ffbd517dSChris Mason /* WRITE_SYNC bios */ 65ffbd517dSChris Mason struct btrfs_pending_bios pending_sync_bios; 66ffbd517dSChris Mason 67d5ee37bcSMiao Xie struct block_device *bdev; 68d5ee37bcSMiao Xie 69d5ee37bcSMiao Xie /* the mode sent to blkdev_get */ 70d5ee37bcSMiao Xie fmode_t mode; 71d5ee37bcSMiao Xie 722b82032cSYan Zheng int writeable; 73dfe25020SChris Mason int in_fs_metadata; 74cd02dca5SChris Mason int missing; 75d5e2003cSJosef Bacik int can_discard; 7663a212abSStefan Behrens int is_tgtdev_for_dev_replace; 77b3075717SChris Mason 787cc8e58dSMiao Xie #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED 797cc8e58dSMiao Xie seqcount_t data_seqcount; 807cc8e58dSMiao Xie #endif 817cc8e58dSMiao Xie 820b86a832SChris Mason /* the internal btrfs device id */ 830b86a832SChris Mason u64 devid; 840b86a832SChris Mason 856ba40b61SMiao Xie /* size of the device in memory */ 860b86a832SChris Mason u64 total_bytes; 870b86a832SChris Mason 886ba40b61SMiao Xie /* size of the device on disk */ 89d6397baeSChris Ball u64 disk_total_bytes; 90d6397baeSChris Ball 910b86a832SChris Mason /* bytes used */ 920b86a832SChris Mason u64 bytes_used; 930b86a832SChris Mason 940b86a832SChris Mason /* optimal io alignment for this device */ 950b86a832SChris Mason u32 io_align; 960b86a832SChris Mason 970b86a832SChris Mason /* optimal io width for this device */ 980b86a832SChris Mason u32 io_width; 993c45bfc1SDulshani Gunawardhana /* type and info about this device */ 1003c45bfc1SDulshani Gunawardhana u64 type; 1010b86a832SChris Mason 1020b86a832SChris Mason /* minimal io size for this device */ 1030b86a832SChris Mason u32 sector_size; 1040b86a832SChris Mason 1050b86a832SChris Mason /* physical drive uuid (or lvm uuid) */ 106e17cade2SChris Mason u8 uuid[BTRFS_UUID_SIZE]; 1078b712842SChris Mason 108935e5cc9SMiao Xie /* 109935e5cc9SMiao Xie * size of the device on the current transaction 110935e5cc9SMiao Xie * 111935e5cc9SMiao Xie * This variant is update when committing the transaction, 112935e5cc9SMiao Xie * and protected by device_list_mutex 113935e5cc9SMiao Xie */ 114935e5cc9SMiao Xie u64 commit_total_bytes; 115935e5cc9SMiao Xie 116ce7213c7SMiao Xie /* bytes used on the current transaction */ 117ce7213c7SMiao Xie u64 commit_bytes_used; 118935e5cc9SMiao Xie /* 119935e5cc9SMiao Xie * used to manage the device which is resized 120935e5cc9SMiao Xie * 121935e5cc9SMiao Xie * It is protected by chunk_lock. 122935e5cc9SMiao Xie */ 123935e5cc9SMiao Xie struct list_head resized_list; 124935e5cc9SMiao Xie 1253c45bfc1SDulshani Gunawardhana /* for sending down flush barriers */ 1263c45bfc1SDulshani Gunawardhana int nobarriers; 1273c45bfc1SDulshani Gunawardhana struct bio *flush_bio; 1283c45bfc1SDulshani Gunawardhana struct completion flush_wait; 1293c45bfc1SDulshani Gunawardhana 130a2de733cSArne Jansen /* per-device scrub information */ 131d9d181c1SStefan Behrens struct scrub_ctx *scrub_device; 132a2de733cSArne Jansen 133d458b054SQu Wenruo struct btrfs_work work; 1341f78160cSXiao Guangrong struct rcu_head rcu; 1351f78160cSXiao Guangrong struct work_struct rcu_work; 13690519d66SArne Jansen 13790519d66SArne Jansen /* readahead state */ 13890519d66SArne Jansen spinlock_t reada_lock; 13990519d66SArne Jansen atomic_t reada_in_flight; 14090519d66SArne Jansen u64 reada_next; 14190519d66SArne Jansen struct reada_zone *reada_curr_zone; 14290519d66SArne Jansen struct radix_tree_root reada_zones; 14390519d66SArne Jansen struct radix_tree_root reada_extents; 144387125fcSChris Mason 145442a4f63SStefan Behrens /* disk I/O failure stats. For detailed description refer to 146442a4f63SStefan Behrens * enum btrfs_dev_stat_values in ioctl.h */ 147733f4fbbSStefan Behrens int dev_stats_valid; 148addc3fa7SMiao Xie 149addc3fa7SMiao Xie /* Counter to record the change of device stats */ 150addc3fa7SMiao Xie atomic_t dev_stats_ccnt; 151442a4f63SStefan Behrens atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX]; 1520b86a832SChris Mason }; 1530b86a832SChris Mason 1547cc8e58dSMiao Xie /* 1557cc8e58dSMiao Xie * If we read those variants at the context of their own lock, we needn't 1567cc8e58dSMiao Xie * use the following helpers, reading them directly is safe. 1577cc8e58dSMiao Xie */ 1587cc8e58dSMiao Xie #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 1597cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name) \ 1607cc8e58dSMiao Xie static inline u64 \ 1617cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev) \ 1627cc8e58dSMiao Xie { \ 1637cc8e58dSMiao Xie u64 size; \ 1647cc8e58dSMiao Xie unsigned int seq; \ 1657cc8e58dSMiao Xie \ 1667cc8e58dSMiao Xie do { \ 1677cc8e58dSMiao Xie seq = read_seqcount_begin(&dev->data_seqcount); \ 1687cc8e58dSMiao Xie size = dev->name; \ 1697cc8e58dSMiao Xie } while (read_seqcount_retry(&dev->data_seqcount, seq)); \ 1707cc8e58dSMiao Xie return size; \ 1717cc8e58dSMiao Xie } \ 1727cc8e58dSMiao Xie \ 1737cc8e58dSMiao Xie static inline void \ 1747cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ 1757cc8e58dSMiao Xie { \ 1767cc8e58dSMiao Xie preempt_disable(); \ 1777cc8e58dSMiao Xie write_seqcount_begin(&dev->data_seqcount); \ 1787cc8e58dSMiao Xie dev->name = size; \ 1797cc8e58dSMiao Xie write_seqcount_end(&dev->data_seqcount); \ 1807cc8e58dSMiao Xie preempt_enable(); \ 1817cc8e58dSMiao Xie } 1827cc8e58dSMiao Xie #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) 1837cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name) \ 1847cc8e58dSMiao Xie static inline u64 \ 1857cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev) \ 1867cc8e58dSMiao Xie { \ 1877cc8e58dSMiao Xie u64 size; \ 1887cc8e58dSMiao Xie \ 1897cc8e58dSMiao Xie preempt_disable(); \ 1907cc8e58dSMiao Xie size = dev->name; \ 1917cc8e58dSMiao Xie preempt_enable(); \ 1927cc8e58dSMiao Xie return size; \ 1937cc8e58dSMiao Xie } \ 1947cc8e58dSMiao Xie \ 1957cc8e58dSMiao Xie static inline void \ 1967cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ 1977cc8e58dSMiao Xie { \ 1987cc8e58dSMiao Xie preempt_disable(); \ 1997cc8e58dSMiao Xie dev->name = size; \ 2007cc8e58dSMiao Xie preempt_enable(); \ 2017cc8e58dSMiao Xie } 2027cc8e58dSMiao Xie #else 2037cc8e58dSMiao Xie #define BTRFS_DEVICE_GETSET_FUNCS(name) \ 2047cc8e58dSMiao Xie static inline u64 \ 2057cc8e58dSMiao Xie btrfs_device_get_##name(const struct btrfs_device *dev) \ 2067cc8e58dSMiao Xie { \ 2077cc8e58dSMiao Xie return dev->name; \ 2087cc8e58dSMiao Xie } \ 2097cc8e58dSMiao Xie \ 2107cc8e58dSMiao Xie static inline void \ 2117cc8e58dSMiao Xie btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ 2127cc8e58dSMiao Xie { \ 2137cc8e58dSMiao Xie dev->name = size; \ 2147cc8e58dSMiao Xie } 2157cc8e58dSMiao Xie #endif 2167cc8e58dSMiao Xie 2177cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(total_bytes); 2187cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes); 2197cc8e58dSMiao Xie BTRFS_DEVICE_GETSET_FUNCS(bytes_used); 2207cc8e58dSMiao Xie 2218a4b83ccSChris Mason struct btrfs_fs_devices { 2228a4b83ccSChris Mason u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 2238a4b83ccSChris Mason 2248a4b83ccSChris Mason u64 num_devices; 225a0af469bSChris Mason u64 open_devices; 2262b82032cSYan Zheng u64 rw_devices; 227cd02dca5SChris Mason u64 missing_devices; 2282b82032cSYan Zheng u64 total_rw_bytes; 22902db0844SJosef Bacik u64 total_devices; 2308a4b83ccSChris Mason struct block_device *latest_bdev; 231e5e9a520SChris Mason 232e5e9a520SChris Mason /* all of the devices in the FS, protected by a mutex 233e5e9a520SChris Mason * so we can safely walk it to write out the supers without 2349b011adfSWang Shilong * worrying about add/remove by the multi-device code. 2359b011adfSWang Shilong * Scrubbing super can kick off supers writing by holding 2369b011adfSWang Shilong * this mutex lock. 237e5e9a520SChris Mason */ 238e5e9a520SChris Mason struct mutex device_list_mutex; 2398a4b83ccSChris Mason struct list_head devices; 240b3075717SChris Mason 241935e5cc9SMiao Xie struct list_head resized_devices; 242b3075717SChris Mason /* devices not currently being allocated */ 243b3075717SChris Mason struct list_head alloc_list; 2448a4b83ccSChris Mason struct list_head list; 2452b82032cSYan Zheng 2462b82032cSYan Zheng struct btrfs_fs_devices *seed; 2472b82032cSYan Zheng int seeding; 2482b82032cSYan Zheng 2492b82032cSYan Zheng int opened; 250c289811cSChris Mason 251c289811cSChris Mason /* set when we find or add a device that doesn't have the 252c289811cSChris Mason * nonrot flag set 253c289811cSChris Mason */ 254c289811cSChris Mason int rotating; 2552e7910d6SAnand Jain 2565a13f430SAnand Jain struct btrfs_fs_info *fs_info; 2572e7910d6SAnand Jain /* sysfs kobjects */ 258c1b7e474SAnand Jain struct kobject fsid_kobj; 2592e7910d6SAnand Jain struct kobject *device_dir_kobj; 2602e7910d6SAnand Jain struct completion kobj_unregister; 2618a4b83ccSChris Mason }; 2628a4b83ccSChris Mason 263facc8a22SMiao Xie #define BTRFS_BIO_INLINE_CSUM_SIZE 64 264facc8a22SMiao Xie 2659be3395bSChris Mason /* 2669be3395bSChris Mason * we need the mirror number and stripe index to be passed around 2679be3395bSChris Mason * the call chain while we are processing end_io (especially errors). 2689be3395bSChris Mason * Really, what we need is a btrfs_bio structure that has this info 2699be3395bSChris Mason * and is properly sized with its stripe array, but we're not there 2709be3395bSChris Mason * quite yet. We have our own btrfs bioset, and all of the bios 2719be3395bSChris Mason * we allocate are actually btrfs_io_bios. We'll cram as much of 2729be3395bSChris Mason * struct btrfs_bio as we can into this over time. 2739be3395bSChris Mason */ 274facc8a22SMiao Xie typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err); 2759be3395bSChris Mason struct btrfs_io_bio { 276c1dc0896SMiao Xie unsigned int mirror_num; 277c1dc0896SMiao Xie unsigned int stripe_index; 278c1dc0896SMiao Xie u64 logical; 279facc8a22SMiao Xie u8 *csum; 280facc8a22SMiao Xie u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; 281facc8a22SMiao Xie u8 *csum_allocated; 282facc8a22SMiao Xie btrfs_io_bio_end_io_t *end_io; 2839be3395bSChris Mason struct bio bio; 2849be3395bSChris Mason }; 2859be3395bSChris Mason 2869be3395bSChris Mason static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio) 2879be3395bSChris Mason { 2889be3395bSChris Mason return container_of(bio, struct btrfs_io_bio, bio); 2899be3395bSChris Mason } 2909be3395bSChris Mason 291cea9e445SChris Mason struct btrfs_bio_stripe { 292cea9e445SChris Mason struct btrfs_device *dev; 293cea9e445SChris Mason u64 physical; 294fce3bb9aSLi Dongyang u64 length; /* only used for discard mappings */ 295cea9e445SChris Mason }; 296cea9e445SChris Mason 297a1d3c478SJan Schmidt struct btrfs_bio; 298a1d3c478SJan Schmidt typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err); 299a1d3c478SJan Schmidt 300a1d3c478SJan Schmidt struct btrfs_bio { 3016e9606d2SZhao Lei atomic_t refs; 302cea9e445SChris Mason atomic_t stripes_pending; 303c404e0dcSMiao Xie struct btrfs_fs_info *fs_info; 30410f11900SZhao Lei u64 map_type; /* get from map_lookup->type */ 305cea9e445SChris Mason bio_end_io_t *end_io; 3067d2b4daaSChris Mason struct bio *orig_bio; 307c55f1396SMiao Xie unsigned long flags; 308cea9e445SChris Mason void *private; 309a236aed1SChris Mason atomic_t error; 310a236aed1SChris Mason int max_errors; 311cea9e445SChris Mason int num_stripes; 312a1d3c478SJan Schmidt int mirror_num; 3132c8cdd6eSMiao Xie int num_tgtdevs; 3142c8cdd6eSMiao Xie int *tgtdev_map; 3158e5cfb55SZhao Lei /* 3168e5cfb55SZhao Lei * logical block numbers for the start of each stripe 3178e5cfb55SZhao Lei * The last one or two are p/q. These are sorted, 3188e5cfb55SZhao Lei * so raid_map[0] is the start of our full stripe 3198e5cfb55SZhao Lei */ 3208e5cfb55SZhao Lei u64 *raid_map; 321cea9e445SChris Mason struct btrfs_bio_stripe stripes[]; 322cea9e445SChris Mason }; 323cea9e445SChris Mason 324b2117a39SMiao Xie struct btrfs_device_info { 325b2117a39SMiao Xie struct btrfs_device *dev; 326b2117a39SMiao Xie u64 dev_offset; 327b2117a39SMiao Xie u64 max_avail; 32873c5de00SArne Jansen u64 total_avail; 329b2117a39SMiao Xie }; 330b2117a39SMiao Xie 33131e50229SLiu Bo struct btrfs_raid_attr { 33231e50229SLiu Bo int sub_stripes; /* sub_stripes info for map */ 33331e50229SLiu Bo int dev_stripes; /* stripes per dev */ 33431e50229SLiu Bo int devs_max; /* max devs to use */ 33531e50229SLiu Bo int devs_min; /* min devs needed */ 3368789f4feSZhao Lei int tolerated_failures; /* max tolerated fail devs */ 33731e50229SLiu Bo int devs_increment; /* ndevs has to be a multiple of this */ 33831e50229SLiu Bo int ncopies; /* how many copies to data has */ 33931e50229SLiu Bo }; 34031e50229SLiu Bo 341af902047SZhao Lei extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES]; 342621292baSDavid Sterba extern const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES]; 343af902047SZhao Lei extern const u64 btrfs_raid_group[BTRFS_NR_RAID_TYPES]; 344af902047SZhao Lei 3451abe9b8aSliubo struct map_lookup { 3461abe9b8aSliubo u64 type; 3471abe9b8aSliubo int io_align; 3481abe9b8aSliubo int io_width; 3493d8da678SLiu Bo u64 stripe_len; 3501abe9b8aSliubo int sector_size; 3511abe9b8aSliubo int num_stripes; 3521abe9b8aSliubo int sub_stripes; 3531abe9b8aSliubo struct btrfs_bio_stripe stripes[]; 3541abe9b8aSliubo }; 3551abe9b8aSliubo 356a2de733cSArne Jansen #define map_lookup_size(n) (sizeof(struct map_lookup) + \ 357a2de733cSArne Jansen (sizeof(struct btrfs_bio_stripe) * (n))) 358a2de733cSArne Jansen 359c9e9f97bSIlya Dryomov struct btrfs_balance_args; 36019a39dceSIlya Dryomov struct btrfs_balance_progress; 361c9e9f97bSIlya Dryomov struct btrfs_balance_control { 362c9e9f97bSIlya Dryomov struct btrfs_fs_info *fs_info; 363c9e9f97bSIlya Dryomov 364c9e9f97bSIlya Dryomov struct btrfs_balance_args data; 365c9e9f97bSIlya Dryomov struct btrfs_balance_args meta; 366c9e9f97bSIlya Dryomov struct btrfs_balance_args sys; 367c9e9f97bSIlya Dryomov 368c9e9f97bSIlya Dryomov u64 flags; 36919a39dceSIlya Dryomov 37019a39dceSIlya Dryomov struct btrfs_balance_progress stat; 371c9e9f97bSIlya Dryomov }; 372c9e9f97bSIlya Dryomov 373cf8cddd3SChristoph Hellwig enum btrfs_map_op { 374cf8cddd3SChristoph Hellwig BTRFS_MAP_READ, 375cf8cddd3SChristoph Hellwig BTRFS_MAP_WRITE, 376cf8cddd3SChristoph Hellwig BTRFS_MAP_DISCARD, 377cf8cddd3SChristoph Hellwig BTRFS_MAP_GET_READ_MIRRORS, 378cf8cddd3SChristoph Hellwig }; 379cf8cddd3SChristoph Hellwig 380cf8cddd3SChristoph Hellwig static inline enum btrfs_map_op btrfs_op(struct bio *bio) 381cf8cddd3SChristoph Hellwig { 382cf8cddd3SChristoph Hellwig switch (bio_op(bio)) { 383cf8cddd3SChristoph Hellwig case REQ_OP_DISCARD: 384cf8cddd3SChristoph Hellwig return BTRFS_MAP_DISCARD; 385cf8cddd3SChristoph Hellwig case REQ_OP_WRITE: 386cf8cddd3SChristoph Hellwig return BTRFS_MAP_WRITE; 387cf8cddd3SChristoph Hellwig default: 388cf8cddd3SChristoph Hellwig WARN_ON_ONCE(1); 389cf8cddd3SChristoph Hellwig case REQ_OP_READ: 390cf8cddd3SChristoph Hellwig return BTRFS_MAP_READ; 391cf8cddd3SChristoph Hellwig } 392cf8cddd3SChristoph Hellwig } 393cf8cddd3SChristoph Hellwig 3946d07bcecSMiao Xie int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, 3956d07bcecSMiao Xie u64 end, u64 *length); 3966e9606d2SZhao Lei void btrfs_get_bbio(struct btrfs_bio *bbio); 3976e9606d2SZhao Lei void btrfs_put_bbio(struct btrfs_bio *bbio); 398cf8cddd3SChristoph Hellwig int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, 399cea9e445SChris Mason u64 logical, u64 *length, 400a1d3c478SJan Schmidt struct btrfs_bio **bbio_ret, int mirror_num); 401cf8cddd3SChristoph Hellwig int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, 402af8e2d1dSMiao Xie u64 logical, u64 *length, 403af8e2d1dSMiao Xie struct btrfs_bio **bbio_ret, int mirror_num, 4048e5cfb55SZhao Lei int need_raid_map); 405ab8d0fc4SJeff Mahoney int btrfs_rmap_block(struct btrfs_fs_info *fs_info, 406a512bbf8SYan Zheng u64 chunk_start, u64 physical, u64 devid, 407a512bbf8SYan Zheng u64 **logical, int *naddrs, int *stripe_len); 4086bccf3abSJeff Mahoney int btrfs_read_sys_array(struct btrfs_fs_info *fs_info); 4095b4aacefSJeff Mahoney int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info); 4100b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 4112ff7e61eSJeff Mahoney struct btrfs_fs_info *fs_info, u64 type); 4120b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 4130b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 4142ff7e61eSJeff Mahoney int btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, 4158b712842SChris Mason int mirror_num, int async_submit); 4168a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 41797288f2cSChristoph Hellwig fmode_t flags, void *holder); 41897288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 4198a4b83ccSChris Mason struct btrfs_fs_devices **fs_devices_ret); 4208a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 4219eaed21eSEric Sandeen void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step); 42288acff64SAnand Jain void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info, 42388acff64SAnand Jain struct btrfs_device *device, struct btrfs_device *this_dev); 4242ff7e61eSJeff Mahoney int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info, 4257ba15b7dSStefan Behrens char *device_path, 4267ba15b7dSStefan Behrens struct btrfs_device **device); 4272ff7e61eSJeff Mahoney int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid, 4285c5c0df0SDavid Sterba char *devpath, 42924e0474bSAnand Jain struct btrfs_device **device); 43012bd2fc0SIlya Dryomov struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, 43112bd2fc0SIlya Dryomov const u64 *devid, 43212bd2fc0SIlya Dryomov const u8 *uuid); 4332ff7e61eSJeff Mahoney int btrfs_rm_device(struct btrfs_fs_info *fs_info, 4342ff7e61eSJeff Mahoney char *device_path, u64 devid); 435143bede5SJeff Mahoney void btrfs_cleanup_fs_uuids(void); 4365d964051SStefan Behrens int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); 4378f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans, 4388f18cf13SChris Mason struct btrfs_device *device, u64 new_size); 439aa1b8cd4SStefan Behrens struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, 4402b82032cSYan Zheng u8 *uuid, u8 *fsid); 4418f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 4425112febbSJeff Mahoney int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *path); 4432ff7e61eSJeff Mahoney int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, 4442ff7e61eSJeff Mahoney char *device_path, 4451c43366dSMiao Xie struct btrfs_device *srcdev, 446e93c89c1SStefan Behrens struct btrfs_device **device_out); 447c9e9f97bSIlya Dryomov int btrfs_balance(struct btrfs_balance_control *bctl, 448c9e9f97bSIlya Dryomov struct btrfs_ioctl_balance_args *bargs); 4492b6ba629SIlya Dryomov int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info); 45068310a5eSIlya Dryomov int btrfs_recover_balance(struct btrfs_fs_info *fs_info); 451837d5b6eSIlya Dryomov int btrfs_pause_balance(struct btrfs_fs_info *fs_info); 452a7e99c69SIlya Dryomov int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); 453f7a81ea4SStefan Behrens int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); 45470f80175SStefan Behrens int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info); 4552ff7e61eSJeff Mahoney int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset); 456499f377fSJeff Mahoney int find_free_dev_extent_start(struct btrfs_transaction *transaction, 457499f377fSJeff Mahoney struct btrfs_device *device, u64 num_bytes, 458499f377fSJeff Mahoney u64 search_start, u64 *start, u64 *max_avail); 4596df9a95eSJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans, 4606df9a95eSJosef Bacik struct btrfs_device *device, u64 num_bytes, 461ba1bf481SJosef Bacik u64 *start, u64 *max_avail); 462442a4f63SStefan Behrens void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); 4632ff7e61eSJeff Mahoney int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, 464b27f7c0cSDavid Sterba struct btrfs_ioctl_get_dev_stats *stats); 465cb517eabSMiao Xie void btrfs_init_devices_late(struct btrfs_fs_info *fs_info); 466733f4fbbSStefan Behrens int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info); 467733f4fbbSStefan Behrens int btrfs_run_dev_stats(struct btrfs_trans_handle *trans, 468733f4fbbSStefan Behrens struct btrfs_fs_info *fs_info); 469084b6e7cSQu Wenruo void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info, 470084b6e7cSQu Wenruo struct btrfs_device *srcdev); 471084b6e7cSQu Wenruo void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info, 472e93c89c1SStefan Behrens struct btrfs_device *srcdev); 473e93c89c1SStefan Behrens void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, 474e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 475e93c89c1SStefan Behrens void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, 476e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 47712b1c263SAnand Jain void btrfs_scratch_superblocks(struct block_device *bdev, char *device_path); 47853b381b3SDavid Woodhouse int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree, 47953b381b3SDavid Woodhouse u64 logical, u64 len, int mirror_num); 4802ff7e61eSJeff Mahoney unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, 48153b381b3SDavid Woodhouse struct btrfs_mapping_tree *map_tree, 48253b381b3SDavid Woodhouse u64 logical); 4836df9a95eSJosef Bacik int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, 4846bccf3abSJeff Mahoney struct btrfs_fs_info *fs_info, 4856df9a95eSJosef Bacik u64 chunk_offset, u64 chunk_size); 48647ab2a6cSJosef Bacik int btrfs_remove_chunk(struct btrfs_trans_handle *trans, 4875b4aacefSJeff Mahoney struct btrfs_fs_info *fs_info, u64 chunk_offset); 488addc3fa7SMiao Xie 489addc3fa7SMiao Xie static inline int btrfs_dev_stats_dirty(struct btrfs_device *dev) 490addc3fa7SMiao Xie { 491addc3fa7SMiao Xie return atomic_read(&dev->dev_stats_ccnt); 492addc3fa7SMiao Xie } 493addc3fa7SMiao Xie 494442a4f63SStefan Behrens static inline void btrfs_dev_stat_inc(struct btrfs_device *dev, 495442a4f63SStefan Behrens int index) 496442a4f63SStefan Behrens { 497442a4f63SStefan Behrens atomic_inc(dev->dev_stat_values + index); 498addc3fa7SMiao Xie smp_mb__before_atomic(); 499addc3fa7SMiao Xie atomic_inc(&dev->dev_stats_ccnt); 500442a4f63SStefan Behrens } 501442a4f63SStefan Behrens 502442a4f63SStefan Behrens static inline int btrfs_dev_stat_read(struct btrfs_device *dev, 503442a4f63SStefan Behrens int index) 504442a4f63SStefan Behrens { 505442a4f63SStefan Behrens return atomic_read(dev->dev_stat_values + index); 506442a4f63SStefan Behrens } 507442a4f63SStefan Behrens 508442a4f63SStefan Behrens static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev, 509442a4f63SStefan Behrens int index) 510442a4f63SStefan Behrens { 511442a4f63SStefan Behrens int ret; 512442a4f63SStefan Behrens 513442a4f63SStefan Behrens ret = atomic_xchg(dev->dev_stat_values + index, 0); 514addc3fa7SMiao Xie smp_mb__before_atomic(); 515addc3fa7SMiao Xie atomic_inc(&dev->dev_stats_ccnt); 516442a4f63SStefan Behrens return ret; 517442a4f63SStefan Behrens } 518442a4f63SStefan Behrens 519442a4f63SStefan Behrens static inline void btrfs_dev_stat_set(struct btrfs_device *dev, 520442a4f63SStefan Behrens int index, unsigned long val) 521442a4f63SStefan Behrens { 522442a4f63SStefan Behrens atomic_set(dev->dev_stat_values + index, val); 523addc3fa7SMiao Xie smp_mb__before_atomic(); 524addc3fa7SMiao Xie atomic_inc(&dev->dev_stats_ccnt); 525442a4f63SStefan Behrens } 526442a4f63SStefan Behrens 527442a4f63SStefan Behrens static inline void btrfs_dev_stat_reset(struct btrfs_device *dev, 528442a4f63SStefan Behrens int index) 529442a4f63SStefan Behrens { 530442a4f63SStefan Behrens btrfs_dev_stat_set(dev, index, 0); 531442a4f63SStefan Behrens } 532935e5cc9SMiao Xie 533935e5cc9SMiao Xie void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info); 5342ff7e61eSJeff Mahoney void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info, 535ce7213c7SMiao Xie struct btrfs_transaction *transaction); 53604216820SFilipe Manana 5373796d335SJeff Mahoney static inline void lock_chunks(struct btrfs_fs_info *fs_info) 53804216820SFilipe Manana { 5393796d335SJeff Mahoney mutex_lock(&fs_info->chunk_mutex); 54004216820SFilipe Manana } 54104216820SFilipe Manana 5423796d335SJeff Mahoney static inline void unlock_chunks(struct btrfs_fs_info *fs_info) 54304216820SFilipe Manana { 5443796d335SJeff Mahoney mutex_unlock(&fs_info->chunk_mutex); 54504216820SFilipe Manana } 54604216820SFilipe Manana 547c73eccf7SAnand Jain struct list_head *btrfs_get_fs_uuids(void); 5485a13f430SAnand Jain void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info); 5495a13f430SAnand Jain void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info); 55004216820SFilipe Manana 5510b86a832SChris Mason #endif 552