]> www.infradead.org Git - users/hch/xfsprogs.git/log
users/hch/xfsprogs.git
8 months agoxfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname
Christoph Hellwig [Tue, 15 Oct 2024 19:43:44 +0000 (12:43 -0700)]
xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname

Source kernel commit: b1c649da15c2e4c86344c8e5af69c8afa215efec

xfs_attr_leaf_try_add is only called by xfs_attr_leaf_addname, and
merging the two will simplify a following error handling fix.

To facilitate this move the remote block state save/restore helpers up in
the file so that they don't need forward declarations now.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
8 months agoxfs: enable block size larger than page size support
Pankaj Raghav [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: enable block size larger than page size support

Source kernel commit: 7df7c204c678e24cd32d33360538670b7b90e330

Page cache now has the ability to have a minimum order when allocating
a folio which is a prerequisite to add support for block size > page
size.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20240827-xfs-fix-wformat-bs-gt-ps-v1-1-aec6717609e0@kernel.org
Link: https://lore.kernel.org/r/20240822135018.1931258-11-kernel@pankajraghav.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
8 months agoxfs: ensure st_blocks never goes to zero during COW writes
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: ensure st_blocks never goes to zero during COW writes

Source kernel commit: 90fa22da6d6b41dc17435aff7b800f9ca3c00401

COW writes remove the amount overwritten either directly for delalloc
reservations, or in earlier deferred transactions than adding the new
amount back in the bmap map transaction.  This means st_blocks on an
inode where all data is overwritten using the COW path can temporarily
show a 0 st_blocks.  This can easily be reproduced with the pending
zoned device support where all writes use this path and trips the
check in generic/615, but could also happen on a reflink file without
that.

Fix this by temporarily add the pending blocks to be mapped to
i_delayed_blks while the item is queued.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: convert perag lookup to xarray
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: convert perag lookup to xarray

Source kernel commit: 32fa4059fe6776d7db1e9058f360e06b36c9f2ce

Convert the perag lookup from the legacy radix tree to the xarray,
which allows for much nicer iteration and bulk lookup semantics.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: move the tagged perag lookup helpers to xfs_icache.c
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: move the tagged perag lookup helpers to xfs_icache.c

Source kernel commit: f48f0a8e00b67028d4492e7656b346fa0d806570

The tagged perag helpers are only used in xfs_icache.c in the kernel code
and not at all in xfsprogs.  Move them to xfs_icache.c in preparation for
switching to an xarray, for which I have no plan to implement the tagged
lookup functions for userspace.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: use kfree_rcu_mightsleep to free the perag structures
Christoph Hellwig [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: use kfree_rcu_mightsleep to free the perag structures

Source kernel commit: 4ef7c6d39dc72dae983b836c8b2b5de7128c0da3

Using the kfree_rcu_mightsleep is simpler and removes the need for a
rcu_head in the perag structure.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: remove unnecessary check
Dan Carpenter [Tue, 15 Oct 2024 19:43:43 +0000 (12:43 -0700)]
xfs: remove unnecessary check

Source kernel commit: fb8b941c75bd70ddfb0a8a3bb9bb770ed1d648f8

We checked that "pip" is non-NULL at the start of the if else statement
so there is no need to check again here.  Delete the check.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
8 months agoxfs: use kvmalloc for xattr buffers
Dave Chinner [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: use kvmalloc for xattr buffers

Source kernel commit: de631e1a8b71017b8a12b57d07db82e4052555af

Pankaj Raghav reported that when filesystem block size is larger
than page size, the xattr code can use kmalloc() for high order
allocations. This triggers a useless warning in the allocator as it
is a __GFP_NOFAIL allocation here:

static inline
struct page *rmqueue(struct zone *preferred_zone,
struct zone *zone, unsigned int order,
gfp_t gfp_flags, unsigned int alloc_flags,
int migratetype)
{
struct page *page;

/*
* We most definitely don't want callers attempting to
* allocate greater than order-1 page units with __GFP_NOFAIL.
*/
>>>>    WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1));
...

Fix this by changing all these call sites to use kvmalloc(), which
will strip the NOFAIL from the kmalloc attempt and if that fails
will do a __GFP_NOFAIL vmalloc().

This is not an issue that productions systems will see as
filesystems with block size > page size cannot be mounted by the
kernel; Pankaj is developing this functionality right now.

Reported-by: Pankaj Raghav <kernel@pankajraghav.com>
Fixes: f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()")
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Link: https://lore.kernel.org/r/20240822135018.1931258-8-kernel@pankajraghav.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
8 months agoxfs: standardize the btree maxrecs function parameters
Darrick J. Wong [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: standardize the btree maxrecs function parameters

Source kernel commit: 411a71256de6f5a0015a28929cfbe6bc36c503dc

Standardize the parameters in xfs_{alloc,bm,ino,rmap,refcount}bt_maxrecs
so that we have consistent calling conventions.  This doesn't affect the
kernel that much, but enables us to clean up userspace a bit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: replace shouty XFS_BM{BT,DR} macros
Darrick J. Wong [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: replace shouty XFS_BM{BT,DR} macros

Source kernel commit: 79124b3740063573312de4b225407ebdae219275

Replace all the shouty bmap btree and bmap disk root macros with actual
functions.

sed \
-e 's/XFS_BMBT_BLOCK_LEN/xfs_bmbt_block_len/g' \
-e 's/XFS_BMBT_REC_ADDR/xfs_bmbt_rec_addr/g' \
-e 's/XFS_BMBT_KEY_ADDR/xfs_bmbt_key_addr/g' \
-e 's/XFS_BMBT_PTR_ADDR/xfs_bmbt_ptr_addr/g' \
-e 's/XFS_BMDR_REC_ADDR/xfs_bmdr_rec_addr/g' \
-e 's/XFS_BMDR_KEY_ADDR/xfs_bmdr_key_addr/g' \
-e 's/XFS_BMDR_PTR_ADDR/xfs_bmdr_ptr_addr/g' \
-e 's/XFS_BMAP_BROOT_PTR_ADDR/xfs_bmap_broot_ptr_addr/g' \
-e 's/XFS_BMAP_BROOT_SPACE_CALC/xfs_bmap_broot_space_calc/g' \
-e 's/XFS_BMAP_BROOT_SPACE/xfs_bmap_broot_space/g' \
-e 's/XFS_BMDR_SPACE_CALC/xfs_bmdr_space_calc/g' \
-e 's/XFS_BMAP_BMDR_SPACE/xfs_bmap_bmdr_space/g' \
-i $(git ls-files fs/xfs/*.[ch] fs/xfs/libxfs/*.[ch] fs/xfs/scrub/*.[ch])

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: fix a sloppy memory handling bug in xfs_iroot_realloc
Darrick J. Wong [Tue, 15 Oct 2024 19:43:42 +0000 (12:43 -0700)]
xfs: fix a sloppy memory handling bug in xfs_iroot_realloc

Source kernel commit: de55149b6639e903c4d06eb0474ab2c05060e61d

While refactoring code, I noticed that when xfs_iroot_realloc tries to
shrink a bmbt root block, it allocates a smaller new block and then
copies "records" and pointers to the new block.  However, bmbt root
blocks cannot ever be leaves, which means that it's not technically
correct to copy records.  We /should/ be copying keys.

Note that this has never resulted in actual memory corruption because
sizeof(bmbt_rec) == (sizeof(bmbt_key) + sizeof(bmbt_ptr)).  However,
this will no longer be true when we start adding realtime rmap stuff,
so fix this now.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: replace m_rsumsize with m_rsumblocks
Christoph Hellwig [Tue, 15 Oct 2024 19:43:41 +0000 (12:43 -0700)]
xfs: replace m_rsumsize with m_rsumblocks

Source kernel commit: 33912286cb1956920712aba8cb6f38e434824357

Track the RT summary file size in blocks, just like the RT bitmap
file.  While we have users of both units, blocks are used slightly
more often and this matches the bitmap file for consistency.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove xfs_{rtbitmap,rtsummary}_wordcount
Christoph Hellwig [Tue, 15 Oct 2024 19:43:41 +0000 (12:43 -0700)]
xfs: remove xfs_{rtbitmap,rtsummary}_wordcount

Source kernel commit: 1fc51cf11dd8b26856ae1c4111e402caec73019c

xfs_rtbitmap_wordcount and xfs_rtsummary_wordcount are currently unused,
so remove them to simplify refactoring other rtbitmap helpers.  They
can be added back or simply open coded when actually needed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: clean up the ISVALID macro in xfs_bmap_adjacent
Christoph Hellwig [Tue, 15 Oct 2024 19:43:41 +0000 (12:43 -0700)]
xfs: clean up the ISVALID macro in xfs_bmap_adjacent

Source kernel commit: 1e21d1897f935815618d419c94e88452070ec8e5

Turn the  ISVALID macro defined and used inside in xfs_bmap_adjacent
that relies on implict context into a proper inline function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: simplify xfs_rtalloc_query_range
Christoph Hellwig [Tue, 15 Oct 2024 19:43:41 +0000 (12:43 -0700)]
xfs: simplify xfs_rtalloc_query_range

Source kernel commit: df8b181f1551581e96076a653cdca43468093c0f

There isn't much of a good reason to pass the xfs_rtalloc_rec structures
that describe extents to xfs_rtalloc_query_range as we really just want
a lower and upper bound xfs_rtxnum_t.  Pass the rtxnum directly and
simply the interface.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove xfs_rtb_to_rtxrem
Christoph Hellwig [Tue, 15 Oct 2024 19:43:41 +0000 (12:43 -0700)]
xfs: remove xfs_rtb_to_rtxrem

Source kernel commit: fa0fc38b255cc88aef31ff13b5593e27622204e1

Simplify the number of block number conversion helpers by removing
xfs_rtb_to_rtxrem.  Any recent compiler is smart enough to eliminate
the double divisions if using separate xfs_rtb_to_rtx and
xfs_rtb_to_rtxoff calls.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: ensure rtx mask/shift are correct after growfs
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: ensure rtx mask/shift are correct after growfs

Source kernel commit: 86a0264ef26e90214a5bd74c72fb6e3455403bcf

When growfs sets an extent size, it doesn't updated the m_rtxblklog and
m_rtxblkmask values, which could lead to incorrect usage of them if they
were set before and can't be used for the new extent size.

Add a xfs_mount_sb_set_rextsize helper that updates the two fields, and
also use it when calculating the new RT geometry instead of disabling
the optimization there.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock

Source kernel commit: 0a59e4f3e1670bc49d60e1bd1a9b19ca156ae9cb

To prepare for being able to join an already locked rtbitmap inode to a
transaction split out separate helpers for joining the transaction from
the locking helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: factor out rtbitmap/summary initialization helpers
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: factor out rtbitmap/summary initialization helpers

Source kernel commit: 2a95ffc44b610643c9d5d2665600d3fbefa5ec4f

Add helpers to libxfs that can be shared by growfs and mkfs for
initializing the rtbitmap and summary, and by passing the optional data
pointer also by repair for rebuilding them.  This will become even more
useful when the rtgroups feature adds a metadata header to each block,
which means even more shared code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: minor documentation and data advance tweaks]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf

Source kernel commit: b4781eea6872431840e53ffebb95a5614e6944b4

Add a corruption check for passing an invalid block number, which is a
lot easier to understand than the xfs_bmapi_read failure later on.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: assert a valid limit in xfs_rtfind_forw
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: assert a valid limit in xfs_rtfind_forw

Source kernel commit: 6d2db12d56a389b3e8efa236976f8dc3a8ae00f0

Protect against developers passing stupid limits when refactoring the
RT code once again.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove the limit argument to xfs_rtfind_back
Christoph Hellwig [Tue, 15 Oct 2024 19:43:40 +0000 (12:43 -0700)]
xfs: remove the limit argument to xfs_rtfind_back

Source kernel commit: 119c65e56bc131b466a7cd958a4089e286ce3c4b

All callers pass a 0 limit to xfs_rtfind_back, so remove the argument
and hard code it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: factor out a xfs_validate_rt_geometry helper
Christoph Hellwig [Tue, 15 Oct 2024 19:43:39 +0000 (12:43 -0700)]
xfs: factor out a xfs_validate_rt_geometry helper

Source kernel commit: 6529eef810e2ded0e540162273ee31a41314ec4e

Split the RT geometry validation in the early mount code into a
helper than can be reused by repair (from which this code was
apparently originally stolen anyway).

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: u64 return value for calc_rbmblocks]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: remove xfs_validate_rtextents
Christoph Hellwig [Tue, 15 Oct 2024 19:43:39 +0000 (12:43 -0700)]
xfs: remove xfs_validate_rtextents

Source kernel commit: 021d9c107e29a598e51fb66a54b22e5416125408

Replace xfs_validate_rtextents with an open coded check for 0
rtextents.  The name for the function implies it does a lot more
than a zero check, which is more obvious when open coded.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agoxfs: pass the icreate args object to xfs_dialloc
Darrick J. Wong [Tue, 15 Oct 2024 19:43:39 +0000 (12:43 -0700)]
xfs: pass the icreate args object to xfs_dialloc

Source kernel commit: 390b4775d6787706b1846f15623a68e576ec900c

Pass the xfs_icreate_args object to xfs_dialloc since we can extract the
relevant mode (really just the file type) and parent inumber from there.
This simplifies the calling convention in preparation for the next
patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agoxfs: introduce new file range commit ioctls
Darrick J. Wong [Tue, 15 Oct 2024 19:43:39 +0000 (12:43 -0700)]
xfs: introduce new file range commit ioctls

Source kernel commit: 398597c3ef7fb1d8fa31491c8f4f3996cff45701

This patch introduces two more new ioctls to manage atomic updates to
file contents -- XFS_IOC_START_COMMIT and XFS_IOC_COMMIT_RANGE.  The
does, but with the additional requirement that file2 cannot have changed
since some sampling point.  The start-commit ioctl performs the sampling
of file attributes.

Note: This patch currently samples i_ctime during START_COMMIT and
checks that it hasn't changed during COMMIT_RANGE.  This isn't entirely
safe in kernels prior to 6.12 because ctime only had coarse grained
granularity and very fast updates could collide with a COMMIT_RANGE.
With the multi-granularity ctime introduced by Jeff Layton, it's now
possible to update ctime such that this does not happen.

It is critical, then, that this patch must not be backported to any
kernel that does not support fine-grained file change timestamps.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Acked-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibfrog: add xarray emulation
Christoph Hellwig [Tue, 15 Oct 2024 19:43:39 +0000 (12:43 -0700)]
libfrog: add xarray emulation

Implement the simple parts of the kernel xarray API on-top of the libfrog
radix-tree.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
8 months agolibxfs: port IS_ENABLED from the kernel
Darrick J. Wong [Tue, 15 Oct 2024 19:43:38 +0000 (12:43 -0700)]
libxfs: port IS_ENABLED from the kernel

Port the IS_ENABLED macro from the kernel so that it can be used in
libxfs.  This requires a bit of hygiene on our part -- any CONFIG_XFS_*
define in userspace that have counterparts in the kernel must be defined
to 1 (and not simply define'd) so that the macro works, because the
kernel translates CONFIG_FOO=y in .config to #define CONFIG_FOO 1.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibxfs: test compiling public headers with a C++ compiler
Darrick J. Wong [Tue, 15 Oct 2024 19:43:38 +0000 (12:43 -0700)]
libxfs: test compiling public headers with a C++ compiler

Apparently C++ compilers don't like the implicit void* casts that go on
in the system headers.  Compile a dummy program with the C++ compiler to
make sure this works.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Tested-by: Sam James <sam@gentoo.org>
Reviewed-by: Sam James <sam@gentoo.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
8 months agolibxfs: require -std=gnu11 for compilation by default
Darrick J. Wong [Tue, 15 Oct 2024 19:43:38 +0000 (12:43 -0700)]
libxfs: require -std=gnu11 for compilation by default

The kernel now builds with -std=gnu11, so let's make xfsprogs do that by
default too.  Distributions can still override the parameters by passing
CFLAGS= and BUILD_CFLAGS= to configure, just as they always have.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfsprogs: Release v6.11.0
Andrey Albershteyn [Wed, 16 Oct 2024 18:13:22 +0000 (20:13 +0200)]
xfsprogs: Release v6.11.0

Update all the necessary files for a v6.11.0 release.

Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
9 months agoxfsprogs: update gitignore
Andrey Albershteyn [Fri, 4 Oct 2024 11:57:04 +0000 (13:57 +0200)]
xfsprogs: update gitignore

Building xfsprogs seems to produce many build artifacts which are
not tracked by git. Ignore them.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
9 months agoxfsprogs: fix permissions on files installed by libtoolize
Andrey Albershteyn [Fri, 4 Oct 2024 11:57:03 +0000 (13:57 +0200)]
xfsprogs: fix permissions on files installed by libtoolize

Libtoolize installs some set of AUX files from its system package.
Not all distributions have the same permissions set on these files.
For example, read-only libtoolize system package will copy those
files without write permissions. This causes build to fail as next
line copies ./include/install-sh over ./install-sh which is not
writable.

Fix this by setting permission explicitly on files copied by
libtoolize.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
9 months agomkfs: break up the rest of the rtinit() function
Darrick J. Wong [Wed, 2 Oct 2024 01:27:05 +0000 (18:27 -0700)]
mkfs: break up the rest of the rtinit() function

Break up this really long function into smaller functions that each do
one thing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agomkfs: clean up the rtinit() function
Darrick J. Wong [Wed, 2 Oct 2024 01:26:49 +0000 (18:26 -0700)]
mkfs: clean up the rtinit() function

Clean up some of the warts in this function, like the inconsistent use
of @i for @error, missing comments, and make this more visually pleasing
by adding some whitespace between major sections.  Some things are left
untouched for the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_repair: use library functions for orphanage creation
Darrick J. Wong [Wed, 2 Oct 2024 01:26:34 +0000 (18:26 -0700)]
xfs_repair: use library functions for orphanage creation

Use new library functions to create lost+found.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_repair: use library functions to reset root/rbm/rsum inodes
Darrick J. Wong [Wed, 2 Oct 2024 01:26:18 +0000 (18:26 -0700)]
xfs_repair: use library functions to reset root/rbm/rsum inodes

Use the iroot reset function to reset root inodes instead of open-coding
the reset routine.  While we're at it, fix a longstanding memory leak if
the inode being reset actually had an xattr fork full of mappings.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_repair: don't crash in get_inode_parent
Darrick J. Wong [Wed, 2 Oct 2024 01:26:02 +0000 (18:26 -0700)]
xfs_repair: don't crash in get_inode_parent

The xfs_repair fuzz test suite encountered a crash in xfs_repair.  In
the fuzzed filesystem, inode 8388736 is a single-block directory where
the one dir data block has been trashed.  This inode maps to agno 1
agino 128, and all other inodes in that inode chunk are regular files.
Output is as follows:

Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan (but don't clear) agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
Metadata corruption detected at 0x565335fbd534, xfs_dir3_block block 0x4ebc78/0x1000
corrupt directory block 0 for inode 8388736
no . entry for directory 8388736
no .. entry for directory 8388736
problem with directory contents in inode 8388736
would have cleared inode 8388736
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
entry "S_IFDIR.FMT_BLOCK" at block 0 offset 1728 in directory inode 128 references free inode 8388736
        would clear inode number in entry at offset 1728...
        - agno = 1
entry "." at block 0 offset 64 in directory inode 8388736 references free inode 8388736
imap claims in-use inode 8388736 is free, would correct imap
        - agno = 2
        - agno = 3
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
./common/xfs: line 387: 84940 Segmentation fault      (core dumped) $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV

From the coredump, we crashed in get_inode_parent here because ptbl is a
NULL pointer:

if (ptbl->pmask & (1ULL << offset))  {

Directory inode 8388736 doesn't have a dotdot entry and phase 3 decides
to clear that inode, so it never calls set_inode_parent for 8388736.
Because the rest of the inodes in the chunk are regular files, phase 3
never calls set_inode_parent on the corresponding irec.  As a result,
neither irec->ino_un.plist nor irec->ino_un.ex_data->parents are ever
set to a parents array.

When phase 6 calls get_inode_parent to check the S_IFDIR.FMT_BLOCK
dirent from the root directory to inode 8388736, it sets ptbl to
irec->ino_un.ex_data->parents (which is still NULL) and walks off the
NULL pointer.

Because get_inode_parent already has the behavior that it can return
zero for "unknown parent", the correction is simple: check ptbl before
dereferencing it.  git blame says this code has been in xfsprogs since
the beginning of git, so I won't bother with a fixes tag.

Found by fuzzing bhdr.hdr.bno = zeroes in xfs/386.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_repair: fix exchrange upgrade
Darrick J. Wong [Wed, 2 Oct 2024 01:25:47 +0000 (18:25 -0700)]
xfs_repair: fix exchrange upgrade

Set the correct superblock field for the exchange-range feature upgrade.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_db: port the iunlink command to use the libxfs iunlink function
Darrick J. Wong [Wed, 2 Oct 2024 01:25:31 +0000 (18:25 -0700)]
xfs_db: port the iunlink command to use the libxfs iunlink function

Now that we've ported the kernel's iunlink code to userspace, adapt the
debugger command to use it instead of duplicating the logic.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_db/mdrestore/repair: don't use the incore struct xfs_sb for offsets into struct...
Darrick J. Wong [Wed, 2 Oct 2024 01:25:16 +0000 (18:25 -0700)]
xfs_db/mdrestore/repair: don't use the incore struct xfs_sb for offsets into struct xfs_dsb

Source kernel commit: ac3a0275165b4f80d9b7b516d6a8f8b308644fff

Currently, the XFS_SB_CRC_OFF macro uses the incore superblock struct
(xfs_sb) to compute the address of sb_crc within the ondisk superblock
struct (xfs_dsb).  This is a landmine if we ever change the layout of
the incore superblock (as we're about to do), so redefine the macro
to use xfs_dsb to compute the layout of xfs_dsb.

Port the userspace utilities to the new code just like we did for the
kernel.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs_db/mkfs/xfs_repair: port to use XFS_ICREATE_UNLINKABLE
Darrick J. Wong [Wed, 2 Oct 2024 01:25:00 +0000 (18:25 -0700)]
xfs_db/mkfs/xfs_repair: port to use XFS_ICREATE_UNLINKABLE

INIT_XATTRS is overloaded here -- it's set during the creat process when
we think that we're immediately going to set some ACL xattrs to save
time.  However, it's also used by the parent pointers code to enable the
attr fork in preparation to receive ppptr xattrs.  This results in
xfs_has_parent() branches scattered around the codebase to turn on
INIT_XATTRS.

Linkable files are created far more commonly than unlinkable temporary
files or directory tree roots, so we should centralize this logic in
xfs_inode_init.  For the three callers that don't want parent pointers
(online repiar tempfiles, unlinkable tempfiles, rootdir creation) we
provide an UNLINKABLE flag to skip attr fork initialization.

Port these three utilities to use XFS_ICREATE_UNLINKABLE the same as we
did for the kernel.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[aalbersh: drop reference to kernel commit]

9 months agoxfs_db: port the unlink command to use libxfs_droplink
Darrick J. Wong [Wed, 2 Oct 2024 01:24:44 +0000 (18:24 -0700)]
xfs_db: port the unlink command to use libxfs_droplink

Port this command to use the libxfs droplink implementation instead of
opencoding it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: xfs_finobt_count_blocks() walks the wrong btree
Dave Chinner [Wed, 2 Oct 2024 01:24:29 +0000 (18:24 -0700)]
xfs: xfs_finobt_count_blocks() walks the wrong btree

Source kernel commit: 95179935beadccaf0f0bb461adb778731e293da4

As a result of the factoring in commit 14dd46cf31f4 ("xfs: split
xfs_inobt_init_cursor"), mount started taking a long time on a
user's filesystem.  For Anders, this made mount times regress from
under a second to over 15 minutes for a filesystem with only 30
million inodes in it.

Anders bisected it down to the above commit, but even then the bug
was not obvious. In this commit, over 20 calls to
xfs_inobt_init_cursor() were modified, and some we modified to call
a new function named xfs_finobt_init_cursor().

If that takes you a moment to reread those function names to see
what the rename was, then you have realised why this bug wasn't
spotted during review. And it wasn't spotted on inspection even
after the bisect pointed at this commit - a single missing "f" isn't
the easiest thing for a human eye to notice....

The result is that xfs_finobt_count_blocks() now incorrectly calls
xfs_inobt_init_cursor() so it is now walking the inobt instead of
the finobt. Hence when there are lots of allocated inodes in a
filesystem, mount takes a -long- time run because it now walks a
massive allocated inode btrees instead of the small, nearly empty
free inode btrees. It also means all the finobt space reservations
are wrong, so mount could potentially given ENOSPC on kernel
upgrade.

In hindsight, commit 14dd46cf31f4 should have been two commits - the
first to convert the finobt callers to the new API, the second to
modify the xfs_inobt_init_cursor() API for the inobt callers. That
would have made the bug very obvious during review.

Fixes: 14dd46cf31f4 ("xfs: split xfs_inobt_init_cursor")
Reported-by: Anders Blomdell <anders.blomdell@gmail.com>
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: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: fix di_onlink checking for V1/V2 inodes
Darrick J. Wong [Wed, 2 Oct 2024 01:24:13 +0000 (18:24 -0700)]
xfs: fix di_onlink checking for V1/V2 inodes

Source kernel commit: e21fea4ac3cf12eba1921fbbf7764bf69c6d4b2c

"KjellR" complained on IRC that an old V4 filesystem suddenly stopped
mounting after upgrading from 6.9.11 to 6.10.3, with the following splat
when trying to read the rt bitmap inode:

00000000: 49 4e 80 00 01 02 00 01 00 00 00 00 00 00 00 00  IN..............
00000010: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000020: 00 00 00 00 00 00 00 00 43 d2 a9 da 21 0f d6 30  ........C...!..0
00000030: 43 d2 a9 da 21 0f d6 30 00 00 00 00 00 00 00 00  C...!..0........
00000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000050: 00 00 00 02 00 00 00 00 00 00 00 04 00 00 00 00  ................
00000060: ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

As Dave Chinner points out, this is a V1 inode with both di_onlink and
di_nlink set to 1 and di_flushiter == 0.  In other words, this inode was
formatted this way by mkfs and hasn't been touched since then.

Back in the old days of xfsprogs 3.2.3, I observed that libxfs_ialloc
would set di_nlink, but if the filesystem didn't have NLINK, it would
then set di_version = 1.  libxfs_iflush_int later sees the V1 inode and
copies the value of di_nlink to di_onlink without zeroing di_onlink.

Eventually this filesystem must have been upgraded to support NLINK
because 6.10 doesn't support !NLINK filesystems, which is how we tripped
over this old behavior.  The filesystem doesn't have a realtime section,
so that's why the rtbitmap inode has never been touched.

Fix this by removing the di_onlink/di_nlink checking for all V1/V2
inodes because this is a muddy mess.  The V3 inode handling code has
always supported NLINK and written di_onlink==0 so keep that check.
The removal of the V1 inode handling code when we dropped support for
!NLINK obscured this old behavior.

Reported-by: kjell.m.randa@gmail.com
Fixes: 40cb8613d612 ("xfs: check unused nlink fields in the ondisk inode")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: remove unused parameter in macro XFS_DQUOT_LOGRES
Julian Sun [Wed, 2 Oct 2024 01:23:58 +0000 (18:23 -0700)]
xfs: remove unused parameter in macro XFS_DQUOT_LOGRES

Source kernel commit: af5d92f2fad818663da2ce073b6fe15b9d56ffdc

In the macro definition of XFS_DQUOT_LOGRES, a parameter is accepted,
but it is not used. Hence, it should be removed.

This patch has only passed compilation test, but it should be fine.

Signed-off-by: Julian Sun <sunjunchao2870@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: get rid of xfs_ag_resv_rmapbt_alloc
Long Li [Wed, 2 Oct 2024 01:23:42 +0000 (18:23 -0700)]
xfs: get rid of xfs_ag_resv_rmapbt_alloc

Source kernel commit: 49cdc4e834e46d7c11a91d7adcfa04f56d19efaf

The pag in xfs_ag_resv_rmapbt_alloc() is already held when the struct
xfs_btree_cur is initialized in xfs_rmapbt_init_cursor(), so there is no
need to get pag again.

On the other hand, in xfs_rmapbt_free_block(), the similar function
xfs_ag_resv_rmapbt_free() was removed in commit 92a005448f6f ("xfs: get
rid of unnecessary xfs_perag_{get,put} pairs"), xfs_ag_resv_rmapbt_alloc()
was left because scrub used it, but now scrub has removed it. Therefore,
we could get rid of xfs_ag_resv_rmapbt_alloc() just like the rmap free
block, make the code cleaner.

Signed-off-by: Long Li <leo.lilong@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: background AIL push should target physical space
Dave Chinner [Wed, 2 Oct 2024 01:23:26 +0000 (18:23 -0700)]
xfs: background AIL push should target physical space

Source kernel commit: b50b4c49d8d79af05ac3bb3587f58589713139cc

Currently the AIL attempts to keep 25% of the "log space" free,
where the current used space is tracked by the reserve grant head.
That is, it tracks both physical space used plus the amount reserved
by transactions in progress.

When we start tail pushing, we are trying to make space for new
reservations by writing back older metadata and the log is generally
physically full of dirty metadata, and reservations for modifications
in flight take up whatever space the AIL can physically free up.

Hence we don't really need to take into account the reservation
space that has been used - we just need to keep the log tail moving
as fast as we can to free up space for more reservations to be made.
We know exactly how much physical space the journal is consuming in
the AIL (i.e. max LSN - min LSN) so we can base push thresholds
directly on this state rather than have to look at grant head
reservations to determine how much to physically push out of the
log.

This also allows code that needs to know if log items in the current
transaction need to be pushed or re-logged to simply sample the
current target - they don't need to calculate the current target
themselves. This avoids the need for any locking when doing such
checks.

Further, moving to a physical target means we don't need "push all
until empty semantics" like were introduced in the previous patch.
We can now test and clear the "push all" as a one-shot command to
set the target to the current head of the AIL. This allows the
xfsaild to maximise the use of log space right up to the point where
conditions indicate that the xfsaild is not keeping up with load and
it needs to work harder, and as soon as those constraints go away
(i.e. external code no longer needs everything pushed) the xfsaild
will return to maintaining the normal 25% free space thresholds.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: AIL doesn't need manual pushing
Dave Chinner [Wed, 2 Oct 2024 01:23:11 +0000 (18:23 -0700)]
xfs: AIL doesn't need manual pushing

Source kernel commit: 9adf40249e6cfd7231c2973bb305f6c20902bfd9

We have a mechanism that checks the amount of log space remaining
available every time we make a transaction reservation. If the
amount of space is below a threshold (25% free) we push on the AIL
to tell it to do more work. To do this, we end up calculating the
LSN that the AIL needs to push to on every reservation and updating
the push target for the AIL with that new target LSN.

This is silly and expensive. The AIL is perfectly capable of
calculating the push target itself, and it will always be running
when the AIL contains objects.

What the target does is determine if the AIL needs to do
any work before it goes back to sleep. If we haven't run out of
reservation space or memory (or some other push all trigger), it
will simply go back to sleep for a while if there is more than 25%
of the journal space free without doing anything.

If there are items in the AIL at a lower LSN than the target, it
will try to push up to the target or to the point of getting stuck
before going back to sleep and trying again soon after.`

Hence we can modify the AIL to calculate it's own 25% push target
before it starts a push using the same reserve grant head based
calculation as is currently used, and remove all the places where we
ask the AIL to push to a new 25% free target. We can also drop the
minimum free space size of 256BBs from the calculation because the
25% of a minimum sized log is *always going to be larger than
256BBs.

This does still require a manual push in certain circumstances.
These circumstances arise when the AIL is not full, but the
reservation grants consume the entire of the free space in the log.
In this case, we still need to push on the AIL to free up space, so
when we hit this condition (i.e. reservation going to sleep to wait
on log space) we do a single push to tell the AIL it should empty
itself. This will keep the AIL moving as new reservations come in
and want more space, rather than keep queuing them and having to
push the AIL repeatedly.

The reason for using the "push all" when grant space runs out is
that we can run out of grant space when there is more than 25% of
the log free. Small logs are notorious for this, and we have a hack
in the log callback code (xlog_state_set_callback()) where we push
the AIL because the *head* moved) to ensure that we kick the AIL
when we consume space in it because that can push us over the "less
than 25% available" available that starts tail pushing back up
again.

Hence when we run out of grant space and are going to sleep, we have
to consider that the grant space may be consuming almost all the log
space and there is almost nothing in the AIL. In this situation, the
AIL pins the tail and moving the tail forwards is the only way the
grant space will come available, so we have to force the AIL to push
everything to guarantee grant space will eventually be returned.
Hence triggering a "push all" just before sleeping removes all the
nasty corner cases we have in other parts of the code that work
around the "we didn't ask the AIL to push enough to free grant
space" condition that leads to log space hangs...

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: Avoid races with cnt_btree lastrec updates
Zizhi Wo [Wed, 2 Oct 2024 01:22:55 +0000 (18:22 -0700)]
xfs: Avoid races with cnt_btree lastrec updates

Source kernel commit: 94a0333b9212a114d19096a77903f76d0d5bca26

A concurrent file creation and little writing could unexpectedly return
-ENOSPC error since there is a race window that the allocator could get
the wrong agf->agf_longest.

Write file process steps:
1) Find the entry that best meets the conditions, then calculate the start
address and length of the remaining part of the entry after allocation.
2) Delete this entry and update the -current- agf->agf_longest.
3) Insert the remaining unused parts of this entry based on the
calculations in 1), and update the agf->agf_longest again if necessary.

Create file process steps:
1) Check whether there are free inodes in the inode chunk.
2) If there is no free inode, check whether there has space for creating
inode chunks, perform the no-lock judgment first.
3) If the judgment succeeds, the judgment is performed again with agf lock
held. Otherwire, an error is returned directly.

If the write process is in step 2) but not go to 3) yet, the create file
process goes to 2) at this time, it may be mistaken for no space,
resulting in the file system still has space but the file creation fails.

We have sent two different commits to the community in order to fix this
problem[1][2]. Unfortunately, both solutions have flaws. In [2], I
discussed with Dave and Darrick, realized that a better solution to this
problem requires the "last cnt record tracking" to be ripped out of the
generic btree code. And surprisingly, Dave directly provided his fix code.
This patch includes appropriate modifications based on his tmp-code to
address this issue.

The entire fix can be roughly divided into two parts:
1) Delete the code related to lastrec-update in the generic btree code.
2) Place the process of updating longest freespace with cntbt separately
to the end of the cntbt modifications. Move the cursor to the rightmost
firstly, and update the longest free extent based on the record.

Note that we can not update the longest with xfs_alloc_get_rec() after
find the longest record, as xfs_verify_agbno() may not pass because
pag->block_count is updated on the outside. Therefore, use
xfs_btree_get_rec() as a replacement.

[1] https://lore.kernel.org/all/20240419061848.1032366-2-yebin10@huawei.com
[2] https://lore.kernel.org/all/20240604071121.3981686-1-wozizhi@huawei.com

Reported by: Ye Bin <yebin10@huawei.com>

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
9 months agoxfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c
Darrick J. Wong [Wed, 2 Oct 2024 01:22:40 +0000 (18:22 -0700)]
xfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c

Source kernel commit: 783e8a7c9cab6744ebc5dfe75081248ac39181b2

Move the code that adds the incore xfs_refcount_update_item deferred
work data to a transaction live with the CUI log item code.  This means
that the refcount code no longer has to know about the inner workings of
the CUI log items.

As a consequence, we can get rid of the _{get,put}_group helpers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: simplify usage of the rcur local variable in xfs_refcount_finish_one
Darrick J. Wong [Wed, 2 Oct 2024 01:22:24 +0000 (18:22 -0700)]
xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one

Source kernel commit: e51987a12cb57ca3702bff5df8a615037b2c8f8a

Only update rcur when we know the final *pcur value.

Inspired-by: Christoph Hellwig <hch@lst.de>
[djwong: don't leave the caller with a dangling ref]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one
Darrick J. Wong [Wed, 2 Oct 2024 01:22:08 +0000 (18:22 -0700)]
xfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one

Source kernel commit: bac3f784925299b5e69a857e7e03e59c88aa14be

In xfs_refcount_finish_one we know the cursor is non-zero when calling
xfs_refcount_finish_one_cleanup and we pass a 0 error variable.  This
means xfs_refcount_finish_one_cleanup is just doing a
xfs_btree_del_cursor.

Open code that and move xfs_refcount_finish_one_cleanup to
fs/xfs/xfs_refcount_item.c.

Inspired-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: reuse xfs_refcount_update_cancel_item
Darrick J. Wong [Wed, 2 Oct 2024 01:21:53 +0000 (18:21 -0700)]
xfs: reuse xfs_refcount_update_cancel_item

Source kernel commit: 8aef79928b3ddd8c10a3235f982933addc15a977

Reuse xfs_refcount_update_cancel_item to put the AG/RTG and free the
item in a few places that currently open code the logic.

Inspired-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: add a ci_entry helper
Darrick J. Wong [Wed, 2 Oct 2024 01:21:37 +0000 (18:21 -0700)]
xfs: add a ci_entry helper

Source kernel commit: 0e9254861f980bd60a58b7c2b57ba0414c038409

Add a helper to translate from the item list head to the
refcount_intent_item structure and use it so shorten assignments and
avoid the need for extra local variables.

Inspired-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: clean up refcount log intent item tracepoint callsites
Darrick J. Wong [Wed, 2 Oct 2024 01:21:22 +0000 (18:21 -0700)]
xfs: clean up refcount log intent item tracepoint callsites

Source kernel commit: 886f11c797722650d98c554b28e66f12317a33e4

Pass the incore refcount intent structure to the tracepoints instead of
open-coding the argument passing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: pass btree cursors to refcount btree tracepoints
Darrick J. Wong [Wed, 2 Oct 2024 01:21:06 +0000 (18:21 -0700)]
xfs: pass btree cursors to refcount btree tracepoints

Source kernel commit: 8fbac2f1a0947dc45ecf13e9b5aa17b5942b4a2d

Prepare the rest of refcount btree tracepoints for use with realtime
reflink by making them take the btree cursor object as a parameter.
This will save us a lot of trouble later on.

Remove the xfs_refcount_recover_extent tracepoint since it's already
covered by other refcount tracepoints.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create specialized classes for refcount tracepoints
Darrick J. Wong [Wed, 2 Oct 2024 01:20:50 +0000 (18:20 -0700)]
xfs: create specialized classes for refcount tracepoints

Source kernel commit: bb0efb0d0a2885b4c65ca31e2815da2281b99153

The only user of the "ag" tracepoint event classes is the refcount
btree, so rename them to make that obvious and make them take the btree
cursor to simplify the arguments.  This will save us a lot of trouble
later on.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: give refcount btree cursor error tracepoints their own class
Darrick J. Wong [Wed, 2 Oct 2024 01:20:35 +0000 (18:20 -0700)]
xfs: give refcount btree cursor error tracepoints their own class

Source kernel commit: 7cf2663ff1cfb20f5fe025122016b68920b28041

Convert all the refcount tracepoints to use the btree error tracepoint
class.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c
Darrick J. Wong [Wed, 2 Oct 2024 01:20:19 +0000 (18:20 -0700)]
xfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c

Source kernel commit: ea7b0820d960d5a3ee72bc67cbd8b5d47c67aa4c

Move the code that adds the incore xfs_rmap_update_item deferred work
data to a transaction to live with the RUI log item code.  This means
that the rmap code no longer has to know about the inner workings of the
RUI log items.

As a consequence, we can get rid of the _{get,put}_group helpers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: simplify usage of the rcur local variable in xfs_rmap_finish_one
Christoph Hellwig [Wed, 2 Oct 2024 01:20:04 +0000 (18:20 -0700)]
xfs: simplify usage of the rcur local variable in xfs_rmap_finish_one

Source kernel commit: 905af72610d90f58f994feff4ead1fc258f5d2b1

Only update rcur when we know the final *pcur value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
[djwong: don't leave the caller with a dangling ref]
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: don't bother calling xfs_rmap_finish_one_cleanup in xfs_rmap_finish_one
Darrick J. Wong [Wed, 2 Oct 2024 01:19:48 +0000 (18:19 -0700)]
xfs: don't bother calling xfs_rmap_finish_one_cleanup in xfs_rmap_finish_one

Source kernel commit: 8363b4361997044ecb99880a1a9bfdebf9145eed

In xfs_rmap_finish_one we known the cursor is non-zero when calling
xfs_rmap_finish_one_cleanup and we pass a 0 error variable.  This means
xfs_rmap_finish_one_cleanup is just doing a xfs_btree_del_cursor.

Open code that and move xfs_rmap_finish_one_cleanup to
fs/xfs/xfs_rmap_item.c.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: minor porting changes]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: reuse xfs_rmap_update_cancel_item
Christoph Hellwig [Wed, 2 Oct 2024 01:19:32 +0000 (18:19 -0700)]
xfs: reuse xfs_rmap_update_cancel_item

Source kernel commit: 37f9d1db03ba0511403c5d25ba0baaddf5208ba7

Reuse xfs_rmap_update_cancel_item to put the AG/RTG and free the item in
a few places that currently open code the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: add a ri_entry helper
Christoph Hellwig [Wed, 2 Oct 2024 01:19:17 +0000 (18:19 -0700)]
xfs: add a ri_entry helper

Source kernel commit: f93963779b438a33ca4b13384c070a6864ce2b2b

Add a helper to translate from the item list head to the
rmap_intent_item structure and use it so shorten assignments
and avoid the need for extra local variables.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: clean up rmap log intent item tracepoint callsites
Darrick J. Wong [Wed, 2 Oct 2024 01:19:01 +0000 (18:19 -0700)]
xfs: clean up rmap log intent item tracepoint callsites

Source kernel commit: fbe8c7e167a6b226ae0234c26ebb65d8401473a5

Pass the incore rmap structure to the tracepoints instead of open-coding
the argument passing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: pass btree cursors to rmap btree tracepoints
Darrick J. Wong [Wed, 2 Oct 2024 01:18:46 +0000 (18:18 -0700)]
xfs: pass btree cursors to rmap btree tracepoints

Source kernel commit: 47492ed124219b37acf65cd931c1e45d5bc0c274

Prepare the rmap btree tracepoints for use with realtime rmap btrees by
making them take the btree cursor object as a parameter.  This will save
us a lot of trouble later on.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: give rmap btree cursor error tracepoints their own class
Darrick J. Wong [Wed, 2 Oct 2024 01:18:30 +0000 (18:18 -0700)]
xfs: give rmap btree cursor error tracepoints their own class

Source kernel commit: 71f5a17e526775f001f643c9d54e5b59fa29d7ac

Create a new tracepoint class for btree-related errors, then convert all
the rmap tracepoints to use it.  Also fix the one tracepoint that was
abusing the old class by making it a separate tracepoint.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: move xfs_extent_free_defer_add to xfs_extfree_item.c
Darrick J. Wong [Wed, 2 Oct 2024 01:18:14 +0000 (18:18 -0700)]
xfs: move xfs_extent_free_defer_add to xfs_extfree_item.c

Source kernel commit: 84a3c1576c5aade32170fae6c61d51bd2d16010f

Move the code that adds the incore xfs_extent_free_item deferred work
data to a transaction to live with the EFI log item code.  This means
that the allocator code no longer has to know about the inner workings
of the EFI log items.

As a consequence, we can get rid of the _{get,put}_group helpers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: remove xfs_defer_agfl_block
Christoph Hellwig [Wed, 2 Oct 2024 01:17:59 +0000 (18:17 -0700)]
xfs: remove xfs_defer_agfl_block

Source kernel commit: 7272f77c67c0710918e5678266f8dad6e3bfc8d2

xfs_free_extent_later can handle the extra AGFL special casing with
very little extra logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: remove duplicate asserts in xfs_defer_extent_free
Christoph Hellwig [Wed, 2 Oct 2024 01:17:43 +0000 (18:17 -0700)]
xfs: remove duplicate asserts in xfs_defer_extent_free

Source kernel commit: 851a6781895a0f6e0ba75168dc7aecc132d13e6a

The bno/len verification is already done by the calls to
xfs_verify_rtbext / xfs_verify_fsbext, and reporting a corruption error
seem like the better handling than tripping an assert anyway.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: reuse xfs_extent_free_cancel_item
Christoph Hellwig [Wed, 2 Oct 2024 01:17:28 +0000 (18:17 -0700)]
xfs: reuse xfs_extent_free_cancel_item

Source kernel commit: 61665fae4e4302f2a48de56749640a9f1a4c2ec5

Reuse xfs_extent_free_cancel_item to put the AG/RTG and free the item in
a few places that currently open code the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: add a xefi_entry helper
Christoph Hellwig [Wed, 2 Oct 2024 01:17:12 +0000 (18:17 -0700)]
xfs: add a xefi_entry helper

Source kernel commit: 649c0c2b86ee944a1a9962b310b1b97ead12e97a

Add a helper to translate from the item list head to the
xfs_extent_free_item structure and use it so shorten assignments
and avoid the need for extra local variables.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: pass the fsbno to xfs_perag_intent_get
Christoph Hellwig [Wed, 2 Oct 2024 01:16:56 +0000 (18:16 -0700)]
xfs: pass the fsbno to xfs_perag_intent_get

Source kernel commit: 62d597a197e390a89eadff60b98231e91b32ab83

All callers of xfs_perag_intent_get have a fsbno and need boilerplate
code to turn that into an agno.  Just pass the fsbno to
xfs_perag_intent_get and look up the agno there.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: convert "skip_discard" to a proper flags bitset
Darrick J. Wong [Wed, 2 Oct 2024 01:16:41 +0000 (18:16 -0700)]
xfs: convert "skip_discard" to a proper flags bitset

Source kernel commit: 980faece91a60c279e7c24cb1d1a378bbbb74bb9

Convert the boolean to skip discard on free into a proper flags field so
that we can add more flags in the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: clean up extent free log intent item tracepoint callsites
Darrick J. Wong [Wed, 2 Oct 2024 01:16:25 +0000 (18:16 -0700)]
xfs: clean up extent free log intent item tracepoint callsites

Source kernel commit: 4e0e2c0fe35b44cd4db6a138ed4316178ed60b5c

Pass the incore EFI structure to the tracepoints instead of open-coding
the argument passing.  This cleans up the call sites a bit.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
Darrick J. Wong [Wed, 2 Oct 2024 01:16:10 +0000 (18:16 -0700)]
xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb

Source kernel commit: ac3a0275165b4f80d9b7b516d6a8f8b308644fff

Currently, the XFS_SB_CRC_OFF macro uses the incore superblock struct
(xfs_sb) to compute the address of sb_crc within the ondisk superblock
struct (xfs_dsb).  This is a landmine if we ever change the layout of
the incore superblock (as we're about to do), so redefine the macro
to use xfs_dsb to compute the layout of xfs_dsb.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: move dirent update hooks to xfs_dir2.c
Darrick J. Wong [Wed, 2 Oct 2024 01:15:54 +0000 (18:15 -0700)]
xfs: move dirent update hooks to xfs_dir2.c

Source kernel commit: 62bbf50bea21b1c76990fd1bae58a65660a11c27

Move the directory entry update hook code to xfs_dir2 so that it is
mostly consolidated with the higher level directory functions.  Retain
the exports so that online fsck can still send notifications through the
hooks.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create libxfs helper to rename two directory entries
Darrick J. Wong [Wed, 2 Oct 2024 01:15:38 +0000 (18:15 -0700)]
xfs: create libxfs helper to rename two directory entries

Source kernel commit: 28d0d813444645689fefa232bcf88e86a5a3a746

Create a new libxfs function to rename two directory entries.  The
upcoming metadata directory feature will need this to replace a metadata
inode directory entry.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create libxfs helper to exchange two directory entries
Darrick J. Wong [Wed, 2 Oct 2024 01:15:23 +0000 (18:15 -0700)]
xfs: create libxfs helper to exchange two directory entries

Source kernel commit: a55712b35c065eee4ab1195233a5478fb7c93efa

Create a new libxfs function to exchange two directory entries.
The upcoming metadata directory feature will need this to replace a
metadata inode directory entry.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create libxfs helper to remove an existing inode/name from a directory
Darrick J. Wong [Wed, 2 Oct 2024 01:15:07 +0000 (18:15 -0700)]
xfs: create libxfs helper to remove an existing inode/name from a directory

Source kernel commit: 90636e4531a8bfb5ef37d38a76eb97e5f5793deb

Create a new libxfs function to remove a (name, inode) entry from a
directory.  The upcoming metadata directory feature will need this to
create a metadata directory tree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: hoist inode free function to libxfs
Darrick J. Wong [Wed, 2 Oct 2024 01:14:52 +0000 (18:14 -0700)]
xfs: hoist inode free function to libxfs

Source kernel commit: 1964435d19d947b8626379d09db3e33b9669f333

Create a libxfs helper function that marks an inode free on disk.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create libxfs helper to link an existing inode into a directory
Darrick J. Wong [Wed, 2 Oct 2024 01:14:36 +0000 (18:14 -0700)]
xfs: create libxfs helper to link an existing inode into a directory

Source kernel commit: c1f0bad4232fd309b2fe849153fcf473e775b1f7

Create a new libxfs function to link an existing inode into a directory.
The upcoming metadata directory feature will need this to create a
metadata directory tree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: create libxfs helper to link a new inode into a directory
Darrick J. Wong [Wed, 2 Oct 2024 01:14:20 +0000 (18:14 -0700)]
xfs: create libxfs helper to link a new inode into a directory

Source kernel commit: 1fa2e81957cf11620867729fb613b121692ee0d3

Create a new libxfs function to link a newly created inode into a
directory.  The upcoming metadata directory feature will need this to
create a metadata directory tree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: separate the icreate logic around INIT_XATTRS
Darrick J. Wong [Wed, 2 Oct 2024 01:14:05 +0000 (18:14 -0700)]
xfs: separate the icreate logic around INIT_XATTRS

Source kernel commit: b11b11e3b7a72606cfef527255a9467537bcaaa5

INIT_XATTRS is overloaded here -- it's set during the creat process when
we think that we're immediately going to set some ACL xattrs to save
time.  However, it's also used by the parent pointers code to enable the
attr fork in preparation to receive ppptr xattrs.  This results in
xfs_has_parent() branches scattered around the codebase to turn on
INIT_XATTRS.

Linkable files are created far more commonly than unlinkable temporary
files or directory tree roots, so we should centralize this logic in
xfs_inode_init.  For the three callers that don't want parent pointers
(online repiar tempfiles, unlinkable tempfiles, rootdir creation) we
provide an UNLINKABLE flag to skip attr fork initialization.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: hoist xfs_{bump,drop}link to libxfs
Darrick J. Wong [Wed, 2 Oct 2024 01:13:49 +0000 (18:13 -0700)]
xfs: hoist xfs_{bump,drop}link to libxfs

Source kernel commit: a9e583d34facc64b6edf3c9afb2ff4891038176d

Move xfs_bumplink and xfs_droplink to libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: hoist xfs_iunlink to libxfs
Darrick J. Wong [Wed, 2 Oct 2024 01:13:34 +0000 (18:13 -0700)]
xfs: hoist xfs_iunlink to libxfs

Source kernel commit: b8a6107921ca799330ff3efdd154b7fa0ff54582

Move xfs_iunlink and xfs_iunlink_remove to libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: hoist new inode initialization functions to libxfs
Darrick J. Wong [Wed, 2 Oct 2024 01:13:18 +0000 (18:13 -0700)]
xfs: hoist new inode initialization functions to libxfs

Source kernel commit: e9d2b35bb9d3ff372fad27998fc3969ced3f563d

Move all the code that initializes a new inode's attributes from the
icreate_args structure and the parent directory into libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: implement get_random_u32
Darrick J. Wong [Wed, 2 Oct 2024 01:13:02 +0000 (18:13 -0700)]
libxfs: implement get_random_u32

Actually query the kernel for some random bytes instead of returning
zero, if that's possible.  The most noticeable effect of this is that
mkfs will now create the rtbitmap file, the rtsummary file, and children
of the root directory with a nonzero generation.  Apparently xfsdump
requires that the root directory have a generation number of zero.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: remove libxfs_dir_ialloc
Darrick J. Wong [Wed, 2 Oct 2024 01:12:47 +0000 (18:12 -0700)]
libxfs: remove libxfs_dir_ialloc

This function no longer exists in the kernel, and it's not really needed
in userspace either.  There are two users of it: repair and mkfs.
xfs_repair and xfs_db do not have useful cred and fsxattr structures so
they can call libxfs_dialloc and libxfs_icreate directly.  For mkfs
we'll move the guts of libxfs_dir_ialloc into proto.c as a creatproto
function that handles setting user/group ids, and move struct cred to
mkfs since it's now the only user.

This gets us ready to hoist the rest of the inode initialization code to
libxfs for metadata directories.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: backport inode init code from the kernel
Darrick J. Wong [Wed, 2 Oct 2024 01:12:31 +0000 (18:12 -0700)]
libxfs: backport inode init code from the kernel

Reorganize the userspace inode initialization code to more closely
resemble its kernel counterpart.  This is preparation to hoist the
initialization routines to libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: split new inode creation into two pieces
Darrick J. Wong [Wed, 2 Oct 2024 01:12:16 +0000 (18:12 -0700)]
libxfs: split new inode creation into two pieces

Source kernel commit: 38fd3d6a956f1b104f11cd6eee116c54bfe458c4

There are two parts to initializing a newly allocated inode: setting up
the incore structures, and initializing the new inode core based on the
parent inode and the current user's environment.  The initialization
code is not specific to the kernel, so we would like to share that with
userspace by hoisting it to libxfs.  Therefore, split xfs_icreate into
separate functions to prepare for the next few patches.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: split new inode creation into two pieces
Darrick J. Wong [Wed, 2 Oct 2024 01:12:00 +0000 (18:12 -0700)]
xfs: split new inode creation into two pieces

Source kernel commit: 38fd3d6a956f1b104f11cd6eee116c54bfe458c4

There are two parts to initializing a newly allocated inode: setting up
the incore structures, and initializing the new inode core based on the
parent inode and the current user's environment.  The initialization
code is not specific to the kernel, so we would like to share that with
userspace by hoisting it to libxfs.  Therefore, split xfs_icreate into
separate functions to prepare for the next few patches.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: pass flags2 from parent to child when creating files
Darrick J. Wong [Wed, 2 Oct 2024 01:11:44 +0000 (18:11 -0700)]
libxfs: pass flags2 from parent to child when creating files

When mkfs creates a new file as a child of an existing directory, we
should propagate the flags2 field from parent to child like the kernel
does.  This ensures that mkfs propagates cowextsize hints properly when
protofiles are in use.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: when creating a file in a directory, set the project id based on the parent
Darrick J. Wong [Wed, 2 Oct 2024 01:11:29 +0000 (18:11 -0700)]
libxfs: when creating a file in a directory, set the project id based on the parent

When we're creating a file as a child of an existing directory, use
xfs_get_initial_prid to have the child inherit the project id of the
directory if the directory has PROJINHERIT set, just like the kernel
does.  This fixes mkfs project id propagation with -d projinherit=X when
protofiles are in use.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: set access time when creating files
Darrick J. Wong [Wed, 2 Oct 2024 01:11:13 +0000 (18:11 -0700)]
libxfs: set access time when creating files

Set the access time on files that we're creating, to match the behavior
of the kernel.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: rearrange libxfs_trans_ichgtime call when creating inodes
Darrick J. Wong [Wed, 2 Oct 2024 01:10:58 +0000 (18:10 -0700)]
libxfs: rearrange libxfs_trans_ichgtime call when creating inodes

Rearrange the libxfs_trans_ichgtime call in libxfs_ialloc so that we
call it once with the flags we want.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agoxfs: implement atime updates in xfs_trans_ichgtime
Darrick J. Wong [Wed, 2 Oct 2024 01:10:42 +0000 (18:10 -0700)]
xfs: implement atime updates in xfs_trans_ichgtime

Source kernel commit: 3d1dfb6df9b7b9ffc95499b9ddd92d949e5a60d2

Enable xfs_trans_ichgtime to change the inode access time so that we can
use this function to set inode times when allocating inodes instead of
open-coding it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: pack icreate initialization parameters into a separate structure
Darrick J. Wong [Wed, 2 Oct 2024 01:10:26 +0000 (18:10 -0700)]
libxfs: pack icreate initialization parameters into a separate structure

Source kernel commit: ba4b39fe4c011078469dcd28f51447d75852d21c

Callers that want to create an inode currently pass all possible file
attribute values for the new inode into xfs_init_new_inode as ten
separate parameters.  This causes two code maintenance issues: first, we
have large multi-line call sites which programmers must read carefully
to make sure they did not accidentally invert a value.  Second, all
three file id parameters must be passed separately to the quota
functions; any discrepancy results in quota count errors.

Clean this up by creating a new icreate_args structure to hold all this
information, some helpers to initialize them properly, and make the
callers pass this structure through to the creation function, whose name
we shorten to xfs_icreate.  This eliminates the issues, enables us to
keep the inode init code in sync with userspace via libxfs, and is
needed for future metadata directory tree management.

(A subsequent cleanup will also fix the quota alloc calls.)

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
9 months agoxfs: pack icreate initialization parameters into a separate structure
Darrick J. Wong [Wed, 2 Oct 2024 01:10:11 +0000 (18:10 -0700)]
xfs: pack icreate initialization parameters into a separate structure

Source kernel commit: ba4b39fe4c011078469dcd28f51447d75852d21c

Callers that want to create an inode currently pass all possible file
attribute values for the new inode into xfs_init_new_inode as ten
separate parameters.  This causes two code maintenance issues: first, we
have large multi-line call sites which programmers must read carefully
to make sure they did not accidentally invert a value.  Second, all
three file id parameters must be passed separately to the quota
functions; any discrepancy results in quota count errors.

Clean this up by creating a new icreate_args structure to hold all this
information, some helpers to initialize them properly, and make the
callers pass this structure through to the creation function, whose name
we shorten to xfs_icreate.  This eliminates the issues, enables us to
keep the inode init code in sync with userspace via libxfs, and is
needed for future metadata directory tree management.

(A subsequent cleanup will also fix the quota alloc calls.)

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
9 months agolibxfs: pass IGET flags through to xfs_iread
Darrick J. Wong [Wed, 2 Oct 2024 01:09:55 +0000 (18:09 -0700)]
libxfs: pass IGET flags through to xfs_iread

Change the lock_flags parameter to iget_flags so that we can supply
XFS_IGET_ flags in future patches.  All callers of libxfs_iget and
libxfs_trans_iget pass zero for this parameter and there are no inode
locks in xfsprogs, so there's no behavior change here.

Port the kernel's version of the xfs_inode_from_disk callsite.

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