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