Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2007 Oracle.  All rights reserved.
0004  */
0005 
0006 #ifndef BTRFS_VOLUMES_H
0007 #define BTRFS_VOLUMES_H
0008 
0009 #include <linux/bio.h>
0010 #include <linux/sort.h>
0011 #include <linux/btrfs.h>
0012 #include "async-thread.h"
0013 
0014 #define BTRFS_MAX_DATA_CHUNK_SIZE   (10ULL * SZ_1G)
0015 
0016 extern struct mutex uuid_mutex;
0017 
0018 #define BTRFS_STRIPE_LEN    SZ_64K
0019 
0020 /* Used by sanity check for btrfs_raid_types. */
0021 #define const_ffs(n) (__builtin_ctzll(n) + 1)
0022 
0023 /*
0024  * The conversion from BTRFS_BLOCK_GROUP_* bits to btrfs_raid_type requires
0025  * RAID0 always to be the lowest profile bit.
0026  * Although it's part of on-disk format and should never change, do extra
0027  * compile-time sanity checks.
0028  */
0029 static_assert(const_ffs(BTRFS_BLOCK_GROUP_RAID0) <
0030           const_ffs(BTRFS_BLOCK_GROUP_PROFILE_MASK & ~BTRFS_BLOCK_GROUP_RAID0));
0031 static_assert(const_ilog2(BTRFS_BLOCK_GROUP_RAID0) >
0032           ilog2(BTRFS_BLOCK_GROUP_TYPE_MASK));
0033 
0034 /* ilog2() can handle both constants and variables */
0035 #define BTRFS_BG_FLAG_TO_INDEX(profile)                 \
0036     ilog2((profile) >> (ilog2(BTRFS_BLOCK_GROUP_RAID0) - 1))
0037 
0038 enum btrfs_raid_types {
0039     /* SINGLE is the special one as it doesn't have on-disk bit. */
0040     BTRFS_RAID_SINGLE  = 0,
0041 
0042     BTRFS_RAID_RAID0   = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID0),
0043     BTRFS_RAID_RAID1   = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1),
0044     BTRFS_RAID_DUP     = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_DUP),
0045     BTRFS_RAID_RAID10  = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID10),
0046     BTRFS_RAID_RAID5   = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID5),
0047     BTRFS_RAID_RAID6   = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID6),
0048     BTRFS_RAID_RAID1C3 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1C3),
0049     BTRFS_RAID_RAID1C4 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1C4),
0050 
0051     BTRFS_NR_RAID_TYPES
0052 };
0053 
0054 struct btrfs_io_geometry {
0055     /* remaining bytes before crossing a stripe */
0056     u64 len;
0057     /* offset of logical address in chunk */
0058     u64 offset;
0059     /* length of single IO stripe */
0060     u32 stripe_len;
0061     /* offset of address in stripe */
0062     u32 stripe_offset;
0063     /* number of stripe where address falls */
0064     u64 stripe_nr;
0065     /* offset of raid56 stripe into the chunk */
0066     u64 raid56_stripe_offset;
0067 };
0068 
0069 /*
0070  * Use sequence counter to get consistent device stat data on
0071  * 32-bit processors.
0072  */
0073 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
0074 #include <linux/seqlock.h>
0075 #define __BTRFS_NEED_DEVICE_DATA_ORDERED
0076 #define btrfs_device_data_ordered_init(device)  \
0077     seqcount_init(&device->data_seqcount)
0078 #else
0079 #define btrfs_device_data_ordered_init(device) do { } while (0)
0080 #endif
0081 
0082 #define BTRFS_DEV_STATE_WRITEABLE   (0)
0083 #define BTRFS_DEV_STATE_IN_FS_METADATA  (1)
0084 #define BTRFS_DEV_STATE_MISSING     (2)
0085 #define BTRFS_DEV_STATE_REPLACE_TGT (3)
0086 #define BTRFS_DEV_STATE_FLUSH_SENT  (4)
0087 #define BTRFS_DEV_STATE_NO_READA    (5)
0088 
0089 struct btrfs_zoned_device_info;
0090 
0091 struct btrfs_device {
0092     struct list_head dev_list; /* device_list_mutex */
0093     struct list_head dev_alloc_list; /* chunk mutex */
0094     struct list_head post_commit_list; /* chunk mutex */
0095     struct btrfs_fs_devices *fs_devices;
0096     struct btrfs_fs_info *fs_info;
0097 
0098     struct rcu_string __rcu *name;
0099 
0100     u64 generation;
0101 
0102     struct block_device *bdev;
0103 
0104     struct btrfs_zoned_device_info *zone_info;
0105 
0106     /* the mode sent to blkdev_get */
0107     fmode_t mode;
0108 
0109     /*
0110      * Device's major-minor number. Must be set even if the device is not
0111      * opened (bdev == NULL), unless the device is missing.
0112      */
0113     dev_t devt;
0114     unsigned long dev_state;
0115     blk_status_t last_flush_error;
0116 
0117 #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
0118     seqcount_t data_seqcount;
0119 #endif
0120 
0121     /* the internal btrfs device id */
0122     u64 devid;
0123 
0124     /* size of the device in memory */
0125     u64 total_bytes;
0126 
0127     /* size of the device on disk */
0128     u64 disk_total_bytes;
0129 
0130     /* bytes used */
0131     u64 bytes_used;
0132 
0133     /* optimal io alignment for this device */
0134     u32 io_align;
0135 
0136     /* optimal io width for this device */
0137     u32 io_width;
0138     /* type and info about this device */
0139     u64 type;
0140 
0141     /* minimal io size for this device */
0142     u32 sector_size;
0143 
0144     /* physical drive uuid (or lvm uuid) */
0145     u8 uuid[BTRFS_UUID_SIZE];
0146 
0147     /*
0148      * size of the device on the current transaction
0149      *
0150      * This variant is update when committing the transaction,
0151      * and protected by chunk mutex
0152      */
0153     u64 commit_total_bytes;
0154 
0155     /* bytes used on the current transaction */
0156     u64 commit_bytes_used;
0157 
0158     /* Bio used for flushing device barriers */
0159     struct bio flush_bio;
0160     struct completion flush_wait;
0161 
0162     /* per-device scrub information */
0163     struct scrub_ctx *scrub_ctx;
0164 
0165     /* disk I/O failure stats. For detailed description refer to
0166      * enum btrfs_dev_stat_values in ioctl.h */
0167     int dev_stats_valid;
0168 
0169     /* Counter to record the change of device stats */
0170     atomic_t dev_stats_ccnt;
0171     atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
0172 
0173     struct extent_io_tree alloc_state;
0174 
0175     struct completion kobj_unregister;
0176     /* For sysfs/FSID/devinfo/devid/ */
0177     struct kobject devid_kobj;
0178 
0179     /* Bandwidth limit for scrub, in bytes */
0180     u64 scrub_speed_max;
0181 };
0182 
0183 /*
0184  * If we read those variants at the context of their own lock, we needn't
0185  * use the following helpers, reading them directly is safe.
0186  */
0187 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
0188 #define BTRFS_DEVICE_GETSET_FUNCS(name)                 \
0189 static inline u64                           \
0190 btrfs_device_get_##name(const struct btrfs_device *dev)         \
0191 {                                   \
0192     u64 size;                           \
0193     unsigned int seq;                       \
0194                                     \
0195     do {                                \
0196         seq = read_seqcount_begin(&dev->data_seqcount);     \
0197         size = dev->name;                   \
0198     } while (read_seqcount_retry(&dev->data_seqcount, seq));    \
0199     return size;                            \
0200 }                                   \
0201                                     \
0202 static inline void                          \
0203 btrfs_device_set_##name(struct btrfs_device *dev, u64 size)     \
0204 {                                   \
0205     preempt_disable();                      \
0206     write_seqcount_begin(&dev->data_seqcount);          \
0207     dev->name = size;                       \
0208     write_seqcount_end(&dev->data_seqcount);            \
0209     preempt_enable();                       \
0210 }
0211 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
0212 #define BTRFS_DEVICE_GETSET_FUNCS(name)                 \
0213 static inline u64                           \
0214 btrfs_device_get_##name(const struct btrfs_device *dev)         \
0215 {                                   \
0216     u64 size;                           \
0217                                     \
0218     preempt_disable();                      \
0219     size = dev->name;                       \
0220     preempt_enable();                       \
0221     return size;                            \
0222 }                                   \
0223                                     \
0224 static inline void                          \
0225 btrfs_device_set_##name(struct btrfs_device *dev, u64 size)     \
0226 {                                   \
0227     preempt_disable();                      \
0228     dev->name = size;                       \
0229     preempt_enable();                       \
0230 }
0231 #else
0232 #define BTRFS_DEVICE_GETSET_FUNCS(name)                 \
0233 static inline u64                           \
0234 btrfs_device_get_##name(const struct btrfs_device *dev)         \
0235 {                                   \
0236     return dev->name;                       \
0237 }                                   \
0238                                     \
0239 static inline void                          \
0240 btrfs_device_set_##name(struct btrfs_device *dev, u64 size)     \
0241 {                                   \
0242     dev->name = size;                       \
0243 }
0244 #endif
0245 
0246 BTRFS_DEVICE_GETSET_FUNCS(total_bytes);
0247 BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
0248 BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
0249 
0250 enum btrfs_chunk_allocation_policy {
0251     BTRFS_CHUNK_ALLOC_REGULAR,
0252     BTRFS_CHUNK_ALLOC_ZONED,
0253 };
0254 
0255 /*
0256  * Read policies for mirrored block group profiles, read picks the stripe based
0257  * on these policies.
0258  */
0259 enum btrfs_read_policy {
0260     /* Use process PID to choose the stripe */
0261     BTRFS_READ_POLICY_PID,
0262     BTRFS_NR_READ_POLICY,
0263 };
0264 
0265 struct btrfs_fs_devices {
0266     u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
0267     u8 metadata_uuid[BTRFS_FSID_SIZE];
0268     bool fsid_change;
0269     struct list_head fs_list;
0270 
0271     /*
0272      * Number of devices under this fsid including missing and
0273      * replace-target device and excludes seed devices.
0274      */
0275     u64 num_devices;
0276 
0277     /*
0278      * The number of devices that successfully opened, including
0279      * replace-target, excludes seed devices.
0280      */
0281     u64 open_devices;
0282 
0283     /* The number of devices that are under the chunk allocation list. */
0284     u64 rw_devices;
0285 
0286     /* Count of missing devices under this fsid excluding seed device. */
0287     u64 missing_devices;
0288     u64 total_rw_bytes;
0289 
0290     /*
0291      * Count of devices from btrfs_super_block::num_devices for this fsid,
0292      * which includes the seed device, excludes the transient replace-target
0293      * device.
0294      */
0295     u64 total_devices;
0296 
0297     /* Highest generation number of seen devices */
0298     u64 latest_generation;
0299 
0300     /*
0301      * The mount device or a device with highest generation after removal
0302      * or replace.
0303      */
0304     struct btrfs_device *latest_dev;
0305 
0306     /* all of the devices in the FS, protected by a mutex
0307      * so we can safely walk it to write out the supers without
0308      * worrying about add/remove by the multi-device code.
0309      * Scrubbing super can kick off supers writing by holding
0310      * this mutex lock.
0311      */
0312     struct mutex device_list_mutex;
0313 
0314     /* List of all devices, protected by device_list_mutex */
0315     struct list_head devices;
0316 
0317     /*
0318      * Devices which can satisfy space allocation. Protected by
0319      * chunk_mutex
0320      */
0321     struct list_head alloc_list;
0322 
0323     struct list_head seed_list;
0324     bool seeding;
0325 
0326     int opened;
0327 
0328     /* set when we find or add a device that doesn't have the
0329      * nonrot flag set
0330      */
0331     bool rotating;
0332 
0333     struct btrfs_fs_info *fs_info;
0334     /* sysfs kobjects */
0335     struct kobject fsid_kobj;
0336     struct kobject *devices_kobj;
0337     struct kobject *devinfo_kobj;
0338     struct completion kobj_unregister;
0339 
0340     enum btrfs_chunk_allocation_policy chunk_alloc_policy;
0341 
0342     /* Policy used to read the mirrored stripes */
0343     enum btrfs_read_policy read_policy;
0344 };
0345 
0346 #define BTRFS_BIO_INLINE_CSUM_SIZE  64
0347 
0348 #define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info)    \
0349             - sizeof(struct btrfs_chunk))       \
0350             / sizeof(struct btrfs_stripe) + 1)
0351 
0352 #define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE    \
0353                 - 2 * sizeof(struct btrfs_disk_key) \
0354                 - 2 * sizeof(struct btrfs_chunk))   \
0355                 / sizeof(struct btrfs_stripe) + 1)
0356 
0357 /*
0358  * Maximum number of sectors for a single bio to limit the size of the
0359  * checksum array.  This matches the number of bio_vecs per bio and thus the
0360  * I/O size for buffered I/O.
0361  */
0362 #define BTRFS_MAX_BIO_SECTORS               (256)
0363 
0364 /*
0365  * Additional info to pass along bio.
0366  *
0367  * Mostly for btrfs specific features like csum and mirror_num.
0368  */
0369 struct btrfs_bio {
0370     unsigned int mirror_num;
0371 
0372     /* for direct I/O */
0373     u64 file_offset;
0374 
0375     /* @device is for stripe IO submission. */
0376     struct btrfs_device *device;
0377     u8 *csum;
0378     u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
0379     struct bvec_iter iter;
0380 
0381     /* For read end I/O handling */
0382     struct work_struct end_io_work;
0383 
0384     /*
0385      * This member must come last, bio_alloc_bioset will allocate enough
0386      * bytes for entire btrfs_bio but relies on bio being last.
0387      */
0388     struct bio bio;
0389 };
0390 
0391 static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
0392 {
0393     return container_of(bio, struct btrfs_bio, bio);
0394 }
0395 
0396 static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio)
0397 {
0398     if (bbio->csum != bbio->csum_inline) {
0399         kfree(bbio->csum);
0400         bbio->csum = NULL;
0401     }
0402 }
0403 
0404 /*
0405  * Iterate through a btrfs_bio (@bbio) on a per-sector basis.
0406  *
0407  * bvl        - struct bio_vec
0408  * bbio       - struct btrfs_bio
0409  * iters      - struct bvec_iter
0410  * bio_offset - unsigned int
0411  */
0412 #define btrfs_bio_for_each_sector(fs_info, bvl, bbio, iter, bio_offset) \
0413     for ((iter) = (bbio)->iter, (bio_offset) = 0;           \
0414          (iter).bi_size &&                  \
0415          (((bvl) = bio_iter_iovec((&(bbio)->bio), (iter))), 1); \
0416          (bio_offset) += fs_info->sectorsize,           \
0417          bio_advance_iter_single(&(bbio)->bio, &(iter),     \
0418          (fs_info)->sectorsize))
0419 
0420 struct btrfs_io_stripe {
0421     struct btrfs_device *dev;
0422     union {
0423         /* Block mapping */
0424         u64 physical;
0425         /* For the endio handler */
0426         struct btrfs_io_context *bioc;
0427     };
0428 };
0429 
0430 struct btrfs_discard_stripe {
0431     struct btrfs_device *dev;
0432     u64 physical;
0433     u64 length;
0434 };
0435 
0436 /*
0437  * Context for IO subsmission for device stripe.
0438  *
0439  * - Track the unfinished mirrors for mirror based profiles
0440  *   Mirror based profiles are SINGLE/DUP/RAID1/RAID10.
0441  *
0442  * - Contain the logical -> physical mapping info
0443  *   Used by submit_stripe_bio() for mapping logical bio
0444  *   into physical device address.
0445  *
0446  * - Contain device replace info
0447  *   Used by handle_ops_on_dev_replace() to copy logical bios
0448  *   into the new device.
0449  *
0450  * - Contain RAID56 full stripe logical bytenrs
0451  */
0452 struct btrfs_io_context {
0453     refcount_t refs;
0454     atomic_t stripes_pending;
0455     struct btrfs_fs_info *fs_info;
0456     u64 map_type; /* get from map_lookup->type */
0457     bio_end_io_t *end_io;
0458     struct bio *orig_bio;
0459     void *private;
0460     atomic_t error;
0461     int max_errors;
0462     int num_stripes;
0463     int mirror_num;
0464     int num_tgtdevs;
0465     int *tgtdev_map;
0466     /*
0467      * logical block numbers for the start of each stripe
0468      * The last one or two are p/q.  These are sorted,
0469      * so raid_map[0] is the start of our full stripe
0470      */
0471     u64 *raid_map;
0472     struct btrfs_io_stripe stripes[];
0473 };
0474 
0475 struct btrfs_device_info {
0476     struct btrfs_device *dev;
0477     u64 dev_offset;
0478     u64 max_avail;
0479     u64 total_avail;
0480 };
0481 
0482 struct btrfs_raid_attr {
0483     u8 sub_stripes;     /* sub_stripes info for map */
0484     u8 dev_stripes;     /* stripes per dev */
0485     u8 devs_max;        /* max devs to use */
0486     u8 devs_min;        /* min devs needed */
0487     u8 tolerated_failures;  /* max tolerated fail devs */
0488     u8 devs_increment;  /* ndevs has to be a multiple of this */
0489     u8 ncopies;     /* how many copies to data has */
0490     u8 nparity;     /* number of stripes worth of bytes to store
0491                  * parity information */
0492     u8 mindev_error;    /* error code if min devs requisite is unmet */
0493     const char raid_name[8]; /* name of the raid */
0494     u64 bg_flag;        /* block group flag of the raid */
0495 };
0496 
0497 extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
0498 
0499 struct map_lookup {
0500     u64 type;
0501     int io_align;
0502     int io_width;
0503     u32 stripe_len;
0504     int num_stripes;
0505     int sub_stripes;
0506     int verified_stripes; /* For mount time dev extent verification */
0507     struct btrfs_io_stripe stripes[];
0508 };
0509 
0510 #define map_lookup_size(n) (sizeof(struct map_lookup) + \
0511                 (sizeof(struct btrfs_io_stripe) * (n)))
0512 
0513 struct btrfs_balance_args;
0514 struct btrfs_balance_progress;
0515 struct btrfs_balance_control {
0516     struct btrfs_balance_args data;
0517     struct btrfs_balance_args meta;
0518     struct btrfs_balance_args sys;
0519 
0520     u64 flags;
0521 
0522     struct btrfs_balance_progress stat;
0523 };
0524 
0525 /*
0526  * Search for a given device by the set parameters
0527  */
0528 struct btrfs_dev_lookup_args {
0529     u64 devid;
0530     u8 *uuid;
0531     u8 *fsid;
0532     bool missing;
0533 };
0534 
0535 /* We have to initialize to -1 because BTRFS_DEV_REPLACE_DEVID is 0 */
0536 #define BTRFS_DEV_LOOKUP_ARGS_INIT { .devid = (u64)-1 }
0537 
0538 #define BTRFS_DEV_LOOKUP_ARGS(name) \
0539     struct btrfs_dev_lookup_args name = BTRFS_DEV_LOOKUP_ARGS_INIT
0540 
0541 enum btrfs_map_op {
0542     BTRFS_MAP_READ,
0543     BTRFS_MAP_WRITE,
0544     BTRFS_MAP_DISCARD,
0545     BTRFS_MAP_GET_READ_MIRRORS,
0546 };
0547 
0548 static inline enum btrfs_map_op btrfs_op(struct bio *bio)
0549 {
0550     switch (bio_op(bio)) {
0551     case REQ_OP_DISCARD:
0552         return BTRFS_MAP_DISCARD;
0553     case REQ_OP_WRITE:
0554     case REQ_OP_ZONE_APPEND:
0555         return BTRFS_MAP_WRITE;
0556     default:
0557         WARN_ON_ONCE(1);
0558         fallthrough;
0559     case REQ_OP_READ:
0560         return BTRFS_MAP_READ;
0561     }
0562 }
0563 
0564 void btrfs_get_bioc(struct btrfs_io_context *bioc);
0565 void btrfs_put_bioc(struct btrfs_io_context *bioc);
0566 int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
0567             u64 logical, u64 *length,
0568             struct btrfs_io_context **bioc_ret, int mirror_num);
0569 int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
0570              u64 logical, u64 *length,
0571              struct btrfs_io_context **bioc_ret);
0572 struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,
0573                            u64 logical, u64 *length_ret,
0574                            u32 *num_stripes);
0575 int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *map,
0576               enum btrfs_map_op op, u64 logical,
0577               struct btrfs_io_geometry *io_geom);
0578 int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
0579 int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
0580 struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
0581                         u64 type);
0582 void btrfs_mapping_tree_free(struct extent_map_tree *tree);
0583 void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, int mirror_num);
0584 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
0585                fmode_t flags, void *holder);
0586 struct btrfs_device *btrfs_scan_one_device(const char *path,
0587                        fmode_t flags, void *holder);
0588 int btrfs_forget_devices(dev_t devt);
0589 void btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
0590 void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices);
0591 void btrfs_assign_next_active_device(struct btrfs_device *device,
0592                      struct btrfs_device *this_dev);
0593 struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
0594                           u64 devid,
0595                           const char *devpath);
0596 int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
0597                  struct btrfs_dev_lookup_args *args,
0598                  const char *path);
0599 struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
0600                     const u64 *devid,
0601                     const u8 *uuid);
0602 void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);
0603 void btrfs_free_device(struct btrfs_device *device);
0604 int btrfs_rm_device(struct btrfs_fs_info *fs_info,
0605             struct btrfs_dev_lookup_args *args,
0606             struct block_device **bdev, fmode_t *mode);
0607 void __exit btrfs_cleanup_fs_uuids(void);
0608 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
0609 int btrfs_grow_device(struct btrfs_trans_handle *trans,
0610               struct btrfs_device *device, u64 new_size);
0611 struct btrfs_device *btrfs_find_device(const struct btrfs_fs_devices *fs_devices,
0612                        const struct btrfs_dev_lookup_args *args);
0613 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
0614 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
0615 int btrfs_balance(struct btrfs_fs_info *fs_info,
0616           struct btrfs_balance_control *bctl,
0617           struct btrfs_ioctl_balance_args *bargs);
0618 void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
0619 int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
0620 int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
0621 int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
0622 int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset);
0623 int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
0624 int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
0625 int btrfs_uuid_scan_kthread(void *data);
0626 bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset);
0627 int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
0628              u64 *start, u64 *max_avail);
0629 void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
0630 int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
0631             struct btrfs_ioctl_get_dev_stats *stats);
0632 void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
0633 int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
0634 int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
0635 void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
0636 void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev);
0637 void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
0638 int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
0639                u64 logical, u64 len);
0640 unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
0641                     u64 logical);
0642 u64 btrfs_calc_stripe_length(const struct extent_map *em);
0643 int btrfs_nr_parity_stripes(u64 type);
0644 int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
0645                      struct btrfs_block_group *bg);
0646 int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
0647 struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
0648                        u64 logical, u64 length);
0649 void btrfs_release_disk_super(struct btrfs_super_block *super);
0650 
0651 static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
0652                       int index)
0653 {
0654     atomic_inc(dev->dev_stat_values + index);
0655     /*
0656      * This memory barrier orders stores updating statistics before stores
0657      * updating dev_stats_ccnt.
0658      *
0659      * It pairs with smp_rmb() in btrfs_run_dev_stats().
0660      */
0661     smp_mb__before_atomic();
0662     atomic_inc(&dev->dev_stats_ccnt);
0663 }
0664 
0665 static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
0666                       int index)
0667 {
0668     return atomic_read(dev->dev_stat_values + index);
0669 }
0670 
0671 static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
0672                         int index)
0673 {
0674     int ret;
0675 
0676     ret = atomic_xchg(dev->dev_stat_values + index, 0);
0677     /*
0678      * atomic_xchg implies a full memory barriers as per atomic_t.txt:
0679      * - RMW operations that have a return value are fully ordered;
0680      *
0681      * This implicit memory barriers is paired with the smp_rmb in
0682      * btrfs_run_dev_stats
0683      */
0684     atomic_inc(&dev->dev_stats_ccnt);
0685     return ret;
0686 }
0687 
0688 static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
0689                       int index, unsigned long val)
0690 {
0691     atomic_set(dev->dev_stat_values + index, val);
0692     /*
0693      * This memory barrier orders stores updating statistics before stores
0694      * updating dev_stats_ccnt.
0695      *
0696      * It pairs with smp_rmb() in btrfs_run_dev_stats().
0697      */
0698     smp_mb__before_atomic();
0699     atomic_inc(&dev->dev_stats_ccnt);
0700 }
0701 
0702 void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
0703 
0704 struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
0705 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
0706                     struct btrfs_device *failing_dev);
0707 void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
0708                    struct block_device *bdev,
0709                    const char *device_path);
0710 
0711 enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags);
0712 int btrfs_bg_type_to_factor(u64 flags);
0713 const char *btrfs_bg_type_to_raid_name(u64 flags);
0714 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
0715 bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
0716 
0717 #endif