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