| .. | .. |
|---|
| 16 | 16 | #include <linux/backing-dev.h> |
|---|
| 17 | 17 | #include <linux/wait.h> |
|---|
| 18 | 18 | #include <linux/slab.h> |
|---|
| 19 | | -#include <linux/kobject.h> |
|---|
| 20 | 19 | #include <trace/events/btrfs.h> |
|---|
| 21 | | -#include <asm/kmap_types.h> |
|---|
| 20 | +#include <asm/unaligned.h> |
|---|
| 22 | 21 | #include <linux/pagemap.h> |
|---|
| 23 | 22 | #include <linux/btrfs.h> |
|---|
| 24 | 23 | #include <linux/btrfs_tree.h> |
|---|
| .. | .. |
|---|
| 28 | 27 | #include <linux/dynamic_debug.h> |
|---|
| 29 | 28 | #include <linux/refcount.h> |
|---|
| 30 | 29 | #include <linux/crc32c.h> |
|---|
| 30 | +#include "extent-io-tree.h" |
|---|
| 31 | 31 | #include "extent_io.h" |
|---|
| 32 | 32 | #include "extent_map.h" |
|---|
| 33 | 33 | #include "async-thread.h" |
|---|
| 34 | +#include "block-rsv.h" |
|---|
| 35 | +#include "locking.h" |
|---|
| 34 | 36 | |
|---|
| 35 | 37 | struct btrfs_trans_handle; |
|---|
| 36 | 38 | struct btrfs_transaction; |
|---|
| 37 | 39 | struct btrfs_pending_snapshot; |
|---|
| 40 | +struct btrfs_delayed_ref_root; |
|---|
| 41 | +struct btrfs_space_info; |
|---|
| 42 | +struct btrfs_block_group; |
|---|
| 38 | 43 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
|---|
| 39 | 44 | extern struct kmem_cache *btrfs_bit_radix_cachep; |
|---|
| 40 | 45 | extern struct kmem_cache *btrfs_path_cachep; |
|---|
| 41 | 46 | extern struct kmem_cache *btrfs_free_space_cachep; |
|---|
| 42 | 47 | extern struct kmem_cache *btrfs_free_space_bitmap_cachep; |
|---|
| 43 | 48 | struct btrfs_ordered_sum; |
|---|
| 44 | | - |
|---|
| 45 | | -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 46 | | -#define STATIC noinline |
|---|
| 47 | | -#else |
|---|
| 48 | | -#define STATIC static noinline |
|---|
| 49 | | -#endif |
|---|
| 49 | +struct btrfs_ref; |
|---|
| 50 | 50 | |
|---|
| 51 | 51 | #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */ |
|---|
| 52 | 52 | |
|---|
| 53 | | -#define BTRFS_MAX_MIRRORS 3 |
|---|
| 53 | +/* |
|---|
| 54 | + * Maximum number of mirrors that can be available for all profiles counting |
|---|
| 55 | + * the target device of dev-replace as one. During an active device replace |
|---|
| 56 | + * procedure, the target device of the copy operation is a mirror for the |
|---|
| 57 | + * filesystem data as well that can be used to read data in order to repair |
|---|
| 58 | + * read errors on other disks. |
|---|
| 59 | + * |
|---|
| 60 | + * Current value is derived from RAID1C4 with 4 copies. |
|---|
| 61 | + */ |
|---|
| 62 | +#define BTRFS_MAX_MIRRORS (4 + 1) |
|---|
| 54 | 63 | |
|---|
| 55 | 64 | #define BTRFS_MAX_LEVEL 8 |
|---|
| 56 | 65 | |
|---|
| .. | .. |
|---|
| 75 | 84 | */ |
|---|
| 76 | 85 | #define BTRFS_LINK_MAX 65535U |
|---|
| 77 | 86 | |
|---|
| 78 | | -/* four bytes for CRC32 */ |
|---|
| 79 | | -static const int btrfs_csum_sizes[] = { 4 }; |
|---|
| 80 | | - |
|---|
| 81 | 87 | #define BTRFS_EMPTY_DIR_SIZE 0 |
|---|
| 82 | 88 | |
|---|
| 83 | 89 | /* ioprio of readahead is set to idle */ |
|---|
| .. | .. |
|---|
| 95 | 101 | |
|---|
| 96 | 102 | #define BTRFS_MAX_EXTENT_SIZE SZ_128M |
|---|
| 97 | 103 | |
|---|
| 104 | +/* |
|---|
| 105 | + * Deltas are an effective way to populate global statistics. Give macro names |
|---|
| 106 | + * to make it clear what we're doing. An example is discard_extents in |
|---|
| 107 | + * btrfs_free_space_ctl. |
|---|
| 108 | + */ |
|---|
| 109 | +#define BTRFS_STAT_NR_ENTRIES 2 |
|---|
| 110 | +#define BTRFS_STAT_CURR 0 |
|---|
| 111 | +#define BTRFS_STAT_PREV 1 |
|---|
| 98 | 112 | |
|---|
| 99 | 113 | /* |
|---|
| 100 | 114 | * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size |
|---|
| .. | .. |
|---|
| 104 | 118 | return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); |
|---|
| 105 | 119 | } |
|---|
| 106 | 120 | |
|---|
| 107 | | -struct btrfs_mapping_tree { |
|---|
| 108 | | - struct extent_map_tree map_tree; |
|---|
| 109 | | -}; |
|---|
| 110 | | - |
|---|
| 111 | 121 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
|---|
| 112 | 122 | { |
|---|
| 113 | 123 | BUG_ON(num_stripes == 0); |
|---|
| .. | .. |
|---|
| 116 | 126 | } |
|---|
| 117 | 127 | |
|---|
| 118 | 128 | /* |
|---|
| 119 | | - * File system states |
|---|
| 129 | + * Runtime (in-memory) states of filesystem |
|---|
| 120 | 130 | */ |
|---|
| 121 | | -#define BTRFS_FS_STATE_ERROR 0 |
|---|
| 122 | | -#define BTRFS_FS_STATE_REMOUNTING 1 |
|---|
| 123 | | -#define BTRFS_FS_STATE_TRANS_ABORTED 2 |
|---|
| 124 | | -#define BTRFS_FS_STATE_DEV_REPLACING 3 |
|---|
| 125 | | -#define BTRFS_FS_STATE_DUMMY_FS_INFO 4 |
|---|
| 131 | +enum { |
|---|
| 132 | + /* Global indicator of serious filesystem errors */ |
|---|
| 133 | + BTRFS_FS_STATE_ERROR, |
|---|
| 134 | + /* |
|---|
| 135 | + * Filesystem is being remounted, allow to skip some operations, like |
|---|
| 136 | + * defrag |
|---|
| 137 | + */ |
|---|
| 138 | + BTRFS_FS_STATE_REMOUNTING, |
|---|
| 139 | + /* Track if a transaction abort has been reported on this filesystem */ |
|---|
| 140 | + BTRFS_FS_STATE_TRANS_ABORTED, |
|---|
| 141 | + /* |
|---|
| 142 | + * Bio operations should be blocked on this filesystem because a source |
|---|
| 143 | + * or target device is being destroyed as part of a device replace |
|---|
| 144 | + */ |
|---|
| 145 | + BTRFS_FS_STATE_DEV_REPLACING, |
|---|
| 146 | + /* The btrfs_fs_info created for self-tests */ |
|---|
| 147 | + BTRFS_FS_STATE_DUMMY_FS_INFO, |
|---|
| 148 | +}; |
|---|
| 126 | 149 | |
|---|
| 127 | 150 | #define BTRFS_BACKREF_REV_MAX 256 |
|---|
| 128 | 151 | #define BTRFS_BACKREF_REV_SHIFT 56 |
|---|
| .. | .. |
|---|
| 202 | 225 | * it currently lacks any block count etc etc |
|---|
| 203 | 226 | */ |
|---|
| 204 | 227 | struct btrfs_super_block { |
|---|
| 205 | | - u8 csum[BTRFS_CSUM_SIZE]; |
|---|
| 206 | 228 | /* the first 4 fields must match struct btrfs_header */ |
|---|
| 207 | | - u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ |
|---|
| 229 | + u8 csum[BTRFS_CSUM_SIZE]; |
|---|
| 230 | + /* FS specific UUID, visible to user */ |
|---|
| 231 | + u8 fsid[BTRFS_FSID_SIZE]; |
|---|
| 208 | 232 | __le64 bytenr; /* this block number */ |
|---|
| 209 | 233 | __le64 flags; |
|---|
| 210 | 234 | |
|---|
| .. | .. |
|---|
| 241 | 265 | __le64 cache_generation; |
|---|
| 242 | 266 | __le64 uuid_tree_generation; |
|---|
| 243 | 267 | |
|---|
| 268 | + /* the UUID written into btree blocks */ |
|---|
| 269 | + u8 metadata_uuid[BTRFS_FSID_SIZE]; |
|---|
| 270 | + |
|---|
| 244 | 271 | /* future expansion */ |
|---|
| 245 | | - __le64 reserved[30]; |
|---|
| 272 | + __le64 reserved[28]; |
|---|
| 246 | 273 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; |
|---|
| 247 | 274 | struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS]; |
|---|
| 248 | 275 | } __attribute__ ((__packed__)); |
|---|
| .. | .. |
|---|
| 272 | 299 | BTRFS_FEATURE_INCOMPAT_RAID56 | \ |
|---|
| 273 | 300 | BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \ |
|---|
| 274 | 301 | BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \ |
|---|
| 275 | | - BTRFS_FEATURE_INCOMPAT_NO_HOLES) |
|---|
| 302 | + BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ |
|---|
| 303 | + BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ |
|---|
| 304 | + BTRFS_FEATURE_INCOMPAT_RAID1C34) |
|---|
| 276 | 305 | |
|---|
| 277 | 306 | #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \ |
|---|
| 278 | 307 | (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF) |
|---|
| .. | .. |
|---|
| 323 | 352 | * The slots array records the index of the item or block pointer |
|---|
| 324 | 353 | * used while walking the tree. |
|---|
| 325 | 354 | */ |
|---|
| 326 | | -enum { READA_NONE = 0, READA_BACK, READA_FORWARD }; |
|---|
| 355 | +enum { READA_NONE, READA_BACK, READA_FORWARD }; |
|---|
| 327 | 356 | struct btrfs_path { |
|---|
| 328 | 357 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
|---|
| 329 | 358 | int slots[BTRFS_MAX_LEVEL]; |
|---|
| .. | .. |
|---|
| 344 | 373 | unsigned int search_commit_root:1; |
|---|
| 345 | 374 | unsigned int need_commit_sem:1; |
|---|
| 346 | 375 | unsigned int skip_release_on_error:1; |
|---|
| 376 | + unsigned int recurse:1; |
|---|
| 347 | 377 | }; |
|---|
| 348 | 378 | #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ |
|---|
| 349 | 379 | sizeof(struct btrfs_item)) |
|---|
| .. | .. |
|---|
| 367 | 397 | struct btrfs_device *tgtdev; |
|---|
| 368 | 398 | |
|---|
| 369 | 399 | struct mutex lock_finishing_cancel_unmount; |
|---|
| 370 | | - rwlock_t lock; |
|---|
| 371 | | - atomic_t read_locks; |
|---|
| 372 | | - atomic_t blocking_readers; |
|---|
| 373 | | - wait_queue_head_t read_lock_wq; |
|---|
| 400 | + struct rw_semaphore rwsem; |
|---|
| 374 | 401 | |
|---|
| 375 | 402 | struct btrfs_scrub_progress scrub_progress; |
|---|
| 376 | | -}; |
|---|
| 377 | 403 | |
|---|
| 378 | | -/* For raid type sysfs entries */ |
|---|
| 379 | | -struct raid_kobject { |
|---|
| 380 | | - u64 flags; |
|---|
| 381 | | - struct kobject kobj; |
|---|
| 382 | | - struct list_head list; |
|---|
| 383 | | -}; |
|---|
| 384 | | - |
|---|
| 385 | | -struct btrfs_space_info { |
|---|
| 386 | | - spinlock_t lock; |
|---|
| 387 | | - |
|---|
| 388 | | - u64 total_bytes; /* total bytes in the space, |
|---|
| 389 | | - this doesn't take mirrors into account */ |
|---|
| 390 | | - u64 bytes_used; /* total bytes used, |
|---|
| 391 | | - this doesn't take mirrors into account */ |
|---|
| 392 | | - u64 bytes_pinned; /* total bytes pinned, will be freed when the |
|---|
| 393 | | - transaction finishes */ |
|---|
| 394 | | - u64 bytes_reserved; /* total bytes the allocator has reserved for |
|---|
| 395 | | - current allocations */ |
|---|
| 396 | | - u64 bytes_may_use; /* number of bytes that may be used for |
|---|
| 397 | | - delalloc/allocations */ |
|---|
| 398 | | - u64 bytes_readonly; /* total bytes that are read only */ |
|---|
| 399 | | - |
|---|
| 400 | | - u64 max_extent_size; /* This will hold the maximum extent size of |
|---|
| 401 | | - the space info if we had an ENOSPC in the |
|---|
| 402 | | - allocator. */ |
|---|
| 403 | | - |
|---|
| 404 | | - unsigned int full:1; /* indicates that we cannot allocate any more |
|---|
| 405 | | - chunks for this space */ |
|---|
| 406 | | - unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ |
|---|
| 407 | | - |
|---|
| 408 | | - unsigned int flush:1; /* set if we are trying to make space */ |
|---|
| 409 | | - |
|---|
| 410 | | - unsigned int force_alloc; /* set if we need to force a chunk |
|---|
| 411 | | - alloc for this space */ |
|---|
| 412 | | - |
|---|
| 413 | | - u64 disk_used; /* total bytes used on disk */ |
|---|
| 414 | | - u64 disk_total; /* total bytes on disk, takes mirrors into |
|---|
| 415 | | - account */ |
|---|
| 416 | | - |
|---|
| 417 | | - u64 flags; |
|---|
| 418 | | - |
|---|
| 419 | | - /* |
|---|
| 420 | | - * bytes_pinned is kept in line with what is actually pinned, as in |
|---|
| 421 | | - * we've called update_block_group and dropped the bytes_used counter |
|---|
| 422 | | - * and increased the bytes_pinned counter. However this means that |
|---|
| 423 | | - * bytes_pinned does not reflect the bytes that will be pinned once the |
|---|
| 424 | | - * delayed refs are flushed, so this counter is inc'ed every time we |
|---|
| 425 | | - * call btrfs_free_extent so it is a realtime count of what will be |
|---|
| 426 | | - * freed once the transaction is committed. It will be zeroed every |
|---|
| 427 | | - * time the transaction commits. |
|---|
| 428 | | - */ |
|---|
| 429 | | - struct percpu_counter total_bytes_pinned; |
|---|
| 430 | | - |
|---|
| 431 | | - struct list_head list; |
|---|
| 432 | | - /* Protected by the spinlock 'lock'. */ |
|---|
| 433 | | - struct list_head ro_bgs; |
|---|
| 434 | | - struct list_head priority_tickets; |
|---|
| 435 | | - struct list_head tickets; |
|---|
| 436 | | - /* |
|---|
| 437 | | - * tickets_id just indicates the next ticket will be handled, so note |
|---|
| 438 | | - * it's not stored per ticket. |
|---|
| 439 | | - */ |
|---|
| 440 | | - u64 tickets_id; |
|---|
| 441 | | - |
|---|
| 442 | | - struct rw_semaphore groups_sem; |
|---|
| 443 | | - /* for block groups in our same type */ |
|---|
| 444 | | - struct list_head block_groups[BTRFS_NR_RAID_TYPES]; |
|---|
| 445 | | - wait_queue_head_t wait; |
|---|
| 446 | | - |
|---|
| 447 | | - struct kobject kobj; |
|---|
| 448 | | - struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; |
|---|
| 449 | | -}; |
|---|
| 450 | | - |
|---|
| 451 | | -#define BTRFS_BLOCK_RSV_GLOBAL 1 |
|---|
| 452 | | -#define BTRFS_BLOCK_RSV_DELALLOC 2 |
|---|
| 453 | | -#define BTRFS_BLOCK_RSV_TRANS 3 |
|---|
| 454 | | -#define BTRFS_BLOCK_RSV_CHUNK 4 |
|---|
| 455 | | -#define BTRFS_BLOCK_RSV_DELOPS 5 |
|---|
| 456 | | -#define BTRFS_BLOCK_RSV_EMPTY 6 |
|---|
| 457 | | -#define BTRFS_BLOCK_RSV_TEMP 7 |
|---|
| 458 | | - |
|---|
| 459 | | -struct btrfs_block_rsv { |
|---|
| 460 | | - u64 size; |
|---|
| 461 | | - u64 reserved; |
|---|
| 462 | | - struct btrfs_space_info *space_info; |
|---|
| 463 | | - spinlock_t lock; |
|---|
| 464 | | - unsigned short full; |
|---|
| 465 | | - unsigned short type; |
|---|
| 466 | | - unsigned short failfast; |
|---|
| 467 | | - |
|---|
| 468 | | - /* |
|---|
| 469 | | - * Qgroup equivalent for @size @reserved |
|---|
| 470 | | - * |
|---|
| 471 | | - * Unlike normal @size/@reserved for inode rsv, qgroup doesn't care |
|---|
| 472 | | - * about things like csum size nor how many tree blocks it will need to |
|---|
| 473 | | - * reserve. |
|---|
| 474 | | - * |
|---|
| 475 | | - * Qgroup cares more about net change of the extent usage. |
|---|
| 476 | | - * |
|---|
| 477 | | - * So for one newly inserted file extent, in worst case it will cause |
|---|
| 478 | | - * leaf split and level increase, nodesize for each file extent is |
|---|
| 479 | | - * already too much. |
|---|
| 480 | | - * |
|---|
| 481 | | - * In short, qgroup_size/reserved is the upper limit of possible needed |
|---|
| 482 | | - * qgroup metadata reservation. |
|---|
| 483 | | - */ |
|---|
| 484 | | - u64 qgroup_rsv_size; |
|---|
| 485 | | - u64 qgroup_rsv_reserved; |
|---|
| 404 | + struct percpu_counter bio_counter; |
|---|
| 405 | + wait_queue_head_t replace_wait; |
|---|
| 486 | 406 | }; |
|---|
| 487 | 407 | |
|---|
| 488 | 408 | /* |
|---|
| .. | .. |
|---|
| 504 | 424 | /* We did a full search and couldn't create a cluster */ |
|---|
| 505 | 425 | bool fragmented; |
|---|
| 506 | 426 | |
|---|
| 507 | | - struct btrfs_block_group_cache *block_group; |
|---|
| 427 | + struct btrfs_block_group *block_group; |
|---|
| 508 | 428 | /* |
|---|
| 509 | 429 | * when a cluster is allocated from a block group, we put the |
|---|
| 510 | 430 | * cluster onto a list in the block group so that it can |
|---|
| .. | .. |
|---|
| 514 | 434 | }; |
|---|
| 515 | 435 | |
|---|
| 516 | 436 | enum btrfs_caching_type { |
|---|
| 517 | | - BTRFS_CACHE_NO = 0, |
|---|
| 518 | | - BTRFS_CACHE_STARTED = 1, |
|---|
| 519 | | - BTRFS_CACHE_FAST = 2, |
|---|
| 520 | | - BTRFS_CACHE_FINISHED = 3, |
|---|
| 521 | | - BTRFS_CACHE_ERROR = 4, |
|---|
| 522 | | -}; |
|---|
| 523 | | - |
|---|
| 524 | | -enum btrfs_disk_cache_state { |
|---|
| 525 | | - BTRFS_DC_WRITTEN = 0, |
|---|
| 526 | | - BTRFS_DC_ERROR = 1, |
|---|
| 527 | | - BTRFS_DC_CLEAR = 2, |
|---|
| 528 | | - BTRFS_DC_SETUP = 3, |
|---|
| 529 | | -}; |
|---|
| 530 | | - |
|---|
| 531 | | -struct btrfs_caching_control { |
|---|
| 532 | | - struct list_head list; |
|---|
| 533 | | - struct mutex mutex; |
|---|
| 534 | | - wait_queue_head_t wait; |
|---|
| 535 | | - struct btrfs_work work; |
|---|
| 536 | | - struct btrfs_block_group_cache *block_group; |
|---|
| 537 | | - u64 progress; |
|---|
| 538 | | - refcount_t count; |
|---|
| 539 | | -}; |
|---|
| 540 | | - |
|---|
| 541 | | -/* Once caching_thread() finds this much free space, it will wake up waiters. */ |
|---|
| 542 | | -#define CACHING_CTL_WAKE_UP SZ_2M |
|---|
| 543 | | - |
|---|
| 544 | | -struct btrfs_io_ctl { |
|---|
| 545 | | - void *cur, *orig; |
|---|
| 546 | | - struct page *page; |
|---|
| 547 | | - struct page **pages; |
|---|
| 548 | | - struct btrfs_fs_info *fs_info; |
|---|
| 549 | | - struct inode *inode; |
|---|
| 550 | | - unsigned long size; |
|---|
| 551 | | - int index; |
|---|
| 552 | | - int num_pages; |
|---|
| 553 | | - int entries; |
|---|
| 554 | | - int bitmaps; |
|---|
| 555 | | - unsigned check_crcs:1; |
|---|
| 437 | + BTRFS_CACHE_NO, |
|---|
| 438 | + BTRFS_CACHE_STARTED, |
|---|
| 439 | + BTRFS_CACHE_FAST, |
|---|
| 440 | + BTRFS_CACHE_FINISHED, |
|---|
| 441 | + BTRFS_CACHE_ERROR, |
|---|
| 556 | 442 | }; |
|---|
| 557 | 443 | |
|---|
| 558 | 444 | /* |
|---|
| .. | .. |
|---|
| 563 | 449 | struct mutex lock; |
|---|
| 564 | 450 | }; |
|---|
| 565 | 451 | |
|---|
| 566 | | -struct btrfs_block_group_cache { |
|---|
| 567 | | - struct btrfs_key key; |
|---|
| 568 | | - struct btrfs_block_group_item item; |
|---|
| 569 | | - struct btrfs_fs_info *fs_info; |
|---|
| 570 | | - struct inode *inode; |
|---|
| 452 | +/* Discard control. */ |
|---|
| 453 | +/* |
|---|
| 454 | + * Async discard uses multiple lists to differentiate the discard filter |
|---|
| 455 | + * parameters. Index 0 is for completely free block groups where we need to |
|---|
| 456 | + * ensure the entire block group is trimmed without being lossy. Indices |
|---|
| 457 | + * afterwards represent monotonically decreasing discard filter sizes to |
|---|
| 458 | + * prioritize what should be discarded next. |
|---|
| 459 | + */ |
|---|
| 460 | +#define BTRFS_NR_DISCARD_LISTS 3 |
|---|
| 461 | +#define BTRFS_DISCARD_INDEX_UNUSED 0 |
|---|
| 462 | +#define BTRFS_DISCARD_INDEX_START 1 |
|---|
| 463 | + |
|---|
| 464 | +struct btrfs_discard_ctl { |
|---|
| 465 | + struct workqueue_struct *discard_workers; |
|---|
| 466 | + struct delayed_work work; |
|---|
| 571 | 467 | spinlock_t lock; |
|---|
| 572 | | - u64 pinned; |
|---|
| 573 | | - u64 reserved; |
|---|
| 574 | | - u64 delalloc_bytes; |
|---|
| 575 | | - u64 bytes_super; |
|---|
| 576 | | - u64 flags; |
|---|
| 577 | | - u64 cache_generation; |
|---|
| 578 | | - |
|---|
| 579 | | - /* |
|---|
| 580 | | - * If the free space extent count exceeds this number, convert the block |
|---|
| 581 | | - * group to bitmaps. |
|---|
| 582 | | - */ |
|---|
| 583 | | - u32 bitmap_high_thresh; |
|---|
| 584 | | - |
|---|
| 585 | | - /* |
|---|
| 586 | | - * If the free space extent count drops below this number, convert the |
|---|
| 587 | | - * block group back to extents. |
|---|
| 588 | | - */ |
|---|
| 589 | | - u32 bitmap_low_thresh; |
|---|
| 590 | | - |
|---|
| 591 | | - /* |
|---|
| 592 | | - * It is just used for the delayed data space allocation because |
|---|
| 593 | | - * only the data space allocation and the relative metadata update |
|---|
| 594 | | - * can be done cross the transaction. |
|---|
| 595 | | - */ |
|---|
| 596 | | - struct rw_semaphore data_rwsem; |
|---|
| 597 | | - |
|---|
| 598 | | - /* for raid56, this is a full stripe, without parity */ |
|---|
| 599 | | - unsigned long full_stripe_len; |
|---|
| 600 | | - |
|---|
| 601 | | - unsigned int ro; |
|---|
| 602 | | - unsigned int iref:1; |
|---|
| 603 | | - unsigned int has_caching_ctl:1; |
|---|
| 604 | | - unsigned int removed:1; |
|---|
| 605 | | - |
|---|
| 606 | | - int disk_cache_state; |
|---|
| 607 | | - |
|---|
| 608 | | - /* cache tracking stuff */ |
|---|
| 609 | | - int cached; |
|---|
| 610 | | - struct btrfs_caching_control *caching_ctl; |
|---|
| 611 | | - u64 last_byte_to_unpin; |
|---|
| 612 | | - |
|---|
| 613 | | - struct btrfs_space_info *space_info; |
|---|
| 614 | | - |
|---|
| 615 | | - /* free space cache stuff */ |
|---|
| 616 | | - struct btrfs_free_space_ctl *free_space_ctl; |
|---|
| 617 | | - |
|---|
| 618 | | - /* block group cache stuff */ |
|---|
| 619 | | - struct rb_node cache_node; |
|---|
| 620 | | - |
|---|
| 621 | | - /* for block groups in the same raid type */ |
|---|
| 622 | | - struct list_head list; |
|---|
| 623 | | - |
|---|
| 624 | | - /* usage count */ |
|---|
| 625 | | - atomic_t count; |
|---|
| 626 | | - |
|---|
| 627 | | - /* List of struct btrfs_free_clusters for this block group. |
|---|
| 628 | | - * Today it will only have one thing on it, but that may change |
|---|
| 629 | | - */ |
|---|
| 630 | | - struct list_head cluster_list; |
|---|
| 631 | | - |
|---|
| 632 | | - /* For delayed block group creation or deletion of empty block groups */ |
|---|
| 633 | | - struct list_head bg_list; |
|---|
| 634 | | - |
|---|
| 635 | | - /* For read-only block groups */ |
|---|
| 636 | | - struct list_head ro_list; |
|---|
| 637 | | - |
|---|
| 638 | | - atomic_t trimming; |
|---|
| 639 | | - |
|---|
| 640 | | - /* For dirty block groups */ |
|---|
| 641 | | - struct list_head dirty_list; |
|---|
| 642 | | - struct list_head io_list; |
|---|
| 643 | | - |
|---|
| 644 | | - struct btrfs_io_ctl io_ctl; |
|---|
| 645 | | - |
|---|
| 646 | | - /* |
|---|
| 647 | | - * Incremented when doing extent allocations and holding a read lock |
|---|
| 648 | | - * on the space_info's groups_sem semaphore. |
|---|
| 649 | | - * Decremented when an ordered extent that represents an IO against this |
|---|
| 650 | | - * block group's range is created (after it's added to its inode's |
|---|
| 651 | | - * root's list of ordered extents) or immediately after the allocation |
|---|
| 652 | | - * if it's a metadata extent or fallocate extent (for these cases we |
|---|
| 653 | | - * don't create ordered extents). |
|---|
| 654 | | - */ |
|---|
| 655 | | - atomic_t reservations; |
|---|
| 656 | | - |
|---|
| 657 | | - /* |
|---|
| 658 | | - * Incremented while holding the spinlock *lock* by a task checking if |
|---|
| 659 | | - * it can perform a nocow write (incremented if the value for the *ro* |
|---|
| 660 | | - * field is 0). Decremented by such tasks once they create an ordered |
|---|
| 661 | | - * extent or before that if some error happens before reaching that step. |
|---|
| 662 | | - * This is to prevent races between block group relocation and nocow |
|---|
| 663 | | - * writes through direct IO. |
|---|
| 664 | | - */ |
|---|
| 665 | | - atomic_t nocow_writers; |
|---|
| 666 | | - |
|---|
| 667 | | - /* Lock for free space tree operations. */ |
|---|
| 668 | | - struct mutex free_space_lock; |
|---|
| 669 | | - |
|---|
| 670 | | - /* |
|---|
| 671 | | - * Does the block group need to be added to the free space tree? |
|---|
| 672 | | - * Protected by free_space_lock. |
|---|
| 673 | | - */ |
|---|
| 674 | | - int needs_free_space; |
|---|
| 675 | | - |
|---|
| 676 | | - /* Record locked full stripes for RAID5/6 block group */ |
|---|
| 677 | | - struct btrfs_full_stripe_locks_tree full_stripe_locks_root; |
|---|
| 468 | + struct btrfs_block_group *block_group; |
|---|
| 469 | + struct list_head discard_list[BTRFS_NR_DISCARD_LISTS]; |
|---|
| 470 | + u64 prev_discard; |
|---|
| 471 | + atomic_t discardable_extents; |
|---|
| 472 | + atomic64_t discardable_bytes; |
|---|
| 473 | + u64 max_discard_size; |
|---|
| 474 | + unsigned long delay; |
|---|
| 475 | + u32 iops_limit; |
|---|
| 476 | + u32 kbps_limit; |
|---|
| 477 | + u64 discard_extent_bytes; |
|---|
| 478 | + u64 discard_bitmap_bytes; |
|---|
| 479 | + atomic64_t discard_bytes_saved; |
|---|
| 678 | 480 | }; |
|---|
| 679 | 481 | |
|---|
| 680 | 482 | /* delayed seq elem */ |
|---|
| .. | .. |
|---|
| 692 | 494 | ORPHAN_CLEANUP_DONE = 2, |
|---|
| 693 | 495 | }; |
|---|
| 694 | 496 | |
|---|
| 695 | | -/* used by the raid56 code to lock stripes for read/modify/write */ |
|---|
| 696 | | -struct btrfs_stripe_hash { |
|---|
| 697 | | - struct list_head hash_list; |
|---|
| 698 | | - spinlock_t lock; |
|---|
| 699 | | -}; |
|---|
| 700 | | - |
|---|
| 701 | | -/* used by the raid56 code to lock stripes for read/modify/write */ |
|---|
| 702 | | -struct btrfs_stripe_hash_table { |
|---|
| 703 | | - struct list_head stripe_cache; |
|---|
| 704 | | - spinlock_t cache_lock; |
|---|
| 705 | | - int cache_size; |
|---|
| 706 | | - struct btrfs_stripe_hash table[]; |
|---|
| 707 | | -}; |
|---|
| 708 | | - |
|---|
| 709 | | -#define BTRFS_STRIPE_HASH_TABLE_BITS 11 |
|---|
| 710 | | - |
|---|
| 711 | | -void btrfs_init_async_reclaim_work(struct work_struct *work); |
|---|
| 497 | +void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info); |
|---|
| 712 | 498 | |
|---|
| 713 | 499 | /* fs_info */ |
|---|
| 714 | 500 | struct reloc_control; |
|---|
| .. | .. |
|---|
| 717 | 503 | struct btrfs_balance_control; |
|---|
| 718 | 504 | struct btrfs_delayed_root; |
|---|
| 719 | 505 | |
|---|
| 720 | | -#define BTRFS_FS_BARRIER 1 |
|---|
| 721 | | -#define BTRFS_FS_CLOSING_START 2 |
|---|
| 722 | | -#define BTRFS_FS_CLOSING_DONE 3 |
|---|
| 723 | | -#define BTRFS_FS_LOG_RECOVERING 4 |
|---|
| 724 | | -#define BTRFS_FS_OPEN 5 |
|---|
| 725 | | -#define BTRFS_FS_QUOTA_ENABLED 6 |
|---|
| 726 | | -#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9 |
|---|
| 727 | | -#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10 |
|---|
| 728 | | -#define BTRFS_FS_BTREE_ERR 11 |
|---|
| 729 | | -#define BTRFS_FS_LOG1_ERR 12 |
|---|
| 730 | | -#define BTRFS_FS_LOG2_ERR 13 |
|---|
| 731 | | -#define BTRFS_FS_QUOTA_OVERRIDE 14 |
|---|
| 732 | | -/* Used to record internally whether fs has been frozen */ |
|---|
| 733 | | -#define BTRFS_FS_FROZEN 15 |
|---|
| 506 | +/* |
|---|
| 507 | + * Block group or device which contains an active swapfile. Used for preventing |
|---|
| 508 | + * unsafe operations while a swapfile is active. |
|---|
| 509 | + * |
|---|
| 510 | + * These are sorted on (ptr, inode) (note that a block group or device can |
|---|
| 511 | + * contain more than one swapfile). We compare the pointer values because we |
|---|
| 512 | + * don't actually care what the object is, we just need a quick check whether |
|---|
| 513 | + * the object exists in the rbtree. |
|---|
| 514 | + */ |
|---|
| 515 | +struct btrfs_swapfile_pin { |
|---|
| 516 | + struct rb_node node; |
|---|
| 517 | + void *ptr; |
|---|
| 518 | + struct inode *inode; |
|---|
| 519 | + /* |
|---|
| 520 | + * If true, ptr points to a struct btrfs_block_group. Otherwise, ptr |
|---|
| 521 | + * points to a struct btrfs_device. |
|---|
| 522 | + */ |
|---|
| 523 | + bool is_block_group; |
|---|
| 524 | + /* |
|---|
| 525 | + * Only used when 'is_block_group' is true and it is the number of |
|---|
| 526 | + * extents used by a swapfile for this block group ('ptr' field). |
|---|
| 527 | + */ |
|---|
| 528 | + int bg_extent_count; |
|---|
| 529 | +}; |
|---|
| 530 | + |
|---|
| 531 | +bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr); |
|---|
| 532 | + |
|---|
| 533 | +enum { |
|---|
| 534 | + BTRFS_FS_BARRIER, |
|---|
| 535 | + BTRFS_FS_CLOSING_START, |
|---|
| 536 | + BTRFS_FS_CLOSING_DONE, |
|---|
| 537 | + BTRFS_FS_LOG_RECOVERING, |
|---|
| 538 | + BTRFS_FS_OPEN, |
|---|
| 539 | + BTRFS_FS_QUOTA_ENABLED, |
|---|
| 540 | + BTRFS_FS_UPDATE_UUID_TREE_GEN, |
|---|
| 541 | + BTRFS_FS_CREATING_FREE_SPACE_TREE, |
|---|
| 542 | + BTRFS_FS_BTREE_ERR, |
|---|
| 543 | + BTRFS_FS_LOG1_ERR, |
|---|
| 544 | + BTRFS_FS_LOG2_ERR, |
|---|
| 545 | + BTRFS_FS_QUOTA_OVERRIDE, |
|---|
| 546 | + /* Used to record internally whether fs has been frozen */ |
|---|
| 547 | + BTRFS_FS_FROZEN, |
|---|
| 548 | + /* |
|---|
| 549 | + * Indicate that balance has been set up from the ioctl and is in the |
|---|
| 550 | + * main phase. The fs_info::balance_ctl is initialized. |
|---|
| 551 | + * Set and cleared while holding fs_info::balance_mutex. |
|---|
| 552 | + */ |
|---|
| 553 | + BTRFS_FS_BALANCE_RUNNING, |
|---|
| 554 | + |
|---|
| 555 | + /* Indicate that the cleaner thread is awake and doing something. */ |
|---|
| 556 | + BTRFS_FS_CLEANER_RUNNING, |
|---|
| 557 | + |
|---|
| 558 | + /* |
|---|
| 559 | + * The checksumming has an optimized version and is considered fast, |
|---|
| 560 | + * so we don't need to offload checksums to workqueues. |
|---|
| 561 | + */ |
|---|
| 562 | + BTRFS_FS_CSUM_IMPL_FAST, |
|---|
| 563 | + |
|---|
| 564 | + /* Indicate that the discard workqueue can service discards. */ |
|---|
| 565 | + BTRFS_FS_DISCARD_RUNNING, |
|---|
| 566 | + |
|---|
| 567 | + /* Indicate that we can't trust the free space tree for caching yet */ |
|---|
| 568 | + BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, |
|---|
| 569 | +}; |
|---|
| 734 | 570 | |
|---|
| 735 | 571 | /* |
|---|
| 736 | | - * Indicate that a whole-filesystem exclusive operation is running |
|---|
| 737 | | - * (device replace, resize, device add/delete, balance) |
|---|
| 572 | + * Exclusive operations (device replace, resize, device add/remove, balance) |
|---|
| 738 | 573 | */ |
|---|
| 739 | | -#define BTRFS_FS_EXCL_OP 16 |
|---|
| 740 | | - |
|---|
| 741 | | -/* |
|---|
| 742 | | - * To info transaction_kthread we need an immediate commit so it doesn't |
|---|
| 743 | | - * need to wait for commit_interval |
|---|
| 744 | | - */ |
|---|
| 745 | | -#define BTRFS_FS_NEED_ASYNC_COMMIT 17 |
|---|
| 746 | | - |
|---|
| 747 | | -/* |
|---|
| 748 | | - * Indicate that balance has been set up from the ioctl and is in the main |
|---|
| 749 | | - * phase. The fs_info::balance_ctl is initialized. |
|---|
| 750 | | - */ |
|---|
| 751 | | -#define BTRFS_FS_BALANCE_RUNNING 18 |
|---|
| 574 | +enum btrfs_exclusive_operation { |
|---|
| 575 | + BTRFS_EXCLOP_NONE, |
|---|
| 576 | + BTRFS_EXCLOP_BALANCE, |
|---|
| 577 | + BTRFS_EXCLOP_DEV_ADD, |
|---|
| 578 | + BTRFS_EXCLOP_DEV_REMOVE, |
|---|
| 579 | + BTRFS_EXCLOP_DEV_REPLACE, |
|---|
| 580 | + BTRFS_EXCLOP_RESIZE, |
|---|
| 581 | + BTRFS_EXCLOP_SWAP_ACTIVATE, |
|---|
| 582 | +}; |
|---|
| 752 | 583 | |
|---|
| 753 | 584 | struct btrfs_fs_info { |
|---|
| 754 | | - u8 fsid[BTRFS_FSID_SIZE]; |
|---|
| 755 | 585 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
|---|
| 756 | 586 | unsigned long flags; |
|---|
| 757 | 587 | struct btrfs_root *extent_root; |
|---|
| .. | .. |
|---|
| 763 | 593 | struct btrfs_root *quota_root; |
|---|
| 764 | 594 | struct btrfs_root *uuid_root; |
|---|
| 765 | 595 | struct btrfs_root *free_space_root; |
|---|
| 596 | + struct btrfs_root *data_reloc_root; |
|---|
| 766 | 597 | |
|---|
| 767 | 598 | /* the log root tree is a directory of all the other log roots */ |
|---|
| 768 | 599 | struct btrfs_root *log_root_tree; |
|---|
| .. | .. |
|---|
| 778 | 609 | /* keep track of unallocated space */ |
|---|
| 779 | 610 | atomic64_t free_chunk_space; |
|---|
| 780 | 611 | |
|---|
| 781 | | - struct extent_io_tree freed_extents[2]; |
|---|
| 782 | | - struct extent_io_tree *pinned_extents; |
|---|
| 612 | + /* Track ranges which are used by log trees blocks/logged data extents */ |
|---|
| 613 | + struct extent_io_tree excluded_extents; |
|---|
| 783 | 614 | |
|---|
| 784 | 615 | /* logical->physical extent mapping */ |
|---|
| 785 | | - struct btrfs_mapping_tree mapping_tree; |
|---|
| 616 | + struct extent_map_tree mapping_tree; |
|---|
| 786 | 617 | |
|---|
| 787 | 618 | /* |
|---|
| 788 | 619 | * block reservation for extent, checksum, root tree and |
|---|
| .. | .. |
|---|
| 795 | 626 | struct btrfs_block_rsv chunk_block_rsv; |
|---|
| 796 | 627 | /* block reservation for delayed operations */ |
|---|
| 797 | 628 | struct btrfs_block_rsv delayed_block_rsv; |
|---|
| 629 | + /* block reservation for delayed refs */ |
|---|
| 630 | + struct btrfs_block_rsv delayed_refs_rsv; |
|---|
| 798 | 631 | |
|---|
| 799 | 632 | struct btrfs_block_rsv empty_block_rsv; |
|---|
| 800 | 633 | |
|---|
| .. | .. |
|---|
| 876 | 709 | struct rw_semaphore cleanup_work_sem; |
|---|
| 877 | 710 | |
|---|
| 878 | 711 | struct rw_semaphore subvol_sem; |
|---|
| 879 | | - struct srcu_struct subvol_srcu; |
|---|
| 880 | 712 | |
|---|
| 881 | 713 | spinlock_t trans_lock; |
|---|
| 882 | 714 | /* |
|---|
| .. | .. |
|---|
| 891 | 723 | |
|---|
| 892 | 724 | spinlock_t delayed_iput_lock; |
|---|
| 893 | 725 | struct list_head delayed_iputs; |
|---|
| 894 | | - struct mutex cleaner_delayed_iput_mutex; |
|---|
| 726 | + atomic_t nr_delayed_iputs; |
|---|
| 727 | + wait_queue_head_t delayed_iputs_wait; |
|---|
| 895 | 728 | |
|---|
| 896 | 729 | atomic64_t tree_mod_seq; |
|---|
| 897 | 730 | |
|---|
| .. | .. |
|---|
| 937 | 770 | struct btrfs_workqueue *endio_workers; |
|---|
| 938 | 771 | struct btrfs_workqueue *endio_meta_workers; |
|---|
| 939 | 772 | struct btrfs_workqueue *endio_raid56_workers; |
|---|
| 940 | | - struct btrfs_workqueue *endio_repair_workers; |
|---|
| 941 | 773 | struct btrfs_workqueue *rmw_workers; |
|---|
| 942 | 774 | struct btrfs_workqueue *endio_meta_write_workers; |
|---|
| 943 | 775 | struct btrfs_workqueue *endio_write_workers; |
|---|
| 944 | 776 | struct btrfs_workqueue *endio_freespace_worker; |
|---|
| 945 | | - struct btrfs_workqueue *submit_workers; |
|---|
| 946 | 777 | struct btrfs_workqueue *caching_workers; |
|---|
| 947 | 778 | struct btrfs_workqueue *readahead_workers; |
|---|
| 948 | 779 | |
|---|
| .. | .. |
|---|
| 954 | 785 | struct btrfs_workqueue *fixup_workers; |
|---|
| 955 | 786 | struct btrfs_workqueue *delayed_workers; |
|---|
| 956 | 787 | |
|---|
| 957 | | - /* the extent workers do delayed refs on the extent allocation tree */ |
|---|
| 958 | | - struct btrfs_workqueue *extent_workers; |
|---|
| 959 | 788 | struct task_struct *transaction_kthread; |
|---|
| 960 | 789 | struct task_struct *cleaner_kthread; |
|---|
| 961 | 790 | u32 thread_pool_size; |
|---|
| 962 | 791 | |
|---|
| 963 | 792 | struct kobject *space_info_kobj; |
|---|
| 964 | | - struct list_head pending_raid_kobjs; |
|---|
| 965 | | - spinlock_t pending_raid_kobjs_lock; /* uncontended */ |
|---|
| 793 | + struct kobject *qgroups_kobj; |
|---|
| 966 | 794 | |
|---|
| 967 | 795 | u64 total_pinned; |
|---|
| 968 | 796 | |
|---|
| 969 | 797 | /* used to keep from writing metadata until there is a nice batch */ |
|---|
| 970 | 798 | struct percpu_counter dirty_metadata_bytes; |
|---|
| 971 | 799 | struct percpu_counter delalloc_bytes; |
|---|
| 800 | + struct percpu_counter dio_bytes; |
|---|
| 972 | 801 | s32 dirty_metadata_batch; |
|---|
| 973 | 802 | s32 delalloc_batch; |
|---|
| 974 | 803 | |
|---|
| .. | .. |
|---|
| 1029 | 858 | atomic_t scrubs_paused; |
|---|
| 1030 | 859 | atomic_t scrub_cancel_req; |
|---|
| 1031 | 860 | wait_queue_head_t scrub_pause_wait; |
|---|
| 1032 | | - int scrub_workers_refcnt; |
|---|
| 861 | + /* |
|---|
| 862 | + * The worker pointers are NULL iff the refcount is 0, ie. scrub is not |
|---|
| 863 | + * running. |
|---|
| 864 | + */ |
|---|
| 865 | + refcount_t scrub_workers_refcnt; |
|---|
| 1033 | 866 | struct btrfs_workqueue *scrub_workers; |
|---|
| 1034 | 867 | struct btrfs_workqueue *scrub_wr_completion_workers; |
|---|
| 1035 | | - struct btrfs_workqueue *scrub_nocow_workers; |
|---|
| 1036 | 868 | struct btrfs_workqueue *scrub_parity_workers; |
|---|
| 869 | + |
|---|
| 870 | + struct btrfs_discard_ctl discard_ctl; |
|---|
| 1037 | 871 | |
|---|
| 1038 | 872 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
|---|
| 1039 | 873 | u32 check_integrity_print_mask; |
|---|
| .. | .. |
|---|
| 1043 | 877 | |
|---|
| 1044 | 878 | /* holds configuration and tracking. Protected by qgroup_lock */ |
|---|
| 1045 | 879 | struct rb_root qgroup_tree; |
|---|
| 1046 | | - struct rb_root qgroup_op_tree; |
|---|
| 1047 | 880 | spinlock_t qgroup_lock; |
|---|
| 1048 | | - spinlock_t qgroup_op_lock; |
|---|
| 1049 | | - atomic_t qgroup_op_seq; |
|---|
| 1050 | 881 | |
|---|
| 1051 | 882 | /* |
|---|
| 1052 | 883 | * used to avoid frequently calling ulist_alloc()/ulist_free() |
|---|
| .. | .. |
|---|
| 1054 | 885 | */ |
|---|
| 1055 | 886 | struct ulist *qgroup_ulist; |
|---|
| 1056 | 887 | |
|---|
| 1057 | | - /* protect user change for quota operations */ |
|---|
| 888 | + /* |
|---|
| 889 | + * Protect user change for quota operations. If a transaction is needed, |
|---|
| 890 | + * it must be started before locking this lock. |
|---|
| 891 | + */ |
|---|
| 1058 | 892 | struct mutex qgroup_ioctl_lock; |
|---|
| 1059 | 893 | |
|---|
| 1060 | 894 | /* list of dirty qgroups to be written at next commit */ |
|---|
| .. | .. |
|---|
| 1093 | 927 | /* device replace state */ |
|---|
| 1094 | 928 | struct btrfs_dev_replace dev_replace; |
|---|
| 1095 | 929 | |
|---|
| 1096 | | - struct percpu_counter bio_counter; |
|---|
| 1097 | | - wait_queue_head_t replace_wait; |
|---|
| 1098 | | - |
|---|
| 1099 | 930 | struct semaphore uuid_tree_rescan_sem; |
|---|
| 1100 | 931 | |
|---|
| 1101 | 932 | /* Used to reclaim the metadata space in the background. */ |
|---|
| 1102 | 933 | struct work_struct async_reclaim_work; |
|---|
| 934 | + struct work_struct async_data_reclaim_work; |
|---|
| 1103 | 935 | |
|---|
| 1104 | 936 | spinlock_t unused_bgs_lock; |
|---|
| 1105 | 937 | struct list_head unused_bgs; |
|---|
| 1106 | 938 | struct mutex unused_bg_unpin_mutex; |
|---|
| 1107 | 939 | struct mutex delete_unused_bgs_mutex; |
|---|
| 1108 | 940 | |
|---|
| 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 | | - |
|---|
| 1118 | 941 | /* Cached block sizes */ |
|---|
| 1119 | 942 | u32 nodesize; |
|---|
| 1120 | 943 | u32 sectorsize; |
|---|
| 1121 | 944 | u32 stripesize; |
|---|
| 1122 | 945 | |
|---|
| 946 | + /* Block groups and devices containing active swapfiles. */ |
|---|
| 947 | + spinlock_t swapfile_pins_lock; |
|---|
| 948 | + struct rb_root swapfile_pins; |
|---|
| 949 | + |
|---|
| 950 | + struct crypto_shash *csum_shash; |
|---|
| 951 | + |
|---|
| 952 | + /* |
|---|
| 953 | + * Number of send operations in progress. |
|---|
| 954 | + * Updated while holding fs_info::balance_mutex. |
|---|
| 955 | + */ |
|---|
| 956 | + int send_in_progress; |
|---|
| 957 | + |
|---|
| 958 | + /* Type of exclusive operation running */ |
|---|
| 959 | + unsigned long exclusive_operation; |
|---|
| 960 | + |
|---|
| 1123 | 961 | #ifdef CONFIG_BTRFS_FS_REF_VERIFY |
|---|
| 1124 | 962 | spinlock_t ref_verify_lock; |
|---|
| 1125 | 963 | struct rb_root block_tree; |
|---|
| 964 | +#endif |
|---|
| 965 | + |
|---|
| 966 | +#ifdef CONFIG_BTRFS_DEBUG |
|---|
| 967 | + struct kobject *debug_kobj; |
|---|
| 968 | + struct kobject *discard_debug_kobj; |
|---|
| 969 | + struct list_head allocated_roots; |
|---|
| 970 | + |
|---|
| 971 | + spinlock_t eb_leak_lock; |
|---|
| 972 | + struct list_head allocated_ebs; |
|---|
| 1126 | 973 | #endif |
|---|
| 1127 | 974 | }; |
|---|
| 1128 | 975 | |
|---|
| .. | .. |
|---|
| 1131 | 978 | return sb->s_fs_info; |
|---|
| 1132 | 979 | } |
|---|
| 1133 | 980 | |
|---|
| 1134 | | -struct btrfs_subvolume_writers { |
|---|
| 1135 | | - struct percpu_counter counter; |
|---|
| 1136 | | - wait_queue_head_t wait; |
|---|
| 1137 | | -}; |
|---|
| 1138 | | - |
|---|
| 1139 | 981 | /* |
|---|
| 1140 | 982 | * The state of btrfs root |
|---|
| 1141 | 983 | */ |
|---|
| 984 | +enum { |
|---|
| 985 | + /* |
|---|
| 986 | + * btrfs_record_root_in_trans is a multi-step process, and it can race |
|---|
| 987 | + * with the balancing code. But the race is very small, and only the |
|---|
| 988 | + * first time the root is added to each transaction. So IN_TRANS_SETUP |
|---|
| 989 | + * is used to tell us when more checks are required |
|---|
| 990 | + */ |
|---|
| 991 | + BTRFS_ROOT_IN_TRANS_SETUP, |
|---|
| 992 | + |
|---|
| 993 | + /* |
|---|
| 994 | + * Set if tree blocks of this root can be shared by other roots. |
|---|
| 995 | + * Only subvolume trees and their reloc trees have this bit set. |
|---|
| 996 | + * Conflicts with TRACK_DIRTY bit. |
|---|
| 997 | + * |
|---|
| 998 | + * This affects two things: |
|---|
| 999 | + * |
|---|
| 1000 | + * - How balance works |
|---|
| 1001 | + * For shareable roots, we need to use reloc tree and do path |
|---|
| 1002 | + * replacement for balance, and need various pre/post hooks for |
|---|
| 1003 | + * snapshot creation to handle them. |
|---|
| 1004 | + * |
|---|
| 1005 | + * While for non-shareable trees, we just simply do a tree search |
|---|
| 1006 | + * with COW. |
|---|
| 1007 | + * |
|---|
| 1008 | + * - How dirty roots are tracked |
|---|
| 1009 | + * For shareable roots, btrfs_record_root_in_trans() is needed to |
|---|
| 1010 | + * track them, while non-subvolume roots have TRACK_DIRTY bit, they |
|---|
| 1011 | + * don't need to set this manually. |
|---|
| 1012 | + */ |
|---|
| 1013 | + BTRFS_ROOT_SHAREABLE, |
|---|
| 1014 | + BTRFS_ROOT_TRACK_DIRTY, |
|---|
| 1015 | + BTRFS_ROOT_IN_RADIX, |
|---|
| 1016 | + BTRFS_ROOT_ORPHAN_ITEM_INSERTED, |
|---|
| 1017 | + BTRFS_ROOT_DEFRAG_RUNNING, |
|---|
| 1018 | + BTRFS_ROOT_FORCE_COW, |
|---|
| 1019 | + BTRFS_ROOT_MULTI_LOG_TASKS, |
|---|
| 1020 | + BTRFS_ROOT_DIRTY, |
|---|
| 1021 | + BTRFS_ROOT_DELETING, |
|---|
| 1022 | + |
|---|
| 1023 | + /* |
|---|
| 1024 | + * Reloc tree is orphan, only kept here for qgroup delayed subtree scan |
|---|
| 1025 | + * |
|---|
| 1026 | + * Set for the subvolume tree owning the reloc tree. |
|---|
| 1027 | + */ |
|---|
| 1028 | + BTRFS_ROOT_DEAD_RELOC_TREE, |
|---|
| 1029 | + /* Mark dead root stored on device whose cleanup needs to be resumed */ |
|---|
| 1030 | + BTRFS_ROOT_DEAD_TREE, |
|---|
| 1031 | + /* The root has a log tree. Used only for subvolume roots. */ |
|---|
| 1032 | + BTRFS_ROOT_HAS_LOG_TREE, |
|---|
| 1033 | + /* Qgroup flushing is in progress */ |
|---|
| 1034 | + BTRFS_ROOT_QGROUP_FLUSHING, |
|---|
| 1035 | +}; |
|---|
| 1036 | + |
|---|
| 1142 | 1037 | /* |
|---|
| 1143 | | - * btrfs_record_root_in_trans is a multi-step process, |
|---|
| 1144 | | - * and it can race with the balancing code. But the |
|---|
| 1145 | | - * race is very small, and only the first time the root |
|---|
| 1146 | | - * is added to each transaction. So IN_TRANS_SETUP |
|---|
| 1147 | | - * is used to tell us when more checks are required |
|---|
| 1038 | + * Record swapped tree blocks of a subvolume tree for delayed subtree trace |
|---|
| 1039 | + * code. For detail check comment in fs/btrfs/qgroup.c. |
|---|
| 1148 | 1040 | */ |
|---|
| 1149 | | -#define BTRFS_ROOT_IN_TRANS_SETUP 0 |
|---|
| 1150 | | -#define BTRFS_ROOT_REF_COWS 1 |
|---|
| 1151 | | -#define BTRFS_ROOT_TRACK_DIRTY 2 |
|---|
| 1152 | | -#define BTRFS_ROOT_IN_RADIX 3 |
|---|
| 1153 | | -#define BTRFS_ROOT_ORPHAN_ITEM_INSERTED 4 |
|---|
| 1154 | | -#define BTRFS_ROOT_DEFRAG_RUNNING 5 |
|---|
| 1155 | | -#define BTRFS_ROOT_FORCE_COW 6 |
|---|
| 1156 | | -#define BTRFS_ROOT_MULTI_LOG_TASKS 7 |
|---|
| 1157 | | -#define BTRFS_ROOT_DIRTY 8 |
|---|
| 1041 | +struct btrfs_qgroup_swapped_blocks { |
|---|
| 1042 | + spinlock_t lock; |
|---|
| 1043 | + /* RM_EMPTY_ROOT() of above blocks[] */ |
|---|
| 1044 | + bool swapped; |
|---|
| 1045 | + struct rb_root blocks[BTRFS_MAX_LEVEL]; |
|---|
| 1046 | +}; |
|---|
| 1158 | 1047 | |
|---|
| 1159 | 1048 | /* |
|---|
| 1160 | 1049 | * in ram representation of the tree. extent_root is used for all allocations |
|---|
| .. | .. |
|---|
| 1191 | 1080 | wait_queue_head_t log_writer_wait; |
|---|
| 1192 | 1081 | wait_queue_head_t log_commit_wait[2]; |
|---|
| 1193 | 1082 | struct list_head log_ctxs[2]; |
|---|
| 1083 | + /* Used only for log trees of subvolumes, not for the log root tree */ |
|---|
| 1194 | 1084 | atomic_t log_writers; |
|---|
| 1195 | 1085 | atomic_t log_commit[2]; |
|---|
| 1086 | + /* Used only for log trees of subvolumes, not for the log root tree */ |
|---|
| 1196 | 1087 | atomic_t log_batch; |
|---|
| 1197 | 1088 | int log_transid; |
|---|
| 1198 | 1089 | /* No matter the commit succeeds or not*/ |
|---|
| .. | .. |
|---|
| 1201 | 1092 | int last_log_commit; |
|---|
| 1202 | 1093 | pid_t log_start_pid; |
|---|
| 1203 | 1094 | |
|---|
| 1204 | | - u64 objectid; |
|---|
| 1205 | 1095 | u64 last_trans; |
|---|
| 1206 | 1096 | |
|---|
| 1207 | 1097 | u32 type; |
|---|
| 1208 | 1098 | |
|---|
| 1209 | 1099 | u64 highest_objectid; |
|---|
| 1210 | 1100 | |
|---|
| 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; |
|---|
| 1217 | 1101 | struct btrfs_key defrag_progress; |
|---|
| 1218 | 1102 | struct btrfs_key defrag_max; |
|---|
| 1219 | 1103 | |
|---|
| 1220 | | - /* the dirty list is only used by non-reference counted roots */ |
|---|
| 1104 | + /* The dirty list is only used by non-shareable roots */ |
|---|
| 1221 | 1105 | struct list_head dirty_list; |
|---|
| 1222 | 1106 | |
|---|
| 1223 | 1107 | struct list_head root_list; |
|---|
| .. | .. |
|---|
| 1273 | 1157 | u64 nr_ordered_extents; |
|---|
| 1274 | 1158 | |
|---|
| 1275 | 1159 | /* |
|---|
| 1160 | + * Not empty if this subvolume root has gone through tree block swap |
|---|
| 1161 | + * (relocation) |
|---|
| 1162 | + * |
|---|
| 1163 | + * Will be used by reloc_control::dirty_subvol_roots. |
|---|
| 1164 | + */ |
|---|
| 1165 | + struct list_head reloc_dirty_list; |
|---|
| 1166 | + |
|---|
| 1167 | + /* |
|---|
| 1276 | 1168 | * Number of currently running SEND ioctls to prevent |
|---|
| 1277 | 1169 | * manipulation with the read-only status via SUBVOL_SETFLAGS |
|---|
| 1278 | 1170 | */ |
|---|
| 1279 | 1171 | int send_in_progress; |
|---|
| 1280 | | - struct btrfs_subvolume_writers *subv_writers; |
|---|
| 1281 | | - atomic_t will_be_snapshotted; |
|---|
| 1172 | + /* |
|---|
| 1173 | + * Number of currently running deduplication operations that have a |
|---|
| 1174 | + * destination inode belonging to this root. Protected by the lock |
|---|
| 1175 | + * root_item_lock. |
|---|
| 1176 | + */ |
|---|
| 1177 | + int dedupe_in_progress; |
|---|
| 1178 | + /* For exclusion of snapshot creation and nocow writes */ |
|---|
| 1179 | + struct btrfs_drew_lock snapshot_lock; |
|---|
| 1180 | + |
|---|
| 1282 | 1181 | atomic_t snapshot_force_cow; |
|---|
| 1283 | 1182 | |
|---|
| 1284 | 1183 | /* For qgroup metadata reserved space */ |
|---|
| 1285 | 1184 | spinlock_t qgroup_meta_rsv_lock; |
|---|
| 1286 | 1185 | u64 qgroup_meta_rsv_pertrans; |
|---|
| 1287 | 1186 | u64 qgroup_meta_rsv_prealloc; |
|---|
| 1187 | + wait_queue_head_t qgroup_flush_wait; |
|---|
| 1188 | + |
|---|
| 1189 | + /* Number of active swapfiles */ |
|---|
| 1190 | + atomic_t nr_swapfiles; |
|---|
| 1191 | + |
|---|
| 1192 | + /* Record pairs of swapped blocks for qgroup */ |
|---|
| 1193 | + struct btrfs_qgroup_swapped_blocks swapped_blocks; |
|---|
| 1194 | + |
|---|
| 1195 | + /* Used only by log trees, when logging csum items */ |
|---|
| 1196 | + struct extent_io_tree log_csum_range; |
|---|
| 1197 | + |
|---|
| 1198 | +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 1199 | + u64 alloc_bytenr; |
|---|
| 1200 | +#endif |
|---|
| 1201 | + |
|---|
| 1202 | +#ifdef CONFIG_BTRFS_DEBUG |
|---|
| 1203 | + struct list_head leak_list; |
|---|
| 1204 | +#endif |
|---|
| 1205 | +}; |
|---|
| 1206 | + |
|---|
| 1207 | +/* |
|---|
| 1208 | + * Structure that conveys information about an extent that is going to replace |
|---|
| 1209 | + * all the extents in a file range. |
|---|
| 1210 | + */ |
|---|
| 1211 | +struct btrfs_replace_extent_info { |
|---|
| 1212 | + u64 disk_offset; |
|---|
| 1213 | + u64 disk_len; |
|---|
| 1214 | + u64 data_offset; |
|---|
| 1215 | + u64 data_len; |
|---|
| 1216 | + u64 file_offset; |
|---|
| 1217 | + /* Pointer to a file extent item of type regular or prealloc. */ |
|---|
| 1218 | + char *extent_buf; |
|---|
| 1219 | + /* |
|---|
| 1220 | + * Set to true when attempting to replace a file range with a new extent |
|---|
| 1221 | + * described by this structure, set to false when attempting to clone an |
|---|
| 1222 | + * existing extent into a file range. |
|---|
| 1223 | + */ |
|---|
| 1224 | + bool is_new_extent; |
|---|
| 1225 | + /* Meaningful only if is_new_extent is true. */ |
|---|
| 1226 | + int qgroup_reserved; |
|---|
| 1227 | + /* |
|---|
| 1228 | + * Meaningful only if is_new_extent is true. |
|---|
| 1229 | + * Used to track how many extent items we have already inserted in a |
|---|
| 1230 | + * subvolume tree that refer to the extent described by this structure, |
|---|
| 1231 | + * so that we know when to create a new delayed ref or update an existing |
|---|
| 1232 | + * one. |
|---|
| 1233 | + */ |
|---|
| 1234 | + int insertions; |
|---|
| 1288 | 1235 | }; |
|---|
| 1289 | 1236 | |
|---|
| 1290 | 1237 | struct btrfs_file_private { |
|---|
| 1291 | 1238 | void *filldir_buf; |
|---|
| 1292 | 1239 | }; |
|---|
| 1293 | 1240 | |
|---|
| 1294 | | -static inline u32 btrfs_inode_sectorsize(const struct inode *inode) |
|---|
| 1295 | | -{ |
|---|
| 1296 | | - return btrfs_sb(inode->i_sb)->sectorsize; |
|---|
| 1297 | | -} |
|---|
| 1298 | 1241 | |
|---|
| 1299 | 1242 | static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info) |
|---|
| 1300 | 1243 | { |
|---|
| .. | .. |
|---|
| 1342 | 1285 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) |
|---|
| 1343 | 1286 | #define BTRFS_MOUNT_SSD_SPREAD (1 << 8) |
|---|
| 1344 | 1287 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
|---|
| 1345 | | -#define BTRFS_MOUNT_DISCARD (1 << 10) |
|---|
| 1288 | +#define BTRFS_MOUNT_DISCARD_SYNC (1 << 10) |
|---|
| 1346 | 1289 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) |
|---|
| 1347 | 1290 | #define BTRFS_MOUNT_SPACE_CACHE (1 << 12) |
|---|
| 1348 | 1291 | #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13) |
|---|
| .. | .. |
|---|
| 1361 | 1304 | #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26) |
|---|
| 1362 | 1305 | #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27) |
|---|
| 1363 | 1306 | #define BTRFS_MOUNT_REF_VERIFY (1 << 28) |
|---|
| 1307 | +#define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29) |
|---|
| 1364 | 1308 | |
|---|
| 1365 | 1309 | #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) |
|---|
| 1366 | 1310 | #define BTRFS_DEFAULT_MAX_INLINE (2048) |
|---|
| .. | .. |
|---|
| 1372 | 1316 | BTRFS_MOUNT_##opt) |
|---|
| 1373 | 1317 | |
|---|
| 1374 | 1318 | #define btrfs_set_and_info(fs_info, opt, fmt, args...) \ |
|---|
| 1375 | | -{ \ |
|---|
| 1319 | +do { \ |
|---|
| 1376 | 1320 | if (!btrfs_test_opt(fs_info, opt)) \ |
|---|
| 1377 | 1321 | btrfs_info(fs_info, fmt, ##args); \ |
|---|
| 1378 | 1322 | btrfs_set_opt(fs_info->mount_opt, opt); \ |
|---|
| 1379 | | -} |
|---|
| 1323 | +} while (0) |
|---|
| 1380 | 1324 | |
|---|
| 1381 | 1325 | #define btrfs_clear_and_info(fs_info, opt, fmt, args...) \ |
|---|
| 1382 | | -{ \ |
|---|
| 1326 | +do { \ |
|---|
| 1383 | 1327 | if (btrfs_test_opt(fs_info, opt)) \ |
|---|
| 1384 | 1328 | btrfs_info(fs_info, fmt, ##args); \ |
|---|
| 1385 | 1329 | btrfs_clear_opt(fs_info->mount_opt, opt); \ |
|---|
| 1386 | | -} |
|---|
| 1387 | | - |
|---|
| 1388 | | -#ifdef CONFIG_BTRFS_DEBUG |
|---|
| 1389 | | -static inline int |
|---|
| 1390 | | -btrfs_should_fragment_free_space(struct btrfs_block_group_cache *block_group) |
|---|
| 1391 | | -{ |
|---|
| 1392 | | - struct btrfs_fs_info *fs_info = block_group->fs_info; |
|---|
| 1393 | | - |
|---|
| 1394 | | - return (btrfs_test_opt(fs_info, FRAGMENT_METADATA) && |
|---|
| 1395 | | - block_group->flags & BTRFS_BLOCK_GROUP_METADATA) || |
|---|
| 1396 | | - (btrfs_test_opt(fs_info, FRAGMENT_DATA) && |
|---|
| 1397 | | - block_group->flags & BTRFS_BLOCK_GROUP_DATA); |
|---|
| 1398 | | -} |
|---|
| 1399 | | -#endif |
|---|
| 1330 | +} while (0) |
|---|
| 1400 | 1331 | |
|---|
| 1401 | 1332 | /* |
|---|
| 1402 | 1333 | * Requests for changes that need to be done during transaction commit. |
|---|
| .. | .. |
|---|
| 1475 | 1406 | BTRFS_INODE_ROOT_ITEM_INIT) |
|---|
| 1476 | 1407 | |
|---|
| 1477 | 1408 | struct btrfs_map_token { |
|---|
| 1478 | | - const struct extent_buffer *eb; |
|---|
| 1409 | + struct extent_buffer *eb; |
|---|
| 1479 | 1410 | char *kaddr; |
|---|
| 1480 | 1411 | unsigned long offset; |
|---|
| 1481 | 1412 | }; |
|---|
| .. | .. |
|---|
| 1483 | 1414 | #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \ |
|---|
| 1484 | 1415 | ((bytes) >> (fs_info)->sb->s_blocksize_bits) |
|---|
| 1485 | 1416 | |
|---|
| 1486 | | -static inline void btrfs_init_map_token (struct btrfs_map_token *token) |
|---|
| 1417 | +static inline void btrfs_init_map_token(struct btrfs_map_token *token, |
|---|
| 1418 | + struct extent_buffer *eb) |
|---|
| 1487 | 1419 | { |
|---|
| 1488 | | - token->kaddr = NULL; |
|---|
| 1420 | + token->eb = eb; |
|---|
| 1421 | + token->kaddr = page_address(eb->pages[0]); |
|---|
| 1422 | + token->offset = 0; |
|---|
| 1489 | 1423 | } |
|---|
| 1490 | 1424 | |
|---|
| 1491 | 1425 | /* some macros to generate set/get functions for the struct fields. This |
|---|
| .. | .. |
|---|
| 1495 | 1429 | #define le8_to_cpu(v) (v) |
|---|
| 1496 | 1430 | #define cpu_to_le8(v) (v) |
|---|
| 1497 | 1431 | #define __le8 u8 |
|---|
| 1432 | + |
|---|
| 1433 | +static inline u8 get_unaligned_le8(const void *p) |
|---|
| 1434 | +{ |
|---|
| 1435 | + return *(u8 *)p; |
|---|
| 1436 | +} |
|---|
| 1437 | + |
|---|
| 1438 | +static inline void put_unaligned_le8(u8 val, void *p) |
|---|
| 1439 | +{ |
|---|
| 1440 | + *(u8 *)p = val; |
|---|
| 1441 | +} |
|---|
| 1498 | 1442 | |
|---|
| 1499 | 1443 | #define read_eb_member(eb, ptr, type, member, result) (\ |
|---|
| 1500 | 1444 | read_extent_buffer(eb, (char *)(result), \ |
|---|
| .. | .. |
|---|
| 1509 | 1453 | sizeof(((type *)0)->member))) |
|---|
| 1510 | 1454 | |
|---|
| 1511 | 1455 | #define DECLARE_BTRFS_SETGET_BITS(bits) \ |
|---|
| 1512 | | -u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \ |
|---|
| 1513 | | - const void *ptr, unsigned long off, \ |
|---|
| 1514 | | - struct btrfs_map_token *token); \ |
|---|
| 1515 | | -void btrfs_set_token_##bits(struct extent_buffer *eb, const void *ptr, \ |
|---|
| 1516 | | - unsigned long off, u##bits val, \ |
|---|
| 1517 | | - struct btrfs_map_token *token); \ |
|---|
| 1518 | | -static inline u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ |
|---|
| 1519 | | - const void *ptr, \ |
|---|
| 1520 | | - unsigned long off) \ |
|---|
| 1521 | | -{ \ |
|---|
| 1522 | | - return btrfs_get_token_##bits(eb, ptr, off, NULL); \ |
|---|
| 1523 | | -} \ |
|---|
| 1524 | | -static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr,\ |
|---|
| 1525 | | - unsigned long off, u##bits val) \ |
|---|
| 1526 | | -{ \ |
|---|
| 1527 | | - btrfs_set_token_##bits(eb, ptr, off, val, NULL); \ |
|---|
| 1528 | | -} |
|---|
| 1456 | +u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ |
|---|
| 1457 | + const void *ptr, unsigned long off); \ |
|---|
| 1458 | +void btrfs_set_token_##bits(struct btrfs_map_token *token, \ |
|---|
| 1459 | + const void *ptr, unsigned long off, \ |
|---|
| 1460 | + u##bits val); \ |
|---|
| 1461 | +u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ |
|---|
| 1462 | + const void *ptr, unsigned long off); \ |
|---|
| 1463 | +void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ |
|---|
| 1464 | + unsigned long off, u##bits val); |
|---|
| 1529 | 1465 | |
|---|
| 1530 | 1466 | DECLARE_BTRFS_SETGET_BITS(8) |
|---|
| 1531 | 1467 | DECLARE_BTRFS_SETGET_BITS(16) |
|---|
| .. | .. |
|---|
| 1539 | 1475 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ |
|---|
| 1540 | 1476 | return btrfs_get_##bits(eb, s, offsetof(type, member)); \ |
|---|
| 1541 | 1477 | } \ |
|---|
| 1542 | | -static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \ |
|---|
| 1478 | +static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ |
|---|
| 1543 | 1479 | u##bits val) \ |
|---|
| 1544 | 1480 | { \ |
|---|
| 1545 | 1481 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ |
|---|
| 1546 | 1482 | btrfs_set_##bits(eb, s, offsetof(type, member), val); \ |
|---|
| 1547 | 1483 | } \ |
|---|
| 1548 | | -static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\ |
|---|
| 1549 | | - const type *s, \ |
|---|
| 1550 | | - struct btrfs_map_token *token) \ |
|---|
| 1484 | +static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \ |
|---|
| 1485 | + const type *s) \ |
|---|
| 1551 | 1486 | { \ |
|---|
| 1552 | 1487 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ |
|---|
| 1553 | | - return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \ |
|---|
| 1488 | + return btrfs_get_token_##bits(token, s, offsetof(type, member));\ |
|---|
| 1554 | 1489 | } \ |
|---|
| 1555 | | -static inline void btrfs_set_token_##name(struct extent_buffer *eb, \ |
|---|
| 1556 | | - type *s, u##bits val, \ |
|---|
| 1557 | | - struct btrfs_map_token *token) \ |
|---|
| 1490 | +static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ |
|---|
| 1491 | + type *s, u##bits val) \ |
|---|
| 1558 | 1492 | { \ |
|---|
| 1559 | 1493 | BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \ |
|---|
| 1560 | | - btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \ |
|---|
| 1494 | + btrfs_set_token_##bits(token, s, offsetof(type, member), val); \ |
|---|
| 1561 | 1495 | } |
|---|
| 1562 | 1496 | |
|---|
| 1563 | 1497 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ |
|---|
| 1564 | 1498 | static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ |
|---|
| 1565 | 1499 | { \ |
|---|
| 1566 | 1500 | const type *p = page_address(eb->pages[0]); \ |
|---|
| 1567 | | - u##bits res = le##bits##_to_cpu(p->member); \ |
|---|
| 1568 | | - return res; \ |
|---|
| 1501 | + return get_unaligned_le##bits(&p->member); \ |
|---|
| 1569 | 1502 | } \ |
|---|
| 1570 | | -static inline void btrfs_set_##name(struct extent_buffer *eb, \ |
|---|
| 1503 | +static inline void btrfs_set_##name(const struct extent_buffer *eb, \ |
|---|
| 1571 | 1504 | u##bits val) \ |
|---|
| 1572 | 1505 | { \ |
|---|
| 1573 | 1506 | type *p = page_address(eb->pages[0]); \ |
|---|
| 1574 | | - p->member = cpu_to_le##bits(val); \ |
|---|
| 1507 | + put_unaligned_le##bits(val, &p->member); \ |
|---|
| 1575 | 1508 | } |
|---|
| 1576 | 1509 | |
|---|
| 1577 | 1510 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
|---|
| 1578 | 1511 | static inline u##bits btrfs_##name(const type *s) \ |
|---|
| 1579 | 1512 | { \ |
|---|
| 1580 | | - return le##bits##_to_cpu(s->member); \ |
|---|
| 1513 | + return get_unaligned_le##bits(&s->member); \ |
|---|
| 1581 | 1514 | } \ |
|---|
| 1582 | 1515 | static inline void btrfs_set_##name(type *s, u##bits val) \ |
|---|
| 1583 | 1516 | { \ |
|---|
| 1584 | | - s->member = cpu_to_le##bits(val); \ |
|---|
| 1517 | + put_unaligned_le##bits(val, &s->member); \ |
|---|
| 1585 | 1518 | } |
|---|
| 1586 | 1519 | |
|---|
| 1587 | | - |
|---|
| 1588 | | -static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb, |
|---|
| 1520 | +static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, |
|---|
| 1589 | 1521 | struct btrfs_dev_item *s) |
|---|
| 1590 | 1522 | { |
|---|
| 1591 | 1523 | BUILD_BUG_ON(sizeof(u64) != |
|---|
| .. | .. |
|---|
| 1593 | 1525 | return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, |
|---|
| 1594 | 1526 | total_bytes)); |
|---|
| 1595 | 1527 | } |
|---|
| 1596 | | -static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb, |
|---|
| 1528 | +static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb, |
|---|
| 1597 | 1529 | struct btrfs_dev_item *s, |
|---|
| 1598 | 1530 | u64 val) |
|---|
| 1599 | 1531 | { |
|---|
| .. | .. |
|---|
| 1697 | 1629 | return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); |
|---|
| 1698 | 1630 | } |
|---|
| 1699 | 1631 | |
|---|
| 1700 | | -static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb, |
|---|
| 1632 | +static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb, |
|---|
| 1701 | 1633 | struct btrfs_chunk *c, int nr) |
|---|
| 1702 | 1634 | { |
|---|
| 1703 | 1635 | return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); |
|---|
| 1704 | 1636 | } |
|---|
| 1705 | 1637 | |
|---|
| 1706 | | -static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, |
|---|
| 1638 | +static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb, |
|---|
| 1707 | 1639 | struct btrfs_chunk *c, int nr) |
|---|
| 1708 | 1640 | { |
|---|
| 1709 | 1641 | return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); |
|---|
| 1710 | 1642 | } |
|---|
| 1711 | 1643 | |
|---|
| 1712 | 1644 | /* struct btrfs_block_group_item */ |
|---|
| 1713 | | -BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, |
|---|
| 1645 | +BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item, |
|---|
| 1714 | 1646 | used, 64); |
|---|
| 1715 | | -BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, |
|---|
| 1647 | +BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item, |
|---|
| 1716 | 1648 | used, 64); |
|---|
| 1717 | | -BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid, |
|---|
| 1649 | +BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid, |
|---|
| 1718 | 1650 | struct btrfs_block_group_item, chunk_objectid, 64); |
|---|
| 1719 | 1651 | |
|---|
| 1720 | | -BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid, |
|---|
| 1652 | +BTRFS_SETGET_FUNCS(block_group_chunk_objectid, |
|---|
| 1721 | 1653 | struct btrfs_block_group_item, chunk_objectid, 64); |
|---|
| 1722 | | -BTRFS_SETGET_FUNCS(disk_block_group_flags, |
|---|
| 1654 | +BTRFS_SETGET_FUNCS(block_group_flags, |
|---|
| 1723 | 1655 | struct btrfs_block_group_item, flags, 64); |
|---|
| 1724 | | -BTRFS_SETGET_STACK_FUNCS(block_group_flags, |
|---|
| 1656 | +BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags, |
|---|
| 1725 | 1657 | struct btrfs_block_group_item, flags, 64); |
|---|
| 1726 | 1658 | |
|---|
| 1727 | 1659 | /* struct btrfs_free_space_info */ |
|---|
| .. | .. |
|---|
| 1783 | 1715 | BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, |
|---|
| 1784 | 1716 | chunk_offset, 64); |
|---|
| 1785 | 1717 | 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 | | - |
|---|
| 1793 | 1718 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); |
|---|
| 1794 | 1719 | BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, |
|---|
| 1795 | 1720 | generation, 64); |
|---|
| 1796 | 1721 | BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); |
|---|
| 1797 | 1722 | |
|---|
| 1798 | | -BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32); |
|---|
| 1799 | | - |
|---|
| 1800 | | - |
|---|
| 1801 | 1723 | BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); |
|---|
| 1802 | 1724 | |
|---|
| 1803 | | -static inline void btrfs_tree_block_key(struct extent_buffer *eb, |
|---|
| 1725 | +static inline void btrfs_tree_block_key(const struct extent_buffer *eb, |
|---|
| 1804 | 1726 | struct btrfs_tree_block_info *item, |
|---|
| 1805 | 1727 | struct btrfs_disk_key *key) |
|---|
| 1806 | 1728 | { |
|---|
| 1807 | 1729 | read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); |
|---|
| 1808 | 1730 | } |
|---|
| 1809 | 1731 | |
|---|
| 1810 | | -static inline void btrfs_set_tree_block_key(struct extent_buffer *eb, |
|---|
| 1732 | +static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb, |
|---|
| 1811 | 1733 | struct btrfs_tree_block_info *item, |
|---|
| 1812 | 1734 | struct btrfs_disk_key *key) |
|---|
| 1813 | 1735 | { |
|---|
| .. | .. |
|---|
| 1845 | 1767 | return 0; |
|---|
| 1846 | 1768 | } |
|---|
| 1847 | 1769 | |
|---|
| 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 | | - |
|---|
| 1854 | 1770 | /* struct btrfs_node */ |
|---|
| 1855 | 1771 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); |
|---|
| 1856 | 1772 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
|---|
| .. | .. |
|---|
| 1859 | 1775 | BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, |
|---|
| 1860 | 1776 | generation, 64); |
|---|
| 1861 | 1777 | |
|---|
| 1862 | | -static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
|---|
| 1778 | +static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr) |
|---|
| 1863 | 1779 | { |
|---|
| 1864 | 1780 | unsigned long ptr; |
|---|
| 1865 | 1781 | ptr = offsetof(struct btrfs_node, ptrs) + |
|---|
| .. | .. |
|---|
| 1867 | 1783 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); |
|---|
| 1868 | 1784 | } |
|---|
| 1869 | 1785 | |
|---|
| 1870 | | -static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
|---|
| 1786 | +static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb, |
|---|
| 1871 | 1787 | int nr, u64 val) |
|---|
| 1872 | 1788 | { |
|---|
| 1873 | 1789 | unsigned long ptr; |
|---|
| .. | .. |
|---|
| 1876 | 1792 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); |
|---|
| 1877 | 1793 | } |
|---|
| 1878 | 1794 | |
|---|
| 1879 | | -static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
|---|
| 1795 | +static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr) |
|---|
| 1880 | 1796 | { |
|---|
| 1881 | 1797 | unsigned long ptr; |
|---|
| 1882 | 1798 | ptr = offsetof(struct btrfs_node, ptrs) + |
|---|
| .. | .. |
|---|
| 1884 | 1800 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); |
|---|
| 1885 | 1801 | } |
|---|
| 1886 | 1802 | |
|---|
| 1887 | | -static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, |
|---|
| 1803 | +static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, |
|---|
| 1888 | 1804 | int nr, u64 val) |
|---|
| 1889 | 1805 | { |
|---|
| 1890 | 1806 | unsigned long ptr; |
|---|
| .. | .. |
|---|
| 1902 | 1818 | void btrfs_node_key(const struct extent_buffer *eb, |
|---|
| 1903 | 1819 | struct btrfs_disk_key *disk_key, int nr); |
|---|
| 1904 | 1820 | |
|---|
| 1905 | | -static inline void btrfs_set_node_key(struct extent_buffer *eb, |
|---|
| 1821 | +static inline void btrfs_set_node_key(const struct extent_buffer *eb, |
|---|
| 1906 | 1822 | struct btrfs_disk_key *disk_key, int nr) |
|---|
| 1907 | 1823 | { |
|---|
| 1908 | 1824 | unsigned long ptr; |
|---|
| .. | .. |
|---|
| 2026 | 1942 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); |
|---|
| 2027 | 1943 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); |
|---|
| 2028 | 1944 | |
|---|
| 1945 | +#ifdef __LITTLE_ENDIAN |
|---|
| 1946 | + |
|---|
| 1947 | +/* |
|---|
| 1948 | + * Optimized helpers for little-endian architectures where CPU and on-disk |
|---|
| 1949 | + * structures have the same endianness and we can skip conversions. |
|---|
| 1950 | + */ |
|---|
| 1951 | + |
|---|
| 1952 | +static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key, |
|---|
| 1953 | + const struct btrfs_disk_key *disk_key) |
|---|
| 1954 | +{ |
|---|
| 1955 | + memcpy(cpu_key, disk_key, sizeof(struct btrfs_key)); |
|---|
| 1956 | +} |
|---|
| 1957 | + |
|---|
| 1958 | +static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key, |
|---|
| 1959 | + const struct btrfs_key *cpu_key) |
|---|
| 1960 | +{ |
|---|
| 1961 | + memcpy(disk_key, cpu_key, sizeof(struct btrfs_key)); |
|---|
| 1962 | +} |
|---|
| 1963 | + |
|---|
| 1964 | +static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, |
|---|
| 1965 | + struct btrfs_key *cpu_key, int nr) |
|---|
| 1966 | +{ |
|---|
| 1967 | + struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
|---|
| 1968 | + |
|---|
| 1969 | + btrfs_node_key(eb, disk_key, nr); |
|---|
| 1970 | +} |
|---|
| 1971 | + |
|---|
| 1972 | +static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, |
|---|
| 1973 | + struct btrfs_key *cpu_key, int nr) |
|---|
| 1974 | +{ |
|---|
| 1975 | + struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
|---|
| 1976 | + |
|---|
| 1977 | + btrfs_item_key(eb, disk_key, nr); |
|---|
| 1978 | +} |
|---|
| 1979 | + |
|---|
| 1980 | +static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, |
|---|
| 1981 | + const struct btrfs_dir_item *item, |
|---|
| 1982 | + struct btrfs_key *cpu_key) |
|---|
| 1983 | +{ |
|---|
| 1984 | + struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
|---|
| 1985 | + |
|---|
| 1986 | + btrfs_dir_item_key(eb, item, disk_key); |
|---|
| 1987 | +} |
|---|
| 1988 | + |
|---|
| 1989 | +#else |
|---|
| 1990 | + |
|---|
| 2029 | 1991 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
|---|
| 2030 | 1992 | const struct btrfs_disk_key *disk) |
|---|
| 2031 | 1993 | { |
|---|
| .. | .. |
|---|
| 2067 | 2029 | btrfs_disk_key_to_cpu(key, &disk_key); |
|---|
| 2068 | 2030 | } |
|---|
| 2069 | 2031 | |
|---|
| 2070 | | -static inline u8 btrfs_key_type(const struct btrfs_key *key) |
|---|
| 2071 | | -{ |
|---|
| 2072 | | - return key->type; |
|---|
| 2073 | | -} |
|---|
| 2074 | | - |
|---|
| 2075 | | -static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) |
|---|
| 2076 | | -{ |
|---|
| 2077 | | - key->type = val; |
|---|
| 2078 | | -} |
|---|
| 2032 | +#endif |
|---|
| 2079 | 2033 | |
|---|
| 2080 | 2034 | /* struct btrfs_header */ |
|---|
| 2081 | 2035 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
|---|
| .. | .. |
|---|
| 2097 | 2051 | return (btrfs_header_flags(eb) & flag) == flag; |
|---|
| 2098 | 2052 | } |
|---|
| 2099 | 2053 | |
|---|
| 2100 | | -static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) |
|---|
| 2054 | +static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) |
|---|
| 2101 | 2055 | { |
|---|
| 2102 | 2056 | u64 flags = btrfs_header_flags(eb); |
|---|
| 2103 | 2057 | btrfs_set_header_flags(eb, flags | flag); |
|---|
| 2104 | | - return (flags & flag) == flag; |
|---|
| 2105 | 2058 | } |
|---|
| 2106 | 2059 | |
|---|
| 2107 | | -static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) |
|---|
| 2060 | +static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) |
|---|
| 2108 | 2061 | { |
|---|
| 2109 | 2062 | u64 flags = btrfs_header_flags(eb); |
|---|
| 2110 | 2063 | btrfs_set_header_flags(eb, flags & ~flag); |
|---|
| 2111 | | - return (flags & flag) == flag; |
|---|
| 2112 | 2064 | } |
|---|
| 2113 | 2065 | |
|---|
| 2114 | 2066 | static inline int btrfs_header_backref_rev(const struct extent_buffer *eb) |
|---|
| .. | .. |
|---|
| 2124 | 2076 | flags &= ~BTRFS_BACKREF_REV_MASK; |
|---|
| 2125 | 2077 | flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; |
|---|
| 2126 | 2078 | 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); |
|---|
| 2137 | 2079 | } |
|---|
| 2138 | 2080 | |
|---|
| 2139 | 2081 | static inline int btrfs_is_leaf(const struct extent_buffer *eb) |
|---|
| .. | .. |
|---|
| 2364 | 2306 | BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, |
|---|
| 2365 | 2307 | uuid_tree_generation, 64); |
|---|
| 2366 | 2308 | |
|---|
| 2367 | | -static inline int btrfs_super_csum_size(const struct btrfs_super_block *s) |
|---|
| 2368 | | -{ |
|---|
| 2369 | | - u16 t = btrfs_super_csum_type(s); |
|---|
| 2370 | | - /* |
|---|
| 2371 | | - * csum type is validated at mount time |
|---|
| 2372 | | - */ |
|---|
| 2373 | | - return btrfs_csum_sizes[t]; |
|---|
| 2374 | | -} |
|---|
| 2309 | +int btrfs_super_csum_size(const struct btrfs_super_block *s); |
|---|
| 2310 | +const char *btrfs_super_csum_name(u16 csum_type); |
|---|
| 2311 | +const char *btrfs_super_csum_driver(u16 csum_type); |
|---|
| 2312 | +size_t __attribute_const__ btrfs_get_num_csums(void); |
|---|
| 2375 | 2313 | |
|---|
| 2376 | 2314 | |
|---|
| 2377 | 2315 | /* |
|---|
| .. | .. |
|---|
| 2379 | 2317 | * this returns the address of the start of the last item, |
|---|
| 2380 | 2318 | * which is the stop of the leaf data stack |
|---|
| 2381 | 2319 | */ |
|---|
| 2382 | | -static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info, |
|---|
| 2383 | | - const struct extent_buffer *leaf) |
|---|
| 2320 | +static inline unsigned int leaf_data_end(const struct extent_buffer *leaf) |
|---|
| 2384 | 2321 | { |
|---|
| 2385 | 2322 | u32 nr = btrfs_header_nritems(leaf); |
|---|
| 2386 | 2323 | |
|---|
| 2387 | 2324 | if (nr == 0) |
|---|
| 2388 | | - return BTRFS_LEAF_DATA_SIZE(fs_info); |
|---|
| 2325 | + return BTRFS_LEAF_DATA_SIZE(leaf->fs_info); |
|---|
| 2389 | 2326 | return btrfs_item_offset_nr(leaf, nr - 1); |
|---|
| 2390 | 2327 | } |
|---|
| 2391 | 2328 | |
|---|
| 2392 | 2329 | /* struct btrfs_file_extent_item */ |
|---|
| 2393 | | -BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); |
|---|
| 2330 | +BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, |
|---|
| 2331 | + type, 8); |
|---|
| 2394 | 2332 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, |
|---|
| 2395 | 2333 | struct btrfs_file_extent_item, disk_bytenr, 64); |
|---|
| 2396 | 2334 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, |
|---|
| .. | .. |
|---|
| 2399 | 2337 | struct btrfs_file_extent_item, generation, 64); |
|---|
| 2400 | 2338 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, |
|---|
| 2401 | 2339 | struct btrfs_file_extent_item, num_bytes, 64); |
|---|
| 2340 | +BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, |
|---|
| 2341 | + struct btrfs_file_extent_item, ram_bytes, 64); |
|---|
| 2402 | 2342 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, |
|---|
| 2403 | 2343 | struct btrfs_file_extent_item, disk_num_bytes, 64); |
|---|
| 2404 | 2344 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, |
|---|
| .. | .. |
|---|
| 2415 | 2355 | return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; |
|---|
| 2416 | 2356 | } |
|---|
| 2417 | 2357 | |
|---|
| 2358 | +BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); |
|---|
| 2418 | 2359 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
|---|
| 2419 | 2360 | disk_bytenr, 64); |
|---|
| 2420 | 2361 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
|---|
| .. | .. |
|---|
| 2444 | 2385 | struct btrfs_item *e) |
|---|
| 2445 | 2386 | { |
|---|
| 2446 | 2387 | 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)); |
|---|
| 2471 | 2388 | } |
|---|
| 2472 | 2389 | |
|---|
| 2473 | 2390 | /* btrfs_qgroup_status_item */ |
|---|
| .. | .. |
|---|
| 2565 | 2482 | ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \ |
|---|
| 2566 | 2483 | btrfs_item_offset_nr(leaf, slot))) |
|---|
| 2567 | 2484 | |
|---|
| 2485 | +static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length) |
|---|
| 2486 | +{ |
|---|
| 2487 | + return crc32c(crc, address, length); |
|---|
| 2488 | +} |
|---|
| 2489 | + |
|---|
| 2490 | +static inline void btrfs_crc32c_final(u32 crc, u8 *result) |
|---|
| 2491 | +{ |
|---|
| 2492 | + put_unaligned_le32(~crc, result); |
|---|
| 2493 | +} |
|---|
| 2494 | + |
|---|
| 2568 | 2495 | static inline u64 btrfs_name_hash(const char *name, int len) |
|---|
| 2569 | 2496 | { |
|---|
| 2570 | 2497 | return crc32c((u32)~1, name, len); |
|---|
| .. | .. |
|---|
| 2579 | 2506 | return (u64) crc32c(parent_objectid, name, len); |
|---|
| 2580 | 2507 | } |
|---|
| 2581 | 2508 | |
|---|
| 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 | | - |
|---|
| 2588 | 2509 | static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) |
|---|
| 2589 | 2510 | { |
|---|
| 2590 | 2511 | return mapping_gfp_constraint(mapping, ~__GFP_FS); |
|---|
| .. | .. |
|---|
| 2593 | 2514 | /* extent-tree.c */ |
|---|
| 2594 | 2515 | |
|---|
| 2595 | 2516 | enum btrfs_inline_ref_type { |
|---|
| 2596 | | - BTRFS_REF_TYPE_INVALID = 0, |
|---|
| 2597 | | - BTRFS_REF_TYPE_BLOCK = 1, |
|---|
| 2598 | | - BTRFS_REF_TYPE_DATA = 2, |
|---|
| 2599 | | - BTRFS_REF_TYPE_ANY = 3, |
|---|
| 2517 | + BTRFS_REF_TYPE_INVALID, |
|---|
| 2518 | + BTRFS_REF_TYPE_BLOCK, |
|---|
| 2519 | + BTRFS_REF_TYPE_DATA, |
|---|
| 2520 | + BTRFS_REF_TYPE_ANY, |
|---|
| 2600 | 2521 | }; |
|---|
| 2601 | 2522 | |
|---|
| 2602 | 2523 | int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb, |
|---|
| 2603 | 2524 | struct btrfs_extent_inline_ref *iref, |
|---|
| 2604 | 2525 | enum btrfs_inline_ref_type is_data); |
|---|
| 2526 | +u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset); |
|---|
| 2605 | 2527 | |
|---|
| 2606 | 2528 | u64 btrfs_csum_bytes_to_leaves(struct btrfs_fs_info *fs_info, u64 csum_bytes); |
|---|
| 2607 | 2529 | |
|---|
| 2608 | | -static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_fs_info *fs_info, |
|---|
| 2609 | | - unsigned num_items) |
|---|
| 2530 | +/* |
|---|
| 2531 | + * Use this if we would be adding new items, as we could split nodes as we cow |
|---|
| 2532 | + * down the tree. |
|---|
| 2533 | + */ |
|---|
| 2534 | +static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info, |
|---|
| 2535 | + unsigned num_items) |
|---|
| 2610 | 2536 | { |
|---|
| 2611 | 2537 | return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; |
|---|
| 2612 | 2538 | } |
|---|
| 2613 | 2539 | |
|---|
| 2614 | 2540 | /* |
|---|
| 2615 | | - * Doing a truncate won't result in new nodes or leaves, just what we need for |
|---|
| 2616 | | - * COW. |
|---|
| 2541 | + * Doing a truncate or a modification won't result in new nodes or leaves, just |
|---|
| 2542 | + * what we need for COW. |
|---|
| 2617 | 2543 | */ |
|---|
| 2618 | | -static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_fs_info *fs_info, |
|---|
| 2544 | +static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info, |
|---|
| 2619 | 2545 | unsigned num_items) |
|---|
| 2620 | 2546 | { |
|---|
| 2621 | 2547 | return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items; |
|---|
| 2622 | 2548 | } |
|---|
| 2623 | 2549 | |
|---|
| 2624 | | -int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, |
|---|
| 2625 | | - struct btrfs_fs_info *fs_info); |
|---|
| 2626 | | -int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, |
|---|
| 2627 | | - struct btrfs_fs_info *fs_info); |
|---|
| 2628 | | -void btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info, |
|---|
| 2629 | | - const u64 start); |
|---|
| 2630 | | -void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg); |
|---|
| 2631 | | -bool btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); |
|---|
| 2632 | | -void btrfs_dec_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr); |
|---|
| 2633 | | -void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg); |
|---|
| 2634 | | -void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
|---|
| 2550 | +int btrfs_add_excluded_extent(struct btrfs_fs_info *fs_info, |
|---|
| 2551 | + u64 start, u64 num_bytes); |
|---|
| 2552 | +void btrfs_free_excluded_extents(struct btrfs_block_group *cache); |
|---|
| 2635 | 2553 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, |
|---|
| 2636 | 2554 | unsigned long count); |
|---|
| 2637 | | -int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info, |
|---|
| 2638 | | - unsigned long count, u64 transid, int wait); |
|---|
| 2555 | +void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, |
|---|
| 2556 | + struct btrfs_delayed_ref_root *delayed_refs, |
|---|
| 2557 | + struct btrfs_delayed_ref_head *head); |
|---|
| 2639 | 2558 | int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len); |
|---|
| 2640 | 2559 | int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, |
|---|
| 2641 | 2560 | struct btrfs_fs_info *fs_info, u64 bytenr, |
|---|
| 2642 | 2561 | u64 offset, int metadata, u64 *refs, u64 *flags); |
|---|
| 2643 | | -int btrfs_pin_extent(struct btrfs_fs_info *fs_info, |
|---|
| 2644 | | - u64 bytenr, u64 num, int reserved); |
|---|
| 2645 | | -int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info, |
|---|
| 2562 | +int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num, |
|---|
| 2563 | + int reserved); |
|---|
| 2564 | +int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans, |
|---|
| 2646 | 2565 | u64 bytenr, u64 num_bytes); |
|---|
| 2647 | | -int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, |
|---|
| 2648 | | - struct extent_buffer *eb); |
|---|
| 2566 | +int btrfs_exclude_logged_extents(struct extent_buffer *eb); |
|---|
| 2649 | 2567 | int btrfs_cross_ref_exist(struct btrfs_root *root, |
|---|
| 2650 | | - u64 objectid, u64 offset, u64 bytenr); |
|---|
| 2651 | | -struct btrfs_block_group_cache *btrfs_lookup_block_group( |
|---|
| 2652 | | - struct btrfs_fs_info *info, |
|---|
| 2653 | | - u64 bytenr); |
|---|
| 2654 | | -void btrfs_get_block_group(struct btrfs_block_group_cache *cache); |
|---|
| 2655 | | -void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
|---|
| 2568 | + u64 objectid, u64 offset, u64 bytenr, bool strict); |
|---|
| 2656 | 2569 | struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, |
|---|
| 2657 | 2570 | struct btrfs_root *root, |
|---|
| 2658 | 2571 | u64 parent, u64 root_objectid, |
|---|
| 2659 | 2572 | const struct btrfs_disk_key *key, |
|---|
| 2660 | 2573 | int level, u64 hint, |
|---|
| 2661 | | - u64 empty_size); |
|---|
| 2574 | + u64 empty_size, |
|---|
| 2575 | + enum btrfs_lock_nesting nest); |
|---|
| 2662 | 2576 | void btrfs_free_tree_block(struct btrfs_trans_handle *trans, |
|---|
| 2663 | 2577 | struct btrfs_root *root, |
|---|
| 2664 | 2578 | struct extent_buffer *buf, |
|---|
| .. | .. |
|---|
| 2678 | 2592 | int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
|---|
| 2679 | 2593 | struct extent_buffer *buf, int full_backref); |
|---|
| 2680 | 2594 | int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, |
|---|
| 2681 | | - struct btrfs_fs_info *fs_info, |
|---|
| 2682 | | - u64 bytenr, u64 num_bytes, u64 flags, |
|---|
| 2595 | + struct extent_buffer *eb, u64 flags, |
|---|
| 2683 | 2596 | int level, int is_data); |
|---|
| 2684 | | -int btrfs_free_extent(struct btrfs_trans_handle *trans, |
|---|
| 2685 | | - struct btrfs_root *root, |
|---|
| 2686 | | - u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid, |
|---|
| 2687 | | - u64 owner, u64 offset); |
|---|
| 2597 | +int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); |
|---|
| 2688 | 2598 | |
|---|
| 2689 | 2599 | int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, |
|---|
| 2690 | 2600 | u64 start, u64 len, int delalloc); |
|---|
| 2691 | | -int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info, |
|---|
| 2692 | | - u64 start, u64 len); |
|---|
| 2693 | | -void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info); |
|---|
| 2601 | +int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start, |
|---|
| 2602 | + u64 len); |
|---|
| 2694 | 2603 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); |
|---|
| 2695 | 2604 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
|---|
| 2696 | | - struct btrfs_root *root, |
|---|
| 2697 | | - u64 bytenr, u64 num_bytes, u64 parent, |
|---|
| 2698 | | - u64 root_objectid, u64 owner, u64 offset); |
|---|
| 2605 | + struct btrfs_ref *generic_ref); |
|---|
| 2699 | 2606 | |
|---|
| 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); |
|---|
| 2705 | 2607 | 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); |
|---|
| 2725 | 2608 | void btrfs_clear_space_info_full(struct btrfs_fs_info *info); |
|---|
| 2726 | 2609 | |
|---|
| 2610 | +/* |
|---|
| 2611 | + * Different levels for to flush space when doing space reservations. |
|---|
| 2612 | + * |
|---|
| 2613 | + * The higher the level, the more methods we try to reclaim space. |
|---|
| 2614 | + */ |
|---|
| 2727 | 2615 | enum btrfs_reserve_flush_enum { |
|---|
| 2728 | 2616 | /* If we are in the transaction, we can't flush anything.*/ |
|---|
| 2729 | 2617 | BTRFS_RESERVE_NO_FLUSH, |
|---|
| 2618 | + |
|---|
| 2730 | 2619 | /* |
|---|
| 2731 | | - * Flushing delalloc may cause deadlock somewhere, in this |
|---|
| 2732 | | - * case, use FLUSH LIMIT |
|---|
| 2620 | + * Flush space by: |
|---|
| 2621 | + * - Running delayed inode items |
|---|
| 2622 | + * - Allocating a new chunk |
|---|
| 2733 | 2623 | */ |
|---|
| 2734 | 2624 | BTRFS_RESERVE_FLUSH_LIMIT, |
|---|
| 2625 | + |
|---|
| 2626 | + /* |
|---|
| 2627 | + * Flush space by: |
|---|
| 2628 | + * - Running delayed inode items |
|---|
| 2629 | + * - Running delayed refs |
|---|
| 2630 | + * - Running delalloc and waiting for ordered extents |
|---|
| 2631 | + * - Allocating a new chunk |
|---|
| 2632 | + */ |
|---|
| 2633 | + BTRFS_RESERVE_FLUSH_EVICT, |
|---|
| 2634 | + |
|---|
| 2635 | + /* |
|---|
| 2636 | + * Flush space by above mentioned methods and by: |
|---|
| 2637 | + * - Running delayed iputs |
|---|
| 2638 | + * - Commiting transaction |
|---|
| 2639 | + * |
|---|
| 2640 | + * Can be interruped by fatal signal. |
|---|
| 2641 | + */ |
|---|
| 2642 | + BTRFS_RESERVE_FLUSH_DATA, |
|---|
| 2643 | + BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE, |
|---|
| 2735 | 2644 | BTRFS_RESERVE_FLUSH_ALL, |
|---|
| 2645 | + |
|---|
| 2646 | + /* |
|---|
| 2647 | + * Pretty much the same as FLUSH_ALL, but can also steal space from |
|---|
| 2648 | + * global rsv. |
|---|
| 2649 | + * |
|---|
| 2650 | + * Can be interruped by fatal signal. |
|---|
| 2651 | + */ |
|---|
| 2652 | + BTRFS_RESERVE_FLUSH_ALL_STEAL, |
|---|
| 2736 | 2653 | }; |
|---|
| 2737 | 2654 | |
|---|
| 2738 | 2655 | enum btrfs_flush_state { |
|---|
| 2739 | 2656 | FLUSH_DELAYED_ITEMS_NR = 1, |
|---|
| 2740 | 2657 | FLUSH_DELAYED_ITEMS = 2, |
|---|
| 2741 | | - FLUSH_DELALLOC = 3, |
|---|
| 2742 | | - FLUSH_DELALLOC_WAIT = 4, |
|---|
| 2743 | | - ALLOC_CHUNK = 5, |
|---|
| 2744 | | - COMMIT_TRANS = 6, |
|---|
| 2658 | + FLUSH_DELAYED_REFS_NR = 3, |
|---|
| 2659 | + FLUSH_DELAYED_REFS = 4, |
|---|
| 2660 | + FLUSH_DELALLOC = 5, |
|---|
| 2661 | + FLUSH_DELALLOC_WAIT = 6, |
|---|
| 2662 | + ALLOC_CHUNK = 7, |
|---|
| 2663 | + ALLOC_CHUNK_FORCE = 8, |
|---|
| 2664 | + RUN_DELAYED_IPUTS = 9, |
|---|
| 2665 | + COMMIT_TRANS = 10, |
|---|
| 2745 | 2666 | }; |
|---|
| 2746 | 2667 | |
|---|
| 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); |
|---|
| 2758 | 2668 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
|---|
| 2759 | 2669 | struct btrfs_block_rsv *rsv, |
|---|
| 2760 | 2670 | int nitems, bool use_global_rsv); |
|---|
| 2761 | | -void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, |
|---|
| 2671 | +void btrfs_subvolume_release_metadata(struct btrfs_root *root, |
|---|
| 2762 | 2672 | struct btrfs_block_rsv *rsv); |
|---|
| 2763 | 2673 | void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes); |
|---|
| 2764 | 2674 | |
|---|
| 2765 | 2675 | 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); |
|---|
| 2797 | 2676 | u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); |
|---|
| 2798 | 2677 | int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, |
|---|
| 2799 | 2678 | u64 start, u64 end); |
|---|
| 2800 | 2679 | int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, |
|---|
| 2801 | 2680 | u64 num_bytes, u64 *actual_bytes); |
|---|
| 2802 | | -int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type); |
|---|
| 2803 | 2681 | int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); |
|---|
| 2804 | 2682 | |
|---|
| 2805 | 2683 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info); |
|---|
| .. | .. |
|---|
| 2808 | 2686 | int btrfs_start_write_no_snapshotting(struct btrfs_root *root); |
|---|
| 2809 | 2687 | void btrfs_end_write_no_snapshotting(struct btrfs_root *root); |
|---|
| 2810 | 2688 | 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); |
|---|
| 2815 | 2689 | |
|---|
| 2816 | 2690 | /* ctree.c */ |
|---|
| 2817 | 2691 | int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, |
|---|
| 2818 | | - int level, int *slot); |
|---|
| 2819 | | -int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); |
|---|
| 2692 | + int *slot); |
|---|
| 2693 | +int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); |
|---|
| 2820 | 2694 | int btrfs_previous_item(struct btrfs_root *root, |
|---|
| 2821 | 2695 | struct btrfs_path *path, u64 min_objectid, |
|---|
| 2822 | 2696 | int type); |
|---|
| .. | .. |
|---|
| 2826 | 2700 | struct btrfs_path *path, |
|---|
| 2827 | 2701 | const struct btrfs_key *new_key); |
|---|
| 2828 | 2702 | 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); |
|---|
| 2831 | 2703 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, |
|---|
| 2832 | 2704 | struct btrfs_key *key, int lowest_level, |
|---|
| 2833 | 2705 | u64 min_trans); |
|---|
| 2834 | 2706 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, |
|---|
| 2835 | 2707 | struct btrfs_path *path, |
|---|
| 2836 | 2708 | u64 min_trans); |
|---|
| 2837 | | -enum btrfs_compare_tree_result { |
|---|
| 2838 | | - BTRFS_COMPARE_TREE_NEW, |
|---|
| 2839 | | - BTRFS_COMPARE_TREE_DELETED, |
|---|
| 2840 | | - BTRFS_COMPARE_TREE_CHANGED, |
|---|
| 2841 | | - BTRFS_COMPARE_TREE_SAME, |
|---|
| 2842 | | -}; |
|---|
| 2843 | | -typedef int (*btrfs_changed_cb_t)(struct btrfs_path *left_path, |
|---|
| 2844 | | - struct btrfs_path *right_path, |
|---|
| 2845 | | - struct btrfs_key *key, |
|---|
| 2846 | | - enum btrfs_compare_tree_result result, |
|---|
| 2847 | | - void *ctx); |
|---|
| 2848 | | -int btrfs_compare_trees(struct btrfs_root *left_root, |
|---|
| 2849 | | - struct btrfs_root *right_root, |
|---|
| 2850 | | - btrfs_changed_cb_t cb, void *ctx); |
|---|
| 2709 | +struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent, |
|---|
| 2710 | + int slot); |
|---|
| 2711 | + |
|---|
| 2851 | 2712 | int btrfs_cow_block(struct btrfs_trans_handle *trans, |
|---|
| 2852 | 2713 | struct btrfs_root *root, struct extent_buffer *buf, |
|---|
| 2853 | 2714 | struct extent_buffer *parent, int parent_slot, |
|---|
| 2854 | | - struct extent_buffer **cow_ret); |
|---|
| 2715 | + struct extent_buffer **cow_ret, |
|---|
| 2716 | + enum btrfs_lock_nesting nest); |
|---|
| 2855 | 2717 | int btrfs_copy_root(struct btrfs_trans_handle *trans, |
|---|
| 2856 | 2718 | struct btrfs_root *root, |
|---|
| 2857 | 2719 | struct extent_buffer *buf, |
|---|
| 2858 | 2720 | struct extent_buffer **cow_ret, u64 new_root_objectid); |
|---|
| 2859 | 2721 | int btrfs_block_can_be_shared(struct btrfs_root *root, |
|---|
| 2860 | 2722 | struct extent_buffer *buf); |
|---|
| 2861 | | -void btrfs_extend_item(struct btrfs_fs_info *fs_info, struct btrfs_path *path, |
|---|
| 2862 | | - u32 data_size); |
|---|
| 2863 | | -void btrfs_truncate_item(struct btrfs_fs_info *fs_info, |
|---|
| 2864 | | - struct btrfs_path *path, u32 new_size, int from_end); |
|---|
| 2723 | +void btrfs_extend_item(struct btrfs_path *path, u32 data_size); |
|---|
| 2724 | +void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end); |
|---|
| 2865 | 2725 | int btrfs_split_item(struct btrfs_trans_handle *trans, |
|---|
| 2866 | 2726 | struct btrfs_root *root, |
|---|
| 2867 | 2727 | struct btrfs_path *path, |
|---|
| .. | .. |
|---|
| 2889 | 2749 | void btrfs_release_path(struct btrfs_path *p); |
|---|
| 2890 | 2750 | struct btrfs_path *btrfs_alloc_path(void); |
|---|
| 2891 | 2751 | 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); |
|---|
| 2896 | 2752 | |
|---|
| 2897 | 2753 | int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
|---|
| 2898 | 2754 | struct btrfs_path *path, int slot, int nr); |
|---|
| .. | .. |
|---|
| 2905 | 2761 | |
|---|
| 2906 | 2762 | void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, |
|---|
| 2907 | 2763 | const struct btrfs_key *cpu_key, u32 *data_size, |
|---|
| 2908 | | - u32 total_data, u32 total_size, int nr); |
|---|
| 2764 | + int nr); |
|---|
| 2909 | 2765 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
|---|
| 2910 | 2766 | const struct btrfs_key *key, void *data, u32 data_size); |
|---|
| 2911 | 2767 | int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, |
|---|
| .. | .. |
|---|
| 2939 | 2795 | { |
|---|
| 2940 | 2796 | return btrfs_next_old_item(root, p, 0); |
|---|
| 2941 | 2797 | } |
|---|
| 2942 | | -int btrfs_leaf_free_space(struct btrfs_fs_info *fs_info, |
|---|
| 2943 | | - struct extent_buffer *leaf); |
|---|
| 2944 | | -int __must_check btrfs_drop_snapshot(struct btrfs_root *root, |
|---|
| 2945 | | - struct btrfs_block_rsv *block_rsv, |
|---|
| 2946 | | - int update_ref, int for_reloc); |
|---|
| 2798 | +int btrfs_leaf_free_space(struct extent_buffer *leaf); |
|---|
| 2799 | +int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, |
|---|
| 2800 | + int for_reloc); |
|---|
| 2947 | 2801 | int btrfs_drop_subtree(struct btrfs_trans_handle *trans, |
|---|
| 2948 | 2802 | struct btrfs_root *root, |
|---|
| 2949 | 2803 | struct extent_buffer *node, |
|---|
| .. | .. |
|---|
| 2969 | 2823 | static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info) |
|---|
| 2970 | 2824 | { |
|---|
| 2971 | 2825 | 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); |
|---|
| 2990 | 2826 | } |
|---|
| 2991 | 2827 | |
|---|
| 2992 | 2828 | /* tree mod log functions from ctree.c */ |
|---|
| .. | .. |
|---|
| 3027 | 2863 | u64 subid); |
|---|
| 3028 | 2864 | int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, |
|---|
| 3029 | 2865 | u64 subid); |
|---|
| 3030 | | -int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info, |
|---|
| 3031 | | - int (*check_func)(struct btrfs_fs_info *, u8 *, u8, |
|---|
| 3032 | | - u64)); |
|---|
| 2866 | +int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info); |
|---|
| 3033 | 2867 | |
|---|
| 3034 | 2868 | /* dir-item.c */ |
|---|
| 3035 | 2869 | int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir, |
|---|
| 3036 | 2870 | const char *name, int name_len); |
|---|
| 3037 | | -int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, |
|---|
| 3038 | | - struct btrfs_root *root, const char *name, |
|---|
| 2871 | +int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name, |
|---|
| 3039 | 2872 | int name_len, struct btrfs_inode *dir, |
|---|
| 3040 | 2873 | struct btrfs_key *location, u8 type, u64 index); |
|---|
| 3041 | 2874 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
|---|
| .. | .. |
|---|
| 3103 | 2936 | u64 inode_objectid, u64 ref_objectid, int ins_len, |
|---|
| 3104 | 2937 | int cow); |
|---|
| 3105 | 2938 | |
|---|
| 3106 | | -int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot, |
|---|
| 3107 | | - const char *name, |
|---|
| 3108 | | - int name_len, struct btrfs_inode_ref **ref_ret); |
|---|
| 3109 | | -int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot, |
|---|
| 3110 | | - u64 ref_objectid, const char *name, |
|---|
| 3111 | | - int name_len, |
|---|
| 3112 | | - struct btrfs_inode_extref **extref_ret); |
|---|
| 3113 | | - |
|---|
| 2939 | +struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf, |
|---|
| 2940 | + int slot, const char *name, |
|---|
| 2941 | + int name_len); |
|---|
| 2942 | +struct btrfs_inode_extref *btrfs_find_name_in_ext_backref( |
|---|
| 2943 | + struct extent_buffer *leaf, int slot, u64 ref_objectid, |
|---|
| 2944 | + const char *name, int name_len); |
|---|
| 3114 | 2945 | /* file-item.c */ |
|---|
| 3115 | 2946 | struct btrfs_dio_private; |
|---|
| 3116 | 2947 | int btrfs_del_csums(struct btrfs_trans_handle *trans, |
|---|
| 3117 | 2948 | struct btrfs_root *root, u64 bytenr, u64 len); |
|---|
| 3118 | | -blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u32 *dst); |
|---|
| 3119 | | -blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, |
|---|
| 3120 | | - u64 logical_offset); |
|---|
| 2949 | +blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, |
|---|
| 2950 | + u64 offset, u8 *dst); |
|---|
| 3121 | 2951 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
|---|
| 3122 | 2952 | struct btrfs_root *root, |
|---|
| 3123 | 2953 | u64 objectid, u64 pos, |
|---|
| .. | .. |
|---|
| 3131 | 2961 | int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, |
|---|
| 3132 | 2962 | struct btrfs_root *root, |
|---|
| 3133 | 2963 | struct btrfs_ordered_sum *sums); |
|---|
| 3134 | | -blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, |
|---|
| 3135 | | - u64 file_start, int contig); |
|---|
| 2964 | +blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio, |
|---|
| 2965 | + u64 file_start, int contig); |
|---|
| 3136 | 2966 | int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, |
|---|
| 3137 | 2967 | struct list_head *list, int search_commit); |
|---|
| 3138 | 2968 | void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, |
|---|
| .. | .. |
|---|
| 3140 | 2970 | struct btrfs_file_extent_item *fi, |
|---|
| 3141 | 2971 | const bool new_inline, |
|---|
| 3142 | 2972 | struct extent_map *em); |
|---|
| 2973 | +int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, |
|---|
| 2974 | + u64 len); |
|---|
| 2975 | +int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, |
|---|
| 2976 | + u64 len); |
|---|
| 2977 | +void btrfs_inode_safe_disk_i_size_write(struct inode *inode, u64 new_i_size); |
|---|
| 2978 | +u64 btrfs_file_extent_end(const struct btrfs_path *path); |
|---|
| 3143 | 2979 | |
|---|
| 3144 | 2980 | /* inode.c */ |
|---|
| 2981 | +blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, |
|---|
| 2982 | + int mirror_num, unsigned long bio_flags); |
|---|
| 2983 | +int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, |
|---|
| 2984 | + struct page *page, u64 start, u64 end, int mirror); |
|---|
| 3145 | 2985 | struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, |
|---|
| 3146 | | - struct page *page, size_t pg_offset, u64 start, |
|---|
| 3147 | | - u64 len, int create); |
|---|
| 2986 | + u64 start, u64 len); |
|---|
| 3148 | 2987 | noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, |
|---|
| 3149 | 2988 | u64 *orig_start, u64 *orig_block_len, |
|---|
| 3150 | | - u64 *ram_bytes); |
|---|
| 2989 | + u64 *ram_bytes, bool strict); |
|---|
| 3151 | 2990 | |
|---|
| 3152 | 2991 | void __btrfs_del_delalloc_inode(struct btrfs_root *root, |
|---|
| 3153 | 2992 | struct btrfs_inode *inode); |
|---|
| .. | .. |
|---|
| 3169 | 3008 | u32 min_type); |
|---|
| 3170 | 3009 | |
|---|
| 3171 | 3010 | int btrfs_start_delalloc_snapshot(struct btrfs_root *root); |
|---|
| 3172 | | -int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr); |
|---|
| 3173 | | -int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, |
|---|
| 3011 | +int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr, |
|---|
| 3012 | + bool in_reclaim_context); |
|---|
| 3013 | +int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end, |
|---|
| 3174 | 3014 | unsigned int extra_bits, |
|---|
| 3175 | | - struct extent_state **cached_state, int dedupe); |
|---|
| 3015 | + struct extent_state **cached_state); |
|---|
| 3176 | 3016 | int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, |
|---|
| 3177 | 3017 | struct btrfs_root *new_root, |
|---|
| 3178 | 3018 | struct btrfs_root *parent_root, |
|---|
| 3179 | 3019 | u64 new_dirid); |
|---|
| 3180 | | -int btrfs_merge_bio_hook(struct page *page, unsigned long offset, |
|---|
| 3181 | | - size_t size, struct bio *bio, |
|---|
| 3182 | | - unsigned long bio_flags); |
|---|
| 3020 | + void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state, |
|---|
| 3021 | + unsigned *bits); |
|---|
| 3022 | +void btrfs_clear_delalloc_extent(struct inode *inode, |
|---|
| 3023 | + struct extent_state *state, unsigned *bits); |
|---|
| 3024 | +void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new, |
|---|
| 3025 | + struct extent_state *other); |
|---|
| 3026 | +void btrfs_split_delalloc_extent(struct inode *inode, |
|---|
| 3027 | + struct extent_state *orig, u64 split); |
|---|
| 3028 | +int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio, |
|---|
| 3029 | + unsigned long bio_flags); |
|---|
| 3183 | 3030 | void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end); |
|---|
| 3184 | 3031 | vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); |
|---|
| 3185 | 3032 | int btrfs_readpage(struct file *file, struct page *page); |
|---|
| .. | .. |
|---|
| 3187 | 3034 | int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); |
|---|
| 3188 | 3035 | struct inode *btrfs_alloc_inode(struct super_block *sb); |
|---|
| 3189 | 3036 | void btrfs_destroy_inode(struct inode *inode); |
|---|
| 3037 | +void btrfs_free_inode(struct inode *inode); |
|---|
| 3190 | 3038 | int btrfs_drop_inode(struct inode *inode); |
|---|
| 3191 | 3039 | int __init btrfs_init_cachep(void); |
|---|
| 3192 | 3040 | void __cold btrfs_destroy_cachep(void); |
|---|
| 3193 | | -struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location, |
|---|
| 3194 | | - struct btrfs_root *root, int *new, |
|---|
| 3195 | | - struct btrfs_path *path); |
|---|
| 3196 | | -struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, |
|---|
| 3197 | | - struct btrfs_root *root, int *was_new); |
|---|
| 3041 | +struct inode *btrfs_iget_path(struct super_block *s, u64 ino, |
|---|
| 3042 | + struct btrfs_root *root, struct btrfs_path *path); |
|---|
| 3043 | +struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root); |
|---|
| 3198 | 3044 | struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, |
|---|
| 3199 | | - struct page *page, size_t pg_offset, |
|---|
| 3200 | | - u64 start, u64 end, int create); |
|---|
| 3045 | + struct page *page, size_t pg_offset, |
|---|
| 3046 | + u64 start, u64 end); |
|---|
| 3201 | 3047 | int btrfs_update_inode(struct btrfs_trans_handle *trans, |
|---|
| 3202 | 3048 | struct btrfs_root *root, |
|---|
| 3203 | 3049 | struct inode *inode); |
|---|
| .. | .. |
|---|
| 3209 | 3055 | int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size); |
|---|
| 3210 | 3056 | void btrfs_add_delayed_iput(struct inode *inode); |
|---|
| 3211 | 3057 | void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info); |
|---|
| 3058 | +int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info); |
|---|
| 3212 | 3059 | int btrfs_prealloc_file_range(struct inode *inode, int mode, |
|---|
| 3213 | 3060 | u64 start, u64 num_bytes, u64 min_size, |
|---|
| 3214 | 3061 | loff_t actual_len, u64 *alloc_hint); |
|---|
| .. | .. |
|---|
| 3216 | 3063 | struct btrfs_trans_handle *trans, int mode, |
|---|
| 3217 | 3064 | u64 start, u64 num_bytes, u64 min_size, |
|---|
| 3218 | 3065 | loff_t actual_len, u64 *alloc_hint); |
|---|
| 3219 | | -int btrfs_run_delalloc_range(void *private_data, struct page *locked_page, |
|---|
| 3066 | +int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page, |
|---|
| 3220 | 3067 | u64 start, u64 end, int *page_started, unsigned long *nr_written, |
|---|
| 3221 | 3068 | struct writeback_control *wbc); |
|---|
| 3069 | +int btrfs_writepage_cow_fixup(struct page *page, u64 start, u64 end); |
|---|
| 3070 | +void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start, |
|---|
| 3071 | + u64 end, int uptodate); |
|---|
| 3222 | 3072 | extern const struct dentry_operations btrfs_dentry_operations; |
|---|
| 3223 | | -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 3224 | | -void btrfs_test_inode_set_ops(struct inode *inode); |
|---|
| 3225 | | -#endif |
|---|
| 3073 | +ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter); |
|---|
| 3226 | 3074 | |
|---|
| 3227 | 3075 | /* ioctl.c */ |
|---|
| 3228 | 3076 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
|---|
| 3229 | 3077 | long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
|---|
| 3230 | 3078 | int btrfs_ioctl_get_supported_features(void __user *arg); |
|---|
| 3231 | 3079 | void btrfs_sync_inode_flags_to_i_flags(struct inode *inode); |
|---|
| 3232 | | -int btrfs_is_empty_uuid(u8 *uuid); |
|---|
| 3080 | +int __pure btrfs_is_empty_uuid(u8 *uuid); |
|---|
| 3233 | 3081 | int btrfs_defrag_file(struct inode *inode, struct file *file, |
|---|
| 3234 | 3082 | struct btrfs_ioctl_defrag_range_args *range, |
|---|
| 3235 | 3083 | u64 newer_than, unsigned long max_pages); |
|---|
| .. | .. |
|---|
| 3237 | 3085 | struct btrfs_ioctl_space_info *space); |
|---|
| 3238 | 3086 | void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info, |
|---|
| 3239 | 3087 | struct btrfs_ioctl_balance_args *bargs); |
|---|
| 3240 | | -int btrfs_dedupe_file_range(struct file *src_file, loff_t src_loff, |
|---|
| 3241 | | - struct file *dst_file, loff_t dst_loff, |
|---|
| 3242 | | - u64 olen); |
|---|
| 3088 | +bool btrfs_exclop_start(struct btrfs_fs_info *fs_info, |
|---|
| 3089 | + enum btrfs_exclusive_operation type); |
|---|
| 3090 | +void btrfs_exclop_finish(struct btrfs_fs_info *fs_info); |
|---|
| 3243 | 3091 | |
|---|
| 3244 | 3092 | /* file.c */ |
|---|
| 3245 | 3093 | int __init btrfs_auto_defrag_init(void); |
|---|
| .. | .. |
|---|
| 3253 | 3101 | int skip_pinned); |
|---|
| 3254 | 3102 | extern const struct file_operations btrfs_file_operations; |
|---|
| 3255 | 3103 | int __btrfs_drop_extents(struct btrfs_trans_handle *trans, |
|---|
| 3256 | | - struct btrfs_root *root, struct inode *inode, |
|---|
| 3104 | + struct btrfs_root *root, struct btrfs_inode *inode, |
|---|
| 3257 | 3105 | struct btrfs_path *path, u64 start, u64 end, |
|---|
| 3258 | 3106 | u64 *drop_end, int drop_cache, |
|---|
| 3259 | 3107 | int replace_extent, |
|---|
| .. | .. |
|---|
| 3262 | 3110 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, |
|---|
| 3263 | 3111 | struct btrfs_root *root, struct inode *inode, u64 start, |
|---|
| 3264 | 3112 | u64 end, int drop_cache); |
|---|
| 3113 | +int btrfs_replace_file_extents(struct inode *inode, struct btrfs_path *path, |
|---|
| 3114 | + const u64 start, const u64 end, |
|---|
| 3115 | + struct btrfs_replace_extent_info *extent_info, |
|---|
| 3116 | + struct btrfs_trans_handle **trans_out); |
|---|
| 3265 | 3117 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
|---|
| 3266 | 3118 | struct btrfs_inode *inode, u64 start, u64 end); |
|---|
| 3267 | 3119 | int btrfs_release_file(struct inode *inode, struct file *file); |
|---|
| 3268 | | -int btrfs_dirty_pages(struct inode *inode, struct page **pages, |
|---|
| 3120 | +int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages, |
|---|
| 3269 | 3121 | size_t num_pages, loff_t pos, size_t write_bytes, |
|---|
| 3270 | 3122 | struct extent_state **cached); |
|---|
| 3271 | 3123 | int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); |
|---|
| 3272 | | -int btrfs_clone_file_range(struct file *file_in, loff_t pos_in, |
|---|
| 3273 | | - struct file *file_out, loff_t pos_out, u64 len); |
|---|
| 3124 | +int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos, |
|---|
| 3125 | + size_t *write_bytes); |
|---|
| 3126 | +void btrfs_check_nocow_unlock(struct btrfs_inode *inode); |
|---|
| 3274 | 3127 | |
|---|
| 3275 | 3128 | /* tree-defrag.c */ |
|---|
| 3276 | 3129 | int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, |
|---|
| 3277 | 3130 | 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); |
|---|
| 3284 | 3131 | |
|---|
| 3285 | 3132 | /* super.c */ |
|---|
| 3286 | 3133 | int btrfs_parse_options(struct btrfs_fs_info *info, char *options, |
|---|
| .. | .. |
|---|
| 3374 | 3221 | |
|---|
| 3375 | 3222 | #if defined(CONFIG_DYNAMIC_DEBUG) |
|---|
| 3376 | 3223 | #define btrfs_debug(fs_info, fmt, args...) \ |
|---|
| 3377 | | -do { \ |
|---|
| 3378 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 3379 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ |
|---|
| 3380 | | - btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \ |
|---|
| 3381 | | -} while (0) |
|---|
| 3382 | | -#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ |
|---|
| 3383 | | -do { \ |
|---|
| 3384 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 3385 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ |
|---|
| 3386 | | - btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \ |
|---|
| 3387 | | -} while (0) |
|---|
| 3224 | + _dynamic_func_call_no_desc(fmt, btrfs_printk, \ |
|---|
| 3225 | + fs_info, KERN_DEBUG fmt, ##args) |
|---|
| 3226 | +#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ |
|---|
| 3227 | + _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ |
|---|
| 3228 | + fs_info, KERN_DEBUG fmt, ##args) |
|---|
| 3388 | 3229 | #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ |
|---|
| 3389 | | -do { \ |
|---|
| 3390 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 3391 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ |
|---|
| 3392 | | - btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \ |
|---|
| 3393 | | - ##args);\ |
|---|
| 3394 | | -} while (0) |
|---|
| 3395 | | -#define btrfs_debug_rl(fs_info, fmt, args...) \ |
|---|
| 3396 | | -do { \ |
|---|
| 3397 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 3398 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ |
|---|
| 3399 | | - btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \ |
|---|
| 3400 | | - ##args); \ |
|---|
| 3401 | | -} while (0) |
|---|
| 3230 | + _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ |
|---|
| 3231 | + fs_info, KERN_DEBUG fmt, ##args) |
|---|
| 3232 | +#define btrfs_debug_rl(fs_info, fmt, args...) \ |
|---|
| 3233 | + _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ |
|---|
| 3234 | + fs_info, KERN_DEBUG fmt, ##args) |
|---|
| 3402 | 3235 | #elif defined(DEBUG) |
|---|
| 3403 | 3236 | #define btrfs_debug(fs_info, fmt, args...) \ |
|---|
| 3404 | 3237 | btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) |
|---|
| .. | .. |
|---|
| 3450 | 3283 | } while (0) |
|---|
| 3451 | 3284 | |
|---|
| 3452 | 3285 | #ifdef CONFIG_BTRFS_ASSERT |
|---|
| 3453 | | - |
|---|
| 3454 | | -__cold |
|---|
| 3455 | | -static inline void assfail(const char *expr, const char *file, int line) |
|---|
| 3286 | +__cold __noreturn |
|---|
| 3287 | +static inline void assertfail(const char *expr, const char *file, int line) |
|---|
| 3456 | 3288 | { |
|---|
| 3457 | | - pr_err("assertion failed: %s, file: %s, line: %d\n", |
|---|
| 3458 | | - expr, file, line); |
|---|
| 3289 | + pr_err("assertion failed: %s, in %s:%d\n", expr, file, line); |
|---|
| 3459 | 3290 | BUG(); |
|---|
| 3460 | 3291 | } |
|---|
| 3461 | 3292 | |
|---|
| 3462 | | -#define ASSERT(expr) \ |
|---|
| 3463 | | - (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) |
|---|
| 3293 | +#define ASSERT(expr) \ |
|---|
| 3294 | + (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__)) |
|---|
| 3295 | + |
|---|
| 3464 | 3296 | #else |
|---|
| 3465 | | -#define ASSERT(expr) ((void)0) |
|---|
| 3297 | +static inline void assertfail(const char *expr, const char* file, int line) { } |
|---|
| 3298 | +#define ASSERT(expr) (void)(expr) |
|---|
| 3299 | +#endif |
|---|
| 3300 | + |
|---|
| 3301 | +/* |
|---|
| 3302 | + * Use that for functions that are conditionally exported for sanity tests but |
|---|
| 3303 | + * otherwise static |
|---|
| 3304 | + */ |
|---|
| 3305 | +#ifndef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 3306 | +#define EXPORT_FOR_TESTS static |
|---|
| 3307 | +#else |
|---|
| 3308 | +#define EXPORT_FOR_TESTS |
|---|
| 3466 | 3309 | #endif |
|---|
| 3467 | 3310 | |
|---|
| 3468 | 3311 | __cold |
|---|
| .. | .. |
|---|
| 3477 | 3320 | void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function, |
|---|
| 3478 | 3321 | unsigned int line, int errno, const char *fmt, ...); |
|---|
| 3479 | 3322 | |
|---|
| 3480 | | -const char *btrfs_decode_error(int errno); |
|---|
| 3323 | +const char * __attribute_const__ btrfs_decode_error(int errno); |
|---|
| 3481 | 3324 | |
|---|
| 3482 | 3325 | __cold |
|---|
| 3483 | 3326 | void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, |
|---|
| .. | .. |
|---|
| 3493 | 3336 | /* Report first abort since mount */ \ |
|---|
| 3494 | 3337 | if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ |
|---|
| 3495 | 3338 | &((trans)->fs_info->fs_state))) { \ |
|---|
| 3496 | | - if ((errno) != -EIO) { \ |
|---|
| 3339 | + if ((errno) != -EIO && (errno) != -EROFS) { \ |
|---|
| 3497 | 3340 | WARN(1, KERN_DEBUG \ |
|---|
| 3498 | 3341 | "BTRFS: Transaction aborted (error %d)\n", \ |
|---|
| 3499 | 3342 | (errno)); \ |
|---|
| .. | .. |
|---|
| 3531 | 3374 | /* compatibility and incompatibility defines */ |
|---|
| 3532 | 3375 | |
|---|
| 3533 | 3376 | #define btrfs_set_fs_incompat(__fs_info, opt) \ |
|---|
| 3534 | | - __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) |
|---|
| 3377 | + __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \ |
|---|
| 3378 | + #opt) |
|---|
| 3535 | 3379 | |
|---|
| 3536 | 3380 | static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, |
|---|
| 3537 | | - u64 flag) |
|---|
| 3381 | + u64 flag, const char* name) |
|---|
| 3538 | 3382 | { |
|---|
| 3539 | 3383 | struct btrfs_super_block *disk_super; |
|---|
| 3540 | 3384 | u64 features; |
|---|
| .. | .. |
|---|
| 3547 | 3391 | if (!(features & flag)) { |
|---|
| 3548 | 3392 | features |= flag; |
|---|
| 3549 | 3393 | btrfs_set_super_incompat_flags(disk_super, features); |
|---|
| 3550 | | - btrfs_info(fs_info, "setting %llu feature flag", |
|---|
| 3551 | | - flag); |
|---|
| 3394 | + btrfs_info(fs_info, |
|---|
| 3395 | + "setting incompat feature flag for %s (0x%llx)", |
|---|
| 3396 | + name, flag); |
|---|
| 3552 | 3397 | } |
|---|
| 3553 | 3398 | spin_unlock(&fs_info->super_lock); |
|---|
| 3554 | 3399 | } |
|---|
| 3555 | 3400 | } |
|---|
| 3556 | 3401 | |
|---|
| 3557 | 3402 | #define btrfs_clear_fs_incompat(__fs_info, opt) \ |
|---|
| 3558 | | - __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt) |
|---|
| 3403 | + __btrfs_clear_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \ |
|---|
| 3404 | + #opt) |
|---|
| 3559 | 3405 | |
|---|
| 3560 | 3406 | static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, |
|---|
| 3561 | | - u64 flag) |
|---|
| 3407 | + u64 flag, const char* name) |
|---|
| 3562 | 3408 | { |
|---|
| 3563 | 3409 | struct btrfs_super_block *disk_super; |
|---|
| 3564 | 3410 | u64 features; |
|---|
| .. | .. |
|---|
| 3571 | 3417 | if (features & flag) { |
|---|
| 3572 | 3418 | features &= ~flag; |
|---|
| 3573 | 3419 | btrfs_set_super_incompat_flags(disk_super, features); |
|---|
| 3574 | | - btrfs_info(fs_info, "clearing %llu feature flag", |
|---|
| 3575 | | - flag); |
|---|
| 3420 | + btrfs_info(fs_info, |
|---|
| 3421 | + "clearing incompat feature flag for %s (0x%llx)", |
|---|
| 3422 | + name, flag); |
|---|
| 3576 | 3423 | } |
|---|
| 3577 | 3424 | spin_unlock(&fs_info->super_lock); |
|---|
| 3578 | 3425 | } |
|---|
| .. | .. |
|---|
| 3589 | 3436 | } |
|---|
| 3590 | 3437 | |
|---|
| 3591 | 3438 | #define btrfs_set_fs_compat_ro(__fs_info, opt) \ |
|---|
| 3592 | | - __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) |
|---|
| 3439 | + __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \ |
|---|
| 3440 | + #opt) |
|---|
| 3593 | 3441 | |
|---|
| 3594 | 3442 | static inline void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, |
|---|
| 3595 | | - u64 flag) |
|---|
| 3443 | + u64 flag, const char *name) |
|---|
| 3596 | 3444 | { |
|---|
| 3597 | 3445 | struct btrfs_super_block *disk_super; |
|---|
| 3598 | 3446 | u64 features; |
|---|
| .. | .. |
|---|
| 3605 | 3453 | if (!(features & flag)) { |
|---|
| 3606 | 3454 | features |= flag; |
|---|
| 3607 | 3455 | btrfs_set_super_compat_ro_flags(disk_super, features); |
|---|
| 3608 | | - btrfs_info(fs_info, "setting %llu ro feature flag", |
|---|
| 3609 | | - flag); |
|---|
| 3456 | + btrfs_info(fs_info, |
|---|
| 3457 | + "setting compat-ro feature flag for %s (0x%llx)", |
|---|
| 3458 | + name, flag); |
|---|
| 3610 | 3459 | } |
|---|
| 3611 | 3460 | spin_unlock(&fs_info->super_lock); |
|---|
| 3612 | 3461 | } |
|---|
| 3613 | 3462 | } |
|---|
| 3614 | 3463 | |
|---|
| 3615 | 3464 | #define btrfs_clear_fs_compat_ro(__fs_info, opt) \ |
|---|
| 3616 | | - __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) |
|---|
| 3465 | + __btrfs_clear_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \ |
|---|
| 3466 | + #opt) |
|---|
| 3617 | 3467 | |
|---|
| 3618 | 3468 | static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, |
|---|
| 3619 | | - u64 flag) |
|---|
| 3469 | + u64 flag, const char *name) |
|---|
| 3620 | 3470 | { |
|---|
| 3621 | 3471 | struct btrfs_super_block *disk_super; |
|---|
| 3622 | 3472 | u64 features; |
|---|
| .. | .. |
|---|
| 3629 | 3479 | if (features & flag) { |
|---|
| 3630 | 3480 | features &= ~flag; |
|---|
| 3631 | 3481 | btrfs_set_super_compat_ro_flags(disk_super, features); |
|---|
| 3632 | | - btrfs_info(fs_info, "clearing %llu ro feature flag", |
|---|
| 3633 | | - flag); |
|---|
| 3482 | + btrfs_info(fs_info, |
|---|
| 3483 | + "clearing compat-ro feature flag for %s (0x%llx)", |
|---|
| 3484 | + name, flag); |
|---|
| 3634 | 3485 | } |
|---|
| 3635 | 3486 | spin_unlock(&fs_info->super_lock); |
|---|
| 3636 | 3487 | } |
|---|
| .. | .. |
|---|
| 3669 | 3520 | int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, |
|---|
| 3670 | 3521 | struct btrfs_root *root); |
|---|
| 3671 | 3522 | int btrfs_recover_relocation(struct btrfs_root *root); |
|---|
| 3672 | | -int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len); |
|---|
| 3523 | +int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len); |
|---|
| 3673 | 3524 | int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, |
|---|
| 3674 | 3525 | struct btrfs_root *root, struct extent_buffer *buf, |
|---|
| 3675 | 3526 | struct extent_buffer *cow); |
|---|
| .. | .. |
|---|
| 3677 | 3528 | u64 *bytes_to_reserve); |
|---|
| 3678 | 3529 | int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, |
|---|
| 3679 | 3530 | struct btrfs_pending_snapshot *pending); |
|---|
| 3531 | +int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info); |
|---|
| 3532 | +struct btrfs_root *find_reloc_root(struct btrfs_fs_info *fs_info, |
|---|
| 3533 | + u64 bytenr); |
|---|
| 3534 | +int btrfs_should_ignore_reloc_root(struct btrfs_root *root); |
|---|
| 3680 | 3535 | |
|---|
| 3681 | 3536 | /* scrub.c */ |
|---|
| 3682 | 3537 | int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, |
|---|
| .. | .. |
|---|
| 3685 | 3540 | void btrfs_scrub_pause(struct btrfs_fs_info *fs_info); |
|---|
| 3686 | 3541 | void btrfs_scrub_continue(struct btrfs_fs_info *fs_info); |
|---|
| 3687 | 3542 | int btrfs_scrub_cancel(struct btrfs_fs_info *info); |
|---|
| 3688 | | -int btrfs_scrub_cancel_dev(struct btrfs_fs_info *info, |
|---|
| 3689 | | - struct btrfs_device *dev); |
|---|
| 3543 | +int btrfs_scrub_cancel_dev(struct btrfs_device *dev); |
|---|
| 3690 | 3544 | int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid, |
|---|
| 3691 | 3545 | struct btrfs_scrub_progress *progress); |
|---|
| 3692 | 3546 | static inline void btrfs_init_full_stripe_locks_tree( |
|---|
| .. | .. |
|---|
| 3720 | 3574 | int btrfs_reada_wait(void *handle); |
|---|
| 3721 | 3575 | void btrfs_reada_detach(void *handle); |
|---|
| 3722 | 3576 | int btree_readahead_hook(struct extent_buffer *eb, int err); |
|---|
| 3577 | +void btrfs_reada_remove_dev(struct btrfs_device *dev); |
|---|
| 3578 | +void btrfs_reada_undo_remove_dev(struct btrfs_device *dev); |
|---|
| 3723 | 3579 | |
|---|
| 3724 | 3580 | static inline int is_fstree(u64 rootid) |
|---|
| 3725 | 3581 | { |
|---|
| .. | .. |
|---|
| 3735 | 3591 | return signal_pending(current); |
|---|
| 3736 | 3592 | } |
|---|
| 3737 | 3593 | |
|---|
| 3594 | +#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len)) |
|---|
| 3595 | + |
|---|
| 3738 | 3596 | /* Sanity test specific functions */ |
|---|
| 3739 | 3597 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 3740 | 3598 | void btrfs_test_destroy_inode(struct inode *inode); |
|---|
| 3741 | | -#endif |
|---|
| 3742 | | - |
|---|
| 3743 | 3599 | static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) |
|---|
| 3744 | 3600 | { |
|---|
| 3745 | | -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
|---|
| 3746 | | - if (unlikely(test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, |
|---|
| 3747 | | - &fs_info->fs_state))) |
|---|
| 3748 | | - return 1; |
|---|
| 3749 | | -#endif |
|---|
| 3601 | + return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); |
|---|
| 3602 | +} |
|---|
| 3603 | +#else |
|---|
| 3604 | +static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) |
|---|
| 3605 | +{ |
|---|
| 3750 | 3606 | return 0; |
|---|
| 3751 | 3607 | } |
|---|
| 3752 | | - |
|---|
| 3753 | | -static inline void cond_wake_up(struct wait_queue_head *wq) |
|---|
| 3754 | | -{ |
|---|
| 3755 | | - /* |
|---|
| 3756 | | - * This implies a full smp_mb barrier, see comments for |
|---|
| 3757 | | - * waitqueue_active why. |
|---|
| 3758 | | - */ |
|---|
| 3759 | | - if (wq_has_sleeper(wq)) |
|---|
| 3760 | | - wake_up(wq); |
|---|
| 3761 | | -} |
|---|
| 3762 | | - |
|---|
| 3763 | | -static inline void cond_wake_up_nomb(struct wait_queue_head *wq) |
|---|
| 3764 | | -{ |
|---|
| 3765 | | - /* |
|---|
| 3766 | | - * Special case for conditional wakeup where the barrier required for |
|---|
| 3767 | | - * waitqueue_active is implied by some of the preceding code. Eg. one |
|---|
| 3768 | | - * of such atomic operations (atomic_dec_and_return, ...), or a |
|---|
| 3769 | | - * unlock/lock sequence, etc. |
|---|
| 3770 | | - */ |
|---|
| 3771 | | - if (waitqueue_active(wq)) |
|---|
| 3772 | | - wake_up(wq); |
|---|
| 3773 | | -} |
|---|
| 3608 | +#endif |
|---|
| 3774 | 3609 | |
|---|
| 3775 | 3610 | #endif |
|---|