xfsprogs: catch us up to 6.10
PATCH v2 1/1 xfsprogs: catch us up to 6.10
Hi Carlos,
For archival purposes, this is a resend of every patch that I have queued (+ reviewed) for xfsprogs 6.10. This will be followed by a pile of pull requests for all that work.
v2: apply reviewed by tags, accumulate bugfixes
--Darrick
PATCH 1/23 libxfs: fixes for 6.9
Hi all,
A couple more last minute fixes for 6.9.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-6.9-fixes
---
Commits in this patchset:
* [PATCH v3] Remove support for split-/usr installs
* repair: btree blocks are never on the RT subvolume
* xfile: fix missing error unlock in xfile_fcb_find
* xfs_repair: don't leak the rootdir inode when orphanage already exists
* xfs_repair: don't crash on -vv
--- configure.ac | 21 --------------------- debian/Makefile | 4 ++-- debian/local/initramfs.hook | 2 +- debian/rules | 5 ++--- fsck/Makefile | 4 ++-- include/builddefs.in | 2 -- include/buildmacros | 20 ++++++++++---------- libxfs/xfile.c | 6 +++--- mkfs/Makefile | 4 ++-- repair/Makefile | 4 ++-- repair/phase6.c | 7 +++++-- repair/progress.c | 2 +- repair/scan.c | 21 +++++---------------- repair/xfs_repair.c | 2 +- 14 files changed, 36 insertions(+), 68 deletions(-)
PATCH 2/23 libxfs: sync with 6.10
In reply to Darrick J. WongHi all,
Synchronize libxfs with the kernel.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-sync-6.10
---
Commits in this patchset:
* xfs: pass xfs_buf lookup flags to xfs_*read_agi
* xfs: constify xfs_bmap_is_written_extent
* xfs: introduce new file range exchange ioctl
* xfs: create a incompat flag for atomic file mapping exchanges
* xfs: introduce a file mapping exchange log intent item
* xfs: create deferred log items for file mapping exchanges
* xfs: add error injection to test file mapping exchange recovery
* xfs: condense extended attributes after a mapping exchange operation
* xfs: condense directories after a mapping exchange operation
* xfs: condense symbolic links after a mapping exchange operation
* xfs: make file range exchange support realtime files
* xfs: capture inode generation numbers in the ondisk exchmaps log item
* xfs: enable logged file mapping exchange feature
* xfs: add an explicit owner field to xfs_da_args
* xfs: use the xfs_da_args owner field to set new dir/attr block owner
* xfs: validate attr leaf buffer owners
* xfs: validate attr remote value buffer owners
* xfs: validate dabtree node buffer owners
* xfs: validate directory leaf buffer owners
* xfs: validate explicit directory data buffer owners
* xfs: validate explicit directory block buffer owners
* xfs: validate explicit directory free block owners
* xfs: use atomic extent swapping to fix user file fork data
* xfs: repair extended attributes
* xfs: expose xfs_bmap_local_to_extents for online repair
* xfs: pass the owner to xfs_symlink_write_target
* xfs: check unused nlink fields in the ondisk inode
* xfs: try to avoid allocating from sick inode clusters
* xfs: pin inodes that would otherwise overflow link count
* xfs: Increase XFS_DEFER_OPS_NR_INODES to 5
* xfs: make XFS_TRANS_LOWMODE match the other XFS_TRANS_ definitions
* xfs: refactor realtime inode locking
* xfs: free RT extents after updating the bmap btree
* xfs: move RT inode locking out of __xfs_bunmapi
* xfs: split xfs_mod_freecounter
* xfs: reinstate RT support in xfs_bmapi_reserve_delalloc
* xfs: cleanup fdblock/frextent accounting in xfs_bmap_del_extent_delay
* xfs: support RT inodes in xfs_mod_delalloc
* xfs: rework splitting of indirect block reservations
* xfs: stop the steal (of data blocks for RT indirect blocks)
* xfs: remove XFS_DA_OP_REMOVE
* xfs: remove XFS_DA_OP_NOTIME
* xfs: remove xfs_da_args.attr_flags
* xfs: make attr removal an explicit operation
* xfs: rearrange xfs_da_args a bit to use less space
* xfs: attr fork iext must be loaded before calling xfs_attr_is_leaf
* xfs: fix missing check for invalid attr flags
* xfs: restructure xfs_attr_complete_op a bit
* xfs: use helpers to extract xattr op from opflags
* xfs: enforce one namespace per attribute
* xfs: rearrange xfs_attr_match parameters
* xfs: check the flags earlier in xfs_attr_match
* xfs: move xfs_attr_defer_add to xfs_attr_item.c
* xfs: create a separate hashname function for extended attributes
* xfs: add parent pointer support to attribute code
* xfs: define parent pointer ondisk extended attribute format
* xfs: allow xattr matching on name and value for parent pointers
* xfs: create attr log item opcodes and formats for parent pointers
* xfs: record inode generation in xattr update log intent items
* xfs: add parent pointer validator functions
* xfs: extend transaction reservations for parent attributes
* xfs: create a hashname function for parent pointers
* xfs: parent pointer attribute creation
* xfs: add parent attributes to link
* xfs: add parent attributes to symlink
* xfs: remove parent pointers in unlink
* xfs: Add parent pointers to rename
* xfs: don't return XFS_ATTR_PARENT attributes via listxattr
* xfs: pass the attr value to put_listent when possible
* xfs: split out handle management helpers a bit
* xfs: add parent pointer ioctls
* xfs: don't remove the attr fork when parent pointers are enabled
* xfs: add a incompat feature bit for parent pointers
* xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res
* xfs: drop compatibility minimum log size computations for reflink
* xfs: enable parent pointers
* xfs: check dirents have parent pointers
* xfs: remove some boilerplate from xfs_attr_set
* xfs: make the reserved block permission flag explicit in xfs_attr_set
* xfs: add raw parent pointer apis to support repair
* xfs: remove pointless unlocked assertion
* xfs: split xfs_bmap_add_attrfork into two pieces
* xfs: actually rebuild the parent pointer xattrs
* xfs: teach online scrub to find directory tree structure problems
* xfs: report directory tree corruption in the health information
* xfs: introduce vectored scrub mode
* xfs: factor out a xfs_dir_lookup_args helper
* xfs: factor out a xfs_dir_createname_args helper
* xfs: factor out a xfs_dir_removename_args helper
* xfs: factor out a xfs_dir_replace_args helper
* xfs: refactor dir format helpers
* xfs: make the seq argument to xfs_bmapi_convert_delalloc() optional
* xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset
* xfs: fix error returns from xfs_bmapi_write
* xfs: remove the unusued tmp_logflags variable in xfs_bmapi_allocate
* xfs: lift a xfs_valid_startblock into xfs_bmapi_allocate
* xfs: don't open code XFS_FILBLKS_MIN in xfs_bmapi_write
* xfs: pass the actual offset and len to allocate to xfs_bmapi_allocate
* xfs: remove the xfs_iext_peek_prev_extent call in xfs_bmapi_allocate
* xfs: fix xfs_bmap_add_extent_delay_real for partial conversions
* xfs: do not allocate the entire delalloc extent in xfs_bmapi_write
* xfs: use unsigned ints for non-negative quantities in xfs_attr_remote.c
* xfs: turn XFS_ATTR3_RMT_BUF_SPACE into a function
* xfs: create a helper to compute the blockcount of a max sized remote value
* xfs: minor cleanups of xfs_attr3_rmt_blocks
* xfs: xfs_quota_unreserve_blkres can't fail
* xfs: simplify iext overflow checking and upgrade
* xfs: Stop using __maybe_unused in xfs_alloc.c
* xfs: fix xfs_init_attr_trans not handling explicit operation codes
* xfs: allow symlinks with short remote targets
* xfs: Add cond_resched to block unmap range and reflink remap path
* xfs: make sure sb_fdblocks is non-negative
* xfs: restrict when we try to align cow fork delalloc to cowextsz hints
* xfs: allow unlinked symlinks and dirs with zero size
* xfs: fix direction in XFS_IOC_EXCHANGE_RANGE
--- db/attr.c | 2 db/attrset.c | 11 db/iunlink.c | 4 db/metadump.c | 8 db/namei.c | 23 - include/libxfs.h | 1 include/xfs_inode.h | 16 + include/xfs_mount.h | 2 include/xfs_trace.h | 15 + io/inject.c | 1 libxfs/Makefile | 5 libxfs/defer_item.c | 116 ++++ libxfs/defer_item.h | 13 libxfs/init.c | 3 libxfs/libxfs_api_defs.h | 6 libxfs/libxfs_priv.h | 75 ++- libxfs/util.c | 6 libxfs/xfs_ag.c | 12 libxfs/xfs_ag_resv.c | 24 - libxfs/xfs_ag_resv.h | 2 libxfs/xfs_alloc.c | 10 libxfs/xfs_attr.c | 272 ++++++--- libxfs/xfs_attr.h | 49 +- libxfs/xfs_attr_leaf.c | 154 ++++- libxfs/xfs_attr_leaf.h | 4 libxfs/xfs_attr_remote.c | 102 ++-- libxfs/xfs_attr_remote.h | 8 libxfs/xfs_attr_sf.h | 1 libxfs/xfs_bmap.c | 409 ++++++++------ libxfs/xfs_bmap.h | 13 libxfs/xfs_da_btree.c | 189 ++++++- libxfs/xfs_da_btree.h | 34 + libxfs/xfs_da_format.h | 37 + libxfs/xfs_defer.c | 12 libxfs/xfs_defer.h | 10 libxfs/xfs_dir2.c | 283 +++++----- libxfs/xfs_dir2.h | 23 + libxfs/xfs_dir2_block.c | 42 + libxfs/xfs_dir2_data.c | 18 - libxfs/xfs_dir2_leaf.c | 100 +++ libxfs/xfs_dir2_node.c | 44 +- libxfs/xfs_dir2_priv.h | 15 - libxfs/xfs_errortag.h | 4 libxfs/xfs_exchmaps.c | 1232 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_exchmaps.h | 124 ++++ libxfs/xfs_format.h | 34 + libxfs/xfs_fs.h | 158 +++++- libxfs/xfs_health.h | 4 libxfs/xfs_ialloc.c | 56 ++ libxfs/xfs_ialloc.h | 5 libxfs/xfs_ialloc_btree.c | 4 libxfs/xfs_inode_buf.c | 55 ++ libxfs/xfs_inode_fork.c | 63 +- libxfs/xfs_inode_fork.h | 6 libxfs/xfs_log_format.h | 89 +++ libxfs/xfs_log_rlimit.c | 46 ++ libxfs/xfs_ondisk.h | 6 libxfs/xfs_parent.c | 376 +++++++++++++ libxfs/xfs_parent.h | 110 ++++ libxfs/xfs_rtbitmap.c | 57 ++ libxfs/xfs_rtbitmap.h | 17 + libxfs/xfs_sb.c | 15 - libxfs/xfs_shared.h | 6 libxfs/xfs_symlink_remote.c | 54 ++ libxfs/xfs_symlink_remote.h | 8 libxfs/xfs_trans_resv.c | 324 +++++++++-- libxfs/xfs_trans_space.c | 121 ++++ libxfs/xfs_trans_space.h | 29 + mkfs/proto.c | 3 repair/attr_repair.c | 7 repair/phase6.c | 35 + 71 files changed, 4349 insertions(+), 873 deletions(-) create mode 100644 libxfs/xfs_exchmaps.c create mode 100644 libxfs/xfs_exchmaps.h create mode 100644 libxfs/xfs_parent.c create mode 100644 libxfs/xfs_parent.h create mode 100644 libxfs/xfs_trans_space.c
PATCH 3/23 xfsprogs: atomic file updates
In reply to Darrick J. WongHi all,
This series creates a new XFS_IOC_EXCHANGE_RANGE ioctl to exchange ranges of bytes between two files atomically.
This new functionality enables data storage programs to stage and commit file updates such that reader programs will see either the old contents or the new contents in their entirety, with no chance of torn writes. A successful call completion guarantees that the new contents will be seen even if the system fails.
The ability to exchange file fork mappings between files in this manner is critical to supporting online filesystem repair, which is built upon the strategy of constructing a clean copy of a damaged structure and committing the new structure into the metadata file atomically. The ioctls exist to facilitate testing of the new functionality and to enable future application program designs.
User programs will be able to update files atomically by opening an O_TMPFILE, reflinking the source file to it, making whatever updates they want to make, and exchange the relevant ranges of the temp file with the original file. If the updates are aligned with the file block size, a new (since v2) flag provides for exchanging only the written areas. Note that application software must quiesce writes to the file while it stages an atomic update. This will be addressed by a subsequent series.
This mechanism solves the clunkiness of two existing atomic file update
mechanisms: for O_TRUNC + rewrite, this eliminates the brief period where other programs can see an empty file. For create tempfile + rename, the need to copy file attributes and extended attributes for each file update is eliminated.
However, this method introduces its own awkwardness -- any program initiating an exchange now needs to have a way to signal to other programs that the file contents have changed. For file access mediated via read and write, fanotify or inotify are probably sufficient. For mmaped files, that may not be fast enough.
The reference implementation in XFS creates a new log incompat feature and log intent items to track high level progress of swapping ranges of two files and finish interrupted work if the system goes down. Sample code can be found in the corresponding changes to xfs_io to exercise the use case mentioned above.
Note that this function is /not/ the O_DIRECT atomic untorn file writes concept that has also been floating around for years. It is also not the RWF_ATOMIC patchset that has been shared. This RFC is constructed entirely in software, which means that there are no limitations other than the general filesystem limits.
As a side note, the original motivation behind the kernel functionality is online repair of file-based metadata. The atomic file content exchange is implemented as an atomic exchange of file fork mappings, which means that we can implement online reconstruction of extended attributes and directories by building a new one in another inode and exchanging the contents.
Subsequent patchsets adapt the online filesystem repair code to use atomic file exchanges. This enables repair functions to construct a clean copy of a directory, xattr information, symbolic links, realtime bitmaps, and realtime summary information in a temporary inode. If this completes successfully, the new contents can be committed atomically into the inode being repaired. This is essential to avoid making corruption problems worse if the system goes down in the middle of running repair.
For userspace, this series also includes the userspace pieces needed to test the new functionality, and a sample implementation of atomic file updates.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=atomic-file-updates-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=atomic-file-updates-6.10
---
Commits in this patchset:
* man: document the exchange-range ioctl
* man: document XFS_FSOP_GEOM_FLAGS_EXCHRANGE
* libhandle: add support for bulkstat v5
* libfrog: add support for exchange range ioctl family
* xfs_db: advertise exchange-range in the version command
* xfs_logprint: support dumping exchmaps log items
* xfs_fsr: convert to bulkstat v5 ioctls
* xfs_fsr: skip the xattr/forkoff levering with the newer swapext implementations
* xfs_io: create exchangerange command to test file range exchange ioctl
* libfrog: advertise exchange-range support
* xfs_repair: add exchange-range to file systems
* mkfs: add a formatting option for exchange-range
--- db/sb.c | 2 fsr/xfs_fsr.c | 167 +++++++++++++-------- include/jdm.h | 23 +++ io/Makefile | 48 +++++- io/exchrange.c | 156 ++++++++++++++++++++ io/init.c | 1 io/io.h | 1 libfrog/Makefile | 2 libfrog/file_exchange.c | 52 +++++++ libfrog/file_exchange.h | 15 ++ libfrog/fsgeom.c | 49 +++++- libfrog/fsgeom.h | 1 libhandle/jdm.c | 117 +++++++++++++++ logprint/log_misc.c | 11 + logprint/log_print_all.c | 12 ++ logprint/log_redo.c | 128 ++++++++++++++++ logprint/logprint.h | 6 + man/man2/ioctl_xfs_exchange_range.2 | 278 +++++++++++++++++++++++++++++++++++ man/man2/ioctl_xfs_fsgeometry.2 | 3 man/man8/mkfs.xfs.8.in | 7 + man/man8/xfs_admin.8 | 7 + man/man8/xfs_io.8 | 40 +++++ mkfs/lts_4.19.conf | 1 mkfs/lts_5.10.conf | 1 mkfs/lts_5.15.conf | 1 mkfs/lts_5.4.conf | 1 mkfs/lts_6.1.conf | 1 mkfs/lts_6.6.conf | 1 mkfs/xfs_mkfs.c | 26 +++ repair/globals.c | 1 repair/globals.h | 1 repair/phase2.c | 30 ++++ repair/xfs_repair.c | 11 + 33 files changed, 1114 insertions(+), 87 deletions(-) create mode 100644 io/exchrange.c create mode 100644 libfrog/file_exchange.c create mode 100644 libfrog/file_exchange.h create mode 100644 man/man2/ioctl_xfs_exchange_range.2
PATCH 4/23 xfsprogs: set and validate dir/attr block owners
In reply to Darrick J. WongHi all,
There are a couple of significatn changes that need to be made to the directory and xattr code before we can support online repairs of those data structures.
The first change is because online repair is designed to use libxfs to create a replacement dir/xattr structure in a temporary file, and use atomic extent swapping to commit the corrected structure. To avoid the performance hit of walking every block of the new structure to rewrite the owner number, we instead change libxfs to allow callers of the dir and xattr code the ability to set an explicit owner number to be written into the header fields of any new blocks that are created.
The second change is to update the dir/xattr code to actually *check* the owner number in each block that is read off the disk, since we don't currently do that.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=dirattr-validate-owners-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=dirattr-validate-owners-6.10
---
Commits in this patchset:
* xfs_{db,repair}: add an explicit owner field to xfs_da_args
--- db/namei.c | 1 + repair/phase6.c | 3 +++ 2 files changed, 4 insertions(+)
PATCH 5/23 xfsprogs: inode-related repair fixes
In reply to Darrick J. WongHi all,
While doing QA of the online fsck code, I made a few observations:
First, nobody was checking that the di_onlink field is actually zero; Second, that allocating a temporary file for repairs can fail (and thus bring down the entire fs) if the inode cluster is corrupt; and Third, that file link counts do not pin at ~0U to prevent integer overflows.
This scattered patchset fixes those three problems.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=inode-repair-improvements-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=inode-repair-improvements-6.10
---
Commits in this patchset:
* libxfs: port the bumplink function from the kernel
* mkfs/repair: pin inodes that would otherwise overflow link count
--- include/xfs_inode.h | 2 ++ libxfs/util.c | 18 ++++++++++++++++++ mkfs/proto.c | 4 ++-- repair/incore_ino.c | 14 +++++++++----- repair/phase6.c | 10 +++++----- 5 files changed, 36 insertions(+), 12 deletions(-)
PATCH 6/23 xfs_scrub: fixes to the repair code
In reply to Darrick J. WongHi all,
Now that we've landed the new kernel code, it's time to reorganize the xfs_scrub code that handles repairs. Clean up various naming warts and misleading error messages. Move the repair code to scrub/repair.c as the first step. Then, fix various issues in the repair code before we start reorganizing things.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-repair-fixes-6.10
---
Commits in this patchset:
* xfs_scrub: remove ALP_* flags namespace
* xfs_scrub: move repair functions to repair.c
* xfs_scrub: log when a repair was unnecessary
* xfs_scrub: require primary superblock repairs to complete before proceeding
* xfs_scrub: actually try to fix summary counters ahead of repairs
--- scrub/phase1.c | 2 scrub/phase2.c | 3 - scrub/phase3.c | 2 scrub/phase4.c | 22 ++++- scrub/phase5.c | 2 scrub/phase7.c | 2 scrub/repair.c | 177 ++++++++++++++++++++++++++++++++++++++++++- scrub/repair.h | 16 +++- scrub/scrub.c | 204 +------------------------------------------------ scrub/scrub.h | 16 ---- scrub/scrub_private.h | 55 +++++++++++++ 11 files changed, 269 insertions(+), 232 deletions(-) create mode 100644 scrub/scrub_private.h
PATCH 7/23 xfs_scrub: improve warnings about difficult repairs
In reply to Darrick J. WongHi all,
While I was poking through the QA results for xfs_scrub, I noticed that it doesn't warn the user when the primary and secondary realtime metadata are so out of whack that the chances of a successful repair are not so high. I decided that it was worth refactoring the scrub code a bit so that we could warn the user about these types of things, and ended up refactoring unnecessary helpers out of existence and fixing other reporting gaps.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-better-repair-warnings-6.10
---
Commits in this patchset:
* xfs_scrub: fix missing scrub coverage for broken inodes
* xfs_scrub: collapse trivial superblock scrub helpers
* xfs_scrub: get rid of trivial fs metadata scanner helpers
* xfs_scrub: split up the mustfix repairs and difficulty assessment functions
* xfs_scrub: add missing repair types to the mustfix and difficulty assessment
* xfs_scrub: any inconsistency in metadata should trigger difficulty warnings
* xfs_scrub: warn about difficult repairs to rt and quota metadata
* xfs_scrub: enable users to bump information messages to warnings
--- man/man8/xfs_scrub.8 | 19 ++++++++++++++++++ scrub/common.c | 2 ++ scrub/phase1.c | 2 +- scrub/phase2.c | 53 +++++++++++++++++++++++++++++++------------------- scrub/phase3.c | 21 ++++++++++++++++---- scrub/phase4.c | 9 +++++--- scrub/phase5.c | 15 +++++++------- scrub/repair.c | 47 ++++++++++++++++++++++++++++++++++---------- scrub/repair.h | 10 +++++++-- scrub/scrub.c | 52 +------------------------------------------------ scrub/scrub.h | 7 ++----- scrub/xfs_scrub.c | 45 ++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.h | 1 + 13 files changed, 175 insertions(+), 108 deletions(-)
PATCH 8/23 xfs_scrub: track data dependencies for repairs
In reply to Darrick J. WongHi all,
Certain kinds of XFS metadata depend on the correctness of lower level metadata. For example, directory indexes depends on the directory data fork, which in turn depend on the directory inode to be correct. The current scrub code does not strictly preserve these dependencies if it has to defer a repair until phase 4, because phase 4 prioritizes repairs by type (corruption, then cross referencing, and then preening) and loses the ordering of in the previous phases. This leads to absurd things like trying to repair a directory before repairing its corrupted fork, which is absurd.
To solve this problem, introduce a repair ticket structure to track all the repairs pending for a principal object (inode, AG, etc). This reduces memory requirements if an object requires more than one type of repair and makes it very easy to track the data dependencies between sub-objects of a principal object. Repair dependencies between object types (e.g. bnobt before inodes) must still be encoded statically into phase 4.
A secondary benefit of this new ticket structure is that we can decide to attempt a repair of an object A that was flagged for a cross referencing error during the scan if a different object B depends on A but only B showed definitive signs of corruption.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-repair-data-deps-6.10
---
Commits in this patchset:
* xfs_scrub: track repair items by principal, not by individual repairs
* xfs_scrub: use repair_item to direct repair activities
* xfs_scrub: remove action lists from phaseX code
* xfs_scrub: remove scrub_metadata_file
* xfs_scrub: boost the repair priority of dependencies of damaged items
* xfs_scrub: clean up repair_item_difficulty a little
* xfs_scrub: check dependencies of a scrub type before repairing
* xfs_scrub: retry incomplete repairs
* xfs_scrub: remove unused action_list fields
--- libfrog/scrub.c | 1 scrub/phase1.c | 9 - scrub/phase2.c | 46 ++-- scrub/phase3.c | 77 ++++--- scrub/phase4.c | 17 +- scrub/phase5.c | 9 - scrub/phase7.c | 9 - scrub/repair.c | 530 +++++++++++++++++++++++++++++++++---------------- scrub/repair.h | 47 +++- scrub/scrub.c | 136 ++++++------- scrub/scrub.h | 108 ++++++++-- scrub/scrub_private.h | 37 +++ 12 files changed, 664 insertions(+), 362 deletions(-)
PATCH 9/23 xfs_scrub: use scrub_item to track check progress
In reply to Darrick J. WongHi all,
Now that we've introduced tickets to track the status of repairs to a specific principal XFS object (fs, ag, file), use them to track the scrub state of those same objects. Ultimately, we want to make it easy to introduce vectorized repair, where we send a batch of repair requests to the kernel instead of making millions of ioctl calls. For now, however, we'll settle for easier bookkeepping.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-object-tracking-6.10
---
Commits in this patchset:
* xfs_scrub: start tracking scrub state in scrub_item
* xfs_scrub: remove enum check_outcome
* xfs_scrub: refactor scrub_meta_type out of existence
* xfs_scrub: hoist repair retry loop to repair_item_class
* xfs_scrub: hoist scrub retry loop to scrub_item_check_file
--- scrub/phase1.c | 3 scrub/phase2.c | 12 +- scrub/phase3.c | 41 ++---- scrub/phase4.c | 16 +- scrub/phase5.c | 5 - scrub/phase7.c | 5 + scrub/repair.c | 71 +++++------ scrub/scrub.c | 321 ++++++++++++++++++++++--------------------------- scrub/scrub.h | 40 ++++-- scrub/scrub_private.h | 14 ++ 10 files changed, 257 insertions(+), 271 deletions(-)
PATCH 10/23 xfs_scrub: improve scheduling of repair items
In reply to Darrick J. WongHi all,
Currently, phase 4 of xfs_scrub uses per-AG repair item lists to schedule repair work across a thread pool. This scheme is suboptimal when most of the repairs involve a single AG because all the work gets dumped on a single pool thread.
Instead, we should create a thread pool with the same number of workers as CPUs, and dispatch individual repair tickets as separate work items to maximize parallelization.
However, we also need to ensure that repairs to space metadata and file metadata are kept in separate queues because file repairs generally depend on correctness of space metadata.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-repair-scheduling-6.10
---
Commits in this patchset:
* libfrog: enhance ptvar to support initializer functions
* xfs_scrub: improve thread scheduling repair items during phase 4
* xfs_scrub: recheck entire metadata objects after corruption repairs
* xfs_scrub: try to repair space metadata before file metadata
--- libfrog/ptvar.c | 9 ++ libfrog/ptvar.h | 4 + scrub/counter.c | 2 scrub/descr.c | 2 scrub/phase1.c | 15 ++- scrub/phase2.c | 23 ++++- scrub/phase3.c | 106 ++++++++++++++------- scrub/phase4.c | 244 ++++++++++++++++++++++++++++++++++++------------- scrub/phase7.c | 2 scrub/read_verify.c | 2 scrub/repair.c | 172 ++++++++++++++++++++++------------- scrub/repair.h | 37 ++++++- scrub/scrub.c | 5 + scrub/scrub.h | 10 ++ scrub/scrub_private.h | 2 scrub/xfs_scrub.h | 3 - 16 files changed, 455 insertions(+), 183 deletions(-)
PATCH 11/23 xfs_scrub: detect deceptive filename extensions
In reply to Darrick J. WongHi all,
In early 2023, malware researchers disclosed a phishing attack that was targeted at people running Linux workstations. The attack vector involved the use of filenames containing what looked like a file extension but instead contained a lookalike for the full stop (".") and a common extension ("pdf"). Enhance xfs_scrub phase 5 to detect these types of attacks and warn the system administrator.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-detect-deceptive-extensions-6.10
---
Commits in this patchset:
* xfs_scrub: use proper UChar string iterators
* xfs_scrub: hoist code that removes ignorable characters
* xfs_scrub: add a couple of omitted invisible code points
* xfs_scrub: avoid potential UAF after freeing a duplicate name entry
* xfs_scrub: guard against libicu returning negative buffer lengths
* xfs_scrub: hoist non-rendering character predicate
* xfs_scrub: store bad flags with the name entry
* xfs_scrub: rename UNICRASH_ZERO_WIDTH to UNICRASH_INVISIBLE
* xfs_scrub: type-coerce the UNICRASH_* flags
* xfs_scrub: reduce size of struct name_entry
* xfs_scrub: rename struct unicrash.normalizer
* xfs_scrub: report deceptive file extensions
* xfs_scrub: dump unicode points
--- scrub/unicrash.c | 532 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 426 insertions(+), 106 deletions(-)
PATCH 12/23 xfs_scrub: move fstrim to a separate phase
In reply to Darrick J. WongHi all,
Back when I originally designed xfs_scrub, all filesystem metadata checks were complete by the end of phase 3, and phase 4 was where all the metadata repairs occurred. On the grounds that the filesystem should be fully consistent by then, I made a call to FITRIM at the end of phase 4 to discard empty space in the filesystem.
Unfortunately, that's no longer the case -- summary counters, link counts, and quota counters are not checked until phase 7. It's not safe to instruct the storage to unmap "empty" areas if we don't know where those empty areas are, so we need to create a phase 8 to trim the fs. While we're at it, make it more obvious that fstrim only gets to run if there are no unfixed corruptions and no other runtime errors have occurred.
Finally, reduce the latency impacts on the rest of the system by breaking up the fstrim work into a loop that targets only 16GB per call. This enables better progress reporting for interactive runs and cgroup based resource constraints for background runs.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-fstrim-phase-6.10
---
Commits in this patchset:
* xfs_scrub: move FITRIM to phase 8
* xfs_scrub: ignore phase 8 if the user disabled fstrim
* xfs_scrub: collapse trim_filesystem
* xfs_scrub: fix the work estimation for phase 8
* xfs_scrub: report FITRIM errors properly
* xfs_scrub: don't call FITRIM after runtime errors
* xfs_scrub: improve responsiveness while trimming the filesystem
--- scrub/Makefile | 1 scrub/phase4.c | 30 +---------- scrub/phase8.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/vfs.c | 22 +++++--- scrub/vfs.h | 2 - scrub/xfs_scrub.c | 11 ++++ scrub/xfs_scrub.h | 3 + 7 files changed, 183 insertions(+), 37 deletions(-) create mode 100644 scrub/phase8.c
PATCH 13/23 xfs_scrub: use free space histograms to reduce fstrim runtime
In reply to Darrick J. WongHi all,
This patchset dramatically reduces the runtime of the FITRIM calls made during phase 8 of xfs_scrub. It turns out that phase 8 can really get bogged down if the free space contains a large number of very small extents. In these cases, the runtime can increase by an order of magnitude to free less than 1% of the free space. This is not worth the time, since we're spending a lot of time to do very little work. The FITRIM ioctl allows us to specify a minimum extent length, so we can use statistical methods to compute a minlen parameter.
It turns out xfs_db/spaceman already have the code needed to create histograms of free space extent lengths. We add the ability to compute a CDF of the extent lengths, which make it easy to pick a minimum length corresponding to 99% of the free space. In most cases, this results in dramatic reductions in phase 8 runtime. Hence, move the histogram code to libfrog, and wire up xfs_scrub, since phase 7 already walks the fsmap.
We also add a new -o suboption to xfs_scrub so that people who /do/ want to examine every free extent can do so.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-fstrim-minlen-freesp-histogram-6.10
---
Commits in this patchset:
* libfrog: hoist free space histogram code
* libfrog: print wider columns for free space histogram
* libfrog: print cdf of free space buckets
* xfs_scrub: don't close stdout when closing the progress bar
* xfs_scrub: remove pointless spacemap.c arguments
* xfs_scrub: collect free space histograms during phase 7
* xfs_scrub: tune fstrim minlen parameter based on free space histograms
--- db/freesp.c | 89 ++++------------ libfrog/Makefile | 2 libfrog/histogram.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/histogram.h | 77 ++++++++++++++ man/man8/xfs_scrub.8 | 16 +++ scrub/phase7.c | 47 ++++++++- scrub/phase8.c | 91 ++++++++++++++++- scrub/spacemap.c | 11 +- scrub/vfs.c | 4 + scrub/vfs.h | 2 scrub/xfs_scrub.c | 45 ++++++++ scrub/xfs_scrub.h | 16 +++ spaceman/freesp.c | 99 ++++++------------ 13 files changed, 619 insertions(+), 150 deletions(-) create mode 100644 libfrog/histogram.c create mode 100644 libfrog/histogram.h
PATCH 14/23 xfs_scrub: tighten security of systemd services
In reply to Darrick J. WongHi all,
To reduce the risk of the online fsck service suffering some sort of catastrophic breach that results in attackers reconfiguring the running system, I embarked on a security audit of the systemd service files. The result should be that all elements of the background service (individual scrub jobs, the scrub_all initiator, and the failure reporting) run with as few privileges and within as strong of a sandbox as possible.
Granted, this does nothing about the potential for the /kernel/ screwing up, but at least we could prevent obvious container escapes.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-service-security-6.10
---
Commits in this patchset:
* xfs_scrub: allow auxiliary pathnames for sandboxing
* xfs_scrub.service: reduce background CPU usage to less than one core if possible
* xfs_scrub: use dynamic users when running as a systemd service
* xfs_scrub: tighten up the security on the background systemd service
* xfs_scrub_fail: tighten up the security on the background systemd service
* xfs_scrub_all: tighten up the security on the background systemd service
--- man/man8/xfs_scrub.8 | 9 +++- scrub/Makefile | 7 ++- scrub/phase1.c | 4 +- scrub/system-xfs_scrub.slice | 30 ++++++++++++ scrub/vfs.c | 2 - scrub/xfs_scrub.c | 11 +++- scrub/xfs_scrub.h | 5 ++ scrub/[email protected] | 97 ++++++++++++++++++++++++++++++++++---- scrub/xfs_scrub_all.service.in | 66 ++++++++++++++++++++++++++ scrub/[email protected] | 59 +++++++++++++++++++++++ 10 files changed, 270 insertions(+), 20 deletions(-) create mode 100644 scrub/system-xfs_scrub.slice
PATCH 15/23 xfs_scrub_all: automatic media scan service
In reply to Darrick J. WongHi all,
Now that we've completed the online fsck functionality, there are a few things that could be improved in the automatic service. Specifically, we would like to perform a more intensive metadata + media scan once per month, to give the user confidence that the filesystem isn't losing data silently. To accomplish this, enhance xfs_scrub_all to be able to trigger media scans. Next, add a duplicate set of system services that start the media scans automatically.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-media-scan-service-6.10
---
Commits in this patchset:
* xfs_scrub_all: only use the xfs_scrub@ systemd services in service mode
* xfs_scrub_all: remove journalctl background process
* xfs_scrub_all: support metadata+media scans of all filesystems
* xfs_scrub_all: enable periodic file data scrubs automatically
* xfs_scrub_all: trigger automatic media scans once per month
* xfs_scrub_all: failure reporting for the xfs_scrub_all job
--- debian/rules | 3 + include/builddefs.in | 3 + man/man8/Makefile | 7 ++ man/man8/xfs_scrub_all.8.in | 20 +++++ scrub/Makefile | 21 +++++ scrub/[email protected] | 2 - scrub/xfs_scrub_all.cron.in | 2 - scrub/xfs_scrub_all.in | 126 ++++++++++++++++++++++++++------ scrub/xfs_scrub_all.service.in | 9 ++ scrub/xfs_scrub_all_fail.service.in | 71 ++++++++++++++++++ scrub/xfs_scrub_fail.in | 46 +++++++++--- scrub/[email protected] | 2 - scrub/[email protected] | 100 +++++++++++++++++++++++++ scrub/[email protected] | 76 +++++++++++++++++++ 14 files changed, 443 insertions(+), 45 deletions(-) rename man/man8/{xfs_scrub_all.8 => xfs_scrub_all.8.in} (59%) create mode 100644 scrub/xfs_scrub_all_fail.service.in create mode 100644 scrub/[email protected] create mode 100644 scrub/[email protected]
PATCH 16/23 xfs_scrub_all: improve systemd handling
In reply to Darrick J. WongHi all,
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-all-improve-systemd-handling-6.10
---
Commits in this patchset:
* xfs_scrub_all: encapsulate all the subprocess code in an object
* xfs_scrub_all: encapsulate all the systemctl code in an object
* xfs_scrub_all: add CLI option for easier debugging
* xfs_scrub_all: convert systemctl calls to dbus
* xfs_scrub_all: implement retry and backoff for dbus calls
--- debian/control | 2 scrub/xfs_scrub_all.in | 284 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 213 insertions(+), 73 deletions(-)
PATCH 17/23 xfsprogs: improve extended attribute validation
In reply to Darrick J. WongHi all,
Prior to introducing parent pointer extended attributes, let's spend some time cleaning up the attr code and strengthening the validation that it performs on attrs coming in from the disk.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=improve-attr-validation-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=improve-attr-validation-6.10
---
Commits in this patchset:
* xfs_scrub_all: fail fast on masked units
* xfs_scrub: automatic downgrades to dry-run mode in service mode
* xfs_scrub: add an optimization-only mode
* xfs_repair: check free space requirements before allowing upgrades
* xfs_repair: enforce one namespace bit per extended attribute
* xfs_repair: check for unknown flags in attr entries
--- include/libxfs.h | 1 libxfs/libxfs_api_defs.h | 1 man/man8/xfs_scrub.8 | 6 ++ repair/attr_repair.c | 30 ++++++++++ repair/phase2.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ scrub/Makefile | 2 - scrub/phase1.c | 13 ++++ scrub/phase4.c | 6 ++ scrub/repair.c | 37 ++++++++++++- scrub/repair.h | 2 + scrub/scrub.c | 4 + scrub/xfs_scrub.c | 21 +++++++ scrub/xfs_scrub.h | 1 scrub/xfs_scrub_all.in | 21 +++++++ 14 files changed, 272 insertions(+), 7 deletions(-)
PATCH 18/23 xfsprogs: Parent Pointers
In reply to Darrick J. WongHi all,
This is the latest parent pointer attributes for xfs. The goal of this patch set is to add a parent pointer attribute to each inode. The attribute name containing the parent inode, generation, and directory offset, while the attribute value contains the file name. This feature will enable future optimizations for online scrub, shrink, nfs handles, verity, or any other feature that could make use of quickly deriving an inodes path from the mount point.
Directory parent pointers are stored as namespaced extended attributes of a file. Because parent pointers are an indivisible tuple of (dirent_name, parent_ino, parent_gen) we cannot use the usual attr name lookup functions to find a parent pointer. This is solvable by introducing a new lookup mode that checks both the name and the value of the xattr.
Therefore, introduce this new name-value lookup mode that's gated on the XFS_ATTR_PARENT namespace. This requires the introduction of new opcodes for the extended attribute update log intent items, which actually means that parent pointers (itself an INCOMPAT feature) does not depend on the LOGGED_XATTRS log incompat feature bit.
To reduce collisions on the dirent names of parent pointers, introduce a new attr hash mode that is the dir2 namehash of the dirent name xor'd with the parent inode number.
At this point, Allison has moved on to other things, so I've merged her patchset into djwong-dev for merging.
Updates since v12 [djwong]:
Rebase on 6.9-rc and update the online fsck design document. Redesign the ondisk format to use the name-value lookups to get us back to the point where the attr is (dirent_name -> parent_ino/gen).
Updates since v11 [djwong]:
Rebase on 6.4-rc and make some tweaks and bugfixes to enable the repair prototypes. Merge with djwong-dev and make online repair actually work.
Updates since v10 [djwong]:
Merge in the ondisk format changes to get rid of the diroffset conflicts with the parent pointer repair code, rebase the entire series with the attr vlookup changes first, and merge all the other random fixes.
Updates since v9:
Reordered patches 2 and 3 to be 6 and 7
xfs: Add xfs_verify_pptr
moved parent pointer validators to xfs_parent
xfs: Add parent pointer ioctl
Extra validation checks for fs id
added missing release for the inode
use GFP_KERNEL flags for malloc/realloc reworked ioctl to use pptr listenty and flex array
NEW
xfs: don't remove the attr fork when parent pointers are enabled
NEW
directory lookups should return diroffsets too
NEW
xfs: move/add parent pointer validators to xfs_parent
Updates since v8:
xfs: parent pointer attribute creation
Fix xfs_parent_init to release log assist on alloc fail Add slab cache for xfs_parent_defer
Fix xfs_create to release after unlock
Add xfs_parent_start and xfs_parent_finish wrappers removed unused xfs_parent_name_irec and xfs_init_parent_name_irec
xfs: add parent attributes to link
Start/finish wrapper updates
Fix xfs_link to disallow reservationless quotas
xfs: add parent attributes to symlink
Fix xfs_symlink to release after unlock
Start/finish wrapper updates
xfs: remove parent pointers in unlink
Start/finish wrapper updates
Add missing parent free
xfs: Add parent pointers to rename
Start/finish wrapper updates
Fix rename to only grab logged xattr once Fix xfs_rename to disallow reservationless quotas Fix double unlock on dqattach fail
Move parent frees to out_release_wip
xfs: Add parent pointers to xfs_cross_rename
Hoist parent pointers into rename
Questions comments and feedback appreciated!
Thanks all!
Allison
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=pptrs-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=pptrs-6.10
---
Commits in this patchset:
* libxfs: create attr log item opcodes and formats for parent pointers
* xfs_{db,repair}: implement new attr hash value function
* xfs_logprint: dump new attr log item fields
* man: document the XFS_IOC_GETPARENTS ioctl
* libfrog: report parent pointers to userspace
* libfrog: add parent pointer support code
* xfs_io: adapt parent command to new parent pointer ioctls
* xfs_io: Add i, n and f flags to parent command
* xfs_logprint: decode parent pointers in ATTRI items fully
* xfs_spaceman: report file paths
* xfs_scrub: use parent pointers when possible to report file operations
* xfs_scrub: use parent pointers to report lost file data
* xfs_db: report parent pointers in version command
* xfs_db: report parent bit on xattrs
* xfs_db: report parent pointers embedded in xattrs
* xfs_db: obfuscate dirent and parent pointer names consistently
* libxfs: export attr3_leaf_hdr_from_disk via libxfs_api_defs.h
* xfs_db: add a parents command to list the parents of a file
* xfs_db: make attr_set and attr_remove handle parent pointers
* xfs_db: add link and unlink expert commands
* xfs_db: compute hashes of parent pointers
* libxfs: create new files with attr forks if necessary
* mkfs: Add parent pointers during protofile creation
* mkfs: enable formatting with parent pointers
--- db/attr.c | 33 ++ db/attrset.c | 202 +++++++++-- db/attrshort.c | 27 ++ db/field.c | 10 + db/field.h | 3 db/hash.c | 44 ++ db/metadump.c | 322 +++++++++++++++++- db/namei.c | 701 +++++++++++++++++++++++++++++++++++++++ db/sb.c | 2 include/handle.h | 1 include/xfs_inode.h | 4 io/parent.c | 541 +++++++++++------------------- libfrog/Makefile | 2 libfrog/fsgeom.c | 6 libfrog/getparents.c | 355 ++++++++++++++++++++ libfrog/getparents.h | 42 ++ libfrog/paths.c | 168 +++++++++ libfrog/paths.h | 25 + libhandle/handle.c | 7 libxfs/defer_item.c | 52 +++ libxfs/init.c | 4 libxfs/libxfs_api_defs.h | 19 + libxfs/util.c | 19 + logprint/log_redo.c | 217 +++++++++++- logprint/logprint.h | 5 man/man2/ioctl_xfs_getparents.2 | 212 ++++++++++++ man/man8/xfs_db.8 | 59 +++ man/man8/xfs_io.8 | 32 +- man/man8/xfs_spaceman.8 | 7 mkfs/lts_4.19.conf | 3 mkfs/lts_5.10.conf | 3 mkfs/lts_5.15.conf | 3 mkfs/lts_5.4.conf | 3 mkfs/lts_6.1.conf | 3 mkfs/lts_6.6.conf | 3 mkfs/proto.c | 62 +++ mkfs/xfs_mkfs.c | 45 ++- repair/attr_repair.c | 24 + scrub/common.c | 41 ++ scrub/phase6.c | 75 ++++ spaceman/Makefile | 16 + spaceman/file.c | 7 spaceman/health.c | 53 ++- spaceman/space.h | 3 44 files changed, 2941 insertions(+), 524 deletions(-) create mode 100644 libfrog/getparents.c create mode 100644 libfrog/getparents.h create mode 100644 man/man2/ioctl_xfs_getparents.2
PATCH 19/23 xfsprogs: scrubbing for parent pointers
In reply to Darrick J. WongHi all,
Teach online fsck to use parent pointers to assist in checking directories, parent pointers, extended attributes, and link counts.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-pptrs-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-pptrs-6.10
---
Commits in this patchset:
* xfs: create a blob array data structure
* man2: update ioctl_xfs_scrub_metadata.2 for parent pointers
--- libxfs/Makefile | 2 libxfs/xfblob.c | 147 +++++++++++++++++++++++++++++++++++ libxfs/xfblob.h | 24 ++++++ libxfs/xfile.c | 11 +++ libxfs/xfile.h | 1 man/man2/ioctl_xfs_scrub_metadata.2 | 20 ++++- 6 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 libxfs/xfblob.c create mode 100644 libxfs/xfblob.h
PATCH 20/23 xfsprogs: offline repair for parent pointers
In reply to Darrick J. WongHi all,
This series implements online checking and repair for directory parent pointer metadata. The checking half is fairly straightforward -- for each outgoing directory link (forward or backwards), grab the inode at the other end, and confirm that there's a corresponding link. If we can't grab an inode or lock it, we'll save that link for a slower loop that cycles all the locks, confirms the continued existence of the link, and rechecks the link if it's actually still there.
Repairs are a bit more involved -- for directories, we walk the entire filesystem to rebuild the dirents from parent pointer information. Parent pointer repairs do the same walk but rebuild the pptrs from the dirent information, but with the added twist that it duplicates all the xattrs so that it can use the atomic extent swapping code to commit the repairs atomically.
This introduces an added twist to the xattr repair code -- we use dirent hooks to detect a colliding update to the pptr data while we're not holding the ILOCKs; if one is detected, we restart the xattr salvaging process but this time hold all the ILOCKs until the end of the scan.
For offline repair, the phase6 directory connectivity scan generates an index of all the expected parent pointers in the filesystem. Then it walks each file and compares the parent pointers attached to that file against the index generated, and resyncs the results as necessary.
The last patch teaches xfs_scrub to report pathnames of files that are being repaired, when possible.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-pptrs-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-pptrs-6.10
---
Commits in this patchset:
* xfs_db: remove some boilerplate from xfs_attr_set
* xfs_db: actually report errors from libxfs_attr_set
* xfs_repair: junk parent pointer attributes when filesystem doesn't support them
* xfs_repair: add parent pointers when messing with /lost+found
* xfs_repair: junk duplicate hashtab entries when processing sf dirents
* xfs_repair: build a parent pointer index
* xfs_repair: move the global dirent name store to a separate object
* xfs_repair: deduplicate strings stored in string blob
* xfs_repair: check parent pointers
* xfs_repair: dump garbage parent pointer attributes
* xfs_repair: update ondisk parent pointer records
* xfs_repair: wipe ondisk parent pointers when there are none
--- db/attrset.c | 36 + libxfs/libxfs_api_defs.h | 6 libxfs/xfblob.c | 9 libxfs/xfblob.h | 2 repair/Makefile | 6 repair/attr_repair.c | 30 + repair/listxattr.c | 271 +++++++++ repair/listxattr.h | 15 + repair/phase6.c | 121 ++++ repair/pptr.c | 1331 ++++++++++++++++++++++++++++++++++++++++++++++ repair/pptr.h | 17 + repair/strblobs.c | 211 +++++++ repair/strblobs.h | 24 + 13 files changed, 2069 insertions(+), 10 deletions(-) create mode 100644 repair/listxattr.c create mode 100644 repair/listxattr.h create mode 100644 repair/pptr.c create mode 100644 repair/pptr.h create mode 100644 repair/strblobs.c create mode 100644 repair/strblobs.h
PATCH 21/23 xfsprogs: detect and correct directory tree problems
In reply to Darrick J. WongHi all,
Historically, checking the tree-ness of the directory tree structure has not been complete. Cycles of subdirectories break the tree properties, as do subdirectories with multiple parents. It's easy enough for DFS to detect problems as long as one of the participants is reachable from the root, but this technique cannot find unconnected cycles.
Directory parent pointers change that, because we can discover all of these problems from a simple walk from a subdirectory towards the root. For each child we start with, if the walk terminates without reaching the root, we know the path is disconnected and ought to be attached to the lost and found. If we find ourselves, we know this is a cycle and can delete an incoming edge. If we find multiple paths to the root, we know to delete an incoming edge.
Even better, once we've finished walking paths, we've identified the good ones and know which other path(s) to remove.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-directory-tree-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-directory-tree-6.10
---
Commits in this patchset:
* libfrog: add directory tree structure scrubber to scrub library
* xfs_spaceman: report directory tree corruption in the health information
* xfs_scrub: fix erroring out of check_inode_names
* xfs_scrub: detect and repair directory tree corruptions
* xfs_scrub: defer phase5 file scans if dirloop fails
--- libfrog/scrub.c | 5 + man/man2/ioctl_xfs_bulkstat.2 | 3 man/man2/ioctl_xfs_fsbulkstat.2 | 3 man/man2/ioctl_xfs_scrub_metadata.2 | 14 ++ scrub/phase5.c | 271 +++++++++++++++++++++++++++++++++-- scrub/repair.c | 13 ++ scrub/repair.h | 2 spaceman/health.c | 4 + 8 files changed, 301 insertions(+), 14 deletions(-)
PATCH 22/23 xfs_scrub: vectorize kernel calls
In reply to Darrick J. WongHi all,
Create a vectorized version of the metadata scrub and repair ioctl, and adapt xfs_scrub to use that. This is an experiment to measure overhead and to try refactoring xfs_scrub.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=vectorized-scrub-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=vectorized-scrub-6.10
---
Commits in this patchset:
* man: document vectored scrub mode
* libfrog: support vectored scrub
* xfs_io: support vectored scrub
* xfs_scrub: split the scrub epilogue code into a separate function
* xfs_scrub: split the repair epilogue code into a separate function
* xfs_scrub: convert scrub and repair epilogues to use xfs_scrub_vec
* xfs_scrub: vectorize scrub calls
* xfs_scrub: vectorize repair calls
* xfs_scrub: use scrub barriers to reduce kernel calls
* xfs_scrub: try spot repairs of metadata items to make scrub progress
--- io/scrub.c | 368 ++++++++++++++++++++++++++++++---- libfrog/fsgeom.h | 6 + libfrog/scrub.c | 137 +++++++++++++ libfrog/scrub.h | 35 +++ man/man2/ioctl_xfs_scrubv_metadata.2 | 171 ++++++++++++++++ man/man8/xfs_io.8 | 51 +++++ scrub/phase1.c | 2 scrub/phase2.c | 93 +++++++-- scrub/phase3.c | 84 ++++++-- scrub/repair.c | 355 +++++++++++++++++++++------------ scrub/scrub.c | 360 +++++++++++++++++++++++++-------- scrub/scrub.h | 19 ++ scrub/scrub_private.h | 55 +++-- scrub/xfs_scrub.c | 1 14 files changed, 1431 insertions(+), 306 deletions(-) create mode 100644 man/man2/ioctl_xfs_scrubv_metadata.2
PATCH 23/23 xfs_repair: fixes for kernel 6.10
In reply to Darrick J. WongHi all,
Fix some incorrect validation problems in xfs_repair.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-fixes-6.10
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-fixes-6.10
---
Commits in this patchset:
* xfs_repair: allow symlinks with short remote targets
--- repair/dinode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
PATCH v3 1/5 Remove support for split-/usr installs
In reply to Darrick J. WongFrom: Chris Hofstaedtler <[email protected]>
Always install binaries and other files under /usr, not /. This will break any distribution that hasn't yet merged the two, which are vanishingly small these days. This breaks the usecase of needing to repair the /usr partition when there is no initramfs or livecd available and / is the only option.
--- configure.ac | 21 --------------------- debian/Makefile | 4 ++-- debian/local/initramfs.hook | 2 +- debian/rules | 5 ++--- fsck/Makefile | 4 ++-- include/builddefs.in | 2 -- include/buildmacros | 20 ++++++++++---------- mkfs/Makefile | 4 ++-- repair/Makefile | 4 ++-- 9 files changed, 21 insertions(+), 45 deletions(-)
configure.ac +0 -21
@@ -113,27 +113,6 @@ esac # test -n "$multiarch" && enable_lib64=no -# -# Some important tools should be installed into the root partitions. -# -# Check whether exec_prefix=/usr: and install them to /sbin in that -# case. If the user chooses a different prefix assume they just want -# a local install for testing and not a system install. -# -case $exec_prefix:$prefix in -NONE:NONE | NONE:/usr | /usr:*) - root_sbindir='/sbin' - root_libdir="/${base_libdir}" - ;; -*) - root_sbindir="${sbindir}" - root_libdir="${libdir}" - ;; -esac - -AC_SUBST([root_sbindir]) -AC_SUBST([root_libdir]) - # Find localized files. Don't descend into any "dot directories" # (like .git or .pc from quilt). Strangely, the "-print" argument # to "find" is required, to avoid including such directories in the
debian/Makefile +2 -2
@@ -31,6 +31,6 @@ endif install-d-i: default ifeq ($(PKG_DISTRIBUTION), debian) - $(INSTALL) -m 755 -d $(PKG_ROOT_SBIN_DIR) - $(INSTALL) -m 755 $(BOOT_MKFS_BIN) $(PKG_ROOT_SBIN_DIR)/mkfs.xfs + $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) + $(INSTALL) -m 755 $(BOOT_MKFS_BIN) $(PKG_SBIN_DIR)/mkfs.xfs endif
debian/local/initramfs.hook +1 -1
@@ -45,7 +45,7 @@ rootfs_type() { . /usr/share/initramfs-tools/hook-functions if [ "$(rootfs_type)" = "xfs" ]; then - copy_exec /sbin/xfs_repair + copy_exec /usr/sbin/xfs_repair copy_exec /usr/sbin/xfs_db copy_exec /usr/sbin/xfs_metadump fi
debian/rules +2 -3
@@ -105,9 +105,8 @@ binary-arch: checkroot built $(pkgme) $(MAKE) dist install -D -m 0755 debian/local/initramfs.hook debian/xfsprogs/usr/share/initramfs-tools/hooks/xfs rmdir debian/xfslibs-dev/usr/share/doc/xfsprogs - rm -f debian/xfslibs-dev/lib/$(DEB_HOST_MULTIARCH)/libhandle.la - rm -f debian/xfslibs-dev/lib/$(DEB_HOST_MULTIARCH)/libhandle.a - rm -fr debian/xfslibs-dev/usr/lib + rm -f debian/xfslibs-dev/usr/lib/$(DEB_HOST_MULTIARCH)/libhandle.la + rm -f debian/xfslibs-dev/usr/lib/$(DEB_HOST_MULTIARCH)/libhandle.a dh_installdocs -XCHANGES dh_installchangelogs dh_strip
fsck/Makefile +2 -2
@@ -12,6 +12,6 @@ default: $(LTCOMMAND) include $(BUILDRULES) install: default - $(INSTALL) -m 755 -d $(PKG_ROOT_SBIN_DIR) - $(INSTALL) -m 755 xfs_fsck.sh $(PKG_ROOT_SBIN_DIR)/fsck.xfs + $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) + $(INSTALL) -m 755 xfs_fsck.sh $(PKG_SBIN_DIR)/fsck.xfs install-dev:
include/builddefs.in +0 -2
@@ -48,8 +48,6 @@ datarootdir = @datarootdir@ top_builddir = @top_builddir@ PKG_SBIN_DIR = @sbindir@ -PKG_ROOT_SBIN_DIR = @root_sbindir@ -PKG_ROOT_LIB_DIR= @root_libdir@@libdirsuffix@ PKG_LIB_DIR = @libdir@@libdirsuffix@ PKG_LIBEXEC_DIR = @libexecdir@/@pkg_name@ PKG_INC_DIR = @includedir@/xfs
include/buildmacros +10 -10
@@ -50,16 +50,16 @@ LTINSTALL = $(LIBTOOL) --quiet --mode=install $(INSTALL) LTCOMPILE = $(LIBTOOL) --quiet --tag=CC --mode=compile $(CCF) ifeq ($(ENABLE_SHARED),yes) -LTLDFLAGS += -rpath $(PKG_ROOT_LIB_DIR) +LTLDFLAGS += -rpath $(PKG_LIB_DIR) LTLDFLAGS += -version-info $(LTVERSION) endif ifeq ($(ENABLE_SHARED),yes) INSTALL_LTLIB = \ cd $(TOPDIR)/$(LIBNAME)/.libs; \ - ../$(INSTALL) -m 755 -d $(PKG_ROOT_LIB_DIR); \ - ../$(INSTALL) -m 755 -T so_dot_version $(LIBNAME).lai $(PKG_ROOT_LIB_DIR); \ - ../$(INSTALL) -T so_dot_current $(LIBNAME).lai $(PKG_ROOT_LIB_DIR) + ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ + ../$(INSTALL) -m 755 -T so_dot_version $(LIBNAME).lai $(PKG_LIB_DIR); \ + ../$(INSTALL) -T so_dot_current $(LIBNAME).lai $(PKG_LIB_DIR) endif # Libtool thinks the static and shared libs should be in the same dir, so
@@ -74,13 +74,13 @@ INSTALL_LTLIB_DEV = \ ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ ../$(INSTALL) -m 644 -T old_lib $(LIBNAME).lai $(PKG_LIB_DIR); \ ../$(INSTALL) -m 644 $(LIBNAME).lai $(PKG_LIB_DIR)/$(LIBNAME).la ; \ - ../$(INSTALL) -m 755 -d $(PKG_ROOT_LIB_DIR); \ - ../$(INSTALL) -T so_base $(LIBNAME).lai $(PKG_ROOT_LIB_DIR); \ + ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ + ../$(INSTALL) -T so_base $(LIBNAME).lai $(PKG_LIB_DIR); \ if [ "x$(shell readlink -f $(PKG_LIB_DIR))" != \ - "x$(shell readlink -f $(PKG_ROOT_LIB_DIR))" ]; then \ - ../$(INSTALL) -S $(PKG_LIB_DIR)/$(LIBNAME).a $(PKG_ROOT_LIB_DIR)/$(LIBNAME).a; \ - ../$(INSTALL) -S $(PKG_LIB_DIR)/$(LIBNAME).la $(PKG_ROOT_LIB_DIR)/$(LIBNAME).la; \ - ../$(INSTALL) -S $(PKG_ROOT_LIB_DIR)/$(LIBNAME).so $(PKG_LIB_DIR)/$(LIBNAME).so; \ + "x$(shell readlink -f $(PKG_LIB_DIR))" ]; then \ + ../$(INSTALL) -S $(PKG_LIB_DIR)/$(LIBNAME).a $(PKG_LIB_DIR)/$(LIBNAME).a; \ + ../$(INSTALL) -S $(PKG_LIB_DIR)/$(LIBNAME).la $(PKG_LIB_DIR)/$(LIBNAME).la; \ + ../$(INSTALL) -S $(PKG_LIB_DIR)/$(LIBNAME).so $(PKG_LIB_DIR)/$(LIBNAME).so; \ fi else INSTALL_LTLIB_DEV = $(INSTALL_LTLIB_STATIC)
mkfs/Makefile +2 -2
@@ -28,8 +28,8 @@ default: depend $(LTCOMMAND) $(CFGFILES) include $(BUILDRULES) install: default - $(INSTALL) -m 755 -d $(PKG_ROOT_SBIN_DIR) - $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_ROOT_SBIN_DIR) + $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) + $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) $(INSTALL) -m 755 -d $(MKFS_CFG_DIR) $(INSTALL) -m 644 $(CFGFILES) $(MKFS_CFG_DIR)
repair/Makefile +2 -2
@@ -103,8 +103,8 @@ include $(BUILDRULES) #CFLAGS += ... install: default - $(INSTALL) -m 755 -d $(PKG_ROOT_SBIN_DIR) - $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_ROOT_SBIN_DIR) + $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) + $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) install-dev: -include .dep
PATCH 2/5 repair: btree blocks are never on the RT subvolume
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
scan_bmapbt tries to track btree blocks in the RT duplicate extent AVL tree if the inode has the realtime flag set. Given that the RT subvolume is only ever used for file data this is incorrect.
--- repair/scan.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
repair/scan.c +5 -16
@@ -390,22 +390,11 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"),break ; }pthread_mutex_unlock (&ag_locks[agno].lock); - }else { -/* -* attribute fork for realtime files is in the regular -* filesystem -*/ -if (type !=XR_INO_RTDATA || whichfork !=XFS_DATA_FORK ) { -if (search_dup_extent (XFS_FSB_TO_AGNO (mp, bno), -XFS_FSB_TO_AGBNO (mp, bno), -XFS_FSB_TO_AGBNO (mp, bno) +1 )) -return (1 ); - }else { -xfs_rtxnum_t ext =xfs_rtb_to_rtx (mp, bno); - -if (search_rt_dup_extent (mp, ext)) -return 1 ; - } + }else { +if (search_dup_extent (XFS_FSB_TO_AGNO (mp, bno), +XFS_FSB_TO_AGBNO (mp, bno), +XFS_FSB_TO_AGBNO (mp, bno) +1 )) +return 1 ; } (*tot)++; numrecs =be16_to_cpu (block->bb_numrecs);
PATCH 3/5 xfile: fix missing error unlock in xfile_fcb_find
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Fix a missing mutex pthread_mutex_unlock and uninitialized return value in xfile_fcb_find.
Coverity-id: 1604113
Coverity-id: 1604099
--- libxfs/xfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libxfs/xfile.c +3 -3
@@ -179,7 +179,7 @@ xfile_fcb_find( {struct xfile_fcb *fcb;int ret; -int error; +int error =0 ;/* No maximum range means that the caller gets a private memfd. */ if (maxbytes ==0 ) {
@@ -222,13 +222,13 @@ xfile_fcb_find(/* Otherwise, open a new memfd and add it to our list. */ error =xfile_fcb_create (description, &fcb);if (error) -return error; + goto out_unlock; ret =ftruncate (fcb->fd, maxbytes);if (ret) { error = -errno;xfile_fcb_irele (fcb,0 , maxbytes); -return error; + goto out_unlock; }list_add_tail (&fcb->fcb_list, &fcb_list);
PATCH 4/5 xfs_repair: don't leak the rootdir inode when orphanage already exists
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If repair calls mk_orphanage and the /lost+found directory already exists, we need to irele the root directory before exiting the function.
--- repair/phase6.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
repair/phase6.c +5 -2
@@ -919,8 +919,10 @@ mk_orphanage(xfs_mount_t *mp) xname.len =strlen (ORPHANAGE ); xname.type =XFS_DIR3_FT_DIR ; -if (libxfs_dir_lookup (NULL , pip, &xname, &ino,NULL ) ==0 ) -return ino; +/* If the lookup of /lost+found succeeds, return the inumber. */ + error = -libxfs_dir_lookup (NULL , pip, &xname, &ino,NULL ); +if (error ==0 ) + goto out_pip;/* * could not be found, create it
@@ -1012,6 +1014,7 @@ mk_orphanage(xfs_mount_t *mp) ORPHANAGE, error); }libxfs_irele (ip); +out_pip:libxfs_irele (pip);return (ino);
PATCH 5/5 xfs_repair: don't crash on -vv
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
A user reported a crash in xfs_repair when they run it with -vv specified on the command line. Ultimately this harks back to xfs_m in main() containing uninitialized stack contents, and inadequate null checks. Fix both problems in one go.
--- repair/progress.c | 2 +- repair/xfs_repair.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
repair/progress.c +1 -1
@@ -394,7 +394,7 @@ timestamp(time_t now;struct tm *tmp; -if (verbose >1 && mp && mp->m_ddev_targp) +if (verbose >1 && mp && mp->m_ddev_targp && mp->m_ddev_targp->bcache)cache_report (stderr,"libxfs_bcache" , mp->m_ddev_targp->bcache); now =time (NULL );
repair/xfs_repair.c +1 -1
@@ -1018,7 +1018,7 @@ main(int argc, char **argv)xfs_mount_t *temp_mp;xfs_mount_t *mp;struct xfs_buf *sbp; -xfs_mount_t xfs_m; +struct xfs_mount xfs_m = { };struct xlog log = {0 };char *msgbuf;struct xfs_sb psb;
PATCH 1/115 xfs: pass xfs_buf lookup flags to xfs_*read_agi
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 549d3c9a29921f388ef3bcfd1d4f669b7dd4eed2
Allow callers to pass buffer lookup flags to xfs_read_agi and xfs_ialloc_read_agi. This will be used in the next patch to fix a deadlock in the online fsck inode scanner.
--- db/iunlink.c | 4 ++-- libxfs/xfs_ag.c | 8 ++++---- libxfs/xfs_ialloc.c | 16 ++++++++++------ libxfs/xfs_ialloc.h | 5 +++-- libxfs/xfs_ialloc_btree.c | 4 ++-- 5 files changed, 21 insertions(+), 16 deletions(-)
db/iunlink.c +2 -2
@@ -117,7 +117,7 @@ dump_unlinked(xfs_agnumber_t agno = pag->pag_agno;int error; - error = -libxfs_ialloc_read_agi (pag,NULL , &agi_bp); + error = -libxfs_ialloc_read_agi (pag,NULL ,0 , &agi_bp);if (error) {dbprintf (_ ("AGI %u: %s\n" ), agno,strerror (errno));return ;
@@ -295,7 +295,7 @@ iunlink( pag =libxfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino));/* Get the agi buffer first. It ensures lock ordering on the list. */ - error = -libxfs_read_agi (pag, tp, &agibp); + error = -libxfs_read_agi (pag, tp,0 , &agibp);if (error) goto out;
libxfs/xfs_ag.c +4 -4
@@ -192,7 +192,7 @@ xfs_initialize_perag_data( pag =xfs_perag_get (mp, index); error =xfs_alloc_read_agf (pag,NULL ,0 ,NULL );if (!error) - error =xfs_ialloc_read_agi (pag,NULL ,NULL ); + error =xfs_ialloc_read_agi (pag,NULL ,0 ,NULL );if (error) {xfs_perag_put (pag);return error;
@@ -929,7 +929,7 @@ xfs_ag_shrink_space(int error, err2;ASSERT (pag->pag_agno == mp->m_sb.sb_agcount -1 ); - error =xfs_ialloc_read_agi (pag, *tpp, &agibp); + error =xfs_ialloc_read_agi (pag, *tpp,0 , &agibp);if (error)return error;
@@ -1060,7 +1060,7 @@ xfs_ag_extend_space(ASSERT (pag->pag_agno == pag->pag_mount->m_sb.sb_agcount -1 ); - error =xfs_ialloc_read_agi (pag, tp, &bp); + error =xfs_ialloc_read_agi (pag, tp,0 , &bp);if (error)return error;
@@ -1117,7 +1117,7 @@ xfs_ag_get_geometry(int error;/* Lock the AG headers. */ - error =xfs_ialloc_read_agi (pag,NULL , &agi_bp); + error =xfs_ialloc_read_agi (pag,NULL ,0 , &agi_bp);if (error)return error; error =xfs_alloc_read_agf (pag,NULL ,0 , &agf_bp);
libxfs/xfs_ialloc.c +10 -6
@@ -1694,7 +1694,7 @@ xfs_dialloc_good_ag(return false;if (!xfs_perag_initialised_agi (pag)) { - error =xfs_ialloc_read_agi (pag, tp,NULL ); + error =xfs_ialloc_read_agi (pag, tp,0 ,NULL );if (error)return false; }
@@ -1763,7 +1763,7 @@ xfs_dialloc_try_ag(* Then read in the AGI buffer and recheck with the AGI buffer * lock held. */ - error =xfs_ialloc_read_agi (pag, *tpp, &agbp); + error =xfs_ialloc_read_agi (pag, *tpp,0 , &agbp);if (error)return error;
@@ -2281,7 +2281,7 @@ xfs_difree(/* * Get the allocation group header. */ - error =xfs_ialloc_read_agi (pag, tp, &agbp); + error =xfs_ialloc_read_agi (pag, tp,0 , &agbp);if (error) {xfs_warn (mp,"%s: xfs_ialloc_read_agi() returned error %d." , __func__, error);
@@ -2327,7 +2327,7 @@ xfs_imap_lookup(int error;int i; - error =xfs_ialloc_read_agi (pag, tp, &agbp); + error =xfs_ialloc_read_agi (pag, tp,0 , &agbp);if (error) { xfs_alert(mp, "%s: xfs_ialloc_read_agi() returned error %d, agno %d",
@@ -2670,6 +2670,7 @@ intxfs_read_agi ( struct xfs_perag *pag, struct xfs_trans *tp, + xfs_buf_flags_t flags, struct xfs_buf **agibpp) { struct xfs_mount *mp = pag->pag_mount;
@@ -2679,7 +2680,7 @@ xfs_read_agi( error =xfs_trans_read_buf (mp, tp, mp->m_ddev_targp,XFS_AG_DADDR (mp, pag->pag_agno,XFS_AGI_DADDR (mp)), -XFS_FSS_TO_BB (mp,1 ),0 , agibpp, &xfs_agi_buf_ops); +XFS_FSS_TO_BB (mp,1 ), flags, agibpp, &xfs_agi_buf_ops);if (xfs_metadata_is_sick (error))xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI );if (error)
@@ -2699,6 +2700,7 @@ intxfs_ialloc_read_agi ( struct xfs_perag *pag, struct xfs_trans *tp, + int flags, struct xfs_buf **agibpp) { struct xfs_buf *agibp;
@@ -2707,7 +2709,9 @@ xfs_ialloc_read_agi(trace_xfs_ialloc_read_agi (pag->pag_mount, pag->pag_agno); - error =xfs_read_agi (pag, tp, &agibp); + error =xfs_read_agi (pag, tp, + (flags &XFS_IALLOC_FLAG_TRYLOCK ) ?XBF_TRYLOCK :0 , + &agibp);if (error)return error;
libxfs/xfs_ialloc.h +3 -2
@@ -63,10 +63,11 @@ xfs_ialloc_log_agi(struct xfs_buf *bp,/* allocation group header buffer */ uint32_t fields); /* bitmask of fields to log */ -int xfs_read_agi (struct xfs_perag *pag,struct xfs_trans *tp, +int xfs_read_agi (struct xfs_perag *pag,struct xfs_trans *tp,xfs_buf_flags_t flags,struct xfs_buf **agibpp);int xfs_ialloc_read_agi (struct xfs_perag *pag,struct xfs_trans *tp, -struct xfs_buf **agibpp); +int flags,struct xfs_buf **agibpp); +#define XFS_IALLOC_FLAG_TRYLOCK (1U << 0)/* use trylock for buffer locking */ /* * Lookup a record by ino in the btree given by cur.
libxfs/xfs_ialloc_btree.c +2 -2
@@ -744,7 +744,7 @@ xfs_finobt_count_blocks(struct xfs_btree_cur *cur;int error; - error =xfs_ialloc_read_agi (pag, tp, &agbp); + error =xfs_ialloc_read_agi (pag, tp,0 , &agbp);if (error)return error;
@@ -767,7 +767,7 @@ xfs_finobt_read_blocks(struct xfs_agi *agi;int error; - error =xfs_ialloc_read_agi (pag, tp, &agbp); + error =xfs_ialloc_read_agi (pag, tp,0 , &agbp);if (error)return error;
PATCH 2/115 xfs: constify xfs_bmap_is_written_extent
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 15f78aa3eb07645e7bef15a53b4ae1c757907d2c
This predicate doesn't modify the structure that's being passed in, so we can mark it const.
--- libxfs/xfs_bmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_bmap.h +1 -1
@@ -158,7 +158,7 @@ static inline bool xfs_bmap_is_real_extent(const struct xfs_bmbt_irec *irec)* Return true if the extent is a real, allocated extent, or false if it is a * delayed allocation, and unwritten extent or a hole. */ -static inline bool xfs_bmap_is_written_extent (struct xfs_bmbt_irec *irec) +static inline bool xfs_bmap_is_written_extent (const struct xfs_bmbt_irec *irec) {return xfs_bmap_is_real_extent (irec) && irec->br_state !=XFS_EXT_UNWRITTEN ;
PATCH 3/115 xfs: introduce new file range exchange ioctl
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 9a64d9b3109d01cca0b83c1d36538b7a37c5284e
Introduce a new ioctl to handle exchanging ranges of bytes between files. The goal here is to perform the exchange atomically with respect to applications -- either they see the file contents before the exchange or they see that A-B is now B-A, even if the kernel crashes.
My original goal with all this code was to make it so that online repair can build a replacement directory or xattr structure in a temporary file and commit the repair by atomically exchanging all the data blocks between the two files. However, I needed a way to test this mechanism thoroughly, so I've been evolving an ioctl interface since then.
--- libxfs/xfs_fs.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
libxfs/xfs_fs.h +41 -0
@@ -772,6 +772,46 @@ struct xfs_scrub_metadata {# define XFS_XATTR_LIST_MAX 65536#endif +/* +* Exchange part of file1 with part of the file that this ioctl that is being +* called against (which we'll call file2). Filesystems must be able to +* restart and complete the operation even after the system goes down. +*/ +struct xfs_exchange_range { +__s32 file1_fd; +__u32 pad;/* must be zeroes */ +__u64 file1_offset;/* file1 offset, bytes */ +__u64 file2_offset;/* file2 offset, bytes */ +__u64 length;/* bytes to exchange */ + +__u64 flags;/* see XFS_EXCHANGE_RANGE_* below */ +}; + +/* +* Exchange file data all the way to the ends of both files, and then exchange +* the file sizes. This flag can be used to replace a file's contents with a +* different amount of data. length will be ignored. +*/ +#define XFS_EXCHANGE_RANGE_TO_EOF (1ULL << 0) + +/* Flush all changes in file data and file metadata to disk before returning. */ +#define XFS_EXCHANGE_RANGE_DSYNC (1ULL << 1) + +/* Dry run; do all the parameter verification but do not change anything. */ +#define XFS_EXCHANGE_RANGE_DRY_RUN (1ULL << 2) + +/* +* Exchange only the parts of the two files where the file allocation units +* mapped to file1's range have been written to. This can accelerate +* scatter-gather atomic writes with a temp file if all writes are aligned to +* the file allocation unit. +*/ +#define XFS_EXCHANGE_RANGE_FILE1_WRITTEN (1ULL << 3) + +#define XFS_EXCHANGE_RANGE_ALL_FLAGS (XFS_EXCHANGE_RANGE_TO_EOF | \ + XFS_EXCHANGE_RANGE_DSYNC | \ + XFS_EXCHANGE_RANGE_DRY_RUN | \ + XFS_EXCHANGE_RANGE_FILE1_WRITTEN)/* * ioctl commands that are used by Linux filesystems
@@ -843,6 +883,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_EXCHANGE_RANGE _IOWR('X', 129, struct xfs_exchange_range)/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
PATCH 4/115 xfs: create a incompat flag for atomic file mapping exchanges
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 1518646eef26c220e9256906260ecaaa64503522
Create a incompat flag so that we only attempt to process file mapping exchange log items if the filesystem supports it, and a geometry flag to advertise support if it's present.
--- include/xfs_mount.h | 2 ++ libxfs/xfs_format.h | 23 ++++++++++++----------- libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 4 ++++ 4 files changed, 19 insertions(+), 11 deletions(-)
include/xfs_mount.h +2 -0
@@ -169,6 +169,7 @@ typedef struct xfs_mount {#define XFS_FEAT_BIGTIME (1ULL << 24)/* large timestamps */ #define XFS_FEAT_NEEDSREPAIR (1ULL << 25)/* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26)/* large extent counters */ +#define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27)/* exchange range */ #define __XFS_HAS_FEAT (name,NAME ) \ static inline bool xfs_has_ ## name (struct xfs_mount *mp) \
@@ -213,6 +214,7 @@ __XFS_HAS_FEAT(inobtcounts, INOBTCNT) __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) +__XFS_HAS_FEAT (exchange_range,EXCHANGE_RANGE ) /* Kernel mount features that we don't support */#define __XFS_UNSUPP_FEAT (name) \
libxfs/xfs_format.h +12 -11
@@ -367,18 +367,19 @@ xfs_sb_has_ro_compat_feature(return (sbp->sb_features_ro_compat & feature) !=0 ; } -#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ -#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ -#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3)/* large timestamps */ -#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ -#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)/* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ +#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ +#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ +#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3)/* large timestamps */ +#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ +#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)/* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_EXCHRANGE (1 << 6)/* exchangerange supported */ #define XFS_SB_FEAT_INCOMPAT_ALL \ - (XFS_SB_FEAT_INCOMPAT_FTYPE| \ - XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID| \ - XFS_SB_FEAT_INCOMPAT_BIGTIME| \ - XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ + (XFS_SB_FEAT_INCOMPAT_FTYPE | \ + XFS_SB_FEAT_INCOMPAT_SPINODES | \ + XFS_SB_FEAT_INCOMPAT_META_UUID | \ + XFS_SB_FEAT_INCOMPAT_BIGTIME | \ + XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ XFS_SB_FEAT_INCOMPAT_NREXT64)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
libxfs/xfs_fs.h +1 -0
@@ -239,6 +239,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_BIGTIME (1 << 21)/* 64-bit nsec timestamps */ #define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22)/* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23)/* large extent counters */ +#define XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE (1 << 24)/* exchange range */ /* * Minimum and maximum sizes need for growth checks.
libxfs/xfs_sb.c +4 -0
@@ -173,6 +173,8 @@ xfs_sb_version_to_features( features |=XFS_FEAT_NEEDSREPAIR ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_NREXT64 ) features |=XFS_FEAT_NREXT64 ; +if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_EXCHRANGE ) + features |=XFS_FEAT_EXCHANGE_RANGE ;return features; }
@@ -1257,6 +1259,8 @@ xfs_fs_geometry( }if (xfs_has_large_extent_counts (mp)) geo->flags |=XFS_FSOP_GEOM_FLAGS_NREXT64 ; +if (xfs_has_exchange_range (mp)) + geo->flags |=XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE ; geo->rtsectsize = sbp->sb_blocksize; geo->dirblocksize =xfs_dir2_dirblock_bytes (sbp);
PATCH 5/115 xfs: introduce a file mapping exchange log intent item
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 6c08f434bd33f88cf169e9e43c7a5e42fb3f2118
Introduce a new intent log item to handle exchanging mappings between the forks of two files.
--- libxfs/xfs_log_format.h | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
libxfs/xfs_log_format.h +39 -3
@@ -117,8 +117,9 @@ struct xfs_unmount_log_format {#define XLOG_REG_TYPE_ATTRD_FORMAT 28#define XLOG_REG_TYPE_ATTR_NAME 29#define XLOG_REG_TYPE_ATTR_VALUE 30 -#define XLOG_REG_TYPE_MAX 30 - +#define XLOG_REG_TYPE_XMI_FORMAT 31 +#define XLOG_REG_TYPE_XMD_FORMAT 32 +#define XLOG_REG_TYPE_MAX 32/* * Flags to log operation header
@@ -243,6 +244,8 @@ typedef struct xfs_trans_header {#define XFS_LI_BUD 0x1245#define XFS_LI_ATTRI 0x1246/* attr set/remove intent*/ #define XFS_LI_ATTRD 0x1247/* attr set/remove done */ +#define XFS_LI_XMI 0x1248/* mapping exchange intent */ +#define XFS_LI_XMD 0x1249/* mapping exchange done */ #define XFS_LI_TYPE_DESC \ { XFS_LI_EFI, "XFS_LI_EFI" }, \
@@ -260,7 +263,9 @@ typedef struct xfs_trans_header { { XFS_LI_BUI, "XFS_LI_BUI" }, \ { XFS_LI_BUD, "XFS_LI_BUD" }, \ { XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \ - { XFS_LI_ATTRD, "XFS_LI_ATTRD" } + { XFS_LI_ATTRD, "XFS_LI_ATTRD" }, \ + { XFS_LI_XMI, "XFS_LI_XMI" }, \ + { XFS_LI_XMD, "XFS_LI_XMD" }/* * Inode Log Item Format definitions.
@@ -878,6 +883,37 @@ struct xfs_bud_log_format {uint64_t bud_bui_id;/* id of corresponding bui */ }; +/* +* XMI/XMD (file mapping exchange) log format definitions +*/ + +/* This is the structure used to lay out an mapping exchange log item. */ +struct xfs_xmi_log_format { +uint16_t xmi_type;/* xmi log item type */ +uint16_t xmi_size;/* size of this item */ +uint32_t __pad;/* must be zero */ +uint64_t xmi_id;/* xmi identifier */ + +uint64_t xmi_inode1;/* inumber of first file */ +uint64_t xmi_inode2;/* inumber of second file */ +uint64_t xmi_startoff1;/* block offset into file1 */ +uint64_t xmi_startoff2;/* block offset into file2 */ +uint64_t xmi_blockcount;/* number of blocks */ +uint64_t xmi_flags;/* XFS_EXCHMAPS_* */ +uint64_t xmi_isize1;/* intended file1 size */ +uint64_t xmi_isize2;/* intended file2 size */ +}; + +#define XFS_EXCHMAPS_LOGGED_FLAGS (0) + +/* This is the structure used to lay out an mapping exchange done log item. */ +struct xfs_xmd_log_format { +uint16_t xmd_type;/* xmd log item type */ +uint16_t xmd_size;/* size of this item */ +uint32_t __pad; +uint64_t xmd_xmi_id;/* id of corresponding xmi */ +}; +/* * Dquot Log format definitions. *
PATCH 6/115 xfs: create deferred log items for file mapping exchanges
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 966ceafc7a437105ecfe1cadb3747b2965a260ca
Now that we've created the skeleton of a log intent item to track and restart file mapping exchange operations, add the upper level logic to log. This builds on the existing bmap update intent items that have been around for a while now.
--- include/xfs_trace.h | 14 + libxfs/Makefile | 2 libxfs/defer_item.c | 88 ++++ libxfs/defer_item.h | 5 libxfs/libxfs_priv.h | 30 + libxfs/xfs_defer.c | 6 libxfs/xfs_defer.h | 2 libxfs/xfs_exchmaps.c | 1042 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_exchmaps.h | 118 +++++ libxfs/xfs_log_format.h | 24 + libxfs/xfs_trans_space.h | 4 11 files changed, 1333 insertions(+), 2 deletions(-) create mode 100644 libxfs/xfs_exchmaps.c create mode 100644 libxfs/xfs_exchmaps.h
include/xfs_trace.h +14 -0
@@ -329,6 +329,9 @@#define trace_xfs_refcount_cow_decrease (...) ((void) 0)#define trace_xfs_refcount_recover_extent (...) ((void) 0) +#define trace_xfs_reflink_set_inode_flag (...) ((void) 0) +#define trace_xfs_reflink_unset_inode_flag (...) ((void) 0) +#define trace_xfs_rmap_find_left_neighbor_candidate (...) ((void) 0)#define trace_xfs_rmap_find_left_neighbor_query (...) ((void) 0)#define trace_xfs_rmap_find_left_neighbor_result (...) ((void) 0)
@@ -342,6 +345,17 @@#define trace_xfs_rmap_map_error (...) ((void) 0)#define trace_xfs_rmap_delete_error (...) ((void) 0) +#define trace_xfs_exchmaps_defer (...) ((void) 0) +#define trace_xfs_exchmaps_delta_nextents (...) ((void) 0) +#define trace_xfs_exchmaps_delta_nextents_step (...) ((void) 0) +#define trace_xfs_exchmaps_mapping1_skip (...) ((void) 0) +#define trace_xfs_exchmaps_mapping1 (...) ((void) 0) +#define trace_xfs_exchmaps_mapping2 (...) ((void) 0) +#define trace_xfs_exchmaps_final_estimate (...) ((void) 0) +#define trace_xfs_exchmaps_initial_estimate (...) ((void) 0) +#define trace_xfs_exchmaps_overhead (...) ((void) 0) +#define trace_xfs_exchmaps_update_inode_size (...) ((void) 0) +#define trace_xfs_fs_mark_healthy (a,b) ((void) 0)#define trace_xlog_intent_recovery_failed (...) ((void) 0)
libxfs/Makefile +2 -0
@@ -45,6 +45,7 @@ HFILES = \ xfs_da_btree.h \ xfs_dir2.h \ xfs_errortag.h \ + xfs_exchmaps.h \ xfs_ialloc.h \ xfs_ialloc_btree.h \ xfs_inode_buf.h \
@@ -94,6 +95,7 @@ CFILES = buf_mem.c \ xfs_dir2_node.c \ xfs_dir2_sf.c \ xfs_dquot_buf.c \ + xfs_exchmaps.c \ xfs_ialloc.c \ xfs_iext_tree.c \ xfs_inode_buf.c \
libxfs/defer_item.c +88 -0
97 lines not on this page · raw message
libxfs/defer_item.h +5 -0
@@ -10,4 +10,9 @@ struct xfs_bmap_intent;void xfs_bmap_defer_add (struct xfs_trans *tp,struct xfs_bmap_intent *bi); +struct xfs_exchmaps_intent ; + +void xfs_exchmaps_defer_add (struct xfs_trans *tp, +struct xfs_exchmaps_intent *xmi); +#endif /* __LIBXFS_DEFER_ITEM_H_ */
libxfs/libxfs_priv.h +30 -0
@@ -219,6 +219,35 @@ static inline bool WARN_ON(bool expr) { (inode)->i_version = (version); \ } while (0) +#define __must_check __attribute__((__warn_unused_result__)) + +/* +* Allows for effectively applying __must_check to a macro so we can have +* both the type-agnostic benefits of the macros while also being able to +* enforce that the return value is, in fact, checked. +*/ +static inline bool __must_check __must_check_overflow (bool overflow) +{ +return unlikely (overflow); +} + +/* +* For simplicity and code hygiene, the fallback code below insists on +* a, b and *d having the same type (similar to the min() and max() +* macros), whereas gcc's type-generic overflow checkers accept +* different types. Hence we don't just make check_add_overflow an +* alias for __builtin_add_overflow, but add type checks similar to +* below. +*/ +#define check_add_overflow (a, b, d) __must_check_overflow(({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + typeof(d) __d = (d); \ + (void) (&__a == &__b); \ + (void) (&__a == __d); \ + __builtin_add_overflow(__a, __b, __d); \ +})) +#define min_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })#define max_t (type,x,y) \
@@ -541,6 +570,7 @@ void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *lip, int type,#define xfs_log_in_recovery (mp) (false)/* xfs_icache.c */ +#define xfs_inode_clear_cowblocks_tag (ip) do { } while (0)#define xfs_inode_set_cowblocks_tag (ip) do { } while (0)#define xfs_inode_set_eofblocks_tag (ip) do { } while (0)
libxfs/xfs_defer.c +6 -0
@@ -21,6 +21,7 @@#include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_attr.h" +#include "xfs_exchmaps.h" static struct kmem_cache *xfs_defer_pending_cache;
@@ -1170,6 +1171,10 @@ xfs_defer_init_item_caches(void) error =xfs_attr_intent_init_cache ();if (error) goto err; + error =xfs_exchmaps_intent_init_cache (); +if (error) + goto err; +return 0 ; err:xfs_defer_destroy_item_caches ();
@@ -1180,6 +1185,7 @@ xfs_defer_init_item_caches(void)void xfs_defer_destroy_item_caches (void ) { +xfs_exchmaps_intent_destroy_cache ();xfs_attr_intent_destroy_cache ();xfs_extfree_intent_destroy_cache ();xfs_bmap_intent_destroy_cache ();
libxfs/xfs_defer.h +1 -1
@@ -72,7 +72,7 @@ extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;extern const struct xfs_defer_op_type xfs_extent_free_defer_type;extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;extern const struct xfs_defer_op_type xfs_attr_defer_type; - +extern const struct xfs_defer_op_type xfs_exchmaps_defer_type;/* * Deferred operation item relogging limits.
libxfs/xfs_exchmaps.c new file +1042 -0
1,042 lines not on this page · raw message
libxfs/xfs_exchmaps.h new file +118 -0
118 lines not on this page · raw message
libxfs/xfs_log_format.h +23 -1
@@ -904,7 +904,29 @@ struct xfs_xmi_log_format {uint64_t xmi_isize2;/* intended file2 size */ }; -#define XFS_EXCHMAPS_LOGGED_FLAGS (0) +/* Exchange mappings between extended attribute forks instead of data forks. */ +#define XFS_EXCHMAPS_ATTR_FORK (1ULL << 0) + +/* Set the file sizes when finished. */ +#define XFS_EXCHMAPS_SET_SIZES (1ULL << 1) + +/* +* Exchange the mappings of the two files only if the file allocation units +* mapped to file1's range have been written. +*/ +#define XFS_EXCHMAPS_INO1_WRITTEN (1ULL << 2) + +/* Clear the reflink flag from inode1 after the operation. */ +#define XFS_EXCHMAPS_CLEAR_INO1_REFLINK (1ULL << 3) + +/* Clear the reflink flag from inode2 after the operation. */ +#define XFS_EXCHMAPS_CLEAR_INO2_REFLINK (1ULL << 4) + +#define XFS_EXCHMAPS_LOGGED_FLAGS (XFS_EXCHMAPS_ATTR_FORK | \ + XFS_EXCHMAPS_SET_SIZES | \ + XFS_EXCHMAPS_INO1_WRITTEN | \ + XFS_EXCHMAPS_CLEAR_INO1_REFLINK | \ + XFS_EXCHMAPS_CLEAR_INO2_REFLINK)/* This is the structure used to lay out an mapping exchange done log item. */ struct xfs_xmd_log_format {
libxfs/xfs_trans_space.h +4 -0
@@ -10,6 +10,10 @@* Components of space reservations. */ +/* Worst case number of bmaps that can be held in a block. */ +#define XFS_MAX_CONTIG_BMAPS_PER_BLOCK (mp) \ + (((mp)->m_bmap_dmxr[0]) - ((mp)->m_bmap_dmnr[0])) +/* Worst case number of rmaps that can be held in a block. */ #define XFS_MAX_CONTIG_RMAPS_PER_BLOCK (mp) \ (((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0]))
PATCH 7/115 xfs: add error injection to test file mapping exchange recovery
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 5fd022ec7d420dfca1eaaf997923a5d4dd0dcf62
Add an errortag so that we can test recovery of exchmaps log items.
--- io/inject.c | 1 + libxfs/xfs_errortag.h | 4 +++- libxfs/xfs_exchmaps.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-)
io/inject.c +1 -0
@@ -63,6 +63,7 @@ error_tag(char *name) { XFS_ERRTAG_ATTR_LEAF_TO_NODE, "attr_leaf_to_node" }, { XFS_ERRTAG_WB_DELAY_MS, "wb_delay_ms" }, { XFS_ERRTAG_WRITE_DELAY_MS, "write_delay_ms" }, + { XFS_ERRTAG_EXCHMAPS_FINISH_ONE, "exchmaps_finish_one" }, { XFS_ERRTAG_MAX, NULL } };int count;
libxfs/xfs_errortag.h +3 -1
@@ -63,7 +63,8 @@#define XFS_ERRTAG_ATTR_LEAF_TO_NODE 41#define XFS_ERRTAG_WB_DELAY_MS 42#define XFS_ERRTAG_WRITE_DELAY_MS 43 -#define XFS_ERRTAG_MAX 44 +#define XFS_ERRTAG_EXCHMAPS_FINISH_ONE 44 +#define XFS_ERRTAG_MAX 45/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -111,5 +112,6 @@#define XFS_RANDOM_ATTR_LEAF_TO_NODE 1#define XFS_RANDOM_WB_DELAY_MS 3000#define XFS_RANDOM_WRITE_DELAY_MS 3000 +#define XFS_RANDOM_EXCHMAPS_FINISH_ONE 1#endif /* __XFS_ERRORTAG_H_ */
libxfs/xfs_exchmaps.c +3 -0
@@ -434,6 +434,9 @@ xfs_exchmaps_finish_one(return error; } +if (XFS_TEST_ERROR (false, tp->t_mountp,XFS_ERRTAG_EXCHMAPS_FINISH_ONE )) +return -EIO ; +/* If we still have work to do, ask for a new transaction. */ if (xmi_has_more_exchange_work (xmi) ||xmi_has_postop_work (xmi)) {trace_xfs_exchmaps_defer (tp->t_mountp, xmi);
PATCH 8/115 xfs: condense extended attributes after a mapping exchange operation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 497d7a2608f8b7329e92bdaaf745ca127a582ad9
Add a new file mapping exchange flag that enables us to perform post-exchange processing on file2 once we're done exchanging the extent mappings. If we were swapping mappings between extended attribute forks, we want to be able to convert file2's attr fork from block to inline format.
(This implies that all fork contents are exchanged.)
This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online xattr repair feature can create salvaged attrs in a temporary file and exchange the attr fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed file's attr fork back down to inline format if possible.
--- libxfs/xfs_exchmaps.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- libxfs/xfs_exchmaps.h | 5 +++++ 2 files changed, 56 insertions(+), 2 deletions(-)
libxfs/xfs_exchmaps.c +51 -2
@@ -21,6 +21,10 @@#include "xfs_errortag.h" #include "xfs_health.h" #include "defer_item.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_attr_leaf.h" +#include "xfs_attr.h" struct kmem_cache *xfs_exchmaps_intent_cache;
@@ -118,7 +122,8 @@ static inline bool xmi_has_postop_work(const struct xfs_exchmaps_intent *xmi) {return xmi->xmi_flags & (XFS_EXCHMAPS_CLEAR_INO1_REFLINK | -XFS_EXCHMAPS_CLEAR_INO2_REFLINK ); +XFS_EXCHMAPS_CLEAR_INO2_REFLINK | + __XFS_EXCHMAPS_INO2_SHORTFORM); }/* Check all mappings to make sure we can actually exchange them. */
@@ -357,6 +362,36 @@ xfs_exchmaps_one_step(xmi_advance (xmi, irec1); } +/* Convert inode2's leaf attr fork back to shortform, if possible.. */ +STATIC int +xfs_exchmaps_attr_to_sf ( +struct xfs_trans *tp, +struct xfs_exchmaps_intent *xmi) +{ +struct xfs_da_args args = { + .dp = xmi->xmi_ip2, + .geo = tp->t_mountp->m_attr_geo, + .whichfork =XFS_ATTR_FORK , + .trans = tp, + }; +struct xfs_buf *bp; +int forkoff; +int error; + +if (!xfs_attr_is_leaf (xmi->xmi_ip2)) +return 0 ; + + error =xfs_attr3_leaf_read (tp, xmi->xmi_ip2,0 , &bp); +if (error) +return error; + + forkoff =xfs_attr_shortform_allfit (bp, xmi->xmi_ip2); +if (forkoff ==0 ) +return 0 ; + +return xfs_attr3_leaf_to_shortform (bp, &args, forkoff); +} +/* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink(
@@ -375,6 +410,16 @@ xfs_exchmaps_do_postop_work( struct xfs_trans *tp, struct xfs_exchmaps_intent *xmi) { +if (xmi->xmi_flags & __XFS_EXCHMAPS_INO2_SHORTFORM) { +int error =0 ; + +if (xmi->xmi_flags &XFS_EXCHMAPS_ATTR_FORK ) + error =xfs_exchmaps_attr_to_sf (tp, xmi); + xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM; +if (error) +return error; + } +if (xmi->xmi_flags &XFS_EXCHMAPS_CLEAR_INO1_REFLINK ) {xfs_exchmaps_clear_reflink (tp, xmi->xmi_ip1); xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO1_REFLINK ;
@@ -806,8 +851,10 @@ xfs_exchmaps_init_intent( xmi->xmi_isize1 = xmi->xmi_isize2 =-1 ; xmi->xmi_flags = req->flags &XFS_EXCHMAPS_PARAMS ; -if (xfs_exchmaps_whichfork (xmi) ==XFS_ATTR_FORK ) +if (xfs_exchmaps_whichfork (xmi) ==XFS_ATTR_FORK ) { + xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM;return xmi; + }if (req->flags &XFS_EXCHMAPS_SET_SIZES ) { xmi->xmi_flags |=XFS_EXCHMAPS_SET_SIZES ;
@@ -1028,6 +1075,8 @@ xfs_exchange_mappings( {struct xfs_exchmaps_intent *xmi; +BUILD_BUG_ON (XFS_EXCHMAPS_INTERNAL_FLAGS &XFS_EXCHMAPS_LOGGED_FLAGS ); +xfs_assert_ilocked (req->ip1,XFS_ILOCK_EXCL );xfs_assert_ilocked (req->ip2,XFS_ILOCK_EXCL );ASSERT (!(req->flags & ~XFS_EXCHMAPS_LOGGED_FLAGS ));
libxfs/xfs_exchmaps.h +5 -0
@@ -27,6 +27,11 @@ struct xfs_exchmaps_intent {uint64_t xmi_flags;/* XFS_EXCHMAPS_* flags */ }; +/* Try to convert inode2 from block to short format at the end, if possible. */ +#define __XFS_EXCHMAPS_INO2_SHORTFORM (1ULL << 63) + +#define XFS_EXCHMAPS_INTERNAL_FLAGS (__XFS_EXCHMAPS_INO2_SHORTFORM) +/* flags that can be passed to xfs_exchmaps_{estimate,mappings} */ #define XFS_EXCHMAPS_PARAMS (XFS_EXCHMAPS_ATTR_FORK | \ XFS_EXCHMAPS_SET_SIZES | \
PATCH 9/115 xfs: condense directories after a mapping exchange operation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: da165fbde23b84591b6ccdf6749277d2d767b770
The previous commit added a new file mapping exchange flag that enables us to perform post-swap processing on file2 once we're done exchanging extent mappings. Now add this ability for directories.
This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online directory repair feature can create salvaged dirents in a temporary directory and exchange the data fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed directory down to inline format if possible.
--- libxfs/xfs_exchmaps.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
libxfs/xfs_exchmaps.c +43 -0
@@ -25,6 +25,8 @@#include "xfs_da_btree.h" #include "xfs_attr_leaf.h" #include "xfs_attr.h" +#include "xfs_dir2_priv.h" +#include "xfs_dir2.h" struct kmem_cache *xfs_exchmaps_intent_cache;
@@ -392,6 +394,42 @@ xfs_exchmaps_attr_to_sf(return xfs_attr3_leaf_to_shortform (bp, &args, forkoff); } +/* Convert inode2's block dir fork back to shortform, if possible.. */ +STATIC int +xfs_exchmaps_dir_to_sf ( +struct xfs_trans *tp, +struct xfs_exchmaps_intent *xmi) +{ +struct xfs_da_args args = { + .dp = xmi->xmi_ip2, + .geo = tp->t_mountp->m_dir_geo, + .whichfork =XFS_DATA_FORK , + .trans = tp, + }; +struct xfs_dir2_sf_hdr sfh; +struct xfs_buf *bp; +bool isblock; +int size; +int error; + + error =xfs_dir2_isblock (&args, &isblock); +if (error) +return error; + +if (!isblock) +return 0 ; + + error =xfs_dir3_block_read (tp, xmi->xmi_ip2, &bp); +if (error) +return error; + + size =xfs_dir2_block_sfsize (xmi->xmi_ip2, bp->b_addr, &sfh); +if (size >xfs_inode_data_fork_size (xmi->xmi_ip2)) +return 0 ; + +return xfs_dir2_block_to_sf (&args, bp, size, &sfh); +} +/* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink(
@@ -415,6 +453,8 @@ xfs_exchmaps_do_postop_work(if (xmi->xmi_flags &XFS_EXCHMAPS_ATTR_FORK ) error =xfs_exchmaps_attr_to_sf (tp, xmi); +else if (S_ISDIR (VFS_I (xmi->xmi_ip2)->i_mode)) + error =xfs_exchmaps_dir_to_sf (tp, xmi); xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM;if (error)return error;
@@ -879,6 +919,9 @@ xfs_exchmaps_init_intent( xmi->xmi_flags |=XFS_EXCHMAPS_CLEAR_INO2_REFLINK ; } +if (S_ISDIR (VFS_I (xmi->xmi_ip2)->i_mode)) + xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM; +return xmi; }
PATCH 10/115 xfs: condense symbolic links after a mapping exchange operation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 33a9be2b7016e79f47c4c1b523a0aa59d41893c0
The previous commit added a new file mapping exchange flag that enables us to perform post-exchange processing on file2 once we're done exchanging the extent mappings. Now add this ability for symlinks.
This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online symlink repair feature can salvage the remote target in a temporary link and exchange the data fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed symlink down to inline format if possible.
--- libxfs/xfs_exchmaps.c | 49 ++++++++++++++++++++++++++++++++++++++++++- libxfs/xfs_symlink_remote.c | 47 +++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_symlink_remote.h | 1 + 3 files changed, 96 insertions(+), 1 deletion(-)
libxfs/xfs_exchmaps.c +48 -1
@@ -27,6 +27,7 @@#include "xfs_attr.h" #include "xfs_dir2_priv.h" #include "xfs_dir2.h" +#include "xfs_symlink_remote.h" struct kmem_cache *xfs_exchmaps_intent_cache;
@@ -430,6 +431,49 @@ xfs_exchmaps_dir_to_sf(return xfs_dir2_block_to_sf (&args, bp, size, &sfh); } +/* Convert inode2's remote symlink target back to shortform, if possible. */ +STATIC int +xfs_exchmaps_link_to_sf ( +struct xfs_trans *tp, +struct xfs_exchmaps_intent *xmi) +{ +struct xfs_inode *ip = xmi->xmi_ip2; +struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); +char *buf; +int error; + +if (ifp->if_format ==XFS_DINODE_FMT_LOCAL || + ip->i_disk_size >xfs_inode_data_fork_size (ip)) +return 0 ; + +/* Read the current symlink target into a buffer. */ + buf =kmalloc (ip->i_disk_size +1 , +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); +if (!buf) { +ASSERT (0 ); +return -ENOMEM ; + } + + error =xfs_symlink_remote_read (ip, buf); +if (error) + goto free; + +/* Remove the blocks. */ + error =xfs_symlink_remote_truncate (tp, ip); +if (error) + goto free; + +/* Convert fork to local format and log our changes. */ +xfs_idestroy_fork (ifp); + ifp->if_bytes =0 ; + ifp->if_format =XFS_DINODE_FMT_LOCAL ; +xfs_init_local_fork (ip,XFS_DATA_FORK , buf, ip->i_disk_size); +xfs_trans_log_inode (tp, ip,XFS_ILOG_DDATA |XFS_ILOG_CORE ); +free: +kfree (buf); +return error; +} +/* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink(
@@ -455,6 +499,8 @@ xfs_exchmaps_do_postop_work( error =xfs_exchmaps_attr_to_sf (tp, xmi); else if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode)) error =xfs_exchmaps_dir_to_sf (tp, xmi); + else if (S_ISLNK(VFS_I(xmi->xmi_ip2)->i_mode)) + error =xfs_exchmaps_link_to_sf (tp, xmi); xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM;if (error)return error;
@@ -919,7 +965,8 @@ xfs_exchmaps_init_intent( xmi->xmi_flags |=XFS_EXCHMAPS_CLEAR_INO2_REFLINK ; } -if (S_ISDIR (VFS_I (xmi->xmi_ip2)->i_mode)) +if (S_ISDIR (VFS_I (xmi->xmi_ip2)->i_mode) || +S_ISLNK (VFS_I (xmi->xmi_ip2)->i_mode)) xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM;return xmi;
libxfs/xfs_symlink_remote.c +47 -0
50 lines not on this page · raw message
libxfs/xfs_symlink_remote.h +1 -0
@@ -22,5 +22,6 @@ int xfs_symlink_remote_read(struct xfs_inode *ip, char *link);int xfs_symlink_write_target (struct xfs_trans *tp,struct xfs_inode *ip,const char *target_path,int pathlen,xfs_fsblock_t fs_blocks,uint resblks); +int xfs_symlink_remote_truncate (struct xfs_trans *tp,struct xfs_inode *ip);#endif /* __XFS_SYMLINK_REMOTE_H */
PATCH 11/115 xfs: make file range exchange support realtime files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: e62941103faa2eedba6a155316e059a490c743a6
Now that bmap items support the realtime device, we can add the necessary pieces to the file range exchange code to support exchanging mappings. All we really need to do here is adjust the blockcount upwards to the end of the rt extent and remove the inode checks.
--- include/xfs_inode.h | 10 +++++++ libxfs/xfs_exchmaps.c | 70 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 10 deletions(-)
include/xfs_inode.h +10 -0
@@ -325,6 +325,16 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)return ip->i_diflags2 &XFS_DIFLAG2_NREXT64 ; } + +/* +* Decide if this file is a realtime file whose data allocation unit is larger +* than a single filesystem block. +*/ +static inline bool xfs_inode_has_bigrtalloc (struct xfs_inode *ip) +{ +return XFS_IS_REALTIME_INODE (ip) && ip->i_mount->m_sb.sb_rextsize >1 ; +} +/* Always set the child's GID to this value, even if the parent is setgid. */ #define CRED_FORCE_GID (1U << 0)struct cred {
libxfs/xfs_exchmaps.c +60 -10
89 lines not on this page · raw message
PATCH 12/115 xfs: capture inode generation numbers in the ondisk exchmaps log item
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 14f19991020b3c712d626727c17599f134cc6efa
Per some very late review comments, capture the generation numbers of both inodes involved in a file content exchange operation so that we don't accidentally target files with have been reallocated.
--- libxfs/xfs_log_format.h | 2 ++ 1 file changed, 2 insertions(+)
libxfs/xfs_log_format.h +2 -0
@@ -896,6 +896,8 @@ struct xfs_xmi_log_format {uint64_t xmi_inode1;/* inumber of first file */ uint64_t xmi_inode2;/* inumber of second file */ +uint32_t xmi_igen1;/* generation of first file */ +uint32_t xmi_igen2;/* generation of second file */ uint64_t xmi_startoff1;/* block offset into file1 */ uint64_t xmi_startoff2;/* block offset into file2 */ uint64_t xmi_blockcount;/* number of blocks */
PATCH 13/115 xfs: enable logged file mapping exchange feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 0730e8d8ba1d1507f1d7fd719e1f835ce69961fe
Add the XFS_SB_FEAT_INCOMPAT_EXCHRANGE feature to the set of features that we will permit when mounting a filesystem. This turns on support for the file range exchange feature.
--- libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_format.h +2 -1
@@ -380,7 +380,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_META_UUID | \ XFS_SB_FEAT_INCOMPAT_BIGTIME | \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ - XFS_SB_FEAT_INCOMPAT_NREXT64) + XFS_SB_FEAT_INCOMPAT_NREXT64 | \ + XFS_SB_FEAT_INCOMPAT_EXCHRANGE)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
PATCH 14/115 xfs: add an explicit owner field to xfs_da_args
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 9eef772f3a194f6841850e45dacdf4207ec7da84
Add an explicit owner field to xfs_da_args, which will make it easier for online fsck to set the owner field of the temporary directory and xattr structures that it builds to repair damaged metadata.
Note: I hopefully found all the xfs_da_args definitions by looking for automatic stack variable declarations and xfs_da_args.dp assignments:
git grep -E '(args.*dp =|struct xfs_da_args[[:space:]]*[a-z0-9][a-z0-9]*)'
Note that callers of xfs_attr_{get,set,change} can set the owner to zero (or leave it unset) to have the default set to args->dp.
--- libxfs/xfs_attr.c | 4 ++++ libxfs/xfs_attr_leaf.c | 2 ++ libxfs/xfs_bmap.c | 1 + libxfs/xfs_da_btree.h | 1 + libxfs/xfs_dir2.c | 5 +++++ libxfs/xfs_exchmaps.c | 2 ++ 6 files changed, 15 insertions(+)
libxfs/xfs_attr.c +4 -0
@@ -262,6 +262,8 @@ xfs_attr_get(if (xfs_is_shutdown (args->dp->i_mount))return -EIO ; +if (!args->owner) + args->owner = args->dp->i_ino; args->geo = args->dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->hashval =xfs_da_hashname (args->name, args->namelen);
@@ -935,6 +937,8 @@ xfs_attr_set(if (error)return error; +if (!args->owner) + args->owner = args->dp->i_ino; args->geo = mp->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->hashval =xfs_da_hashname (args->name, args->namelen);
libxfs/xfs_attr_leaf.c +2 -0
@@ -901,6 +901,7 @@ xfs_attr_shortform_to_leaf( nargs.whichfork =XFS_ATTR_FORK ; nargs.trans = args->trans; nargs.op_flags =XFS_DA_OP_OKNOENT ; + nargs.owner = args->owner; sfe =xfs_attr_sf_firstentry (sf);for (i =0 ; i < sf->count; i++) {
@@ -1103,6 +1104,7 @@ xfs_attr3_leaf_to_shortform( nargs.whichfork =XFS_ATTR_FORK ; nargs.trans = args->trans; nargs.op_flags =XFS_DA_OP_OKNOENT ; + nargs.owner = args->owner;for (i =0 ; i < ichdr.count; entry++, i++) {if (entry->flags &XFS_ATTR_INCOMPLETE )
libxfs/xfs_bmap.c +1 -0
@@ -970,6 +970,7 @@ xfs_bmap_add_attrfork_local( dargs.total = dargs.geo->fsbcount; dargs.whichfork =XFS_DATA_FORK ; dargs.trans = tp; + dargs.owner = ip->i_ino;return xfs_dir2_sf_to_block (&dargs); }
libxfs/xfs_da_btree.h +1 -0
@@ -79,6 +79,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ uint32_t op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +xfs_ino_t owner;/* inode that owns the dir/attr data */ } xfs_da_args_t;/*
libxfs/xfs_dir2.c +5 -0
@@ -249,6 +249,7 @@ xfs_dir_init( args->geo = dp->i_mount->m_dir_geo; args->dp = dp; args->trans = tp; + args->owner = dp->i_ino; error =xfs_dir2_sf_create (args, pdp->i_ino);kfree (args);return error;
@@ -294,6 +295,7 @@ xfs_dir_createname( args->whichfork =XFS_DATA_FORK ; args->trans = tp; args->op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ; + args->owner = dp->i_ino;if (!inum) args->op_flags |=XFS_DA_OP_JUSTCHECK ;
@@ -382,6 +384,7 @@ xfs_dir_lookup( args->whichfork =XFS_DATA_FORK ; args->trans = tp; args->op_flags =XFS_DA_OP_OKNOENT ; + args->owner = dp->i_ino;if (ci_name) args->op_flags |=XFS_DA_OP_CILOOKUP ;
@@ -455,6 +458,7 @@ xfs_dir_removename( args->total = total; args->whichfork =XFS_DATA_FORK ; args->trans = tp; + args->owner = dp->i_ino;if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { rval =xfs_dir2_sf_removename (args);
@@ -516,6 +520,7 @@ xfs_dir_replace( args->total = total; args->whichfork =XFS_DATA_FORK ; args->trans = tp; + args->owner = dp->i_ino;if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { rval =xfs_dir2_sf_replace (args);
libxfs/xfs_exchmaps.c +2 -0
@@ -426,6 +426,7 @@ xfs_exchmaps_attr_to_sf( .geo = tp->t_mountp->m_attr_geo, .whichfork = XFS_ATTR_FORK, .trans = tp, + .owner = xmi->xmi_ip2->i_ino, };struct xfs_buf *bp;int forkoff;
@@ -456,6 +457,7 @@ xfs_exchmaps_dir_to_sf( .geo = tp->t_mountp->m_dir_geo, .whichfork = XFS_DATA_FORK, .trans = tp, + .owner = xmi->xmi_ip2->i_ino, };struct xfs_dir2_sf_hdr sfh;struct xfs_buf *bp;
PATCH 15/115 xfs: use the xfs_da_args owner field to set new dir/attr block owner
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 17a85dc64ae0804d33a2293686fc987a830a462d
When we're creating leaf, data, freespace, or dabtree blocks for directories and xattrs, use the explicit owner field (instead of the xfs_inode) to set the owner field. This will enable online repair to construct replacement data structures in a temporary file without having to change the owner fields prior to swapping the new and old structures.
--- libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_attr_remote.c | 4 ++-- libxfs/xfs_da_btree.c | 2 +- libxfs/xfs_dir2_block.c | 19 ++++++++++--------- libxfs/xfs_dir2_data.c | 2 +- libxfs/xfs_dir2_leaf.c | 11 +++++------ libxfs/xfs_dir2_node.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-)
libxfs/xfs_attr_leaf.c +1 -1
@@ -1236,7 +1236,7 @@ xfs_attr3_leaf_create( ichdr.magic =XFS_ATTR3_LEAF_MAGIC ; hdr3->blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - hdr3->owner =cpu_to_be64 (dp->i_ino); + hdr3->owner =cpu_to_be64 (args->owner);uuid_copy (&hdr3->uuid, &mp->m_sb.sb_meta_uuid); ichdr.freemap[0 ].base =sizeof (struct xfs_attr3_leaf_hdr );
libxfs/xfs_attr_remote.c +2 -2
@@ -521,8 +521,8 @@ xfs_attr_rmtval_set_value(return error; bp->b_ops = &xfs_attr3_rmt_buf_ops; -xfs_attr_rmtval_copyin (mp, bp, args->dp->i_ino, &offset, - &valuelen, &src); +xfs_attr_rmtval_copyin (mp, bp, args->owner, &offset, &valuelen, + &src); error =xfs_bwrite (bp);/* GROT: NOTE: synchronous write */ xfs_buf_relse (bp);
libxfs/xfs_da_btree.c +1 -1
@@ -482,7 +482,7 @@ xfs_da3_node_create(memset (hdr3,0 ,sizeof (struct xfs_da3_node_hdr )); ichdr.magic =XFS_DA3_NODE_MAGIC ; hdr3->info.blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - hdr3->info.owner =cpu_to_be64 (args->dp->i_ino); + hdr3->info.owner =cpu_to_be64 (args->owner);uuid_copy (&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid); }else { ichdr.magic =XFS_DA_NODE_MAGIC ;
libxfs/xfs_dir2_block.c +10 -9
@@ -160,12 +160,13 @@ xfs_dir3_block_read(static void xfs_dir3_block_init ( -struct xfs_mount *mp, -struct xfs_trans *tp, -struct xfs_buf *bp, -struct xfs_inode *dp) +struct xfs_da_args *args, +struct xfs_buf *bp) { -struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; +struct xfs_trans *tp = args->trans; +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; bp->b_ops = &xfs_dir3_block_buf_ops;xfs_trans_buf_set_type (tp, bp,XFS_BLFT_DIR_BLOCK_BUF );
@@ -174,7 +175,7 @@ xfs_dir3_block_init(memset (hdr3,0 ,sizeof (*hdr3)); hdr3->magic =cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC ); hdr3->blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - hdr3->owner =cpu_to_be64 (dp->i_ino); + hdr3->owner =cpu_to_be64 (args->owner);uuid_copy (&hdr3->uuid, &mp->m_sb.sb_meta_uuid);return ;
@@ -1006,7 +1007,7 @@ xfs_dir2_leaf_to_block(/* * Start converting it to block form. */ -xfs_dir3_block_init (mp, tp, dbp, dp); +xfs_dir3_block_init (args, dbp); needlog =1 ; needscan =0 ;
@@ -1126,7 +1127,7 @@ xfs_dir2_sf_to_block( error =xfs_dir3_data_init (args, blkno, &bp);if (error) goto out_free; -xfs_dir3_block_init (mp, tp, bp, dp); +xfs_dir3_block_init (args, bp); hdr = bp->b_addr;/*
@@ -1166,7 +1167,7 @@ xfs_dir2_sf_to_block(* Create entry for . */ dep = bp->b_addr + offset; - dep->inumber =cpu_to_be64 (dp->i_ino); + dep->inumber =cpu_to_be64 (args->owner); dep->namelen =1 ; dep->name[0 ] ='.' ;xfs_dir2_data_put_ftype (mp, dep,XFS_DIR3_FT_DIR );
libxfs/xfs_dir2_data.c +1 -1
@@ -722,7 +722,7 @@ xfs_dir3_data_init(memset (hdr3,0 ,sizeof (*hdr3)); hdr3->magic =cpu_to_be32 (XFS_DIR3_DATA_MAGIC ); hdr3->blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - hdr3->owner =cpu_to_be64 (dp->i_ino); + hdr3->owner =cpu_to_be64 (args->owner);uuid_copy (&hdr3->uuid, &mp->m_sb.sb_meta_uuid); }else
libxfs/xfs_dir2_leaf.c +5 -6
@@ -302,12 +302,12 @@ xfs_dir3_leafn_read(*/ static void xfs_dir3_leaf_init ( -struct xfs_mount *mp, -struct xfs_trans *tp, +struct xfs_da_args *args,struct xfs_buf *bp, -xfs_ino_t owner,uint16_t type) { +struct xfs_mount *mp = args->dp->i_mount; +struct xfs_trans *tp = args->trans;struct xfs_dir2_leaf *leaf = bp->b_addr;ASSERT (type ==XFS_DIR2_LEAF1_MAGIC || type ==XFS_DIR2_LEAFN_MAGIC );
@@ -321,7 +321,7 @@ xfs_dir3_leaf_init( ?cpu_to_be16 (XFS_DIR3_LEAF1_MAGIC ) :cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC ); leaf3->info.blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - leaf3->info.owner =cpu_to_be64 (owner); + leaf3->info.owner =cpu_to_be64 (args->owner);uuid_copy (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid); }else {memset (leaf,0 ,sizeof (*leaf));
@@ -354,7 +354,6 @@ xfs_dir3_leaf_get_buf( {struct xfs_inode *dp = args->dp;struct xfs_trans *tp = args->trans; -struct xfs_mount *mp = dp->i_mount;struct xfs_buf *bp;int error;
@@ -367,7 +366,7 @@ xfs_dir3_leaf_get_buf(if (error)return error; -xfs_dir3_leaf_init (mp, tp, bp, dp->i_ino, magic); +xfs_dir3_leaf_init (args, bp, magic);xfs_dir3_leaf_log_header (args, bp);if (magic ==XFS_DIR2_LEAF1_MAGIC )xfs_dir3_leaf_log_tail (args, bp);
libxfs/xfs_dir2_node.c +1 -1
@@ -346,7 +346,7 @@ xfs_dir3_free_get_buf( hdr.magic =XFS_DIR3_FREE_MAGIC ; hdr3->hdr.blkno =cpu_to_be64 (xfs_buf_daddr (bp)); - hdr3->hdr.owner =cpu_to_be64 (dp->i_ino); + hdr3->hdr.owner =cpu_to_be64 (args->owner);uuid_copy (&hdr3->hdr.uuid, &mp->m_sb.sb_meta_uuid); }else hdr.magic =XFS_DIR2_FREE_MAGIC ;
PATCH 16/115 xfs: validate attr leaf buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f4887fbc41dcb1560ec5da982ac7c6ad04b71de5
Create a leaf block header checking function to validate the owner field of xattr leaf blocks.
--- libxfs/xfs_attr.c | 10 ++++----- libxfs/xfs_attr_leaf.c | 56 ++++++++++++++++++++++++++++++++++++++++-------- libxfs/xfs_attr_leaf.h | 4 +++ libxfs/xfs_da_btree.c | 42 ++++++++++++++++++++++++++++++++++++ libxfs/xfs_da_btree.h | 1 + libxfs/xfs_exchmaps.c | 3 ++- 6 files changed, 100 insertions(+), 16 deletions(-)
libxfs/xfs_attr.c +5 -5
@@ -647,8 +647,8 @@ xfs_attr_leaf_remove_attr(int forkoff;int error; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, - &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->owner, + args->blkno, &bp);if (error)return error;
@@ -679,7 +679,7 @@ xfs_attr_leaf_shrink(if (!xfs_attr_is_leaf (dp))return 0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp,0 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->owner,0 , &bp);if (error)return error;
@@ -1156,7 +1156,7 @@ xfs_attr_leaf_try_add(struct xfs_buf *bp;int error; - error =xfs_attr3_leaf_read (args->trans, args->dp,0 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->owner,0 , &bp);if (error)return error;
@@ -1204,7 +1204,7 @@ xfs_attr_leaf_hasname( {int error =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp,0 , bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->owner,0 , bp);if (error)return error;
libxfs/xfs_attr_leaf.c +47 -9
112 lines not on this page · raw message
libxfs/xfs_attr_leaf.h +3 -1
@@ -98,12 +98,14 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp, struct xfs_buf *leaf2_bp);int xfs_attr_leaf_newentsize (struct xfs_da_args *args,int *local);int xfs_attr3_leaf_read (struct xfs_trans *tp,struct xfs_inode *dp, -xfs_dablk_t bno,struct xfs_buf **bpp); +xfs_ino_t owner,xfs_dablk_t bno,struct xfs_buf **bpp);void xfs_attr3_leaf_hdr_from_disk (struct xfs_da_geometry *geo,struct xfs_attr3_icleaf_hdr *to,struct xfs_attr_leafblock *from);void xfs_attr3_leaf_hdr_to_disk (struct xfs_da_geometry *geo,struct xfs_attr_leafblock *to,struct xfs_attr3_icleaf_hdr *from); +xfs_failaddr_t xfs_attr3_leaf_header_check (struct xfs_buf *bp, +xfs_ino_t owner);#endif /* __XFS_ATTR_LEAF_H__ */
libxfs/xfs_da_btree.c +42 -0
84 lines not on this page · raw message
libxfs/xfs_da_btree.h +1 -0
@@ -236,6 +236,7 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from);void xfs_da3_node_hdr_to_disk (struct xfs_mount *mp,struct xfs_da_intnode *to,struct xfs_da3_icnode_hdr *from); +xfs_failaddr_t xfs_da3_header_check (struct xfs_buf *bp,xfs_ino_t owner);extern struct kmem_cache *xfs_da_state_cache;
libxfs/xfs_exchmaps.c +2 -1
@@ -435,7 +435,8 @@ xfs_exchmaps_attr_to_sf(if (!xfs_attr_is_leaf (xmi->xmi_ip2))return 0 ; - error =xfs_attr3_leaf_read (tp, xmi->xmi_ip2,0 , &bp); + error =xfs_attr3_leaf_read (tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino,0 , + &bp);if (error)return error;
PATCH 17/115 xfs: validate attr remote value buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 8c25dc728bd1ca9344001aa6ef4556885572baa4
Check the owner field of xattr remote value blocks.
--- libxfs/xfs_attr_remote.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
libxfs/xfs_attr_remote.c +4 -5
@@ -279,12 +279,12 @@ xfs_attr_rmtval_copyout(struct xfs_mount *mp, struct xfs_buf *bp, struct xfs_inode *dp, + xfs_ino_t owner, int *offset, int *valuelen, uint8_t **dst) { char *src = bp->b_addr; -xfs_ino_t ino = dp->i_ino;xfs_daddr_t bno =xfs_buf_daddr (bp);int len =BBTOB (bp->b_length);int blksize = mp->m_attr_geo->blksize;
@@ -298,11 +298,11 @@ xfs_attr_rmtval_copyout( byte_cnt =min (*valuelen, byte_cnt);if (xfs_has_crc (mp)) { -if (xfs_attr3_rmt_hdr_ok (src, ino, *offset, +if (xfs_attr3_rmt_hdr_ok (src, owner, *offset, byte_cnt, bno)) {xfs_alert (mp,"remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)" , - bno, *offset, byte_cnt, ino); + bno, *offset, byte_cnt, owner);xfs_dirattr_mark_sick (dp,XFS_ATTR_FORK );return -EFSCORRUPTED ; }
@@ -426,8 +426,7 @@ xfs_attr_rmtval_get(return error; error =xfs_attr_rmtval_copyout (mp, bp, args->dp, - &offset, &valuelen, - &dst); + args->owner, &offset, &valuelen, &dst);xfs_buf_relse (bp);if (error)return error;
PATCH 18/115 xfs: validate dabtree node buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: d44bea9b41ca25f91fd9f25ed2cc3bb2f6dab4bc
Check the owner field of dabtree node blocks.
--- libxfs/xfs_da_btree.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_da_btree.h | 1 2 files changed, 110 insertions(+)
libxfs/xfs_da_btree.c +109 -0
@@ -248,6 +248,26 @@ xfs_da3_node_verify(return NULL ; } +xfs_failaddr_t +xfs_da3_node_header_check ( +struct xfs_buf *bp, +xfs_ino_t owner) +{ +struct xfs_mount *mp = bp->b_mount; + +if (xfs_has_crc (mp)) { +struct xfs_da3_blkinfo *hdr3 = bp->b_addr; + +if (hdr3->hdr.magic !=cpu_to_be16 (XFS_DA3_NODE_MAGIC )) +return __this_address; + +if (be64_to_cpu (hdr3->owner) != owner) +return __this_address; + } + +return NULL ; +} + xfs_failaddr_t xfs_da3_header_check( struct xfs_buf *bp,
@@ -262,6 +282,8 @@ xfs_da3_header_check(switch (hdr->magic) {case cpu_to_be16 (XFS_ATTR3_LEAF_MAGIC ):return xfs_attr3_leaf_header_check (bp, owner); +case cpu_to_be16 (XFS_DA3_NODE_MAGIC ): +return xfs_da3_node_header_check (bp, owner); }return NULL ;
@@ -1214,6 +1236,7 @@ xfs_da3_root_join(struct xfs_da3_icnode_hdr oldroothdr;int error;struct xfs_inode *dp = state->args->dp; +xfs_failaddr_t fa;trace_xfs_da_root_join (state->args);
@@ -1240,6 +1263,13 @@ xfs_da3_root_join( error =xfs_da3_node_read (args->trans, dp, child, &bp, args->whichfork);if (error)return error; + fa =xfs_da3_header_check (bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (args->trans, bp); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + }xfs_da_blkinfo_onlychild_validate (bp->b_addr, oldroothdr.level);/*
@@ -1274,6 +1304,7 @@ xfs_da3_node_toosmall(struct xfs_da_blkinfo *info;xfs_dablk_t blkno;struct xfs_buf *bp; +xfs_failaddr_t fa;struct xfs_da3_icnode_hdr nodehdr;int count;int forward;
@@ -1348,6 +1379,13 @@ xfs_da3_node_toosmall( state->args->whichfork);if (error)return error; + fa =xfs_da3_node_header_check (bp, state->args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (state->args->trans, bp); +xfs_da_mark_sick (state->args); +return -EFSCORRUPTED ; + } node = bp->b_addr;xfs_da3_node_hdr_from_disk (dp->i_mount, &thdr, node);
@@ -1670,6 +1708,13 @@ xfs_da3_node_lookup_int(return -EFSCORRUPTED ; } + fa =xfs_da3_node_header_check (blk->bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (blk->bp, fa); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + } + blk->magic =XFS_DA_NODE_MAGIC ;/*
@@ -1842,6 +1887,7 @@ xfs_da3_blk_link(struct xfs_da_blkinfo *tmp_info;struct xfs_da_args *args;struct xfs_buf *bp; +xfs_failaddr_t fa;int before =0 ;int error;struct xfs_inode *dp = state->args->dp;
@@ -1885,6 +1931,13 @@ xfs_da3_blk_link( &bp, args->whichfork);if (error)return error; + fa =xfs_da3_header_check (bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (args->trans, bp); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + }ASSERT (bp !=NULL ); tmp_info = bp->b_addr;ASSERT (tmp_info->magic == old_info->magic);
@@ -1906,6 +1959,13 @@ xfs_da3_blk_link( &bp, args->whichfork);if (error)return error; + fa =xfs_da3_header_check (bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (args->trans, bp); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + }ASSERT (bp !=NULL ); tmp_info = bp->b_addr;ASSERT (tmp_info->magic == old_info->magic);
@@ -1935,6 +1995,7 @@ xfs_da3_blk_unlink(struct xfs_da_blkinfo *tmp_info;struct xfs_da_args *args;struct xfs_buf *bp; +xfs_failaddr_t fa;int error;/*
@@ -1965,6 +2026,13 @@ xfs_da3_blk_unlink( &bp, args->whichfork);if (error)return error; + fa =xfs_da3_header_check (bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (args->trans, bp); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + }ASSERT (bp !=NULL ); tmp_info = bp->b_addr;ASSERT (tmp_info->magic == save_info->magic);
@@ -1982,6 +2050,13 @@ xfs_da3_blk_unlink( &bp, args->whichfork);if (error)return error; + fa =xfs_da3_header_check (bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (bp, fa); +xfs_trans_brelse (args->trans, bp); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + }ASSERT (bp !=NULL ); tmp_info = bp->b_addr;ASSERT (tmp_info->magic == save_info->magic);
@@ -2097,6 +2172,12 @@ xfs_da3_path_shift(switch (be16_to_cpu (info->magic)) {case XFS_DA_NODE_MAGIC :case XFS_DA3_NODE_MAGIC : + fa =xfs_da3_node_header_check (blk->bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (blk->bp, fa); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + } blk->magic =XFS_DA_NODE_MAGIC ;xfs_da3_node_hdr_from_disk (dp->i_mount, &nodehdr, bp->b_addr);
@@ -2402,6 +2483,13 @@ xfs_da3_swap_lastblock( error =xfs_da3_node_read (tp, dp, sib_blkno, &sib_buf, w);if (error) goto done; + fa =xfs_da3_header_check (sib_buf, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (sib_buf, fa); +xfs_da_mark_sick (args); + error = -EFSCORRUPTED ; + goto done; + } sib_info = sib_buf->b_addr; if (XFS_IS_CORRUPT(mp, be32_to_cpu(sib_info->forw) != last_blkno ||
@@ -2423,6 +2511,13 @@ xfs_da3_swap_lastblock( error =xfs_da3_node_read (tp, dp, sib_blkno, &sib_buf, w);if (error) goto done; + fa =xfs_da3_header_check (sib_buf, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (sib_buf, fa); +xfs_da_mark_sick (args); + error = -EFSCORRUPTED ; + goto done; + } sib_info = sib_buf->b_addr; if (XFS_IS_CORRUPT(mp, be32_to_cpu(sib_info->back) != last_blkno ||
@@ -2446,6 +2541,13 @@ xfs_da3_swap_lastblock( error =xfs_da3_node_read (tp, dp, par_blkno, &par_buf, w);if (error) goto done; + fa =xfs_da3_node_header_check (par_buf, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (par_buf, fa); +xfs_da_mark_sick (args); + error = -EFSCORRUPTED ; + goto done; + } par_node = par_buf->b_addr;xfs_da3_node_hdr_from_disk (dp->i_mount, &par_hdr, par_node); if (XFS_IS_CORRUPT(mp,
@@ -2495,6 +2597,13 @@ xfs_da3_swap_lastblock( error =xfs_da3_node_read (tp, dp, par_blkno, &par_buf, w);if (error) goto done; + fa =xfs_da3_node_header_check (par_buf, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (par_buf, fa); +xfs_da_mark_sick (args); + error = -EFSCORRUPTED ; + goto done; + } par_node = par_buf->b_addr;xfs_da3_node_hdr_from_disk (dp->i_mount, &par_hdr, par_node);if (XFS_IS_CORRUPT (mp, par_hdr.level != level)) {
libxfs/xfs_da_btree.h +1 -0
@@ -237,6 +237,7 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp,void xfs_da3_node_hdr_to_disk (struct xfs_mount *mp,struct xfs_da_intnode *to,struct xfs_da3_icnode_hdr *from);xfs_failaddr_t xfs_da3_header_check (struct xfs_buf *bp,xfs_ino_t owner); +xfs_failaddr_t xfs_da3_node_header_check (struct xfs_buf *bp,xfs_ino_t owner);extern struct kmem_cache *xfs_da_state_cache;
PATCH 19/115 xfs: validate directory leaf buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 402eef10a1bab0b428c418cfbaaa0a62efc9c951
Check the owner field of directory leaf blocks.
--- libxfs/xfs_da_btree.c | 16 ++++++++++++ libxfs/xfs_dir2.h | 2 + libxfs/xfs_dir2_leaf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++---- libxfs/xfs_dir2_node.c | 3 +- libxfs/xfs_dir2_priv.h | 4 +-- 5 files changed, 81 insertions(+), 9 deletions(-)
libxfs/xfs_da_btree.c +16 -0
@@ -284,8 +284,12 @@ xfs_da3_header_check(return xfs_attr3_leaf_header_check (bp, owner);case cpu_to_be16 (XFS_DA3_NODE_MAGIC ):return xfs_da3_node_header_check (bp, owner); +case cpu_to_be16 (XFS_DIR3_LEAF1_MAGIC ): +case cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC ): +return xfs_dir3_leaf_header_check (bp, owner); } +ASSERT (0 );return NULL ; }
@@ -1696,6 +1700,12 @@ xfs_da3_node_lookup_int(if (magic ==XFS_DIR2_LEAFN_MAGIC || magic ==XFS_DIR3_LEAFN_MAGIC ) { + fa =xfs_dir3_leaf_header_check (blk->bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (blk->bp, fa); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + } blk->magic =XFS_DIR2_LEAFN_MAGIC ; blk->hashval =xfs_dir2_leaf_lasthash (args->dp, blk->bp,NULL );
@@ -2204,6 +2214,12 @@ xfs_da3_path_shift(break ;case XFS_DIR2_LEAFN_MAGIC :case XFS_DIR3_LEAFN_MAGIC : + fa =xfs_dir3_leaf_header_check (blk->bp, args->owner); +if (fa) { +__xfs_buf_mark_corrupt (blk->bp, fa); +xfs_da_mark_sick (args); +return -EFSCORRUPTED ; + } blk->magic =XFS_DIR2_LEAFN_MAGIC ;ASSERT (level == path->active-1 ); blk->index =0 ;
libxfs/xfs_dir2.h +2 -0
@@ -101,6 +101,8 @@ extern struct xfs_dir2_data_free *xfs_dir2_data_freefind(extern int xfs_dir_ino_validate (struct xfs_mount *mp,xfs_ino_t ino); +xfs_failaddr_t xfs_dir3_leaf_header_check (struct xfs_buf *bp,xfs_ino_t owner); +extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops;
libxfs/xfs_dir2_leaf.c +59 -6
111 lines not on this page · raw message
libxfs/xfs_dir2_node.c +2 -1
@@ -1559,7 +1559,8 @@ xfs_dir2_leafn_toosmall(/* * Read the sibling leaf block. */ - error =xfs_dir3_leafn_read (state->args->trans, dp, blkno, &bp); + error =xfs_dir3_leafn_read (state->args->trans, dp, + state->args->owner, blkno, &bp);if (error)return error;
libxfs/xfs_dir2_priv.h +2 -2
@@ -95,9 +95,9 @@ void xfs_dir2_leaf_hdr_from_disk(struct xfs_mount *mp,void xfs_dir2_leaf_hdr_to_disk (struct xfs_mount *mp,struct xfs_dir2_leaf *to,struct xfs_dir3_icleaf_hdr *from);int xfs_dir3_leaf_read (struct xfs_trans *tp,struct xfs_inode *dp, -xfs_dablk_t fbno,struct xfs_buf **bpp); +xfs_ino_t owner,xfs_dablk_t fbno,struct xfs_buf **bpp);int xfs_dir3_leafn_read (struct xfs_trans *tp,struct xfs_inode *dp, -xfs_dablk_t fbno,struct xfs_buf **bpp); +xfs_ino_t owner,xfs_dablk_t fbno,struct xfs_buf **bpp);extern int xfs_dir2_block_to_leaf (struct xfs_da_args *args,struct xfs_buf *dbp);extern int xfs_dir2_leaf_addname (struct xfs_da_args *args);
PATCH 20/115 xfs: validate explicit directory data buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: cc6740ddb423db2066f7669eaaa377fdbf84ab1e
Port the existing directory data header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible.
--- db/namei.c | 3 ++- libxfs/xfs_dir2.h | 1 + libxfs/xfs_dir2_block.c | 3 ++- libxfs/xfs_dir2_data.c | 16 ++++++++++------ libxfs/xfs_dir2_leaf.c | 21 +++++++++++---------- libxfs/xfs_dir2_node.c | 7 +++---- libxfs/xfs_dir2_priv.h | 3 ++- 7 files changed, 31 insertions(+), 23 deletions(-)
db/namei.c +2 -1
@@ -398,7 +398,8 @@ list_leafdir(libxfs_trim_extent (&map, dabno, geo->leafblk - dabno);/* Read the directory block of that first mapping. */ - error =xfs_dir3_data_read (NULL , dp, map.br_startoff,0 , &bp); + error =xfs_dir3_data_read (NULL , dp, args->owner, + map.br_startoff,0 , &bp);if (error)break ;
libxfs/xfs_dir2.h +1 -0
@@ -102,6 +102,7 @@ extern struct xfs_dir2_data_free *xfs_dir2_data_freefind(extern int xfs_dir_ino_validate (struct xfs_mount *mp,xfs_ino_t ino);xfs_failaddr_t xfs_dir3_leaf_header_check (struct xfs_buf *bp,xfs_ino_t owner); +xfs_failaddr_t xfs_dir3_data_header_check (struct xfs_buf *bp,xfs_ino_t owner);extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
libxfs/xfs_dir2_block.c +2 -1
@@ -979,7 +979,8 @@ xfs_dir2_leaf_to_block(* Read the data block if we don't already have it, give up if it fails. */ if (!dbp) { - error =xfs_dir3_data_read (tp, dp, args->geo->datablk,0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, + args->geo->datablk,0 , &dbp);if (error)return error; }
libxfs/xfs_dir2_data.c +10 -6
@@ -392,17 +392,20 @@ static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { .verify_write = xfs_dir3_data_write_verify, }; -static xfs_failaddr_t +xfs_failaddr_t xfs_dir3_data_header_check ( -struct xfs_inode *dp, -struct xfs_buf *bp) +struct xfs_buf *bp, +xfs_ino_t owner) { -struct xfs_mount *mp = dp->i_mount; +struct xfs_mount *mp = bp->b_mount;if (xfs_has_crc (mp)) {struct xfs_dir3_data_hdr *hdr3 = bp->b_addr; -if (be64_to_cpu (hdr3->hdr.owner) != dp->i_ino) +if (hdr3->hdr.magic !=cpu_to_be32 (XFS_DIR3_DATA_MAGIC )) +return __this_address; + +if (be64_to_cpu (hdr3->hdr.owner) != owner)return __this_address; }
@@ -413,6 +416,7 @@ intxfs_dir3_data_read ( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp)
@@ -426,7 +430,7 @@ xfs_dir3_data_read(return err;/* Check things that we can't do in the verifier. */ - fa =xfs_dir3_data_header_check (dp, *bpp); + fa =xfs_dir3_data_header_check (*bpp, owner);if (fa) {__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp);
libxfs/xfs_dir2_leaf.c +11 -10
@@ -883,9 +883,9 @@ xfs_dir2_leaf_addname(* Already had space in some data block. * Just read that one in. */ - error =xfs_dir3_data_read (tp, dp, -xfs_dir2_db_to_da (args->geo, use_block), -0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, +xfs_dir2_db_to_da (args->geo, use_block),0 , + &dbp);if (error) {xfs_trans_brelse (tp, lbp);return error;
@@ -1326,9 +1326,9 @@ xfs_dir2_leaf_lookup_int(if (newdb != curdb) {if (dbp)xfs_trans_brelse (tp, dbp); - error =xfs_dir3_data_read (tp, dp, -xfs_dir2_db_to_da (args->geo, newdb), -0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, +xfs_dir2_db_to_da (args->geo, newdb),0 , + &dbp);if (error) {xfs_trans_brelse (tp, lbp);return error;
@@ -1368,9 +1368,9 @@ xfs_dir2_leaf_lookup_int(ASSERT (cidb !=-1 );if (cidb != curdb) {xfs_trans_brelse (tp, dbp); - error =xfs_dir3_data_read (tp, dp, -xfs_dir2_db_to_da (args->geo, cidb), -0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, +xfs_dir2_db_to_da (args->geo, cidb),0 , + &dbp);if (error) {xfs_trans_brelse (tp, lbp);return error;
@@ -1664,7 +1664,8 @@ xfs_dir2_leaf_trim_data(/* * Read the offending data block. We need its buffer. */ - error =xfs_dir3_data_read (tp, dp,xfs_dir2_db_to_da (geo, db),0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, +xfs_dir2_db_to_da (geo, db),0 , &dbp);if (error)return error;
libxfs/xfs_dir2_node.c +3 -4
@@ -860,7 +860,7 @@ xfs_dir2_leafn_lookup_for_entry(ASSERT (state->extravalid); curbp = state->extrablk.bp; }else { - error =xfs_dir3_data_read (tp, dp, + error =xfs_dir3_data_read (tp, dp, args->owner,xfs_dir2_db_to_da (args->geo, newdb),0 , &curbp);
@@ -1946,9 +1946,8 @@ xfs_dir2_node_addname_int( &freehdr, &findex); }else {/* Read the data block in. */ - error =xfs_dir3_data_read (tp, dp, -xfs_dir2_db_to_da (args->geo, dbno), -0 , &dbp); + error =xfs_dir3_data_read (tp, dp, args->owner, +xfs_dir2_db_to_da (args->geo, dbno),0 , &dbp); }if (error)return error;
libxfs/xfs_dir2_priv.h +2 -1
@@ -78,7 +78,8 @@ extern void xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp);extern xfs_failaddr_t __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp);int xfs_dir3_data_read (struct xfs_trans *tp,struct xfs_inode *dp, -xfs_dablk_t bno,unsigned int flags,struct xfs_buf **bpp); +xfs_ino_t owner,xfs_dablk_t bno,unsigned int flags, +struct xfs_buf **bpp);int xfs_dir3_data_readahead (struct xfs_inode *dp,xfs_dablk_t bno,unsigned int flags);
PATCH 21/115 xfs: validate explicit directory block buffer owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 29b41ce919b7f0b0c2220e088e450d9b132bec36
Port the existing directory block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible.
--- db/namei.c | 2 +- libxfs/xfs_dir2.h | 1 + libxfs/xfs_dir2_block.c | 20 ++++++++++++-------- libxfs/xfs_dir2_priv.h | 4 ++-- libxfs/xfs_exchmaps.c | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-)
db/namei.c +1 -1
@@ -337,7 +337,7 @@ list_blockdir(unsigned int end;int error; - error =xfs_dir3_block_read (NULL , dp, &bp); + error =xfs_dir3_block_read (NULL , dp, args->owner, &bp);if (error)return error;
libxfs/xfs_dir2.h +1 -0
@@ -103,6 +103,7 @@ extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);xfs_failaddr_t xfs_dir3_leaf_header_check (struct xfs_buf *bp,xfs_ino_t owner);xfs_failaddr_t xfs_dir3_data_header_check (struct xfs_buf *bp,xfs_ino_t owner); +xfs_failaddr_t xfs_dir3_block_header_check (struct xfs_buf *bp,xfs_ino_t owner);extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
libxfs/xfs_dir2_block.c +12 -8
@@ -112,17 +112,20 @@ const struct xfs_buf_ops xfs_dir3_block_buf_ops = { .verify_struct = xfs_dir3_block_verify, }; -static xfs_failaddr_t +xfs_failaddr_t xfs_dir3_block_header_check ( -struct xfs_inode *dp, -struct xfs_buf *bp) +struct xfs_buf *bp, +xfs_ino_t owner) { -struct xfs_mount *mp = dp->i_mount; +struct xfs_mount *mp = bp->b_mount;if (xfs_has_crc (mp)) {struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; -if (be64_to_cpu (hdr3->owner) != dp->i_ino) +if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) +return __this_address; + +if (be64_to_cpu (hdr3->owner) != owner)return __this_address; }
@@ -133,6 +136,7 @@ intxfs_dir3_block_read ( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, struct xfs_buf **bpp) { struct xfs_mount *mp = dp->i_mount;
@@ -145,7 +149,7 @@ xfs_dir3_block_read(return err;/* Check things that we can't do in the verifier. */ - fa =xfs_dir3_block_header_check (dp, *bpp); + fa =xfs_dir3_block_header_check (*bpp, owner);if (fa) {__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp);
@@ -380,7 +384,7 @@ xfs_dir2_block_addname( tp = args->trans;/* Read the (one and only) directory block into bp. */ - error =xfs_dir3_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp, args->owner, &bp);if (error)return error;
@@ -695,7 +699,7 @@ xfs_dir2_block_lookup_int( dp = args->dp; tp = args->trans; - error =xfs_dir3_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp, args->owner, &bp);if (error)return error;
libxfs/xfs_dir2_priv.h +2 -2
@@ -50,8 +50,8 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args,/* xfs_dir2_block.c */ -extern int xfs_dir3_block_read (struct xfs_trans *tp,struct xfs_inode *dp, -struct xfs_buf **bpp); +int xfs_dir3_block_read (struct xfs_trans *tp,struct xfs_inode *dp, +xfs_ino_t owner,struct xfs_buf **bpp);extern int xfs_dir2_block_addname (struct xfs_da_args *args);extern int xfs_dir2_block_lookup (struct xfs_da_args *args);extern int xfs_dir2_block_removename (struct xfs_da_args *args);
libxfs/xfs_exchmaps.c +1 -1
@@ -473,7 +473,7 @@ xfs_exchmaps_dir_to_sf(if (!isblock)return 0 ; - error =xfs_dir3_block_read (tp, xmi->xmi_ip2, &bp); + error =xfs_dir3_block_read (tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, &bp);if (error)return error;
PATCH 22/115 xfs: validate explicit directory free block owners
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: fe6c9f8e48e0dcbfc3dba17edd88490c8579b34b
Port the existing directory freespace block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible.
--- libxfs/xfs_dir2_leaf.c | 3 ++- libxfs/xfs_dir2_node.c | 32 ++++++++++++++++++-------------- libxfs/xfs_dir2_priv.h | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-)
libxfs/xfs_dir2_leaf.c +2 -1
@@ -1804,7 +1804,8 @@ xfs_dir2_node_to_leaf(/* * Read the freespace block. */ - error =xfs_dir2_free_read (tp, dp, args->geo->freeblk, &fbp); + error =xfs_dir2_free_read (tp, dp, args->owner, args->geo->freeblk, + &fbp);if (error)return error;xfs_dir2_free_hdr_from_disk (mp, &freehdr, fbp->b_addr);
libxfs/xfs_dir2_node.c +18 -14
@@ -172,11 +172,11 @@ const struct xfs_buf_ops xfs_dir3_free_buf_ops = {/* Everything ok in the free block header? */ static xfs_failaddr_t xfs_dir3_free_header_check ( -struct xfs_inode *dp, -xfs_dablk_t fbno, -struct xfs_buf *bp) +struct xfs_buf *bp, +xfs_ino_t owner, +xfs_dablk_t fbno) { -struct xfs_mount *mp = dp->i_mount; +struct xfs_mount *mp = bp->b_mount;int maxbests = mp->m_dir_geo->free_max_bests;unsigned int firstdb;
@@ -192,7 +192,7 @@ xfs_dir3_free_header_check(return __this_address;if (be32_to_cpu (hdr3->nvalid) <be32_to_cpu (hdr3->nused))return __this_address; -if (be64_to_cpu (hdr3->hdr.owner) != dp->i_ino) +if (be64_to_cpu (hdr3->hdr.owner) != owner)return __this_address; }else {struct xfs_dir2_free_hdr *hdr = bp->b_addr;
@@ -211,6 +211,7 @@ static int__xfs_dir3_free_read ( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, unsigned int flags, struct xfs_buf **bpp)
@@ -224,7 +225,7 @@ __xfs_dir3_free_read(return err;/* Check things that we can't do in the verifier. */ - fa =xfs_dir3_free_header_check (dp, fbno, *bpp); + fa =xfs_dir3_free_header_check (*bpp, owner, fbno);if (fa) {__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp);
@@ -296,20 +297,23 @@ intxfs_dir2_free_read ( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, 0, bpp); + return __xfs_dir3_free_read(tp, dp, owner, fbno, 0, bpp); }static int xfs_dir2_free_try_read (struct xfs_trans *tp,struct xfs_inode *dp, +xfs_ino_t owner,xfs_dablk_t fbno,struct xfs_buf **bpp) { -return __xfs_dir3_free_read (tp, dp, fbno,XFS_DABUF_MAP_HOLE_OK , bpp); +return __xfs_dir3_free_read (tp, dp, owner, fbno,XFS_DABUF_MAP_HOLE_OK , + bpp); } static int
@@ -714,7 +718,7 @@ xfs_dir2_leafn_lookup_for_addname(if (curbp)xfs_trans_brelse (tp, curbp); - error =xfs_dir2_free_read (tp, dp, + error =xfs_dir2_free_read (tp, dp, args->owner,xfs_dir2_db_to_da (args->geo, newfdb), &curbp);
@@ -1353,8 +1357,8 @@ xfs_dir2_leafn_remove(* read in the free block. */ fdb =xfs_dir2_db_to_fdb (geo, db); - error =xfs_dir2_free_read (tp, dp,xfs_dir2_db_to_da (geo, fdb), - &fbp); + error =xfs_dir2_free_read (tp, dp, args->owner, +xfs_dir2_db_to_da (geo, fdb), &fbp);if (error)return error; free = fbp->b_addr;
@@ -1713,7 +1717,7 @@ xfs_dir2_node_add_datablk(* that was just allocated. */ fbno =xfs_dir2_db_to_fdb (args->geo, *dbno); - error =xfs_dir2_free_try_read (tp, dp, + error =xfs_dir2_free_try_read (tp, dp, args->owner,xfs_dir2_db_to_da (args->geo, fbno), &fbp);if (error)return error;
@@ -1860,7 +1864,7 @@ xfs_dir2_node_find_freeblk(* so this might not succeed. This should be really rare, so * there's no reason to avoid it. */ - error =xfs_dir2_free_try_read (tp, dp, + error =xfs_dir2_free_try_read (tp, dp, args->owner,xfs_dir2_db_to_da (args->geo, fbno), &fbp);if (error)
@@ -2299,7 +2303,7 @@ xfs_dir2_node_trim_free(/* * Read the freespace block. */ - error =xfs_dir2_free_try_read (tp, dp, fo, &bp); + error =xfs_dir2_free_try_read (tp, dp, args->owner, fo, &bp);if (error)return error;/*
libxfs/xfs_dir2_priv.h +2 -2
@@ -155,8 +155,8 @@ extern int xfs_dir2_node_removename(struct xfs_da_args *args);extern int xfs_dir2_node_replace (struct xfs_da_args *args);extern int xfs_dir2_node_trim_free (struct xfs_da_args *args,xfs_fileoff_t fo,int *rvalp); -extern int xfs_dir2_free_read (struct xfs_trans *tp,struct xfs_inode *dp, -xfs_dablk_t fbno,struct xfs_buf **bpp); +int xfs_dir2_free_read (struct xfs_trans *tp,struct xfs_inode *dp, +xfs_ino_t owner,xfs_dablk_t fbno,struct xfs_buf **bpp);/* xfs_dir2_sf.c */ xfs_ino_t xfs_dir2_sf_get_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
PATCH 23/115 xfs: use atomic extent swapping to fix user file fork data
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 629fdaf5f5b1b7f7107ed4de04e0991a99501ced
Build on the code that was recently added to the temporary repair file code so that we can atomically switch the contents of any file fork, even if the fork is in local format. The upcoming functions to repair xattrs, directories, and symlinks will need that capability.
Repair can lock out access to these user files by holding IOLOCK_EXCL on these user files. Therefore, it is safe to drop the ILOCK of both the file being repaired and the tempfile being used for staging, and cancel the scrub transaction. We do this so that we can reuse the resource estimation and transaction allocation functions used by a regular file exchange operation.
--- libxfs/xfs_exchmaps.c | 2 +- libxfs/xfs_exchmaps.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_exchmaps.c +1 -1
@@ -672,7 +672,7 @@ xfs_exchmaps_rmapbt_blocks( }/* Estimate the bmbt and rmapbt overhead required to exchange mappings. */ -static int +int xfs_exchmaps_estimate_overhead (struct xfs_exchmaps_req *req) {
libxfs/xfs_exchmaps.h +1 -0
@@ -97,6 +97,7 @@ xfs_exchmaps_reqfork(const struct xfs_exchmaps_req *req)return XFS_DATA_FORK ; } +int xfs_exchmaps_estimate_overhead (struct xfs_exchmaps_req *req);int xfs_exchmaps_estimate (struct xfs_exchmaps_req *req);extern struct kmem_cache *xfs_exchmaps_intent_cache;
PATCH 24/115 xfs: repair extended attributes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: e47dcf113ae348678143cc935a1183059c02c9ad
If the extended attributes look bad, try to sift through the rubble to find whatever keys/values we can, stage a new attribute structure in a temporary file and use the atomic extent swapping mechanism to commit the results in bulk.
--- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr.h | 2 ++ libxfs/xfs_da_format.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-)
libxfs/xfs_attr.c +1 -1
@@ -1053,7 +1053,7 @@ xfs_attr_set(* External routines when attribute list is inside the inode *========================================================================*/ -static inline int xfs_attr_sf_totsize (struct xfs_inode *dp) +int xfs_attr_sf_totsize (struct xfs_inode *dp) {struct xfs_attr_sf_hdr *sf = dp->i_af.if_data;
libxfs/xfs_attr.h +2 -0
@@ -618,4 +618,6 @@ extern struct kmem_cache *xfs_attr_intent_cache;int __init xfs_attr_intent_init_cache (void );void xfs_attr_intent_destroy_cache (void ); +int xfs_attr_sf_totsize (struct xfs_inode *dp); +#endif /* __XFS_ATTR_H__ */
libxfs/xfs_da_format.h +5 -0
@@ -721,6 +721,11 @@ struct xfs_attr3_leafblock {#define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT)#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NAMESPACE_STR \ + { XFS_ATTR_LOCAL, "local" }, \ + { XFS_ATTR_ROOT, "root" }, \ + { XFS_ATTR_SECURE, "secure" } +/* * Alignment for namelist and valuelist entries (since they are mixed * there can be only one alignment value)
PATCH 25/115 xfs: expose xfs_bmap_local_to_extents for online repair
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ef744be416b5c649d287604730400dfa728779fe
Allow online repair to call xfs_bmap_local_to_extents and add a void * argument at the end so that online repair can pass its own context.
--- libxfs/xfs_bmap.c | 11 ++++++----- libxfs/xfs_bmap.h | 6 ++++++ libxfs/xfs_symlink_remote.c | 3 ++- libxfs/xfs_symlink_remote.h | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-)
libxfs/xfs_bmap.c +6 -5
@@ -773,7 +773,7 @@ xfs_bmap_local_to_extents_empty( } -STATIC int /* error */ +int /* error */ xfs_bmap_local_to_extents( xfs_trans_t *tp, /* transaction pointer */ xfs_inode_t *ip, /* incore inode pointer */
@@ -783,7 +783,8 @@ xfs_bmap_local_to_extents(void (*init_fn)(struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_inode *ip, - struct xfs_ifork *ifp)) +struct xfs_ifork *ifp,void *priv), + void *priv) { int error = 0;int flags;/* logging flags returned */
@@ -844,7 +845,7 @@ xfs_bmap_local_to_extents(* log here. Note that init_fn must also set the buffer log item type * correctly. */ -init_fn (tp, bp, ip, ifp); +init_fn (tp, bp, ip, ifp, priv);/* account for the change in fork size */ xfs_idata_realloc (ip, -ifp->if_bytes, whichfork);
@@ -976,8 +977,8 @@ xfs_bmap_add_attrfork_local(if (S_ISLNK (VFS_I (ip)->i_mode))return xfs_bmap_local_to_extents (tp, ip,1 , flags, -XFS_DATA_FORK , - xfs_symlink_local_to_remote); +XFS_DATA_FORK , xfs_symlink_local_to_remote, +NULL );/* should only be called for types that support local format data */ ASSERT (0 );
libxfs/xfs_bmap.h +6 -0
@@ -179,6 +179,12 @@ unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);void xfs_bmap_local_to_extents_empty (struct xfs_trans *tp,struct xfs_inode *ip,int whichfork); +int xfs_bmap_local_to_extents (struct xfs_trans *tp,struct xfs_inode *ip, +xfs_extlen_t total,int *logflagsp,int whichfork, +void (*init_fn)(struct xfs_trans *tp,struct xfs_buf *bp, +struct xfs_inode *ip,struct xfs_ifork *ifp, +void *priv), +void *priv);void xfs_bmap_compute_maxlevels (struct xfs_mount *mp,int whichfork);int xfs_bmap_first_unused (struct xfs_trans *tp,struct xfs_inode *ip,xfs_extlen_t len,xfs_fileoff_t *unused,int whichfork);
libxfs/xfs_symlink_remote.c +2 -1
@@ -166,7 +166,8 @@ xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, - struct xfs_ifork *ifp) + struct xfs_ifork *ifp, + void *priv) { struct xfs_mount *mp = ip->i_mount;char *buf;
libxfs/xfs_symlink_remote.h +2 -1
@@ -16,7 +16,8 @@ int xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset,bool xfs_symlink_hdr_ok (xfs_ino_t ino,uint32_t offset,uint32_t size,struct xfs_buf *bp);void xfs_symlink_local_to_remote (struct xfs_trans *tp,struct xfs_buf *bp, -struct xfs_inode *ip,struct xfs_ifork *ifp); +struct xfs_inode *ip,struct xfs_ifork *ifp, +void *priv);xfs_failaddr_t xfs_symlink_shortform_verify (void *sfp,int64_t size);int xfs_symlink_remote_read (struct xfs_inode *ip,char *link); int xfs_symlink_write_target(struct xfs_trans *tp, struct xfs_inode *ip,
PATCH 26/115 xfs: pass the owner to xfs_symlink_write_target
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ea8214c3195c2ed3a205dea42bbe7746712fc461
Require callers of xfs_symlink_write_target to pass the owner number explicitly. This sets us up for online repair to be able to write a remote symlink target to sc->tempip with sc->ip's inumber in the block heaader.
--- libxfs/xfs_symlink_remote.c | 4 ++-- libxfs/xfs_symlink_remote.h | 4 ++-- mkfs/proto.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-)
libxfs/xfs_symlink_remote.c +2 -2
@@ -308,6 +308,7 @@ intxfs_symlink_write_target ( struct xfs_trans *tp, struct xfs_inode *ip, + xfs_ino_t owner, const char *target_path, int pathlen, xfs_fsblock_t fs_blocks,
@@ -362,8 +363,7 @@ xfs_symlink_write_target( byte_cnt =min (byte_cnt, pathlen); buf = bp->b_addr; - buf +=xfs_symlink_hdr_set (mp, ip->i_ino, offset, byte_cnt, - bp); + buf +=xfs_symlink_hdr_set (mp, owner, offset, byte_cnt, bp);memcpy (buf, cur_chunk, byte_cnt);
libxfs/xfs_symlink_remote.h +2 -2
@@ -21,8 +21,8 @@ void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,xfs_failaddr_t xfs_symlink_shortform_verify (void *sfp,int64_t size);int xfs_symlink_remote_read (struct xfs_inode *ip,char *link);int xfs_symlink_write_target (struct xfs_trans *tp,struct xfs_inode *ip, -const char *target_path,int pathlen,xfs_fsblock_t fs_blocks, -uint resblks); +xfs_ino_t owner,const char *target_path,int pathlen, +xfs_fsblock_t fs_blocks,uint resblks);int xfs_symlink_remote_truncate (struct xfs_trans *tp,struct xfs_inode *ip);#endif /* __XFS_SYMLINK_REMOTE_H */
mkfs/proto.c +2 -1
@@ -252,7 +252,8 @@ writesymlink(xfs_extlen_t nb =XFS_B_TO_FSB (mp, len);int error; - error = -libxfs_symlink_write_target (tp, ip, buf, len, nb, nb); + error = -libxfs_symlink_write_target (tp, ip, ip->i_ino, buf, len, nb, + nb);if (error) {fprintf (stderr,_ ("%s: error %d creating symlink to '%s'.\n" ), progname, error, buf);
PATCH 27/115 xfs: check unused nlink fields in the ondisk inode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 40cb8613d6122ca80a9e42e4cecc4d308c3b80fb
v2/v3 inodes use di_nlink and not di_onlink; and v1 inodes use di_onlink and not di_nlink. Whichever field is not in use, make sure its contents are zero, and teach xfs_scrub to fix that if it is.
This clears a bunch of missing scrub failure errors in xfs/385 for core.onlink.
--- libxfs/xfs_inode_buf.c | 8 ++++++++ 1 file changed, 8 insertions(+)
libxfs/xfs_inode_buf.c +8 -0
@@ -488,6 +488,14 @@ xfs_dinode_verify(return __this_address; } +if (dip->di_version >1 ) { +if (dip->di_onlink) +return __this_address; + }else { +if (dip->di_nlink) +return __this_address; + } +/* don't allow invalid i_size */ di_size =be64_to_cpu (dip->di_size);if (di_size & (1ULL <<63 ))
PATCH 28/115 xfs: try to avoid allocating from sick inode clusters
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 2935213a6831a0087442d406301c2cdcc87b0f61
I noticed that xfs/413 and xfs/375 occasionally failed while fuzzing core.mode of an inode. The root cause of these problems is that the field we fuzzed (core.mode or core.magic, typically) causes the entire inode cluster buffer verification to fail, which affects several inodes at once. The repair process tries to create either a /lost+found or a temporary repair file, but regrettably it picks the same inode cluster that we just corrupted, with the result that repair triggers the demise of the filesystem.
Try avoid this by making the inode allocation path detect when the perag health status indicates that someone has found bad inode cluster buffers, and try to read the inode cluster buffer. If the cluster buffer fails the verifiers, try another AG. This isn't foolproof and can result in premature ENOSPC, but that might be better than shutting down.
--- libxfs/util.c | 6 ++++++ libxfs/xfs_ialloc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
libxfs/util.c +6 -0
@@ -732,6 +732,12 @@ void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask) { }void xfs_agno_mark_sick (struct xfs_mount *mp,xfs_agnumber_t agno,unsigned int mask) { }void xfs_ag_mark_sick (struct xfs_perag *pag,unsigned int mask) { } +void xfs_ag_measure_sickness (struct xfs_perag *pag,unsigned int *sick, +unsigned int *checked) +{ + *sick =0 ; + *checked =0 ; +}void xfs_bmap_mark_sick (struct xfs_inode *ip,int whichfork) { }void xfs_btree_mark_sick (struct xfs_btree_cur *cur) { }void xfs_dirattr_mark_sick (struct xfs_inode *ip,int whichfork) { }
libxfs/xfs_ialloc.c +40 -0
@@ -1052,6 +1052,33 @@ xfs_inobt_first_free_inode(return xfs_lowbit64 (realfree); } +/* +* If this AG has corrupt inodes, check if allocating this inode would fail +* with corruption errors. Returns 0 if we're clear, or EAGAIN to try again +* somewhere else. +*/ +static int +xfs_dialloc_check_ino ( +struct xfs_perag *pag, +struct xfs_trans *tp, +xfs_ino_t ino) +{ +struct xfs_imap imap; +struct xfs_buf *bp; +int error; + + error =xfs_imap (pag, tp, ino, &imap,0 ); +if (error) +return -EAGAIN ; + + error =xfs_imap_to_bp (pag->pag_mount, tp, &imap, &bp); +if (error) +return -EAGAIN ; + +xfs_trans_brelse (tp, bp); +return 0 ; +} +/* * Allocate an inode using the inobt-only algorithm. */
@@ -1304,6 +1331,13 @@ xfs_dialloc_ag_inobt(ASSERT ((XFS_AGINO_TO_OFFSET (mp, rec.ir_startino) %XFS_INODES_PER_CHUNK ) ==0 ); ino =XFS_AGINO_TO_INO (mp, pag->pag_agno, rec.ir_startino + offset); + +if (xfs_ag_has_sickness (pag,XFS_SICK_AG_INODES )) { + error =xfs_dialloc_check_ino (pag, tp, ino); +if (error) + goto error0; + } + rec.ir_free &= ~XFS_INOBT_MASK (offset); rec.ir_freecount--; error =xfs_inobt_update (cur, &rec);
@@ -1579,6 +1613,12 @@ xfs_dialloc_ag( XFS_INODES_PER_CHUNK) == 0); ino =XFS_AGINO_TO_INO (mp, pag->pag_agno, rec.ir_startino + offset); +if (xfs_ag_has_sickness (pag,XFS_SICK_AG_INODES )) { + error =xfs_dialloc_check_ino (pag, tp, ino); +if (error) + goto error_cur; + } +/* * Modify or remove the finobt record. */
PATCH 29/115 xfs: pin inodes that would otherwise overflow link count
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 5f204051d998ec3d7306db0d749bddcbf4c97693
The VFS inc_nlink function does not explicitly check for integer overflows in the i_nlink field. Instead, it checks the link count against s_max_links in the vfs_{link,create,rename} functions. XFS sets the maximum link count to 2.1 billion, so integer overflows should not be a problem.
However. It's possible that online repair could find that a file has more than four billion links, particularly if the link count got corrupted while creating hardlinks to the file. The di_nlinkv2 field is not large enough to store a value larger than 2^32, so we ought to define a magic pin value of ~0U which means that the inode never gets deleted. This will prevent a UAF error if the repair finds this situation and users begin deleting links to the file.
--- libxfs/xfs_format.h | 6 ++++++ 1 file changed, 6 insertions(+)
libxfs/xfs_format.h +6 -0
@@ -899,6 +899,12 @@ static inline uint xfs_dinode_size(int version)*/ #define XFS_MAXLINK ((1U << 31) - 1U) +/* +* Any file that hits the maximum ondisk link count should be pinned to avoid +* a use-after-free situation. +*/ +#define XFS_NLINK_PINNED (~0U) +/* * Values for di_format *
PATCH 30/115 xfs: Increase XFS_DEFER_OPS_NR_INODES to 5
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 7560c937b4b5a3c671053be86ff00156a6fdd399
Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order. So we need to increase the number of defer ops inodes and relock them in the same way.
--- libxfs/libxfs_priv.h | 2 ++ libxfs/xfs_defer.c | 6 +++++- libxfs/xfs_defer.h | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-)
libxfs/libxfs_priv.h +2 -0
@@ -440,6 +440,8 @@ xfs_buf_readahead( })#define xfs_lock_two_inodes (ip0,mode0,ip1,mode1) ((void) 0)#define xfs_assert_ilocked (ip, flags) ((void) 0) +#define xfs_lock_inodes (i_tab, nr, mode) ((void) 0) +#define xfs_sort_inodes (i_tab, nr) ((void) 0)/* space allocation */ #define XFS_EXTENT_BUSY_DISCARDED 0x01/* undergoing a discard op. */
libxfs/xfs_defer.c +5 -1
@@ -1086,7 +1086,11 @@ xfs_defer_ops_continue(ASSERT (!(tp->t_flags &XFS_TRANS_DIRTY ));/* Lock the captured resources to the new transaction. */ -if (dfc->dfc_held.dr_inos ==2 ) +if (dfc->dfc_held.dr_inos >2 ) { +xfs_sort_inodes (dfc->dfc_held.dr_ip, dfc->dfc_held.dr_inos); +xfs_lock_inodes (dfc->dfc_held.dr_ip, dfc->dfc_held.dr_inos, +XFS_ILOCK_EXCL ); + }else if (dfc->dfc_held.dr_inos ==2 )xfs_lock_two_inodes (dfc->dfc_held.dr_ip[0 ],XFS_ILOCK_EXCL , dfc->dfc_held.dr_ip[1 ],XFS_ILOCK_EXCL );else if (dfc->dfc_held.dr_inos ==1 )
libxfs/xfs_defer.h +7 -1
@@ -77,7 +77,13 @@ extern const struct xfs_defer_op_type xfs_exchmaps_defer_type;/* * Deferred operation item relogging limits. */ -#define XFS_DEFER_OPS_NR_INODES 2/* join up to two inodes */ + +/* +* Rename w/ parent pointers can require up to 5 inodes with deferred ops to +* be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip. +* These inodes are locked in sorted order by their inode numbers +*/ +#define XFS_DEFER_OPS_NR_INODES 5#define XFS_DEFER_OPS_NR_BUFS 2/* join up to two buffers */ /* Resources that must be held across a transaction roll. */
PATCH 31/115 xfs: make XFS_TRANS_LOWMODE match the other XFS_TRANS_ definitions
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 330c4f94b0d73e440de3f738a625e38defe1bc15
Commit bb7b1c9c5dd3 ("xfs: tag transactions that contain intent done items") switched the XFS_TRANS_ definitions to be bit based, and using comments above the definitions. As XFS_TRANS_LOWMODE was last and has a big fat comment it was missed. Switch it to the same style.
--- libxfs/xfs_shared.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libxfs/xfs_shared.h +1 -2
@@ -124,7 +124,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,#define XFS_TRANS_RES_FDBLKS (1u << 6)/* Transaction contains an intent done log item */ #define XFS_TRANS_HAS_INTENT_DONE (1u << 7) -/* * LOWMODE is used by the allocator to activate the lowspace algorithm - when * free space is running low the extent allocator may choose to allocate an
@@ -136,7 +135,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,* for free space from AG 0. If the correct transaction reservations have been * made then this algorithm will eventually find all the space it needs. */ -#define XFS_TRANS_LOWMODE 0x100/* allocate in low space mode */ +#define XFS_TRANS_LOWMODE (1u << 8)/* * Field values for xfs_trans_mod_sb.
PATCH 32/115 xfs: refactor realtime inode locking
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: b7e23c0e2e3b1c520a3370f058870b914071a470
Create helper functions to deal with locking realtime metadata inodes. This enables us to maintain correct locking order once we start adding the realtime rmap and refcount btree inodes.
--- libxfs/libxfs_priv.h | 3 +++ libxfs/xfs_bmap.c | 7 ++---- libxfs/xfs_rtbitmap.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtbitmap.h | 17 +++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-)
libxfs/libxfs_priv.h +3 -0
@@ -170,6 +170,9 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#define XFS_ERRLEVEL_LOW 1#define XFS_ILOCK_EXCL 0 +#define XFS_ILOCK_SHARED 0 +#define XFS_ILOCK_RTBITMAP 0 +#define XFS_ILOCK_RTSUM 0#define XFS_STATS_INC (mp, count) do { (mp) = (mp); } while (0)#define XFS_STATS_DEC (mp, count, x) do { (mp) = (mp); } while (0)#define XFS_STATS_ADD (mp, count, x) do { (mp) = (mp); } while (0)
libxfs/xfs_bmap.c +2 -5
@@ -5412,12 +5412,9 @@ __xfs_bunmapi(if (isrt) {/* -* Synchronize by locking the bitmap inode. +* Synchronize by locking the realtime bitmap. */ -xfs_ilock (mp->m_rbmip,XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP ); -xfs_trans_ijoin (tp, mp->m_rbmip,XFS_ILOCK_EXCL ); -xfs_ilock (mp->m_rsumip,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ); -xfs_trans_ijoin (tp, mp->m_rsumip,XFS_ILOCK_EXCL ); +xfs_rtbitmap_lock (tp, mp); } extno =0 ;
libxfs/xfs_rtbitmap.c +57 -0
60 lines not on this page · raw message
libxfs/xfs_rtbitmap.h +17 -0
@@ -360,6 +360,19 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp, unsigned int rsumlevels, xfs_extlen_t rbmblocks);unsigned long long xfs_rtsummary_wordcount (struct xfs_mount *mp,unsigned int rsumlevels,xfs_extlen_t rbmblocks); + +void xfs_rtbitmap_lock (struct xfs_trans *tp,struct xfs_mount *mp); +void xfs_rtbitmap_unlock (struct xfs_mount *mp); + +/* Lock the rt bitmap inode in shared mode */ +#define XFS_RBMLOCK_BITMAP (1U << 0) +/* Lock the rt summary inode in shared mode */ +#define XFS_RBMLOCK_SUMMARY (1U << 1) + +void xfs_rtbitmap_lock_shared (struct xfs_mount *mp, +unsigned int rbmlock_flags); +void xfs_rtbitmap_unlock_shared (struct xfs_mount *mp, +unsigned int rbmlock_flags);#else /* CONFIG_XFS_RT */ # define xfs_rtfree_extent (t,b,l) (-ENOSYS)# define xfs_rtfree_blocks (t,rb,rl) (-ENOSYS)
@@ -378,6 +391,10 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)# define xfs_rtbitmap_wordcount (mp, r) (0)# define xfs_rtsummary_blockcount (mp, l, b) (0)# define xfs_rtsummary_wordcount (mp, l, b) (0) +# define xfs_rtbitmap_lock (tp, mp) do { } while (0) +# define xfs_rtbitmap_unlock (mp) do { } while (0) +# define xfs_rtbitmap_lock_shared (mp, lf) do { } while (0) +# define xfs_rtbitmap_unlock_shared (mp, lf) do { } while (0)#endif /* CONFIG_XFS_RT */ #endif /* __XFS_RTBITMAP_H__ */
PATCH 33/115 xfs: free RT extents after updating the bmap btree
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 9871d0963751293bf0587759a9b6b8f808e35c7c
Currently xfs_bmap_del_extent_real frees RT extents before updating the bmap btree, while it frees regular blocks after performing the bmap btree update for convoluted historic reasons. Switch to free the RT blocks in the same place as the regular data blocks instead to simply the code and fix a very theoretical bug.
A short history of this code researched by Dave Chiner below:
The truncate for data device extents was originally a two-phase operation. First it removed the bmapbt record, but because this can free BMBT extents, it can use up all the free space tree reservation space. So the transaction gets rolled to commit the BMBT change and the xfs_bmap_finish() call that frees the data extent runs with a new transaction reservation that allows different free space btrees to be logged without overrun.
However, on crash, this could lose the free space because there was nothing to tell recovery about the extents removed from the BMBT, hence EFIs were introduced. They tie the extent free operation to the bmapbt record removal commit for recovery of the second phase of the extent removal process.
Then RT extents came along. RT extent freeing does not require a free space btree reservation because the free space metadata is static and transaction size is bound. Hence we don't need to care if the BMBT record removal modifies the per-ag free space trees and we don't need a two-phase extent remove transaction. The only thing we have to care about is not losing space on crash.
Hence instead of recording the extent for freeing in the bmap list for xfs_bmap_finish() to process in a new transaction, it simply freed the rtextent directly. So the original code (from 1994) simply replaced the "free AG extent later" queueing with a direct free.
This code was originally at the start of xfs_dmap_del_extent(), but the xfs_bmap_add_free() got moved to the end of the function via the "do_fx" flag (the current code logic) in 1997 (commit c4fac74eaa58 in the historic xfs-import tree) because there was a shutdown occurring because of a case where splitting the extent record failed because the BMBT split and the filesystem didn't have enough space for the split to be done. (FWIW, I'm not sure this can happen anymore.)
The commit backed out the BMBT change on ENOSPC error, and in doing so I think this actually breaks RT free space tracking. However, it then returns an ENOSPC error, and we have a dirty transaction in the RT case so this will shut down the filesysetm when the transaction is cancelled. Hence the corrupted "bmbt now points at freed rt dev space" condition never make it to disk, but it's still the wrong way to handle the issue.
IOWs, this proposed change fixes that "shutdown at ENOSPC on rt devices" situation that was introduced by the above commit back in 1997.
--- libxfs/xfs_bmap.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
libxfs/xfs_bmap.c +9 -17
@@ -5103,8 +5103,7 @@ xfs_bmap_del_extent_real( {xfs_fsblock_t del_endblock=0 ;/* first block past del */ xfs_fileoff_t del_endoff;/* first offset past del */ -int do_fx;/* free extent at end of routine */ -int error;/* error return value */ +int error =0 ;/* error return value */ struct xfs_bmbt_irec got;/* current extent entry */ xfs_fileoff_t got_endoff;/* first offset past got */ int i;/* temp state */
@@ -5147,20 +5146,10 @@ xfs_bmap_del_extent_real(return -ENOSPC ; *logflagsp =XFS_ILOG_CORE ; -if (xfs_ifork_is_realtime (ip, whichfork)) { -if (!(bflags &XFS_BMAPI_REMAP )) { - error =xfs_rtfree_blocks (tp, del->br_startblock, - del->br_blockcount); -if (error) -return error; - } - - do_fx =0 ; +if (xfs_ifork_is_realtime (ip, whichfork)) qfield =XFS_TRANS_DQ_RTBCOUNT ; - }else { - do_fx =1 ; +else qfield =XFS_TRANS_DQ_BCOUNT ; - } nblks = del->br_blockcount; del_endblock = del->br_startblock + del->br_blockcount;
@@ -5308,18 +5297,21 @@ xfs_bmap_del_extent_real(/* * If we need to, add to list of extents to delete. */ -if (do_fx && !(bflags &XFS_BMAPI_REMAP )) { +if (!(bflags &XFS_BMAPI_REMAP )) {if (xfs_is_reflink_inode (ip) && whichfork ==XFS_DATA_FORK ) {xfs_refcount_decrease_extent (tp, del); + }else if (xfs_ifork_is_realtime (ip, whichfork)) { + error =xfs_rtfree_blocks (tp, del->br_startblock, + del->br_blockcount); }else { error =xfs_free_extent_later (tp, del->br_startblock, del->br_blockcount,NULL ,XFS_AG_RESV_NONE , ((bflags &XFS_BMAPI_NODISCARD ) || del->br_state ==XFS_EXT_UNWRITTEN )); -if (error) -return error; } +if (error) +return error; }/*
PATCH 34/115 xfs: move RT inode locking out of __xfs_bunmapi
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: de37dbd0ccc6933fbf4bd7b3ccbc5ac640e80b28
__xfs_bunmapi is a bit of an odd place to lock the rtbitmap and rtsummary inodes given that it is very high level code. While this only looks ugly right now, it will become a problem when supporting delayed allocations for RT inodes as __xfs_bunmapi might end up deleting only delalloc extents and thus never unlock the rt inodes.
Move the locking into xfs_bmap_del_extent_real just before the call to xfs_rtfree_blocks instead and use a new flag in the transaction to ensure that the locking happens only once.
--- libxfs/xfs_bmap.c | 15 ++++++++------- libxfs/xfs_shared.h | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-)
libxfs/xfs_bmap.c +8 -7
@@ -5301,6 +5301,14 @@ xfs_bmap_del_extent_real(if (xfs_is_reflink_inode (ip) && whichfork ==XFS_DATA_FORK ) {xfs_refcount_decrease_extent (tp, del); }else if (xfs_ifork_is_realtime (ip, whichfork)) { +/* +* Ensure the bitmap and summary inodes are locked +* and joined to the transaction before modifying them. +*/ +if (!(tp->t_flags &XFS_TRANS_RTBITMAP_LOCKED )) { + tp->t_flags |=XFS_TRANS_RTBITMAP_LOCKED ; +xfs_rtbitmap_lock (tp, mp); + } error =xfs_rtfree_blocks (tp, del->br_startblock, del->br_blockcount); }else {
@@ -5402,13 +5410,6 @@ __xfs_bunmapi( }else cur =NULL ; -if (isrt) { -/* -* Synchronize by locking the realtime bitmap. -*/ -xfs_rtbitmap_lock (tp, mp); - } - extno =0 ;while (end != (xfs_fileoff_t)-1 && end >= start && (nexts ==0 || extno < nexts)) {
libxfs/xfs_shared.h +3 -0
@@ -137,6 +137,9 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,*/ #define XFS_TRANS_LOWMODE (1u << 8) +/* Transaction has locked the rtbitmap and rtsum inodes */ +#define XFS_TRANS_RTBITMAP_LOCKED (1u << 9) +/* * Field values for xfs_trans_mod_sb. */
PATCH 35/115 xfs: split xfs_mod_freecounter
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: f30f656e25eb72c4309e76b16fa45062e183a2ee
xfs_mod_freecounter has two entirely separate code paths for adding or subtracting from the free counters. Only the subtract case looks at the rsvd flag and can return an error.
Split xfs_mod_freecounter into separate helpers for subtracting or adding the freecounter, and remove all the impossible to reach error handling for the addition case.
--- libxfs/libxfs_priv.h | 10 +++++++--- libxfs/xfs_ag.c | 4 +--- libxfs/xfs_ag_resv.c | 24 ++++++------------------ libxfs/xfs_ag_resv.h | 2 +- libxfs/xfs_alloc.c | 4 ++-- libxfs/xfs_bmap.c | 23 ++++++++++++----------- 6 files changed, 29 insertions(+), 38 deletions(-)
libxfs/libxfs_priv.h +7 -3
@@ -541,10 +541,14 @@ struct xfs_buf *xfs_trans_buf_item_match(struct xfs_trans *, struct xfs_buftarg *, struct xfs_buf_map *, int);/* local source files */ -#define xfs_mod_fdblocks (mp, delta, rsvd) \ - libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd) -#define xfs_mod_frextents (mp, delta) \ +#define xfs_add_fdblocks (mp, delta) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, false) +#define xfs_dec_fdblocks (mp, delta, rsvd) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, -(int64_t)(delta), rsvd) +#define xfs_add_frextents (mp, delta) \ libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0) +#define xfs_dec_frextents (mp, delta) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, -(int64_t)(delta), 0)int libxfs_mod_incore_sb (struct xfs_mount *,int ,int64_t ,int );/* percpu counters in mp are #defined to the superblock sb_ counters */ #define xfs_reinit_percpu_counters (mp)
libxfs/xfs_ag.c +1 -3
@@ -961,9 +961,7 @@ xfs_ag_shrink_space(* Disable perag reservations so it doesn't cause the allocation request * to fail. We'll reestablish reservation before we return. */ - error =xfs_ag_resv_free (pag); -if (error) -return error; +xfs_ag_resv_free (pag);/* internal log shouldn't also show up in the free space btrees */ error = xfs_alloc_vextent_exact_bno(&args,
libxfs/xfs_ag_resv.c +6 -18
@@ -125,14 +125,13 @@ xfs_ag_resv_needed( }/* Clean out a reservation */ -static int +static void __xfs_ag_resv_free (struct xfs_perag *pag,enum xfs_ag_resv_type type) {struct xfs_ag_resv *resv;xfs_extlen_t oldresv; -int error;trace_xfs_ag_resv_free (pag, type,0 );
@@ -148,30 +147,19 @@ __xfs_ag_resv_free( oldresv = resv->ar_orig_reserved; else oldresv = resv->ar_reserved; - error =xfs_mod_fdblocks (pag->pag_mount, oldresv, true); +xfs_add_fdblocks (pag->pag_mount, oldresv); resv->ar_reserved =0 ; resv->ar_asked =0 ; resv->ar_orig_reserved =0 ; - -if (error) -trace_xfs_ag_resv_free_error (pag->pag_mount, pag->pag_agno, - error, _RET_IP_); -return error; }/* Free a per-AG reservation. */ -int +void xfs_ag_resv_free (struct xfs_perag *pag) { -int error; -int err2; - - error =__xfs_ag_resv_free (pag,XFS_AG_RESV_RMAPBT ); - err2 =__xfs_ag_resv_free (pag,XFS_AG_RESV_METADATA ); -if (err2 && !error) - error = err2; -return error; +__xfs_ag_resv_free (pag,XFS_AG_RESV_RMAPBT ); +__xfs_ag_resv_free (pag,XFS_AG_RESV_METADATA ); } static int
@@ -215,7 +203,7 @@ __xfs_ag_resv_init(if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_AG_RESV_FAIL )) error = -ENOSPC ;else - error =xfs_mod_fdblocks (mp, -(int64_t )hidden_space, true); + error =xfs_dec_fdblocks (mp, hidden_space, true);if (error) {trace_xfs_ag_resv_init_error (pag->pag_mount, pag->pag_agno, error, _RET_IP_);
libxfs/xfs_ag_resv.h +1 -1
@@ -6,7 +6,7 @@#ifndef __XFS_AG_RESV_H__#define __XFS_AG_RESV_H__ -int xfs_ag_resv_free (struct xfs_perag *pag); +void xfs_ag_resv_free (struct xfs_perag *pag);int xfs_ag_resv_init (struct xfs_perag *pag,struct xfs_trans *tp);bool xfs_ag_resv_critical (struct xfs_perag *pag,enum xfs_ag_resv_type type);
libxfs/xfs_alloc.c +2 -2
@@ -75,7 +75,7 @@ xfs_prealloc_blocks( }/* -* The number of blocks per AG that we withhold from xfs_mod_fdblocks to +* The number of blocks per AG that we withhold from xfs_dec_fdblocks to * guarantee that we can refill the AGFL prior to allocating space in a nearly * full AG. Although the space described by the free space btrees, the * blocks used by the freesp btrees themselves, and the blocks owned by the
@@ -85,7 +85,7 @@ xfs_prealloc_blocks(* until the fs goes down, we subtract this many AG blocks from the incore * fdblocks to ensure user allocation does not overcommit the space the * filesystem needs for the AGFLs. The rmap btree uses a per-AG reservation to -* withhold space from xfs_mod_fdblocks, so we do not account for that here. +* withhold space from xfs_dec_fdblocks, so we do not account for that here. */ #define XFS_ALLOCBT_AGFL_RESERVE 4
libxfs/xfs_bmap.c +12 -11
@@ -1979,10 +1979,11 @@ xfs_bmap_add_extent_delay_real( }/* adjust for changes in reserved delayed indirect blocks */ -if (da_new != da_old) { -ASSERT (state ==0 || da_new < da_old); - error =xfs_mod_fdblocks (mp, (int64_t )(da_old - da_new), - false); +if (da_new < da_old) { +xfs_add_fdblocks (mp, da_old - da_new); + }else if (da_new > da_old) { +ASSERT (state ==0 ); + error =xfs_dec_fdblocks (mp, da_new - da_old, false); }xfs_bmap_check_leaf_extents (bma->cur, bma->ip, whichfork);
@@ -2684,8 +2685,8 @@ xfs_bmap_add_extent_hole_delay( }if (oldlen != newlen) {ASSERT (oldlen > newlen); -xfs_mod_fdblocks (ip->i_mount, (int64_t )(oldlen - newlen), - false); +xfs_add_fdblocks (ip->i_mount, oldlen - newlen); +/* * Nothing to do for disk quota accounting here. */
@@ -4104,11 +4105,11 @@ xfs_bmapi_reserve_delalloc( indlen = (xfs_extlen_t )xfs_bmap_worst_indlen (ip, alen);ASSERT (indlen >0 ); - error =xfs_mod_fdblocks (mp, -((int64_t )alen), false); + error =xfs_dec_fdblocks (mp, alen, false);if (error) goto out_unreserve_quota; - error =xfs_mod_fdblocks (mp, -((int64_t )indlen), false); + error =xfs_dec_fdblocks (mp, indlen, false);if (error) goto out_unreserve_blocks;
@@ -4136,7 +4137,7 @@ xfs_bmapi_reserve_delalloc(return 0 ; out_unreserve_blocks: -xfs_mod_fdblocks (mp, alen, false); +xfs_add_fdblocks (mp, alen); out_unreserve_quota:if (XFS_IS_QUOTA_ON (mp))xfs_quota_unreserve_blkres (ip, alen);
@@ -4922,7 +4923,7 @@ xfs_bmap_del_extent_delay(ASSERT (got_endoff >= del_endoff);if (isrt) -xfs_mod_frextents (mp,xfs_rtb_to_rtx (mp, del->br_blockcount)); +xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, del->br_blockcount));/* * Update the inode delalloc counter now and wait to update the
@@ -5009,7 +5010,7 @@ xfs_bmap_del_extent_delay(if (!isrt) da_diff += del->br_blockcount;if (da_diff) { -xfs_mod_fdblocks (mp, da_diff, false); +xfs_add_fdblocks (mp, da_diff);xfs_mod_delalloc (mp, -da_diff); }return error;
PATCH 36/115 xfs: reinstate RT support in xfs_bmapi_reserve_delalloc
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: dc1b17a25c321c8f1b4f90f9d6f8afb1d132b69c
Allocate data blocks for RT inodes using xfs_dec_frextents. While at it optimize the data device case by doing only a single xfs_dec_fdblocks call for the extent itself and the indirect blocks.
--- libxfs/xfs_bmap.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
libxfs/xfs_bmap.c +14 -8
@@ -4063,6 +4063,7 @@ xfs_bmapi_reserve_delalloc(struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);xfs_extlen_t alen;xfs_extlen_t indlen; +uint64_t fdblocks;int error;xfs_fileoff_t aoff = off;
@@ -4105,14 +4106,18 @@ xfs_bmapi_reserve_delalloc( indlen = (xfs_extlen_t )xfs_bmap_worst_indlen (ip, alen);ASSERT (indlen >0 ); - error =xfs_dec_fdblocks (mp, alen, false); -if (error) - goto out_unreserve_quota; + fdblocks = indlen; +if (XFS_IS_REALTIME_INODE (ip)) { + error =xfs_dec_frextents (mp,xfs_rtb_to_rtx (mp, alen)); +if (error) + goto out_unreserve_quota; + }else { + fdblocks += alen; + } - error =xfs_dec_fdblocks (mp, indlen, false); + error =xfs_dec_fdblocks (mp, fdblocks, false);if (error) - goto out_unreserve_blocks; - + goto out_unreserve_frextents; ip->i_delayed_blks += alen;xfs_mod_delalloc (ip->i_mount, alen + indlen);
@@ -4136,8 +4141,9 @@ xfs_bmapi_reserve_delalloc(return 0 ; -out_unreserve_blocks: -xfs_add_fdblocks (mp, alen); +out_unreserve_frextents: +if (XFS_IS_REALTIME_INODE (ip)) +xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, alen)); out_unreserve_quota:if (XFS_IS_QUOTA_ON (mp))xfs_quota_unreserve_blkres (ip, alen);
PATCH 37/115 xfs: cleanup fdblock/frextent accounting in xfs_bmap_del_extent_delay
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 7e77d57a1fea5f6bfe166210385ba9f227a606d1
The code to account fdblocks and frextents in xfs_bmap_del_extent_delay is a bit weird in that it accounts frextents before the iext tree manipulations and fdblocks after it. Given that the iext tree manipulations cannot fail currently that's not really a problem, but still odd. Move the frextent manipulation to the end, and use a fdblocks variable to account of the unconditional indirect blocks and the data blocks only freed for !RT. This prepares for following updates in the area and already makes the code more readable.
Also remove the !isrt assert given that this code clearly handles rt extents correctly, and we'll soon reinstate delalloc support for RT inodes.
--- libxfs/xfs_bmap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
libxfs/xfs_bmap.c +10 -10
@@ -4913,6 +4913,7 @@ xfs_bmap_del_extent_delay(xfs_fileoff_t del_endoff, got_endoff;xfs_filblks_t got_indlen, new_indlen, stolen;uint32_t state =xfs_bmap_fork_to_state (whichfork); +uint64_t fdblocks;int error =0 ;bool isrt;
@@ -4928,15 +4929,11 @@ xfs_bmap_del_extent_delay(ASSERT (got->br_startoff <= del->br_startoff);ASSERT (got_endoff >= del_endoff); -if (isrt) -xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, del->br_blockcount)); -/* * Update the inode delalloc counter now and wait to update the * sb counters as we might have to borrow some blocks for the * indirect block accounting. */ -ASSERT (!isrt); error =xfs_quota_unreserve_blkres (ip, del->br_blockcount);if (error)return error;
@@ -5013,12 +5010,15 @@ xfs_bmap_del_extent_delay(ASSERT (da_old >= da_new); da_diff = da_old - da_new; -if (!isrt) - da_diff += del->br_blockcount; -if (da_diff) { -xfs_add_fdblocks (mp, da_diff); -xfs_mod_delalloc (mp, -da_diff); - } + fdblocks = da_diff; + +if (isrt) +xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, del->br_blockcount)); +else + fdblocks += del->br_blockcount; + +xfs_add_fdblocks (mp, fdblocks); +xfs_mod_delalloc (mp, -(int64_t )fdblocks);return error; }
PATCH 38/115 xfs: support RT inodes in xfs_mod_delalloc
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 7099bd0f243fa7511de6e95b0b8807ba7d3e5204
To prepare for re-enabling delalloc on RT devices, track the data blocks (which use the RT device when the inode sits on it) and the indirect blocks (which don't) separately to xfs_mod_delalloc, and add a new percpu counter to also track the RT delalloc blocks.
--- libxfs/libxfs_priv.h | 2 +- libxfs/xfs_bmap.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
libxfs/libxfs_priv.h +1 -1
@@ -141,7 +141,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#define xfs_force_shutdown (d,n) ((void) 0) -#define xfs_mod_delalloc (a,b) ((void) 0) +#define xfs_mod_delalloc (a,b,c) ((void) 0)/* stop unused var warnings by assigning mp to itself */
libxfs/xfs_bmap.c +6 -6
@@ -1971,7 +1971,7 @@ xfs_bmap_add_extent_delay_real( }if (da_new != da_old) -xfs_mod_delalloc (mp, (int64_t )da_new - da_old); +xfs_mod_delalloc (bma->ip,0 , (int64_t )da_new - da_old);if (bma->cur) { da_new += bma->cur->bc_bmap.allocated;
@@ -2690,7 +2690,7 @@ xfs_bmap_add_extent_hole_delay(/* * Nothing to do for disk quota accounting here. */ -xfs_mod_delalloc (ip->i_mount, (int64_t )newlen - oldlen); +xfs_mod_delalloc (ip,0 , (int64_t )newlen - oldlen); } }
@@ -3367,7 +3367,7 @@ xfs_bmap_alloc_account(* yet. */ if (ap->wasdel) { -xfs_mod_delalloc (ap->ip->i_mount, -(int64_t )ap->length); +xfs_mod_delalloc (ap->ip, -(int64_t )ap->length,0 );return ; }
@@ -3391,7 +3391,7 @@ xfs_bmap_alloc_account(xfs_trans_log_inode (ap->tp, ap->ip,XFS_ILOG_CORE );if (ap->wasdel) { ap->ip->i_delayed_blks -= ap->length; -xfs_mod_delalloc (ap->ip->i_mount, -(int64_t )ap->length); +xfs_mod_delalloc (ap->ip, -(int64_t )ap->length,0 ); fld = isrt ?XFS_TRANS_DQ_DELRTBCOUNT :XFS_TRANS_DQ_DELBCOUNT ; }else { fld = isrt ?XFS_TRANS_DQ_RTBCOUNT :XFS_TRANS_DQ_BCOUNT ;
@@ -4120,7 +4120,7 @@ xfs_bmapi_reserve_delalloc( goto out_unreserve_frextents; ip->i_delayed_blks += alen; -xfs_mod_delalloc (ip->i_mount, alen + indlen); +xfs_mod_delalloc (ip, alen, indlen); got->br_startoff = aoff; got->br_startblock =nullstartblock (indlen);
@@ -5018,7 +5018,7 @@ xfs_bmap_del_extent_delay( fdblocks += del->br_blockcount;xfs_add_fdblocks (mp, fdblocks); -xfs_mod_delalloc (mp, -(int64_t )fdblocks); +xfs_mod_delalloc (ip, -(int64_t )del->br_blockcount, -da_diff);return error; }
PATCH 39/115 xfs: rework splitting of indirect block reservations
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: da2b9c3a8d2cbdeec3f13cebf4c6c86c13e1077e
Move the check if we have enough indirect blocks and the stealing of the deleted extent blocks out of xfs_bmap_split_indlen and into the caller to prepare for handling delayed allocation of RT extents that can't easily be stolen.
--- libxfs/xfs_bmap.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-)
libxfs/xfs_bmap.c +16 -22
@@ -4825,31 +4825,17 @@ xfs_bmapi_remap(* ores == 1). The number of stolen blocks is returned. The availability and * subsequent accounting of stolen blocks is the responsibility of the caller. */ -static xfs_filblks_t +static void xfs_bmap_split_indlen (xfs_filblks_t ores,/* original res. */ xfs_filblks_t *indlen1,/* ext1 worst indlen */ -xfs_filblks_t *indlen2,/* ext2 worst indlen */ -xfs_filblks_t avail)/* stealable blocks */ +xfs_filblks_t *indlen2)/* ext2 worst indlen */ {xfs_filblks_t len1 = *indlen1;xfs_filblks_t len2 = *indlen2;xfs_filblks_t nres = len1 + len2;/* new total res. */ -xfs_filblks_t stolen =0 ;xfs_filblks_t resfactor; -/* -* Steal as many blocks as we can to try and satisfy the worst case -* indlen for both new extents. -*/ -if (ores < nres && avail) - stolen =XFS_FILBLKS_MIN (nres - ores, avail); - ores += stolen; - -/* nothing else to do if we've satisfied the new reservation */ -if (ores >= nres) -return stolen; -/* * We can't meet the total required reservation for the two extents. * Calculate the percent of the overall shortage between both extents
@@ -4894,8 +4880,6 @@ xfs_bmap_split_indlen( *indlen1 = len1; *indlen2 = len2; - -return stolen; }int
@@ -4911,7 +4895,7 @@ xfs_bmap_del_extent_delay(struct xfs_bmbt_irec new;int64_t da_old, da_new, da_diff =0 ;xfs_fileoff_t del_endoff, got_endoff; -xfs_filblks_t got_indlen, new_indlen, stolen; +xfs_filblks_t got_indlen, new_indlen, stolen =0 ;uint32_t state =xfs_bmap_fork_to_state (whichfork);uint64_t fdblocks;int error =0 ;
@@ -4990,8 +4974,19 @@ xfs_bmap_del_extent_delay( new_indlen =xfs_bmap_worst_indlen (ip, new.br_blockcount);WARN_ON_ONCE (!got_indlen || !new_indlen); - stolen =xfs_bmap_split_indlen (da_old, &got_indlen, &new_indlen, - del->br_blockcount); +/* +* Steal as many blocks as we can to try and satisfy the worst +* case indlen for both new extents. +*/ + da_new = got_indlen + new_indlen; +if (da_new > da_old) { + stolen =XFS_FILBLKS_MIN (da_new - da_old, + del->br_blockcount); + da_old += stolen; + } +if (da_new > da_old) +xfs_bmap_split_indlen (da_old, &got_indlen, &new_indlen); + da_new = got_indlen + new_indlen; got->br_startblock =nullstartblock ((int )got_indlen);
@@ -5003,7 +4998,6 @@ xfs_bmap_del_extent_delay(xfs_iext_next (ifp, icur);xfs_iext_insert (ip, icur, &new, state); - da_new = got_indlen + new_indlen - stolen; del->br_blockcount -= stolen;break ; }
PATCH 40/115 xfs: stop the steal (of data blocks for RT indirect blocks)
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: bd1753d8c42b6bd5d9a81c81d1ce6e3affe3a59f
When xfs_bmap_del_extent_delay has to split an indirect block it tries to steal blocks from the the part that gets unmapped to increase the indirect block reservation that now needs to cover for two extents instead of one.
This works perfectly fine on the data device, where the data and indirect blocks come from the same pool. It has no chance of working when the inode sits on the RT device. To support re-enabling delalloc for inodes on the RT device, make this behavior conditional on not being for rt extents.
Note that split of delalloc extents should only happen on writeback failure, as for other kinds of hole punching we first write back all data and thus convert the delalloc reservations covering the hole to a real allocation.
--- libxfs/xfs_bmap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
libxfs/xfs_bmap.c +6 -1
@@ -4977,9 +4977,14 @@ xfs_bmap_del_extent_delay(/* * Steal as many blocks as we can to try and satisfy the worst * case indlen for both new extents. +* +* However, we can't just steal reservations from the data +* blocks if this is an RT inodes as the data and metadata +* blocks come from different pools. We'll have to live with +* under-filled indirect reservation in this case. */ da_new = got_indlen + new_indlen; -if (da_new > da_old) { +if (da_new > da_old && !isrt) { stolen =XFS_FILBLKS_MIN (da_new - da_old, del->br_blockcount); da_old += stolen;
PATCH 41/115 xfs: remove XFS_DA_OP_REMOVE
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f566d5b9fb7136d39d4e9c54d84c82835b539b4e
Nobody checks this flag, so get rid of it.
--- libxfs/xfs_attr.h | 1 - libxfs/xfs_da_btree.h | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-)
libxfs/xfs_attr.h +0 -1
@@ -590,7 +590,6 @@ xfs_attr_init_add_state(struct xfs_da_args *args)static inline enum xfs_delattr_state xfs_attr_init_remove_state (struct xfs_da_args *args) { - args->op_flags |=XFS_DA_OP_REMOVE ;if (xfs_attr_is_shortform (args->dp))return XFS_DAS_SF_REMOVE ;if (xfs_attr_is_leaf (args->dp))
libxfs/xfs_da_btree.h +2 -4
@@ -91,9 +91,8 @@ typedef struct xfs_da_args {#define XFS_DA_OP_OKNOENT (1u << 3)/* lookup op, ENOENT ok, else die */ #define XFS_DA_OP_CILOOKUP (1u << 4)/* lookup returns CI name if found */ #define XFS_DA_OP_NOTIME (1u << 5)/* don't update inode timestamps */ -#define XFS_DA_OP_REMOVE (1u << 6)/* this is a remove operation */ -#define XFS_DA_OP_RECOVERY (1u << 7)/* Log recovery operation */ -#define XFS_DA_OP_LOGGED (1u << 8)/* Use intent items to track op */ +#define XFS_DA_OP_RECOVERY (1u << 6)/* Log recovery operation */ +#define XFS_DA_OP_LOGGED (1u << 7)/* Use intent items to track op */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
@@ -102,7 +101,6 @@ typedef struct xfs_da_args { { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ { XFS_DA_OP_NOTIME, "NOTIME" }, \ - { XFS_DA_OP_REMOVE, "REMOVE" }, \ { XFS_DA_OP_RECOVERY, "RECOVERY" }, \ { XFS_DA_OP_LOGGED, "LOGGED" }
PATCH 42/115 xfs: remove XFS_DA_OP_NOTIME
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 779a4b606c7678343e3603398fe07de38b817ef4
The only user of this flag sets it prior to an xfs_attr_get_ilocked call, which doesn't update anything. Get rid of the flag.
--- libxfs/xfs_attr.c | 5 ++--- libxfs/xfs_da_btree.h | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-)
libxfs/xfs_attr.c +2 -3
@@ -363,7 +363,7 @@ xfs_attr_try_sf_addname(* Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ -if (!error && !(args->op_flags &XFS_DA_OP_NOTIME )) +if (!error)xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );if (xfs_has_wsync (dp->i_mount))
@@ -1031,8 +1031,7 @@ xfs_attr_set(if (xfs_has_wsync (mp))xfs_trans_set_sync (args->trans); -if (!(args->op_flags &XFS_DA_OP_NOTIME )) -xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG ); +xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );/* * Commit the last in the sequence of transactions.
libxfs/xfs_da_btree.h +2 -4
@@ -90,9 +90,8 @@ typedef struct xfs_da_args {#define XFS_DA_OP_ADDNAME (1u << 2)/* this is an add operation */ #define XFS_DA_OP_OKNOENT (1u << 3)/* lookup op, ENOENT ok, else die */ #define XFS_DA_OP_CILOOKUP (1u << 4)/* lookup returns CI name if found */ -#define XFS_DA_OP_NOTIME (1u << 5)/* don't update inode timestamps */ -#define XFS_DA_OP_RECOVERY (1u << 6)/* Log recovery operation */ -#define XFS_DA_OP_LOGGED (1u << 7)/* Use intent items to track op */ +#define XFS_DA_OP_RECOVERY (1u << 5)/* Log recovery operation */ +#define XFS_DA_OP_LOGGED (1u << 6)/* Use intent items to track op */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
@@ -100,7 +99,6 @@ typedef struct xfs_da_args { { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ - { XFS_DA_OP_NOTIME, "NOTIME" }, \ { XFS_DA_OP_RECOVERY, "RECOVERY" }, \ { XFS_DA_OP_LOGGED, "LOGGED" }
PATCH 43/115 xfs: remove xfs_da_args.attr_flags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 54275d8496f3e4764302cebc0e9517d950ba6589
This field only ever contains XATTR_{CREATE,REPLACE}, and it only goes as deep as xfs_attr_set. Remove the field from the structure and replace it with an enum specifying exactly what kind of change we want to make to the xattr structure. Upsert is the name that we'll give to the flags==0 operation, because we're either updating an existing value or inserting it, and the caller doesn't care.
--- db/attrset.c | 11 +++++------ libxfs/xfs_attr.c | 7 ++++--- libxfs/xfs_attr.h | 9 ++++++++- libxfs/xfs_da_btree.h | 1 - 4 files changed, 17 insertions(+), 11 deletions(-)
db/attrset.c +5 -6
@@ -69,6 +69,7 @@ attr_set_f( {struct xfs_da_args args = { };char *sp; +enum xfs_attr_update op =XFS_ATTRUPDATE_UPSERTR ;int c;if (cur_typ ==NULL ) {
@@ -98,12 +99,10 @@ attr_set_f(/* modifiers */ case 'C' : - args.attr_flags |=XATTR_CREATE ; - args.attr_flags &= ~XATTR_REPLACE ; + op =XFS_ATTRUPDATE_CREATE ;break ;case 'R' : - args.attr_flags |=XATTR_REPLACE ; - args.attr_flags &= ~XATTR_CREATE ; + op =XFS_ATTRUPDATE_REPLACE ;break ;case 'n' :
@@ -162,7 +161,7 @@ attr_set_f( goto out; } -if (libxfs_attr_set (&args)) { +if (libxfs_attr_set (&args, op)) {dbprintf (_ ("failed to set attr %s on inode %llu\n" ), args.name, (unsigned long long )iocur_top->ino); goto out;
@@ -248,7 +247,7 @@ attr_remove_f( goto out; } -if (libxfs_attr_set (&args)) { +if (libxfs_attr_set (&args,XFS_ATTRUPDATE_UPSERTR )) {dbprintf (_ ("failed to remove attr %s from inode %llu\n" ), (unsigned char *)args.name, (unsigned long long )iocur_top->ino);
libxfs/xfs_attr.c +4 -3
@@ -920,7 +920,8 @@ xfs_attr_defer_add(*/ int xfs_attr_set ( -struct xfs_da_args *args) +struct xfs_da_args *args, +enum xfs_attr_update op) {struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount;
@@ -1006,7 +1007,7 @@ xfs_attr_set( }/* Pure create fails if the attr already exists */ -if (args->attr_flags &XATTR_CREATE ) +if (op ==XFS_ATTRUPDATE_CREATE ) goto out_trans_cancel;xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_REPLACE );break ;
@@ -1016,7 +1017,7 @@ xfs_attr_set( goto out_trans_cancel;/* Pure replace fails if no existing attr to replace. */ -if (args->attr_flags &XATTR_REPLACE ) +if (op ==XFS_ATTRUPDATE_REPLACE ) goto out_trans_cancel;xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_SET );break ;
libxfs/xfs_attr.h +8 -1
@@ -544,7 +544,14 @@ int xfs_inode_hasattr(struct xfs_inode *ip);bool xfs_attr_is_leaf (struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args); -int xfs_attr_set (struct xfs_da_args *args); + +enum xfs_attr_update { +XFS_ATTRUPDATE_UPSERTR ,/* set/remove value, replace any existing attr */ +XFS_ATTRUPDATE_CREATE ,/* set value, fail if attr already exists */ +XFS_ATTRUPDATE_REPLACE ,/* set value, fail if attr does not exist */ +}; + +int xfs_attr_set (struct xfs_da_args *args,enum xfs_attr_update op);int xfs_attr_set_iter (struct xfs_attr_intent *attr);int xfs_attr_remove_iter (struct xfs_attr_intent *attr);bool xfs_attr_namecheck (const void *name,size_t length);
libxfs/xfs_da_btree.h +0 -1
@@ -60,7 +60,6 @@ typedef struct xfs_da_args {void *value;/* set of bytes (maybe contain NULLs) */ int valuelen;/* length of value */ unsigned int attr_filter;/* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ -unsigned int attr_flags;/* XATTR_{CREATE,REPLACE} */ xfs_dahash_t hashval;/* hash value of name */ xfs_ino_t inumber;/* input/output inode number */ struct xfs_inode *dp;/* directory inode to manipulate */
PATCH 44/115 xfs: make attr removal an explicit operation
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: c27411d4c640037d70e2fa5751616e175e52ca5e
Parent pointers match attrs on name+value, unlike everything else which matches on only the name. Therefore, we cannot keep using the heuristic that !value means remove. Make this an explicit operation code.
--- db/attrset.c | 4 ++-- libxfs/xfs_attr.c | 19 ++++++++++--------- libxfs/xfs_attr.h | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-)
db/attrset.c +2 -2
@@ -69,7 +69,7 @@ attr_set_f( {struct xfs_da_args args = { };char *sp; -enum xfs_attr_update op =XFS_ATTRUPDATE_UPSERTR ; +enum xfs_attr_update op =XFS_ATTRUPDATE_UPSERT ;int c;if (cur_typ ==NULL ) {
@@ -247,7 +247,7 @@ attr_remove_f( goto out; } -if (libxfs_attr_set (&args,XFS_ATTRUPDATE_UPSERTR )) { +if (libxfs_attr_set (&args,XFS_ATTRUPDATE_REMOVE )) {dbprintf (_ ("failed to remove attr %s from inode %llu\n" ), (unsigned char *)args.name, (unsigned long long )iocur_top->ino);
libxfs/xfs_attr.c +10 -9
@@ -914,10 +914,6 @@ xfs_attr_defer_add(trace_xfs_attr_defer_add (new->xattri_dela_state, args->dp); } -/* -* Note: If args->value is NULL the attribute will be removed, just like the -* Linux ->setattr API. -*/ int xfs_attr_set( struct xfs_da_args *args,
@@ -953,7 +949,10 @@ xfs_attr_set( args->op_flags =XFS_DA_OP_OKNOENT | (args->op_flags &XFS_DA_OP_LOGGED ); -if (args->value) { +switch (op) { +case XFS_ATTRUPDATE_UPSERT : +case XFS_ATTRUPDATE_CREATE : +case XFS_ATTRUPDATE_REPLACE :XFS_STATS_INC (mp, xs_attr_set); args->total =xfs_attr_calc_size (args, &local);
@@ -973,9 +972,11 @@ xfs_attr_set(if (!local) rmt_blks =xfs_attr3_rmt_blocks (mp, args->valuelen); - }else { +break ; +case XFS_ATTRUPDATE_REMOVE :XFS_STATS_INC (mp, xs_attr_remove); rmt_blks =xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX ); +break ; }/*
@@ -987,7 +988,7 @@ xfs_attr_set(if (error)return error; -if (args->value ||xfs_inode_hasattr (dp)) { +if (op !=XFS_ATTRUPDATE_REMOVE ||xfs_inode_hasattr (dp)) { error =xfs_iext_count_may_overflow (dp,XFS_ATTR_FORK ,XFS_IEXT_ATTR_MANIP_CNT (rmt_blks));if (error == -EFBIG )
@@ -1000,7 +1001,7 @@ xfs_attr_set( error =xfs_attr_lookup (args);switch (error) {case -EEXIST : -if (!args->value) { +if (op ==XFS_ATTRUPDATE_REMOVE ) {/* if no value, we are performing a remove operation */ xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_REMOVE );break ;
@@ -1013,7 +1014,7 @@ xfs_attr_set(break ;case -ENOATTR :/* Can't remove what isn't there. */ -if (!args->value) +if (op ==XFS_ATTRUPDATE_REMOVE ) goto out_trans_cancel;/* Pure replace fails if no existing attr to replace. */
libxfs/xfs_attr.h +2 -1
@@ -546,7 +546,8 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);enum xfs_attr_update { -XFS_ATTRUPDATE_UPSERTR ,/* set/remove value, replace any existing attr */ +XFS_ATTRUPDATE_REMOVE ,/* remove attr */ +XFS_ATTRUPDATE_UPSERT ,/* set value, replace any existing attr */ XFS_ATTRUPDATE_CREATE ,/* set value, fail if attr already exists */ XFS_ATTRUPDATE_REPLACE ,/* set value, fail if attr does not exist */ };
PATCH 45/115 xfs: rearrange xfs_da_args a bit to use less space
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: cda60317ac57add7a0a2865aa29afbc6caad3e9a
A few notes about struct xfs_da_args:
The XFS_ATTR_* flags only go up as far as XFS_ATTR_INCOMPLETE, which means that attr_filter could be a u8 field.
I've reduced the number of XFS_DA_OP_* flags down to the point where op_flags would also fit into a u8.
filetype has 7 bytes of slack after it, which is wasteful.
namelen will never be greater than MAXNAMELEN, which is 256. This field could be reduced to a short.
Rearrange the fields in xfs_da_args to waste less space. This reduces the structure size from 136 bytes to 128. Later when we add extra fields to support parent pointer replacement, this will only bloat the structure to 144 bytes, instead of 168.
--- libxfs/xfs_da_btree.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
libxfs/xfs_da_btree.h +11 -9
@@ -54,16 +54,20 @@ enum xfs_dacmp {*/ typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ - const uint8_t *name; /* string (maybe not NULL terminated) */ - int namelen; /* length of string (maybe no NULL) */ - uint8_t filetype; /* filetype of inode for directories */ + const uint8_t *name; /* string (maybe not NULL terminated) */ void *value; /* set of bytes (maybe contain NULLs) */ - int valuelen; /* length of value */ - unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ - xfs_dahash_t hashval; /* hash value of name */ - xfs_ino_t inumber; /* input/output inode number */ struct xfs_inode *dp; /* directory inode to manipulate */ struct xfs_trans *trans; /* current trans (changes over time) */ + + xfs_ino_t inumber; /* input/output inode number */ + xfs_ino_t owner; /* inode that owns the dir/attr data */ + + int valuelen; /* length of value */ + uint8_t filetype; /* filetype of inode for directories */ + uint8_t op_flags; /* operation flags */ + uint8_t attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ + short namelen; /* length of string (maybe no NULL) */ + xfs_dahash_t hashval; /* hash value of name */ xfs_extlen_t total; /* total blocks needed, for 1st bmap */ int whichfork; /* data or attribute fork */ xfs_dablk_t blkno; /* blkno of attr leaf of interest */
@@ -76,9 +80,7 @@ typedef struct xfs_da_args {xfs_dablk_t rmtblkno2;/* remote attr value starting blkno */ int rmtblkcnt2;/* remote attr value block count */ int rmtvaluelen2;/* remote attr value length in bytes */ -uint32_t op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ -xfs_ino_t owner;/* inode that owns the dir/attr data */ } xfs_da_args_t;/*
PATCH 46/115 xfs: attr fork iext must be loaded before calling xfs_attr_is_leaf
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ef80de940a6344da1d4f12c948a0ad4d6ff6e841
Christoph noticed that the xfs_attr_is_leaf in xfs_attr_get_ilocked can access the incore extent tree of the attr fork, but nothing in the xfs_attr_get path guarantees that the incore tree is actually loaded.
Most of the time it is, but seeing as xfs_attr_is_leaf ignores the return value of xfs_iext_get_extent I guess we've been making choices based on random stack contents and nobody's complained?
--- libxfs/xfs_attr.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
libxfs/xfs_attr.c +17 -0
@@ -85,6 +85,8 @@ xfs_attr_is_leaf(struct xfs_iext_cursor icur;struct xfs_bmbt_irec imap; +ASSERT (!xfs_need_iread_extents (ifp)); +if (ifp->if_nextents !=1 || ifp->if_format !=XFS_DINODE_FMT_EXTENTS )return false;
@@ -222,11 +224,21 @@ intxfs_attr_get_ilocked ( struct xfs_da_args *args) { +int error; +xfs_assert_ilocked (args->dp,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL );if (!xfs_inode_hasattr (args->dp))return -ENOATTR ; +/* +* The incore attr fork iext tree must be loaded for xfs_attr_is_leaf +* to work correctly. +*/ + error =xfs_iread_extents (args->trans, args->dp,XFS_ATTR_FORK ); +if (error) +return error; +if (args->dp->i_af.if_format ==XFS_DINODE_FMT_LOCAL )return xfs_attr_shortform_getvalue (args);if (xfs_attr_is_leaf (args->dp))
@@ -868,6 +880,11 @@ xfs_attr_lookup(return -ENOATTR ; } +/* Prerequisite for xfs_attr_is_leaf */ + error =xfs_iread_extents (args->trans, args->dp,XFS_ATTR_FORK ); +if (error) +return error; +if (xfs_attr_is_leaf (dp)) { error =xfs_attr_leaf_hasname (args, &bp);
PATCH 47/115 xfs: fix missing check for invalid attr flags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f660ec8eaeb50d0317c29601aacabdb15e5f2203
The xattr scrubber doesn't check for undefined flags in shortform attr entries. Therefore, define a mask XFS_ATTR_ONDISK_MASK that has all possible XFS_ATTR_* flags in it, and use that to check for unknown bits in xchk_xattr_actor.
Refactor the check in the dabtree scanner function to use the new mask as well. The redundant checks need to be in place because the dabtree check examines the hash mappings and therefore needs to decode the attr leaf entries to compute the namehash. This happens before the walk of the xattr entries themselves.
--- libxfs/xfs_da_format.h | 5 +++++ 1 file changed, 5 insertions(+)
libxfs/xfs_da_format.h +5 -0
@@ -719,8 +719,13 @@ struct xfs_attr3_leafblock {#define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT)#define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT)#define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) +#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ + XFS_ATTR_LOCAL | \ + XFS_ATTR_INCOMPLETE) +#define XFS_ATTR_NAMESPACE_STR \ { XFS_ATTR_LOCAL, "local" }, \ { XFS_ATTR_ROOT, "root" }, \
PATCH 48/115 xfs: restructure xfs_attr_complete_op a bit
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 992c3b5c3fe6f42778436649ddae2b7a2984b7aa
Eliminate the local variable from this function so that we can streamline things a bit later when we add the PPTR_REPLACE op code.
--- libxfs/xfs_attr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
libxfs/xfs_attr.c +4 -5
@@ -430,14 +430,13 @@ xfs_attr_complete_op( enum xfs_delattr_state replace_state) {struct xfs_da_args *args = attr->xattri_da_args; -bool do_replace = args->op_flags &XFS_DA_OP_REPLACE ; + +if (!(args->op_flags &XFS_DA_OP_REPLACE )) + replace_state =XFS_DAS_DONE ; args->op_flags &= ~XFS_DA_OP_REPLACE ; args->attr_filter &= ~XFS_ATTR_INCOMPLETE ; -if (do_replace) -return replace_state; - -return XFS_DAS_DONE ; +return replace_state; } static int
PATCH 49/115 xfs: use helpers to extract xattr op from opflags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 2a2c05d013d0562076ec475a6deb0991ce1942ca
Create helper functions to extract the xattr op from the ondisk xattri log item and the incore attr intent item. These will get more use in the patches that follow.
--- libxfs/xfs_attr.h | 5 +++++ 1 file changed, 5 insertions(+)
libxfs/xfs_attr.h +5 -0
@@ -529,6 +529,11 @@ struct xfs_attr_intent {struct xfs_bmbt_irec xattri_map; }; +static inline unsigned int +xfs_attr_intent_op (const struct xfs_attr_intent *attr) +{ +return attr->xattri_op_flags &XFS_ATTRI_OP_FLAGS_TYPE_MASK ; +}/*======================================================================== * Function prototypes for the kernel.
PATCH 50/115 xfs: enforce one namespace per attribute
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ea0b3e814741fb64e7785b564ea619578058e0b0
Create a standardized helper function to enforce one namespace bit per extended attribute, and refactor all the open-coded hweight logic. This function is not a static inline to avoid porting hassles in userspace.
--- libxfs/xfs_attr.c | 11 +++++++++++ libxfs/xfs_attr.h | 4 +++- libxfs/xfs_attr_leaf.c | 7 ++++++- repair/attr_repair.c | 7 ++++--- 4 files changed, 24 insertions(+), 5 deletions(-)
libxfs/xfs_attr.c +11 -0
@@ -1530,12 +1530,23 @@ xfs_attr_node_get(return error; } +/* Enforce that there is at most one namespace bit per attr. */ +inline bool xfs_attr_check_namespace (unsigned int attr_flags) +{ +return hweight32 (attr_flags &XFS_ATTR_NSP_ONDISK_MASK ) <2 ; +} +/* Returns true if the attribute entry name is valid. */ bool xfs_attr_namecheck ( +unsigned int attr_flags,const void *name,size_t length) { +/* Only one namespace bit allowed. */ +if (!xfs_attr_check_namespace (attr_flags)) +return false; +/* * MAXNAMELEN includes the trailing null, but (name/length) leave it * out, so use >= for the length check.
libxfs/xfs_attr.h +3 -1
@@ -560,7 +560,9 @@ enum xfs_attr_update {int xfs_attr_set (struct xfs_da_args *args,enum xfs_attr_update op);int xfs_attr_set_iter (struct xfs_attr_intent *attr);int xfs_attr_remove_iter (struct xfs_attr_intent *attr); -bool xfs_attr_namecheck (const void *name,size_t length); +bool xfs_attr_check_namespace (unsigned int attr_flags); +bool xfs_attr_namecheck (unsigned int attr_flags,const void *name, +size_t length);int xfs_attr_calc_size (struct xfs_da_args *args,int *local);void xfs_init_attr_trans (struct xfs_da_args *args,struct xfs_trans_res *tres,unsigned int *total);
libxfs/xfs_attr_leaf.c +6 -1
@@ -947,6 +947,11 @@ xfs_attr_shortform_to_leaf( nargs.hashval =xfs_da_hashname (sfe->nameval, sfe->namelen); nargs.attr_filter = sfe->flags &XFS_ATTR_NSP_ONDISK_MASK ; +if (!xfs_attr_check_namespace (sfe->flags)) { +xfs_da_mark_sick (args); + error = -EFSCORRUPTED ; + goto out; + } error =xfs_attr3_leaf_lookup_int (bp, &nargs);/* set a->index */ ASSERT (error == -ENOATTR ); error =xfs_attr3_leaf_add (bp, &nargs);
@@ -1060,7 +1065,7 @@ xfs_attr_shortform_verify(* one namespace flag per xattr, so we can just count the * bits (i.e. hweight) here. */ -if (hweight8 (sfep->flags &XFS_ATTR_NSP_ONDISK_MASK ) >1 ) +if (!xfs_attr_check_namespace (sfep->flags))return __this_address; sfep = next_sfep;
repair/attr_repair.c +4 -3
@@ -292,7 +292,8 @@ process_shortform_attr( }/* namecheck checks for null chars in attr names. */ -if (!libxfs_attr_namecheck (currententry->nameval, +if (!libxfs_attr_namecheck (currententry->flags, + currententry->nameval, currententry->namelen)) {do_warn (_ ("entry contains illegal character in shortform attribute name\n" ));
@@ -473,7 +474,7 @@ process_leaf_attr_local( local =xfs_attr3_leaf_name_local (leaf, i);if (local->namelen ==0 || - !libxfs_attr_namecheck (local->nameval, + !libxfs_attr_namecheck (entry->flags, local->nameval, local->namelen)) { do_warn( _("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),
@@ -529,7 +530,7 @@ process_leaf_attr_remote( remotep =xfs_attr3_leaf_name_remote (leaf, i);if (remotep->namelen ==0 || - !libxfs_attr_namecheck (remotep->name, + !libxfs_attr_namecheck (entry->flags, remotep->name, remotep->namelen) ||be32_to_cpu (entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0],
PATCH 51/115 xfs: rearrange xfs_attr_match parameters
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 63211876ced33fbb730f515e8d830de53533fc82
Rearrange the parameters to this function so that they match the order of attr listent: attr_flags -> name -> namelen -> value -> valuelen.
--- libxfs/xfs_attr_leaf.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
libxfs/xfs_attr_leaf.c +12 -11
@@ -507,9 +507,9 @@ xfs_attr3_leaf_read(static bool xfs_attr_match (struct xfs_da_args *args, -uint8_t namelen, -unsigned char *name, -int flags) +unsigned int attr_flags, +const unsigned char *name, +unsigned int namelen) {if (args->namelen != namelen)
@@ -519,12 +519,12 @@ xfs_attr_match(/* Recovery ignores the INCOMPLETE flag. */ if ((args->op_flags &XFS_DA_OP_RECOVERY ) && - args->attr_filter == (flags &XFS_ATTR_NSP_ONDISK_MASK )) + args->attr_filter == (attr_flags &XFS_ATTR_NSP_ONDISK_MASK ))return true;/* All remaining matches need to be filtered by INCOMPLETE state. */ if (args->attr_filter != - (flags & (XFS_ATTR_NSP_ONDISK_MASK |XFS_ATTR_INCOMPLETE ))) + (attr_flags & (XFS_ATTR_NSP_ONDISK_MASK |XFS_ATTR_INCOMPLETE )))return false;return true; }
@@ -743,8 +743,8 @@ xfs_attr_sf_findname(for (sfe =xfs_attr_sf_firstentry (sf); sfe <xfs_attr_sf_endptr (sf); sfe =xfs_attr_sf_nextentry (sfe)) { -if (xfs_attr_match (args, sfe->namelen, sfe->nameval, - sfe->flags)) +if (xfs_attr_match (args, sfe->flags, sfe->nameval, + sfe->namelen))return sfe; }
@@ -2440,15 +2440,16 @@ xfs_attr3_leaf_lookup_int(*/ if (entry->flags &XFS_ATTR_LOCAL ) { name_loc =xfs_attr3_leaf_name_local (leaf, probe); -if (!xfs_attr_match (args, name_loc->namelen, - name_loc->nameval, entry->flags)) +if (!xfs_attr_match (args, entry->flags, + name_loc->nameval, + name_loc->namelen))continue ; args->index = probe;return -EEXIST ; }else { name_rmt =xfs_attr3_leaf_name_remote (leaf, probe); -if (!xfs_attr_match (args, name_rmt->namelen, - name_rmt->name, entry->flags)) +if (!xfs_attr_match (args, entry->flags, name_rmt->name, + name_rmt->namelen))continue ; args->index = probe; args->rmtvaluelen =be32_to_cpu (name_rmt->valuelen);
PATCH 52/115 xfs: check the flags earlier in xfs_attr_match
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: f49af061f49c004fb6df7f791f39f9ed370f767b
Checking the flags match is much cheaper than a memcmp, so do it early on in xfs_attr_match, and also add a little helper to calculate the match mask right under the comment explaining the logic for it.
--- libxfs/xfs_attr_leaf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
libxfs/xfs_attr_leaf.c +10 -9
@@ -504,6 +504,13 @@ xfs_attr3_leaf_read(* INCOMPLETE flag will not be set in attr->attr_filter, but rather * XFS_DA_OP_RECOVERY will be set in args->op_flags. */ +static inline unsigned int xfs_attr_match_mask (const struct xfs_da_args *args) +{ +if (args->op_flags &XFS_DA_OP_RECOVERY ) +return XFS_ATTR_NSP_ONDISK_MASK ; +return XFS_ATTR_NSP_ONDISK_MASK |XFS_ATTR_INCOMPLETE ; +} + static bool xfs_attr_match( struct xfs_da_args *args,
@@ -511,21 +518,15 @@ xfs_attr_match(const unsigned char *name, unsigned int namelen) { + unsigned int mask = xfs_attr_match_mask(args);if (args->namelen != namelen)return false; +if ((args->attr_filter & mask) != (attr_flags & mask)) +return false;if (memcmp (args->name, name, namelen) !=0 )return false; -/* Recovery ignores the INCOMPLETE flag. */ -if ((args->op_flags &XFS_DA_OP_RECOVERY ) && - args->attr_filter == (attr_flags &XFS_ATTR_NSP_ONDISK_MASK )) -return true; - -/* All remaining matches need to be filtered by INCOMPLETE state. */ -if (args->attr_filter != - (attr_flags & (XFS_ATTR_NSP_ONDISK_MASK |XFS_ATTR_INCOMPLETE ))) -return false;return true; }
PATCH 53/115 xfs: move xfs_attr_defer_add to xfs_attr_item.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 9713dc88773d066413ae23aa474b13241507a89e
Move the code that adds the incore xfs_attr_item deferred work data to a transaction live with the ATTRI log item code. This means that the upper level extended attribute code no longer has to know about the inner workings of the ATTRI log items.
--- libxfs/defer_item.c | 28 ++++++++++++++++++++++++++++ libxfs/defer_item.h | 8 ++++++++ libxfs/xfs_attr.c | 38 ++++---------------------------------- 3 files changed, 40 insertions(+), 34 deletions(-)
libxfs/defer_item.c +28 -0
@@ -670,6 +670,34 @@ xfs_attr_cancel_item(xfs_attr_free_item (attr); } +void +xfs_attr_defer_add ( +struct xfs_da_args *args, +enum xfs_attr_defer_op op) +{ +struct xfs_attr_intent *new; + + new =kmem_cache_zalloc (xfs_attr_intent_cache,GFP_NOFS | __GFP_NOFAIL); + new->xattri_da_args = args; + +switch (op) { +case XFS_ATTR_DEFER_SET : + new->xattri_op_flags =XFS_ATTRI_OP_FLAGS_SET ; + new->xattri_dela_state =xfs_attr_init_add_state (args); +break ; +case XFS_ATTR_DEFER_REPLACE : + new->xattri_op_flags =XFS_ATTRI_OP_FLAGS_REPLACE ; + new->xattri_dela_state =xfs_attr_init_replace_state (args); +break ; +case XFS_ATTR_DEFER_REMOVE : + new->xattri_op_flags =XFS_ATTRI_OP_FLAGS_REMOVE ; + new->xattri_dela_state =xfs_attr_init_remove_state (args); +break ; + } + +xfs_defer_add (args->trans, &new->xattri_list, &xfs_attr_defer_type); +} +const struct xfs_defer_op_type xfs_attr_defer_type = { .name ="attr" , .max_items =1 ,
libxfs/defer_item.h +8 -0
@@ -10,6 +10,14 @@ struct xfs_bmap_intent;void xfs_bmap_defer_add (struct xfs_trans *tp,struct xfs_bmap_intent *bi); +enum xfs_attr_defer_op { +XFS_ATTR_DEFER_SET , +XFS_ATTR_DEFER_REMOVE , +XFS_ATTR_DEFER_REPLACE , +}; + +void xfs_attr_defer_add (struct xfs_da_args *args,enum xfs_attr_defer_op op); +struct xfs_exchmaps_intent ; void xfs_exchmaps_defer_add(struct xfs_trans *tp,
libxfs/xfs_attr.c +4 -34
@@ -24,6 +24,7 @@#include "xfs_quota_defs.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "defer_item.h" struct kmem_cache *xfs_attr_intent_cache;
@@ -899,37 +900,6 @@ xfs_attr_lookup(return error; } -static void -xfs_attr_defer_add ( -struct xfs_da_args *args, -unsigned int op_flags) -{ - -struct xfs_attr_intent *new; - - new =kmem_cache_zalloc (xfs_attr_intent_cache, -GFP_KERNEL | __GFP_NOFAIL); - new->xattri_op_flags = op_flags; - new->xattri_da_args = args; - -switch (op_flags) { -case XFS_ATTRI_OP_FLAGS_SET : - new->xattri_dela_state =xfs_attr_init_add_state (args); -break ; -case XFS_ATTRI_OP_FLAGS_REPLACE : - new->xattri_dela_state =xfs_attr_init_replace_state (args); -break ; -case XFS_ATTRI_OP_FLAGS_REMOVE : - new->xattri_dela_state =xfs_attr_init_remove_state (args); -break ; -default : -ASSERT (0 ); - } - -xfs_defer_add (args->trans, &new->xattri_list, &xfs_attr_defer_type); -trace_xfs_attr_defer_add (new->xattri_dela_state, args->dp); -} - int xfs_attr_set( struct xfs_da_args *args,
@@ -1019,14 +989,14 @@ xfs_attr_set(case -EEXIST :if (op ==XFS_ATTRUPDATE_REMOVE ) {/* if no value, we are performing a remove operation */ -xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_REMOVE ); +xfs_attr_defer_add (args,XFS_ATTR_DEFER_REMOVE );break ; }/* Pure create fails if the attr already exists */ if (op ==XFS_ATTRUPDATE_CREATE ) goto out_trans_cancel; -xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_REPLACE ); +xfs_attr_defer_add (args,XFS_ATTR_DEFER_REPLACE );break ;case -ENOATTR :/* Can't remove what isn't there. */
@@ -1036,7 +1006,7 @@ xfs_attr_set(/* Pure replace fails if no existing attr to replace. */ if (op ==XFS_ATTRUPDATE_REPLACE ) goto out_trans_cancel; -xfs_attr_defer_add (args,XFS_ATTRI_OP_FLAGS_SET ); +xfs_attr_defer_add (args,XFS_ATTR_DEFER_SET );break ;default : goto out_trans_cancel;
PATCH 54/115 xfs: create a separate hashname function for extended attributes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a64e0134754bf88021e937aa34f1fbb5b524e585
Create a separate function to compute name hashvalues for extended attributes. When we get to parent pointers we'll be altering the rules so that metadump obfuscation doesn't turn heinous.
--- libxfs/xfs_attr.c | 28 ++++++++++++++++++++++++++-- libxfs/xfs_attr.h | 14 ++++++++++++++ libxfs/xfs_attr_leaf.c | 3 +-- 3 files changed, 41 insertions(+), 4 deletions(-)
libxfs/xfs_attr.c +26 -2
@@ -279,7 +279,7 @@ xfs_attr_get( args->owner = args->dp->i_ino; args->geo = args->dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; - args->hashval =xfs_da_hashname (args->name, args->namelen); +xfs_attr_sethash (args);/* Entirely possible to look up a name which doesn't exist */ args->op_flags =XFS_DA_OP_OKNOENT ;
@@ -414,6 +414,30 @@ xfs_attr_sf_addname(return error; } +/* Compute the hash value for a user/root/secure extended attribute */ +xfs_dahash_t +xfs_attr_hashname ( +const uint8_t *name, +int namelen) +{ +return xfs_da_hashname (name, namelen); +} + +/* Compute the hash value for any extended attribute from any namespace. */ +xfs_dahash_t +xfs_attr_hashval ( +struct xfs_mount *mp, +unsigned int attr_flags, +const uint8_t *name, +int namelen, +const void *value, +int valuelen) +{ +ASSERT (xfs_attr_check_namespace (attr_flags)); + +return xfs_attr_hashname (name, namelen); +} +/* * Handle the state change on completion of a multi-state attr operation. *
@@ -924,7 +948,7 @@ xfs_attr_set( args->owner = args->dp->i_ino; args->geo = mp->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; - args->hashval =xfs_da_hashname (args->name, args->namelen); +xfs_attr_sethash (args);/* * We have no control over the attribute names that userspace passes us
libxfs/xfs_attr.h +14 -0
@@ -628,6 +628,20 @@ xfs_attr_init_replace_state(struct xfs_da_args *args)return xfs_attr_init_add_state (args); } +xfs_dahash_t xfs_attr_hashname (const uint8_t *name,int namelen); + +xfs_dahash_t xfs_attr_hashval (struct xfs_mount *mp,unsigned int attr_flags, +const uint8_t *name,int namelen,const void *value, +int valuelen); + +/* Set the hash value for any extended attribute from any namespace. */ +static inline void xfs_attr_sethash (struct xfs_da_args *args) +{ + args->hashval =xfs_attr_hashval (args->dp->i_mount, args->attr_filter, + args->name, args->namelen, + args->value, args->valuelen); +} +extern struct kmem_cache *xfs_attr_intent_cache;int __init xfs_attr_intent_init_cache (void );void xfs_attr_intent_destroy_cache (void );
libxfs/xfs_attr_leaf.c +1 -2
@@ -945,14 +945,13 @@ xfs_attr_shortform_to_leaf( nargs.namelen = sfe->namelen; nargs.value = &sfe->nameval[nargs.namelen]; nargs.valuelen = sfe->valuelen; - nargs.hashval =xfs_da_hashname (sfe->nameval, - sfe->namelen); nargs.attr_filter = sfe->flags &XFS_ATTR_NSP_ONDISK_MASK ;if (!xfs_attr_check_namespace (sfe->flags)) {xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto out; } +xfs_attr_sethash (&nargs); error =xfs_attr3_leaf_lookup_int (bp, &nargs);/* set a->index */ ASSERT (error == -ENOATTR ); error =xfs_attr3_leaf_add (bp, &nargs);
PATCH 55/115 xfs: add parent pointer support to attribute code
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 98493ff878859eb0adefbc57a49ad47a92dfd252
Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT.
--- libxfs/xfs_da_format.h | 9 +++++++-- libxfs/xfs_log_format.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
libxfs/xfs_da_format.h +7 -2
@@ -714,13 +714,17 @@ struct xfs_attr3_leafblock {#define XFS_ATTR_LOCAL_BIT 0/* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1/* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2/* limit access to secure attrs */ +#define XFS_ATTR_PARENT_BIT 3/* parent pointer attrs */ #define XFS_ATTR_INCOMPLETE_BIT 7/* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1u << XFS_ATTR_LOCAL_BIT)#define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT)#define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) +#define XFS_ATTR_PARENT (1u << XFS_ATTR_PARENT_BIT)#define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) -#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | \ + XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT)#define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ XFS_ATTR_LOCAL | \
@@ -729,7 +733,8 @@ struct xfs_attr3_leafblock {#define XFS_ATTR_NAMESPACE_STR \ { XFS_ATTR_LOCAL, "local" }, \ { XFS_ATTR_ROOT, "root" }, \ - { XFS_ATTR_SECURE, "secure" } + { XFS_ATTR_SECURE, "secure" }, \ + { XFS_ATTR_PARENT, "parent" }/* * Alignment for namelist and valuelist entries (since they are mixed
libxfs/xfs_log_format.h +1 -0
@@ -1034,6 +1034,7 @@ struct xfs_icreate_log {*/ #define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \ XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT | \ XFS_ATTR_INCOMPLETE)/*
PATCH 56/115 xfs: define parent pointer ondisk extended attribute format
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 8337d58ab2868f231a29824cd86d2e309bd36fa9
We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information:
name={dirent name}
value={parent inumber, parent inode generation} hash=xfs_dir2_hashname(dirent name) ^ (parent_inumber)
The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls.
By using the name-value lookup mode in the extended attribute code to match parent pointers using both the xattr name and value, we can identify the exact parent pointer EA we need to modify/remove in rename/unlink operations without searching the entire EA space.
By storing the dirent name, we have enough information to be able to validate and reconstruct damaged directory trees. Earlier iterations of this patchset encoded the directory offset in the parent pointer key, but this format required repair to keep that in sync across directory rebuilds, which is unnecessary complexity.
--- libxfs/xfs_da_format.h | 13 +++++++++++++ libxfs/xfs_ondisk.h | 1 + 2 files changed, 14 insertions(+)
libxfs/xfs_da_format.h +13 -0
@@ -890,4 +890,17 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp)xfs_failaddr_t xfs_da3_blkinfo_verify (struct xfs_buf *bp,struct xfs_da3_blkinfo *hdr3); +/* +* Parent pointer attribute format definition +* +* The xattr name contains the dirent name. +* The xattr value encodes the parent inode number and generation to ease +* opening parents by handle. +* The xattr hashval is xfs_dir2_namehash() ^ p_ino +*/ +struct xfs_parent_rec { +__be64 p_ino; +__be32 p_gen; +} __packed; +#endif /* __XFS_DA_FORMAT_H__ */
libxfs/xfs_ondisk.h +1 -0
@@ -119,6 +119,7 @@ xfs_check_ondisk_structs(void)XFS_CHECK_OFFSET (xfs_dir2_sf_entry_t, offset,1 );XFS_CHECK_OFFSET (xfs_dir2_sf_entry_t, name,3 );XFS_CHECK_STRUCT_SIZE (xfs_dir2_sf_hdr_t,10 ); + XFS_CHECK_STRUCT_SIZE(struct xfs_parent_rec, 12);/* log structures */ XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88);
PATCH 57/115 xfs: allow xattr matching on name and value for parent pointers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f041455eb5773eda3291903ad6d1f33d4798e9a2
If a file is hardlinked with the same name but from multiple parents, the parent pointers will all have the same dirent name (== attr name) but with different parent_ino/parent_gen values. To disambiguate, we need to be able to match on both the attr name and the attr value. This is in contrast to regular xattrs, which are matchtg edit
d only on name.
Therefore, plumb in the ability to match shortform and local attrs on name and value in the XFS_ATTR_PARENT namespace. Parent pointer attr values are never large enough to be stored in a remote attr, so we need can reject these cases as corruption.
--- libxfs/xfs_attr_leaf.c | 52 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-)
libxfs/xfs_attr_leaf.c +46 -6
@@ -511,12 +511,37 @@ static inline unsigned int xfs_attr_match_mask(const struct xfs_da_args *args)return XFS_ATTR_NSP_ONDISK_MASK |XFS_ATTR_INCOMPLETE ; } +static inline bool +xfs_attr_parent_match ( +const struct xfs_da_args *args, +const void *value, +unsigned int valuelen) +{ +ASSERT (args->value !=NULL ); + +/* Parent pointers do not use remote values */ +if (!value) +return false; + +/* +* The only value we support is a parent rec. However, we'll accept +* any valuelen so that offline repair can delete ATTR_PARENT values +* that are not parent pointers. +*/ +if (valuelen != args->valuelen) +return false; + +return memcmp (args->value, value, valuelen) ==0 ; +} +static bool xfs_attr_match (struct xfs_da_args *args,unsigned int attr_flags,const unsigned char *name, -unsigned int namelen) +unsigned int namelen, +const void *value, +unsigned int valuelen) {unsigned int mask =xfs_attr_match_mask (args);
@@ -527,6 +552,9 @@ xfs_attr_match(if (memcmp (args->name, name, namelen) !=0 )return false; +if (attr_flags &XFS_ATTR_PARENT ) +return xfs_attr_parent_match (args, value, valuelen); +return true; }
@@ -536,6 +564,13 @@ xfs_attr_copy_value( unsigned char *value, int valuelen) { +/* +* Parent pointer lookups require the caller to specify the name and +* value, so don't copy anything. +*/ +if (args->attr_filter &XFS_ATTR_PARENT ) +return 0 ; +/* * No copy if all we have to do is get the length */
@@ -745,7 +780,8 @@ xfs_attr_sf_findname( sfe <xfs_attr_sf_endptr (sf); sfe = xfs_attr_sf_nextentry(sfe)) {if (xfs_attr_match (args, sfe->flags, sfe->nameval, - sfe->namelen)) + sfe->namelen, &sfe->nameval[sfe->namelen], + sfe->valuelen))return sfe; }
@@ -2441,18 +2477,22 @@ xfs_attr3_leaf_lookup_int(if (entry->flags &XFS_ATTR_LOCAL ) { name_loc =xfs_attr3_leaf_name_local (leaf, probe);if (!xfs_attr_match (args, entry->flags, - name_loc->nameval, - name_loc->namelen)) + name_loc->nameval, name_loc->namelen, + &name_loc->nameval[name_loc->namelen], +be16_to_cpu (name_loc->valuelen)))continue ; args->index = probe;return -EEXIST ; }else { +unsigned int valuelen; + name_rmt =xfs_attr3_leaf_name_remote (leaf, probe); + valuelen =be32_to_cpu (name_rmt->valuelen);if (!xfs_attr_match (args, entry->flags, name_rmt->name, - name_rmt->namelen)) + name_rmt->namelen,NULL , valuelen))continue ; args->index = probe; - args->rmtvaluelen =be32_to_cpu (name_rmt->valuelen); + args->rmtvaluelen = valuelen; args->rmtblkno =be32_to_cpu (name_rmt->valueblk); args->rmtblkcnt = xfs_attr3_rmt_blocks( args->dp->i_mount,
PATCH 58/115 xfs: create attr log item opcodes and formats for parent pointers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 5773f7f82be5aa98e4883566072d33342814cebe
Make the necessary alterations to the extended attribute log intent item ondisk format so that we can log parent pointer operations. This requires the creation of new opcodes specific to parent pointers, and a new four-argument replace operation to handle renames. At this point this part of the patchset has changed so much from what Allison original wrote that I no longer think her SoB applies.
--- libxfs/xfs_attr.c | 19 +++++++++++++++++++ libxfs/xfs_attr.h | 4 ++-- libxfs/xfs_da_btree.h | 4 ++++ libxfs/xfs_log_format.h | 22 +++++++++++++++++++--- 4 files changed, 44 insertions(+), 5 deletions(-)
libxfs/xfs_attr.c +19 -0
@@ -438,6 +438,23 @@ xfs_attr_hashval(return xfs_attr_hashname (name, namelen); } +/* +* PPTR_REPLACE operations require the caller to set the old and new names and +* values explicitly. Update the canonical fields to the new name and value +* here now that the removal phase has finished. +*/ +static void +xfs_attr_update_pptr_replace_args ( +struct xfs_da_args *args) +{ +ASSERT (args->new_namelen >0 ); + args->name = args->new_name; + args->namelen = args->new_namelen; + args->value = args->new_value; + args->valuelen = args->new_valuelen; +xfs_attr_sethash (args); +} +/* * Handle the state change on completion of a multi-state attr operation. *
@@ -458,6 +475,8 @@ xfs_attr_complete_op(if (!(args->op_flags &XFS_DA_OP_REPLACE )) replace_state =XFS_DAS_DONE ; +else if (xfs_attr_intent_op (attr) ==XFS_ATTRI_OP_FLAGS_PPTR_REPLACE ) +xfs_attr_update_pptr_replace_args (args); args->op_flags &= ~XFS_DA_OP_REPLACE ; args->attr_filter &= ~XFS_ATTR_INCOMPLETE ;
libxfs/xfs_attr.h +2 -2
@@ -510,8 +510,8 @@ struct xfs_attr_intent {struct xfs_da_args *xattri_da_args;/* -* Shared buffer containing the attr name and value so that the logging -* code can share large memory buffers between log items. +* Shared buffer containing the attr name, new name, and value so that +* the logging code can share large memory buffers between log items. */ struct xfs_attri_log_nameval *xattri_nameval;
libxfs/xfs_da_btree.h +4 -0
@@ -55,7 +55,9 @@ enum xfs_dacmp { typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ const uint8_t *name; /* string (maybe not NULL terminated) */ + const uint8_t *new_name; /* new attr name */ void *value; /* set of bytes (maybe contain NULLs) */ + void *new_value; /* new xattr value (may contain NULLs) */ struct xfs_inode *dp; /* directory inode to manipulate */ struct xfs_trans *trans; /* current trans (changes over time) */
@@ -63,10 +65,12 @@ typedef struct xfs_da_args {xfs_ino_t owner;/* inode that owns the dir/attr data */ int valuelen;/* length of value */ +int new_valuelen;/* length of new_value */ uint8_t filetype;/* filetype of inode for directories */ uint8_t op_flags;/* operation flags */ uint8_t attr_filter;/* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ short namelen;/* length of string (maybe no NULL) */ +short new_namelen;/* length of new attr name */ xfs_dahash_t hashval;/* hash value of name */ xfs_extlen_t total;/* total blocks needed, for 1st bmap */ int whichfork;/* data or attribute fork */
libxfs/xfs_log_format.h +19 -3
@@ -115,11 +115,13 @@ struct xfs_unmount_log_format {#define XLOG_REG_TYPE_BUD_FORMAT 26#define XLOG_REG_TYPE_ATTRI_FORMAT 27#define XLOG_REG_TYPE_ATTRD_FORMAT 28 -#define XLOG_REG_TYPE_ATTR_NAME 29 +#define XLOG_REG_TYPE_ATTR_NAME 29#define XLOG_REG_TYPE_ATTR_VALUE 30#define XLOG_REG_TYPE_XMI_FORMAT 31#define XLOG_REG_TYPE_XMD_FORMAT 32 -#define XLOG_REG_TYPE_MAX 32 +#define XLOG_REG_TYPE_ATTR_NEWNAME 33 +#define XLOG_REG_TYPE_ATTR_NEWVALUE 34 +#define XLOG_REG_TYPE_MAX 34/* * Flags to log operation header
@@ -1026,6 +1028,9 @@ struct xfs_icreate_log {#define XFS_ATTRI_OP_FLAGS_SET 1/* Set the attribute */ #define XFS_ATTRI_OP_FLAGS_REMOVE 2/* Remove the attribute */ #define XFS_ATTRI_OP_FLAGS_REPLACE 3/* Replace the attribute */ +#define XFS_ATTRI_OP_FLAGS_PPTR_SET 4/* Set parent pointer */ +#define XFS_ATTRI_OP_FLAGS_PPTR_REMOVE 5/* Remove parent pointer */ +#define XFS_ATTRI_OP_FLAGS_PPTR_REPLACE 6/* Replace parent pointer */ #define XFS_ATTRI_OP_FLAGS_TYPE_MASK 0xFF/* Flags type mask */ /*
@@ -1048,7 +1053,18 @@ struct xfs_attri_log_format {uint64_t alfi_id;/* attri identifier */ uint64_t alfi_ino;/* the inode for this attr operation */ uint32_t alfi_op_flags;/* marks the op as a set or remove */ -uint32_t alfi_name_len;/* attr name length */ +union { +uint32_t alfi_name_len;/* attr name length */ +struct { +/* +* For PPTR_REPLACE, these are the lengths of the old +* and new attr names. The new and old values must +* have the same length. +*/ +uint16_t alfi_old_name_len; +uint16_t alfi_new_name_len; + }; + };uint32_t alfi_value_len;/* attr value length */ uint32_t alfi_attr_filter;/* attr filter flags */ };
PATCH 59/115 xfs: record inode generation in xattr update log intent items
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ae673f534a30976ce5e709c4535a59c12b786ef3
For parent pointer updates, record the i_generation of the file that is being updated so that we don't accidentally jump generations.
--- libxfs/xfs_log_format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_log_format.h +1 -1
@@ -1049,7 +1049,7 @@ struct xfs_icreate_log {struct xfs_attri_log_format {uint16_t alfi_type;/* attri log item type */ uint16_t alfi_size;/* size of this item */ -uint32_t __pad;/* pad to 64 bit aligned */ +uint32_t alfi_igen;/* generation of alfi_ino for pptr ops */ uint64_t alfi_id;/* attri identifier */ uint64_t alfi_ino;/* the inode for this attr operation */ uint32_t alfi_op_flags;/* marks the op as a set or remove */
PATCH 60/115 xfs: add parent pointer validator functions
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: a08d6729637428b6ef8c6a5a94d8c6db7b805a44
The attr name of a parent pointer is a string, and the attr value of a parent pointer is (more or less) a file handle. So we need to modify attr_namecheck to verify the parent pointer name, and add a xfs_parent_valuecheck function to sanitize the handle. At the same time, we need to validate attr values during log recovery if the xattr is really a parent pointer.
--- libxfs/Makefile | 2 + libxfs/xfs_attr.c | 5 +++ libxfs/xfs_parent.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 15 +++++++++ 4 files changed, 111 insertions(+) create mode 100644 libxfs/xfs_parent.c create mode 100644 libxfs/xfs_parent.h
libxfs/Makefile +2 -0
@@ -50,6 +50,7 @@ HFILES = \ xfs_ialloc_btree.h \ xfs_inode_buf.h \ xfs_inode_fork.h \ + xfs_parent.h \ xfs_quota_defs.h \ xfs_refcount.h \ xfs_refcount_btree.h \
@@ -102,6 +103,7 @@ CFILES = buf_mem.c \ xfs_inode_fork.c \ xfs_ialloc_btree.c \ xfs_log_rlimit.c \ + xfs_parent.c \ xfs_refcount.c \ xfs_refcount_btree.c \ xfs_rmap.c \
libxfs/xfs_attr.c +5 -0
@@ -25,6 +25,7 @@#include "xfs_trans_space.h" #include "xfs_trace.h" #include "defer_item.h" +#include "xfs_parent.h" struct kmem_cache *xfs_attr_intent_cache;
@@ -1567,6 +1568,10 @@ xfs_attr_namecheck(if (length >=MAXNAMELEN )return false; +/* Parent pointers have their own validation. */ +if (attr_flags &XFS_ATTR_PARENT ) +return xfs_parent_namecheck (attr_flags, name, length); +/* There shouldn't be any nulls here */ return !memchr (name,0 , length); }
libxfs/xfs_parent.c new file +89 -0
89 lines not on this page · raw message
libxfs/xfs_parent.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022-2024 Oracle. +* All Rights Reserved. +*/ +#ifndef __XFS_PARENT_H__ +#define __XFS_PARENT_H__ + +/* Metadata validators */ +bool xfs_parent_namecheck (unsigned int attr_flags,const void *name, +size_t length); +bool xfs_parent_valuecheck (struct xfs_mount *mp,const void *value, +size_t valuelen); + +#endif /* __XFS_PARENT_H__ */
PATCH 61/115 xfs: extend transaction reservations for parent attributes
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 7dba4a5fe1c5cdf0859830380c52f29295cbf345
We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations.
--- libxfs/libxfs_priv.h | 1 libxfs/xfs_trans_resv.c | 324 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 273 insertions(+), 52 deletions(-)
libxfs/libxfs_priv.h +1 -0
@@ -492,6 +492,7 @@ static inline int retzero(void) { return 0; }#define xfs_icreate_log (tp, agno, agbno, cnt, isize, len, gen) ((void) 0)#define xfs_sb_validate_fsb_count (sbp, nblks) (0) +#define xlog_calc_iovec_len (len) roundup(len, sizeof(uint32_t))/* * Prototypes for kernel static functions that are aren't in their
libxfs/xfs_trans_resv.c +272 -52
418 lines not on this page · raw message
PATCH 62/115 xfs: create a hashname function for parent pointers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: fb102fe7fe02e70f8a49cc7f74bc0769cdab2912
Although directory entry and parent pointer recordsets look very similar (name -> ino), there's one major difference between them: a file can be hardlinked from multiple parent directories with the same filename. This is common in shared container environments where a base directory tree might be hardlink-copied multiple times. IOWs the same 'ls' program might be hardlinked to multiple /srv/*/bin/ls paths.
We don't want parent pointer operations to bog down on hash collisions between the same dirent name, so create a special hash function that mixes in the parent directory inode number.
--- libxfs/libxfs_priv.h | 18 ++++++++++++++++++ libxfs/xfs_attr.c | 3 +++ libxfs/xfs_parent.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++++ 4 files changed, 73 insertions(+)
libxfs/libxfs_priv.h +18 -0
@@ -618,4 +618,22 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,/* xfs_inode.h */ #define xfs_iflags_set (ip, flags) do { } while (0) +/* linux/wordpart.h */ + +/** +* upper_32_bits - return bits 32-63 of a number +* @n: the number we're accessing +* +* A basic shift-right of a 64- or 32-bit quantity. Use this to suppress +* the "right shift count >= width of type" warning when that quantity is +* 32-bits. +*/ +#define upper_32_bits (n) ((uint32_t)(((n) >> 16) >> 16)) + +/** +* lower_32_bits - return bits 0-31 of a number +* @n: the number we're accessing +*/ +#define lower_32_bits (n) ((uint32_t)((n) & 0xffffffff)) +#endif /* __LIBXFS_INTERNAL_XFS_H__ */
libxfs/xfs_attr.c +3 -0
@@ -436,6 +436,9 @@ xfs_attr_hashval( {ASSERT (xfs_attr_check_namespace (attr_flags)); +if (attr_flags &XFS_ATTR_PARENT ) +return xfs_parent_hashattr (mp, name, namelen, value, valuelen); +return xfs_attr_hashname (name, namelen); }
libxfs/xfs_parent.c +47 -0
50 lines not on this page · raw message
libxfs/xfs_parent.h +5 -0
@@ -12,4 +12,9 @@ bool xfs_parent_namecheck(unsigned int attr_flags, const void *name,bool xfs_parent_valuecheck (struct xfs_mount *mp,const void *value,size_t valuelen); +xfs_dahash_t xfs_parent_hashval (struct xfs_mount *mp,const uint8_t *name, +int namelen,xfs_ino_t parent_ino); +xfs_dahash_t xfs_parent_hashattr (struct xfs_mount *mp,const uint8_t *name, +int namelen,const void *value,int valuelen); +#endif /* __XFS_PARENT_H__ */
PATCH 63/115 xfs: parent pointer attribute creation
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: b7c62d90c12c6cc86f10b8a62cefe0029374b6ff
Add parent pointer attribute during xfs_create, and subroutines to initialize attributes. Note that the xfs_attr_intent object contains a pointer to the caller's xfs_da_args object, so the latter must persist until transaction commit.
[djwong: shorten names, adjust to new format, set init_xattrs for parent pointers]
--- include/libxfs.h | 1 + include/xfs_inode.h | 6 ++++ libxfs/Makefile | 1 + libxfs/init.c | 3 ++ libxfs/libxfs_api_defs.h | 2 + libxfs/xfs_parent.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 65 ++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_trans_space.c | 52 +++++++++++++++++++++++++++++++++++ libxfs/xfs_trans_space.h | 9 +++--- repair/phase6.c | 8 +++-- 10 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 libxfs/xfs_trans_space.c
include/libxfs.h +1 -0
@@ -90,6 +90,7 @@ struct iomap;#include "libxfs/xfile.h" #include "libxfs/buf_mem.h" #include "xfs_btree_mem.h" +#include "xfs_parent.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))
include/xfs_inode.h +6 -0
@@ -268,6 +268,12 @@ static inline struct inode *VFS_I(struct xfs_inode *ip)return &ip->i_vnode; } +/* convert from const xfs inode to const vfs inode */ +static inline const struct inode *VFS_IC (const struct xfs_inode *ip) +{ +return &ip->i_vnode; +} +/* We only have i_size in the xfs inode in userspace */ static inline loff_t i_size_read (struct inode *inode) {
libxfs/Makefile +1 -0
@@ -113,6 +113,7 @@ CFILES = buf_mem.c \ xfs_symlink_remote.c \ xfs_trans_inode.c \ xfs_trans_resv.c \ + xfs_trans_space.c \ xfs_types.c #
libxfs/init.c +3 -0
@@ -214,6 +214,8 @@ init_caches(void) "xfs_extfree_item"); xfs_trans_cache =kmem_cache_init (sizeof (struct xfs_trans ),"xfs_trans" ); + xfs_parent_args_cache =kmem_cache_init ( +sizeof (struct xfs_parent_args ),"xfs_parent_args" ); } static int
@@ -231,6 +233,7 @@ destroy_caches(void)xfs_btree_destroy_cur_caches (); leaked +=kmem_cache_destroy (xfs_extfree_item_cache); leaked +=kmem_cache_destroy (xfs_trans_cache); + leaked +=kmem_cache_destroy (xfs_parent_args_cache);return leaked; }
libxfs/libxfs_api_defs.h +2 -0
@@ -98,6 +98,7 @@#define xfs_calc_dquots_per_chunk libxfs_calc_dquots_per_chunk#define xfs_cntbt_init_cursor libxfs_cntbt_init_cursor#define xfs_compute_rextslog libxfs_compute_rextslog +#define xfs_create_space_res libxfs_create_space_res#define xfs_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk#define xfs_da_get_buf libxfs_da_get_buf#define xfs_da_hashname libxfs_da_hashname
@@ -186,6 +187,7 @@#define xfs_log_get_max_trans_res libxfs_log_get_max_trans_res#define xfs_log_sb libxfs_log_sb#define xfs_mode_to_ftype libxfs_mode_to_ftype +#define xfs_mkdir_space_res libxfs_mkdir_space_res#define xfs_perag_get libxfs_perag_get#define xfs_perag_hold libxfs_perag_hold#define xfs_perag_put libxfs_perag_put
libxfs/xfs_parent.c +68 -0
77 lines not on this page · raw message
libxfs/xfs_parent.h +65 -0
69 lines not on this page · raw message
libxfs/xfs_trans_space.c new file +52 -0
52 lines not on this page · raw message
libxfs/xfs_trans_space.h +5 -4
@@ -80,8 +80,6 @@/* This macro is not used - see inline code in xfs_attr_set */ #define XFS_ATTRSET_SPACE_RES (mp, v) \ (XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v)) -#define XFS_CREATE_SPACE_RES (mp,nl) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))#define XFS_DIOSTRAT_SPACE_RES (mp, v) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v))#define XFS_GROWFS_SPACE_RES (mp) \
@@ -90,8 +88,6 @@ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK))#define XFS_LINK_SPACE_RES (mp,nl) \ XFS_DIRENTER_SPACE_RES(mp,nl) -#define XFS_MKDIR_SPACE_RES (mp,nl) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))#define XFS_QM_DQALLOC_SPACE_RES (mp) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \ XFS_DQUOT_CLUSTER_SIZE_FSB)
@@ -106,5 +102,10 @@#define XFS_IFREE_SPACE_RES (mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) +unsigned int xfs_parent_calc_space_res (struct xfs_mount *mp, +unsigned int namelen); + +unsigned int xfs_create_space_res (struct xfs_mount *mp,unsigned int namelen); +unsigned int xfs_mkdir_space_res (struct xfs_mount *mp,unsigned int namelen);#endif /* __XFS_TRANS_SPACE_H__ */
repair/phase6.c +4 -4
@@ -927,7 +927,7 @@ mk_orphanage(xfs_mount_t *mp)/* * could not be found, create it */ - nres =XFS_MKDIR_SPACE_RES (mp, xname.len); + nres =libxfs_mkdir_space_res (mp, xname.len); i = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_mkdir, nres,0 ,0 , &tp);if (i)res_failed (i);
@@ -1343,7 +1343,7 @@ longform_dir2_rebuild( p->name.name[1] == '.'))))continue ; - nres =XFS_CREATE_SPACE_RES (mp, p->name.len); + nres =libxfs_create_space_res (mp, p->name.len); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_create, nres,0 ,0 , &tp);if (error)
@@ -2955,7 +2955,7 @@ _("error %d fixing shortform directory %llu\n"),do_warn (_ ("recreating root directory .. entry\n" )); - nres =XFS_MKDIR_SPACE_RES (mp,2 ); + nres =libxfs_mkdir_space_res (mp,2 ); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_mkdir, nres,0 ,0 , &tp);if (error)
@@ -3010,7 +3010,7 @@ _("error %d fixing shortform directory %llu\n"),do_warn (_ ("creating missing \".\" entry in dir ino %" PRIu64"\n" ), ino); - nres =XFS_MKDIR_SPACE_RES (mp,1 ); + nres =libxfs_mkdir_space_res (mp,1 ); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_mkdir, nres,0 ,0 , &tp);if (error)
PATCH 64/115 xfs: add parent attributes to link
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: f1097be220fa938de5114db57a1ddb5de2bf6046
This patch modifies xfs_link to add a parent pointer to the inode.
--- libxfs/xfs_trans_space.c | 14 ++++++++++++++ libxfs/xfs_trans_space.h | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-)
libxfs/xfs_trans_space.c +14 -0
@@ -50,3 +50,17 @@ xfs_mkdir_space_res( {return xfs_create_space_res (mp, namelen); } + +unsigned int +xfs_link_space_res ( +struct xfs_mount *mp, +unsigned int namelen) +{ +unsigned int ret; + + ret =XFS_DIRENTER_SPACE_RES (mp, namelen); +if (xfs_has_parent (mp)) + ret +=xfs_parent_calc_space_res (mp, namelen); + +return ret; +}
libxfs/xfs_trans_space.h +1 -2
@@ -86,8 +86,6 @@ (2 * (mp)->m_alloc_maxlevels)#define XFS_GROWFSRT_SPACE_RES (mp,b) \ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK)) -#define XFS_LINK_SPACE_RES (mp,nl) \ - XFS_DIRENTER_SPACE_RES(mp,nl)#define XFS_QM_DQALLOC_SPACE_RES (mp) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \ XFS_DQUOT_CLUSTER_SIZE_FSB)
@@ -107,5 +105,6 @@ unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp,unsigned int xfs_create_space_res (struct xfs_mount *mp,unsigned int namelen);unsigned int xfs_mkdir_space_res (struct xfs_mount *mp,unsigned int namelen); +unsigned int xfs_link_space_res (struct xfs_mount *mp,unsigned int namelen);#endif /* __XFS_TRANS_SPACE_H__ */
PATCH 65/115 xfs: add parent attributes to symlink
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 5d31a85dcc1fa4c5d4a925c6da67751653a700ba
This patch modifies xfs_symlink to add a parent pointer to the inode.
--- libxfs/xfs_trans_space.c | 17 +++++++++++++++++ libxfs/xfs_trans_space.h | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-)
libxfs/xfs_trans_space.c +17 -0
@@ -64,3 +64,20 @@ xfs_link_space_res(return ret; } + +unsigned int +xfs_symlink_space_res ( +struct xfs_mount *mp, +unsigned int namelen, +unsigned int fsblocks) +{ +unsigned int ret; + + ret =XFS_IALLOC_SPACE_RES (mp) +XFS_DIRENTER_SPACE_RES (mp, namelen) + + fsblocks; + +if (xfs_has_parent (mp)) + ret +=xfs_parent_calc_space_res (mp, namelen); + +return ret; +}
libxfs/xfs_trans_space.h +2 -2
@@ -95,8 +95,6 @@ XFS_DIRREMOVE_SPACE_RES(mp)#define XFS_RENAME_SPACE_RES (mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) -#define XFS_SYMLINK_SPACE_RES (mp,nl,b) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b))#define XFS_IFREE_SPACE_RES (mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0)
@@ -106,5 +104,7 @@ unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp,unsigned int xfs_create_space_res (struct xfs_mount *mp,unsigned int namelen);unsigned int xfs_mkdir_space_res (struct xfs_mount *mp,unsigned int namelen);unsigned int xfs_link_space_res (struct xfs_mount *mp,unsigned int namelen); +unsigned int xfs_symlink_space_res (struct xfs_mount *mp,unsigned int namelen, +unsigned int fsblocks);#endif /* __XFS_TRANS_SPACE_H__ */
PATCH 66/115 xfs: remove parent pointers in unlink
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: d2d18330f63cd70b50eddac76de7c59a36f2faa7
This patch removes the parent pointer attribute during unlink
--- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_parent.c | 22 ++++++++++++++++++++++ libxfs/xfs_parent.h | 3 +++ libxfs/xfs_trans_space.c | 13 +++++++++++++ libxfs/xfs_trans_space.h | 3 +-- repair/phase6.c | 6 +++--- 6 files changed, 43 insertions(+), 5 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -204,6 +204,7 @@#define xfs_refcountbt_stage_cursor libxfs_refcountbt_stage_cursor#define xfs_refcount_get_rec libxfs_refcount_get_rec#define xfs_refcount_lookup_le libxfs_refcount_lookup_le +#define xfs_remove_space_res libxfs_remove_space_res#define xfs_rmap_alloc libxfs_rmap_alloc#define xfs_rmapbt_calc_reserves libxfs_rmapbt_calc_reserves
libxfs/xfs_parent.c +22 -0
@@ -202,3 +202,25 @@ xfs_parent_addname(xfs_attr_defer_add (&ppargs->args,XFS_ATTR_DEFER_SET );return 0 ; } + +/* Remove a parent pointer to reflect a dirent removal. */ +int +xfs_parent_removename ( +struct xfs_trans *tp, +struct xfs_parent_args *ppargs, +struct xfs_inode *dp, +const struct xfs_name *parent_name, +struct xfs_inode *child) +{ +int error; + + error =xfs_parent_iread_extents (tp, child); +if (error) +return error; + +xfs_inode_to_parent_rec (&ppargs->rec, dp); +xfs_parent_da_args_init (&ppargs->args, tp, &ppargs->rec, child, + child->i_ino, parent_name); +xfs_attr_defer_add (&ppargs->args,XFS_ATTR_DEFER_REMOVE ); +return 0 ; +}
libxfs/xfs_parent.h +3 -0
@@ -81,5 +81,8 @@ xfs_parent_finish(int xfs_parent_addname (struct xfs_trans *tp,struct xfs_parent_args *ppargs,struct xfs_inode *dp,const struct xfs_name *parent_name,struct xfs_inode *child); +int xfs_parent_removename (struct xfs_trans *tp,struct xfs_parent_args *ppargs, +struct xfs_inode *dp,const struct xfs_name *parent_name, +struct xfs_inode *child);#endif /* __XFS_PARENT_H__ */
libxfs/xfs_trans_space.c +13 -0
@@ -81,3 +81,16 @@ xfs_symlink_space_res(return ret; } + +unsigned int +xfs_remove_space_res ( +struct xfs_mount *mp, +unsigned int namelen) +{ +unsigned int ret =XFS_DIRREMOVE_SPACE_RES (mp); + +if (xfs_has_parent (mp)) + ret +=xfs_parent_calc_space_res (mp, namelen); + +return ret; +}
libxfs/xfs_trans_space.h +1 -2
@@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB)#define XFS_QM_QINOCREATE_SPACE_RES (mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_REMOVE_SPACE_RES (mp) \ - XFS_DIRREMOVE_SPACE_RES(mp)#define XFS_RENAME_SPACE_RES (mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))#define XFS_IFREE_SPACE_RES (mp) \
@@ -106,5 +104,6 @@ unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen);unsigned int xfs_link_space_res (struct xfs_mount *mp,unsigned int namelen);unsigned int xfs_symlink_space_res (struct xfs_mount *mp,unsigned int namelen,unsigned int fsblocks); +unsigned int xfs_remove_space_res (struct xfs_mount *mp,unsigned int namelen);#endif /* __XFS_TRANS_SPACE_H__ */
repair/phase6.c +3 -3
@@ -1283,7 +1283,7 @@ longform_dir2_rebuild( libxfs_dir_ino_validate(mp, pip.i_ino)) pip.i_ino = mp->m_sb.sb_rootino; - nres =XFS_REMOVE_SPACE_RES (mp); + nres =libxfs_remove_space_res (mp,0 ); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_remove, nres,0 ,0 , &tp);if (error)res_failed (error);
@@ -1389,7 +1389,7 @@ dir2_kill_block(int nres;xfs_trans_t *tp; - nres =XFS_REMOVE_SPACE_RES (mp); + nres =libxfs_remove_space_res (mp,0 ); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_remove, nres,0 ,0 , &tp);if (error)res_failed (error);
@@ -2908,7 +2908,7 @@ process_dir_inode(* inode but it's easier than wedging a * new define in ourselves. */ - nres = no_modify ?0 :XFS_REMOVE_SPACE_RES (mp); + nres = no_modify ?0 :libxfs_remove_space_res (mp,0 ); error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_remove, nres,0 ,0 , &tp);if (error)
PATCH 67/115 xfs: Add parent pointers to rename
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 5a8338c88284df4e9e697225aa65f2709333a659
This patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer.
--- libxfs/xfs_parent.c | 30 ++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 6 ++++++ libxfs/xfs_trans_space.c | 25 +++++++++++++++++++++++++ libxfs/xfs_trans_space.h | 6 ++++-- 4 files changed, 65 insertions(+), 2 deletions(-)
libxfs/xfs_parent.c +30 -0
@@ -224,3 +224,33 @@ xfs_parent_removename(xfs_attr_defer_add (&ppargs->args,XFS_ATTR_DEFER_REMOVE );return 0 ; } + +/* Replace one parent pointer with another to reflect a rename. */ +int +xfs_parent_replacename ( +struct xfs_trans *tp, +struct xfs_parent_args *ppargs, +struct xfs_inode *old_dp, +const struct xfs_name *old_name, +struct xfs_inode *new_dp, +const struct xfs_name *new_name, +struct xfs_inode *child) +{ +int error; + + error =xfs_parent_iread_extents (tp, child); +if (error) +return error; + +xfs_inode_to_parent_rec (&ppargs->rec, old_dp); +xfs_parent_da_args_init (&ppargs->args, tp, &ppargs->rec, child, + child->i_ino, old_name); + +xfs_inode_to_parent_rec (&ppargs->new_rec, new_dp); + ppargs->args.new_name = new_name->name; + ppargs->args.new_namelen = new_name->len; + ppargs->args.new_value = &ppargs->new_rec; + ppargs->args.new_valuelen =sizeof (struct xfs_parent_rec ); +xfs_attr_defer_add (&ppargs->args,XFS_ATTR_DEFER_REPLACE ); +return 0 ; +}
libxfs/xfs_parent.h +6 -0
@@ -45,6 +45,7 @@ extern struct kmem_cache *xfs_parent_args_cache;*/ struct xfs_parent_args {struct xfs_parent_rec rec; +struct xfs_parent_rec new_rec;struct xfs_da_args args; };
@@ -84,5 +85,10 @@ int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs,int xfs_parent_removename (struct xfs_trans *tp,struct xfs_parent_args *ppargs,struct xfs_inode *dp,const struct xfs_name *parent_name,struct xfs_inode *child); +int xfs_parent_replacename (struct xfs_trans *tp, +struct xfs_parent_args *ppargs, +struct xfs_inode *old_dp,const struct xfs_name *old_name, +struct xfs_inode *new_dp,const struct xfs_name *new_name, +struct xfs_inode *child);#endif /* __XFS_PARENT_H__ */
libxfs/xfs_trans_space.c +25 -0
@@ -94,3 +94,28 @@ xfs_remove_space_res(return ret; } + +unsigned int +xfs_rename_space_res ( +struct xfs_mount *mp, +unsigned int src_namelen, +bool target_exists, +unsigned int target_namelen, +bool has_whiteout) +{ +unsigned int ret; + + ret =XFS_DIRREMOVE_SPACE_RES (mp) + +XFS_DIRENTER_SPACE_RES (mp, target_namelen); + +if (xfs_has_parent (mp)) { +if (has_whiteout) + ret +=xfs_parent_calc_space_res (mp, src_namelen); + ret +=2 *xfs_parent_calc_space_res (mp, target_namelen); + } + +if (target_exists) + ret +=xfs_parent_calc_space_res (mp, target_namelen); + +return ret; +}
libxfs/xfs_trans_space.h +4 -2
@@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB)#define XFS_QM_QINOCREATE_SPACE_RES (mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_RENAME_SPACE_RES (mp,nl) \ - (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))#define XFS_IFREE_SPACE_RES (mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0)
@@ -106,4 +104,8 @@ unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen, unsigned int fsblocks);unsigned int xfs_remove_space_res (struct xfs_mount *mp,unsigned int namelen); +unsigned int xfs_rename_space_res (struct xfs_mount *mp, +unsigned int src_namelen,bool target_exists, +unsigned int target_namelen,bool has_whiteout); +#endif /* __XFS_TRANS_SPACE_H__ */
PATCH 68/115 xfs: don't return XFS_ATTR_PARENT attributes via listxattr
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: daf9f884906bcfcffe26967aee9ece893fba019b
Parent pointers are internal filesystem metadata. They're not intended to be directly visible to userspace, so filter them out of xfs_xattr_put_listent so that they don't appear in listxattr.
--- libxfs/xfs_da_format.h | 3 +++ 1 file changed, 3 insertions(+)
libxfs/xfs_da_format.h +3 -0
@@ -726,6 +726,9 @@ struct xfs_attr3_leafblock { XFS_ATTR_SECURE | \ XFS_ATTR_PARENT) +/* Private attr namespaces not exposed to userspace */ +#define XFS_ATTR_PRIVATE_NSP_MASK (XFS_ATTR_PARENT) +#define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ XFS_ATTR_LOCAL | \ XFS_ATTR_INCOMPLETE)
PATCH 69/115 xfs: pass the attr value to put_listent when possible
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 8f4b980ee67fe53a77b70b1fdd8e15f2fe37180c
Pass the attr value to put_listent when we have local xattrs or shortform xattrs. This will enable the GETPARENTS ioctl to use xfs_attr_list as its backend.
--- libxfs/xfs_attr.h | 5 +++-- libxfs/xfs_attr_sf.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-)
libxfs/xfs_attr.h +3 -2
@@ -47,8 +47,9 @@ struct xfs_attrlist_cursor_kern {/* void; state communicated via *context */ -typedef void (*put_listent_func_t )(struct xfs_attr_list_context *,int , -unsigned char *,int ,int ); +typedef void (*put_listent_func_t )(struct xfs_attr_list_context *context, +int flags,unsigned char *name,int namelen,void *value, +int valuelen);struct xfs_attr_list_context {struct xfs_trans *tp;
libxfs/xfs_attr_sf.h +1 -0
@@ -16,6 +16,7 @@ typedef struct xfs_attr_sf_sort {uint8_t flags;/* flags bits (see xfs_attr_leaf.h) */ xfs_dahash_t hash;/* this entry's hash value */ unsigned char *name;/* name value, pointer into buffer */ +void *value; } xfs_attr_sf_sort_t;#define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \
PATCH 70/115 xfs: split out handle management helpers a bit
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: b8c9d4253da43c02b287831f7e576568f24fbe58
Split out the functions that generate file/fs handles and map them back into dentries in preparation for the GETPARENTS ioctl next.
--- libxfs/xfs_fs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +3 -1
@@ -633,7 +633,9 @@ typedef struct xfs_fsop_attrmulti_handlereq {/* * per machine unique filesystem identifier types. */ -typedef struct {__u32 val[2 ]; }xfs_fsid_t ;/* file system id type */ +typedef struct xfs_fsid { +__u32 val[2 ];/* file system id type */ +}xfs_fsid_t ; typedef struct xfs_fid { __u16 fid_len; /* length of remainder */
PATCH 71/115 xfs: add parent pointer ioctls
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 233f4e12bbb2c5fb1588b857336a26e8bb6942af
This patch adds a pair of new file ioctls to retrieve the parent pointer of a given inode. They both return the same results, but one operates on the file descriptor passed to ioctl() whereas the other allows the caller to specify a file handle for which the caller wants results.
--- libxfs/xfs_fs.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ondisk.h | 5 +++ libxfs/xfs_parent.c | 34 +++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++ 4 files changed, 118 insertions(+)
libxfs/xfs_fs.h +74 -0
@@ -816,6 +816,78 @@ struct xfs_exchange_range { XFS_EXCHANGE_RANGE_DRY_RUN | \ XFS_EXCHANGE_RANGE_FILE1_WRITTEN) +/* Iterating parent pointers of files. */ + +/* target was the root directory */ +#define XFS_GETPARENTS_OFLAG_ROOT (1U << 0) + +/* Cursor is done iterating pptrs */ +#define XFS_GETPARENTS_OFLAG_DONE (1U << 1) + +#define XFS_GETPARENTS_OFLAGS_ALL (XFS_GETPARENTS_OFLAG_ROOT | \ + XFS_GETPARENTS_OFLAG_DONE) + +#define XFS_GETPARENTS_IFLAGS_ALL (0) + +struct xfs_getparents_rec { +struct xfs_handle gpr_parent;/* Handle to parent */ +__u32 gpr_reclen;/* Length of entire record */ +__u32 gpr_reserved;/* zero */ +char gpr_name[];/* Null-terminated filename */ +}; + +/* Iterate through this file's directory parent pointers */ +struct xfs_getparents { +/* +* Structure to track progress in iterating the parent pointers. +* Must be initialized to zeroes before the first ioctl call, and +* not touched by callers after that. +*/ +struct xfs_attrlist_cursor gp_cursor; + +/* Input flags: XFS_GETPARENTS_IFLAG* */ +__u16 gp_iflags; + +/* Output flags: XFS_GETPARENTS_OFLAG* */ +__u16 gp_oflags; + +/* Size of the gp_buffer in bytes */ +__u32 gp_bufsize; + +/* Must be set to zero */ +__u64 gp_reserved; + +/* Pointer to a buffer in which to place xfs_getparents_rec */ +__u64 gp_buffer; +}; + +static inline struct xfs_getparents_rec * +xfs_getparents_first_rec (struct xfs_getparents *gp) +{ +return (struct xfs_getparents_rec *)(uintptr_t )gp->gp_buffer; +} + +static inline struct xfs_getparents_rec * +xfs_getparents_next_rec (struct xfs_getparents *gp, +struct xfs_getparents_rec *gpr) +{ +void *next = ((void *)gpr + gpr->gpr_reclen); +void *end = (void *)(uintptr_t )(gp->gp_buffer + gp->gp_bufsize); + +if (next >= end) +return NULL ; + +return next; +} + +/* Iterate through this file handle's directory parent pointers. */ +struct xfs_getparents_by_handle { +/* Handle to file whose parents we want. */ +struct xfs_handle gph_handle; + +struct xfs_getparents gph_request; +}; +/* * ioctl commands that are used by Linux filesystems */
@@ -851,6 +923,8 @@ struct xfs_exchange_range {/* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata)#define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) +#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents) +#define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle)/* * ioctl commands that replace IRIX syssgi()'s
libxfs/xfs_ondisk.h +5 -0
@@ -156,6 +156,11 @@ xfs_check_ondisk_structs(void) XFS_CHECK_OFFSET(struct xfs_efi_log_format_32, efi_extents, 16); XFS_CHECK_OFFSET(struct xfs_efi_log_format_64, efi_extents, 16); +/* parent pointer ioctls */ + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents_rec, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents_by_handle, 64); +/* * The v5 superblock format extended several v4 header structures with * additional data. While new fields are only accessible on v5
libxfs/xfs_parent.c +34 -0
@@ -254,3 +254,37 @@ xfs_parent_replacename(xfs_attr_defer_add (&ppargs->args,XFS_ATTR_DEFER_REPLACE );return 0 ; } + +/* +* Extract parent pointer information from any parent pointer xattr into +* @parent_ino/gen. The last two parameters can be NULL pointers. +* +* Returns 0 if this is not a parent pointer xattr at all; or -EFSCORRUPTED for +* garbage. +*/ +int +xfs_parent_from_attr ( +struct xfs_mount *mp, +unsigned int attr_flags, +const unsigned char *name, +unsigned int namelen, +const void *value, +unsigned int valuelen, +xfs_ino_t *parent_ino, +uint32_t *parent_gen) +{ +const struct xfs_parent_rec *rec = value; + +ASSERT (attr_flags &XFS_ATTR_PARENT ); + +if (!xfs_parent_namecheck (attr_flags, name, namelen)) +return -EFSCORRUPTED ; +if (!xfs_parent_valuecheck (mp, value, valuelen)) +return -EFSCORRUPTED ; + +if (parent_ino) + *parent_ino =be64_to_cpu (rec->p_ino); +if (parent_gen) + *parent_gen =be32_to_cpu (rec->p_gen); +return 0 ; +}
libxfs/xfs_parent.h +5 -0
@@ -91,4 +91,9 @@ int xfs_parent_replacename(struct xfs_trans *tp, struct xfs_inode *new_dp, const struct xfs_name *new_name, struct xfs_inode *child); +int xfs_parent_from_attr (struct xfs_mount *mp,unsigned int attr_flags, +const unsigned char *name,unsigned int namelen, +const void *value,unsigned int valuelen, +xfs_ino_t *parent_ino,uint32_t *parent_gen); +#endif /* __XFS_PARENT_H__ */
PATCH 72/115 xfs: don't remove the attr fork when parent pointers are enabled
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 7dafb449b7922c1eec6fee3ed85b679d51f0f431
When an inode is removed, it may also cause the attribute fork to be removed if it is the last attribute. This transaction gets flushed to the log, but if the system goes down before we could inactivate the symlink, the log recovery tries to inactivate this inode (since it is on the unlinked list) but the verifier trips over the remote value and leaks it.
Hence we ended up with a file in this odd state on a "clean" mount. The "obvious" fix is to prohibit erasure of the attr fork to avoid tripping over the verifiers when pptrs are enabled.
--- libxfs/xfs_attr_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libxfs/xfs_attr_leaf.c +4 -2
@@ -888,7 +888,8 @@ xfs_attr_sf_removename(*/ if (totsize ==sizeof (struct xfs_attr_sf_hdr ) &&xfs_has_attr2 (mp) && (dp->i_df.if_format !=XFS_DINODE_FMT_BTREE ) && - !(args->op_flags & (XFS_DA_OP_ADDNAME |XFS_DA_OP_REPLACE ))) { + !(args->op_flags & (XFS_DA_OP_ADDNAME |XFS_DA_OP_REPLACE )) && + !xfs_has_parent (mp)) {xfs_attr_fork_remove (dp, args->trans); }else {xfs_idata_realloc (dp, -size,XFS_ATTR_FORK );
@@ -897,7 +898,8 @@ xfs_attr_sf_removename(ASSERT (totsize >sizeof (struct xfs_attr_sf_hdr ) || (args->op_flags &XFS_DA_OP_ADDNAME ) || !xfs_has_attr2 (mp) || - dp->i_df.if_format ==XFS_DINODE_FMT_BTREE ); + dp->i_df.if_format ==XFS_DINODE_FMT_BTREE || +xfs_has_parent (mp));xfs_trans_log_inode (args->trans, dp,XFS_ILOG_CORE |XFS_ILOG_ADATA ); }
PATCH 73/115 xfs: add a incompat feature bit for parent pointers
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 5f98ec1cb5c264e4815e21d632ee0b3d6e700e3d
Create an incompat feature bit and a fs geometry flag so that we can enable the feature in the ondisk superblock and advertise its existence to userspace.
--- libxfs/xfs_format.h | 1 + libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 4 ++++ 3 files changed, 6 insertions(+)
libxfs/xfs_format.h +1 -0
@@ -374,6 +374,7 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)/* large extent counters */ #define XFS_SB_FEAT_INCOMPAT_EXCHRANGE (1 << 6)/* exchangerange supported */ +#define XFS_SB_FEAT_INCOMPAT_PARENT (1 << 7)/* parent pointers */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE | \ XFS_SB_FEAT_INCOMPAT_SPINODES | \
libxfs/xfs_fs.h +1 -0
@@ -240,6 +240,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22)/* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23)/* large extent counters */ #define XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE (1 << 24)/* exchange range */ +#define XFS_FSOP_GEOM_FLAGS_PARENT (1 << 25)/* linux parent pointers */ /* * Minimum and maximum sizes need for growth checks.
libxfs/xfs_sb.c +4 -0
@@ -175,6 +175,8 @@ xfs_sb_version_to_features( features |=XFS_FEAT_NREXT64 ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_EXCHRANGE ) features |=XFS_FEAT_EXCHANGE_RANGE ; +if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_PARENT ) + features |=XFS_FEAT_PARENT ;return features; }
@@ -1251,6 +1253,8 @@ xfs_fs_geometry( geo->flags |=XFS_FSOP_GEOM_FLAGS_BIGTIME ;if (xfs_has_inobtcounts (mp)) geo->flags |=XFS_FSOP_GEOM_FLAGS_INOBTCNT ; +if (xfs_has_parent (mp)) + geo->flags |=XFS_FSOP_GEOM_FLAGS_PARENT ;if (xfs_has_sector (mp)) { geo->flags |=XFS_FSOP_GEOM_FLAGS_SECTOR ; geo->logsectsize = sbp->sb_logsectsize;
PATCH 74/115 xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 7ea816ca4043c2bc6052f696b6aebe2c22980a03
Dave and I were discussing some recent test regressions as a result of me turning on nrext64=1 on realtime filesystems, when we noticed that the minimum log size of a 32M filesystem jumped from 954 blocks to 4287 blocks.
Digging through xfs_log_calc_max_attrsetm_res, Dave noticed that @size contains the maximum estimated amount of space needed for a local format xattr, in bytes, but we feed this quantity to XFS_NEXTENTADD_SPACE_RES, which requires units of blocks. This has resulted in an overestimation of the minimum log size over the years.
We should nominally correct this, but there's a backwards compatibility problem -- if we enable it now, the minimum log size will decrease. If a corrected mkfs formats a filesystem with this new smaller log size, a user will encounter mount failures on an uncorrected kernel due to the larger minimum log size computations there.
Therefore, turn this on for parent pointers because it wasn't merged at all upstream when this issue was discovered.
--- libxfs/xfs_log_rlimit.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
libxfs/xfs_log_rlimit.c +32 -0
@@ -16,6 +16,29 @@#include "xfs_bmap_btree.h" #include "xfs_trace.h" +/* +* Shortly after enabling the large extents count feature in 2023, longstanding +* bugs were found in the code that computes the minimum log size. Luckily, +* the bugs resulted in over-estimates of that size, so there's no impact to +* existing users. However, we don't want to reduce the minimum log size +* because that can create the situation where a newer mkfs writes a new +* filesystem that an older kernel won't mount. +* +* Therefore, we only may correct the computation starting with filesystem +* features that didn't exist in 2023. In other words, only turn this on if +* the filesystem has parent pointers. +* +* This function can be called before the XFS_HAS_* flags have been set up, +* (e.g. mkfs) so we must check the ondisk superblock. +*/ +static inline bool +xfs_want_minlogsize_fixes ( +struct xfs_sb *sb) +{ +return xfs_sb_is_v5 (sb) && +xfs_sb_has_incompat_feature (sb,XFS_SB_FEAT_INCOMPAT_PARENT ); +} +/* * Calculate the maximum length in bytes that would be required for a local * attribute value as large attributes out of line are not logged.
@@ -31,6 +54,15 @@ xfs_log_calc_max_attrsetm_res(MAXNAMELEN -1 ; nblks =XFS_DAENTER_SPACE_RES (mp,XFS_ATTR_FORK ); nblks +=XFS_B_TO_FSB (mp, size); + +/* +* If the feature set is new enough, correct a unit conversion error in +* the xattr transaction reservation code that resulted in oversized +* minimum log size computations. +*/ +if (xfs_want_minlogsize_fixes (&mp->m_sb)) + size =XFS_B_TO_FSB (mp, size); + nblks +=XFS_NEXTENTADD_SPACE_RES (mp, size,XFS_ATTR_FORK ); return M_RES(mp)->tr_attrsetm.tr_logres +
PATCH 75/115 xfs: drop compatibility minimum log size computations for reflink
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 6ed858c7c678218aa8df9d9e75d5e9955c105415
Let's also drop the oversized minimum log computations for reflink and rmap that were the result of bugs introduced many years ago.
--- libxfs/xfs_log_rlimit.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
libxfs/xfs_log_rlimit.c +14 -0
@@ -24,6 +24,11 @@* because that can create the situation where a newer mkfs writes a new * filesystem that an older kernel won't mount. * +* Several years prior, we also discovered that the transaction reservations +* for rmap and reflink operations were unnecessarily large. That was fixed, +* but the minimum log size computation was left alone to avoid the +* compatibility problems noted above. Fix that too. +* * Therefore, we only may correct the computation starting with filesystem * features that didn't exist in 2023. In other words, only turn this on if * the filesystem has parent pointers.
@@ -80,6 +85,15 @@ xfs_log_calc_trans_resv_for_minlogblocks( {unsigned int rmap_maxlevels = mp->m_rmap_maxlevels; +/* +* If the feature set is new enough, drop the oversized minimum log +* size computation introduced by the original reflink code. +*/ +if (xfs_want_minlogsize_fixes (&mp->m_sb)) { +xfs_trans_resv_calc (mp, resv); +return ; + } +/* * In the early days of rmap+reflink, we always set the rmap maxlevels * to 9 even if the AG was small enough that it would never grow to
PATCH 76/115 xfs: enable parent pointers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 67ac7091e35bd34b75c0ec77331b53ca052e0cb3
Add parent pointers to the list of supported features.
--- libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_format.h +2 -1
@@ -382,7 +382,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_BIGTIME | \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ XFS_SB_FEAT_INCOMPAT_NREXT64 | \ - XFS_SB_FEAT_INCOMPAT_EXCHRANGE) + XFS_SB_FEAT_INCOMPAT_EXCHRANGE | \ + XFS_SB_FEAT_INCOMPAT_PARENT)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
PATCH 77/115 xfs: check dirents have parent pointers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 61b3f0df5c235806d372aaf696ce9aee7746d18f
If the fs has parent pointers, we need to check that each child dirent points to a file that has a parent pointer pointing back at us.
--- libxfs/xfs_parent.c | 22 ++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++++ 2 files changed, 27 insertions(+)
libxfs/xfs_parent.c +22 -0
@@ -288,3 +288,25 @@ xfs_parent_from_attr( *parent_gen =be32_to_cpu (rec->p_gen);return 0 ; } + +/* +* Look up a parent pointer record (@parent_name -> @pptr) of @ip. +* +* Caller must hold at least ILOCK_SHARED. The scratchpad need not be +* initialized. +* +* Returns 0 if the pointer is found, -ENOATTR if there is no match, or a +* negative errno. +*/ +int +xfs_parent_lookup ( +struct xfs_trans *tp, +struct xfs_inode *ip, +const struct xfs_name *parent_name, +struct xfs_parent_rec *pptr, +struct xfs_da_args *scratch) +{ +memset (scratch,0 ,sizeof (struct xfs_da_args )); +xfs_parent_da_args_init (scratch, tp, pptr, ip, ip->i_ino, parent_name); +return xfs_attr_get_ilocked (scratch); +}
libxfs/xfs_parent.h +5 -0
@@ -96,4 +96,9 @@ int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags, const void *value, unsigned int valuelen, xfs_ino_t *parent_ino, uint32_t *parent_gen); +/* Repair functions */ +int xfs_parent_lookup (struct xfs_trans *tp,struct xfs_inode *ip, +const struct xfs_name *name,struct xfs_parent_rec *pptr, +struct xfs_da_args *scratch); +#endif /* __XFS_PARENT_H__ */
PATCH 78/115 xfs: remove some boilerplate from xfs_attr_set
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: e7420e75ef04787bc51688fc9bbca7da4d164a1e
In preparation for online/offline repair wanting to use xfs_attr_set, move some of the boilerplate out of this function into the callers. Repair can initialize the da_args completely, and the userspace flag handling/twisting goes away once we move it to xfs_attr_change.
--- libxfs/xfs_attr.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
libxfs/xfs_attr.c +12 -21
@@ -947,6 +947,16 @@ xfs_attr_lookup(return error; } +/* +* Make a change to the xattr structure. +* +* The caller must have initialized @args, attached dquots, and must not hold +* any ILOCKs. +* +* Returns -EEXIST for XFS_ATTRUPDATE_CREATE if the name already exists. +* Returns -ENOATTR for XFS_ATTRUPDATE_REMOVE if the name does not exist. +* Returns 0 on success, or a negative errno if something else went wrong. +*/ int xfs_attr_set( struct xfs_da_args *args,
@@ -960,27 +970,7 @@ xfs_attr_set(int rmt_blks =0 ;unsigned int total; -if (xfs_is_shutdown (dp->i_mount)) -return -EIO ; - - error =xfs_qm_dqattach (dp); -if (error) -return error; - -if (!args->owner) - args->owner = args->dp->i_ino; - args->geo = mp->m_attr_geo; - args->whichfork =XFS_ATTR_FORK ; -xfs_attr_sethash (args); - -/* -* We have no control over the attribute names that userspace passes us -* to remove, so we have to allow the name lookup prior to attribute -* removal to fail as well. Preserve the logged flag, since we need -* to pass that through to the logging code. -*/ - args->op_flags =XFS_DA_OP_OKNOENT | - (args->op_flags &XFS_DA_OP_LOGGED ); +ASSERT (!args->trans);switch (op) {case XFS_ATTRUPDATE_UPSERT :
@@ -1075,6 +1065,7 @@ xfs_attr_set( error =xfs_trans_commit (args->trans); out_unlock:xfs_iunlock (dp,XFS_ILOCK_EXCL ); + args->trans =NULL ;return error; out_trans_cancel:
PATCH 79/115 xfs: make the reserved block permission flag explicit in xfs_attr_set
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: bf61c36a45d4c215994699a7a06a00c58d22e8a2
Make the use of reserved blocks an explicit parameter to xfs_attr_set. Userspace setting XFS_ATTR_ROOT attrs should continue to be able to use it, but for online repairs we can back out and therefore do not care.
--- db/attrset.c | 4 ++-- libxfs/xfs_attr.c | 6 +++--- libxfs/xfs_attr.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
db/attrset.c +2 -2
@@ -161,7 +161,7 @@ attr_set_f( goto out; } -if (libxfs_attr_set (&args, op)) { +if (libxfs_attr_set (&args, op, false)) {dbprintf (_ ("failed to set attr %s on inode %llu\n" ), args.name, (unsigned long long )iocur_top->ino); goto out;
@@ -247,7 +247,7 @@ attr_remove_f( goto out; } -if (libxfs_attr_set (&args,XFS_ATTRUPDATE_REMOVE )) { +if (libxfs_attr_set (&args,XFS_ATTRUPDATE_REMOVE , false)) {dbprintf (_ ("failed to remove attr %s from inode %llu\n" ), (unsigned char *)args.name, (unsigned long long )iocur_top->ino);
libxfs/xfs_attr.c +3 -3
@@ -951,7 +951,7 @@ xfs_attr_lookup(* Make a change to the xattr structure. * * The caller must have initialized @args, attached dquots, and must not hold -* any ILOCKs. +* any ILOCKs. Reserved data blocks may be used if @rsvd is set. * * Returns -EEXIST for XFS_ATTRUPDATE_CREATE if the name already exists. * Returns -ENOATTR for XFS_ATTRUPDATE_REMOVE if the name does not exist.
@@ -960,12 +960,12 @@ xfs_attr_lookup(int xfs_attr_set (struct xfs_da_args *args, -enum xfs_attr_update op) +enum xfs_attr_update op, +bool rsvd) {struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount;struct xfs_trans_res tres; -bool rsvd = (args->attr_filter &XFS_ATTR_ROOT );int error, local;int rmt_blks =0 ;unsigned int total;
libxfs/xfs_attr.h +1 -1
@@ -558,7 +558,7 @@ enum xfs_attr_update { XFS_ATTRUPDATE_REPLACE, /* set value, fail if attr does not exist */ }; -int xfs_attr_set (struct xfs_da_args *args,enum xfs_attr_update op); +int xfs_attr_set (struct xfs_da_args *args,enum xfs_attr_update op,bool rsvd);int xfs_attr_set_iter (struct xfs_attr_intent *attr);int xfs_attr_remove_iter (struct xfs_attr_intent *attr);bool xfs_attr_check_namespace (unsigned int attr_flags);
PATCH 80/115 xfs: add raw parent pointer apis to support repair
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 5769aa41ee34d4d1cc2b35376107b8e9694698f0
Add a couple of utility functions to set or remove parent pointers from a file. These functions will be used by repair code, hence they skip the xattr logging that regular parent pointer updates use.
--- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2.h | 2 +- libxfs/xfs_parent.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 6 +++++ 4 files changed, 72 insertions(+), 2 deletions(-)
libxfs/xfs_dir2.c +1 -1
@@ -433,7 +433,7 @@ intxfs_dir_removename ( struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t total) /* bmap's total block count */ {
libxfs/xfs_dir2.h +1 -1
@@ -58,7 +58,7 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t *inum, struct xfs_name *ci_name);extern int xfs_dir_removename (struct xfs_trans *tp,struct xfs_inode *dp, -struct xfs_name *name,xfs_ino_t ino, +const struct xfs_name *name,xfs_ino_t ino,xfs_extlen_t tot); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum,
libxfs/xfs_parent.c +64 -0
67 lines not on this page · raw message
libxfs/xfs_parent.h +6 -0
@@ -100,5 +100,11 @@ int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags,int xfs_parent_lookup (struct xfs_trans *tp,struct xfs_inode *ip,const struct xfs_name *name,struct xfs_parent_rec *pptr,struct xfs_da_args *scratch); +int xfs_parent_set (struct xfs_inode *ip,xfs_ino_t owner, +const struct xfs_name *name,struct xfs_parent_rec *pptr, +struct xfs_da_args *scratch); +int xfs_parent_unset (struct xfs_inode *ip,xfs_ino_t owner, +const struct xfs_name *name,struct xfs_parent_rec *pptr, +struct xfs_da_args *scratch);#endif /* __XFS_PARENT_H__ */
PATCH 81/115 xfs: remove pointless unlocked assertion
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 13db7007892694c891fc37feccbd2ac8f227af78
Remove this assertion about the inode not having an attr fork from xfs_bmap_add_attrfork because the function handles that case just fine. Weirder still, the function actually /requires/ the caller not to hold the ILOCK, which means that its accesses are not stabilized.
--- libxfs/xfs_bmap.c | 2 -- 1 file changed, 2 deletions(-)
libxfs/xfs_bmap.c +0 -2
@@ -1035,8 +1035,6 @@ xfs_bmap_add_attrfork(int logflags;/* logging flags */ int error;/* error return value */ -ASSERT (xfs_inode_has_attr_fork (ip) ==0 ); - mp = ip->i_mount;ASSERT (!XFS_NOT_DQATTACHED (mp, ip));
PATCH 82/115 xfs: split xfs_bmap_add_attrfork into two pieces
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 55edcd1f86474f973fccf5c5ccc8bc7908893142
Split this function into two pieces -- one to make the actual changes to the inode core to add the attr fork, and another one to deal with getting the transaction and locking the inodes.
The next couple of patches will need this to be split into two. One patch implements committing new parent pointer recordsets to damaged files. If one file has an attr fork and the other does not, we have to create the missing attr fork before the atomic swap transaction, and can use the behavior encoded in the current xfs_bmap_add_attrfork.
The second patch adapts /lost+found adoptions to handle parent pointers correctly. The adoption process will add a parent pointer to a child that is being moved to /lost+found, but this requires that the attr fork already exists. We don't know if we're actually going to commit the adoption until we've already reserved a transaction and taken the ILOCKs, which means that we must have a way to bypass the start of the current xfs_bmap_add_attrfork.
Therefore, create xfs_attr_add_fork as the helper that creates a transaction and takes locks; and make xfs_bmap_add_attrfork the function that updates the inode core and allocates the incore attr fork.
--- libxfs/xfs_attr.c | 39 ++++++++++++++++++++++++++++++++++++++- libxfs/xfs_bmap.c | 36 ++++++++++-------------------------- libxfs/xfs_bmap.h | 3 ++- 3 files changed, 50 insertions(+), 28 deletions(-)
libxfs/xfs_attr.c +38 -1
@@ -947,6 +947,43 @@ xfs_attr_lookup(return error; } +STATIC int +xfs_attr_add_fork ( +struct xfs_inode *ip,/* incore inode pointer */ +int size,/* space new attribute needs */ +int rsvd)/* xact may use reserved blks */ +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp;/* transaction pointer */ +unsigned int blks;/* space reservation */ +int error;/* error return value */ + +ASSERT (!XFS_NOT_DQATTACHED (mp, ip)); + + blks =XFS_ADDAFORK_SPACE_RES (mp); + + error =xfs_trans_alloc_inode (ip, &M_RES (mp)->tr_addafork, blks,0 , + rsvd, &tp); +if (error) +return error; + +if (xfs_inode_has_attr_fork (ip)) + goto trans_cancel; + + error =xfs_bmap_add_attrfork (tp, ip, size, rsvd); +if (error) + goto trans_cancel; + + error =xfs_trans_commit (tp); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return error; + +trans_cancel: +xfs_trans_cancel (tp); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return error; +} +/* * Make a change to the xattr structure. *
@@ -988,7 +1025,7 @@ xfs_attr_set(xfs_attr_sf_entsize_byname (args->namelen, args->valuelen); - error =xfs_bmap_add_attrfork (dp, sf_size, rsvd); + error =xfs_attr_add_fork (dp, sf_size, rsvd);if (error)return error; }
libxfs/xfs_bmap.c +10 -26
@@ -1019,38 +1019,29 @@ xfs_bmap_set_attrforkoff( }/* -* Convert inode from non-attributed to attributed. -* Must not be in a transaction, ip must not be locked. +* Convert inode from non-attributed to attributed. Caller must hold the +* ILOCK_EXCL and the file cannot have an attr fork. */ int /* error code */ xfs_bmap_add_attrfork ( -xfs_inode_t *ip,/* incore inode pointer */ +struct xfs_trans *tp, +struct xfs_inode *ip,/* incore inode pointer */ int size,/* space new attribute needs */ int rsvd)/* xact may use reserved blks */ { -xfs_mount_t *mp;/* mount structure */ -xfs_trans_t *tp;/* transaction pointer */ -int blks;/* space reservation */ +struct xfs_mount *mp = tp->t_mountp;int version =1 ;/* superblock attr version */ int logflags;/* logging flags */ int error;/* error return value */ - mp = ip->i_mount; +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (!XFS_NOT_DQATTACHED (mp, ip)); - - blks =XFS_ADDAFORK_SPACE_RES (mp); - - error =xfs_trans_alloc_inode (ip, &M_RES (mp)->tr_addafork, blks,0 , - rsvd, &tp); -if (error) -return error; -if (xfs_inode_has_attr_fork (ip)) - goto trans_cancel; +ASSERT (!xfs_inode_has_attr_fork (ip));xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); error =xfs_bmap_set_attrforkoff (ip, size, &version);if (error) - goto trans_cancel; +return error;xfs_ifork_init_attr (ip,XFS_DINODE_FMT_EXTENTS ,0 ); logflags =0 ;
@@ -1071,7 +1062,7 @@ xfs_bmap_add_attrfork(if (logflags)xfs_trans_log_inode (tp, ip, logflags);if (error) - goto trans_cancel; +return error;if (!xfs_has_attr (mp) || (!xfs_has_attr2 (mp) && version ==2 )) {bool log_sb = false;
@@ -1090,14 +1081,7 @@ xfs_bmap_add_attrfork(xfs_log_sb (tp); } - error =xfs_trans_commit (tp); -xfs_iunlock (ip,XFS_ILOCK_EXCL ); -return error; - -trans_cancel: -xfs_trans_cancel (tp); -xfs_iunlock (ip,XFS_ILOCK_EXCL ); -return error; +return 0 ; }/*
libxfs/xfs_bmap.h +2 -1
@@ -176,7 +176,8 @@ int xfs_bmap_longest_free_extent(struct xfs_perag *pag,void xfs_trim_extent (struct xfs_bmbt_irec *irec,xfs_fileoff_t bno,xfs_filblks_t len);unsigned int xfs_bmap_compute_attr_offset (struct xfs_mount *mp); -int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd); +int xfs_bmap_add_attrfork (struct xfs_trans *tp,struct xfs_inode *ip, +int size,int rsvd);void xfs_bmap_local_to_extents_empty (struct xfs_trans *tp,struct xfs_inode *ip,int whichfork); int xfs_bmap_local_to_extents(struct xfs_trans *tp, struct xfs_inode *ip,
PATCH 83/115 xfs: actually rebuild the parent pointer xattrs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a26dc21309af68623b82b4e366cbbeb5a85ce65b
Once we've assembled all the parent pointers for a file, we need to are embedded in the xattr structure, which means that we must write a new extended attribute structure, again, atomically. Therefore, we must copy the non-parent-pointer attributes from the file being repaired into the temporary file's extended attributes and then call the atomic extent swap mechanism to exchange the blocks.
--- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_attr.c +1 -1
@@ -947,7 +947,7 @@ xfs_attr_lookup(return error; } -STATIC int +int xfs_attr_add_fork( struct xfs_inode *ip, /* incore inode pointer */ int size, /* space new attribute needs */
libxfs/xfs_attr.h +1 -0
@@ -648,5 +648,6 @@ int __init xfs_attr_intent_init_cache(void);void xfs_attr_intent_destroy_cache (void );int xfs_attr_sf_totsize (struct xfs_inode *dp); +int xfs_attr_add_fork (struct xfs_inode *ip,int size,int rsvd);#endif /* __XFS_ATTR_H__ */
PATCH 84/115 xfs: teach online scrub to find directory tree structure problems
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 928b721a11789a9363d6d7c32a1f3166a79f3b5f
Create a new scrubber that detects corruptions within the directory tree structure itself. It can detect directories with multiple parents; loops within the directory tree; and directory loops not accessible from the root.
--- libxfs/xfs_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +2 -1
@@ -719,9 +719,10 @@ struct xfs_scrub_metadata {#define XFS_SCRUB_TYPE_QUOTACHECK 25/* quota counters */ #define XFS_SCRUB_TYPE_NLINKS 26/* inode link counts */ #define XFS_SCRUB_TYPE_HEALTHY 27/* everything checked out ok */ +#define XFS_SCRUB_TYPE_DIRTREE 28/* directory tree structure */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 28 +#define XFS_SCRUB_TYPE_NR 29/* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0)
PATCH 85/115 xfs: report directory tree corruption in the health information
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 37056912d5721324ac28787a4f903798f7361099
Report directories that are the source of corruption in the directory tree.
--- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +1 -0
@@ -411,6 +411,7 @@ struct xfs_bulkstat {#define XFS_BS_SICK_XATTR (1 << 5)/* extended attributes */ #define XFS_BS_SICK_SYMLINK (1 << 6)/* symbolic link remote target */ #define XFS_BS_SICK_PARENT (1 << 7)/* parent pointers */ +#define XFS_BS_SICK_DIRTREE (1 << 8)/* directory tree structure */ /* * Project quota id helpers (previously projid was 16bit only
libxfs/xfs_health.h +3 -1
@@ -95,6 +95,7 @@ struct xfs_da_args;/* Don't propagate sick status to ag health summary during inactivation */ #define XFS_SICK_INO_FORGET (1 << 12) +#define XFS_SICK_INO_DIRTREE (1 << 13)/* directory tree structure */ /* Primary evidence of health problems in a given group. */ #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \
@@ -125,7 +126,8 @@ struct xfs_da_args; XFS_SICK_INO_DIR | \ XFS_SICK_INO_XATTR | \ XFS_SICK_INO_SYMLINK | \ - XFS_SICK_INO_PARENT) + XFS_SICK_INO_PARENT | \ + XFS_SICK_INO_DIRTREE)#define XFS_SICK_INO_ZAPPED (XFS_SICK_INO_BMBTD_ZAPPED | \ XFS_SICK_INO_BMBTA_ZAPPED | \
PATCH 86/115 xfs: introduce vectored scrub mode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: c77b37584c2d1054452853e47e42c7350b8fe687
Introduce a variant on XFS_SCRUB_METADATA that allows for a vectored mode. The caller specifies the principal metadata object that they want to scrub (allocation group, inode, etc.) once, followed by an array of scrub types they want called on that object. The kernel runs the scrub operations and writes the output flags and errno code to the corresponding array element.
A new pseudo scrub type BARRIER is introduced to force the kernel to return to userspace if any corruptions have been found when scrubbing the previous scrub types in the array. This enables userspace to schedule, for example, the sequence:
1. data fork
2. barrier
3. directory
If the data fork scrub is clean, then the kernel will perform the directory scrub. If not, the barrier in 2 will exit back to userspace.
The alternative would have been an interface where userspace passes a pointer to an empty buffer, and the kernel formats that with xfs_scrub_vecs that tell userspace what it scrubbed and what the outcome was. With that the kernel would have to communicate that the buffer needed to have been at least X size, even though for our cases XFS_SCRUB_TYPE_NR + 2 would always be enough.
Compared to that, this design keeps all the dependency policy and ordering logic in userspace where it already resides instead of duplicating it in the kernel. The downside of that is that it needs the barrier logic.
When running fstests in "rebuild all metadata after each test" mode, I observed a 10% reduction in runtime due to fewer transitions across the system call boundary.
--- libxfs/xfs_fs.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
libxfs/xfs_fs.h +33 -0
@@ -725,6 +725,15 @@ struct xfs_scrub_metadata {/* Number of scrub subcommands. */ #define XFS_SCRUB_TYPE_NR 29 +/* +* This special type code only applies to the vectored scrub implementation. +* +* If any of the previous scrub vectors recorded runtime errors or have +* sv_flags bits set that match the OFLAG bits in the barrier vector's +* sv_flags, set the barrier's sv_ret to -ECANCELED and return to userspace. +*/ +#define XFS_SCRUB_TYPE_BARRIER (0xFFFFFFFF) +/* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0)
@@ -769,6 +778,29 @@ struct xfs_scrub_metadata { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED)#define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT) +/* Vectored scrub calls to reduce the number of kernel transitions. */ + +struct xfs_scrub_vec { +__u32 sv_type;/* XFS_SCRUB_TYPE_* */ +__u32 sv_flags;/* XFS_SCRUB_FLAGS_* */ +__s32 sv_ret;/* 0 or a negative error code */ +__u32 sv_reserved;/* must be zero */ +}; + +/* Vectored metadata scrub control structure. */ +struct xfs_scrub_vec_head { +__u64 svh_ino;/* inode number. */ +__u32 svh_gen;/* inode generation. */ +__u32 svh_agno;/* ag number. */ +__u32 svh_flags;/* XFS_SCRUB_VEC_FLAGS_* */ +__u16 svh_rest_us;/* wait this much time between vector items */ +__u16 svh_nr;/* number of svh_vectors */ +__u64 svh_reserved;/* must be zero */ +__u64 svh_vectors;/* pointer to buffer of xfs_scrub_vec */ +}; + +#define XFS_SCRUB_VEC_FLAGS_ALL (0) +/* * ioctl limits */
@@ -928,6 +960,7 @@ struct xfs_getparents_by_handle {#define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry)#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents)#define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle) +#define XFS_IOC_SCRUBV_METADATA _IOWR('X', 64, struct xfs_scrub_vec_head)/* * ioctl commands that replace IRIX syssgi()'s
PATCH 87/115 xfs: factor out a xfs_dir_lookup_args helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 14ee22fef420c864c0869419e54aa4e88f64b4e6
Add a helper to switch between the different directory formats for lookup and to handle the -EEXIST return for a successful lookup.
--- libxfs/xfs_dir2.c | 66 ++++++++++++++++++++++++++++++++--------------------- libxfs/xfs_dir2.h | 2 ++ 2 files changed, 42 insertions(+), 26 deletions(-)
libxfs/xfs_dir2.c +40 -26
@@ -351,6 +351,45 @@ xfs_dir_cilookup_result(return -EEXIST ; } +int +xfs_dir_lookup_args ( +struct xfs_da_args *args) +{ +bool is_block, is_leaf; +int error; + +if (args->dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { + error =xfs_dir2_sf_lookup (args); + goto out; + } + +/* dir2 functions require that the data fork is loaded */ + error =xfs_iread_extents (args->trans, args->dp,XFS_DATA_FORK ); +if (error) + goto out; + + error =xfs_dir2_isblock (args, &is_block); +if (error) + goto out; + +if (is_block) { + error =xfs_dir2_block_lookup (args); + goto out; + } + + error =xfs_dir2_isleaf (args, &is_leaf); +if (error) + goto out; +if (is_leaf) + error =xfs_dir2_leaf_lookup (args); +else + error =xfs_dir2_node_lookup (args); +out: +if (error != -EEXIST ) +return error; +return 0 ; +} +/* * Lookup a name in a directory, give back the inode number. * If ci_name is not NULL, returns the actual name in ci_name if it differs
@@ -367,7 +406,6 @@ xfs_dir_lookup( {struct xfs_da_args *args;int rval; -bool v;int lock_mode;ASSERT (S_ISDIR (VFS_I (dp)->i_mode));
@@ -389,30 +427,7 @@ xfs_dir_lookup( args->op_flags |=XFS_DA_OP_CILOOKUP ; lock_mode =xfs_ilock_data_map_shared (dp); -if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { - rval =xfs_dir2_sf_lookup (args); - goto out_check_rval; - } - - rval =xfs_dir2_isblock (args, &v); -if (rval) - goto out_free; -if (v) { - rval =xfs_dir2_block_lookup (args); - goto out_check_rval; - } - - rval =xfs_dir2_isleaf (args, &v); -if (rval) - goto out_free; -if (v) - rval =xfs_dir2_leaf_lookup (args); -else - rval =xfs_dir2_node_lookup (args); - -out_check_rval: -if (rval == -EEXIST ) - rval =0 ; + rval =xfs_dir_lookup_args (args);if (!rval) { *inum = args->inumber;if (ci_name) {
@@ -420,7 +435,6 @@ xfs_dir_lookup( ci_name->len = args->valuelen; } } -out_free:xfs_iunlock (dp, lock_mode);kfree (args);return rval;
libxfs/xfs_dir2.h +2 -0
@@ -66,6 +66,8 @@ extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp,extern int xfs_dir_canenter (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name); +int xfs_dir_lookup_args (struct xfs_da_args *args); +/* * Direct call from the bmap code, bypassing the generic directory layer. */
PATCH 88/115 xfs: factor out a xfs_dir_createname_args helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4d893a40514e9c4ee6e3be48ed1b77efb38c313b
Add a helper to switch between the different directory formats for creating a directory entry and to handle the XFS_DA_OP_JUSTCHECK flag based on the passed in ino number field.
--- libxfs/xfs_dir2.c | 53 ++++++++++++++++++++++++++++------------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 29 insertions(+), 25 deletions(-)
libxfs/xfs_dir2.c +28 -25
@@ -255,6 +255,33 @@ xfs_dir_init(return error; } +int +xfs_dir_createname_args ( +struct xfs_da_args *args) +{ +bool is_block, is_leaf; +int error; + +if (!args->inumber) + args->op_flags |=XFS_DA_OP_JUSTCHECK ; + +if (args->dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) +return xfs_dir2_sf_addname (args); + + error =xfs_dir2_isblock (args, &is_block); +if (error) +return error; +if (is_block) +return xfs_dir2_block_addname (args); + + error =xfs_dir2_isleaf (args, &is_leaf); +if (error) +return error; +if (is_leaf) +return xfs_dir2_leaf_addname (args); +return xfs_dir2_node_addname (args); +} +/* * Enter a name in a directory, or check for available space. * If inum is 0, only the available space test is performed.
@@ -269,7 +296,6 @@ xfs_dir_createname( {struct xfs_da_args *args;int rval; -bool v;ASSERT (S_ISDIR (VFS_I (dp)->i_mode));
@@ -296,31 +322,8 @@ xfs_dir_createname( args->trans = tp; args->op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ; args->owner = dp->i_ino; -if (!inum) - args->op_flags |=XFS_DA_OP_JUSTCHECK ; -if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { - rval =xfs_dir2_sf_addname (args); - goto out_free; - } - - rval =xfs_dir2_isblock (args, &v); -if (rval) - goto out_free; -if (v) { - rval =xfs_dir2_block_addname (args); - goto out_free; - } - - rval =xfs_dir2_isleaf (args, &v); -if (rval) - goto out_free; -if (v) - rval =xfs_dir2_leaf_addname (args); -else - rval =xfs_dir2_node_addname (args); - -out_free: + rval =xfs_dir_createname_args (args);kfree (args);return rval; }
libxfs/xfs_dir2.h +1 -0
@@ -67,6 +67,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name);int xfs_dir_lookup_args (struct xfs_da_args *args); +int xfs_dir_createname_args (struct xfs_da_args *args);/* * Direct call from the bmap code, bypassing the generic directory layer.
PATCH 89/115 xfs: factor out a xfs_dir_removename_args helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 3866e6e669e2c1b3eebf580b8779ea55838c3f5a
Add a helper to switch between the different directory formats for removing a directory entry.
--- libxfs/xfs_dir2.c | 48 +++++++++++++++++++++++++----------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 26 insertions(+), 23 deletions(-)
libxfs/xfs_dir2.c +25 -23
@@ -443,6 +443,30 @@ xfs_dir_lookup(return rval; } +int +xfs_dir_removename_args ( +struct xfs_da_args *args) +{ +bool is_block, is_leaf; +int error; + +if (args->dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) +return xfs_dir2_sf_removename (args); + + error =xfs_dir2_isblock (args, &is_block); +if (error) +return error; +if (is_block) +return xfs_dir2_block_removename (args); + + error =xfs_dir2_isleaf (args, &is_leaf); +if (error) +return error; +if (is_leaf) +return xfs_dir2_leaf_removename (args); +return xfs_dir2_node_removename (args); +} +/* * Remove an entry from a directory. */
@@ -456,7 +480,6 @@ xfs_dir_removename( {struct xfs_da_args *args;int rval; -bool v;ASSERT (S_ISDIR (VFS_I (dp)->i_mode));XFS_STATS_INC (dp->i_mount, xs_dir_remove);
@@ -476,28 +499,7 @@ xfs_dir_removename( args->whichfork =XFS_DATA_FORK ; args->trans = tp; args->owner = dp->i_ino; - -if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { - rval =xfs_dir2_sf_removename (args); - goto out_free; - } - - rval =xfs_dir2_isblock (args, &v); -if (rval) - goto out_free; -if (v) { - rval =xfs_dir2_block_removename (args); - goto out_free; - } - - rval =xfs_dir2_isleaf (args, &v); -if (rval) - goto out_free; -if (v) - rval =xfs_dir2_leaf_removename (args); -else - rval =xfs_dir2_node_removename (args); -out_free: + rval =xfs_dir_removename_args (args);kfree (args);return rval; }
libxfs/xfs_dir2.h +1 -0
@@ -68,6 +68,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,int xfs_dir_lookup_args (struct xfs_da_args *args);int xfs_dir_createname_args (struct xfs_da_args *args); +int xfs_dir_removename_args (struct xfs_da_args *args);/* * Direct call from the bmap code, bypassing the generic directory layer.
PATCH 90/115 xfs: factor out a xfs_dir_replace_args helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: dfe5febe2b6a175d730861441bff4f726fc58a6c
Add a helper to switch between the different directory formats for removing a directory entry.
--- libxfs/xfs_dir2.c | 49 ++++++++++++++++++++++++++----------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 27 insertions(+), 23 deletions(-)
libxfs/xfs_dir2.c +26 -23
@@ -504,6 +504,31 @@ xfs_dir_removename(return rval; } +int +xfs_dir_replace_args ( +struct xfs_da_args *args) +{ +bool is_block, is_leaf; +int error; + +if (args->dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) +return xfs_dir2_sf_replace (args); + + error =xfs_dir2_isblock (args, &is_block); +if (error) +return error; +if (is_block) +return xfs_dir2_block_replace (args); + + error =xfs_dir2_isleaf (args, &is_leaf); +if (error) +return error; +if (is_leaf) +return xfs_dir2_leaf_replace (args); + +return xfs_dir2_node_replace (args); +} +/* * Replace the inode number of a directory entry. */
@@ -517,7 +542,6 @@ xfs_dir_replace( {struct xfs_da_args *args;int rval; -bool v;ASSERT (S_ISDIR (VFS_I (dp)->i_mode));
@@ -540,28 +564,7 @@ xfs_dir_replace( args->whichfork =XFS_DATA_FORK ; args->trans = tp; args->owner = dp->i_ino; - -if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { - rval =xfs_dir2_sf_replace (args); - goto out_free; - } - - rval =xfs_dir2_isblock (args, &v); -if (rval) - goto out_free; -if (v) { - rval =xfs_dir2_block_replace (args); - goto out_free; - } - - rval =xfs_dir2_isleaf (args, &v); -if (rval) - goto out_free; -if (v) - rval =xfs_dir2_leaf_replace (args); -else - rval =xfs_dir2_node_replace (args); -out_free: + rval =xfs_dir_replace_args (args);kfree (args);return rval; }
libxfs/xfs_dir2.h +1 -0
@@ -69,6 +69,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,int xfs_dir_lookup_args (struct xfs_da_args *args);int xfs_dir_createname_args (struct xfs_da_args *args);int xfs_dir_removename_args (struct xfs_da_args *args); +int xfs_dir_replace_args (struct xfs_da_args *args);/* * Direct call from the bmap code, bypassing the generic directory layer.
PATCH 91/115 xfs: refactor dir format helpers
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: e58ac1770ded2a316447ca7608bb7809af82eca6
Add a new enum and a xfs_dir2_format helper that returns it to allow the code to switch on the format of a directory in a single operation and switch all helpers of xfs_dir2_isblock and xfs_dir2_isleaf to it.
This also removes the explicit xfs_iread_extents call in a few of the call sites given that xfs_bmap_last_offset already takes care of it underneath.
--- db/namei.c | 18 ++-- libxfs/libxfs_api_defs.h | 3 - libxfs/xfs_dir2.c | 188 ++++++++++++++++++---------------------------- libxfs/xfs_dir2.h | 12 ++- libxfs/xfs_exchmaps.c | 9 -- repair/phase6.c | 21 ++--- 6 files changed, 105 insertions(+), 146 deletions(-)
db/namei.c +9 -9
@@ -449,18 +449,18 @@ listdir( .geo = dp->i_mount->m_dir_geo, };int error; -bool isblock; -if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) +switch (libxfs_dir2_format (&args, &error)) { +case XFS_DIR2_FMT_SF :return list_sfdir (&args); - - error = -libxfs_dir2_isblock (&args, &isblock); -if (error) -return error; - -if (isblock) +case XFS_DIR2_FMT_BLOCK :return list_blockdir (&args); -return list_leafdir (&args); +case XFS_DIR2_FMT_LEAF : +case XFS_DIR2_FMT_NODE : +return list_leafdir (&args); +default : +return error; + } }/* List the inode number of the currently selected inode. */
libxfs/libxfs_api_defs.h +1 -2
@@ -122,9 +122,8 @@#define xfs_dir2_data_use_free libxfs_dir2_data_use_free#define xfs_dir2_free_hdr_from_disk libxfs_dir2_free_hdr_from_disk#define xfs_dir2_hashname libxfs_dir2_hashname -#define xfs_dir2_isblock libxfs_dir2_isblock -#define xfs_dir2_isleaf libxfs_dir2_isleaf#define xfs_dir2_leaf_hdr_from_disk libxfs_dir2_leaf_hdr_from_disk +#define xfs_dir2_format libxfs_dir2_format#define xfs_dir2_namecheck libxfs_dir2_namecheck#define xfs_dir2_sf_entsize libxfs_dir2_sf_entsize#define xfs_dir2_sf_get_ftype libxfs_dir2_sf_get_ftype
libxfs/xfs_dir2.c +73 -115
246 lines not on this page · raw message
libxfs/xfs_dir2.h +10 -2
@@ -36,6 +36,16 @@ xfs_dir2_samename(return !memcmp (n1->name, n2->name, n1->len); } +enum xfs_dir2_fmt { +XFS_DIR2_FMT_SF , +XFS_DIR2_FMT_BLOCK , +XFS_DIR2_FMT_LEAF , +XFS_DIR2_FMT_NODE , +XFS_DIR2_FMT_ERROR , +}; + +enum xfs_dir2_fmt xfs_dir2_format (struct xfs_da_args *args,int *error); +/* * Convert inode mode to directory entry filetype */
@@ -79,8 +89,6 @@ extern int xfs_dir2_sf_to_block(struct xfs_da_args *args);/* * Interface routines used by userspace utilities */ -extern int xfs_dir2_isblock (struct xfs_da_args *args,bool *isblock); -extern int xfs_dir2_isleaf (struct xfs_da_args *args,bool *isleaf);extern int xfs_dir2_shrink_inode (struct xfs_da_args *args,xfs_dir2_db_t db,struct xfs_buf *bp);
libxfs/xfs_exchmaps.c +2 -7
@@ -462,17 +462,12 @@ xfs_exchmaps_dir_to_sf( };struct xfs_dir2_sf_hdr sfh;struct xfs_buf *bp; -bool isblock;int size; -int error; +int error =0 ; - error =xfs_dir2_isblock (&args, &isblock); -if (error) +if (xfs_dir2_format (&args, &error) !=XFS_DIR2_FMT_BLOCK )return error; -if (!isblock) -return 0 ; - error =xfs_dir3_block_read (tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, &bp);if (error)return error;
repair/phase6.c +10 -11
@@ -2269,12 +2269,12 @@ longform_dir2_entry_check(xfs_dablk_t da_bno;freetab_t *freetab;int i; -bool isblock; -bool isleaf; +enum xfs_dir2_fmt fmt;xfs_fileoff_t next_da_bno;int seeval;int fixit =0 ;struct xfs_da_args args; +int error; *need_dot =1 ; freetab =malloc (FREETAB_SIZE (ip->i_disk_size / mp->m_dir_geo->blksize));
@@ -2294,8 +2294,7 @@ longform_dir2_entry_check(/* is this a block, leaf, or node directory? */ args.dp = ip; args.geo = mp->m_dir_geo; -libxfs_dir2_isblock (&args, &isblock); -libxfs_dir2_isleaf (&args, &isleaf); + fmt =libxfs_dir2_format (&args, &error);/* check directory "data" blocks (ie. name/inode pairs) */ for (da_bno = 0, next_da_bno = 0;
@@ -2318,7 +2317,7 @@ longform_dir2_entry_check(break ; } -if (isblock) +if (fmt ==XFS_DIR2_FMT_BLOCK ) ops = &xfs_dir3_block_buf_ops;else ops = &xfs_dir3_data_buf_ops;
@@ -2335,7 +2334,7 @@ longform_dir2_entry_check(* block form and we fail, there isn't anything else to * read, and nothing we can do but trash it. */ -if (isblock) { +if (fmt ==XFS_DIR2_FMT_BLOCK ) { fixit++; goto out_fix; }
@@ -2349,7 +2348,7 @@ longform_dir2_entry_check( error =check_dir3_header (mp, bp, ino);if (error) { fixit++; -if (isblock) +if (fmt ==XFS_DIR2_FMT_BLOCK ) goto out_fix;libxfs_buf_relse (bp);
@@ -2360,8 +2359,8 @@ longform_dir2_entry_check(longform_dir2_entry_check_data (mp, ip, num_illegal, need_dot, irec, ino_offset, bp, hashtab, - &freetab, da_bno, isblock); -if (isblock) + &freetab, da_bno, fmt ==XFS_DIR2_FMT_BLOCK ); +if (fmt ==XFS_DIR2_FMT_BLOCK )break ;libxfs_buf_relse (bp);
@@ -2371,7 +2370,7 @@ longform_dir2_entry_check(if (!dotdot_update) {/* check btree and freespace */ -if (isblock) { +if (fmt ==XFS_DIR2_FMT_BLOCK ) {struct xfs_dir2_data_hdr *block;xfs_dir2_block_tail_t *btp;xfs_dir2_leaf_entry_t *blp;
@@ -2384,7 +2383,7 @@ longform_dir2_entry_check( be32_to_cpu(btp->stale));if (dir_hash_check (hashtab, ip, seeval)) fixit |=1 ; - }else if (isleaf) { + }else if (fmt ==XFS_DIR2_FMT_LEAF ) { fixit |=longform_dir2_check_leaf (mp, ip, hashtab, freetab); }else {
PATCH 92/115 xfs: make the seq argument to xfs_bmapi_convert_delalloc() optional
In reply to Darrick J. WongFrom: Zhang Yi <[email protected]>
Source kernel commit: fc8d0ba0ff5fe4700fa02008b7751ec6b84b7677
Allow callers to pass a NULLL seq argument if they don't care about the fork sequence number.
--- libxfs/xfs_bmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libxfs/xfs_bmap.c +4 -2
@@ -4642,7 +4642,8 @@ xfs_bmapi_convert_delalloc(if (!isnullstartblock (bma.got.br_startblock)) {xfs_bmbt_to_iomap (ip, iomap, &bma.got,0 , flags,xfs_iomap_inode_sequence (ip, flags)); - *seq =READ_ONCE (ifp->if_seq); +if (seq) + *seq =READ_ONCE (ifp->if_seq); goto out_trans_cancel; }
@@ -4693,7 +4694,8 @@ xfs_bmapi_convert_delalloc(ASSERT (!isnullstartblock (bma.got.br_startblock));xfs_bmbt_to_iomap (ip, iomap, &bma.got,0 , flags,xfs_iomap_inode_sequence (ip, flags)); - *seq =READ_ONCE (ifp->if_seq); +if (seq) + *seq =READ_ONCE (ifp->if_seq);if (whichfork ==XFS_COW_FORK )xfs_refcount_alloc_cow_extent (tp, bma.blkno, bma.length);
PATCH 93/115 xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset
In reply to Darrick J. WongFrom: Zhang Yi <[email protected]>
Source kernel commit: 2e08371a83f1c06fd85eea8cd37c87a224cc4cc4
Since xfs_bmapi_convert_delalloc() only attempts to allocate the entire delalloc extent and require multiple invocations to allocate the target offset. So xfs_convert_blocks() add a loop to do this job and we call it in the write back path, but xfs_convert_blocks() isn't a common helper. Let's do it in xfs_bmapi_convert_delalloc() and drop xfs_convert_blocks(), preparing for the post EOF delalloc blocks converting in the buffered write begin path.
--- libxfs/libxfs_priv.h | 5 ++++- libxfs/xfs_bmap.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-)
libxfs/libxfs_priv.h +4 -1
@@ -79,7 +79,10 @@ extern struct kmem_cache *xfs_trans_cache;#define crc32c (c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))/* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */ -struct iomap ; +struct iomap { +unsigned long long offset;/* do not use */ +unsigned long long length;/* do not use */ +};#define cancel_delayed_work_sync (work) do { } while(0)
libxfs/xfs_bmap.c +32 -2
@@ -4584,8 +4584,8 @@ xfs_bmapi_write(* invocations to allocate the target offset if a large enough physical extent * is not available. */ -int -xfs_bmapi_convert_delalloc( +static int +xfs_bmapi_convert_one_delalloc( struct xfs_inode *ip, int whichfork, xfs_off_t offset,
@@ -4718,6 +4718,36 @@ xfs_bmapi_convert_delalloc(return error; } +/* +* Pass in a dellalloc extent and convert it to real extents, return the real +* extent that maps offset_fsb in iomap. +*/ +int +xfs_bmapi_convert_delalloc ( +struct xfs_inode *ip, +int whichfork, +loff_t offset, +struct iomap *iomap, +unsigned int *seq) +{ +int error; + +/* +* Attempt to allocate whatever delalloc extent currently backs offset +* and put the result into iomap. Allocate in a loop because it may +* take several attempts to allocate real blocks for a contiguous +* delalloc extent if free space is sufficiently fragmented. +*/ +do { + error =xfs_bmapi_convert_one_delalloc (ip, whichfork, offset, + iomap, seq); +if (error) +return error; + }while (iomap->offset + iomap->length <= offset); + +return 0 ; +} + int xfs_bmapi_remap( struct xfs_trans *tp,
PATCH 94/115 xfs: fix error returns from xfs_bmapi_write
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 6773da870ab89123d1b513da63ed59e32a29cb77
xfs_bmapi_write can return 0 without actually returning a mapping in mval in two different cases:
1) when there is absolutely no space available to do an allocation
2) when converting delalloc space, and the allocation is so small that it only covers parts of the delalloc extent before the range requested by the caller
Callers at best can handle one of these cases, but in many cases can't cope with either one. Switch xfs_bmapi_write to always return a mapping or return an error code instead. For case 1) above ENOSPC is the obvious choice which is very much what the callers expect anyway. For case 2) there is no really good error code, so pick a funky one from the SysV streams portfolio.
This fixes the reproducer here:
which uses reserved blocks to create file systems that are gravely out of space and thus cause at least xfs_file_alloc_space to hang and trigger the lack of ENOSPC handling in xfs_dquot_disk_alloc.
Note that this patch does not actually make any caller but xfs_alloc_file_space deal intelligently with case 2) above.
--- libxfs/xfs_attr_remote.c | 1 - libxfs/xfs_bmap.c | 46 +++++++++++++++++++++++++++++++++++++--------- libxfs/xfs_da_btree.c | 20 +++++--------------- 3 files changed, 42 insertions(+), 25 deletions(-)
libxfs/xfs_attr_remote.c +0 -1
@@ -624,7 +624,6 @@ xfs_attr_rmtval_set_blk(if (error)return error; -ASSERT (nmap ==1 );ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && (map->br_startblock !=HOLESTARTBLOCK ));
libxfs/xfs_bmap.c +37 -9
84 lines not on this page · raw message
libxfs/xfs_da_btree.c +5 -15
@@ -2293,8 +2293,8 @@ xfs_da_grow_inode_int(struct xfs_inode *dp = args->dp;int w = args->whichfork;xfs_rfsblock_t nblks = dp->i_nblocks; -struct xfs_bmbt_irec map, *mapp; -int nmap, error, got, i, mapi; +struct xfs_bmbt_irec map, *mapp = ↦ +int nmap, error, got, i, mapi =1 ;/* * Find a spot in the file space to put the new block.
@@ -2310,14 +2310,7 @@ xfs_da_grow_inode_int( error =xfs_bmapi_write (tp, dp, *bno, count,xfs_bmapi_aflag (w)|XFS_BMAPI_METADATA |XFS_BMAPI_CONTIG , args->total, &map, &nmap); -if (error) -return error; - -ASSERT (nmap <=1 ); -if (nmap ==1 ) { - mapp = ↦ - mapi =1 ; - }else if (nmap ==0 && count >1 ) { +if (error == -ENOSPC && count >1 ) {xfs_fileoff_t b;int c;
@@ -2335,16 +2328,13 @@ xfs_da_grow_inode_int( args->total, &mapp[mapi], &nmap);if (error) goto out_free_map; -if (nmap <1 ) -break ; mapi += nmap; b = mapp[mapi -1 ].br_startoff + mapp[mapi -1 ].br_blockcount; } - }else { - mapi =0 ; - mapp =NULL ; } +if (error) + goto out_free_map;/* * Count the blocks we got, make sure it matches the total.
PATCH 95/115 xfs: remove the unusued tmp_logflags variable in xfs_bmapi_allocate
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: b11ed354c9f725ece2b9440dd6343b42cd5d031c
tmp_logflags is initialized to 0 and then ORed into bma->logflags, which isn't actually doing anything.
--- libxfs/xfs_bmap.c | 3 --- 1 file changed, 3 deletions(-)
libxfs/xfs_bmap.c +0 -3
@@ -4176,7 +4176,6 @@ xfs_bmapi_allocate(struct xfs_mount *mp = bma->ip->i_mount;int whichfork =xfs_bmapi_whichfork (bma->flags);struct xfs_ifork *ifp =xfs_ifork_ptr (bma->ip, whichfork); -int tmp_logflags =0 ;int error;ASSERT (bma->length >0 );
@@ -4247,8 +4246,6 @@ xfs_bmapi_allocate( error =xfs_bmap_add_extent_hole_real (bma->tp, bma->ip, whichfork, &bma->icur, &bma->cur, &bma->got, &bma->logflags, bma->flags); - - bma->logflags |= tmp_logflags;if (error)return error;
PATCH 96/115 xfs: lift a xfs_valid_startblock into xfs_bmapi_allocate
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 04c609e6e5066294b60329420d3711e990c47abf
xfs_bmapi_convert_delalloc has a xfs_valid_startblock check on the block allocated by xfs_bmapi_allocate. Lift it into xfs_bmapi_allocate as we should assert the same for xfs_bmapi_write.
--- libxfs/xfs_bmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
libxfs/xfs_bmap.c +5 -6
@@ -4215,6 +4215,11 @@ xfs_bmapi_allocate(if (bma->blkno ==NULLFSBLOCK )return -ENOSPC ; +if (WARN_ON_ONCE (!xfs_valid_startblock (bma->ip, bma->blkno))) { +xfs_bmap_mark_sick (bma->ip, whichfork); +return -EFSCORRUPTED ; + } +if (bma->flags &XFS_BMAPI_ZERO ) { error =xfs_zero_extent (bma->ip, bma->blkno, bma->length);if (error)
@@ -4707,12 +4712,6 @@ xfs_bmapi_convert_one_delalloc(if (error) goto out_finish; -if (WARN_ON_ONCE (!xfs_valid_startblock (ip, bma.got.br_startblock))) { -xfs_bmap_mark_sick (ip, whichfork); - error = -EFSCORRUPTED ; - goto out_finish; - } -XFS_STATS_ADD (mp, xs_xstrat_bytes,XFS_FSB_TO_B (mp, bma.length));XFS_STATS_INC (mp, xs_xstrat_quick);
PATCH 97/115 xfs: don't open code XFS_FILBLKS_MIN in xfs_bmapi_write
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 9d06960341ec5f45d3d65bdead3fbce753455e8a
XFS_FILBLKS_MIN uses min_t and thus does the comparison using the correct xfs_filblks_t type. Use it in xfs_bmapi_write and slightly adjust the comment document th potential pitfall to take account of this
--- libxfs/xfs_bmap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
libxfs/xfs_bmap.c +3 -6
@@ -4522,14 +4522,11 @@ xfs_bmapi_write(* allocation length request (which can be 64 bits in * length) and the bma length request, which is * xfs_extlen_t and therefore 32 bits. Hence we have to -* check for 32-bit overflows and handle them here. +* be careful and do the min() using the larger type to +* avoid overflows. */ -if (len > (xfs_filblks_t )XFS_MAX_BMBT_EXTLEN ) - bma.length =XFS_MAX_BMBT_EXTLEN ; -else - bma.length = len; + bma.length =XFS_FILBLKS_MIN (len,XFS_MAX_BMBT_EXTLEN ); -ASSERT (len >0 );ASSERT (bma.length >0 ); error =xfs_bmapi_allocate (&bma);if (error) {
PATCH 98/115 xfs: pass the actual offset and len to allocate to xfs_bmapi_allocate
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 2a9b99d45be0981536f6d3faf40ae3f58febdd49
xfs_bmapi_allocate currently overwrites offset and len when converting delayed allocations, and duplicates the length cap done for non-delalloc allocations. Move all that logic into the callers to avoid duplication and to make the calling conventions more obvious.
--- libxfs/xfs_bmap.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
libxfs/xfs_bmap.c +18 -14
@@ -4179,21 +4179,11 @@ xfs_bmapi_allocate(int error;ASSERT (bma->length >0 ); +ASSERT (bma->length <=XFS_MAX_BMBT_EXTLEN ); -/* -* For the wasdelay case, we could also just allocate the stuff asked -* for in this bmap call but that wouldn't be as good. -*/ if (bma->wasdel) { - bma->length = (xfs_extlen_t )bma->got.br_blockcount; - bma->offset = bma->got.br_startoff;if (!xfs_iext_peek_prev_extent (ifp, &bma->icur, &bma->prev)) bma->prev.br_startoff =NULLFILEOFF ; - }else { - bma->length =XFS_FILBLKS_MIN (bma->length,XFS_MAX_BMBT_EXTLEN ); -if (!bma->eof) - bma->length =XFS_FILBLKS_MIN (bma->length, - bma->got.br_startoff - bma->offset); }if (bma->flags &XFS_BMAPI_CONTIG )
@@ -4527,6 +4517,15 @@ xfs_bmapi_write(*/ bma.length =XFS_FILBLKS_MIN (len,XFS_MAX_BMBT_EXTLEN ); +if (wasdelay) { + bma.offset = bma.got.br_startoff; + bma.length = bma.got.br_blockcount; + }else { +if (!eof) + bma.length =XFS_FILBLKS_MIN (bma.length, + bma.got.br_startoff - bno); + } +ASSERT (bma.length >0 ); error =xfs_bmapi_allocate (&bma);if (error) {
@@ -4680,10 +4679,15 @@ xfs_bmapi_convert_one_delalloc( bma.tp = tp; bma.ip = ip; bma.wasdel = true; + bma.minleft =xfs_bmapi_minleft (tp, ip, whichfork); + +/* +* Always allocate convert from the start of the delalloc extent even if +* that is outside the passed in range to create large contiguous +* extents on disk. +*/ bma.offset = bma.got.br_startoff; - bma.length =max_t (xfs_filblks_t, bma.got.br_blockcount, -XFS_MAX_BMBT_EXTLEN ); - bma.minleft =xfs_bmapi_minleft (tp, ip, whichfork); + bma.length = bma.got.br_blockcount;/* * When we're converting the delalloc reservations backing dirty pages
PATCH 99/115 xfs: remove the xfs_iext_peek_prev_extent call in xfs_bmapi_allocate
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: a8bb258f703f42c322638022afa16808ca4a7d25
Both callers of xfs_bmapi_allocate already initialize bma->prev, don't redo that in xfs_bmapi_allocate.
--- libxfs/xfs_bmap.c | 5 ----- 1 file changed, 5 deletions(-)
libxfs/xfs_bmap.c +0 -5
@@ -4181,11 +4181,6 @@ xfs_bmapi_allocate(ASSERT (bma->length >0 );ASSERT (bma->length <=XFS_MAX_BMBT_EXTLEN ); -if (bma->wasdel) { -if (!xfs_iext_peek_prev_extent (ifp, &bma->icur, &bma->prev)) - bma->prev.br_startoff =NULLFILEOFF ; - } -if (bma->flags &XFS_BMAPI_CONTIG ) bma->minlen = bma->length;else
PATCH 100/115 xfs: fix xfs_bmap_add_extent_delay_real for partial conversions
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: d69bee6a35d3c5e4873b9e164dd1a9711351a97c
xfs_bmap_add_extent_delay_real takes parts or all of a delalloc extent and converts them to a real extent. It is written to deal with any potential overlap of the to be converted range with the delalloc extent, but it turns out that currently only converting the entire extents, or a part starting at the beginning is actually exercised, as the only caller always tries to convert the entire delalloc extent, and either succeeds or at least progresses partially from the start.
If it only converts a tiny part of a delalloc extent, the indirect block calculation for the new delalloc extent (da_new) might be equivalent to that of the existing delalloc extent (da_old). If this extent conversion now requires allocating an indirect block that gets accounted into da_new, leading to the assert that da_new must be smaller or equal to da_new unless we split the extent to trigger.
Except for the assert that case is actually handled by just trying to allocate more space, as that already handled for the split case (which currently can't be reached at all), so just reusing it should be fine. Except that without dipping into the reserved block pool that would make it a bit too easy to trigger a fs shutdown due to ENOSPC. So in addition to adjusting the assert, also dip into the reserved block pool.
Note that I could only reproduce the assert with a change to only convert the actually asked range instead of the full delalloc extent from xfs_bmapi_write.
--- libxfs/xfs_bmap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
libxfs/xfs_bmap.c +10 -5
@@ -1564,6 +1564,7 @@ xfs_bmap_add_extent_delay_real(if (error) goto done; } +ASSERT (da_new <= da_old);break ;case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG :
@@ -1594,6 +1595,7 @@ xfs_bmap_add_extent_delay_real(if (error) goto done; } +ASSERT (da_new <= da_old);break ;case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG :
@@ -1628,6 +1630,7 @@ xfs_bmap_add_extent_delay_real(if (error) goto done; } +ASSERT (da_new <= da_old);break ;case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING :
@@ -1662,6 +1665,7 @@ xfs_bmap_add_extent_delay_real( goto done; } } +ASSERT (da_new <= da_old);break ;case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG :
@@ -1700,6 +1704,7 @@ xfs_bmap_add_extent_delay_real(if (error) goto done; } +ASSERT (da_new <= da_old);break ;case BMAP_LEFT_FILLING :
@@ -1790,6 +1795,7 @@ xfs_bmap_add_extent_delay_real(xfs_iext_update_extent (bma->ip, state, &bma->icur, &PREV );xfs_iext_next (ifp, &bma->icur);xfs_iext_update_extent (bma->ip, state, &bma->icur, &RIGHT ); +ASSERT (da_new <= da_old);break ;case BMAP_RIGHT_FILLING :
@@ -1839,6 +1845,7 @@ xfs_bmap_add_extent_delay_real(PREV .br_blockcount = temp;xfs_iext_insert (bma->ip, &bma->icur, &PREV , state);xfs_iext_next (ifp, &bma->icur); +ASSERT (da_new <= da_old);break ;case 0 :
@@ -1961,12 +1968,10 @@ xfs_bmap_add_extent_delay_real( }/* adjust for changes in reserved delayed indirect blocks */ -if (da_new < da_old) { +if (da_new < da_old)xfs_add_fdblocks (mp, da_old - da_new); - }else if (da_new > da_old) { -ASSERT (state ==0 ); - error =xfs_dec_fdblocks (mp, da_new - da_old, false); - } +else if (da_new > da_old) + error =xfs_dec_fdblocks (mp, da_new - da_old, true);xfs_bmap_check_leaf_extents (bma->cur, bma->ip, whichfork); done:
PATCH 101/115 xfs: do not allocate the entire delalloc extent in xfs_bmapi_write
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 21255afdd7296f57dd65f815301426bcf911c82d
While trying to convert the entire delalloc extent is a good decision for regular writeback as it leads to larger contigous on-disk extents, but for other callers of xfs_bmapi_write is is rather questionable as it forced them to loop creating new transactions just in case there is no large enough contiguous extent to cover the whole delalloc reservation.
Change xfs_bmapi_write to only allocate the passed in range instead, whіle the writeback path through xfs_bmapi_convert_delalloc and xfs_bmapi_allocate still always converts the full extents.
--- libxfs/xfs_bmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libxfs/xfs_bmap.c +3 -2
@@ -4518,8 +4518,9 @@ xfs_bmapi_write( bma.length =XFS_FILBLKS_MIN (len,XFS_MAX_BMBT_EXTLEN );if (wasdelay) { - bma.offset = bma.got.br_startoff; - bma.length = bma.got.br_blockcount; + bma.length =XFS_FILBLKS_MIN (bma.length, + bma.got.br_blockcount - + (bno - bma.got.br_startoff)); }else {if (!eof) bma.length = XFS_FILBLKS_MIN(bma.length,
PATCH 102/115 xfs: use unsigned ints for non-negative quantities in xfs_attr_remote.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a86f8671d03e6eb31abaefdf6928b92df0a2368c
In the next few patches we're going to refactor the attr remote code so that we can support headerless remote xattr values for storing merkle tree blocks. For now, let's change the code to use unsigned int to describe quantities of bytes and blocks that cannot be negative.
--- libxfs/xfs_attr_remote.c | 61 +++++++++++++++++++++++----------------------- libxfs/xfs_attr_remote.h | 2 +- 2 files changed, 31 insertions(+), 32 deletions(-)
libxfs/xfs_attr_remote.c +30 -31
@@ -46,13 +46,13 @@* Each contiguous block has a header, so it is not just a simple attribute * length to FSB conversion. */ -int +unsigned int xfs_attr3_rmt_blocks ( -struct xfs_mount *mp, -int attrlen) +struct xfs_mount *mp, +unsigned int attrlen) {if (xfs_has_crc (mp)) { -int buflen =XFS_ATTR3_RMT_BUF_SPACE (mp, mp->m_sb.sb_blocksize); +unsigned int buflen =XFS_ATTR3_RMT_BUF_SPACE (mp, mp->m_sb.sb_blocksize);return (attrlen + buflen -1 ) / buflen; }return XFS_B_TO_FSB (mp, attrlen);
@@ -91,7 +91,6 @@ xfs_attr3_rmt_verify(struct xfs_mount *mp, struct xfs_buf *bp, void *ptr, - int fsbsize, xfs_daddr_t bno) { struct xfs_attr3_rmt_hdr *rmt = ptr;
@@ -102,7 +101,7 @@ xfs_attr3_rmt_verify(return __this_address;if (be64_to_cpu (rmt->rm_blkno) != bno)return __this_address; -if (be32_to_cpu (rmt->rm_bytes) > fsbsize -sizeof (*rmt)) +if (be32_to_cpu (rmt->rm_bytes) > mp->m_attr_geo->blksize -sizeof (*rmt))return __this_address;if (be32_to_cpu (rmt->rm_offset) +be32_to_cpu (rmt->rm_bytes) >XFS_XATTR_SIZE_MAX )
@@ -121,9 +120,9 @@ __xfs_attr3_rmt_read_verify( {struct xfs_mount *mp = bp->b_mount;char *ptr; -int len; +unsigned int len;xfs_daddr_t bno; -int blksize = mp->m_attr_geo->blksize; +unsigned int blksize = mp->m_attr_geo->blksize;/* no verification of non-crc buffers */ if (!xfs_has_crc (mp))
@@ -140,7 +139,7 @@ __xfs_attr3_rmt_read_verify( *failaddr = __this_address;return -EFSBADCRC ; } - *failaddr =xfs_attr3_rmt_verify (mp, bp, ptr, blksize, bno); + *failaddr =xfs_attr3_rmt_verify (mp, bp, ptr, bno);if (*failaddr)return -EFSCORRUPTED ; len -= blksize;
@@ -185,7 +184,7 @@ xfs_attr3_rmt_write_verify( {struct xfs_mount *mp = bp->b_mount;xfs_failaddr_t fa; -int blksize = mp->m_attr_geo->blksize; +unsigned int blksize = mp->m_attr_geo->blksize;char *ptr;int len;xfs_daddr_t bno;
@@ -202,7 +201,7 @@ xfs_attr3_rmt_write_verify(while (len >0 ) {struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; - fa =xfs_attr3_rmt_verify (mp, bp, ptr, blksize, bno); + fa =xfs_attr3_rmt_verify (mp, bp, ptr, bno);if (fa) {xfs_verifier_error (bp, -EFSCORRUPTED , fa);return ;
@@ -280,20 +279,20 @@ xfs_attr_rmtval_copyout(struct xfs_buf *bp, struct xfs_inode *dp, xfs_ino_t owner, - int *offset, - int *valuelen, + unsigned int *offset, + unsigned int *valuelen, uint8_t **dst) { char *src = bp->b_addr;xfs_daddr_t bno =xfs_buf_daddr (bp); -int len =BBTOB (bp->b_length); -int blksize = mp->m_attr_geo->blksize; +unsigned int len =BBTOB (bp->b_length); +unsigned int blksize = mp->m_attr_geo->blksize;ASSERT (len >= blksize);while (len >0 && *valuelen >0 ) { -int hdr_size =0 ; -int byte_cnt =XFS_ATTR3_RMT_BUF_SPACE (mp, blksize); +unsigned int hdr_size =0 ; +unsigned int byte_cnt =XFS_ATTR3_RMT_BUF_SPACE (mp, blksize); byte_cnt =min (*valuelen, byte_cnt);
@@ -329,20 +328,20 @@ xfs_attr_rmtval_copyin(struct xfs_mount *mp, struct xfs_buf *bp, xfs_ino_t ino, - int *offset, - int *valuelen, + unsigned int *offset, + unsigned int *valuelen, uint8_t **src) { char *dst = bp->b_addr;xfs_daddr_t bno =xfs_buf_daddr (bp); -int len =BBTOB (bp->b_length); -int blksize = mp->m_attr_geo->blksize; +unsigned int len =BBTOB (bp->b_length); +unsigned int blksize = mp->m_attr_geo->blksize;ASSERT (len >= blksize); while (len > 0 && *valuelen > 0) { - int hdr_size; - int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); + unsigned int hdr_size; + unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); byte_cnt = min(*valuelen, byte_cnt); hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
@@ -388,12 +387,12 @@ xfs_attr_rmtval_get(struct xfs_buf *bp;xfs_dablk_t lblkno = args->rmtblkno;uint8_t *dst = args->value; -int valuelen; +unsigned int valuelen;int nmap;int error; -int blkcnt = args->rmtblkcnt; +unsigned int blkcnt = args->rmtblkcnt;int i; -int offset =0 ; +unsigned int offset =0 ;trace_xfs_attr_rmtval_get (args);
@@ -451,7 +450,7 @@ xfs_attr_rmt_find_hole(struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount;int error; -int blkcnt; +unsigned int blkcnt;xfs_fileoff_t lfileoff =0 ;/*
@@ -480,11 +479,11 @@ xfs_attr_rmtval_set_value(struct xfs_bmbt_irec map;xfs_dablk_t lblkno;uint8_t *src = args->value; -int blkcnt; -int valuelen; +unsigned int blkcnt; +unsigned int valuelen;int nmap;int error; -int offset =0 ; +unsigned int offset =0 ;/* * Roll through the "value", copying the attribute value to the
@@ -643,7 +642,7 @@ xfs_attr_rmtval_invalidate( struct xfs_da_args *args) {xfs_dablk_t lblkno; -int blkcnt; +unsigned int blkcnt;int error;/*
libxfs/xfs_attr_remote.h +1 -1
@@ -6,7 +6,7 @@#ifndef __XFS_ATTR_REMOTE_H__#define __XFS_ATTR_REMOTE_H__ -int xfs_attr3_rmt_blocks (struct xfs_mount *mp,int attrlen); +unsigned int xfs_attr3_rmt_blocks (struct xfs_mount *mp,unsigned int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args); int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
PATCH 103/115 xfs: turn XFS_ATTR3_RMT_BUF_SPACE into a function
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a5714b67cad586f44777ad834e577037ce6b64fd
Turn this into a properly typechecked function, and actually use the correct blocksize for extended attributes. The function cannot be static inline because xfsprogs userspace uses it.
--- db/attr.c | 2 +- db/metadump.c | 8 ++++---- libxfs/xfs_attr_remote.c | 19 ++++++++++++++++--- libxfs/xfs_da_format.h | 4 +--- 4 files changed, 22 insertions(+), 11 deletions(-)
db/attr.c +1 -1
@@ -214,7 +214,7 @@ attr3_remote_data_count(if (hdr->rm_magic !=cpu_to_be32 (XFS_ATTR3_RMT_MAGIC ))return 0 ; - buf_space =XFS_ATTR3_RMT_BUF_SPACE (mp, mp->m_sb.sb_blocksize); + buf_space =xfs_attr3_rmt_buf_space (mp);if (be32_to_cpu (hdr->rm_bytes) > buf_space)return buf_space;return be32_to_cpu (hdr->rm_bytes);
db/metadump.c +4 -4
@@ -1369,7 +1369,7 @@ add_remote_vals( attr_data.remote_vals[attr_data.remote_val_count] = blockidx; attr_data.remote_val_count++; blockidx++; - length -=XFS_ATTR3_RMT_BUF_SPACE (mp, mp->m_sb.sb_blocksize); + length -=xfs_attr3_rmt_buf_space (mp); }if (attr_data.remote_val_count >=MAX_REMOTE_VALS ) {
@@ -1405,8 +1405,8 @@ process_attr_block( attr_data.remote_vals[i] == offset)/* Macros to handle both attr and attr3 */ memset (block + - (bs -XFS_ATTR3_RMT_BUF_SPACE (mp, bs)), -'v' ,XFS_ATTR3_RMT_BUF_SPACE (mp, bs)); + (bs -xfs_attr3_rmt_buf_space (mp)), +'v' ,xfs_attr3_rmt_buf_space (mp)); }return ; }
@@ -1418,7 +1418,7 @@ process_attr_block(if (nentries ==0 || nentries *sizeof (xfs_attr_leaf_entry_t) +xfs_attr3_leaf_hdr_size (leaf) > -XFS_ATTR3_RMT_BUF_SPACE (mp, bs)) { +xfs_attr3_rmt_buf_space (mp)) {if (metadump.show_warnings)print_warning ("invalid attr count in inode %llu" , (long long )metadump.cur_ino);
libxfs/xfs_attr_remote.c +16 -3
@@ -42,6 +42,19 @@* the logging system and therefore never have a log item. */ +/* How many bytes can be stored in a remote value buffer? */ +inline unsigned int +xfs_attr3_rmt_buf_space ( +struct xfs_mount *mp) +{ +unsigned int blocksize = mp->m_attr_geo->blksize; + +if (xfs_has_crc (mp)) +return blocksize -sizeof (struct xfs_attr3_rmt_hdr ); + +return blocksize; +} +/* * Each contiguous block has a header, so it is not just a simple attribute * length to FSB conversion.
@@ -52,7 +65,7 @@ xfs_attr3_rmt_blocks( unsigned int attrlen) {if (xfs_has_crc (mp)) { -unsigned int buflen =XFS_ATTR3_RMT_BUF_SPACE (mp, mp->m_sb.sb_blocksize); +unsigned int buflen =xfs_attr3_rmt_buf_space (mp);return (attrlen + buflen -1 ) / buflen; }return XFS_B_TO_FSB (mp, attrlen);
@@ -292,7 +305,7 @@ xfs_attr_rmtval_copyout(while (len >0 && *valuelen >0 ) {unsigned int hdr_size =0 ; -unsigned int byte_cnt =XFS_ATTR3_RMT_BUF_SPACE (mp, blksize); +unsigned int byte_cnt =xfs_attr3_rmt_buf_space (mp); byte_cnt =min (*valuelen, byte_cnt);
@@ -341,7 +354,7 @@ xfs_attr_rmtval_copyin(while (len >0 && *valuelen >0 ) {unsigned int hdr_size; -unsigned int byte_cnt =XFS_ATTR3_RMT_BUF_SPACE (mp, blksize); +unsigned int byte_cnt =xfs_attr3_rmt_buf_space (mp); byte_cnt =min (*valuelen, byte_cnt); hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
libxfs/xfs_da_format.h +1 -3
@@ -880,9 +880,7 @@ struct xfs_attr3_rmt_hdr {#define XFS_ATTR3_RMT_CRC_OFF offsetof(struct xfs_attr3_rmt_hdr, rm_crc) -#define XFS_ATTR3_RMT_BUF_SPACE (mp, bufsize) \ - ((bufsize) - (xfs_has_crc((mp)) ? \ - sizeof(struct xfs_attr3_rmt_hdr) : 0)) +unsigned int xfs_attr3_rmt_buf_space (struct xfs_mount *mp);/* Number of bytes in a directory block. */ static inline unsigned int xfs_dir2_dirblock_bytes (struct xfs_sb *sbp)
PATCH 104/115 xfs: create a helper to compute the blockcount of a max sized remote value
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 204a26aa1d5a891154c9275fe4022e28793ca112
Create a helper function to compute the number of fsblocks needed to store a maximally-sized extended attribute value.
--- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr_remote.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
libxfs/xfs_attr.c +1 -1
@@ -1035,7 +1035,7 @@ xfs_attr_set(break ;case XFS_ATTRUPDATE_REMOVE :XFS_STATS_INC (mp, xs_attr_remove); - rmt_blks =xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX ); + rmt_blks =xfs_attr3_max_rmt_blocks (mp);break ; }
libxfs/xfs_attr_remote.h +6 -0
@@ -8,6 +8,12 @@unsigned int xfs_attr3_rmt_blocks (struct xfs_mount *mp,unsigned int attrlen); +/* Number of rmt blocks needed to store the maximally sized attr value */ +static inline unsigned int xfs_attr3_max_rmt_blocks (struct xfs_mount *mp) +{ +return xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX ); +} +int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);
PATCH 105/115 xfs: minor cleanups of xfs_attr3_rmt_blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 3791a053294b037a6bf62df03480f5c5ddfd4d1b
Clean up the type signature of this function since we don't have negative attr lengths or block counts.
--- libxfs/xfs_attr_remote.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
libxfs/xfs_attr_remote.c +8 -8
@@ -55,19 +55,19 @@ xfs_attr3_rmt_buf_space(return blocksize; } -/* -* Each contiguous block has a header, so it is not just a simple attribute -* length to FSB conversion. -*/ +/* Compute number of fsblocks needed to store a remote attr value */ unsigned int xfs_attr3_rmt_blocks (struct xfs_mount *mp,unsigned int attrlen) { -if (xfs_has_crc (mp)) { -unsigned int buflen =xfs_attr3_rmt_buf_space (mp); -return (attrlen + buflen -1 ) / buflen; - } +/* +* Each contiguous block has a header, so it is not just a simple +* attribute length to FSB conversion. +*/ +if (xfs_has_crc (mp)) +return howmany (attrlen,xfs_attr3_rmt_buf_space (mp)); +return XFS_B_TO_FSB (mp, attrlen); }
PATCH 106/115 xfs: xfs_quota_unreserve_blkres can't fail
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: cc3c92e7e79eb5f7f3ec4d5790ade384b7d294f7
Unreserving quotas can't fail due to quota limits, and we'll notice a shut down file system a bit later in all the callers anyway. Return void and remove the error checking and propagation in the callers.
--- libxfs/xfs_bmap.c | 16 +++++----------- libxfs/xfs_bmap.h | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-)
libxfs/xfs_bmap.c +5 -11
@@ -4922,7 +4922,7 @@ xfs_bmap_split_indlen( *indlen2 = len2; } -int +void xfs_bmap_del_extent_delay( struct xfs_inode *ip, int whichfork,
@@ -4938,7 +4938,6 @@ xfs_bmap_del_extent_delay(xfs_filblks_t got_indlen, new_indlen, stolen =0 ;uint32_t state =xfs_bmap_fork_to_state (whichfork);uint64_t fdblocks; -int error =0 ;bool isrt;XFS_STATS_INC (mp, xs_del_exlist);
@@ -4958,9 +4957,7 @@ xfs_bmap_del_extent_delay(* sb counters as we might have to borrow some blocks for the * indirect block accounting. */ - error =xfs_quota_unreserve_blkres (ip, del->br_blockcount); -if (error) -return error; +xfs_quota_unreserve_blkres (ip, del->br_blockcount); ip->i_delayed_blks -= del->br_blockcount;if (got->br_startoff == del->br_startoff)
@@ -5058,7 +5055,6 @@ xfs_bmap_del_extent_delay(xfs_add_fdblocks (mp, fdblocks);xfs_mod_delalloc (ip, -(int64_t )del->br_blockcount, -da_diff); -return error; }void
@@ -5616,18 +5612,16 @@ __xfs_bunmapi( delete:if (wasdel) { - error =xfs_bmap_del_extent_delay (ip, whichfork, &icur, - &got, &del); +xfs_bmap_del_extent_delay (ip, whichfork, &icur, &got, &del); }else { error =xfs_bmap_del_extent_real (ip, tp, &icur, cur, &del, &tmp_logflags, whichfork, flags); logflags |= tmp_logflags; +if (error) + goto error0; } -if (error) - goto error0; - end = del.br_startoff -1 ; nodelete:/*
libxfs/xfs_bmap.h +1 -1
@@ -202,7 +202,7 @@ int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip,int xfs_bunmapi (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t bno,xfs_filblks_t len,uint32_t flags,xfs_extnum_t nexts,int *done); -int xfs_bmap_del_extent_delay (struct xfs_inode *ip,int whichfork, +void xfs_bmap_del_extent_delay (struct xfs_inode *ip,int whichfork,struct xfs_iext_cursor *cur,struct xfs_bmbt_irec *got,struct xfs_bmbt_irec *del); void xfs_bmap_del_extent_cow(struct xfs_inode *ip,
PATCH 107/115 xfs: simplify iext overflow checking and upgrade
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 25576c5420e61dea4c2b52942460f2221b8e46e8
Currently the calls to xfs_iext_count_may_overflow and xfs_iext_count_upgrade are always paired. Merge them into a single function to simplify the callers and the actual check and upgrade logic itself.
--- libxfs/xfs_attr.c | 5 +--- libxfs/xfs_bmap.c | 5 +--- libxfs/xfs_inode_fork.c | 63 +++++++++++++++++++++-------------------------- libxfs/xfs_inode_fork.h | 6 +--- 4 files changed, 32 insertions(+), 47 deletions(-)
libxfs/xfs_attr.c +1 -4
@@ -1049,11 +1049,8 @@ xfs_attr_set(return error;if (op !=XFS_ATTRUPDATE_REMOVE ||xfs_inode_hasattr (dp)) { - error =xfs_iext_count_may_overflow (dp,XFS_ATTR_FORK , + error =xfs_iext_count_extend (args->trans, dp,XFS_ATTR_FORK ,XFS_IEXT_ATTR_MANIP_CNT (rmt_blks)); -if (error == -EFBIG ) - error =xfs_iext_count_upgrade (args->trans, dp, -XFS_IEXT_ATTR_MANIP_CNT (rmt_blks));if (error) goto out_trans_cancel; }
libxfs/xfs_bmap.c +1 -4
@@ -4645,11 +4645,8 @@ xfs_bmapi_convert_one_delalloc(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,0 ); - error =xfs_iext_count_may_overflow (ip, whichfork, + error =xfs_iext_count_extend (tp, ip, whichfork,XFS_IEXT_ADD_NOSPLIT_CNT ); -if (error == -EFBIG ) - error =xfs_iext_count_upgrade (tp, ip, -XFS_IEXT_ADD_NOSPLIT_CNT );if (error) goto out_trans_cancel;
libxfs/xfs_inode_fork.c +28 -35
81 lines not on this page · raw message
libxfs/xfs_inode_fork.h +2 -4
@@ -256,10 +256,8 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip);int xfs_ifork_verify_local_data (struct xfs_inode *ip);int xfs_ifork_verify_local_attr (struct xfs_inode *ip); -int xfs_iext_count_may_overflow (struct xfs_inode *ip,int whichfork, -int nr_to_add); -int xfs_iext_count_upgrade (struct xfs_trans *tp,struct xfs_inode *ip, -uint nr_to_add); +int xfs_iext_count_extend (struct xfs_trans *tp,struct xfs_inode *ip, +int whichfork,uint nr_to_add);bool xfs_ifork_is_realtime (struct xfs_inode *ip,int whichfork);/* returns true if the fork has extents but they are not read in yet. */
PATCH 108/115 xfs: Stop using __maybe_unused in xfs_alloc.c
In reply to Darrick J. WongFrom: John Garry <[email protected]>
Source kernel commit: b33874fb7f28326380562f208d948bab785fbd6f
In both xfs_alloc_cur_finish() and xfs_alloc_ag_vextent_exact(), local variable @afg is tagged as __maybe_unused. Otherwise an unused variable warning would be generated for when building with W=1 and CONFIG_XFS_DEBUG unset. In both cases, the variable is unused as it is only referenced in an ASSERT() call, which is compiled out (in this config).
It is generally a poor programming style to use __maybe_unused for variables.
The ASSERT() call is to verify that agbno of the end of the extent is within bounds for both functions. @afg is used as an intermediate variable to find the AG length.
However xfs_verify_agbext() already exists to verify a valid extent range. The arguments for calling xfs_verify_agbext() are already available, so use that instead.
An advantage of using xfs_verify_agbext() is that it verifies that both the start and the end of the extent are within the bounds of the AG and catches overflows.
--- libxfs/xfs_alloc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
libxfs/xfs_alloc.c +2 -4
@@ -1004,13 +1004,12 @@ xfs_alloc_cur_finish(struct xfs_alloc_arg *args, struct xfs_alloc_cur *acur) { - struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; int error;ASSERT (acur->cnt && acur->bnolt);ASSERT (acur->bno >= acur->rec_bno);ASSERT (acur->bno + acur->len <= acur->rec_bno + acur->rec_len); -ASSERT (acur->rec_bno + acur->rec_len <=be32_to_cpu (agf->agf_length)); +ASSERT (xfs_verify_agbext (args->pag, acur->rec_bno, acur->rec_len)); error =xfs_alloc_fixup_trees (acur->cnt, acur->bnolt, acur->rec_bno, acur->rec_len, acur->bno, acur->len,0 );
@@ -1213,7 +1212,6 @@ STATIC int /* error */xfs_alloc_ag_vextent_exact ( xfs_alloc_arg_t *args) /* allocation argument structure */ { -struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */ struct xfs_btree_cur *cnt_cur;/* by count btree cursor */ int error;
@@ -1293,7 +1291,7 @@ xfs_alloc_ag_vextent_exact(*/ cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, args->agbp, args->pag); -ASSERT (args->agbno + args->len <=be32_to_cpu (agf->agf_length)); +ASSERT (xfs_verify_agbext (args->pag, args->agbno, args->len)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );if (error) {
PATCH 109/115 xfs: fix xfs_init_attr_trans not handling explicit operation codes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 06c37c719d22339ad09b93735923e9b1a9794871
When we were converting the attr code to use an explicit operation code instead of keying off of attr->value being null, we forgot to change the code that initializes the transaction reservation. Split the function into two helpers that handle the !remove and remove cases, then fix both callsites to handle this correctly.
--- libxfs/xfs_attr.c | 38 ++++++++++++++++++-------------------- libxfs/xfs_attr.h | 3 +-- 2 files changed, 19 insertions(+), 22 deletions(-)
libxfs/xfs_attr.c +18 -20
@@ -328,26 +328,20 @@ xfs_attr_calc_size(return nblks; } -/* Initialize transaction reservation for attr operations */ -void -xfs_init_attr_trans ( -struct xfs_da_args *args, -struct xfs_trans_res *tres, -unsigned int *total) +/* Initialize transaction reservation for an xattr set/replace/upsert */ +inline struct xfs_trans_res +xfs_attr_set_resv ( +const struct xfs_da_args *args) { -struct xfs_mount *mp = args->dp->i_mount; +struct xfs_mount *mp = args->dp->i_mount; +struct xfs_trans_res ret = { + .tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + +M_RES (mp)->tr_attrsetrt.tr_logres * args->total, + .tr_logcount =XFS_ATTRSET_LOG_COUNT , + .tr_logflags =XFS_TRANS_PERM_LOG_RES , + }; -if (args->value) { - tres->tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + -M_RES (mp)->tr_attrsetrt.tr_logres * - args->total; - tres->tr_logcount =XFS_ATTRSET_LOG_COUNT ; - tres->tr_logflags =XFS_TRANS_PERM_LOG_RES ; - *total = args->total; - }else { - *tres =M_RES (mp)->tr_attrrm; - *total =XFS_ATTRRM_SPACE_RES (mp); - } +return ret; }/*
@@ -1005,7 +999,7 @@ xfs_attr_set(struct xfs_trans_res tres;int error, local;int rmt_blks =0 ; -unsigned int total; +unsigned int total =0 ;ASSERT (!args->trans);
@@ -1032,10 +1026,15 @@ xfs_attr_set(if (!local) rmt_blks =xfs_attr3_rmt_blocks (mp, args->valuelen); + + tres =xfs_attr_set_resv (args); + total = args->total;break ;case XFS_ATTRUPDATE_REMOVE :XFS_STATS_INC (mp, xs_attr_remove); rmt_blks =xfs_attr3_max_rmt_blocks (mp); + tres =M_RES (mp)->tr_attrrm; + total =XFS_ATTRRM_SPACE_RES (mp);break ; }
@@ -1043,7 +1042,6 @@ xfs_attr_set(* Root fork attributes can use reserved data blocks for this * operation if necessary */ -xfs_init_attr_trans (args, &tres, &total); error =xfs_trans_alloc_inode (dp, &tres, total,0 , rsvd, &args->trans);if (error)return error;
libxfs/xfs_attr.h +1 -2
@@ -565,8 +565,7 @@ bool xfs_attr_check_namespace(unsigned int attr_flags);bool xfs_attr_namecheck (unsigned int attr_flags,const void *name,size_t length);int xfs_attr_calc_size (struct xfs_da_args *args,int *local); -void xfs_init_attr_trans (struct xfs_da_args *args,struct xfs_trans_res *tres, -unsigned int *total); +struct xfs_trans_res xfs_attr_set_resv (const struct xfs_da_args *args);/* * Check to see if the attr should be upgraded from non-existent or shortform to