]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/btrfs/volumes.h
Merge tag 'fixes-v5.9a' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[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
c4a816c6
NA
210enum btrfs_chunk_allocation_policy {
211 BTRFS_CHUNK_ALLOC_REGULAR,
212};
213
8a4b83cc
CM
214struct btrfs_fs_devices {
215 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
7239ff4b 216 u8 metadata_uuid[BTRFS_FSID_SIZE];
d1a63002 217 bool fsid_change;
c4babc5e 218 struct list_head fs_list;
8a4b83cc 219
8a4b83cc 220 u64 num_devices;
a0af469b 221 u64 open_devices;
2b82032c 222 u64 rw_devices;
cd02dca5 223 u64 missing_devices;
2b82032c 224 u64 total_rw_bytes;
02db0844 225 u64 total_devices;
d1a63002
NB
226
227 /* Highest generation number of seen devices */
228 u64 latest_generation;
229
8a4b83cc 230 struct block_device *latest_bdev;
e5e9a520
CM
231
232 /* all of the devices in the FS, protected by a mutex
233 * so we can safely walk it to write out the supers without
9b011adf
WS
234 * worrying about add/remove by the multi-device code.
235 * Scrubbing super can kick off supers writing by holding
236 * this mutex lock.
e5e9a520
CM
237 */
238 struct mutex device_list_mutex;
0b6f5d40
NB
239
240 /* List of all devices, protected by device_list_mutex */
8a4b83cc 241 struct list_head devices;
b3075717 242
0b6f5d40
NB
243 /*
244 * Devices which can satisfy space allocation. Protected by
245 * chunk_mutex
246 */
b3075717 247 struct list_head alloc_list;
2b82032c
YZ
248
249 struct btrfs_fs_devices *seed;
0395d84f 250 bool seeding;
2b82032c
YZ
251
252 int opened;
c289811c
CM
253
254 /* set when we find or add a device that doesn't have the
255 * nonrot flag set
256 */
7f0432d0 257 bool rotating;
2e7910d6 258
5a13f430 259 struct btrfs_fs_info *fs_info;
2e7910d6 260 /* sysfs kobjects */
c1b7e474 261 struct kobject fsid_kobj;
b5501504 262 struct kobject *devices_kobj;
a013d141 263 struct kobject *devinfo_kobj;
2e7910d6 264 struct completion kobj_unregister;
c4a816c6
NA
265
266 enum btrfs_chunk_allocation_policy chunk_alloc_policy;
8a4b83cc
CM
267};
268
facc8a22
MX
269#define BTRFS_BIO_INLINE_CSUM_SIZE 64
270
ab4ba2e1
QW
271#define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \
272 - sizeof(struct btrfs_chunk)) \
273 / sizeof(struct btrfs_stripe) + 1)
274
275#define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \
276 - 2 * sizeof(struct btrfs_disk_key) \
277 - 2 * sizeof(struct btrfs_chunk)) \
278 / sizeof(struct btrfs_stripe) + 1)
279
9be3395b
CM
280/*
281 * we need the mirror number and stripe index to be passed around
282 * the call chain while we are processing end_io (especially errors).
283 * Really, what we need is a btrfs_bio structure that has this info
284 * and is properly sized with its stripe array, but we're not there
285 * quite yet. We have our own btrfs bioset, and all of the bios
286 * we allocate are actually btrfs_io_bios. We'll cram as much of
287 * struct btrfs_bio as we can into this over time.
288 */
289struct btrfs_io_bio {
c1dc0896 290 unsigned int mirror_num;
c31efbdf 291 struct btrfs_device *device;
c1dc0896 292 u64 logical;
facc8a22
MX
293 u8 *csum;
294 u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
17347cec 295 struct bvec_iter iter;
fa1bcbe0
DS
296 /*
297 * This member must come last, bio_alloc_bioset will allocate enough
298 * bytes for entire btrfs_io_bio but relies on bio being last.
299 */
9be3395b
CM
300 struct bio bio;
301};
302
303static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio)
304{
305 return container_of(bio, struct btrfs_io_bio, bio);
306}
307
b3a0dd50
DS
308static inline void btrfs_io_bio_free_csum(struct btrfs_io_bio *io_bio)
309{
310 if (io_bio->csum != io_bio->csum_inline) {
311 kfree(io_bio->csum);
312 io_bio->csum = NULL;
313 }
314}
315
cea9e445
CM
316struct btrfs_bio_stripe {
317 struct btrfs_device *dev;
318 u64 physical;
fce3bb9a 319 u64 length; /* only used for discard mappings */
cea9e445
CM
320};
321
a1d3c478 322struct btrfs_bio {
140475ae 323 refcount_t refs;
cea9e445 324 atomic_t stripes_pending;
c404e0dc 325 struct btrfs_fs_info *fs_info;
10f11900 326 u64 map_type; /* get from map_lookup->type */
cea9e445 327 bio_end_io_t *end_io;
7d2b4daa 328 struct bio *orig_bio;
cea9e445 329 void *private;
a236aed1
CM
330 atomic_t error;
331 int max_errors;
cea9e445 332 int num_stripes;
a1d3c478 333 int mirror_num;
2c8cdd6e
MX
334 int num_tgtdevs;
335 int *tgtdev_map;
8e5cfb55
ZL
336 /*
337 * logical block numbers for the start of each stripe
338 * The last one or two are p/q. These are sorted,
339 * so raid_map[0] is the start of our full stripe
340 */
341 u64 *raid_map;
cea9e445
CM
342 struct btrfs_bio_stripe stripes[];
343};
344
b2117a39
MX
345struct btrfs_device_info {
346 struct btrfs_device *dev;
347 u64 dev_offset;
348 u64 max_avail;
73c5de00 349 u64 total_avail;
b2117a39
MX
350};
351
31e50229 352struct btrfs_raid_attr {
8c3e3582
DS
353 u8 sub_stripes; /* sub_stripes info for map */
354 u8 dev_stripes; /* stripes per dev */
355 u8 devs_max; /* max devs to use */
356 u8 devs_min; /* min devs needed */
357 u8 tolerated_failures; /* max tolerated fail devs */
358 u8 devs_increment; /* ndevs has to be a multiple of this */
359 u8 ncopies; /* how many copies to data has */
360 u8 nparity; /* number of stripes worth of bytes to store
b50836ed 361 * parity information */
8c3e3582 362 u8 mindev_error; /* error code if min devs requisite is unmet */
ed23467b 363 const char raid_name[8]; /* name of the raid */
41a6e891 364 u64 bg_flag; /* block group flag of the raid */
31e50229
LB
365};
366
af902047 367extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
af902047 368
1abe9b8a 369struct map_lookup {
370 u64 type;
371 int io_align;
372 int io_width;
3d8da678 373 u64 stripe_len;
1abe9b8a 374 int num_stripes;
375 int sub_stripes;
cf90d884 376 int verified_stripes; /* For mount time dev extent verification */
1abe9b8a 377 struct btrfs_bio_stripe stripes[];
378};
379
a2de733c
AJ
380#define map_lookup_size(n) (sizeof(struct map_lookup) + \
381 (sizeof(struct btrfs_bio_stripe) * (n)))
382
c9e9f97b 383struct btrfs_balance_args;
19a39dce 384struct btrfs_balance_progress;
c9e9f97b 385struct btrfs_balance_control {
c9e9f97b
ID
386 struct btrfs_balance_args data;
387 struct btrfs_balance_args meta;
388 struct btrfs_balance_args sys;
389
390 u64 flags;
19a39dce
ID
391
392 struct btrfs_balance_progress stat;
c9e9f97b
ID
393};
394
cf8cddd3
CH
395enum btrfs_map_op {
396 BTRFS_MAP_READ,
397 BTRFS_MAP_WRITE,
398 BTRFS_MAP_DISCARD,
399 BTRFS_MAP_GET_READ_MIRRORS,
400};
401
402static inline enum btrfs_map_op btrfs_op(struct bio *bio)
403{
404 switch (bio_op(bio)) {
405 case REQ_OP_DISCARD:
406 return BTRFS_MAP_DISCARD;
407 case REQ_OP_WRITE:
408 return BTRFS_MAP_WRITE;
409 default:
410 WARN_ON_ONCE(1);
c730ae0c 411 fallthrough;
cf8cddd3
CH
412 case REQ_OP_READ:
413 return BTRFS_MAP_READ;
414 }
415}
416
6e9606d2
ZL
417void btrfs_get_bbio(struct btrfs_bio *bbio);
418void btrfs_put_bbio(struct btrfs_bio *bbio);
cf8cddd3 419int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
cea9e445 420 u64 logical, u64 *length,
a1d3c478 421 struct btrfs_bio **bbio_ret, int mirror_num);
cf8cddd3 422int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
af8e2d1d 423 u64 logical, u64 *length,
825ad4c9 424 struct btrfs_bio **bbio_ret);
5f141126 425int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
89b798ad 426 u64 logical, u64 len, struct btrfs_io_geometry *io_geom);
6bccf3ab 427int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
5b4aacef 428int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
c216b203 429int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type);
c8bf1b67 430void btrfs_mapping_tree_free(struct extent_map_tree *tree);
58efbc9f 431blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
08635bae 432 int mirror_num);
8a4b83cc 433int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
97288f2c 434 fmode_t flags, void *holder);
36350e95
GJ
435struct btrfs_device *btrfs_scan_one_device(const char *path,
436 fmode_t flags, void *holder);
228a73ab 437int btrfs_forget_devices(const char *path);
8a4b83cc 438int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
9b99b115 439void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
d6507cf1
NB
440void btrfs_assign_next_active_device(struct btrfs_device *device,
441 struct btrfs_device *this_dev);
a27a94c2
NB
442struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
443 u64 devid,
444 const char *devpath);
12bd2fc0
ID
445struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
446 const u64 *devid,
447 const u8 *uuid);
a425f9d4 448void btrfs_free_device(struct btrfs_device *device);
2ff7e61e 449int btrfs_rm_device(struct btrfs_fs_info *fs_info,
da353f6b 450 const char *device_path, u64 devid);
ffc5a379 451void __exit btrfs_cleanup_fs_uuids(void);
5d964051 452int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
8f18cf13
CM
453int btrfs_grow_device(struct btrfs_trans_handle *trans,
454 struct btrfs_device *device, u64 new_size);
e4319cd9 455struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
09ba3bc9 456 u64 devid, u8 *uuid, u8 *fsid, bool seed);
8f18cf13 457int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
da353f6b 458int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
6fcf6e2b
DS
459int btrfs_balance(struct btrfs_fs_info *fs_info,
460 struct btrfs_balance_control *bctl,
c9e9f97b 461 struct btrfs_ioctl_balance_args *bargs);
f89e09cf 462void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
2b6ba629 463int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
68310a5e 464int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
837d5b6e 465int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
a7e99c69 466int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
f7a81ea4 467int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
97f4dd09 468int btrfs_uuid_scan_kthread(void *data);
2ff7e61e 469int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset);
60dfdf25 470int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
ba1bf481 471 u64 *start, u64 *max_avail);
442a4f63 472void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
2ff7e61e 473int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
b27f7c0c 474 struct btrfs_ioctl_get_dev_stats *stats);
cb517eab 475void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
733f4fbb 476int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
196c9d8d 477int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
68a9db5f 478void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
65237ee3 479void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev);
4f5ad7bd 480void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
592d92ee 481int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
e4ff5fb5 482 u64 logical, u64 len);
2ff7e61e 483unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
53b381b3 484 u64 logical);
6df9a95e 485int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
97aff912
NB
486 u64 chunk_offset, u64 chunk_size);
487int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
60ca842e
OS
488struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
489 u64 logical, u64 length);
8f32380d 490void btrfs_release_disk_super(struct btrfs_super_block *super);
addc3fa7 491
442a4f63
SB
492static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
493 int index)
494{
495 atomic_inc(dev->dev_stat_values + index);
9deae968
NB
496 /*
497 * This memory barrier orders stores updating statistics before stores
498 * updating dev_stats_ccnt.
499 *
500 * It pairs with smp_rmb() in btrfs_run_dev_stats().
501 */
addc3fa7
MX
502 smp_mb__before_atomic();
503 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
504}
505
506static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
507 int index)
508{
509 return atomic_read(dev->dev_stat_values + index);
510}
511
512static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
513 int index)
514{
515 int ret;
516
517 ret = atomic_xchg(dev->dev_stat_values + index, 0);
4660c49f
NB
518 /*
519 * atomic_xchg implies a full memory barriers as per atomic_t.txt:
520 * - RMW operations that have a return value are fully ordered;
521 *
522 * This implicit memory barriers is paired with the smp_rmb in
523 * btrfs_run_dev_stats
524 */
addc3fa7 525 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
526 return ret;
527}
528
529static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
530 int index, unsigned long val)
531{
532 atomic_set(dev->dev_stat_values + index, val);
9deae968
NB
533 /*
534 * This memory barrier orders stores updating statistics before stores
535 * updating dev_stats_ccnt.
536 *
537 * It pairs with smp_rmb() in btrfs_run_dev_stats().
538 */
addc3fa7
MX
539 smp_mb__before_atomic();
540 atomic_inc(&dev->dev_stats_ccnt);
442a4f63
SB
541}
542
3e72ee88
QW
543/*
544 * Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
545 * can be used as index to access btrfs_raid_array[].
546 */
547static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
548{
549 if (flags & BTRFS_BLOCK_GROUP_RAID10)
550 return BTRFS_RAID_RAID10;
551 else if (flags & BTRFS_BLOCK_GROUP_RAID1)
552 return BTRFS_RAID_RAID1;
47e6f742
DS
553 else if (flags & BTRFS_BLOCK_GROUP_RAID1C3)
554 return BTRFS_RAID_RAID1C3;
8d6fac00
DS
555 else if (flags & BTRFS_BLOCK_GROUP_RAID1C4)
556 return BTRFS_RAID_RAID1C4;
3e72ee88
QW
557 else if (flags & BTRFS_BLOCK_GROUP_DUP)
558 return BTRFS_RAID_DUP;
559 else if (flags & BTRFS_BLOCK_GROUP_RAID0)
560 return BTRFS_RAID_RAID0;
561 else if (flags & BTRFS_BLOCK_GROUP_RAID5)
562 return BTRFS_RAID_RAID5;
563 else if (flags & BTRFS_BLOCK_GROUP_RAID6)
564 return BTRFS_RAID_RAID6;
565
566 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
567}
568
bbbf7243 569void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
04216820 570
4143cb8b 571struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
5a13f430
AJ
572void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
573void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
6528b99d
AJ
574bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
575 struct btrfs_device *failing_dev);
21634a19 576
46df06b8 577int btrfs_bg_type_to_factor(u64 flags);
158da513 578const char *btrfs_bg_type_to_raid_name(u64 flags);
cf90d884 579int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
46df06b8 580
0b86a832 581#endif