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; 390b86a832SChris Mason struct btrfs_root *dev_root; 40ffbd517dSChris Mason 41ffbd517dSChris Mason /* regular prio bios */ 42ffbd517dSChris Mason struct btrfs_pending_bios pending_bios; 43ffbd517dSChris Mason /* WRITE_SYNC bios */ 44ffbd517dSChris Mason struct btrfs_pending_bios pending_sync_bios; 45ffbd517dSChris Mason 468b712842SChris Mason int running_pending; 47dfe25020SChris Mason u64 generation; 48b3075717SChris Mason 492b82032cSYan Zheng int writeable; 50dfe25020SChris Mason int in_fs_metadata; 51cd02dca5SChris Mason int missing; 52d5e2003cSJosef Bacik int can_discard; 5363a212abSStefan Behrens int is_tgtdev_for_dev_replace; 54b3075717SChris Mason 558790d502SChris Mason spinlock_t io_lock; 560b86a832SChris Mason 570b86a832SChris Mason struct block_device *bdev; 580b86a832SChris Mason 59d4d77629STejun Heo /* the mode sent to blkdev_get */ 6015916de8SChris Mason fmode_t mode; 6115916de8SChris Mason 62606686eeSJosef Bacik struct rcu_string *name; 638a4b83ccSChris Mason 640b86a832SChris Mason /* the internal btrfs device id */ 650b86a832SChris Mason u64 devid; 660b86a832SChris Mason 670b86a832SChris Mason /* size of the device */ 680b86a832SChris Mason u64 total_bytes; 690b86a832SChris Mason 70d6397baeSChris Ball /* size of the 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; 810b86a832SChris Mason 820b86a832SChris Mason /* minimal io size for this device */ 830b86a832SChris Mason u32 sector_size; 840b86a832SChris Mason 850b86a832SChris Mason /* type and info about this device */ 860b86a832SChris Mason u64 type; 870b86a832SChris Mason 880b86a832SChris Mason /* physical drive uuid (or lvm uuid) */ 89e17cade2SChris Mason u8 uuid[BTRFS_UUID_SIZE]; 908b712842SChris Mason 91a2de733cSArne Jansen /* per-device scrub information */ 92d9d181c1SStefan Behrens struct scrub_ctx *scrub_device; 93a2de733cSArne Jansen 948b712842SChris Mason struct btrfs_work work; 951f78160cSXiao Guangrong struct rcu_head rcu; 961f78160cSXiao Guangrong struct work_struct rcu_work; 9790519d66SArne Jansen 9890519d66SArne Jansen /* readahead state */ 9990519d66SArne Jansen spinlock_t reada_lock; 10090519d66SArne Jansen atomic_t reada_in_flight; 10190519d66SArne Jansen u64 reada_next; 10290519d66SArne Jansen struct reada_zone *reada_curr_zone; 10390519d66SArne Jansen struct radix_tree_root reada_zones; 10490519d66SArne Jansen struct radix_tree_root reada_extents; 105387125fcSChris Mason 106387125fcSChris Mason /* for sending down flush barriers */ 107387125fcSChris Mason struct bio *flush_bio; 108387125fcSChris Mason struct completion flush_wait; 109387125fcSChris Mason int nobarriers; 110387125fcSChris Mason 111442a4f63SStefan Behrens /* disk I/O failure stats. For detailed description refer to 112442a4f63SStefan Behrens * enum btrfs_dev_stat_values in ioctl.h */ 113733f4fbbSStefan Behrens int dev_stats_valid; 114442a4f63SStefan Behrens int dev_stats_dirty; /* counters need to be written to disk */ 115442a4f63SStefan Behrens atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX]; 1160b86a832SChris Mason }; 1170b86a832SChris Mason 1188a4b83ccSChris Mason struct btrfs_fs_devices { 1198a4b83ccSChris Mason u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 1208a4b83ccSChris Mason 121d4a78947SWu Fengguang /* the device with this id has the most recent copy of the super */ 1228a4b83ccSChris Mason u64 latest_devid; 1238a4b83ccSChris Mason u64 latest_trans; 1248a4b83ccSChris Mason u64 num_devices; 125a0af469bSChris Mason u64 open_devices; 1262b82032cSYan Zheng u64 rw_devices; 127cd02dca5SChris Mason u64 missing_devices; 1282b82032cSYan Zheng u64 total_rw_bytes; 129d5e2003cSJosef Bacik u64 num_can_discard; 13002db0844SJosef Bacik u64 total_devices; 1318a4b83ccSChris Mason struct block_device *latest_bdev; 132e5e9a520SChris Mason 133e5e9a520SChris Mason /* all of the devices in the FS, protected by a mutex 134e5e9a520SChris Mason * so we can safely walk it to write out the supers without 135e5e9a520SChris Mason * worrying about add/remove by the multi-device code 136e5e9a520SChris Mason */ 137e5e9a520SChris Mason struct mutex device_list_mutex; 1388a4b83ccSChris Mason struct list_head devices; 139b3075717SChris Mason 140b3075717SChris Mason /* devices not currently being allocated */ 141b3075717SChris Mason struct list_head alloc_list; 1428a4b83ccSChris Mason struct list_head list; 1432b82032cSYan Zheng 1442b82032cSYan Zheng struct btrfs_fs_devices *seed; 1452b82032cSYan Zheng int seeding; 1462b82032cSYan Zheng 1472b82032cSYan Zheng int opened; 148c289811cSChris Mason 149c289811cSChris Mason /* set when we find or add a device that doesn't have the 150c289811cSChris Mason * nonrot flag set 151c289811cSChris Mason */ 152c289811cSChris Mason int rotating; 1538a4b83ccSChris Mason }; 1548a4b83ccSChris Mason 155facc8a22SMiao Xie #define BTRFS_BIO_INLINE_CSUM_SIZE 64 156facc8a22SMiao Xie 1579be3395bSChris Mason /* 1589be3395bSChris Mason * we need the mirror number and stripe index to be passed around 1599be3395bSChris Mason * the call chain while we are processing end_io (especially errors). 1609be3395bSChris Mason * Really, what we need is a btrfs_bio structure that has this info 1619be3395bSChris Mason * and is properly sized with its stripe array, but we're not there 1629be3395bSChris Mason * quite yet. We have our own btrfs bioset, and all of the bios 1639be3395bSChris Mason * we allocate are actually btrfs_io_bios. We'll cram as much of 1649be3395bSChris Mason * struct btrfs_bio as we can into this over time. 1659be3395bSChris Mason */ 166facc8a22SMiao Xie typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err); 1679be3395bSChris Mason struct btrfs_io_bio { 1689be3395bSChris Mason unsigned long mirror_num; 1699be3395bSChris Mason unsigned long stripe_index; 170facc8a22SMiao Xie u8 *csum; 171facc8a22SMiao Xie u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; 172facc8a22SMiao Xie u8 *csum_allocated; 173facc8a22SMiao Xie btrfs_io_bio_end_io_t *end_io; 1749be3395bSChris Mason struct bio bio; 1759be3395bSChris Mason }; 1769be3395bSChris Mason 1779be3395bSChris Mason static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio) 1789be3395bSChris Mason { 1799be3395bSChris Mason return container_of(bio, struct btrfs_io_bio, bio); 1809be3395bSChris Mason } 1819be3395bSChris Mason 182cea9e445SChris Mason struct btrfs_bio_stripe { 183cea9e445SChris Mason struct btrfs_device *dev; 184cea9e445SChris Mason u64 physical; 185fce3bb9aSLi Dongyang u64 length; /* only used for discard mappings */ 186cea9e445SChris Mason }; 187cea9e445SChris Mason 188a1d3c478SJan Schmidt struct btrfs_bio; 189a1d3c478SJan Schmidt typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err); 190a1d3c478SJan Schmidt 191a1d3c478SJan Schmidt struct btrfs_bio { 192cea9e445SChris Mason atomic_t stripes_pending; 193cea9e445SChris Mason bio_end_io_t *end_io; 1947d2b4daaSChris Mason struct bio *orig_bio; 195cea9e445SChris Mason void *private; 196a236aed1SChris Mason atomic_t error; 197a236aed1SChris Mason int max_errors; 198cea9e445SChris Mason int num_stripes; 199a1d3c478SJan Schmidt int mirror_num; 200cea9e445SChris Mason struct btrfs_bio_stripe stripes[]; 201cea9e445SChris Mason }; 202cea9e445SChris Mason 203b2117a39SMiao Xie struct btrfs_device_info { 204b2117a39SMiao Xie struct btrfs_device *dev; 205b2117a39SMiao Xie u64 dev_offset; 206b2117a39SMiao Xie u64 max_avail; 20773c5de00SArne Jansen u64 total_avail; 208b2117a39SMiao Xie }; 209b2117a39SMiao Xie 21031e50229SLiu Bo struct btrfs_raid_attr { 21131e50229SLiu Bo int sub_stripes; /* sub_stripes info for map */ 21231e50229SLiu Bo int dev_stripes; /* stripes per dev */ 21331e50229SLiu Bo int devs_max; /* max devs to use */ 21431e50229SLiu Bo int devs_min; /* min devs needed */ 21531e50229SLiu Bo int devs_increment; /* ndevs has to be a multiple of this */ 21631e50229SLiu Bo int ncopies; /* how many copies to data has */ 21731e50229SLiu Bo }; 21831e50229SLiu Bo 2191abe9b8aSliubo struct map_lookup { 2201abe9b8aSliubo u64 type; 2211abe9b8aSliubo int io_align; 2221abe9b8aSliubo int io_width; 2231abe9b8aSliubo int stripe_len; 2241abe9b8aSliubo int sector_size; 2251abe9b8aSliubo int num_stripes; 2261abe9b8aSliubo int sub_stripes; 2271abe9b8aSliubo struct btrfs_bio_stripe stripes[]; 2281abe9b8aSliubo }; 2291abe9b8aSliubo 230a2de733cSArne Jansen #define map_lookup_size(n) (sizeof(struct map_lookup) + \ 231a2de733cSArne Jansen (sizeof(struct btrfs_bio_stripe) * (n))) 232a2de733cSArne Jansen 233f43ffb60SIlya Dryomov /* 234f43ffb60SIlya Dryomov * Restriper's general type filter 235f43ffb60SIlya Dryomov */ 236f43ffb60SIlya Dryomov #define BTRFS_BALANCE_DATA (1ULL << 0) 237f43ffb60SIlya Dryomov #define BTRFS_BALANCE_SYSTEM (1ULL << 1) 238f43ffb60SIlya Dryomov #define BTRFS_BALANCE_METADATA (1ULL << 2) 239f43ffb60SIlya Dryomov 240f43ffb60SIlya Dryomov #define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \ 241f43ffb60SIlya Dryomov BTRFS_BALANCE_SYSTEM | \ 242f43ffb60SIlya Dryomov BTRFS_BALANCE_METADATA) 243e4d8ec0fSIlya Dryomov 244e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_FORCE (1ULL << 3) 24559641015SIlya Dryomov #define BTRFS_BALANCE_RESUME (1ULL << 4) 246e4d8ec0fSIlya Dryomov 247ed25e9b2SIlya Dryomov /* 248ed25e9b2SIlya Dryomov * Balance filters 249ed25e9b2SIlya Dryomov */ 250ed25e9b2SIlya Dryomov #define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0) 2515ce5b3c0SIlya Dryomov #define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1) 252409d404bSIlya Dryomov #define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2) 25394e60d5aSIlya Dryomov #define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3) 254ea67176aSIlya Dryomov #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4) 255f43ffb60SIlya Dryomov 256cfa4c961SIlya Dryomov /* 257cfa4c961SIlya Dryomov * Profile changing flags. When SOFT is set we won't relocate chunk if 258cfa4c961SIlya Dryomov * it already has the target profile (even though it may be 259cfa4c961SIlya Dryomov * half-filled). 260cfa4c961SIlya Dryomov */ 261e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8) 262cfa4c961SIlya Dryomov #define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9) 263e4d8ec0fSIlya Dryomov 264c9e9f97bSIlya Dryomov struct btrfs_balance_args; 26519a39dceSIlya Dryomov struct btrfs_balance_progress; 266c9e9f97bSIlya Dryomov struct btrfs_balance_control { 267c9e9f97bSIlya Dryomov struct btrfs_fs_info *fs_info; 268c9e9f97bSIlya Dryomov 269c9e9f97bSIlya Dryomov struct btrfs_balance_args data; 270c9e9f97bSIlya Dryomov struct btrfs_balance_args meta; 271c9e9f97bSIlya Dryomov struct btrfs_balance_args sys; 272c9e9f97bSIlya Dryomov 273c9e9f97bSIlya Dryomov u64 flags; 27419a39dceSIlya Dryomov 27519a39dceSIlya Dryomov struct btrfs_balance_progress stat; 276c9e9f97bSIlya Dryomov }; 277c9e9f97bSIlya Dryomov 2786d07bcecSMiao Xie int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, 2796d07bcecSMiao Xie u64 end, u64 *length); 2806d07bcecSMiao Xie 281a1d3c478SJan Schmidt #define btrfs_bio_size(n) (sizeof(struct btrfs_bio) + \ 282cea9e445SChris Mason (sizeof(struct btrfs_bio_stripe) * (n))) 283cea9e445SChris Mason 2843ec706c8SStefan Behrens int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, 285cea9e445SChris Mason u64 logical, u64 *length, 286a1d3c478SJan Schmidt struct btrfs_bio **bbio_ret, int mirror_num); 287a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, 288a512bbf8SYan Zheng u64 chunk_start, u64 physical, u64 devid, 289a512bbf8SYan Zheng u64 **logical, int *naddrs, int *stripe_len); 290e4404d6eSYan Zheng int btrfs_read_sys_array(struct btrfs_root *root); 2910b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root); 2920b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 2932b82032cSYan Zheng struct btrfs_root *extent_root, u64 type); 2940b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 2950b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 296f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 2978b712842SChris Mason int mirror_num, int async_submit); 2988a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 29997288f2cSChristoph Hellwig fmode_t flags, void *holder); 30097288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 3018a4b83ccSChris Mason struct btrfs_fs_devices **fs_devices_ret); 3028a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 3038dabb742SStefan Behrens void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 3048dabb742SStefan Behrens struct btrfs_fs_devices *fs_devices, int step); 3057ba15b7dSStefan Behrens int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, 3067ba15b7dSStefan Behrens char *device_path, 3077ba15b7dSStefan Behrens struct btrfs_device **device); 308a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path); 309143bede5SJeff Mahoney void btrfs_cleanup_fs_uuids(void); 3105d964051SStefan Behrens int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); 3118f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans, 3128f18cf13SChris Mason struct btrfs_device *device, u64 new_size); 313aa1b8cd4SStefan Behrens struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, 3142b82032cSYan Zheng u8 *uuid, u8 *fsid); 3158f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 316788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path); 317e93c89c1SStefan Behrens int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, 318e93c89c1SStefan Behrens struct btrfs_device **device_out); 319c9e9f97bSIlya Dryomov int btrfs_balance(struct btrfs_balance_control *bctl, 320c9e9f97bSIlya Dryomov struct btrfs_ioctl_balance_args *bargs); 3212b6ba629SIlya Dryomov int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info); 32268310a5eSIlya Dryomov int btrfs_recover_balance(struct btrfs_fs_info *fs_info); 323837d5b6eSIlya Dryomov int btrfs_pause_balance(struct btrfs_fs_info *fs_info); 324a7e99c69SIlya Dryomov int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); 325*f7a81ea4SStefan Behrens int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); 3262b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 3276df9a95eSJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans, 3286df9a95eSJosef Bacik struct btrfs_device *device, u64 num_bytes, 329ba1bf481SJosef Bacik u64 *start, u64 *max_avail); 330442a4f63SStefan Behrens void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); 331c11d2c23SStefan Behrens int btrfs_get_dev_stats(struct btrfs_root *root, 332b27f7c0cSDavid Sterba struct btrfs_ioctl_get_dev_stats *stats); 333cb517eabSMiao Xie void btrfs_init_devices_late(struct btrfs_fs_info *fs_info); 334733f4fbbSStefan Behrens int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info); 335733f4fbbSStefan Behrens int btrfs_run_dev_stats(struct btrfs_trans_handle *trans, 336733f4fbbSStefan Behrens struct btrfs_fs_info *fs_info); 337e93c89c1SStefan Behrens void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info, 338e93c89c1SStefan Behrens struct btrfs_device *srcdev); 339e93c89c1SStefan Behrens void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, 340e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 341e93c89c1SStefan Behrens void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, 342e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 343a8a6dab7SStefan Behrens int btrfs_scratch_superblock(struct btrfs_device *device); 34453b381b3SDavid Woodhouse int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree, 34553b381b3SDavid Woodhouse u64 logical, u64 len, int mirror_num); 34653b381b3SDavid Woodhouse unsigned long btrfs_full_stripe_len(struct btrfs_root *root, 34753b381b3SDavid Woodhouse struct btrfs_mapping_tree *map_tree, 34853b381b3SDavid Woodhouse u64 logical); 3496df9a95eSJosef Bacik int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, 3506df9a95eSJosef Bacik struct btrfs_root *extent_root, 3516df9a95eSJosef Bacik u64 chunk_offset, u64 chunk_size); 352442a4f63SStefan Behrens static inline void btrfs_dev_stat_inc(struct btrfs_device *dev, 353442a4f63SStefan Behrens int index) 354442a4f63SStefan Behrens { 355442a4f63SStefan Behrens atomic_inc(dev->dev_stat_values + index); 356442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 357442a4f63SStefan Behrens } 358442a4f63SStefan Behrens 359442a4f63SStefan Behrens static inline int btrfs_dev_stat_read(struct btrfs_device *dev, 360442a4f63SStefan Behrens int index) 361442a4f63SStefan Behrens { 362442a4f63SStefan Behrens return atomic_read(dev->dev_stat_values + index); 363442a4f63SStefan Behrens } 364442a4f63SStefan Behrens 365442a4f63SStefan Behrens static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev, 366442a4f63SStefan Behrens int index) 367442a4f63SStefan Behrens { 368442a4f63SStefan Behrens int ret; 369442a4f63SStefan Behrens 370442a4f63SStefan Behrens ret = atomic_xchg(dev->dev_stat_values + index, 0); 371442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 372442a4f63SStefan Behrens return ret; 373442a4f63SStefan Behrens } 374442a4f63SStefan Behrens 375442a4f63SStefan Behrens static inline void btrfs_dev_stat_set(struct btrfs_device *dev, 376442a4f63SStefan Behrens int index, unsigned long val) 377442a4f63SStefan Behrens { 378442a4f63SStefan Behrens atomic_set(dev->dev_stat_values + index, val); 379442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 380442a4f63SStefan Behrens } 381442a4f63SStefan Behrens 382442a4f63SStefan Behrens static inline void btrfs_dev_stat_reset(struct btrfs_device *dev, 383442a4f63SStefan Behrens int index) 384442a4f63SStefan Behrens { 385442a4f63SStefan Behrens btrfs_dev_stat_set(dev, index, 0); 386442a4f63SStefan Behrens } 3870b86a832SChris Mason #endif 388