Commit Graph

60 Commits

Author SHA1 Message Date
Bill O'Donnell 71b1929648 xfs: repair refcount btrees
JIRA: https://issues.redhat.com/browse/RHEL-65728

commit 9099cd38002f8029c9a1da08e6832d1cd18e8451
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Fri Dec 15 10:03:33 2023 -0800

    xfs: repair refcount btrees

    Reconstruct the refcount data from the rmap btree.

    Link: https://docs.kernel.org/filesystems/xfs-online-fsck-design.html#case-study-rebuilding-the-space-reference-counts
    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-11-20 11:26:04 -06:00
Bill O'Donnell 059e57c35e xfs: remove __xfs_free_extent_later
JIRA: https://issues.redhat.com/browse/RHEL-65728

commit 4c88fef3af4a51c2cdba6a28237e98da4873e8dc
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Wed Dec 6 18:40:57 2023 -0800

    xfs: remove __xfs_free_extent_later

    xfs_free_extent_later is a trivial helper, so remove it to reduce the
    amount of thinking required to understand the deferred freeing
    interface.  This will make it easier to introduce automatic reaping of
    speculative allocations in the next patch.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-11-20 11:25:54 -06:00
Bill O'Donnell 53919fd386 xfs: use deferred frees for btree block freeing
JIRA: https://issues.redhat.com/browse/RHEL-25419

Conflicts: context

commit b742d7b4f0e03df25c2a772adcded35044b625ca
Author: Dave Chinner <dchinner@redhat.com>
Date:   Wed Jun 28 11:04:32 2023 -0700

    xfs: use deferred frees for btree block freeing

    Btrees that aren't freespace management trees use the normal extent
    allocation and freeing routines for their blocks. Hence when a btree
    block is freed, a direct call to xfs_free_extent() is made and the
    extent is immediately freed. This puts the entire free space
    management btrees under this path, so we are stacking btrees on
    btrees in the call stack. The inobt, finobt and refcount btrees
    all do this.

    However, the bmap btree does not do this - it calls
    xfs_free_extent_later() to defer the extent free operation via an
    XEFI and hence it gets processed in deferred operation processing
    during the commit of the primary transaction (i.e. via intent
    chaining).

    We need to change xfs_free_extent() to behave in a non-blocking
    manner so that we can avoid deadlocks with busy extents near ENOSPC
    in transactions that free multiple extents. Inserting or removing a
    record from a btree can cause a multi-level tree merge operation and
    that will free multiple blocks from the btree in a single
    transaction. i.e. we can call xfs_free_extent() multiple times, and
    hence the btree manipulation transaction is vulnerable to this busy
    extent deadlock vector.

    To fix this, convert all the remaining callers of xfs_free_extent()
    to use xfs_free_extent_later() to queue XEFIs and hence defer
    processing of the extent frees to a context that can be safely
    restarted if a deadlock condition is detected.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>
    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-06-06 10:32:52 -05:00
Bill O'Donnell 359e294324 xfs: implement masked btree key comparisons for _has_records scans
JIRA: https://issues.redhat.com/browse/RHEL-25419

commit 4a200a0978288f919aba3f015f374f6ed279e658
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Apr 11 19:00:11 2023 -0700

    xfs: implement masked btree key comparisons for _has_records scans

    For keyspace fullness scans, we want to be able to mask off the parts of
    the key that we don't care about.  For most btree types we /do/ want the
    full keyspace, but for checking that a given space usage also has a full
    complement of rmapbt records (even if different/multiple owners) we need
    this masking so that we only track sparseness of rm_startblock, not the
    whole keyspace (which is extremely sparse).

    Augment the ->diff_two_keys and ->keys_contiguous helpers to take a
    third union xfs_btree_key argument, and wire up xfs_rmap_has_records to
    pass this through.  This third "mask" argument should contain a nonzero
    value in each structure field that should be used in the key comparisons
    done during the scan.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-06-05 16:56:21 -05:00
Bill O'Donnell de02d9af50 xfs: replace xfs_btree_has_record with a general keyspace scanner
JIRA: https://issues.redhat.com/browse/RHEL-25419

commit 6abc7aef85b1f42cb39a3149f4ab64ca255e41e6
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Apr 11 19:00:10 2023 -0700

    xfs: replace xfs_btree_has_record with a general keyspace scanner

    The current implementation of xfs_btree_has_record returns true if it
    finds /any/ record within the given range.  Unfortunately, that's not
    sufficient for scrub.  We want to be able to tell if a range of keyspace
    for a btree is devoid of records, is totally mapped to records, or is
    somewhere in between.  By forcing this to be a boolean, we conflated
    sparseness and fullness, which caused scrub to return incorrect results.
    Fix the API so that we can tell the caller which of those three is the
    current state.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-06-05 16:56:20 -05:00
Bill O'Donnell 07297e64e0 xfs: create traced helper to get extra perag references
JIRA: https://issues.redhat.com/browse/RHEL-25419

commit 9b2e5a234c89f097ec36f922763dfa1465dc06f8
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Apr 11 18:59:55 2023 -0700

    xfs: create traced helper to get extra perag references

    There are a few places in the XFS codebase where a caller has either an
    active or a passive reference to a perag structure and wants to give
    a passive reference to some other piece of code.  Btree cursor creation
    and inode walks are good examples of this.  Replace the open-coded logic
    with a helper to do this.

    The new function adds a few safeguards -- it checks that there's at
    least one reference to the perag structure passed in, and it records the
    refcount bump in the ftrace information.  This makes it much easier to
    debug perag refcounting problems.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-06-05 16:56:14 -05:00
Bill O'Donnell 720387b2f7 xfs: pass per-ag references to xfs_free_extent
JIRA: https://issues.redhat.com/browse/RHEL-25419

commit b2ccab3199aa7cea9154d80ea2585312c5f6eba0
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Apr 11 18:59:53 2023 -0700

    xfs: pass per-ag references to xfs_free_extent

    Pass a reference to the per-AG structure to xfs_free_extent.  Most
    callers already have one, so we can eliminate unnecessary lookups.  The
    one exception to this is the EFI code, which the next patch will fix.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-06-05 16:56:13 -05:00
Bill O'Donnell 8ed52fa327 xfs: introduce xfs_alloc_vextent_near_bno()
JIRA: https://issues.redhat.com/browse/RHEL-2002

commit db4710fd12248e5d4c3842520cd13f034136576b
Author: Dave Chinner <dchinner@redhat.com>
Date:   Mon Feb 13 09:14:54 2023 +1100

    xfs: introduce xfs_alloc_vextent_near_bno()

    The remaining callers of xfs_alloc_vextent() are all doing NEAR_BNO
    allocations. We can replace that function with a new
    xfs_alloc_vextent_near_bno() function that does this explicitly.

    We also multiplex NEAR_BNO allocations through
    xfs_alloc_vextent_this_ag via args->type. Replace all of these with
    direct calls to xfs_alloc_vextent_near_bno(), too.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-11-10 07:22:22 -06:00
Bill O'Donnell f393aca22e xfs: use xfs_alloc_vextent_this_ag() where appropriate
JIRA: https://issues.redhat.com/browse/RHEL-2002

commit 74c36a8689d3d8ca9d9e96759c9bbf337e049097
Author: Dave Chinner <dchinner@redhat.com>
Date:   Mon Feb 13 09:14:53 2023 +1100

    xfs: use xfs_alloc_vextent_this_ag() where appropriate

    Change obvious callers of single AG allocation to use
    xfs_alloc_vextent_this_ag(). Drive the per-ag grabbing out to the
    callers, too, so that callers with active references don't need
    to do new lookups just for an allocation in a context that already
    has a perag reference.

    The only remaining caller that does single AG allocation through
    xfs_alloc_vextent() is xfs_bmap_btalloc() with
    XFS_ALLOCTYPE_NEAR_BNO. That is going to need more untangling before
    it can be converted cleanly.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-11-10 07:22:21 -06:00
Bill O'Donnell 6ee6b421b0 xfs: perags need atomic operational state
JIRA: https://issues.redhat.com/browse/RHEL-2002

commit 7ac2ff8bb3713c7cb43564c04384af2ee7cc1f8d
Author: Dave Chinner <dchinner@redhat.com>
Date:   Mon Feb 13 09:14:52 2023 +1100

    xfs: perags need atomic operational state

    We currently don't have any flags or operational state in the
    xfs_perag except for the pagf_init and pagi_init flags. And the
    agflreset flag. Oh, there's also the pagf_metadata and pagi_inodeok
    flags, too.

    For controlling per-ag operations, we are going to need some atomic
    state flags. Hence add an opstate field similar to what we already
    have in the mount and log, and convert all these state flags across
    to atomic bit operations.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-11-10 07:22:21 -06:00
Bill O'Donnell 7d0d335ad8 xfs: track cow/shared record domains explicitly in xfs_refcount_irec
JIRA: https://issues.redhat.com/browse/RHEL-2002

commit 9a50ee4f8db6e4dd0d8d757b7adaf0591776860a
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Mon Oct 10 09:06:24 2022 -0700

    xfs: track cow/shared record domains explicitly in xfs_refcount_irec

    Just prior to committing the reflink code into upstream, the xfs
    maintainer at the time requested that I find a way to shard the refcount
    records into two domains -- one for records tracking shared extents, and
    a second for tracking CoW staging extents.  The idea here was to
    minimize mount time CoW reclamation by pushing all the CoW records to
    the right edge of the keyspace, and it was accomplished by setting the
    upper bit in rc_startblock.  We don't allow AGs to have more than 2^31
    blocks, so the bit was free.

    Unfortunately, this was a very late addition to the codebase, so most of
    the refcount record processing code still treats rc_startblock as a u32
    and pays no attention to whether or not the upper bit (the cow flag) is
    set.  This is a weakness is theoretically exploitable, since we're not
    fully validating the incoming metadata records.

    Fuzzing demonstrates practical exploits of this weakness.  If the cow
    flag of a node block key record is corrupted, a lookup operation can go
    to the wrong record block and start returning records from the wrong
    cow/shared domain.  This causes the math to go all wrong (since cow
    domain is still implicit in the upper bit of rc_startblock) and we can
    crash the kernel by tricking xfs into jumping into a nonexistent AG and
    tripping over xfs_perag_get(mp, <nonexistent AG>) returning NULL.

    To fix this, start tracking the domain as an explicit part of struct
    xfs_refcount_irec, adjust all refcount functions to check the domain
    of a returned record, and alter the function definitions to accept them
    where necessary.

    Found by fuzzing keys[2].cowflag = add in xfs/464.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-11-06 19:42:19 -06:00
Bill O'Donnell f8121a9b84 xfs: make is_log_ag() a first class helper
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit 36029dee382a20cf515494376ce9f0d5949944eb
Author: Dave Chinner <dchinner@redhat.com>
Date:   Thu Jul 7 19:13:21 2022 +1000

    xfs: make is_log_ag() a first class helper

    We check if an ag contains the log in many places, so make this
    a first class XFS helper by lifting it to fs/xfs/libxfs/xfs_ag.h and
    renaming it xfs_ag_contains_log(). The convert all the places that
    check if the AG contains the log to use this helper.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:41 -05:00
Bill O'Donnell d1a077edc7 xfs: pass perag to xfs_alloc_read_agf()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit 08d3e84feeb8cb8e20d54f659446b98fe17913aa
Author: Dave Chinner <dchinner@redhat.com>
Date:   Thu Jul 7 19:07:40 2022 +1000

    xfs: pass perag to xfs_alloc_read_agf()

    xfs_alloc_read_agf() initialises the perag if it hasn't been done
    yet, so it makes sense to pass it the perag rather than pull a
    reference from the buffer. This allows callers to be per-ag centric
    rather than passing mount/agno pairs everywhere.

    Whilst modifying the xfs_reflink_find_shared() function definition,
    declare it static and remove the extern declaration as it is an
    internal function only these days.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:39 -05:00
Carlos Maiolino d912d565bb xfs: remove kmem_zone typedef
Bugzilla: https://bugzilla.redhat.com/2125724

Remove these typedefs by referencing kmem_cache directly.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit e7720afad068a6729d9cd3aaa08212f2f5a7ceff)
2022-10-21 12:50:46 +02:00
Carlos Maiolino e3c2c647f7 xfs: use separate btree cursor cache for each btree type
Bugzilla: https://bugzilla.redhat.com/2125724

Now that we have the infrastructure to track the max possible height of
each btree type, we can create a separate slab cache for cursors of each
type of btree.  For smaller indices like the free space btrees, this
means that we can pack more cursors into a slab page, improving slab
utilization.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit 9fa47bdcd33b117599e9ee3f2e315cb47939ac2d)
2022-10-21 12:50:46 +02:00
Carlos Maiolino f164f431d6 xfs: compute absolute maximum nlevels for each btree type
Bugzilla: https://bugzilla.redhat.com/2125724

Add code for all five btree types so that we can compute the absolute
maximum possible btree height for each btree type.  This is a setup for
the next patch, which makes every btree type have its own cursor cache.

The functions are exported so that we can have xfs_db report the
absolute maximum btree heights for each btree type, rather than making
everyone run their own ad-hoc computations.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit 0ed5f7356daee74244b02e100b3cc043e886e686)
2022-10-21 12:50:46 +02:00
Carlos Maiolino 02e10206a0 xfs: dynamically allocate cursors based on maxlevels
Bugzilla: https://bugzilla.redhat.com/2125724

To support future btree code, we need to be able to size btree cursors
dynamically for very large btrees.  Switch the maxlevels computation to
use the precomputed values in the superblock, and create cursors that
can handle a certain height.  For now, we retain the btree cursor cache
that can handle up to 9-level btrees, though a subsequent patch
introduces separate caches for each btree type, where each cache's
objects will be exactly tall enough to handle the specific btree type.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit c940a0c54a2e9333478f1d87ed40006a04fcec7e)
2022-10-21 12:50:46 +02:00
Carlos Maiolino 73ee1d48f2 xfs: refactor btree cursor allocation function
Bugzilla: https://bugzilla.redhat.com/2125724

Refactor btree allocation to a common helper.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit 56370ea6e5fe3e3d6e1ca2da58f95fb0d5e1779f)
2022-10-21 12:50:46 +02:00
Carlos Maiolino 3db6a105c6 xfs: remove xfs_btree_cur.bc_blocklog
Bugzilla: https://bugzilla.redhat.com/2125724

This field isn't used by anyone, so get rid of it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
(cherry picked from commit cc411740472d958b718b9c6a7791ba00d88f7cef)
2022-10-21 12:50:46 +02:00
Brian Foster 74f147b83b xfs: introduce xfs_buf_daddr()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit 04fcad80cd068731a779fb442f78234732683755
Author: Dave Chinner <dchinner@redhat.com>
Date:   Wed Aug 18 18:46:57 2021 -0700

    xfs: introduce xfs_buf_daddr()

    Introduce a helper function xfs_buf_daddr() to extract the disk
    address of the buffer from the struct xfs_buf. This will replace
    direct accesses to bp->b_bn and bp->b_maps[0].bm_bn, as well as
    the XFS_BUF_ADDR() macro.

    This patch introduces the helper function and replaces all uses of
    XFS_BUF_ADDR() as this is just a simple sed replacement.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:36 -04:00
Brian Foster d54a790d1d xfs: replace xfs_sb_version checks with feature flag checks
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit 38c26bfd90e1999650d5ef40f90d721f05916643
Author: Dave Chinner <dchinner@redhat.com>
Date:   Wed Aug 18 18:46:37 2021 -0700

    xfs: replace xfs_sb_version checks with feature flag checks

    Convert the xfs_sb_version_hasfoo() to checks against
    mp->m_features. Checks of the superblock itself during disk
    operations (e.g. in the read/write verifiers and the to/from disk
    formatters) are not converted - they operate purely on the
    superblock state. Everything else should use the mount features.

    Large parts of this conversion were done with sed with commands like
    this:

    for f in `git grep -l xfs_sb_version_has fs/xfs/*.c`; do
            sed -i -e 's/xfs_sb_version_has\(.*\)(&\(.*\)->m_sb)/xfs_has_\1(\2)/' $f
    done

    With manual cleanups for things like "xfs_has_extflgbit" and other
    little inconsistencies in naming.

    The result is ia lot less typing to check features and an XFS binary
    size reduced by a bit over 3kB:

    $ size -t fs/xfs/built-in.a
            text       data     bss     dec     hex filenam
    before  1130866  311352     484 1442702  16038e (TOTALS)
    after   1127727  311352     484 1439563  15f74b (TOTALS)

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Darrick J. Wong <djwong@kernel.org>
    Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:34 -04:00
Brian Foster 4d9abe49b5 xfs: make the start pointer passed to btree alloc_block functions const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit deb06b9ab6dfa167c280a68d5acb2f12e007073f
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Thu Aug 12 09:53:27 2021 -0700

    xfs: make the start pointer passed to btree alloc_block functions const

    The @start pointer passed to each per-AG btree type's ->alloc_block
    function isn't supposed to be modified, since it's a hint about the
    location of the btree block being split that is to be fed to the
    allocator, so mark the parameter const.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:30 -04:00
Brian Foster 1439943f4a xfs: make the pointer passed to btree set_root functions const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit b5a6e5fe0e6840bc90e51cf522d6c5a880cde567
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Thu Aug 12 09:49:03 2021 -0700

    xfs: make the pointer passed to btree set_root functions const

    The pointer passed to each per-AG btree type's ->set_root function isn't
    supposed to be modified (that function sets an external pointer to the
    root block) so mark them const.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:30 -04:00
Brian Foster 0fa328b41a xfs: make the keys and records passed to btree inorder functions const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit 8e38dc88a67b3c7475cbe8a132d03542717c1e27
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Aug 10 17:02:17 2021 -0700

    xfs: make the keys and records passed to btree inorder functions const

    The inorder functions are simple predicates, which means that they don't
    modify the parameters.  Mark them all const.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:30 -04:00
Brian Foster 046569f054 xfs: mark the record passed into btree init_key functions as const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit 23825cd148764ce133ee92375da395140d6ccb15
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Aug 10 17:02:16 2021 -0700

    xfs: mark the record passed into btree init_key functions as const

    These functions initialize a key from a record, but they aren't supposed
    to modify the record.  Mark it const.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:29 -04:00
Brian Foster 542740cc19 xfs: make the key parameters to all btree key comparison functions const
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2083143
Upstream Status: linux.git

commit d29d5577774d7d032da1343dba80be7423e307f9
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Tue Aug 10 17:02:15 2021 -0700

    xfs: make the key parameters to all btree key comparison functions const

    The btree key comparison functions are not allowed to change the keys
    that are passed in, so mark them const.  We'll need this for the next
    patch, which adds const to the btree range query functions.

    Signed-off-by: Darrick J. Wong <djwong@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Brian Foster <bfoster@redhat.com>
2022-08-25 08:11:29 -04:00
Dave Chinner 50f02fe333 xfs: remove agno from btree cursor
Now that everything passes a perag, the agno is not needed anymore.
Convert all the users to use pag->pag_agno instead and remove the
agno from the cursor. This was largely done as an automated search
and replace.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
2021-06-02 10:48:24 +10:00
Dave Chinner a81a06211f xfs: convert refcount btree cursor to use perags
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
2021-06-02 10:48:24 +10:00
Dave Chinner be9fb17d88 xfs: add a perag to the btree cursor
Which will eventually completely replace the agno in it.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2021-06-02 10:48:24 +10:00
Dave Chinner 30933120ad xfs: push perags through the ag reservation callouts
We currently pass an agno from the AG reservation functions to the
individual feature accounting functions, which in future may have to
do perag lookups to access per-AG state. Instead, pre-emptively
plumb the perag through from the highest AG reservation layer to the
feature callouts so they won't have to look it up again.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2021-06-02 10:48:24 +10:00
Dave Chinner 9bbafc7191 xfs: move xfs_perag_get/put to xfs_ag.[ch]
They are AG functions, not superblock functions, so move them to the
appropriate location.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
2021-06-02 10:48:24 +10:00
Carlos Maiolino 32a2b11f46 xfs: Remove kmem_zone_zalloc() usage
Use kmem_cache_zalloc() directly.

With the exception of xlog_ticket_alloc() which will be dealt on the
next patch for readability.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2020-07-28 20:24:14 -07:00
Gao Xiang 92a005448f xfs: get rid of unnecessary xfs_perag_{get,put} pairs
In the course of some operations, we look up the perag from
the mount multiple times to get or change perag information.
These are often very short pieces of code, so while the
lookup cost is generally low, the cost of the lookup is far
higher than the cost of the operation we are doing on the
perag.

Since we changed buffers to hold references to the perag
they are cached in, many modification contexts already hold
active references to the perag that are held across these
operations. This is especially true for any operation that
is serialised by an allocation group header buffer.

In these cases, we can just use the buffer's reference to
the perag to avoid needing to do lookups to access the
perag. This means that many operations don't need to do
perag lookups at all to access the perag because they've
already looked up objects that own persistent references
and hence can use that reference instead.

Cc: Dave Chinner <dchinner@redhat.com>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-07-14 08:47:33 -07:00
Darrick J. Wong 56e98164ff xfs: add support for refcount btree staging cursors
Add support for btree staging cursors for the refcount btrees.  This
is needed both for online repair and also to convert xfs_repair to use
btree bulk loading.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2020-03-18 08:12:23 -07:00
Dave Chinner c4aa10d041 xfs: make the btree ag cursor private union anonymous
This is much less widely used than the bc_private union was, so this
is done as a single patch. The named union xfs_btree_cur_private
goes away and is embedded into the struct xfs_btree_cur_ag as an
anonymous union, and the code is modified via this script:

$ sed -i 's/priv\.\([abt|refc]\)/\1/g' fs/xfs/*[ch] fs/xfs/*/*[ch]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2020-03-13 10:37:15 -07:00
Dave Chinner 576af73228 xfs: convert btree cursor ag-private member name
bc_private.a -> bc_ag conversion via script:

`sed -i 's/bc_private\.a/bc_ag/g' fs/xfs/*[ch] fs/xfs/*/*[ch]`

And then revert the change to the bc_ag #define in
fs/xfs/libxfs/xfs_btree.h manually.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2020-03-13 10:37:14 -07:00
Christoph Hellwig 9798f615ad xfs: remove XFS_BUF_TO_AGF
Just dereference bp->b_addr directly and make the code a little
simpler and more clear.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-03-11 09:11:39 -07:00
Eric Sandeen 250d4b4c40 xfs: remove unused header files
There are many, many xfs header files which are included but
unneeded (or included twice) in the xfs code, so remove them.

nb: xfs_linux.h includes about 9 headers for everyone, so those
explicit includes get removed by this.  I'm not sure what the
preference is, but if we wanted explicit includes everywhere,
a followup patch could remove those xfs_*.h includes from
xfs_linux.h and move them into the files that need them.
Or it could be left as-is.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-06-28 19:30:43 -07:00
Christoph Hellwig dbd329f1e4 xfs: add struct xfs_mount pointer to struct xfs_buf
We need to derive the mount pointer from a buffer in a lot of place.
Add a direct pointer to short cut the pointer chasing.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-06-28 19:27:29 -07:00
Darrick J. Wong 5cd213b0fe xfs: don't reserve per-AG space for an internal log
It turns out that the log can consume nearly all the space in an AG, and
when this happens this it's possible that there will be less free space
in the AG than the reservation would try to hide.  On a debug kernel
this can trigger an ASSERT in xfs/250:

XFS: Assertion failed: xfs_perag_resv(pag, XFS_AG_RESV_METADATA)->ar_reserved + xfs_perag_resv(pag, XFS_AG_RESV_RMAPBT)->ar_reserved <= pag->pagf_freeblks + pag->pagf_flcount, file: fs/xfs/libxfs/xfs_ag_resv.c, line: 319

The log is permanently allocated, so we know we're never going to have
to expand the btrees to hold any records associated with the log space.
We therefore can treat the space as if it doesn't exist.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
2019-05-20 11:25:39 -07:00
Brian Foster 39708c20ab xfs: miscellaneous verifier magic value fixups
Most buffer verifiers have hardcoded magic value checks
conditionalized on the version of the filesystem. The magic value
field of the verifier structure facilitates abstraction of some of
this code. Populate the ->magic field of various verifiers to take
advantage of this abstraction. No functional changes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-02-11 16:07:01 -08:00
Darrick J. Wong 7280fedaf3 xfs: remove xfs_rmap_ag_owner and friends
Owner information for static fs metadata can be defined readonly at
build time because it never changes across filesystems.  This enables us
to reduce stack usage (particularly in scrub) because we can use the
statically defined oinfo structures.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2018-12-12 08:47:16 -08:00
Darrick J. Wong ebcbef3a61 xfs: pass transaction lock while setting up agresv on cyclic metadata
Pass a tranaction pointer through to all helpers that calculate the
per-AG block reservation.  Online repair will use this to reinitialize
per-ag reservations while it still holds all the AG headers locked to
the repair transaction.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2018-07-29 22:37:08 -07:00
Brian Foster 64396ff2c2 xfs: remove xfs_alloc_arg firstblock field
The xfs_alloc_arg.firstblock field is used to control the starting
agno for an allocation. The structure already carries a pointer to
the transaction, which carries the current firstblock value.

Remove the field and access ->t_firstblock directly in the
allocation code.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-07-11 22:26:30 -07:00
Brian Foster ed7ef8e55c xfs: remove unused btree cursor bc_private.a.dfops field
The xfs_btree_cur.bc_private.a.dfops field is only ever initialized
by the refcountbt cursor init function. The only caller of that
function with a non-NULL dfops is from deferred completion context,
which already has attached to ->t_dfops.

In addition to that, the only actual reference of a.dfops is the
cursor duplication function, which means the field is effectively
unused.

Remove the dfops field from the bc_private.a union. Any future users
can acquire the dfops from the transaction. This patch does not
change behavior.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-07-11 22:26:17 -07:00
Dave Chinner 0b61f8a407 xfs: convert to SPDX license tags
Remove the verbose license text from XFS files and replace them
with SPDX tags. This does not change the license of any of the code,
merely refers to the common, up-to-date license files in LICENSES/

This change was mostly scripted. fs/xfs/Makefile and
fs/xfs/libxfs/xfs_fs.h were modified by hand, the rest were detected
and modified by the following command:

for f in `git grep -l "GNU General" fs/xfs/` ; do
	echo $f
	cat $f | awk -f hdr.awk > $f.new
	mv -f $f.new $f
done

And the hdr.awk script that did the modification (including
detecting the difference between GPL-2.0 and GPL-2.0+ licenses)
is as follows:

$ cat hdr.awk
BEGIN {
	hdr = 1.0
	tag = "GPL-2.0"
	str = ""
}

/^ \* This program is free software/ {
	hdr = 2.0;
	next
}

/any later version./ {
	tag = "GPL-2.0+"
	next
}

/^ \*\// {
	if (hdr > 0.0) {
		print "// SPDX-License-Identifier: " tag
		print str
		print $0
		str=""
		hdr = 0.0
		next
	}
	print $0
	next
}

/^ \* / {
	if (hdr > 1.0)
		next
	if (hdr > 0.0) {
		if (str != "")
			str = str "\n"
		str = str $0
		next
	}
	print $0
	next
}

/^ \*/ {
	if (hdr > 0.0)
		next
	print $0
	next
}

// {
	if (hdr > 0.0) {
		if (str != "")
			str = str "\n"
		str = str $0
		next
	}
	print $0
}

END { }
$

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-06-06 14:17:53 -07:00
Darrick J. Wong 1f5c071d19 xfs: don't ASSERT on short form btree root pointer of zero
Don't ASSERT if the short form btree root pointer is zero.  Now that we
use xfs_verify_agbno to check all short form btree pointers, we'll let
that log the error and pass it to the upper layers.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2018-06-04 14:45:30 -07:00
Eric Sandeen a1f69417c6 xfs: non-scrub - remove unused function parameters
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-04-09 10:23:42 -07:00
Carlos Maiolino e157ebdcb3 Cleanup old XFS_BTREE_* traces
Remove unused legacy btree traces from IRIX era.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-03-11 20:27:55 -07:00
Darrick J. Wong b55725974c xfs: create a new buf_ops pointer to verify structure metadata
Expose all metadata structure buffer verifier functions via buf_ops.
These will be used by the online scrub mechanism to look for problems
with buffers that are already sitting around in memory.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2018-01-08 10:54:47 -08:00