btrfs: combine device update operations during transaction commit
[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
cea9e445 9#include <linux/bio.h>
b2117a39 10#include <linux/sort.h>
55e301fd 11#include <linux/btrfs.h>
8b712842 12#include "async-thread.h"
cea9e445 13
fce466ea
QW
14#define BTRFS_MAX_DATA_CHUNK_SIZE (10ULL * SZ_1G)
15
67a2c45e
MX
16extern struct mutex uuid_mutex;
17
ee22184b 18#define BTRFS_STRIPE_LEN SZ_64K
b2117a39 19
f2984462 20struct buffer_head;
ffbd517d
CM
21struct btrfs_pending_bios {
22 struct bio *head;
23 struct bio *tail;
24};
25
7cc8e58d
MX
26/*
27 * Use sequence counter to get consistent device stat data on
28 * 32-bit processors.
29 */
30#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
31#include <linux/seqlock.h>
32#define __BTRFS_NEED_DEVICE_DATA_ORDERED
33#define btrfs_device_data_ordered_init(device) \
34 seqcount_init(&device->data_seqcount)
35#else
36#define btrfs_device_data_ordered_init(device) do { } while (0)
37#endif
38
ebbede42 39#define BTRFS_DEV_STATE_WRITEABLE (0)
e12c9621 40#define BTRFS_DEV_STATE_IN_FS_METADATA (1)
e6e674bd 41#define BTRFS_DEV_STATE_MISSING (2)
401e29c1 42#define BTRFS_DEV_STATE_REPLACE_TGT (3)
1c3063b6 43#define BTRFS_DEV_STATE_FLUSH_SENT (4)
ebbede42 44
0b86a832
CM
45struct btrfs_device {
46 struct list_head dev_list;
b3075717 47 struct list_head dev_alloc_list;
bbbf7243 48 struct list_head post_commit_list; /* chunk mutex */
2b82032c 49 struct btrfs_fs_devices *fs_devices;
fb456252 50 struct btrfs_fs_info *fs_info;
ffbd517d 51
d5ee37bc
MX
52 struct rcu_string *name;
53
54 u64 generation;
55
56 spinlock_t io_lock ____cacheline_aligned;
57 int running_pending;
ffbd517d
CM
58 /* regular prio bios */
59 struct btrfs_pending_bios pending_bios;
70fd7614 60 /* sync bios */
ffbd517d
CM
61 struct btrfs_pending_bios pending_sync_bios;
62
d5ee37bc
MX
63 struct block_device *bdev;
64
65 /* the mode sent to blkdev_get */
66 fmode_t mode;
67
ebbede42 68 unsigned long dev_state;
58efbc9f 69 blk_status_t last_flush_error;
e0ae9994 70 int flush_bio_sent;
b3075717 71
7cc8e58d
MX
72#ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
73 seqcount_t data_seqcount;
74#endif
75
0b86a832
CM
76 /* the internal btrfs device id */
77 u64 devid;
78
6ba40b61 79 /* size of the device in memory */
0b86a832
CM
80 u64 total_bytes;
81
6ba40b61 82 /* size of the device on disk */
d6397bae
CB
83 u64 disk_total_bytes;
84
0b86a832
CM
85 /* bytes used */
86 u64 bytes_used;
87
88 /* optimal io alignment for this device */
89 u32 io_align;
90
91 /* optimal io width for this device */
92 u32 io_width;
3c45bfc1
DG
93 /* type and info about this device */
94 u64 type;
0b86a832
CM
95
96 /* minimal io size for this device */
97 u32 sector_size;
98
0b86a832 99 /* physical drive uuid (or lvm uuid) */
e17cade2 100 u8 uuid[BTRFS_UUID_SIZE];
8b712842 101
935e5cc9
MX
102 /*
103 * size of the device on the current transaction
104 *
105 * This variant is update when committing the transaction,
bbbf7243 106 * and protected by chunk mutex
935e5cc9
MX
107 */
108 u64 commit_total_bytes;
109
ce7213c7
MX
110 /* bytes used on the current transaction */
111 u64 commit_bytes_used;
935e5cc9 112
3c45bfc1 113 /* for sending down flush barriers */
3c45bfc1
DG
114 struct bio *flush_bio;
115 struct completion flush_wait;
116
a2de733c 117 /* per-device scrub information */
cadbc0a0 118 struct scrub_ctx *scrub_ctx;
a2de733c 119
d458b054 120 struct btrfs_work work;
1f78160c 121 struct rcu_head rcu;
90519d66
AJ
122
123 /* readahead state */
90519d66
AJ
124 atomic_t reada_in_flight;
125 u64 reada_next;
126 struct reada_zone *reada_curr_zone;
127 struct radix_tree_root reada_zones;
128 struct radix_tree_root reada_extents;
387125fc 129
442a4f63
SB
130 /* disk I/O failure stats. For detailed description refer to
131 * enum btrfs_dev_stat_values in ioctl.h */
733f4fbb 132 int dev_stats_valid;
addc3fa7
MX
133
134 /* Counter to record the change of device stats */
135 atomic_t dev_stats_ccnt;
442a4f63 136 atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
0b86a832
CM
137};
138
7cc8e58d
MX
139/*
140 * If we read those variants at the context of their own lock, we needn't
141 * use the following helpers, reading them directly is safe.
142 */
143#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
144#define BTRFS_DEVICE_GETSET_FUNCS(name) \
145static inline u64 \
146btrfs_device_get_##name(const struct btrfs_device *dev) \
147{ \
148 u64 size; \
149 unsigned int seq; \
150 \
151 do { \
152 seq = read_seqcount_begin(&dev->data_seqcount); \
153 size = dev->name; \
154 } while (read_seqcount_retry(&dev->data_seqcount, seq)); \
155 return size; \
156} \
157 \
158static inline void \
159btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
160{ \
161 preempt_disable(); \
162 write_seqcount_begin(&dev->data_seqcount); \
163 dev->name = size; \
164 write_seqcount_end(&dev->data_seqcount); \
165 preempt_enable(); \
166}
167#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
168#define BTRFS_DEVICE_GETSET_FUNCS(name) \
169static inline u64 \
170btrfs_device_get_##name(const struct btrfs_device *dev) \
171{ \
172 u64 size; \
173 \
174 preempt_disable(); \
175 size = dev->name; \
176 preempt_enable(); \
177 return size; \
178} \
179 \
180static inline void \
181btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
182{ \
183 preempt_disable(); \
184 dev->name = size; \
185 preempt_enable(); \
186}
187#else
188#define BTRFS_DEVICE_GETSET_FUNCS(name) \
189static inline u64 \
190btrfs_device_get_##name(const struct btrfs_device *dev) \
191{ \
192 return dev->name; \
193} \
194 \
195static inline void \
196btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
197{ \
198 dev->name = size; \
199}
200#endif
201
202BTRFS_DEVICE_GETSET_FUNCS(total_bytes);
203BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
204BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
205
8a4b83cc
CM
206struct btrfs_fs_devices {
207 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
7239ff4b 208 u8 metadata_uuid[BTRFS_FSID_SIZE];
d1a63002 209 bool fsid_change;
c4babc5e 210 struct list_head fs_list;
8a4b83cc 211
8a4b83cc 212 u64 num_devices;
a0af469b 213 u64 open_devices;
2b82032c 214 u64 rw_devices;
cd02dca5 215 u64 missing_devices;
2b82032c 216 u64 total_rw_bytes;
02db0844 217 u64 total_devices;
d1a63002
NB
218
219 /* Highest generation number of seen devices */
220 u64 latest_generation;
221
8a4b83cc 222 struct block_device *latest_bdev;
e5e9a520
CM
223
224 /* all of the devices in the FS, protected by a mutex
225 * so we can safely walk it to write out the supers without
9b011adf
WS
226 * worrying about add/remove by the multi-device code.
227 * Scrubbing super can kick off supers writing by holding
228 * this mutex lock.
e5e9a520
CM
229 */
230 struct mutex device_list_mutex;
8a4b83cc 231 struct list_head devices;
b3075717
CM
232
233 /* devices not currently being allocated */
234 struct list_head alloc_list;
2b82032c
YZ
235
236 struct btrfs_fs_devices *seed;
237 int seeding;
2b82032c
YZ
238
239 int opened;
c289811c
CM
240
241 /* set when we find or add a device that doesn't have the
242 * nonrot flag set
243 */
244 int rotating;
2e7910d6 245
5a13f430 246 struct btrfs_fs_info *fs_info;
2e7910d6 247 /* sysfs kobjects */
c1b7e474 248 struct kobject fsid_kobj;
2e7910d6
AJ
249 struct kobject *device_dir_kobj;
250 struct completion kobj_unregister;
8a4b83cc
CM
251};
252
facc8a22
MX
253#define BTRFS_BIO_INLINE_CSUM_SIZE 64
254
ab4ba2e1
QW
255#define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \
256 - sizeof(struct btrfs_chunk)) \
257 / sizeof(struct btrfs_stripe) + 1)
258
259#define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \
260 - 2 * sizeof(struct btrfs_disk_key) \
261 - 2 * sizeof(struct btrfs_chunk)) \
262 / sizeof(struct btrfs_stripe) + 1)
263
9be3395b
CM
264/*
265 * we need the mirror number and stripe index to be passed around
266 * the call chain while we are processing end_io (especially errors).
267 * Really, what we need is a btrfs_bio structure that has this info
268 * and is properly sized with its stripe array, but we're not there
269 * quite yet. We have our own btrfs bioset, and all of the bios
270 * we allocate are actually btrfs_io_bios. We'll cram as much of
271 * struct btrfs_bio as we can into this over time.
272 */
273struct btrfs_io_bio {
c1dc0896
MX
274 unsigned int mirror_num;
275 unsigned int stripe_index;
276 u64 logical;
facc8a22
MX
277 u8 *csum;
278 u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
17347cec 279 struct bvec_iter iter;
fa1bcbe0
DS
280 /*
281 * This member must come last, bio_alloc_bioset will allocate enough
282 * bytes for entire btrfs_io_bio but relies on bio being last.
283 */
9be3395b
CM
284 struct bio bio;
285};
286
287static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio)
288{
289 return container_of(bio, struct btrfs_io_bio, bio);
290}
291
b3a0dd50
DS
292static inline void btrfs_io_bio_free_csum(struct btrfs_io_bio *io_bio)
293{
294 if (io_bio->csum != io_bio->csum_inline) {
295 kfree(io_bio->csum);
296 io_bio->csum = NULL;
297 }
298}
299
cea9e445
CM
300struct btrfs_bio_stripe {
301 struct btrfs_device *dev;
302 u64 physical;
fce3bb9a 303 u64 length; /* only used for discard mappings */
cea9e445
CM
304};
305
a1d3c478 306struct btrfs_bio {
140475ae 307 refcount_t refs;
cea9e445 308 atomic_t stripes_pending;
c404e0dc 309 struct btrfs_fs_info *fs_info;
10f11900 310 u64 map_type; /* get from map_lookup->type */
cea9e445 311 bio_end_io_t *end_io;
7d2b4daa 312 struct bio *orig_bio;
c55f1396 313 unsigned long flags;
cea9e445 314 void *private;
a236aed1
CM
315 atomic_t error;
316 int max_errors;
cea9e445 317 int num_stripes;
a1d3c478 318 int mirror_num;
2c8cdd6e
MX
319 int num_tgtdevs;
320 int *tgtdev_map;
8e5cfb55
ZL
321 /*
322 * logical block numbers for the start of each stripe
323 * The last one or two are p/q. These are sorted,
324 * so raid_map[0] is the start of our full stripe
325 */
326 u64 *raid_map;
cea9e445
CM
327 struct btrfs_bio_stripe stripes[];
328};
329
b2117a39
MX
330struct btrfs_device_info {
331 struct btrfs_device *dev;
332 u64 dev_offset;
333 u64 max_avail;
73c5de00 334 u64 total_avail;
b2117a39
MX
335};
336
31e50229
LB
337struct btrfs_raid_attr {
338 int sub_stripes; /* sub_stripes info for map */
339 int dev_stripes; /* stripes per dev */
340 int devs_max; /* max devs to use */
341 int devs_min; /* min devs needed */
8789f4fe 342 int tolerated_failures; /* max tolerated fail devs */
31e50229
LB
343 int devs_increment; /* ndevs has to be a multiple of this */
344 int ncopies; /* how many copies to data has */
b50836ed
HK
345 int nparity; /* number of stripes worth of bytes to store
346 * parity information */
f9fbcaa2 347 int mindev_error; /* error code if min devs requisite is unmet */
ed23467b 348 const char raid_name[8]; /* name of the raid */
41a6e891 349 u64 bg_flag; /* block group flag of the raid */
31e50229
LB
350};
351
af902047 352extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
af902047 353
1abe9b8a 354struct map_lookup {
355 u64 type;
356 int io_align;
357 int io_width;
3d8da678 358 u64 stripe_len;
1abe9b8a 359 int num_stripes;
360 int sub_stripes;
cf90d884 361 int verified_stripes; /* For mount time dev extent verification */
1abe9b8a 362 struct btrfs_bio_stripe stripes[];
363};
364
a2de733c
AJ
365#define map_lookup_size(n) (sizeof(struct map_lookup) + \
366 (sizeof(struct btrfs_bio_stripe) * (n)))
367
c9e9f97b 368struct btrfs_balance_args;
19a39dce 369struct btrfs_balance_progress;
c9e9f97b 370struct btrfs_balance_control {
c9e9f97b
ID
371 struct btrfs_balance_args data;
372 struct btrfs_balance_args meta;
373 struct btrfs_balance_args sys;
374
375 u64 flags;
19a39dce
ID
376
377 struct btrfs_balance_progress stat;
c9e9f97b
ID
378};
379
cf8cddd3
CH
380enum btrfs_map_op {
381 BTRFS_MAP_READ,
382 BTRFS_MAP_WRITE,
383 BTRFS_MAP_DISCARD,
384 BTRFS_MAP_GET_READ_MIRRORS,
385};
386
387static inline enum btrfs_map_op btrfs_op(struct bio *bio)
388{
389 switch (bio_op(bio)) {
390 case REQ_OP_DISCARD:
391 return BTRFS_MAP_DISCARD;
392 case REQ_OP_WRITE:
393 return BTRFS_MAP_WRITE;
394 default:
395 WARN_ON_ONCE(1);
396 case REQ_OP_READ:
397 return BTRFS_MAP_READ;
398 }
399}
400
6e9606d2
ZL
401void btrfs_get_bbio(struct btrfs_bio *bbio);
402void btrfs_put_bbio(struct btrfs_bio *bbio);
cf8cddd3 403int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
cea9e445 404 u64 logical, u64 *length,
a1d3c478 405 struct btrfs_bio **bbio_ret, int mirror_num);
cf8cddd3 406int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
af8e2d1d 407 u64 logical, u64 *length,
825ad4c9 408 struct btrfs_bio **bbio_ret);
63a9c7b9
NB
409int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
410 u64 physical, u64 **logical, int *naddrs, int *stripe_len);
6bccf3ab 411int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
5b4aacef 412int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
c216b203 413int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type);
0b86a832
CM
414void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
415void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
58efbc9f
OS
416blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
417 int mirror_num, int async_submit);
8a4b83cc 418int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
97288f2c 419 fmode_t flags, void *holder);
36350e95
GJ
420struct btrfs_device *btrfs_scan_one_device(const char *path,
421 fmode_t flags, void *holder);
228a73ab 422int btrfs_forget_devices(const char *path);
8a4b83cc 423int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
9b99b115 424void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
d6507cf1
NB
425void btrfs_assign_next_active_device(struct btrfs_device *device,
426 struct btrfs_device *this_dev);
a27a94c2
NB
427struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
428 u64 devid,
429 const char *devpath);
12bd2fc0
ID
430struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
431 const u64 *devid,
432 const u8 *uuid);
a425f9d4 433void btrfs_free_device(struct btrfs_device *device);
2ff7e61e 434int btrfs_rm_device(struct btrfs_fs_info *fs_info,
da353f6b 435 const char *device_path, u64 devid);
ffc5a379 436void __exit btrfs_cleanup_fs_uuids(void);
5d964051 437int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
8f18cf13
CM
438int btrfs_grow_device(struct btrfs_trans_handle *trans,
439 struct btrfs_device *device, u64 new_size);
e4319cd9 440struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
09ba3bc9 441 u64 devid, u8 *uuid, u8 *fsid, bool seed);
8f18cf13 442int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
da353f6b 443int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
6fcf6e2b
DS
444int btrfs_balance(struct btrfs_fs_info *fs_info,
445 struct btrfs_balance_control *bctl,
c9e9f97b 446 struct btrfs_ioctl_balance_args *bargs);
f89e09cf 447void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
2b6ba629 448int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
68310a5e 449int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
837d5b6e 450int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
a7e99c69 451int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
f7a81ea4 452int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
70f80175 453int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
2ff7e61e 454int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset);
499f377f
JM
455int find_free_dev_extent_start(struct btrfs_transaction *transaction,
456 struct btrfs_device *device, u64 num_bytes,
457 u64 search_start, u64 *start, u64 *max_avail);
6df9a95e
JB
458int find_free_dev_extent(struct btrfs_trans_handle *trans,
459 struct btrfs_device *device, u64 num_bytes,
ba1bf481 460 u64 *start, u64 *max_avail);
442a4f63 461void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
2ff7e61e 462int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
b27f7c0c 463 struct btrfs_ioctl_get_dev_stats *stats);
cb517eab 464void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
733f4fbb
SB
465int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
466int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
467 struct btrfs_fs_info *fs_info);
68a9db5f 468void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
084b6e7c
QW
469void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
470 struct btrfs_device *srcdev);
4f5ad7bd 471void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
da353f6b 472void btrfs_scratch_superblocks(struct block_device *bdev, const char *device_path);
592d92ee 473int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
e4ff5fb5 474 u64 logical, u64 len);
2ff7e61e 475unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
53b381b3 476 u64 logical);
6df9a95e 477int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
97aff912
NB
478 u64 chunk_offset, u64 chunk_size);
479int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
60ca842e
OS
480struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
481 u64 logical, u64 length);
addc3fa7 482
442a4f63
SB
483static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
484 int index)
485{
486 atomic_inc(dev->dev_stat_values + index);
9deae968
NB
487 /*
488 * This memory barrier orders stores updating statistics before stores
489 * updating dev_stats_ccnt.
490 *
491 * It pairs with smp_rmb() in btrfs_run_dev_stats().
492 */
addc3fa7
MX
493 smp_mb__before_atomic();
494 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
495}
496
497static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
498 int index)
499{
500 return atomic_read(dev->dev_stat_values + index);
501}
502
503static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
504 int index)
505{
506 int ret;
507
508 ret = atomic_xchg(dev->dev_stat_values + index, 0);
4660c49f
NB
509 /*
510 * atomic_xchg implies a full memory barriers as per atomic_t.txt:
511 * - RMW operations that have a return value are fully ordered;
512 *
513 * This implicit memory barriers is paired with the smp_rmb in
514 * btrfs_run_dev_stats
515 */
addc3fa7 516 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
517 return ret;
518}
519
520static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
521 int index, unsigned long val)
522{
523 atomic_set(dev->dev_stat_values + index, val);
9deae968
NB
524 /*
525 * This memory barrier orders stores updating statistics before stores
526 * updating dev_stats_ccnt.
527 *
528 * It pairs with smp_rmb() in btrfs_run_dev_stats().
529 */
addc3fa7
MX
530 smp_mb__before_atomic();
531 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
532}
533
534static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
535 int index)
536{
537 btrfs_dev_stat_set(dev, index, 0);
538}
935e5cc9 539
3e72ee88
QW
540/*
541 * Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
542 * can be used as index to access btrfs_raid_array[].
543 */
544static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
545{
546 if (flags & BTRFS_BLOCK_GROUP_RAID10)
547 return BTRFS_RAID_RAID10;
548 else if (flags & BTRFS_BLOCK_GROUP_RAID1)
549 return BTRFS_RAID_RAID1;
550 else if (flags & BTRFS_BLOCK_GROUP_DUP)
551 return BTRFS_RAID_DUP;
552 else if (flags & BTRFS_BLOCK_GROUP_RAID0)
553 return BTRFS_RAID_RAID0;
554 else if (flags & BTRFS_BLOCK_GROUP_RAID5)
555 return BTRFS_RAID_RAID5;
556 else if (flags & BTRFS_BLOCK_GROUP_RAID6)
557 return BTRFS_RAID_RAID6;
558
559 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
560}
561
ed23467b
AJ
562const char *get_raid_name(enum btrfs_raid_types type);
563
bbbf7243 564void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
04216820 565
c73eccf7 566struct list_head *btrfs_get_fs_uuids(void);
5a13f430
AJ
567void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
568void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
6528b99d
AJ
569bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
570 struct btrfs_device *failing_dev);
21634a19 571
46df06b8 572int btrfs_bg_type_to_factor(u64 flags);
cf90d884 573int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
46df06b8 574
0b86a832 575#endif