hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/btrfs/ctree.h
....@@ -16,9 +16,9 @@
1616 #include <linux/backing-dev.h>
1717 #include <linux/wait.h>
1818 #include <linux/slab.h>
19
-#include <linux/kobject.h>
2019 #include <trace/events/btrfs.h>
2120 #include <asm/kmap_types.h>
21
+#include <asm/unaligned.h>
2222 #include <linux/pagemap.h>
2323 #include <linux/btrfs.h>
2424 #include <linux/btrfs_tree.h>
....@@ -28,29 +28,39 @@
2828 #include <linux/dynamic_debug.h>
2929 #include <linux/refcount.h>
3030 #include <linux/crc32c.h>
31
+#include "extent-io-tree.h"
3132 #include "extent_io.h"
3233 #include "extent_map.h"
3334 #include "async-thread.h"
35
+#include "block-rsv.h"
36
+#include "locking.h"
3437
3538 struct btrfs_trans_handle;
3639 struct btrfs_transaction;
3740 struct btrfs_pending_snapshot;
41
+struct btrfs_delayed_ref_root;
42
+struct btrfs_space_info;
43
+struct btrfs_block_group;
3844 extern struct kmem_cache *btrfs_trans_handle_cachep;
3945 extern struct kmem_cache *btrfs_bit_radix_cachep;
4046 extern struct kmem_cache *btrfs_path_cachep;
4147 extern struct kmem_cache *btrfs_free_space_cachep;
4248 extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
4349 struct btrfs_ordered_sum;
44
-
45
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
46
-#define STATIC noinline
47
-#else
48
-#define STATIC static noinline
49
-#endif
50
+struct btrfs_ref;
5051
5152 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
5253
53
-#define BTRFS_MAX_MIRRORS 3
54
+/*
55
+ * Maximum number of mirrors that can be available for all profiles counting
56
+ * the target device of dev-replace as one. During an active device replace
57
+ * procedure, the target device of the copy operation is a mirror for the
58
+ * filesystem data as well that can be used to read data in order to repair
59
+ * read errors on other disks.
60
+ *
61
+ * Current value is derived from RAID1C4 with 4 copies.
62
+ */
63
+#define BTRFS_MAX_MIRRORS (4 + 1)
5464
5565 #define BTRFS_MAX_LEVEL 8
5666
....@@ -75,9 +85,6 @@
7585 */
7686 #define BTRFS_LINK_MAX 65535U
7787
78
-/* four bytes for CRC32 */
79
-static const int btrfs_csum_sizes[] = { 4 };
80
-
8188 #define BTRFS_EMPTY_DIR_SIZE 0
8289
8390 /* ioprio of readahead is set to idle */
....@@ -95,6 +102,14 @@
95102
96103 #define BTRFS_MAX_EXTENT_SIZE SZ_128M
97104
105
+/*
106
+ * Deltas are an effective way to populate global statistics. Give macro names
107
+ * to make it clear what we're doing. An example is discard_extents in
108
+ * btrfs_free_space_ctl.
109
+ */
110
+#define BTRFS_STAT_NR_ENTRIES 2
111
+#define BTRFS_STAT_CURR 0
112
+#define BTRFS_STAT_PREV 1
98113
99114 /*
100115 * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
....@@ -104,10 +119,6 @@
104119 return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
105120 }
106121
107
-struct btrfs_mapping_tree {
108
- struct extent_map_tree map_tree;
109
-};
110
-
111122 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
112123 {
113124 BUG_ON(num_stripes == 0);
....@@ -116,13 +127,26 @@
116127 }
117128
118129 /*
119
- * File system states
130
+ * Runtime (in-memory) states of filesystem
120131 */
121
-#define BTRFS_FS_STATE_ERROR 0
122
-#define BTRFS_FS_STATE_REMOUNTING 1
123
-#define BTRFS_FS_STATE_TRANS_ABORTED 2
124
-#define BTRFS_FS_STATE_DEV_REPLACING 3
125
-#define BTRFS_FS_STATE_DUMMY_FS_INFO 4
132
+enum {
133
+ /* Global indicator of serious filesystem errors */
134
+ BTRFS_FS_STATE_ERROR,
135
+ /*
136
+ * Filesystem is being remounted, allow to skip some operations, like
137
+ * defrag
138
+ */
139
+ BTRFS_FS_STATE_REMOUNTING,
140
+ /* Track if a transaction abort has been reported on this filesystem */
141
+ BTRFS_FS_STATE_TRANS_ABORTED,
142
+ /*
143
+ * Bio operations should be blocked on this filesystem because a source
144
+ * or target device is being destroyed as part of a device replace
145
+ */
146
+ BTRFS_FS_STATE_DEV_REPLACING,
147
+ /* The btrfs_fs_info created for self-tests */
148
+ BTRFS_FS_STATE_DUMMY_FS_INFO,
149
+};
126150
127151 #define BTRFS_BACKREF_REV_MAX 256
128152 #define BTRFS_BACKREF_REV_SHIFT 56
....@@ -202,9 +226,10 @@
202226 * it currently lacks any block count etc etc
203227 */
204228 struct btrfs_super_block {
205
- u8 csum[BTRFS_CSUM_SIZE];
206229 /* the first 4 fields must match struct btrfs_header */
207
- u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
230
+ u8 csum[BTRFS_CSUM_SIZE];
231
+ /* FS specific UUID, visible to user */
232
+ u8 fsid[BTRFS_FSID_SIZE];
208233 __le64 bytenr; /* this block number */
209234 __le64 flags;
210235
....@@ -241,8 +266,11 @@
241266 __le64 cache_generation;
242267 __le64 uuid_tree_generation;
243268
269
+ /* the UUID written into btree blocks */
270
+ u8 metadata_uuid[BTRFS_FSID_SIZE];
271
+
244272 /* future expansion */
245
- __le64 reserved[30];
273
+ __le64 reserved[28];
246274 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
247275 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
248276 } __attribute__ ((__packed__));
....@@ -272,7 +300,9 @@
272300 BTRFS_FEATURE_INCOMPAT_RAID56 | \
273301 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
274302 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
275
- BTRFS_FEATURE_INCOMPAT_NO_HOLES)
303
+ BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
304
+ BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
305
+ BTRFS_FEATURE_INCOMPAT_RAID1C34)
276306
277307 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
278308 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
....@@ -323,7 +353,7 @@
323353 * The slots array records the index of the item or block pointer
324354 * used while walking the tree.
325355 */
326
-enum { READA_NONE = 0, READA_BACK, READA_FORWARD };
356
+enum { READA_NONE, READA_BACK, READA_FORWARD };
327357 struct btrfs_path {
328358 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
329359 int slots[BTRFS_MAX_LEVEL];
....@@ -344,6 +374,7 @@
344374 unsigned int search_commit_root:1;
345375 unsigned int need_commit_sem:1;
346376 unsigned int skip_release_on_error:1;
377
+ unsigned int recurse:1;
347378 };
348379 #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \
349380 sizeof(struct btrfs_item))
....@@ -367,122 +398,12 @@
367398 struct btrfs_device *tgtdev;
368399
369400 struct mutex lock_finishing_cancel_unmount;
370
- rwlock_t lock;
371
- atomic_t read_locks;
372
- atomic_t blocking_readers;
373
- wait_queue_head_t read_lock_wq;
401
+ struct rw_semaphore rwsem;
374402
375403 struct btrfs_scrub_progress scrub_progress;
376
-};
377404
378
-/* For raid type sysfs entries */
379
-struct raid_kobject {
380
- u64 flags;
381
- struct kobject kobj;
382
- struct list_head list;
383
-};
384
-
385
-struct btrfs_space_info {
386
- spinlock_t lock;
387
-
388
- u64 total_bytes; /* total bytes in the space,
389
- this doesn't take mirrors into account */
390
- u64 bytes_used; /* total bytes used,
391
- this doesn't take mirrors into account */
392
- u64 bytes_pinned; /* total bytes pinned, will be freed when the
393
- transaction finishes */
394
- u64 bytes_reserved; /* total bytes the allocator has reserved for
395
- current allocations */
396
- u64 bytes_may_use; /* number of bytes that may be used for
397
- delalloc/allocations */
398
- u64 bytes_readonly; /* total bytes that are read only */
399
-
400
- u64 max_extent_size; /* This will hold the maximum extent size of
401
- the space info if we had an ENOSPC in the
402
- allocator. */
403
-
404
- unsigned int full:1; /* indicates that we cannot allocate any more
405
- chunks for this space */
406
- unsigned int chunk_alloc:1; /* set if we are allocating a chunk */
407
-
408
- unsigned int flush:1; /* set if we are trying to make space */
409
-
410
- unsigned int force_alloc; /* set if we need to force a chunk
411
- alloc for this space */
412
-
413
- u64 disk_used; /* total bytes used on disk */
414
- u64 disk_total; /* total bytes on disk, takes mirrors into
415
- account */
416
-
417
- u64 flags;
418
-
419
- /*
420
- * bytes_pinned is kept in line with what is actually pinned, as in
421
- * we've called update_block_group and dropped the bytes_used counter
422
- * and increased the bytes_pinned counter. However this means that
423
- * bytes_pinned does not reflect the bytes that will be pinned once the
424
- * delayed refs are flushed, so this counter is inc'ed every time we
425
- * call btrfs_free_extent so it is a realtime count of what will be
426
- * freed once the transaction is committed. It will be zeroed every
427
- * time the transaction commits.
428
- */
429
- struct percpu_counter total_bytes_pinned;
430
-
431
- struct list_head list;
432
- /* Protected by the spinlock 'lock'. */
433
- struct list_head ro_bgs;
434
- struct list_head priority_tickets;
435
- struct list_head tickets;
436
- /*
437
- * tickets_id just indicates the next ticket will be handled, so note
438
- * it's not stored per ticket.
439
- */
440
- u64 tickets_id;
441
-
442
- struct rw_semaphore groups_sem;
443
- /* for block groups in our same type */
444
- struct list_head block_groups[BTRFS_NR_RAID_TYPES];
445
- wait_queue_head_t wait;
446
-
447
- struct kobject kobj;
448
- struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
449
-};
450
-
451
-#define BTRFS_BLOCK_RSV_GLOBAL 1
452
-#define BTRFS_BLOCK_RSV_DELALLOC 2
453
-#define BTRFS_BLOCK_RSV_TRANS 3
454
-#define BTRFS_BLOCK_RSV_CHUNK 4
455
-#define BTRFS_BLOCK_RSV_DELOPS 5
456
-#define BTRFS_BLOCK_RSV_EMPTY 6
457
-#define BTRFS_BLOCK_RSV_TEMP 7
458
-
459
-struct btrfs_block_rsv {
460
- u64 size;
461
- u64 reserved;
462
- struct btrfs_space_info *space_info;
463
- spinlock_t lock;
464
- unsigned short full;
465
- unsigned short type;
466
- unsigned short failfast;
467
-
468
- /*
469
- * Qgroup equivalent for @size @reserved
470
- *
471
- * Unlike normal @size/@reserved for inode rsv, qgroup doesn't care
472
- * about things like csum size nor how many tree blocks it will need to
473
- * reserve.
474
- *
475
- * Qgroup cares more about net change of the extent usage.
476
- *
477
- * So for one newly inserted file extent, in worst case it will cause
478
- * leaf split and level increase, nodesize for each file extent is
479
- * already too much.
480
- *
481
- * In short, qgroup_size/reserved is the upper limit of possible needed
482
- * qgroup metadata reservation.
483
- */
484
- u64 qgroup_rsv_size;
485
- u64 qgroup_rsv_reserved;
405
+ struct percpu_counter bio_counter;
406
+ wait_queue_head_t replace_wait;
486407 };
487408
488409 /*
....@@ -504,7 +425,7 @@
504425 /* We did a full search and couldn't create a cluster */
505426 bool fragmented;
506427
507
- struct btrfs_block_group_cache *block_group;
428
+ struct btrfs_block_group *block_group;
508429 /*
509430 * when a cluster is allocated from a block group, we put the
510431 * cluster onto a list in the block group so that it can
....@@ -514,45 +435,11 @@
514435 };
515436
516437 enum btrfs_caching_type {
517
- BTRFS_CACHE_NO = 0,
518
- BTRFS_CACHE_STARTED = 1,
519
- BTRFS_CACHE_FAST = 2,
520
- BTRFS_CACHE_FINISHED = 3,
521
- BTRFS_CACHE_ERROR = 4,
522
-};
523
-
524
-enum btrfs_disk_cache_state {
525
- BTRFS_DC_WRITTEN = 0,
526
- BTRFS_DC_ERROR = 1,
527
- BTRFS_DC_CLEAR = 2,
528
- BTRFS_DC_SETUP = 3,
529
-};
530
-
531
-struct btrfs_caching_control {
532
- struct list_head list;
533
- struct mutex mutex;
534
- wait_queue_head_t wait;
535
- struct btrfs_work work;
536
- struct btrfs_block_group_cache *block_group;
537
- u64 progress;
538
- refcount_t count;
539
-};
540
-
541
-/* Once caching_thread() finds this much free space, it will wake up waiters. */
542
-#define CACHING_CTL_WAKE_UP SZ_2M
543
-
544
-struct btrfs_io_ctl {
545
- void *cur, *orig;
546
- struct page *page;
547
- struct page **pages;
548
- struct btrfs_fs_info *fs_info;
549
- struct inode *inode;
550
- unsigned long size;
551
- int index;
552
- int num_pages;
553
- int entries;
554
- int bitmaps;
555
- unsigned check_crcs:1;
438
+ BTRFS_CACHE_NO,
439
+ BTRFS_CACHE_STARTED,
440
+ BTRFS_CACHE_FAST,
441
+ BTRFS_CACHE_FINISHED,
442
+ BTRFS_CACHE_ERROR,
556443 };
557444
558445 /*
....@@ -563,118 +450,34 @@
563450 struct mutex lock;
564451 };
565452
566
-struct btrfs_block_group_cache {
567
- struct btrfs_key key;
568
- struct btrfs_block_group_item item;
569
- struct btrfs_fs_info *fs_info;
570
- struct inode *inode;
453
+/* Discard control. */
454
+/*
455
+ * Async discard uses multiple lists to differentiate the discard filter
456
+ * parameters. Index 0 is for completely free block groups where we need to
457
+ * ensure the entire block group is trimmed without being lossy. Indices
458
+ * afterwards represent monotonically decreasing discard filter sizes to
459
+ * prioritize what should be discarded next.
460
+ */
461
+#define BTRFS_NR_DISCARD_LISTS 3
462
+#define BTRFS_DISCARD_INDEX_UNUSED 0
463
+#define BTRFS_DISCARD_INDEX_START 1
464
+
465
+struct btrfs_discard_ctl {
466
+ struct workqueue_struct *discard_workers;
467
+ struct delayed_work work;
571468 spinlock_t lock;
572
- u64 pinned;
573
- u64 reserved;
574
- u64 delalloc_bytes;
575
- u64 bytes_super;
576
- u64 flags;
577
- u64 cache_generation;
578
-
579
- /*
580
- * If the free space extent count exceeds this number, convert the block
581
- * group to bitmaps.
582
- */
583
- u32 bitmap_high_thresh;
584
-
585
- /*
586
- * If the free space extent count drops below this number, convert the
587
- * block group back to extents.
588
- */
589
- u32 bitmap_low_thresh;
590
-
591
- /*
592
- * It is just used for the delayed data space allocation because
593
- * only the data space allocation and the relative metadata update
594
- * can be done cross the transaction.
595
- */
596
- struct rw_semaphore data_rwsem;
597
-
598
- /* for raid56, this is a full stripe, without parity */
599
- unsigned long full_stripe_len;
600
-
601
- unsigned int ro;
602
- unsigned int iref:1;
603
- unsigned int has_caching_ctl:1;
604
- unsigned int removed:1;
605
-
606
- int disk_cache_state;
607
-
608
- /* cache tracking stuff */
609
- int cached;
610
- struct btrfs_caching_control *caching_ctl;
611
- u64 last_byte_to_unpin;
612
-
613
- struct btrfs_space_info *space_info;
614
-
615
- /* free space cache stuff */
616
- struct btrfs_free_space_ctl *free_space_ctl;
617
-
618
- /* block group cache stuff */
619
- struct rb_node cache_node;
620
-
621
- /* for block groups in the same raid type */
622
- struct list_head list;
623
-
624
- /* usage count */
625
- atomic_t count;
626
-
627
- /* List of struct btrfs_free_clusters for this block group.
628
- * Today it will only have one thing on it, but that may change
629
- */
630
- struct list_head cluster_list;
631
-
632
- /* For delayed block group creation or deletion of empty block groups */
633
- struct list_head bg_list;
634
-
635
- /* For read-only block groups */
636
- struct list_head ro_list;
637
-
638
- atomic_t trimming;
639
-
640
- /* For dirty block groups */
641
- struct list_head dirty_list;
642
- struct list_head io_list;
643
-
644
- struct btrfs_io_ctl io_ctl;
645
-
646
- /*
647
- * Incremented when doing extent allocations and holding a read lock
648
- * on the space_info's groups_sem semaphore.
649
- * Decremented when an ordered extent that represents an IO against this
650
- * block group's range is created (after it's added to its inode's
651
- * root's list of ordered extents) or immediately after the allocation
652
- * if it's a metadata extent or fallocate extent (for these cases we
653
- * don't create ordered extents).
654
- */
655
- atomic_t reservations;
656
-
657
- /*
658
- * Incremented while holding the spinlock *lock* by a task checking if
659
- * it can perform a nocow write (incremented if the value for the *ro*
660
- * field is 0). Decremented by such tasks once they create an ordered
661
- * extent or before that if some error happens before reaching that step.
662
- * This is to prevent races between block group relocation and nocow
663
- * writes through direct IO.
664
- */
665
- atomic_t nocow_writers;
666
-
667
- /* Lock for free space tree operations. */
668
- struct mutex free_space_lock;
669
-
670
- /*
671
- * Does the block group need to be added to the free space tree?
672
- * Protected by free_space_lock.
673
- */
674
- int needs_free_space;
675
-
676
- /* Record locked full stripes for RAID5/6 block group */
677
- struct btrfs_full_stripe_locks_tree full_stripe_locks_root;
469
+ struct btrfs_block_group *block_group;
470
+ struct list_head discard_list[BTRFS_NR_DISCARD_LISTS];
471
+ u64 prev_discard;
472
+ atomic_t discardable_extents;
473
+ atomic64_t discardable_bytes;
474
+ u64 max_discard_size;
475
+ unsigned long delay;
476
+ u32 iops_limit;
477
+ u32 kbps_limit;
478
+ u64 discard_extent_bytes;
479
+ u64 discard_bitmap_bytes;
480
+ atomic64_t discard_bytes_saved;
678481 };
679482
680483 /* delayed seq elem */
....@@ -692,23 +495,7 @@
692495 ORPHAN_CLEANUP_DONE = 2,
693496 };
694497
695
-/* used by the raid56 code to lock stripes for read/modify/write */
696
-struct btrfs_stripe_hash {
697
- struct list_head hash_list;
698
- spinlock_t lock;
699
-};
700
-
701
-/* used by the raid56 code to lock stripes for read/modify/write */
702
-struct btrfs_stripe_hash_table {
703
- struct list_head stripe_cache;
704
- spinlock_t cache_lock;
705
- int cache_size;
706
- struct btrfs_stripe_hash table[];
707
-};
708
-
709
-#define BTRFS_STRIPE_HASH_TABLE_BITS 11
710
-
711
-void btrfs_init_async_reclaim_work(struct work_struct *work);
498
+void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
712499
713500 /* fs_info */
714501 struct reloc_control;
....@@ -717,41 +504,83 @@
717504 struct btrfs_balance_control;
718505 struct btrfs_delayed_root;
719506
720
-#define BTRFS_FS_BARRIER 1
721
-#define BTRFS_FS_CLOSING_START 2
722
-#define BTRFS_FS_CLOSING_DONE 3
723
-#define BTRFS_FS_LOG_RECOVERING 4
724
-#define BTRFS_FS_OPEN 5
725
-#define BTRFS_FS_QUOTA_ENABLED 6
726
-#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9
727
-#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10
728
-#define BTRFS_FS_BTREE_ERR 11
729
-#define BTRFS_FS_LOG1_ERR 12
730
-#define BTRFS_FS_LOG2_ERR 13
731
-#define BTRFS_FS_QUOTA_OVERRIDE 14
732
-/* Used to record internally whether fs has been frozen */
733
-#define BTRFS_FS_FROZEN 15
507
+/*
508
+ * Block group or device which contains an active swapfile. Used for preventing
509
+ * unsafe operations while a swapfile is active.
510
+ *
511
+ * These are sorted on (ptr, inode) (note that a block group or device can
512
+ * contain more than one swapfile). We compare the pointer values because we
513
+ * don't actually care what the object is, we just need a quick check whether
514
+ * the object exists in the rbtree.
515
+ */
516
+struct btrfs_swapfile_pin {
517
+ struct rb_node node;
518
+ void *ptr;
519
+ struct inode *inode;
520
+ /*
521
+ * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr
522
+ * points to a struct btrfs_device.
523
+ */
524
+ bool is_block_group;
525
+ /*
526
+ * Only used when 'is_block_group' is true and it is the number of
527
+ * extents used by a swapfile for this block group ('ptr' field).
528
+ */
529
+ int bg_extent_count;
530
+};
531
+
532
+enum {
533
+ BTRFS_FS_BARRIER,
534
+ BTRFS_FS_CLOSING_START,
535
+ BTRFS_FS_CLOSING_DONE,
536
+ BTRFS_FS_LOG_RECOVERING,
537
+ BTRFS_FS_OPEN,
538
+ BTRFS_FS_QUOTA_ENABLED,
539
+ BTRFS_FS_UPDATE_UUID_TREE_GEN,
540
+ BTRFS_FS_CREATING_FREE_SPACE_TREE,
541
+ BTRFS_FS_BTREE_ERR,
542
+ BTRFS_FS_LOG1_ERR,
543
+ BTRFS_FS_LOG2_ERR,
544
+ BTRFS_FS_QUOTA_OVERRIDE,
545
+ /* Used to record internally whether fs has been frozen */
546
+ BTRFS_FS_FROZEN,
547
+ /*
548
+ * Indicate that balance has been set up from the ioctl and is in the
549
+ * main phase. The fs_info::balance_ctl is initialized.
550
+ * Set and cleared while holding fs_info::balance_mutex.
551
+ */
552
+ BTRFS_FS_BALANCE_RUNNING,
553
+
554
+ /* Indicate that the cleaner thread is awake and doing something. */
555
+ BTRFS_FS_CLEANER_RUNNING,
556
+
557
+ /*
558
+ * The checksumming has an optimized version and is considered fast,
559
+ * so we don't need to offload checksums to workqueues.
560
+ */
561
+ BTRFS_FS_CSUM_IMPL_FAST,
562
+
563
+ /* Indicate that the discard workqueue can service discards. */
564
+ BTRFS_FS_DISCARD_RUNNING,
565
+
566
+ /* Indicate that we can't trust the free space tree for caching yet */
567
+ BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
568
+};
734569
735570 /*
736
- * Indicate that a whole-filesystem exclusive operation is running
737
- * (device replace, resize, device add/delete, balance)
571
+ * Exclusive operations (device replace, resize, device add/remove, balance)
738572 */
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
573
+enum btrfs_exclusive_operation {
574
+ BTRFS_EXCLOP_NONE,
575
+ BTRFS_EXCLOP_BALANCE,
576
+ BTRFS_EXCLOP_DEV_ADD,
577
+ BTRFS_EXCLOP_DEV_REMOVE,
578
+ BTRFS_EXCLOP_DEV_REPLACE,
579
+ BTRFS_EXCLOP_RESIZE,
580
+ BTRFS_EXCLOP_SWAP_ACTIVATE,
581
+};
752582
753583 struct btrfs_fs_info {
754
- u8 fsid[BTRFS_FSID_SIZE];
755584 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
756585 unsigned long flags;
757586 struct btrfs_root *extent_root;
....@@ -763,6 +592,7 @@
763592 struct btrfs_root *quota_root;
764593 struct btrfs_root *uuid_root;
765594 struct btrfs_root *free_space_root;
595
+ struct btrfs_root *data_reloc_root;
766596
767597 /* the log root tree is a directory of all the other log roots */
768598 struct btrfs_root *log_root_tree;
....@@ -778,11 +608,11 @@
778608 /* keep track of unallocated space */
779609 atomic64_t free_chunk_space;
780610
781
- struct extent_io_tree freed_extents[2];
782
- struct extent_io_tree *pinned_extents;
611
+ /* Track ranges which are used by log trees blocks/logged data extents */
612
+ struct extent_io_tree excluded_extents;
783613
784614 /* logical->physical extent mapping */
785
- struct btrfs_mapping_tree mapping_tree;
615
+ struct extent_map_tree mapping_tree;
786616
787617 /*
788618 * block reservation for extent, checksum, root tree and
....@@ -795,6 +625,8 @@
795625 struct btrfs_block_rsv chunk_block_rsv;
796626 /* block reservation for delayed operations */
797627 struct btrfs_block_rsv delayed_block_rsv;
628
+ /* block reservation for delayed refs */
629
+ struct btrfs_block_rsv delayed_refs_rsv;
798630
799631 struct btrfs_block_rsv empty_block_rsv;
800632
....@@ -876,7 +708,6 @@
876708 struct rw_semaphore cleanup_work_sem;
877709
878710 struct rw_semaphore subvol_sem;
879
- struct srcu_struct subvol_srcu;
880711
881712 spinlock_t trans_lock;
882713 /*
....@@ -891,7 +722,8 @@
891722
892723 spinlock_t delayed_iput_lock;
893724 struct list_head delayed_iputs;
894
- struct mutex cleaner_delayed_iput_mutex;
725
+ atomic_t nr_delayed_iputs;
726
+ wait_queue_head_t delayed_iputs_wait;
895727
896728 atomic64_t tree_mod_seq;
897729
....@@ -937,12 +769,10 @@
937769 struct btrfs_workqueue *endio_workers;
938770 struct btrfs_workqueue *endio_meta_workers;
939771 struct btrfs_workqueue *endio_raid56_workers;
940
- struct btrfs_workqueue *endio_repair_workers;
941772 struct btrfs_workqueue *rmw_workers;
942773 struct btrfs_workqueue *endio_meta_write_workers;
943774 struct btrfs_workqueue *endio_write_workers;
944775 struct btrfs_workqueue *endio_freespace_worker;
945
- struct btrfs_workqueue *submit_workers;
946776 struct btrfs_workqueue *caching_workers;
947777 struct btrfs_workqueue *readahead_workers;
948778
....@@ -954,21 +784,19 @@
954784 struct btrfs_workqueue *fixup_workers;
955785 struct btrfs_workqueue *delayed_workers;
956786
957
- /* the extent workers do delayed refs on the extent allocation tree */
958
- struct btrfs_workqueue *extent_workers;
959787 struct task_struct *transaction_kthread;
960788 struct task_struct *cleaner_kthread;
961789 u32 thread_pool_size;
962790
963791 struct kobject *space_info_kobj;
964
- struct list_head pending_raid_kobjs;
965
- spinlock_t pending_raid_kobjs_lock; /* uncontended */
792
+ struct kobject *qgroups_kobj;
966793
967794 u64 total_pinned;
968795
969796 /* used to keep from writing metadata until there is a nice batch */
970797 struct percpu_counter dirty_metadata_bytes;
971798 struct percpu_counter delalloc_bytes;
799
+ struct percpu_counter dio_bytes;
972800 s32 dirty_metadata_batch;
973801 s32 delalloc_batch;
974802
....@@ -1029,11 +857,16 @@
1029857 atomic_t scrubs_paused;
1030858 atomic_t scrub_cancel_req;
1031859 wait_queue_head_t scrub_pause_wait;
1032
- int scrub_workers_refcnt;
860
+ /*
861
+ * The worker pointers are NULL iff the refcount is 0, ie. scrub is not
862
+ * running.
863
+ */
864
+ refcount_t scrub_workers_refcnt;
1033865 struct btrfs_workqueue *scrub_workers;
1034866 struct btrfs_workqueue *scrub_wr_completion_workers;
1035
- struct btrfs_workqueue *scrub_nocow_workers;
1036867 struct btrfs_workqueue *scrub_parity_workers;
868
+
869
+ struct btrfs_discard_ctl discard_ctl;
1037870
1038871 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
1039872 u32 check_integrity_print_mask;
....@@ -1043,10 +876,7 @@
1043876
1044877 /* holds configuration and tracking. Protected by qgroup_lock */
1045878 struct rb_root qgroup_tree;
1046
- struct rb_root qgroup_op_tree;
1047879 spinlock_t qgroup_lock;
1048
- spinlock_t qgroup_op_lock;
1049
- atomic_t qgroup_op_seq;
1050880
1051881 /*
1052882 * used to avoid frequently calling ulist_alloc()/ulist_free()
....@@ -1054,7 +884,10 @@
1054884 */
1055885 struct ulist *qgroup_ulist;
1056886
1057
- /* protect user change for quota operations */
887
+ /*
888
+ * Protect user change for quota operations. If a transaction is needed,
889
+ * it must be started before locking this lock.
890
+ */
1058891 struct mutex qgroup_ioctl_lock;
1059892
1060893 /* list of dirty qgroups to be written at next commit */
....@@ -1093,36 +926,49 @@
1093926 /* device replace state */
1094927 struct btrfs_dev_replace dev_replace;
1095928
1096
- struct percpu_counter bio_counter;
1097
- wait_queue_head_t replace_wait;
1098
-
1099929 struct semaphore uuid_tree_rescan_sem;
1100930
1101931 /* Used to reclaim the metadata space in the background. */
1102932 struct work_struct async_reclaim_work;
933
+ struct work_struct async_data_reclaim_work;
1103934
1104935 spinlock_t unused_bgs_lock;
1105936 struct list_head unused_bgs;
1106937 struct mutex unused_bg_unpin_mutex;
1107938 struct mutex delete_unused_bgs_mutex;
1108939
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
-
1118940 /* Cached block sizes */
1119941 u32 nodesize;
1120942 u32 sectorsize;
1121943 u32 stripesize;
1122944
945
+ /* Block groups and devices containing active swapfiles. */
946
+ spinlock_t swapfile_pins_lock;
947
+ struct rb_root swapfile_pins;
948
+
949
+ struct crypto_shash *csum_shash;
950
+
951
+ /*
952
+ * Number of send operations in progress.
953
+ * Updated while holding fs_info::balance_mutex.
954
+ */
955
+ int send_in_progress;
956
+
957
+ /* Type of exclusive operation running */
958
+ unsigned long exclusive_operation;
959
+
1123960 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
1124961 spinlock_t ref_verify_lock;
1125962 struct rb_root block_tree;
963
+#endif
964
+
965
+#ifdef CONFIG_BTRFS_DEBUG
966
+ struct kobject *debug_kobj;
967
+ struct kobject *discard_debug_kobj;
968
+ struct list_head allocated_roots;
969
+
970
+ spinlock_t eb_leak_lock;
971
+ struct list_head allocated_ebs;
1126972 #endif
1127973 };
1128974
....@@ -1131,30 +977,72 @@
1131977 return sb->s_fs_info;
1132978 }
1133979
1134
-struct btrfs_subvolume_writers {
1135
- struct percpu_counter counter;
1136
- wait_queue_head_t wait;
1137
-};
1138
-
1139980 /*
1140981 * The state of btrfs root
1141982 */
983
+enum {
984
+ /*
985
+ * btrfs_record_root_in_trans is a multi-step process, and it can race
986
+ * with the balancing code. But the race is very small, and only the
987
+ * first time the root is added to each transaction. So IN_TRANS_SETUP
988
+ * is used to tell us when more checks are required
989
+ */
990
+ BTRFS_ROOT_IN_TRANS_SETUP,
991
+
992
+ /*
993
+ * Set if tree blocks of this root can be shared by other roots.
994
+ * Only subvolume trees and their reloc trees have this bit set.
995
+ * Conflicts with TRACK_DIRTY bit.
996
+ *
997
+ * This affects two things:
998
+ *
999
+ * - How balance works
1000
+ * For shareable roots, we need to use reloc tree and do path
1001
+ * replacement for balance, and need various pre/post hooks for
1002
+ * snapshot creation to handle them.
1003
+ *
1004
+ * While for non-shareable trees, we just simply do a tree search
1005
+ * with COW.
1006
+ *
1007
+ * - How dirty roots are tracked
1008
+ * For shareable roots, btrfs_record_root_in_trans() is needed to
1009
+ * track them, while non-subvolume roots have TRACK_DIRTY bit, they
1010
+ * don't need to set this manually.
1011
+ */
1012
+ BTRFS_ROOT_SHAREABLE,
1013
+ BTRFS_ROOT_TRACK_DIRTY,
1014
+ BTRFS_ROOT_IN_RADIX,
1015
+ BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
1016
+ BTRFS_ROOT_DEFRAG_RUNNING,
1017
+ BTRFS_ROOT_FORCE_COW,
1018
+ BTRFS_ROOT_MULTI_LOG_TASKS,
1019
+ BTRFS_ROOT_DIRTY,
1020
+ BTRFS_ROOT_DELETING,
1021
+
1022
+ /*
1023
+ * Reloc tree is orphan, only kept here for qgroup delayed subtree scan
1024
+ *
1025
+ * Set for the subvolume tree owning the reloc tree.
1026
+ */
1027
+ BTRFS_ROOT_DEAD_RELOC_TREE,
1028
+ /* Mark dead root stored on device whose cleanup needs to be resumed */
1029
+ BTRFS_ROOT_DEAD_TREE,
1030
+ /* The root has a log tree. Used only for subvolume roots. */
1031
+ BTRFS_ROOT_HAS_LOG_TREE,
1032
+ /* Qgroup flushing is in progress */
1033
+ BTRFS_ROOT_QGROUP_FLUSHING,
1034
+};
1035
+
11421036 /*
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
1037
+ * Record swapped tree blocks of a subvolume tree for delayed subtree trace
1038
+ * code. For detail check comment in fs/btrfs/qgroup.c.
11481039 */
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
1040
+struct btrfs_qgroup_swapped_blocks {
1041
+ spinlock_t lock;
1042
+ /* RM_EMPTY_ROOT() of above blocks[] */
1043
+ bool swapped;
1044
+ struct rb_root blocks[BTRFS_MAX_LEVEL];
1045
+};
11581046
11591047 /*
11601048 * in ram representation of the tree. extent_root is used for all allocations
....@@ -1191,8 +1079,10 @@
11911079 wait_queue_head_t log_writer_wait;
11921080 wait_queue_head_t log_commit_wait[2];
11931081 struct list_head log_ctxs[2];
1082
+ /* Used only for log trees of subvolumes, not for the log root tree */
11941083 atomic_t log_writers;
11951084 atomic_t log_commit[2];
1085
+ /* Used only for log trees of subvolumes, not for the log root tree */
11961086 atomic_t log_batch;
11971087 int log_transid;
11981088 /* No matter the commit succeeds or not*/
....@@ -1201,23 +1091,16 @@
12011091 int last_log_commit;
12021092 pid_t log_start_pid;
12031093
1204
- u64 objectid;
12051094 u64 last_trans;
12061095
12071096 u32 type;
12081097
12091098 u64 highest_objectid;
12101099
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;
12171100 struct btrfs_key defrag_progress;
12181101 struct btrfs_key defrag_max;
12191102
1220
- /* the dirty list is only used by non-reference counted roots */
1103
+ /* The dirty list is only used by non-shareable roots */
12211104 struct list_head dirty_list;
12221105
12231106 struct list_head root_list;
....@@ -1273,28 +1156,87 @@
12731156 u64 nr_ordered_extents;
12741157
12751158 /*
1159
+ * Not empty if this subvolume root has gone through tree block swap
1160
+ * (relocation)
1161
+ *
1162
+ * Will be used by reloc_control::dirty_subvol_roots.
1163
+ */
1164
+ struct list_head reloc_dirty_list;
1165
+
1166
+ /*
12761167 * Number of currently running SEND ioctls to prevent
12771168 * manipulation with the read-only status via SUBVOL_SETFLAGS
12781169 */
12791170 int send_in_progress;
1280
- struct btrfs_subvolume_writers *subv_writers;
1281
- atomic_t will_be_snapshotted;
1171
+ /*
1172
+ * Number of currently running deduplication operations that have a
1173
+ * destination inode belonging to this root. Protected by the lock
1174
+ * root_item_lock.
1175
+ */
1176
+ int dedupe_in_progress;
1177
+ /* For exclusion of snapshot creation and nocow writes */
1178
+ struct btrfs_drew_lock snapshot_lock;
1179
+
12821180 atomic_t snapshot_force_cow;
12831181
12841182 /* For qgroup metadata reserved space */
12851183 spinlock_t qgroup_meta_rsv_lock;
12861184 u64 qgroup_meta_rsv_pertrans;
12871185 u64 qgroup_meta_rsv_prealloc;
1186
+ wait_queue_head_t qgroup_flush_wait;
1187
+
1188
+ /* Number of active swapfiles */
1189
+ atomic_t nr_swapfiles;
1190
+
1191
+ /* Record pairs of swapped blocks for qgroup */
1192
+ struct btrfs_qgroup_swapped_blocks swapped_blocks;
1193
+
1194
+ /* Used only by log trees, when logging csum items */
1195
+ struct extent_io_tree log_csum_range;
1196
+
1197
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1198
+ u64 alloc_bytenr;
1199
+#endif
1200
+
1201
+#ifdef CONFIG_BTRFS_DEBUG
1202
+ struct list_head leak_list;
1203
+#endif
1204
+};
1205
+
1206
+/*
1207
+ * Structure that conveys information about an extent that is going to replace
1208
+ * all the extents in a file range.
1209
+ */
1210
+struct btrfs_replace_extent_info {
1211
+ u64 disk_offset;
1212
+ u64 disk_len;
1213
+ u64 data_offset;
1214
+ u64 data_len;
1215
+ u64 file_offset;
1216
+ /* Pointer to a file extent item of type regular or prealloc. */
1217
+ char *extent_buf;
1218
+ /*
1219
+ * Set to true when attempting to replace a file range with a new extent
1220
+ * described by this structure, set to false when attempting to clone an
1221
+ * existing extent into a file range.
1222
+ */
1223
+ bool is_new_extent;
1224
+ /* Meaningful only if is_new_extent is true. */
1225
+ int qgroup_reserved;
1226
+ /*
1227
+ * Meaningful only if is_new_extent is true.
1228
+ * Used to track how many extent items we have already inserted in a
1229
+ * subvolume tree that refer to the extent described by this structure,
1230
+ * so that we know when to create a new delayed ref or update an existing
1231
+ * one.
1232
+ */
1233
+ int insertions;
12881234 };
12891235
12901236 struct btrfs_file_private {
12911237 void *filldir_buf;
12921238 };
12931239
1294
-static inline u32 btrfs_inode_sectorsize(const struct inode *inode)
1295
-{
1296
- return btrfs_sb(inode->i_sb)->sectorsize;
1297
-}
12981240
12991241 static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
13001242 {
....@@ -1342,7 +1284,7 @@
13421284 #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7)
13431285 #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
13441286 #define BTRFS_MOUNT_NOSSD (1 << 9)
1345
-#define BTRFS_MOUNT_DISCARD (1 << 10)
1287
+#define BTRFS_MOUNT_DISCARD_SYNC (1 << 10)
13461288 #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
13471289 #define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
13481290 #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
....@@ -1361,6 +1303,7 @@
13611303 #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)
13621304 #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)
13631305 #define BTRFS_MOUNT_REF_VERIFY (1 << 28)
1306
+#define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29)
13641307
13651308 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
13661309 #define BTRFS_DEFAULT_MAX_INLINE (2048)
....@@ -1372,31 +1315,18 @@
13721315 BTRFS_MOUNT_##opt)
13731316
13741317 #define btrfs_set_and_info(fs_info, opt, fmt, args...) \
1375
-{ \
1318
+do { \
13761319 if (!btrfs_test_opt(fs_info, opt)) \
13771320 btrfs_info(fs_info, fmt, ##args); \
13781321 btrfs_set_opt(fs_info->mount_opt, opt); \
1379
-}
1322
+} while (0)
13801323
13811324 #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \
1382
-{ \
1325
+do { \
13831326 if (btrfs_test_opt(fs_info, opt)) \
13841327 btrfs_info(fs_info, fmt, ##args); \
13851328 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
1329
+} while (0)
14001330
14011331 /*
14021332 * Requests for changes that need to be done during transaction commit.
....@@ -1475,7 +1405,7 @@
14751405 BTRFS_INODE_ROOT_ITEM_INIT)
14761406
14771407 struct btrfs_map_token {
1478
- const struct extent_buffer *eb;
1408
+ struct extent_buffer *eb;
14791409 char *kaddr;
14801410 unsigned long offset;
14811411 };
....@@ -1483,9 +1413,12 @@
14831413 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
14841414 ((bytes) >> (fs_info)->sb->s_blocksize_bits)
14851415
1486
-static inline void btrfs_init_map_token (struct btrfs_map_token *token)
1416
+static inline void btrfs_init_map_token(struct btrfs_map_token *token,
1417
+ struct extent_buffer *eb)
14871418 {
1488
- token->kaddr = NULL;
1419
+ token->eb = eb;
1420
+ token->kaddr = page_address(eb->pages[0]);
1421
+ token->offset = 0;
14891422 }
14901423
14911424 /* some macros to generate set/get functions for the struct fields. This
....@@ -1495,6 +1428,16 @@
14951428 #define le8_to_cpu(v) (v)
14961429 #define cpu_to_le8(v) (v)
14971430 #define __le8 u8
1431
+
1432
+static inline u8 get_unaligned_le8(const void *p)
1433
+{
1434
+ return *(u8 *)p;
1435
+}
1436
+
1437
+static inline void put_unaligned_le8(u8 val, void *p)
1438
+{
1439
+ *(u8 *)p = val;
1440
+}
14981441
14991442 #define read_eb_member(eb, ptr, type, member, result) (\
15001443 read_extent_buffer(eb, (char *)(result), \
....@@ -1509,23 +1452,15 @@
15091452 sizeof(((type *)0)->member)))
15101453
15111454 #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
-}
1455
+u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
1456
+ const void *ptr, unsigned long off); \
1457
+void btrfs_set_token_##bits(struct btrfs_map_token *token, \
1458
+ const void *ptr, unsigned long off, \
1459
+ u##bits val); \
1460
+u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
1461
+ const void *ptr, unsigned long off); \
1462
+void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
1463
+ unsigned long off, u##bits val);
15291464
15301465 DECLARE_BTRFS_SETGET_BITS(8)
15311466 DECLARE_BTRFS_SETGET_BITS(16)
....@@ -1539,53 +1474,49 @@
15391474 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15401475 return btrfs_get_##bits(eb, s, offsetof(type, member)); \
15411476 } \
1542
-static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \
1477
+static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
15431478 u##bits val) \
15441479 { \
15451480 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
15461481 btrfs_set_##bits(eb, s, offsetof(type, member), val); \
15471482 } \
1548
-static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\
1549
- const type *s, \
1550
- struct btrfs_map_token *token) \
1483
+static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
1484
+ const type *s) \
15511485 { \
15521486 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1553
- return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \
1487
+ return btrfs_get_token_##bits(token, s, offsetof(type, member));\
15541488 } \
1555
-static inline void btrfs_set_token_##name(struct extent_buffer *eb, \
1556
- type *s, u##bits val, \
1557
- struct btrfs_map_token *token) \
1489
+static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
1490
+ type *s, u##bits val) \
15581491 { \
15591492 BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1560
- btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \
1493
+ btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
15611494 }
15621495
15631496 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
15641497 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
15651498 { \
15661499 const type *p = page_address(eb->pages[0]); \
1567
- u##bits res = le##bits##_to_cpu(p->member); \
1568
- return res; \
1500
+ return get_unaligned_le##bits(&p->member); \
15691501 } \
1570
-static inline void btrfs_set_##name(struct extent_buffer *eb, \
1502
+static inline void btrfs_set_##name(const struct extent_buffer *eb, \
15711503 u##bits val) \
15721504 { \
15731505 type *p = page_address(eb->pages[0]); \
1574
- p->member = cpu_to_le##bits(val); \
1506
+ put_unaligned_le##bits(val, &p->member); \
15751507 }
15761508
15771509 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
15781510 static inline u##bits btrfs_##name(const type *s) \
15791511 { \
1580
- return le##bits##_to_cpu(s->member); \
1512
+ return get_unaligned_le##bits(&s->member); \
15811513 } \
15821514 static inline void btrfs_set_##name(type *s, u##bits val) \
15831515 { \
1584
- s->member = cpu_to_le##bits(val); \
1516
+ put_unaligned_le##bits(val, &s->member); \
15851517 }
15861518
1587
-
1588
-static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb,
1519
+static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
15891520 struct btrfs_dev_item *s)
15901521 {
15911522 BUILD_BUG_ON(sizeof(u64) !=
....@@ -1593,7 +1524,7 @@
15931524 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
15941525 total_bytes));
15951526 }
1596
-static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb,
1527
+static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
15971528 struct btrfs_dev_item *s,
15981529 u64 val)
15991530 {
....@@ -1697,31 +1628,31 @@
16971628 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
16981629 }
16991630
1700
-static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
1631
+static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
17011632 struct btrfs_chunk *c, int nr)
17021633 {
17031634 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
17041635 }
17051636
1706
-static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
1637
+static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
17071638 struct btrfs_chunk *c, int nr)
17081639 {
17091640 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
17101641 }
17111642
17121643 /* struct btrfs_block_group_item */
1713
-BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
1644
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
17141645 used, 64);
1715
-BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
1646
+BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item,
17161647 used, 64);
1717
-BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
1648
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
17181649 struct btrfs_block_group_item, chunk_objectid, 64);
17191650
1720
-BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
1651
+BTRFS_SETGET_FUNCS(block_group_chunk_objectid,
17211652 struct btrfs_block_group_item, chunk_objectid, 64);
1722
-BTRFS_SETGET_FUNCS(disk_block_group_flags,
1653
+BTRFS_SETGET_FUNCS(block_group_flags,
17231654 struct btrfs_block_group_item, flags, 64);
1724
-BTRFS_SETGET_STACK_FUNCS(block_group_flags,
1655
+BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
17251656 struct btrfs_block_group_item, flags, 64);
17261657
17271658 /* struct btrfs_free_space_info */
....@@ -1783,31 +1714,21 @@
17831714 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
17841715 chunk_offset, 64);
17851716 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
-
17931717 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
17941718 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
17951719 generation, 64);
17961720 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
17971721
1798
-BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1799
-
1800
-
18011722 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
18021723
1803
-static inline void btrfs_tree_block_key(struct extent_buffer *eb,
1724
+static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
18041725 struct btrfs_tree_block_info *item,
18051726 struct btrfs_disk_key *key)
18061727 {
18071728 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
18081729 }
18091730
1810
-static inline void btrfs_set_tree_block_key(struct extent_buffer *eb,
1731
+static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
18111732 struct btrfs_tree_block_info *item,
18121733 struct btrfs_disk_key *key)
18131734 {
....@@ -1845,12 +1766,6 @@
18451766 return 0;
18461767 }
18471768
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
-
18541769 /* struct btrfs_node */
18551770 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
18561771 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
....@@ -1859,7 +1774,7 @@
18591774 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
18601775 generation, 64);
18611776
1862
-static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1777
+static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
18631778 {
18641779 unsigned long ptr;
18651780 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1867,7 +1782,7 @@
18671782 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
18681783 }
18691784
1870
-static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1785
+static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
18711786 int nr, u64 val)
18721787 {
18731788 unsigned long ptr;
....@@ -1876,7 +1791,7 @@
18761791 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
18771792 }
18781793
1879
-static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1794
+static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
18801795 {
18811796 unsigned long ptr;
18821797 ptr = offsetof(struct btrfs_node, ptrs) +
....@@ -1884,7 +1799,7 @@
18841799 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
18851800 }
18861801
1887
-static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1802
+static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
18881803 int nr, u64 val)
18891804 {
18901805 unsigned long ptr;
....@@ -1902,7 +1817,7 @@
19021817 void btrfs_node_key(const struct extent_buffer *eb,
19031818 struct btrfs_disk_key *disk_key, int nr);
19041819
1905
-static inline void btrfs_set_node_key(struct extent_buffer *eb,
1820
+static inline void btrfs_set_node_key(const struct extent_buffer *eb,
19061821 struct btrfs_disk_key *disk_key, int nr)
19071822 {
19081823 unsigned long ptr;
....@@ -2026,6 +1941,52 @@
20261941 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
20271942 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
20281943
1944
+#ifdef __LITTLE_ENDIAN
1945
+
1946
+/*
1947
+ * Optimized helpers for little-endian architectures where CPU and on-disk
1948
+ * structures have the same endianness and we can skip conversions.
1949
+ */
1950
+
1951
+static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
1952
+ const struct btrfs_disk_key *disk_key)
1953
+{
1954
+ memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
1955
+}
1956
+
1957
+static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
1958
+ const struct btrfs_key *cpu_key)
1959
+{
1960
+ memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
1961
+}
1962
+
1963
+static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
1964
+ struct btrfs_key *cpu_key, int nr)
1965
+{
1966
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1967
+
1968
+ btrfs_node_key(eb, disk_key, nr);
1969
+}
1970
+
1971
+static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
1972
+ struct btrfs_key *cpu_key, int nr)
1973
+{
1974
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1975
+
1976
+ btrfs_item_key(eb, disk_key, nr);
1977
+}
1978
+
1979
+static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
1980
+ const struct btrfs_dir_item *item,
1981
+ struct btrfs_key *cpu_key)
1982
+{
1983
+ struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
1984
+
1985
+ btrfs_dir_item_key(eb, item, disk_key);
1986
+}
1987
+
1988
+#else
1989
+
20291990 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
20301991 const struct btrfs_disk_key *disk)
20311992 {
....@@ -2067,15 +2028,7 @@
20672028 btrfs_disk_key_to_cpu(key, &disk_key);
20682029 }
20692030
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
-}
2031
+#endif
20792032
20802033 /* struct btrfs_header */
20812034 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
....@@ -2097,18 +2050,16 @@
20972050 return (btrfs_header_flags(eb) & flag) == flag;
20982051 }
20992052
2100
-static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
2053
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
21012054 {
21022055 u64 flags = btrfs_header_flags(eb);
21032056 btrfs_set_header_flags(eb, flags | flag);
2104
- return (flags & flag) == flag;
21052057 }
21062058
2107
-static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
2059
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
21082060 {
21092061 u64 flags = btrfs_header_flags(eb);
21102062 btrfs_set_header_flags(eb, flags & ~flag);
2111
- return (flags & flag) == flag;
21122063 }
21132064
21142065 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
....@@ -2124,16 +2075,6 @@
21242075 flags &= ~BTRFS_BACKREF_REV_MASK;
21252076 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
21262077 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);
21372078 }
21382079
21392080 static inline int btrfs_is_leaf(const struct extent_buffer *eb)
....@@ -2364,14 +2305,10 @@
23642305 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
23652306 uuid_tree_generation, 64);
23662307
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
-}
2308
+int btrfs_super_csum_size(const struct btrfs_super_block *s);
2309
+const char *btrfs_super_csum_name(u16 csum_type);
2310
+const char *btrfs_super_csum_driver(u16 csum_type);
2311
+size_t __attribute_const__ btrfs_get_num_csums(void);
23752312
23762313
23772314 /*
....@@ -2379,18 +2316,18 @@
23792316 * this returns the address of the start of the last item,
23802317 * which is the stop of the leaf data stack
23812318 */
2382
-static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info,
2383
- const struct extent_buffer *leaf)
2319
+static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
23842320 {
23852321 u32 nr = btrfs_header_nritems(leaf);
23862322
23872323 if (nr == 0)
2388
- return BTRFS_LEAF_DATA_SIZE(fs_info);
2324
+ return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
23892325 return btrfs_item_offset_nr(leaf, nr - 1);
23902326 }
23912327
23922328 /* struct btrfs_file_extent_item */
2393
-BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
2329
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
2330
+ type, 8);
23942331 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
23952332 struct btrfs_file_extent_item, disk_bytenr, 64);
23962333 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
....@@ -2399,6 +2336,8 @@
23992336 struct btrfs_file_extent_item, generation, 64);
24002337 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
24012338 struct btrfs_file_extent_item, num_bytes, 64);
2339
+BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
2340
+ struct btrfs_file_extent_item, ram_bytes, 64);
24022341 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
24032342 struct btrfs_file_extent_item, disk_num_bytes, 64);
24042343 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
....@@ -2415,6 +2354,7 @@
24152354 return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
24162355 }
24172356
2357
+BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
24182358 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
24192359 disk_bytenr, 64);
24202360 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
....@@ -2444,30 +2384,6 @@
24442384 struct btrfs_item *e)
24452385 {
24462386 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));
24712387 }
24722388
24732389 /* btrfs_qgroup_status_item */
....@@ -2565,6 +2481,16 @@
25652481 ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
25662482 btrfs_item_offset_nr(leaf, slot)))
25672483
2484
+static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
2485
+{
2486
+ return crc32c(crc, address, length);
2487
+}
2488
+
2489
+static inline void btrfs_crc32c_final(u32 crc, u8 *result)
2490
+{
2491
+ put_unaligned_le32(~crc, result);
2492
+}
2493
+
25682494 static inline u64 btrfs_name_hash(const char *name, int len)
25692495 {
25702496 return crc32c((u32)~1, name, len);
....@@ -2579,12 +2505,6 @@
25792505 return (u64) crc32c(parent_objectid, name, len);
25802506 }
25812507
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
-
25882508 static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
25892509 {
25902510 return mapping_gfp_constraint(mapping, ~__GFP_FS);
....@@ -2593,72 +2513,65 @@
25932513 /* extent-tree.c */
25942514
25952515 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,
2516
+ BTRFS_REF_TYPE_INVALID,
2517
+ BTRFS_REF_TYPE_BLOCK,
2518
+ BTRFS_REF_TYPE_DATA,
2519
+ BTRFS_REF_TYPE_ANY,
26002520 };
26012521
26022522 int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
26032523 struct btrfs_extent_inline_ref *iref,
26042524 enum btrfs_inline_ref_type is_data);
2525
+u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
26052526
26062527 u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes);
26072528
2608
-static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info,
2609
- unsigned num_items)
2529
+/*
2530
+ * Use this if we would be adding new items, as we could split nodes as we cow
2531
+ * down the tree.
2532
+ */
2533
+static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info,
2534
+ unsigned num_items)
26102535 {
26112536 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;
26122537 }
26132538
26142539 /*
2615
- * Doing a truncate won't result in new nodes or leaves, just what we need for
2616
- * COW.
2540
+ * Doing a truncate or a modification won't result in new nodes or leaves, just
2541
+ * what we need for COW.
26172542 */
2618
-static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info,
2543
+static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info,
26192544 unsigned num_items)
26202545 {
26212546 return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items;
26222547 }
26232548
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);
2549
+int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info,
2550
+ u64 start, u64 num_bytes);
2551
+void btrfs_free_excluded_extents(struct btrfs_block_group *cache);
26352552 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
26362553 unsigned long count);
2637
-int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
2638
- unsigned long count, u64 transid, int wait);
2554
+void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2555
+ struct btrfs_delayed_ref_root *delayed_refs,
2556
+ struct btrfs_delayed_ref_head *head);
26392557 int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
26402558 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
26412559 struct btrfs_fs_info *fs_info, u64 bytenr,
26422560 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,
2561
+int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
2562
+ int reserved);
2563
+int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
26462564 u64 bytenr, u64 num_bytes);
2647
-int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
2648
- struct extent_buffer *eb);
2565
+int btrfs_exclude_logged_extents(struct extent_buffer *eb);
26492566 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);
2567
+ u64 objectid, u64 offset, u64 bytenr, bool strict);
26562568 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
26572569 struct btrfs_root *root,
26582570 u64 parent, u64 root_objectid,
26592571 const struct btrfs_disk_key *key,
26602572 int level, u64 hint,
2661
- u64 empty_size);
2573
+ u64 empty_size,
2574
+ enum btrfs_lock_nesting nest);
26622575 void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
26632576 struct btrfs_root *root,
26642577 struct extent_buffer *buf,
....@@ -2678,128 +2591,92 @@
26782591 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
26792592 struct extent_buffer *buf, int full_backref);
26802593 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,
2594
+ struct extent_buffer *eb, u64 flags,
26832595 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);
2596
+int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
26882597
26892598 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
26902599 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);
2600
+int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start,
2601
+ u64 len);
26942602 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
26952603 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);
2604
+ struct btrfs_ref *generic_ref);
26992605
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);
27052606 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);
27252607 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
27262608
2609
+/*
2610
+ * Different levels for to flush space when doing space reservations.
2611
+ *
2612
+ * The higher the level, the more methods we try to reclaim space.
2613
+ */
27272614 enum btrfs_reserve_flush_enum {
27282615 /* If we are in the transaction, we can't flush anything.*/
27292616 BTRFS_RESERVE_NO_FLUSH,
2617
+
27302618 /*
2731
- * Flushing delalloc may cause deadlock somewhere, in this
2732
- * case, use FLUSH LIMIT
2619
+ * Flush space by:
2620
+ * - Running delayed inode items
2621
+ * - Allocating a new chunk
27332622 */
27342623 BTRFS_RESERVE_FLUSH_LIMIT,
2624
+
2625
+ /*
2626
+ * Flush space by:
2627
+ * - Running delayed inode items
2628
+ * - Running delayed refs
2629
+ * - Running delalloc and waiting for ordered extents
2630
+ * - Allocating a new chunk
2631
+ */
2632
+ BTRFS_RESERVE_FLUSH_EVICT,
2633
+
2634
+ /*
2635
+ * Flush space by above mentioned methods and by:
2636
+ * - Running delayed iputs
2637
+ * - Commiting transaction
2638
+ *
2639
+ * Can be interruped by fatal signal.
2640
+ */
2641
+ BTRFS_RESERVE_FLUSH_DATA,
2642
+ BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE,
27352643 BTRFS_RESERVE_FLUSH_ALL,
2644
+
2645
+ /*
2646
+ * Pretty much the same as FLUSH_ALL, but can also steal space from
2647
+ * global rsv.
2648
+ *
2649
+ * Can be interruped by fatal signal.
2650
+ */
2651
+ BTRFS_RESERVE_FLUSH_ALL_STEAL,
27362652 };
27372653
27382654 enum btrfs_flush_state {
27392655 FLUSH_DELAYED_ITEMS_NR = 1,
27402656 FLUSH_DELAYED_ITEMS = 2,
2741
- FLUSH_DELALLOC = 3,
2742
- FLUSH_DELALLOC_WAIT = 4,
2743
- ALLOC_CHUNK = 5,
2744
- COMMIT_TRANS = 6,
2657
+ FLUSH_DELAYED_REFS_NR = 3,
2658
+ FLUSH_DELAYED_REFS = 4,
2659
+ FLUSH_DELALLOC = 5,
2660
+ FLUSH_DELALLOC_WAIT = 6,
2661
+ ALLOC_CHUNK = 7,
2662
+ ALLOC_CHUNK_FORCE = 8,
2663
+ RUN_DELAYED_IPUTS = 9,
2664
+ COMMIT_TRANS = 10,
27452665 };
27462666
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);
27582667 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
27592668 struct btrfs_block_rsv *rsv,
27602669 int nitems, bool use_global_rsv);
2761
-void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
2670
+void btrfs_subvolume_release_metadata(struct btrfs_root *root,
27622671 struct btrfs_block_rsv *rsv);
27632672 void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
27642673
27652674 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);
27972675 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
27982676 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
27992677 u64 start, u64 end);
28002678 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
28012679 u64 num_bytes, u64 *actual_bytes);
2802
-int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
28032680 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
28042681
28052682 int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
....@@ -2808,15 +2685,11 @@
28082685 int btrfs_start_write_no_snapshotting(struct btrfs_root *root);
28092686 void btrfs_end_write_no_snapshotting(struct btrfs_root *root);
28102687 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);
28152688
28162689 /* ctree.c */
28172690 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);
2691
+ int *slot);
2692
+int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
28202693 int btrfs_previous_item(struct btrfs_root *root,
28212694 struct btrfs_path *path, u64 min_objectid,
28222695 int type);
....@@ -2826,42 +2699,28 @@
28262699 struct btrfs_path *path,
28272700 const struct btrfs_key *new_key);
28282701 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);
28312702 int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
28322703 struct btrfs_key *key, int lowest_level,
28332704 u64 min_trans);
28342705 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
28352706 struct btrfs_path *path,
28362707 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);
2708
+struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
2709
+ int slot);
2710
+
28512711 int btrfs_cow_block(struct btrfs_trans_handle *trans,
28522712 struct btrfs_root *root, struct extent_buffer *buf,
28532713 struct extent_buffer *parent, int parent_slot,
2854
- struct extent_buffer **cow_ret);
2714
+ struct extent_buffer **cow_ret,
2715
+ enum btrfs_lock_nesting nest);
28552716 int btrfs_copy_root(struct btrfs_trans_handle *trans,
28562717 struct btrfs_root *root,
28572718 struct extent_buffer *buf,
28582719 struct extent_buffer **cow_ret, u64 new_root_objectid);
28592720 int btrfs_block_can_be_shared(struct btrfs_root *root,
28602721 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);
2722
+void btrfs_extend_item(struct btrfs_path *path, u32 data_size);
2723
+void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
28652724 int btrfs_split_item(struct btrfs_trans_handle *trans,
28662725 struct btrfs_root *root,
28672726 struct btrfs_path *path,
....@@ -2889,10 +2748,6 @@
28892748 void btrfs_release_path(struct btrfs_path *p);
28902749 struct btrfs_path *btrfs_alloc_path(void);
28912750 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);
28962751
28972752 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
28982753 struct btrfs_path *path, int slot, int nr);
....@@ -2905,7 +2760,7 @@
29052760
29062761 void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
29072762 const struct btrfs_key *cpu_key, u32 *data_size,
2908
- u32 total_data, u32 total_size, int nr);
2763
+ int nr);
29092764 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
29102765 const struct btrfs_key *key, void *data, u32 data_size);
29112766 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
....@@ -2939,11 +2794,9 @@
29392794 {
29402795 return btrfs_next_old_item(root, p, 0);
29412796 }
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);
2797
+int btrfs_leaf_free_space(struct extent_buffer *leaf);
2798
+int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
2799
+ int for_reloc);
29472800 int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
29482801 struct btrfs_root *root,
29492802 struct extent_buffer *node,
....@@ -2969,24 +2822,6 @@
29692822 static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
29702823 {
29712824 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);
29902825 }
29912826
29922827 /* tree mod log functions from ctree.c */
....@@ -3027,15 +2862,12 @@
30272862 u64 subid);
30282863 int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
30292864 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));
2865
+int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
30332866
30342867 /* dir-item.c */
30352868 int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
30362869 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,
2870
+int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
30392871 int name_len, struct btrfs_inode *dir,
30402872 struct btrfs_key *location, u8 type, u64 index);
30412873 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
....@@ -3103,21 +2935,18 @@
31032935 u64 inode_objectid, u64 ref_objectid, int ins_len,
31042936 int cow);
31052937
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
-
2938
+struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
2939
+ int slot, const char *name,
2940
+ int name_len);
2941
+struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
2942
+ struct extent_buffer *leaf, int slot, u64 ref_objectid,
2943
+ const char *name, int name_len);
31142944 /* file-item.c */
31152945 struct btrfs_dio_private;
31162946 int btrfs_del_csums(struct btrfs_trans_handle *trans,
31172947 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);
2948
+blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
2949
+ u64 offset, u8 *dst);
31212950 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
31222951 struct btrfs_root *root,
31232952 u64 objectid, u64 pos,
....@@ -3131,8 +2960,8 @@
31312960 int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
31322961 struct btrfs_root *root,
31332962 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);
2963
+blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
2964
+ u64 file_start, int contig);
31362965 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
31372966 struct list_head *list, int search_commit);
31382967 void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
....@@ -3140,14 +2969,23 @@
31402969 struct btrfs_file_extent_item *fi,
31412970 const bool new_inline,
31422971 struct extent_map *em);
2972
+int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
2973
+ u64 len);
2974
+int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start,
2975
+ u64 len);
2976
+void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size);
2977
+u64 btrfs_file_extent_end(const struct btrfs_path *path);
31432978
31442979 /* inode.c */
2980
+blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
2981
+ int mirror_num, unsigned long bio_flags);
2982
+int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
2983
+ struct page *page, u64 start, u64 end, int mirror);
31452984 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);
2985
+ u64 start, u64 len);
31482986 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
31492987 u64 *orig_start, u64 *orig_block_len,
3150
- u64 *ram_bytes);
2988
+ u64 *ram_bytes, bool strict);
31512989
31522990 void __btrfs_del_delalloc_inode(struct btrfs_root *root,
31532991 struct btrfs_inode *inode);
....@@ -3169,17 +3007,25 @@
31693007 u32 min_type);
31703008
31713009 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,
3010
+int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,
3011
+ bool in_reclaim_context);
3012
+int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
31743013 unsigned int extra_bits,
3175
- struct extent_state **cached_state, int dedupe);
3014
+ struct extent_state **cached_state);
31763015 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
31773016 struct btrfs_root *new_root,
31783017 struct btrfs_root *parent_root,
31793018 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);
3019
+ void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
3020
+ unsigned *bits);
3021
+void btrfs_clear_delalloc_extent(struct inode *inode,
3022
+ struct extent_state *state, unsigned *bits);
3023
+void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,
3024
+ struct extent_state *other);
3025
+void btrfs_split_delalloc_extent(struct inode *inode,
3026
+ struct extent_state *orig, u64 split);
3027
+int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
3028
+ unsigned long bio_flags);
31833029 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
31843030 vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
31853031 int btrfs_readpage(struct file *file, struct page *page);
....@@ -3187,17 +3033,16 @@
31873033 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
31883034 struct inode *btrfs_alloc_inode(struct super_block *sb);
31893035 void btrfs_destroy_inode(struct inode *inode);
3036
+void btrfs_free_inode(struct inode *inode);
31903037 int btrfs_drop_inode(struct inode *inode);
31913038 int __init btrfs_init_cachep(void);
31923039 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);
3040
+struct inode *btrfs_iget_path(struct super_block *s, u64 ino,
3041
+ struct btrfs_root *root, struct btrfs_path *path);
3042
+struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root);
31983043 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);
3044
+ struct page *page, size_t pg_offset,
3045
+ u64 start, u64 end);
32013046 int btrfs_update_inode(struct btrfs_trans_handle *trans,
32023047 struct btrfs_root *root,
32033048 struct inode *inode);
....@@ -3209,6 +3054,7 @@
32093054 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
32103055 void btrfs_add_delayed_iput(struct inode *inode);
32113056 void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
3057
+int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
32123058 int btrfs_prealloc_file_range(struct inode *inode, int mode,
32133059 u64 start, u64 num_bytes, u64 min_size,
32143060 loff_t actual_len, u64 *alloc_hint);
....@@ -3216,20 +3062,21 @@
32163062 struct btrfs_trans_handle *trans, int mode,
32173063 u64 start, u64 num_bytes, u64 min_size,
32183064 loff_t actual_len, u64 *alloc_hint);
3219
-int btrfs_run_delalloc_range(void *private_data, struct page *locked_page,
3065
+int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page,
32203066 u64 start, u64 end, int *page_started, unsigned long *nr_written,
32213067 struct writeback_control *wbc);
3068
+int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end);
3069
+void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
3070
+ u64 end, int uptodate);
32223071 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
3072
+ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
32263073
32273074 /* ioctl.c */
32283075 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32293076 long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
32303077 int btrfs_ioctl_get_supported_features(void __user *arg);
32313078 void btrfs_sync_inode_flags_to_i_flags(struct inode *inode);
3232
-int btrfs_is_empty_uuid(u8 *uuid);
3079
+int __pure btrfs_is_empty_uuid(u8 *uuid);
32333080 int btrfs_defrag_file(struct inode *inode, struct file *file,
32343081 struct btrfs_ioctl_defrag_range_args *range,
32353082 u64 newer_than, unsigned long max_pages);
....@@ -3237,9 +3084,9 @@
32373084 struct btrfs_ioctl_space_info *space);
32383085 void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
32393086 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);
3087
+bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
3088
+ enum btrfs_exclusive_operation type);
3089
+void btrfs_exclop_finish(struct btrfs_fs_info *fs_info);
32433090
32443091 /* file.c */
32453092 int __init btrfs_auto_defrag_init(void);
....@@ -3253,7 +3100,7 @@
32533100 int skip_pinned);
32543101 extern const struct file_operations btrfs_file_operations;
32553102 int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
3256
- struct btrfs_root *root, struct inode *inode,
3103
+ struct btrfs_root *root, struct btrfs_inode *inode,
32573104 struct btrfs_path *path, u64 start, u64 end,
32583105 u64 *drop_end, int drop_cache,
32593106 int replace_extent,
....@@ -3262,25 +3109,24 @@
32623109 int btrfs_drop_extents(struct btrfs_trans_handle *trans,
32633110 struct btrfs_root *root, struct inode *inode, u64 start,
32643111 u64 end, int drop_cache);
3112
+int btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path,
3113
+ const u64 start, const u64 end,
3114
+ struct btrfs_replace_extent_info *extent_info,
3115
+ struct btrfs_trans_handle **trans_out);
32653116 int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
32663117 struct btrfs_inode *inode, u64 start, u64 end);
32673118 int btrfs_release_file(struct inode *inode, struct file *file);
3268
-int btrfs_dirty_pages(struct inode *inode, struct page **pages,
3119
+int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
32693120 size_t num_pages, loff_t pos, size_t write_bytes,
32703121 struct extent_state **cached);
32713122 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);
3123
+int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
3124
+ size_t *write_bytes);
3125
+void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
32743126
32753127 /* tree-defrag.c */
32763128 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
32773129 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);
32843130
32853131 /* super.c */
32863132 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
....@@ -3374,31 +3220,17 @@
33743220
33753221 #if defined(CONFIG_DYNAMIC_DEBUG)
33763222 #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)
3223
+ _dynamic_func_call_no_desc(fmt, btrfs_printk, \
3224
+ fs_info, KERN_DEBUG fmt, ##args)
3225
+#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3226
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
3227
+ fs_info, KERN_DEBUG fmt, ##args)
33883228 #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)
3229
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
3230
+ fs_info, KERN_DEBUG fmt, ##args)
3231
+#define btrfs_debug_rl(fs_info, fmt, args...) \
3232
+ _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
3233
+ fs_info, KERN_DEBUG fmt, ##args)
34023234 #elif defined(DEBUG)
34033235 #define btrfs_debug(fs_info, fmt, args...) \
34043236 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
....@@ -3450,19 +3282,29 @@
34503282 } while (0)
34513283
34523284 #ifdef CONFIG_BTRFS_ASSERT
3453
-
3454
-__cold
3455
-static inline void assfail(const char *expr, const char *file, int line)
3285
+__cold __noreturn
3286
+static inline void assertfail(const char *expr, const char *file, int line)
34563287 {
3457
- pr_err("assertion failed: %s, file: %s, line: %d\n",
3458
- expr, file, line);
3288
+ pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
34593289 BUG();
34603290 }
34613291
3462
-#define ASSERT(expr) \
3463
- (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
3292
+#define ASSERT(expr) \
3293
+ (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
3294
+
34643295 #else
3465
-#define ASSERT(expr) ((void)0)
3296
+static inline void assertfail(const char *expr, const char* file, int line) { }
3297
+#define ASSERT(expr) (void)(expr)
3298
+#endif
3299
+
3300
+/*
3301
+ * Use that for functions that are conditionally exported for sanity tests but
3302
+ * otherwise static
3303
+ */
3304
+#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3305
+#define EXPORT_FOR_TESTS static
3306
+#else
3307
+#define EXPORT_FOR_TESTS
34663308 #endif
34673309
34683310 __cold
....@@ -3477,7 +3319,7 @@
34773319 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
34783320 unsigned int line, int errno, const char *fmt, ...);
34793321
3480
-const char *btrfs_decode_error(int errno);
3322
+const char * __attribute_const__ btrfs_decode_error(int errno);
34813323
34823324 __cold
34833325 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
....@@ -3493,7 +3335,7 @@
34933335 /* Report first abort since mount */ \
34943336 if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \
34953337 &((trans)->fs_info->fs_state))) { \
3496
- if ((errno) != -EIO) { \
3338
+ if ((errno) != -EIO && (errno) != -EROFS) { \
34973339 WARN(1, KERN_DEBUG \
34983340 "BTRFS: Transaction aborted (error %d)\n", \
34993341 (errno)); \
....@@ -3531,10 +3373,11 @@
35313373 /* compatibility and incompatibility defines */
35323374
35333375 #define btrfs_set_fs_incompat(__fs_info, opt) \
3534
- __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3376
+ __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3377
+ #opt)
35353378
35363379 static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
3537
- u64 flag)
3380
+ u64 flag, const char* name)
35383381 {
35393382 struct btrfs_super_block *disk_super;
35403383 u64 features;
....@@ -3547,18 +3390,20 @@
35473390 if (!(features & flag)) {
35483391 features |= flag;
35493392 btrfs_set_super_incompat_flags(disk_super, features);
3550
- btrfs_info(fs_info, "setting %llu feature flag",
3551
- flag);
3393
+ btrfs_info(fs_info,
3394
+ "setting incompat feature flag for %s (0x%llx)",
3395
+ name, flag);
35523396 }
35533397 spin_unlock(&fs_info->super_lock);
35543398 }
35553399 }
35563400
35573401 #define btrfs_clear_fs_incompat(__fs_info, opt) \
3558
- __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
3402
+ __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
3403
+ #opt)
35593404
35603405 static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
3561
- u64 flag)
3406
+ u64 flag, const char* name)
35623407 {
35633408 struct btrfs_super_block *disk_super;
35643409 u64 features;
....@@ -3571,8 +3416,9 @@
35713416 if (features & flag) {
35723417 features &= ~flag;
35733418 btrfs_set_super_incompat_flags(disk_super, features);
3574
- btrfs_info(fs_info, "clearing %llu feature flag",
3575
- flag);
3419
+ btrfs_info(fs_info,
3420
+ "clearing incompat feature flag for %s (0x%llx)",
3421
+ name, flag);
35763422 }
35773423 spin_unlock(&fs_info->super_lock);
35783424 }
....@@ -3589,10 +3435,11 @@
35893435 }
35903436
35913437 #define btrfs_set_fs_compat_ro(__fs_info, opt) \
3592
- __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3438
+ __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3439
+ #opt)
35933440
35943441 static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info,
3595
- u64 flag)
3442
+ u64 flag, const char *name)
35963443 {
35973444 struct btrfs_super_block *disk_super;
35983445 u64 features;
....@@ -3605,18 +3452,20 @@
36053452 if (!(features & flag)) {
36063453 features |= flag;
36073454 btrfs_set_super_compat_ro_flags(disk_super, features);
3608
- btrfs_info(fs_info, "setting %llu ro feature flag",
3609
- flag);
3455
+ btrfs_info(fs_info,
3456
+ "setting compat-ro feature flag for %s (0x%llx)",
3457
+ name, flag);
36103458 }
36113459 spin_unlock(&fs_info->super_lock);
36123460 }
36133461 }
36143462
36153463 #define btrfs_clear_fs_compat_ro(__fs_info, opt) \
3616
- __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
3464
+ __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
3465
+ #opt)
36173466
36183467 static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
3619
- u64 flag)
3468
+ u64 flag, const char *name)
36203469 {
36213470 struct btrfs_super_block *disk_super;
36223471 u64 features;
....@@ -3629,8 +3478,9 @@
36293478 if (features & flag) {
36303479 features &= ~flag;
36313480 btrfs_set_super_compat_ro_flags(disk_super, features);
3632
- btrfs_info(fs_info, "clearing %llu ro feature flag",
3633
- flag);
3481
+ btrfs_info(fs_info,
3482
+ "clearing compat-ro feature flag for %s (0x%llx)",
3483
+ name, flag);
36343484 }
36353485 spin_unlock(&fs_info->super_lock);
36363486 }
....@@ -3669,7 +3519,7 @@
36693519 int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
36703520 struct btrfs_root *root);
36713521 int btrfs_recover_relocation(struct btrfs_root *root);
3672
-int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
3522
+int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len);
36733523 int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
36743524 struct btrfs_root *root, struct extent_buffer *buf,
36753525 struct extent_buffer *cow);
....@@ -3677,6 +3527,10 @@
36773527 u64 *bytes_to_reserve);
36783528 int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
36793529 struct btrfs_pending_snapshot *pending);
3530
+int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info);
3531
+struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info,
3532
+ u64 bytenr);
3533
+int btrfs_should_ignore_reloc_root(struct btrfs_root *root);
36803534
36813535 /* scrub.c */
36823536 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
....@@ -3685,8 +3539,7 @@
36853539 void btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
36863540 void btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
36873541 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);
3542
+int btrfs_scrub_cancel_dev(struct btrfs_device *dev);
36903543 int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
36913544 struct btrfs_scrub_progress *progress);
36923545 static inline void btrfs_init_full_stripe_locks_tree(
....@@ -3720,6 +3573,8 @@
37203573 int btrfs_reada_wait(void *handle);
37213574 void btrfs_reada_detach(void *handle);
37223575 int btree_readahead_hook(struct extent_buffer *eb, int err);
3576
+void btrfs_reada_remove_dev(struct btrfs_device *dev);
3577
+void btrfs_reada_undo_remove_dev(struct btrfs_device *dev);
37233578
37243579 static inline int is_fstree(u64 rootid)
37253580 {
....@@ -3735,41 +3590,20 @@
37353590 return signal_pending(current);
37363591 }
37373592
3593
+#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
3594
+
37383595 /* Sanity test specific functions */
37393596 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
37403597 void btrfs_test_destroy_inode(struct inode *inode);
3741
-#endif
3742
-
37433598 static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
37443599 {
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
3600
+ return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
3601
+}
3602
+#else
3603
+static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info)
3604
+{
37503605 return 0;
37513606 }
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
-}
3607
+#endif
37743608
37753609 #endif