Pull btrfs updates from David Sterba: "This round there are a lot of cleanups and moved code so the diffstat looks huge, otherwise there are some nice performance improvements and an update to raid56 reliability. User visible features: - raid56 reliability vs performance trade off: - fix destructive RMW for raid5 data (raid6 still needs work): do full checksum verification for all data during RMW cycle, this should prevent rewriting potentially corrupted data without notice - stripes are cached in memory which should reduce the performance impact but still can hurt some workloads - checksums are verified after repair again - this is the last option without introducing additional features (write intent bitmap, journal, another tree), the extra checksum read/verification was supposed to be avoided by the original implementation exactly for performance reasons but that caused all the reliability problems - discard=async by default for devices that support it - implement emergency flush reserve to avoid almost all unnecessary transaction aborts due to ENOSPC in cases where there are too many delayed refs or delayed allocation - skip block group synchronization if there's no change in used bytes, can reduce transaction commit count for some workloads Performance improvements: - fiemap and lseek: - overall speedup due to skipping unnecessary or duplicate searches (-40% run time) - cache some data structures and sharedness of extents (-30% run time) - send: - faster backref resolution when finding clones - cached leaf to root mapping for faster backref walking - improved clone/sharing detection - overall run time improvements (-70%) Core: - module initialization converted to a table of function pointers run in a sequence - preparation for fscrypt, extend passing file names across calls, dir item can store encryption status - raid56 updates: - more accurate error tracking of sectors within stripe - simplify recovery path and remove dedicated endio worker kthread - simplify scrub call paths - refactoring to support the extra data checksum verification during RMW cycle - tree block parentness checks consolidated and done at metadata read time - improved error handling - cleanups: - move a lot of code for better synchronization between kernel and user space sources, split big files - enum cleanups - GFP flag cleanups - header file cleanups, prototypes, dependencies - redundant parameter cleanups - inline extent handling simplifications - inode parameter conversion - data structure cleanups, reductions, renames, merges" * tag 'for-6.2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (249 commits) btrfs: print transaction aborted messages with an error level btrfs: sync some cleanups from progs into uapi/btrfs.h btrfs: do not BUG_ON() on ENOMEM when dropping extent items for a range btrfs: fix extent map use-after-free when handling missing device in read_one_chunk btrfs: remove outdated logic from overwrite_item() and add assertion btrfs: unify overwrite_item() and do_overwrite_item() btrfs: replace strncpy() with strscpy() btrfs: fix uninitialized variable in find_first_clear_extent_bit btrfs: fix uninitialized parent in insert_state btrfs: add might_sleep() annotations btrfs: add stack helpers for a few btrfs items btrfs: add nr_global_roots to the super block definition btrfs: remove BTRFS_LEAF_DATA_OFFSET btrfs: add helpers for manipulating leaf items and data btrfs: add eb to btrfs_node_key_ptr_offset btrfs: pass the extent buffer for the btrfs_item_nr helpers btrfs: move the csum helpers into ctree.h btrfs: move eb offset helpers into extent_io.h btrfs: move file_extent_item helpers into file-item.h btrfs: move leaf_data_end into ctree.c ...
Showing the changes to include/uapi (2 of 121 files). Show all
Unified · Split
| @@ -19,8 +19,14 @@ · 18 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | #ifndef _UAPI_LINUX_BTRFS_H |
| 21 | 21 | #define _UAPI_LINUX_BTRFS_H |
| 22 | + | |
| 23 | +#ifdef __cplusplus | |
| 24 | +extern "C" { | |
| 25 | +#endif | |
| 26 | + | |
| 22 | 27 | #include <linux/types.h> |
| 23 | 28 | #include <linux/ioctl.h> |
| 29 | +#include <linux/fs.h> | |
| 24 | 30 | |
| 25 | 31 | #define BTRFS_IOCTL_MAGIC 0x94 |
| 26 | 32 | #define BTRFS_VOL_NAME_MAX 255 |
| @@ -333,6 +339,12 @@ struct btrfs_ioctl_feature_flags { · 306 unmodified lines | ||
| 333 | 339 | */ |
| 334 | 340 | struct btrfs_balance_args { |
| 335 | 341 | __u64 profiles; |
| 342 | + | |
| 343 | + /* | |
| 344 | + * usage filter | |
| 345 | + * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' | |
| 346 | + * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max | |
| 347 | + */ | |
| 336 | 348 | union { |
| 337 | 349 | __u64 usage; |
| 338 | 350 | struct { |
| @@ -549,7 +561,7 @@ struct btrfs_ioctl_search_header { · 210 unmodified lines | ||
| 549 | 561 | __u64 offset; |
| 550 | 562 | __u32 type; |
| 551 | 563 | __u32 len; |
| 552 | −}; | |
| 564 | +} __attribute__ ((__may_alias__)); | |
| 553 | 565 | |
| 554 | 566 | #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) |
| 555 | 567 | /* |
| @@ -562,6 +574,10 @@ struct btrfs_ioctl_search_args { · 6 unmodified lines | ||
| 562 | 574 | char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; |
| 563 | 575 | }; |
| 564 | 576 | |
| 577 | +/* | |
| 578 | + * Extended version of TREE_SEARCH ioctl that can return more than 4k of bytes. | |
| 579 | + * The allocated size of the buffer is set in buf_size. | |
| 580 | + */ | |
| 565 | 581 | struct btrfs_ioctl_search_args_v2 { |
| 566 | 582 | struct btrfs_ioctl_search_key key; /* in/out - search parameters */ |
| 567 | 583 | __u64 buf_size; /* in - size of buffer |
| @@ -570,10 +586,11 @@ struct btrfs_ioctl_search_args_v2 { · 2 unmodified lines | ||
| 570 | 586 | __u64 buf[]; /* out - found items */ |
| 571 | 587 | }; |
| 572 | 588 | |
| 589 | +/* With a @src_length of zero, the range from @src_offset->EOF is cloned! */ | |
| 573 | 590 | struct btrfs_ioctl_clone_range_args { |
| 574 | − __s64 src_fd; | |
| 575 | − __u64 src_offset, src_length; | |
| 576 | − __u64 dest_offset; | |
| 591 | + __s64 src_fd; | |
| 592 | + __u64 src_offset, src_length; | |
| 593 | + __u64 dest_offset; | |
| 577 | 594 | }; |
| 578 | 595 | |
| 579 | 596 | /* |
| @@ -677,8 +694,11 @@ struct btrfs_ioctl_logical_ino_args { · 97 unmodified lines | ||
| 677 | 694 | /* struct btrfs_data_container *inodes; out */ |
| 678 | 695 | __u64 inodes; |
| 679 | 696 | }; |
| 680 | −/* Return every ref to the extent, not just those containing logical block. | |
| 681 | − * Requires logical == extent bytenr. */ | |
| 697 | + | |
| 698 | +/* | |
| 699 | + * Return every ref to the extent, not just those containing logical block. | |
| 700 | + * Requires logical == extent bytenr. | |
| 701 | + */ | |
| 682 | 702 | #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0) |
| 683 | 703 | |
| 684 | 704 | enum btrfs_dev_stat_values { |
| @@ -1144,4 +1164,8 @@ enum btrfs_err_code { · 459 unmodified lines | ||
| 1144 | 1164 | #define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, \ |
| 1145 | 1165 | struct btrfs_ioctl_encoded_io_args) |
| 1146 | 1166 | |
| 1167 | +#ifdef __cplusplus | |
| 1168 | +} | |
| 1169 | +#endif | |
| 1170 | + | |
| 1147 | 1171 | #endif /* _UAPI_LINUX_BTRFS_H */ |
| @@ -10,6 +10,23 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <stddef.h> |
| 11 | 11 | #endif |
| 12 | 12 | |
| 13 | +/* ASCII for _BHRfS_M, no terminating nul */ | |
| 14 | +#define BTRFS_MAGIC 0x4D5F53665248425FULL | |
| 15 | + | |
| 16 | +#define BTRFS_MAX_LEVEL 8 | |
| 17 | + | |
| 18 | +/* | |
| 19 | + * We can actually store much bigger names, but lets not confuse the rest of | |
| 20 | + * linux. | |
| 21 | + */ | |
| 22 | +#define BTRFS_NAME_LEN 255 | |
| 23 | + | |
| 24 | +/* | |
| 25 | + * Theoretical limit is larger, but we keep this down to a sane value. That | |
| 26 | + * should limit greatly the possibility of collisions on inode ref items. | |
| 27 | + */ | |
| 28 | +#define BTRFS_LINK_MAX 65535U | |
| 29 | + | |
| 13 | 30 | /* |
| 14 | 31 | * This header contains the structure definitions and constants used |
| 15 | 32 | * by file system objects that can be retrieved using |
| @@ -359,6 +376,50 @@ enum btrfs_csum_type { · 343 unmodified lines | ||
| 359 | 376 | #define BTRFS_FT_SYMLINK 7 |
| 360 | 377 | #define BTRFS_FT_XATTR 8 |
| 361 | 378 | #define BTRFS_FT_MAX 9 |
| 379 | +/* Directory contains encrypted data */ | |
| 380 | +#define BTRFS_FT_ENCRYPTED 0x80 | |
| 381 | + | |
| 382 | +static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags) | |
| 383 | +{ | |
| 384 | + return flags & ~BTRFS_FT_ENCRYPTED; | |
| 385 | +} | |
| 386 | + | |
| 387 | +/* | |
| 388 | + * Inode flags | |
| 389 | + */ | |
| 390 | +#define BTRFS_INODE_NODATASUM (1U << 0) | |
| 391 | +#define BTRFS_INODE_NODATACOW (1U << 1) | |
| 392 | +#define BTRFS_INODE_READONLY (1U << 2) | |
| 393 | +#define BTRFS_INODE_NOCOMPRESS (1U << 3) | |
| 394 | +#define BTRFS_INODE_PREALLOC (1U << 4) | |
| 395 | +#define BTRFS_INODE_SYNC (1U << 5) | |
| 396 | +#define BTRFS_INODE_IMMUTABLE (1U << 6) | |
| 397 | +#define BTRFS_INODE_APPEND (1U << 7) | |
| 398 | +#define BTRFS_INODE_NODUMP (1U << 8) | |
| 399 | +#define BTRFS_INODE_NOATIME (1U << 9) | |
| 400 | +#define BTRFS_INODE_DIRSYNC (1U << 10) | |
| 401 | +#define BTRFS_INODE_COMPRESS (1U << 11) | |
| 402 | + | |
| 403 | +#define BTRFS_INODE_ROOT_ITEM_INIT (1U << 31) | |
| 404 | + | |
| 405 | +#define BTRFS_INODE_FLAG_MASK \ | |
| 406 | + (BTRFS_INODE_NODATASUM | \ | |
| 407 | + BTRFS_INODE_NODATACOW | \ | |
| 408 | + BTRFS_INODE_READONLY | \ | |
| 409 | + BTRFS_INODE_NOCOMPRESS | \ | |
| 410 | + BTRFS_INODE_PREALLOC | \ | |
| 411 | + BTRFS_INODE_SYNC | \ | |
| 412 | + BTRFS_INODE_IMMUTABLE | \ | |
| 413 | + BTRFS_INODE_APPEND | \ | |
| 414 | + BTRFS_INODE_NODUMP | \ | |
| 415 | + BTRFS_INODE_NOATIME | \ | |
| 416 | + BTRFS_INODE_DIRSYNC | \ | |
| 417 | + BTRFS_INODE_COMPRESS | \ | |
| 418 | + BTRFS_INODE_ROOT_ITEM_INIT) | |
| 419 | + | |
| 420 | +#define BTRFS_INODE_RO_VERITY (1U << 0) | |
| 421 | + | |
| 422 | +#define BTRFS_INODE_RO_FLAG_MASK (BTRFS_INODE_RO_VERITY) | |
| 362 | 423 | |
| 363 | 424 | /* |
| 364 | 425 | * The key defines the order in the tree, and so it also defines (optimal) |
| @@ -389,6 +450,109 @@ struct btrfs_key { · 24 unmodified lines | ||
| 389 | 450 | __u64 offset; |
| 390 | 451 | } __attribute__ ((__packed__)); |
| 391 | 452 | |
| 453 | +/* | |
| 454 | + * Every tree block (leaf or node) starts with this header. | |
| 455 | + */ | |
| 456 | +struct btrfs_header { | |
| 457 | + /* These first four must match the super block */ | |
| 458 | + __u8 csum[BTRFS_CSUM_SIZE]; | |
| 459 | + /* FS specific uuid */ | |
| 460 | + __u8 fsid[BTRFS_FSID_SIZE]; | |
| 461 | + /* Which block this node is supposed to live in */ | |
| 462 | + __le64 bytenr; | |
| 463 | + __le64 flags; | |
| 464 | + | |
| 465 | + /* Allowed to be different from the super from here on down */ | |
| 466 | + __u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; | |
| 467 | + __le64 generation; | |
| 468 | + __le64 owner; | |
| 469 | + __le32 nritems; | |
| 470 | + __u8 level; | |
| 471 | +} __attribute__ ((__packed__)); | |
| 472 | + | |
| 473 | +/* | |
| 474 | + * This is a very generous portion of the super block, giving us room to | |
| 475 | + * translate 14 chunks with 3 stripes each. | |
| 476 | + */ | |
| 477 | +#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 | |
| 478 | + | |
| 479 | +/* | |
| 480 | + * Just in case we somehow lose the roots and are not able to mount, we store | |
| 481 | + * an array of the roots from previous transactions in the super. | |
| 482 | + */ | |
| 483 | +#define BTRFS_NUM_BACKUP_ROOTS 4 | |
| 484 | +struct btrfs_root_backup { | |
| 485 | + __le64 tree_root; | |
| 486 | + __le64 tree_root_gen; | |
| 487 | + | |
| 488 | + __le64 chunk_root; | |
| 489 | + __le64 chunk_root_gen; | |
| 490 | + | |
| 491 | + __le64 extent_root; | |
| 492 | + __le64 extent_root_gen; | |
| 493 | + | |
| 494 | + __le64 fs_root; | |
| 495 | + __le64 fs_root_gen; | |
| 496 | + | |
| 497 | + __le64 dev_root; | |
| 498 | + __le64 dev_root_gen; | |
| 499 | + | |
| 500 | + __le64 csum_root; | |
| 501 | + __le64 csum_root_gen; | |
| 502 | + | |
| 503 | + __le64 total_bytes; | |
| 504 | + __le64 bytes_used; | |
| 505 | + __le64 num_devices; | |
| 506 | + /* future */ | |
| 507 | + __le64 unused_64[4]; | |
| 508 | + | |
| 509 | + __u8 tree_root_level; | |
| 510 | + __u8 chunk_root_level; | |
| 511 | + __u8 extent_root_level; | |
| 512 | + __u8 fs_root_level; | |
| 513 | + __u8 dev_root_level; | |
| 514 | + __u8 csum_root_level; | |
| 515 | + /* future and to align */ | |
| 516 | + __u8 unused_8[10]; | |
| 517 | +} __attribute__ ((__packed__)); | |
| 518 | + | |
| 519 | +/* | |
| 520 | + * A leaf is full of items. offset and size tell us where to find the item in | |
| 521 | + * the leaf (relative to the start of the data area) | |
| 522 | + */ | |
| 523 | +struct btrfs_item { | |
| 524 | + struct btrfs_disk_key key; | |
| 525 | + __le32 offset; | |
| 526 | + __le32 size; | |
| 527 | +} __attribute__ ((__packed__)); | |
| 528 | + | |
| 529 | +/* | |
| 530 | + * Leaves have an item area and a data area: | |
| 531 | + * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
| 532 | + * | |
| 533 | + * The data is separate from the items to get the keys closer together during | |
| 534 | + * searches. | |
| 535 | + */ | |
| 536 | +struct btrfs_leaf { | |
| 537 | + struct btrfs_header header; | |
| 538 | + struct btrfs_item items[]; | |
| 539 | +} __attribute__ ((__packed__)); | |
| 540 | + | |
| 541 | +/* | |
| 542 | + * All non-leaf blocks are nodes, they hold only keys and pointers to other | |
| 543 | + * blocks. | |
| 544 | + */ | |
| 545 | +struct btrfs_key_ptr { | |
| 546 | + struct btrfs_disk_key key; | |
| 547 | + __le64 blockptr; | |
| 548 | + __le64 generation; | |
| 549 | +} __attribute__ ((__packed__)); | |
| 550 | + | |
| 551 | +struct btrfs_node { | |
| 552 | + struct btrfs_header header; | |
| 553 | + struct btrfs_key_ptr ptrs[]; | |
| 554 | +} __attribute__ ((__packed__)); | |
| 555 | + | |
| 392 | 556 | struct btrfs_dev_item { |
| 393 | 557 | /* the internal btrfs device id */ |
| 394 | 558 | __le64 devid; |
| @@ -472,6 +636,69 @@ struct btrfs_chunk { · 77 unmodified lines | ||
| 472 | 636 | /* additional stripes go here */ |
| 473 | 637 | } __attribute__ ((__packed__)); |
| 474 | 638 | |
| 639 | +/* | |
| 640 | + * The super block basically lists the main trees of the FS. | |
| 641 | + */ | |
| 642 | +struct btrfs_super_block { | |
| 643 | + /* The first 4 fields must match struct btrfs_header */ | |
| 644 | + __u8 csum[BTRFS_CSUM_SIZE]; | |
| 645 | + /* FS specific UUID, visible to user */ | |
| 646 | + __u8 fsid[BTRFS_FSID_SIZE]; | |
| 647 | + /* This block number */ | |
| 648 | + __le64 bytenr; | |
| 649 | + __le64 flags; | |
| 650 | + | |
| 651 | + /* Allowed to be different from the btrfs_header from here own down */ | |
| 652 | + __le64 magic; | |
| 653 | + __le64 generation; | |
| 654 | + __le64 root; | |
| 655 | + __le64 chunk_root; | |
| 656 | + __le64 log_root; | |
| 657 | + | |
| 658 | + /* | |
| 659 | + * This member has never been utilized since the very beginning, thus | |
| 660 | + * it's always 0 regardless of kernel version. We always use | |
| 661 | + * generation + 1 to read log tree root. So here we mark it deprecated. | |
| 662 | + */ | |
| 663 | + __le64 __unused_log_root_transid; | |
| 664 | + __le64 total_bytes; | |
| 665 | + __le64 bytes_used; | |
| 666 | + __le64 root_dir_objectid; | |
| 667 | + __le64 num_devices; | |
| 668 | + __le32 sectorsize; | |
| 669 | + __le32 nodesize; | |
| 670 | + __le32 __unused_leafsize; | |
| 671 | + __le32 stripesize; | |
| 672 | + __le32 sys_chunk_array_size; | |
| 673 | + __le64 chunk_root_generation; | |
| 674 | + __le64 compat_flags; | |
| 675 | + __le64 compat_ro_flags; | |
| 676 | + __le64 incompat_flags; | |
| 677 | + __le16 csum_type; | |
| 678 | + __u8 root_level; | |
| 679 | + __u8 chunk_root_level; | |
| 680 | + __u8 log_root_level; | |
| 681 | + struct btrfs_dev_item dev_item; | |
| 682 | + | |
| 683 | + char label[BTRFS_LABEL_SIZE]; | |
| 684 | + | |
| 685 | + __le64 cache_generation; | |
| 686 | + __le64 uuid_tree_generation; | |
| 687 | + | |
| 688 | + /* The UUID written into btree blocks */ | |
| 689 | + __u8 metadata_uuid[BTRFS_FSID_SIZE]; | |
| 690 | + | |
| 691 | + __u64 nr_global_roots; | |
| 692 | + | |
| 693 | + /* Future expansion */ | |
| 694 | + __le64 reserved[27]; | |
| 695 | + __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; | |
| 696 | + struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS]; | |
| 697 | + | |
| 698 | + /* Padded to 4096 bytes */ | |
| 699 | + __u8 padding[565]; | |
| 700 | +} __attribute__ ((__packed__)); | |
| 701 | + | |
| 475 | 702 | #define BTRFS_FREE_SPACE_EXTENT 1 |
| 476 | 703 | #define BTRFS_FREE_SPACE_BITMAP 2 |
| 477 | 704 | |
| @@ -526,6 +753,14 @@ struct btrfs_extent_item_v0 { · 48 unmodified lines | ||
| 526 | 753 | /* use full backrefs for extent pointers in the block */ |
| 527 | 754 | #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) |
| 528 | 755 | |
| 756 | +#define BTRFS_BACKREF_REV_MAX 256 | |
| 757 | +#define BTRFS_BACKREF_REV_SHIFT 56 | |
| 758 | +#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ | |
| 759 | + BTRFS_BACKREF_REV_SHIFT) | |
| 760 | + | |
| 761 | +#define BTRFS_OLD_BACKREF_REV 0 | |
| 762 | +#define BTRFS_MIXED_BACKREF_REV 1 | |
| 763 | + | |
| 529 | 764 | /* |
| 530 | 765 | * this flag is only used internally by scrub and may be changed at any time |
| 531 | 766 | * it is only declared here to avoid collisions |