]>
Commit | Line | Data |
---|---|---|
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 |
16 | extern struct mutex uuid_mutex; |
17 | ||
ee22184b | 18 | #define BTRFS_STRIPE_LEN SZ_64K |
b2117a39 | 19 | |
5f141126 NB |
20 | struct 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 | |
d5c82388 DB |
42 | #define btrfs_device_data_ordered_init(device, info) \ |
43 | seqcount_mutex_init(&device->data_seqcount, &info->chunk_mutex) | |
7cc8e58d | 44 | #else |
d5c82388 | 45 | #define btrfs_device_data_ordered_init(device, info) do { } while (0) |
7cc8e58d MX |
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) |
66d204a1 | 53 | #define BTRFS_DEV_STATE_NO_READA (5) |
ebbede42 | 54 | |
0b86a832 | 55 | struct btrfs_device { |
0b6f5d40 NB |
56 | struct list_head dev_list; /* device_list_mutex */ |
57 | struct list_head dev_alloc_list; /* chunk mutex */ | |
bbbf7243 | 58 | struct list_head post_commit_list; /* chunk mutex */ |
2b82032c | 59 | struct btrfs_fs_devices *fs_devices; |
fb456252 | 60 | struct btrfs_fs_info *fs_info; |
ffbd517d | 61 | |
8d1a7aae | 62 | struct rcu_string __rcu *name; |
d5ee37bc MX |
63 | |
64 | u64 generation; | |
65 | ||
d5ee37bc MX |
66 | struct block_device *bdev; |
67 | ||
68 | /* the mode sent to blkdev_get */ | |
69 | fmode_t mode; | |
70 | ||
ebbede42 | 71 | unsigned long dev_state; |
58efbc9f | 72 | blk_status_t last_flush_error; |
b3075717 | 73 | |
7cc8e58d | 74 | #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED |
d5c82388 DB |
75 | /* A seqcount_t with associated chunk_mutex (for lockdep) */ |
76 | seqcount_mutex_t data_seqcount; | |
7cc8e58d MX |
77 | #endif |
78 | ||
0b86a832 CM |
79 | /* the internal btrfs device id */ |
80 | u64 devid; | |
81 | ||
6ba40b61 | 82 | /* size of the device in memory */ |
0b86a832 CM |
83 | u64 total_bytes; |
84 | ||
6ba40b61 | 85 | /* size of the device on disk */ |
d6397bae CB |
86 | u64 disk_total_bytes; |
87 | ||
0b86a832 CM |
88 | /* bytes used */ |
89 | u64 bytes_used; | |
90 | ||
91 | /* optimal io alignment for this device */ | |
92 | u32 io_align; | |
93 | ||
94 | /* optimal io width for this device */ | |
95 | u32 io_width; | |
3c45bfc1 DG |
96 | /* type and info about this device */ |
97 | u64 type; | |
0b86a832 CM |
98 | |
99 | /* minimal io size for this device */ | |
100 | u32 sector_size; | |
101 | ||
0b86a832 | 102 | /* physical drive uuid (or lvm uuid) */ |
e17cade2 | 103 | u8 uuid[BTRFS_UUID_SIZE]; |
8b712842 | 104 | |
935e5cc9 MX |
105 | /* |
106 | * size of the device on the current transaction | |
107 | * | |
108 | * This variant is update when committing the transaction, | |
bbbf7243 | 109 | * and protected by chunk mutex |
935e5cc9 MX |
110 | */ |
111 | u64 commit_total_bytes; | |
112 | ||
ce7213c7 MX |
113 | /* bytes used on the current transaction */ |
114 | u64 commit_bytes_used; | |
935e5cc9 | 115 | |
3c45bfc1 | 116 | /* for sending down flush barriers */ |
3c45bfc1 DG |
117 | struct bio *flush_bio; |
118 | struct completion flush_wait; | |
119 | ||
a2de733c | 120 | /* per-device scrub information */ |
cadbc0a0 | 121 | struct scrub_ctx *scrub_ctx; |
a2de733c | 122 | |
90519d66 | 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]; |
1c11b63e JM |
137 | |
138 | struct extent_io_tree alloc_state; | |
668e48af AJ |
139 | |
140 | struct completion kobj_unregister; | |
141 | /* For sysfs/FSID/devinfo/devid/ */ | |
142 | struct kobject devid_kobj; | |
0b86a832 CM |
143 | }; |
144 | ||
7cc8e58d MX |
145 | /* |
146 | * If we read those variants at the context of their own lock, we needn't | |
147 | * use the following helpers, reading them directly is safe. | |
148 | */ | |
149 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | |
150 | #define BTRFS_DEVICE_GETSET_FUNCS(name) \ | |
151 | static inline u64 \ | |
152 | btrfs_device_get_##name(const struct btrfs_device *dev) \ | |
153 | { \ | |
154 | u64 size; \ | |
155 | unsigned int seq; \ | |
156 | \ | |
157 | do { \ | |
158 | seq = read_seqcount_begin(&dev->data_seqcount); \ | |
159 | size = dev->name; \ | |
160 | } while (read_seqcount_retry(&dev->data_seqcount, seq)); \ | |
161 | return size; \ | |
162 | } \ | |
163 | \ | |
164 | static inline void \ | |
165 | btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ | |
166 | { \ | |
7cc8e58d MX |
167 | write_seqcount_begin(&dev->data_seqcount); \ |
168 | dev->name = size; \ | |
169 | write_seqcount_end(&dev->data_seqcount); \ | |
7cc8e58d | 170 | } |
94545870 | 171 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION) |
7cc8e58d MX |
172 | #define BTRFS_DEVICE_GETSET_FUNCS(name) \ |
173 | static inline u64 \ | |
174 | btrfs_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 | \ | |
184 | static inline void \ | |
185 | btrfs_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) \ | |
193 | static inline u64 \ | |
194 | btrfs_device_get_##name(const struct btrfs_device *dev) \ | |
195 | { \ | |
196 | return dev->name; \ | |
197 | } \ | |
198 | \ | |
199 | static inline void \ | |
200 | btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ | |
201 | { \ | |
202 | dev->name = size; \ | |
203 | } | |
204 | #endif | |
205 | ||
206 | BTRFS_DEVICE_GETSET_FUNCS(total_bytes); | |
207 | BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes); | |
208 | BTRFS_DEVICE_GETSET_FUNCS(bytes_used); | |
209 | ||
c4a816c6 NA |
210 | enum btrfs_chunk_allocation_policy { |
211 | BTRFS_CHUNK_ALLOC_REGULAR, | |
212 | }; | |
213 | ||
8a4b83cc CM |
214 | struct 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 | 248 | |
944d3f9f | 249 | struct list_head seed_list; |
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 | */ | |
289 | struct 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 | ||
303 | static 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 |
308 | static 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 |
316 | struct 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 | 322 | struct 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 |
345 | struct 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 | 352 | struct 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 | 367 | extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES]; |
af902047 | 368 | |
1abe9b8a | 369 | struct 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 | 383 | struct btrfs_balance_args; |
19a39dce | 384 | struct btrfs_balance_progress; |
c9e9f97b | 385 | struct 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 |
395 | enum btrfs_map_op { |
396 | BTRFS_MAP_READ, | |
397 | BTRFS_MAP_WRITE, | |
398 | BTRFS_MAP_DISCARD, | |
399 | BTRFS_MAP_GET_READ_MIRRORS, | |
400 | }; | |
401 | ||
402 | static 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 |
417 | void btrfs_get_bbio(struct btrfs_bio *bbio); |
418 | void btrfs_put_bbio(struct btrfs_bio *bbio); | |
cf8cddd3 | 419 | int 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 | 422 | int 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 | 425 | int 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 | 427 | int btrfs_read_sys_array(struct btrfs_fs_info *fs_info); |
5b4aacef | 428 | int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info); |
c216b203 | 429 | int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type); |
c8bf1b67 | 430 | void btrfs_mapping_tree_free(struct extent_map_tree *tree); |
58efbc9f | 431 | blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, |
08635bae | 432 | int mirror_num); |
8a4b83cc | 433 | int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, |
97288f2c | 434 | fmode_t flags, void *holder); |
36350e95 GJ |
435 | struct btrfs_device *btrfs_scan_one_device(const char *path, |
436 | fmode_t flags, void *holder); | |
228a73ab | 437 | int btrfs_forget_devices(const char *path); |
54eed6ae | 438 | void btrfs_close_devices(struct btrfs_fs_devices *fs_devices); |
9b99b115 | 439 | void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step); |
d6507cf1 NB |
440 | void btrfs_assign_next_active_device(struct btrfs_device *device, |
441 | struct btrfs_device *this_dev); | |
a27a94c2 NB |
442 | struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, |
443 | u64 devid, | |
444 | const char *devpath); | |
12bd2fc0 ID |
445 | struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, |
446 | const u64 *devid, | |
447 | const u8 *uuid); | |
a425f9d4 | 448 | void btrfs_free_device(struct btrfs_device *device); |
2ff7e61e | 449 | int btrfs_rm_device(struct btrfs_fs_info *fs_info, |
da353f6b | 450 | const char *device_path, u64 devid); |
ffc5a379 | 451 | void __exit btrfs_cleanup_fs_uuids(void); |
5d964051 | 452 | int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); |
8f18cf13 CM |
453 | int btrfs_grow_device(struct btrfs_trans_handle *trans, |
454 | struct btrfs_device *device, u64 new_size); | |
e4319cd9 | 455 | struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices, |
09ba3bc9 | 456 | u64 devid, u8 *uuid, u8 *fsid, bool seed); |
8f18cf13 | 457 | int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); |
da353f6b | 458 | int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path); |
6fcf6e2b DS |
459 | int btrfs_balance(struct btrfs_fs_info *fs_info, |
460 | struct btrfs_balance_control *bctl, | |
c9e9f97b | 461 | struct btrfs_ioctl_balance_args *bargs); |
f89e09cf | 462 | void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf); |
2b6ba629 | 463 | int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info); |
68310a5e | 464 | int btrfs_recover_balance(struct btrfs_fs_info *fs_info); |
837d5b6e | 465 | int btrfs_pause_balance(struct btrfs_fs_info *fs_info); |
a7e99c69 | 466 | int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); |
f7a81ea4 | 467 | int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); |
97f4dd09 | 468 | int btrfs_uuid_scan_kthread(void *data); |
2ff7e61e | 469 | int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset); |
60dfdf25 | 470 | int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, |
ba1bf481 | 471 | u64 *start, u64 *max_avail); |
442a4f63 | 472 | void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); |
2ff7e61e | 473 | int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, |
b27f7c0c | 474 | struct btrfs_ioctl_get_dev_stats *stats); |
cb517eab | 475 | void btrfs_init_devices_late(struct btrfs_fs_info *fs_info); |
733f4fbb | 476 | int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info); |
196c9d8d | 477 | int btrfs_run_dev_stats(struct btrfs_trans_handle *trans); |
68a9db5f | 478 | void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev); |
65237ee3 | 479 | void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev); |
4f5ad7bd | 480 | void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev); |
592d92ee | 481 | int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, |
e4ff5fb5 | 482 | u64 logical, u64 len); |
2ff7e61e | 483 | unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, |
53b381b3 | 484 | u64 logical); |
6df9a95e | 485 | int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, |
97aff912 NB |
486 | u64 chunk_offset, u64 chunk_size); |
487 | int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset); | |
60ca842e OS |
488 | struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info, |
489 | u64 logical, u64 length); | |
8f32380d | 490 | void btrfs_release_disk_super(struct btrfs_super_block *super); |
addc3fa7 | 491 | |
442a4f63 SB |
492 | static 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 | ||
506 | static 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 | ||
512 | static 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 | ||
529 | static 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 | */ | |
547 | static 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 | 569 | void btrfs_commit_device_sizes(struct btrfs_transaction *trans); |
04216820 | 570 | |
4143cb8b | 571 | struct list_head * __attribute_const__ btrfs_get_fs_uuids(void); |
6528b99d AJ |
572 | bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, |
573 | struct btrfs_device *failing_dev); | |
313b0858 JB |
574 | void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, |
575 | struct block_device *bdev, | |
576 | const char *device_path); | |
21634a19 | 577 | |
46df06b8 | 578 | int btrfs_bg_type_to_factor(u64 flags); |
158da513 | 579 | const char *btrfs_bg_type_to_raid_name(u64 flags); |
cf90d884 | 580 | int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info); |
46df06b8 | 581 | |
0b86a832 | 582 | #endif |