Commit Graph

45 Commits

Author SHA1 Message Date
Bill O'Donnell 96930a46e4 xfs: extract xfs_da_buf_copy() helper function
JIRA: https://issues.redhat.com/browse/RHEL-65728

commit fd45ddb9dd606b3eaddf26e13f64340636955986
Author: Zhang Tianci <zhangtianci.1997@bytedance.com>
Date:   Tue Dec 5 13:59:00 2023 +0800

    xfs: extract xfs_da_buf_copy() helper function

    This patch does not modify logic.

    xfs_da_buf_copy() will copy one block from src xfs_buf to
    dst xfs_buf, and update the block metadata in dst directly.

    Signed-off-by: Zhang Tianci <zhangtianci.1997@bytedance.com>
    Suggested-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2024-11-20 11:25:57 -06:00
Bill O'Donnell 510137b4dd xfs: fix TOCTOU race involving the new logged xattrs control knob
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit f4288f01820e2d57722d21874c1fda661003c9b9
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Sun Jun 5 18:51:22 2022 -0700

    xfs: fix TOCTOU race involving the new logged xattrs control knob

    I found a race involving the larp control knob, aka the debugging knob
    that lets developers enable logging of extended attribute updates:

    Thread 1                        Thread 2

    echo 0 > /sys/fs/xfs/debug/larp
                                    setxattr(REPLACE)
                                    xfs_has_larp (returns false)
                                    xfs_attr_set

    echo 1 > /sys/fs/xfs/debug/larp

                                    xfs_attr_defer_replace
                                    xfs_attr_init_replace_state
                                    xfs_has_larp (returns true)
                                    xfs_attr_init_remove_state

                                    <oops, wrong DAS state!>

    This isn't a particularly severe problem right now because xattr logging
    is only enabled when CONFIG_XFS_DEBUG=y, and developers *should* know
    what they're doing.

    However, the eventual intent is that callers should be able to ask for
    the assistance of the log in persisting xattr updates.  This capability
    might not be required for /all/ callers, which means that dynamic
    control must work correctly.  Once an xattr update has decided whether
    or not to use logged xattrs, it needs to stay in that mode until the end
    of the operation regardless of what subsequent parallel operations might
    do.

    Therefore, it is an error to continue sampling xfs_globals.larp once
    xfs_attr_change has made a decision about larp, and it was not correct
    for me to have told Allison that ->create_intent functions can sample
    the global log incompat feature bitfield to decide to elide a log item.

    Instead, create a new op flag for the xfs_da_args structure, and convert
    all other callers of xfs_has_larp and xfs_sb_version_haslogxattrs within
    the attr update state machine to look for the operations flag.

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

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:32 -05:00
Bill O'Donnell 01cdb845d3 xfs: clean up xfs_attr_node_hasname
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit 4d0cdd2bb8f0bf1a30d361f14bafc428794551e0
Author: Darrick J. Wong <djwong@kernel.org>
Date:   Sun May 22 15:59:34 2022 +1000

    xfs: clean up xfs_attr_node_hasname

    The calling conventions of this function are a mess -- callers /can/
    provide a pointer to a pointer to a state structure, but it's not
    required, and as evidenced by the last two patches, the callers that do
    weren't be careful enough about how to deal with an existing da state.

    Push the allocation and freeing responsibilty to the callers, which
    means that callers from the xattr node state machine steps now have the
    visibility to allocate or free the da state structure as they please.
    As a bonus, the node remove/add paths for larp-mode replaces can reset
    the da state structure instead of freeing and immediately reallocating
    it.

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

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:26 -05:00
Bill O'Donnell 38b5dff00d xfs: ATTR_REPLACE algorithm with LARP enabled needs rework
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit fdaf1bb3cafcfee9ef05c4eaf6ee1193fd90cbd2
Author: Dave Chinner <dchinner@redhat.com>
Date:   Thu May 12 15:12:56 2022 +1000

    xfs: ATTR_REPLACE algorithm with LARP enabled needs rework

    We can't use the same algorithm for replacing an existing attribute
    when logging attributes. The existing algorithm is essentially:

    1. create new attr w/ INCOMPLETE
    2. atomically flip INCOMPLETE flags between old + new attribute
    3. remove old attr which is marked w/ INCOMPLETE

    This algorithm guarantees that we see either the old or new
    attribute, and if we fail after the atomic flag flip, we don't have
    to recover the removal of the old attr because we never see
    INCOMPLETE attributes in lookups.

    For logged attributes, however, this does not work. The logged
    attribute intents do not track the work that has been done as the
    transaction rolls, and hence the only recovery mechanism we have is
    "run the replace operation from scratch".

    This is further exacerbated by the attempt to avoid needing the
    INCOMPLETE flag to create an atomic swap. This means we can create
    a second active attribute of the same name before we remove the
    original. If we fail at any point after the create but before the
    removal has completed, we end up with duplicate attributes in
    the attr btree and recovery only tries to replace one of them.

    There are several other failure modes where we can leave partially
    allocated remote attributes that expose stale data, partially free
    remote attributes that enable UAF based stale data exposure, etc.

    TO fix this, we need a different algorithm for replace operations
    when LARP is enabled. Luckily, it's not that complex if we take the
    right first step. That is, the first thing we log is the attri
    intent with the new name/value pair and mark the old attr as
    INCOMPLETE in the same transaction.

    From there, we then remove the old attr and keep relogging the
    new name/value in the intent, such that we always know that we have
    to create the new attr in recovery. Once the old attr is removed,
    we then run a normal ATTR_CREATE operation relogging the intent as
    we go. If the new attr is local, then it gets created in a single
    atomic transaction that also logs the final intent done. If the new
    attr is remote, the we set INCOMPLETE on the new attr while we
    allocate and set the remote value, and then we clear the INCOMPLETE
    flag at in the last transaction taht logs the final intent done.

    If we fail at any point in this algorithm, log recovery will always
    see the same state on disk: the new name/value in the intent, and
    either an INCOMPLETE attr or no attr in the attr btree. If we find
    an INCOMPLETE attr, we run the full replace starting with removing
    the INCOMPLETE attr. If we don't find it, then we simply create the
    new attr.

    Notably, recovery of a failed create that has an INCOMPLETE flag set
    is now the same - we start with the lookup of the INCOMPLETE attr,
    and if that exists then we do the full replace recovery process,
    otherwise we just create the new attr.

    Hence changing the way we do the replace operation when LARP is
    enabled allows us to use the same log recovery algorithm for both
    the ATTR_CREATE and ATTR_REPLACE operations. This is also the same
    algorithm we use for runtime ATTR_REPLACE operations (except for the
    step setting up the initial conditions).

    The result is that:

    - ATTR_CREATE uses the same algorithm regardless of whether LARP is
      enabled or not
    - ATTR_REPLACE with larp=0 is identical to the old algorithm
    - ATTR_REPLACE with larp=1 runs an unmodified attr removal algorithm
      from the larp=0 code and then runs the unmodified ATTR_CREATE
      code.
    - log recovery when larp=1 runs the same ATTR_REPLACE algorithm as
      it uses at runtime.

    Because the state machine is now quite clean, changing the algorithm
    is really just a case of changing the initial state and how the
    states link together for the ATTR_REPLACE case. Hence it's not a
    huge amount of code for what is a fairly substantial rework
    of the attr logging and recovery algorithm....

    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: Dave Chinner <david@fromorbit.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:23 -05:00
Bill O'Donnell 159a808d8f xfs: use XFS_DA_OP flags in deferred attr ops
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit e7f358dee4e5cf1ce8b11ff2e65d5ccb1ced24db
Author: Dave Chinner <dchinner@redhat.com>
Date:   Thu May 12 15:12:56 2022 +1000

    xfs: use XFS_DA_OP flags in deferred attr ops

    We currently store the high level attr operation in
    args->attr_flags. This field contains what the VFS is telling us to
    do, but don't necessarily match what we are doing in the low level
    modification state machine. e.g. XATTR_REPLACE implies both
    XFS_DA_OP_ADDNAME and XFS_DA_OP_RENAME because it is doing both a
    remove and adding a new attr.

    However, deep in the individual state machine operations, we check
    errors against this high level VFS op flags, not the low level
    XFS_DA_OP flags. Indeed, we don't even have a low level flag for
    a REMOVE operation, so the only way we know we are doing a remove
    is the complete absence of XATTR_REPLACE, XATTR_CREATE,
    XFS_DA_OP_ADDNAME and XFS_DA_OP_RENAME. And because there are other
    flags in these fields, this is a pain to check if we need to.

    As the XFS_DA_OP flags are only needed once the deferred operations
    are set up, set these flags appropriately when we set the initial
    operation state. We also introduce a XFS_DA_OP_REMOVE flag to make
    it easy to know that we are doing a remove operation.

    With these, we can remove the use of XATTR_REPLACE and XATTR_CREATE
    in low level lookup operations, and manipulate the low level flags
    according to the low level context that is operating. e.g. log
    recovery does not have a VFS xattr operation state to copy into
    args->attr_flags, and the low level state machine ops we do for
    recovery do not match the high level VFS operations that were in
    progress when the system failed...

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

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:23 -05:00
Bill O'Donnell 8dc9bb270c xfs: convert da btree operations flags to unsigned.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit 3402d931575f1fb0c6863eaad6595f55e6389eda
Author: Dave Chinner <dchinner@redhat.com>
Date:   Thu Apr 21 10:46:47 2022 +1000

    xfs: convert da btree operations flags to unsigned.

    5.18 w/ std=gnu11 compiled with gcc-5 wants flags stored in unsigned
    fields to be unsigned.

    Signed-off-by: Dave Chinner <dchinner@redhat.com>
    Reviewed-by: Chandan Babu R <chandan.babu@oracle.com>
    Signed-off-by: Dave Chinner <david@fromorbit.com>

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:11:07 -05:00
Bill O'Donnell b67c061975 xfs: Directory's data fork extent counter can never overflow
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2167832

commit 83a21c18441f75aec64548692b52d34582b98a6a
Author: Chandan Babu R <chandan.babu@oracle.com>
Date:   Tue Mar 29 06:14:00 2022 +0000

    xfs: Directory's data fork extent counter can never overflow

    The maximum file size that can be represented by the data fork extent counter
    in the worst case occurs when all extents are 1 block in length and each block
    is 1KB in size.

    With XFS_MAX_EXTCNT_DATA_FORK_SMALL representing maximum extent count and with
    1KB sized blocks, a file can reach upto,
    (2^31) * 1KB = 2TB

    This is much larger than the theoretical maximum size of a directory
    i.e. XFS_DIR2_SPACE_SIZE * 3 = ~96GB.

    Since a directory's inode can never overflow its data fork extent counter,
    this commit removes all the overflow checks associated with
    it. xfs_dinode_verify() now performs a rough check to verify if a diretory's
    data fork is larger than 96GB.

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

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
2023-05-18 11:10:59 -05:00
Carlos Maiolino 25a40d32f8 xfs: rename _zone variables to _cache
Bugzilla: https://bugzilla.redhat.com/2125724

Conflicts:
	Small conflict at xfs_inode_alloc() due to out of order
	backport. Inode alloc using kmem_cache_alloc() has been
	converted to use alloc_inode_sb() before this patch.

Now that we've gotten rid of the kmem_zone_t typedef, rename the
variables to _cache since that's what they are.

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 182696fb021fc196e5cbe641565ca40fcf0f885a)
2022-10-21 12:50:46 +02: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 4491a3dd71 xfs: Refactor xfs_da_state_alloc() helper
Every call to xfs_da_state_alloc() also requires setting up state->args
and state->mp

Change xfs_da_state_alloc() to receive an xfs_da_args_t as argument and
return a xfs_da_state_t with both args and mp already set.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: reduce struct typedef usage]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2020-07-28 20:24:14 -07:00
Nishad Kamdar 508578f2f5 xfs: Use the correct style for SPDX License Identifier
This patch corrects the SPDX License Identifier style in header files
related to XFS File System support. For C header files
Documentation/process/license-rules.rst mandates C-like comments.
(opposed to C source files where C++ style should be used).

Changes made by using a script provided by Joe Perches here:
https://lkml.org/lkml/2019/2/7/46.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Nishad Kamdar <nishadkamdar@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-05-13 15:32:45 -07:00
Christoph Hellwig 254f800f81 xfs: remove XFS_DA_OP_INCOMPLETE
Now that we use the on-disk flags field also for the interface to the
lower level attr routines we can use the XFS_ATTR_INCOMPLETE definition
from the on-disk format directly instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-03-02 20:55:55 -08:00
Christoph Hellwig d5f0f49a9b xfs: clean up the attr flag confusion
The ATTR_* flags have a long IRIX history, where they a userspace
interface, the on-disk format and an internal interface.  We've split
out the on-disk interface to the XFS_ATTR_* values, but despite (or
because?) of that the flag have still been a mess.  Switch the
internal interface to pass the on-disk XFS_ATTR_* flags for the
namespace and the Linux XATTR_* flags for the actual flags instead.
The ATTR_* values that are actually used are move to xfs_fs.h with a
new XFS_IOC_* prefix to not conflict with the userspace version that
has the same name and must have the same value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-03-02 20:55:55 -08:00
Christoph Hellwig 1d73301994 xfs: replace ATTR_KERNOTIME with XFS_DA_OP_NOTIME
op_flags with the XFS_DA_OP_* flags is the usual place for in-kernel
only flags, so move the notime flag there.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-03-02 20:55:53 -08:00
Christoph Hellwig d49db18b24 xfs: remove ATTR_ALLOC and XFS_DA_OP_ALLOCVAL
Use a NULL args->value as the indicator to lazily allocate a buffer
instead, and let the caller always free args->value instead of
duplicating the cleanup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2020-03-02 20:55:53 -08:00
Christoph Hellwig ead189adb8 xfs: turn xfs_da_args.value into a void pointer
The xattr values are blobs and should not be typed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-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>
2020-03-02 20:55:53 -08:00
Christoph Hellwig 780d290577 xfs: fix misuse of the XFS_ATTR_INCOMPLETE flag
XFS_ATTR_INCOMPLETE is a flag in the on-disk attribute format, and thus
in a different namespace as the ATTR_* flags in xfs_da_args.flags.
Switch to using a XFS_DA_OP_INCOMPLETE flag in op_flags instead.  Without
this users might be able to inject this flag into operations using the
attr by handle ioctl.

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>
2020-01-09 10:55:18 -08:00
Christoph Hellwig 2911edb653 xfs: remove the mappedbno argument to xfs_da_get_buf
Use the xfs_da_get_buf_daddr function directly for the two callers
that pass a mapped disk address, and then remove the mappedbno argument.

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-11-22 08:17:10 -08:00
Christoph Hellwig cd2c9f1b54 xfs: remove the mappedbno argument to xfs_da_read_buf
Move the code for reading an already mapped block into
xfs_da3_node_read_mapped, which is the only caller ever passing a block
number in the mappedbno argument and replace the mappedbno argument with
the simple xfs_dabuf_get flags.

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-11-22 08:17:10 -08:00
Christoph Hellwig 02c57f0a8b xfs: split xfs_da3_node_read
Split xfs_da3_node_read into one variant that always looks up the daddr
and doesn't accept holes, and one that already has a daddr at hand.
This is in preparation of splitting up xfs_da_read_buf in a similar way.

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-11-22 08:17:10 -08:00
Christoph Hellwig 06566fda42 xfs: remove the mappedbno argument to xfs_da_reada_buf
Replace the mappedbno argument with the simple flags for xfs_da_reada_buf
and xfs_dir3_data_readahead.

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-11-22 08:17:09 -08:00
Christoph Hellwig 199e9ba4e4 xfs: improve the xfs_dabuf_map calling conventions
Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
a hole is okay and not corruption, and return 0 with *nmap set to 0 to
signal that case in the return value instead of a nameless -1 return
code.

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-11-22 08:17:09 -08:00
Christoph Hellwig d8d11fc703 xfs: devirtualize ->m_dirnameops
Instead of causing a relatively expensive indirect call for each
hashing and comparism of a file name in a directory just use an
inline function and a simple branch on the ASCII CI bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: fix unused variable warning]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-11-13 11:13:45 -08:00
Christoph Hellwig 957ee13e20 xfs: remove the now unused dir ops infrastructure
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-11-10 16:54:24 -08:00
Christoph Hellwig d73e1cee8a xfs: move the dir2 data block fixed offsets to struct xfs_da_geometry
Move the data block fixed offsets towards our structure for dir/attr
geometry parameters.

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-11-10 16:54:24 -08:00
Christoph Hellwig 5893e4feb0 xfs: move the max dir2 free bests count to struct xfs_da_geometry
Move the max free bests count towards our structure for dir/attr
geometry parameters.

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-11-10 16:54:21 -08:00
Christoph Hellwig ed1d612fbe xfs: move the dir2 free header size to struct xfs_da_geometry
Move the free header size towards our structure for dir/attr geometry
parameters.

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-11-10 16:54:21 -08:00
Christoph Hellwig 478c7835cb xfs: move the max dir2 leaf entries count to struct xfs_da_geometry
Move the max leaf entries count towards our structure for dir/attr
geometry parameters.

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-11-10 16:54:20 -08:00
Christoph Hellwig 545910bcc8 xfs: move the dir2 leaf header size to struct xfs_da_geometry
Move the leaf header size towards our structure for dir/attr geometry
parameters.

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-11-10 16:54:20 -08:00
Christoph Hellwig 3b34441309 xfs: move the node header size to struct xfs_da_geometry
Move the node header size field to struct xfs_da_geometry, and remove
the now unused non-directory dir ops infrastructure.

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-11-10 16:54:19 -08:00
Christoph Hellwig 51908ca75f xfs: add a btree entries pointer to struct xfs_da3_icnode_hdr
All but two callers of the ->node_tree_p dir operation already have a
xfs_da3_icnode_hdr from a previous call to xfs_da3_node_hdr_from_disk at
hand.  Add a pointer to the btree entries to struct xfs_da3_icnode_hdr
to clean up this pattern.  The two remaining callers now expand the
whole header as well, but that isn't very expensive and not in a super
hot path anyway.

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-11-10 16:54:19 -08:00
Christoph Hellwig e1c8af1e02 xfs: devirtualize ->node_hdr_to_disk
Replace the ->node_hdr_to_disk dir ops method with a directly called
xfs_da_node_hdr_to_disk helper that takes care of the v4 vs v5
difference.

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-11-10 16:54:19 -08:00
Christoph Hellwig f475dc4dc7 xfs: devirtualize ->node_hdr_from_disk
Replace the ->node_hdr_from_disk dir ops method with a directly called
xfs_da_node_hdr_from_disk helper that takes care of the v4 vs v5
difference.

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-11-10 16:54:19 -08:00
Christoph Hellwig b16be56187 xfs: use unsigned int for all size values in struct xfs_da_geometry
None of these can ever be negative, so use unsigned types.

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-11-10 16:54:19 -08:00
Christoph Hellwig a39f089a25 xfs: move incore structures out of xfs_da_format.h
Move the abstract in-memory version of various btree block headers
out of xfs_da_format.h as they aren't on-disk formats.

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-11-10 16:54:19 -08:00
Dave Chinner ddbca70cc4 xfs: allocate xattr buffer on demand
When doing file lookups and checking for permissions, we end up in
xfs_get_acl() to see if there are any ACLs on the inode. This
requires and xattr lookup, and to do that we have to supply a buffer
large enough to hold an maximum sized xattr.

On workloads were we are accessing a wide range of cache cold files
under memory pressure (e.g. NFS fileservers) we end up spending a
lot of time allocating the buffer. The buffer is 64k in length, so
is a contiguous multi-page allocation, and if that then fails we
fall back to vmalloc(). Hence the allocation here is /expensive/
when we are looking up hundreds of thousands of files a second.

Initial numbers from a bpf trace show average time in xfs_get_acl()
is ~32us, with ~19us of that in the memory allocation. Note these
are average times, so there are going to be affected by the worst
case allocations more than the common fast case...

To avoid this, we could just do a "null"  lookup to see if the ACL
xattr exists and then only do the allocation if it exists. This,
however, optimises the path for the "no ACL present" case at the
expense of the "acl present" case. i.e. we can halve the time in
xfs_get_acl() for the no acl case (i.e down to ~10-15us), but that
then increases the ACL case by 30% (i.e. up to 40-45us).

To solve this and speed up both cases, drive the xattr buffer
allocation into the attribute code once we know what the actual
xattr length is. For the no-xattr case, we avoid the allocation
completely, speeding up that case. For the common ACL case, we'll
end up with a fast heap allocation (because it'll be smaller than a
page), and only for the rarer "we have a remote xattr" will we have
a multi-page allocation occur. Hence the common ACL case will be
much faster, too.

Signed-off-by: Dave Chinner <dchinner@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>
2019-08-30 22:43:57 -07:00
Brian Foster 9d9e623385 xfs: fold dfops into the transaction
struct xfs_defer_ops has now been reduced to a single list_head. The
external dfops mechanism is unused and thus everywhere a (permanent)
transaction is accessible the associated dfops structure is as well.

Remove the xfs_defer_ops structure and fold the list_head into the
transaction. Also remove the last remnant of external dfops in
xfs_trans_dup().

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-08-02 23:05:14 -07:00
Brian Foster 766139032f xfs: use ->t_firstblock in xattr ops
Similar to the dirops code, the xattr code uses an on-stack
firstblock variable for the various operations. This code rolls the
underlying transaction in various places, however, which means we
cannot simply replace the local firstblock vars with ->t_firstblock.
Doing so (without further changes) would invalidate the memory
pointed to by xfs_da_args.firstblock as soon as the first
transaction rolls.

To avoid this problem, remove xfs_da_args.firstblock and replace all
such accesses with ->t_firstblock at the same time. This ensures
that accesses to the current firstblock always occur through the
current transaction rather than a potentially invalid xfs_da_args
pointer.

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:22 -07:00
Brian Foster 32a9b7c65c xfs: replace xfs_da_args->dfops accesses with ->t_dfops and remove
Now that xfs_da_args->dfops is always assigned from a ->t_dfops
pointer (or one that is immediately attached), replace all
downstream accesses of the former with the latter and remove the
field from struct xfs_da_args.

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:11 -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 c8ce540db5 xfs: remove double-underscore integer types
This is a purely mechanical patch that removes the private
__{u,}int{8,16,32,64}_t typedefs in favor of using the system
{u,}int{8,16,32,64}_t typedefs.  This is the sed script used to perform
the transformation and fix the resulting whitespace and indentation
errors:

s/typedef\t__uint8_t/typedef __uint8_t\t/g
s/typedef\t__uint/typedef __uint/g
s/typedef\t__int\([0-9]*\)_t/typedef int\1_t\t/g
s/__uint8_t\t/__uint8_t\t\t/g
s/__uint/uint/g
s/__int\([0-9]*\)_t\t/__int\1_t\t\t/g
s/__int/int/g
/^typedef.*int[0-9]*_t;$/d

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2017-06-19 14:11:33 -07:00
Darrick J. Wong 7a652bbe36 xfs: fail _dir_open when readahead fails
When we open a directory, we try to readahead block 0 of the directory
on the assumption that we're going to need it soon.  If the bmbt is
corrupt, the directory will never be usable and the readahead fails
immediately, so we might as well prevent the directory from being opened
at all.  This prevents a subsequent read or modify operation from
hitting it and taking the fs offline.

NOTE: We're only checking for early failures in the block mapping, not
the readahead directory block itself.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2017-02-02 15:13:58 -08:00
Darrick J. Wong 2c3234d1ef xfs: rename flist/free_list to dfops
Mechanical change of flist/free_list to dfops, since they're now
deferred ops, not just a freeing list.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 11:19:29 +10:00
Darrick J. Wong 310a75a3c6 xfs: change xfs_bmap_{finish,cancel,init,free} -> xfs_defer_*
Drop the compatibility shims that we were using to integrate the new
deferred operation mechanism into the existing code.  No new code.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 11:18:10 +10:00
Dave Chinner 84be0ffc90 libxfs: move header files
Move all the header files that are shared with userspace into
libxfs. This is done as one big chunk simpy to get it done quickly.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2014-06-25 14:57:36 +10:00