Merge tag 'regmap-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[linux-block.git] / fs / btrfs / volumes.h
CommitLineData
9888c340 1/* SPDX-License-Identifier: GPL-2.0 */
0b86a832
CM
2/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
0b86a832
CM
4 */
5
9888c340
DS
6#ifndef BTRFS_VOLUMES_H
7#define BTRFS_VOLUMES_H
8790d502 8
b2117a39 9#include <linux/sort.h>
55e301fd 10#include <linux/btrfs.h>
8b712842 11#include "async-thread.h"
b31bed17 12#include "messages.h"
27137fac 13#include "tree-checker.h"
cb3e217b 14#include "rcu-string.h"
cea9e445 15
fce466ea
QW
16#define BTRFS_MAX_DATA_CHUNK_SIZE (10ULL * SZ_1G)
17
67a2c45e
MX
18extern struct mutex uuid_mutex;
19
ee22184b 20#define BTRFS_STRIPE_LEN SZ_64K
b2117a39 21
719fae89
QW
22/* Used by sanity check for btrfs_raid_types. */
23#define const_ffs(n) (__builtin_ctzll(n) + 1)
24
25/*
26 * The conversion from BTRFS_BLOCK_GROUP_* bits to btrfs_raid_type requires
27 * RAID0 always to be the lowest profile bit.
28 * Although it's part of on-disk format and should never change, do extra
29 * compile-time sanity checks.
30 */
31static_assert(const_ffs(BTRFS_BLOCK_GROUP_RAID0) <
32 const_ffs(BTRFS_BLOCK_GROUP_PROFILE_MASK & ~BTRFS_BLOCK_GROUP_RAID0));
33static_assert(const_ilog2(BTRFS_BLOCK_GROUP_RAID0) >
34 ilog2(BTRFS_BLOCK_GROUP_TYPE_MASK));
35
36/* ilog2() can handle both constants and variables */
37#define BTRFS_BG_FLAG_TO_INDEX(profile) \
38 ilog2((profile) >> (ilog2(BTRFS_BLOCK_GROUP_RAID0) - 1))
39
f04fbcc6 40enum btrfs_raid_types {
719fae89
QW
41 /* SINGLE is the special one as it doesn't have on-disk bit. */
42 BTRFS_RAID_SINGLE = 0,
43
44 BTRFS_RAID_RAID0 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID0),
45 BTRFS_RAID_RAID1 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1),
46 BTRFS_RAID_DUP = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_DUP),
47 BTRFS_RAID_RAID10 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID10),
48 BTRFS_RAID_RAID5 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID5),
49 BTRFS_RAID_RAID6 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID6),
50 BTRFS_RAID_RAID1C3 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1C3),
51 BTRFS_RAID_RAID1C4 = BTRFS_BG_FLAG_TO_INDEX(BTRFS_BLOCK_GROUP_RAID1C4),
52
f04fbcc6
QW
53 BTRFS_NR_RAID_TYPES
54};
55
7cc8e58d
MX
56/*
57 * Use sequence counter to get consistent device stat data on
58 * 32-bit processors.
59 */
60#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
61#include <linux/seqlock.h>
62#define __BTRFS_NEED_DEVICE_DATA_ORDERED
c41ec452
SY
63#define btrfs_device_data_ordered_init(device) \
64 seqcount_init(&device->data_seqcount)
7cc8e58d 65#else
c41ec452 66#define btrfs_device_data_ordered_init(device) do { } while (0)
7cc8e58d
MX
67#endif
68
ebbede42 69#define BTRFS_DEV_STATE_WRITEABLE (0)
e12c9621 70#define BTRFS_DEV_STATE_IN_FS_METADATA (1)
e6e674bd 71#define BTRFS_DEV_STATE_MISSING (2)
401e29c1 72#define BTRFS_DEV_STATE_REPLACE_TGT (3)
1c3063b6 73#define BTRFS_DEV_STATE_FLUSH_SENT (4)
66d204a1 74#define BTRFS_DEV_STATE_NO_READA (5)
ebbede42 75
5b316468
NA
76struct btrfs_zoned_device_info;
77
0b86a832 78struct btrfs_device {
0b6f5d40
NB
79 struct list_head dev_list; /* device_list_mutex */
80 struct list_head dev_alloc_list; /* chunk mutex */
bbbf7243 81 struct list_head post_commit_list; /* chunk mutex */
2b82032c 82 struct btrfs_fs_devices *fs_devices;
fb456252 83 struct btrfs_fs_info *fs_info;
ffbd517d 84
8d1a7aae 85 struct rcu_string __rcu *name;
d5ee37bc
MX
86
87 u64 generation;
88
d5ee37bc
MX
89 struct block_device *bdev;
90
5b316468
NA
91 struct btrfs_zoned_device_info *zone_info;
92
d5ee37bc
MX
93 /* the mode sent to blkdev_get */
94 fmode_t mode;
95
4889bc05
AJ
96 /*
97 * Device's major-minor number. Must be set even if the device is not
98 * opened (bdev == NULL), unless the device is missing.
99 */
100 dev_t devt;
ebbede42 101 unsigned long dev_state;
58efbc9f 102 blk_status_t last_flush_error;
b3075717 103
7cc8e58d 104#ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
c41ec452 105 seqcount_t data_seqcount;
7cc8e58d
MX
106#endif
107
0b86a832
CM
108 /* the internal btrfs device id */
109 u64 devid;
110
6ba40b61 111 /* size of the device in memory */
0b86a832
CM
112 u64 total_bytes;
113
6ba40b61 114 /* size of the device on disk */
d6397bae
CB
115 u64 disk_total_bytes;
116
0b86a832
CM
117 /* bytes used */
118 u64 bytes_used;
119
120 /* optimal io alignment for this device */
121 u32 io_align;
122
123 /* optimal io width for this device */
124 u32 io_width;
3c45bfc1
DG
125 /* type and info about this device */
126 u64 type;
0b86a832
CM
127
128 /* minimal io size for this device */
129 u32 sector_size;
130
0b86a832 131 /* physical drive uuid (or lvm uuid) */
e17cade2 132 u8 uuid[BTRFS_UUID_SIZE];
8b712842 133
935e5cc9
MX
134 /*
135 * size of the device on the current transaction
136 *
137 * This variant is update when committing the transaction,
bbbf7243 138 * and protected by chunk mutex
935e5cc9
MX
139 */
140 u64 commit_total_bytes;
141
ce7213c7
MX
142 /* bytes used on the current transaction */
143 u64 commit_bytes_used;
935e5cc9 144
f9e69aa9
CH
145 /* Bio used for flushing device barriers */
146 struct bio flush_bio;
3c45bfc1
DG
147 struct completion flush_wait;
148
a2de733c 149 /* per-device scrub information */
cadbc0a0 150 struct scrub_ctx *scrub_ctx;
a2de733c 151
442a4f63
SB
152 /* disk I/O failure stats. For detailed description refer to
153 * enum btrfs_dev_stat_values in ioctl.h */
733f4fbb 154 int dev_stats_valid;
addc3fa7
MX
155
156 /* Counter to record the change of device stats */
157 atomic_t dev_stats_ccnt;
442a4f63 158 atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
1c11b63e
JM
159
160 struct extent_io_tree alloc_state;
668e48af
AJ
161
162 struct completion kobj_unregister;
163 /* For sysfs/FSID/devinfo/devid/ */
164 struct kobject devid_kobj;
eb3b5053
DS
165
166 /* Bandwidth limit for scrub, in bytes */
167 u64 scrub_speed_max;
0b86a832
CM
168};
169
2103da3b
JB
170/*
171 * Block group or device which contains an active swapfile. Used for preventing
172 * unsafe operations while a swapfile is active.
173 *
174 * These are sorted on (ptr, inode) (note that a block group or device can
175 * contain more than one swapfile). We compare the pointer values because we
176 * don't actually care what the object is, we just need a quick check whether
177 * the object exists in the rbtree.
178 */
179struct btrfs_swapfile_pin {
180 struct rb_node node;
181 void *ptr;
182 struct inode *inode;
183 /*
184 * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
185 * points to a struct btrfs_device.
186 */
187 bool is_block_group;
188 /*
189 * Only used when 'is_block_group' is true and it is the number of
190 * extents used by a swapfile for this block group ('ptr' field).
191 */
192 int bg_extent_count;
193};
194
7cc8e58d
MX
195/*
196 * If we read those variants at the context of their own lock, we needn't
197 * use the following helpers, reading them directly is safe.
198 */
199#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
200#define BTRFS_DEVICE_GETSET_FUNCS(name) \
201static inline u64 \
202btrfs_device_get_##name(const struct btrfs_device *dev) \
203{ \
204 u64 size; \
205 unsigned int seq; \
206 \
207 do { \
208 seq = read_seqcount_begin(&dev->data_seqcount); \
209 size = dev->name; \
210 } while (read_seqcount_retry(&dev->data_seqcount, seq)); \
211 return size; \
212} \
213 \
214static inline void \
215btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
216{ \
c41ec452 217 preempt_disable(); \
7cc8e58d
MX
218 write_seqcount_begin(&dev->data_seqcount); \
219 dev->name = size; \
220 write_seqcount_end(&dev->data_seqcount); \
c41ec452 221 preempt_enable(); \
7cc8e58d 222}
94545870 223#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
7cc8e58d
MX
224#define BTRFS_DEVICE_GETSET_FUNCS(name) \
225static inline u64 \
226btrfs_device_get_##name(const struct btrfs_device *dev) \
227{ \
228 u64 size; \
229 \
230 preempt_disable(); \
231 size = dev->name; \
232 preempt_enable(); \
233 return size; \
234} \
235 \
236static inline void \
237btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
238{ \
239 preempt_disable(); \
240 dev->name = size; \
241 preempt_enable(); \
242}
243#else
244#define BTRFS_DEVICE_GETSET_FUNCS(name) \
245static inline u64 \
246btrfs_device_get_##name(const struct btrfs_device *dev) \
247{ \
248 return dev->name; \
249} \
250 \
251static inline void \
252btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
253{ \
254 dev->name = size; \
255}
256#endif
257
258BTRFS_DEVICE_GETSET_FUNCS(total_bytes);
259BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
260BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
261
c4a816c6
NA
262enum btrfs_chunk_allocation_policy {
263 BTRFS_CHUNK_ALLOC_REGULAR,
1cd6121f 264 BTRFS_CHUNK_ALLOC_ZONED,
c4a816c6
NA
265};
266
33fd2f71
AJ
267/*
268 * Read policies for mirrored block group profiles, read picks the stripe based
269 * on these policies.
270 */
271enum btrfs_read_policy {
272 /* Use process PID to choose the stripe */
273 BTRFS_READ_POLICY_PID,
274 BTRFS_NR_READ_POLICY,
275};
276
8a4b83cc
CM
277struct btrfs_fs_devices {
278 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
7239ff4b 279 u8 metadata_uuid[BTRFS_FSID_SIZE];
d1a63002 280 bool fsid_change;
c4babc5e 281 struct list_head fs_list;
8a4b83cc 282
add9745a
AJ
283 /*
284 * Number of devices under this fsid including missing and
285 * replace-target device and excludes seed devices.
286 */
8a4b83cc 287 u64 num_devices;
add9745a
AJ
288
289 /*
290 * The number of devices that successfully opened, including
291 * replace-target, excludes seed devices.
292 */
a0af469b 293 u64 open_devices;
add9745a
AJ
294
295 /* The number of devices that are under the chunk allocation list. */
2b82032c 296 u64 rw_devices;
add9745a
AJ
297
298 /* Count of missing devices under this fsid excluding seed device. */
cd02dca5 299 u64 missing_devices;
2b82032c 300 u64 total_rw_bytes;
add9745a
AJ
301
302 /*
303 * Count of devices from btrfs_super_block::num_devices for this fsid,
304 * which includes the seed device, excludes the transient replace-target
305 * device.
306 */
02db0844 307 u64 total_devices;
d1a63002
NB
308
309 /* Highest generation number of seen devices */
310 u64 latest_generation;
311
d24fa5c1
AJ
312 /*
313 * The mount device or a device with highest generation after removal
314 * or replace.
315 */
316 struct btrfs_device *latest_dev;
e5e9a520
CM
317
318 /* all of the devices in the FS, protected by a mutex
319 * so we can safely walk it to write out the supers without
9b011adf
WS
320 * worrying about add/remove by the multi-device code.
321 * Scrubbing super can kick off supers writing by holding
322 * this mutex lock.
e5e9a520
CM
323 */
324 struct mutex device_list_mutex;
0b6f5d40
NB
325
326 /* List of all devices, protected by device_list_mutex */
8a4b83cc 327 struct list_head devices;
b3075717 328
0b6f5d40
NB
329 /*
330 * Devices which can satisfy space allocation. Protected by
331 * chunk_mutex
332 */
b3075717 333 struct list_head alloc_list;
2b82032c 334
944d3f9f 335 struct list_head seed_list;
0395d84f 336 bool seeding;
2b82032c
YZ
337
338 int opened;
c289811c
CM
339
340 /* set when we find or add a device that doesn't have the
341 * nonrot flag set
342 */
7f0432d0 343 bool rotating;
63a7cb13
DS
344 /* Devices support TRIM/discard commands */
345 bool discardable;
2e7910d6 346
5a13f430 347 struct btrfs_fs_info *fs_info;
2e7910d6 348 /* sysfs kobjects */
c1b7e474 349 struct kobject fsid_kobj;
b5501504 350 struct kobject *devices_kobj;
a013d141 351 struct kobject *devinfo_kobj;
2e7910d6 352 struct completion kobj_unregister;
c4a816c6
NA
353
354 enum btrfs_chunk_allocation_policy chunk_alloc_policy;
33fd2f71
AJ
355
356 /* Policy used to read the mirrored stripes */
357 enum btrfs_read_policy read_policy;
8a4b83cc
CM
358};
359
ab4ba2e1
QW
360#define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \
361 - sizeof(struct btrfs_chunk)) \
362 / sizeof(struct btrfs_stripe) + 1)
363
364#define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \
365 - 2 * sizeof(struct btrfs_disk_key) \
366 - 2 * sizeof(struct btrfs_chunk)) \
367 / sizeof(struct btrfs_stripe) + 1)
368
4c664611 369struct btrfs_io_stripe {
cea9e445 370 struct btrfs_device *dev;
9ff7ddd3
CH
371 union {
372 /* Block mapping */
373 u64 physical;
374 /* For the endio handler */
375 struct btrfs_io_context *bioc;
376 };
a4012f06
CH
377};
378
379struct btrfs_discard_stripe {
380 struct btrfs_device *dev;
381 u64 physical;
382 u64 length;
cea9e445
CM
383};
384
4c664611
QW
385/*
386 * Context for IO subsmission for device stripe.
387 *
388 * - Track the unfinished mirrors for mirror based profiles
389 * Mirror based profiles are SINGLE/DUP/RAID1/RAID10.
390 *
391 * - Contain the logical -> physical mapping info
392 * Used by submit_stripe_bio() for mapping logical bio
393 * into physical device address.
394 *
395 * - Contain device replace info
396 * Used by handle_ops_on_dev_replace() to copy logical bios
397 * into the new device.
398 *
399 * - Contain RAID56 full stripe logical bytenrs
400 */
401struct btrfs_io_context {
140475ae 402 refcount_t refs;
c404e0dc 403 struct btrfs_fs_info *fs_info;
10f11900 404 u64 map_type; /* get from map_lookup->type */
7d2b4daa 405 struct bio *orig_bio;
a236aed1
CM
406 atomic_t error;
407 int max_errors;
cea9e445 408 int num_stripes;
a1d3c478 409 int mirror_num;
2c8cdd6e
MX
410 int num_tgtdevs;
411 int *tgtdev_map;
8e5cfb55
ZL
412 /*
413 * logical block numbers for the start of each stripe
414 * The last one or two are p/q. These are sorted,
415 * so raid_map[0] is the start of our full stripe
416 */
417 u64 *raid_map;
4c664611 418 struct btrfs_io_stripe stripes[];
cea9e445
CM
419};
420
b2117a39
MX
421struct btrfs_device_info {
422 struct btrfs_device *dev;
423 u64 dev_offset;
424 u64 max_avail;
73c5de00 425 u64 total_avail;
b2117a39
MX
426};
427
31e50229 428struct btrfs_raid_attr {
8c3e3582
DS
429 u8 sub_stripes; /* sub_stripes info for map */
430 u8 dev_stripes; /* stripes per dev */
431 u8 devs_max; /* max devs to use */
432 u8 devs_min; /* min devs needed */
433 u8 tolerated_failures; /* max tolerated fail devs */
434 u8 devs_increment; /* ndevs has to be a multiple of this */
435 u8 ncopies; /* how many copies to data has */
436 u8 nparity; /* number of stripes worth of bytes to store
b50836ed 437 * parity information */
8c3e3582 438 u8 mindev_error; /* error code if min devs requisite is unmet */
ed23467b 439 const char raid_name[8]; /* name of the raid */
41a6e891 440 u64 bg_flag; /* block group flag of the raid */
31e50229
LB
441};
442
af902047 443extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
af902047 444
1abe9b8a 445struct map_lookup {
446 u64 type;
447 int io_align;
448 int io_width;
cc353a8b 449 u32 stripe_len;
1abe9b8a 450 int num_stripes;
451 int sub_stripes;
cf90d884 452 int verified_stripes; /* For mount time dev extent verification */
4c664611 453 struct btrfs_io_stripe stripes[];
1abe9b8a 454};
455
a2de733c 456#define map_lookup_size(n) (sizeof(struct map_lookup) + \
4c664611 457 (sizeof(struct btrfs_io_stripe) * (n)))
a2de733c 458
c9e9f97b 459struct btrfs_balance_args;
19a39dce 460struct btrfs_balance_progress;
c9e9f97b 461struct btrfs_balance_control {
c9e9f97b
ID
462 struct btrfs_balance_args data;
463 struct btrfs_balance_args meta;
464 struct btrfs_balance_args sys;
465
466 u64 flags;
19a39dce
ID
467
468 struct btrfs_balance_progress stat;
c9e9f97b
ID
469};
470
562d7b15
JB
471/*
472 * Search for a given device by the set parameters
473 */
474struct btrfs_dev_lookup_args {
475 u64 devid;
476 u8 *uuid;
477 u8 *fsid;
478 bool missing;
479};
480
481/* We have to initialize to -1 because BTRFS_DEV_REPLACE_DEVID is 0 */
482#define BTRFS_DEV_LOOKUP_ARGS_INIT { .devid = (u64)-1 }
483
484#define BTRFS_DEV_LOOKUP_ARGS(name) \
485 struct btrfs_dev_lookup_args name = BTRFS_DEV_LOOKUP_ARGS_INIT
486
cf8cddd3
CH
487enum btrfs_map_op {
488 BTRFS_MAP_READ,
489 BTRFS_MAP_WRITE,
490 BTRFS_MAP_DISCARD,
491 BTRFS_MAP_GET_READ_MIRRORS,
492};
493
494static inline enum btrfs_map_op btrfs_op(struct bio *bio)
495{
496 switch (bio_op(bio)) {
497 case REQ_OP_DISCARD:
498 return BTRFS_MAP_DISCARD;
499 case REQ_OP_WRITE:
cfe94440 500 case REQ_OP_ZONE_APPEND:
cf8cddd3
CH
501 return BTRFS_MAP_WRITE;
502 default:
503 WARN_ON_ONCE(1);
c730ae0c 504 fallthrough;
cf8cddd3
CH
505 case REQ_OP_READ:
506 return BTRFS_MAP_READ;
507 }
508}
509
b31bed17
JB
510static inline unsigned long btrfs_chunk_item_size(int num_stripes)
511{
512 ASSERT(num_stripes);
513 return sizeof(struct btrfs_chunk) +
514 sizeof(struct btrfs_stripe) * (num_stripes - 1);
515}
516
4c664611
QW
517void btrfs_get_bioc(struct btrfs_io_context *bioc);
518void btrfs_put_bioc(struct btrfs_io_context *bioc);
cf8cddd3 519int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
cea9e445 520 u64 logical, u64 *length,
4c664611 521 struct btrfs_io_context **bioc_ret, int mirror_num);
cf8cddd3 522int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
af8e2d1d 523 u64 logical, u64 *length,
4c664611 524 struct btrfs_io_context **bioc_ret);
103c1972
CH
525int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
526 u64 logical, u64 *length,
527 struct btrfs_io_context **bioc_ret,
528 struct btrfs_io_stripe *smap, int *mirror_num_ret,
529 int need_raid_map);
a4012f06
CH
530struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,
531 u64 logical, u64 *length_ret,
532 u32 *num_stripes);
6bccf3ab 533int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
5b4aacef 534int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
f6f39f7a 535struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
79bd3712 536 u64 type);
c8bf1b67 537void btrfs_mapping_tree_free(struct extent_map_tree *tree);
8a4b83cc 538int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
97288f2c 539 fmode_t flags, void *holder);
36350e95
GJ
540struct btrfs_device *btrfs_scan_one_device(const char *path,
541 fmode_t flags, void *holder);
16cab91a 542int btrfs_forget_devices(dev_t devt);
54eed6ae 543void btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
bacce86a 544void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices);
d6507cf1
NB
545void btrfs_assign_next_active_device(struct btrfs_device *device,
546 struct btrfs_device *this_dev);
a27a94c2
NB
547struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
548 u64 devid,
549 const char *devpath);
faa775c4
JB
550int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
551 struct btrfs_dev_lookup_args *args,
552 const char *path);
12bd2fc0 553struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
bb21e302
AJ
554 const u64 *devid, const u8 *uuid,
555 const char *path);
faa775c4 556void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);
a425f9d4 557void btrfs_free_device(struct btrfs_device *device);
2ff7e61e 558int btrfs_rm_device(struct btrfs_fs_info *fs_info,
1a15eb72 559 struct btrfs_dev_lookup_args *args,
3fa421de 560 struct block_device **bdev, fmode_t *mode);
ffc5a379 561void __exit btrfs_cleanup_fs_uuids(void);
5d964051 562int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
8f18cf13
CM
563int btrfs_grow_device(struct btrfs_trans_handle *trans,
564 struct btrfs_device *device, u64 new_size);
562d7b15
JB
565struct btrfs_device *btrfs_find_device(const struct btrfs_fs_devices *fs_devices,
566 const struct btrfs_dev_lookup_args *args);
8f18cf13 567int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
da353f6b 568int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
6fcf6e2b
DS
569int btrfs_balance(struct btrfs_fs_info *fs_info,
570 struct btrfs_balance_control *bctl,
c9e9f97b 571 struct btrfs_ioctl_balance_args *bargs);
f89e09cf 572void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
2b6ba629 573int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
68310a5e 574int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
837d5b6e 575int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
18bb8bbf 576int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset);
a7e99c69 577int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
f7a81ea4 578int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
97f4dd09 579int btrfs_uuid_scan_kthread(void *data);
a09f23c3 580bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset);
60dfdf25 581int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
ba1bf481 582 u64 *start, u64 *max_avail);
442a4f63 583void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
2ff7e61e 584int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
b27f7c0c 585 struct btrfs_ioctl_get_dev_stats *stats);
a8d1b164 586int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
733f4fbb 587int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
196c9d8d 588int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
68a9db5f 589void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
65237ee3 590void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev);
4f5ad7bd 591void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
592d92ee 592int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
e4ff5fb5 593 u64 logical, u64 len);
2ff7e61e 594unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
53b381b3 595 u64 logical);
bc88b486 596u64 btrfs_calc_stripe_length(const struct extent_map *em);
0b30f719 597int btrfs_nr_parity_stripes(u64 type);
79bd3712
FM
598int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
599 struct btrfs_block_group *bg);
97aff912 600int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
60ca842e
OS
601struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
602 u64 logical, u64 length);
8f32380d 603void btrfs_release_disk_super(struct btrfs_super_block *super);
addc3fa7 604
442a4f63
SB
605static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
606 int index)
607{
608 atomic_inc(dev->dev_stat_values + index);
9deae968
NB
609 /*
610 * This memory barrier orders stores updating statistics before stores
611 * updating dev_stats_ccnt.
612 *
613 * It pairs with smp_rmb() in btrfs_run_dev_stats().
614 */
addc3fa7
MX
615 smp_mb__before_atomic();
616 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
617}
618
619static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
620 int index)
621{
622 return atomic_read(dev->dev_stat_values + index);
623}
624
625static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
626 int index)
627{
628 int ret;
629
630 ret = atomic_xchg(dev->dev_stat_values + index, 0);
4660c49f
NB
631 /*
632 * atomic_xchg implies a full memory barriers as per atomic_t.txt:
633 * - RMW operations that have a return value are fully ordered;
634 *
635 * This implicit memory barriers is paired with the smp_rmb in
636 * btrfs_run_dev_stats
637 */
addc3fa7 638 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
639 return ret;
640}
641
642static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
643 int index, unsigned long val)
644{
645 atomic_set(dev->dev_stat_values + index, val);
9deae968
NB
646 /*
647 * This memory barrier orders stores updating statistics before stores
648 * updating dev_stats_ccnt.
649 *
650 * It pairs with smp_rmb() in btrfs_run_dev_stats().
651 */
addc3fa7
MX
652 smp_mb__before_atomic();
653 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
654}
655
cb3e217b
QW
656static inline const char *btrfs_dev_name(const struct btrfs_device *device)
657{
658 if (!device || test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
659 return "<missing disk>";
660 else
661 return rcu_str_deref(device->name);
662}
663
bbbf7243 664void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
04216820 665
4143cb8b 666struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
6528b99d
AJ
667bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
668 struct btrfs_device *failing_dev);
313b0858
JB
669void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
670 struct block_device *bdev,
671 const char *device_path);
21634a19 672
500a44c9 673enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags);
46df06b8 674int btrfs_bg_type_to_factor(u64 flags);
158da513 675const char *btrfs_bg_type_to_raid_name(u64 flags);
cf90d884 676int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
554aed7d 677bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
46df06b8 678
c2e79e86
JB
679bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
680
0b86a832 681#endif