forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/fs/btrfs/ctree.h
....@@ -16,9 +16,8 @@
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>
21
-#include <asm/kmap_types.h>
20
+#include <asm/unaligned.h>
2221 #include <linux/pagemap.h>
2322 #include <linux/btrfs.h>
2423 #include <linux/btrfs_tree.h>
....@@ -28,29 +27,39 @@
2827 #include <linux/dynamic_debug.h>
2928 #include <linux/refcount.h>
3029 #include <linux/crc32c.h>
30
+#include "extent-io-tree.h"
3131 #include "extent_io.h"
3232 #include "extent_map.h"
3333 #include "async-thread.h"
34
+#include "block-rsv.h"
35
+#include "locking.h"
3436
3537 struct btrfs_trans_handle;
3638 struct btrfs_transaction;
3739 struct btrfs_pending_snapshot;
40
+struct btrfs_delayed_ref_root;
41
+struct btrfs_space_info;
42
+struct btrfs_block_group;
3843 extern struct kmem_cache *btrfs_trans_handle_cachep;
3944 extern struct kmem_cache *btrfs_bit_radix_cachep;
4045 extern struct kmem_cache *btrfs_path_cachep;
4146 extern struct kmem_cache *btrfs_free_space_cachep;
4247 extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
4348 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
49
+struct btrfs_ref;
5050
5151 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
5252
53
-#define BTRFS_MAX_MIRRORS 3
53
+/*
54
+ * Maximum number of mirrors that can be available for all profiles counting
55
+ * the target device of dev-replace as one. During an active device replace
56
+ * procedure, the target device of the copy operation is a mirror for the
57
+ * filesystem data as well that can be used to read data in order to repair
58
+ * read errors on other disks.
59
+ *
60
+ * Current value is derived from RAID1C4 with 4 copies.
61
+ */
62
+#define BTRFS_MAX_MIRRORS (4 + 1)
5463
5564 #define BTRFS_MAX_LEVEL 8
5665
....@@ -75,9 +84,6 @@
7584 */
7685 #define BTRFS_LINK_MAX 65535U
7786
78
-/* four bytes for CRC32 */
79
-static const int btrfs_csum_sizes[] = { 4 };
80
-
8187 #define BTRFS_EMPTY_DIR_SIZE 0
8288
8389 /* ioprio of readahead is set to idle */
....@@ -95,6 +101,14 @@
95101
96102 #define BTRFS_MAX_EXTENT_SIZE SZ_128M
97103
104
+/*
105
+ * Deltas are an effective way to populate global statistics. Give macro names
106
+ * to make it clear what we're doing. An example is discard_extents in
107
+ * btrfs_free_space_ctl.
108
+ */
109
+#define BTRFS_STAT_NR_ENTRIES 2
110
+#define BTRFS_STAT_CURR 0
111
+#define BTRFS_STAT_PREV 1
98112
99113 /*
100114 * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
....@@ -104,10 +118,6 @@
104118 return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
105119 }
106120
107
-struct btrfs_mapping_tree {
108
- struct extent_map_tree map_tree;
109
-};
110
-
111121 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
112122 {
113123 BUG_ON(num_stripes == 0);
....@@ -116,13 +126,26 @@
116126 }
117127
118128 /*
119
- * File system states
129
+ * Runtime (in-memory) states of filesystem
120130 */
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
131
+enum {
132
+ /* Global indicator of serious filesystem errors */
133
+ BTRFS_FS_STATE_ERROR,
134
+ /*
135
+ * Filesystem is being remounted, allow to skip some operations, like
136
+ * defrag
137
+ */
138
+ BTRFS_FS_STATE_REMOUNTING,
139
+ /* Track if a transaction abort has been reported on this filesystem */
140
+ BTRFS_FS_STATE_TRANS_ABORTED,
141
+ /*
142
+ * Bio operations should be blocked on this filesystem because a source
143
+ * or target device is being destroyed as part of a device replace
144
+ */
145
+ BTRFS_FS_STATE_DEV_REPLACING,
146
+ /* The btrfs_fs_info created for self-tests */
147
+ BTRFS_FS_STATE_DUMMY_FS_INFO,
148
+};
126149
127150 #define BTRFS_BACKREF_REV_MAX 256
128151 #define BTRFS_BACKREF_REV_SHIFT 56
....@@ -202,9 +225,10 @@
202225 * it currently lacks any block count etc etc
203226 */
204227 struct btrfs_super_block {
205
- u8 csum[BTRFS_CSUM_SIZE];
206228 /* the first 4 fields must match struct btrfs_header */
207
- u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
229
+ u8 csum[BTRFS_CSUM_SIZE];
230
+ /* FS specific UUID, visible to user */
231
+ u8 fsid[BTRFS_FSID_SIZE];
208232 __le64 bytenr; /* this block number */
209233 __le64 flags;
210234
....@@ -241,8 +265,11 @@
241265 __le64 cache_generation;
242266 __le64 uuid_tree_generation;
243267
268
+ /* the UUID written into btree blocks */
269
+ u8 metadata_uuid[BTRFS_FSID_SIZE];
270
+
244271 /* future expansion */
245
- __le64 reserved[30];
272
+ __le64 reserved[28];
246273 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
247274 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
248275 } __attribute__ ((__packed__));
....@@ -272,7 +299,9 @@
272299 BTRFS_FEATURE_INCOMPAT_RAID56 | \
273300 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
274301 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
275
- BTRFS_FEATURE_INCOMPAT_NO_HOLES)
302
+ BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
303
+ BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
304
+ BTRFS_FEATURE_INCOMPAT_RAID1C34)
276305
277306 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
278307 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
....@@ -323,7 +352,7 @@
323352 * The slots array records the index of the item or block pointer
324353 * used while walking the tree.
325354 */
326
-enum { READA_NONE = 0, READA_BACK, READA_FORWARD };
355
+enum { READA_NONE, READA_BACK, READA_FORWARD };
327356 struct btrfs_path {
328357 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
329358 int slots[BTRFS_MAX_LEVEL];
....@@ -344,6 +373,7 @@
344373 unsigned int search_commit_root:1;
345374 unsigned int need_commit_sem:1;
346375 unsigned int skip_release_on_error:1;
376
+ unsigned int recurse:1;
347377 };
348378 #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
349379 sizeof(struct btrfs_item))
....@@ -367,122 +397,12 @@
367397 struct btrfs_device *tgtdev;
368398
369399 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;
400
+ struct rw_semaphore rwsem;
374401
375402 struct btrfs_scrub_progress scrub_progress;
376
-};
377403
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;
404
+ struct percpu_counter bio_counter;
405
+ wait_queue_head_t replace_wait;
486406 };
487407
488408 /*
....@@ -504,7 +424,7 @@
504424 /* We did a full search and couldn't create a cluster */
505425 bool fragmented;
506426
507
- struct btrfs_block_group_cache *block_group;
427
+ struct btrfs_block_group *block_group;
508428 /*
509429 * when a cluster is allocated from a block group, we put the
510430 * cluster onto a list in the block group so that it can
....@@ -514,45 +434,11 @@
514434 };
515435
516436 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;
437
+ BTRFS_CACHE_NO,
438
+ BTRFS_CACHE_STARTED,
439
+ BTRFS_CACHE_FAST,
440
+ BTRFS_CACHE_FINISHED,
441
+ BTRFS_CACHE_ERROR,
556442 };
557443
558444 /*
....@@ -563,118 +449,34 @@
563449 struct mutex lock;
564450 };
565451
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;
452
+/* Discard control. */
453
+/*
454
+ * Async discard uses multiple lists to differentiate the discard filter
455
+ * parameters. Index 0 is for completely free block groups where we need to
456
+ * ensure the entire block group is trimmed without being lossy. Indices
457
+ * afterwards represent monotonically decreasing discard filter sizes to
458
+ * prioritize what should be discarded next.
459
+ */
460
+#define BTRFS_NR_DISCARD_LISTS 3
461
+#define BTRFS_DISCARD_INDEX_UNUSED 0
462
+#define BTRFS_DISCARD_INDEX_START 1
463
+
464
+struct btrfs_discard_ctl {
465
+ struct workqueue_struct *discard_workers;
466
+ struct delayed_work work;
571467 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;
468
+ struct btrfs_block_group *block_group;
469
+ struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
470
+ u64 prev_discard;
471
+ atomic_t discardable_extents;
472
+ atomic64_t discardable_bytes;
473
+ u64 max_discard_size;
474
+ unsigned long delay;
475
+ u32 iops_limit;
476
+ u32 kbps_limit;
477
+ u64 discard_extent_bytes;
478
+ u64 discard_bitmap_bytes;
479
+ atomic64_t discard_bytes_saved;
678480 };
679481
680482 /* delayed seq elem */
....@@ -692,23 +494,7 @@
692494 ORPHAN_CLEANUP_DONE = 2,
693495 };
694496
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);
497
+void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
712498
713499 /* fs_info */
714500 struct reloc_control;
....@@ -717,41 +503,85 @@
717503 struct btrfs_balance_control;
718504 struct btrfs_delayed_root;
719505
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
506
+/*
507
+ * Block group or device which contains an active swapfile. Used for preventing
508
+ * unsafe operations while a swapfile is active.
509
+ *
510
+ * These are sorted on (ptr, inode) (note that a block group or device can
511
+ * contain more than one swapfile). We compare the pointer values because we
512
+ * don't actually care what the object is, we just need a quick check whether
513
+ * the object exists in the rbtree.
514
+ */
515
+struct btrfs_swapfile_pin {
516
+ struct rb_node node;
517
+ void *ptr;
518
+ struct inode *inode;
519
+ /*
520
+ * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
521
+ * points to a struct btrfs_device.
522
+ */
523
+ bool is_block_group;
524
+ /*
525
+ * Only used when 'is_block_group' is true and it is the number of
526
+ * extents used by a swapfile for this block group ('ptr' field).
527
+ */
528
+ int bg_extent_count;
529
+};
530
+
531
+bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
532
+
533
+enum {
534
+ BTRFS_FS_BARRIER,
535
+ BTRFS_FS_CLOSING_START,
536
+ BTRFS_FS_CLOSING_DONE,
537
+ BTRFS_FS_LOG_RECOVERING,
538
+ BTRFS_FS_OPEN,
539
+ BTRFS_FS_QUOTA_ENABLED,
540
+ BTRFS_FS_UPDATE_UUID_TREE_GEN,
541
+ BTRFS_FS_CREATING_FREE_SPACE_TREE,
542
+ BTRFS_FS_BTREE_ERR,
543
+ BTRFS_FS_LOG1_ERR,
544
+ BTRFS_FS_LOG2_ERR,
545
+ BTRFS_FS_QUOTA_OVERRIDE,
546
+ /* Used to record internally whether fs has been frozen */
547
+ BTRFS_FS_FROZEN,
548
+ /*
549
+ * Indicate that balance has been set up from the ioctl and is in the
550
+ * main phase. The fs_info::balance_ctl is initialized.
551
+ * Set and cleared while holding fs_info::balance_mutex.
552
+ */
553
+ BTRFS_FS_BALANCE_RUNNING,
554
+
555
+ /* Indicate that the cleaner thread is awake and doing something. */
556
+ BTRFS_FS_CLEANER_RUNNING,
557
+
558
+ /*
559
+ * The checksumming has an optimized version and is considered fast,
560
+ * so we don't need to offload checksums to workqueues.
561
+ */
562
+ BTRFS_FS_CSUM_IMPL_FAST,
563
+
564
+ /* Indicate that the discard workqueue can service discards. */
565
+ BTRFS_FS_DISCARD_RUNNING,
566
+
567
+ /* Indicate that we can't trust the free space tree for caching yet */
568
+ BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
569
+};
734570
735571 /*
736
- * Indicate that a whole-filesystem exclusive operation is running
737
- * (device replace, resize, device add/delete, balance)
572
+ * Exclusive operations (device replace, resize, device add/remove, balance)
738573 */
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
574
+enum btrfs_exclusive_operation {
575
+ BTRFS_EXCLOP_NONE,
576
+ BTRFS_EXCLOP_BALANCE,
577
+ BTRFS_EXCLOP_DEV_ADD,
578
+ BTRFS_EXCLOP_DEV_REMOVE,
579
+ BTRFS_EXCLOP_DEV_REPLACE,
580
+ BTRFS_EXCLOP_RESIZE,
581
+ BTRFS_EXCLOP_SWAP_ACTIVATE,
582
+};
752583
753584 struct btrfs_fs_info {
754
- u8 fsid[BTRFS_FSID_SIZE];
755585 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
756586 unsigned long flags;
757587 struct btrfs_root *extent_root;
....@@ -763,6 +593,7 @@
763593 struct btrfs_root *quota_root;
764594 struct btrfs_root *uuid_root;
765595 struct btrfs_root *free_space_root;
596
+ struct btrfs_root *data_reloc_root;
766597
767598 /* the log root tree is a directory of all the other log roots */
768599 struct btrfs_root *log_root_tree;
....@@ -778,11 +609,11 @@
778609 /* keep track of unallocated space */
779610 atomic64_t free_chunk_space;
780611
781
- struct extent_io_tree freed_extents[2];
782
- struct extent_io_tree *pinned_extents;
612
+ /* Track ranges which are used by log trees blocks/logged data extents */
613
+ struct extent_io_tree excluded_extents;
783614
784615 /* logical->physical extent mapping */
785
- struct btrfs_mapping_tree mapping_tree;
616
+ struct extent_map_tree mapping_tree;
786617
787618 /*
788619 * block reservation for extent, checksum, root tree and
....@@ -795,6 +626,8 @@
795626 struct btrfs_block_rsv chunk_block_rsv;
796627 /* block reservation for delayed operations */
797628 struct btrfs_block_rsv delayed_block_rsv;
629
+ /* block reservation for delayed refs */
630
+ struct btrfs_block_rsv delayed_refs_rsv;
798631
799632 struct btrfs_block_rsv empty_block_rsv;
800633
....@@ -876,7 +709,6 @@
876709 struct rw_semaphore cleanup_work_sem;
877710
878711 struct rw_semaphore subvol_sem;
879
- struct srcu_struct subvol_srcu;
880712
881713 spinlock_t trans_lock;
882714 /*
....@@ -891,7 +723,8 @@
891723
892724 spinlock_t delayed_iput_lock;
893725 struct list_head delayed_iputs;
894
- struct mutex cleaner_delayed_iput_mutex;
726
+ atomic_t nr_delayed_iputs;
727
+ wait_queue_head_t delayed_iputs_wait;
895728
896729 atomic64_t tree_mod_seq;
897730
....@@ -937,12 +770,10 @@
937770 struct btrfs_workqueue *endio_workers;
938771 struct btrfs_workqueue *endio_meta_workers;
939772 struct btrfs_workqueue *endio_raid56_workers;
940
- struct btrfs_workqueue *endio_repair_workers;
941773 struct btrfs_workqueue *rmw_workers;
942774 struct btrfs_workqueue *endio_meta_write_workers;
943775 struct btrfs_workqueue *endio_write_workers;
944776 struct btrfs_workqueue *endio_freespace_worker;
945
- struct btrfs_workqueue *submit_workers;
946777 struct btrfs_workqueue *caching_workers;
947778 struct btrfs_workqueue *readahead_workers;
948779
....@@ -954,21 +785,19 @@
954785 struct btrfs_workqueue *fixup_workers;
955786 struct btrfs_workqueue *delayed_workers;
956787
957
- /* the extent workers do delayed refs on the extent allocation tree */
958
- struct btrfs_workqueue *extent_workers;
959788 struct task_struct *transaction_kthread;
960789 struct task_struct *cleaner_kthread;
961790 u32 thread_pool_size;
962791
963792 struct kobject *space_info_kobj;
964
- struct list_head pending_raid_kobjs;
965
- spinlock_t pending_raid_kobjs_lock; /* uncontended */
793
+ struct kobject *qgroups_kobj;
966794
967795 u64 total_pinned;
968796
969797 /* used to keep from writing metadata until there is a nice batch */
970798 struct percpu_counter dirty_metadata_bytes;
971799 struct percpu_counter delalloc_bytes;
800
+ struct percpu_counter dio_bytes;
972801 s32 dirty_metadata_batch;
973802 s32 delalloc_batch;
974803
....@@ -1029,11 +858,16 @@
1029858 atomic_t scrubs_paused;
1030859 atomic_t scrub_cancel_req;
1031860 wait_queue_head_t scrub_pause_wait;
1032
- int scrub_workers_refcnt;
861
+ /*
862
+ * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
863
+ * running.
864
+ */
865
+ refcount_t scrub_workers_refcnt;
1033866 struct btrfs_workqueue *scrub_workers;
1034867 struct btrfs_workqueue *scrub_wr_completion_workers;
1035
- struct btrfs_workqueue *scrub_nocow_workers;
1036868 struct btrfs_workqueue *scrub_parity_workers;
869
+
870
+ struct btrfs_discard_ctl discard_ctl;
1037871
1038872 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
1039873 u32 check_integrity_print_mask;
....@@ -1043,10 +877,7 @@
1043877
1044878 /* holds configuration and tracking. Protected by qgroup_lock */
1045879 struct rb_root qgroup_tree;
1046
- struct rb_root qgroup_op_tree;
1047880 spinlock_t qgroup_lock;
1048
- spinlock_t qgroup_op_lock;
1049
- atomic_t qgroup_op_seq;
1050881
1051882 /*
1052883 * used to avoid frequently calling ulist_alloc()/ulist_free()
....@@ -1054,7 +885,10 @@
1054885 */
1055886 struct ulist *qgroup_ulist;
1056887
1057
- /* protect user change for quota operations */
888
+ /*
889
+ * Protect user change for quota operations. If a transaction is needed,
890
+ * it must be started before locking this lock.
891
+ */
1058892 struct mutex qgroup_ioctl_lock;
1059893
1060894 /* list of dirty qgroups to be written at next commit */
....@@ -1093,36 +927,49 @@
1093927 /* device replace state */
1094928 struct btrfs_dev_replace dev_replace;
1095929
1096
- struct percpu_counter bio_counter;
1097
- wait_queue_head_t replace_wait;
1098
-
1099930 struct semaphore uuid_tree_rescan_sem;
1100931
1101932 /* Used to reclaim the metadata space in the background. */
1102933 struct work_struct async_reclaim_work;
934
+ struct work_struct async_data_reclaim_work;
1103935
1104936 spinlock_t unused_bgs_lock;
1105937 struct list_head unused_bgs;
1106938 struct mutex unused_bg_unpin_mutex;
1107939 struct mutex delete_unused_bgs_mutex;
1108940
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
-
1118941 /* Cached block sizes */
1119942 u32 nodesize;
1120943 u32 sectorsize;
1121944 u32 stripesize;
1122945
946
+ /* Block groups and devices containing active swapfiles. */
947
+ spinlock_t swapfile_pins_lock;
948
+ struct rb_root swapfile_pins;
949
+
950
+ struct crypto_shash *csum_shash;
951
+
952
+ /*
953
+ * Number of send operations in progress.
954
+ * Updated while holding fs_info::balance_mutex.
955
+ */
956
+ int send_in_progress;
957
+
958
+ /* Type of exclusive operation running */
959
+ unsigned long exclusive_operation;
960
+
1123961 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
1124962 spinlock_t ref_verify_lock;
1125963 struct rb_root block_tree;
964
+#endif
965
+
966
+#ifdef CONFIG_BTRFS_DEBUG
967
+ struct kobject *debug_kobj;
968
+ struct kobject *discard_debug_kobj;
969
+ struct list_head allocated_roots;
970
+
971
+ spinlock_t eb_leak_lock;
972
+ struct list_head allocated_ebs;
1126973 #endif
1127974 };
1128975
....@@ -1131,30 +978,72 @@
1131978 return sb->s_fs_info;
1132979 }
1133980
1134
-struct btrfs_subvolume_writers {
1135
- struct percpu_counter counter;
1136
- wait_queue_head_t wait;
1137
-};
1138
-
1139981 /*
1140982 * The state of btrfs root
1141983 */
984
+enum {
985
+ /*
986
+ * btrfs_record_root_in_trans is a multi-step process, and it can race
987
+ * with the balancing code. But the race is very small, and only the
988
+ * first time the root is added to each transaction. So IN_TRANS_SETUP
989
+ * is used to tell us when more checks are required
990
+ */
991
+ BTRFS_ROOT_IN_TRANS_SETUP,
992
+
993
+ /*
994
+ * Set if tree blocks of this root can be shared by other roots.
995
+ * Only subvolume trees and their reloc trees have this bit set.
996
+ * Conflicts with TRACK_DIRTY bit.
997
+ *
998
+ * This affects two things:
999
+ *
1000
+ * - How balance works
1001
+ * For shareable roots, we need to use reloc tree and do path
1002
+ * replacement for balance, and need various pre/post hooks for
1003
+ * snapshot creation to handle them.
1004
+ *
1005
+ * While for non-shareable trees, we just simply do a tree search
1006
+ * with COW.
1007
+ *
1008
+ * - How dirty roots are tracked
1009
+ * For shareable roots, btrfs_record_root_in_trans() is needed to
1010
+ * track them, while non-subvolume roots have TRACK_DIRTY bit, they
1011
+ * don't need to set this manually.
1012
+ */
1013
+ BTRFS_ROOT_SHAREABLE,
1014
+ BTRFS_ROOT_TRACK_DIRTY,
1015
+ BTRFS_ROOT_IN_RADIX,
1016
+ BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
1017
+ BTRFS_ROOT_DEFRAG_RUNNING,
1018
+ BTRFS_ROOT_FORCE_COW,
1019
+ BTRFS_ROOT_MULTI_LOG_TASKS,
1020
+ BTRFS_ROOT_DIRTY,
1021
+ BTRFS_ROOT_DELETING,
1022
+
1023
+ /*
1024
+ * Reloc tree is orphan, only kept here for qgroup delayed subtree scan
1025
+ *
1026
+ * Set for the subvolume tree owning the reloc tree.
1027
+ */
1028
+ BTRFS_ROOT_DEAD_RELOC_TREE,
1029
+ /* Mark dead root stored on device whose cleanup needs to be resumed */
1030
+ BTRFS_ROOT_DEAD_TREE,
1031
+ /* The root has a log tree. Used only for subvolume roots. */
1032
+ BTRFS_ROOT_HAS_LOG_TREE,
1033
+ /* Qgroup flushing is in progress */
1034
+ BTRFS_ROOT_QGROUP_FLUSHING,
1035
+};
1036
+
11421037 /*
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
1038
+ * Record swapped tree blocks of a subvolume tree for delayed subtree trace
1039
+ * code. For detail check comment in fs/btrfs/qgroup.c.
11481040 */
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
1041
+struct btrfs_qgroup_swapped_blocks {
1042
+ spinlock_t lock;
1043
+ /* RM_EMPTY_ROOT() of above blocks[] */
1044
+ bool swapped;
1045
+ struct rb_root blocks[BTRFS_MAX_LEVEL];
1046
+};
11581047
11591048 /*
11601049 * in ram representation of the tree. extent_root is used for all allocations
....@@ -1191,8 +1080,10 @@
11911080 wait_queue_head_t log_writer_wait;
11921081 wait_queue_head_t log_commit_wait[2];
11931082 struct list_head log_ctxs[2];
1083
+ /* Used only for log trees of subvolumes, not for the log root tree */
11941084 atomic_t log_writers;
11951085 atomic_t log_commit[2];
1086
+ /* Used only for log trees of subvolumes, not for the log root tree */
11961087 atomic_t log_batch;
11971088 int log_transid;
11981089 /* No matter the commit succeeds or not*/
....@@ -1201,23 +1092,16 @@
12011092 int last_log_commit;
12021093 pid_t log_start_pid;
12031094
1204
- u64 objectid;
12051095 u64 last_trans;
12061096
12071097 u32 type;
12081098
12091099 u64 highest_objectid;
12101100
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;
12171101 struct btrfs_key defrag_progress;
12181102 struct btrfs_key defrag_max;
12191103
1220
- /* the dirty list is only used by non-reference counted roots */
1104
+ /* The dirty list is only used by non-shareable roots */
12211105 struct list_head dirty_list;
12221106
12231107 struct list_head root_list;
....@@ -1273,28 +1157,87 @@
12731157 u64 nr_ordered_extents;
12741158
12751159 /*
1160
+ * Not empty if this subvolume root has gone through tree block swap
1161
+ * (relocation)
1162
+ *
1163
+ * Will be used by reloc_control::dirty_subvol_roots.
1164
+ */
1165
+ struct list_head reloc_dirty_list;
1166
+
1167
+ /*
12761168 * Number of currently running SEND ioctls to prevent
12771169 * manipulation with the read-only status via SUBVOL_SETFLAGS
12781170 */
12791171 int send_in_progress;
1280
- struct btrfs_subvolume_writers *subv_writers;
1281
- atomic_t will_be_snapshotted;
1172
+ /*
1173
+ * Number of currently running deduplication operations that have a
1174
+ * destination inode belonging to this root. Protected by the lock
1175
+ * root_item_lock.
1176
+ */
1177
+ int dedupe_in_progress;
1178
+ /* For exclusion of snapshot creation and nocow writes */
1179
+ struct btrfs_drew_lock snapshot_lock;
1180
+
12821181 atomic_t snapshot_force_cow;
12831182
12841183 /* For qgroup metadata reserved space */
12851184 spinlock_t qgroup_meta_rsv_lock;
12861185 u64 qgroup_meta_rsv_pertrans;
12871186 u64 qgroup_meta_rsv_prealloc;
1187
+ wait_queue_head_t qgroup_flush_wait;
1188
+
1189
+ /* Number of active swapfiles */
1190
+ atomic_t nr_swapfiles;
1191
+
1192
+ /* Record pairs of swapped blocks for qgroup */
1193
+ struct btrfs_qgroup_swapped_blocks swapped_blocks;
1194
+
1195
+ /* Used only by log trees, when logging csum items */
1196
+ struct extent_io_tree log_csum_range;
1197
+
1198
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1199
+ u64 alloc_bytenr;
1200
+#endif
1201
+
1202
+#ifdef CONFIG_BTRFS_DEBUG
1203
+ struct list_head leak_list;
1204
+#endif
1205
+};
1206
+
1207
+/*
1208
+ * Structure that conveys information about an extent that is going to replace
1209
+ * all the extents in a file range.
1210
+ */
1211
+struct btrfs_replace_extent_info {
1212
+ u64 disk_offset;
1213
+ u64 disk_len;
1214
+ u64 data_offset;
1215
+ u64 data_len;
1216
+ u64 file_offset;
1217
+ /* Pointer to a file extent item of type regular or prealloc. */
1218
+ char *extent_buf;
1219
+ /*
1220
+ * Set to true when attempting to replace a file range with a new extent
1221
+ * described by this structure, set to false when attempting to clone an
1222
+ * existing extent into a file range.
1223
+ */
1224
+ bool is_new_extent;
1225
+ /* Meaningful only if is_new_extent is true. */
1226
+ int qgroup_reserved;
1227
+ /*
1228
+ * Meaningful only if is_new_extent is true.
1229
+ * Used to track how many extent items we have already inserted in a
1230
+ * subvolume tree that refer to the extent described by this structure,
1231
+ * so that we know when to create a new delayed ref or update an existing
1232
+ * one.
1233
+ */
1234
+ int insertions;
12881235 };
12891236
12901237 struct btrfs_file_private {
12911238 void *filldir_buf;
12921239 };
12931240
1294
-static inline u32 btrfs_inode_sectorsize(const struct inode *inode)
1295
-{
1296
- return btrfs_sb(inode->i_sb)->sectorsize;
1297
-}
12981241
12991242 static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
13001243 {
....@@ -1342,7 +1285,7 @@
13421285 #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7)
13431286 #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
13441287 #define BTRFS_MOUNT_NOSSD (1 << 9)
1345
-#define BTRFS_MOUNT_DISCARD (1 << 10)
1288
+#define BTRFS_MOUNT_DISCARD_SYNC (1 << 10)
13461289 #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
13471290 #define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
13481291 #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
....@@ -1361,6 +1304,7 @@
13611304 #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)
13621305 #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)
13631306 #define BTRFS_MOUNT_REF_VERIFY (1 << 28)
1307
+#define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29)
13641308
13651309 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
13661310 #define BTRFS_DEFAULT_MAX_INLINE (2048)
....@@ -1372,31 +1316,18 @@
13721316 BTRFS_MOUNT_##opt)
13731317
13741318 #define btrfs_set_and_info(fs_info, opt, fmt, args...) \
1375
-{ \
1319
+do { \
13761320 if (!btrfs_test_opt(fs_info, opt)) \
13771321 btrfs_info(fs_info, fmt, ##args); \
13781322 btrfs_set_opt(fs_info->mount_opt, opt); \
1379
-}
1323
+} while (0)
13801324
13811325 #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \
1382
-{ \
1326
+do { \
13831327 if (btrfs_test_opt(fs_info, opt)) \
13841328 btrfs_info(fs_info, fmt, ##args); \
13851329 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
1330
+} while (0)
14001331
14011332 /*
14021333 * Requests for changes that need to be done during transaction commit.
....@@ -1475,7 +1406,7 @@
14751406 BTRFS_INODE_ROOT_ITEM_INIT)
14761407
14771408 struct btrfs_map_token {
1478
- const struct extent_buffer *eb;
1409
+ struct extent_buffer *eb;
14791410 char *kaddr;
14801411 unsigned long offset;
14811412 };
....@@ -1483,9 +1414,12 @@
14831414 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
14841415 ((bytes) >> (fs_info)->sb->s_blocksize_bits)
14851416
1486
-static inline void btrfs_init_map_token (struct btrfs_map_token *token)
1417
+static inline void btrfs_init_map_token(struct btrfs_map_token *token,
1418
+ struct extent_buffer *eb)
14871419 {
1488
- token->kaddr = NULL;
1420
+ token->eb = eb;
1421
+ token->kaddr = page_address(eb->pages[0]);
1422
+ token->offset = 0;
14891423 }
14901424
14911425 /* some macros to generate set/get functions for the struct fields. This
....@@ -1495,6 +1429,16 @@
14951429 #define le8_to_cpu(v) (v)
14961430 #define cpu_to_le8(v) (v)
14971431 #define __le8 u8
1432
+
1433
+static inline u8 get_unaligned_le8(const void *p)
1434
+{
1435
+ return *(u8 *)p;
1436
+}
1437
+
1438
+static inline void put_unaligned_le8(u8 val, void *p)
1439
+{
1440
+ *(u8 *)p = val;
1441
+}
14981442
14991443 #define read_eb_member(eb, ptr, type, member, result) (\
15001444 read_extent_buffer(eb, (char *)(result), \
....@@ -1509,23 +1453,15 @@
15091453 sizeof(((type *)0)->member)))
15101454
15111455 #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
-}
1456
+u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
1457
+ const void *ptr, unsigned long off); \
1458
+void btrfs_set_token_##bits(struct btrfs_map_token *token, \
1459
+ const void *ptr, unsigned long off, \
1460
+ u##bits val); \
1461
+u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
1462
+ const void *ptr, unsigned long off); \
1463
+void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
1464
+ unsigned long off, u##bits val);
15291465
15301466 DECLARE_BTRFS_SETGET_BITS(8)
15311467 DECLARE_BTRFS_SETGET_BITS(16)
....@@ -1539,53 +1475,49 @@
15391475 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15401476 return btrfs_get_##bits(eb, s, offsetof(type, member)); \
15411477 } \
1542
-static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \
1478
+static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
15431479 u##bits val) \
15441480 { \
15451481 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15461482 btrfs_set_##bits(eb, s, offsetof(type, member), val); \
15471483 } \
1548
-static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\
1549
- const type *s, \
1550
- struct btrfs_map_token *token) \
1484
+static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
1485
+ const type *s) \
15511486 { \
15521487 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1553
- return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \
1488
+ return btrfs_get_token_##bits(token, s, offsetof(type, member));\
15541489 } \
1555
-static inline void btrfs_set_token_##name(struct extent_buffer *eb, \
1556
- type *s, u##bits val, \
1557
- struct btrfs_map_token *token) \
1490
+static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
1491
+ type *s, u##bits val) \
15581492 { \
15591493 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1560
- btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \
1494
+ btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
15611495 }
15621496
15631497 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
15641498 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
15651499 { \
15661500 const type *p = page_address(eb->pages[0]); \
1567
- u##bits res = le##bits##_to_cpu(p->member); \
1568
- return res; \
1501
+ return get_unaligned_le##bits(&p->member); \
15691502 } \
1570
-static inline void btrfs_set_##name(struct extent_buffer *eb, \
1503
+static inline void btrfs_set_##name(const struct extent_buffer *eb, \
15711504 u##bits val) \
15721505 { \
15731506 type *p = page_address(eb->pages[0]); \
1574
- p->member = cpu_to_le##bits(val); \
1507
+ put_unaligned_le##bits(val, &p->member); \
15751508 }
15761509
15771510 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
15781511 static inline u##bits btrfs_##name(const type *s) \
15791512 { \
1580
- return le##bits##_to_cpu(s->member); \
1513
+ return get_unaligned_le##bits(&s->member); \
15811514 } \
15821515 static inline void btrfs_set_##name(type *s, u##bits val) \
15831516 { \
1584
- s->member = cpu_to_le##bits(val); \
1517
+ put_unaligned_le##bits(val, &s->member); \
15851518 }
15861519
1587
-
1588
-static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb,
1520
+static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
15891521 struct btrfs_dev_item *s)
15901522 {
15911523 BUILD_BUG_ON(sizeof(u64) !=
....@@ -1593,7 +1525,7 @@
15931525 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
15941526 total_bytes));
15951527 }
1596
-static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb,
1528
+static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
15971529 struct btrfs_dev_item *s,
15981530 u64 val)
15991531 {
....@@ -1697,31 +1629,31 @@
16971629 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
16981630 }
16991631
1700
-static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
1632
+static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
17011633 struct btrfs_chunk *c, int nr)
17021634 {
17031635 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
17041636 }
17051637
1706
-static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
1638
+static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
17071639 struct btrfs_chunk *c, int nr)
17081640 {
17091641 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
17101642 }
17111643
17121644 /* struct btrfs_block_group_item */
1713
-BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
1645
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
17141646 used, 64);
1715
-BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
1647
+BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item,
17161648 used, 64);
1717
-BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
1649
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
17181650 struct btrfs_block_group_item, chunk_objectid, 64);
17191651
1720
-BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
1652
+BTRFS_SETGET_FUNCS(block_group_chunk_objectid,
17211653 struct btrfs_block_group_item, chunk_objectid, 64);
1722
-BTRFS_SETGET_FUNCS(disk_block_group_flags,
1654
+BTRFS_SETGET_FUNCS(block_group_flags,
17231655 struct btrfs_block_group_item, flags, 64);
1724
-BTRFS_SETGET_STACK_FUNCS(block_group_flags,
1656
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
17251657 struct btrfs_block_group_item, flags, 64);
17261658
17271659 /* struct btrfs_free_space_info */
....@@ -1783,31 +1715,21 @@
17831715 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
17841716 chunk_offset, 64);
17851717 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
-
17931718 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
17941719 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
17951720 generation, 64);
17961721 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
17971722
1798
-BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1799
-
1800
-
18011723 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
18021724
1803
-static inline void btrfs_tree_block_key(struct extent_buffer *eb,
1725
+static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
18041726 struct btrfs_tree_block_info *item,
18051727 struct btrfs_disk_key *key)
18061728 {
18071729 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
18081730 }
18091731
1810
-static inline void btrfs_set_tree_block_key(struct extent_buffer *eb,
1732
+static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
18111733 struct btrfs_tree_block_info *item,
18121734 struct btrfs_disk_key *key)
18131735 {
....@@ -1845,12 +1767,6 @@
18451767 return 0;
18461768 }
18471769
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
-
18541770 /* struct btrfs_node */
18551771 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
18561772 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
....@@ -1859,7 +1775,7 @@
18591775 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
18601776 generation, 64);
18611777
1862
-static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1778
+static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
18631779 {
18641780 unsigned long ptr;
18651781 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1867,7 +1783,7 @@
18671783 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
18681784 }
18691785
1870
-static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1786
+static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
18711787 int nr, u64 val)
18721788 {
18731789 unsigned long ptr;
....@@ -1876,7 +1792,7 @@
18761792 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
18771793 }
18781794
1879
-static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1795
+static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
18801796 {
18811797 unsigned long ptr;
18821798 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1884,7 +1800,7 @@
18841800 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
18851801 }
18861802
1887
-static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1803
+static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
18881804 int nr, u64 val)
18891805 {
18901806 unsigned long ptr;
....@@ -1902,7 +1818,7 @@
19021818 void btrfs_node_key(const struct extent_buffer *eb,
19031819 struct btrfs_disk_key *disk_key, int nr);
19041820
1905
-static inline void btrfs_set_node_key(struct extent_buffer *eb,
1821
+static inline void btrfs_set_node_key(const struct extent_buffer *eb,
19061822 struct btrfs_disk_key *disk_key, int nr)
19071823 {
19081824 unsigned long ptr;
....@@ -2026,6 +1942,52 @@
20261942 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
20271943 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
20281944
1945
+#ifdef __LITTLE_ENDIAN
1946
+
1947
+/*
1948
+ * Optimized helpers for little-endian architectures where CPU and on-disk
1949
+ * structures have the same endianness and we can skip conversions.
1950
+ */
1951
+
1952
+static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
1953
+ const struct btrfs_disk_key *disk_key)
1954
+{
1955
+ memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
1956
+}
1957
+
1958
+static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
1959
+ const struct btrfs_key *cpu_key)
1960
+{
1961
+ memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
1962
+}
1963
+
1964
+static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
1965
+ struct btrfs_key *cpu_key, int nr)
1966
+{
1967
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1968
+
1969
+ btrfs_node_key(eb, disk_key, nr);
1970
+}
1971
+
1972
+static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
1973
+ struct btrfs_key *cpu_key, int nr)
1974
+{
1975
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1976
+
1977
+ btrfs_item_key(eb, disk_key, nr);
1978
+}
1979
+
1980
+static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
1981
+ const struct btrfs_dir_item *item,
1982
+ struct btrfs_key *cpu_key)
1983
+{
1984
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1985
+
1986
+ btrfs_dir_item_key(eb, item, disk_key);
1987
+}
1988
+
1989
+#else
1990
+
20291991 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
20301992 const struct btrfs_disk_key *disk)
20311993 {
....@@ -2067,15 +2029,7 @@
20672029 btrfs_disk_key_to_cpu(key, &disk_key);
20682030 }
20692031
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
-}
2032
+#endif
20792033
20802034 /* struct btrfs_header */
20812035 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
....@@ -2097,18 +2051,16 @@
20972051 return (btrfs_header_flags(eb) & flag) == flag;
20982052 }
20992053
2100
-static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
2054
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
21012055 {
21022056 u64 flags = btrfs_header_flags(eb);
21032057 btrfs_set_header_flags(eb, flags | flag);
2104
- return (flags & flag) == flag;
21052058 }
21062059
2107
-static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
2060
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
21082061 {
21092062 u64 flags = btrfs_header_flags(eb);
21102063 btrfs_set_header_flags(eb, flags & ~flag);
2111
- return (flags & flag) == flag;
21122064 }
21132065
21142066 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
....@@ -2124,16 +2076,6 @@
21242076 flags &= ~BTRFS_BACKREF_REV_MASK;
21252077 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
21262078 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);
21372079 }
21382080
21392081 static inline int btrfs_is_leaf(const struct extent_buffer *eb)
....@@ -2364,14 +2306,10 @@
23642306 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
23652307 uuid_tree_generation, 64);
23662308
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
-}
2309
+int btrfs_super_csum_size(const struct btrfs_super_block *s);
2310
+const char *btrfs_super_csum_name(u16 csum_type);
2311
+const char *btrfs_super_csum_driver(u16 csum_type);
2312
+size_t __attribute_const__ btrfs_get_num_csums(void);
23752313
23762314
23772315 /*
....@@ -2379,18 +2317,18 @@
23792317 * this returns the address of the start of the last item,
23802318 * which is the stop of the leaf data stack
23812319 */
2382
-static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info,
2383
- const struct extent_buffer *leaf)
2320
+static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
23842321 {
23852322 u32 nr = btrfs_header_nritems(leaf);
23862323
23872324 if (nr == 0)
2388
- return BTRFS_LEAF_DATA_SIZE(fs_info);
2325
+ return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
23892326 return btrfs_item_offset_nr(leaf, nr - 1);
23902327 }
23912328
23922329 /* struct btrfs_file_extent_item */
2393
-BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
2330
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
2331
+ type, 8);
23942332 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
23952333 struct btrfs_file_extent_item, disk_bytenr, 64);
23962334 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
....@@ -2399,6 +2337,8 @@
23992337 struct btrfs_file_extent_item, generation, 64);
24002338 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
24012339 struct btrfs_file_extent_item, num_bytes, 64);
2340
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
2341
+ struct btrfs_file_extent_item, ram_bytes, 64);
24022342 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
24032343 struct btrfs_file_extent_item, disk_num_bytes, 64);
24042344 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
....@@ -2415,6 +2355,7 @@
24152355 return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
24162356 }
24172357
2358
+BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
24182359 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
24192360 disk_bytenr, 64);
24202361 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
....@@ -2444,30 +2385,6 @@
24442385 struct btrfs_item *e)
24452386 {
24462387 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));
24712388 }
24722389
24732390 /* btrfs_qgroup_status_item */
....@@ -2565,6 +2482,16 @@
25652482 ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
25662483 btrfs_item_offset_nr(leaf, slot)))
25672484
2485
+static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
2486
+{
2487
+ return crc32c(crc, address, length);
2488
+}
2489
+
2490
+static inline void btrfs_crc32c_final(u32 crc, u8 *result)
2491
+{
2492
+ put_unaligned_le32(~crc, result);
2493
+}
2494
+
25682495 static inline u64 btrfs_name_hash(const char *name, int len)
25692496 {
25702497 return crc32c((u32)~1, name, len);
....@@ -2579,12 +2506,6 @@
25792506 return (u64) crc32c(parent_objectid, name, len);
25802507 }
25812508
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
-
25882509 static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
25892510 {
25902511 return mapping_gfp_constraint(mapping, ~__GFP_FS);
....@@ -2593,72 +2514,65 @@
25932514 /* extent-tree.c */
25942515
25952516 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,
2517
+ BTRFS_REF_TYPE_INVALID,
2518
+ BTRFS_REF_TYPE_BLOCK,
2519
+ BTRFS_REF_TYPE_DATA,
2520
+ BTRFS_REF_TYPE_ANY,
26002521 };
26012522
26022523 int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
26032524 struct btrfs_extent_inline_ref *iref,
26042525 enum btrfs_inline_ref_type is_data);
2526
+u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
26052527
26062528 u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes);
26072529
2608
-static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info,
2609
- unsigned num_items)
2530
+/*
2531
+ * Use this if we would be adding new items, as we could split nodes as we cow
2532
+ * down the tree.
2533
+ */
2534
+static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info,
2535
+ unsigned num_items)
26102536 {
26112537 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
26122538 }
26132539
26142540 /*
2615
- * Doing a truncate won't result in new nodes or leaves, just what we need for
2616
- * COW.
2541
+ * Doing a truncate or a modification won't result in new nodes or leaves, just
2542
+ * what we need for COW.
26172543 */
2618
-static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info,
2544
+static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info,
26192545 unsigned num_items)
26202546 {
26212547 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
26222548 }
26232549
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);
2550
+int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info,
2551
+ u64 start, u64 num_bytes);
2552
+void btrfs_free_excluded_extents(struct btrfs_block_group *cache);
26352553 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
26362554 unsigned long count);
2637
-int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
2638
- unsigned long count, u64 transid, int wait);
2555
+void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2556
+ struct btrfs_delayed_ref_root *delayed_refs,
2557
+ struct btrfs_delayed_ref_head *head);
26392558 int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
26402559 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
26412560 struct btrfs_fs_info *fs_info, u64 bytenr,
26422561 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,
2562
+int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
2563
+ int reserved);
2564
+int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
26462565 u64 bytenr, u64 num_bytes);
2647
-int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
2648
- struct extent_buffer *eb);
2566
+int btrfs_exclude_logged_extents(struct extent_buffer *eb);
26492567 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);
2568
+ u64 objectid, u64 offset, u64 bytenr, bool strict);
26562569 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
26572570 struct btrfs_root *root,
26582571 u64 parent, u64 root_objectid,
26592572 const struct btrfs_disk_key *key,
26602573 int level, u64 hint,
2661
- u64 empty_size);
2574
+ u64 empty_size,
2575
+ enum btrfs_lock_nesting nest);
26622576 void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
26632577 struct btrfs_root *root,
26642578 struct extent_buffer *buf,
....@@ -2678,128 +2592,92 @@
26782592 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
26792593 struct extent_buffer *buf, int full_backref);
26802594 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,
2595
+ struct extent_buffer *eb, u64 flags,
26832596 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);
2597
+int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
26882598
26892599 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
26902600 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);
2601
+int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start,
2602
+ u64 len);
26942603 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
26952604 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);
2605
+ struct btrfs_ref *generic_ref);
26992606
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);
27052607 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);
27252608 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
27262609
2610
+/*
2611
+ * Different levels for to flush space when doing space reservations.
2612
+ *
2613
+ * The higher the level, the more methods we try to reclaim space.
2614
+ */
27272615 enum btrfs_reserve_flush_enum {
27282616 /* If we are in the transaction, we can't flush anything.*/
27292617 BTRFS_RESERVE_NO_FLUSH,
2618
+
27302619 /*
2731
- * Flushing delalloc may cause deadlock somewhere, in this
2732
- * case, use FLUSH LIMIT
2620
+ * Flush space by:
2621
+ * - Running delayed inode items
2622
+ * - Allocating a new chunk
27332623 */
27342624 BTRFS_RESERVE_FLUSH_LIMIT,
2625
+
2626
+ /*
2627
+ * Flush space by:
2628
+ * - Running delayed inode items
2629
+ * - Running delayed refs
2630
+ * - Running delalloc and waiting for ordered extents
2631
+ * - Allocating a new chunk
2632
+ */
2633
+ BTRFS_RESERVE_FLUSH_EVICT,
2634
+
2635
+ /*
2636
+ * Flush space by above mentioned methods and by:
2637
+ * - Running delayed iputs
2638
+ * - Commiting transaction
2639
+ *
2640
+ * Can be interruped by fatal signal.
2641
+ */
2642
+ BTRFS_RESERVE_FLUSH_DATA,
2643
+ BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE,
27352644 BTRFS_RESERVE_FLUSH_ALL,
2645
+
2646
+ /*
2647
+ * Pretty much the same as FLUSH_ALL, but can also steal space from
2648
+ * global rsv.
2649
+ *
2650
+ * Can be interruped by fatal signal.
2651
+ */
2652
+ BTRFS_RESERVE_FLUSH_ALL_STEAL,
27362653 };
27372654
27382655 enum btrfs_flush_state {
27392656 FLUSH_DELAYED_ITEMS_NR = 1,
27402657 FLUSH_DELAYED_ITEMS = 2,
2741
- FLUSH_DELALLOC = 3,
2742
- FLUSH_DELALLOC_WAIT = 4,
2743
- ALLOC_CHUNK = 5,
2744
- COMMIT_TRANS = 6,
2658
+ FLUSH_DELAYED_REFS_NR = 3,
2659
+ FLUSH_DELAYED_REFS = 4,
2660
+ FLUSH_DELALLOC = 5,
2661
+ FLUSH_DELALLOC_WAIT = 6,
2662
+ ALLOC_CHUNK = 7,
2663
+ ALLOC_CHUNK_FORCE = 8,
2664
+ RUN_DELAYED_IPUTS = 9,
2665
+ COMMIT_TRANS = 10,
27452666 };
27462667
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);
27582668 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
27592669 struct btrfs_block_rsv *rsv,
27602670 int nitems, bool use_global_rsv);
2761
-void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
2671
+void btrfs_subvolume_release_metadata(struct btrfs_root *root,
27622672 struct btrfs_block_rsv *rsv);
27632673 void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
27642674
27652675 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);
27972676 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
27982677 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
27992678 u64 start, u64 end);
28002679 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
28012680 u64 num_bytes, u64 *actual_bytes);
2802
-int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
28032681 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
28042682
28052683 int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
....@@ -2808,15 +2686,11 @@
28082686 int btrfs_start_write_no_snapshotting(struct btrfs_root *root);
28092687 void btrfs_end_write_no_snapshotting(struct btrfs_root *root);
28102688 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);
28152689
28162690 /* ctree.c */
28172691 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);
2692
+ int *slot);
2693
+int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
28202694 int btrfs_previous_item(struct btrfs_root *root,
28212695 struct btrfs_path *path, u64 min_objectid,
28222696 int type);
....@@ -2826,42 +2700,28 @@
28262700 struct btrfs_path *path,
28272701 const struct btrfs_key *new_key);
28282702 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);
28312703 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
28322704 struct btrfs_key *key, int lowest_level,
28332705 u64 min_trans);
28342706 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
28352707 struct btrfs_path *path,
28362708 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);
2709
+struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
2710
+ int slot);
2711
+
28512712 int btrfs_cow_block(struct btrfs_trans_handle *trans,
28522713 struct btrfs_root *root, struct extent_buffer *buf,
28532714 struct extent_buffer *parent, int parent_slot,
2854
- struct extent_buffer **cow_ret);
2715
+ struct extent_buffer **cow_ret,
2716
+ enum btrfs_lock_nesting nest);
28552717 int btrfs_copy_root(struct btrfs_trans_handle *trans,
28562718 struct btrfs_root *root,
28572719 struct extent_buffer *buf,
28582720 struct extent_buffer **cow_ret, u64 new_root_objectid);
28592721 int btrfs_block_can_be_shared(struct btrfs_root *root,
28602722 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);
2723
+void btrfs_extend_item(struct btrfs_path *path, u32 data_size);
2724
+void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
28652725 int btrfs_split_item(struct btrfs_trans_handle *trans,
28662726 struct btrfs_root *root,
28672727 struct btrfs_path *path,
....@@ -2889,10 +2749,6 @@
28892749 void btrfs_release_path(struct btrfs_path *p);
28902750 struct btrfs_path *btrfs_alloc_path(void);
28912751 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);
28962752
28972753 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
28982754 struct btrfs_path *path, int slot, int nr);
....@@ -2905,7 +2761,7 @@
29052761
29062762 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
29072763 const struct btrfs_key *cpu_key, u32 *data_size,
2908
- u32 total_data, u32 total_size, int nr);
2764
+ int nr);
29092765 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
29102766 const struct btrfs_key *key, void *data, u32 data_size);
29112767 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
....@@ -2939,11 +2795,9 @@
29392795 {
29402796 return btrfs_next_old_item(root, p, 0);
29412797 }
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);
2798
+int btrfs_leaf_free_space(struct extent_buffer *leaf);
2799
+int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
2800
+ int for_reloc);
29472801 int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
29482802 struct btrfs_root *root,
29492803 struct extent_buffer *node,
....@@ -2969,24 +2823,6 @@
29692823 static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
29702824 {
29712825 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);
29902826 }
29912827
29922828 /* tree mod log functions from ctree.c */
....@@ -3027,15 +2863,12 @@
30272863 u64 subid);
30282864 int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
30292865 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));
2866
+int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
30332867
30342868 /* dir-item.c */
30352869 int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
30362870 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,
2871
+int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
30392872 int name_len, struct btrfs_inode *dir,
30402873 struct btrfs_key *location, u8 type, u64 index);
30412874 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
....@@ -3103,21 +2936,18 @@
31032936 u64 inode_objectid, u64 ref_objectid, int ins_len,
31042937 int cow);
31052938
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
-
2939
+struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
2940
+ int slot, const char *name,
2941
+ int name_len);
2942
+struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
2943
+ struct extent_buffer *leaf, int slot, u64 ref_objectid,
2944
+ const char *name, int name_len);
31142945 /* file-item.c */
31152946 struct btrfs_dio_private;
31162947 int btrfs_del_csums(struct btrfs_trans_handle *trans,
31172948 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);
2949
+blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
2950
+ u64 offset, u8 *dst);
31212951 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
31222952 struct btrfs_root *root,
31232953 u64 objectid, u64 pos,
....@@ -3131,8 +2961,8 @@
31312961 int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
31322962 struct btrfs_root *root,
31332963 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);
2964
+blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
2965
+ u64 file_start, int contig);
31362966 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
31372967 struct list_head *list, int search_commit);
31382968 void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
....@@ -3140,14 +2970,23 @@
31402970 struct btrfs_file_extent_item *fi,
31412971 const bool new_inline,
31422972 struct extent_map *em);
2973
+int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
2974
+ u64 len);
2975
+int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start,
2976
+ u64 len);
2977
+void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size);
2978
+u64 btrfs_file_extent_end(const struct btrfs_path *path);
31432979
31442980 /* inode.c */
2981
+blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
2982
+ int mirror_num, unsigned long bio_flags);
2983
+int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
2984
+ struct page *page, u64 start, u64 end, int mirror);
31452985 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);
2986
+ u64 start, u64 len);
31482987 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
31492988 u64 *orig_start, u64 *orig_block_len,
3150
- u64 *ram_bytes);
2989
+ u64 *ram_bytes, bool strict);
31512990
31522991 void __btrfs_del_delalloc_inode(struct btrfs_root *root,
31532992 struct btrfs_inode *inode);
....@@ -3169,17 +3008,25 @@
31693008 u32 min_type);
31703009
31713010 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,
3011
+int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,
3012
+ bool in_reclaim_context);
3013
+int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
31743014 unsigned int extra_bits,
3175
- struct extent_state **cached_state, int dedupe);
3015
+ struct extent_state **cached_state);
31763016 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
31773017 struct btrfs_root *new_root,
31783018 struct btrfs_root *parent_root,
31793019 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);
3020
+ void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
3021
+ unsigned *bits);
3022
+void btrfs_clear_delalloc_extent(struct inode *inode,
3023
+ struct extent_state *state, unsigned *bits);
3024
+void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
3025
+ struct extent_state *other);
3026
+void btrfs_split_delalloc_extent(struct inode *inode,
3027
+ struct extent_state *orig, u64 split);
3028
+int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
3029
+ unsigned long bio_flags);
31833030 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
31843031 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
31853032 int btrfs_readpage(struct file *file, struct page *page);
....@@ -3187,17 +3034,16 @@
31873034 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
31883035 struct inode *btrfs_alloc_inode(struct super_block *sb);
31893036 void btrfs_destroy_inode(struct inode *inode);
3037
+void btrfs_free_inode(struct inode *inode);
31903038 int btrfs_drop_inode(struct inode *inode);
31913039 int __init btrfs_init_cachep(void);
31923040 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);
3041
+struct inode *btrfs_iget_path(struct super_block *s, u64 ino,
3042
+ struct btrfs_root *root, struct btrfs_path *path);
3043
+struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root);
31983044 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);
3045
+ struct page *page, size_t pg_offset,
3046
+ u64 start, u64 end);
32013047 int btrfs_update_inode(struct btrfs_trans_handle *trans,
32023048 struct btrfs_root *root,
32033049 struct inode *inode);
....@@ -3209,6 +3055,7 @@
32093055 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
32103056 void btrfs_add_delayed_iput(struct inode *inode);
32113057 void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
3058
+int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
32123059 int btrfs_prealloc_file_range(struct inode *inode, int mode,
32133060 u64 start, u64 num_bytes, u64 min_size,
32143061 loff_t actual_len, u64 *alloc_hint);
....@@ -3216,20 +3063,21 @@
32163063 struct btrfs_trans_handle *trans, int mode,
32173064 u64 start, u64 num_bytes, u64 min_size,
32183065 loff_t actual_len, u64 *alloc_hint);
3219
-int btrfs_run_delalloc_range(void *private_data, struct page *locked_page,
3066
+int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page,
32203067 u64 start, u64 end, int *page_started, unsigned long *nr_written,
32213068 struct writeback_control *wbc);
3069
+int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
3070
+void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
3071
+ u64 end, int uptodate);
32223072 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
3073
+ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
32263074
32273075 /* ioctl.c */
32283076 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32293077 long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32303078 int btrfs_ioctl_get_supported_features(void __user *arg);
32313079 void btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
3232
-int btrfs_is_empty_uuid(u8 *uuid);
3080
+int __pure btrfs_is_empty_uuid(u8 *uuid);
32333081 int btrfs_defrag_file(struct inode *inode, struct file *file,
32343082 struct btrfs_ioctl_defrag_range_args *range,
32353083 u64 newer_than, unsigned long max_pages);
....@@ -3237,9 +3085,9 @@
32373085 struct btrfs_ioctl_space_info *space);
32383086 void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
32393087 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);
3088
+bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
3089
+ enum btrfs_exclusive_operation type);
3090
+void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
32433091
32443092 /* file.c */
32453093 int __init btrfs_auto_defrag_init(void);
....@@ -3253,7 +3101,7 @@
32533101 int skip_pinned);
32543102 extern const struct file_operations btrfs_file_operations;
32553103 int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
3256
- struct btrfs_root *root, struct inode *inode,
3104
+ struct btrfs_root *root, struct btrfs_inode *inode,
32573105 struct btrfs_path *path, u64 start, u64 end,
32583106 u64 *drop_end, int drop_cache,
32593107 int replace_extent,
....@@ -3262,25 +3110,24 @@
32623110 int btrfs_drop_extents(struct btrfs_trans_handle *trans,
32633111 struct btrfs_root *root, struct inode *inode, u64 start,
32643112 u64 end, int drop_cache);
3113
+int btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path,
3114
+ const u64 start, const u64 end,
3115
+ struct btrfs_replace_extent_info *extent_info,
3116
+ struct btrfs_trans_handle **trans_out);
32653117 int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
32663118 struct btrfs_inode *inode, u64 start, u64 end);
32673119 int btrfs_release_file(struct inode *inode, struct file *file);
3268
-int btrfs_dirty_pages(struct inode *inode, struct page **pages,
3120
+int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
32693121 size_t num_pages, loff_t pos, size_t write_bytes,
32703122 struct extent_state **cached);
32713123 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);
3124
+int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
3125
+ size_t *write_bytes);
3126
+void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
32743127
32753128 /* tree-defrag.c */
32763129 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
32773130 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);
32843131
32853132 /* super.c */
32863133 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
....@@ -3374,31 +3221,17 @@
33743221
33753222 #if defined(CONFIG_DYNAMIC_DEBUG)
33763223 #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)
3224
+ _dynamic_func_call_no_desc(fmt, btrfs_printk, \
3225
+ fs_info, KERN_DEBUG fmt, ##args)
3226
+#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3227
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
3228
+ fs_info, KERN_DEBUG fmt, ##args)
33883229 #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)
3230
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
3231
+ fs_info, KERN_DEBUG fmt, ##args)
3232
+#define btrfs_debug_rl(fs_info, fmt, args...) \
3233
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
3234
+ fs_info, KERN_DEBUG fmt, ##args)
34023235 #elif defined(DEBUG)
34033236 #define btrfs_debug(fs_info, fmt, args...) \
34043237 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
....@@ -3450,19 +3283,29 @@
34503283 } while (0)
34513284
34523285 #ifdef CONFIG_BTRFS_ASSERT
3453
-
3454
-__cold
3455
-static inline void assfail(const char *expr, const char *file, int line)
3286
+__cold __noreturn
3287
+static inline void assertfail(const char *expr, const char *file, int line)
34563288 {
3457
- pr_err("assertion failed: %s, file: %s, line: %d\n",
3458
- expr, file, line);
3289
+ pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
34593290 BUG();
34603291 }
34613292
3462
-#define ASSERT(expr) \
3463
- (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
3293
+#define ASSERT(expr) \
3294
+ (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
3295
+
34643296 #else
3465
-#define ASSERT(expr) ((void)0)
3297
+static inline void assertfail(const char *expr, const char* file, int line) { }
3298
+#define ASSERT(expr) (void)(expr)
3299
+#endif
3300
+
3301
+/*
3302
+ * Use that for functions that are conditionally exported for sanity tests but
3303
+ * otherwise static
3304
+ */
3305
+#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3306
+#define EXPORT_FOR_TESTS static
3307
+#else
3308
+#define EXPORT_FOR_TESTS
34663309 #endif
34673310
34683311 __cold
....@@ -3477,7 +3320,7 @@
34773320 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
34783321 unsigned int line, int errno, const char *fmt, ...);
34793322
3480
-const char *btrfs_decode_error(int errno);
3323
+const char * __attribute_const__ btrfs_decode_error(int errno);
34813324
34823325 __cold
34833326 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
....@@ -3493,7 +3336,7 @@
34933336 /* Report first abort since mount */ \
34943337 if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \
34953338 &((trans)->fs_info->fs_state))) { \
3496
- if ((errno) != -EIO) { \
3339
+ if ((errno) != -EIO && (errno) != -EROFS) { \
34973340 WARN(1, KERN_DEBUG \
34983341 "BTRFS: Transaction aborted (error %d)\n", \
34993342 (errno)); \
....@@ -3531,10 +3374,11 @@
35313374 /* compatibility and incompatibility defines */
35323375
35333376 #define btrfs_set_fs_incompat(__fs_info, opt) \
3534
- __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3377
+ __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3378
+ #opt)
35353379
35363380 static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
3537
- u64 flag)
3381
+ u64 flag, const char* name)
35383382 {
35393383 struct btrfs_super_block *disk_super;
35403384 u64 features;
....@@ -3547,18 +3391,20 @@
35473391 if (!(features & flag)) {
35483392 features |= flag;
35493393 btrfs_set_super_incompat_flags(disk_super, features);
3550
- btrfs_info(fs_info, "setting %llu feature flag",
3551
- flag);
3394
+ btrfs_info(fs_info,
3395
+ "setting incompat feature flag for %s (0x%llx)",
3396
+ name, flag);
35523397 }
35533398 spin_unlock(&fs_info->super_lock);
35543399 }
35553400 }
35563401
35573402 #define btrfs_clear_fs_incompat(__fs_info, opt) \
3558
- __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3403
+ __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3404
+ #opt)
35593405
35603406 static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
3561
- u64 flag)
3407
+ u64 flag, const char* name)
35623408 {
35633409 struct btrfs_super_block *disk_super;
35643410 u64 features;
....@@ -3571,8 +3417,9 @@
35713417 if (features & flag) {
35723418 features &= ~flag;
35733419 btrfs_set_super_incompat_flags(disk_super, features);
3574
- btrfs_info(fs_info, "clearing %llu feature flag",
3575
- flag);
3420
+ btrfs_info(fs_info,
3421
+ "clearing incompat feature flag for %s (0x%llx)",
3422
+ name, flag);
35763423 }
35773424 spin_unlock(&fs_info->super_lock);
35783425 }
....@@ -3589,10 +3436,11 @@
35893436 }
35903437
35913438 #define btrfs_set_fs_compat_ro(__fs_info, opt) \
3592
- __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3439
+ __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3440
+ #opt)
35933441
35943442 static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info,
3595
- u64 flag)
3443
+ u64 flag, const char *name)
35963444 {
35973445 struct btrfs_super_block *disk_super;
35983446 u64 features;
....@@ -3605,18 +3453,20 @@
36053453 if (!(features & flag)) {
36063454 features |= flag;
36073455 btrfs_set_super_compat_ro_flags(disk_super, features);
3608
- btrfs_info(fs_info, "setting %llu ro feature flag",
3609
- flag);
3456
+ btrfs_info(fs_info,
3457
+ "setting compat-ro feature flag for %s (0x%llx)",
3458
+ name, flag);
36103459 }
36113460 spin_unlock(&fs_info->super_lock);
36123461 }
36133462 }
36143463
36153464 #define btrfs_clear_fs_compat_ro(__fs_info, opt) \
3616
- __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3465
+ __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3466
+ #opt)
36173467
36183468 static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
3619
- u64 flag)
3469
+ u64 flag, const char *name)
36203470 {
36213471 struct btrfs_super_block *disk_super;
36223472 u64 features;
....@@ -3629,8 +3479,9 @@
36293479 if (features & flag) {
36303480 features &= ~flag;
36313481 btrfs_set_super_compat_ro_flags(disk_super, features);
3632
- btrfs_info(fs_info, "clearing %llu ro feature flag",
3633
- flag);
3482
+ btrfs_info(fs_info,
3483
+ "clearing compat-ro feature flag for %s (0x%llx)",
3484
+ name, flag);
36343485 }
36353486 spin_unlock(&fs_info->super_lock);
36363487 }
....@@ -3669,7 +3520,7 @@
36693520 int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
36703521 struct btrfs_root *root);
36713522 int btrfs_recover_relocation(struct btrfs_root *root);
3672
-int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
3523
+int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len);
36733524 int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
36743525 struct btrfs_root *root, struct extent_buffer *buf,
36753526 struct extent_buffer *cow);
....@@ -3677,6 +3528,10 @@
36773528 u64 *bytes_to_reserve);
36783529 int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
36793530 struct btrfs_pending_snapshot *pending);
3531
+int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info);
3532
+struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info,
3533
+ u64 bytenr);
3534
+int btrfs_should_ignore_reloc_root(struct btrfs_root *root);
36803535
36813536 /* scrub.c */
36823537 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
....@@ -3685,8 +3540,7 @@
36853540 void btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
36863541 void btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
36873542 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);
3543
+int btrfs_scrub_cancel_dev(struct btrfs_device *dev);
36903544 int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
36913545 struct btrfs_scrub_progress *progress);
36923546 static inline void btrfs_init_full_stripe_locks_tree(
....@@ -3720,6 +3574,8 @@
37203574 int btrfs_reada_wait(void *handle);
37213575 void btrfs_reada_detach(void *handle);
37223576 int btree_readahead_hook(struct extent_buffer *eb, int err);
3577
+void btrfs_reada_remove_dev(struct btrfs_device *dev);
3578
+void btrfs_reada_undo_remove_dev(struct btrfs_device *dev);
37233579
37243580 static inline int is_fstree(u64 rootid)
37253581 {
....@@ -3735,41 +3591,20 @@
37353591 return signal_pending(current);
37363592 }
37373593
3594
+#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
3595
+
37383596 /* Sanity test specific functions */
37393597 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
37403598 void btrfs_test_destroy_inode(struct inode *inode);
3741
-#endif
3742
-
37433599 static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
37443600 {
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
3601
+ return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
3602
+}
3603
+#else
3604
+static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
3605
+{
37503606 return 0;
37513607 }
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
-}
3608
+#endif
37743609
37753610 #endif