]>
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 | |
c41ec452 SY |
42 | #define btrfs_device_data_ordered_init(device) \ |
43 | seqcount_init(&device->data_seqcount) | |
7cc8e58d | 44 | #else |
c41ec452 | 45 | #define btrfs_device_data_ordered_init(device) 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 | |
5b316468 NA |
55 | struct btrfs_zoned_device_info; |
56 | ||
0b86a832 | 57 | struct btrfs_device { |
0b6f5d40 NB |
58 | struct list_head dev_list; /* device_list_mutex */ |
59 | struct list_head dev_alloc_list; /* chunk mutex */ | |
bbbf7243 | 60 | struct list_head post_commit_list; /* chunk mutex */ |
2b82032c | 61 | struct btrfs_fs_devices *fs_devices; |
fb456252 | 62 | struct btrfs_fs_info *fs_info; |
ffbd517d | 63 | |
8d1a7aae | 64 | struct rcu_string __rcu *name; |
d5ee37bc MX |
65 | |
66 | u64 generation; | |
67 | ||
d5ee37bc MX |
68 | struct block_device *bdev; |
69 | ||
5b316468 NA |
70 | struct btrfs_zoned_device_info *zone_info; |
71 | ||
d5ee37bc MX |
72 | /* the mode sent to blkdev_get */ |
73 | fmode_t mode; | |
74 | ||
ebbede42 | 75 | unsigned long dev_state; |
58efbc9f | 76 | blk_status_t last_flush_error; |
b3075717 | 77 | |
7cc8e58d | 78 | #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED |
c41ec452 | 79 | seqcount_t data_seqcount; |
7cc8e58d MX |
80 | #endif |
81 | ||
0b86a832 CM |
82 | /* the internal btrfs device id */ |
83 | u64 devid; | |
84 | ||
6ba40b61 | 85 | /* size of the device in memory */ |
0b86a832 CM |
86 | u64 total_bytes; |
87 | ||
6ba40b61 | 88 | /* size of the device on disk */ |
d6397bae CB |
89 | u64 disk_total_bytes; |
90 | ||
0b86a832 CM |
91 | /* bytes used */ |
92 | u64 bytes_used; | |
93 | ||
94 | /* optimal io alignment for this device */ | |
95 | u32 io_align; | |
96 | ||
97 | /* optimal io width for this device */ | |
98 | u32 io_width; | |
3c45bfc1 DG |
99 | /* type and info about this device */ |
100 | u64 type; | |
0b86a832 CM |
101 | |
102 | /* minimal io size for this device */ | |
103 | u32 sector_size; | |
104 | ||
0b86a832 | 105 | /* physical drive uuid (or lvm uuid) */ |
e17cade2 | 106 | u8 uuid[BTRFS_UUID_SIZE]; |
8b712842 | 107 | |
935e5cc9 MX |
108 | /* |
109 | * size of the device on the current transaction | |
110 | * | |
111 | * This variant is update when committing the transaction, | |
bbbf7243 | 112 | * and protected by chunk mutex |
935e5cc9 MX |
113 | */ |
114 | u64 commit_total_bytes; | |
115 | ||
ce7213c7 MX |
116 | /* bytes used on the current transaction */ |
117 | u64 commit_bytes_used; | |
935e5cc9 | 118 | |
3c45bfc1 | 119 | /* for sending down flush barriers */ |
3c45bfc1 DG |
120 | struct bio *flush_bio; |
121 | struct completion flush_wait; | |
122 | ||
a2de733c | 123 | /* per-device scrub information */ |
cadbc0a0 | 124 | struct scrub_ctx *scrub_ctx; |
a2de733c | 125 | |
90519d66 | 126 | /* readahead state */ |
90519d66 AJ |
127 | atomic_t reada_in_flight; |
128 | u64 reada_next; | |
129 | struct reada_zone *reada_curr_zone; | |
130 | struct radix_tree_root reada_zones; | |
131 | struct radix_tree_root reada_extents; | |
387125fc | 132 | |
442a4f63 SB |
133 | /* disk I/O failure stats. For detailed description refer to |
134 | * enum btrfs_dev_stat_values in ioctl.h */ | |
733f4fbb | 135 | int dev_stats_valid; |
addc3fa7 MX |
136 | |
137 | /* Counter to record the change of device stats */ | |
138 | atomic_t dev_stats_ccnt; | |
442a4f63 | 139 | atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX]; |
1c11b63e JM |
140 | |
141 | struct extent_io_tree alloc_state; | |
668e48af AJ |
142 | |
143 | struct completion kobj_unregister; | |
144 | /* For sysfs/FSID/devinfo/devid/ */ | |
145 | struct kobject devid_kobj; | |
eb3b5053 DS |
146 | |
147 | /* Bandwidth limit for scrub, in bytes */ | |
148 | u64 scrub_speed_max; | |
0b86a832 CM |
149 | }; |
150 | ||
7cc8e58d MX |
151 | /* |
152 | * If we read those variants at the context of their own lock, we needn't | |
153 | * use the following helpers, reading them directly is safe. | |
154 | */ | |
155 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | |
156 | #define BTRFS_DEVICE_GETSET_FUNCS(name) \ | |
157 | static inline u64 \ | |
158 | btrfs_device_get_##name(const struct btrfs_device *dev) \ | |
159 | { \ | |
160 | u64 size; \ | |
161 | unsigned int seq; \ | |
162 | \ | |
163 | do { \ | |
164 | seq = read_seqcount_begin(&dev->data_seqcount); \ | |
165 | size = dev->name; \ | |
166 | } while (read_seqcount_retry(&dev->data_seqcount, seq)); \ | |
167 | return size; \ | |
168 | } \ | |
169 | \ | |
170 | static inline void \ | |
171 | btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ | |
172 | { \ | |
c41ec452 | 173 | preempt_disable(); \ |
7cc8e58d MX |
174 | write_seqcount_begin(&dev->data_seqcount); \ |
175 | dev->name = size; \ | |
176 | write_seqcount_end(&dev->data_seqcount); \ | |
c41ec452 | 177 | preempt_enable(); \ |
7cc8e58d | 178 | } |
94545870 | 179 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION) |
7cc8e58d MX |
180 | #define BTRFS_DEVICE_GETSET_FUNCS(name) \ |
181 | static inline u64 \ | |
182 | btrfs_device_get_##name(const struct btrfs_device *dev) \ | |
183 | { \ | |
184 | u64 size; \ | |
185 | \ | |
186 | preempt_disable(); \ | |
187 | size = dev->name; \ | |
188 | preempt_enable(); \ | |
189 | return size; \ | |
190 | } \ | |
191 | \ | |
192 | static inline void \ | |
193 | btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ | |
194 | { \ | |
195 | preempt_disable(); \ | |
196 | dev->name = size; \ | |
197 | preempt_enable(); \ | |
198 | } | |
199 | #else | |
200 | #define BTRFS_DEVICE_GETSET_FUNCS(name) \ | |
201 | static inline u64 \ | |
202 | btrfs_device_get_##name(const struct btrfs_device *dev) \ | |
203 | { \ | |
204 | return dev->name; \ | |
205 | } \ | |
206 | \ | |
207 | static inline void \ | |
208 | btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \ | |
209 | { \ | |
210 | dev->name = size; \ | |
211 | } | |
212 | #endif | |
213 | ||
214 | BTRFS_DEVICE_GETSET_FUNCS(total_bytes); | |
215 | BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes); | |
216 | BTRFS_DEVICE_GETSET_FUNCS(bytes_used); | |
217 | ||
c4a816c6 NA |
218 | enum btrfs_chunk_allocation_policy { |
219 | BTRFS_CHUNK_ALLOC_REGULAR, | |
1cd6121f | 220 | BTRFS_CHUNK_ALLOC_ZONED, |
c4a816c6 NA |
221 | }; |
222 | ||
33fd2f71 AJ |
223 | /* |
224 | * Read policies for mirrored block group profiles, read picks the stripe based | |
225 | * on these policies. | |
226 | */ | |
227 | enum btrfs_read_policy { | |
228 | /* Use process PID to choose the stripe */ | |
229 | BTRFS_READ_POLICY_PID, | |
230 | BTRFS_NR_READ_POLICY, | |
231 | }; | |
232 | ||
8a4b83cc CM |
233 | struct btrfs_fs_devices { |
234 | u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ | |
7239ff4b | 235 | u8 metadata_uuid[BTRFS_FSID_SIZE]; |
d1a63002 | 236 | bool fsid_change; |
c4babc5e | 237 | struct list_head fs_list; |
8a4b83cc | 238 | |
add9745a AJ |
239 | /* |
240 | * Number of devices under this fsid including missing and | |
241 | * replace-target device and excludes seed devices. | |
242 | */ | |
8a4b83cc | 243 | u64 num_devices; |
add9745a AJ |
244 | |
245 | /* | |
246 | * The number of devices that successfully opened, including | |
247 | * replace-target, excludes seed devices. | |
248 | */ | |
a0af469b | 249 | u64 open_devices; |
add9745a AJ |
250 | |
251 | /* The number of devices that are under the chunk allocation list. */ | |
2b82032c | 252 | u64 rw_devices; |
add9745a AJ |
253 | |
254 | /* Count of missing devices under this fsid excluding seed device. */ | |
cd02dca5 | 255 | u64 missing_devices; |
2b82032c | 256 | u64 total_rw_bytes; |
add9745a AJ |
257 | |
258 | /* | |
259 | * Count of devices from btrfs_super_block::num_devices for this fsid, | |
260 | * which includes the seed device, excludes the transient replace-target | |
261 | * device. | |
262 | */ | |
02db0844 | 263 | u64 total_devices; |
d1a63002 NB |
264 | |
265 | /* Highest generation number of seen devices */ | |
266 | u64 latest_generation; | |
267 | ||
d24fa5c1 AJ |
268 | /* |
269 | * The mount device or a device with highest generation after removal | |
270 | * or replace. | |
271 | */ | |
272 | struct btrfs_device *latest_dev; | |
e5e9a520 CM |
273 | |
274 | /* all of the devices in the FS, protected by a mutex | |
275 | * so we can safely walk it to write out the supers without | |
9b011adf WS |
276 | * worrying about add/remove by the multi-device code. |
277 | * Scrubbing super can kick off supers writing by holding | |
278 | * this mutex lock. | |
e5e9a520 CM |
279 | */ |
280 | struct mutex device_list_mutex; | |
0b6f5d40 NB |
281 | |
282 | /* List of all devices, protected by device_list_mutex */ | |
8a4b83cc | 283 | struct list_head devices; |
b3075717 | 284 | |
0b6f5d40 NB |
285 | /* |
286 | * Devices which can satisfy space allocation. Protected by | |
287 | * chunk_mutex | |
288 | */ | |
b3075717 | 289 | struct list_head alloc_list; |
2b82032c | 290 | |
944d3f9f | 291 | struct list_head seed_list; |
0395d84f | 292 | bool seeding; |
2b82032c YZ |
293 | |
294 | int opened; | |
c289811c CM |
295 | |
296 | /* set when we find or add a device that doesn't have the | |
297 | * nonrot flag set | |
298 | */ | |
7f0432d0 | 299 | bool rotating; |
2e7910d6 | 300 | |
5a13f430 | 301 | struct btrfs_fs_info *fs_info; |
2e7910d6 | 302 | /* sysfs kobjects */ |
c1b7e474 | 303 | struct kobject fsid_kobj; |
b5501504 | 304 | struct kobject *devices_kobj; |
a013d141 | 305 | struct kobject *devinfo_kobj; |
2e7910d6 | 306 | struct completion kobj_unregister; |
c4a816c6 NA |
307 | |
308 | enum btrfs_chunk_allocation_policy chunk_alloc_policy; | |
33fd2f71 AJ |
309 | |
310 | /* Policy used to read the mirrored stripes */ | |
311 | enum btrfs_read_policy read_policy; | |
8a4b83cc CM |
312 | }; |
313 | ||
facc8a22 MX |
314 | #define BTRFS_BIO_INLINE_CSUM_SIZE 64 |
315 | ||
ab4ba2e1 QW |
316 | #define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \ |
317 | - sizeof(struct btrfs_chunk)) \ | |
318 | / sizeof(struct btrfs_stripe) + 1) | |
319 | ||
320 | #define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \ | |
321 | - 2 * sizeof(struct btrfs_disk_key) \ | |
322 | - 2 * sizeof(struct btrfs_chunk)) \ | |
323 | / sizeof(struct btrfs_stripe) + 1) | |
324 | ||
9be3395b | 325 | /* |
c3a3b19b QW |
326 | * Additional info to pass along bio. |
327 | * | |
328 | * Mostly for btrfs specific features like csum and mirror_num. | |
9be3395b | 329 | */ |
c3a3b19b | 330 | struct btrfs_bio { |
c1dc0896 | 331 | unsigned int mirror_num; |
c3a3b19b QW |
332 | |
333 | /* @device is for stripe IO submission. */ | |
c31efbdf | 334 | struct btrfs_device *device; |
facc8a22 MX |
335 | u8 *csum; |
336 | u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE]; | |
17347cec | 337 | struct bvec_iter iter; |
c3a3b19b | 338 | |
fa1bcbe0 DS |
339 | /* |
340 | * This member must come last, bio_alloc_bioset will allocate enough | |
c3a3b19b | 341 | * bytes for entire btrfs_bio but relies on bio being last. |
fa1bcbe0 | 342 | */ |
9be3395b CM |
343 | struct bio bio; |
344 | }; | |
345 | ||
c3a3b19b | 346 | static inline struct btrfs_bio *btrfs_bio(struct bio *bio) |
9be3395b | 347 | { |
c3a3b19b | 348 | return container_of(bio, struct btrfs_bio, bio); |
9be3395b CM |
349 | } |
350 | ||
c3a3b19b | 351 | static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio) |
b3a0dd50 | 352 | { |
c3a3b19b QW |
353 | if (bbio->csum != bbio->csum_inline) { |
354 | kfree(bbio->csum); | |
355 | bbio->csum = NULL; | |
b3a0dd50 DS |
356 | } |
357 | } | |
358 | ||
4c664611 | 359 | struct btrfs_io_stripe { |
cea9e445 CM |
360 | struct btrfs_device *dev; |
361 | u64 physical; | |
fce3bb9a | 362 | u64 length; /* only used for discard mappings */ |
cea9e445 CM |
363 | }; |
364 | ||
4c664611 QW |
365 | /* |
366 | * Context for IO subsmission for device stripe. | |
367 | * | |
368 | * - Track the unfinished mirrors for mirror based profiles | |
369 | * Mirror based profiles are SINGLE/DUP/RAID1/RAID10. | |
370 | * | |
371 | * - Contain the logical -> physical mapping info | |
372 | * Used by submit_stripe_bio() for mapping logical bio | |
373 | * into physical device address. | |
374 | * | |
375 | * - Contain device replace info | |
376 | * Used by handle_ops_on_dev_replace() to copy logical bios | |
377 | * into the new device. | |
378 | * | |
379 | * - Contain RAID56 full stripe logical bytenrs | |
380 | */ | |
381 | struct btrfs_io_context { | |
140475ae | 382 | refcount_t refs; |
cea9e445 | 383 | atomic_t stripes_pending; |
c404e0dc | 384 | struct btrfs_fs_info *fs_info; |
10f11900 | 385 | u64 map_type; /* get from map_lookup->type */ |
cea9e445 | 386 | bio_end_io_t *end_io; |
7d2b4daa | 387 | struct bio *orig_bio; |
cea9e445 | 388 | void *private; |
a236aed1 CM |
389 | atomic_t error; |
390 | int max_errors; | |
cea9e445 | 391 | int num_stripes; |
a1d3c478 | 392 | int mirror_num; |
2c8cdd6e MX |
393 | int num_tgtdevs; |
394 | int *tgtdev_map; | |
8e5cfb55 ZL |
395 | /* |
396 | * logical block numbers for the start of each stripe | |
397 | * The last one or two are p/q. These are sorted, | |
398 | * so raid_map[0] is the start of our full stripe | |
399 | */ | |
400 | u64 *raid_map; | |
4c664611 | 401 | struct btrfs_io_stripe stripes[]; |
cea9e445 CM |
402 | }; |
403 | ||
b2117a39 MX |
404 | struct btrfs_device_info { |
405 | struct btrfs_device *dev; | |
406 | u64 dev_offset; | |
407 | u64 max_avail; | |
73c5de00 | 408 | u64 total_avail; |
b2117a39 MX |
409 | }; |
410 | ||
31e50229 | 411 | struct btrfs_raid_attr { |
8c3e3582 DS |
412 | u8 sub_stripes; /* sub_stripes info for map */ |
413 | u8 dev_stripes; /* stripes per dev */ | |
414 | u8 devs_max; /* max devs to use */ | |
415 | u8 devs_min; /* min devs needed */ | |
416 | u8 tolerated_failures; /* max tolerated fail devs */ | |
417 | u8 devs_increment; /* ndevs has to be a multiple of this */ | |
418 | u8 ncopies; /* how many copies to data has */ | |
419 | u8 nparity; /* number of stripes worth of bytes to store | |
b50836ed | 420 | * parity information */ |
8c3e3582 | 421 | u8 mindev_error; /* error code if min devs requisite is unmet */ |
ed23467b | 422 | const char raid_name[8]; /* name of the raid */ |
41a6e891 | 423 | u64 bg_flag; /* block group flag of the raid */ |
31e50229 LB |
424 | }; |
425 | ||
af902047 | 426 | extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES]; |
af902047 | 427 | |
1abe9b8a | 428 | struct map_lookup { |
429 | u64 type; | |
430 | int io_align; | |
431 | int io_width; | |
3d8da678 | 432 | u64 stripe_len; |
1abe9b8a | 433 | int num_stripes; |
434 | int sub_stripes; | |
cf90d884 | 435 | int verified_stripes; /* For mount time dev extent verification */ |
4c664611 | 436 | struct btrfs_io_stripe stripes[]; |
1abe9b8a | 437 | }; |
438 | ||
a2de733c | 439 | #define map_lookup_size(n) (sizeof(struct map_lookup) + \ |
4c664611 | 440 | (sizeof(struct btrfs_io_stripe) * (n))) |
a2de733c | 441 | |
c9e9f97b | 442 | struct btrfs_balance_args; |
19a39dce | 443 | struct btrfs_balance_progress; |
c9e9f97b | 444 | struct btrfs_balance_control { |
c9e9f97b ID |
445 | struct btrfs_balance_args data; |
446 | struct btrfs_balance_args meta; | |
447 | struct btrfs_balance_args sys; | |
448 | ||
449 | u64 flags; | |
19a39dce ID |
450 | |
451 | struct btrfs_balance_progress stat; | |
c9e9f97b ID |
452 | }; |
453 | ||
cf8cddd3 CH |
454 | enum btrfs_map_op { |
455 | BTRFS_MAP_READ, | |
456 | BTRFS_MAP_WRITE, | |
457 | BTRFS_MAP_DISCARD, | |
458 | BTRFS_MAP_GET_READ_MIRRORS, | |
459 | }; | |
460 | ||
461 | static inline enum btrfs_map_op btrfs_op(struct bio *bio) | |
462 | { | |
463 | switch (bio_op(bio)) { | |
464 | case REQ_OP_DISCARD: | |
465 | return BTRFS_MAP_DISCARD; | |
466 | case REQ_OP_WRITE: | |
cfe94440 | 467 | case REQ_OP_ZONE_APPEND: |
cf8cddd3 CH |
468 | return BTRFS_MAP_WRITE; |
469 | default: | |
470 | WARN_ON_ONCE(1); | |
c730ae0c | 471 | fallthrough; |
cf8cddd3 CH |
472 | case REQ_OP_READ: |
473 | return BTRFS_MAP_READ; | |
474 | } | |
475 | } | |
476 | ||
4c664611 QW |
477 | void btrfs_get_bioc(struct btrfs_io_context *bioc); |
478 | void btrfs_put_bioc(struct btrfs_io_context *bioc); | |
cf8cddd3 | 479 | int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
cea9e445 | 480 | u64 logical, u64 *length, |
4c664611 | 481 | struct btrfs_io_context **bioc_ret, int mirror_num); |
cf8cddd3 | 482 | int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
af8e2d1d | 483 | u64 logical, u64 *length, |
4c664611 | 484 | struct btrfs_io_context **bioc_ret); |
42034313 | 485 | int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *map, |
43c0d1a5 | 486 | enum btrfs_map_op op, u64 logical, |
42034313 | 487 | struct btrfs_io_geometry *io_geom); |
6bccf3ab | 488 | int btrfs_read_sys_array(struct btrfs_fs_info *fs_info); |
5b4aacef | 489 | int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info); |
f6f39f7a | 490 | struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, |
79bd3712 | 491 | u64 type); |
c8bf1b67 | 492 | void btrfs_mapping_tree_free(struct extent_map_tree *tree); |
58efbc9f | 493 | blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, |
08635bae | 494 | int mirror_num); |
8a4b83cc | 495 | int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, |
97288f2c | 496 | fmode_t flags, void *holder); |
36350e95 GJ |
497 | struct btrfs_device *btrfs_scan_one_device(const char *path, |
498 | fmode_t flags, void *holder); | |
228a73ab | 499 | int btrfs_forget_devices(const char *path); |
54eed6ae | 500 | void btrfs_close_devices(struct btrfs_fs_devices *fs_devices); |
bacce86a | 501 | void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices); |
d6507cf1 NB |
502 | void btrfs_assign_next_active_device(struct btrfs_device *device, |
503 | struct btrfs_device *this_dev); | |
a27a94c2 NB |
504 | struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, |
505 | u64 devid, | |
506 | const char *devpath); | |
12bd2fc0 ID |
507 | struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, |
508 | const u64 *devid, | |
509 | const u8 *uuid); | |
a425f9d4 | 510 | void btrfs_free_device(struct btrfs_device *device); |
2ff7e61e | 511 | int btrfs_rm_device(struct btrfs_fs_info *fs_info, |
3fa421de JB |
512 | const char *device_path, u64 devid, |
513 | struct block_device **bdev, fmode_t *mode); | |
ffc5a379 | 514 | void __exit btrfs_cleanup_fs_uuids(void); |
5d964051 | 515 | int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); |
8f18cf13 CM |
516 | int btrfs_grow_device(struct btrfs_trans_handle *trans, |
517 | struct btrfs_device *device, u64 new_size); | |
e4319cd9 | 518 | struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices, |
b2598edf | 519 | u64 devid, u8 *uuid, u8 *fsid); |
8f18cf13 | 520 | int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); |
da353f6b | 521 | int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path); |
6fcf6e2b DS |
522 | int btrfs_balance(struct btrfs_fs_info *fs_info, |
523 | struct btrfs_balance_control *bctl, | |
c9e9f97b | 524 | struct btrfs_ioctl_balance_args *bargs); |
f89e09cf | 525 | void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf); |
2b6ba629 | 526 | int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info); |
68310a5e | 527 | int btrfs_recover_balance(struct btrfs_fs_info *fs_info); |
837d5b6e | 528 | int btrfs_pause_balance(struct btrfs_fs_info *fs_info); |
18bb8bbf | 529 | int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset); |
a7e99c69 | 530 | int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); |
f7a81ea4 | 531 | int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); |
97f4dd09 | 532 | int btrfs_uuid_scan_kthread(void *data); |
a09f23c3 | 533 | bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset); |
60dfdf25 | 534 | int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, |
ba1bf481 | 535 | u64 *start, u64 *max_avail); |
442a4f63 | 536 | void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); |
2ff7e61e | 537 | int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, |
b27f7c0c | 538 | struct btrfs_ioctl_get_dev_stats *stats); |
cb517eab | 539 | void btrfs_init_devices_late(struct btrfs_fs_info *fs_info); |
733f4fbb | 540 | int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info); |
196c9d8d | 541 | int btrfs_run_dev_stats(struct btrfs_trans_handle *trans); |
68a9db5f | 542 | void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev); |
65237ee3 | 543 | void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev); |
4f5ad7bd | 544 | void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev); |
592d92ee | 545 | int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, |
e4ff5fb5 | 546 | u64 logical, u64 len); |
2ff7e61e | 547 | unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, |
53b381b3 | 548 | u64 logical); |
79bd3712 FM |
549 | int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans, |
550 | struct btrfs_block_group *bg); | |
97aff912 | 551 | int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset); |
60ca842e OS |
552 | struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info, |
553 | u64 logical, u64 length); | |
8f32380d | 554 | void btrfs_release_disk_super(struct btrfs_super_block *super); |
addc3fa7 | 555 | |
442a4f63 SB |
556 | static inline void btrfs_dev_stat_inc(struct btrfs_device *dev, |
557 | int index) | |
558 | { | |
559 | atomic_inc(dev->dev_stat_values + index); | |
9deae968 NB |
560 | /* |
561 | * This memory barrier orders stores updating statistics before stores | |
562 | * updating dev_stats_ccnt. | |
563 | * | |
564 | * It pairs with smp_rmb() in btrfs_run_dev_stats(). | |
565 | */ | |
addc3fa7 MX |
566 | smp_mb__before_atomic(); |
567 | atomic_inc(&dev->dev_stats_ccnt); | |
442a4f63 SB |
568 | } |
569 | ||
570 | static inline int btrfs_dev_stat_read(struct btrfs_device *dev, | |
571 | int index) | |
572 | { | |
573 | return atomic_read(dev->dev_stat_values + index); | |
574 | } | |
575 | ||
576 | static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev, | |
577 | int index) | |
578 | { | |
579 | int ret; | |
580 | ||
581 | ret = atomic_xchg(dev->dev_stat_values + index, 0); | |
4660c49f NB |
582 | /* |
583 | * atomic_xchg implies a full memory barriers as per atomic_t.txt: | |
584 | * - RMW operations that have a return value are fully ordered; | |
585 | * | |
586 | * This implicit memory barriers is paired with the smp_rmb in | |
587 | * btrfs_run_dev_stats | |
588 | */ | |
addc3fa7 | 589 | atomic_inc(&dev->dev_stats_ccnt); |
442a4f63 SB |
590 | return ret; |
591 | } | |
592 | ||
593 | static inline void btrfs_dev_stat_set(struct btrfs_device *dev, | |
594 | int index, unsigned long val) | |
595 | { | |
596 | atomic_set(dev->dev_stat_values + index, val); | |
9deae968 NB |
597 | /* |
598 | * This memory barrier orders stores updating statistics before stores | |
599 | * updating dev_stats_ccnt. | |
600 | * | |
601 | * It pairs with smp_rmb() in btrfs_run_dev_stats(). | |
602 | */ | |
addc3fa7 MX |
603 | smp_mb__before_atomic(); |
604 | atomic_inc(&dev->dev_stats_ccnt); | |
442a4f63 SB |
605 | } |
606 | ||
bbbf7243 | 607 | void btrfs_commit_device_sizes(struct btrfs_transaction *trans); |
04216820 | 608 | |
4143cb8b | 609 | struct list_head * __attribute_const__ btrfs_get_fs_uuids(void); |
6528b99d AJ |
610 | bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, |
611 | struct btrfs_device *failing_dev); | |
313b0858 JB |
612 | void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, |
613 | struct block_device *bdev, | |
614 | const char *device_path); | |
21634a19 | 615 | |
500a44c9 | 616 | enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags); |
46df06b8 | 617 | int btrfs_bg_type_to_factor(u64 flags); |
158da513 | 618 | const char *btrfs_bg_type_to_raid_name(u64 flags); |
cf90d884 | 619 | int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info); |
f7ef5287 | 620 | int btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical); |
46df06b8 | 621 | |
0b86a832 | 622 | #endif |