xfsprogs: catch us up to 6.9 (final)
Hi Carlos,
This patchbomb contains all the patches that I have prepared for xfsprogs 6.9 against the 6.8 release. These are the final versions of the patches; a pile of pull requests is coming shortly.
--D
PATCH 1/10 libxfs: prepare to sync with 6.9
Hi all,
Apply some cleanups to libxfs before we synchronize it 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-6.9-sync-prep
---
Commits in this patchset:
* libxfs: actually set m_fsname
* libxfs: clean up xfs_da_unmount usage
* libfrog: create a new scrub group for things requiring full inode scans
--- io/scrub.c | 1 + libfrog/scrub.h | 1 + libxfs/init.c | 24 +++++++++++++++++------- scrub/phase5.c | 22 ++++++++++++++++++++-- scrub/scrub.c | 33 +++++++++++++++++++++++++++++++++ scrub/scrub.h | 1 + scrub/xfs_scrub.h | 1 + 7 files changed, 74 insertions(+), 9 deletions(-)
PATCH 2/10 libxfs: sync with 6.9
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.9
---
Commits in this patchset:
* xfs: convert kmem_zalloc() to kzalloc()
* xfs: convert kmem_alloc() to kmalloc()
* xfs: convert remaining kmem_free() to kfree()
* xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS
* xfs: use GFP_KERNEL in pure transaction contexts
* xfs: clean up remaining GFP_NOFS users
* xfs: use xfs_defer_alloc a bit more
* xfs: Replace xfs_isilocked with xfs_assert_ilocked
* xfs: create a static name for the dot entry too
* xfs: create a predicate to determine if two xfs_names are the same
* xfs: create a macro for decoding ftypes in tracepoints
* xfs: report the health of quota counts
* xfs: implement live quotacheck inode scan
* xfs: report health of inode link counts
* xfs: teach scrub to check file nlinks
* xfs: separate the marking of sick and checked metadata
* xfs: report fs corruption errors to the health tracking system
* xfs: report ag header corruption errors to the health tracking system
* xfs: report block map corruption errors to the health tracking system
* xfs: report btree block corruption errors to the health system
* xfs: report dir/attr block corruption errors to the health system
* xfs: report inode corruption errors to the health system
* xfs: report realtime metadata corruption errors to the health system
* xfs: report XFS_IS_CORRUPT errors to the health system
* xfs: add secondary and indirect classes to the health tracking system
* xfs: remember sick inodes that get inactivated
* xfs: update health status if we get a clean bill of health
* xfs: consolidate btree block freeing tracepoints
* xfs: consolidate btree block allocation tracepoints
* xfs: set the btree cursor bc_ops in xfs_btree_alloc_cursor
* xfs: drop XFS_BTREE_CRC_BLOCKS
* xfs: encode the btree geometry flags in the btree ops structure
* xfs: remove bc_ino.flags
* xfs: consolidate the xfs_alloc_lookup_* helpers
* xfs: turn the allocbt cursor active field into a btree flag
* xfs: extern some btree ops structures
* xfs: initialize btree blocks using btree_ops structure
* xfs: rename btree block/buffer init functions
* xfs: btree convert xfs_btree_init_block to xfs_btree_init_buf calls
* xfs: remove the unnecessary daddr paramter to _init_block
* xfs: set btree block buffer ops in _init_buf
* xfs: move lru refs to the btree ops structure
* xfs: move the btree stats offset into struct btree_ops
* xfs: factor out a xfs_btree_owner helper
* xfs: factor out a btree block owner check
* xfs: store the btree pointer length in struct xfs_btree_ops
* xfs: split out a btree type from the btree ops geometry flags
* xfs: split the per-btree union in struct xfs_btree_cur
* xfs: create predicate to determine if cursor is at inode root level
* xfs: move comment about two 2 keys per pointer in the rmap btree
* xfs: add a xfs_btree_init_ptr_from_cur
* xfs: don't override bc_ops for staging btrees
* xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor
* xfs: remove xfs_allocbt_stage_cursor
* xfs: fold xfs_inobt_init_common into xfs_inobt_init_cursor
* xfs: remove xfs_inobt_stage_cursor
* xfs: fold xfs_refcountbt_init_common into xfs_refcountbt_init_cursor
* xfs: remove xfs_refcountbt_stage_cursor
* xfs: fold xfs_rmapbt_init_common into xfs_rmapbt_init_cursor
* xfs: remove xfs_rmapbt_stage_cursor
* xfs: make full use of xfs_btree_stage_ifakeroot in xfs_bmbt_stage_cursor
* xfs: make staging file forks explicit
* xfs: fold xfs_bmbt_init_common into xfs_bmbt_init_cursor
* xfs: remove xfs_bmbt_stage_cursor
* xfs: split the agf_roots and agf_levels arrays
* xfs: add a name field to struct xfs_btree_ops
* xfs: add a sick_mask to struct xfs_btree_ops
* xfs: split xfs_allocbt_init_cursor
* xfs: remove xfs_inobt_cur
* xfs: remove the btnum argument to xfs_inobt_count_blocks
* xfs: split xfs_inobt_insert_sprec
* xfs: split xfs_inobt_init_cursor
* xfs: pass a 'bool is_finobt' to xfs_inobt_insert
* xfs: remove xfs_btnum_t
* xfs: simplify xfs_btree_check_sblock_siblings
* xfs: simplify xfs_btree_check_lblock_siblings
* xfs: open code xfs_btree_check_lptr in xfs_bmap_btree_to_extents
* xfs: consolidate btree ptr checking
* xfs: misc cleanups for __xfs_btree_check_sblock
* xfs: remove the crc variable in __xfs_btree_check_lblock
* xfs: tighten up validation of root block in inode forks
* xfs: consolidate btree block verification
* xfs: rename btree helpers that depends on the block number representation
* xfs: factor out a __xfs_btree_check_lblock_hdr helper
* xfs: remove xfs_btree_reada_bufl
* xfs: remove xfs_btree_reada_bufs
* xfs: move and rename xfs_btree_read_bufl
* libxfs: teach buftargs to maintain their own buffer hashtable
* libxfs: add xfile support
* libxfs: partition memfd files to avoid using too many fds
* xfs: teach buftargs to maintain their own buffer hashtable
* libxfs: support in-memory buffer cache targets
* xfs: add a xfs_btree_ptrs_equal helper
* xfs: support in-memory btrees
* xfs: launder in-memory btree buffers before transaction commit
* xfs: create a helper to decide if a file mapping targets the rt volume
* xfs: repair the rmapbt
* xfs: create a shadow rmap btree during rmap repair
* xfs: hook live rmap operations during a repair operation
* xfs: clean up bmap log intent item tracepoint callsites
* xfs: move xfs_bmap_defer_add to xfs_bmap_item.c
* xfs: fix xfs_bunmapi to allow unmapping of partial rt extents
* xfs: add a realtime flag to the bmap update log redo items
* xfs: support deferred bmap updates on the attr fork
* xfs: xfs_bmap_finish_one should map unwritten extents properly
* xfs: move xfs_symlink_remote.c declarations to xfs_symlink_remote.h
* xfs: move remote symlink target read function to libxfs
* xfs: move symlink target write function to libxfs
* xfs: xfs_btree_bload_prep_block() should use __GFP_NOFAIL
* xfs: shrink failure needs to hold AGI buffer
* xfs: allow sunit mount option to repair bad primary sb stripe values
--- copy/xfs_copy.c | 4 db/agf.c | 28 - db/bmap_inflate.c | 8 db/check.c | 14 - db/freesp.c | 8 db/metadump.c | 12 include/kmem.h | 5 include/libxfs.h | 4 include/xfs_mount.h | 5 include/xfs_trace.h | 17 - include/xfs_trans.h | 1 libxfs/Makefile | 9 libxfs/buf_mem.c | 313 ++++++++++++ libxfs/buf_mem.h | 30 + libxfs/defer_item.c | 15 + libxfs/defer_item.h | 13 + libxfs/init.c | 52 +- libxfs/libxfs_api_defs.h | 10 libxfs/libxfs_io.h | 42 +- libxfs/libxfs_priv.h | 19 - libxfs/logitem.c | 2 libxfs/rdwr.c | 86 ++- libxfs/trans.c | 40 ++ libxfs/util.c | 10 libxfs/xfile.c | 393 +++++++++++++++ libxfs/xfile.h | 34 + libxfs/xfs_ag.c | 79 ++- libxfs/xfs_ag.h | 18 - libxfs/xfs_alloc.c | 258 ++++++---- libxfs/xfs_alloc_btree.c | 191 ++++--- libxfs/xfs_alloc_btree.h | 10 libxfs/xfs_attr.c | 5 libxfs/xfs_attr_leaf.c | 22 + libxfs/xfs_attr_remote.c | 37 + libxfs/xfs_bmap.c | 365 ++++++++++---- libxfs/xfs_bmap.h | 19 + libxfs/xfs_bmap_btree.c | 152 ++---- libxfs/xfs_bmap_btree.h | 5 libxfs/xfs_btree.c | 1097 ++++++++++++++++++++++++++----------------- libxfs/xfs_btree.h | 274 +++++------ libxfs/xfs_btree_mem.c | 346 ++++++++++++++ libxfs/xfs_btree_mem.h | 75 +++ libxfs/xfs_btree_staging.c | 133 +---- libxfs/xfs_btree_staging.h | 10 libxfs/xfs_da_btree.c | 59 ++ libxfs/xfs_da_format.h | 11 libxfs/xfs_defer.c | 25 - libxfs/xfs_dir2.c | 59 +- libxfs/xfs_dir2.h | 13 + libxfs/xfs_dir2_block.c | 8 libxfs/xfs_dir2_data.c | 3 libxfs/xfs_dir2_leaf.c | 3 libxfs/xfs_dir2_node.c | 7 libxfs/xfs_dir2_sf.c | 16 - libxfs/xfs_format.h | 21 - libxfs/xfs_fs.h | 8 libxfs/xfs_health.h | 95 ++++ libxfs/xfs_ialloc.c | 232 ++++++--- libxfs/xfs_ialloc_btree.c | 173 +++---- libxfs/xfs_ialloc_btree.h | 11 libxfs/xfs_iext_tree.c | 26 + libxfs/xfs_inode_buf.c | 12 libxfs/xfs_inode_fork.c | 49 +- libxfs/xfs_inode_fork.h | 1 libxfs/xfs_log_format.h | 4 libxfs/xfs_refcount.c | 69 ++- libxfs/xfs_refcount_btree.c | 78 +-- libxfs/xfs_refcount_btree.h | 2 libxfs/xfs_rmap.c | 284 +++++++++-- libxfs/xfs_rmap.h | 31 + libxfs/xfs_rmap_btree.c | 240 +++++++-- libxfs/xfs_rmap_btree.h | 8 libxfs/xfs_rtbitmap.c | 11 libxfs/xfs_sb.c | 42 +- libxfs/xfs_sb.h | 5 libxfs/xfs_shared.h | 67 ++- libxfs/xfs_symlink_remote.c | 155 ++++++ libxfs/xfs_symlink_remote.h | 26 + libxfs/xfs_trans_inode.c | 6 libxfs/xfs_types.h | 26 - logprint/log_misc.c | 8 logprint/log_print_all.c | 8 mkfs/xfs_mkfs.c | 8 repair/agbtree.c | 28 + repair/bmap_repair.c | 4 repair/bulkload.c | 2 repair/phase5.c | 28 + repair/phase6.c | 4 repair/prefetch.c | 12 repair/prefetch.h | 1 repair/progress.c | 14 - repair/progress.h | 2 repair/scan.c | 18 - repair/xfs_repair.c | 47 +- 94 files changed, 4425 insertions(+), 1915 deletions(-) create mode 100644 libxfs/buf_mem.c create mode 100644 libxfs/buf_mem.h create mode 100644 libxfs/defer_item.h create mode 100644 libxfs/xfile.c create mode 100644 libxfs/xfile.h create mode 100644 libxfs/xfs_btree_mem.c create mode 100644 libxfs/xfs_btree_mem.h create mode 100644 libxfs/xfs_symlink_remote.h
PATCH 3/10 xfsprogs: bmap log intent cleanups
In reply to Darrick J. WongHi all,
The next major target of online repair are metadata that are persisted in blocks mapped by a file fork. In other words, we want to repair directories, extended attributes, symbolic links, and the realtime free space information. For file-based metadata, we assume that the space metadata is correct, which enables repair to construct new versions of the metadata in a temporary file. We then need to swap the file fork mappings of the two files atomically. With this patchset, we begin constructing such a facility based on the existing bmap log items and a new extent swap log item.
This series cleans up a few parts of the file block mapping log intent code before we start adding support for realtime bmap intents. Most of it involves cleaning up tracepoints so that more of the data extraction logic ends up in the tracepoint code and not the tracepoint call site, which should reduce overhead further when tracepoints are disabled. There is also a change to pass bmap intents all the way back to the bmap code instead of unboxing the intent values and re-boxing them after the _finish_one function completes.
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=bmap-intent-cleanups-6.9
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=bmap-intent-cleanups-6.9
---
Commits in this patchset:
* libxfs: remove kmem_alloc, kmem_zalloc, and kmem_free
* libxfs: add a bi_entry helper
* libxfs: reuse xfs_bmap_update_cancel_item
* libxfs: add a xattr_entry helper
--- db/bmap_inflate.c | 2 +- include/kmem.h | 10 +------- libxfs/defer_item.c | 58 ++++++++++++++++++++++++--------------------- libxfs/init.c | 2 +- libxfs/kmem.c | 32 ++++++++----------------- libxlog/xfs_log_recover.c | 19 +++++++-------- repair/bmap_repair.c | 4 ++- 7 files changed, 55 insertions(+), 72 deletions(-)
PATCH 4/10 xfsprogs: widen BUI formats to support realtime
In reply to Darrick J. WongHi all,
Atomic extent swapping (and later, reverse mapping and reflink) on the realtime device needs to be able to defer file mapping and extent freeing work in much the same manner as is required on the data volume. Make the BUI log items operate on rt extents in preparation for atomic swapping and realtime rmap.
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=realtime-bmap-intents-6.9
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=realtime-bmap-intents-6.9
---
Commits in this patchset:
* libxfs: add a realtime flag to the bmap update log redo items
--- libxfs/defer_item.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
PATCH 5/10 xfs_spaceman: updates for 6.9
In reply to Darrick J. WongHi all,
Update xfs_spaceman to handle the new health reporting code that was merged in 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=spaceman-updates-6.9
---
Commits in this patchset:
* xfs_spaceman: report the health of quota counts
* xfs_spaceman: report health of inode link counts
--- man/man2/ioctl_xfs_fsgeometry.2 | 3 +++ spaceman/health.c | 8 ++++++++ 2 files changed, 11 insertions(+)
PATCH 6/10 xfs_scrub: updates for 6.9
In reply to Darrick J. WongHi all,
Now that the kernel has the code for userspace to upload a clean bill of health (which clears out all the secondary markers of ill health that hint at forgotten sicknesses), let's make xfs_scrub do that if the filesystem is actually clean.
Second, restructure the xfs_scrub program so that it scrubs file link counts and quotacheck in parallel.
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-fixes-6.9
---
Commits in this patchset:
* xfs_scrub: implement live quotacheck inode scan
* xfs_scrub: check file link counts
* xfs_scrub: update health status if we get a clean bill of health
* xfs_scrub: use multiple threads to run in-kernel metadata scrubs that scan inodes
* xfs_scrub: upload clean bills of health
--- libfrog/scrub.c | 15 ++++ man/man2/ioctl_xfs_scrub_metadata.2 | 10 ++ scrub/phase1.c | 38 +++++++++ scrub/phase4.c | 17 ++++ scrub/phase5.c | 150 ++++++++++++++++++++++++++++++++--- scrub/repair.c | 18 ++++ scrub/repair.h | 1 scrub/scrub.c | 43 +++++++--- scrub/scrub.h | 3 + 9 files changed, 265 insertions(+), 30 deletions(-)
PATCH 7/10 xfs_repair: minor fixes
In reply to Darrick J. WongHi all,
Fix some random minor 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.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-fixes-6.9
---
Commits in this patchset:
* xfs_repair: log when buffers fail CRC checks even if we just recompute it
* xfs_repair: check num before bplist[num]
--- repair/attr_repair.c | 15 ++++++++++++--- repair/da_util.c | 12 ++++++++---- repair/dir2.c | 28 +++++++++++++++++++++------- repair/prefetch.c | 2 +- 4 files changed, 42 insertions(+), 15 deletions(-)
PATCH 8/10 xfs_repair: use in-memory rmap btrees
In reply to Darrick J. WongHi all,
Now that we've ported support for in-memory btrees to userspace, port xfs_repair to use them instead of the clunky slab interface that we currently use. This has the effect of moving memory consumption for tracking reverse mappings into a memfd file, which means that we could (theoretically) reduce the memory requirements by pointing it at an on-disk file or something. It also enables us to remove the sorting step and to avoid having to coalesce adjacent contiguous bmap records into a single rmap record.
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=repair-use-in-memory-btrees-6.9
---
Commits in this patchset:
* libxfs: provide a kernel-compatible kasprintf
* xfs_repair: convert regular rmap repair to use in-memory btrees
* xfs_repair: verify on-disk rmap btrees with in-memory btree data
* xfs_repair: compute refcount data from in-memory rmap btrees
* xfs_repair: reduce rmap bag memory usage when creating refcounts
* xfs_repair: remove the old rmap collection slabs
--- include/kmem.h | 3 include/libxfs.h | 3 libxfs/buf_mem.h | 5 libxfs/kmem.c | 13 + libxfs/libxfs_api_defs.h | 13 + repair/agbtree.c | 18 + repair/agbtree.h | 1 repair/dinode.c | 9 - repair/phase4.c | 25 -- repair/phase5.c | 2 repair/rmap.c | 762 ++++++++++++++++++++++++++++++---------------- repair/rmap.h | 25 +- repair/scan.c | 7 repair/slab.c | 49 ++- repair/slab.h | 2 repair/xfs_repair.c | 6 16 files changed, 602 insertions(+), 341 deletions(-)
PATCH 9/10 xfs_repair: reduce refcount repair memory usage
In reply to Darrick J. WongHi all,
The refcountbt repair code has serious memory usage problems when the block sharing factor of the filesystem is very high. This can happen if a deduplication tool has been run against the filesystem, or if the fs stores reflinked VM images that have been aging for a long time.
Recall that the original reference counting algorithm walks the reverse mapping records of the filesystem to generate reference counts. For any given block in the AG, the rmap bag structure contains the all rmap records that cover that block; the refcount is the size of that bag.
For online repair, the bag doesn't need the owner, offset, or state flag information, so it discards those. This halves the record size, but the bag structure still stores one excerpted record for each reverse mapping. If the sharing count is high, this will use a LOT of memory storing redundant records. In the extreme case, 100k mappings to the same piece of space will consume 100k*16 bytes = 1.6M of memory.
For offline repair, the bag stores the owner values so that we know which inodes need to be marked as being reflink inodes. If a deduplication tool has been run and there are many blocks within a file pointing to the same physical space, this will stll use a lot of memory to store redundant records.
The solution to this problem is to deduplicate the bag records when possible by adding a reference count to the bag record, and changing the bag add function to detect an existing record to bump the refcount. In the above example, the 100k mappings will now use 24 bytes of memory. These lookups can be done efficiently with a btree, so we create a new refcount bag btree type (inside of online repair). This is why we refactored the btree code in the previous patchset.
The btree conversion also dramatically reduces the runtime of the refcount generation algorithm, because the code to delete all bag records that end at a given agblock now only has to delete one record instead of (using the example above) 100k records. As an added benefit, record deletion now gives back the unused xfile space, which it did not do previously.
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-refcount-scalability-6.9
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-refcount-scalability-6.9
---
Commits in this patchset:
* xfs_repair: define an in-memory btree for storing refcount bag info
* xfs_repair: create refcount bag
* xfs_repair: port to the new refcount bag structure
* xfs_repair: remove the old bag implementation
--- libxfs/libxfs_api_defs.h | 9 + repair/Makefile | 4 repair/rcbag.c | 371 ++++++++++++++++++++++++++++++++++++++++++++ repair/rcbag.h | 32 ++++ repair/rcbag_btree.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++ repair/rcbag_btree.h | 77 +++++++++ repair/rmap.c | 157 +++++-------------- repair/slab.c | 130 --------------- repair/slab.h | 19 -- repair/xfs_repair.c | 6 + 10 files changed, 934 insertions(+), 261 deletions(-) create mode 100644 repair/rcbag.c create mode 100644 repair/rcbag.h create mode 100644 repair/rcbag_btree.c create mode 100644 repair/rcbag_btree.h
PATCH 10/10 mkfs: cleanups for 6.9
In reply to Darrick J. WongHi all,
Clean up mkfs' open-coded symlink handling code.
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=mkfs-cleanups-6.9
---
Commits in this patchset:
* mkfs: use libxfs to create symlinks
--- libxfs/libxfs_api_defs.h | 1 + mkfs/proto.c | 72 ++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 34 deletions(-)
PATCH 1/3 libxfs: actually set m_fsname
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Set the name of the filesystem before we actually start using it for creating xfiles. This leads to nice(r) output from /proc/maps such as:
7fcd0a44f000-7fcd0a450000 rw-s 021f6000 00:01 3612684 /memfd:xfs_repair (/dev/sda): AG 0 rmap records (deleted)
--- libxfs/init.c | 8 ++++++++ 1 file changed, 8 insertions(+)
libxfs/init.c +8 -0
@@ -643,6 +643,11 @@ libxfs_mount(xfs_set_reporting_corruption (mp);libxfs_buftarg_init (mp, xi); +if (xi->data.name) + mp->m_fsname =strdup (xi->data.name); +else + mp->m_fsname =NULL ; + mp->m_finobt_nores = true;xfs_set_inode32 (mp); mp->m_sb = *sb;
@@ -903,6 +908,9 @@ libxfs_umount(kmem_free (mp->m_attr_geo);kmem_free (mp->m_dir_geo); +free (mp->m_fsname); + mp->m_fsname =NULL ; +kmem_free (mp->m_rtdev_targp);if (mp->m_logdev_targp != mp->m_ddev_targp)kmem_free (mp->m_logdev_targp);
PATCH 2/3 libxfs: clean up xfs_da_unmount usage
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Replace the open-coded xfs_da_unmount usage in libxfs_umount and teach libxfs_mount not to leak the dir/attr geometry structures when the mount attempt fails.
--- libxfs/init.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
libxfs/init.c +9 -7
@@ -721,7 +721,7 @@ libxfs_mount(if (error) {fprintf (stderr,_ ("%s: data size check failed\n" ), progname);if (!xfs_is_debugger (mp)) -return NULL ; + goto out_da; }else libxfs_buf_relse (bp);
@@ -735,7 +735,7 @@ libxfs_mount(fprintf (stderr,_ ("%s: log size checks failed\n" ), progname);if (!xfs_is_debugger (mp)) -return NULL ; + goto out_da; }if (bp)libxfs_buf_relse (bp);
@@ -746,8 +746,8 @@ libxfs_mount(/* Initialize realtime fields in the mount structure */ if (rtmount_init (mp)) {fprintf (stderr,_ ("%s: realtime device init failed\n" ), - progname); -return NULL ; + progname); + goto out_da; }/*
@@ -765,7 +765,7 @@ libxfs_mount(fprintf (stderr,_ ("%s: read of AG %u failed\n" ), progname, sbp->sb_agcount);if (!xfs_is_debugger (mp)) -return NULL ; + goto out_da;fprintf (stderr,_ ("%s: limiting reads to AG 0\n" ), progname); sbp->sb_agcount =1 ;
@@ -783,6 +783,9 @@ libxfs_mount(xfs_set_perag_data_loaded (mp);return mp; +out_da: +xfs_da_unmount (mp); +return NULL ; }void
@@ -905,8 +908,7 @@ libxfs_umount(if (xfs_is_perag_data_loaded (mp))libxfs_free_perag (mp); -kmem_free (mp->m_attr_geo); -kmem_free (mp->m_dir_geo); +xfs_da_unmount (mp);free (mp->m_fsname); mp->m_fsname =NULL ;
PATCH 3/3 libfrog: create a new scrub group for things requiring full inode scans
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Subsequent patches will add online fsck types (quotacheck, link counts) that require us to walk every inode in the entire filesystem. This requires the AG metadata and the inodes to be in good enough shape to complete the scan without hitting corruption errors. As such, they ought to run after phases 2-4 and before phase 7, which summarizes what we've found.
Phase 5 seems like a reasonable place to do this, since it already walks every xattr and directory entry in the filesystem to look for suspicious looking names. Add a new XFROG_SCRUB_GROUP, and add it to phase 5.
--- io/scrub.c | 1 + libfrog/scrub.h | 1 + scrub/phase5.c | 22 ++++++++++++++++++++-- scrub/scrub.c | 33 +++++++++++++++++++++++++++++++++ scrub/scrub.h | 1 + scrub/xfs_scrub.h | 1 + 6 files changed, 57 insertions(+), 2 deletions(-)
io/scrub.c +1 -0
@@ -184,6 +184,7 @@ parse_args(case XFROG_SCRUB_GROUP_FS :case XFROG_SCRUB_GROUP_NONE :case XFROG_SCRUB_GROUP_SUMMARY : +case XFROG_SCRUB_GROUP_ISCAN :if (!parse_none (argc, optind)) { exitcode =1 ;return command_usage (cmdinfo);
libfrog/scrub.h +1 -0
@@ -13,6 +13,7 @@ enum xfrog_scrub_group {XFROG_SCRUB_GROUP_PERAG ,/* per-AG metadata */ XFROG_SCRUB_GROUP_FS ,/* per-FS metadata */ XFROG_SCRUB_GROUP_INODE ,/* per-inode metadata */ +XFROG_SCRUB_GROUP_ISCAN ,/* metadata requiring full inode scan */ XFROG_SCRUB_GROUP_SUMMARY, /* summary metadata */ };
scrub/phase5.c +20 -2
@@ -16,6 +16,8 @@#include "list.h" #include "libfrog/paths.h" #include "libfrog/workqueue.h" +#include "libfrog/fsgeom.h" +#include "libfrog/scrub.h" #include "xfs_scrub.h" #include "common.h" #include "inodes.h"
@@ -23,8 +25,9 @@#include "scrub.h" #include "descr.h" #include "unicrash.h" +#include "repair.h" -/* Phase 5: Check directory connectivity. */ +/* Phase 5: Full inode scans and check directory connectivity. */ /* * Warn about problematic bytes in a directory/attribute name. That means
@@ -386,9 +389,24 @@ intphase5_func ( struct scrub_ctx *ctx) { +struct action_list alist;bool aborted = false;int ret; +/* +* Check and fix anything that requires a full inode scan. We do this +* after we've checked all inodes and repaired anything that could get +* in the way of a scan. +*/ +action_list_init (&alist); + ret =scrub_iscan_metadata (ctx, &alist); +if (ret) +return ret; + ret =action_list_process (ctx, ctx->mnt.fd, &alist, +ALP_COMPLAIN_IF_UNFIXED |ALP_NOPROGRESS ); +if (ret) +return ret; +if (ctx->corruptions_found || ctx->unfixable_errors) {str_info (ctx, ctx->mntpoint,_ ("Filesystem has errors, skipping connectivity checks." ));
@@ -417,7 +435,7 @@ phase5_estimate(unsigned int *nr_threads, int *rshift) { - *items = ctx->mnt_sv.f_files - ctx->mnt_sv.f_ffree; + *items =scrub_estimate_iscan_work (ctx); *nr_threads =scrub_nproc (ctx); *rshift =0 ;return 0 ;
scrub/scrub.c +33 -0
@@ -47,6 +47,7 @@ format_scrub_descr(break ;case XFROG_SCRUB_GROUP_FS :case XFROG_SCRUB_GROUP_SUMMARY : +case XFROG_SCRUB_GROUP_ISCAN :return snprintf (buf, buflen,_ ("%s" ),_ (sc->descr));break ;case XFROG_SCRUB_GROUP_NONE :
@@ -421,6 +422,15 @@ scrub_summary_metadata(return scrub_group (ctx,XFROG_SCRUB_GROUP_SUMMARY ,0 , alist); } +/* Scrub all metadata requiring a full inode scan. */ +int +scrub_iscan_metadata ( +struct scrub_ctx *ctx, +struct action_list *alist) +{ +return scrub_group (ctx,XFROG_SCRUB_GROUP_ISCAN ,0 , alist); +} +/* Scrub /only/ the superblock summary counters. */ int scrub_fs_counters(
@@ -456,6 +466,29 @@ scrub_estimate_ag_work(return estimate; } +/* +* How many kernel calls will we make to scrub everything requiring a full +* inode scan? +*/ +unsigned int +scrub_estimate_iscan_work ( +struct scrub_ctx *ctx) +{ +const struct xfrog_scrub_descr *sc; +int type; +unsigned int estimate; + + estimate = ctx->mnt_sv.f_files - ctx->mnt_sv.f_ffree; + + sc = xfrog_scrubbers; +for (type =0 ; type <XFS_SCRUB_TYPE_NR ; type++, sc++) { +if (sc->group ==XFROG_SCRUB_GROUP_ISCAN ) + estimate++; + } + +return estimate; +} +/* * Scrub file metadata of some sort. If errors occur, this function will log * them and return nonzero.
scrub/scrub.h +1 -0
@@ -24,6 +24,7 @@ int scrub_ag_metadata(struct scrub_ctx *ctx, xfs_agnumber_t agno, struct action_list *alist);int scrub_fs_metadata (struct scrub_ctx *ctx,unsigned int scrub_type,struct action_list *alist); +int scrub_iscan_metadata (struct scrub_ctx *ctx,struct action_list *alist);int scrub_summary_metadata (struct scrub_ctx *ctx,struct action_list *alist);int scrub_fs_counters (struct scrub_ctx *ctx,struct action_list *alist);
scrub/xfs_scrub.h +1 -0
@@ -99,6 +99,7 @@ int phase7_func(struct scrub_ctx *ctx);/* Progress estimator functions */ unsigned int scrub_estimate_ag_work (struct scrub_ctx *ctx); +unsigned int scrub_estimate_iscan_work (struct scrub_ctx *ctx);int phase2_estimate (struct scrub_ctx *ctx,uint64_t *items,unsigned int *nr_threads,int *rshift); int phase3_estimate(struct scrub_ctx *ctx, uint64_t *items,
PATCH 1/111 xfs: convert kmem_zalloc() to kzalloc()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 10634530f7ba947d8eab52a580e0840778d4ef75
There's no reason to keep the kmem_zalloc() around anymore, it's just a thin wrapper around kmalloc(), so lets get rid of it.
--- include/kmem.h | 5 ++++- libxfs/xfs_ag.c | 2 +- libxfs/xfs_attr_leaf.c | 3 ++- libxfs/xfs_btree_staging.c | 2 +- libxfs/xfs_da_btree.c | 5 +++-- libxfs/xfs_defer.c | 2 +- libxfs/xfs_dir2.c | 18 +++++++++--------- libxfs/xfs_iext_tree.c | 12 ++++++++---- 8 files changed, 29 insertions(+), 20 deletions(-)
include/kmem.h +4 -1
@@ -25,8 +25,9 @@ typedef unsigned int __bitwise gfp_t;#define GFP_NOFS ((__force gfp_t)0)#define __GFP_NOFAIL ((__force gfp_t)0)#define __GFP_NOLOCKDEP ((__force gfp_t)0) +#define __GFP_RETRY_MAYFAIL ((__force gfp_t)0) -#define __GFP_ZERO (__force gfp_t)1 +#define __GFP_ZERO ((__force gfp_t)1) struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int slab_flags,
@@ -65,6 +66,8 @@ static inline void *kmalloc(size_t size, gfp_t flags)return kvmalloc (size, flags); } +#define kzalloc (size, gfp) kvmalloc((size), (gfp) | __GFP_ZERO) +static inline void kfree (const void *ptr) {return kmem_free (ptr);
libxfs/xfs_ag.c +1 -1
@@ -379,7 +379,7 @@ xfs_initialize_perag(continue ; } - pag =kmem_zalloc (sizeof (*pag),KM_MAYFAIL ); + pag =kzalloc (sizeof (*pag),GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!pag) { error = -ENOMEM ; goto out_unwind_new_pags;
libxfs/xfs_attr_leaf.c +2 -1
@@ -2247,7 +2247,8 @@ xfs_attr3_leaf_unbalance(struct xfs_attr_leafblock *tmp_leaf;struct xfs_attr3_icleaf_hdr tmphdr; - tmp_leaf =kmem_zalloc (state->args->geo->blksize,0 ); + tmp_leaf =kzalloc (state->args->geo->blksize, +GFP_KERNEL | __GFP_NOFAIL);/* * Copy the header into the temp leaf so that all the stuff
libxfs/xfs_btree_staging.c +1 -1
@@ -406,7 +406,7 @@ xfs_btree_bload_prep_block(/* Allocate a new incore btree root block. */ new_size = bbl->iroot_size (cur, level, nr_this_block, priv); - ifp->if_broot =kmem_zalloc (new_size,0 ); + ifp->if_broot =kzalloc (new_size,GFP_KERNEL ); ifp->if_broot_bytes = (int )new_size;/* Initialize it and send it out. */
libxfs/xfs_da_btree.c +3 -2
@@ -2514,7 +2514,7 @@ xfs_dabuf_map(int error =0 , nirecs, i;if (nfsb >1 ) - irecs =kmem_zalloc (sizeof (irec) * nfsb,KM_NOFS ); + irecs =kzalloc (sizeof (irec) * nfsb,GFP_NOFS | __GFP_NOFAIL); nirecs = nfsb; error = xfs_bmapi_read(dp, bno, nfsb, irecs, &nirecs,
@@ -2527,7 +2527,8 @@ xfs_dabuf_map(* larger one that needs to be free by the caller. */ if (nirecs >1 ) { - map =kmem_zalloc (nirecs *sizeof (struct xfs_buf_map ),KM_NOFS ); + map =kzalloc (nirecs *sizeof (struct xfs_buf_map ), +GFP_NOFS | __GFP_NOFAIL);if (!map) { error = -ENOMEM ; goto out_free_irecs;
libxfs/xfs_defer.c +1 -1
@@ -973,7 +973,7 @@ xfs_defer_ops_capture(return ERR_PTR (error);/* Create an object to capture the defer ops. */ - dfc =kmem_zalloc (sizeof (*dfc),KM_NOFS ); + dfc =kzalloc (sizeof (*dfc),GFP_NOFS | __GFP_NOFAIL);INIT_LIST_HEAD (&dfc->dfc_list);INIT_LIST_HEAD (&dfc->dfc_dfops);
libxfs/xfs_dir2.c +9 -9
@@ -103,10 +103,10 @@ xfs_da_mount(ASSERT (mp->m_sb.sb_versionnum &XFS_SB_VERSION_DIRV2BIT );ASSERT (xfs_dir2_dirblock_bytes (&mp->m_sb) <=XFS_MAX_BLOCKSIZE ); - mp->m_dir_geo =kmem_zalloc (sizeof (struct xfs_da_geometry ), -KM_MAYFAIL ); - mp->m_attr_geo =kmem_zalloc (sizeof (struct xfs_da_geometry ), -KM_MAYFAIL ); + mp->m_dir_geo =kzalloc (sizeof (struct xfs_da_geometry ), +GFP_KERNEL | __GFP_RETRY_MAYFAIL); + mp->m_attr_geo =kzalloc (sizeof (struct xfs_da_geometry ), +GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!mp->m_dir_geo || !mp->m_attr_geo) {kmem_free (mp->m_dir_geo);kmem_free (mp->m_attr_geo);
@@ -235,7 +235,7 @@ xfs_dir_init(if (error)return error; - args =kmem_zalloc (sizeof (*args),KM_NOFS ); + args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -272,7 +272,7 @@ xfs_dir_createname(XFS_STATS_INC (dp->i_mount, xs_dir_create); } - args =kmem_zalloc (sizeof (*args),KM_NOFS ); + args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -371,7 +371,7 @@ xfs_dir_lookup(* lockdep Doing this avoids having to add a bunch of lockdep class * annotations into the reclaim path for the ilock. */ - args =kmem_zalloc (sizeof (*args),KM_NOFS ); + args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); args->geo = dp->i_mount->m_dir_geo; args->name = name->name; args->namelen = name->len;
@@ -440,7 +440,7 @@ xfs_dir_removename(ASSERT (S_ISDIR (VFS_I (dp)->i_mode));XFS_STATS_INC (dp->i_mount, xs_dir_remove); - args =kmem_zalloc (sizeof (*args),KM_NOFS ); + args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -501,7 +501,7 @@ xfs_dir_replace(if (rval)return rval; - args =kmem_zalloc (sizeof (*args),KM_NOFS ); + args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL);if (!args)return -ENOMEM ;
libxfs/xfs_iext_tree.c +8 -4
@@ -398,7 +398,8 @@ static voidxfs_iext_grow ( struct xfs_ifork *ifp) { -struct xfs_iext_node *node =kmem_zalloc (NODE_SIZE ,KM_NOFS ); +struct xfs_iext_node *node =kzalloc (NODE_SIZE , +GFP_NOFS | __GFP_NOFAIL);int i;if (ifp->if_height ==1 ) {
@@ -454,7 +455,8 @@ xfs_iext_split_node( int *nr_entries) {struct xfs_iext_node *node = *nodep; -struct xfs_iext_node *new =kmem_zalloc (NODE_SIZE ,KM_NOFS ); +struct xfs_iext_node *new =kzalloc (NODE_SIZE , +GFP_NOFS | __GFP_NOFAIL);const int nr_move =KEYS_PER_NODE /2 ;int nr_keep = nr_move + (KEYS_PER_NODE &1 );int i =0 ;
@@ -542,7 +544,8 @@ xfs_iext_split_leaf( int *nr_entries) {struct xfs_iext_leaf *leaf = cur->leaf; -struct xfs_iext_leaf *new =kmem_zalloc (NODE_SIZE ,KM_NOFS ); +struct xfs_iext_leaf *new =kzalloc (NODE_SIZE , +GFP_NOFS | __GFP_NOFAIL);const int nr_move =RECS_PER_LEAF /2 ;int nr_keep = nr_move + (RECS_PER_LEAF &1 );int i;
@@ -583,7 +586,8 @@ xfs_iext_alloc_root( {ASSERT (ifp->if_bytes ==0 ); - ifp->if_data =kmem_zalloc (sizeof (struct xfs_iext_rec ),KM_NOFS ); + ifp->if_data =kzalloc (sizeof (struct xfs_iext_rec ), +GFP_NOFS | __GFP_NOFAIL); ifp->if_height =1 ;/* now that we have a node step into it */
PATCH 2/111 xfs: convert kmem_alloc() to kmalloc()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: f078d4ea827607867d42fb3b2ef907caf86ce49d
kmem_alloc() is just a thin wrapper around kmalloc() these days. Convert everything to use kmalloc() so we can get rid of the wrapper.
Note: the transaction region allocation in xlog_add_to_transaction() can be a high order allocation. Converting it to use kmalloc(__GFP_NOFAIL) results in warnings in the page allocation code being triggered because the mm subsystem does not want us to use __GFP_NOFAIL with high order allocations like we've been doing with the kmem_alloc() wrapper for a couple of decades. Hence this specific case gets converted to xlog_kvmalloc() rather than kmalloc() to avoid this issue.
--- libxfs/xfs_attr_leaf.c | 7 +++---- libxfs/xfs_btree_staging.c | 4 ++-- libxfs/xfs_da_btree.c | 3 ++- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2_block.c | 2 +- libxfs/xfs_dir2_sf.c | 8 ++++---- libxfs/xfs_inode_fork.c | 15 ++++++++------- 7 files changed, 21 insertions(+), 20 deletions(-)
libxfs/xfs_attr_leaf.c +3 -4
@@ -876,8 +876,7 @@ xfs_attr_shortform_to_leaf(trace_xfs_attr_sf_to_leaf (args); - tmpbuffer =kmem_alloc (size,0 ); -ASSERT (tmpbuffer !=NULL ); + tmpbuffer =kmalloc (size,GFP_KERNEL | __GFP_NOFAIL);memcpy (tmpbuffer, ifp->if_data, size); sf = (struct xfs_attr_sf_hdr *)tmpbuffer;
@@ -1056,7 +1055,7 @@ xfs_attr3_leaf_to_shortform(trace_xfs_attr_leaf_to_sf (args); - tmpbuffer =kmem_alloc (args->geo->blksize,0 ); + tmpbuffer =kmalloc (args->geo->blksize,GFP_KERNEL | __GFP_NOFAIL);if (!tmpbuffer)return -ENOMEM ;
@@ -1530,7 +1529,7 @@ xfs_attr3_leaf_compact(trace_xfs_attr_leaf_compact (args); - tmpbuffer =kmem_alloc (args->geo->blksize,0 ); + tmpbuffer =kmalloc (args->geo->blksize,GFP_KERNEL | __GFP_NOFAIL);memcpy (tmpbuffer, bp->b_addr, args->geo->blksize);memset (bp->b_addr,0 , args->geo->blksize); leaf_src = (xfs_attr_leafblock_t *)tmpbuffer;
libxfs/xfs_btree_staging.c +2 -2
@@ -139,7 +139,7 @@ xfs_btree_stage_afakeroot(ASSERT (!(cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ));ASSERT (cur->bc_tp ==NULL ); - nops =kmem_alloc (sizeof (struct xfs_btree_ops ),KM_NOFS ); + nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_NOFS | __GFP_NOFAIL);memcpy (nops, cur->bc_ops,sizeof (struct xfs_btree_ops )); nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->free_block = xfs_btree_fakeroot_free_block;
@@ -220,7 +220,7 @@ xfs_btree_stage_ifakeroot(ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE );ASSERT (cur->bc_tp ==NULL ); - nops =kmem_alloc (sizeof (struct xfs_btree_ops ),KM_NOFS ); + nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_NOFS | __GFP_NOFAIL);memcpy (nops, cur->bc_ops,sizeof (struct xfs_btree_ops )); nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->free_block = xfs_btree_fakeroot_free_block;
libxfs/xfs_da_btree.c +2 -1
@@ -2178,7 +2178,8 @@ xfs_da_grow_inode_int(* If we didn't get it and the block might work if fragmented, * try without the CONTIG flag. Loop until we get it all. */ - mapp =kmem_alloc (sizeof (*mapp) * count,0 ); + mapp =kmalloc (sizeof (*mapp) * count, +GFP_KERNEL | __GFP_NOFAIL);for (b = *bno, mapi =0 ; b < *bno + count; ) { c = (int )(*bno + count - b); nmap =min (XFS_BMAP_MAX_NMAP , c);
libxfs/xfs_dir2.c +1 -1
@@ -332,7 +332,7 @@ xfs_dir_cilookup_result( !(args->op_flags & XFS_DA_OP_CILOOKUP))return -EEXIST ; - args->value =kmem_alloc (len,KM_NOFS |KM_MAYFAIL ); + args->value =kmalloc (len,GFP_NOFS | __GFP_RETRY_MAYFAIL);if (!args->value)return -ENOMEM ;
libxfs/xfs_dir2_block.c +1 -1
@@ -1105,7 +1105,7 @@ xfs_dir2_sf_to_block(* Copy the directory into a temporary buffer. * Then pitch the incore inode data so we can make extents. */ - sfp =kmem_alloc (ifp->if_bytes,0 ); + sfp =kmalloc (ifp->if_bytes,GFP_KERNEL | __GFP_NOFAIL);memcpy (sfp, oldsfp, ifp->if_bytes);xfs_idata_realloc (dp, -ifp->if_bytes,XFS_DATA_FORK );
libxfs/xfs_dir2_sf.c +4 -4
@@ -276,7 +276,7 @@ xfs_dir2_block_to_sf(* format the data into. Once we have formatted the data, we can free * the block and copy the formatted data into the inode literal area. */ - sfp =kmem_alloc (mp->m_sb.sb_inodesize,0 ); + sfp =kmalloc (mp->m_sb.sb_inodesize,GFP_KERNEL | __GFP_NOFAIL);memcpy (sfp, sfhp,xfs_dir2_sf_hdr_size (sfhp->i8count));/*
@@ -524,7 +524,7 @@ xfs_dir2_sf_addname_hard(* Copy the old directory to the stack buffer. */ old_isize = (int )dp->i_disk_size; - buf =kmem_alloc (old_isize,0 ); + buf =kmalloc (old_isize,GFP_KERNEL | __GFP_NOFAIL); oldsfp = (xfs_dir2_sf_hdr_t *)buf;memcpy (oldsfp, dp->i_df.if_data, old_isize);/*
@@ -1151,7 +1151,7 @@ xfs_dir2_sf_toino4(* Don't want xfs_idata_realloc copying the data here. */ oldsize = dp->i_df.if_bytes; - buf =kmem_alloc (oldsize,0 ); + buf =kmalloc (oldsize,GFP_KERNEL | __GFP_NOFAIL);ASSERT (oldsfp->i8count ==1 );memcpy (buf, oldsfp, oldsize);/*
@@ -1223,7 +1223,7 @@ xfs_dir2_sf_toino8(* Don't want xfs_idata_realloc copying the data here. */ oldsize = dp->i_df.if_bytes; - buf =kmem_alloc (oldsize,0 ); + buf =kmalloc (oldsize,GFP_KERNEL | __GFP_NOFAIL);ASSERT (oldsfp->i8count ==0 );memcpy (buf, oldsfp, oldsize);/*
libxfs/xfs_inode_fork.c +8 -7
@@ -48,7 +48,7 @@ xfs_init_local_fork( mem_size++;if (size) { -char *new_data =kmem_alloc (mem_size,KM_NOFS ); +char *new_data =kmalloc (mem_size,GFP_NOFS | __GFP_NOFAIL);memcpy (new_data, data, size);if (zero_terminate)
@@ -75,7 +75,7 @@ xfs_iformat_local(/* * If the size is unreasonable, then something * is wrong and we just bail out rather than crash in -* kmem_alloc() or memcpy() below. +* kmalloc() or memcpy() below. */ if (unlikely (size >XFS_DFORK_SIZE (dip, ip->i_mount, whichfork))) { xfs_warn(ip->i_mount,
@@ -114,7 +114,7 @@ xfs_iformat_extents(/* * If the number of extents is unreasonable, then something is wrong and -* we just bail out rather than crash in kmem_alloc() or memcpy() below. +* we just bail out rather than crash in kmalloc() or memcpy() below. */ if (unlikely (size <0 || size >XFS_DFORK_SIZE (dip, mp, whichfork))) { xfs_warn(ip->i_mount, "corrupt inode %llu ((a)extents = %llu).",
@@ -203,7 +203,7 @@ xfs_iformat_btree( } ifp->if_broot_bytes = size; - ifp->if_broot =kmem_alloc (size,KM_NOFS ); + ifp->if_broot =kmalloc (size,GFP_NOFS | __GFP_NOFAIL);ASSERT (ifp->if_broot !=NULL );/* * Copy and convert from the on-disk structure
@@ -397,7 +397,8 @@ xfs_iroot_realloc(*/ if (ifp->if_broot_bytes ==0 ) { new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, rec_diff); - ifp->if_broot =kmem_alloc (new_size,KM_NOFS ); + ifp->if_broot =kmalloc (new_size, +GFP_NOFS | __GFP_NOFAIL); ifp->if_broot_bytes = (int )new_size;return ; }
@@ -438,7 +439,7 @@ xfs_iroot_realloc(else new_size =0 ;if (new_size >0 ) { - new_broot =kmem_alloc (new_size,KM_NOFS ); + new_broot =kmalloc (new_size,GFP_NOFS | __GFP_NOFAIL);/* * First copy over the btree block header. */
@@ -486,7 +487,7 @@ xfs_iroot_realloc(* * If the amount of space needed has decreased below the size of the * inline buffer, then switch to using the inline buffer. Otherwise, -* use kmem_realloc() or kmem_alloc() to adjust the size of the buffer +* use krealloc() or kmalloc() to adjust the size of the buffer * to what is needed. * * ip -- the inode whose if_data area is changing
PATCH 3/111 xfs: convert remaining kmem_free() to kfree()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: d4c75a1b40cd036a84d98e2711db9cf30eaaaf5f
The remaining callers of kmem_free() are freeing heap memory, so we can convert them directly to kfree() and get rid of kmem_free() altogether.
This conversion was done with:
$ for f in `git grep -l kmem_free fs/xfs`; do
Quoted 2 lines
sed -i s/kmem_free/kfree/ $f
done
$
--- libxfs/xfs_ag.c | 6 +++--- libxfs/xfs_attr_leaf.c | 8 ++++---- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree_staging.c | 4 ++-- libxfs/xfs_da_btree.c | 10 +++++----- libxfs/xfs_defer.c | 4 ++-- libxfs/xfs_dir2.c | 18 +++++++++--------- libxfs/xfs_dir2_block.c | 4 ++-- libxfs/xfs_dir2_sf.c | 8 ++++---- libxfs/xfs_iext_tree.c | 8 ++++---- libxfs/xfs_inode_fork.c | 6 +++--- 11 files changed, 39 insertions(+), 39 deletions(-)
libxfs/xfs_ag.c +3 -3
@@ -239,7 +239,7 @@ __xfs_free_perag( struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head);ASSERT (!delayed_work_pending (&pag->pag_blockgc_work)); -kmem_free (pag); +kfree (pag); }/*
@@ -351,7 +351,7 @@ xfs_free_unused_perag_range(break ;xfs_buf_hash_destroy (pag);xfs_defer_drain_free (&pag->pag_intents_drain); -kmem_free (pag); +kfree (pag); } }
@@ -451,7 +451,7 @@ xfs_initialize_perag(radix_tree_delete (&mp->m_perag_tree, index);spin_unlock (&mp->m_perag_lock); out_free_pag: -kmem_free (pag); +kfree (pag); out_unwind_new_pags:/* unwind any prior newly initialized pags */ xfs_free_unused_perag_range (mp, first_initialised, agcount);
libxfs/xfs_attr_leaf.c +4 -4
@@ -920,7 +920,7 @@ xfs_attr_shortform_to_leaf( } error =0 ; out: -kmem_free (tmpbuffer); +kfree (tmpbuffer);return error; }
@@ -1121,7 +1121,7 @@ xfs_attr3_leaf_to_shortform( error =0 ; out: -kmem_free (tmpbuffer); +kfree (tmpbuffer);return error; }
@@ -1567,7 +1567,7 @@ xfs_attr3_leaf_compact(*/ xfs_trans_log_buf (trans, bp,0 , args->geo->blksize -1 ); -kmem_free (tmpbuffer); +kfree (tmpbuffer); }/*
@@ -2287,7 +2287,7 @@ xfs_attr3_leaf_unbalance( }memcpy (save_leaf, tmp_leaf, state->args->geo->blksize); savehdr = tmphdr;/* struct copy */ -kmem_free (tmp_leaf); +kfree (tmp_leaf); }xfs_attr3_leaf_hdr_to_disk (state->args->geo, save_leaf, &savehdr);
libxfs/xfs_btree.c +1 -1
@@ -448,7 +448,7 @@ xfs_btree_del_cursor(ASSERT (cur->bc_btnum !=XFS_BTNUM_BMAP || cur->bc_ino.allocated ==0 ||xfs_is_shutdown (cur->bc_mp) || error !=0 );if (unlikely (cur->bc_flags &XFS_BTREE_STAGING )) -kmem_free (cur->bc_ops); +kfree (cur->bc_ops);if (!(cur->bc_flags &XFS_BTREE_LONG_PTRS ) && cur->bc_ag.pag)xfs_perag_put (cur->bc_ag.pag);kmem_cache_free (cur->bc_cache, cur);
libxfs/xfs_btree_staging.c +2 -2
@@ -171,7 +171,7 @@ xfs_btree_commit_afakeroot(trace_xfs_btree_commit_afakeroot (cur); -kmem_free ((void *)cur->bc_ops); +kfree ((void *)cur->bc_ops); cur->bc_ag.agbp = agbp; cur->bc_ops = ops; cur->bc_flags &= ~XFS_BTREE_STAGING ;
@@ -254,7 +254,7 @@ xfs_btree_commit_ifakeroot(trace_xfs_btree_commit_ifakeroot (cur); -kmem_free ((void *)cur->bc_ops); +kfree ((void *)cur->bc_ops); cur->bc_ino.ifake =NULL ; cur->bc_ino.whichfork = whichfork; cur->bc_ops = ops;
libxfs/xfs_da_btree.c +5 -5
@@ -2216,7 +2216,7 @@ xfs_da_grow_inode_int( out_free_map:if (mapp != &map) -kmem_free (mapp); +kfree (mapp);return error; }
@@ -2555,7 +2555,7 @@ xfs_dabuf_map( *nmaps = nirecs; out_free_irecs:if (irecs != &irec) -kmem_free (irecs); +kfree (irecs);return error; invalid_mapping:
@@ -2611,7 +2611,7 @@ xfs_da_get_buf( out_free:if (mapp != &map) -kmem_free (mapp); +kfree (mapp);return error; }
@@ -2652,7 +2652,7 @@ xfs_da_read_buf( *bpp = bp; out_free:if (mapp != &map) -kmem_free (mapp); +kfree (mapp);return error; }
@@ -2683,7 +2683,7 @@ xfs_da_reada_buf( out_free:if (mapp != &map) -kmem_free (mapp); +kfree (mapp);return error; }
libxfs/xfs_defer.c +2 -2
@@ -1032,7 +1032,7 @@ xfs_defer_ops_capture_abort(for (i =0 ; i < dfc->dfc_held.dr_inos; i++)xfs_irele (dfc->dfc_held.dr_ip[i]); -kmem_free (dfc); +kfree (dfc); }/*
@@ -1108,7 +1108,7 @@ xfs_defer_ops_continue(list_splice_init (&dfc->dfc_dfops, &tp->t_dfops); tp->t_flags |= dfc->dfc_tpflags; -kmem_free (dfc); +kfree (dfc); }/* Release the resources captured and continued during recovery. */
libxfs/xfs_dir2.c +9 -9
@@ -108,8 +108,8 @@ xfs_da_mount( mp->m_attr_geo =kzalloc (sizeof (struct xfs_da_geometry ),GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!mp->m_dir_geo || !mp->m_attr_geo) { -kmem_free (mp->m_dir_geo); -kmem_free (mp->m_attr_geo); +kfree (mp->m_dir_geo); +kfree (mp->m_attr_geo);return -ENOMEM ; }
@@ -177,8 +177,8 @@ voidxfs_da_unmount ( struct xfs_mount *mp) { -kmem_free (mp->m_dir_geo); -kmem_free (mp->m_attr_geo); +kfree (mp->m_dir_geo); +kfree (mp->m_attr_geo); }/*
@@ -243,7 +243,7 @@ xfs_dir_init( args->dp = dp; args->trans = tp; error =xfs_dir2_sf_create (args, pdp->i_ino); -kmem_free (args); +kfree (args);return error; }
@@ -312,7 +312,7 @@ xfs_dir_createname( rval =xfs_dir2_node_addname (args); out_free: -kmem_free (args); +kfree (args);return rval; }
@@ -418,7 +418,7 @@ xfs_dir_lookup( } out_free:xfs_iunlock (dp, lock_mode); -kmem_free (args); +kfree (args);return rval; }
@@ -476,7 +476,7 @@ xfs_dir_removename(else rval =xfs_dir2_node_removename (args); out_free: -kmem_free (args); +kfree (args);return rval; }
@@ -537,7 +537,7 @@ xfs_dir_replace(else rval =xfs_dir2_node_replace (args); out_free: -kmem_free (args); +kfree (args);return rval; }
libxfs/xfs_dir2_block.c +2 -2
@@ -1250,7 +1250,7 @@ xfs_dir2_sf_to_block( sfep =xfs_dir2_sf_nextentry (mp, sfp, sfep); }/* Done with the temporary buffer */ -kmem_free (sfp); +kfree (sfp);/* * Sort the leaf entries by hash value. */
@@ -1265,6 +1265,6 @@ xfs_dir2_sf_to_block(xfs_dir3_data_check (dp, bp);return 0 ; out_free: -kmem_free (sfp); +kfree (sfp);return error; }
libxfs/xfs_dir2_sf.c +4 -4
@@ -350,7 +350,7 @@ xfs_dir2_block_to_sf(xfs_dir2_sf_check (args); out:xfs_trans_log_inode (args->trans, dp, logflags); -kmem_free (sfp); +kfree (sfp);return error; }
@@ -576,7 +576,7 @@ xfs_dir2_sf_addname_hard( sfep =xfs_dir2_sf_nextentry (mp, sfp, sfep);memcpy (sfep, oldsfep, old_isize - nbytes); } -kmem_free (buf); +kfree (buf); dp->i_disk_size = new_isize;xfs_dir2_sf_check (args); }
@@ -1190,7 +1190,7 @@ xfs_dir2_sf_toino4(/* * Clean up the inode. */ -kmem_free (buf); +kfree (buf); dp->i_disk_size = newsize;xfs_trans_log_inode (args->trans, dp,XFS_ILOG_CORE |XFS_ILOG_DDATA ); }
@@ -1262,7 +1262,7 @@ xfs_dir2_sf_toino8(/* * Clean up the inode. */ -kmem_free (buf); +kfree (buf); dp->i_disk_size = newsize;xfs_trans_log_inode (args->trans, dp,XFS_ILOG_CORE |XFS_ILOG_DDATA ); }
libxfs/xfs_iext_tree.c +4 -4
@@ -747,7 +747,7 @@ xfs_iext_remove_node( again:ASSERT (node->ptrs[pos]);ASSERT (node->ptrs[pos] == victim); -kmem_free (victim); +kfree (victim); nr_entries =xfs_iext_node_nr_entries (node, pos) -1 ; offset = node->keys[0 ];
@@ -793,7 +793,7 @@ xfs_iext_remove_node(ASSERT (node == ifp->if_data); ifp->if_data = node->ptrs[0 ]; ifp->if_height--; -kmem_free (node); +kfree (node); } }
@@ -867,7 +867,7 @@ xfs_iext_free_last_leaf( struct xfs_ifork *ifp) { ifp->if_height--; -kmem_free (ifp->if_data); +kfree (ifp->if_data); ifp->if_data =NULL ; }
@@ -1048,7 +1048,7 @@ xfs_iext_destroy_node( } } -kmem_free (node); +kfree (node); }void
libxfs/xfs_inode_fork.c +3 -3
@@ -469,7 +469,7 @@ xfs_iroot_realloc( (int)new_size);memcpy (np, op, new_max * (uint )sizeof (xfs_fsblock_t)); } -kmem_free (ifp->if_broot); +kfree (ifp->if_broot); ifp->if_broot = new_broot; ifp->if_broot_bytes = (int )new_size;if (ifp->if_broot)
@@ -523,13 +523,13 @@ xfs_idestroy_fork( struct xfs_ifork *ifp) {if (ifp->if_broot !=NULL ) { -kmem_free (ifp->if_broot); +kfree (ifp->if_broot); ifp->if_broot =NULL ; }switch (ifp->if_format) {case XFS_DINODE_FMT_LOCAL : -kmem_free (ifp->if_data); +kfree (ifp->if_data); ifp->if_data =NULL ;break ;case XFS_DINODE_FMT_EXTENTS :
PATCH 4/111 xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 94a69db2367efcd7e0eeb5d4603340aff1d3c340
In the past we've had problems with lockdep false positives stemming from inode locking occurring in memory reclaim contexts (e.g. from superblock shrinkers). Lockdep doesn't know that inodes access from above memory reclaim cannot be accessed from below memory reclaim (and vice versa) but there has never been a good solution to solving this problem with lockdep annotations.
This situation isn't unique to inode locks - buffers are also locked above and below memory reclaim, and we have to maintain lock ordering for them - and against inodes - appropriately. IOWs, the same code paths and locks are taken both above and below memory reclaim and so we always need to make sure the lock orders are consistent. We are spared the lockdep problems this might cause by the fact that semaphores and bit locks aren't covered by lockdep.
In general, this sort of lockdep false positive detection is cause by code that runs GFP_KERNEL memory allocation with an actively referenced inode locked. When it is run from a transaction, memory allocation is automatically GFP_NOFS, so we don't have reclaim recursion issues. So in the places where we do memory allocation with inodes locked outside of a transaction, we have explicitly set them to use GFP_NOFS allocations to prevent lockdep false positives from being reported if the allocation dips into direct memory reclaim.
More recently, __GFP_NOLOCKDEP was added to the memory allocation flags to tell lockdep not to track that particular allocation for the purposes of reclaim recursion detection. This is a much better way of preventing false positives - it allows us to use GFP_KERNEL context outside of transactions, and allows direct memory reclaim to proceed normally without throwing out false positive deadlock warnings.
The obvious places that lock inodes and do memory allocation are the lookup paths and inode extent list initialisation. These occur in non-transactional GFP_KERNEL contexts, and so can run direct reclaim and lock inodes.
This patch makes a first path through all the explicit GFP_NOFS allocations in XFS and converts the obvious ones to GFP_KERNEL | __GFP_NOLOCKDEP as a first step towards removing explicit GFP_NOFS allocations from the XFS code.
--- libxfs/xfs_ag.c | 2 +- libxfs/xfs_btree.h | 4 +++- libxfs/xfs_da_btree.c | 8 +++++--- libxfs/xfs_dir2.c | 14 ++++---------- libxfs/xfs_iext_tree.c | 22 +++++++++++++--------- libxfs/xfs_inode_fork.c | 8 +++++--- 6 files changed, 31 insertions(+), 27 deletions(-)
libxfs/xfs_ag.c +1 -1
@@ -387,7 +387,7 @@ xfs_initialize_perag( pag->pag_agno = index; pag->pag_mount = mp; - error =radix_tree_preload (GFP_NOFS ); + error =radix_tree_preload (GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (error) goto out_free_pag;
libxfs/xfs_btree.h +3 -1
@@ -725,7 +725,9 @@ xfs_btree_alloc_cursor( {struct xfs_btree_cur *cur; - cur =kmem_cache_zalloc (cache,GFP_NOFS | __GFP_NOFAIL); +/* BMBT allocations can come through from non-transactional context. */ + cur =kmem_cache_zalloc (cache, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum;
libxfs/xfs_da_btree.c +5 -3
@@ -81,7 +81,8 @@ xfs_da_state_alloc( {struct xfs_da_state *state; - state =kmem_cache_zalloc (xfs_da_state_cache,GFP_NOFS | __GFP_NOFAIL); + state =kmem_cache_zalloc (xfs_da_state_cache, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); state->args = args; state->mp = args->dp->i_mount;return state;
@@ -2515,7 +2516,8 @@ xfs_dabuf_map(int error =0 , nirecs, i;if (nfsb >1 ) - irecs =kzalloc (sizeof (irec) * nfsb,GFP_NOFS | __GFP_NOFAIL); + irecs =kzalloc (sizeof (irec) * nfsb, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); nirecs = nfsb; error = xfs_bmapi_read(dp, bno, nfsb, irecs, &nirecs,
@@ -2529,7 +2531,7 @@ xfs_dabuf_map(*/ if (nirecs >1 ) { map =kzalloc (nirecs *sizeof (struct xfs_buf_map ), -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);if (!map) { error = -ENOMEM ; goto out_free_irecs;
libxfs/xfs_dir2.c +4 -10
@@ -332,7 +332,8 @@ xfs_dir_cilookup_result( !(args->op_flags & XFS_DA_OP_CILOOKUP))return -EEXIST ; - args->value =kmalloc (len,GFP_NOFS | __GFP_RETRY_MAYFAIL); + args->value =kmalloc (len, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL);if (!args->value)return -ENOMEM ;
@@ -363,15 +364,8 @@ xfs_dir_lookup(ASSERT (S_ISDIR (VFS_I (dp)->i_mode));XFS_STATS_INC (dp->i_mount, xs_dir_lookup); -/* -* We need to use KM_NOFS here so that lockdep will not throw false -* positive deadlock warnings on a non-transactional lookup path. It is -* safe to recurse into inode recalim in that case, but lockdep can't -* easily be taught about it. Hence KM_NOFS avoids having to add more -* lockdep Doing this avoids having to add a bunch of lockdep class -* annotations into the reclaim path for the ilock. -*/ - args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); + args =kzalloc (sizeof (*args), +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); args->geo = dp->i_mount->m_dir_geo; args->name = name->name; args->namelen = name->len;
libxfs/xfs_iext_tree.c +13 -9
@@ -394,12 +394,18 @@ xfs_iext_leaf_key(return leaf->recs[n].lo &XFS_IEXT_STARTOFF_MASK ; } +static inline void * +xfs_iext_alloc_node ( +int size) +{ +return kzalloc (size,GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); +} +static void xfs_iext_grow (struct xfs_ifork *ifp) { -struct xfs_iext_node *node =kzalloc (NODE_SIZE , -GFP_NOFS | __GFP_NOFAIL); +struct xfs_iext_node *node =xfs_iext_alloc_node (NODE_SIZE );int i;if (ifp->if_height ==1 ) {
@@ -455,8 +461,7 @@ xfs_iext_split_node( int *nr_entries) {struct xfs_iext_node *node = *nodep; -struct xfs_iext_node *new =kzalloc (NODE_SIZE , -GFP_NOFS | __GFP_NOFAIL); +struct xfs_iext_node *new =xfs_iext_alloc_node (NODE_SIZE );const int nr_move =KEYS_PER_NODE /2 ;int nr_keep = nr_move + (KEYS_PER_NODE &1 );int i =0 ;
@@ -544,8 +549,7 @@ xfs_iext_split_leaf( int *nr_entries) {struct xfs_iext_leaf *leaf = cur->leaf; -struct xfs_iext_leaf *new =kzalloc (NODE_SIZE , -GFP_NOFS | __GFP_NOFAIL); +struct xfs_iext_leaf *new =xfs_iext_alloc_node (NODE_SIZE );const int nr_move =RECS_PER_LEAF /2 ;int nr_keep = nr_move + (RECS_PER_LEAF &1 );int i;
@@ -586,8 +590,7 @@ xfs_iext_alloc_root( {ASSERT (ifp->if_bytes ==0 ); - ifp->if_data =kzalloc (sizeof (struct xfs_iext_rec ), -GFP_NOFS | __GFP_NOFAIL); + ifp->if_data =xfs_iext_alloc_node (sizeof (struct xfs_iext_rec )); ifp->if_height =1 ;/* now that we have a node step into it */
@@ -607,7 +610,8 @@ xfs_iext_realloc_root(if (new_size /sizeof (struct xfs_iext_rec ) ==RECS_PER_LEAF ) new_size =NODE_SIZE ; - new =krealloc (ifp->if_data, new_size,GFP_NOFS | __GFP_NOFAIL); + new =krealloc (ifp->if_data, new_size, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);memset (new + ifp->if_bytes,0 , new_size - ifp->if_bytes); ifp->if_data = new; cur->leaf = new;
libxfs/xfs_inode_fork.c +5 -3
@@ -48,7 +48,8 @@ xfs_init_local_fork( mem_size++;if (size) { -char *new_data =kmalloc (mem_size,GFP_NOFS | __GFP_NOFAIL); +char *new_data =kmalloc (mem_size, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);memcpy (new_data, data, size);if (zero_terminate)
@@ -203,7 +204,8 @@ xfs_iformat_btree( } ifp->if_broot_bytes = size; - ifp->if_broot =kmalloc (size,GFP_NOFS | __GFP_NOFAIL); + ifp->if_broot =kmalloc (size, +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);ASSERT (ifp->if_broot !=NULL );/* * Copy and convert from the on-disk structure
@@ -688,7 +690,7 @@ xfs_ifork_init_cow(return ; ip->i_cowfp =kmem_cache_zalloc (xfs_ifork_cache, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); ip->i_cowfp->if_format =XFS_DINODE_FMT_EXTENTS ; }
PATCH 5/111 xfs: use GFP_KERNEL in pure transaction contexts
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 0b3a76e955ebe3d71a2bcd5990404ed522b40e17
When running in a transaction context, memory allocations are scoped to GFP_NOFS. Hence we don't need to use GFP_NOFS contexts in pure transaction context allocations - GFP_KERNEL will automatically get converted to GFP_NOFS as appropriate.
Go through the code and convert all the obvious GFP_NOFS allocations in transaction context to use GFP_KERNEL. This further reduces the explicit use of GFP_NOFS in XFS.
--- libxfs/xfs_attr.c | 3 ++- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_defer.c | 6 +++--- libxfs/xfs_dir2.c | 8 ++++---- libxfs/xfs_inode_fork.c | 8 ++++---- libxfs/xfs_refcount.c | 2 +- libxfs/xfs_rmap.c | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-)
libxfs/xfs_attr.c +2 -1
@@ -889,7 +889,8 @@ xfs_attr_defer_add(struct xfs_attr_intent *new; - new =kmem_cache_zalloc (xfs_attr_intent_cache,GFP_NOFS | __GFP_NOFAIL); + new =kmem_cache_zalloc (xfs_attr_intent_cache, +GFP_KERNEL | __GFP_NOFAIL); new->xattri_op_flags = op_flags; new->xattri_da_args = args;
libxfs/xfs_bmap.c +1 -1
@@ -6092,7 +6092,7 @@ __xfs_bmap_add( bmap->br_blockcount, bmap->br_state); - bi =kmem_cache_alloc (xfs_bmap_intent_cache,GFP_NOFS | __GFP_NOFAIL); + bi =kmem_cache_alloc (xfs_bmap_intent_cache,GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&bi->bi_list); bi->bi_type = type; bi->bi_owner = ip;
libxfs/xfs_defer.c +3 -3
@@ -819,7 +819,7 @@ xfs_defer_alloc(struct xfs_defer_pending *dfp; dfp =kmem_cache_zalloc (xfs_defer_pending_cache, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL); dfp->dfp_ops = ops;INIT_LIST_HEAD (&dfp->dfp_work);list_add_tail (&dfp->dfp_list, &tp->t_dfops);
@@ -882,7 +882,7 @@ xfs_defer_start_recovery(struct xfs_defer_pending *dfp; dfp =kmem_cache_zalloc (xfs_defer_pending_cache, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL); dfp->dfp_ops = ops; dfp->dfp_intent = lip;INIT_LIST_HEAD (&dfp->dfp_work);
@@ -973,7 +973,7 @@ xfs_defer_ops_capture(return ERR_PTR (error);/* Create an object to capture the defer ops. */ - dfc =kzalloc (sizeof (*dfc),GFP_NOFS | __GFP_NOFAIL); + dfc =kzalloc (sizeof (*dfc),GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&dfc->dfc_list);INIT_LIST_HEAD (&dfc->dfc_dfops);
libxfs/xfs_dir2.c +4 -4
@@ -235,7 +235,7 @@ xfs_dir_init(if (error)return error; - args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); + args =kzalloc (sizeof (*args),GFP_KERNEL | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -272,7 +272,7 @@ xfs_dir_createname(XFS_STATS_INC (dp->i_mount, xs_dir_create); } - args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); + args =kzalloc (sizeof (*args),GFP_KERNEL | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -434,7 +434,7 @@ xfs_dir_removename(ASSERT (S_ISDIR (VFS_I (dp)->i_mode));XFS_STATS_INC (dp->i_mount, xs_dir_remove); - args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); + args =kzalloc (sizeof (*args),GFP_KERNEL | __GFP_NOFAIL);if (!args)return -ENOMEM ;
@@ -495,7 +495,7 @@ xfs_dir_replace(if (rval)return rval; - args =kzalloc (sizeof (*args),GFP_NOFS | __GFP_NOFAIL); + args =kzalloc (sizeof (*args),GFP_KERNEL | __GFP_NOFAIL);if (!args)return -ENOMEM ;
libxfs/xfs_inode_fork.c +4 -4
@@ -400,7 +400,7 @@ xfs_iroot_realloc(if (ifp->if_broot_bytes ==0 ) { new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, rec_diff); ifp->if_broot =kmalloc (new_size, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL); ifp->if_broot_bytes = (int )new_size;return ; }
@@ -415,7 +415,7 @@ xfs_iroot_realloc( new_max = cur_max + rec_diff; new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, new_max); ifp->if_broot =krealloc (ifp->if_broot, new_size, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL); op = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, ifp->if_broot,1 , ifp->if_broot_bytes); np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
@@ -441,7 +441,7 @@ xfs_iroot_realloc(else new_size =0 ;if (new_size >0 ) { - new_broot =kmalloc (new_size,GFP_NOFS | __GFP_NOFAIL); + new_broot =kmalloc (new_size,GFP_KERNEL | __GFP_NOFAIL);/* * First copy over the btree block header. */
@@ -510,7 +510,7 @@ xfs_idata_realloc(if (byte_diff) { ifp->if_data =krealloc (ifp->if_data, new_size, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL);if (new_size ==0 ) ifp->if_data =NULL ; ifp->if_bytes = new_size;
libxfs/xfs_refcount.c +1 -1
@@ -1448,7 +1448,7 @@ __xfs_refcount_add( blockcount); ri =kmem_cache_alloc (xfs_refcount_intent_cache, -GFP_NOFS | __GFP_NOFAIL); +GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&ri->ri_list); ri->ri_type = type; ri->ri_startblock = startblock;
libxfs/xfs_rmap.c +1 -1
@@ -2558,7 +2558,7 @@ __xfs_rmap_add( bmap->br_blockcount, bmap->br_state); - ri =kmem_cache_alloc (xfs_rmap_intent_cache,GFP_NOFS | __GFP_NOFAIL); + ri =kmem_cache_alloc (xfs_rmap_intent_cache,GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&ri->ri_list); ri->ri_type = type; ri->ri_owner = owner;
PATCH 6/111 xfs: clean up remaining GFP_NOFS users
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 204fae32d5f7b9ac673d3d4f636dcef8697db2f0
These few remaining GFP_NOFS callers do not need to use GFP_NOFS at all. They are only called from a non-transactional context or cannot be accessed from memory reclaim due to other constraints. Hence they can just use GFP_KERNEL.
--- libxfs/xfs_btree_staging.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/xfs_btree_staging.c +2 -2
@@ -139,7 +139,7 @@ xfs_btree_stage_afakeroot(ASSERT (!(cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ));ASSERT (cur->bc_tp ==NULL ); - nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_NOFS | __GFP_NOFAIL); + nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);memcpy (nops, cur->bc_ops,sizeof (struct xfs_btree_ops )); nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->free_block = xfs_btree_fakeroot_free_block;
@@ -220,7 +220,7 @@ xfs_btree_stage_ifakeroot(ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE );ASSERT (cur->bc_tp ==NULL ); - nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_NOFS | __GFP_NOFAIL); + nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);memcpy (nops, cur->bc_ops,sizeof (struct xfs_btree_ops )); nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->free_block = xfs_btree_fakeroot_free_block;
PATCH 7/111 xfs: use xfs_defer_alloc a bit more
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 57b98393b812ddaf9cf33a0d57d70b25cabfed66
Noticed by inspection, simple factoring allows the same allocation routine to be used for both transaction and recovery contexts.
--- libxfs/xfs_defer.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
libxfs/xfs_defer.c +5 -10
@@ -813,7 +813,7 @@ xfs_defer_can_append(/* Create a new pending item at the end of the transaction list. */ static inline struct xfs_defer_pending *xfs_defer_alloc ( -struct xfs_trans *tp, +struct list_head *dfops,const struct xfs_defer_op_type *ops) {struct xfs_defer_pending *dfp;
@@ -822,7 +822,7 @@ xfs_defer_alloc( GFP_KERNEL | __GFP_NOFAIL); dfp->dfp_ops = ops;INIT_LIST_HEAD (&dfp->dfp_work); -list_add_tail (&dfp->dfp_list, &tp->t_dfops); +list_add_tail (&dfp->dfp_list, dfops);return dfp; }
@@ -840,7 +840,7 @@ xfs_defer_add( dfp =xfs_defer_find_last (tp, ops);if (!dfp || !xfs_defer_can_append (dfp, ops)) - dfp =xfs_defer_alloc (tp, ops); + dfp =xfs_defer_alloc (&tp->t_dfops, ops);xfs_defer_add_item (dfp, li);trace_xfs_defer_add_item (tp->t_mountp, dfp, li);
@@ -864,7 +864,7 @@ xfs_defer_add_barrier(if (dfp)return ; -xfs_defer_alloc (tp, &xfs_barrier_defer_type); +xfs_defer_alloc (&tp->t_dfops, &xfs_barrier_defer_type);trace_xfs_defer_add_item (tp->t_mountp, dfp,NULL ); }
@@ -879,14 +879,9 @@ xfs_defer_start_recovery(struct list_head *r_dfops, const struct xfs_defer_op_type *ops) { - struct xfs_defer_pending *dfp; + struct xfs_defer_pending *dfp = xfs_defer_alloc(r_dfops, ops); - dfp =kmem_cache_zalloc (xfs_defer_pending_cache, -GFP_KERNEL | __GFP_NOFAIL); - dfp->dfp_ops = ops; dfp->dfp_intent = lip; -INIT_LIST_HEAD (&dfp->dfp_work); -list_add_tail (&dfp->dfp_list, r_dfops); }/*
PATCH 8/111 xfs: Replace xfs_isilocked with xfs_assert_ilocked
In reply to Darrick J. WongFrom: Matthew Wilcox (Oracle) <[email protected]>
Source kernel commit: 3fed24fffc76dd1a8105db558e98bc8355d60379
To use the new rwsem_assert_held()/rwsem_assert_held_write(), we can't use the existing ASSERT macro. Add a new xfs_assert_ilocked() and convert all the callers.
Fix an apparent bug in xfs_isilocked(): If the caller specifies XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL, xfs_assert_ilocked() will check both the IOLOCK and the ILOCK are held for write. xfs_isilocked() only checked that the ILOCK was held for write.
xfs_assert_ilocked() is always on, even if DEBUG or XFS_WARN aren't defined. It's a cheap check, so I don't think it's worth defining it away.
--- libxfs/libxfs_priv.h | 1 + libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr_remote.c | 2 +- libxfs/xfs_bmap.c | 21 ++++++++++----------- libxfs/xfs_defer.c | 2 +- libxfs/xfs_inode_fork.c | 2 +- libxfs/xfs_rtbitmap.c | 2 +- libxfs/xfs_trans_inode.c | 6 +++--- 8 files changed, 19 insertions(+), 19 deletions(-)
libxfs/libxfs_priv.h +1 -0
@@ -406,6 +406,7 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa); __mode = __mode;/* no set-but-unused warning */ \ })#define xfs_lock_two_inodes (ip0,mode0,ip1,mode1) ((void) 0) +#define xfs_assert_ilocked (ip, flags) ((void) 0)/* space allocation */ #define XFS_EXTENT_BUSY_DISCARDED 0x01/* undergoing a discard op. */
libxfs/xfs_attr.c +1 -1
@@ -222,7 +222,7 @@ intxfs_attr_get_ilocked ( struct xfs_da_args *args) { -ASSERT (xfs_isilocked (args->dp,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )); +xfs_assert_ilocked (args->dp,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL );if (!xfs_inode_hasattr (args->dp))return -ENOATTR ;
libxfs/xfs_attr_remote.c +1 -1
@@ -544,7 +544,7 @@ xfs_attr_rmtval_stale(struct xfs_buf *bp;int error; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );if (XFS_IS_CORRUPT (mp, map->br_startblock ==DELAYSTARTBLOCK ) ||XFS_IS_CORRUPT (mp, map->br_startblock ==HOLESTARTBLOCK ))
libxfs/xfs_bmap.c +10 -11
@@ -1183,7 +1183,7 @@ xfs_iread_extents(if (!xfs_need_iread_extents (ifp))return 0 ; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL ); ir.loaded =0 ;xfs_iext_first (ifp, &ir.icur);
@@ -3892,7 +3892,7 @@ xfs_bmapi_read(ASSERT (*nmap >=1 );ASSERT (!(flags & ~(XFS_BMAPI_ATTRFORK |XFS_BMAPI_ENTIRE ))); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL );if (WARN_ON_ONCE (!ifp))return -EFSCORRUPTED ;
@@ -4363,7 +4363,7 @@ xfs_bmapi_write(ASSERT (tp !=NULL );ASSERT (len >0 );ASSERT (ifp->if_format !=XFS_DINODE_FMT_LOCAL ); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (!(flags &XFS_BMAPI_REMAP ));/* zeroing is for currently only for data extents, not metadata */
@@ -4660,7 +4660,7 @@ xfs_bmapi_remap( ifp =xfs_ifork_ptr (ip, whichfork);ASSERT (len >0 );ASSERT (len <= (xfs_filblks_t )XFS_MAX_BMBT_EXTLEN ); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (!(flags & ~(XFS_BMAPI_ATTRFORK |XFS_BMAPI_PREALLOC |XFS_BMAPI_NORMAP ))); ASSERT((flags & (XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC)) !=
@@ -5285,7 +5285,7 @@ __xfs_bunmapi(if (xfs_is_shutdown (mp))return -EIO ; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (len >0 );ASSERT (nexts >=0 );
@@ -5629,8 +5629,7 @@ xfs_bmse_merge( blockcount = left->br_blockcount + got->br_blockcount; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL );ASSERT (xfs_bmse_can_merge (left, got, shift)); new = *left;
@@ -5758,7 +5757,7 @@ xfs_bmap_collapse_extents(if (xfs_is_shutdown (mp))return -EIO ; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL ); error =xfs_iread_extents (tp, ip, whichfork);if (error)
@@ -5831,7 +5830,7 @@ xfs_bmap_can_insert_extents(int is_empty;int error =0 ; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_IOLOCK_EXCL );if (xfs_is_shutdown (ip->i_mount))return -EIO ;
@@ -5873,7 +5872,7 @@ xfs_bmap_insert_extents(if (xfs_is_shutdown (mp))return -EIO ; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL ); error =xfs_iread_extents (tp, ip, whichfork);if (error)
@@ -6251,7 +6250,7 @@ xfs_bunmapi_range(xfs_filblks_t unmap_len = endoff - startoff +1 ;int error =0 ; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );while (unmap_len >0 ) {ASSERT ((*tpp)->t_highest_agno ==NULLAGNUMBER );
libxfs/xfs_defer.c +1 -1
@@ -1000,7 +1000,7 @@ xfs_defer_ops_capture(* transaction. */ for (i =0 ; i < dfc->dfc_held.dr_inos; i++) { -ASSERT (xfs_isilocked (dfc->dfc_held.dr_ip[i],XFS_ILOCK_EXCL )); +xfs_assert_ilocked (dfc->dfc_held.dr_ip[i],XFS_ILOCK_EXCL );ihold (VFS_I (dfc->dfc_held.dr_ip[i])); }
libxfs/xfs_inode_fork.c +1 -1
@@ -563,7 +563,7 @@ xfs_iextents_copy(struct xfs_bmbt_irec rec;int64_t copied =0 ; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL |XFS_ILOCK_SHARED )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL |XFS_ILOCK_SHARED );ASSERT (ifp->if_bytes >0 );for_each_xfs_iext (ifp, &icur, &rec) {
libxfs/xfs_rtbitmap.c +1 -1
@@ -932,7 +932,7 @@ xfs_rtfree_extent(struct timespec64 atime;ASSERT (mp->m_rbmip->i_itemp !=NULL ); -ASSERT (xfs_isilocked (mp->m_rbmip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (mp->m_rbmip,XFS_ILOCK_EXCL ); error =xfs_rtcheck_alloc_range (&args, start, len);if (error)
libxfs/xfs_trans_inode.c +3 -3
@@ -28,7 +28,7 @@ xfs_trans_ijoin( {struct xfs_inode_log_item *iip; -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );if (ip->i_itemp ==NULL )xfs_inode_item_init (ip, ip->i_mount); iip = ip->i_itemp;
@@ -57,7 +57,7 @@ xfs_trans_ichgtime(struct timespec64 tv;ASSERT (tp); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL ); tv =current_time (inode);
@@ -87,7 +87,7 @@ xfs_trans_log_inode(struct inode *inode =VFS_I (ip);ASSERT (iip); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (!xfs_iflags_test (ip,XFS_ISTALE )); tp->t_flags |=XFS_TRANS_DIRTY ;
PATCH 9/111 xfs: create a static name for the dot entry too
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: e99bfc9e687e208d4ba7e85167b8753e80cf4169
Create an xfs_name_dot object so that upcoming scrub code can compare against that. Offline repair already has such an object, so we're really just hoisting it to the kernel.
--- libxfs/xfs_dir2.c | 6 ++++++ libxfs/xfs_dir2.h | 1 + repair/phase6.c | 4 ---- 3 files changed, 7 insertions(+), 4 deletions(-)
libxfs/xfs_dir2.c +6 -0
@@ -24,6 +24,12 @@ const struct xfs_name xfs_name_dotdot = { .type = XFS_DIR3_FT_DIR, }; +const struct xfs_name xfs_name_dot = { + .name = (const unsigned char *)"." , + .len =1 , + .type =XFS_DIR3_FT_DIR , +}; +/* * Convert inode mode to directory entry filetype */
libxfs/xfs_dir2.h +1 -0
@@ -22,6 +22,7 @@ struct xfs_dir3_icfree_hdr;struct xfs_dir3_icleaf_hdr ;extern const struct xfs_name xfs_name_dotdot; +extern const struct xfs_name xfs_name_dot;/* * Convert inode mode to directory entry filetype
repair/phase6.c +0 -4
@@ -23,10 +23,6 @@ static struct cred zerocr;static struct fsxattr zerofsx;static xfs_ino_t orphanage_ino; -static struct xfs_name xfs_name_dot = {(unsigned char *)"." , -1 , -XFS_DIR3_FT_DIR }; -/* * Data structures used to keep track of directories where the ".." * entries are updated. These must be rebuilt after the initial pass
PATCH 10/111 xfs: create a predicate to determine if two xfs_names are the same
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: d9c0775897147bab54410611ac2659a7477c770c
Create a simple predicate to determine if two xfs_names are the same objects or have the exact same name. The comparison is always case sensitive.
--- libxfs/xfs_dir2.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
libxfs/xfs_dir2.h +12 -0
@@ -24,6 +24,18 @@ struct xfs_dir3_icleaf_hdr;extern const struct xfs_name xfs_name_dotdot;extern const struct xfs_name xfs_name_dot; +static inline bool +xfs_dir2_samename ( +const struct xfs_name *n1, +const struct xfs_name *n2) +{ +if (n1 == n2) +return true; +if (n1->len != n2->len) +return false; +return !memcmp (n1->name, n2->name, n1->len); +} +/* * Convert inode mode to directory entry filetype */
PATCH 11/111 xfs: create a macro for decoding ftypes in tracepoints
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 3c79e6a87221e063064e3680946a8b4bcd9fe78d
Create the XFS_DIR3_FTYPE_STR macro so that we can report ftype as strings instead of numbers in tracepoints.
--- libxfs/xfs_da_format.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
libxfs/xfs_da_format.h +11 -0
@@ -159,6 +159,17 @@ struct xfs_da3_intnode {#define XFS_DIR3_FT_MAX 9 +#define XFS_DIR3_FTYPE_STR \ + { XFS_DIR3_FT_UNKNOWN, "unknown" }, \ + { XFS_DIR3_FT_REG_FILE, "file" }, \ + { XFS_DIR3_FT_DIR, "directory" }, \ + { XFS_DIR3_FT_CHRDEV, "char" }, \ + { XFS_DIR3_FT_BLKDEV, "block" }, \ + { XFS_DIR3_FT_FIFO, "fifo" }, \ + { XFS_DIR3_FT_SOCK, "sock" }, \ + { XFS_DIR3_FT_SYMLINK, "symlink" }, \ + { XFS_DIR3_FT_WHT, "whiteout" } +/* * Byte offset in data block and shortform entry. */
PATCH 12/111 xfs: report the health of quota counts
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 3d8f1426977f1bf10f867bcd26df6518ae6c2b2c
Report the health of quota counts.
--- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +1 -0
@@ -195,6 +195,7 @@ struct xfs_fsop_geom {#define XFS_FSOP_GEOM_SICK_PQUOTA (1 << 3)/* project quota */ #define XFS_FSOP_GEOM_SICK_RT_BITMAP (1 << 4)/* realtime bitmap */ #define XFS_FSOP_GEOM_SICK_RT_SUMMARY (1 << 5)/* realtime summary */ +#define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6)/* quota counts */ /* Output for XFS_FS_COUNTS */ typedef struct xfs_fsop_counts {
libxfs/xfs_health.h +3 -1
@@ -41,6 +41,7 @@ struct xfs_fsop_geom;#define XFS_SICK_FS_UQUOTA (1 << 1)/* user quota */ #define XFS_SICK_FS_GQUOTA (1 << 2)/* group quota */ #define XFS_SICK_FS_PQUOTA (1 << 3)/* project quota */ +#define XFS_SICK_FS_QUOTACHECK (1 << 4)/* quota counts */ /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0)/* realtime bitmap */
@@ -77,7 +78,8 @@ struct xfs_fsop_geom;#define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \ XFS_SICK_FS_UQUOTA | \ XFS_SICK_FS_GQUOTA | \ - XFS_SICK_FS_PQUOTA) + XFS_SICK_FS_PQUOTA | \ + XFS_SICK_FS_QUOTACHECK)#define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \ XFS_SICK_RT_SUMMARY)
PATCH 13/111 xfs: implement live quotacheck inode scan
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 48dd9117a34fe9a34a6be0b1dba5694e0f19cbd4
Create a new trio of scrub functions to check quota counters. While the dquots themselves are filesystem metadata and should be checked early, the dquot counter values are computed from other metadata and are therefore summary counters. We don't plug these into the scrub dispatch just yet, because we still need to be able to watch quota updates while doing our scan.
--- libxfs/xfs_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +2 -1
@@ -710,9 +710,10 @@ struct xfs_scrub_metadata {#define XFS_SCRUB_TYPE_GQUOTA 22/* group quotas */ #define XFS_SCRUB_TYPE_PQUOTA 23/* project quotas */ #define XFS_SCRUB_TYPE_FSCOUNTERS 24/* fs summary counters */ +#define XFS_SCRUB_TYPE_QUOTACHECK 25/* quota counters */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 25 +#define XFS_SCRUB_TYPE_NR 26/* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0)
PATCH 14/111 xfs: report health of inode link counts
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 93687ee2e3748a4a6b541ff0d83d1480815b00a9
Report on the health of the inode link counts.
--- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +1 -0
@@ -196,6 +196,7 @@ struct xfs_fsop_geom {#define XFS_FSOP_GEOM_SICK_RT_BITMAP (1 << 4)/* realtime bitmap */ #define XFS_FSOP_GEOM_SICK_RT_SUMMARY (1 << 5)/* realtime summary */ #define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6)/* quota counts */ +#define XFS_FSOP_GEOM_SICK_NLINKS (1 << 7)/* inode link counts */ /* Output for XFS_FS_COUNTS */ typedef struct xfs_fsop_counts {
libxfs/xfs_health.h +3 -1
@@ -42,6 +42,7 @@ struct xfs_fsop_geom;#define XFS_SICK_FS_GQUOTA (1 << 2)/* group quota */ #define XFS_SICK_FS_PQUOTA (1 << 3)/* project quota */ #define XFS_SICK_FS_QUOTACHECK (1 << 4)/* quota counts */ +#define XFS_SICK_FS_NLINKS (1 << 5)/* inode link counts */ /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0)/* realtime bitmap */
@@ -79,7 +80,8 @@ struct xfs_fsop_geom;XFS_SICK_FS_UQUOTA | \XFS_SICK_FS_GQUOTA | \XFS_SICK_FS_PQUOTA | \ - XFS_SICK_FS_QUOTACHECK) +XFS_SICK_FS_QUOTACHECK | \ + XFS_SICK_FS_NLINKS) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \XFS_SICK_RT_SUMMARY )
PATCH 15/111 xfs: teach scrub to check file nlinks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f1184081ac97625d30c59851944f4c59ae7ddc2b
Create the necessary scrub code to walk the filesystem's directory tree so that we can compute file link counts. Similar to quotacheck, we create an incore shadow array of link count information and then we walk the filesystem a second time to compare the link counts. We need live updates to keep the information up to date during the lengthy scan, so this scrubber remains disabled until the next patch.
--- libxfs/xfs_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +2 -1
@@ -712,9 +712,10 @@ struct xfs_scrub_metadata {#define XFS_SCRUB_TYPE_PQUOTA 23/* project quotas */ #define XFS_SCRUB_TYPE_FSCOUNTERS 24/* fs summary counters */ #define XFS_SCRUB_TYPE_QUOTACHECK 25/* quota counters */ +#define XFS_SCRUB_TYPE_NLINKS 26/* inode link counts */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 26 +#define XFS_SCRUB_TYPE_NR 27/* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0)
PATCH 16/111 xfs: separate the marking of sick and checked metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 0b8686f19879d896bbe2d3e893f433a08160452d
Split the setting of the sick and checked masks into separate functions as part of preparing to add the ability for regular runtime fs code (i.e. not scrub) to mark metadata structures sick when corruptions are found. Improve the documentation of libxfs' requirements for helper behavior.
--- libxfs/xfs_health.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
libxfs/xfs_health.h +22 -1
@@ -111,24 +111,45 @@ struct xfs_fsop_geom; XFS_SICK_INO_DIR_ZAPPED | \ XFS_SICK_INO_SYMLINK_ZAPPED) -/* These functions must be provided by the xfs implementation. */ +/* +* These functions must be provided by the xfs implementation. Function +* behavior with respect to the first argument should be as follows: +* +* xfs_*_mark_sick: Set the sick flags and do not set checked flags. +* Runtime code should call this upon encountering +* a corruption. +* +* xfs_*_mark_corrupt: Set the sick and checked flags simultaneously. +* Fsck tools should call this when corruption is +* found. +* +* xfs_*_mark_healthy: Clear the sick flags and set the checked flags. +* Fsck tools should call this after correcting errors. +* +* xfs_*_measure_sickness: Return the sick and check status in the provided +* out parameters. +*/ void xfs_fs_mark_sick (struct xfs_mount *mp,unsigned int mask); +void xfs_fs_mark_corrupt (struct xfs_mount *mp,unsigned int mask);void xfs_fs_mark_healthy (struct xfs_mount *mp,unsigned int mask);void xfs_fs_measure_sickness (struct xfs_mount *mp,unsigned int *sick,unsigned int *checked);void xfs_rt_mark_sick (struct xfs_mount *mp,unsigned int mask); +void xfs_rt_mark_corrupt (struct xfs_mount *mp,unsigned int mask);void xfs_rt_mark_healthy (struct xfs_mount *mp,unsigned int mask);void xfs_rt_measure_sickness (struct xfs_mount *mp,unsigned int *sick,unsigned int *checked);void xfs_ag_mark_sick (struct xfs_perag *pag,unsigned int mask); +void xfs_ag_mark_corrupt (struct xfs_perag *pag,unsigned int mask);void xfs_ag_mark_healthy (struct xfs_perag *pag,unsigned int mask);void xfs_ag_measure_sickness (struct xfs_perag *pag,unsigned int *sick,unsigned int *checked);void xfs_inode_mark_sick (struct xfs_inode *ip,unsigned int mask); +void xfs_inode_mark_corrupt (struct xfs_inode *ip,unsigned int mask);void xfs_inode_mark_healthy (struct xfs_inode *ip,unsigned int mask);void xfs_inode_measure_sickness (struct xfs_inode *ip,unsigned int *sick,unsigned int *checked);
PATCH 17/111 xfs: report fs corruption errors to the health tracking system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 50645ce8822d23ae3e002d3bee775fa8c315f957
Whenever we encounter corrupt fs metadata, we should report that to the health monitoring system for later reporting. A convenient program for identifying places to insert xfs_*_mark_sick calls is as follows:
#!/bin/bash
# Detect missing calls to xfs_*_mark_sick
filter=cat
tty -s && filter=less
git grep -B3 EFSCORRUPTED fs/xfs/*.[ch] fs/xfs/libxfs/*.[ch] fs/xfs/scrub/*.[ch] | awk ' BEGIN {
ignore = 0;
lineno = 0;
delete lines;
}
{
if ($0 == "--") {
if (!ignore) {
for (i = 0; i < lineno; i++) {print(lines[i]);
}printf("--\n");
}
delete lines;
lineno = 0;
ignore = 0;
} else if ($0 ~ /mark_sick/) {
ignore = 1;
} else if ($0 ~ /if .fa/) {
ignore = 1;
} else if ($0 ~ /failaddr/) {
ignore = 1;
} else if ($0 ~ /_verifier_error/) {
ignore = 1;
} else if ($0 ~ /^ \* .*EFSCORRUPTED/) {
ignore = 1;
} else if ($0 ~ /== -EFSCORRUPTED/) {
ignore = 1;
} else if ($0 ~ /!= -EFSCORRUPTED/) {
ignore = 1;
} else {
lines[lineno++] = $0;
}
}
' | $filter
--- libxfs/util.c | 1 + libxfs/xfs_ag.c | 1 + 2 files changed, 2 insertions(+)
libxfs/util.c +1 -0
@@ -728,3 +728,4 @@ xfs_fs_mark_healthy( }void xfs_ag_geom_health (struct xfs_perag *pag,struct xfs_ag_geometry *ageo) { } +void xfs_fs_mark_sick (struct xfs_mount *mp,unsigned int mask) { }
libxfs/xfs_ag.c +1 -0
@@ -215,6 +215,7 @@ xfs_initialize_perag_data(*/ if (fdblocks > sbp->sb_dblocks || ifree > ialloc) {xfs_alert (mp,"AGF corruption. Please run xfs_repair." ); +xfs_fs_mark_sick (mp,XFS_SICK_FS_COUNTERS ); error = -EFSCORRUPTED ; goto out; }
PATCH 18/111 xfs: report ag header corruption errors to the health tracking system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: de6077ec4198b9313c6e09e4c6acbe9179d057c1
Whenever we encounter a corrupt AG header, we should report that to the health monitoring system for later reporting. Buffer readers that don't respond to corruption events with a _mark_sick call can be detected with the following script:
#!/bin/bash
# Detect missing calls to xfs_*_mark_sick
filter=cat
tty -s && filter=less
git grep -A10 -E '( = xfs_trans_read_buf| = xfs_buf_read\()' fs/xfs/*.[ch] fs/xfs/libxfs/*.[ch] | awk ' BEGIN {
ignore = 0;
lineno = 0;
delete lines;
}
{
if ($0 == "--") {
if (!ignore) {
for (i = 0; i < lineno; i++) {print(lines[i]);
}printf("--\n");
}
delete lines;
lineno = 0;
ignore = 0;
} else if ($0 ~ /mark_sick/) {
ignore = 1;
} else {
lines[lineno++] = $0;
}
}
' | $filter
--- libxfs/util.c | 3 +++ libxfs/xfs_alloc.c | 6 ++++++ libxfs/xfs_health.h | 13 ++++++++++--- libxfs/xfs_ialloc.c | 3 +++ libxfs/xfs_sb.c | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-)
libxfs/util.c +3 -0
@@ -729,3 +729,6 @@ xfs_fs_mark_healthy(void xfs_ag_geom_health (struct xfs_perag *pag,struct xfs_ag_geometry *ageo) { }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) { }
libxfs/xfs_alloc.c +6 -0
@@ -22,6 +22,7 @@#include "xfs_ag.h" #include "xfs_ag_resv.h" #include "xfs_bmap.h" +#include "xfs_health.h" struct kmem_cache *xfs_extfree_item_cache;
@@ -751,6 +752,8 @@ xfs_alloc_read_agfl( mp, tp, mp->m_ddev_targp,XFS_AG_DADDR (mp, pag->pag_agno,XFS_AGFL_DADDR (mp)), XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_agfl_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGFL );if (error)return error;xfs_buf_set_ref (bp,XFS_AGFL_REF );
@@ -772,6 +775,7 @@ xfs_alloc_update_counters(if (unlikely (be32_to_cpu (agf->agf_freeblks) >be32_to_cpu (agf->agf_length))) {xfs_buf_mark_corrupt (agbp); +xfs_ag_mark_sick (agbp->b_pag,XFS_SICK_AG_AGF );return -EFSCORRUPTED ; }
@@ -3264,6 +3268,8 @@ xfs_read_agf( error =xfs_trans_read_buf (mp, tp, mp->m_ddev_targp,XFS_AG_DADDR (mp, pag->pag_agno,XFS_AGF_DADDR (mp)),XFS_FSS_TO_BB (mp,1 ), flags, agfbpp, &xfs_agf_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGF );if (error)return error;
libxfs/xfs_health.h +10 -3
@@ -26,9 +26,11 @@* and the "sick" field tells us if that piece was found to need repairs. * Therefore we can conclude that for a given sick flag value: * -* - checked && sick => metadata needs repair -* - checked && !sick => metadata is ok -* - !checked => has not been examined since mount +* - checked && sick => metadata needs repair +* - checked && !sick => metadata is ok +* - !checked && sick => errors have been observed during normal operation, +* but the metadata has not been checked thoroughly +* - !checked && !sick => has not been examined since mount */ struct xfs_mount ;
@@ -142,6 +144,8 @@ void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask);void xfs_rt_measure_sickness (struct xfs_mount *mp,unsigned int *sick,unsigned int *checked); +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_mark_corrupt (struct xfs_perag *pag,unsigned int mask);void xfs_ag_mark_healthy (struct xfs_perag *pag,unsigned int mask);
@@ -222,4 +226,7 @@ void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);void xfs_ag_geom_health (struct xfs_perag *pag,struct xfs_ag_geometry *ageo);void xfs_bulkstat_health (struct xfs_inode *ip,struct xfs_bulkstat *bs); +#define xfs_metadata_is_sick (error) \ + (unlikely((error) == -EFSCORRUPTED || (error) == -EFSBADCRC)) +#endif /* __XFS_HEALTH_H__ */
libxfs/xfs_ialloc.c +3 -0
@@ -22,6 +22,7 @@#include "xfs_trace.h" #include "xfs_rmap.h" #include "xfs_ag.h" +#include "xfs_health.h" /* * Lookup a record by ino in the btree given by cur.
@@ -2599,6 +2600,8 @@ 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); +if (xfs_metadata_is_sick (error)) +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI );if (error)return error;if (tp)
libxfs/xfs_sb.c +2 -0
@@ -1288,6 +1288,8 @@ xfs_sb_read_secondary( error =xfs_trans_read_buf (mp, tp, mp->m_ddev_targp,XFS_AG_DADDR (mp, agno,XFS_SB_BLOCK (mp)),XFS_FSS_TO_BB (mp,1 ),0 , &bp, &xfs_sb_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_agno_mark_sick (mp, agno,XFS_SICK_AG_SB );if (error)return error;xfs_buf_set_ref (bp,XFS_SSB_REF );
PATCH 19/111 xfs: report block map corruption errors to the health tracking system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 1196f3f5abf736809cafac1696967ac318a44ca0
Whenever we encounter a corrupt block mapping, we should report that to the health monitoring system for later reporting.
--- libxfs/util.c | 1 + libxfs/xfs_bmap.c | 35 +++++++++++++++++++++++++++++------ libxfs/xfs_health.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-)
libxfs/util.c +1 -0
@@ -732,3 +732,4 @@ 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_bmap_mark_sick (struct xfs_inode *ip,int whichfork) { }
libxfs/xfs_bmap.c +29 -6
@@ -30,6 +30,7 @@#include "xfs_ag_resv.h" #include "xfs_refcount.h" #include "xfs_rtbitmap.h" +#include "xfs_health.h" struct kmem_cache *xfs_bmap_intent_cache;
@@ -954,6 +955,7 @@ xfs_bmap_add_attrfork_local(/* should only be called for types that support local format data */ ASSERT (0 ); +xfs_bmap_mark_sick (ip,XFS_ATTR_FORK );return -EFSCORRUPTED ; }
@@ -1137,6 +1139,7 @@ xfs_iread_bmbt_block( (unsigned long long)ip->i_ino);xfs_inode_verifier_error (ip, -EFSCORRUPTED , __func__, block,sizeof (*block), __this_address); +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -1152,6 +1155,7 @@ xfs_iread_bmbt_block(xfs_inode_verifier_error (ip, -EFSCORRUPTED ,"xfs_iread_extents(2)" , frp,sizeof (*frp), fa); +xfs_bmap_mark_sick (ip, whichfork);return xfs_bmap_complain_bad_rec (ip, whichfork, fa, &new); }
@@ -1207,6 +1211,8 @@ xfs_iread_extents(smp_store_release (&ifp->if_needextents,0 );return 0 ; out: +if (xfs_metadata_is_sick (error)) +xfs_bmap_mark_sick (ip, whichfork);xfs_iext_destroy (ifp);return error; }
@@ -1286,6 +1292,7 @@ xfs_bmap_last_before(break ;default :ASSERT (0 ); +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -3894,12 +3901,16 @@ xfs_bmapi_read(ASSERT (!(flags & ~(XFS_BMAPI_ATTRFORK |XFS_BMAPI_ENTIRE )));xfs_assert_ilocked (ip,XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ); -if (WARN_ON_ONCE (!ifp)) +if (WARN_ON_ONCE (!ifp)) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; + }if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) || -XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) +XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; + }if (xfs_is_shutdown (mp))return -EIO ;
@@ -4380,6 +4391,7 @@ xfs_bmapi_write(if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -4607,9 +4619,11 @@ xfs_bmapi_convert_delalloc( error = -ENOSPC ;if (WARN_ON_ONCE (bma.blkno ==NULLFSBLOCK )) goto out_finish; - error = -EFSCORRUPTED ; -if (WARN_ON_ONCE (!xfs_valid_startblock (ip, bma.got.br_startblock))) +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);
@@ -4668,6 +4682,7 @@ xfs_bmapi_remap(if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -5280,8 +5295,10 @@ __xfs_bunmapi( whichfork =xfs_bmapi_whichfork (flags);ASSERT (whichfork !=XFS_COW_FORK ); ifp =xfs_ifork_ptr (ip, whichfork); -if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp))) +if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp))) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; + }if (xfs_is_shutdown (mp))return -EIO ;
@@ -5751,6 +5768,7 @@ xfs_bmap_collapse_extents(if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -5866,6 +5884,7 @@ xfs_bmap_insert_extents(if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -5969,6 +5988,7 @@ xfs_bmap_split_extent(if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) { +xfs_bmap_mark_sick (ip, whichfork);return -EFSCORRUPTED ; }
@@ -6151,8 +6171,10 @@ xfs_bmap_finish_one( bmap->br_startoff, bmap->br_blockcount, bmap->br_state); -if (WARN_ON_ONCE (bi->bi_whichfork !=XFS_DATA_FORK )) +if (WARN_ON_ONCE (bi->bi_whichfork !=XFS_DATA_FORK )) { +xfs_bmap_mark_sick (bi->bi_owner, bi->bi_whichfork);return -EFSCORRUPTED ; + }if (XFS_TEST_ERROR (false, tp->t_mountp,XFS_ERRTAG_BMAP_FINISH_ONE ))
@@ -6170,6 +6192,7 @@ xfs_bmap_finish_one(break ;default :ASSERT (0 ); +xfs_bmap_mark_sick (bi->bi_owner, bi->bi_whichfork); error = -EFSCORRUPTED ; }
libxfs/xfs_health.h +1 -0
@@ -159,6 +159,7 @@ void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick, unsigned int *checked);void xfs_health_unmount (struct xfs_mount *mp); +void xfs_bmap_mark_sick (struct xfs_inode *ip,int whichfork);/* Now some helpers. */
PATCH 20/111 xfs: report btree block corruption errors to the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a78d10f45b23149f1b23019a4f4fb57dcf852e39
Whenever we encounter corrupt btree blocks, we should report that to the health monitoring system for later reporting.
--- libxfs/util.c | 1 + libxfs/xfs_alloc.c | 2 ++ libxfs/xfs_bmap.c | 6 ++++++ libxfs/xfs_btree.c | 25 ++++++++++++++++++++++--- libxfs/xfs_health.h | 2 ++ libxfs/xfs_ialloc.c | 1 + libxfs/xfs_refcount.c | 6 +++++- libxfs/xfs_rmap.c | 6 +++++- 8 files changed, 44 insertions(+), 5 deletions(-)
libxfs/util.c +1 -0
@@ -733,3 +733,4 @@ 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_bmap_mark_sick (struct xfs_inode *ip,int whichfork) { } +void xfs_btree_mark_sick (struct xfs_btree_cur *cur) { }
libxfs/xfs_alloc.c +2 -0
@@ -271,6 +271,7 @@ xfs_alloc_complain_bad_rec(xfs_warn (mp,"start block 0x%x block count 0x%x" , irec->ar_startblock, irec->ar_blockcount); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
@@ -2698,6 +2699,7 @@ xfs_exact_minlen_extent_available( goto out;if (*stat ==0 ) { +xfs_btree_mark_sick (cnt_cur); error = -EFSCORRUPTED ; goto out; }
libxfs/xfs_bmap.c +6 -0
@@ -362,6 +362,8 @@ xfs_bmap_check_leaf_extents( error =xfs_btree_read_bufl (mp,NULL , bno, &bp,XFS_BMAP_BTREE_REF , &xfs_bmbt_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_btree_mark_sick (cur);if (error) goto error_norelse; }
@@ -448,6 +450,8 @@ xfs_bmap_check_leaf_extents( error =xfs_btree_read_bufl (mp,NULL , bno, &bp,XFS_BMAP_BTREE_REF , &xfs_bmbt_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_btree_mark_sick (cur);if (error) goto error_norelse; }
@@ -562,6 +566,8 @@ xfs_bmap_btree_to_extents(#endif error =xfs_btree_read_bufl (mp, tp, cbno, &cbp,XFS_BMAP_BTREE_REF , &xfs_bmbt_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_btree_mark_sick (cur);if (error)return error; cblock =XFS_BUF_TO_BLOCK (cbp);
libxfs/xfs_btree.c +22 -3
@@ -24,6 +24,7 @@#include "xfs_bmap_btree.h" #include "xfs_rmap_btree.h" #include "xfs_refcount_btree.h" +#include "xfs_health.h" /* * Btree magic numbers.
@@ -174,6 +175,7 @@ xfs_btree_check_lblock( XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_LBLOCK)) {if (bp)trace_xfs_btree_corrupt (bp, _RET_IP_); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }return 0 ;
@@ -240,6 +242,7 @@ xfs_btree_check_sblock( XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_SBLOCK)) {if (bp)trace_xfs_btree_corrupt (bp, _RET_IP_); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }return 0 ;
@@ -315,6 +318,7 @@ xfs_btree_check_ptr( level, index); } +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
@@ -495,6 +499,8 @@ xfs_btree_dup_cursor(xfs_buf_daddr (bp), mp->m_bsize,0 , &bp, cur->bc_ops->buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_btree_mark_sick (new);if (error) {xfs_btree_del_cursor (new, error); *ncur =NULL ;
@@ -1348,6 +1354,8 @@ xfs_btree_read_buf_block( error =xfs_trans_read_buf (mp, cur->bc_tp, mp->m_ddev_targp, d, mp->m_bsize, flags, bpp, cur->bc_ops->buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_btree_mark_sick (cur);if (error)return error;
@@ -1658,6 +1666,7 @@ xfs_btree_increment(if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) goto out0;ASSERT (0 ); +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -1751,6 +1760,7 @@ xfs_btree_decrement(if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) goto out0;ASSERT (0 ); +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -1843,6 +1853,7 @@ xfs_btree_lookup_get_block( *blkp =NULL ;xfs_buf_mark_corrupt (bp);xfs_trans_brelse (cur->bc_tp, bp); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
@@ -1889,8 +1900,10 @@ xfs_btree_lookup(XFS_BTREE_STATS_INC (cur, lookup);/* No such thing as a zero-level tree. */ -if (XFS_IS_CORRUPT (cur->bc_mp, cur->bc_nlevels ==0 )) +if (XFS_IS_CORRUPT (cur->bc_mp, cur->bc_nlevels ==0 )) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } block =NULL ; keyno =0 ;
@@ -1933,6 +1946,7 @@ xfs_btree_lookup(XFS_ERRLEVEL_LOW , cur->bc_mp, block, sizeof(*block)); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
@@ -4366,12 +4380,16 @@ xfs_btree_visit_block(*/ if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) {if (be64_to_cpu (rptr.l) ==XFS_DADDR_TO_FSB (cur->bc_mp, -xfs_buf_daddr (bp))) +xfs_buf_daddr (bp))) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } }else {if (be32_to_cpu (rptr.s) ==xfs_daddr_to_agbno (cur->bc_mp, -xfs_buf_daddr (bp))) +xfs_buf_daddr (bp))) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } }return xfs_btree_lookup_get_block (cur, level, &rptr, &block); }
@@ -5230,6 +5248,7 @@ xfs_btree_goto_left_edge(return error;if (stat !=0 ) {ASSERT (0 ); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
libxfs/xfs_health.h +2 -0
@@ -37,6 +37,7 @@ struct xfs_mount;struct xfs_perag ;struct xfs_inode ;struct xfs_fsop_geom ; +struct xfs_btree_cur ;/* Observable health issues for metadata spanning the entire filesystem. */ #define XFS_SICK_FS_COUNTERS (1 << 0)/* summary counters */
@@ -160,6 +161,7 @@ void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,void xfs_health_unmount (struct xfs_mount *mp);void xfs_bmap_mark_sick (struct xfs_inode *ip,int whichfork); +void xfs_btree_mark_sick (struct xfs_btree_cur *cur);/* Now some helpers. */
libxfs/xfs_ialloc.c +1 -0
@@ -143,6 +143,7 @@ xfs_inobt_complain_bad_rec("start inode 0x%x, count 0x%x, free 0x%x freemask 0x%llx, holemask 0x%x" , irec->ir_startino, irec->ir_count, irec->ir_freecount, irec->ir_free, irec->ir_holemask); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
libxfs/xfs_refcount.c +5 -1
@@ -22,6 +22,7 @@#include "xfs_refcount.h" #include "xfs_rmap.h" #include "xfs_ag.h" +#include "xfs_health.h" struct kmem_cache *xfs_refcount_intent_cache;
@@ -155,6 +156,7 @@ xfs_refcount_complain_bad_rec(xfs_warn (mp,"Start block 0x%x, block count 0x%x, references 0x%x" , irec->rc_startblock, irec->rc_blockcount, irec->rc_refcount); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
@@ -1888,8 +1890,10 @@ xfs_refcount_recover_extent(struct xfs_refcount_recovery *rr;if (XFS_IS_CORRUPT (cur->bc_mp, -be32_to_cpu (rec->refc.rc_refcount) !=1 )) +be32_to_cpu (rec->refc.rc_refcount) !=1 )) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } rr =kmalloc (sizeof (struct xfs_refcount_recovery ),GFP_KERNEL | __GFP_NOFAIL);
libxfs/xfs_rmap.c +5 -1
@@ -22,6 +22,7 @@#include "xfs_errortag.h" #include "xfs_inode.h" #include "xfs_ag.h" +#include "xfs_health.h" struct kmem_cache *xfs_rmap_intent_cache;
@@ -55,8 +56,10 @@ xfs_rmap_lookup_le( error =xfs_rmap_get_rec (cur, irec, &get_stat);if (error)return error; -if (!get_stat) +if (!get_stat) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + }return 0 ; }
@@ -276,6 +279,7 @@ xfs_rmap_complain_bad_rec("Owner 0x%llx, flags 0x%x, start block 0x%x block count 0x%x" , irec->rm_owner, irec->rm_flags, irec->rm_startblock, irec->rm_blockcount); +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
PATCH 21/111 xfs: report dir/attr block corruption errors to the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ca14c0968c1f693ab4bcb5368c800c33e7a2ad7e
Whenever we encounter corrupt directory or extended attribute blocks, we should report that to the health monitoring system for later reporting.
--- libxfs/util.c | 2 ++ libxfs/xfs_attr_leaf.c | 4 ++++ libxfs/xfs_attr_remote.c | 27 ++++++++++++++++----------- libxfs/xfs_da_btree.c | 37 ++++++++++++++++++++++++++++++++----- libxfs/xfs_dir2.c | 5 ++++- libxfs/xfs_dir2_block.c | 2 ++ libxfs/xfs_dir2_data.c | 3 +++ libxfs/xfs_dir2_leaf.c | 3 +++ libxfs/xfs_dir2_node.c | 7 +++++++ libxfs/xfs_health.h | 3 +++ 10 files changed, 76 insertions(+), 17 deletions(-)
libxfs/util.c +2 -0
@@ -734,3 +734,5 @@ void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno,void xfs_ag_mark_sick (struct xfs_perag *pag,unsigned int mask) { }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) { } +void xfs_da_mark_sick (struct xfs_da_args *args) { }
libxfs/xfs_attr_leaf.c +4 -0
@@ -26,6 +26,7 @@#include "xfs_dir2.h" #include "xfs_ag.h" #include "xfs_errortag.h" +#include "xfs_health.h" /*
@@ -2340,6 +2341,7 @@ xfs_attr3_leaf_lookup_int( entries =xfs_attr3_leaf_entryp (leaf);if (ichdr.count >= args->geo->blksize /8 ) {xfs_buf_mark_corrupt (bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -2359,10 +2361,12 @@ xfs_attr3_leaf_lookup_int( }if (!(probe >=0 && (!ichdr.count || probe < ichdr.count))) {xfs_buf_mark_corrupt (bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }if (!(span <=4 ||be32_to_cpu (entry->hashval) == hashval)) {xfs_buf_mark_corrupt (bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
libxfs/xfs_attr_remote.c +16 -11
@@ -21,6 +21,7 @@#include "xfs_attr.h" #include "xfs_attr_remote.h" #include "xfs_trace.h" +#include "xfs_health.h" #define ATTR_RMTVALUE_MAPSIZE 1/* # of map entries at once */
@@ -275,17 +276,18 @@ xfs_attr3_rmt_hdr_set(*/ STATIC intxfs_attr_rmtval_copyout ( -struct xfs_mount *mp, -struct xfs_buf *bp, -xfs_ino_t ino, -int *offset, -int *valuelen, -uint8_t **dst) +struct xfs_mount *mp, +struct xfs_buf *bp, +struct xfs_inode *dp, +int *offset, +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; +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;ASSERT (len >= blksize);
@@ -301,6 +303,7 @@ xfs_attr_rmtval_copyout(xfs_alert (mp,"remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)" , bno, *offset, byte_cnt, ino); +xfs_dirattr_mark_sick (dp,XFS_ATTR_FORK );return -EFSCORRUPTED ; } hdr_size =sizeof (struct xfs_attr3_rmt_hdr );
@@ -417,10 +420,12 @@ xfs_attr_rmtval_get( dblkcnt =XFS_FSB_TO_BB (mp, map[i].br_blockcount); error =xfs_buf_read (mp->m_ddev_targp, dblkno, dblkcnt,0 , &bp, &xfs_attr3_rmt_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_dirattr_mark_sick (args->dp,XFS_ATTR_FORK );if (error)return error; - error =xfs_attr_rmtval_copyout (mp, bp, args->dp->i_ino, + error =xfs_attr_rmtval_copyout (mp, bp, args->dp, &offset, &valuelen, &dst);xfs_buf_relse (bp);
libxfs/xfs_da_btree.c +32 -5
@@ -19,6 +19,7 @@#include "xfs_bmap.h" #include "xfs_attr_leaf.h" #include "xfs_trace.h" +#include "xfs_health.h" /* * xfs_da_btree.c
@@ -349,6 +350,8 @@ const struct xfs_buf_ops xfs_da3_node_buf_ops = {static int xfs_da3_node_set_type (struct xfs_trans *tp, +struct xfs_inode *dp, +int whichfork,struct xfs_buf *bp) {struct xfs_da_blkinfo *info = bp->b_addr;
@@ -370,6 +373,7 @@ xfs_da3_node_set_type(XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , tp->t_mountp, info,sizeof (*info));xfs_trans_brelse (tp, bp); +xfs_dirattr_mark_sick (dp, whichfork);return -EFSCORRUPTED ; } }
@@ -388,7 +392,7 @@ xfs_da3_node_read( &xfs_da3_node_buf_ops);if (error || !*bpp || !tp)return error; -return xfs_da3_node_set_type (tp, *bpp); +return xfs_da3_node_set_type (tp, dp, whichfork, *bpp); }int
@@ -405,6 +409,8 @@ xfs_da3_node_read_mapped( error =xfs_trans_read_buf (mp, tp, mp->m_ddev_targp, mappedbno,XFS_FSB_TO_BB (mp,xfs_dabuf_nfsb (mp, whichfork)),0 , bpp, &xfs_da3_node_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_dirattr_mark_sick (dp, whichfork);if (error || !*bpp)return error;
@@ -415,7 +421,7 @@ xfs_da3_node_read_mapped(if (!tp)return 0 ; -return xfs_da3_node_set_type (tp, *bpp); +return xfs_da3_node_set_type (tp, dp, whichfork, *bpp); }/*
@@ -628,6 +634,7 @@ xfs_da3_split(if (node->hdr.info.forw) {if (be32_to_cpu (node->hdr.info.forw) != addblk->blkno) {xfs_buf_mark_corrupt (oldblk->bp); +xfs_da_mark_sick (state->args); error = -EFSCORRUPTED ; goto out; }
@@ -641,6 +648,7 @@ xfs_da3_split(if (node->hdr.info.back) {if (be32_to_cpu (node->hdr.info.back) != addblk->blkno) {xfs_buf_mark_corrupt (oldblk->bp); +xfs_da_mark_sick (state->args); error = -EFSCORRUPTED ; goto out; }
@@ -1632,6 +1640,7 @@ xfs_da3_node_lookup_int(if (magic !=XFS_DA_NODE_MAGIC && magic !=XFS_DA3_NODE_MAGIC ) {xfs_buf_mark_corrupt (blk->bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -1647,6 +1656,7 @@ xfs_da3_node_lookup_int(/* Tree taller than we can handle; bail out! */ if (nodehdr.level >=XFS_DA_NODE_MAXDEPTH ) {xfs_buf_mark_corrupt (blk->bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -1655,6 +1665,7 @@ xfs_da3_node_lookup_int( expected_level = nodehdr.level -1 ; else if (expected_level != nodehdr.level) {xfs_buf_mark_corrupt (blk->bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; } else expected_level--;
@@ -1706,12 +1717,16 @@ xfs_da3_node_lookup_int( }/* We can't point back to the root. */ -if (XFS_IS_CORRUPT (dp->i_mount, blkno == args->geo->leafblk)) +if (XFS_IS_CORRUPT (dp->i_mount, blkno == args->geo->leafblk)) { +xfs_da_mark_sick (args);return -EFSCORRUPTED ; + } } -if (XFS_IS_CORRUPT (dp->i_mount, expected_level !=0 )) +if (XFS_IS_CORRUPT (dp->i_mount, expected_level !=0 )) { +xfs_da_mark_sick (args);return -EFSCORRUPTED ; + }/* * A leaf block that ends in the hashval that we are interested in
@@ -1729,6 +1744,7 @@ xfs_da3_node_lookup_int( args->blkno = blk->blkno; }else {ASSERT (0 ); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; } if (((retval == -ENOENT) || (retval == -ENOATTR)) &&
@@ -2295,8 +2311,10 @@ xfs_da3_swap_lastblock( error =xfs_bmap_last_before (tp, dp, &lastoff, w);if (error)return error; -if (XFS_IS_CORRUPT (mp, lastoff ==0 )) +if (XFS_IS_CORRUPT (mp, lastoff ==0 )) { +xfs_da_mark_sick (args);return -EFSCORRUPTED ; + }/* * Read the last block in the btree space. */
@@ -2346,6 +2364,7 @@ xfs_da3_swap_lastblock(if (XFS_IS_CORRUPT (mp,be32_to_cpu (sib_info->forw) != last_blkno || sib_info->magic != dead_info->magic)) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2366,6 +2385,7 @@ xfs_da3_swap_lastblock(if (XFS_IS_CORRUPT (mp,be32_to_cpu (sib_info->back) != last_blkno || sib_info->magic != dead_info->magic)) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2388,6 +2408,7 @@ xfs_da3_swap_lastblock(xfs_da3_node_hdr_from_disk (dp->i_mount, &par_hdr, par_node);if (XFS_IS_CORRUPT (mp, level >=0 && level != par_hdr.level +1 )) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2399,6 +2420,7 @@ xfs_da3_swap_lastblock( entno++)continue ;if (XFS_IS_CORRUPT (mp, entno == par_hdr.count)) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2424,6 +2446,7 @@ xfs_da3_swap_lastblock(xfs_trans_brelse (tp, par_buf); par_buf =NULL ;if (XFS_IS_CORRUPT (mp, par_blkno ==0 )) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2433,6 +2456,7 @@ xfs_da3_swap_lastblock( 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)) { +xfs_da_mark_sick (args); error = -EFSCORRUPTED ; goto done; }
@@ -2563,6 +2587,7 @@ xfs_dabuf_map( invalid_mapping:/* Caller ok with no mapping. */ if (XFS_IS_CORRUPT (mp, !(flags &XFS_DABUF_MAP_HOLE_OK ))) { +xfs_dirattr_mark_sick (dp, whichfork); error = -EFSCORRUPTED ;if (xfs_error_level >=XFS_ERRLEVEL_LOW ) { xfs_alert(mp, "%s: bno %u inode %llu",
@@ -2644,6 +2669,8 @@ xfs_da_read_buf( error =xfs_trans_read_buf_map (mp, tp, mp->m_ddev_targp, mapp, nmap,0 , &bp, ops); +if (xfs_metadata_is_sick (error)) +xfs_dirattr_mark_sick (dp, whichfork);if (error) goto out_free;
libxfs/xfs_dir2.c +4 -1
@@ -17,6 +17,7 @@#include "xfs_dir2_priv.h" #include "xfs_errortag.h" #include "xfs_trace.h" +#include "xfs_health.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -625,8 +626,10 @@ xfs_dir2_isblock(return 0 ; *isblock = true; -if (XFS_IS_CORRUPT (mp, args->dp->i_disk_size != args->geo->blksize)) +if (XFS_IS_CORRUPT (mp, args->dp->i_disk_size != args->geo->blksize)) { +xfs_da_mark_sick (args);return -EFSCORRUPTED ; + }return 0 ; }
libxfs/xfs_dir2_block.c +2 -0
@@ -17,6 +17,7 @@#include "xfs_dir2.h" #include "xfs_dir2_priv.h" #include "xfs_trace.h" +#include "xfs_health.h" /* * Local function prototypes.
@@ -149,6 +150,7 @@ xfs_dir3_block_read(__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp); *bpp =NULL ; +xfs_dirattr_mark_sick (dp,XFS_DATA_FORK );return -EFSCORRUPTED ; }
libxfs/xfs_dir2_data.c +3 -0
@@ -15,6 +15,7 @@#include "xfs_dir2.h" #include "xfs_dir2_priv.h" #include "xfs_trans.h" +#include "xfs_health.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
@@ -430,6 +431,7 @@ xfs_dir3_data_read(__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp); *bpp =NULL ; +xfs_dirattr_mark_sick (dp,XFS_DATA_FORK );return -EFSCORRUPTED ; }
@@ -1195,6 +1197,7 @@ xfs_dir2_data_use_free( corrupt:xfs_corruption_error (__func__,XFS_ERRLEVEL_LOW , args->dp->i_mount, hdr,sizeof (*hdr), __FILE__, __LINE__, fa); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
libxfs/xfs_dir2_leaf.c +3 -0
@@ -17,6 +17,7 @@#include "xfs_dir2_priv.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_health.h" /* * Local function declarations.
@@ -1391,8 +1392,10 @@ xfs_dir2_leaf_removename( bestsp =xfs_dir2_leaf_bests_p (ltp);if (be16_to_cpu (bestsp[db]) != oldbest) {xfs_buf_mark_corrupt (lbp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; } +/* * Mark the former data entry unused. */
libxfs/xfs_dir2_node.c +7 -0
@@ -17,6 +17,7 @@#include "xfs_dir2_priv.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_health.h" /* * Function declarations.
@@ -228,6 +229,7 @@ __xfs_dir3_free_read(__xfs_buf_mark_corrupt (*bpp, fa);xfs_trans_brelse (tp, *bpp); *bpp =NULL ; +xfs_dirattr_mark_sick (dp,XFS_DATA_FORK );return -EFSCORRUPTED ; }
@@ -440,6 +442,7 @@ xfs_dir2_leaf_to_node(if (be32_to_cpu (ltp->bestcount) > (uint )dp->i_disk_size / args->geo->blksize) {xfs_buf_mark_corrupt (lbp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -514,6 +517,7 @@ xfs_dir2_leafn_add(*/ if (index <0 ) {xfs_buf_mark_corrupt (bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -733,6 +737,7 @@ xfs_dir2_leafn_lookup_for_addname( cpu_to_be16(NULLDATAOFF))) {if (curfdb != newfdb)xfs_trans_brelse (tp, curbp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; } curfdb = newfdb;
@@ -801,6 +806,7 @@ xfs_dir2_leafn_lookup_for_entry(xfs_dir3_leaf_check (dp, bp);if (leafhdr.count <=0 ) {xfs_buf_mark_corrupt (bp); +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
@@ -1736,6 +1742,7 @@ xfs_dir2_node_add_datablk( }else {xfs_alert (mp," ... fblk is NULL" ); } +xfs_da_mark_sick (args);return -EFSCORRUPTED ; }
libxfs/xfs_health.h +3 -0
@@ -38,6 +38,7 @@ struct xfs_perag;struct xfs_inode ;struct xfs_fsop_geom ;struct xfs_btree_cur ; +struct xfs_da_args ;/* Observable health issues for metadata spanning the entire filesystem. */ #define XFS_SICK_FS_COUNTERS (1 << 0)/* summary counters */
@@ -162,6 +163,8 @@ void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,void xfs_health_unmount (struct xfs_mount *mp);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); +void xfs_da_mark_sick (struct xfs_da_args *args);/* Now some helpers. */
PATCH 22/111 xfs: report inode corruption errors to the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: baf44fa5c37a2357a7ae92889f74bc1824f33fd4
Whenever we encounter corrupt inode records, we should report that to the health monitoring system for later reporting.
--- libxfs/util.c | 1 + libxfs/xfs_ialloc.c | 1 + libxfs/xfs_inode_buf.c | 12 +++++++++--- libxfs/xfs_inode_fork.c | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-)
libxfs/util.c +1 -0
@@ -736,3 +736,4 @@ 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) { }void xfs_da_mark_sick (struct xfs_da_args *args) { } +void xfs_inode_mark_sick (struct xfs_inode *ip,unsigned int mask) { }
libxfs/xfs_ialloc.c +1 -0
@@ -2994,6 +2994,7 @@ xfs_ialloc_check_shrink( goto out;if (!has) { +xfs_ag_mark_sick (pag,XFS_SICK_AG_INOBT ); error = -EFSCORRUPTED ; goto out; }
libxfs/xfs_inode_buf.c +9 -3
@@ -16,6 +16,7 @@#include "xfs_trans.h" #include "xfs_ialloc.h" #include "xfs_dir2.h" +#include "xfs_health.h" /*
@@ -129,9 +130,14 @@ xfs_imap_to_bp(struct xfs_imap *imap, struct xfs_buf **bpp) { - return xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno, - imap->im_len, XBF_UNMAPPED, bpp, - &xfs_inode_buf_ops); + int error; + + error =xfs_trans_read_buf (mp, tp, mp->m_ddev_targp, imap->im_blkno, + imap->im_len,XBF_UNMAPPED , bpp, &xfs_inode_buf_ops); +if (xfs_metadata_is_sick (error)) +xfs_agno_mark_sick (mp,xfs_daddr_to_agno (mp, imap->im_blkno), +XFS_SICK_AG_INOBT ); +return error; }static inline struct timespec64 xfs_inode_decode_bigtime (uint64_t ts)
libxfs/xfs_inode_fork.c +8 -0
@@ -23,6 +23,7 @@#include "xfs_attr_leaf.h" #include "xfs_types.h" #include "xfs_errortag.h" +#include "xfs_health.h" struct kmem_cache *xfs_ifork_cache;
@@ -86,6 +87,7 @@ xfs_iformat_local(xfs_inode_verifier_error (ip, -EFSCORRUPTED ,"xfs_iformat_local" , dip,sizeof (*dip), __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return -EFSCORRUPTED ; }
@@ -123,6 +125,7 @@ xfs_iformat_extents(xfs_inode_verifier_error (ip, -EFSCORRUPTED ,"xfs_iformat_extents(1)" , dip,sizeof (*dip), __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return -EFSCORRUPTED ; }
@@ -142,6 +145,7 @@ xfs_iformat_extents(xfs_inode_verifier_error (ip, -EFSCORRUPTED ,"xfs_iformat_extents(2)" , dp,sizeof (*dp), fa); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return xfs_bmap_complain_bad_rec (ip, whichfork, fa, &new); }
@@ -200,6 +204,7 @@ xfs_iformat_btree(xfs_inode_verifier_error (ip, -EFSCORRUPTED ,"xfs_iformat_btree" , dfp, size, __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return -EFSCORRUPTED ; }
@@ -265,12 +270,14 @@ xfs_iformat_data_fork(default :xfs_inode_verifier_error (ip, -EFSCORRUPTED , __func__, dip,sizeof (*dip), __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return -EFSCORRUPTED ; }break ;default :xfs_inode_verifier_error (ip, -EFSCORRUPTED , __func__, dip,sizeof (*dip), __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE );return -EFSCORRUPTED ; } }
@@ -342,6 +349,7 @@ xfs_iformat_attr_fork(default :xfs_inode_verifier_error (ip, error, __func__, dip,sizeof (*dip), __this_address); +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE ); error = -EFSCORRUPTED ;break ; }
PATCH 23/111 xfs: report realtime metadata corruption errors to the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 8368ad49aaf771a6283840140149440b958b20fb
Whenever we encounter corrupt realtime metadat blocks, we should report that to the health monitoring system for later reporting.
--- libxfs/util.c | 1 + libxfs/xfs_rtbitmap.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
libxfs/util.c +1 -0
@@ -737,3 +737,4 @@ void xfs_btree_mark_sick(struct xfs_btree_cur *cur) { }void xfs_dirattr_mark_sick (struct xfs_inode *ip,int whichfork) { }void xfs_da_mark_sick (struct xfs_da_args *args) { }void xfs_inode_mark_sick (struct xfs_inode *ip,unsigned int mask) { } +void xfs_rt_mark_sick (struct xfs_mount *mp,unsigned int mask) { }
libxfs/xfs_rtbitmap.c +8 -1
@@ -15,6 +15,7 @@#include "xfs_bmap.h" #include "xfs_trans.h" #include "xfs_rtbitmap.h" +#include "xfs_health.h" /* * Realtime allocator bitmap functions shared with userspace.
@@ -113,13 +114,19 @@ xfs_rtbuf_get(if (error)return error; -if (XFS_IS_CORRUPT (mp, nmap ==0 || !xfs_bmap_is_written_extent (&map))) +if (XFS_IS_CORRUPT (mp, nmap ==0 || !xfs_bmap_is_written_extent (&map))) { +xfs_rt_mark_sick (mp, issum ?XFS_SICK_RT_SUMMARY : +XFS_SICK_RT_BITMAP );return -EFSCORRUPTED ; + }ASSERT (map.br_startblock !=NULLFSBLOCK ); error =xfs_trans_read_buf (mp, args->tp, mp->m_ddev_targp,XFS_FSB_TO_DADDR (mp, map.br_startblock), mp->m_bsize,0 , &bp, &xfs_rtbuf_ops); +if (xfs_metadata_is_sick (error)) +xfs_rt_mark_sick (mp, issum ?XFS_SICK_RT_SUMMARY : +XFS_SICK_RT_BITMAP );if (error)return error;
PATCH 24/111 xfs: report XFS_IS_CORRUPT errors to the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 989d5ec3175be7c0012d7744c667ae6a266fab06
Whenever we encounter XFS_IS_CORRUPT failures, we should report that to the health monitoring system for later reporting.
I started with this semantic patch and massaged everything until it built:
@@
expression mp, test;
@@
- if (XFS_IS_CORRUPT(mp, test)) return -EFSCORRUPTED;
+ if (XFS_IS_CORRUPT(mp, test)) { xfs_btree_mark_sick(cur); return -EFSCORRUPTED; }
@@
expression mp, test;
identifier label, error;
@@
- if (XFS_IS_CORRUPT(mp, test)) { error = -EFSCORRUPTED; goto label; }
+ if (XFS_IS_CORRUPT(mp, test)) { xfs_btree_mark_sick(cur); error = -EFSCORRUPTED; goto label; }
--- libxfs/xfs_ag.c | 4 +- libxfs/xfs_alloc.c | 97 ++++++++++++++++++++++++++++++++++++++-------- libxfs/xfs_attr_remote.c | 8 +++- libxfs/xfs_bmap.c | 94 ++++++++++++++++++++++++++++++++++++++++----- libxfs/xfs_btree.c | 14 ++++++- libxfs/xfs_ialloc.c | 52 ++++++++++++++++++++----- libxfs/xfs_refcount.c | 37 +++++++++++++++++- libxfs/xfs_rmap.c | 77 +++++++++++++++++++++++++++++++++++-- 8 files changed, 339 insertions(+), 44 deletions(-)
libxfs/xfs_ag.c +3 -1
@@ -949,8 +949,10 @@ xfs_ag_shrink_space( agf = agfbp->b_addr; aglen =be32_to_cpu (agi->agi_length);/* some extra paranoid checks before we shrink the ag */ -if (XFS_IS_CORRUPT (mp, agf->agf_length != agi->agi_length)) +if (XFS_IS_CORRUPT (mp, agf->agf_length != agi->agi_length)) { +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGF );return -EFSCORRUPTED ; + }if (delta >= aglen)return -EINVAL ;
libxfs/xfs_alloc.c +81 -16
374 lines not on this page · raw message
libxfs/xfs_attr_remote.c +6 -2
@@ -552,8 +552,10 @@ xfs_attr_rmtval_stale(xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );if (XFS_IS_CORRUPT (mp, map->br_startblock ==DELAYSTARTBLOCK ) || -XFS_IS_CORRUPT (mp, map->br_startblock ==HOLESTARTBLOCK )) +XFS_IS_CORRUPT (mp, map->br_startblock ==HOLESTARTBLOCK )) { +xfs_bmap_mark_sick (ip,XFS_ATTR_FORK );return -EFSCORRUPTED ; + } error = xfs_buf_incore(mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, map->br_startblock),
@@ -663,8 +665,10 @@ xfs_attr_rmtval_invalidate( blkcnt, &map, &nmap, XFS_BMAPI_ATTRFORK);if (error)return error; -if (XFS_IS_CORRUPT (args->dp->i_mount, nmap !=1 )) +if (XFS_IS_CORRUPT (args->dp->i_mount, nmap !=1 )) { +xfs_bmap_mark_sick (args->dp,XFS_ATTR_FORK );return -EFSCORRUPTED ; + } error =xfs_attr_rmtval_stale (args->dp, &map,XBF_TRYLOCK );if (error)return error;
libxfs/xfs_bmap.c +84 -10
484 lines not on this page · raw message
libxfs/xfs_btree.c +13 -1
@@ -2023,8 +2023,10 @@ xfs_btree_lookup( error =xfs_btree_increment (cur,0 , &i);if (error) goto error0; -if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) +if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } *stat =1 ;return 0 ; }
@@ -2477,6 +2479,7 @@ xfs_btree_lshift( goto error0; i =xfs_btree_firstrec (tcur, level);if (XFS_IS_CORRUPT (tcur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -2647,6 +2650,7 @@ xfs_btree_rshift( goto error0; i =xfs_btree_lastrec (tcur, level);if (XFS_IS_CORRUPT (tcur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -3535,6 +3539,7 @@ xfs_btree_insert( }if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -3942,6 +3947,7 @@ xfs_btree_delrec(*/ i =xfs_btree_lastrec (tcur, level);if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -3950,12 +3956,14 @@ xfs_btree_delrec(if (error) goto error0;if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; } i =xfs_btree_lastrec (tcur, level);if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -4003,6 +4011,7 @@ xfs_btree_delrec(if (!xfs_btree_ptr_is_null (cur, &lptr)) { i =xfs_btree_firstrec (tcur, level);if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -4011,6 +4020,7 @@ xfs_btree_delrec(if (error) goto error0;if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -4028,6 +4038,7 @@ xfs_btree_delrec(*/ i =xfs_btree_firstrec (tcur, level);if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
@@ -4037,6 +4048,7 @@ xfs_btree_delrec( goto error0; i =xfs_btree_firstrec (tcur, level);if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto error0; }
libxfs/xfs_ialloc.c +43 -9
205 lines not on this page · raw message
libxfs/xfs_refcount.c +36 -1
@@ -239,6 +239,7 @@ xfs_refcount_insert(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, *i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -269,12 +270,14 @@ xfs_refcount_delete(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }trace_xfs_refcount_delete (cur->bc_mp, cur->bc_ag.pag->pag_agno, &irec); error =xfs_btree_delete (cur, i);if (XFS_IS_CORRUPT (cur->bc_mp, *i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -399,6 +402,7 @@ xfs_refcount_split_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -426,6 +430,7 @@ xfs_refcount_split_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -471,6 +476,7 @@ xfs_refcount_merge_center_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -479,6 +485,7 @@ xfs_refcount_merge_center_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -488,6 +495,7 @@ xfs_refcount_merge_center_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -499,6 +507,7 @@ xfs_refcount_merge_center_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -543,6 +552,7 @@ xfs_refcount_merge_left_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -551,6 +561,7 @@ xfs_refcount_merge_left_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -562,6 +573,7 @@ xfs_refcount_merge_left_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -609,6 +621,7 @@ xfs_refcount_merge_right_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -617,6 +630,7 @@ xfs_refcount_merge_right_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -628,6 +642,7 @@ xfs_refcount_merge_right_extent(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -675,6 +690,7 @@ xfs_refcount_find_left_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -694,6 +710,7 @@ xfs_refcount_find_left_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -768,6 +785,7 @@ xfs_refcount_find_right_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -787,6 +805,7 @@ xfs_refcount_find_right_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1143,6 +1162,7 @@ xfs_refcount_adjust_extents( goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_tmp !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1181,6 +1201,7 @@ xfs_refcount_adjust_extents(*/ if (XFS_IS_CORRUPT (cur->bc_mp, ext.rc_blockcount ==0 ) ||XFS_IS_CORRUPT (cur->bc_mp, ext.rc_blockcount > *aglen)) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1204,6 +1225,7 @@ xfs_refcount_adjust_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1328,8 +1350,10 @@ xfs_refcount_continue_op(struct xfs_perag *pag = cur->bc_ag.pag;if (XFS_IS_CORRUPT (mp, !xfs_verify_agbext (pag, new_agbno, - ri->ri_blockcount))) + ri->ri_blockcount))) { +xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; + } ri->ri_startblock =XFS_AGB_TO_FSB (mp, pag->pag_agno, new_agbno);
@@ -1536,6 +1560,7 @@ xfs_refcount_find_shared(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1553,6 +1578,7 @@ xfs_refcount_find_shared(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1586,6 +1612,7 @@ xfs_refcount_find_shared(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, i !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1683,6 +1710,7 @@ xfs_refcount_adjust_cow_extents( goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec && ext.rc_domain !=XFS_REFC_DOMAIN_COW )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1698,6 +1726,7 @@ xfs_refcount_adjust_cow_extents(/* Adding a CoW reservation, there should be nothing here. */ if (XFS_IS_CORRUPT (cur->bc_mp, agbno + aglen > ext.rc_startblock)) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1715,6 +1744,7 @@ xfs_refcount_adjust_cow_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_tmp !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1722,14 +1752,17 @@ xfs_refcount_adjust_cow_extents(case XFS_REFCOUNT_ADJUST_COW_FREE :/* Removing a CoW reservation, there should be one extent. */ if (XFS_IS_CORRUPT (cur->bc_mp, ext.rc_startblock != agbno)) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }if (XFS_IS_CORRUPT (cur->bc_mp, ext.rc_blockcount != aglen)) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }if (XFS_IS_CORRUPT (cur->bc_mp, ext.rc_refcount !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1741,6 +1774,7 @@ xfs_refcount_adjust_cow_extents(if (error) goto out_error;if (XFS_IS_CORRUPT (cur->bc_mp, found_rec !=1 )) { +xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ; goto out_error; }
@@ -1903,6 +1937,7 @@ xfs_refcount_recover_extent(if (xfs_refcount_check_irec (cur->bc_ag.pag, &rr->rr_rrec) !=NULL ||XFS_IS_CORRUPT (cur->bc_mp, rr->rr_rrec.rc_domain !=XFS_REFC_DOMAIN_COW )) { +xfs_btree_mark_sick (cur);kfree (rr);return -EFSCORRUPTED ; }
libxfs/xfs_rmap.c +73 -4
476 lines not on this page · raw message
PATCH 25/111 xfs: add secondary and indirect classes to the health tracking system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 4e587917ee1cc28ac3a04cd55937419b9e65d81d
Establish two more classes of health tracking bits:
* Indirect problems, which suggest problems in other health domains that we weren't able to preserve.
* Secondary problems, which track state that's related to primary evidence of health problems; and
The first class we'll use in an upcoming patch to record in the AG health status the fact that we ran out of memory and had to inactivate an inode with defective metadata. The second class we use to indicate that repair knows that an inode is bad and we need to fix it later.
--- libxfs/xfs_health.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
libxfs/xfs_health.h +43 -0
@@ -31,6 +31,19 @@* - !checked && sick => errors have been observed during normal operation, * but the metadata has not been checked thoroughly * - !checked && !sick => has not been examined since mount +* +* Evidence of health problems can be sorted into three basic categories: +* +* a) Primary evidence, which signals that something is defective within the +* general grouping of metadata. +* +* b) Secondary evidence, which are side effects of primary problem but are +* not themselves problems. These can be forgotten when the primary +* health problems are addressed. +* +* c) Indirect evidence, which points to something being wrong in another +* group, but we had to release resources and this is all that's left of +* that state. */ struct xfs_mount ;
@@ -115,6 +128,36 @@ struct xfs_da_args; XFS_SICK_INO_DIR_ZAPPED | \ XFS_SICK_INO_SYMLINK_ZAPPED) +/* Secondary state related to (but not primary evidence of) health problems. */ +#define XFS_SICK_FS_SECONDARY (0) +#define XFS_SICK_RT_SECONDARY (0) +#define XFS_SICK_AG_SECONDARY (0) +#define XFS_SICK_INO_SECONDARY (0) + +/* Evidence of health problems elsewhere. */ +#define XFS_SICK_FS_INDIRECT (0) +#define XFS_SICK_RT_INDIRECT (0) +#define XFS_SICK_AG_INDIRECT (0) +#define XFS_SICK_INO_INDIRECT (0) + +/* All health masks. */ +#define XFS_SICK_FS_ALL (XFS_SICK_FS_PRIMARY | \ + XFS_SICK_FS_SECONDARY | \ + XFS_SICK_FS_INDIRECT) + +#define XFS_SICK_RT_ALL (XFS_SICK_RT_PRIMARY | \ + XFS_SICK_RT_SECONDARY | \ + XFS_SICK_RT_INDIRECT) + +#define XFS_SICK_AG_ALL (XFS_SICK_AG_PRIMARY | \ + XFS_SICK_AG_SECONDARY | \ + XFS_SICK_AG_INDIRECT) + +#define XFS_SICK_INO_ALL (XFS_SICK_INO_PRIMARY | \ + XFS_SICK_INO_SECONDARY | \ + XFS_SICK_INO_INDIRECT | \ + XFS_SICK_INO_ZAPPED) +/* * These functions must be provided by the xfs implementation. Function * behavior with respect to the first argument should be as follows:
PATCH 26/111 xfs: remember sick inodes that get inactivated
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 0e24ec3c56fbc797b34fc94073320c336336b4f9
If an unhealthy inode gets inactivated, remember this fact in the per-fs health summary.
--- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 8 ++++++-- libxfs/xfs_inode_buf.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)
libxfs/xfs_fs.h +1 -0
@@ -294,6 +294,7 @@ struct xfs_ag_geometry {#define XFS_AG_GEOM_SICK_FINOBT (1 << 7)/* free inode index */ #define XFS_AG_GEOM_SICK_RMAPBT (1 << 8)/* reverse mappings */ #define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9)/* reference counts */ +#define XFS_AG_GEOM_SICK_INODES (1 << 10)/* bad inodes were seen */ /* * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT
libxfs/xfs_health.h +6 -2
@@ -76,6 +76,7 @@ struct xfs_da_args;#define XFS_SICK_AG_FINOBT (1 << 7)/* free inode index */ #define XFS_SICK_AG_RMAPBT (1 << 8)/* reverse mappings */ #define XFS_SICK_AG_REFCNTBT (1 << 9)/* reference counts */ +#define XFS_SICK_AG_INODES (1 << 10)/* inactivated bad inodes */ /* Observable health issues for inode metadata. */ #define XFS_SICK_INO_CORE (1 << 0)/* inode core */
@@ -92,6 +93,9 @@ struct xfs_da_args;#define XFS_SICK_INO_DIR_ZAPPED (1 << 10)/* directory erased */ #define XFS_SICK_INO_SYMLINK_ZAPPED (1 << 11)/* symlink erased */ +/* Don't propagate sick status to ag health summary during inactivation */ +#define XFS_SICK_INO_FORGET (1 << 12) +/* Primary evidence of health problems in a given group. */ #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \ XFS_SICK_FS_UQUOTA | \
@@ -132,12 +136,12 @@ struct xfs_da_args;#define XFS_SICK_FS_SECONDARY (0)#define XFS_SICK_RT_SECONDARY (0)#define XFS_SICK_AG_SECONDARY (0) -#define XFS_SICK_INO_SECONDARY (0) +#define XFS_SICK_INO_SECONDARY (XFS_SICK_INO_FORGET)/* Evidence of health problems elsewhere. */ #define XFS_SICK_FS_INDIRECT (0)#define XFS_SICK_RT_INDIRECT (0) -#define XFS_SICK_AG_INDIRECT (0) +#define XFS_SICK_AG_INDIRECT (XFS_SICK_AG_INODES)#define XFS_SICK_INO_INDIRECT (0)/* All health masks. */
libxfs/xfs_inode_buf.c +1 -1
@@ -136,7 +136,7 @@ xfs_imap_to_bp( imap->im_len, XBF_UNMAPPED, bpp, &xfs_inode_buf_ops);if (xfs_metadata_is_sick (error))xfs_agno_mark_sick (mp,xfs_daddr_to_agno (mp, imap->im_blkno), -XFS_SICK_AG_INOBT ); +XFS_SICK_AG_INODES );return error; }
PATCH 27/111 xfs: update health status if we get a clean bill of health
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a1f3e0cca41036c3c66abb6a2ed8fedc214e9a4c
If scrub finds that everything is ok with the filesystem, we need a way to tell the health tracking that it can let go of indirect health flags, since indirect flags only mean that at some point in the past we lost some context.
--- libxfs/xfs_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_fs.h +2 -1
@@ -714,9 +714,10 @@ struct xfs_scrub_metadata {#define XFS_SCRUB_TYPE_FSCOUNTERS 24/* fs summary counters */ #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 */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 27 +#define XFS_SCRUB_TYPE_NR 28/* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0)
PATCH 28/111 xfs: consolidate btree block freeing tracepoints
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 78067b92b9096a70ca731a6cde1c286582ff03d7
Don't waste memory on extra per-btree block freeing tracepoints when we can do it from the generic btree code.
With this patch applied, two tracepoints are collapsed into one tracepoint, with the following effects on objdump -hx xfs.ko output:
Before:
10 __tracepoints_ptrs 00000b3c 0000000000000000 0000000000000000 00140eb0 2**2 14 __tracepoints_strings 00005453 0000000000000000 0000000000000000 00168540 2**5 29 __tracepoints 00010d90 0000000000000000 0000000000000000 0023f5e0 2**5
After:
10 __tracepoints_ptrs 00000b38 0000000000000000 0000000000000000 001412f0 2**2 14 __tracepoints_strings 00005433 0000000000000000 0000000000000000 001689a0 2**5 29 __tracepoints 00010d30 0000000000000000 0000000000000000 0023fe00 2**5
Column 3 is the section size in bytes; removing these two tracepoints reduces the size of the ELF segments by 132 bytes.
--- include/xfs_trace.h | 3 +-- libxfs/xfs_btree.c | 2 ++ libxfs/xfs_refcount_btree.c | 2 -- libxfs/xfs_rmap_btree.c | 2 -- 4 files changed, 3 insertions(+), 6 deletions(-)
include/xfs_trace.h +1 -2
@@ -68,6 +68,7 @@#define trace_xfs_btree_commit_ifakeroot (a) ((void) 0)#define trace_xfs_btree_bload_level_geometry (a,b,c,d,e,f,g) ((void) 0)#define trace_xfs_btree_bload_block (a,b,c,d,e,f) ((void) 0) +#define trace_xfs_btree_free_block (...) ((void) 0)#define trace_xfs_free_extent (a,b,c,d,e,f,g) ((void) 0)#define trace_xfs_agf (a,b,c,d) ((void) 0)
@@ -256,7 +257,6 @@#define trace_xfs_rmap_find_left_neighbor_result (...) ((void) 0)#define trace_xfs_rmap_lookup_le_range_result (...) ((void) 0) -#define trace_xfs_rmapbt_free_block (...) ((void) 0)#define trace_xfs_rmapbt_alloc_block (...) ((void) 0)#define trace_xfs_ag_resv_critical (...) ((void) 0)
@@ -276,7 +276,6 @@#define trace_xfs_refcount_insert_error (...) ((void) 0)#define trace_xfs_refcount_delete (...) ((void) 0)#define trace_xfs_refcount_delete_error (...) ((void) 0) -#define trace_xfs_refcountbt_free_block (...) ((void) 0)#define trace_xfs_refcountbt_alloc_block (...) ((void) 0)#define trace_xfs_refcount_rec_order_error (...) ((void) 0)
libxfs/xfs_btree.c +2 -0
@@ -411,6 +411,8 @@ xfs_btree_free_block( {int error; +trace_xfs_btree_free_block (cur, bp); + error = cur->bc_ops->free_block (cur, bp);if (!error) {xfs_trans_binval (cur->bc_tp, bp);
libxfs/xfs_refcount_btree.c +0 -2
@@ -106,8 +106,6 @@ xfs_refcountbt_free_block(struct xfs_agf *agf = agbp->b_addr;xfs_fsblock_t fsbno =XFS_DADDR_TO_FSB (mp,xfs_buf_daddr (bp)); -trace_xfs_refcountbt_free_block (cur->bc_mp, cur->bc_ag.pag->pag_agno, -XFS_FSB_TO_AGBNO (cur->bc_mp, fsbno),1 );be32_add_cpu (&agf->agf_refcount_blocks,-1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_REFCOUNT_BLOCKS ); return xfs_free_extent_later(cur->bc_tp, fsbno, 1,
libxfs/xfs_rmap_btree.c +0 -2
@@ -123,8 +123,6 @@ xfs_rmapbt_free_block(int error; bno =xfs_daddr_to_agbno (cur->bc_mp,xfs_buf_daddr (bp)); -trace_xfs_rmapbt_free_block (cur->bc_mp, pag->pag_agno, - bno,1 );be32_add_cpu (&agf->agf_rmap_blocks,-1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_RMAP_BLOCKS ); error =xfs_alloc_put_freelist (pag, cur->bc_tp, agbp,NULL , bno,1 );
PATCH 29/111 xfs: consolidate btree block allocation tracepoints
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 2ed0b2c7f33159825af1a1a83face66edb52348a
Don't waste tracepoint segment memory on per-btree block allocation tracepoints when we can do it from the generic btree code.
With this patch applied, two tracepoints are collapsed into one tracepoint, with the following effects on objdump -hx xfs.ko output:
Before:
10 __tracepoints_ptrs 00000b38 0000000000000000 0000000000000000 001412f0 2**2 14 __tracepoints_strings 00005433 0000000000000000 0000000000000000 001689a0 2**5 29 __tracepoints 00010d30 0000000000000000 0000000000000000 0023fe00 2**5
After:
10 __tracepoints_ptrs 00000b34 0000000000000000 0000000000000000 001417b0 2**2 14 __tracepoints_strings 00005413 0000000000000000 0000000000000000 00168e80 2**5 29 __tracepoints 00010cd0 0000000000000000 0000000000000000 00240760 2**5
Column 3 is the section size in bytes; removing these two tracepoints reduces the size of the ELF segments by 132 bytes.
--- include/xfs_trace.h | 4 +--- libxfs/xfs_btree.c | 20 +++++++++++++++++--- libxfs/xfs_refcount_btree.c | 2 -- libxfs/xfs_rmap_btree.c | 2 -- 4 files changed, 18 insertions(+), 10 deletions(-)
include/xfs_trace.h +1 -3
@@ -69,6 +69,7 @@#define trace_xfs_btree_bload_level_geometry (a,b,c,d,e,f,g) ((void) 0)#define trace_xfs_btree_bload_block (a,b,c,d,e,f) ((void) 0)#define trace_xfs_btree_free_block (...) ((void) 0) +#define trace_xfs_btree_alloc_block (...) ((void) 0)#define trace_xfs_free_extent (a,b,c,d,e,f,g) ((void) 0)#define trace_xfs_agf (a,b,c,d) ((void) 0)
@@ -257,8 +258,6 @@#define trace_xfs_rmap_find_left_neighbor_result (...) ((void) 0)#define trace_xfs_rmap_lookup_le_range_result (...) ((void) 0) -#define trace_xfs_rmapbt_alloc_block (...) ((void) 0) -#define trace_xfs_ag_resv_critical (...) ((void) 0)#define trace_xfs_ag_resv_needed (...) ((void) 0)#define trace_xfs_ag_resv_free (...) ((void) 0)
@@ -276,7 +275,6 @@#define trace_xfs_refcount_insert_error (...) ((void) 0)#define trace_xfs_refcount_delete (...) ((void) 0)#define trace_xfs_refcount_delete_error (...) ((void) 0) -#define trace_xfs_refcountbt_alloc_block (...) ((void) 0)#define trace_xfs_refcount_rec_order_error (...) ((void) 0)#define trace_xfs_refcount_lookup (...) ((void) 0)
libxfs/xfs_btree.c +17 -3
@@ -2690,6 +2690,20 @@ xfs_btree_rshift(return error; } +static inline int +xfs_btree_alloc_block ( +struct xfs_btree_cur *cur, +const union xfs_btree_ptr *hint_block, +union xfs_btree_ptr *new_block, +int *stat) +{ +int error; + + error = cur->bc_ops->alloc_block (cur, hint_block, new_block, stat); +trace_xfs_btree_alloc_block (cur, new_block, *stat, error); +return error; +} +/* * Split cur/level block in half. * Return new block number and the key to its first
@@ -2733,7 +2747,7 @@ __xfs_btree_split(xfs_btree_buf_to_ptr (cur, lbp, &lptr);/* Allocate the new block. If we can't do it, we're toast. Give up. */ - error = cur->bc_ops->alloc_block (cur, &lptr, &rptr, stat); + error =xfs_btree_alloc_block (cur, &lptr, &rptr, stat);if (error) goto error0;if (*stat ==0 )
@@ -3013,7 +3027,7 @@ xfs_btree_new_iroot( pp =xfs_btree_ptr_addr (cur,1 , block);/* Allocate the new block. If we can't do it, we're toast. Give up. */ - error = cur->bc_ops->alloc_block (cur, pp, &nptr, stat); + error =xfs_btree_alloc_block (cur, pp, &nptr, stat);if (error) goto error0;if (*stat ==0 )
@@ -3113,7 +3127,7 @@ xfs_btree_new_root( cur->bc_ops->init_ptr_from_cur (cur, &rptr);/* Allocate the new block. If we can't do it, we're toast. Give up. */ - error = cur->bc_ops->alloc_block (cur, &rptr, &lptr, stat); + error =xfs_btree_alloc_block (cur, &rptr, &lptr, stat);if (error) goto error0;if (*stat ==0 )
libxfs/xfs_refcount_btree.c +0 -2
@@ -76,8 +76,6 @@ xfs_refcountbt_alloc_block( xfs_refc_block(args.mp)));if (error) goto out_error; -trace_xfs_refcountbt_alloc_block (cur->bc_mp, cur->bc_ag.pag->pag_agno, - args.agbno,1 );if (args.fsbno ==NULLFSBLOCK ) { *stat =0 ;return 0 ;
libxfs/xfs_rmap_btree.c +0 -2
@@ -92,8 +92,6 @@ xfs_rmapbt_alloc_block( &bno, 1);if (error)return error; - -trace_xfs_rmapbt_alloc_block (cur->bc_mp, pag->pag_agno, bno,1 );if (bno ==NULLAGBLOCK ) { *stat =0 ;return 0 ;
PATCH 30/111 xfs: set the btree cursor bc_ops in xfs_btree_alloc_cursor
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 056d22c87132cf4968f5e702116439bea9795930
This is a precursor to putting more static data in the btree ops structure.
--- libxfs/xfs_alloc_btree.c | 11 +++++------ libxfs/xfs_bmap_btree.c | 3 +-- libxfs/xfs_btree.h | 2 ++ libxfs/xfs_ialloc_btree.c | 10 ++++++---- libxfs/xfs_refcount_btree.c | 4 ++-- libxfs/xfs_rmap_btree.c | 3 +-- 6 files changed, 17 insertions(+), 16 deletions(-)
libxfs/xfs_alloc_btree.c +5 -6
@@ -510,18 +510,17 @@ xfs_allocbt_init_common(ASSERT (btnum ==XFS_BTNUM_BNO || btnum ==XFS_BTNUM_CNT ); - cur =xfs_btree_alloc_cursor (mp, tp, btnum, mp->m_alloc_maxlevels, - xfs_allocbt_cur_cache); - cur->bc_ag.abt.active = false; -if (btnum ==XFS_BTNUM_CNT ) { - cur->bc_ops = &xfs_cntbt_ops; + cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_cntbt_ops, + mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtc_2); cur->bc_flags =XFS_BTREE_LASTREC_UPDATE ; }else { - cur->bc_ops = &xfs_bnobt_ops; + cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_bnobt_ops, + mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtb_2); } + cur->bc_ag.abt.active = false; cur->bc_ag.pag =xfs_perag_hold (pag);
libxfs/xfs_bmap_btree.c +1 -2
@@ -548,11 +548,10 @@ xfs_bmbt_init_common(ASSERT (whichfork !=XFS_COW_FORK ); - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BMAP , + cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BMAP , &xfs_bmbt_ops, mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_bmbt_2); - cur->bc_ops = &xfs_bmbt_ops; cur->bc_flags =XFS_BTREE_LONG_PTRS |XFS_BTREE_ROOT_IN_INODE ;if (xfs_has_crc (mp)) cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ;
libxfs/xfs_btree.h +2 -0
@@ -720,6 +720,7 @@ xfs_btree_alloc_cursor(struct xfs_mount *mp, struct xfs_trans *tp, xfs_btnum_t btnum, + const struct xfs_btree_ops *ops, uint8_t maxlevels, struct kmem_cache *cache) {
@@ -728,6 +729,7 @@ xfs_btree_alloc_cursor(/* BMBT allocations can come through from non-transactional context. */ cur =kmem_cache_zalloc (cache,GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); + cur->bc_ops = ops; cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum;
libxfs/xfs_ialloc_btree.c +6 -4
@@ -453,14 +453,16 @@ xfs_inobt_init_common(struct xfs_mount *mp = pag->pag_mount;struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp, btnum, -M_IGEO (mp)->inobt_maxlevels, xfs_inobt_cur_cache);if (btnum ==XFS_BTNUM_INO ) { + cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_inobt_ops, +M_IGEO (mp)->inobt_maxlevels, + xfs_inobt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_ibt_2); - cur->bc_ops = &xfs_inobt_ops; }else { + cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_finobt_ops, +M_IGEO (mp)->inobt_maxlevels, + xfs_inobt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_fibt_2); - cur->bc_ops = &xfs_finobt_ops; }if (xfs_has_crc (mp))
libxfs/xfs_refcount_btree.c +2 -2
@@ -352,7 +352,8 @@ xfs_refcountbt_init_common(ASSERT (pag->pag_agno < mp->m_sb.sb_agcount); cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_REFC , - mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); + &xfs_refcountbt_ops, mp->m_refc_maxlevels, + xfs_refcountbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_refcbt_2); cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ;
@@ -360,7 +361,6 @@ xfs_refcountbt_init_common( cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ; - cur->bc_ops = &xfs_refcountbt_ops;return cur; }
libxfs/xfs_rmap_btree.c +1 -2
@@ -501,11 +501,10 @@ xfs_rmapbt_init_common(struct xfs_btree_cur *cur;/* Overlapping btree; 2 keys per pointer. */ - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , + cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); cur->bc_flags =XFS_BTREE_CRC_BLOCKS |XFS_BTREE_OVERLAPPING ; cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); - cur->bc_ops = &xfs_rmapbt_ops; cur->bc_ag.pag =xfs_perag_hold (pag);return cur;
PATCH 31/111 xfs: drop XFS_BTREE_CRC_BLOCKS
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f9e325bf61d1fb3ef5f705268a22de95809db9fa
All existing btree types set XFS_BTREE_CRC_BLOCKS when running against a V5 filesystem. All currently proposed btree types are V5 only and use the richer XFS_BTREE_CRC_BLOCKS format. Therefore, we can drop this flag and change the conditional to xfs_has_crc.
--- libxfs/xfs_alloc_btree.c | 3 --- libxfs/xfs_bmap_btree.c | 2 -- libxfs/xfs_btree.c | 8 ++++---- libxfs/xfs_btree.h | 1 - libxfs/xfs_ialloc_btree.c | 3 --- libxfs/xfs_refcount_btree.c | 2 -- libxfs/xfs_rmap_btree.c | 2 +- 7 files changed, 5 insertions(+), 16 deletions(-)
libxfs/xfs_alloc_btree.c +0 -3
@@ -524,9 +524,6 @@ xfs_allocbt_init_common( cur->bc_ag.pag =xfs_perag_hold (pag); -if (xfs_has_crc (mp)) - cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; -return cur; }
libxfs/xfs_bmap_btree.c +0 -2
@@ -553,8 +553,6 @@ xfs_bmbt_init_common( cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_bmbt_2); cur->bc_flags =XFS_BTREE_LONG_PTRS |XFS_BTREE_ROOT_IN_INODE ; -if (xfs_has_crc (mp)) - cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; cur->bc_ino.ip = ip; cur->bc_ino.allocated =0 ;
libxfs/xfs_btree.c +4 -4
@@ -595,11 +595,11 @@ xfs_btree_dup_cursor(static inline size_t xfs_btree_block_len (struct xfs_btree_cur *cur) {if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) { -if (cur->bc_flags &XFS_BTREE_CRC_BLOCKS ) +if (xfs_has_crc (cur->bc_mp))return XFS_BTREE_LBLOCK_CRC_LEN ;return XFS_BTREE_LBLOCK_LEN ; } -if (cur->bc_flags &XFS_BTREE_CRC_BLOCKS ) +if (xfs_has_crc (cur->bc_mp))return XFS_BTREE_SBLOCK_CRC_LEN ;return XFS_BTREE_SBLOCK_LEN ; }
@@ -1573,7 +1573,7 @@ xfs_btree_log_block(if (bp) {int nbits; -if (cur->bc_flags &XFS_BTREE_CRC_BLOCKS ) { +if (xfs_has_crc (cur->bc_mp)) {/* * We don't log the CRC when updating a btree * block but instead recreate it during log
@@ -3045,7 +3045,7 @@ xfs_btree_new_iroot(* In that case have to also ensure the blkno remains correct */ memcpy (cblock, block,xfs_btree_block_len (cur)); -if (cur->bc_flags &XFS_BTREE_CRC_BLOCKS ) { +if (xfs_has_crc (cur->bc_mp)) {__be64 bno =cpu_to_be64 (xfs_buf_daddr (cbp));if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) cblock->bb_u.l.bb_blkno = bno;
libxfs/xfs_btree.h +0 -1
@@ -308,7 +308,6 @@ xfs_btree_cur_sizeof(unsigned int nlevels)#define XFS_BTREE_LONG_PTRS (1<<0)/* pointers are 64bits long */ #define XFS_BTREE_ROOT_IN_INODE (1<<1)/* root may be variable size */ #define XFS_BTREE_LASTREC_UPDATE (1<<2)/* track last rec externally */ -#define XFS_BTREE_CRC_BLOCKS (1<<3)/* uses extended btree blocks */ #define XFS_BTREE_OVERLAPPING (1<<4)/* overlapping intervals */ /* * The root of this btree is a fakeroot structure so that we can stage a btree
libxfs/xfs_ialloc_btree.c +0 -3
@@ -465,9 +465,6 @@ xfs_inobt_init_common( cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_fibt_2); } -if (xfs_has_crc (mp)) - cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; - cur->bc_ag.pag =xfs_perag_hold (pag);return cur; }
libxfs/xfs_refcount_btree.c +0 -2
@@ -356,8 +356,6 @@ xfs_refcountbt_init_common( xfs_refcountbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_refcbt_2); - cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; - cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ;
libxfs/xfs_rmap_btree.c +1 -1
@@ -503,7 +503,7 @@ xfs_rmapbt_init_common(/* Overlapping btree; 2 keys per pointer. */ cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); - cur->bc_flags =XFS_BTREE_CRC_BLOCKS |XFS_BTREE_OVERLAPPING ; + cur->bc_flags =XFS_BTREE_OVERLAPPING ; cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); cur->bc_ag.pag =xfs_perag_hold (pag);
PATCH 32/111 xfs: encode the btree geometry flags in the btree ops structure
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: fd9c7f7722d815527269b80d9990aecffa06957c
Certain btree flags never change for the life of a btree cursor because they describe the geometry of the btree itself. Encode these in the btree ops structure and reduce the amount of code required in each btree type's init_cursor functions. This also frees up most of the bits in bc_flags.
A previous version of this patch also converted the open-coded flags logic to helpers. This was removed due to the pending refactoring (that follows this patch) to eliminate most of the state flags.
Conversion script:
sed \
-e 's/XFS_BTREE_LONG_PTRS/XFS_BTGEO_LONG_PTRS/g' \
-e 's/XFS_BTREE_ROOT_IN_INODE/XFS_BTGEO_ROOT_IN_INODE/g' \
-e 's/XFS_BTREE_LASTREC_UPDATE/XFS_BTGEO_LASTREC_UPDATE/g' \
-e 's/XFS_BTREE_OVERLAPPING/XFS_BTGEO_OVERLAPPING/g' \
-e 's/cur->bc_flags & XFS_BTGEO_/cur->bc_ops->geom_flags \& XFS_BTGEO_/g' \
-i $(git ls-files fs/xfs/*.[ch] fs/xfs/libxfs/*.[ch] fs/xfs/scrub/*.[ch])
--- libxfs/xfs_alloc_btree.c | 4 +- libxfs/xfs_bmap.c | 4 +- libxfs/xfs_bmap_btree.c | 6 +- libxfs/xfs_btree.c | 110 ++++++++++++++++++++++---------------------- libxfs/xfs_btree.h | 23 ++++++--- libxfs/xfs_btree_staging.c | 14 +++--- libxfs/xfs_btree_staging.h | 2 - libxfs/xfs_rmap_btree.c | 3 + repair/bulkload.c | 2 - 9 files changed, 87 insertions(+), 81 deletions(-)
libxfs/xfs_alloc_btree.c +2 -2
@@ -476,6 +476,8 @@ static const struct xfs_btree_ops xfs_bnobt_ops = { };static const struct xfs_btree_ops xfs_cntbt_ops = { + .geom_flags =XFS_BTGEO_LASTREC_UPDATE , + .rec_len =sizeof (xfs_alloc_rec_t), .key_len =sizeof (xfs_alloc_key_t),
@@ -514,7 +516,6 @@ xfs_allocbt_init_common( cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_cntbt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtc_2); - cur->bc_flags =XFS_BTREE_LASTREC_UPDATE ; }else { cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_bnobt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache);
@@ -589,7 +590,6 @@ xfs_allocbt_commit_staged_btree(if (cur->bc_btnum ==XFS_BTNUM_BNO ) {xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_bnobt_ops); }else { - cur->bc_flags |=XFS_BTREE_LASTREC_UPDATE ;xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_cntbt_ops); } }
libxfs/xfs_bmap.c +2 -2
@@ -640,7 +640,7 @@ xfs_bmap_extents_to_btree( block = ifp->if_broot;xfs_btree_init_block_int (mp, block,XFS_BUF_DADDR_NULL ,XFS_BTNUM_BMAP ,1 ,1 , ip->i_ino, -XFS_BTREE_LONG_PTRS ); +XFS_BTGEO_LONG_PTRS );/* * Need a cursor. Can't allocate until bb_level is filled in. */
@@ -687,7 +687,7 @@ xfs_bmap_extents_to_btree( ablock =XFS_BUF_TO_BLOCK (abp);xfs_btree_init_block_int (mp, ablock,xfs_buf_daddr (abp),XFS_BTNUM_BMAP ,0 ,0 , ip->i_ino, -XFS_BTREE_LONG_PTRS ); +XFS_BTGEO_LONG_PTRS );for_each_xfs_iext (ifp, &icur, &rec) {if (isnullstartblock (rec.br_startblock))
libxfs/xfs_bmap_btree.c +3 -3
@@ -45,7 +45,7 @@ xfs_bmdr_to_bmbt(xfs_btree_init_block_int (mp, rblock,XFS_BUF_DADDR_NULL ,XFS_BTNUM_BMAP ,0 ,0 , ip->i_ino, -XFS_BTREE_LONG_PTRS ); +XFS_BTGEO_LONG_PTRS ); rblock->bb_level = dblock->bb_level;ASSERT (be16_to_cpu (rblock->bb_level) >0 ); rblock->bb_numrecs = dblock->bb_numrecs;
@@ -515,6 +515,8 @@ xfs_bmbt_keys_contiguous( }static const struct xfs_btree_ops xfs_bmbt_ops = { + .geom_flags =XFS_BTGEO_LONG_PTRS |XFS_BTGEO_ROOT_IN_INODE , + .rec_len =sizeof (xfs_bmbt_rec_t), .key_len =sizeof (xfs_bmbt_key_t),
@@ -552,8 +554,6 @@ xfs_bmbt_init_common( mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_bmbt_2); - cur->bc_flags =XFS_BTREE_LONG_PTRS |XFS_BTREE_ROOT_IN_INODE ; - cur->bc_ino.ip = ip; cur->bc_ino.allocated =0 ; cur->bc_ino.flags =0 ;
libxfs/xfs_btree.c +55 -55
435 lines not on this page · raw message
libxfs/xfs_btree.h +14 -9
@@ -112,6 +112,9 @@ static inline enum xbtree_key_contig xbtree_key_contig(uint64_t x, uint64_t y) }struct xfs_btree_ops { +/* XFS_BTGEO_* flags that determine the geometry of the btree */ +unsigned int geom_flags; +/* size of the key and record structures */ size_t key_len;size_t rec_len;
@@ -199,6 +202,12 @@ struct xfs_btree_ops { const union xfs_btree_key *mask); }; +/* btree geometry flags */ +#define XFS_BTGEO_LONG_PTRS (1U << 0)/* pointers are 64bits long */ +#define XFS_BTGEO_ROOT_IN_INODE (1U << 1)/* root may be variable size */ +#define XFS_BTGEO_LASTREC_UPDATE (1U << 2)/* track last rec externally */ +#define XFS_BTGEO_OVERLAPPING (1U << 3)/* overlapping intervals */ +/* * Reasons for the update_lastrec method to be called. */
@@ -281,7 +290,7 @@ struct xfs_btree_cur/* * Short btree pointers need an agno to be able to turn the pointers * into physical addresses for IO, so the btree cursor switches between -* bc_ino and bc_ag based on whether XFS_BTREE_LONG_PTRS is set for the +* bc_ino and bc_ag based on whether XFS_BTGEO_LONG_PTRS is set for the * cursor. */ union {
@@ -304,17 +313,13 @@ xfs_btree_cur_sizeof(unsigned int nlevels) return struct_size_t(struct xfs_btree_cur, bc_levels, nlevels); } -/* cursor flags */ -#define XFS_BTREE_LONG_PTRS (1<<0)/* pointers are 64bits long */ -#define XFS_BTREE_ROOT_IN_INODE (1<<1)/* root may be variable size */ -#define XFS_BTREE_LASTREC_UPDATE (1<<2)/* track last rec externally */ -#define XFS_BTREE_OVERLAPPING (1<<4)/* overlapping intervals */ +/* cursor state flags */ /* * The root of this btree is a fakeroot structure so that we can stage a btree * rebuild without leaving it accessible via primary metadata. The ops struct * is dynamically allocated and must be freed when the cursor is deleted. */ -#define XFS_BTREE_STAGING (1<<5) +#define XFS_BTREE_STAGING (1U << 0)#define XFS_BTREE_NOERROR 0#define XFS_BTREE_ERROR 1
@@ -447,7 +452,7 @@ xfs_btree_init_block_int(__u16 level, __u16 numrecs, __u64 owner, - unsigned int flags); + unsigned int geom_flags);/* * Common btree core entry points.
@@ -689,7 +694,7 @@ xfs_btree_islastblock( block =xfs_btree_get_block (cur, level, &bp); -if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) +if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS )return block->bb_u.l.bb_rightsib ==cpu_to_be64 (NULLFSBLOCK );return block->bb_u.s.bb_rightsib ==cpu_to_be32 (NULLAGBLOCK ); }
libxfs/xfs_btree_staging.c +7 -7
@@ -136,7 +136,7 @@ xfs_btree_stage_afakeroot(struct xfs_btree_ops *nops;ASSERT (!(cur->bc_flags &XFS_BTREE_STAGING )); -ASSERT (!(cur->bc_flags &XFS_BTREE_ROOT_IN_INODE )); +ASSERT (!(cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ));ASSERT (cur->bc_tp ==NULL ); nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);
@@ -217,7 +217,7 @@ xfs_btree_stage_ifakeroot(struct xfs_btree_ops *nops;ASSERT (!(cur->bc_flags &XFS_BTREE_STAGING )); -ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ); +ASSERT (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE );ASSERT (cur->bc_tp ==NULL ); nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);
@@ -397,7 +397,7 @@ xfs_btree_bload_prep_block(struct xfs_btree_block *new_block;int ret; -if ((cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) && +if ((cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) && level == cur->bc_nlevels -1 ) {struct xfs_ifork *ifp =xfs_btree_ifork_ptr (cur);size_t new_size;
@@ -413,7 +413,7 @@ xfs_btree_bload_prep_block(xfs_btree_init_block_int (cur->bc_mp, ifp->if_broot,XFS_BUF_DADDR_NULL , cur->bc_btnum, level, nr_this_block, cur->bc_ino.ip->i_ino, - cur->bc_flags); + cur->bc_ops->geom_flags); *bpp =NULL ; *blockp = ifp->if_broot;
@@ -704,7 +704,7 @@ xfs_btree_bload_compute_geometry(xfs_btree_bload_level_geometry (cur, bbl, level, nr_this_level, &avg_per_block, &level_blocks, &dontcare64); -if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) { +if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) {/* * If all the items we want to store at this level * would fit in the inode root block, then we have our
@@ -763,7 +763,7 @@ xfs_btree_bload_compute_geometry(return -EOVERFLOW ; bbl->btree_height = cur->bc_nlevels; -if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) +if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) bbl->nr_blocks = nr_blocks -1 ;else bbl->nr_blocks = nr_blocks;
@@ -890,7 +890,7 @@ xfs_btree_bload( }/* Initialize the new root. */ -if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) { +if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) {ASSERT (xfs_btree_ptr_is_null (cur, &ptr)); cur->bc_ino.ifake->if_levels = cur->bc_nlevels; cur->bc_ino.ifake->if_blocks = total_blocks -1 ;
libxfs/xfs_btree_staging.h +1 -1
@@ -76,7 +76,7 @@ struct xfs_btree_bload {/* * This function should return the size of the in-core btree root -* block. It is only necessary for XFS_BTREE_ROOT_IN_INODE btree +* block. It is only necessary for XFS_BTGEO_ROOT_IN_INODE btree * types. */ xfs_btree_bload_iroot_size_fn iroot_size;
libxfs/xfs_rmap_btree.c +2 -1
@@ -471,6 +471,8 @@ xfs_rmapbt_keys_contiguous( }static const struct xfs_btree_ops xfs_rmapbt_ops = { + .geom_flags =XFS_BTGEO_OVERLAPPING , + .rec_len =sizeof (struct xfs_rmap_rec ), .key_len =2 *sizeof (struct xfs_rmap_key ),
@@ -503,7 +505,6 @@ xfs_rmapbt_init_common(/* Overlapping btree; 2 keys per pointer. */ cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); - cur->bc_flags =XFS_BTREE_OVERLAPPING ; cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); cur->bc_ag.pag =xfs_perag_hold (pag);
repair/bulkload.c +1 -1
@@ -314,7 +314,7 @@ bulkload_claim_block(if (resv->used == resv->len)list_move_tail (&resv->list, &bkl->resv_list); -if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) +if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) ptr->l =cpu_to_be64 (XFS_AGB_TO_FSB (mp, resv->pag->pag_agno, agbno));else
PATCH 33/111 xfs: remove bc_ino.flags
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: e9e66df8bfa4132d905543a6b099ec8a3380b732
Just move the two flags into bc_flags where there is plenty of space.
--- libxfs/xfs_bmap.c | 27 +++++++++------------------ libxfs/xfs_bmap_btree.c | 14 ++++---------- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree.h | 12 ++++++------ 4 files changed, 20 insertions(+), 35 deletions(-)
libxfs/xfs_bmap.c +9 -18
@@ -645,7 +645,8 @@ xfs_bmap_extents_to_btree(* Need a cursor. Can't allocate until bb_level is filled in. */ cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags = wasdel ?XFS_BTCUR_BMBT_WASDEL :0 ; +if (wasdel) + cur->bc_flags |=XFS_BTREE_BMBT_WASDEL ;/* * Convert to a btree with two levels, one record in root. */
@@ -1443,8 +1444,7 @@ xfs_bmap_add_extent_delay_real(ASSERT (whichfork !=XFS_ATTR_FORK );ASSERT (!isnullstartblock (new->br_startblock)); -ASSERT (!bma->cur || - (bma->cur->bc_ino.flags &XFS_BTCUR_BMBT_WASDEL )); +ASSERT (!bma->cur || (bma->cur->bc_flags &XFS_BTREE_BMBT_WASDEL ));XFS_STATS_INC (mp, xs_add_exlist);
@@ -2703,7 +2703,7 @@ xfs_bmap_add_extent_hole_real(struct xfs_bmbt_irec old;ASSERT (!isnullstartblock (new->br_startblock)); -ASSERT (!cur || !(cur->bc_ino.flags &XFS_BTCUR_BMBT_WASDEL )); +ASSERT (!cur || !(cur->bc_flags &XFS_BTREE_BMBT_WASDEL ));XFS_STATS_INC (mp, xs_add_exlist);
@@ -4223,9 +4223,8 @@ xfs_bmapi_allocate(*/ bma->nallocs++; -if (bma->cur) - bma->cur->bc_ino.flags = - bma->wasdel ?XFS_BTCUR_BMBT_WASDEL :0 ; +if (bma->cur && bma->wasdel) + bma->cur->bc_flags |=XFS_BTREE_BMBT_WASDEL ; bma->got.br_startoff = bma->offset; bma->got.br_startblock = bma->blkno;
@@ -4760,10 +4759,8 @@ xfs_bmapi_remap( ip->i_nblocks += len;xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); -if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) { +if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags =0 ; - } got.br_startoff = bno; got.br_startblock = startblock;
@@ -5394,7 +5391,6 @@ __xfs_bunmapi(if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) {ASSERT (ifp->if_format ==XFS_DINODE_FMT_BTREE ); cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags =0 ; }else cur =NULL ;
@@ -5855,10 +5851,8 @@ xfs_bmap_collapse_extents(if (error)return error; -if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) { +if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags =0 ; - }if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, &icur, &got)) { *done = true;
@@ -5972,10 +5966,8 @@ xfs_bmap_insert_extents(if (error)return error; -if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) { +if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags =0 ; - }if (*next_fsb ==NULLFSBLOCK ) {xfs_iext_last (ifp, &icur);
@@ -6092,7 +6084,6 @@ xfs_bmap_split_extent(if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) { cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); - cur->bc_ino.flags =0 ; error =xfs_bmbt_lookup_eq (cur, &got, &i);if (error) goto del_cursor;
libxfs/xfs_bmap_btree.c +4 -10
@@ -170,13 +170,8 @@ xfs_bmbt_dup_cursor( new =xfs_bmbt_init_cursor (cur->bc_mp, cur->bc_tp, cur->bc_ino.ip, cur->bc_ino.whichfork); - -/* -* Copy the firstblock, dfops, and flags values, -* since init cursor doesn't get them. -*/ - new->bc_ino.flags = cur->bc_ino.flags; - + new->bc_flags |= (cur->bc_flags & + (XFS_BTREE_BMBT_INVALID_OWNER |XFS_BTREE_BMBT_WASDEL ));return new; }
@@ -210,7 +205,7 @@ xfs_bmbt_alloc_block(xfs_rmap_ino_bmbt_owner (&args.oinfo, cur->bc_ino.ip->i_ino, cur->bc_ino.whichfork); args.minlen = args.maxlen = args.prod =1 ; - args.wasdel = cur->bc_ino.flags &XFS_BTCUR_BMBT_WASDEL ; + args.wasdel = cur->bc_flags &XFS_BTREE_BMBT_WASDEL ;if (!args.wasdel && args.tp->t_blk_res ==0 )return -ENOSPC ;
@@ -556,7 +551,6 @@ xfs_bmbt_init_common( cur->bc_ino.ip = ip; cur->bc_ino.allocated =0 ; - cur->bc_ino.flags =0 ;return cur; }
@@ -747,7 +741,7 @@ xfs_bmbt_change_owner(ASSERT (xfs_ifork_ptr (ip, whichfork)->if_format ==XFS_DINODE_FMT_BTREE ); cur =xfs_bmbt_init_cursor (ip->i_mount, tp, ip, whichfork); - cur->bc_ino.flags |=XFS_BTCUR_BMBT_INVALID_OWNER ; + cur->bc_flags |=XFS_BTREE_BMBT_INVALID_OWNER ; error =xfs_btree_change_owner (cur, new_owner, buffer_list);xfs_btree_del_cursor (cur, error);
libxfs/xfs_btree.c +1 -1
@@ -1834,7 +1834,7 @@ xfs_btree_lookup_get_block(/* Check the inode owner since the verifiers don't. */ if (xfs_has_crc (cur->bc_mp) && - !(cur->bc_ino.flags &XFS_BTCUR_BMBT_INVALID_OWNER ) && + !(cur->bc_flags &XFS_BTREE_BMBT_INVALID_OWNER ) && (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) &&be64_to_cpu ((*blkp)->bb_u.l.bb_owner) != cur->bc_ino.ip->i_ino)
libxfs/xfs_btree.h +6 -6
@@ -249,12 +249,6 @@ struct xfs_btree_cur_ino {int allocated;short forksize;char whichfork; -char flags; -/* We are converting a delalloc reservation */ -#define XFS_BTCUR_BMBT_WASDEL (1 << 0) - -/* For extent swap, ignore owner check in verifier */ -#define XFS_BTCUR_BMBT_INVALID_OWNER (1 << 1) };struct xfs_btree_level {
@@ -321,6 +315,12 @@ xfs_btree_cur_sizeof(unsigned int nlevels)*/ #define XFS_BTREE_STAGING (1U << 0) +/* We are converting a delalloc reservation (only for bmbt btrees) */ +#define XFS_BTREE_BMBT_WASDEL (1U << 1) + +/* For extent swap, ignore owner check in verifier (only for bmbt btrees) */ +#define XFS_BTREE_BMBT_INVALID_OWNER (1U << 2) +#define XFS_BTREE_NOERROR 0#define XFS_BTREE_ERROR 1
PATCH 34/111 xfs: consolidate the xfs_alloc_lookup_* helpers
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 73a8fd93c421c4a6ac2c581c4d3478d3d68a0def
Add a single xfs_alloc_lookup helper to sort out the argument passing and setting of the active flag instead of duplicating the logic three times.
--- libxfs/xfs_alloc.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
libxfs/xfs_alloc.c +22 -21
@@ -147,23 +147,35 @@ xfs_alloc_ag_max_usable(return mp->m_sb.sb_agblocks - blocks; } + +static int +xfs_alloc_lookup ( +struct xfs_btree_cur *cur, +xfs_lookup_t dir, +xfs_agblock_t bno, +xfs_extlen_t len, +int *stat) +{ +int error; + + cur->bc_rec.a.ar_startblock = bno; + cur->bc_rec.a.ar_blockcount = len; + error =xfs_btree_lookup (cur, dir, stat); + cur->bc_ag.abt.active = (*stat ==1 ); +return error; +} +/* * Lookup the record equal to [bno, len] in the btree given by cur. */ -STATIC int /* error */ +static inline int /* error */ xfs_alloc_lookup_eq (struct xfs_btree_cur *cur,/* btree cursor */ xfs_agblock_t bno,/* starting block of extent */ xfs_extlen_t len,/* length of extent */ int *stat)/* success/failure */ { -int error; - - cur->bc_rec.a.ar_startblock = bno; - cur->bc_rec.a.ar_blockcount = len; - error =xfs_btree_lookup (cur,XFS_LOOKUP_EQ , stat); - cur->bc_ag.abt.active = (*stat ==1 ); -return error; +return xfs_alloc_lookup (cur,XFS_LOOKUP_EQ , bno, len, stat); }/*
@@ -177,13 +189,7 @@ xfs_alloc_lookup_ge(xfs_extlen_t len,/* length of extent */ int *stat) /* success/failure */ { - int error; - - cur->bc_rec.a.ar_startblock = bno; - cur->bc_rec.a.ar_blockcount = len; - error =xfs_btree_lookup (cur,XFS_LOOKUP_GE , stat); - cur->bc_ag.abt.active = (*stat ==1 ); -return error; + return xfs_alloc_lookup(cur, XFS_LOOKUP_GE, bno, len, stat); }/*
@@ -197,12 +203,7 @@ xfs_alloc_lookup_le(xfs_extlen_t len,/* length of extent */ int *stat) /* success/failure */ { - int error; - cur->bc_rec.a.ar_startblock = bno; - cur->bc_rec.a.ar_blockcount = len; - error =xfs_btree_lookup (cur,XFS_LOOKUP_LE , stat); - cur->bc_ag.abt.active = (*stat ==1 ); -return error; + return xfs_alloc_lookup(cur, XFS_LOOKUP_LE, bno, len, stat); } static inline bool
PATCH 35/111 xfs: turn the allocbt cursor active field into a btree flag
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: b20775ed644af0cbaee9632ad63ae6ec5ee502cc
Add a new XFS_BTREE_ALLOCBT_ACTIVE flag to replace the active field.
--- libxfs/xfs_alloc.c | 13 ++++++++----- libxfs/xfs_alloc_btree.c | 1 - libxfs/xfs_btree.h | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-)
libxfs/xfs_alloc.c +8 -5
@@ -161,7 +161,10 @@ xfs_alloc_lookup( cur->bc_rec.a.ar_startblock = bno; cur->bc_rec.a.ar_blockcount = len; error =xfs_btree_lookup (cur, dir, stat); - cur->bc_ag.abt.active = (*stat ==1 ); +if (*stat ==1 ) + cur->bc_flags |=XFS_BTREE_ALLOCBT_ACTIVE ; +else + cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE ;return error; }
@@ -210,7 +213,7 @@ static inline boolxfs_alloc_cur_active ( struct xfs_btree_cur *cur) { -return cur && cur->bc_ag.abt.active; +return cur && (cur->bc_flags &XFS_BTREE_ALLOCBT_ACTIVE ); }/*
@@ -988,7 +991,7 @@ xfs_alloc_cur_check( deactivate = true; out:if (deactivate) - cur->bc_ag.abt.active = false; + cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE ;trace_xfs_alloc_cur_check (args->mp, cur->bc_btnum, bno, len, diff, *new);return 0 ;
@@ -1363,7 +1366,7 @@ xfs_alloc_walk_iter(if (error)return error;if (i ==0 ) - cur->bc_ag.abt.active = false; + cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE ;if (count >0 ) count--;
@@ -1477,7 +1480,7 @@ xfs_alloc_ag_vextent_locality(if (error)return error;if (i) { - acur->cnt->bc_ag.abt.active = true; + acur->cnt->bc_flags |=XFS_BTREE_ALLOCBT_ACTIVE ; fbcur = acur->cnt; fbinc = false; }
libxfs/xfs_alloc_btree.c +0 -1
@@ -521,7 +521,6 @@ xfs_allocbt_init_common( mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtb_2); } - cur->bc_ag.abt.active = false; cur->bc_ag.pag =xfs_perag_hold (pag);
libxfs/xfs_btree.h +3 -3
@@ -236,9 +236,6 @@ struct xfs_btree_cur_ag {unsigned int nr_ops;/* # record updates */ unsigned int shape_changes;/* # of extent splits */ } refc; -struct { -bool active;/* allocation cursor state */ - } abt; }; };
@@ -321,6 +318,9 @@ xfs_btree_cur_sizeof(unsigned int nlevels)/* For extent swap, ignore owner check in verifier (only for bmbt btrees) */ #define XFS_BTREE_BMBT_INVALID_OWNER (1U << 2) +/* Cursor is active (only for allocbt btrees) */ +#define XFS_BTREE_ALLOCBT_ACTIVE (1U << 3) +#define XFS_BTREE_NOERROR 0#define XFS_BTREE_ERROR 1
PATCH 36/111 xfs: extern some btree ops structures
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: d8d6df4253adcdb5862a9410d962e9168b973c88
Expose these static btree ops structures so that we can reference them in the AG initialization code in the next patch.
--- libxfs/xfs_alloc_btree.c | 4 ++-- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_ialloc_btree.c | 4 ++-- libxfs/xfs_refcount_btree.c | 2 +- libxfs/xfs_rmap_btree.c | 2 +- libxfs/xfs_shared.h | 9 +++++++++ 6 files changed, 16 insertions(+), 7 deletions(-)
libxfs/xfs_alloc_btree.c +2 -2
@@ -452,7 +452,7 @@ xfs_allocbt_keys_contiguous( be32_to_cpu(key2->alloc.ar_startblock)); } -static const struct xfs_btree_ops xfs_bnobt_ops = { +const struct xfs_btree_ops xfs_bnobt_ops = { .rec_len =sizeof (xfs_alloc_rec_t), .key_len =sizeof (xfs_alloc_key_t),
@@ -475,7 +475,7 @@ static const struct xfs_btree_ops xfs_bnobt_ops = { .keys_contiguous = xfs_allocbt_keys_contiguous, }; -static const struct xfs_btree_ops xfs_cntbt_ops = { +const struct xfs_btree_ops xfs_cntbt_ops = { .geom_flags =XFS_BTGEO_LASTREC_UPDATE , .rec_len =sizeof (xfs_alloc_rec_t),
libxfs/xfs_bmap_btree.c +1 -1
@@ -509,7 +509,7 @@ xfs_bmbt_keys_contiguous( be64_to_cpu(key2->bmbt.br_startoff)); } -static const struct xfs_btree_ops xfs_bmbt_ops = { +const struct xfs_btree_ops xfs_bmbt_ops = { .geom_flags =XFS_BTGEO_LONG_PTRS |XFS_BTGEO_ROOT_IN_INODE , .rec_len =sizeof (xfs_bmbt_rec_t),
libxfs/xfs_ialloc_btree.c +2 -2
@@ -397,7 +397,7 @@ xfs_inobt_keys_contiguous( be32_to_cpu(key2->inobt.ir_startino)); } -static const struct xfs_btree_ops xfs_inobt_ops = { +const struct xfs_btree_ops xfs_inobt_ops = { .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t),
@@ -419,7 +419,7 @@ static const struct xfs_btree_ops xfs_inobt_ops = { .keys_contiguous = xfs_inobt_keys_contiguous, }; -static const struct xfs_btree_ops xfs_finobt_ops = { +const struct xfs_btree_ops xfs_finobt_ops = { .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t),
libxfs/xfs_refcount_btree.c +1 -1
@@ -316,7 +316,7 @@ xfs_refcountbt_keys_contiguous( be32_to_cpu(key2->refc.rc_startblock)); } -static const struct xfs_btree_ops xfs_refcountbt_ops = { +const struct xfs_btree_ops xfs_refcountbt_ops = { .rec_len =sizeof (struct xfs_refcount_rec ), .key_len =sizeof (struct xfs_refcount_key ),
libxfs/xfs_rmap_btree.c +1 -1
@@ -470,7 +470,7 @@ xfs_rmapbt_keys_contiguous( be32_to_cpu(key2->rmap.rm_startblock)); } -static const struct xfs_btree_ops xfs_rmapbt_ops = { +const struct xfs_btree_ops xfs_rmapbt_ops = { .geom_flags =XFS_BTGEO_OVERLAPPING , .rec_len =sizeof (struct xfs_rmap_rec ),
libxfs/xfs_shared.h +9 -0
@@ -43,6 +43,15 @@ extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops; +/* btree ops */ +extern const struct xfs_btree_ops xfs_bnobt_ops; +extern const struct xfs_btree_ops xfs_cntbt_ops; +extern const struct xfs_btree_ops xfs_inobt_ops; +extern const struct xfs_btree_ops xfs_finobt_ops; +extern const struct xfs_btree_ops xfs_bmbt_ops; +extern const struct xfs_btree_ops xfs_refcountbt_ops; +extern const struct xfs_btree_ops xfs_rmapbt_ops; +/* log size calculation functions */ int xfs_log_calc_unit_res (struct xfs_mount *mp,int unit_bytes);int xfs_log_calc_minimum_size (struct xfs_mount *);
PATCH 37/111 xfs: initialize btree blocks using btree_ops structure
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: c87e3bf7802477cb4500dfafe0ab039313aa2dda
Notice now that the btree ops structure encodes btree geometry flags and the magic number through the buffer ops. Refactor the btree block initialization functions to use the btree ops so that we no longer have to open code all that.
--- libxfs/xfs_ag.c | 33 ++++++++++--------------- libxfs/xfs_ag.h | 2 +- libxfs/xfs_bmap.c | 8 ++---- libxfs/xfs_bmap_btree.c | 20 +++++++++++++-- libxfs/xfs_bmap_btree.h | 3 ++ libxfs/xfs_btree.c | 57 ++++++++++++++++++-------------------------- libxfs/xfs_btree.h | 28 ++++++---------------- libxfs/xfs_btree_staging.c | 5 ++-- 8 files changed, 69 insertions(+), 87 deletions(-)
libxfs/xfs_ag.c +13 -20
@@ -490,7 +490,7 @@ xfs_btroot_init(struct xfs_buf *bp, struct aghdr_init_data *id) { - xfs_btree_init_block(mp, bp, id->type, 0, 0, id->agno); + xfs_btree_init_block(mp, bp, id->bc_ops, 0, 0, id->agno); }/* Finish initializing a free space btree. */
@@ -548,7 +548,7 @@ xfs_freesp_init_recs( }/* -* Alloc btree root block init functions +* bnobt/cntbt btree root block init functions */ static void xfs_bnoroot_init(
@@ -556,17 +556,7 @@ xfs_bnoroot_init(struct xfs_buf *bp, struct aghdr_init_data *id) { - xfs_btree_init_block(mp, bp, XFS_BTNUM_BNO, 0, 0, id->agno); -xfs_freesp_init_recs (mp, bp, id); -} - -static void -xfs_cntroot_init ( -struct xfs_mount *mp, -struct xfs_buf *bp, -struct aghdr_init_data *id) -{ -xfs_btree_init_block (mp, bp,XFS_BTNUM_CNT ,0 ,0 , id->agno); + xfs_btree_init_block(mp, bp, id->bc_ops, 0, 0, id->agno);xfs_freesp_init_recs (mp, bp, id); }
@@ -582,7 +572,7 @@ xfs_rmaproot_init(struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_rmap_rec *rrec; -xfs_btree_init_block (mp, bp,XFS_BTNUM_RMAP ,0 ,4 , id->agno); +xfs_btree_init_block (mp, bp, id->bc_ops,0 ,4 , id->agno);/* * mark the AG header regions as static metadata The BNO
@@ -795,7 +785,7 @@ struct xfs_aghdr_grow_data {size_t numblks;const struct xfs_buf_ops *ops;aghdr_init_work_f work; -xfs_btnum_t type; +const struct xfs_btree_ops *bc_ops;bool need_init; };
@@ -849,13 +839,15 @@ xfs_ag_init_headers( .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_bnobt_buf_ops, .work = &xfs_bnoroot_init, + .bc_ops = &xfs_bnobt_ops, .need_init = true }, {/* CNT root block */ .daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_CNT_BLOCK(mp)), .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_cntbt_buf_ops, - .work = &xfs_cntroot_init, + .work = &xfs_bnoroot_init, + .bc_ops = &xfs_cntbt_ops, .need_init = true }, {/* INO root block */
@@ -863,7 +855,7 @@ xfs_ag_init_headers( .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_inobt_buf_ops, .work = &xfs_btroot_init, - .type = XFS_BTNUM_INO, + .bc_ops = &xfs_inobt_ops, .need_init = true }, {/* FINO root block */
@@ -871,7 +863,7 @@ xfs_ag_init_headers( .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_finobt_buf_ops, .work = &xfs_btroot_init, - .type = XFS_BTNUM_FINO, + .bc_ops = &xfs_finobt_ops, .need_init = xfs_has_finobt(mp) }, {/* RMAP root block */
@@ -879,6 +871,7 @@ xfs_ag_init_headers( .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_rmapbt_buf_ops, .work = &xfs_rmaproot_init, + .bc_ops = &xfs_rmapbt_ops, .need_init = xfs_has_rmapbt(mp) }, {/* REFC root block */
@@ -886,7 +879,7 @@ xfs_ag_init_headers( .numblks = BTOBB(mp->m_sb.sb_blocksize), .ops = &xfs_refcountbt_buf_ops, .work = &xfs_btroot_init, - .type = XFS_BTNUM_REFC, + .bc_ops = &xfs_refcountbt_ops, .need_init = xfs_has_reflink(mp) }, {/* NULL terminating block */
@@ -904,7 +897,7 @@ xfs_ag_init_headers( id->daddr = dp->daddr; id->numblks = dp->numblks; - id->type = dp->type; + id->bc_ops = dp->bc_ops; error =xfs_ag_init_hdr (mp, id, dp->work, dp->ops);if (error)break ;
libxfs/xfs_ag.h +1 -1
@@ -331,7 +331,7 @@ struct aghdr_init_data {/* per header data */ xfs_daddr_t daddr;/* header location */ size_t numblks;/* size of header */ -xfs_btnum_t type;/* type of btree root block */ +const struct xfs_btree_ops *bc_ops;/* btree ops */ };int xfs_ag_init_headers (struct xfs_mount *mp,struct aghdr_init_data *id);
libxfs/xfs_bmap.c +2 -6
@@ -638,9 +638,7 @@ xfs_bmap_extents_to_btree(* Fill in the root. */ block = ifp->if_broot; -xfs_btree_init_block_int (mp, block,XFS_BUF_DADDR_NULL , -XFS_BTNUM_BMAP ,1 ,1 , ip->i_ino, -XFS_BTGEO_LONG_PTRS ); +xfs_bmbt_init_block (ip, block,NULL ,1 ,1 );/* * Need a cursor. Can't allocate until bb_level is filled in. */
@@ -686,9 +684,7 @@ xfs_bmap_extents_to_btree(*/ abp->b_ops = &xfs_bmbt_buf_ops; ablock =XFS_BUF_TO_BLOCK (abp); -xfs_btree_init_block_int (mp, ablock,xfs_buf_daddr (abp), -XFS_BTNUM_BMAP ,0 ,0 , ip->i_ino, -XFS_BTGEO_LONG_PTRS ); +xfs_bmbt_init_block (ip, ablock, abp,0 ,0 );for_each_xfs_iext (ifp, &icur, &rec) {if (isnullstartblock (rec.br_startblock))
libxfs/xfs_bmap_btree.c +17 -3
@@ -25,6 +25,22 @@static struct kmem_cache *xfs_bmbt_cur_cache; +void +xfs_bmbt_init_block ( +struct xfs_inode *ip, +struct xfs_btree_block *buf, +struct xfs_buf *bp, +__u16 level, +__u16 numrecs) +{ +if (bp) +xfs_btree_init_block (ip->i_mount, bp, &xfs_bmbt_ops, level, + numrecs, ip->i_ino); +else +xfs_btree_init_block_int (ip->i_mount, buf, &xfs_bmbt_ops, +XFS_BUF_DADDR_NULL , level, numrecs, ip->i_ino); +} +/* * Convert on-disk form of btree root to in-memory form. */
@@ -43,9 +59,7 @@ xfs_bmdr_to_bmbt(xfs_bmbt_key_t *tkp;__be64 *tpp; -xfs_btree_init_block_int (mp, rblock,XFS_BUF_DADDR_NULL , -XFS_BTNUM_BMAP ,0 ,0 , ip->i_ino, -XFS_BTGEO_LONG_PTRS ); +xfs_bmbt_init_block (ip, rblock,NULL ,0 ,0 ); rblock->bb_level = dblock->bb_level;ASSERT (be16_to_cpu (rblock->bb_level) >0 ); rblock->bb_numrecs = dblock->bb_numrecs;
libxfs/xfs_bmap_btree.h +3 -0
@@ -120,4 +120,7 @@ unsigned int xfs_bmbt_maxlevels_ondisk(void);int __init xfs_bmbt_init_cur_cache (void );void xfs_bmbt_destroy_cur_cache (void ); +void xfs_bmbt_init_block (struct xfs_inode *ip,struct xfs_btree_block *buf, +struct xfs_buf *bp,__u16 level,__u16 numrecs); +#endif /* __XFS_BMAP_BTREE_H__ */
libxfs/xfs_btree.c +23 -34
122 lines not on this page · raw message
libxfs/xfs_btree.h +8 -20
@@ -63,7 +63,8 @@ union xfs_btree_rec {#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi)#define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi) -uint32_t xfs_btree_magic (int crc,xfs_btnum_t btnum); +struct xfs_btree_ops ; +uint32_t xfs_btree_magic (struct xfs_mount *mp,const struct xfs_btree_ops *ops);/* * For logging record fields.
@@ -434,25 +435,12 @@ xfs_btree_reada_bufs(/* * Initialise a new btree block header */ -void -xfs_btree_init_block ( -struct xfs_mount *mp, -struct xfs_buf *bp, -xfs_btnum_t btnum, -__u16 level, -__u16 numrecs, -__u64 owner); - -void -xfs_btree_init_block_int ( -struct xfs_mount *mp, -struct xfs_btree_block *buf, -xfs_daddr_t blkno, -xfs_btnum_t btnum, -__u16 level, -__u16 numrecs, -__u64 owner, -unsigned int geom_flags); +void xfs_btree_init_block (struct xfs_mount *mp,struct xfs_buf *bp, +const struct xfs_btree_ops *ops,__u16 level,__u16 numrecs, +__u64 owner); +void xfs_btree_init_block_int (struct xfs_mount *mp, +struct xfs_btree_block *buf,const struct xfs_btree_ops *ops, +xfs_daddr_t blkno,__u16 level,__u16 numrecs,__u64 owner);/* * Common btree core entry points.
libxfs/xfs_btree_staging.c +2 -3
@@ -411,9 +411,8 @@ xfs_btree_bload_prep_block(/* Initialize it and send it out. */ xfs_btree_init_block_int (cur->bc_mp, ifp->if_broot, -XFS_BUF_DADDR_NULL , cur->bc_btnum, level, - nr_this_block, cur->bc_ino.ip->i_ino, - cur->bc_ops->geom_flags); + cur->bc_ops,XFS_BUF_DADDR_NULL , level, + nr_this_block, cur->bc_ino.ip->i_ino); *bpp =NULL ; *blockp = ifp->if_broot;
PATCH 38/111 xfs: rename btree block/buffer init functions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 3c68858b264fac292f74733eeaf558595978a5e5
Rename xfs_btree_init_block_int to xfs_btree_init_block, and xfs_btree_init_block to xfs_btree_init_buf so that the name suggests the type that caller are supposed to pass in.
--- libxfs/xfs_ag.c | 6 +++--- libxfs/xfs_bmap_btree.c | 4 ++-- libxfs/xfs_btree.c | 8 ++++---- libxfs/xfs_btree.h | 4 ++-- libxfs/xfs_btree_staging.c | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-)
libxfs/xfs_ag.c +3 -3
@@ -490,7 +490,7 @@ xfs_btroot_init(struct xfs_buf *bp, struct aghdr_init_data *id) { - xfs_btree_init_block(mp, bp, id->bc_ops, 0, 0, id->agno); + xfs_btree_init_buf(mp, bp, id->bc_ops, 0, 0, id->agno); }/* Finish initializing a free space btree. */
@@ -556,7 +556,7 @@ xfs_bnoroot_init(struct xfs_buf *bp, struct aghdr_init_data *id) { - xfs_btree_init_block(mp, bp, id->bc_ops, 0, 0, id->agno); + xfs_btree_init_buf(mp, bp, id->bc_ops, 0, 0, id->agno);xfs_freesp_init_recs (mp, bp, id); }
@@ -572,7 +572,7 @@ xfs_rmaproot_init(struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_rmap_rec *rrec; -xfs_btree_init_block (mp, bp, id->bc_ops,0 ,4 , id->agno); +xfs_btree_init_buf (mp, bp, id->bc_ops,0 ,4 , id->agno);/* * mark the AG header regions as static metadata The BNO
libxfs/xfs_bmap_btree.c +2 -2
@@ -34,10 +34,10 @@ xfs_bmbt_init_block( __u16 numrecs) {if (bp) -xfs_btree_init_block (ip->i_mount, bp, &xfs_bmbt_ops, level, +xfs_btree_init_buf (ip->i_mount, bp, &xfs_bmbt_ops, level, numrecs, ip->i_ino);else -xfs_btree_init_block_int (ip->i_mount, buf, &xfs_bmbt_ops, +xfs_btree_init_block (ip->i_mount, buf, &xfs_bmbt_ops,XFS_BUF_DADDR_NULL , level, numrecs, ip->i_ino); }
libxfs/xfs_btree.c +4 -4
@@ -1151,7 +1151,7 @@ xfs_btree_set_sibling( } void -xfs_btree_init_block_int( +xfs_btree_init_block( struct xfs_mount *mp, struct xfs_btree_block *buf, const struct xfs_btree_ops *ops,
@@ -1193,7 +1193,7 @@ xfs_btree_init_block_int( } void -xfs_btree_init_block( +xfs_btree_init_buf( struct xfs_mount *mp, struct xfs_buf *bp, const struct xfs_btree_ops *ops,
@@ -1201,7 +1201,7 @@ xfs_btree_init_block(__u16 numrecs, __u64 owner) { -xfs_btree_init_block_int (mp ,XFS_BUF_TO_BLOCK (bp ),ops , +xfs_btree_init_block (mp ,XFS_BUF_TO_BLOCK (bp ),ops ,xfs_buf_daddr (bp ),level ,numrecs ,owner ); }
@@ -1225,7 +1225,7 @@ xfs_btree_init_block_cur(else owner = cur->bc_ag.pag->pag_agno; -xfs_btree_init_block_int (cur->bc_mp,XFS_BUF_TO_BLOCK (bp), cur->bc_ops, +xfs_btree_init_block (cur->bc_mp,XFS_BUF_TO_BLOCK (bp), cur->bc_ops,xfs_buf_daddr (bp), level, numrecs, owner); }
libxfs/xfs_btree.h +2 -2
@@ -435,10 +435,10 @@ xfs_btree_reada_bufs(/* * Initialise a new btree block header */ -void xfs_btree_init_block (struct xfs_mount *mp,struct xfs_buf *bp, +void xfs_btree_init_buf (struct xfs_mount *mp,struct xfs_buf *bp,const struct xfs_btree_ops *ops,__u16 level,__u16 numrecs,__u64 owner); -void xfs_btree_init_block_int (struct xfs_mount *mp, +void xfs_btree_init_block (struct xfs_mount *mp,struct xfs_btree_block *buf,const struct xfs_btree_ops *ops,xfs_daddr_t blkno,__u16 level,__u16 numrecs,__u64 owner);
libxfs/xfs_btree_staging.c +1 -1
@@ -410,7 +410,7 @@ xfs_btree_bload_prep_block( ifp->if_broot_bytes = (int )new_size;/* Initialize it and send it out. */ -xfs_btree_init_block_int (cur->bc_mp, ifp->if_broot, +xfs_btree_init_block (cur->bc_mp, ifp->if_broot, cur->bc_ops,XFS_BUF_DADDR_NULL , level, nr_this_block, cur->bc_ino.ip->i_ino);
PATCH 39/111 xfs: btree convert xfs_btree_init_block to xfs_btree_init_buf calls
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 7771f7030007e3faa6906864d01b504b590e1ca2
Convert any place we call xfs_btree_init_block with a buffer to use the _init_buf function.
--- libxfs/xfs_btree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libxfs/xfs_btree.c +1 -2
@@ -1225,8 +1225,7 @@ xfs_btree_init_block_cur(else owner = cur->bc_ag.pag->pag_agno; -xfs_btree_init_block (cur->bc_mp,XFS_BUF_TO_BLOCK (bp), cur->bc_ops, -xfs_buf_daddr (bp), level, numrecs, owner); +xfs_btree_init_buf (cur->bc_mp, bp, cur->bc_ops, level, numrecs, owner); }/*
PATCH 40/111 xfs: remove the unnecessary daddr paramter to _init_block
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 11388f6581f40e7d5a69ce5f8b13264eca7c2c5c
Now that all of the callers pass XFS_BUF_DADDR_NULL as the daddr parameter, we can elide that too.
--- libxfs/xfs_bmap_btree.c | 4 ++-- libxfs/xfs_btree.c | 19 ++++++++++++++++--- libxfs/xfs_btree.h | 2 +- libxfs/xfs_btree_staging.c | 5 ++--- 4 files changed, 21 insertions(+), 9 deletions(-)
libxfs/xfs_bmap_btree.c +2 -2
@@ -37,8 +37,8 @@ xfs_bmbt_init_block(xfs_btree_init_buf (ip->i_mount, bp, &xfs_bmbt_ops, level, numrecs, ip->i_ino); else - xfs_btree_init_block(ip->i_mount, buf, &xfs_bmbt_ops, - XFS_BUF_DADDR_NULL, level, numrecs, ip->i_ino); + xfs_btree_init_block(ip->i_mount, buf, &xfs_bmbt_ops, level, + numrecs, ip->i_ino); }/*
libxfs/xfs_btree.c +16 -3
@@ -1150,8 +1150,8 @@ xfs_btree_set_sibling( } } -void -xfs_btree_init_block( +static void +__xfs_btree_init_block( struct xfs_mount *mp, struct xfs_btree_block *buf, const struct xfs_btree_ops *ops,
@@ -1192,6 +1192,19 @@ xfs_btree_init_block( } } +void +xfs_btree_init_block ( +struct xfs_mount *mp, +struct xfs_btree_block *block, +const struct xfs_btree_ops *ops, +__u16 level, +__u16 numrecs, +__u64 owner) +{ +__xfs_btree_init_block (mp, block, ops,XFS_BUF_DADDR_NULL , level, + numrecs, owner); +} + void xfs_btree_init_buf( struct xfs_mount *mp,
@@ -1201,7 +1214,7 @@ xfs_btree_init_buf(__u16 numrecs, __u64 owner) { -xfs_btree_init_block (mp ,XFS_BUF_TO_BLOCK (bp ),ops , +__xfs_btree_init_block (mp ,XFS_BUF_TO_BLOCK (bp ),ops ,xfs_buf_daddr (bp ),level ,numrecs ,owner ); }
libxfs/xfs_btree.h +1 -1
@@ -440,7 +440,7 @@ void xfs_btree_init_buf(struct xfs_mount *mp, struct xfs_buf *bp, __u64 owner);void xfs_btree_init_block (struct xfs_mount *mp,struct xfs_btree_block *buf,const struct xfs_btree_ops *ops, -xfs_daddr_t blkno,__u16 level,__u16 numrecs,__u64 owner); +__u16 level,__u16 numrecs,__u64 owner);/* * Common btree core entry points.
libxfs/xfs_btree_staging.c +2 -3
@@ -410,9 +410,8 @@ xfs_btree_bload_prep_block( ifp->if_broot_bytes = (int )new_size;/* Initialize it and send it out. */ -xfs_btree_init_block (cur->bc_mp, ifp->if_broot, - cur->bc_ops,XFS_BUF_DADDR_NULL , level, - nr_this_block, cur->bc_ino.ip->i_ino); +xfs_btree_init_block (cur->bc_mp, ifp->if_broot, cur->bc_ops, + level, nr_this_block, cur->bc_ino.ip->i_ino); *bpp =NULL ; *blockp = ifp->if_broot;
PATCH 41/111 xfs: set btree block buffer ops in _init_buf
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: ad065ef0d2fcd787225bd8887b6b75c6eb4da9a1
Set the btree block buffer ops in xfs_btree_init_buf since we already have access to that information through the btree ops.
--- libxfs/xfs_bmap.c | 1 - libxfs/xfs_btree.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_bmap.c +0 -1
@@ -682,7 +682,6 @@ xfs_bmap_extents_to_btree(/* * Fill in the child block. */ - abp->b_ops = &xfs_bmbt_buf_ops; ablock =XFS_BUF_TO_BLOCK (abp);xfs_bmbt_init_block (ip, ablock, abp,0 ,0 );
libxfs/xfs_btree.c +1 -0
@@ -1216,6 +1216,7 @@ xfs_btree_init_buf( {__xfs_btree_init_block (mp,XFS_BUF_TO_BLOCK (bp), ops,xfs_buf_daddr (bp), level, numrecs, owner); + bp->b_ops = ops->buf_ops; }void
PATCH 42/111 xfs: move lru refs to the btree ops structure
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 90cfae818dac5227e94e21d0f5250e098432723e
Move the btree buffer LRU refcount to the btree ops structure so that we can eliminate the last bc_btnum switch in the generic btree code. We're about to create repair-specific btree types, and we don't want that stuff cluttering up libxfs.
--- libxfs/xfs_alloc_btree.c | 4 ++++ libxfs/xfs_bmap_btree.c | 2 ++ libxfs/xfs_btree.c | 24 ++---------------------- libxfs/xfs_btree.h | 3 +++ libxfs/xfs_ialloc_btree.c | 4 ++++ libxfs/xfs_refcount_btree.c | 2 ++ libxfs/xfs_rmap_btree.c | 2 ++ 7 files changed, 19 insertions(+), 22 deletions(-)
libxfs/xfs_alloc_btree.c +4 -0
@@ -456,6 +456,8 @@ const struct xfs_btree_ops xfs_bnobt_ops = { .rec_len = sizeof(xfs_alloc_rec_t), .key_len = sizeof(xfs_alloc_key_t), + .lru_refs = XFS_ALLOC_BTREE_REF, + .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root, .alloc_block = xfs_allocbt_alloc_block,
@@ -481,6 +483,8 @@ const struct xfs_btree_ops xfs_cntbt_ops = { .rec_len = sizeof(xfs_alloc_rec_t), .key_len = sizeof(xfs_alloc_key_t), + .lru_refs = XFS_ALLOC_BTREE_REF, + .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root, .alloc_block = xfs_allocbt_alloc_block,
libxfs/xfs_bmap_btree.c +2 -0
@@ -529,6 +529,8 @@ const struct xfs_btree_ops xfs_bmbt_ops = { .rec_len = sizeof(xfs_bmbt_rec_t), .key_len = sizeof(xfs_bmbt_key_t), + .lru_refs = XFS_BMAP_BTREE_REF, + .dup_cursor = xfs_bmbt_dup_cursor, .update_cursor = xfs_bmbt_update_cursor, .alloc_block = xfs_bmbt_alloc_block,
libxfs/xfs_btree.c +2 -22
@@ -1281,32 +1281,12 @@ xfs_btree_buf_to_ptr( } } -STATIC void +static inline void xfs_btree_set_refs (struct xfs_btree_cur *cur,struct xfs_buf *bp) { -switch (cur->bc_btnum) { -case XFS_BTNUM_BNO : -case XFS_BTNUM_CNT : -xfs_buf_set_ref (bp,XFS_ALLOC_BTREE_REF ); -break ; -case XFS_BTNUM_INO : -case XFS_BTNUM_FINO : -xfs_buf_set_ref (bp,XFS_INO_BTREE_REF ); -break ; -case XFS_BTNUM_BMAP : -xfs_buf_set_ref (bp,XFS_BMAP_BTREE_REF ); -break ; -case XFS_BTNUM_RMAP : -xfs_buf_set_ref (bp,XFS_RMAP_BTREE_REF ); -break ; -case XFS_BTNUM_REFC : -xfs_buf_set_ref (bp,XFS_REFC_BTREE_REF ); -break ; -default : -ASSERT (0 ); - } +xfs_buf_set_ref (bp, cur->bc_ops->lru_refs); }int
libxfs/xfs_btree.h +3 -0
@@ -120,6 +120,9 @@ struct xfs_btree_ops {size_t key_len;size_t rec_len; +/* LRU refcount to set on each btree buffer created */ +unsigned int lru_refs; +/* cursor operations */ struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *); void (*update_cursor)(struct xfs_btree_cur *src,
libxfs/xfs_ialloc_btree.c +4 -0
@@ -401,6 +401,8 @@ const struct xfs_btree_ops xfs_inobt_ops = { .rec_len = sizeof(xfs_inobt_rec_t), .key_len = sizeof(xfs_inobt_key_t), + .lru_refs = XFS_INO_BTREE_REF, + .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_inobt_set_root, .alloc_block = xfs_inobt_alloc_block,
@@ -423,6 +425,8 @@ const struct xfs_btree_ops xfs_finobt_ops = { .rec_len = sizeof(xfs_inobt_rec_t), .key_len = sizeof(xfs_inobt_key_t), + .lru_refs = XFS_INO_BTREE_REF, + .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_finobt_set_root, .alloc_block = xfs_finobt_alloc_block,
libxfs/xfs_refcount_btree.c +2 -0
@@ -320,6 +320,8 @@ const struct xfs_btree_ops xfs_refcountbt_ops = { .rec_len = sizeof(struct xfs_refcount_rec), .key_len = sizeof(struct xfs_refcount_key), + .lru_refs = XFS_REFC_BTREE_REF, + .dup_cursor = xfs_refcountbt_dup_cursor, .set_root = xfs_refcountbt_set_root, .alloc_block = xfs_refcountbt_alloc_block,
libxfs/xfs_rmap_btree.c +2 -0
@@ -476,6 +476,8 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .rec_len = sizeof(struct xfs_rmap_rec), .key_len = 2 * sizeof(struct xfs_rmap_key), + .lru_refs = XFS_RMAP_BTREE_REF, + .dup_cursor = xfs_rmapbt_dup_cursor, .set_root = xfs_rmapbt_set_root, .alloc_block = xfs_rmapbt_alloc_block,
PATCH 43/111 xfs: move the btree stats offset into struct btree_ops
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 07b7f2e3172b97da2a7ac273ecbaf173cc09a9f4
The statistics offset is completely static, move it into the btree_ops structure instead of the cursor.
--- libxfs/xfs_alloc_btree.c | 17 +++++++---------- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_btree.h | 10 +++++++--- libxfs/xfs_ialloc_btree.c | 20 +++++++++----------- libxfs/xfs_refcount_btree.c | 3 +-- libxfs/xfs_rmap_btree.c | 3 +-- 6 files changed, 26 insertions(+), 29 deletions(-)
libxfs/xfs_alloc_btree.c +7 -10
@@ -457,6 +457,7 @@ const struct xfs_btree_ops xfs_bnobt_ops = { .key_len = sizeof(xfs_alloc_key_t), .lru_refs = XFS_ALLOC_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_abtb_2), .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root,
@@ -484,6 +485,7 @@ const struct xfs_btree_ops xfs_cntbt_ops = { .key_len = sizeof(xfs_alloc_key_t), .lru_refs = XFS_ALLOC_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_abtc_2), .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root,
@@ -512,22 +514,17 @@ xfs_allocbt_init_common( struct xfs_perag *pag, xfs_btnum_t btnum) { +const struct xfs_btree_ops *ops = &xfs_bnobt_ops;struct xfs_btree_cur *cur;ASSERT (btnum ==XFS_BTNUM_BNO || btnum ==XFS_BTNUM_CNT ); -if (btnum ==XFS_BTNUM_CNT ) { - cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_cntbt_ops, - mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtc_2); - }else { - cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_bnobt_ops, - mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtb_2); - } +if (btnum ==XFS_BTNUM_CNT ) + ops = &xfs_cntbt_ops; + cur =xfs_btree_alloc_cursor (mp, tp, btnum, ops, mp->m_alloc_maxlevels, + xfs_allocbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); -return cur; }
libxfs/xfs_bmap_btree.c +1 -1
@@ -530,6 +530,7 @@ const struct xfs_btree_ops xfs_bmbt_ops = { .key_len = sizeof(xfs_bmbt_key_t), .lru_refs = XFS_BMAP_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2), .dup_cursor = xfs_bmbt_dup_cursor, .update_cursor = xfs_bmbt_update_cursor,
@@ -563,7 +564,6 @@ xfs_bmbt_init_common( cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BMAP , &xfs_bmbt_ops, mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_bmbt_2); cur->bc_ino.ip = ip; cur->bc_ino.allocated =0 ;
libxfs/xfs_btree.h +7 -3
@@ -87,9 +87,11 @@ uint32_t xfs_btree_magic(struct xfs_mount *mp, const struct xfs_btree_ops *ops);* Generic stats interface */ #define XFS_BTREE_STATS_INC (cur, stat) \ - XFS_STATS_INC_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat) + XFS_STATS_INC_OFF((cur)->bc_mp, \ + (cur)->bc_ops->statoff + __XBTS_ ## stat)#define XFS_BTREE_STATS_ADD (cur, stat, val) \ - XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val) + XFS_STATS_ADD_OFF((cur)->bc_mp, \ + (cur)->bc_ops->statoff + __XBTS_ ## stat, val)enum xbtree_key_contig {XBTREE_KEY_GAP =0 ,
@@ -123,6 +125,9 @@ struct xfs_btree_ops {/* LRU refcount to set on each btree buffer created */ unsigned int lru_refs; +/* offset of btree stats array */ +unsigned int statoff; +/* cursor operations */ struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *); void (*update_cursor)(struct xfs_btree_cur *src,
@@ -280,7 +285,6 @@ struct xfs_btree_curunion xfs_btree_irec bc_rec;/* current insert/search record value */ uint8_t bc_nlevels;/* number of levels in the tree */ uint8_t bc_maxlevels;/* maximum levels for this btree type */ -int bc_statoff;/* offset of btree stats array */ /* * Short btree pointers need an agno to be able to turn the pointers
libxfs/xfs_ialloc_btree.c +9 -11
@@ -402,6 +402,7 @@ const struct xfs_btree_ops xfs_inobt_ops = { .key_len = sizeof(xfs_inobt_key_t), .lru_refs = XFS_INO_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_ibt_2), .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_inobt_set_root,
@@ -426,6 +427,7 @@ const struct xfs_btree_ops xfs_finobt_ops = { .key_len = sizeof(xfs_inobt_key_t), .lru_refs = XFS_INO_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_fibt_2), .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_finobt_set_root,
@@ -455,20 +457,16 @@ xfs_inobt_init_common( xfs_btnum_t btnum) /* ialloc or free ino btree */ {struct xfs_mount *mp = pag->pag_mount; +const struct xfs_btree_ops *ops = &xfs_inobt_ops;struct xfs_btree_cur *cur; -if (btnum ==XFS_BTNUM_INO ) { - cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_inobt_ops, -M_IGEO (mp)->inobt_maxlevels, - xfs_inobt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_ibt_2); - }else { - cur =xfs_btree_alloc_cursor (mp, tp, btnum, &xfs_finobt_ops, -M_IGEO (mp)->inobt_maxlevels, - xfs_inobt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_fibt_2); - } +ASSERT (btnum ==XFS_BTNUM_INO || btnum ==XFS_BTNUM_FINO ); +if (btnum ==XFS_BTNUM_FINO ) + ops = &xfs_finobt_ops; + + cur =xfs_btree_alloc_cursor (mp, tp, btnum, ops, +M_IGEO (mp)->inobt_maxlevels, xfs_inobt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag);return cur; }
libxfs/xfs_refcount_btree.c +1 -2
@@ -321,6 +321,7 @@ const struct xfs_btree_ops xfs_refcountbt_ops = { .key_len = sizeof(struct xfs_refcount_key), .lru_refs = XFS_REFC_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2), .dup_cursor = xfs_refcountbt_dup_cursor, .set_root = xfs_refcountbt_set_root,
@@ -356,8 +357,6 @@ xfs_refcountbt_init_common( cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_REFC , &xfs_refcountbt_ops, mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_refcbt_2); - cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ;
libxfs/xfs_rmap_btree.c +1 -2
@@ -477,6 +477,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .key_len = 2 * sizeof(struct xfs_rmap_key), .lru_refs = XFS_RMAP_BTREE_REF, + .statoff = XFS_STATS_CALC_INDEX(xs_rmap_2), .dup_cursor = xfs_rmapbt_dup_cursor, .set_root = xfs_rmapbt_set_root,
@@ -507,8 +508,6 @@ xfs_rmapbt_init_common(/* Overlapping btree; 2 keys per pointer. */ cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); - cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); - cur->bc_ag.pag =xfs_perag_hold (pag);return cur; }
PATCH 44/111 xfs: factor out a xfs_btree_owner helper
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 2054cf051698d30cc9479678c2b807a364248f38
Split out a helper to calculate the owner for a given btree instead of duplicating the logic in two places. While we're at it, make the bc_ag/bc_ino switch logic depend on the correct geometry flag.
--- libxfs/xfs_btree.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
libxfs/xfs_btree.c +11 -14
@@ -1219,6 +1219,15 @@ xfs_btree_init_buf( bp->b_ops = ops->buf_ops; } +static inline __u64 +xfs_btree_owner ( +struct xfs_btree_cur *cur) +{ +if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) +return cur->bc_ino.ip->i_ino; +return cur->bc_ag.pag->pag_agno; +} + void xfs_btree_init_block_cur( struct xfs_btree_cur *cur,
@@ -1226,20 +1235,8 @@ xfs_btree_init_block_cur( int level, int numrecs) { -__u64 owner; - -/* -* we can pull the owner from the cursor right now as the different -* owners align directly with the pointer size of the btree. This may -* change in future, but is safe for current users of the generic btree -* code. -*/ -if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) - owner = cur->bc_ino.ip->i_ino; -else - owner = cur->bc_ag.pag->pag_agno; - -xfs_btree_init_buf (cur->bc_mp, bp, cur->bc_ops, level, numrecs, owner); +xfs_btree_init_buf (cur->bc_mp, bp, cur->bc_ops, level, numrecs, +xfs_btree_owner (cur)); }/*
PATCH 45/111 xfs: factor out a btree block owner check
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 186f20c003199824eb3eb3b78e4eb7c2535a8ffc
Hoist the btree block owner check into a separate helper so that we don't have an ugly multiline if statement.
--- libxfs/xfs_btree.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
libxfs/xfs_btree.c +28 -5
@@ -1774,6 +1774,33 @@ xfs_btree_decrement(return error; } +/* +* Check the btree block owner now that we have the context to know who the +* real owner is. +*/ +static inline xfs_failaddr_t +xfs_btree_check_block_owner ( +struct xfs_btree_cur *cur, +struct xfs_btree_block *block) +{ +__u64 owner; + +if (!xfs_has_crc (cur->bc_mp) || + (cur->bc_flags &XFS_BTREE_BMBT_INVALID_OWNER )) +return NULL ; + + owner =xfs_btree_owner (cur); +if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) { +if (be64_to_cpu (block->bb_u.l.bb_owner) != owner) +return __this_address; + }else { +if (be32_to_cpu (block->bb_u.s.bb_owner) != owner) +return __this_address; + } + +return NULL ; +} + int xfs_btree_lookup_get_block( struct xfs_btree_cur *cur, /* btree cursor */
@@ -1812,11 +1839,7 @@ xfs_btree_lookup_get_block(return error;/* Check the inode owner since the verifiers don't. */ -if (xfs_has_crc (cur->bc_mp) && - !(cur->bc_flags &XFS_BTREE_BMBT_INVALID_OWNER ) && - (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) && -be64_to_cpu ((*blkp)->bb_u.l.bb_owner) != - cur->bc_ino.ip->i_ino) +if (xfs_btree_check_block_owner (cur, *blkp) !=NULL ) goto out_bad;/* Did we get the level we were looking for? */
PATCH 46/111 xfs: store the btree pointer length in struct xfs_btree_ops
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 1a9d26291c68fbb8f8d24f9f694b32223a072745
Make the pointer length an explicit field in the btree operations structure so that the next patch (which introduces an explicit btree type enum) doesn't have to play a bunch of awkward games with inferring the pointer length from the enumeration.
--- libxfs/xfs_alloc_btree.c | 2 ++ libxfs/xfs_bmap_btree.c | 3 ++ libxfs/xfs_btree.c | 57 ++++++++++++++++++------------------------- libxfs/xfs_btree.h | 26 ++++++++++++-------- libxfs/xfs_ialloc_btree.c | 2 ++ libxfs/xfs_refcount_btree.c | 1 + libxfs/xfs_rmap_btree.c | 1 + repair/bulkload.c | 2 +- 8 files changed, 49 insertions(+), 45 deletions(-)
libxfs/xfs_alloc_btree.c +2 -0
@@ -455,6 +455,7 @@ xfs_allocbt_keys_contiguous(const struct xfs_btree_ops xfs_bnobt_ops = { .rec_len =sizeof (xfs_alloc_rec_t), .key_len =sizeof (xfs_alloc_key_t), + .ptr_len =XFS_BTREE_SHORT_PTR_LEN , .lru_refs =XFS_ALLOC_BTREE_REF , .statoff =XFS_STATS_CALC_INDEX (xs_abtb_2),
@@ -483,6 +484,7 @@ const struct xfs_btree_ops xfs_cntbt_ops = { .rec_len = sizeof(xfs_alloc_rec_t), .key_len = sizeof(xfs_alloc_key_t), + .ptr_len = XFS_BTREE_SHORT_PTR_LEN, .lru_refs = XFS_ALLOC_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_abtc_2),
libxfs/xfs_bmap_btree.c +2 -1
@@ -524,10 +524,11 @@ xfs_bmbt_keys_contiguous( }const struct xfs_btree_ops xfs_bmbt_ops = { - .geom_flags =XFS_BTGEO_LONG_PTRS |XFS_BTGEO_ROOT_IN_INODE , + .geom_flags =XFS_BTGEO_ROOT_IN_INODE , .rec_len =sizeof (xfs_bmbt_rec_t), .key_len =sizeof (xfs_bmbt_key_t), + .ptr_len =XFS_BTREE_LONG_PTR_LEN , .lru_refs =XFS_BMAP_BTREE_REF , .statoff =XFS_STATS_CALC_INDEX (xs_bmbt_2),
libxfs/xfs_btree.c +24 -33
201 lines not on this page · raw message
libxfs/xfs_btree.h +16 -10
@@ -114,13 +114,17 @@ static inline enum xbtree_key_contig xbtree_key_contig(uint64_t x, uint64_t y)return XBTREE_KEY_OVERLAP ; } +#define XFS_BTREE_LONG_PTR_LEN (sizeof(__be64)) +#define XFS_BTREE_SHORT_PTR_LEN (sizeof(__be32)) +struct xfs_btree_ops {/* XFS_BTGEO_* flags that determine the geometry of the btree */ unsigned int geom_flags; -/* size of the key and record structures */ -size_t key_len; -size_t rec_len; +/* size of the key, pointer, and record structures */ +size_t key_len; +size_t ptr_len; +size_t rec_len;/* LRU refcount to set on each btree buffer created */ unsigned int lru_refs;
@@ -212,10 +216,9 @@ struct xfs_btree_ops { };/* btree geometry flags */ -#define XFS_BTGEO_LONG_PTRS (1U << 0)/* pointers are 64bits long */ -#define XFS_BTGEO_ROOT_IN_INODE (1U << 1)/* root may be variable size */ -#define XFS_BTGEO_LASTREC_UPDATE (1U << 2)/* track last rec externally */ -#define XFS_BTGEO_OVERLAPPING (1U << 3)/* overlapping intervals */ +#define XFS_BTGEO_ROOT_IN_INODE (1U << 0)/* root may be variable size */ +#define XFS_BTGEO_LASTREC_UPDATE (1U << 1)/* track last rec externally */ +#define XFS_BTGEO_OVERLAPPING (1U << 2)/* overlapping intervals */ /* * Reasons for the update_lastrec method to be called.
@@ -289,8 +292,8 @@ struct xfs_btree_cur/* * Short btree pointers need an agno to be able to turn the pointers * into physical addresses for IO, so the btree cursor switches between -* bc_ino and bc_ag based on whether XFS_BTGEO_LONG_PTRS is set for the -* cursor. +* bc_ino and bc_ag based on whether XFS_BTGEO_ROOT_IN_INODE is set for +* the cursor. */ union {struct xfs_btree_cur_ag bc_ag;
@@ -689,7 +692,7 @@ xfs_btree_islastblock( block =xfs_btree_get_block (cur, level, &bp); -if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) +if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN )return block->bb_u.l.bb_rightsib ==cpu_to_be64 (NULLFSBLOCK );return block->bb_u.s.bb_rightsib ==cpu_to_be32 (NULLAGBLOCK ); }
@@ -725,6 +728,9 @@ xfs_btree_alloc_cursor( {struct xfs_btree_cur *cur; +ASSERT (ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN || + ops->ptr_len ==XFS_BTREE_SHORT_PTR_LEN ); +/* BMBT allocations can come through from non-transactional context. */ cur =kmem_cache_zalloc (cache,GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
libxfs/xfs_ialloc_btree.c +2 -0
@@ -400,6 +400,7 @@ xfs_inobt_keys_contiguous(const struct xfs_btree_ops xfs_inobt_ops = { .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t), + .ptr_len =XFS_BTREE_SHORT_PTR_LEN , .lru_refs =XFS_INO_BTREE_REF , .statoff =XFS_STATS_CALC_INDEX (xs_ibt_2),
@@ -425,6 +426,7 @@ const struct xfs_btree_ops xfs_inobt_ops = {const struct xfs_btree_ops xfs_finobt_ops = { .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t), + .ptr_len =XFS_BTREE_SHORT_PTR_LEN , .lru_refs =XFS_INO_BTREE_REF , .statoff =XFS_STATS_CALC_INDEX (xs_fibt_2),
libxfs/xfs_refcount_btree.c +1 -0
@@ -319,6 +319,7 @@ xfs_refcountbt_keys_contiguous(const struct xfs_btree_ops xfs_refcountbt_ops = { .rec_len =sizeof (struct xfs_refcount_rec ), .key_len =sizeof (struct xfs_refcount_key ), + .ptr_len =XFS_BTREE_SHORT_PTR_LEN , .lru_refs =XFS_REFC_BTREE_REF , .statoff =XFS_STATS_CALC_INDEX (xs_refcbt_2),
libxfs/xfs_rmap_btree.c +1 -0
@@ -475,6 +475,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .rec_len = sizeof(struct xfs_rmap_rec), .key_len = 2 * sizeof(struct xfs_rmap_key), + .ptr_len = XFS_BTREE_SHORT_PTR_LEN, .lru_refs = XFS_RMAP_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_rmap_2),
repair/bulkload.c +1 -1
@@ -314,7 +314,7 @@ bulkload_claim_block(if (resv->used == resv->len)list_move_tail (&resv->list, &bkl->resv_list); -if (cur->bc_ops->geom_flags &XFS_BTGEO_LONG_PTRS ) +if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) ptr->l =cpu_to_be64 (XFS_AGB_TO_FSB (mp, resv->pag->pag_agno, agbno));else
PATCH 47/111 xfs: split out a btree type from the btree ops geometry flags
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4f0cd5a555072e21fb589975607b70798e073f8f
Two of the btree cursor flags are always used together and encode the fundamental btree type. There currently are two such types:
1) an on-disk AG-rooted btree with 32-bit pointers
2) an on-disk inode-rooted btree with 64-bit pointers
and we're about to add:
3) an in-memory btree with 64-bit pointers
Introduce a new enum and a new type field in struct xfs_btree_geom to encode this type directly instead of using flags and change most code to switch on this enum.
--- libxfs/xfs_alloc_btree.c | 3 ++ libxfs/xfs_bmap_btree.c | 2 + libxfs/xfs_btree.c | 66 +++++++++++++++++++++++-------------------- libxfs/xfs_btree.h | 15 +++++++--- libxfs/xfs_btree_staging.c | 12 ++++---- libxfs/xfs_btree_staging.h | 3 +- libxfs/xfs_ialloc_btree.c | 4 +++ libxfs/xfs_refcount_btree.c | 2 + libxfs/xfs_rmap_btree.c | 1 + 9 files changed, 65 insertions(+), 43 deletions(-)
libxfs/xfs_alloc_btree.c +3 -0
@@ -453,6 +453,8 @@ xfs_allocbt_keys_contiguous( }const struct xfs_btree_ops xfs_bnobt_ops = { + .type =XFS_BTREE_TYPE_AG , + .rec_len =sizeof (xfs_alloc_rec_t), .key_len =sizeof (xfs_alloc_key_t), .ptr_len =XFS_BTREE_SHORT_PTR_LEN ,
@@ -480,6 +482,7 @@ const struct xfs_btree_ops xfs_bnobt_ops = { };const struct xfs_btree_ops xfs_cntbt_ops = { + .type =XFS_BTREE_TYPE_AG , .geom_flags =XFS_BTGEO_LASTREC_UPDATE , .rec_len =sizeof (xfs_alloc_rec_t),
libxfs/xfs_bmap_btree.c +1 -1
@@ -524,7 +524,7 @@ xfs_bmbt_keys_contiguous( }const struct xfs_btree_ops xfs_bmbt_ops = { - .geom_flags =XFS_BTGEO_ROOT_IN_INODE , + .type =XFS_BTREE_TYPE_INODE , .rec_len =sizeof (xfs_bmbt_rec_t), .key_len =sizeof (xfs_bmbt_key_t),
libxfs/xfs_btree.c +36 -30
192 lines not on this page · raw message
libxfs/xfs_btree.h +11 -4
@@ -117,7 +117,15 @@ static inline enum xbtree_key_contig xbtree_key_contig(uint64_t x, uint64_t y)#define XFS_BTREE_LONG_PTR_LEN (sizeof(__be64))#define XFS_BTREE_SHORT_PTR_LEN (sizeof(__be32)) +enum xfs_btree_type { +XFS_BTREE_TYPE_AG , +XFS_BTREE_TYPE_INODE , +}; +struct xfs_btree_ops { +/* Type of btree - AG-rooted or inode-rooted */ +enum xfs_btree_type type; +/* XFS_BTGEO_* flags that determine the geometry of the btree */ unsigned int geom_flags;
@@ -216,9 +224,8 @@ struct xfs_btree_ops { };/* btree geometry flags */ -#define XFS_BTGEO_ROOT_IN_INODE (1U << 0)/* root may be variable size */ -#define XFS_BTGEO_LASTREC_UPDATE (1U << 1)/* track last rec externally */ -#define XFS_BTGEO_OVERLAPPING (1U << 2)/* overlapping intervals */ +#define XFS_BTGEO_LASTREC_UPDATE (1U << 0)/* track last rec externally */ +#define XFS_BTGEO_OVERLAPPING (1U << 1)/* overlapping intervals */ /* * Reasons for the update_lastrec method to be called.
@@ -292,7 +299,7 @@ struct xfs_btree_cur/* * Short btree pointers need an agno to be able to turn the pointers * into physical addresses for IO, so the btree cursor switches between -* bc_ino and bc_ag based on whether XFS_BTGEO_ROOT_IN_INODE is set for +* bc_ino and bc_ag based on bc_ops->type. * the cursor. */ union {
libxfs/xfs_btree_staging.c +6 -6
@@ -136,7 +136,7 @@ xfs_btree_stage_afakeroot(struct xfs_btree_ops *nops;ASSERT (!(cur->bc_flags &XFS_BTREE_STAGING )); -ASSERT (!(cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE )); +ASSERT (cur->bc_ops->type !=XFS_BTREE_TYPE_INODE );ASSERT (cur->bc_tp ==NULL ); nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);
@@ -217,7 +217,7 @@ xfs_btree_stage_ifakeroot(struct xfs_btree_ops *nops;ASSERT (!(cur->bc_flags &XFS_BTREE_STAGING )); -ASSERT (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ); +ASSERT (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE );ASSERT (cur->bc_tp ==NULL ); nops =kmalloc (sizeof (struct xfs_btree_ops ),GFP_KERNEL | __GFP_NOFAIL);
@@ -397,7 +397,7 @@ xfs_btree_bload_prep_block(struct xfs_btree_block *new_block;int ret; -if ((cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) && +if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && level == cur->bc_nlevels -1 ) {struct xfs_ifork *ifp =xfs_btree_ifork_ptr (cur);size_t new_size;
@@ -702,7 +702,7 @@ xfs_btree_bload_compute_geometry(xfs_btree_bload_level_geometry (cur, bbl, level, nr_this_level, &avg_per_block, &level_blocks, &dontcare64); -if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) { +if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) {/* * If all the items we want to store at this level * would fit in the inode root block, then we have our
@@ -761,7 +761,7 @@ xfs_btree_bload_compute_geometry(return -EOVERFLOW ; bbl->btree_height = cur->bc_nlevels; -if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) +if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) bbl->nr_blocks = nr_blocks -1 ;else bbl->nr_blocks = nr_blocks;
@@ -888,7 +888,7 @@ xfs_btree_bload( }/* Initialize the new root. */ -if (cur->bc_ops->geom_flags &XFS_BTGEO_ROOT_IN_INODE ) { +if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) {ASSERT (xfs_btree_ptr_is_null (cur, &ptr)); cur->bc_ino.ifake->if_levels = cur->bc_nlevels; cur->bc_ino.ifake->if_blocks = total_blocks -1 ;
libxfs/xfs_btree_staging.h +1 -2
@@ -76,8 +76,7 @@ struct xfs_btree_bload {/* * This function should return the size of the in-core btree root -* block. It is only necessary for XFS_BTGEO_ROOT_IN_INODE btree -* types. +* block. It is only necessary for XFS_BTREE_TYPE_INODE btrees. */ xfs_btree_bload_iroot_size_fn iroot_size;
libxfs/xfs_ialloc_btree.c +4 -0
@@ -398,6 +398,8 @@ xfs_inobt_keys_contiguous( }const struct xfs_btree_ops xfs_inobt_ops = { + .type =XFS_BTREE_TYPE_AG , + .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t), .ptr_len =XFS_BTREE_SHORT_PTR_LEN ,
@@ -424,6 +426,8 @@ const struct xfs_btree_ops xfs_inobt_ops = { };const struct xfs_btree_ops xfs_finobt_ops = { + .type =XFS_BTREE_TYPE_AG , + .rec_len =sizeof (xfs_inobt_rec_t), .key_len =sizeof (xfs_inobt_key_t), .ptr_len =XFS_BTREE_SHORT_PTR_LEN ,
libxfs/xfs_refcount_btree.c +2 -0
@@ -317,6 +317,8 @@ xfs_refcountbt_keys_contiguous( }const struct xfs_btree_ops xfs_refcountbt_ops = { + .type =XFS_BTREE_TYPE_AG , + .rec_len =sizeof (struct xfs_refcount_rec ), .key_len =sizeof (struct xfs_refcount_key ), .ptr_len =XFS_BTREE_SHORT_PTR_LEN ,
libxfs/xfs_rmap_btree.c +1 -0
@@ -471,6 +471,7 @@ xfs_rmapbt_keys_contiguous( }const struct xfs_btree_ops xfs_rmapbt_ops = { + .type =XFS_BTREE_TYPE_AG , .geom_flags =XFS_BTGEO_OVERLAPPING , .rec_len =sizeof (struct xfs_rmap_rec ),
PATCH 48/111 xfs: split the per-btree union in struct xfs_btree_cur
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 88ee2f4849119b82b95d6e8e2d9daa81214eb080
Split up the union that encodes btree-specific fields in struct xfs_btree_cur. Most fields in there are specific to the btree type encoded in xfs_btree_ops.type, and we can use the obviously named union for that. But one field is specific to the bmapbt and two are shared by the refcount and rtrefcountbt. Move those to a separate union to make the usage clear and not need a separate struct for the refcount-related fields.
This will also make unnecessary some very awkward btree cursor refc/rtrefc switching logic in the rtrefcount patchset.
--- libxfs/xfs_bmap.c | 22 +++++++++-------- libxfs/xfs_bmap_btree.c | 9 +++---- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree.h | 55 ++++++++++++++++++------------------------- libxfs/xfs_btree_staging.c | 1 + libxfs/xfs_refcount.c | 24 +++++++++---------- libxfs/xfs_refcount_btree.c | 4 ++- 7 files changed, 54 insertions(+), 63 deletions(-)
libxfs/xfs_bmap.c +11 -11
@@ -670,7 +670,7 @@ xfs_bmap_extents_to_btree( goto out_root_realloc; } - cur->bc_ino.allocated++; + cur->bc_bmap.allocated++; ip->i_nblocks++;xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_BCOUNT ,1L ); error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
@@ -888,7 +888,7 @@ xfs_bmap_add_attrfork_btree(xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR );return -ENOSPC ; } - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ;xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); }return 0 ;
@@ -916,7 +916,7 @@ xfs_bmap_add_attrfork_extents( error =xfs_bmap_extents_to_btree (tp, ip, &cur,0 , flags,XFS_DATA_FORK );if (cur) { - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ;xfs_btree_del_cursor (cur, error); }return error;
@@ -1740,7 +1740,7 @@ xfs_bmap_add_extent_delay_real( temp =PREV .br_blockcount - new->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock) - - (bma->cur ? bma->cur->bc_ino.allocated :0 )); + (bma->cur ? bma->cur->bc_bmap.allocated :0 ));PREV .br_startoff = new_endoff;PREV .br_blockcount = temp;
@@ -1830,7 +1830,7 @@ xfs_bmap_add_extent_delay_real( temp =PREV .br_blockcount - new->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock) - - (bma->cur ? bma->cur->bc_ino.allocated :0 )); + (bma->cur ? bma->cur->bc_bmap.allocated :0 ));PREV .br_startblock =nullstartblock (da_new);PREV .br_blockcount = temp;
@@ -1953,8 +1953,8 @@ xfs_bmap_add_extent_delay_real(xfs_mod_delalloc (mp, (int64_t )da_new - da_old);if (bma->cur) { - da_new += bma->cur->bc_ino.allocated; - bma->cur->bc_ino.allocated =0 ; + da_new += bma->cur->bc_bmap.allocated; + bma->cur->bc_bmap.allocated =0 ; }/* adjust for changes in reserved delayed indirect blocks */
@@ -2519,7 +2519,7 @@ xfs_bmap_add_extent_unwritten_real(/* clear out the allocated field, done with it now in any case. */ if (cur) { - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ; *curp = cur; }
@@ -2907,7 +2907,7 @@ xfs_bmap_add_extent_hole_real(/* clear out the allocated field, done with it now in any case. */ if (cur) - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ;xfs_bmap_check_leaf_extents (cur, ip, whichfork); done:
@@ -5623,7 +5623,7 @@ __xfs_bunmapi(xfs_trans_log_inode (tp, ip, logflags);if (cur) {if (!error) - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ;xfs_btree_del_cursor (cur, error); }return error;
@@ -6139,7 +6139,7 @@ xfs_bmap_split_extent( del_cursor:if (cur) { - cur->bc_ino.allocated =0 ; + cur->bc_bmap.allocated =0 ;xfs_btree_del_cursor (cur, error); }
libxfs/xfs_bmap_btree.c +4 -5
@@ -197,10 +197,10 @@ xfs_bmbt_update_cursor(ASSERT ((dst->bc_tp->t_highest_agno !=NULLAGNUMBER ) || (dst->bc_ino.ip->i_diflags &XFS_DIFLAG_REALTIME )); - dst->bc_ino.allocated += src->bc_ino.allocated; + dst->bc_bmap.allocated += src->bc_bmap.allocated; dst->bc_tp->t_highest_agno = src->bc_tp->t_highest_agno; - src->bc_ino.allocated =0 ; + src->bc_bmap.allocated =0 ; }STATIC int
@@ -255,7 +255,7 @@ xfs_bmbt_alloc_block( }ASSERT (args.len ==1 ); - cur->bc_ino.allocated++; + cur->bc_bmap.allocated++; cur->bc_ino.ip->i_nblocks++;xfs_trans_log_inode (args.tp, cur->bc_ino.ip,XFS_ILOG_CORE ); xfs_trans_mod_dquot_byino(args.tp, cur->bc_ino.ip,
@@ -567,8 +567,7 @@ xfs_bmbt_init_common( mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); cur->bc_ino.ip = ip; - cur->bc_ino.allocated =0 ; - + cur->bc_bmap.allocated =0 ;return cur; }
libxfs/xfs_btree.c +1 -1
@@ -442,7 +442,7 @@ xfs_btree_del_cursor(* zero, then we should be shut down or on our way to shutdown due to * cancelling a dirty transaction on error. */ -ASSERT (cur->bc_btnum !=XFS_BTNUM_BMAP || cur->bc_ino.allocated ==0 || +ASSERT (cur->bc_btnum !=XFS_BTNUM_BMAP || cur->bc_bmap.allocated ==0 ||xfs_is_shutdown (cur->bc_mp) || error !=0 );switch (cur->bc_ops->type) {
libxfs/xfs_btree.h +23 -32
68 lines not on this page · raw message
libxfs/xfs_btree_staging.c +1 -0
@@ -172,6 +172,7 @@ xfs_btree_commit_afakeroot(trace_xfs_btree_commit_afakeroot (cur);kfree ((void *)cur->bc_ops); + cur->bc_ag.afake =NULL ; cur->bc_ag.agbp = agbp; cur->bc_ops = ops; cur->bc_flags &= ~XFS_BTREE_STAGING ;
libxfs/xfs_refcount.c +12 -12
@@ -1076,7 +1076,7 @@ xfs_refcount_still_have_space(* to handle each of the shape changes to the refcount btree. */ overhead =xfs_allocfree_block_count (cur->bc_mp, - cur->bc_ag.refc.shape_changes); + cur->bc_refc.shape_changes); overhead += cur->bc_mp->m_refc_maxlevels; overhead *= cur->bc_mp->m_sb.sb_blocksize;
@@ -1084,17 +1084,17 @@ xfs_refcount_still_have_space(* Only allow 2 refcount extent updates per transaction if the * refcount continue update "error" has been injected. */ -if (cur->bc_ag.refc.nr_ops >2 && +if (cur->bc_refc.nr_ops >2 &&XFS_TEST_ERROR (false, cur->bc_mp,XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE ))return false; -if (cur->bc_ag.refc.nr_ops ==0 ) +if (cur->bc_refc.nr_ops ==0 )return true;else if (overhead > cur->bc_tp->t_log_res)return false; -return cur->bc_tp->t_log_res - overhead > - cur->bc_ag.refc.nr_ops *XFS_REFCOUNT_ITEM_OVERHEAD ; +return cur->bc_tp->t_log_res - overhead > + cur->bc_refc.nr_ops *XFS_REFCOUNT_ITEM_OVERHEAD ; }/*
@@ -1154,7 +1154,7 @@ xfs_refcount_adjust_extents(* Either cover the hole (increment) or * delete the range (decrement). */ - cur->bc_ag.refc.nr_ops++; + cur->bc_refc.nr_ops++;if (tmp.rc_refcount) { error =xfs_refcount_insert (cur, &tmp, &found_tmp);
@@ -1215,7 +1215,7 @@ xfs_refcount_adjust_extents( ext.rc_refcount += adj;trace_xfs_refcount_modify_extent (cur->bc_mp, cur->bc_ag.pag->pag_agno, &ext); - cur->bc_ag.refc.nr_ops++; + cur->bc_refc.nr_ops++;if (ext.rc_refcount >1 ) { error =xfs_refcount_update (cur, &ext);if (error)
@@ -1304,7 +1304,7 @@ xfs_refcount_adjust(if (shape_changed) shape_changes++;if (shape_changes) - cur->bc_ag.refc.shape_changes++; + cur->bc_refc.shape_changes++;/* Now that we've taken care of the ends, adjust the middle extents */ error =xfs_refcount_adjust_extents (cur, agbno, aglen, adj);
@@ -1399,8 +1399,8 @@ xfs_refcount_finish_one(*/ rcur = *pcur;if (rcur !=NULL && rcur->bc_ag.pag != ri->ri_pag) { - nr_ops = rcur->bc_ag.refc.nr_ops; - shape_changes = rcur->bc_ag.refc.shape_changes; + nr_ops = rcur->bc_refc.nr_ops; + shape_changes = rcur->bc_refc.shape_changes;xfs_refcount_finish_one_cleanup (tp, rcur,0 ); rcur =NULL ; *pcur =NULL ;
@@ -1412,8 +1412,8 @@ xfs_refcount_finish_one(return error; rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, ri->ri_pag); - rcur->bc_ag.refc.nr_ops = nr_ops; - rcur->bc_ag.refc.shape_changes = shape_changes; + rcur->bc_refc.nr_ops = nr_ops; + rcur->bc_refc.shape_changes = shape_changes; } *pcur = rcur;
libxfs/xfs_refcount_btree.c +2 -2
@@ -361,8 +361,8 @@ xfs_refcountbt_init_common( &xfs_refcountbt_ops, mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); - cur->bc_ag.refc.nr_ops =0 ; - cur->bc_ag.refc.shape_changes =0 ; + cur->bc_refc.nr_ops =0 ; + cur->bc_refc.shape_changes =0 ;return cur; }
PATCH 49/111 xfs: create predicate to determine if cursor is at inode root level
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: f73def90a7cd24a32a42f689efba6a7a35edeb7b
Create a predicate to decide if the given cursor and level point to the root block in the inode immediate area instead of a disk block, and get rid of the open-coded logic everywhere.
--- libxfs/xfs_btree.c | 56 +++++++++++++++++++------------------------- libxfs/xfs_btree.h | 10 ++++++++ libxfs/xfs_btree_staging.c | 3 +- 3 files changed, 35 insertions(+), 34 deletions(-)
libxfs/xfs_btree.c +24 -32
@@ -746,8 +746,7 @@ xfs_btree_get_block(int level,/* level in btree */ struct xfs_buf **bpp) /* buffer containing the block */ { -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - level == cur->bc_nlevels -1 ) { + if (xfs_btree_at_iroot(cur, level)) { *bpp =NULL ;return xfs_btree_get_iroot (cur); }
@@ -989,8 +988,7 @@ xfs_btree_readahead(* No readahead needed if we are at the root level and the * btree root is stored in the inode. */ -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - lev == cur->bc_nlevels -1 ) +if (xfs_btree_at_iroot (cur, lev))return 0 ;if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra)
@@ -1811,8 +1809,7 @@ xfs_btree_lookup_get_block(int error =0 ;/* special case the root block if in an inode */ -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - level == cur->bc_nlevels -1 ) { +if (xfs_btree_at_iroot (cur, level)) { *blkp =xfs_btree_get_iroot (cur);return 0 ; }
@@ -2347,8 +2344,7 @@ xfs_btree_lshift(int error;/* error return value */ int i; -if ((cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) && - level == cur->bc_nlevels -1 ) +if (xfs_btree_at_iroot (cur, level)) goto out0;/* Set up variables for this block as "right". */
@@ -2543,8 +2539,7 @@ xfs_btree_rshift(int error;/* error return value */ int i;/* loop counter */ -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - level == cur->bc_nlevels -1 ) +if (xfs_btree_at_iroot (cur, level)) goto out0;/* Set up variables for this block as "left". */
@@ -3243,8 +3238,7 @@ xfs_btree_make_block_unfull( {int error =0 ; -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - level == cur->bc_nlevels -1 ) { +if (xfs_btree_at_iroot (cur, level)) {struct xfs_inode *ip = cur->bc_ino.ip;if (numrecs < cur->bc_ops->get_dmaxrecs (cur, level)) {
@@ -3853,27 +3847,25 @@ xfs_btree_delrec(* Try to get rid of the next level down. If we can't then there's * nothing left to do. */ +if (xfs_btree_at_iroot (cur, level)) { +xfs_iroot_realloc (cur->bc_ino.ip,-1 , cur->bc_ino.whichfork); + + error =xfs_btree_kill_iroot (cur); +if (error) + goto error0; + + error =xfs_btree_dec_cursor (cur, level, stat); +if (error) + goto error0; + *stat =1 ; +return 0 ; + } + +/* +* If this is the root level, and there's only one entry left, and it's +* NOT the leaf level, then we can get rid of this level. +*/ if (level == cur->bc_nlevels -1 ) { -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) { -xfs_iroot_realloc (cur->bc_ino.ip,-1 , - cur->bc_ino.whichfork); - - error =xfs_btree_kill_iroot (cur); -if (error) - goto error0; - - error =xfs_btree_dec_cursor (cur, level, stat); -if (error) - goto error0; - *stat =1 ; -return 0 ; - } - -/* -* If this is the root level, and there's only one entry left, -* and it's NOT the leaf level, then we can get rid of this -* level. -*/ if (numrecs ==1 && level >0 ) {union xfs_btree_ptr *pp;/*
libxfs/xfs_btree.h +10 -0
@@ -747,4 +747,14 @@ void xfs_btree_destroy_cur_caches(void);int xfs_btree_goto_left_edge (struct xfs_btree_cur *cur); +/* Does this level of the cursor point to the inode root (and not a block)? */ +static inline bool +xfs_btree_at_iroot ( +const struct xfs_btree_cur *cur, +int level) +{ +return cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && + level == cur->bc_nlevels -1 ; +} +#endif /* __XFS_BTREE_H__ */
libxfs/xfs_btree_staging.c +1 -2
@@ -398,8 +398,7 @@ xfs_btree_bload_prep_block(struct xfs_btree_block *new_block;int ret; -if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE && - level == cur->bc_nlevels -1 ) { +if (xfs_btree_at_iroot (cur, level)) {struct xfs_ifork *ifp =xfs_btree_ifork_ptr (cur);size_t new_size;
PATCH 50/111 xfs: move comment about two 2 keys per pointer in the rmap btree
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 72c2070f3f52196a2e8b4efced94390b62eb8ac4
Move it to the relevant initialization of the ops structure instead of a place that has nothing to do with the key size.
--- libxfs/xfs_rmap_btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_rmap_btree.c +1 -1
@@ -475,6 +475,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .geom_flags = XFS_BTGEO_OVERLAPPING, .rec_len = sizeof(struct xfs_rmap_rec), +/* Overlapping btree; 2 keys per pointer. */ .key_len = 2 * sizeof(struct xfs_rmap_key), .ptr_len = XFS_BTREE_SHORT_PTR_LEN,
@@ -507,7 +508,6 @@ xfs_rmapbt_init_common( {struct xfs_btree_cur *cur; -/* Overlapping btree; 2 keys per pointer. */ cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag);
PATCH 51/111 xfs: add a xfs_btree_init_ptr_from_cur
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: f9c18129e57df7b33f4257340840525816481da6
Inode-rooted btrees don't need to initialize the root pointer in the ->init_ptr_from_cur method as the root is found by the xfs_btree_get_iroot method later. Make ->init_ptr_from_cur option for inode rooted btrees by providing a helper that does the right thing for the given btree type and also documents the semantics.
--- libxfs/xfs_bmap_btree.c | 9 --------- libxfs/xfs_btree.c | 27 +++++++++++++++++++++++---- libxfs/xfs_btree.h | 2 ++ libxfs/xfs_btree_staging.c | 1 - 4 files changed, 25 insertions(+), 14 deletions(-)
libxfs/xfs_bmap_btree.c +0 -9
@@ -368,14 +368,6 @@ xfs_bmbt_init_rec_from_cur(xfs_bmbt_disk_set_all (&rec->bmbt, &cur->bc_rec.b); } -STATIC void -xfs_bmbt_init_ptr_from_cur ( -struct xfs_btree_cur *cur, -union xfs_btree_ptr *ptr) -{ - ptr->l =0 ; -} - STATIC int64_t xfs_bmbt_key_diff( struct xfs_btree_cur *cur,
@@ -543,7 +535,6 @@ const struct xfs_btree_ops xfs_bmbt_ops = { .init_key_from_rec = xfs_bmbt_init_key_from_rec, .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec, .init_rec_from_cur = xfs_bmbt_init_rec_from_cur, - .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur, .key_diff = xfs_bmbt_key_diff, .diff_two_keys = xfs_bmbt_diff_two_keys, .buf_ops = &xfs_bmbt_buf_ops,
libxfs/xfs_btree.c +23 -4
@@ -1878,6 +1878,25 @@ xfs_lookup_get_search_key(return xfs_btree_key_addr (cur, keyno, block); } +/* +* Initialize a pointer to the root block. +*/ +void +xfs_btree_init_ptr_from_cur ( +struct xfs_btree_cur *cur, +union xfs_btree_ptr *ptr) +{ +if (cur->bc_ops->type ==XFS_BTREE_TYPE_INODE ) { +/* +* Inode-rooted btrees call xfs_btree_get_iroot to find the root +* in xfs_btree_lookup_get_block and don't need a pointer here. +*/ + ptr->l =0 ; + }else { + cur->bc_ops->init_ptr_from_cur (cur, ptr); + } +} +/* * Lookup the record. The cursor is made to point to it, based on dir. * stat is set to 0 if can't find any such record, 1 for success.
@@ -1908,7 +1927,7 @@ xfs_btree_lookup( keyno =0 ;/* initialise start pointer from cursor */ - cur->bc_ops->init_ptr_from_cur (cur, &ptr); +xfs_btree_init_ptr_from_cur (cur, &ptr); pp = &ptr;/*
@@ -3118,7 +3137,7 @@ xfs_btree_new_root(XFS_BTREE_STATS_INC (cur, newroot);/* initialise our start point from the cursor */ - cur->bc_ops->init_ptr_from_cur (cur, &rptr); +xfs_btree_init_ptr_from_cur (cur, &rptr);/* Allocate the new block. If we can't do it, we're toast. Give up. */ error =xfs_btree_alloc_block (cur, &rptr, &lptr, stat);
@@ -4427,7 +4446,7 @@ xfs_btree_visit_blocks(struct xfs_btree_block *block =NULL ;int error =0 ; - cur->bc_ops->init_ptr_from_cur (cur, &lptr); +xfs_btree_init_ptr_from_cur (cur, &lptr);/* for each level */ for (level = cur->bc_nlevels -1 ; level >=0 ; level--) {
@@ -4849,7 +4868,7 @@ xfs_btree_overlapped_query_range(/* Load the root of the btree. */ level = cur->bc_nlevels -1 ; - cur->bc_ops->init_ptr_from_cur (cur, &ptr); +xfs_btree_init_ptr_from_cur (cur, &ptr); error =xfs_btree_lookup_get_block (cur, level, &ptr, &block);if (error)return error;
libxfs/xfs_btree.h +2 -0
@@ -714,6 +714,8 @@ void xfs_btree_copy_ptrs(struct xfs_btree_cur *cur,void xfs_btree_copy_keys (struct xfs_btree_cur *cur,union xfs_btree_key *dst_key,const union xfs_btree_key *src_key,int numkeys); +void xfs_btree_init_ptr_from_cur (struct xfs_btree_cur *cur, +union xfs_btree_ptr *ptr);static inline struct xfs_btree_cur * xfs_btree_alloc_cursor(
libxfs/xfs_btree_staging.c +0 -1
@@ -225,7 +225,6 @@ xfs_btree_stage_ifakeroot(memcpy (nops, cur->bc_ops,sizeof (struct xfs_btree_ops )); nops->alloc_block = xfs_btree_fakeroot_alloc_block; nops->free_block = xfs_btree_fakeroot_free_block; - nops->init_ptr_from_cur = xfs_btree_fakeroot_init_ptr_from_cur; nops->dup_cursor = xfs_btree_fakeroot_dup_cursor; cur->bc_ino.ifake = ifake;
PATCH 52/111 xfs: don't override bc_ops for staging btrees
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 2b9e7f2668c540f18afd66a053ea78f3a629f8e2
Add a few conditionals for staging btrees to the core btree code instead of overloading the bc_ops vector.
--- libxfs/xfs_alloc_btree.c | 6 -- libxfs/xfs_bmap_btree.c | 6 +- libxfs/xfs_btree.c | 75 +++++++++++++++++++++++------- libxfs/xfs_btree_staging.c | 109 +------------------------------------------ libxfs/xfs_btree_staging.h | 7 +-- libxfs/xfs_ialloc_btree.c | 4 +- libxfs/xfs_refcount_btree.c | 2 - libxfs/xfs_rmap_btree.c | 2 - 8 files changed, 72 insertions(+), 139 deletions(-)
libxfs/xfs_alloc_btree.c +1 -5
@@ -592,11 +592,7 @@ xfs_allocbt_commit_staged_btree( agf->agf_levels[cur->bc_btnum] =cpu_to_be32 (afake->af_levels);xfs_alloc_log_agf (tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS ); -if (cur->bc_btnum ==XFS_BTNUM_BNO ) { -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_bnobt_ops); - }else { -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_cntbt_ops); - } +xfs_btree_commit_afakeroot (cur, tp, agbp); }/* Calculate number of records in an alloc btree block. */
libxfs/xfs_bmap_btree.c +2 -4
@@ -608,7 +608,6 @@ xfs_bmbt_stage_cursor( struct xbtree_ifakeroot *ifake) {struct xfs_btree_cur *cur; -struct xfs_btree_ops *ops;/* data fork always has larger maxheight */ cur =xfs_bmbt_init_common (mp,NULL , ip,XFS_DATA_FORK );
@@ -617,8 +616,7 @@ xfs_bmbt_stage_cursor(/* Don't let anyone think we're attached to the real fork yet. */ cur->bc_ino.whichfork =-1 ; -xfs_btree_stage_ifakeroot (cur, ifake, &ops); - ops->update_cursor =NULL ; +xfs_btree_stage_ifakeroot (cur, ifake);return cur; }
@@ -662,7 +660,7 @@ xfs_bmbt_commit_staged_btree(break ; }xfs_trans_log_inode (tp, cur->bc_ino.ip, flags); -xfs_btree_commit_ifakeroot (cur, tp, whichfork, &xfs_bmbt_ops); +xfs_btree_commit_ifakeroot (cur, tp, whichfork); }/*
libxfs/xfs_btree.c +59 -16
132 lines not on this page · raw message
libxfs/xfs_btree_staging.c +3 -106
177 lines not on this page · raw message
libxfs/xfs_btree_staging.h +3 -4
@@ -22,7 +22,7 @@ struct xbtree_afakeroot {void xfs_btree_stage_afakeroot (struct xfs_btree_cur *cur,struct xbtree_afakeroot *afake);void xfs_btree_commit_afakeroot (struct xfs_btree_cur *cur,struct xfs_trans *tp, -struct xfs_buf *agbp,const struct xfs_btree_ops *ops); +struct xfs_buf *agbp);/* Fake root for an inode-rooted btree. */ struct xbtree_ifakeroot {
@@ -41,10 +41,9 @@ struct xbtree_ifakeroot {/* Cursor interactions with fake roots for inode-rooted btrees. */ void xfs_btree_stage_ifakeroot (struct xfs_btree_cur *cur, -struct xbtree_ifakeroot *ifake, -struct xfs_btree_ops **new_ops); +struct xbtree_ifakeroot *ifake);void xfs_btree_commit_ifakeroot (struct xfs_btree_cur *cur,struct xfs_trans *tp, -int whichfork,const struct xfs_btree_ops *ops); +int whichfork);/* Bulk loading of staged btrees. */ typedef int (*xfs_btree_bload_get_records_fn)(struct xfs_btree_cur *cur,
libxfs/xfs_ialloc_btree.c +2 -2
@@ -536,7 +536,7 @@ xfs_inobt_commit_staged_btree( fields |=XFS_AGI_IBLOCKS ; }xfs_ialloc_log_agi (tp, agbp, fields); -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_inobt_ops); +xfs_btree_commit_afakeroot (cur, tp, agbp); }else { fields =XFS_AGI_FREE_ROOT |XFS_AGI_FREE_LEVEL ; agi->agi_free_root =cpu_to_be32 (afake->af_root);
@@ -546,7 +546,7 @@ xfs_inobt_commit_staged_btree( fields |=XFS_AGI_IBLOCKS ; }xfs_ialloc_log_agi (tp, agbp, fields); -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_finobt_ops); +xfs_btree_commit_afakeroot (cur, tp, agbp); } }
libxfs/xfs_refcount_btree.c +1 -1
@@ -418,7 +418,7 @@ xfs_refcountbt_commit_staged_btree(xfs_alloc_log_agf (tp, agbp,XFS_AGF_REFCOUNT_BLOCKS |XFS_AGF_REFCOUNT_ROOT |XFS_AGF_REFCOUNT_LEVEL ); -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_refcountbt_ops); +xfs_btree_commit_afakeroot (cur, tp, agbp); }/* Calculate number of records in a refcount btree block. */
libxfs/xfs_rmap_btree.c +1 -1
@@ -565,7 +565,7 @@ xfs_rmapbt_commit_staged_btree( agf->agf_rmap_blocks =cpu_to_be32 (afake->af_blocks);xfs_alloc_log_agf (tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS |XFS_AGF_RMAP_BLOCKS ); -xfs_btree_commit_afakeroot (cur, tp, agbp, &xfs_rmapbt_ops); +xfs_btree_commit_afakeroot (cur, tp, agbp); }/* Calculate number of records in a reverse mapping btree block. */
PATCH 53/111 xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: fb518f8eeb90197624b21a3429e57b6a65bff7bb
Make the levels initialization in xfs_allocbt_init_cursor conditional and merge the two helpers.
--- libxfs/xfs_alloc_btree.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-)
libxfs/xfs_alloc_btree.c +15 -27
@@ -511,11 +511,16 @@ const struct xfs_btree_ops xfs_cntbt_ops = { .keys_contiguous = NULL, /* not needed right now */ }; -/* Allocate most of a new allocation btree cursor. */ -STATIC struct xfs_btree_cur * -xfs_allocbt_init_common ( +/* +* Allocate a new allocation btree cursor. +* +* For staging cursors tp and agbp are NULL. +*/ +struct xfs_btree_cur * +xfs_allocbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp, +struct xfs_buf *agbp,struct xfs_perag *pag,xfs_btnum_t btnum) {
@@ -530,31 +535,14 @@ xfs_allocbt_init_common( cur =xfs_btree_alloc_cursor (mp, tp, btnum, ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); -return cur; -} - -/* -* Allocate a new allocation btree cursor. -*/ -struct xfs_btree_cur */* new alloc btree cursor */ -xfs_allocbt_init_cursor ( -struct xfs_mount *mp,/* file system mount point */ -struct xfs_trans *tp,/* transaction pointer */ -struct xfs_buf *agbp,/* buffer for agf structure */ -struct xfs_perag *pag, -xfs_btnum_t btnum)/* btree identifier */ -{ -struct xfs_agf *agf = agbp->b_addr; -struct xfs_btree_cur *cur; - - cur =xfs_allocbt_init_common (mp, tp, pag, btnum); -if (btnum ==XFS_BTNUM_CNT ) - cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]); -else - cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]); - cur->bc_ag.agbp = agbp; +if (agbp) { +struct xfs_agf *agf = agbp->b_addr; + cur->bc_nlevels = (btnum ==XFS_BTNUM_BNO ) ? +be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]) : +be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]); + }return cur; }
@@ -568,7 +556,7 @@ xfs_allocbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_allocbt_init_common (mp,NULL , pag, btnum); + cur =xfs_allocbt_init_cursor (mp,NULL ,NULL , pag, btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
PATCH 54/111 xfs: remove xfs_allocbt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 91796b2eef8bd725873bec326a7be830a68a11ff
Just open code the two calls in the callers.
--- libxfs/libxfs_api_defs.h | 2 ++ libxfs/xfs_alloc_btree.c | 15 --------------- libxfs/xfs_alloc_btree.h | 3 --- repair/agbtree.c | 11 +++++++---- 4 files changed, 9 insertions(+), 22 deletions(-)
libxfs/libxfs_api_defs.h +2 -0
@@ -26,6 +26,7 @@#define xfs_alloc_ag_max_usable libxfs_alloc_ag_max_usable#define xfs_allocbt_calc_size libxfs_allocbt_calc_size +#define xfs_allocbt_init_cursor libxfs_allocbt_init_cursor#define xfs_allocbt_maxlevels_ondisk libxfs_allocbt_maxlevels_ondisk#define xfs_allocbt_maxrecs libxfs_allocbt_maxrecs#define xfs_allocbt_stage_cursor libxfs_allocbt_stage_cursor
@@ -63,6 +64,7 @@#define xfs_btree_del_cursor libxfs_btree_del_cursor#define xfs_btree_init_block libxfs_btree_init_block#define xfs_btree_rec_addr libxfs_btree_rec_addr +#define xfs_btree_stage_afakeroot libxfs_btree_stage_afakeroot#define xfs_buf_delwri_submit libxfs_buf_delwri_submit#define xfs_buf_get libxfs_buf_get#define xfs_buf_get_uncached libxfs_buf_get_uncached
libxfs/xfs_alloc_btree.c +0 -15
@@ -546,21 +546,6 @@ xfs_allocbt_init_cursor(return cur; } -/* Create a free space btree cursor with a fake root for staging. */ -struct xfs_btree_cur * -xfs_allocbt_stage_cursor ( -struct xfs_mount *mp, -struct xbtree_afakeroot *afake, -struct xfs_perag *pag, -xfs_btnum_t btnum) -{ -struct xfs_btree_cur *cur; - - cur =xfs_allocbt_init_cursor (mp,NULL ,NULL , pag, btnum); -xfs_btree_stage_afakeroot (cur, afake); -return cur; -} -/* * Install a new free space btree root. Caller is responsible for invalidating * and freeing the old btree blocks.
libxfs/xfs_alloc_btree.h +0 -3
@@ -50,9 +50,6 @@ struct xbtree_afakeroot;extern struct xfs_btree_cur *xfs_allocbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_perag *pag,xfs_btnum_t btnum); -struct xfs_btree_cur *xfs_allocbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,struct xfs_perag *pag, -xfs_btnum_t btnum);extern int xfs_allocbt_maxrecs (struct xfs_mount *,int ,int );extern xfs_extlen_t xfs_allocbt_calc_size (struct xfs_mount *mp,unsigned long long len);
repair/agbtree.c +7 -4
@@ -262,10 +262,13 @@ init_freespace_cursors(init_rebuild (sc, &XFS_RMAP_OINFO_AG , est_agfreeblocks, btr_bno);init_rebuild (sc, &XFS_RMAP_OINFO_AG , est_agfreeblocks, btr_cnt); - btr_bno->cur =libxfs_allocbt_stage_cursor (sc->mp, - &btr_bno->newbt.afake, pag,XFS_BTNUM_BNO ); - btr_cnt->cur =libxfs_allocbt_stage_cursor (sc->mp, - &btr_cnt->newbt.afake, pag,XFS_BTNUM_CNT ); + btr_bno->cur =libxfs_allocbt_init_cursor (sc->mp,NULL ,NULL , pag, +XFS_BTNUM_BNO ); +libxfs_btree_stage_afakeroot (btr_bno->cur, &btr_bno->newbt.afake); + + btr_cnt->cur =libxfs_allocbt_init_cursor (sc->mp,NULL ,NULL , pag, +XFS_BTNUM_CNT ); +libxfs_btree_stage_afakeroot (btr_cnt->cur, &btr_cnt->newbt.afake); btr_bno->bload.get_records = get_bnobt_records; btr_bno->bload.claim_block = rebuild_claim_block;
PATCH 55/111 xfs: fold xfs_inobt_init_common into xfs_inobt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: f6c98d921a9e5b753ac1a35d540a6487ee111a33
Make the levels initialization in xfs_inobt_init_cursor conditional and merge the two helpers.
--- libxfs/xfs_ialloc_btree.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-)
libxfs/xfs_ialloc_btree.c +15 -24
@@ -454,12 +454,15 @@ const struct xfs_btree_ops xfs_finobt_ops = { };/* -* Initialize a new inode btree cursor. +* Create an inode btree cursor. +* +* For staging cursors tp and agbp are NULL. */ -static struct xfs_btree_cur * -xfs_inobt_init_common ( +struct xfs_btree_cur * +xfs_inobt_init_cursor (struct xfs_perag *pag, -struct xfs_trans *tp,/* transaction pointer */ +struct xfs_trans *tp, +struct xfs_buf *agbp,xfs_btnum_t btnum)/* ialloc or free ino btree */ {struct xfs_mount *mp = pag->pag_mount;
@@ -474,26 +477,14 @@ xfs_inobt_init_common( cur =xfs_btree_alloc_cursor (mp, tp, btnum, ops,M_IGEO (mp)->inobt_maxlevels, xfs_inobt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); -return cur; -} - -/* Create an inode btree cursor. */ -struct xfs_btree_cur * -xfs_inobt_init_cursor ( -struct xfs_perag *pag, -struct xfs_trans *tp, -struct xfs_buf *agbp, -xfs_btnum_t btnum) -{ -struct xfs_btree_cur *cur; -struct xfs_agi *agi = agbp->b_addr; - - cur =xfs_inobt_init_common (pag, tp, btnum); -if (btnum ==XFS_BTNUM_INO ) - cur->bc_nlevels =be32_to_cpu (agi->agi_level); -else - cur->bc_nlevels =be32_to_cpu (agi->agi_free_level); cur->bc_ag.agbp = agbp; +if (agbp) { +struct xfs_agi *agi = agbp->b_addr; + + cur->bc_nlevels = (btnum ==XFS_BTNUM_INO ) ? +be32_to_cpu (agi->agi_level) : +be32_to_cpu (agi->agi_free_level); + }return cur; }
@@ -506,7 +497,7 @@ xfs_inobt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_inobt_init_common (pag,NULL , btnum); + cur =xfs_inobt_init_cursor (pag,NULL ,NULL , btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
PATCH 56/111 xfs: remove xfs_inobt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 6234dee7e6f58676379f3a2d8b0629a6e9a427fd
Just open code the two calls in the callers.
--- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_ialloc_btree.c | 14 -------------- libxfs/xfs_ialloc_btree.h | 2 -- repair/agbtree.c | 8 +++++--- 4 files changed, 6 insertions(+), 19 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -147,6 +147,7 @@#define xfs_initialize_perag_data libxfs_initialize_perag_data#define xfs_init_local_fork libxfs_init_local_fork +#define xfs_inobt_init_cursor libxfs_inobt_init_cursor#define xfs_inobt_maxrecs libxfs_inobt_maxrecs#define xfs_inobt_stage_cursor libxfs_inobt_stage_cursor#define xfs_inode_from_disk libxfs_inode_from_disk
libxfs/xfs_ialloc_btree.c +0 -14
@@ -488,20 +488,6 @@ xfs_inobt_init_cursor(return cur; } -/* Create an inode btree cursor with a fake root for staging. */ -struct xfs_btree_cur * -xfs_inobt_stage_cursor ( -struct xfs_perag *pag, -struct xbtree_afakeroot *afake, -xfs_btnum_t btnum) -{ -struct xfs_btree_cur *cur; - - cur =xfs_inobt_init_cursor (pag,NULL ,NULL , btnum); -xfs_btree_stage_afakeroot (cur, afake); -return cur; -} -/* * Install a new inobt btree root. Caller is responsible for invalidating * and freeing the old btree blocks.
libxfs/xfs_ialloc_btree.h +0 -2
@@ -48,8 +48,6 @@ struct xfs_perag;extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_perag *pag,struct xfs_trans *tp,struct xfs_buf *agbp,xfs_btnum_t btnum); -struct xfs_btree_cur *xfs_inobt_stage_cursor (struct xfs_perag *pag, -struct xbtree_afakeroot *afake,xfs_btnum_t btnum);extern int xfs_inobt_maxrecs (struct xfs_mount *,int ,int );/* ir_holemask to inode allocation bitmap conversion */
repair/agbtree.c +5 -3
@@ -524,8 +524,9 @@ init_ino_cursors( fino_recs++; } - btr_ino->cur =libxfs_inobt_stage_cursor (pag, &btr_ino->newbt.afake, + btr_ino->cur =libxfs_inobt_init_cursor (pag,NULL ,NULL ,XFS_BTNUM_INO ); +libxfs_btree_stage_afakeroot (btr_ino->cur, &btr_ino->newbt.afake); btr_ino->bload.get_records = get_inobt_records; btr_ino->bload.claim_block = rebuild_claim_block;
@@ -544,8 +545,9 @@ _("Unable to compute inode btree geometry, error %d.\n"), error);return ;init_rebuild (sc, &XFS_RMAP_OINFO_INOBT , est_agfreeblocks, btr_fino); - btr_fino->cur =libxfs_inobt_stage_cursor (pag, - &btr_fino->newbt.afake,XFS_BTNUM_FINO ); + btr_fino->cur =libxfs_inobt_init_cursor (pag,NULL ,NULL , +XFS_BTNUM_FINO ); +libxfs_btree_stage_afakeroot (btr_fino->cur, &btr_fino->newbt.afake); btr_fino->bload.get_records = get_inobt_records; btr_fino->bload.claim_block = rebuild_claim_block;
PATCH 57/111 xfs: fold xfs_refcountbt_init_common into xfs_refcountbt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4f2dc69e4bcb4b3bfaea0a96ac6424b0ed998172
Make the levels initialization in xfs_refcountbt_init_cursor conditional and merge the two helpers.
--- libxfs/xfs_refcount_btree.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
libxfs/xfs_refcount_btree.c +12 -20
@@ -345,12 +345,15 @@ const struct xfs_btree_ops xfs_refcountbt_ops = { };/* -* Initialize a new refcount btree cursor. +* Create a new refcount btree cursor. +* +* For staging cursors tp and agbp are NULL. */ -static struct xfs_btree_cur * -xfs_refcountbt_init_common ( +struct xfs_btree_cur * +xfs_refcountbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp, +struct xfs_buf *agbp,struct xfs_perag *pag) {struct xfs_btree_cur *cur;
@@ -363,23 +366,12 @@ xfs_refcountbt_init_common( cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_refc.nr_ops =0 ; cur->bc_refc.shape_changes =0 ; -return cur; -} - -/* Create a btree cursor. */ -struct xfs_btree_cur * -xfs_refcountbt_init_cursor ( -struct xfs_mount *mp, -struct xfs_trans *tp, -struct xfs_buf *agbp, -struct xfs_perag *pag) -{ -struct xfs_agf *agf = agbp->b_addr; -struct xfs_btree_cur *cur; - - cur =xfs_refcountbt_init_common (mp, tp, pag); - cur->bc_nlevels =be32_to_cpu (agf->agf_refcount_level); cur->bc_ag.agbp = agbp; +if (agbp) { +struct xfs_agf *agf = agbp->b_addr; + + cur->bc_nlevels =be32_to_cpu (agf->agf_refcount_level); + }return cur; }
@@ -392,7 +384,7 @@ xfs_refcountbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_refcountbt_init_common (mp,NULL , pag); + cur =xfs_refcountbt_init_cursor (mp,NULL ,NULL , pag);xfs_btree_stage_afakeroot (cur, afake);return cur; }
PATCH 58/111 xfs: remove xfs_refcountbt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: a5c2194406f322e91b90fb813128541a9b4fed6a
Just open code the two calls in the callers.
--- libxfs/xfs_refcount_btree.c | 14 -------------- libxfs/xfs_refcount_btree.h | 2 -- repair/agbtree.c | 4 ++-- 3 files changed, 2 insertions(+), 18 deletions(-)
libxfs/xfs_refcount_btree.c +0 -14
@@ -375,20 +375,6 @@ xfs_refcountbt_init_cursor(return cur; } -/* Create a btree cursor with a fake root for staging. */ -struct xfs_btree_cur * -xfs_refcountbt_stage_cursor ( -struct xfs_mount *mp, -struct xbtree_afakeroot *afake, -struct xfs_perag *pag) -{ -struct xfs_btree_cur *cur; - - cur =xfs_refcountbt_init_cursor (mp,NULL ,NULL , pag); -xfs_btree_stage_afakeroot (cur, afake); -return cur; -} -/* * Swap in the new btree root. Once we pass this point the newly rebuilt btree * is in place and we have to kill off all the old btree blocks.
libxfs/xfs_refcount_btree.h +0 -2
@@ -48,8 +48,6 @@ struct xbtree_afakeroot;extern struct xfs_btree_cur *xfs_refcountbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *agbp,struct xfs_perag *pag); -struct xfs_btree_cur *xfs_refcountbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,struct xfs_perag *pag);extern int xfs_refcountbt_maxrecs (int blocklen,bool leaf);extern void xfs_refcountbt_compute_maxlevels (struct xfs_mount *mp);
repair/agbtree.c +2 -2
@@ -719,8 +719,8 @@ init_refc_cursor(return ;init_rebuild (sc, &XFS_RMAP_OINFO_REFC , est_agfreeblocks, btr); - btr->cur =libxfs_refcountbt_stage_cursor (sc->mp, &btr->newbt.afake, - pag); + btr->cur =libxfs_refcountbt_init_cursor (sc->mp,NULL ,NULL , pag); +libxfs_btree_stage_afakeroot (btr->cur, &btr->newbt.afake); btr->bload.get_records = get_refcountbt_records; btr->bload.claim_block = rebuild_claim_block;
PATCH 59/111 xfs: fold xfs_rmapbt_init_common into xfs_rmapbt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: c49a4b2f0ef0ac5daee5c2a3cfd2b537345c34eb
Make the levels initialization in xfs_rmapbt_init_cursor conditional and merge the two helpers.
--- libxfs/xfs_rmap_btree.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
libxfs/xfs_rmap_btree.c +14 -19
@@ -500,10 +500,16 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .keys_contiguous = xfs_rmapbt_keys_contiguous, }; -static struct xfs_btree_cur * -xfs_rmapbt_init_common ( +/* +* Create a new reverse mapping btree cursor. +* +* For staging cursors tp and agbp are NULL. +*/ +struct xfs_btree_cur * +xfs_rmapbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp, +struct xfs_buf *agbp,struct xfs_perag *pag) {struct xfs_btree_cur *cur;
@@ -511,23 +517,12 @@ xfs_rmapbt_init_common( cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); -return cur; -} - -/* Create a new reverse mapping btree cursor. */ -struct xfs_btree_cur * -xfs_rmapbt_init_cursor ( -struct xfs_mount *mp, -struct xfs_trans *tp, -struct xfs_buf *agbp, -struct xfs_perag *pag) -{ -struct xfs_agf *agf = agbp->b_addr; -struct xfs_btree_cur *cur; - - cur =xfs_rmapbt_init_common (mp, tp, pag); - cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); cur->bc_ag.agbp = agbp; +if (agbp) { +struct xfs_agf *agf = agbp->b_addr; + + cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); + }return cur; }
@@ -540,7 +535,7 @@ xfs_rmapbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_rmapbt_init_common (mp,NULL , pag); + cur =xfs_rmapbt_init_cursor (mp,NULL ,NULL , pag);xfs_btree_stage_afakeroot (cur, afake);return cur; }
PATCH 60/111 xfs: remove xfs_rmapbt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 1317813290be04bc37196c4adf457712238c7faa
xfs_rmapbt_stage_cursor is currently unused, but future callers can trivially open code the two calls.
--- libxfs/xfs_rmap_btree.c | 14 -------------- libxfs/xfs_rmap_btree.h | 2 -- repair/agbtree.c | 3 ++- 3 files changed, 2 insertions(+), 17 deletions(-)
libxfs/xfs_rmap_btree.c +0 -14
@@ -526,20 +526,6 @@ xfs_rmapbt_init_cursor(return cur; } -/* Create a new reverse mapping btree cursor with a fake root for staging. */ -struct xfs_btree_cur * -xfs_rmapbt_stage_cursor ( -struct xfs_mount *mp, -struct xbtree_afakeroot *afake, -struct xfs_perag *pag) -{ -struct xfs_btree_cur *cur; - - cur =xfs_rmapbt_init_cursor (mp,NULL ,NULL , pag); -xfs_btree_stage_afakeroot (cur, afake); -return cur; -} -/* * Install a new reverse mapping btree root. Caller is responsible for * invalidating and freeing the old btree blocks.
libxfs/xfs_rmap_btree.h +0 -2
@@ -44,8 +44,6 @@ struct xbtree_afakeroot;struct xfs_btree_cur *xfs_rmapbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_perag *pag); -struct xfs_btree_cur *xfs_rmapbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,struct xfs_perag *pag);void xfs_rmapbt_commit_staged_btree (struct xfs_btree_cur *cur,struct xfs_trans *tp,struct xfs_buf *agbp);int xfs_rmapbt_maxrecs (int blocklen,int leaf);
repair/agbtree.c +2 -1
@@ -637,7 +637,8 @@ init_rmapbt_cursor(return ;init_rebuild (sc, &XFS_RMAP_OINFO_AG , est_agfreeblocks, btr); - btr->cur =libxfs_rmapbt_stage_cursor (sc->mp, &btr->newbt.afake, pag); + btr->cur =libxfs_rmapbt_init_cursor (sc->mp,NULL ,NULL , pag); +libxfs_btree_stage_afakeroot (btr->cur, &btr->newbt.afake); btr->bload.get_records = get_rmapbt_records; btr->bload.claim_block = rebuild_claim_block;
PATCH 61/111 xfs: make full use of xfs_btree_stage_ifakeroot in xfs_bmbt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 579d7022d1afea8f4475d1750224ec0b652febee
Remove the duplicate cur->bc_nlevels assignment in xfs_bmbt_stage_cursor, and move the cur->bc_ino.forksize assignment into xfs_btree_stage_ifakeroot as it is part of setting up the fake btree root.
--- libxfs/xfs_bmap_btree.c | 2 -- libxfs/xfs_btree_staging.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-)
libxfs/xfs_bmap_btree.c +0 -2
@@ -611,8 +611,6 @@ xfs_bmbt_stage_cursor(/* data fork always has larger maxheight */ cur =xfs_bmbt_init_common (mp,NULL , ip,XFS_DATA_FORK ); - cur->bc_nlevels = ifake->if_levels; - cur->bc_ino.forksize = ifake->if_fork_size;/* Don't let anyone think we're attached to the real fork yet. */ cur->bc_ino.whichfork =-1 ;
libxfs/xfs_btree_staging.c +1 -0
@@ -133,6 +133,7 @@ xfs_btree_stage_ifakeroot( cur->bc_ino.ifake = ifake; cur->bc_nlevels = ifake->if_levels; + cur->bc_ino.forksize = ifake->if_fork_size; cur->bc_flags |=XFS_BTREE_STAGING ; }
PATCH 62/111 xfs: make staging file forks explicit
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 42e357c806c8c0ffb9c5c2faa4ad034bfe950d77
Don't open-code "-1" for whichfork when we're creating a staging btree for a repair; let's define an actual symbol to make grepping and understanding easier.
--- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_types.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
libxfs/xfs_bmap_btree.c +1 -1
@@ -613,7 +613,7 @@ xfs_bmbt_stage_cursor( cur =xfs_bmbt_init_common (mp,NULL , ip,XFS_DATA_FORK );/* Don't let anyone think we're attached to the real fork yet. */ - cur->bc_ino.whichfork =-1 ; + cur->bc_ino.whichfork =XFS_STAGING_FORK ;xfs_btree_stage_ifakeroot (cur, ifake);return cur; }
libxfs/xfs_types.h +5 -3
@@ -80,11 +80,13 @@ typedef void * xfs_failaddr_t;/* * Inode fork identifiers. */ -#define XFS_DATA_FORK 0 -#define XFS_ATTR_FORK 1 -#define XFS_COW_FORK 2 +#define XFS_STAGING_FORK (-1)/* fake fork for staging a btree */ +#define XFS_DATA_FORK (0) +#define XFS_ATTR_FORK (1) +#define XFS_COW_FORK (2)#define XFS_WHICHFORK_STRINGS \ + { XFS_STAGING_FORK, "staging" }, \ { XFS_DATA_FORK, "data" }, \ { XFS_ATTR_FORK, "attr" }, \ { XFS_COW_FORK, "cow" }
PATCH 63/111 xfs: fold xfs_bmbt_init_common into xfs_bmbt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 802f91f7b1d535ac975e2d696bf5b5dea82816e7
Make the levels initialization in xfs_bmbt_init_cursor conditional and merge the two helpers.
This requires the fakeroot case to now pass a -1 whichfork directly into xfs_bmbt_init_cursor, and some special casing for that, but at least this scheme to deal with the fake btree root is handled and documented in once place now.
--- libxfs/xfs_bmap_btree.c | 58 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-)
libxfs/xfs_bmap_btree.c +28 -30
@@ -543,44 +543,46 @@ const struct xfs_btree_ops xfs_bmbt_ops = { .keys_contiguous = xfs_bmbt_keys_contiguous, }; -static struct xfs_btree_cur * -xfs_bmbt_init_common ( +/* +* Create a new bmap btree cursor. +* +* For staging cursors -1 in passed in whichfork. +*/ +struct xfs_btree_cur * +xfs_bmbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_inode *ip,int whichfork) {struct xfs_btree_cur *cur; +unsigned int maxlevels;ASSERT (whichfork !=XFS_COW_FORK ); +/* +* The Data fork always has larger maxlevel, so use that for staging +* cursors. +*/ +switch (whichfork) { +case XFS_STAGING_FORK : + maxlevels = mp->m_bm_maxlevels[XFS_DATA_FORK ]; +break ; +default : + maxlevels = mp->m_bm_maxlevels[whichfork]; +break ; + } cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BMAP , &xfs_bmbt_ops, - mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); - + maxlevels, xfs_bmbt_cur_cache); cur->bc_ino.ip = ip; - cur->bc_bmap.allocated =0 ; -return cur; -} - -/* -* Allocate a new bmap btree cursor. -*/ -struct xfs_btree_cur * -xfs_bmbt_init_cursor ( -struct xfs_mount *mp, -struct xfs_trans *tp, -struct xfs_inode *ip, -int whichfork) -{ -struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork); -struct xfs_btree_cur *cur; - - cur =xfs_bmbt_init_common (mp, tp, ip, whichfork); - - cur->bc_nlevels =be16_to_cpu (ifp->if_broot->bb_level) +1 ; - cur->bc_ino.forksize =xfs_inode_fork_size (ip, whichfork); cur->bc_ino.whichfork = whichfork; + cur->bc_bmap.allocated =0 ; +if (whichfork !=XFS_STAGING_FORK ) { +struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork); + cur->bc_nlevels =be16_to_cpu (ifp->if_broot->bb_level) +1 ; + cur->bc_ino.forksize =xfs_inode_fork_size (ip, whichfork); + }return cur; }
@@ -609,11 +611,7 @@ xfs_bmbt_stage_cursor( {struct xfs_btree_cur *cur; -/* data fork always has larger maxheight */ - cur =xfs_bmbt_init_common (mp,NULL , ip,XFS_DATA_FORK ); - -/* Don't let anyone think we're attached to the real fork yet. */ - cur->bc_ino.whichfork =XFS_STAGING_FORK ; + cur =xfs_bmbt_init_cursor (mp,NULL , ip,XFS_STAGING_FORK );xfs_btree_stage_ifakeroot (cur, ifake);return cur; }
PATCH 64/111 xfs: remove xfs_bmbt_stage_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 02f7ebf5f99c3776bbf048786885eeafeb2f21ca
Just open code the two calls in the callers.
--- db/bmap_inflate.c | 8 ++++++-- libxfs/libxfs_api_defs.h | 2 ++ libxfs/xfs_bmap_btree.c | 19 ------------------- libxfs/xfs_bmap_btree.h | 2 -- repair/bmap_repair.c | 4 +++- 5 files changed, 11 insertions(+), 24 deletions(-)
db/bmap_inflate.c +6 -2
@@ -351,7 +351,9 @@ build_new_datafork(/* Set up staging for the new bmbt */ ifake.if_fork =kmem_cache_zalloc (xfs_ifork_cache,0 ); ifake.if_fork_size =xfs_inode_fork_size (ip,XFS_DATA_FORK ); - bmap_cur =libxfs_bmbt_stage_cursor (ip->i_mount, ip, &ifake); + bmap_cur =libxfs_bmbt_init_cursor (ip->i_mount,NULL , ip, +XFS_STAGING_FORK ); +libxfs_btree_stage_ifakeroot (bmap_cur, &ifake);/* * Figure out the size and format of the new fork, then fill it with
@@ -405,7 +407,9 @@ estimate_size( ifake.if_fork =kmem_cache_zalloc (xfs_ifork_cache,0 ); ifake.if_fork_size =xfs_inode_fork_size (ip,XFS_DATA_FORK ); - bmap_cur =libxfs_bmbt_stage_cursor (ip->i_mount, ip, &ifake); + bmap_cur =libxfs_bmbt_init_cursor (ip->i_mount,NULL , ip, +XFS_STAGING_FORK ); +libxfs_btree_stage_ifakeroot (bmap_cur, &ifake); error = -libxfs_btree_bload_compute_geometry (bmap_cur, &bmap_bload, nextents);libxfs_btree_del_cursor (bmap_cur, error);
libxfs/libxfs_api_defs.h +2 -0
@@ -54,6 +54,7 @@#define xfs_bmbt_commit_staged_btree libxfs_bmbt_commit_staged_btree#define xfs_bmbt_disk_get_startoff libxfs_bmbt_disk_get_startoff#define xfs_bmbt_disk_set_all libxfs_bmbt_disk_set_all +#define xfs_bmbt_init_cursor libxfs_bmbt_init_cursor#define xfs_bmbt_maxlevels_ondisk libxfs_bmbt_maxlevels_ondisk#define xfs_bmbt_maxrecs libxfs_bmbt_maxrecs#define xfs_bmbt_stage_cursor libxfs_bmbt_stage_cursor
@@ -65,6 +66,7 @@#define xfs_btree_init_block libxfs_btree_init_block#define xfs_btree_rec_addr libxfs_btree_rec_addr#define xfs_btree_stage_afakeroot libxfs_btree_stage_afakeroot +#define xfs_btree_stage_ifakeroot libxfs_btree_stage_ifakeroot#define xfs_buf_delwri_submit libxfs_buf_delwri_submit#define xfs_buf_get libxfs_buf_get#define xfs_buf_get_uncached libxfs_buf_get_uncached
libxfs/xfs_bmap_btree.c +0 -19
@@ -597,25 +597,6 @@ xfs_bmbt_block_maxrecs(return blocklen / (sizeof (xfs_bmbt_key_t) +sizeof (xfs_bmbt_ptr_t)); } -/* -* Allocate a new bmap btree cursor for reloading an inode block mapping data -* structure. Note that callers can use the staged cursor to reload extents -* format inode forks if they rebuild the iext tree and commit the staged -* cursor immediately. -*/ -struct xfs_btree_cur * -xfs_bmbt_stage_cursor ( -struct xfs_mount *mp, -struct xfs_inode *ip, -struct xbtree_ifakeroot *ifake) -{ -struct xfs_btree_cur *cur; - - cur =xfs_bmbt_init_cursor (mp,NULL , ip,XFS_STAGING_FORK ); -xfs_btree_stage_ifakeroot (cur, ifake); -return cur; -} -/* * Swap in the new inode fork root. Once we pass this point the newly rebuilt * mappings are in place and we have to kill off any old btree blocks.
libxfs/xfs_bmap_btree.h +0 -2
@@ -107,8 +107,6 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,extern struct xfs_btree_cur *xfs_bmbt_init_cursor (struct xfs_mount *,struct xfs_trans *,struct xfs_inode *,int ); -struct xfs_btree_cur *xfs_bmbt_stage_cursor (struct xfs_mount *mp, -struct xfs_inode *ip,struct xbtree_ifakeroot *ifake);void xfs_bmbt_commit_staged_btree (struct xfs_btree_cur *cur,struct xfs_trans *tp,int whichfork);
repair/bmap_repair.c +3 -1
@@ -475,7 +475,9 @@ xrep_bmap_build_new_fork(*/ libxfs_rmap_ino_bmbt_owner (&oinfo, sc->ip->i_ino, rb->whichfork);bulkload_init_inode (&rb->new_fork_info, sc, rb->whichfork, &oinfo); - bmap_cur =libxfs_bmbt_stage_cursor (sc->mp, sc->ip, ifake); + bmap_cur =libxfs_bmbt_init_cursor (sc->mp,NULL , sc->ip, +XFS_STAGING_FORK ); +libxfs_btree_stage_ifakeroot (bmap_cur, ifake);/* * Figure out the size and format of the new fork, then fill it with
PATCH 65/111 xfs: split the agf_roots and agf_levels arrays
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: e45ea3645178c6db91aef4314945b05e4c6ee1fc
Using arrays of largely unrelated fields that use the btree number as index is not very robust. Split the arrays into three separate fields instead.
--- copy/xfs_copy.c | 4 ++-- db/agf.c | 28 +++++-------------------- db/check.c | 14 ++++++------ db/freesp.c | 8 ++++--- db/metadump.c | 12 +++++------ libxfs/xfs_ag.c | 13 +++++------- libxfs/xfs_ag.h | 8 ++++--- libxfs/xfs_alloc.c | 49 +++++++++++++++++-------------------------- libxfs/xfs_alloc_btree.c | 52 +++++++++++++++++++++++++++++++--------------- libxfs/xfs_format.h | 21 +++++++++---------- libxfs/xfs_rmap_btree.c | 17 +++++++-------- logprint/log_misc.c | 8 ++++--- logprint/log_print_all.c | 8 ++++--- repair/phase5.c | 24 +++++++++++---------- repair/scan.c | 16 +++++++------- 15 files changed, 136 insertions(+), 146 deletions(-)
copy/xfs_copy.c +2 -2
@@ -1016,10 +1016,10 @@ main(int argc, char **argv)/* traverse btree until we get to the leftmost leaf node */ - bno =be32_to_cpu (ag_hdr.xfs_agf->agf_roots[XFS_BTNUM_BNOi]); + bno =be32_to_cpu (ag_hdr.xfs_agf->agf_bno_root); current_level =0 ; btree_levels =be32_to_cpu (ag_hdr.xfs_agf-> - agf_levels[XFS_BTNUM_BNOi]); + agf_bno_level); ag_end =XFS_AGB_TO_DADDR (mp, agno,be32_to_cpu (ag_hdr.xfs_agf->agf_length) -1 )
db/agf.c +6 -22
@@ -35,31 +35,15 @@ const field_t agf_flds[] = { { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE }, { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE }, { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE }, - { "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF), - FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, - { "bnoroot", FLDT_AGBLOCK, -OI (OFF (roots) +XFS_BTNUM_BNO *SZ (roots[XFS_BTNUM_BNO ])),C1 ,0 , - TYP_BNOBT }, - { "cntroot", FLDT_AGBLOCK, -OI (OFF (roots) +XFS_BTNUM_CNT *SZ (roots[XFS_BTNUM_CNT ])),C1 ,0 , - TYP_CNTBT }, - { "rmaproot", FLDT_AGBLOCKNZ, -OI (OFF (roots) +XFS_BTNUM_RMAP *SZ (roots[XFS_BTNUM_RMAP ])),C1 ,0 , - TYP_RMAPBT }, + { "bnoroot", FLDT_AGBLOCK, OI(OFF(bno_root)), C1, 0, TYP_BNOBT }, + { "cntroot", FLDT_AGBLOCK, OI(OFF(cnt_root)), C1, 0, TYP_CNTBT }, + { "rmaproot", FLDT_AGBLOCKNZ, OI(OFF(rmap_root)), C1, 0, TYP_RMAPBT }, { "refcntroot", FLDT_AGBLOCKNZ,OI (OFF (refcount_root)),C1 ,0 , TYP_REFCBT }, - { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF), - FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, - { "bnolevel", FLDT_UINT32D, -OI (OFF (levels) +XFS_BTNUM_BNO *SZ (levels[XFS_BTNUM_BNO ])),C1 ,0 , - TYP_NONE }, - { "cntlevel", FLDT_UINT32D, -OI (OFF (levels) +XFS_BTNUM_CNT *SZ (levels[XFS_BTNUM_CNT ])),C1 ,0 , - TYP_NONE }, - { "rmaplevel", FLDT_UINT32D, -OI (OFF (levels) +XFS_BTNUM_RMAP *SZ (levels[XFS_BTNUM_RMAP ])),C1 ,0 , - TYP_NONE }, + { "bnolevel", FLDT_UINT32D, OI(OFF(bno_level)), C1, 0, TYP_NONE }, + { "cntlevel", FLDT_UINT32D, OI(OFF(cnt_level)), C1, 0, TYP_NONE }, + { "rmaplevel", FLDT_UINT32D, OI(OFF(rmap_level)), C1, 0, TYP_NONE }, { "refcntlevel", FLDT_UINT32D,OI (OFF (refcount_level)),C1 ,0 , TYP_NONE },
db/check.c +7 -7
@@ -4095,18 +4095,18 @@ scan_ag(scan_freelist (agf); fdblocks--;scan_sbtree (agf, -be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNO ]), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]), +be32_to_cpu (agf->agf_bno_root), +be32_to_cpu (agf->agf_bno_level),1 , scanfunc_bno,TYP_BNOBT ); fdblocks--;scan_sbtree (agf, -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]), +be32_to_cpu (agf->agf_cnt_root), +be32_to_cpu (agf->agf_cnt_level),1 , scanfunc_cnt,TYP_CNTBT ); -if (agf->agf_roots[XFS_BTNUM_RMAP ]) { +if (agf->agf_rmap_root) {scan_sbtree (agf, -be32_to_cpu (agf->agf_roots[XFS_BTNUM_RMAP ]), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]), +be32_to_cpu (agf->agf_rmap_root), +be32_to_cpu (agf->agf_rmap_level),1 , scanfunc_rmap,TYP_RMAPBT ); }if (agf->agf_refcount_root) {
db/freesp.c +4 -4
@@ -209,12 +209,12 @@ scan_ag( agf = iocur_top->data;scan_freelist (agf);if (countflag) -scan_sbtree (agf,be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]), -TYP_CNTBT ,be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]), +scan_sbtree (agf,be32_to_cpu (agf->agf_cnt_root), +TYP_CNTBT ,be32_to_cpu (agf->agf_cnt_level), scanfunc_cnt);else -scan_sbtree (agf,be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNO ]), -TYP_BNOBT ,be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]), +scan_sbtree (agf,be32_to_cpu (agf->agf_bno_root), +TYP_BNOBT ,be32_to_cpu (agf->agf_bno_level), scanfunc_bno);pop_cur (); }
db/metadump.c +6 -6
@@ -460,8 +460,8 @@ copy_free_bno_btree(xfs_agblock_t root;int levels; - root =be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNO ]); - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]); + root =be32_to_cpu (agf->agf_bno_root); + levels =be32_to_cpu (agf->agf_bno_level);/* validate root and levels before processing the tree */ if (root ==0 || root > mp->m_sb.sb_agblocks) {
@@ -488,8 +488,8 @@ copy_free_cnt_btree(xfs_agblock_t root;int levels; - root =be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]); - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]); + root =be32_to_cpu (agf->agf_cnt_root); + levels =be32_to_cpu (agf->agf_cnt_level);/* validate root and levels before processing the tree */ if (root ==0 || root > mp->m_sb.sb_agblocks) {
@@ -560,8 +560,8 @@ copy_rmap_btree(if (!xfs_has_rmapbt (mp))return 1 ; - root =be32_to_cpu (agf->agf_roots[XFS_BTNUM_RMAP ]); - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); + root =be32_to_cpu (agf->agf_rmap_root); + levels =be32_to_cpu (agf->agf_rmap_level);/* validate root and levels before processing the tree */ if (root ==0 || root > mp->m_sb.sb_agblocks) {
libxfs/xfs_ag.c +6 -7
@@ -667,14 +667,13 @@ xfs_agfblock_init( agf->agf_versionnum =cpu_to_be32 (XFS_AGF_VERSION ); agf->agf_seqno =cpu_to_be32 (id->agno); agf->agf_length =cpu_to_be32 (id->agsize); - agf->agf_roots[XFS_BTNUM_BNOi] =cpu_to_be32 (XFS_BNO_BLOCK (mp)); - agf->agf_roots[XFS_BTNUM_CNTi] =cpu_to_be32 (XFS_CNT_BLOCK (mp)); - agf->agf_levels[XFS_BTNUM_BNOi] =cpu_to_be32 (1 ); - agf->agf_levels[XFS_BTNUM_CNTi] =cpu_to_be32 (1 ); + agf->agf_bno_root =cpu_to_be32 (XFS_BNO_BLOCK (mp)); + agf->agf_cnt_root =cpu_to_be32 (XFS_CNT_BLOCK (mp)); + agf->agf_bno_level =cpu_to_be32 (1 ); + agf->agf_cnt_level =cpu_to_be32 (1 );if (xfs_has_rmapbt (mp)) { - agf->agf_roots[XFS_BTNUM_RMAPi] = -cpu_to_be32 (XFS_RMAP_BLOCK (mp)); - agf->agf_levels[XFS_BTNUM_RMAPi] =cpu_to_be32 (1 ); + agf->agf_rmap_root =cpu_to_be32 (XFS_RMAP_BLOCK (mp)); + agf->agf_rmap_level =cpu_to_be32 (1 ); agf->agf_rmap_blocks =cpu_to_be32 (1 ); }
libxfs/xfs_ag.h +5 -3
@@ -36,8 +36,9 @@ struct xfs_perag {atomic_t pag_active_ref;/* active reference count */ wait_queue_head_t pag_active_wq;/* woken active_ref falls to zero */ unsigned long pag_opstate; -uint8_t pagf_levels[XFS_BTNUM_AGF ]; -/* # of levels in bno & cnt btree */ +uint8_t pagf_bno_level;/* # of levels in bno btree */ +uint8_t pagf_cnt_level;/* # of levels in cnt btree */ +uint8_t pagf_rmap_level;/* # of levels in rmap btree */ uint32_t pagf_flcount;/* count of blocks in freelist */ xfs_extlen_t pagf_freeblks;/* total free blocks */ xfs_extlen_t pagf_longest;/* longest free space */
@@ -86,7 +87,8 @@ struct xfs_perag {* Alternate btree heights so that online repair won't trip the write * verifiers while rebuilding the AG btrees. */ -uint8_t pagf_repair_levels[XFS_BTNUM_AGF ]; +uint8_t pagf_repair_bno_level; +uint8_t pagf_repair_cnt_level;uint8_t pagf_repair_refcount_level;#endif
libxfs/xfs_alloc.c +19 -30
94 lines not on this page · raw message
libxfs/xfs_alloc_btree.c +35 -17
99 lines not on this page · raw message
libxfs/xfs_format.h +10 -11
@@ -477,15 +477,9 @@ xfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)#define XFS_AGI_GOOD_VERSION (v) ((v) == XFS_AGI_VERSION)/* -* Btree number 0 is bno, 1 is cnt, 2 is rmap. This value gives the size of the -* arrays below. -*/ -#define XFS_BTNUM_AGF ((int)XFS_BTNUM_RMAPi + 1) - -/* -* The second word of agf_levels in the first a.g. overlaps the EFS -* superblock's magic number. Since the magic numbers valid for EFS -* are > 64k, our value cannot be confused for an EFS superblock's. +* agf_cnt_level in the first AGF overlaps the EFS superblock's magic number. +* Since the magic numbers valid for EFS are > 64k, our value cannot be confused +* for an EFS superblock. */ typedef struct xfs_agf {
@@ -499,8 +493,13 @@ typedef struct xfs_agf {/* * Freespace and rmap information */ -__be32 agf_roots[XFS_BTNUM_AGF ];/* root blocks */ -__be32 agf_levels[XFS_BTNUM_AGF ];/* btree levels */ +__be32 agf_bno_root;/* bnobt root block */ +__be32 agf_cnt_root;/* cntbt root block */ +__be32 agf_rmap_root;/* rmapbt root block */ + +__be32 agf_bno_level;/* bnobt btree levels */ +__be32 agf_cnt_level;/* cntbt btree levels */ +__be32 agf_rmap_level;/* rmapbt btree levels */ __be32 agf_flfirst;/* first freelist block's index */ __be32 agf_fllast;/* last freelist block's index */
libxfs/xfs_rmap_btree.c +8 -9
@@ -63,13 +63,12 @@ xfs_rmapbt_set_root( {struct xfs_buf *agbp = cur->bc_ag.agbp;struct xfs_agf *agf = agbp->b_addr; -int btnum = cur->bc_btnum;ASSERT (ptr->s !=0 ); - agf->agf_roots[btnum] = ptr->s; -be32_add_cpu (&agf->agf_levels[btnum], inc); - cur->bc_ag.pag->pagf_levels[btnum] += inc; + agf->agf_rmap_root = ptr->s; +be32_add_cpu (&agf->agf_rmap_level, inc); + cur->bc_ag.pag->pagf_rmap_level += inc;xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS ); }
@@ -220,7 +219,7 @@ xfs_rmapbt_init_ptr_from_cur(ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agf->agf_seqno)); - ptr->s = agf->agf_roots[cur->bc_btnum]; + ptr->s = agf->agf_rmap_root; }/*
@@ -340,7 +339,7 @@ xfs_rmapbt_verify( level =be16_to_cpu (block->bb_level);if (pag &&xfs_perag_initialised_agf (pag)) { -if (level >= pag->pagf_levels[XFS_BTNUM_RMAPi]) +if (level >= pag->pagf_rmap_level)return __this_address; }else if (level >= mp->m_rmap_maxlevels)return __this_address;
@@ -521,7 +520,7 @@ xfs_rmapbt_init_cursor(if (agbp) {struct xfs_agf *agf = agbp->b_addr; - cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); + cur->bc_nlevels =be32_to_cpu (agf->agf_rmap_level); }return cur; }
@@ -541,8 +540,8 @@ xfs_rmapbt_commit_staged_btree(ASSERT (cur->bc_flags &XFS_BTREE_STAGING ); - agf->agf_roots[cur->bc_btnum] =cpu_to_be32 (afake->af_root); - agf->agf_levels[cur->bc_btnum] =cpu_to_be32 (afake->af_levels); + agf->agf_rmap_root =cpu_to_be32 (afake->af_root); + agf->agf_rmap_level =cpu_to_be32 (afake->af_levels); agf->agf_rmap_blocks =cpu_to_be32 (afake->af_blocks);xfs_alloc_log_agf (tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS |XFS_AGF_RMAP_BLOCKS );
logprint/log_misc.c +4 -4
@@ -378,11 +378,11 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)be32_to_cpu (agf->agf_seqno), be32_to_cpu(agf->agf_length));printf (_ ("root BNO: %d CNT: %d\n" ), -be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi]), -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi])); +be32_to_cpu (agf->agf_bno_root), +be32_to_cpu (agf->agf_cnt_root));printf (_ ("level BNO: %d CNT: %d\n" ), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNOi]), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNTi])); +be32_to_cpu (agf->agf_bno_level), +be32_to_cpu (agf->agf_cnt_level)); printf(_("1st: %d last: %d cnt: %d " "freeblks: %d longest: %d\n"), be32_to_cpu(agf->agf_flfirst),
logprint/log_print_all.c +4 -4
@@ -152,11 +152,11 @@ xlog_recover_print_buffer(be32_to_cpu (agf->agf_seqno), be32_to_cpu(agf->agf_length));printf (_ (" root BNO:%d CNT:%d\n" ), -be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi]), -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi])); +be32_to_cpu (agf->agf_bno_root), +be32_to_cpu (agf->agf_cnt_root));printf (_ (" level BNO:%d CNT:%d\n" ), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNOi]), -be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNTi])); +be32_to_cpu (agf->agf_bno_level), +be32_to_cpu (agf->agf_cnt_level)); printf(_(" 1st:%d last:%d cnt:%d " "freeblks:%d longest:%d\n"), be32_to_cpu(agf->agf_flfirst),
repair/phase5.c +12 -12
@@ -255,20 +255,20 @@ build_agf_agfl( agf->agf_length =cpu_to_be32 (mp->m_sb.sb_dblocks - (xfs_rfsblock_t ) mp->m_sb.sb_agblocks * agno); - agf->agf_roots[XFS_BTNUM_BNO ] = + agf->agf_bno_root =cpu_to_be32 (btr_bno->newbt.afake.af_root); - agf->agf_levels[XFS_BTNUM_BNO ] = + agf->agf_bno_level =cpu_to_be32 (btr_bno->newbt.afake.af_levels); - agf->agf_roots[XFS_BTNUM_CNT ] = + agf->agf_cnt_root =cpu_to_be32 (btr_cnt->newbt.afake.af_root); - agf->agf_levels[XFS_BTNUM_CNT ] = + agf->agf_cnt_level =cpu_to_be32 (btr_cnt->newbt.afake.af_levels); agf->agf_freeblks =cpu_to_be32 (btr_bno->freeblks);if (xfs_has_rmapbt (mp)) { - agf->agf_roots[XFS_BTNUM_RMAP ] = + agf->agf_rmap_root =cpu_to_be32 (btr_rmap->newbt.afake.af_root); - agf->agf_levels[XFS_BTNUM_RMAP ] = + agf->agf_rmap_level =cpu_to_be32 (btr_rmap->newbt.afake.af_levels); agf->agf_rmap_blocks =cpu_to_be32 (btr_rmap->newbt.afake.af_blocks);
@@ -305,8 +305,8 @@ build_agf_agfl(#ifdef XR_BLD_FREE_TRACE fprintf (stderr,"bno root = %u, bcnt root = %u, indices = %u %u\n" , -be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNO ]), -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]), +be32_to_cpu (agf->agf_bno_root), +be32_to_cpu (agf->agf_cnt_root),XFS_BTNUM_BNO ,XFS_BTNUM_CNT );#endif
@@ -367,12 +367,12 @@ build_agf_agfl( agf->agf_longest =cpu_to_be32 ((ext_ptr !=NULL ) ? ext_ptr->ex_blockcount :0 ); -ASSERT (be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi]) != -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi])); +ASSERT (be32_to_cpu (agf->agf_bno_root) != +be32_to_cpu (agf->agf_cnt_root));ASSERT (be32_to_cpu (agf->agf_refcount_root) != -be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi])); +be32_to_cpu (agf->agf_bno_root));ASSERT (be32_to_cpu (agf->agf_refcount_root) != -be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi])); +be32_to_cpu (agf->agf_cnt_root));libxfs_buf_mark_dirty (agf_buf);libxfs_buf_relse (agf_buf);
repair/scan.c +8 -8
@@ -2364,17 +2364,17 @@ validate_agf(unsigned int levels;struct xfs_perag *pag =libxfs_perag_get (mp, agno); - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]); + levels =be32_to_cpu (agf->agf_bno_level);if (levels ==0 || levels > mp->m_alloc_maxlevels) {do_warn (_ ("bad levels %u for btbno root, agno %d\n" ), levels, agno); } - bno =be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNO ]); + bno =be32_to_cpu (agf->agf_bno_root);if (libxfs_verify_agbno (pag, bno)) { magic =xfs_has_crc (mp) ?XFS_ABTB_CRC_MAGIC :XFS_ABTB_MAGIC ; -scan_sbtree (bno,be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]), +scan_sbtree (bno,be32_to_cpu (agf->agf_bno_level), agno,0 , scan_allocbt,1 , magic, agcnts, &xfs_bnobt_buf_ops); }else {
@@ -2382,17 +2382,17 @@ validate_agf( bno, agno); } - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]); + levels =be32_to_cpu (agf->agf_cnt_level);if (levels ==0 || levels > mp->m_alloc_maxlevels) {do_warn (_ ("bad levels %u for btbcnt root, agno %d\n" ), levels, agno); } - bno =be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]); + bno =be32_to_cpu (agf->agf_cnt_root);if (libxfs_verify_agbno (pag, bno)) { magic =xfs_has_crc (mp) ?XFS_ABTC_CRC_MAGIC :XFS_ABTC_MAGIC ; -scan_sbtree (bno,be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]), +scan_sbtree (bno,be32_to_cpu (agf->agf_cnt_level), agno,0 , scan_allocbt,1 , magic, agcnts, &xfs_cntbt_buf_ops); }else {
@@ -2409,14 +2409,14 @@ validate_agf( priv.last_rec.rm_owner =XFS_RMAP_OWN_UNKNOWN ; priv.nr_blocks =0 ; - levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); + levels =be32_to_cpu (agf->agf_rmap_level);if (levels ==0 || levels > mp->m_rmap_maxlevels) {do_warn (_ ("bad levels %u for rmapbt root, agno %d\n" ), levels, agno);rmap_avoid_check (); } - bno =be32_to_cpu (agf->agf_roots[XFS_BTNUM_RMAP ]); + bno =be32_to_cpu (agf->agf_rmap_root);if (libxfs_verify_agbno (pag, bno)) { scan_sbtree(bno, levels, agno, 0, scan_rmapbt, 1, XFS_RMAP_CRC_MAGIC, &priv,
PATCH 66/111 xfs: add a name field to struct xfs_btree_ops
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 77953b97bb19dc031673d055c811a5ba7df92307
The btnum in struct xfs_btree_ops is often used for printing a symbolic name for the btree. Add a name field to the ops structure and use that directly.
--- include/xfs_trace.h | 2 +- libxfs/xfs_alloc.c | 8 +++----- libxfs/xfs_alloc_btree.c | 2 ++ libxfs/xfs_bmap_btree.c | 1 + libxfs/xfs_btree.c | 8 ++++---- libxfs/xfs_btree.h | 2 ++ libxfs/xfs_ialloc.c | 5 ++--- libxfs/xfs_ialloc_btree.c | 2 ++ libxfs/xfs_refcount_btree.c | 1 + libxfs/xfs_rmap_btree.c | 1 + libxfs/xfs_types.h | 9 --------- 11 files changed, 19 insertions(+), 22 deletions(-)
include/xfs_trace.h +1 -1
@@ -8,7 +8,7 @@#define trace_xfs_agfl_reset (a,b,c,d) ((void) 0)#define trace_xfs_agfl_free_defer (a,b,c,d,e) ((void) 0) -#define trace_xfs_alloc_cur_check (a,b,c,d,e,f) ((void) 0) +#define trace_xfs_alloc_cur_check (...) ((void) 0)#define trace_xfs_alloc_cur (a) ((void) 0)#define trace_xfs_alloc_cur_left (a) ((void) 0)#define trace_xfs_alloc_cur_lookup (a) ((void) 0)
libxfs/xfs_alloc.c +3 -5
@@ -269,9 +269,8 @@ xfs_alloc_complain_bad_rec(struct xfs_mount *mp = cur->bc_mp;xfs_warn (mp, -"%s Freespace BTree record corruption in AG %d detected at %pS!" , - cur->bc_btnum ==XFS_BTNUM_BNO ?"Block" :"Size" , - cur->bc_ag.pag->pag_agno, fa); +"%sbt record corruption in AG %d detected at %pS!" , + cur->bc_ops->name, cur->bc_ag.pag->pag_agno, fa);xfs_warn (mp,"start block 0x%x block count 0x%x" , irec->ar_startblock, irec->ar_blockcount);
@@ -992,8 +991,7 @@ xfs_alloc_cur_check( out:if (deactivate) cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE ; -trace_xfs_alloc_cur_check (args->mp, cur->bc_btnum, bno, len, diff, - *new); +trace_xfs_alloc_cur_check (cur, bno, len, diff, *new);return 0 ; }
libxfs/xfs_alloc_btree.c +2 -0
@@ -466,6 +466,7 @@ xfs_allocbt_keys_contiguous( }const struct xfs_btree_ops xfs_bnobt_ops = { + .name ="bno" , .type =XFS_BTREE_TYPE_AG , .rec_len =sizeof (xfs_alloc_rec_t),
@@ -495,6 +496,7 @@ const struct xfs_btree_ops xfs_bnobt_ops = { };const struct xfs_btree_ops xfs_cntbt_ops = { + .name ="cnt" , .type =XFS_BTREE_TYPE_AG , .geom_flags =XFS_BTGEO_LASTREC_UPDATE ,
libxfs/xfs_bmap_btree.c +1 -0
@@ -516,6 +516,7 @@ xfs_bmbt_keys_contiguous( }const struct xfs_btree_ops xfs_bmbt_ops = { + .name ="bmap" , .type =XFS_BTREE_TYPE_INODE , .rec_len =sizeof (xfs_bmbt_rec_t),
libxfs/xfs_btree.c +4 -4
@@ -295,17 +295,17 @@ xfs_btree_check_ptr( level))return 0 ;xfs_err (cur->bc_mp, -"Inode %llu fork %d: Corrupt btree %d pointer at level %d index %d." , +"Inode %llu fork %d: Corrupt %sbt pointer at level %d index %d." , cur->bc_ino.ip->i_ino, - cur->bc_ino.whichfork, cur->bc_btnum, + cur->bc_ino.whichfork, cur->bc_ops->name, level, index); }else {if (xfs_btree_check_sptr (cur,be32_to_cpu ((&ptr->s)[index]), level))return 0 ;xfs_err (cur->bc_mp, -"AG %u: Corrupt btree %d pointer at level %d index %d." , - cur->bc_ag.pag->pag_agno, cur->bc_btnum, +"AG %u: Corrupt %sbt pointer at level %d index %d." , + cur->bc_ag.pag->pag_agno, cur->bc_ops->name, level, index); }
libxfs/xfs_btree.h +2 -0
@@ -123,6 +123,8 @@ enum xfs_btree_type { };struct xfs_btree_ops { +const char *name; +/* Type of btree - AG-rooted or inode-rooted */ enum xfs_btree_type type;
libxfs/xfs_ialloc.c +2 -3
@@ -136,9 +136,8 @@ xfs_inobt_complain_bad_rec(struct xfs_mount *mp = cur->bc_mp;xfs_warn (mp, -"%s Inode BTree record corruption in AG %d detected at %pS!" , - cur->bc_btnum ==XFS_BTNUM_INO ?"Used" :"Free" , - cur->bc_ag.pag->pag_agno, fa); +"%sbt record corruption in AG %d detected at %pS!" , + cur->bc_ops->name, cur->bc_ag.pag->pag_agno, fa); xfs_warn(mp, "start inode 0x%x, count 0x%x, free 0x%x freemask 0x%llx, holemask 0x%x", irec->ir_startino, irec->ir_count, irec->ir_freecount,
libxfs/xfs_ialloc_btree.c +2 -0
@@ -398,6 +398,7 @@ xfs_inobt_keys_contiguous( }const struct xfs_btree_ops xfs_inobt_ops = { + .name ="ino" , .type =XFS_BTREE_TYPE_AG , .rec_len =sizeof (xfs_inobt_rec_t),
@@ -426,6 +427,7 @@ const struct xfs_btree_ops xfs_inobt_ops = { };const struct xfs_btree_ops xfs_finobt_ops = { + .name ="fino" , .type =XFS_BTREE_TYPE_AG , .rec_len =sizeof (xfs_inobt_rec_t),
libxfs/xfs_refcount_btree.c +1 -0
@@ -317,6 +317,7 @@ xfs_refcountbt_keys_contiguous( }const struct xfs_btree_ops xfs_refcountbt_ops = { + .name ="refcount" , .type =XFS_BTREE_TYPE_AG , .rec_len =sizeof (struct xfs_refcount_rec ),
libxfs/xfs_rmap_btree.c +1 -0
@@ -470,6 +470,7 @@ xfs_rmapbt_keys_contiguous( }const struct xfs_btree_ops xfs_rmapbt_ops = { + .name ="rmap" , .type =XFS_BTREE_TYPE_AG , .geom_flags =XFS_BTGEO_OVERLAPPING ,
libxfs/xfs_types.h +0 -9
@@ -125,15 +125,6 @@ typedef enum { XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX } xfs_btnum_t; -#define XFS_BTNUM_STRINGS \ - { XFS_BTNUM_BNOi, "bnobt" }, \ - { XFS_BTNUM_CNTi, "cntbt" }, \ - { XFS_BTNUM_RMAPi, "rmapbt" }, \ - { XFS_BTNUM_BMAPi, "bmbt" }, \ - { XFS_BTNUM_INOi, "inobt" }, \ - { XFS_BTNUM_FINOi, "finobt" }, \ - { XFS_BTNUM_REFCi, "refcbt" } -struct xfs_name {const unsigned char *name;int len;
PATCH 67/111 xfs: add a sick_mask to struct xfs_btree_ops
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 7f47734ad61af77a001b1e24691dcbfcb008c938
Clean up xfs_btree_mark_sick by adding a sick_mask to the btree-ops for all AG-root btrees.
--- libxfs/xfs_alloc_btree.c | 3 +++ libxfs/xfs_btree.h | 3 +++ libxfs/xfs_ialloc_btree.c | 3 +++ libxfs/xfs_refcount_btree.c | 2 ++ libxfs/xfs_rmap_btree.c | 2 ++ 5 files changed, 13 insertions(+)
libxfs/xfs_alloc_btree.c +3 -0
@@ -17,6 +17,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_ag.h" +#include "xfs_health.h" static struct kmem_cache *xfs_allocbt_cur_cache;
@@ -475,6 +476,7 @@ const struct xfs_btree_ops xfs_bnobt_ops = { .lru_refs = XFS_ALLOC_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_abtb_2), + .sick_mask = XFS_SICK_AG_BNOBT, .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root,
@@ -506,6 +508,7 @@ const struct xfs_btree_ops xfs_cntbt_ops = { .lru_refs = XFS_ALLOC_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_abtc_2), + .sick_mask = XFS_SICK_AG_CNTBT, .dup_cursor = xfs_allocbt_dup_cursor, .set_root = xfs_allocbt_set_root,
libxfs/xfs_btree.h +3 -0
@@ -142,6 +142,9 @@ struct xfs_btree_ops {/* offset of btree stats array */ unsigned int statoff; +/* sick mask for health reporting (only for XFS_BTREE_TYPE_AG) */ +unsigned int sick_mask; +/* cursor operations */ struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *); void (*update_cursor)(struct xfs_btree_cur *src,
libxfs/xfs_ialloc_btree.c +3 -0
@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_rmap.h" #include "xfs_ag.h" +#include "xfs_health.h" static struct kmem_cache *xfs_inobt_cur_cache;
@@ -407,6 +408,7 @@ const struct xfs_btree_ops xfs_inobt_ops = { .lru_refs = XFS_INO_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_ibt_2), + .sick_mask = XFS_SICK_AG_INOBT, .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_inobt_set_root,
@@ -436,6 +438,7 @@ const struct xfs_btree_ops xfs_finobt_ops = { .lru_refs = XFS_INO_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_fibt_2), + .sick_mask = XFS_SICK_AG_FINOBT, .dup_cursor = xfs_inobt_dup_cursor, .set_root = xfs_finobt_set_root,
libxfs/xfs_refcount_btree.c +2 -0
@@ -20,6 +20,7 @@#include "xfs_bit.h" #include "xfs_rmap.h" #include "xfs_ag.h" +#include "xfs_health.h" static struct kmem_cache *xfs_refcountbt_cur_cache;
@@ -326,6 +327,7 @@ const struct xfs_btree_ops xfs_refcountbt_ops = { .lru_refs = XFS_REFC_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2), + .sick_mask = XFS_SICK_AG_REFCNTBT, .dup_cursor = xfs_refcountbt_dup_cursor, .set_root = xfs_refcountbt_set_root,
libxfs/xfs_rmap_btree.c +2 -0
@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_ag.h" #include "xfs_ag_resv.h" +#include "xfs_health.h" static struct kmem_cache *xfs_rmapbt_cur_cache;
@@ -481,6 +482,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops = { .lru_refs = XFS_RMAP_BTREE_REF, .statoff = XFS_STATS_CALC_INDEX(xs_rmap_2), + .sick_mask = XFS_SICK_AG_RMAPBT, .dup_cursor = xfs_rmapbt_dup_cursor, .set_root = xfs_rmapbt_set_root,
PATCH 68/111 xfs: split xfs_allocbt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 1c8b9fd278c08e16c27a41be484b77383738de1f
Split xfs_allocbt_init_cursor into separate routines for the by-bno and by-cnt btrees to prepare for the removal of the xfs_btnum global enumeration of btree types.
--- libxfs/libxfs_api_defs.h | 4 ++- libxfs/xfs_alloc.c | 36 +++++++++++++-------------- libxfs/xfs_alloc_btree.c | 62 +++++++++++++++++++++++++++++++++------------- libxfs/xfs_alloc_btree.h | 7 ++++- repair/agbtree.c | 6 +--- 5 files changed, 72 insertions(+), 43 deletions(-)
libxfs/libxfs_api_defs.h +3 -1
@@ -26,7 +26,6 @@#define xfs_alloc_ag_max_usable libxfs_alloc_ag_max_usable#define xfs_allocbt_calc_size libxfs_allocbt_calc_size -#define xfs_allocbt_init_cursor libxfs_allocbt_init_cursor#define xfs_allocbt_maxlevels_ondisk libxfs_allocbt_maxlevels_ondisk#define xfs_allocbt_maxrecs libxfs_allocbt_maxrecs#define xfs_allocbt_stage_cursor libxfs_allocbt_stage_cursor
@@ -60,6 +59,8 @@#define xfs_bmbt_stage_cursor libxfs_bmbt_stage_cursor#define xfs_bmdr_maxrecs libxfs_bmdr_maxrecs +#define xfs_bnobt_init_cursor libxfs_bnobt_init_cursor +#define xfs_btree_bload libxfs_btree_bload#define xfs_btree_bload_compute_geometry libxfs_btree_bload_compute_geometry#define xfs_btree_del_cursor libxfs_btree_del_cursor
@@ -78,6 +79,7 @@#define xfs_bunmapi libxfs_bunmapi#define xfs_bwrite libxfs_bwrite#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_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk#define xfs_da_get_buf libxfs_da_get_buf
libxfs/xfs_alloc.c +18 -18
@@ -858,8 +858,8 @@ xfs_alloc_cur_setup(* attempt a small allocation. */ if (!acur->cnt) - acur->cnt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->pag,XFS_BTNUM_CNT ); + acur->cnt =xfs_cntbt_init_cursor (args->mp, args->tp, + args->agbp, args->pag); error =xfs_alloc_lookup_ge (acur->cnt,0 , args->maxlen, &i);if (error)return error;
@@ -868,11 +868,11 @@ xfs_alloc_cur_setup(* Allocate the bnobt left and right search cursors. */ if (!acur->bnolt) - acur->bnolt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->pag,XFS_BTNUM_BNO ); + acur->bnolt =xfs_bnobt_init_cursor (args->mp, args->tp, + args->agbp, args->pag);if (!acur->bnogt) - acur->bnogt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->pag,XFS_BTNUM_BNO ); + acur->bnogt =xfs_bnobt_init_cursor (args->mp, args->tp, + args->agbp, args->pag);return i ==1 ?0 : -ENOSPC ; }
@@ -1230,8 +1230,8 @@ xfs_alloc_ag_vextent_exact(/* * Allocate/initialize a cursor for the by-number freespace btree. */ - bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag,XFS_BTNUM_BNO ); + bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, args->agbp, + args->pag);/* * Lookup bno and minlen in the btree (minlen is irrelevant, really).
@@ -1291,8 +1291,8 @@ xfs_alloc_ag_vextent_exact(* We are allocating agbno for args->len * Allocate/initialize a cursor for the by-size btree. */ - cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag,XFS_BTNUM_CNT ); + 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)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );
@@ -1706,8 +1706,8 @@ xfs_alloc_ag_vextent_size(/* * Allocate and initialize a cursor for the by-size btree. */ - cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag,XFS_BTNUM_CNT ); + cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, args->agbp, + args->pag); bno_cur =NULL ;/*
@@ -1892,8 +1892,8 @@ xfs_alloc_ag_vextent_size(/* * Allocate and initialize a cursor for the by-block tree. */ - bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag,XFS_BTNUM_BNO ); + bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, args->agbp, + args->pag);if ((error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, rbno, rlen,XFSA_FIXUP_CNT_OK ))) goto error0;
@@ -1967,7 +1967,7 @@ xfs_free_ag_extent(/* * Allocate and initialize a cursor for the by-block btree. */ - bno_cur =xfs_allocbt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_BNO ); + bno_cur =xfs_bnobt_init_cursor (mp, tp, agbp, pag);/* * Look for a neighboring block on the left (lower block numbers) * that is contiguous with this space.
@@ -2041,7 +2041,7 @@ xfs_free_ag_extent(/* * Now allocate and initialize a cursor for the by-size tree. */ - cnt_cur =xfs_allocbt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_CNT ); + cnt_cur =xfs_cntbt_init_cursor (mp, tp, agbp, pag);/* * Have both left and right contiguous neighbors. * Merge all three into a single free block.
@@ -2750,8 +2750,8 @@ xfs_exact_minlen_extent_available(xfs_extlen_t flen;int error =0 ; - cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, agbp, - args->pag,XFS_BTNUM_CNT ); + cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, agbp, + args->pag); error =xfs_alloc_lookup_ge (cnt_cur,0 , args->minlen, stat);if (error) goto out;
libxfs/xfs_alloc_btree.c +44 -18
107 lines not on this page · raw message
libxfs/xfs_alloc_btree.h +5 -2
@@ -47,9 +47,12 @@ struct xbtree_afakeroot; (maxrecs) * sizeof(xfs_alloc_key_t) + \ ((index) - 1) * sizeof(xfs_alloc_ptr_t))) -extern struct xfs_btree_cur *xfs_allocbt_init_cursor (struct xfs_mount *mp, +struct xfs_btree_cur *xfs_bnobt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *bp, -struct xfs_perag *pag,xfs_btnum_t btnum); +struct xfs_perag *pag); +struct xfs_btree_cur *xfs_cntbt_init_cursor (struct xfs_mount *mp, +struct xfs_trans *tp,struct xfs_buf *bp, +struct xfs_perag *pag);extern int xfs_allocbt_maxrecs (struct xfs_mount *,int ,int );extern xfs_extlen_t xfs_allocbt_calc_size (struct xfs_mount *mp,unsigned long long len);
repair/agbtree.c +2 -4
@@ -262,12 +262,10 @@ init_freespace_cursors(init_rebuild (sc, &XFS_RMAP_OINFO_AG , est_agfreeblocks, btr_bno);init_rebuild (sc, &XFS_RMAP_OINFO_AG , est_agfreeblocks, btr_cnt); - btr_bno->cur =libxfs_allocbt_init_cursor (sc->mp,NULL ,NULL , pag, -XFS_BTNUM_BNO ); + btr_bno->cur =libxfs_bnobt_init_cursor (sc->mp,NULL ,NULL , pag);libxfs_btree_stage_afakeroot (btr_bno->cur, &btr_bno->newbt.afake); - btr_cnt->cur =libxfs_allocbt_init_cursor (sc->mp,NULL ,NULL , pag, -XFS_BTNUM_CNT ); + btr_cnt->cur =libxfs_cntbt_init_cursor (sc->mp,NULL ,NULL , pag);libxfs_btree_stage_afakeroot (btr_cnt->cur, &btr_cnt->newbt.afake); btr_bno->bload.get_records = get_bnobt_records;
PATCH 69/111 xfs: remove xfs_inobt_cur
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 3038fd8129384c64946c17198229ee61f6f2c8e1
This helper provides no real advantage over just open code the two calls in it in the callers.
--- libxfs/xfs_ialloc_btree.c | 29 +++-------------------------- libxfs/xfs_ialloc_btree.h | 3 --- 2 files changed, 3 insertions(+), 29 deletions(-)
libxfs/xfs_ialloc_btree.c +3 -26
@@ -709,30 +709,6 @@ xfs_inobt_max_size( XFS_INODES_PER_CHUNK); } -/* Read AGI and create inobt cursor. */ -int -xfs_inobt_cur ( -struct xfs_perag *pag, -struct xfs_trans *tp, -xfs_btnum_t which, -struct xfs_btree_cur **curpp, -struct xfs_buf **agi_bpp) -{ -struct xfs_btree_cur *cur; -int error; - -ASSERT (*agi_bpp ==NULL ); -ASSERT (*curpp ==NULL ); - - error =xfs_ialloc_read_agi (pag, tp, agi_bpp); -if (error) -return error; - - cur =xfs_inobt_init_cursor (pag, tp, *agi_bpp, which); - *curpp = cur; -return 0 ; -} - static int xfs_inobt_count_blocks( struct xfs_perag *pag,
@@ -741,13 +717,14 @@ xfs_inobt_count_blocks( xfs_extlen_t *tree_blocks) {struct xfs_buf *agbp =NULL ; -struct xfs_btree_cur *cur =NULL ; +struct xfs_btree_cur *cur;int error; - error =xfs_inobt_cur (pag, tp, btnum, &cur, &agbp); + error =xfs_ialloc_read_agi (pag, tp, &agbp);if (error)return error; + cur =xfs_inobt_init_cursor (pag, tp, agbp, btnum); error =xfs_btree_count_blocks (cur, tree_blocks);xfs_btree_del_cursor (cur, error);xfs_trans_brelse (tp, agbp);
libxfs/xfs_ialloc_btree.h +0 -3
@@ -64,9 +64,6 @@ int xfs_finobt_calc_reserves(struct xfs_perag *perag, struct xfs_trans *tp, xfs_extlen_t *ask, xfs_extlen_t *used);extern xfs_extlen_t xfs_iallocbt_calc_size (struct xfs_mount *mp,unsigned long long len); -int xfs_inobt_cur (struct xfs_perag *pag,struct xfs_trans *tp, -xfs_btnum_t btnum,struct xfs_btree_cur **curpp, -struct xfs_buf **agi_bpp);void xfs_inobt_commit_staged_btree (struct xfs_btree_cur *cur,struct xfs_trans *tp,struct xfs_buf *agbp);
PATCH 70/111 xfs: remove the btnum argument to xfs_inobt_count_blocks
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4bfb028a4c00d0a079a625d7867325efb3c37de2
xfs_inobt_count_blocks is only used for the finobt. Hardcode the btnum argument and rename the function to match that.
--- libxfs/xfs_ialloc_btree.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
libxfs/xfs_ialloc_btree.c +3 -5
@@ -710,10 +710,9 @@ xfs_inobt_max_size( }static int -xfs_inobt_count_blocks ( +xfs_finobt_count_blocks (struct xfs_perag *pag,struct xfs_trans *tp, -xfs_btnum_t btnum,xfs_extlen_t *tree_blocks) {struct xfs_buf *agbp =NULL ;
@@ -724,7 +723,7 @@ xfs_inobt_count_blocks(if (error)return error; - cur =xfs_inobt_init_cursor (pag, tp, agbp, btnum); + cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_FINO ); error =xfs_btree_count_blocks (cur, tree_blocks);xfs_btree_del_cursor (cur, error);xfs_trans_brelse (tp, agbp);
@@ -772,8 +771,7 @@ xfs_finobt_calc_reserves(if (xfs_has_inobtcounts (pag->pag_mount)) error =xfs_finobt_read_blocks (pag, tp, &tree_len);else - error =xfs_inobt_count_blocks (pag, tp,XFS_BTNUM_FINO , - &tree_len); + error =xfs_finobt_count_blocks (pag, tp, &tree_len);if (error)return error;
PATCH 71/111 xfs: split xfs_inobt_insert_sprec
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 8541a7d9da2dd6e44f401f2363b21749b7413fc9
Split the finobt version that never merges and uses a different cursor out of xfs_inobt_insert_sprec to prepare for removing xfs_btnum_t.
--- libxfs/xfs_ialloc.c | 148 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 52 deletions(-)
libxfs/xfs_ialloc.c +96 -52
@@ -524,16 +524,14 @@ __xfs_inobt_rec_merge( }/* -* Insert a new sparse inode chunk into the associated inode btree. The inode -* record for the sparse chunk is pre-aligned to a startino that should match -* any pre-existing sparse inode record in the tree. This allows sparse chunks -* to fill over time. +* Insert a new sparse inode chunk into the associated inode allocation btree. +* The inode record for the sparse chunk is pre-aligned to a startino that +* should match any pre-existing sparse inode record in the tree. This allows +* sparse chunks to fill over time. * -* This function supports two modes of handling preexisting records depending on -* the merge flag. If merge is true, the provided record is merged with the +* If no preexisting record exists, the provided record is inserted. +* If there is a preexisting record, the provided record is merged with the * existing record and updated in place. The merged record is returned in nrec. -* If merge is false, an existing record is replaced with the provided record. -* If no preexisting record exists, the provided record is always inserted. * * It is considered corruption if a merge is requested and not possible. Given * the sparse inode alignment constraints, this should never happen.
@@ -543,9 +541,7 @@ xfs_inobt_insert_sprec(struct xfs_perag *pag, struct xfs_trans *tp, struct xfs_buf *agbp, - int btnum, - struct xfs_inobt_rec_incore *nrec, /* in/out: new/merged rec. */ - bool merge) /* merge or replace */ + struct xfs_inobt_rec_incore *nrec) /* in/out: new/merged rec. */ { struct xfs_mount *mp = pag->pag_mount;struct xfs_btree_cur *cur;
@@ -553,7 +549,7 @@ xfs_inobt_insert_sprec(int i;struct xfs_inobt_rec_incore rec; - cur =xfs_inobt_init_cursor (pag, tp, agbp, btnum); + cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO );/* the new record is pre-aligned so we know where to look */ error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i);
@@ -576,48 +572,45 @@ xfs_inobt_insert_sprec( }/* -* A record exists at this startino. Merge or replace the record -* depending on what we've been asked to do. +* A record exists at this startino. Merge the records. */ -if (merge) { - error =xfs_inobt_get_rec (cur, &rec, &i); -if (error) - goto error; -if (XFS_IS_CORRUPT (mp, i !=1 )) { -xfs_btree_mark_sick (cur); - error = -EFSCORRUPTED ; - goto error; - } -if (XFS_IS_CORRUPT (mp, rec.ir_startino != nrec->ir_startino)) { -xfs_btree_mark_sick (cur); - error = -EFSCORRUPTED ; - goto error; - } + error =xfs_inobt_get_rec (cur, &rec, &i); +if (error) + goto error; +if (XFS_IS_CORRUPT (mp, i !=1 )) { +xfs_btree_mark_sick (cur); + error = -EFSCORRUPTED ; + goto error; + } +if (XFS_IS_CORRUPT (mp, rec.ir_startino != nrec->ir_startino)) { +xfs_btree_mark_sick (cur); + error = -EFSCORRUPTED ; + goto error; + } -/* -* This should never fail. If we have coexisting records that -* cannot merge, something is seriously wrong. -*/ -if (XFS_IS_CORRUPT (mp, !__xfs_inobt_can_merge (nrec, &rec))) { -xfs_btree_mark_sick (cur); - error = -EFSCORRUPTED ; - goto error; - } +/* +* This should never fail. If we have coexisting records that +* cannot merge, something is seriously wrong. +*/ +if (XFS_IS_CORRUPT (mp, !__xfs_inobt_can_merge (nrec, &rec))) { +xfs_btree_mark_sick (cur); + error = -EFSCORRUPTED ; + goto error; + } -trace_xfs_irec_merge_pre (mp, pag->pag_agno, rec.ir_startino, - rec.ir_holemask, nrec->ir_startino, - nrec->ir_holemask); +trace_xfs_irec_merge_pre (mp, pag->pag_agno, rec.ir_startino, + rec.ir_holemask, nrec->ir_startino, + nrec->ir_holemask); -/* merge to nrec to output the updated record */ -__xfs_inobt_rec_merge (nrec, &rec); +/* merge to nrec to output the updated record */ +__xfs_inobt_rec_merge (nrec, &rec); -trace_xfs_irec_merge_post (mp, pag->pag_agno, nrec->ir_startino, - nrec->ir_holemask); +trace_xfs_irec_merge_post (mp, pag->pag_agno, nrec->ir_startino, + nrec->ir_holemask); - error =xfs_inobt_rec_check_count (mp, nrec); -if (error) - goto error; - } + error =xfs_inobt_rec_check_count (mp, nrec); +if (error) + goto error; error =xfs_inobt_update (cur, nrec);if (error)
@@ -631,6 +624,59 @@ xfs_inobt_insert_sprec(return error; } +/* +* Insert a new sparse inode chunk into the free inode btree. The inode +* record for the sparse chunk is pre-aligned to a startino that should match +* any pre-existing sparse inode record in the tree. This allows sparse chunks +* to fill over time. +* +* The new record is always inserted, overwriting a pre-existing record if +* there is one. +*/ +STATIC int +xfs_finobt_insert_sprec ( +struct xfs_perag *pag, +struct xfs_trans *tp, +struct xfs_buf *agbp, +struct xfs_inobt_rec_incore *nrec)/* in/out: new rec. */ +{ +struct xfs_mount *mp = pag->pag_mount; +struct xfs_btree_cur *cur; +int error; +int i; + + cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_FINO ); + +/* the new record is pre-aligned so we know where to look */ + error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i); +if (error) + goto error; +/* if nothing there, insert a new record and return */ +if (i ==0 ) { + error =xfs_inobt_insert_rec (cur, nrec->ir_holemask, + nrec->ir_count, nrec->ir_freecount, + nrec->ir_free, &i); +if (error) + goto error; +if (XFS_IS_CORRUPT (mp, i !=1 )) { +xfs_btree_mark_sick (cur); + error = -EFSCORRUPTED ; + goto error; + } + }else { + error =xfs_inobt_update (cur, nrec); +if (error) + goto error; + } + +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); +return 0 ; +error: +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; +} + +/* * Allocate new inodes in the allocation group specified by agbp. Returns 0 if * inodes were allocated in this AG; -EAGAIN if there was no space in this AG so
@@ -857,8 +903,7 @@ xfs_ialloc_ag_alloc(* if necessary. If a merge does occur, rec is updated to the * merged record. */ - error =xfs_inobt_insert_sprec (pag, tp, agbp, -XFS_BTNUM_INO , &rec, true); + error =xfs_inobt_insert_sprec (pag, tp, agbp, &rec);if (error == -EFSCORRUPTED ) { xfs_alert(args.mp, "invalid sparse inode record: ino 0x%llx holemask 0x%x count %u",
@@ -882,8 +927,7 @@ xfs_ialloc_ag_alloc(* existing record with this one. */ if (xfs_has_finobt (args.mp)) { - error =xfs_inobt_insert_sprec (pag, tp, agbp, -XFS_BTNUM_FINO , &rec, false); + error =xfs_finobt_insert_sprec (pag, tp, agbp, &rec);if (error)return error; }
PATCH 72/111 xfs: split xfs_inobt_init_cursor
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 14dd46cf31f4aaffcf26b00de9af39d01ec8d547
Split xfs_inobt_init_cursor into separate routines for the inobt and finobt to prepare for the removal of the xfs_btnum global enumeration of btree types.
--- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_ialloc.c | 23 +++++++++++--------- libxfs/xfs_ialloc_btree.c | 51 ++++++++++++++++++++++++++++++++++----------- libxfs/xfs_ialloc_btree.h | 6 ++++- repair/agbtree.c | 6 ++--- 5 files changed, 58 insertions(+), 29 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -129,6 +129,7 @@#define xfs_dquot_verify libxfs_dquot_verify#define xfs_finobt_calc_reserves libxfs_finobt_calc_reserves +#define xfs_finobt_init_cursor libxfs_finobt_init_cursor#define xfs_free_extent libxfs_free_extent#define xfs_free_extent_later libxfs_free_extent_later#define xfs_free_perag libxfs_free_perag
libxfs/xfs_ialloc.c +13 -10
@@ -208,7 +208,10 @@ xfs_inobt_insert(int i;int error; - cur =xfs_inobt_init_cursor (pag, tp, agbp, btnum); +if (btnum ==XFS_BTNUM_FINO ) + cur =xfs_finobt_init_cursor (pag, tp, agbp); +else + cur =xfs_inobt_init_cursor (pag, tp, agbp); for (thisino = newino; thisino < newino + newlen;
@@ -549,7 +552,7 @@ xfs_inobt_insert_sprec(int i;struct xfs_inobt_rec_incore rec; - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (pag, tp, agbp);/* the new record is pre-aligned so we know where to look */ error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i);
@@ -645,7 +648,7 @@ xfs_finobt_insert_sprec(int error;int i; - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_FINO ); + cur =xfs_finobt_init_cursor (pag, tp, agbp);/* the new record is pre-aligned so we know where to look */ error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i);
@@ -1078,7 +1081,7 @@ xfs_dialloc_ag_inobt(ASSERT (pag->pagi_freecount >0 ); restart_pagno: - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (pag, tp, agbp);/* * If pagino is 0 (this is the root inode allocation) use newino. * This must work because we've just allocated some.
@@ -1552,7 +1555,7 @@ xfs_dialloc_ag(if (!pagino) pagino =be32_to_cpu (agi->agi_newino); - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_FINO ); + cur =xfs_finobt_init_cursor (pag, tp, agbp); error =xfs_check_agi_freecount (cur);if (error)
@@ -1595,7 +1598,7 @@ xfs_dialloc_ag(* the original freecount. If all is well, make the equivalent update to * the inobt using the finobt record and offset information. */ - icur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO ); + icur =xfs_inobt_init_cursor (pag, tp, agbp); error =xfs_check_agi_freecount (icur);if (error)
@@ -2012,7 +2015,7 @@ xfs_difree_inobt(/* * Initialize the cursor. */ - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (pag, tp, agbp); error =xfs_check_agi_freecount (cur);if (error)
@@ -2139,7 +2142,7 @@ xfs_difree_finobt(int error;int i; - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_FINO ); + cur =xfs_finobt_init_cursor (pag, tp, agbp); error =xfs_inobt_lookup (cur, ibtrec->ir_startino,XFS_LOOKUP_EQ , &i);if (error)
@@ -2339,7 +2342,7 @@ xfs_imap_lookup(* we have a record, we need to ensure it contains the inode number * we are looking up. */ - cur =xfs_inobt_init_cursor (pag, tp, agbp,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (pag, tp, agbp); error =xfs_inobt_lookup (cur, agino,XFS_LOOKUP_LE , &i);if (!error) {if (i)
@@ -3058,7 +3061,7 @@ xfs_ialloc_check_shrink(if (!xfs_has_sparseinodes (pag->pag_mount))return 0 ; - cur =xfs_inobt_init_cursor (pag, tp, agibp,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (pag, tp, agibp);/* Look up the inobt record that would correspond to the new EOFS. */ agino =XFS_AGB_TO_AGINO (pag->pag_mount, new_length);
libxfs/xfs_ialloc_btree.c +38 -13
87 lines not on this page · raw message
libxfs/xfs_ialloc_btree.h +4 -2
@@ -46,8 +46,10 @@ struct xfs_perag; (maxrecs) * sizeof(xfs_inobt_key_t) + \ ((index) - 1) * sizeof(xfs_inobt_ptr_t))) -extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_perag *pag, -struct xfs_trans *tp,struct xfs_buf *agbp,xfs_btnum_t btnum); +struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_perag *pag, +struct xfs_trans *tp,struct xfs_buf *agbp); +struct xfs_btree_cur *xfs_finobt_init_cursor (struct xfs_perag *pag, +struct xfs_trans *tp,struct xfs_buf *agbp);extern int xfs_inobt_maxrecs (struct xfs_mount *,int ,int );/* ir_holemask to inode allocation bitmap conversion */
repair/agbtree.c +2 -4
@@ -522,8 +522,7 @@ init_ino_cursors( fino_recs++; } - btr_ino->cur =libxfs_inobt_init_cursor (pag,NULL ,NULL , -XFS_BTNUM_INO ); + btr_ino->cur =libxfs_inobt_init_cursor (pag,NULL ,NULL );libxfs_btree_stage_afakeroot (btr_ino->cur, &btr_ino->newbt.afake); btr_ino->bload.get_records = get_inobt_records;
@@ -543,8 +542,7 @@ _("Unable to compute inode btree geometry, error %d.\n"), error);return ;init_rebuild (sc, &XFS_RMAP_OINFO_INOBT , est_agfreeblocks, btr_fino); - btr_fino->cur =libxfs_inobt_init_cursor (pag,NULL ,NULL , -XFS_BTNUM_FINO ); + btr_fino->cur =libxfs_finobt_init_cursor (pag,NULL ,NULL );libxfs_btree_stage_afakeroot (btr_fino->cur, &btr_fino->newbt.afake); btr_fino->bload.get_records = get_inobt_records;
PATCH 73/111 xfs: pass a 'bool is_finobt' to xfs_inobt_insert
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: fbeef4e061ab28bf556af4ee2a5a9848dc4616c5
This is one of the last users of xfs_btnum_t and can only designate either the inobt or finobt. Replace it with a simple bool.
--- libxfs/xfs_ialloc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
libxfs/xfs_ialloc.c +4 -5
@@ -201,14 +201,14 @@ xfs_inobt_insert(struct xfs_buf *agbp, xfs_agino_t newino, xfs_agino_t newlen, - xfs_btnum_t btnum) + bool is_finobt) { struct xfs_btree_cur *cur;xfs_agino_t thisino;int i;int error; -if (btnum ==XFS_BTNUM_FINO ) +if (is_finobt) cur =xfs_finobt_init_cursor (pag, tp, agbp);else cur =xfs_inobt_init_cursor (pag, tp, agbp);
@@ -936,14 +936,13 @@ xfs_ialloc_ag_alloc( } }else {/* full chunk - insert new records to both btrees */ - error =xfs_inobt_insert (pag, tp, agbp, newino, newlen, -XFS_BTNUM_INO ); + error =xfs_inobt_insert (pag, tp, agbp, newino, newlen, false);if (error)return error;if (xfs_has_finobt (args.mp)) { error =xfs_inobt_insert (pag, tp, agbp, newino, - newlen,XFS_BTNUM_FINO ); + newlen, true);if (error)return error; }
PATCH 74/111 xfs: remove xfs_btnum_t
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: ec793e690f801d97a7ae2a0d429fea1fee4d44aa
The last checks for bc_btnum can be replaced with helpers that check the btree ops. This allows adding new btrees to XFS without having to update a global enum.
--- libxfs/xfs_alloc.c | 6 +++--- libxfs/xfs_alloc_btree.c | 12 ++++++------ libxfs/xfs_bmap_btree.c | 4 ++-- libxfs/xfs_btree.c | 4 ++-- libxfs/xfs_btree.h | 11 ----------- libxfs/xfs_ialloc.c | 2 +- libxfs/xfs_ialloc_btree.c | 10 +++++----- libxfs/xfs_refcount_btree.c | 5 ++--- libxfs/xfs_rmap_btree.c | 2 +- libxfs/xfs_shared.h | 35 +++++++++++++++++++++++++++++++++++ libxfs/xfs_types.h | 9 --------- repair/agbtree.c | 4 ++-- repair/phase5.c | 6 ++---- 13 files changed, 61 insertions(+), 49 deletions(-)
libxfs/xfs_alloc.c +3 -3
@@ -914,7 +914,7 @@ xfs_alloc_cur_check(bool busy;unsigned busy_gen =0 ;bool deactivate = false; -bool isbnobt = cur->bc_btnum ==XFS_BTNUM_BNO ; +bool isbnobt =xfs_btree_is_bno (cur->bc_ops); *new =0 ;
@@ -4022,7 +4022,7 @@ xfs_alloc_query_range(union xfs_btree_irec high_brec = { .a = *high_rec };struct xfs_alloc_query_range_info query = { .priv = priv, .fn = fn }; -ASSERT (cur->bc_btnum ==XFS_BTNUM_BNO ); +ASSERT (xfs_btree_is_bno (cur->bc_ops));return xfs_btree_query_range (cur, &low_brec, &high_brec, xfs_alloc_query_range_helper, &query); }
@@ -4036,7 +4036,7 @@ xfs_alloc_query_all( {struct xfs_alloc_query_range_info query; -ASSERT (cur->bc_btnum ==XFS_BTNUM_BNO ); +ASSERT (xfs_btree_is_bno (cur->bc_ops)); query.priv = priv; query.fn = fn;return xfs_btree_query_all (cur, xfs_alloc_query_range_helper, &query);
libxfs/xfs_alloc_btree.c +6 -6
@@ -49,7 +49,7 @@ xfs_allocbt_set_root(ASSERT (ptr->s !=0 ); -if (cur->bc_btnum ==XFS_BTNUM_BNO ) { +if (xfs_btree_is_bno (cur->bc_ops)) { agf->agf_bno_root = ptr->s;be32_add_cpu (&agf->agf_bno_level, inc); cur->bc_ag.pag->pagf_bno_level += inc;
@@ -129,7 +129,7 @@ xfs_allocbt_update_lastrec(__be32 len;int numrecs; -ASSERT (cur->bc_btnum ==XFS_BTNUM_CNT ); +ASSERT (!xfs_btree_is_bno (cur->bc_ops));switch (reason) {case LASTREC_UPDATE :
@@ -239,7 +239,7 @@ xfs_allocbt_init_ptr_from_cur(ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agf->agf_seqno)); -if (cur->bc_btnum ==XFS_BTNUM_BNO ) +if (xfs_btree_is_bno (cur->bc_ops)) ptr->s = agf->agf_bno_root;else ptr->s = agf->agf_cnt_root;
@@ -552,7 +552,7 @@ xfs_bnobt_init_cursor( {struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BNO , &xfs_bnobt_ops, + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_bnobt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.agbp = agbp;
@@ -578,7 +578,7 @@ xfs_cntbt_init_cursor( {struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_CNT , &xfs_cntbt_ops, + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_cntbt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.agbp = agbp;
@@ -605,7 +605,7 @@ xfs_allocbt_commit_staged_btree(ASSERT (cur->bc_flags &XFS_BTREE_STAGING ); -if (cur->bc_btnum ==XFS_BTNUM_BNO ) { +if (xfs_btree_is_bno (cur->bc_ops)) { agf->agf_bno_root =cpu_to_be32 (afake->af_root); agf->agf_bno_level =cpu_to_be32 (afake->af_levels); }else {
libxfs/xfs_bmap_btree.c +2 -2
@@ -573,8 +573,8 @@ xfs_bmbt_init_cursor( maxlevels = mp->m_bm_maxlevels[whichfork];break ; } - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_BMAP , &xfs_bmbt_ops, - maxlevels, xfs_bmbt_cur_cache); + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_bmbt_ops, maxlevels, + xfs_bmbt_cur_cache); cur->bc_ino.ip = ip; cur->bc_ino.whichfork = whichfork; cur->bc_bmap.allocated =0 ;
libxfs/xfs_btree.c +2 -2
@@ -451,7 +451,7 @@ xfs_btree_del_cursor(* zero, then we should be shut down or on our way to shutdown due to * cancelling a dirty transaction on error. */ -ASSERT (cur->bc_btnum !=XFS_BTNUM_BMAP || cur->bc_bmap.allocated ==0 || +ASSERT (!xfs_btree_is_bmap (cur->bc_ops) || cur->bc_bmap.allocated ==0 ||xfs_is_shutdown (cur->bc_mp) || error !=0 );switch (cur->bc_ops->type) {
@@ -3013,7 +3013,7 @@ xfs_btree_split(struct xfs_btree_split_args args;DECLARE_COMPLETION_ONSTACK (done); -if (cur->bc_btnum !=XFS_BTNUM_BMAP || +if (!xfs_btree_is_bmap (cur->bc_ops) || cur->bc_tp->t_highest_agno ==NULLAGNUMBER )return __xfs_btree_split (cur, level, ptrp, key, curp, stat);
libxfs/xfs_btree.h +0 -11
@@ -55,14 +55,6 @@ union xfs_btree_rec {#define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi)#define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi) -#define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi) -#define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi) -#define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi) -#define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi) -#define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi) -#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi) -#define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi) -struct xfs_btree_ops ;uint32_t xfs_btree_magic (struct xfs_mount *mp,const struct xfs_btree_ops *ops);
@@ -272,7 +264,6 @@ struct xfs_btree_curconst struct xfs_btree_ops *bc_ops;struct kmem_cache *bc_cache;/* cursor cache */ unsigned int bc_flags;/* btree features - below */ -xfs_btnum_t bc_btnum;/* identifies which btree type */ union xfs_btree_irec bc_rec;/* current insert/search record value */ uint8_t bc_nlevels;/* number of levels in the tree */ uint8_t bc_maxlevels;/* maximum levels for this btree type */
@@ -726,7 +717,6 @@ static inline struct xfs_btree_cur *xfs_btree_alloc_cursor ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_btnum_t btnum, const struct xfs_btree_ops *ops, uint8_t maxlevels, struct kmem_cache *cache)
@@ -742,7 +732,6 @@ xfs_btree_alloc_cursor( cur->bc_ops = ops; cur->bc_tp = tp; cur->bc_mp = mp; - cur->bc_btnum = btnum; cur->bc_maxlevels = maxlevels; cur->bc_cache = cache;
libxfs/xfs_ialloc.c +1 -1
@@ -2843,7 +2843,7 @@ xfs_ialloc_count_inodes(struct xfs_ialloc_count_inodes ci = {0 };int error; -ASSERT (cur->bc_btnum ==XFS_BTNUM_INO ); +ASSERT (xfs_btree_is_ino (cur->bc_ops)); error =xfs_btree_query_all (cur, xfs_ialloc_count_inodes_rec, &ci);if (error)return error;
libxfs/xfs_ialloc_btree.c +5 -5
@@ -89,9 +89,9 @@ xfs_inobt_mod_blockcount(if (!xfs_has_inobtcounts (cur->bc_mp))return ; -if (cur->bc_btnum ==XFS_BTNUM_FINO ) +if (xfs_btree_is_fino (cur->bc_ops))be32_add_cpu (&agi->agi_fblocks, howmuch); -else if (cur->bc_btnum ==XFS_BTNUM_INO ) +else be32_add_cpu (&agi->agi_iblocks, howmuch);xfs_ialloc_log_agi (cur->bc_tp, agbp,XFS_AGI_IBLOCKS ); }
@@ -480,7 +480,7 @@ xfs_inobt_init_cursor(struct xfs_mount *mp = pag->pag_mount;struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_INO , &xfs_inobt_ops, + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_inobt_ops,M_IGEO (mp)->inobt_maxlevels, xfs_inobt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.agbp = agbp;
@@ -506,7 +506,7 @@ xfs_finobt_init_cursor(struct xfs_mount *mp = pag->pag_mount;struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_FINO , &xfs_finobt_ops, + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_finobt_ops,M_IGEO (mp)->inobt_maxlevels, xfs_inobt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.agbp = agbp;
@@ -534,7 +534,7 @@ xfs_inobt_commit_staged_btree(ASSERT (cur->bc_flags &XFS_BTREE_STAGING ); -if (cur->bc_btnum ==XFS_BTNUM_INO ) { +if (xfs_btree_is_ino (cur->bc_ops)) { fields =XFS_AGI_ROOT |XFS_AGI_LEVEL ; agi->agi_root =cpu_to_be32 (afake->af_root); agi->agi_level =cpu_to_be32 (afake->af_levels);
libxfs/xfs_refcount_btree.c +2 -3
@@ -363,9 +363,8 @@ xfs_refcountbt_init_cursor(ASSERT (pag->pag_agno < mp->m_sb.sb_agcount); - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_REFC , - &xfs_refcountbt_ops, mp->m_refc_maxlevels, - xfs_refcountbt_cur_cache); + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_refcountbt_ops, + mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_refc.nr_ops =0 ; cur->bc_refc.shape_changes =0 ;
libxfs/xfs_rmap_btree.c +1 -1
@@ -516,7 +516,7 @@ xfs_rmapbt_init_cursor( {struct xfs_btree_cur *cur; - cur =xfs_btree_alloc_cursor (mp, tp,XFS_BTNUM_RMAP , &xfs_rmapbt_ops, + cur =xfs_btree_alloc_cursor (mp, tp, &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); cur->bc_ag.pag =xfs_perag_hold (pag); cur->bc_ag.agbp = agbp;
libxfs/xfs_shared.h +35 -0
@@ -52,6 +52,41 @@ extern const struct xfs_btree_ops xfs_bmbt_ops;extern const struct xfs_btree_ops xfs_refcountbt_ops;extern const struct xfs_btree_ops xfs_rmapbt_ops; +static inline bool xfs_btree_is_bno (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_bnobt_ops; +} + +static inline bool xfs_btree_is_cnt (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_cntbt_ops; +} + +static inline bool xfs_btree_is_bmap (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_bmbt_ops; +} + +static inline bool xfs_btree_is_ino (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_inobt_ops; +} + +static inline bool xfs_btree_is_fino (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_finobt_ops; +} + +static inline bool xfs_btree_is_refcount (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_refcountbt_ops; +} + +static inline bool xfs_btree_is_rmap (const struct xfs_btree_ops *ops) +{ +return ops == &xfs_rmapbt_ops; +} +/* log size calculation functions */ int xfs_log_calc_unit_res (struct xfs_mount *mp,int unit_bytes);int xfs_log_calc_minimum_size (struct xfs_mount *);
libxfs/xfs_types.h +0 -9
@@ -116,15 +116,6 @@ typedef enum { { XFS_LOOKUP_LEi, "le" }, \ { XFS_LOOKUP_GEi, "ge" } -/* -* This enum is used in string mapping in xfs_trace.h and scrub/trace.h; -* please keep the TRACE_DEFINE_ENUMs for it up to date. -*/ -typedef enum { - XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi, - XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi,XFS_BTNUM_MAX -}xfs_btnum_t ; -struct xfs_name {const unsigned char *name;int len;
repair/agbtree.c +2 -2
@@ -204,7 +204,7 @@ get_bno_rec( {xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno; -if (cur->bc_btnum ==XFS_BTNUM_BNO ) { +if (xfs_btree_is_bno (cur->bc_ops)) {if (!prev_value)return findfirst_bno_extent (agno);return findnext_bno_extent (prev_value);
@@ -378,7 +378,7 @@ get_ino_rec( {xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno; -if (cur->bc_btnum ==XFS_BTNUM_INO ) { +if (xfs_btree_is_ino (cur->bc_ops)) {if (!prev_value)return findfirst_inode_rec (agno);return next_ino_rec (prev_value);
repair/phase5.c +2 -4
@@ -304,11 +304,9 @@ build_agf_agfl( }#ifdef XR_BLD_FREE_TRACE -fprintf (stderr,"bno root = %u, bcnt root = %u, indices = %u %u\n" , +fprintf (stderr,"bno root = %u, bcnt root = %u\n" ,be32_to_cpu (agf->agf_bno_root), -be32_to_cpu (agf->agf_cnt_root), -XFS_BTNUM_BNO , -XFS_BTNUM_CNT ); +be32_to_cpu (agf->agf_cnt_root));#endif if (xfs_has_crc (mp))
PATCH 75/111 xfs: simplify xfs_btree_check_sblock_siblings
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4bc94bf640e08cf970354036683ec143a7ae974e
Stop using xfs_btree_check_sptr in xfs_btree_check_sblock_siblings, as it only duplicates the xfs_verify_agbno call in the other leg of if / else besides adding a tautological level check.
With this the cur and level arguments can be removed as they are now unused.
--- libxfs/xfs_btree.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
libxfs/xfs_btree.c +6 -13
@@ -83,8 +83,6 @@ xfs_btree_check_lblock_siblings(static inline xfs_failaddr_t xfs_btree_check_sblock_siblings (struct xfs_perag *pag, -struct xfs_btree_cur *cur, -int level,xfs_agblock_t agbno,__be32 dsibling) {
@@ -96,13 +94,8 @@ xfs_btree_check_sblock_siblings( sibling =be32_to_cpu (dsibling);if (sibling == agbno)return __this_address; -if (level >=0 ) { -if (!xfs_btree_check_sptr (cur, sibling, level +1 )) -return __this_address; - }else { -if (!xfs_verify_agbno (pag, sibling)) -return __this_address; - } +if (!xfs_verify_agbno (pag, sibling)) +return __this_address;return NULL ; }
@@ -209,10 +202,10 @@ __xfs_btree_check_sblock(if (bp) agbno =xfs_daddr_to_agbno (mp,xfs_buf_daddr (bp)); - fa =xfs_btree_check_sblock_siblings (pag, cur, level, agbno, + fa =xfs_btree_check_sblock_siblings (pag, agbno, block->bb_u.s.bb_leftsib);if (!fa) - fa =xfs_btree_check_sblock_siblings (pag, cur, level, agbno, + fa =xfs_btree_check_sblock_siblings (pag, agbno, block->bb_u.s.bb_rightsib);return fa; }
@@ -4710,10 +4703,10 @@ xfs_btree_sblock_verify(/* sibling pointer verification */ agbno =xfs_daddr_to_agbno (mp,xfs_buf_daddr (bp)); - fa =xfs_btree_check_sblock_siblings (bp->b_pag,NULL ,-1 , agbno, + fa =xfs_btree_check_sblock_siblings (bp->b_pag, agbno, block->bb_u.s.bb_leftsib);if (!fa) - fa =xfs_btree_check_sblock_siblings (bp->b_pag,NULL ,-1 , agbno, + fa =xfs_btree_check_sblock_siblings (bp->b_pag, agbno, block->bb_u.s.bb_rightsib);return fa; }
PATCH 76/111 xfs: simplify xfs_btree_check_lblock_siblings
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 8b8ada973cacff338a0e817a97dd0afa301798c0
Stop using xfs_btree_check_lptr in xfs_btree_check_lblock_siblings, as it only duplicates the xfs_verify_fsbno call in the other leg of if / else besides adding a tautological level check.
With this the cur and level arguments can be removed as they are now unused.
--- libxfs/xfs_btree.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
libxfs/xfs_btree.c +6 -16
@@ -56,8 +56,6 @@ xfs_btree_magic(static inline xfs_failaddr_t xfs_btree_check_lblock_siblings (struct xfs_mount *mp, -struct xfs_btree_cur *cur, -int level,xfs_fsblock_t fsb,__be64 dsibling) {
@@ -69,14 +67,8 @@ xfs_btree_check_lblock_siblings( sibling =be64_to_cpu (dsibling);if (sibling == fsb)return __this_address; -if (level >=0 ) { -if (!xfs_btree_check_lptr (cur, sibling, level +1 )) -return __this_address; - }else { -if (!xfs_verify_fsbno (mp, sibling)) -return __this_address; - } - +if (!xfs_verify_fsbno (mp, sibling)) +return __this_address;return NULL ; }
@@ -136,10 +128,9 @@ __xfs_btree_check_lblock(if (bp) fsb =XFS_DADDR_TO_FSB (mp,xfs_buf_daddr (bp)); - fa =xfs_btree_check_lblock_siblings (mp, cur, level, fsb, - block->bb_u.l.bb_leftsib); + fa =xfs_btree_check_lblock_siblings (mp, fsb, block->bb_u.l.bb_leftsib);if (!fa) - fa =xfs_btree_check_lblock_siblings (mp, cur, level, fsb, + fa =xfs_btree_check_lblock_siblings (mp, fsb, block->bb_u.l.bb_rightsib);return fa; }
@@ -4648,10 +4639,9 @@ xfs_btree_lblock_verify(/* sibling pointer verification */ fsb =XFS_DADDR_TO_FSB (mp,xfs_buf_daddr (bp)); - fa =xfs_btree_check_lblock_siblings (mp,NULL ,-1 , fsb, - block->bb_u.l.bb_leftsib); + fa =xfs_btree_check_lblock_siblings (mp, fsb, block->bb_u.l.bb_leftsib);if (!fa) - fa =xfs_btree_check_lblock_siblings (mp,NULL ,-1 , fsb, + fa =xfs_btree_check_lblock_siblings (mp, fsb, block->bb_u.l.bb_rightsib);return fa; }
PATCH 77/111 xfs: open code xfs_btree_check_lptr in xfs_bmap_btree_to_extents
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: fb0793f206701a68f8588a09bf32f7cf44878ea3
xfs_bmap_btree_to_extents always passes a level of 1 to xfs_btree_check_lptr, thus making the level check redundant.
--- libxfs/xfs_bmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_bmap.c +1 -1
@@ -562,7 +562,7 @@ xfs_bmap_btree_to_extents( pp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , ifp->if_broot_bytes); cbno =be64_to_cpu (*pp);#ifdef DEBUG -if (XFS_IS_CORRUPT (cur->bc_mp, !xfs_btree_check_lptr (cur, cbno,1 ))) { +if (XFS_IS_CORRUPT (cur->bc_mp, !xfs_verify_fsbno (mp, cbno))) {xfs_btree_mark_sick (cur);return -EFSCORRUPTED ; }
PATCH 78/111 xfs: consolidate btree ptr checking
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 57982d6c835a71da5c66e6090680de1adf6e736a
Merge xfs_btree_check_sptr and xfs_btree_check_lptr into a single __xfs_btree_check_ptr that can be shared between xfs_btree_check_ptr and the scrub code.
--- libxfs/xfs_btree.c | 60 +++++++++++++++++++++++++--------------------------- libxfs/xfs_btree.h | 21 +++--------------- 2 files changed, 32 insertions(+), 49 deletions(-)
libxfs/xfs_btree.c +29 -31
@@ -239,28 +239,27 @@ xfs_btree_check_block(return xfs_btree_check_sblock (cur, block, level, bp); } -/* Check that this long pointer is valid and points within the fs. */ -bool -xfs_btree_check_lptr ( -struct xfs_btree_cur *cur, -xfs_fsblock_t fsbno, -int level) +int +__xfs_btree_check_ptr ( +struct xfs_btree_cur *cur, +const union xfs_btree_ptr *ptr, +int index, +int level) {if (level <=0 ) -return false; -return xfs_verify_fsbno (cur->bc_mp, fsbno); -} +return -EFSCORRUPTED ; -/* Check that this short pointer is valid and points within the AG. */ -bool -xfs_btree_check_sptr ( -struct xfs_btree_cur *cur, -xfs_agblock_t agbno, -int level) -{ -if (level <=0 ) -return false; -return xfs_verify_agbno (cur->bc_ag.pag, agbno); +if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) { +if (!xfs_verify_fsbno (cur->bc_mp, +be64_to_cpu ((&ptr->l)[index]))) +return -EFSCORRUPTED ; + }else { +if (!xfs_verify_agbno (cur->bc_ag.pag, +be32_to_cpu ((&ptr->s)[index]))) +return -EFSCORRUPTED ; + } + +return 0 ; }/*
@@ -274,27 +273,26 @@ xfs_btree_check_ptr(int index, int level) { -if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) { -if (xfs_btree_check_lptr (cur,be64_to_cpu ((&ptr->l)[index]), - level)) -return 0 ; -xfs_err (cur->bc_mp, + int error; + + error =__xfs_btree_check_ptr (cur, ptr, index, level); +if (error) { +if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) { +xfs_err (cur->bc_mp,"Inode %llu fork %d: Corrupt %sbt pointer at level %d index %d." , cur->bc_ino.ip->i_ino, cur->bc_ino.whichfork, cur->bc_ops->name, level, index); - }else { -if (xfs_btree_check_sptr (cur,be32_to_cpu ((&ptr->s)[index]), - level)) -return 0 ; -xfs_err (cur->bc_mp, + }else { +xfs_err (cur->bc_mp,"AG %u: Corrupt %sbt pointer at level %d index %d." , cur->bc_ag.pag->pag_agno, cur->bc_ops->name, level, index); + } +xfs_btree_mark_sick (cur); } -xfs_btree_mark_sick (cur); -return -EFSCORRUPTED ; +return error; }#ifdef DEBUG
libxfs/xfs_btree.h +3 -18
@@ -343,6 +343,9 @@ xfs_failaddr_t __xfs_btree_check_lblock(struct xfs_btree_cur *cur,xfs_failaddr_t __xfs_btree_check_sblock (struct xfs_btree_cur *cur,struct xfs_btree_block *block,int level,struct xfs_buf *bp); +int __xfs_btree_check_ptr (struct xfs_btree_cur *cur, +const union xfs_btree_ptr *ptr,int index,int level); +/* * Check that block header is ok. */
@@ -353,24 +356,6 @@ xfs_btree_check_block(int level,/* level of the btree block */ struct xfs_buf *bp); /* buffer containing block, if any */ -/* -* Check that (long) pointer is ok. -*/ -bool /* error (0 or EFSCORRUPTED) */ -xfs_btree_check_lptr ( -struct xfs_btree_cur *cur,/* btree cursor */ -xfs_fsblock_t fsbno,/* btree block disk address */ -int level);/* btree block level */ - -/* -* Check that (short) pointer is ok. -*/ -bool /* error (0 or EFSCORRUPTED) */ -xfs_btree_check_sptr ( -struct xfs_btree_cur *cur,/* btree cursor */ -xfs_agblock_t agbno,/* btree block disk address */ -int level);/* btree block level */ -/* * Delete the btree cursor. */
PATCH 79/111 xfs: misc cleanups for __xfs_btree_check_sblock
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 43be09192ce1f3cf9c3d2073e822a1d0a42fe5b2
Remove the local crc variable that is only used once and remove the bp NULL checking as it can't ever be NULL for short form blocks.
--- libxfs/xfs_btree.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
libxfs/xfs_btree.c +4 -8
@@ -170,15 +170,13 @@ __xfs_btree_check_sblock( {struct xfs_mount *mp = cur->bc_mp;struct xfs_perag *pag = cur->bc_ag.pag; -bool crc =xfs_has_crc (mp);xfs_failaddr_t fa; -xfs_agblock_t agbno =NULLAGBLOCK ; +xfs_agblock_t agbno; -if (crc) { +if (xfs_has_crc (mp)) {if (!uuid_equal (&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))return __this_address; -if (block->bb_u.s.bb_blkno != -cpu_to_be64 (bp ?xfs_buf_daddr (bp) :XFS_BUF_DADDR_NULL )) +if (block->bb_u.s.bb_blkno !=cpu_to_be64 (xfs_buf_daddr (bp)))return __this_address; }
@@ -190,9 +188,7 @@ __xfs_btree_check_sblock( cur->bc_ops->get_maxrecs(cur, level))return __this_address; -if (bp) - agbno =xfs_daddr_to_agbno (mp,xfs_buf_daddr (bp)); - + agbno =xfs_daddr_to_agbno (mp,xfs_buf_daddr (bp)); fa =xfs_btree_check_sblock_siblings (pag, agbno, block->bb_u.s.bb_leftsib);if (!fa)
PATCH 80/111 xfs: remove the crc variable in __xfs_btree_check_lblock
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: bd45019d9aa942d1c2457d96a7dbf2ad3051754b
crc is only used once, just use the xfs_has_crc check directly.
--- libxfs/xfs_btree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libxfs/xfs_btree.c +1 -2
@@ -103,11 +103,10 @@ __xfs_btree_check_lblock( struct xfs_buf *bp) {struct xfs_mount *mp = cur->bc_mp; -bool crc =xfs_has_crc (mp);xfs_failaddr_t fa;xfs_fsblock_t fsb =NULLFSBLOCK ; -if (crc) { +if (xfs_has_crc (mp)) {if (!uuid_equal (&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))return __this_address; if (block->bb_u.l.bb_blkno !=
PATCH 81/111 xfs: tighten up validation of root block in inode forks
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: d477f1749f00899c71605ea01aba0ce67e030471
Check that root blocks that sit in the inode fork and thus have a NULL bp don't have siblings.
--- libxfs/xfs_btree.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
libxfs/xfs_btree.c +13 -3
@@ -104,7 +104,7 @@ __xfs_btree_check_lblock( {struct xfs_mount *mp = cur->bc_mp;xfs_failaddr_t fa; -xfs_fsblock_t fsb =NULLFSBLOCK ; +xfs_fsblock_t fsb;if (xfs_has_crc (mp)) {if (!uuid_equal (&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid))
@@ -124,9 +124,19 @@ __xfs_btree_check_lblock( cur->bc_ops->get_maxrecs(cur, level))return __this_address; -if (bp) - fsb =XFS_DADDR_TO_FSB (mp,xfs_buf_daddr (bp)); +/* +* For inode-rooted btrees, the root block sits in the inode fork. In +* that case bp is NULL, and the block must not have any siblings. +*/ +if (!bp) { +if (block->bb_u.l.bb_leftsib !=cpu_to_be64 (NULLFSBLOCK )) +return __this_address; +if (block->bb_u.l.bb_rightsib !=cpu_to_be64 (NULLFSBLOCK )) +return __this_address; +return NULL ; + } + fsb =XFS_DADDR_TO_FSB (mp,xfs_buf_daddr (bp)); fa =xfs_btree_check_lblock_siblings (mp, fsb, block->bb_u.l.bb_leftsib);if (!fa) fa = xfs_btree_check_lblock_siblings(mp, fsb,
PATCH 82/111 xfs: consolidate btree block verification
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 4ce0c711d9ab3a435bc605cd2f36a3f6b4e12c05
Add a __xfs_btree_check_block helper that can be called by the scrub code to validate a btree block of any form, and move the duplicate error handling code from xfs_btree_check_sblock and xfs_btree_check_lblock into xfs_btree_check_block and thus remove these two helpers.
--- libxfs/xfs_btree.c | 72 ++++++++++++++++++++++------------------------------ libxfs/xfs_btree.h | 9 +------ 2 files changed, 31 insertions(+), 50 deletions(-)
libxfs/xfs_btree.c +30 -42
@@ -95,7 +95,7 @@ xfs_btree_check_sblock_siblings(* Check a long btree block header. Return the address of the failing check, * or NULL if everything is ok. */ -xfs_failaddr_t +static xfs_failaddr_t __xfs_btree_check_lblock( struct xfs_btree_cur *cur, struct xfs_btree_block *block,
@@ -144,33 +144,11 @@ __xfs_btree_check_lblock(return fa; } -/* Check a long btree block header. */ -static int -xfs_btree_check_lblock ( -struct xfs_btree_cur *cur, -struct xfs_btree_block *block, -int level, -struct xfs_buf *bp) -{ -struct xfs_mount *mp = cur->bc_mp; -xfs_failaddr_t fa; - - fa =__xfs_btree_check_lblock (cur, block, level, bp); -if (XFS_IS_CORRUPT (mp, fa !=NULL ) || -XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BTREE_CHECK_LBLOCK )) { -if (bp) -trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_btree_mark_sick (cur); -return -EFSCORRUPTED ; - } -return 0 ; -} -/* * Check a short btree block header. Return the address of the failing check, * or NULL if everything is ok. */ -xfs_failaddr_t +static xfs_failaddr_t __xfs_btree_check_sblock( struct xfs_btree_cur *cur, struct xfs_btree_block *block,
@@ -206,26 +184,28 @@ __xfs_btree_check_sblock(return fa; } -/* Check a short btree block header. */ -STATIC int -xfs_btree_check_sblock ( +/* +* Internal btree block check. +* +* Return NULL if the block is ok or the address of the failed check otherwise. +*/ +xfs_failaddr_t +__xfs_btree_check_block (struct xfs_btree_cur *cur,struct xfs_btree_block *block,int level,struct xfs_buf *bp) { -struct xfs_mount *mp = cur->bc_mp; -xfs_failaddr_t fa; +if (cur->bc_ops->ptr_len ==XFS_BTREE_SHORT_PTR_LEN ) +return __xfs_btree_check_sblock (cur, block, level, bp); +return __xfs_btree_check_lblock (cur, block, level, bp); +} - fa =__xfs_btree_check_sblock (cur, block, level, bp); -if (XFS_IS_CORRUPT (mp, fa !=NULL ) || -XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BTREE_CHECK_SBLOCK )) { -if (bp) -trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_btree_mark_sick (cur); -return -EFSCORRUPTED ; - } -return 0 ; +static inline unsigned int xfs_btree_block_errtag (struct xfs_btree_cur *cur) +{ +if (cur->bc_ops->ptr_len ==XFS_BTREE_SHORT_PTR_LEN ) +return XFS_ERRTAG_BTREE_CHECK_SBLOCK ; +return XFS_ERRTAG_BTREE_CHECK_LBLOCK ; }/*
@@ -238,10 +218,18 @@ xfs_btree_check_block(int level,/* level of the btree block */ struct xfs_buf *bp) /* buffer containing block, if any */ { -if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) -return xfs_btree_check_lblock (cur, block, level, bp); -else -return xfs_btree_check_sblock (cur, block, level, bp); + struct xfs_mount *mp = cur->bc_mp; +xfs_failaddr_t fa; + + fa =__xfs_btree_check_block (cur, block, level, bp); +if (XFS_IS_CORRUPT (mp, fa !=NULL ) || +XFS_TEST_ERROR (false, mp,xfs_btree_block_errtag (cur))) { +if (bp) +trace_xfs_btree_corrupt (bp, _RET_IP_); +xfs_btree_mark_sick (cur); +return -EFSCORRUPTED ; + } +return 0 ; }int
libxfs/xfs_btree.h +1 -8
@@ -334,15 +334,8 @@ xfs_btree_cur_sizeof(unsigned int nlevels)*/ #define XFS_BUF_TO_BLOCK (bp) ((struct xfs_btree_block *)((bp)->b_addr)) -/* -* Internal long and short btree block checks. They return NULL if the -* block is ok or the address of the failed check otherwise. -*/ -xfs_failaddr_t __xfs_btree_check_lblock (struct xfs_btree_cur *cur, +xfs_failaddr_t __xfs_btree_check_block (struct xfs_btree_cur *cur,struct xfs_btree_block *block,int level,struct xfs_buf *bp); -xfs_failaddr_t __xfs_btree_check_sblock (struct xfs_btree_cur *cur, -struct xfs_btree_block *block,int level,struct xfs_buf *bp); -int __xfs_btree_check_ptr (struct xfs_btree_cur *cur,const union xfs_btree_ptr *ptr,int index,int level);