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 46dfe25020SChris Mason u64 generation; 473c45bfc1SDulshani Gunawardhana int running_pending; 482b82032cSYan Zheng int writeable; 49dfe25020SChris Mason int in_fs_metadata; 50cd02dca5SChris Mason int missing; 51d5e2003cSJosef Bacik int can_discard; 5263a212abSStefan Behrens int is_tgtdev_for_dev_replace; 53b3075717SChris Mason 548790d502SChris Mason spinlock_t io_lock; 553c45bfc1SDulshani Gunawardhana /* the mode sent to blkdev_get */ 563c45bfc1SDulshani Gunawardhana fmode_t mode; 570b86a832SChris Mason 580b86a832SChris Mason struct block_device *bdev; 590b86a832SChris Mason 6015916de8SChris Mason 61606686eeSJosef Bacik struct rcu_string *name; 628a4b83ccSChris Mason 630b86a832SChris Mason /* the internal btrfs device id */ 640b86a832SChris Mason u64 devid; 650b86a832SChris Mason 660b86a832SChris Mason /* size of the device */ 670b86a832SChris Mason u64 total_bytes; 680b86a832SChris Mason 69d6397baeSChris Ball /* size of the disk */ 70d6397baeSChris Ball u64 disk_total_bytes; 71d6397baeSChris Ball 720b86a832SChris Mason /* bytes used */ 730b86a832SChris Mason u64 bytes_used; 740b86a832SChris Mason 750b86a832SChris Mason /* optimal io alignment for this device */ 760b86a832SChris Mason u32 io_align; 770b86a832SChris Mason 780b86a832SChris Mason /* optimal io width for this device */ 790b86a832SChris Mason u32 io_width; 803c45bfc1SDulshani Gunawardhana /* type and info about this device */ 813c45bfc1SDulshani Gunawardhana u64 type; 820b86a832SChris Mason 830b86a832SChris Mason /* minimal io size for this device */ 840b86a832SChris Mason u32 sector_size; 850b86a832SChris Mason 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 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 1359b011adfSWang Shilong * worrying about add/remove by the multi-device code. 1369b011adfSWang Shilong * Scrubbing super can kick off supers writing by holding 1379b011adfSWang Shilong * this mutex lock. 138e5e9a520SChris Mason */ 139e5e9a520SChris Mason struct mutex device_list_mutex; 1408a4b83ccSChris Mason struct list_head devices; 141b3075717SChris Mason 142b3075717SChris Mason /* devices not currently being allocated */ 143b3075717SChris Mason struct list_head alloc_list; 1448a4b83ccSChris Mason struct list_head list; 1452b82032cSYan Zheng 1462b82032cSYan Zheng struct btrfs_fs_devices *seed; 1472b82032cSYan Zheng int seeding; 1482b82032cSYan Zheng 1492b82032cSYan Zheng int opened; 150c289811cSChris Mason 151c289811cSChris Mason /* set when we find or add a device that doesn't have the 152c289811cSChris Mason * nonrot flag set 153c289811cSChris Mason */ 154c289811cSChris Mason int rotating; 1558a4b83ccSChris Mason }; 1568a4b83ccSChris Mason 157facc8a22SMiao Xie #define BTRFS_BIO_INLINE_CSUM_SIZE 64 158facc8a22SMiao Xie 1599be3395bSChris Mason /* 1609be3395bSChris Mason * we need the mirror number and stripe index to be passed around 1619be3395bSChris Mason * the call chain while we are processing end_io (especially errors). 1629be3395bSChris Mason * Really, what we need is a btrfs_bio structure that has this info 1639be3395bSChris Mason * and is properly sized with its stripe array, but we're not there 1649be3395bSChris Mason * quite yet. We have our own btrfs bioset, and all of the bios 1659be3395bSChris Mason * we allocate are actually btrfs_io_bios. We'll cram as much of 1669be3395bSChris Mason * struct btrfs_bio as we can into this over time. 1679be3395bSChris Mason */ 168facc8a22SMiao Xie typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err); 1699be3395bSChris Mason struct btrfs_io_bio { 1709be3395bSChris Mason unsigned long mirror_num; 1719be3395bSChris Mason unsigned long stripe_index; 172facc8a22SMiao Xie u8 *csum; 173facc8a22SMiao Xie u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; 174facc8a22SMiao Xie u8 *csum_allocated; 175facc8a22SMiao Xie btrfs_io_bio_end_io_t *end_io; 1769be3395bSChris Mason struct bio bio; 1779be3395bSChris Mason }; 1789be3395bSChris Mason 1799be3395bSChris Mason static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio) 1809be3395bSChris Mason { 1819be3395bSChris Mason return container_of(bio, struct btrfs_io_bio, bio); 1829be3395bSChris Mason } 1839be3395bSChris Mason 184cea9e445SChris Mason struct btrfs_bio_stripe { 185cea9e445SChris Mason struct btrfs_device *dev; 186cea9e445SChris Mason u64 physical; 187fce3bb9aSLi Dongyang u64 length; /* only used for discard mappings */ 188cea9e445SChris Mason }; 189cea9e445SChris Mason 190a1d3c478SJan Schmidt struct btrfs_bio; 191a1d3c478SJan Schmidt typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err); 192a1d3c478SJan Schmidt 193a1d3c478SJan Schmidt struct btrfs_bio { 194cea9e445SChris Mason atomic_t stripes_pending; 195c404e0dcSMiao Xie struct btrfs_fs_info *fs_info; 196cea9e445SChris Mason bio_end_io_t *end_io; 1977d2b4daaSChris Mason struct bio *orig_bio; 198cea9e445SChris Mason void *private; 199a236aed1SChris Mason atomic_t error; 200a236aed1SChris Mason int max_errors; 201cea9e445SChris Mason int num_stripes; 202a1d3c478SJan Schmidt int mirror_num; 203cea9e445SChris Mason struct btrfs_bio_stripe stripes[]; 204cea9e445SChris Mason }; 205cea9e445SChris Mason 206b2117a39SMiao Xie struct btrfs_device_info { 207b2117a39SMiao Xie struct btrfs_device *dev; 208b2117a39SMiao Xie u64 dev_offset; 209b2117a39SMiao Xie u64 max_avail; 21073c5de00SArne Jansen u64 total_avail; 211b2117a39SMiao Xie }; 212b2117a39SMiao Xie 21331e50229SLiu Bo struct btrfs_raid_attr { 21431e50229SLiu Bo int sub_stripes; /* sub_stripes info for map */ 21531e50229SLiu Bo int dev_stripes; /* stripes per dev */ 21631e50229SLiu Bo int devs_max; /* max devs to use */ 21731e50229SLiu Bo int devs_min; /* min devs needed */ 21831e50229SLiu Bo int devs_increment; /* ndevs has to be a multiple of this */ 21931e50229SLiu Bo int ncopies; /* how many copies to data has */ 22031e50229SLiu Bo }; 22131e50229SLiu Bo 2221abe9b8aSliubo struct map_lookup { 2231abe9b8aSliubo u64 type; 2241abe9b8aSliubo int io_align; 2251abe9b8aSliubo int io_width; 2261abe9b8aSliubo int stripe_len; 2271abe9b8aSliubo int sector_size; 2281abe9b8aSliubo int num_stripes; 2291abe9b8aSliubo int sub_stripes; 2301abe9b8aSliubo struct btrfs_bio_stripe stripes[]; 2311abe9b8aSliubo }; 2321abe9b8aSliubo 233a2de733cSArne Jansen #define map_lookup_size(n) (sizeof(struct map_lookup) + \ 234a2de733cSArne Jansen (sizeof(struct btrfs_bio_stripe) * (n))) 235a2de733cSArne Jansen 236f43ffb60SIlya Dryomov /* 237f43ffb60SIlya Dryomov * Restriper's general type filter 238f43ffb60SIlya Dryomov */ 239f43ffb60SIlya Dryomov #define BTRFS_BALANCE_DATA (1ULL << 0) 240f43ffb60SIlya Dryomov #define BTRFS_BALANCE_SYSTEM (1ULL << 1) 241f43ffb60SIlya Dryomov #define BTRFS_BALANCE_METADATA (1ULL << 2) 242f43ffb60SIlya Dryomov 243f43ffb60SIlya Dryomov #define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \ 244f43ffb60SIlya Dryomov BTRFS_BALANCE_SYSTEM | \ 245f43ffb60SIlya Dryomov BTRFS_BALANCE_METADATA) 246e4d8ec0fSIlya Dryomov 247e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_FORCE (1ULL << 3) 24859641015SIlya Dryomov #define BTRFS_BALANCE_RESUME (1ULL << 4) 249e4d8ec0fSIlya Dryomov 250ed25e9b2SIlya Dryomov /* 251ed25e9b2SIlya Dryomov * Balance filters 252ed25e9b2SIlya Dryomov */ 253ed25e9b2SIlya Dryomov #define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0) 2545ce5b3c0SIlya Dryomov #define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1) 255409d404bSIlya Dryomov #define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2) 25694e60d5aSIlya Dryomov #define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3) 257ea67176aSIlya Dryomov #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4) 258f43ffb60SIlya Dryomov 259cfa4c961SIlya Dryomov /* 260cfa4c961SIlya Dryomov * Profile changing flags. When SOFT is set we won't relocate chunk if 261cfa4c961SIlya Dryomov * it already has the target profile (even though it may be 262cfa4c961SIlya Dryomov * half-filled). 263cfa4c961SIlya Dryomov */ 264e4d8ec0fSIlya Dryomov #define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8) 265cfa4c961SIlya Dryomov #define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9) 266e4d8ec0fSIlya Dryomov 267c9e9f97bSIlya Dryomov struct btrfs_balance_args; 26819a39dceSIlya Dryomov struct btrfs_balance_progress; 269c9e9f97bSIlya Dryomov struct btrfs_balance_control { 270c9e9f97bSIlya Dryomov struct btrfs_fs_info *fs_info; 271c9e9f97bSIlya Dryomov 272c9e9f97bSIlya Dryomov struct btrfs_balance_args data; 273c9e9f97bSIlya Dryomov struct btrfs_balance_args meta; 274c9e9f97bSIlya Dryomov struct btrfs_balance_args sys; 275c9e9f97bSIlya Dryomov 276c9e9f97bSIlya Dryomov u64 flags; 27719a39dceSIlya Dryomov 27819a39dceSIlya Dryomov struct btrfs_balance_progress stat; 279c9e9f97bSIlya Dryomov }; 280c9e9f97bSIlya Dryomov 2816d07bcecSMiao Xie int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, 2826d07bcecSMiao Xie u64 end, u64 *length); 2836d07bcecSMiao Xie 284a1d3c478SJan Schmidt #define btrfs_bio_size(n) (sizeof(struct btrfs_bio) + \ 285cea9e445SChris Mason (sizeof(struct btrfs_bio_stripe) * (n))) 286cea9e445SChris Mason 2873ec706c8SStefan Behrens int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, 288cea9e445SChris Mason u64 logical, u64 *length, 289a1d3c478SJan Schmidt struct btrfs_bio **bbio_ret, int mirror_num); 290a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, 291a512bbf8SYan Zheng u64 chunk_start, u64 physical, u64 devid, 292a512bbf8SYan Zheng u64 **logical, int *naddrs, int *stripe_len); 293e4404d6eSYan Zheng int btrfs_read_sys_array(struct btrfs_root *root); 2940b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root); 2950b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 2962b82032cSYan Zheng struct btrfs_root *extent_root, u64 type); 2970b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 2980b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 299f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 3008b712842SChris Mason int mirror_num, int async_submit); 3018a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 30297288f2cSChristoph Hellwig fmode_t flags, void *holder); 30397288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 3048a4b83ccSChris Mason struct btrfs_fs_devices **fs_devices_ret); 3058a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 3068dabb742SStefan Behrens void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 3078dabb742SStefan Behrens struct btrfs_fs_devices *fs_devices, int step); 3087ba15b7dSStefan Behrens int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, 3097ba15b7dSStefan Behrens char *device_path, 3107ba15b7dSStefan Behrens struct btrfs_device **device); 31112bd2fc0SIlya Dryomov struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, 31212bd2fc0SIlya Dryomov const u64 *devid, 31312bd2fc0SIlya Dryomov const u8 *uuid); 314a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path); 315143bede5SJeff Mahoney void btrfs_cleanup_fs_uuids(void); 3165d964051SStefan Behrens int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); 3178f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans, 3188f18cf13SChris Mason struct btrfs_device *device, u64 new_size); 319aa1b8cd4SStefan Behrens struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, 3202b82032cSYan Zheng u8 *uuid, u8 *fsid); 3218f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 322788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path); 323e93c89c1SStefan Behrens int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, 324e93c89c1SStefan Behrens struct btrfs_device **device_out); 325c9e9f97bSIlya Dryomov int btrfs_balance(struct btrfs_balance_control *bctl, 326c9e9f97bSIlya Dryomov struct btrfs_ioctl_balance_args *bargs); 3272b6ba629SIlya Dryomov int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info); 32868310a5eSIlya Dryomov int btrfs_recover_balance(struct btrfs_fs_info *fs_info); 329837d5b6eSIlya Dryomov int btrfs_pause_balance(struct btrfs_fs_info *fs_info); 330a7e99c69SIlya Dryomov int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); 331f7a81ea4SStefan Behrens int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); 33270f80175SStefan Behrens int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info); 3332b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 3346df9a95eSJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans, 3356df9a95eSJosef Bacik struct btrfs_device *device, u64 num_bytes, 336ba1bf481SJosef Bacik u64 *start, u64 *max_avail); 337442a4f63SStefan Behrens void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); 338c11d2c23SStefan Behrens int btrfs_get_dev_stats(struct btrfs_root *root, 339b27f7c0cSDavid Sterba struct btrfs_ioctl_get_dev_stats *stats); 340cb517eabSMiao Xie void btrfs_init_devices_late(struct btrfs_fs_info *fs_info); 341733f4fbbSStefan Behrens int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info); 342733f4fbbSStefan Behrens int btrfs_run_dev_stats(struct btrfs_trans_handle *trans, 343733f4fbbSStefan Behrens struct btrfs_fs_info *fs_info); 344e93c89c1SStefan Behrens void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info, 345e93c89c1SStefan Behrens struct btrfs_device *srcdev); 346e93c89c1SStefan Behrens void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, 347e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 348e93c89c1SStefan Behrens void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, 349e93c89c1SStefan Behrens struct btrfs_device *tgtdev); 350a8a6dab7SStefan Behrens int btrfs_scratch_superblock(struct btrfs_device *device); 35153b381b3SDavid Woodhouse int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree, 35253b381b3SDavid Woodhouse u64 logical, u64 len, int mirror_num); 35353b381b3SDavid Woodhouse unsigned long btrfs_full_stripe_len(struct btrfs_root *root, 35453b381b3SDavid Woodhouse struct btrfs_mapping_tree *map_tree, 35553b381b3SDavid Woodhouse u64 logical); 3566df9a95eSJosef Bacik int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, 3576df9a95eSJosef Bacik struct btrfs_root *extent_root, 3586df9a95eSJosef Bacik u64 chunk_offset, u64 chunk_size); 359442a4f63SStefan Behrens static inline void btrfs_dev_stat_inc(struct btrfs_device *dev, 360442a4f63SStefan Behrens int index) 361442a4f63SStefan Behrens { 362442a4f63SStefan Behrens atomic_inc(dev->dev_stat_values + index); 363442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 364442a4f63SStefan Behrens } 365442a4f63SStefan Behrens 366442a4f63SStefan Behrens static inline int btrfs_dev_stat_read(struct btrfs_device *dev, 367442a4f63SStefan Behrens int index) 368442a4f63SStefan Behrens { 369442a4f63SStefan Behrens return atomic_read(dev->dev_stat_values + index); 370442a4f63SStefan Behrens } 371442a4f63SStefan Behrens 372442a4f63SStefan Behrens static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev, 373442a4f63SStefan Behrens int index) 374442a4f63SStefan Behrens { 375442a4f63SStefan Behrens int ret; 376442a4f63SStefan Behrens 377442a4f63SStefan Behrens ret = atomic_xchg(dev->dev_stat_values + index, 0); 378442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 379442a4f63SStefan Behrens return ret; 380442a4f63SStefan Behrens } 381442a4f63SStefan Behrens 382442a4f63SStefan Behrens static inline void btrfs_dev_stat_set(struct btrfs_device *dev, 383442a4f63SStefan Behrens int index, unsigned long val) 384442a4f63SStefan Behrens { 385442a4f63SStefan Behrens atomic_set(dev->dev_stat_values + index, val); 386442a4f63SStefan Behrens dev->dev_stats_dirty = 1; 387442a4f63SStefan Behrens } 388442a4f63SStefan Behrens 389442a4f63SStefan Behrens static inline void btrfs_dev_stat_reset(struct btrfs_device *dev, 390442a4f63SStefan Behrens int index) 391442a4f63SStefan Behrens { 392442a4f63SStefan Behrens btrfs_dev_stat_set(dev, index, 0); 393442a4f63SStefan Behrens } 3940b86a832SChris Mason #endif 395