hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/fs/btrfs/ctree.h
....@@ -16,9 +16,9 @@
1616 #include <linux/backing-dev.h>
1717 #include <linux/wait.h>
1818 #include <linux/slab.h>
19
-#include <linux/kobject.h>
2019 #include <trace/events/btrfs.h>
2120 #include <asm/kmap_types.h>
21
+#include <asm/unaligned.h>
2222 #include <linux/pagemap.h>
2323 #include <linux/btrfs.h>
2424 #include <linux/btrfs_tree.h>
....@@ -28,29 +28,39 @@
2828 #include <linux/dynamic_debug.h>
2929 #include <linux/refcount.h>
3030 #include <linux/crc32c.h>
31
+#include "extent-io-tree.h"
3132 #include "extent_io.h"
3233 #include "extent_map.h"
3334 #include "async-thread.h"
35
+#include "block-rsv.h"
36
+#include "locking.h"
3437
3538 struct btrfs_trans_handle;
3639 struct btrfs_transaction;
3740 struct btrfs_pending_snapshot;
41
+struct btrfs_delayed_ref_root;
42
+struct btrfs_space_info;
43
+struct btrfs_block_group;
3844 extern struct kmem_cache *btrfs_trans_handle_cachep;
3945 extern struct kmem_cache *btrfs_bit_radix_cachep;
4046 extern struct kmem_cache *btrfs_path_cachep;
4147 extern struct kmem_cache *btrfs_free_space_cachep;
4248 extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
4349 struct btrfs_ordered_sum;
44
-
45
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
46
-#define STATIC noinline
47
-#else
48
-#define STATIC static noinline
49
-#endif
50
+struct btrfs_ref;
5051
5152 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
5253
53
-#define BTRFS_MAX_MIRRORS 3
54
+/*
55
+ * Maximum number of mirrors that can be available for all profiles counting
56
+ * the target device of dev-replace as one. During an active device replace
57
+ * procedure, the target device of the copy operation is a mirror for the
58
+ * filesystem data as well that can be used to read data in order to repair
59
+ * read errors on other disks.
60
+ *
61
+ * Current value is derived from RAID1C4 with 4 copies.
62
+ */
63
+#define BTRFS_MAX_MIRRORS (4 + 1)
5464
5565 #define BTRFS_MAX_LEVEL 8
5666
....@@ -75,9 +85,6 @@
7585 */
7686 #define BTRFS_LINK_MAX 65535U
7787
78
-/* four bytes for CRC32 */
79
-static const int btrfs_csum_sizes[] = { 4 };
80
-
8188 #define BTRFS_EMPTY_DIR_SIZE 0
8289
8390 /* ioprio of readahead is set to idle */
....@@ -95,6 +102,14 @@
95102
96103 #define BTRFS_MAX_EXTENT_SIZE SZ_128M
97104
105
+/*
106
+ * Deltas are an effective way to populate global statistics. Give macro names
107
+ * to make it clear what we're doing. An example is discard_extents in
108
+ * btrfs_free_space_ctl.
109
+ */
110
+#define BTRFS_STAT_NR_ENTRIES 2
111
+#define BTRFS_STAT_CURR 0
112
+#define BTRFS_STAT_PREV 1
98113
99114 /*
100115 * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
....@@ -104,10 +119,6 @@
104119 return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
105120 }
106121
107
-struct btrfs_mapping_tree {
108
- struct extent_map_tree map_tree;
109
-};
110
-
111122 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
112123 {
113124 BUG_ON(num_stripes == 0);
....@@ -116,13 +127,26 @@
116127 }
117128
118129 /*
119
- * File system states
130
+ * Runtime (in-memory) states of filesystem
120131 */
121
-#define BTRFS_FS_STATE_ERROR 0
122
-#define BTRFS_FS_STATE_REMOUNTING 1
123
-#define BTRFS_FS_STATE_TRANS_ABORTED 2
124
-#define BTRFS_FS_STATE_DEV_REPLACING 3
125
-#define BTRFS_FS_STATE_DUMMY_FS_INFO 4
132
+enum {
133
+ /* Global indicator of serious filesystem errors */
134
+ BTRFS_FS_STATE_ERROR,
135
+ /*
136
+ * Filesystem is being remounted, allow to skip some operations, like
137
+ * defrag
138
+ */
139
+ BTRFS_FS_STATE_REMOUNTING,
140
+ /* Track if a transaction abort has been reported on this filesystem */
141
+ BTRFS_FS_STATE_TRANS_ABORTED,
142
+ /*
143
+ * Bio operations should be blocked on this filesystem because a source
144
+ * or target device is being destroyed as part of a device replace
145
+ */
146
+ BTRFS_FS_STATE_DEV_REPLACING,
147
+ /* The btrfs_fs_info created for self-tests */
148
+ BTRFS_FS_STATE_DUMMY_FS_INFO,
149
+};
126150
127151 #define BTRFS_BACKREF_REV_MAX 256
128152 #define BTRFS_BACKREF_REV_SHIFT 56
....@@ -202,9 +226,10 @@
202226 * it currently lacks any block count etc etc
203227 */
204228 struct btrfs_super_block {
205
- u8 csum[BTRFS_CSUM_SIZE];
206229 /* the first 4 fields must match struct btrfs_header */
207
- u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
230
+ u8 csum[BTRFS_CSUM_SIZE];
231
+ /* FS specific UUID, visible to user */
232
+ u8 fsid[BTRFS_FSID_SIZE];
208233 __le64 bytenr; /* this block number */
209234 __le64 flags;
210235
....@@ -241,8 +266,11 @@
241266 __le64 cache_generation;
242267 __le64 uuid_tree_generation;
243268
269
+ /* the UUID written into btree blocks */
270
+ u8 metadata_uuid[BTRFS_FSID_SIZE];
271
+
244272 /* future expansion */
245
- __le64 reserved[30];
273
+ __le64 reserved[28];
246274 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
247275 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
248276 } __attribute__ ((__packed__));
....@@ -272,7 +300,9 @@
272300 BTRFS_FEATURE_INCOMPAT_RAID56 | \
273301 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
274302 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
275
- BTRFS_FEATURE_INCOMPAT_NO_HOLES)
303
+ BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
304
+ BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
305
+ BTRFS_FEATURE_INCOMPAT_RAID1C34)
276306
277307 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
278308 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
....@@ -323,7 +353,7 @@
323353 * The slots array records the index of the item or block pointer
324354 * used while walking the tree.
325355 */
326
-enum { READA_NONE = 0, READA_BACK, READA_FORWARD };
356
+enum { READA_NONE, READA_BACK, READA_FORWARD };
327357 struct btrfs_path {
328358 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
329359 int slots[BTRFS_MAX_LEVEL];
....@@ -344,6 +374,7 @@
344374 unsigned int search_commit_root:1;
345375 unsigned int need_commit_sem:1;
346376 unsigned int skip_release_on_error:1;
377
+ unsigned int recurse:1;
347378 };
348379 #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
349380 sizeof(struct btrfs_item))
....@@ -367,122 +398,12 @@
367398 struct btrfs_device *tgtdev;
368399
369400 struct mutex lock_finishing_cancel_unmount;
370
- rwlock_t lock;
371
- atomic_t read_locks;
372
- atomic_t blocking_readers;
373
- wait_queue_head_t read_lock_wq;
401
+ struct rw_semaphore rwsem;
374402
375403 struct btrfs_scrub_progress scrub_progress;
376
-};
377404
378
-/* For raid type sysfs entries */
379
-struct raid_kobject {
380
- u64 flags;
381
- struct kobject kobj;
382
- struct list_head list;
383
-};
384
-
385
-struct btrfs_space_info {
386
- spinlock_t lock;
387
-
388
- u64 total_bytes; /* total bytes in the space,
389
- this doesn't take mirrors into account */
390
- u64 bytes_used; /* total bytes used,
391
- this doesn't take mirrors into account */
392
- u64 bytes_pinned; /* total bytes pinned, will be freed when the
393
- transaction finishes */
394
- u64 bytes_reserved; /* total bytes the allocator has reserved for
395
- current allocations */
396
- u64 bytes_may_use; /* number of bytes that may be used for
397
- delalloc/allocations */
398
- u64 bytes_readonly; /* total bytes that are read only */
399
-
400
- u64 max_extent_size; /* This will hold the maximum extent size of
401
- the space info if we had an ENOSPC in the
402
- allocator. */
403
-
404
- unsigned int full:1; /* indicates that we cannot allocate any more
405
- chunks for this space */
406
- unsigned int chunk_alloc:1; /* set if we are allocating a chunk */
407
-
408
- unsigned int flush:1; /* set if we are trying to make space */
409
-
410
- unsigned int force_alloc; /* set if we need to force a chunk
411
- alloc for this space */
412
-
413
- u64 disk_used; /* total bytes used on disk */
414
- u64 disk_total; /* total bytes on disk, takes mirrors into
415
- account */
416
-
417
- u64 flags;
418
-
419
- /*
420
- * bytes_pinned is kept in line with what is actually pinned, as in
421
- * we've called update_block_group and dropped the bytes_used counter
422
- * and increased the bytes_pinned counter. However this means that
423
- * bytes_pinned does not reflect the bytes that will be pinned once the
424
- * delayed refs are flushed, so this counter is inc'ed every time we
425
- * call btrfs_free_extent so it is a realtime count of what will be
426
- * freed once the transaction is committed. It will be zeroed every
427
- * time the transaction commits.
428
- */
429
- struct percpu_counter total_bytes_pinned;
430
-
431
- struct list_head list;
432
- /* Protected by the spinlock 'lock'. */
433
- struct list_head ro_bgs;
434
- struct list_head priority_tickets;
435
- struct list_head tickets;
436
- /*
437
- * tickets_id just indicates the next ticket will be handled, so note
438
- * it's not stored per ticket.
439
- */
440
- u64 tickets_id;
441
-
442
- struct rw_semaphore groups_sem;
443
- /* for block groups in our same type */
444
- struct list_head block_groups[BTRFS_NR_RAID_TYPES];
445
- wait_queue_head_t wait;
446
-
447
- struct kobject kobj;
448
- struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
449
-};
450
-
451
-#define BTRFS_BLOCK_RSV_GLOBAL 1
452
-#define BTRFS_BLOCK_RSV_DELALLOC 2
453
-#define BTRFS_BLOCK_RSV_TRANS 3
454
-#define BTRFS_BLOCK_RSV_CHUNK 4
455
-#define BTRFS_BLOCK_RSV_DELOPS 5
456
-#define BTRFS_BLOCK_RSV_EMPTY 6
457
-#define BTRFS_BLOCK_RSV_TEMP 7
458
-
459
-struct btrfs_block_rsv {
460
- u64 size;
461
- u64 reserved;
462
- struct btrfs_space_info *space_info;
463
- spinlock_t lock;
464
- unsigned short full;
465
- unsigned short type;
466
- unsigned short failfast;
467
-
468
- /*
469
- * Qgroup equivalent for @size @reserved
470
- *
471
- * Unlike normal @size/@reserved for inode rsv, qgroup doesn't care
472
- * about things like csum size nor how many tree blocks it will need to
473
- * reserve.
474
- *
475
- * Qgroup cares more about net change of the extent usage.
476
- *
477
- * So for one newly inserted file extent, in worst case it will cause
478
- * leaf split and level increase, nodesize for each file extent is
479
- * already too much.
480
- *
481
- * In short, qgroup_size/reserved is the upper limit of possible needed
482
- * qgroup metadata reservation.
483
- */
484
- u64 qgroup_rsv_size;
485
- u64 qgroup_rsv_reserved;
405
+ struct percpu_counter bio_counter;
406
+ wait_queue_head_t replace_wait;
486407 };
487408
488409 /*
....@@ -504,7 +425,7 @@
504425 /* We did a full search and couldn't create a cluster */
505426 bool fragmented;
506427
507
- struct btrfs_block_group_cache *block_group;
428
+ struct btrfs_block_group *block_group;
508429 /*
509430 * when a cluster is allocated from a block group, we put the
510431 * cluster onto a list in the block group so that it can
....@@ -514,45 +435,11 @@
514435 };
515436
516437 enum btrfs_caching_type {
517
- BTRFS_CACHE_NO = 0,
518
- BTRFS_CACHE_STARTED = 1,
519
- BTRFS_CACHE_FAST = 2,
520
- BTRFS_CACHE_FINISHED = 3,
521
- BTRFS_CACHE_ERROR = 4,
522
-};
523
-
524
-enum btrfs_disk_cache_state {
525
- BTRFS_DC_WRITTEN = 0,
526
- BTRFS_DC_ERROR = 1,
527
- BTRFS_DC_CLEAR = 2,
528
- BTRFS_DC_SETUP = 3,
529
-};
530
-
531
-struct btrfs_caching_control {
532
- struct list_head list;
533
- struct mutex mutex;
534
- wait_queue_head_t wait;
535
- struct btrfs_work work;
536
- struct btrfs_block_group_cache *block_group;
537
- u64 progress;
538
- refcount_t count;
539
-};
540
-
541
-/* Once caching_thread() finds this much free space, it will wake up waiters. */
542
-#define CACHING_CTL_WAKE_UP SZ_2M
543
-
544
-struct btrfs_io_ctl {
545
- void *cur, *orig;
546
- struct page *page;
547
- struct page **pages;
548
- struct btrfs_fs_info *fs_info;
549
- struct inode *inode;
550
- unsigned long size;
551
- int index;
552
- int num_pages;
553
- int entries;
554
- int bitmaps;
555
- unsigned check_crcs:1;
438
+ BTRFS_CACHE_NO,
439
+ BTRFS_CACHE_STARTED,
440
+ BTRFS_CACHE_FAST,
441
+ BTRFS_CACHE_FINISHED,
442
+ BTRFS_CACHE_ERROR,
556443 };
557444
558445 /*
....@@ -563,118 +450,34 @@
563450 struct mutex lock;
564451 };
565452
566
-struct btrfs_block_group_cache {
567
- struct btrfs_key key;
568
- struct btrfs_block_group_item item;
569
- struct btrfs_fs_info *fs_info;
570
- struct inode *inode;
453
+/* Discard control. */
454
+/*
455
+ * Async discard uses multiple lists to differentiate the discard filter
456
+ * parameters. Index 0 is for completely free block groups where we need to
457
+ * ensure the entire block group is trimmed without being lossy. Indices
458
+ * afterwards represent monotonically decreasing discard filter sizes to
459
+ * prioritize what should be discarded next.
460
+ */
461
+#define BTRFS_NR_DISCARD_LISTS 3
462
+#define BTRFS_DISCARD_INDEX_UNUSED 0
463
+#define BTRFS_DISCARD_INDEX_START 1
464
+
465
+struct btrfs_discard_ctl {
466
+ struct workqueue_struct *discard_workers;
467
+ struct delayed_work work;
571468 spinlock_t lock;
572
- u64 pinned;
573
- u64 reserved;
574
- u64 delalloc_bytes;
575
- u64 bytes_super;
576
- u64 flags;
577
- u64 cache_generation;
578
-
579
- /*
580
- * If the free space extent count exceeds this number, convert the block
581
- * group to bitmaps.
582
- */
583
- u32 bitmap_high_thresh;
584
-
585
- /*
586
- * If the free space extent count drops below this number, convert the
587
- * block group back to extents.
588
- */
589
- u32 bitmap_low_thresh;
590
-
591
- /*
592
- * It is just used for the delayed data space allocation because
593
- * only the data space allocation and the relative metadata update
594
- * can be done cross the transaction.
595
- */
596
- struct rw_semaphore data_rwsem;
597
-
598
- /* for raid56, this is a full stripe, without parity */
599
- unsigned long full_stripe_len;
600
-
601
- unsigned int ro;
602
- unsigned int iref:1;
603
- unsigned int has_caching_ctl:1;
604
- unsigned int removed:1;
605
-
606
- int disk_cache_state;
607
-
608
- /* cache tracking stuff */
609
- int cached;
610
- struct btrfs_caching_control *caching_ctl;
611
- u64 last_byte_to_unpin;
612
-
613
- struct btrfs_space_info *space_info;
614
-
615
- /* free space cache stuff */
616
- struct btrfs_free_space_ctl *free_space_ctl;
617
-
618
- /* block group cache stuff */
619
- struct rb_node cache_node;
620
-
621
- /* for block groups in the same raid type */
622
- struct list_head list;
623
-
624
- /* usage count */
625
- atomic_t count;
626
-
627
- /* List of struct btrfs_free_clusters for this block group.
628
- * Today it will only have one thing on it, but that may change
629
- */
630
- struct list_head cluster_list;
631
-
632
- /* For delayed block group creation or deletion of empty block groups */
633
- struct list_head bg_list;
634
-
635
- /* For read-only block groups */
636
- struct list_head ro_list;
637
-
638
- atomic_t trimming;
639
-
640
- /* For dirty block groups */
641
- struct list_head dirty_list;
642
- struct list_head io_list;
643
-
644
- struct btrfs_io_ctl io_ctl;
645
-
646
- /*
647
- * Incremented when doing extent allocations and holding a read lock
648
- * on the space_info's groups_sem semaphore.
649
- * Decremented when an ordered extent that represents an IO against this
650
- * block group's range is created (after it's added to its inode's
651
- * root's list of ordered extents) or immediately after the allocation
652
- * if it's a metadata extent or fallocate extent (for these cases we
653
- * don't create ordered extents).
654
- */
655
- atomic_t reservations;
656
-
657
- /*
658
- * Incremented while holding the spinlock *lock* by a task checking if
659
- * it can perform a nocow write (incremented if the value for the *ro*
660
- * field is 0). Decremented by such tasks once they create an ordered
661
- * extent or before that if some error happens before reaching that step.
662
- * This is to prevent races between block group relocation and nocow
663
- * writes through direct IO.
664
- */
665
- atomic_t nocow_writers;
666
-
667
- /* Lock for free space tree operations. */
668
- struct mutex free_space_lock;
669
-
670
- /*
671
- * Does the block group need to be added to the free space tree?
672
- * Protected by free_space_lock.
673
- */
674
- int needs_free_space;
675
-
676
- /* Record locked full stripes for RAID5/6 block group */
677
- struct btrfs_full_stripe_locks_tree full_stripe_locks_root;
469
+ struct btrfs_block_group *block_group;
470
+ struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
471
+ u64 prev_discard;
472
+ atomic_t discardable_extents;
473
+ atomic64_t discardable_bytes;
474
+ u64 max_discard_size;
475
+ unsigned long delay;
476
+ u32 iops_limit;
477
+ u32 kbps_limit;
478
+ u64 discard_extent_bytes;
479
+ u64 discard_bitmap_bytes;
480
+ atomic64_t discard_bytes_saved;
678481 };
679482
680483 /* delayed seq elem */
....@@ -692,23 +495,7 @@
692495 ORPHAN_CLEANUP_DONE = 2,
693496 };
694497
695
-/* used by the raid56 code to lock stripes for read/modify/write */
696
-struct btrfs_stripe_hash {
697
- struct list_head hash_list;
698
- spinlock_t lock;
699
-};
700
-
701
-/* used by the raid56 code to lock stripes for read/modify/write */
702
-struct btrfs_stripe_hash_table {
703
- struct list_head stripe_cache;
704
- spinlock_t cache_lock;
705
- int cache_size;
706
- struct btrfs_stripe_hash table[];
707
-};
708
-
709
-#define BTRFS_STRIPE_HASH_TABLE_BITS 11
710
-
711
-void btrfs_init_async_reclaim_work(struct work_struct *work);
498
+void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
712499
713500 /* fs_info */
714501 struct reloc_control;
....@@ -717,41 +504,85 @@
717504 struct btrfs_balance_control;
718505 struct btrfs_delayed_root;
719506
720
-#define BTRFS_FS_BARRIER 1
721
-#define BTRFS_FS_CLOSING_START 2
722
-#define BTRFS_FS_CLOSING_DONE 3
723
-#define BTRFS_FS_LOG_RECOVERING 4
724
-#define BTRFS_FS_OPEN 5
725
-#define BTRFS_FS_QUOTA_ENABLED 6
726
-#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9
727
-#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10
728
-#define BTRFS_FS_BTREE_ERR 11
729
-#define BTRFS_FS_LOG1_ERR 12
730
-#define BTRFS_FS_LOG2_ERR 13
731
-#define BTRFS_FS_QUOTA_OVERRIDE 14
732
-/* Used to record internally whether fs has been frozen */
733
-#define BTRFS_FS_FROZEN 15
507
+/*
508
+ * Block group or device which contains an active swapfile. Used for preventing
509
+ * unsafe operations while a swapfile is active.
510
+ *
511
+ * These are sorted on (ptr, inode) (note that a block group or device can
512
+ * contain more than one swapfile). We compare the pointer values because we
513
+ * don't actually care what the object is, we just need a quick check whether
514
+ * the object exists in the rbtree.
515
+ */
516
+struct btrfs_swapfile_pin {
517
+ struct rb_node node;
518
+ void *ptr;
519
+ struct inode *inode;
520
+ /*
521
+ * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
522
+ * points to a struct btrfs_device.
523
+ */
524
+ bool is_block_group;
525
+ /*
526
+ * Only used when 'is_block_group' is true and it is the number of
527
+ * extents used by a swapfile for this block group ('ptr' field).
528
+ */
529
+ int bg_extent_count;
530
+};
531
+
532
+bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
533
+
534
+enum {
535
+ BTRFS_FS_BARRIER,
536
+ BTRFS_FS_CLOSING_START,
537
+ BTRFS_FS_CLOSING_DONE,
538
+ BTRFS_FS_LOG_RECOVERING,
539
+ BTRFS_FS_OPEN,
540
+ BTRFS_FS_QUOTA_ENABLED,
541
+ BTRFS_FS_UPDATE_UUID_TREE_GEN,
542
+ BTRFS_FS_CREATING_FREE_SPACE_TREE,
543
+ BTRFS_FS_BTREE_ERR,
544
+ BTRFS_FS_LOG1_ERR,
545
+ BTRFS_FS_LOG2_ERR,
546
+ BTRFS_FS_QUOTA_OVERRIDE,
547
+ /* Used to record internally whether fs has been frozen */
548
+ BTRFS_FS_FROZEN,
549
+ /*
550
+ * Indicate that balance has been set up from the ioctl and is in the
551
+ * main phase. The fs_info::balance_ctl is initialized.
552
+ * Set and cleared while holding fs_info::balance_mutex.
553
+ */
554
+ BTRFS_FS_BALANCE_RUNNING,
555
+
556
+ /* Indicate that the cleaner thread is awake and doing something. */
557
+ BTRFS_FS_CLEANER_RUNNING,
558
+
559
+ /*
560
+ * The checksumming has an optimized version and is considered fast,
561
+ * so we don't need to offload checksums to workqueues.
562
+ */
563
+ BTRFS_FS_CSUM_IMPL_FAST,
564
+
565
+ /* Indicate that the discard workqueue can service discards. */
566
+ BTRFS_FS_DISCARD_RUNNING,
567
+
568
+ /* Indicate that we can't trust the free space tree for caching yet */
569
+ BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
570
+};
734571
735572 /*
736
- * Indicate that a whole-filesystem exclusive operation is running
737
- * (device replace, resize, device add/delete, balance)
573
+ * Exclusive operations (device replace, resize, device add/remove, balance)
738574 */
739
-#define BTRFS_FS_EXCL_OP 16
740
-
741
-/*
742
- * To info transaction_kthread we need an immediate commit so it doesn't
743
- * need to wait for commit_interval
744
- */
745
-#define BTRFS_FS_NEED_ASYNC_COMMIT 17
746
-
747
-/*
748
- * Indicate that balance has been set up from the ioctl and is in the main
749
- * phase. The fs_info::balance_ctl is initialized.
750
- */
751
-#define BTRFS_FS_BALANCE_RUNNING 18
575
+enum btrfs_exclusive_operation {
576
+ BTRFS_EXCLOP_NONE,
577
+ BTRFS_EXCLOP_BALANCE,
578
+ BTRFS_EXCLOP_DEV_ADD,
579
+ BTRFS_EXCLOP_DEV_REMOVE,
580
+ BTRFS_EXCLOP_DEV_REPLACE,
581
+ BTRFS_EXCLOP_RESIZE,
582
+ BTRFS_EXCLOP_SWAP_ACTIVATE,
583
+};
752584
753585 struct btrfs_fs_info {
754
- u8 fsid[BTRFS_FSID_SIZE];
755586 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
756587 unsigned long flags;
757588 struct btrfs_root *extent_root;
....@@ -763,6 +594,7 @@
763594 struct btrfs_root *quota_root;
764595 struct btrfs_root *uuid_root;
765596 struct btrfs_root *free_space_root;
597
+ struct btrfs_root *data_reloc_root;
766598
767599 /* the log root tree is a directory of all the other log roots */
768600 struct btrfs_root *log_root_tree;
....@@ -778,11 +610,11 @@
778610 /* keep track of unallocated space */
779611 atomic64_t free_chunk_space;
780612
781
- struct extent_io_tree freed_extents[2];
782
- struct extent_io_tree *pinned_extents;
613
+ /* Track ranges which are used by log trees blocks/logged data extents */
614
+ struct extent_io_tree excluded_extents;
783615
784616 /* logical->physical extent mapping */
785
- struct btrfs_mapping_tree mapping_tree;
617
+ struct extent_map_tree mapping_tree;
786618
787619 /*
788620 * block reservation for extent, checksum, root tree and
....@@ -795,6 +627,8 @@
795627 struct btrfs_block_rsv chunk_block_rsv;
796628 /* block reservation for delayed operations */
797629 struct btrfs_block_rsv delayed_block_rsv;
630
+ /* block reservation for delayed refs */
631
+ struct btrfs_block_rsv delayed_refs_rsv;
798632
799633 struct btrfs_block_rsv empty_block_rsv;
800634
....@@ -876,7 +710,6 @@
876710 struct rw_semaphore cleanup_work_sem;
877711
878712 struct rw_semaphore subvol_sem;
879
- struct srcu_struct subvol_srcu;
880713
881714 spinlock_t trans_lock;
882715 /*
....@@ -891,7 +724,8 @@
891724
892725 spinlock_t delayed_iput_lock;
893726 struct list_head delayed_iputs;
894
- struct mutex cleaner_delayed_iput_mutex;
727
+ atomic_t nr_delayed_iputs;
728
+ wait_queue_head_t delayed_iputs_wait;
895729
896730 atomic64_t tree_mod_seq;
897731
....@@ -937,12 +771,10 @@
937771 struct btrfs_workqueue *endio_workers;
938772 struct btrfs_workqueue *endio_meta_workers;
939773 struct btrfs_workqueue *endio_raid56_workers;
940
- struct btrfs_workqueue *endio_repair_workers;
941774 struct btrfs_workqueue *rmw_workers;
942775 struct btrfs_workqueue *endio_meta_write_workers;
943776 struct btrfs_workqueue *endio_write_workers;
944777 struct btrfs_workqueue *endio_freespace_worker;
945
- struct btrfs_workqueue *submit_workers;
946778 struct btrfs_workqueue *caching_workers;
947779 struct btrfs_workqueue *readahead_workers;
948780
....@@ -954,21 +786,19 @@
954786 struct btrfs_workqueue *fixup_workers;
955787 struct btrfs_workqueue *delayed_workers;
956788
957
- /* the extent workers do delayed refs on the extent allocation tree */
958
- struct btrfs_workqueue *extent_workers;
959789 struct task_struct *transaction_kthread;
960790 struct task_struct *cleaner_kthread;
961791 u32 thread_pool_size;
962792
963793 struct kobject *space_info_kobj;
964
- struct list_head pending_raid_kobjs;
965
- spinlock_t pending_raid_kobjs_lock; /* uncontended */
794
+ struct kobject *qgroups_kobj;
966795
967796 u64 total_pinned;
968797
969798 /* used to keep from writing metadata until there is a nice batch */
970799 struct percpu_counter dirty_metadata_bytes;
971800 struct percpu_counter delalloc_bytes;
801
+ struct percpu_counter dio_bytes;
972802 s32 dirty_metadata_batch;
973803 s32 delalloc_batch;
974804
....@@ -1029,11 +859,16 @@
1029859 atomic_t scrubs_paused;
1030860 atomic_t scrub_cancel_req;
1031861 wait_queue_head_t scrub_pause_wait;
1032
- int scrub_workers_refcnt;
862
+ /*
863
+ * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
864
+ * running.
865
+ */
866
+ refcount_t scrub_workers_refcnt;
1033867 struct btrfs_workqueue *scrub_workers;
1034868 struct btrfs_workqueue *scrub_wr_completion_workers;
1035
- struct btrfs_workqueue *scrub_nocow_workers;
1036869 struct btrfs_workqueue *scrub_parity_workers;
870
+
871
+ struct btrfs_discard_ctl discard_ctl;
1037872
1038873 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
1039874 u32 check_integrity_print_mask;
....@@ -1043,10 +878,7 @@
1043878
1044879 /* holds configuration and tracking. Protected by qgroup_lock */
1045880 struct rb_root qgroup_tree;
1046
- struct rb_root qgroup_op_tree;
1047881 spinlock_t qgroup_lock;
1048
- spinlock_t qgroup_op_lock;
1049
- atomic_t qgroup_op_seq;
1050882
1051883 /*
1052884 * used to avoid frequently calling ulist_alloc()/ulist_free()
....@@ -1054,7 +886,10 @@
1054886 */
1055887 struct ulist *qgroup_ulist;
1056888
1057
- /* protect user change for quota operations */
889
+ /*
890
+ * Protect user change for quota operations. If a transaction is needed,
891
+ * it must be started before locking this lock.
892
+ */
1058893 struct mutex qgroup_ioctl_lock;
1059894
1060895 /* list of dirty qgroups to be written at next commit */
....@@ -1093,36 +928,49 @@
1093928 /* device replace state */
1094929 struct btrfs_dev_replace dev_replace;
1095930
1096
- struct percpu_counter bio_counter;
1097
- wait_queue_head_t replace_wait;
1098
-
1099931 struct semaphore uuid_tree_rescan_sem;
1100932
1101933 /* Used to reclaim the metadata space in the background. */
1102934 struct work_struct async_reclaim_work;
935
+ struct work_struct async_data_reclaim_work;
1103936
1104937 spinlock_t unused_bgs_lock;
1105938 struct list_head unused_bgs;
1106939 struct mutex unused_bg_unpin_mutex;
1107940 struct mutex delete_unused_bgs_mutex;
1108941
1109
- /* For btrfs to record security options */
1110
- struct security_mnt_opts security_opts;
1111
-
1112
- /*
1113
- * Chunks that can't be freed yet (under a trim/discard operation)
1114
- * and will be latter freed. Protected by fs_info->chunk_mutex.
1115
- */
1116
- struct list_head pinned_chunks;
1117
-
1118942 /* Cached block sizes */
1119943 u32 nodesize;
1120944 u32 sectorsize;
1121945 u32 stripesize;
1122946
947
+ /* Block groups and devices containing active swapfiles. */
948
+ spinlock_t swapfile_pins_lock;
949
+ struct rb_root swapfile_pins;
950
+
951
+ struct crypto_shash *csum_shash;
952
+
953
+ /*
954
+ * Number of send operations in progress.
955
+ * Updated while holding fs_info::balance_mutex.
956
+ */
957
+ int send_in_progress;
958
+
959
+ /* Type of exclusive operation running */
960
+ unsigned long exclusive_operation;
961
+
1123962 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
1124963 spinlock_t ref_verify_lock;
1125964 struct rb_root block_tree;
965
+#endif
966
+
967
+#ifdef CONFIG_BTRFS_DEBUG
968
+ struct kobject *debug_kobj;
969
+ struct kobject *discard_debug_kobj;
970
+ struct list_head allocated_roots;
971
+
972
+ spinlock_t eb_leak_lock;
973
+ struct list_head allocated_ebs;
1126974 #endif
1127975 };
1128976
....@@ -1131,30 +979,72 @@
1131979 return sb->s_fs_info;
1132980 }
1133981
1134
-struct btrfs_subvolume_writers {
1135
- struct percpu_counter counter;
1136
- wait_queue_head_t wait;
1137
-};
1138
-
1139982 /*
1140983 * The state of btrfs root
1141984 */
985
+enum {
986
+ /*
987
+ * btrfs_record_root_in_trans is a multi-step process, and it can race
988
+ * with the balancing code. But the race is very small, and only the
989
+ * first time the root is added to each transaction. So IN_TRANS_SETUP
990
+ * is used to tell us when more checks are required
991
+ */
992
+ BTRFS_ROOT_IN_TRANS_SETUP,
993
+
994
+ /*
995
+ * Set if tree blocks of this root can be shared by other roots.
996
+ * Only subvolume trees and their reloc trees have this bit set.
997
+ * Conflicts with TRACK_DIRTY bit.
998
+ *
999
+ * This affects two things:
1000
+ *
1001
+ * - How balance works
1002
+ * For shareable roots, we need to use reloc tree and do path
1003
+ * replacement for balance, and need various pre/post hooks for
1004
+ * snapshot creation to handle them.
1005
+ *
1006
+ * While for non-shareable trees, we just simply do a tree search
1007
+ * with COW.
1008
+ *
1009
+ * - How dirty roots are tracked
1010
+ * For shareable roots, btrfs_record_root_in_trans() is needed to
1011
+ * track them, while non-subvolume roots have TRACK_DIRTY bit, they
1012
+ * don't need to set this manually.
1013
+ */
1014
+ BTRFS_ROOT_SHAREABLE,
1015
+ BTRFS_ROOT_TRACK_DIRTY,
1016
+ BTRFS_ROOT_IN_RADIX,
1017
+ BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
1018
+ BTRFS_ROOT_DEFRAG_RUNNING,
1019
+ BTRFS_ROOT_FORCE_COW,
1020
+ BTRFS_ROOT_MULTI_LOG_TASKS,
1021
+ BTRFS_ROOT_DIRTY,
1022
+ BTRFS_ROOT_DELETING,
1023
+
1024
+ /*
1025
+ * Reloc tree is orphan, only kept here for qgroup delayed subtree scan
1026
+ *
1027
+ * Set for the subvolume tree owning the reloc tree.
1028
+ */
1029
+ BTRFS_ROOT_DEAD_RELOC_TREE,
1030
+ /* Mark dead root stored on device whose cleanup needs to be resumed */
1031
+ BTRFS_ROOT_DEAD_TREE,
1032
+ /* The root has a log tree. Used only for subvolume roots. */
1033
+ BTRFS_ROOT_HAS_LOG_TREE,
1034
+ /* Qgroup flushing is in progress */
1035
+ BTRFS_ROOT_QGROUP_FLUSHING,
1036
+};
1037
+
11421038 /*
1143
- * btrfs_record_root_in_trans is a multi-step process,
1144
- * and it can race with the balancing code. But the
1145
- * race is very small, and only the first time the root
1146
- * is added to each transaction. So IN_TRANS_SETUP
1147
- * is used to tell us when more checks are required
1039
+ * Record swapped tree blocks of a subvolume tree for delayed subtree trace
1040
+ * code. For detail check comment in fs/btrfs/qgroup.c.
11481041 */
1149
-#define BTRFS_ROOT_IN_TRANS_SETUP 0
1150
-#define BTRFS_ROOT_REF_COWS 1
1151
-#define BTRFS_ROOT_TRACK_DIRTY 2
1152
-#define BTRFS_ROOT_IN_RADIX 3
1153
-#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 4
1154
-#define BTRFS_ROOT_DEFRAG_RUNNING 5
1155
-#define BTRFS_ROOT_FORCE_COW 6
1156
-#define BTRFS_ROOT_MULTI_LOG_TASKS 7
1157
-#define BTRFS_ROOT_DIRTY 8
1042
+struct btrfs_qgroup_swapped_blocks {
1043
+ spinlock_t lock;
1044
+ /* RM_EMPTY_ROOT() of above blocks[] */
1045
+ bool swapped;
1046
+ struct rb_root blocks[BTRFS_MAX_LEVEL];
1047
+};
11581048
11591049 /*
11601050 * in ram representation of the tree. extent_root is used for all allocations
....@@ -1191,8 +1081,10 @@
11911081 wait_queue_head_t log_writer_wait;
11921082 wait_queue_head_t log_commit_wait[2];
11931083 struct list_head log_ctxs[2];
1084
+ /* Used only for log trees of subvolumes, not for the log root tree */
11941085 atomic_t log_writers;
11951086 atomic_t log_commit[2];
1087
+ /* Used only for log trees of subvolumes, not for the log root tree */
11961088 atomic_t log_batch;
11971089 int log_transid;
11981090 /* No matter the commit succeeds or not*/
....@@ -1201,23 +1093,16 @@
12011093 int last_log_commit;
12021094 pid_t log_start_pid;
12031095
1204
- u64 objectid;
12051096 u64 last_trans;
12061097
12071098 u32 type;
12081099
12091100 u64 highest_objectid;
12101101
1211
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1212
- /* only used with CONFIG_BTRFS_FS_RUN_SANITY_TESTS is enabled */
1213
- u64 alloc_bytenr;
1214
-#endif
1215
-
1216
- u64 defrag_trans_start;
12171102 struct btrfs_key defrag_progress;
12181103 struct btrfs_key defrag_max;
12191104
1220
- /* the dirty list is only used by non-reference counted roots */
1105
+ /* The dirty list is only used by non-shareable roots */
12211106 struct list_head dirty_list;
12221107
12231108 struct list_head root_list;
....@@ -1273,28 +1158,87 @@
12731158 u64 nr_ordered_extents;
12741159
12751160 /*
1161
+ * Not empty if this subvolume root has gone through tree block swap
1162
+ * (relocation)
1163
+ *
1164
+ * Will be used by reloc_control::dirty_subvol_roots.
1165
+ */
1166
+ struct list_head reloc_dirty_list;
1167
+
1168
+ /*
12761169 * Number of currently running SEND ioctls to prevent
12771170 * manipulation with the read-only status via SUBVOL_SETFLAGS
12781171 */
12791172 int send_in_progress;
1280
- struct btrfs_subvolume_writers *subv_writers;
1281
- atomic_t will_be_snapshotted;
1173
+ /*
1174
+ * Number of currently running deduplication operations that have a
1175
+ * destination inode belonging to this root. Protected by the lock
1176
+ * root_item_lock.
1177
+ */
1178
+ int dedupe_in_progress;
1179
+ /* For exclusion of snapshot creation and nocow writes */
1180
+ struct btrfs_drew_lock snapshot_lock;
1181
+
12821182 atomic_t snapshot_force_cow;
12831183
12841184 /* For qgroup metadata reserved space */
12851185 spinlock_t qgroup_meta_rsv_lock;
12861186 u64 qgroup_meta_rsv_pertrans;
12871187 u64 qgroup_meta_rsv_prealloc;
1188
+ wait_queue_head_t qgroup_flush_wait;
1189
+
1190
+ /* Number of active swapfiles */
1191
+ atomic_t nr_swapfiles;
1192
+
1193
+ /* Record pairs of swapped blocks for qgroup */
1194
+ struct btrfs_qgroup_swapped_blocks swapped_blocks;
1195
+
1196
+ /* Used only by log trees, when logging csum items */
1197
+ struct extent_io_tree log_csum_range;
1198
+
1199
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1200
+ u64 alloc_bytenr;
1201
+#endif
1202
+
1203
+#ifdef CONFIG_BTRFS_DEBUG
1204
+ struct list_head leak_list;
1205
+#endif
1206
+};
1207
+
1208
+/*
1209
+ * Structure that conveys information about an extent that is going to replace
1210
+ * all the extents in a file range.
1211
+ */
1212
+struct btrfs_replace_extent_info {
1213
+ u64 disk_offset;
1214
+ u64 disk_len;
1215
+ u64 data_offset;
1216
+ u64 data_len;
1217
+ u64 file_offset;
1218
+ /* Pointer to a file extent item of type regular or prealloc. */
1219
+ char *extent_buf;
1220
+ /*
1221
+ * Set to true when attempting to replace a file range with a new extent
1222
+ * described by this structure, set to false when attempting to clone an
1223
+ * existing extent into a file range.
1224
+ */
1225
+ bool is_new_extent;
1226
+ /* Meaningful only if is_new_extent is true. */
1227
+ int qgroup_reserved;
1228
+ /*
1229
+ * Meaningful only if is_new_extent is true.
1230
+ * Used to track how many extent items we have already inserted in a
1231
+ * subvolume tree that refer to the extent described by this structure,
1232
+ * so that we know when to create a new delayed ref or update an existing
1233
+ * one.
1234
+ */
1235
+ int insertions;
12881236 };
12891237
12901238 struct btrfs_file_private {
12911239 void *filldir_buf;
12921240 };
12931241
1294
-static inline u32 btrfs_inode_sectorsize(const struct inode *inode)
1295
-{
1296
- return btrfs_sb(inode->i_sb)->sectorsize;
1297
-}
12981242
12991243 static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
13001244 {
....@@ -1342,7 +1286,7 @@
13421286 #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7)
13431287 #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
13441288 #define BTRFS_MOUNT_NOSSD (1 << 9)
1345
-#define BTRFS_MOUNT_DISCARD (1 << 10)
1289
+#define BTRFS_MOUNT_DISCARD_SYNC (1 << 10)
13461290 #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
13471291 #define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
13481292 #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
....@@ -1361,6 +1305,7 @@
13611305 #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)
13621306 #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)
13631307 #define BTRFS_MOUNT_REF_VERIFY (1 << 28)
1308
+#define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29)
13641309
13651310 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
13661311 #define BTRFS_DEFAULT_MAX_INLINE (2048)
....@@ -1372,31 +1317,18 @@
13721317 BTRFS_MOUNT_##opt)
13731318
13741319 #define btrfs_set_and_info(fs_info, opt, fmt, args...) \
1375
-{ \
1320
+do { \
13761321 if (!btrfs_test_opt(fs_info, opt)) \
13771322 btrfs_info(fs_info, fmt, ##args); \
13781323 btrfs_set_opt(fs_info->mount_opt, opt); \
1379
-}
1324
+} while (0)
13801325
13811326 #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \
1382
-{ \
1327
+do { \
13831328 if (btrfs_test_opt(fs_info, opt)) \
13841329 btrfs_info(fs_info, fmt, ##args); \
13851330 btrfs_clear_opt(fs_info->mount_opt, opt); \
1386
-}
1387
-
1388
-#ifdef CONFIG_BTRFS_DEBUG
1389
-static inline int
1390
-btrfs_should_fragment_free_space(struct btrfs_block_group_cache *block_group)
1391
-{
1392
- struct btrfs_fs_info *fs_info = block_group->fs_info;
1393
-
1394
- return (btrfs_test_opt(fs_info, FRAGMENT_METADATA) &&
1395
- block_group->flags & BTRFS_BLOCK_GROUP_METADATA) ||
1396
- (btrfs_test_opt(fs_info, FRAGMENT_DATA) &&
1397
- block_group->flags & BTRFS_BLOCK_GROUP_DATA);
1398
-}
1399
-#endif
1331
+} while (0)
14001332
14011333 /*
14021334 * Requests for changes that need to be done during transaction commit.
....@@ -1475,7 +1407,7 @@
14751407 BTRFS_INODE_ROOT_ITEM_INIT)
14761408
14771409 struct btrfs_map_token {
1478
- const struct extent_buffer *eb;
1410
+ struct extent_buffer *eb;
14791411 char *kaddr;
14801412 unsigned long offset;
14811413 };
....@@ -1483,9 +1415,12 @@
14831415 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
14841416 ((bytes) >> (fs_info)->sb->s_blocksize_bits)
14851417
1486
-static inline void btrfs_init_map_token (struct btrfs_map_token *token)
1418
+static inline void btrfs_init_map_token(struct btrfs_map_token *token,
1419
+ struct extent_buffer *eb)
14871420 {
1488
- token->kaddr = NULL;
1421
+ token->eb = eb;
1422
+ token->kaddr = page_address(eb->pages[0]);
1423
+ token->offset = 0;
14891424 }
14901425
14911426 /* some macros to generate set/get functions for the struct fields. This
....@@ -1495,6 +1430,16 @@
14951430 #define le8_to_cpu(v) (v)
14961431 #define cpu_to_le8(v) (v)
14971432 #define __le8 u8
1433
+
1434
+static inline u8 get_unaligned_le8(const void *p)
1435
+{
1436
+ return *(u8 *)p;
1437
+}
1438
+
1439
+static inline void put_unaligned_le8(u8 val, void *p)
1440
+{
1441
+ *(u8 *)p = val;
1442
+}
14981443
14991444 #define read_eb_member(eb, ptr, type, member, result) (\
15001445 read_extent_buffer(eb, (char *)(result), \
....@@ -1509,23 +1454,15 @@
15091454 sizeof(((type *)0)->member)))
15101455
15111456 #define DECLARE_BTRFS_SETGET_BITS(bits) \
1512
-u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
1513
- const void *ptr, unsigned long off, \
1514
- struct btrfs_map_token *token); \
1515
-void btrfs_set_token_##bits(struct extent_buffer *eb, const void *ptr, \
1516
- unsigned long off, u##bits val, \
1517
- struct btrfs_map_token *token); \
1518
-static inline u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
1519
- const void *ptr, \
1520
- unsigned long off) \
1521
-{ \
1522
- return btrfs_get_token_##bits(eb, ptr, off, NULL); \
1523
-} \
1524
-static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr,\
1525
- unsigned long off, u##bits val) \
1526
-{ \
1527
- btrfs_set_token_##bits(eb, ptr, off, val, NULL); \
1528
-}
1457
+u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
1458
+ const void *ptr, unsigned long off); \
1459
+void btrfs_set_token_##bits(struct btrfs_map_token *token, \
1460
+ const void *ptr, unsigned long off, \
1461
+ u##bits val); \
1462
+u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
1463
+ const void *ptr, unsigned long off); \
1464
+void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
1465
+ unsigned long off, u##bits val);
15291466
15301467 DECLARE_BTRFS_SETGET_BITS(8)
15311468 DECLARE_BTRFS_SETGET_BITS(16)
....@@ -1539,53 +1476,49 @@
15391476 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15401477 return btrfs_get_##bits(eb, s, offsetof(type, member)); \
15411478 } \
1542
-static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \
1479
+static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
15431480 u##bits val) \
15441481 { \
15451482 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15461483 btrfs_set_##bits(eb, s, offsetof(type, member), val); \
15471484 } \
1548
-static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\
1549
- const type *s, \
1550
- struct btrfs_map_token *token) \
1485
+static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
1486
+ const type *s) \
15511487 { \
15521488 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1553
- return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \
1489
+ return btrfs_get_token_##bits(token, s, offsetof(type, member));\
15541490 } \
1555
-static inline void btrfs_set_token_##name(struct extent_buffer *eb, \
1556
- type *s, u##bits val, \
1557
- struct btrfs_map_token *token) \
1491
+static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
1492
+ type *s, u##bits val) \
15581493 { \
15591494 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1560
- btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \
1495
+ btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
15611496 }
15621497
15631498 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
15641499 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
15651500 { \
15661501 const type *p = page_address(eb->pages[0]); \
1567
- u##bits res = le##bits##_to_cpu(p->member); \
1568
- return res; \
1502
+ return get_unaligned_le##bits(&p->member); \
15691503 } \
1570
-static inline void btrfs_set_##name(struct extent_buffer *eb, \
1504
+static inline void btrfs_set_##name(const struct extent_buffer *eb, \
15711505 u##bits val) \
15721506 { \
15731507 type *p = page_address(eb->pages[0]); \
1574
- p->member = cpu_to_le##bits(val); \
1508
+ put_unaligned_le##bits(val, &p->member); \
15751509 }
15761510
15771511 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
15781512 static inline u##bits btrfs_##name(const type *s) \
15791513 { \
1580
- return le##bits##_to_cpu(s->member); \
1514
+ return get_unaligned_le##bits(&s->member); \
15811515 } \
15821516 static inline void btrfs_set_##name(type *s, u##bits val) \
15831517 { \
1584
- s->member = cpu_to_le##bits(val); \
1518
+ put_unaligned_le##bits(val, &s->member); \
15851519 }
15861520
1587
-
1588
-static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb,
1521
+static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
15891522 struct btrfs_dev_item *s)
15901523 {
15911524 BUILD_BUG_ON(sizeof(u64) !=
....@@ -1593,7 +1526,7 @@
15931526 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
15941527 total_bytes));
15951528 }
1596
-static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb,
1529
+static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
15971530 struct btrfs_dev_item *s,
15981531 u64 val)
15991532 {
....@@ -1697,31 +1630,31 @@
16971630 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
16981631 }
16991632
1700
-static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
1633
+static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
17011634 struct btrfs_chunk *c, int nr)
17021635 {
17031636 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
17041637 }
17051638
1706
-static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
1639
+static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
17071640 struct btrfs_chunk *c, int nr)
17081641 {
17091642 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
17101643 }
17111644
17121645 /* struct btrfs_block_group_item */
1713
-BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
1646
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
17141647 used, 64);
1715
-BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
1648
+BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item,
17161649 used, 64);
1717
-BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
1650
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
17181651 struct btrfs_block_group_item, chunk_objectid, 64);
17191652
1720
-BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
1653
+BTRFS_SETGET_FUNCS(block_group_chunk_objectid,
17211654 struct btrfs_block_group_item, chunk_objectid, 64);
1722
-BTRFS_SETGET_FUNCS(disk_block_group_flags,
1655
+BTRFS_SETGET_FUNCS(block_group_flags,
17231656 struct btrfs_block_group_item, flags, 64);
1724
-BTRFS_SETGET_STACK_FUNCS(block_group_flags,
1657
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
17251658 struct btrfs_block_group_item, flags, 64);
17261659
17271660 /* struct btrfs_free_space_info */
....@@ -1783,31 +1716,21 @@
17831716 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
17841717 chunk_offset, 64);
17851718 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
1786
-
1787
-static inline unsigned long btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
1788
-{
1789
- unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
1790
- return (unsigned long)dev + ptr;
1791
-}
1792
-
17931719 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
17941720 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
17951721 generation, 64);
17961722 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
17971723
1798
-BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1799
-
1800
-
18011724 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
18021725
1803
-static inline void btrfs_tree_block_key(struct extent_buffer *eb,
1726
+static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
18041727 struct btrfs_tree_block_info *item,
18051728 struct btrfs_disk_key *key)
18061729 {
18071730 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
18081731 }
18091732
1810
-static inline void btrfs_set_tree_block_key(struct extent_buffer *eb,
1733
+static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
18111734 struct btrfs_tree_block_info *item,
18121735 struct btrfs_disk_key *key)
18131736 {
....@@ -1845,12 +1768,6 @@
18451768 return 0;
18461769 }
18471770
1848
-BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64);
1849
-BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0,
1850
- generation, 64);
1851
-BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64);
1852
-BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32);
1853
-
18541771 /* struct btrfs_node */
18551772 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
18561773 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
....@@ -1859,7 +1776,7 @@
18591776 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
18601777 generation, 64);
18611778
1862
-static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1779
+static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
18631780 {
18641781 unsigned long ptr;
18651782 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1867,7 +1784,7 @@
18671784 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
18681785 }
18691786
1870
-static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1787
+static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
18711788 int nr, u64 val)
18721789 {
18731790 unsigned long ptr;
....@@ -1876,7 +1793,7 @@
18761793 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
18771794 }
18781795
1879
-static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1796
+static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
18801797 {
18811798 unsigned long ptr;
18821799 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1884,7 +1801,7 @@
18841801 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
18851802 }
18861803
1887
-static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1804
+static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
18881805 int nr, u64 val)
18891806 {
18901807 unsigned long ptr;
....@@ -1902,7 +1819,7 @@
19021819 void btrfs_node_key(const struct extent_buffer *eb,
19031820 struct btrfs_disk_key *disk_key, int nr);
19041821
1905
-static inline void btrfs_set_node_key(struct extent_buffer *eb,
1822
+static inline void btrfs_set_node_key(const struct extent_buffer *eb,
19061823 struct btrfs_disk_key *disk_key, int nr)
19071824 {
19081825 unsigned long ptr;
....@@ -2026,6 +1943,52 @@
20261943 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
20271944 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
20281945
1946
+#ifdef __LITTLE_ENDIAN
1947
+
1948
+/*
1949
+ * Optimized helpers for little-endian architectures where CPU and on-disk
1950
+ * structures have the same endianness and we can skip conversions.
1951
+ */
1952
+
1953
+static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
1954
+ const struct btrfs_disk_key *disk_key)
1955
+{
1956
+ memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
1957
+}
1958
+
1959
+static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
1960
+ const struct btrfs_key *cpu_key)
1961
+{
1962
+ memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
1963
+}
1964
+
1965
+static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
1966
+ struct btrfs_key *cpu_key, int nr)
1967
+{
1968
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1969
+
1970
+ btrfs_node_key(eb, disk_key, nr);
1971
+}
1972
+
1973
+static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
1974
+ struct btrfs_key *cpu_key, int nr)
1975
+{
1976
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1977
+
1978
+ btrfs_item_key(eb, disk_key, nr);
1979
+}
1980
+
1981
+static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
1982
+ const struct btrfs_dir_item *item,
1983
+ struct btrfs_key *cpu_key)
1984
+{
1985
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1986
+
1987
+ btrfs_dir_item_key(eb, item, disk_key);
1988
+}
1989
+
1990
+#else
1991
+
20291992 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
20301993 const struct btrfs_disk_key *disk)
20311994 {
....@@ -2067,15 +2030,7 @@
20672030 btrfs_disk_key_to_cpu(key, &disk_key);
20682031 }
20692032
2070
-static inline u8 btrfs_key_type(const struct btrfs_key *key)
2071
-{
2072
- return key->type;
2073
-}
2074
-
2075
-static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
2076
-{
2077
- key->type = val;
2078
-}
2033
+#endif
20792034
20802035 /* struct btrfs_header */
20812036 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
....@@ -2097,18 +2052,16 @@
20972052 return (btrfs_header_flags(eb) & flag) == flag;
20982053 }
20992054
2100
-static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
2055
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
21012056 {
21022057 u64 flags = btrfs_header_flags(eb);
21032058 btrfs_set_header_flags(eb, flags | flag);
2104
- return (flags & flag) == flag;
21052059 }
21062060
2107
-static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
2061
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
21082062 {
21092063 u64 flags = btrfs_header_flags(eb);
21102064 btrfs_set_header_flags(eb, flags & ~flag);
2111
- return (flags & flag) == flag;
21122065 }
21132066
21142067 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
....@@ -2124,16 +2077,6 @@
21242077 flags &= ~BTRFS_BACKREF_REV_MASK;
21252078 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
21262079 btrfs_set_header_flags(eb, flags);
2127
-}
2128
-
2129
-static inline unsigned long btrfs_header_fsid(void)
2130
-{
2131
- return offsetof(struct btrfs_header, fsid);
2132
-}
2133
-
2134
-static inline unsigned long btrfs_header_chunk_tree_uuid(const struct extent_buffer *eb)
2135
-{
2136
- return offsetof(struct btrfs_header, chunk_tree_uuid);
21372080 }
21382081
21392082 static inline int btrfs_is_leaf(const struct extent_buffer *eb)
....@@ -2364,14 +2307,10 @@
23642307 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
23652308 uuid_tree_generation, 64);
23662309
2367
-static inline int btrfs_super_csum_size(const struct btrfs_super_block *s)
2368
-{
2369
- u16 t = btrfs_super_csum_type(s);
2370
- /*
2371
- * csum type is validated at mount time
2372
- */
2373
- return btrfs_csum_sizes[t];
2374
-}
2310
+int btrfs_super_csum_size(const struct btrfs_super_block *s);
2311
+const char *btrfs_super_csum_name(u16 csum_type);
2312
+const char *btrfs_super_csum_driver(u16 csum_type);
2313
+size_t __attribute_const__ btrfs_get_num_csums(void);
23752314
23762315
23772316 /*
....@@ -2379,18 +2318,18 @@
23792318 * this returns the address of the start of the last item,
23802319 * which is the stop of the leaf data stack
23812320 */
2382
-static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info,
2383
- const struct extent_buffer *leaf)
2321
+static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
23842322 {
23852323 u32 nr = btrfs_header_nritems(leaf);
23862324
23872325 if (nr == 0)
2388
- return BTRFS_LEAF_DATA_SIZE(fs_info);
2326
+ return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
23892327 return btrfs_item_offset_nr(leaf, nr - 1);
23902328 }
23912329
23922330 /* struct btrfs_file_extent_item */
2393
-BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
2331
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
2332
+ type, 8);
23942333 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
23952334 struct btrfs_file_extent_item, disk_bytenr, 64);
23962335 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
....@@ -2399,6 +2338,8 @@
23992338 struct btrfs_file_extent_item, generation, 64);
24002339 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
24012340 struct btrfs_file_extent_item, num_bytes, 64);
2341
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
2342
+ struct btrfs_file_extent_item, ram_bytes, 64);
24022343 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
24032344 struct btrfs_file_extent_item, disk_num_bytes, 64);
24042345 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
....@@ -2415,6 +2356,7 @@
24152356 return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
24162357 }
24172358
2359
+BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
24182360 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
24192361 disk_bytenr, 64);
24202362 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
....@@ -2444,30 +2386,6 @@
24442386 struct btrfs_item *e)
24452387 {
24462388 return btrfs_item_size(eb, e) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
2447
-}
2448
-
2449
-/* btrfs_dev_stats_item */
2450
-static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb,
2451
- const struct btrfs_dev_stats_item *ptr,
2452
- int index)
2453
-{
2454
- u64 val;
2455
-
2456
- read_extent_buffer(eb, &val,
2457
- offsetof(struct btrfs_dev_stats_item, values) +
2458
- ((unsigned long)ptr) + (index * sizeof(u64)),
2459
- sizeof(val));
2460
- return val;
2461
-}
2462
-
2463
-static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb,
2464
- struct btrfs_dev_stats_item *ptr,
2465
- int index, u64 val)
2466
-{
2467
- write_extent_buffer(eb, &val,
2468
- offsetof(struct btrfs_dev_stats_item, values) +
2469
- ((unsigned long)ptr) + (index * sizeof(u64)),
2470
- sizeof(val));
24712389 }
24722390
24732391 /* btrfs_qgroup_status_item */
....@@ -2565,6 +2483,16 @@
25652483 ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
25662484 btrfs_item_offset_nr(leaf, slot)))
25672485
2486
+static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
2487
+{
2488
+ return crc32c(crc, address, length);
2489
+}
2490
+
2491
+static inline void btrfs_crc32c_final(u32 crc, u8 *result)
2492
+{
2493
+ put_unaligned_le32(~crc, result);
2494
+}
2495
+
25682496 static inline u64 btrfs_name_hash(const char *name, int len)
25692497 {
25702498 return crc32c((u32)~1, name, len);
....@@ -2579,12 +2507,6 @@
25792507 return (u64) crc32c(parent_objectid, name, len);
25802508 }
25812509
2582
-static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
2583
-{
2584
- return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) &&
2585
- (space_info->flags & BTRFS_BLOCK_GROUP_DATA));
2586
-}
2587
-
25882510 static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
25892511 {
25902512 return mapping_gfp_constraint(mapping, ~__GFP_FS);
....@@ -2593,72 +2515,65 @@
25932515 /* extent-tree.c */
25942516
25952517 enum btrfs_inline_ref_type {
2596
- BTRFS_REF_TYPE_INVALID = 0,
2597
- BTRFS_REF_TYPE_BLOCK = 1,
2598
- BTRFS_REF_TYPE_DATA = 2,
2599
- BTRFS_REF_TYPE_ANY = 3,
2518
+ BTRFS_REF_TYPE_INVALID,
2519
+ BTRFS_REF_TYPE_BLOCK,
2520
+ BTRFS_REF_TYPE_DATA,
2521
+ BTRFS_REF_TYPE_ANY,
26002522 };
26012523
26022524 int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
26032525 struct btrfs_extent_inline_ref *iref,
26042526 enum btrfs_inline_ref_type is_data);
2527
+u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
26052528
26062529 u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes);
26072530
2608
-static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info,
2609
- unsigned num_items)
2531
+/*
2532
+ * Use this if we would be adding new items, as we could split nodes as we cow
2533
+ * down the tree.
2534
+ */
2535
+static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info,
2536
+ unsigned num_items)
26102537 {
26112538 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
26122539 }
26132540
26142541 /*
2615
- * Doing a truncate won't result in new nodes or leaves, just what we need for
2616
- * COW.
2542
+ * Doing a truncate or a modification won't result in new nodes or leaves, just
2543
+ * what we need for COW.
26172544 */
2618
-static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info,
2545
+static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info,
26192546 unsigned num_items)
26202547 {
26212548 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
26222549 }
26232550
2624
-int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
2625
- struct btrfs_fs_info *fs_info);
2626
-int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
2627
- struct btrfs_fs_info *fs_info);
2628
-void btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info,
2629
- const u64 start);
2630
-void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg);
2631
-bool btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr);
2632
-void btrfs_dec_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr);
2633
-void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg);
2634
-void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
2551
+int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info,
2552
+ u64 start, u64 num_bytes);
2553
+void btrfs_free_excluded_extents(struct btrfs_block_group *cache);
26352554 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
26362555 unsigned long count);
2637
-int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
2638
- unsigned long count, u64 transid, int wait);
2556
+void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2557
+ struct btrfs_delayed_ref_root *delayed_refs,
2558
+ struct btrfs_delayed_ref_head *head);
26392559 int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
26402560 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
26412561 struct btrfs_fs_info *fs_info, u64 bytenr,
26422562 u64 offset, int metadata, u64 *refs, u64 *flags);
2643
-int btrfs_pin_extent(struct btrfs_fs_info *fs_info,
2644
- u64 bytenr, u64 num, int reserved);
2645
-int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info,
2563
+int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
2564
+ int reserved);
2565
+int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
26462566 u64 bytenr, u64 num_bytes);
2647
-int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
2648
- struct extent_buffer *eb);
2567
+int btrfs_exclude_logged_extents(struct extent_buffer *eb);
26492568 int btrfs_cross_ref_exist(struct btrfs_root *root,
2650
- u64 objectid, u64 offset, u64 bytenr);
2651
-struct btrfs_block_group_cache *btrfs_lookup_block_group(
2652
- struct btrfs_fs_info *info,
2653
- u64 bytenr);
2654
-void btrfs_get_block_group(struct btrfs_block_group_cache *cache);
2655
-void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
2569
+ u64 objectid, u64 offset, u64 bytenr, bool strict);
26562570 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
26572571 struct btrfs_root *root,
26582572 u64 parent, u64 root_objectid,
26592573 const struct btrfs_disk_key *key,
26602574 int level, u64 hint,
2661
- u64 empty_size);
2575
+ u64 empty_size,
2576
+ enum btrfs_lock_nesting nest);
26622577 void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
26632578 struct btrfs_root *root,
26642579 struct extent_buffer *buf,
....@@ -2678,128 +2593,92 @@
26782593 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
26792594 struct extent_buffer *buf, int full_backref);
26802595 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
2681
- struct btrfs_fs_info *fs_info,
2682
- u64 bytenr, u64 num_bytes, u64 flags,
2596
+ struct extent_buffer *eb, u64 flags,
26832597 int level, int is_data);
2684
-int btrfs_free_extent(struct btrfs_trans_handle *trans,
2685
- struct btrfs_root *root,
2686
- u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid,
2687
- u64 owner, u64 offset);
2598
+int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
26882599
26892600 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
26902601 u64 start, u64 len, int delalloc);
2691
-int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
2692
- u64 start, u64 len);
2693
-void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info);
2602
+int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start,
2603
+ u64 len);
26942604 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
26952605 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
2696
- struct btrfs_root *root,
2697
- u64 bytenr, u64 num_bytes, u64 parent,
2698
- u64 root_objectid, u64 owner, u64 offset);
2606
+ struct btrfs_ref *generic_ref);
26992607
2700
-int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans);
2701
-int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
2702
- struct btrfs_fs_info *fs_info);
2703
-int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
2704
- struct btrfs_fs_info *fs_info);
27052608 int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
2706
-int btrfs_free_block_groups(struct btrfs_fs_info *info);
2707
-int btrfs_read_block_groups(struct btrfs_fs_info *info);
2708
-int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr);
2709
-int btrfs_make_block_group(struct btrfs_trans_handle *trans,
2710
- u64 bytes_used, u64 type, u64 chunk_offset,
2711
- u64 size);
2712
-void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
2713
-struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
2714
- struct btrfs_fs_info *fs_info,
2715
- const u64 chunk_offset);
2716
-int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
2717
- u64 group_start, struct extent_map *em);
2718
-void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info);
2719
-void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache);
2720
-void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *cache);
2721
-void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans);
2722
-u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info);
2723
-u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info);
2724
-u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info);
27252609 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
27262610
2611
+/*
2612
+ * Different levels for to flush space when doing space reservations.
2613
+ *
2614
+ * The higher the level, the more methods we try to reclaim space.
2615
+ */
27272616 enum btrfs_reserve_flush_enum {
27282617 /* If we are in the transaction, we can't flush anything.*/
27292618 BTRFS_RESERVE_NO_FLUSH,
2619
+
27302620 /*
2731
- * Flushing delalloc may cause deadlock somewhere, in this
2732
- * case, use FLUSH LIMIT
2621
+ * Flush space by:
2622
+ * - Running delayed inode items
2623
+ * - Allocating a new chunk
27332624 */
27342625 BTRFS_RESERVE_FLUSH_LIMIT,
2626
+
2627
+ /*
2628
+ * Flush space by:
2629
+ * - Running delayed inode items
2630
+ * - Running delayed refs
2631
+ * - Running delalloc and waiting for ordered extents
2632
+ * - Allocating a new chunk
2633
+ */
2634
+ BTRFS_RESERVE_FLUSH_EVICT,
2635
+
2636
+ /*
2637
+ * Flush space by above mentioned methods and by:
2638
+ * - Running delayed iputs
2639
+ * - Commiting transaction
2640
+ *
2641
+ * Can be interruped by fatal signal.
2642
+ */
2643
+ BTRFS_RESERVE_FLUSH_DATA,
2644
+ BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE,
27352645 BTRFS_RESERVE_FLUSH_ALL,
2646
+
2647
+ /*
2648
+ * Pretty much the same as FLUSH_ALL, but can also steal space from
2649
+ * global rsv.
2650
+ *
2651
+ * Can be interruped by fatal signal.
2652
+ */
2653
+ BTRFS_RESERVE_FLUSH_ALL_STEAL,
27362654 };
27372655
27382656 enum btrfs_flush_state {
27392657 FLUSH_DELAYED_ITEMS_NR = 1,
27402658 FLUSH_DELAYED_ITEMS = 2,
2741
- FLUSH_DELALLOC = 3,
2742
- FLUSH_DELALLOC_WAIT = 4,
2743
- ALLOC_CHUNK = 5,
2744
- COMMIT_TRANS = 6,
2659
+ FLUSH_DELAYED_REFS_NR = 3,
2660
+ FLUSH_DELAYED_REFS = 4,
2661
+ FLUSH_DELALLOC = 5,
2662
+ FLUSH_DELALLOC_WAIT = 6,
2663
+ ALLOC_CHUNK = 7,
2664
+ ALLOC_CHUNK_FORCE = 8,
2665
+ RUN_DELAYED_IPUTS = 9,
2666
+ COMMIT_TRANS = 10,
27452667 };
27462668
2747
-int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes);
2748
-int btrfs_check_data_free_space(struct inode *inode,
2749
- struct extent_changeset **reserved, u64 start, u64 len);
2750
-void btrfs_free_reserved_data_space(struct inode *inode,
2751
- struct extent_changeset *reserved, u64 start, u64 len);
2752
-void btrfs_delalloc_release_space(struct inode *inode,
2753
- struct extent_changeset *reserved,
2754
- u64 start, u64 len, bool qgroup_free);
2755
-void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start,
2756
- u64 len);
2757
-void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans);
27582669 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
27592670 struct btrfs_block_rsv *rsv,
27602671 int nitems, bool use_global_rsv);
2761
-void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
2672
+void btrfs_subvolume_release_metadata(struct btrfs_root *root,
27622673 struct btrfs_block_rsv *rsv);
27632674 void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
27642675
27652676 int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes);
2766
-void btrfs_delalloc_release_metadata(struct btrfs_inode *inode, u64 num_bytes,
2767
- bool qgroup_free);
2768
-int btrfs_delalloc_reserve_space(struct inode *inode,
2769
- struct extent_changeset **reserved, u64 start, u64 len);
2770
-void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type);
2771
-struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info,
2772
- unsigned short type);
2773
-void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
2774
- struct btrfs_block_rsv *rsv,
2775
- unsigned short type);
2776
-void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
2777
- struct btrfs_block_rsv *rsv);
2778
-int btrfs_block_rsv_add(struct btrfs_root *root,
2779
- struct btrfs_block_rsv *block_rsv, u64 num_bytes,
2780
- enum btrfs_reserve_flush_enum flush);
2781
-int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor);
2782
-int btrfs_block_rsv_refill(struct btrfs_root *root,
2783
- struct btrfs_block_rsv *block_rsv, u64 min_reserved,
2784
- enum btrfs_reserve_flush_enum flush);
2785
-int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
2786
- struct btrfs_block_rsv *dst_rsv, u64 num_bytes,
2787
- int update_size);
2788
-int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info,
2789
- struct btrfs_block_rsv *dest, u64 num_bytes,
2790
- int min_factor);
2791
-void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
2792
- struct btrfs_block_rsv *block_rsv,
2793
- u64 num_bytes);
2794
-int btrfs_inc_block_group_ro(struct btrfs_block_group_cache *cache);
2795
-void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache);
2796
-void btrfs_put_block_group_cache(struct btrfs_fs_info *info);
27972677 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
27982678 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
27992679 u64 start, u64 end);
28002680 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
28012681 u64 num_bytes, u64 *actual_bytes);
2802
-int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
28032682 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
28042683
28052684 int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
....@@ -2808,15 +2687,11 @@
28082687 int btrfs_start_write_no_snapshotting(struct btrfs_root *root);
28092688 void btrfs_end_write_no_snapshotting(struct btrfs_root *root);
28102689 void btrfs_wait_for_snapshot_creation(struct btrfs_root *root);
2811
-void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type);
2812
-u64 add_new_free_space(struct btrfs_block_group_cache *block_group,
2813
- u64 start, u64 end);
2814
-void btrfs_mark_bg_unused(struct btrfs_block_group_cache *bg);
28152690
28162691 /* ctree.c */
28172692 int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
2818
- int level, int *slot);
2819
-int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
2693
+ int *slot);
2694
+int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
28202695 int btrfs_previous_item(struct btrfs_root *root,
28212696 struct btrfs_path *path, u64 min_objectid,
28222697 int type);
....@@ -2826,42 +2701,28 @@
28262701 struct btrfs_path *path,
28272702 const struct btrfs_key *new_key);
28282703 struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
2829
-struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
2830
-struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root);
28312704 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
28322705 struct btrfs_key *key, int lowest_level,
28332706 u64 min_trans);
28342707 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
28352708 struct btrfs_path *path,
28362709 u64 min_trans);
2837
-enum btrfs_compare_tree_result {
2838
- BTRFS_COMPARE_TREE_NEW,
2839
- BTRFS_COMPARE_TREE_DELETED,
2840
- BTRFS_COMPARE_TREE_CHANGED,
2841
- BTRFS_COMPARE_TREE_SAME,
2842
-};
2843
-typedef int (*btrfs_changed_cb_t)(struct btrfs_path *left_path,
2844
- struct btrfs_path *right_path,
2845
- struct btrfs_key *key,
2846
- enum btrfs_compare_tree_result result,
2847
- void *ctx);
2848
-int btrfs_compare_trees(struct btrfs_root *left_root,
2849
- struct btrfs_root *right_root,
2850
- btrfs_changed_cb_t cb, void *ctx);
2710
+struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
2711
+ int slot);
2712
+
28512713 int btrfs_cow_block(struct btrfs_trans_handle *trans,
28522714 struct btrfs_root *root, struct extent_buffer *buf,
28532715 struct extent_buffer *parent, int parent_slot,
2854
- struct extent_buffer **cow_ret);
2716
+ struct extent_buffer **cow_ret,
2717
+ enum btrfs_lock_nesting nest);
28552718 int btrfs_copy_root(struct btrfs_trans_handle *trans,
28562719 struct btrfs_root *root,
28572720 struct extent_buffer *buf,
28582721 struct extent_buffer **cow_ret, u64 new_root_objectid);
28592722 int btrfs_block_can_be_shared(struct btrfs_root *root,
28602723 struct extent_buffer *buf);
2861
-void btrfs_extend_item(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
2862
- u32 data_size);
2863
-void btrfs_truncate_item(struct btrfs_fs_info *fs_info,
2864
- struct btrfs_path *path, u32 new_size, int from_end);
2724
+void btrfs_extend_item(struct btrfs_path *path, u32 data_size);
2725
+void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
28652726 int btrfs_split_item(struct btrfs_trans_handle *trans,
28662727 struct btrfs_root *root,
28672728 struct btrfs_path *path,
....@@ -2889,10 +2750,6 @@
28892750 void btrfs_release_path(struct btrfs_path *p);
28902751 struct btrfs_path *btrfs_alloc_path(void);
28912752 void btrfs_free_path(struct btrfs_path *p);
2892
-void btrfs_set_path_blocking(struct btrfs_path *p);
2893
-void btrfs_clear_path_blocking(struct btrfs_path *p,
2894
- struct extent_buffer *held, int held_rw);
2895
-void btrfs_unlock_up_safe(struct btrfs_path *p, int level);
28962753
28972754 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
28982755 struct btrfs_path *path, int slot, int nr);
....@@ -2905,7 +2762,7 @@
29052762
29062763 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
29072764 const struct btrfs_key *cpu_key, u32 *data_size,
2908
- u32 total_data, u32 total_size, int nr);
2765
+ int nr);
29092766 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
29102767 const struct btrfs_key *key, void *data, u32 data_size);
29112768 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
....@@ -2939,11 +2796,9 @@
29392796 {
29402797 return btrfs_next_old_item(root, p, 0);
29412798 }
2942
-int btrfs_leaf_free_space(struct btrfs_fs_info *fs_info,
2943
- struct extent_buffer *leaf);
2944
-int __must_check btrfs_drop_snapshot(struct btrfs_root *root,
2945
- struct btrfs_block_rsv *block_rsv,
2946
- int update_ref, int for_reloc);
2799
+int btrfs_leaf_free_space(struct extent_buffer *leaf);
2800
+int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
2801
+ int for_reloc);
29472802 int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
29482803 struct btrfs_root *root,
29492804 struct extent_buffer *node,
....@@ -2969,24 +2824,6 @@
29692824 static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
29702825 {
29712826 return fs_info->sb->s_flags & SB_RDONLY || btrfs_fs_closing(fs_info);
2972
-}
2973
-
2974
-static inline void free_fs_info(struct btrfs_fs_info *fs_info)
2975
-{
2976
- kfree(fs_info->balance_ctl);
2977
- kfree(fs_info->delayed_root);
2978
- kfree(fs_info->extent_root);
2979
- kfree(fs_info->tree_root);
2980
- kfree(fs_info->chunk_root);
2981
- kfree(fs_info->dev_root);
2982
- kfree(fs_info->csum_root);
2983
- kfree(fs_info->quota_root);
2984
- kfree(fs_info->uuid_root);
2985
- kfree(fs_info->free_space_root);
2986
- kfree(fs_info->super_copy);
2987
- kfree(fs_info->super_for_commit);
2988
- security_free_mnt_opts(&fs_info->security_opts);
2989
- kvfree(fs_info);
29902827 }
29912828
29922829 /* tree mod log functions from ctree.c */
....@@ -3027,15 +2864,12 @@
30272864 u64 subid);
30282865 int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
30292866 u64 subid);
3030
-int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info,
3031
- int (*check_func)(struct btrfs_fs_info *, u8 *, u8,
3032
- u64));
2867
+int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
30332868
30342869 /* dir-item.c */
30352870 int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
30362871 const char *name, int name_len);
3037
-int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
3038
- struct btrfs_root *root, const char *name,
2872
+int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
30392873 int name_len, struct btrfs_inode *dir,
30402874 struct btrfs_key *location, u8 type, u64 index);
30412875 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
....@@ -3103,21 +2937,18 @@
31032937 u64 inode_objectid, u64 ref_objectid, int ins_len,
31042938 int cow);
31052939
3106
-int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
3107
- const char *name,
3108
- int name_len, struct btrfs_inode_ref **ref_ret);
3109
-int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
3110
- u64 ref_objectid, const char *name,
3111
- int name_len,
3112
- struct btrfs_inode_extref **extref_ret);
3113
-
2940
+struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
2941
+ int slot, const char *name,
2942
+ int name_len);
2943
+struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
2944
+ struct extent_buffer *leaf, int slot, u64 ref_objectid,
2945
+ const char *name, int name_len);
31142946 /* file-item.c */
31152947 struct btrfs_dio_private;
31162948 int btrfs_del_csums(struct btrfs_trans_handle *trans,
31172949 struct btrfs_root *root, u64 bytenr, u64 len);
3118
-blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u32 *dst);
3119
-blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio,
3120
- u64 logical_offset);
2950
+blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
2951
+ u64 offset, u8 *dst);
31212952 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
31222953 struct btrfs_root *root,
31232954 u64 objectid, u64 pos,
....@@ -3131,8 +2962,8 @@
31312962 int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
31322963 struct btrfs_root *root,
31332964 struct btrfs_ordered_sum *sums);
3134
-blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
3135
- u64 file_start, int contig);
2965
+blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
2966
+ u64 file_start, int contig);
31362967 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
31372968 struct list_head *list, int search_commit);
31382969 void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
....@@ -3140,14 +2971,23 @@
31402971 struct btrfs_file_extent_item *fi,
31412972 const bool new_inline,
31422973 struct extent_map *em);
2974
+int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
2975
+ u64 len);
2976
+int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start,
2977
+ u64 len);
2978
+void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size);
2979
+u64 btrfs_file_extent_end(const struct btrfs_path *path);
31432980
31442981 /* inode.c */
2982
+blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
2983
+ int mirror_num, unsigned long bio_flags);
2984
+int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
2985
+ struct page *page, u64 start, u64 end, int mirror);
31452986 struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
3146
- struct page *page, size_t pg_offset, u64 start,
3147
- u64 len, int create);
2987
+ u64 start, u64 len);
31482988 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
31492989 u64 *orig_start, u64 *orig_block_len,
3150
- u64 *ram_bytes);
2990
+ u64 *ram_bytes, bool strict);
31512991
31522992 void __btrfs_del_delalloc_inode(struct btrfs_root *root,
31532993 struct btrfs_inode *inode);
....@@ -3169,17 +3009,25 @@
31693009 u32 min_type);
31703010
31713011 int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
3172
-int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr);
3173
-int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
3012
+int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,
3013
+ bool in_reclaim_context);
3014
+int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
31743015 unsigned int extra_bits,
3175
- struct extent_state **cached_state, int dedupe);
3016
+ struct extent_state **cached_state);
31763017 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
31773018 struct btrfs_root *new_root,
31783019 struct btrfs_root *parent_root,
31793020 u64 new_dirid);
3180
-int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
3181
- size_t size, struct bio *bio,
3182
- unsigned long bio_flags);
3021
+ void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
3022
+ unsigned *bits);
3023
+void btrfs_clear_delalloc_extent(struct inode *inode,
3024
+ struct extent_state *state, unsigned *bits);
3025
+void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
3026
+ struct extent_state *other);
3027
+void btrfs_split_delalloc_extent(struct inode *inode,
3028
+ struct extent_state *orig, u64 split);
3029
+int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
3030
+ unsigned long bio_flags);
31833031 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
31843032 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
31853033 int btrfs_readpage(struct file *file, struct page *page);
....@@ -3187,17 +3035,16 @@
31873035 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
31883036 struct inode *btrfs_alloc_inode(struct super_block *sb);
31893037 void btrfs_destroy_inode(struct inode *inode);
3038
+void btrfs_free_inode(struct inode *inode);
31903039 int btrfs_drop_inode(struct inode *inode);
31913040 int __init btrfs_init_cachep(void);
31923041 void __cold btrfs_destroy_cachep(void);
3193
-struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location,
3194
- struct btrfs_root *root, int *new,
3195
- struct btrfs_path *path);
3196
-struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
3197
- struct btrfs_root *root, int *was_new);
3042
+struct inode *btrfs_iget_path(struct super_block *s, u64 ino,
3043
+ struct btrfs_root *root, struct btrfs_path *path);
3044
+struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root);
31983045 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
3199
- struct page *page, size_t pg_offset,
3200
- u64 start, u64 end, int create);
3046
+ struct page *page, size_t pg_offset,
3047
+ u64 start, u64 end);
32013048 int btrfs_update_inode(struct btrfs_trans_handle *trans,
32023049 struct btrfs_root *root,
32033050 struct inode *inode);
....@@ -3209,6 +3056,7 @@
32093056 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
32103057 void btrfs_add_delayed_iput(struct inode *inode);
32113058 void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
3059
+int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
32123060 int btrfs_prealloc_file_range(struct inode *inode, int mode,
32133061 u64 start, u64 num_bytes, u64 min_size,
32143062 loff_t actual_len, u64 *alloc_hint);
....@@ -3216,20 +3064,21 @@
32163064 struct btrfs_trans_handle *trans, int mode,
32173065 u64 start, u64 num_bytes, u64 min_size,
32183066 loff_t actual_len, u64 *alloc_hint);
3219
-int btrfs_run_delalloc_range(void *private_data, struct page *locked_page,
3067
+int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page,
32203068 u64 start, u64 end, int *page_started, unsigned long *nr_written,
32213069 struct writeback_control *wbc);
3070
+int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
3071
+void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
3072
+ u64 end, int uptodate);
32223073 extern const struct dentry_operations btrfs_dentry_operations;
3223
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3224
-void btrfs_test_inode_set_ops(struct inode *inode);
3225
-#endif
3074
+ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
32263075
32273076 /* ioctl.c */
32283077 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32293078 long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32303079 int btrfs_ioctl_get_supported_features(void __user *arg);
32313080 void btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
3232
-int btrfs_is_empty_uuid(u8 *uuid);
3081
+int __pure btrfs_is_empty_uuid(u8 *uuid);
32333082 int btrfs_defrag_file(struct inode *inode, struct file *file,
32343083 struct btrfs_ioctl_defrag_range_args *range,
32353084 u64 newer_than, unsigned long max_pages);
....@@ -3237,9 +3086,9 @@
32373086 struct btrfs_ioctl_space_info *space);
32383087 void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
32393088 struct btrfs_ioctl_balance_args *bargs);
3240
-int btrfs_dedupe_file_range(struct file *src_file, loff_t src_loff,
3241
- struct file *dst_file, loff_t dst_loff,
3242
- u64 olen);
3089
+bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
3090
+ enum btrfs_exclusive_operation type);
3091
+void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
32433092
32443093 /* file.c */
32453094 int __init btrfs_auto_defrag_init(void);
....@@ -3253,7 +3102,7 @@
32533102 int skip_pinned);
32543103 extern const struct file_operations btrfs_file_operations;
32553104 int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
3256
- struct btrfs_root *root, struct inode *inode,
3105
+ struct btrfs_root *root, struct btrfs_inode *inode,
32573106 struct btrfs_path *path, u64 start, u64 end,
32583107 u64 *drop_end, int drop_cache,
32593108 int replace_extent,
....@@ -3262,25 +3111,24 @@
32623111 int btrfs_drop_extents(struct btrfs_trans_handle *trans,
32633112 struct btrfs_root *root, struct inode *inode, u64 start,
32643113 u64 end, int drop_cache);
3114
+int btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path,
3115
+ const u64 start, const u64 end,
3116
+ struct btrfs_replace_extent_info *extent_info,
3117
+ struct btrfs_trans_handle **trans_out);
32653118 int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
32663119 struct btrfs_inode *inode, u64 start, u64 end);
32673120 int btrfs_release_file(struct inode *inode, struct file *file);
3268
-int btrfs_dirty_pages(struct inode *inode, struct page **pages,
3121
+int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
32693122 size_t num_pages, loff_t pos, size_t write_bytes,
32703123 struct extent_state **cached);
32713124 int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
3272
-int btrfs_clone_file_range(struct file *file_in, loff_t pos_in,
3273
- struct file *file_out, loff_t pos_out, u64 len);
3125
+int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
3126
+ size_t *write_bytes);
3127
+void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
32743128
32753129 /* tree-defrag.c */
32763130 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
32773131 struct btrfs_root *root);
3278
-
3279
-/* sysfs.c */
3280
-int __init btrfs_init_sysfs(void);
3281
-void __cold btrfs_exit_sysfs(void);
3282
-int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
3283
-void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
32843132
32853133 /* super.c */
32863134 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
....@@ -3374,31 +3222,17 @@
33743222
33753223 #if defined(CONFIG_DYNAMIC_DEBUG)
33763224 #define btrfs_debug(fs_info, fmt, args...) \
3377
-do { \
3378
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
3379
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
3380
- btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \
3381
-} while (0)
3382
-#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3383
-do { \
3384
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
3385
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
3386
- btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \
3387
-} while (0)
3225
+ _dynamic_func_call_no_desc(fmt, btrfs_printk, \
3226
+ fs_info, KERN_DEBUG fmt, ##args)
3227
+#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3228
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
3229
+ fs_info, KERN_DEBUG fmt, ##args)
33883230 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
3389
-do { \
3390
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
3391
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
3392
- btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \
3393
- ##args);\
3394
-} while (0)
3395
-#define btrfs_debug_rl(fs_info, fmt, args...) \
3396
-do { \
3397
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
3398
- if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
3399
- btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \
3400
- ##args); \
3401
-} while (0)
3231
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
3232
+ fs_info, KERN_DEBUG fmt, ##args)
3233
+#define btrfs_debug_rl(fs_info, fmt, args...) \
3234
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
3235
+ fs_info, KERN_DEBUG fmt, ##args)
34023236 #elif defined(DEBUG)
34033237 #define btrfs_debug(fs_info, fmt, args...) \
34043238 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
....@@ -3450,19 +3284,29 @@
34503284 } while (0)
34513285
34523286 #ifdef CONFIG_BTRFS_ASSERT
3453
-
3454
-__cold
3455
-static inline void assfail(const char *expr, const char *file, int line)
3287
+__cold __noreturn
3288
+static inline void assertfail(const char *expr, const char *file, int line)
34563289 {
3457
- pr_err("assertion failed: %s, file: %s, line: %d\n",
3458
- expr, file, line);
3290
+ pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
34593291 BUG();
34603292 }
34613293
3462
-#define ASSERT(expr) \
3463
- (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
3294
+#define ASSERT(expr) \
3295
+ (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
3296
+
34643297 #else
3465
-#define ASSERT(expr) ((void)0)
3298
+static inline void assertfail(const char *expr, const char* file, int line) { }
3299
+#define ASSERT(expr) (void)(expr)
3300
+#endif
3301
+
3302
+/*
3303
+ * Use that for functions that are conditionally exported for sanity tests but
3304
+ * otherwise static
3305
+ */
3306
+#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3307
+#define EXPORT_FOR_TESTS static
3308
+#else
3309
+#define EXPORT_FOR_TESTS
34663310 #endif
34673311
34683312 __cold
....@@ -3477,7 +3321,7 @@
34773321 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
34783322 unsigned int line, int errno, const char *fmt, ...);
34793323
3480
-const char *btrfs_decode_error(int errno);
3324
+const char * __attribute_const__ btrfs_decode_error(int errno);
34813325
34823326 __cold
34833327 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
....@@ -3493,7 +3337,7 @@
34933337 /* Report first abort since mount */ \
34943338 if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \
34953339 &((trans)->fs_info->fs_state))) { \
3496
- if ((errno) != -EIO) { \
3340
+ if ((errno) != -EIO && (errno) != -EROFS) { \
34973341 WARN(1, KERN_DEBUG \
34983342 "BTRFS: Transaction aborted (error %d)\n", \
34993343 (errno)); \
....@@ -3531,10 +3375,11 @@
35313375 /* compatibility and incompatibility defines */
35323376
35333377 #define btrfs_set_fs_incompat(__fs_info, opt) \
3534
- __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3378
+ __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3379
+ #opt)
35353380
35363381 static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
3537
- u64 flag)
3382
+ u64 flag, const char* name)
35383383 {
35393384 struct btrfs_super_block *disk_super;
35403385 u64 features;
....@@ -3547,18 +3392,20 @@
35473392 if (!(features & flag)) {
35483393 features |= flag;
35493394 btrfs_set_super_incompat_flags(disk_super, features);
3550
- btrfs_info(fs_info, "setting %llu feature flag",
3551
- flag);
3395
+ btrfs_info(fs_info,
3396
+ "setting incompat feature flag for %s (0x%llx)",
3397
+ name, flag);
35523398 }
35533399 spin_unlock(&fs_info->super_lock);
35543400 }
35553401 }
35563402
35573403 #define btrfs_clear_fs_incompat(__fs_info, opt) \
3558
- __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3404
+ __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3405
+ #opt)
35593406
35603407 static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
3561
- u64 flag)
3408
+ u64 flag, const char* name)
35623409 {
35633410 struct btrfs_super_block *disk_super;
35643411 u64 features;
....@@ -3571,8 +3418,9 @@
35713418 if (features & flag) {
35723419 features &= ~flag;
35733420 btrfs_set_super_incompat_flags(disk_super, features);
3574
- btrfs_info(fs_info, "clearing %llu feature flag",
3575
- flag);
3421
+ btrfs_info(fs_info,
3422
+ "clearing incompat feature flag for %s (0x%llx)",
3423
+ name, flag);
35763424 }
35773425 spin_unlock(&fs_info->super_lock);
35783426 }
....@@ -3589,10 +3437,11 @@
35893437 }
35903438
35913439 #define btrfs_set_fs_compat_ro(__fs_info, opt) \
3592
- __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3440
+ __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3441
+ #opt)
35933442
35943443 static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info,
3595
- u64 flag)
3444
+ u64 flag, const char *name)
35963445 {
35973446 struct btrfs_super_block *disk_super;
35983447 u64 features;
....@@ -3605,18 +3454,20 @@
36053454 if (!(features & flag)) {
36063455 features |= flag;
36073456 btrfs_set_super_compat_ro_flags(disk_super, features);
3608
- btrfs_info(fs_info, "setting %llu ro feature flag",
3609
- flag);
3457
+ btrfs_info(fs_info,
3458
+ "setting compat-ro feature flag for %s (0x%llx)",
3459
+ name, flag);
36103460 }
36113461 spin_unlock(&fs_info->super_lock);
36123462 }
36133463 }
36143464
36153465 #define btrfs_clear_fs_compat_ro(__fs_info, opt) \
3616
- __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3466
+ __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3467
+ #opt)
36173468
36183469 static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
3619
- u64 flag)
3470
+ u64 flag, const char *name)
36203471 {
36213472 struct btrfs_super_block *disk_super;
36223473 u64 features;
....@@ -3629,8 +3480,9 @@
36293480 if (features & flag) {
36303481 features &= ~flag;
36313482 btrfs_set_super_compat_ro_flags(disk_super, features);
3632
- btrfs_info(fs_info, "clearing %llu ro feature flag",
3633
- flag);
3483
+ btrfs_info(fs_info,
3484
+ "clearing compat-ro feature flag for %s (0x%llx)",
3485
+ name, flag);
36343486 }
36353487 spin_unlock(&fs_info->super_lock);
36363488 }
....@@ -3669,7 +3521,7 @@
36693521 int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
36703522 struct btrfs_root *root);
36713523 int btrfs_recover_relocation(struct btrfs_root *root);
3672
-int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
3524
+int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len);
36733525 int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
36743526 struct btrfs_root *root, struct extent_buffer *buf,
36753527 struct extent_buffer *cow);
....@@ -3677,6 +3529,10 @@
36773529 u64 *bytes_to_reserve);
36783530 int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
36793531 struct btrfs_pending_snapshot *pending);
3532
+int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info);
3533
+struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info,
3534
+ u64 bytenr);
3535
+int btrfs_should_ignore_reloc_root(struct btrfs_root *root);
36803536
36813537 /* scrub.c */
36823538 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
....@@ -3685,8 +3541,7 @@
36853541 void btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
36863542 void btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
36873543 int btrfs_scrub_cancel(struct btrfs_fs_info *info);
3688
-int btrfs_scrub_cancel_dev(struct btrfs_fs_info *info,
3689
- struct btrfs_device *dev);
3544
+int btrfs_scrub_cancel_dev(struct btrfs_device *dev);
36903545 int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
36913546 struct btrfs_scrub_progress *progress);
36923547 static inline void btrfs_init_full_stripe_locks_tree(
....@@ -3720,6 +3575,8 @@
37203575 int btrfs_reada_wait(void *handle);
37213576 void btrfs_reada_detach(void *handle);
37223577 int btree_readahead_hook(struct extent_buffer *eb, int err);
3578
+void btrfs_reada_remove_dev(struct btrfs_device *dev);
3579
+void btrfs_reada_undo_remove_dev(struct btrfs_device *dev);
37233580
37243581 static inline int is_fstree(u64 rootid)
37253582 {
....@@ -3735,41 +3592,20 @@
37353592 return signal_pending(current);
37363593 }
37373594
3595
+#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
3596
+
37383597 /* Sanity test specific functions */
37393598 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
37403599 void btrfs_test_destroy_inode(struct inode *inode);
3741
-#endif
3742
-
37433600 static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
37443601 {
3745
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3746
- if (unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
3747
- &fs_info->fs_state)))
3748
- return 1;
3749
-#endif
3602
+ return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
3603
+}
3604
+#else
3605
+static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
3606
+{
37503607 return 0;
37513608 }
3752
-
3753
-static inline void cond_wake_up(struct wait_queue_head *wq)
3754
-{
3755
- /*
3756
- * This implies a full smp_mb barrier, see comments for
3757
- * waitqueue_active why.
3758
- */
3759
- if (wq_has_sleeper(wq))
3760
- wake_up(wq);
3761
-}
3762
-
3763
-static inline void cond_wake_up_nomb(struct wait_queue_head *wq)
3764
-{
3765
- /*
3766
- * Special case for conditional wakeup where the barrier required for
3767
- * waitqueue_active is implied by some of the preceding code. Eg. one
3768
- * of such atomic operations (atomic_dec_and_return, ...), or a
3769
- * unlock/lock sequence, etc.
3770
- */
3771
- if (waitqueue_active(wq))
3772
- wake_up(wq);
3773
-}
3609
+#endif
37743610
37753611 #endif