hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/btrfs/volumes.h
....@@ -17,10 +17,19 @@
1717
1818 #define BTRFS_STRIPE_LEN SZ_64K
1919
20
-struct buffer_head;
21
-struct btrfs_pending_bios {
22
- struct bio *head;
23
- struct bio *tail;
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;
2433 };
2534
2635 /*
....@@ -41,28 +50,18 @@
4150 #define BTRFS_DEV_STATE_MISSING (2)
4251 #define BTRFS_DEV_STATE_REPLACE_TGT (3)
4352 #define BTRFS_DEV_STATE_FLUSH_SENT (4)
53
+#define BTRFS_DEV_STATE_NO_READA (5)
4454
4555 struct btrfs_device {
46
- struct list_head dev_list;
47
- struct list_head dev_alloc_list;
56
+ struct list_head dev_list; /* device_list_mutex */
57
+ struct list_head dev_alloc_list; /* chunk mutex */
58
+ struct list_head post_commit_list; /* chunk mutex */
4859 struct btrfs_fs_devices *fs_devices;
4960 struct btrfs_fs_info *fs_info;
5061
51
- struct rcu_string *name;
62
+ struct rcu_string __rcu *name;
5263
5364 u64 generation;
54
-
55
- spinlock_t io_lock ____cacheline_aligned;
56
- int running_pending;
57
- /* When true means this device has pending chunk alloc in
58
- * current transaction. Protected by chunk_mutex.
59
- */
60
- bool has_pending_chunks;
61
-
62
- /* regular prio bios */
63
- struct btrfs_pending_bios pending_bios;
64
- /* sync bios */
65
- struct btrfs_pending_bios pending_sync_bios;
6665
6766 struct block_device *bdev;
6867
....@@ -71,7 +70,6 @@
7170
7271 unsigned long dev_state;
7372 blk_status_t last_flush_error;
74
- int flush_bio_sent;
7573
7674 #ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
7775 seqcount_t data_seqcount;
....@@ -107,18 +105,12 @@
107105 * size of the device on the current transaction
108106 *
109107 * This variant is update when committing the transaction,
110
- * and protected by device_list_mutex
108
+ * and protected by chunk mutex
111109 */
112110 u64 commit_total_bytes;
113111
114112 /* bytes used on the current transaction */
115113 u64 commit_bytes_used;
116
- /*
117
- * used to manage the device which is resized
118
- *
119
- * It is protected by chunk_lock.
120
- */
121
- struct list_head resized_list;
122114
123115 /* for sending down flush barriers */
124116 struct bio *flush_bio;
....@@ -126,9 +118,6 @@
126118
127119 /* per-device scrub information */
128120 struct scrub_ctx *scrub_ctx;
129
-
130
- struct btrfs_work work;
131
- struct rcu_head rcu;
132121
133122 /* readahead state */
134123 atomic_t reada_in_flight;
....@@ -144,6 +133,12 @@
144133 /* Counter to record the change of device stats */
145134 atomic_t dev_stats_ccnt;
146135 atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
136
+
137
+ struct extent_io_tree alloc_state;
138
+
139
+ struct completion kobj_unregister;
140
+ /* For sysfs/FSID/devinfo/devid/ */
141
+ struct kobject devid_kobj;
147142 };
148143
149144 /*
....@@ -174,7 +169,7 @@
174169 write_seqcount_end(&dev->data_seqcount); \
175170 preempt_enable(); \
176171 }
177
-#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
172
+#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
178173 #define BTRFS_DEVICE_GETSET_FUNCS(name) \
179174 static inline u64 \
180175 btrfs_device_get_##name(const struct btrfs_device *dev) \
....@@ -213,8 +208,14 @@
213208 BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
214209 BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
215210
211
+enum btrfs_chunk_allocation_policy {
212
+ BTRFS_CHUNK_ALLOC_REGULAR,
213
+};
214
+
216215 struct btrfs_fs_devices {
217216 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
217
+ u8 metadata_uuid[BTRFS_FSID_SIZE];
218
+ bool fsid_change;
218219 struct list_head fs_list;
219220
220221 u64 num_devices;
....@@ -223,6 +224,10 @@
223224 u64 missing_devices;
224225 u64 total_rw_bytes;
225226 u64 total_devices;
227
+
228
+ /* Highest generation number of seen devices */
229
+ u64 latest_generation;
230
+
226231 struct block_device *latest_bdev;
227232
228233 /* all of the devices in the FS, protected by a mutex
....@@ -232,27 +237,34 @@
232237 * this mutex lock.
233238 */
234239 struct mutex device_list_mutex;
240
+
241
+ /* List of all devices, protected by device_list_mutex */
235242 struct list_head devices;
236243
237
- struct list_head resized_devices;
238
- /* devices not currently being allocated */
244
+ /*
245
+ * Devices which can satisfy space allocation. Protected by
246
+ * chunk_mutex
247
+ */
239248 struct list_head alloc_list;
240249
241
- struct btrfs_fs_devices *seed;
242
- int seeding;
250
+ struct list_head seed_list;
251
+ bool seeding;
243252
244253 int opened;
245254
246255 /* set when we find or add a device that doesn't have the
247256 * nonrot flag set
248257 */
249
- int rotating;
258
+ bool rotating;
250259
251260 struct btrfs_fs_info *fs_info;
252261 /* sysfs kobjects */
253262 struct kobject fsid_kobj;
254
- struct kobject *device_dir_kobj;
263
+ struct kobject *devices_kobj;
264
+ struct kobject *devinfo_kobj;
255265 struct completion kobj_unregister;
266
+
267
+ enum btrfs_chunk_allocation_policy chunk_alloc_policy;
256268 };
257269
258270 #define BTRFS_BIO_INLINE_CSUM_SIZE 64
....@@ -275,15 +287,12 @@
275287 * we allocate are actually btrfs_io_bios. We'll cram as much of
276288 * struct btrfs_bio as we can into this over time.
277289 */
278
-typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err);
279290 struct btrfs_io_bio {
280291 unsigned int mirror_num;
281
- unsigned int stripe_index;
292
+ struct btrfs_device *device;
282293 u64 logical;
283294 u8 *csum;
284295 u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
285
- u8 *csum_allocated;
286
- btrfs_io_bio_end_io_t *end_io;
287296 struct bvec_iter iter;
288297 /*
289298 * This member must come last, bio_alloc_bioset will allocate enough
....@@ -297,14 +306,19 @@
297306 return container_of(bio, struct btrfs_io_bio, bio);
298307 }
299308
309
+static inline void btrfs_io_bio_free_csum(struct btrfs_io_bio *io_bio)
310
+{
311
+ if (io_bio->csum != io_bio->csum_inline) {
312
+ kfree(io_bio->csum);
313
+ io_bio->csum = NULL;
314
+ }
315
+}
316
+
300317 struct btrfs_bio_stripe {
301318 struct btrfs_device *dev;
302319 u64 physical;
303320 u64 length; /* only used for discard mappings */
304321 };
305
-
306
-struct btrfs_bio;
307
-typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err);
308322
309323 struct btrfs_bio {
310324 refcount_t refs;
....@@ -337,14 +351,16 @@
337351 };
338352
339353 struct btrfs_raid_attr {
340
- int sub_stripes; /* sub_stripes info for map */
341
- int dev_stripes; /* stripes per dev */
342
- int devs_max; /* max devs to use */
343
- int devs_min; /* min devs needed */
344
- int tolerated_failures; /* max tolerated fail devs */
345
- int devs_increment; /* ndevs has to be a multiple of this */
346
- int ncopies; /* how many copies to data has */
347
- int mindev_error; /* error code if min devs requisite is unmet */
354
+ u8 sub_stripes; /* sub_stripes info for map */
355
+ u8 dev_stripes; /* stripes per dev */
356
+ u8 devs_max; /* max devs to use */
357
+ u8 devs_min; /* min devs needed */
358
+ u8 tolerated_failures; /* max tolerated fail devs */
359
+ u8 devs_increment; /* ndevs has to be a multiple of this */
360
+ u8 ncopies; /* how many copies to data has */
361
+ u8 nparity; /* number of stripes worth of bytes to store
362
+ * parity information */
363
+ u8 mindev_error; /* error code if min devs requisite is unmet */
348364 const char raid_name[8]; /* name of the raid */
349365 u64 bg_flag; /* block group flag of the raid */
350366 };
....@@ -393,6 +409,7 @@
393409 return BTRFS_MAP_WRITE;
394410 default:
395411 WARN_ON_ONCE(1);
412
+ fallthrough;
396413 case REQ_OP_READ:
397414 return BTRFS_MAP_READ;
398415 }
....@@ -406,29 +423,26 @@
406423 int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
407424 u64 logical, u64 *length,
408425 struct btrfs_bio **bbio_ret);
409
-int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
410
- u64 physical, u64 **logical, int *naddrs, int *stripe_len);
426
+int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
427
+ u64 logical, u64 len, struct btrfs_io_geometry *io_geom);
411428 int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
412429 int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
413430 int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type);
414
-void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
415
-void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
431
+void btrfs_mapping_tree_free(struct extent_map_tree *tree);
416432 blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
417
- int mirror_num, int async_submit);
433
+ int mirror_num);
418434 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
419435 fmode_t flags, void *holder);
420436 struct btrfs_device *btrfs_scan_one_device(const char *path,
421437 fmode_t flags, void *holder);
422
-int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
438
+int btrfs_forget_devices(const char *path);
439
+void btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
423440 void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
424441 void btrfs_assign_next_active_device(struct btrfs_device *device,
425442 struct btrfs_device *this_dev);
426
-int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
427
- const char *device_path,
428
- struct btrfs_device **device);
429
-int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
430
- const char *devpath,
431
- struct btrfs_device **device);
443
+struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
444
+ u64 devid,
445
+ const char *devpath);
432446 struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
433447 const u64 *devid,
434448 const u8 *uuid);
....@@ -446,31 +460,25 @@
446460 int btrfs_balance(struct btrfs_fs_info *fs_info,
447461 struct btrfs_balance_control *bctl,
448462 struct btrfs_ioctl_balance_args *bargs);
463
+void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
449464 int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
450465 int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
451466 int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
452467 int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
453468 int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
454
-int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
469
+int btrfs_uuid_scan_kthread(void *data);
455470 int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset);
456
-int find_free_dev_extent_start(struct btrfs_transaction *transaction,
457
- struct btrfs_device *device, u64 num_bytes,
458
- u64 search_start, u64 *start, u64 *max_avail);
459
-int find_free_dev_extent(struct btrfs_trans_handle *trans,
460
- struct btrfs_device *device, u64 num_bytes,
471
+int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
461472 u64 *start, u64 *max_avail);
462473 void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
463474 int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
464475 struct btrfs_ioctl_get_dev_stats *stats);
465476 void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
466477 int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
467
-int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
468
- struct btrfs_fs_info *fs_info);
478
+int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
469479 void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
470
-void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
471
- struct btrfs_device *srcdev);
480
+void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev);
472481 void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
473
-void btrfs_scratch_superblocks(struct block_device *bdev, const char *device_path);
474482 int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
475483 u64 logical, u64 len);
476484 unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
....@@ -478,6 +486,9 @@
478486 int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
479487 u64 chunk_offset, u64 chunk_size);
480488 int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
489
+struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
490
+ u64 logical, u64 length);
491
+void btrfs_release_disk_super(struct btrfs_super_block *super);
481492
482493 static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
483494 int index)
....@@ -530,12 +541,6 @@
530541 atomic_inc(&dev->dev_stats_ccnt);
531542 }
532543
533
-static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
534
- int index)
535
-{
536
- btrfs_dev_stat_set(dev, index, 0);
537
-}
538
-
539544 /*
540545 * Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
541546 * can be used as index to access btrfs_raid_array[].
....@@ -546,6 +551,10 @@
546551 return BTRFS_RAID_RAID10;
547552 else if (flags & BTRFS_BLOCK_GROUP_RAID1)
548553 return BTRFS_RAID_RAID1;
554
+ else if (flags & BTRFS_BLOCK_GROUP_RAID1C3)
555
+ return BTRFS_RAID_RAID1C3;
556
+ else if (flags & BTRFS_BLOCK_GROUP_RAID1C4)
557
+ return BTRFS_RAID_RAID1C4;
549558 else if (flags & BTRFS_BLOCK_GROUP_DUP)
550559 return BTRFS_RAID_DUP;
551560 else if (flags & BTRFS_BLOCK_GROUP_RAID0)
....@@ -558,18 +567,20 @@
558567 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
559568 }
560569
561
-const char *get_raid_name(enum btrfs_raid_types type);
570
+void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
562571
563
-void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info);
564
-void btrfs_update_commit_device_bytes_used(struct btrfs_transaction *trans);
565
-
566
-struct list_head *btrfs_get_fs_uuids(void);
567
-void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
568
-void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
572
+struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
569573 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
570574 struct btrfs_device *failing_dev);
575
+void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
576
+ struct block_device *bdev,
577
+ const char *device_path);
571578
572579 int btrfs_bg_type_to_factor(u64 flags);
580
+const char *btrfs_bg_type_to_raid_name(u64 flags);
573581 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
574582
583
+bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
584
+u8 *btrfs_sb_fsid_ptr(struct btrfs_super_block *sb);
585
+
575586 #endif