* [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4
@ 2024-10-21 21:56 Darrick J. Wong
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
2024-10-22 5:59 ` [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Christoph Hellwig
0 siblings, 2 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:56 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: xfs
Hi Andrey,
Here's the libxfs sync to catch xfsprogs up to 6.12-rc4. I have a bunch
of tool changes as well, but I'll hold off on sending those until dave &
hch have a chance to look at last week's kernel patchbomb.
The only unreviewed patches are these:
[PATCHSET] libxfs: new code for 6.12
[PATCH 01/37] libxfs: require -std=gnu11 for compilation by default
[PATCH 03/37] libxfs: port IS_ENABLED from the kernel
The first patch brings our C usage in line with the kernel; and the
second one is needed for a bug fix that got merged between rc2 and 3.
--D
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHSET] libxfs: new code for 6.12
2024-10-21 21:56 [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Darrick J. Wong
@ 2024-10-21 21:58 ` Darrick J. Wong
2024-10-21 21:59 ` [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default Darrick J. Wong
` (36 more replies)
2024-10-22 5:59 ` [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Christoph Hellwig
1 sibling, 37 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:58 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
Hi all,
New code for 6.12.
If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.
Comments and questions are, as always, welcome.
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-sync-6.12
---
Commits in this patchset:
* libxfs: require -std=gnu11 for compilation by default
* libxfs: compile with a C++ compiler
* libxfs: port IS_ENABLED from the kernel
* libfrog: add xarray emulation
* xfs: introduce new file range commit ioctls
* xfs: pass the icreate args object to xfs_dialloc
* xfs: remove xfs_validate_rtextents
* xfs: factor out a xfs_validate_rt_geometry helper
* xfs: remove the limit argument to xfs_rtfind_back
* xfs: assert a valid limit in xfs_rtfind_forw
* xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf
* xfs: factor out rtbitmap/summary initialization helpers
* xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock
* xfs: ensure rtx mask/shift are correct after growfs
* xfs: remove xfs_rtb_to_rtxrem
* xfs: simplify xfs_rtalloc_query_range
* xfs: clean up the ISVALID macro in xfs_bmap_adjacent
* xfs: remove xfs_{rtbitmap,rtsummary}_wordcount
* xfs: replace m_rsumsize with m_rsumblocks
* xfs: fix a sloppy memory handling bug in xfs_iroot_realloc
* xfs: replace shouty XFS_BM{BT,DR} macros
* xfs: standardize the btree maxrecs function parameters
* xfs: use kvmalloc for xattr buffers
* xfs: remove unnecessary check
* xfs: use kfree_rcu_mightsleep to free the perag structures
* xfs: move the tagged perag lookup helpers to xfs_icache.c
* xfs: convert perag lookup to xarray
* xfs: ensure st_blocks never goes to zero during COW writes
* xfs: enable block size larger than page size support
* xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname
* xfs: return bool from xfs_attr3_leaf_add
* xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split
* xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname
* xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate
* xfs: don't ifdef around the exact minlen allocations
* xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc
* xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc
---
configure.ac | 13 ++
db/bmap.c | 10 +-
db/bmap_inflate.c | 2
db/bmroot.c | 8 +
db/btheight.c | 18 +--
db/check.c | 11 +-
db/frag.c | 8 +
db/iunlink.c | 2
db/metadump.c | 16 +--
include/builddefs.in | 8 +
include/kmem.h | 11 ++
include/libxfs.h | 6 +
include/platform_defs.h | 63 ++++++++++
include/xfs_mount.h | 4 -
libfrog/radix-tree.h | 35 +++++
libxfs/Makefile | 31 +++++
libxfs/defer_item.c | 14 ++
libxfs/init.c | 11 +-
libxfs/ioctl_c_dummy.c | 11 ++
libxfs/ioctl_cxx_dummy.cpp | 13 ++
libxfs/libxfs_priv.h | 6 +
libxfs/xfs_ag.c | 94 +--------------
libxfs/xfs_ag.h | 14 --
libxfs/xfs_alloc.c | 7 -
libxfs/xfs_alloc.h | 4 -
libxfs/xfs_alloc_btree.c | 6 -
libxfs/xfs_alloc_btree.h | 3
libxfs/xfs_attr.c | 190 +++++++++++++-----------------
libxfs/xfs_attr_leaf.c | 63 +++++-----
libxfs/xfs_attr_leaf.h | 2
libxfs/xfs_bmap.c | 243 ++++++++++++++++----------------------
libxfs/xfs_bmap_btree.c | 24 ++--
libxfs/xfs_bmap_btree.h | 207 ++++++++++++++++++++++----------
libxfs/xfs_da_btree.c | 5 -
libxfs/xfs_fs.h | 26 ++++
libxfs/xfs_ialloc.c | 14 ++
libxfs/xfs_ialloc.h | 4 -
libxfs/xfs_ialloc_btree.c | 6 -
libxfs/xfs_ialloc_btree.h | 3
libxfs/xfs_inode_fork.c | 40 +++---
libxfs/xfs_inode_util.c | 2
libxfs/xfs_refcount_btree.c | 5 -
libxfs/xfs_refcount_btree.h | 3
libxfs/xfs_rmap_btree.c | 7 +
libxfs/xfs_rmap_btree.h | 3
libxfs/xfs_rtbitmap.c | 274 +++++++++++++++++++++++++++++++------------
libxfs/xfs_rtbitmap.h | 61 ++--------
libxfs/xfs_sb.c | 92 ++++++++------
libxfs/xfs_sb.h | 3
libxfs/xfs_shared.h | 3
libxfs/xfs_trans_resv.c | 4 -
libxfs/xfs_types.h | 12 --
m4/package_utilies.m4 | 5 +
mkfs/proto.c | 17 +--
repair/bmap_repair.c | 2
repair/dinode.c | 17 +--
repair/phase5.c | 16 +--
repair/phase6.c | 18 +--
repair/prefetch.c | 8 +
repair/rt.c | 7 -
repair/scan.c | 6 -
61 files changed, 1026 insertions(+), 795 deletions(-)
create mode 100644 libxfs/ioctl_c_dummy.c
create mode 100644 libxfs/ioctl_cxx_dummy.cpp
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
@ 2024-10-21 21:59 ` Darrick J. Wong
2024-10-22 5:56 ` Christoph Hellwig
2024-10-21 21:59 ` [PATCH 02/37] libxfs: compile with a C++ compiler Darrick J. Wong
` (35 subsequent siblings)
36 siblings, 1 reply; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:59 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
configure.ac | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 901208a8d273eb..b75f7d9e7563b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,6 +5,11 @@ AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([include/libxfs.h])
AC_PREFIX_DEFAULT(/usr)
+# Default CFLAGS if nobody specifies anything else
+if test "${CFLAGS+set}" != "set"; then
+ CFLAGS="-g -O2 -std=gnu11"
+fi
+
AC_PROG_INSTALL
LT_INIT
@@ -22,7 +27,7 @@ if test "${BUILD_CFLAGS+set}" != "set"; then
if test $cross_compiling = no; then
BUILD_CFLAGS="$CFLAGS"
else
- BUILD_CFLAGS="-g -O2"
+ BUILD_CFLAGS="-g -O2 -std=gnu11"
fi
fi
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 02/37] libxfs: compile with a C++ compiler
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
2024-10-21 21:59 ` [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default Darrick J. Wong
@ 2024-10-21 21:59 ` Darrick J. Wong
2024-10-22 5:57 ` Christoph Hellwig
2024-10-21 21:59 ` [PATCH 03/37] libxfs: port IS_ENABLED from the kernel Darrick J. Wong
` (34 subsequent siblings)
36 siblings, 1 reply; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:59 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
configure.ac | 6 ++++++
include/builddefs.in | 8 ++++++++
libxfs/Makefile | 31 ++++++++++++++++++++++++++++++-
libxfs/ioctl_c_dummy.c | 11 +++++++++++
libxfs/ioctl_cxx_dummy.cpp | 13 +++++++++++++
m4/package_utilies.m4 | 5 +++++
6 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 libxfs/ioctl_c_dummy.c
create mode 100644 libxfs/ioctl_cxx_dummy.cpp
diff --git a/configure.ac b/configure.ac
index b75f7d9e7563b2..dc587f39b80533 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,9 @@ AC_PREFIX_DEFAULT(/usr)
if test "${CFLAGS+set}" != "set"; then
CFLAGS="-g -O2 -std=gnu11"
fi
+if test "${CXXFLAGS+set}" != "set"; then
+ CXXFLAGS="-g -O2 -std=gnu++11"
+fi
AC_PROG_INSTALL
LT_INIT
@@ -31,6 +34,9 @@ if test "${BUILD_CFLAGS+set}" != "set"; then
fi
fi
+AC_PROG_CXX
+# no C++ build tools yet
+
AC_ARG_ENABLE(shared,
[ --enable-shared=[yes/no] Enable use of shared libraries [default=yes]],,
enable_shared=yes)
diff --git a/include/builddefs.in b/include/builddefs.in
index c8c7de7fd2fd38..1cbace071108dd 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -14,6 +14,7 @@ MALLOCLIB = @malloc_lib@
LOADERFLAGS = @LDFLAGS@
LTLDFLAGS = @LDFLAGS@
CFLAGS = @CFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -Wno-address-of-packed-member
+CXXFLAGS = @CXXFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -Wno-address-of-packed-member
BUILD_CFLAGS = @BUILD_CFLAGS@ -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
# make sure we don't pick up whacky LDFLAGS from the make environment and
@@ -63,6 +64,7 @@ XFS_SCRUB_ALL_AUTO_MEDIA_SCAN_STAMP=$(PKG_STATE_DIR)/xfs_scrub_all_media.stamp
CC = @cc@
BUILD_CC = @BUILD_CC@
+CXX = @cxx@
AWK = @awk@
SED = @sed@
TAR = @tar@
@@ -161,9 +163,15 @@ ifeq ($(ENABLE_GETTEXT),yes)
GCFLAGS += -DENABLE_GETTEXT
endif
+# Override these if C++ needs other options
+SANITIZER_CXXFLAGS = $(SANITIZER_CFLAGS)
+GCXXFLAGS = $(GCFLAGS)
+PCXXFLAGS = $(PCFLAGS)
+
BUILD_CFLAGS += $(GCFLAGS) $(PCFLAGS)
# First, Sanitizer, Global, Platform, Local CFLAGS
CFLAGS += $(FCFLAGS) $(SANITIZER_CFLAGS) $(OPTIMIZER) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS)
+CXXFLAGS += $(FCXXFLAGS) $(SANITIZER_CXXFLAGS) $(OPTIMIZER) $(GCXXFLAGS) $(PCXXFLAGS) $(LCXXFLAGS)
include $(TOPDIR)/include/buildmacros
diff --git a/libxfs/Makefile b/libxfs/Makefile
index 72e287b8b7957a..aca28440adac08 100644
--- a/libxfs/Makefile
+++ b/libxfs/Makefile
@@ -125,6 +125,18 @@ CFILES = buf_mem.c \
xfs_trans_space.c \
xfs_types.c
+EXTRA_CFILES=\
+ ioctl_c_dummy.c
+
+EXTRA_CXXFILES=\
+ ioctl_cxx_dummy.cpp
+
+EXTRA_OBJECTS=\
+ $(patsubst %.c,%.o,$(EXTRA_CFILES)) \
+ $(patsubst %.cpp,%.o,$(EXTRA_CXXFILES))
+
+LDIRT += $(EXTRA_OBJECTS)
+
#
# Tracing flags:
# -DMEM_DEBUG all zone memory use
@@ -148,7 +160,23 @@ LTLIBS = $(LIBPTHREAD) $(LIBRT)
# don't try linking xfs_repair with a debug libxfs.
DEBUG = -DNDEBUG
-default: ltdepend $(LTLIBRARY)
+default: ltdepend $(LTLIBRARY) $(EXTRA_OBJECTS)
+
+%dummy.o: %dummy.cpp
+ @echo " [CXXD] $@"
+ $(Q)$(CXX) $(CXXFLAGS) -c $<
+
+%dummy.o: %dummy.c
+ @echo " [CCD] $@"
+ $(Q)$(CC) $(CFLAGS) -c $<
+
+MAKECXXDEP := $(MAKEDEPEND) $(CXXFLAGS)
+
+.PHONY: .extradep
+
+.extradep: $(EXTRA_CFILES) $(EXTRA_CXXFILES) $(HFILES)
+ $(Q)$(MAKEDEP) $(EXTRA_CFILES) > .extradep
+ $(Q)$(MAKECXXDEP) $(EXTRA_CXXFILES) >> .extradep
# set up include/xfs header directory
include $(BUILDRULES)
@@ -172,4 +200,5 @@ install-dev: install
# running the install-headers target.
ifndef NODEP
-include .ltdep
+-include .extradep
endif
diff --git a/libxfs/ioctl_c_dummy.c b/libxfs/ioctl_c_dummy.c
new file mode 100644
index 00000000000000..e417332c3cf9f6
--- /dev/null
+++ b/libxfs/ioctl_c_dummy.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+
+/* Dummy program to test C compilation of user-exported xfs headers */
+
+#include "include/xfs.h"
+#include "include/handle.h"
+#include "include/jdm.h"
diff --git a/libxfs/ioctl_cxx_dummy.cpp b/libxfs/ioctl_cxx_dummy.cpp
new file mode 100644
index 00000000000000..b95babff0b0aee
--- /dev/null
+++ b/libxfs/ioctl_cxx_dummy.cpp
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+
+/* Dummy program to test C++ compilation of user-exported xfs headers */
+
+extern "C" {
+#include "include/xfs.h"
+#include "include/handle.h"
+#include "include/jdm.h"
+};
diff --git a/m4/package_utilies.m4 b/m4/package_utilies.m4
index 49f4dfbbd2d168..56ee0b266130bf 100644
--- a/m4/package_utilies.m4
+++ b/m4/package_utilies.m4
@@ -42,6 +42,11 @@ AC_DEFUN([AC_PACKAGE_UTILITIES],
AC_SUBST(cc)
AC_PACKAGE_NEED_UTILITY($1, "$cc", cc, [C compiler])
+ AC_PROG_CXX
+ cxx="$CXX"
+ AC_SUBST(cxx)
+ AC_PACKAGE_NEED_UTILITY($1, "$cxx", cxx, [C++ compiler])
+
if test -z "$MAKE"; then
AC_PATH_PROG(MAKE, gmake,, $PATH)
fi
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 03/37] libxfs: port IS_ENABLED from the kernel
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
2024-10-21 21:59 ` [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default Darrick J. Wong
2024-10-21 21:59 ` [PATCH 02/37] libxfs: compile with a C++ compiler Darrick J. Wong
@ 2024-10-21 21:59 ` Darrick J. Wong
2024-10-22 5:58 ` Christoph Hellwig
2024-10-21 21:59 ` [PATCH 04/37] libfrog: add xarray emulation Darrick J. Wong
` (33 subsequent siblings)
36 siblings, 1 reply; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:59 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
include/libxfs.h | 6 +++-
include/platform_defs.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++
libxfs/libxfs_priv.h | 5 ++--
3 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/include/libxfs.h b/include/libxfs.h
index 17cf619f0544aa..fe8e6584f1caca 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -7,10 +7,12 @@
#ifndef __LIBXFS_H__
#define __LIBXFS_H__
+/* CONFIG_XFS_* must be defined to 1 to work with IS_ENABLED() */
+
/* For userspace XFS_RT is always defined */
-#define CONFIG_XFS_RT
+#define CONFIG_XFS_RT 1
/* Ditto in-memory btrees */
-#define CONFIG_XFS_BTREE_IN_MEM
+#define CONFIG_XFS_BTREE_IN_MEM 1
#include "libxfs_api_defs.h"
#include "platform_defs.h"
diff --git a/include/platform_defs.h b/include/platform_defs.h
index c01d4c42674669..a3644dea41cdef 100644
--- a/include/platform_defs.h
+++ b/include/platform_defs.h
@@ -165,4 +165,67 @@ static inline size_t __ab_c_size(size_t a, size_t b, size_t c)
# define barrier() __memory_barrier()
#endif
+/* stuff from include/linux/kconfig.h */
+#define __ARG_PLACEHOLDER_1 0,
+#define __take_second_arg(__ignored, val, ...) val
+
+/*
+ * The use of "&&" / "||" is limited in certain expressions.
+ * The following enable to calculate "and" / "or" with macro expansion only.
+ */
+#define __and(x, y) ___and(x, y)
+#define ___and(x, y) ____and(__ARG_PLACEHOLDER_##x, y)
+#define ____and(arg1_or_junk, y) __take_second_arg(arg1_or_junk y, 0)
+
+#define __or(x, y) ___or(x, y)
+#define ___or(x, y) ____or(__ARG_PLACEHOLDER_##x, y)
+#define ____or(arg1_or_junk, y) __take_second_arg(arg1_or_junk 1, y)
+
+/*
+ * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
+ * these only work with boolean and tristate options.
+ */
+
+/*
+ * Getting something that works in C and CPP for an arg that may or may
+ * not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
+ * we match on the placeholder define, insert the "0," for arg1 and generate
+ * the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
+ * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
+ * the last step cherry picks the 2nd arg, we get a zero.
+ */
+#define __is_defined(x) ___is_defined(x)
+#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
+#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)
+
+/*
+ * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
+ * otherwise. For boolean options, this is equivalent to
+ * IS_ENABLED(CONFIG_FOO).
+ */
+#define IS_BUILTIN(option) __is_defined(option)
+
+/*
+ * IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
+ * otherwise. CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1" in
+ * autoconf.h.
+ */
+#define IS_MODULE(option) __is_defined(option##_MODULE)
+
+/*
+ * IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
+ * code can call a function defined in code compiled based on CONFIG_FOO.
+ * This is similar to IS_ENABLED(), but returns false when invoked from
+ * built-in code when CONFIG_FOO is set to 'm'.
+ */
+#define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
+ __and(IS_MODULE(option), __is_defined(MODULE)))
+
+/*
+ * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
+ * 0 otherwise. Note that CONFIG_FOO=y results in "#define CONFIG_FOO 1" in
+ * autoconf.h, while CONFIG_FOO=m results in "#define CONFIG_FOO_MODULE 1".
+ */
+#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
+
#endif /* __XFS_PLATFORM_DEFS_H__ */
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index b720cc5fac94ff..fa025aeb09712b 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -37,8 +37,9 @@
#ifndef __LIBXFS_INTERNAL_XFS_H__
#define __LIBXFS_INTERNAL_XFS_H__
-#define CONFIG_XFS_RT
-#define CONFIG_XFS_BTREE_IN_MEM
+/* CONFIG_XFS_* must be defined to 1 to work with IS_ENABLED() */
+#define CONFIG_XFS_RT 1
+#define CONFIG_XFS_BTREE_IN_MEM 1
#include "libxfs_api_defs.h"
#include "platform_defs.h"
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 04/37] libfrog: add xarray emulation
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (2 preceding siblings ...)
2024-10-21 21:59 ` [PATCH 03/37] libxfs: port IS_ENABLED from the kernel Darrick J. Wong
@ 2024-10-21 21:59 ` Darrick J. Wong
2024-10-21 22:00 ` [PATCH 05/37] xfs: introduce new file range commit ioctls Darrick J. Wong
` (32 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 21:59 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libfrog/radix-tree.h | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/libfrog/radix-tree.h b/libfrog/radix-tree.h
index dad5f5b72039e3..fe896134eeb283 100644
--- a/libfrog/radix-tree.h
+++ b/libfrog/radix-tree.h
@@ -63,4 +63,39 @@ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
static inline int radix_tree_preload(int gfp_mask) { return 0; }
static inline void radix_tree_preload_end(void) { }
+/*
+ * Emulation of the kernel xarray API. Note that unlike the kernel
+ * xarray, there is no internal locking so code using this should not
+ * allow concurrent operations in userspace.
+ */
+struct xarray {
+ struct radix_tree_root r;
+};
+
+static inline void xa_init(struct xarray *xa)
+{
+ INIT_RADIX_TREE(&xa->r, GFP_KERNEL);
+}
+
+static inline void *xa_load(struct xarray *xa, unsigned long index)
+{
+ return radix_tree_lookup(&xa->r, index);
+}
+
+static inline void *xa_erase(struct xarray *xa, unsigned long index)
+{
+ return radix_tree_delete(&xa->r, index);
+}
+
+static inline int xa_insert(struct xarray *xa, unsigned long index, void *entry,
+ unsigned int gfp)
+{
+ int error;
+
+ error = radix_tree_insert(&xa->r, index, entry);
+ if (error == -EEXIST)
+ return -EBUSY;
+ return error;
+}
+
#endif /* __LIBFROG_RADIX_TREE_H__ */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 05/37] xfs: introduce new file range commit ioctls
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (3 preceding siblings ...)
2024-10-21 21:59 ` [PATCH 04/37] libfrog: add xarray emulation Darrick J. Wong
@ 2024-10-21 22:00 ` Darrick J. Wong
2024-10-21 22:00 ` [PATCH 06/37] xfs: pass the icreate args object to xfs_dialloc Darrick J. Wong
` (31 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:00 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
libxfs/xfs_fs.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h
index 184ccbfe708218..860284064c5aa9 100644
--- a/libxfs/xfs_fs.h
+++ b/libxfs/xfs_fs.h
@@ -826,6 +826,30 @@ struct xfs_exchange_range {
__u64 flags; /* see XFS_EXCHANGE_RANGE_* below */
};
+/*
+ * Using the same definition of file2 as struct xfs_exchange_range, commit the
+ * contents of file1 into file2 if file2 has the same inode number, mtime, and
+ * ctime as the arguments provided to the call. The old contents of file2 will
+ * be moved to file1.
+ *
+ * Returns -EBUSY if there isn't an exact match for the file2 fields.
+ *
+ * Filesystems must be able to restart and complete the operation even after
+ * the system goes down.
+ */
+struct xfs_commit_range {
+ __s32 file1_fd;
+ __u32 pad; /* must be zeroes */
+ __u64 file1_offset; /* file1 offset, bytes */
+ __u64 file2_offset; /* file2 offset, bytes */
+ __u64 length; /* bytes to exchange */
+
+ __u64 flags; /* see XFS_EXCHANGE_RANGE_* below */
+
+ /* opaque file2 metadata for freshness checks */
+ __u64 file2_freshness[6];
+};
+
/*
* Exchange file data all the way to the ends of both files, and then exchange
* the file sizes. This flag can be used to replace a file's contents with a
@@ -998,6 +1022,8 @@ struct xfs_getparents_by_handle {
#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)
#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req)
#define XFS_IOC_EXCHANGE_RANGE _IOW ('X', 129, struct xfs_exchange_range)
+#define XFS_IOC_START_COMMIT _IOR ('X', 130, struct xfs_commit_range)
+#define XFS_IOC_COMMIT_RANGE _IOW ('X', 131, struct xfs_commit_range)
/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 06/37] xfs: pass the icreate args object to xfs_dialloc
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (4 preceding siblings ...)
2024-10-21 22:00 ` [PATCH 05/37] xfs: introduce new file range commit ioctls Darrick J. Wong
@ 2024-10-21 22:00 ` Darrick J. Wong
2024-10-21 22:00 ` [PATCH 07/37] xfs: remove xfs_validate_rtextents Darrick J. Wong
` (30 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:00 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
db/iunlink.c | 2 +-
libxfs/xfs_ialloc.c | 5 +++--
libxfs/xfs_ialloc.h | 4 +++-
mkfs/proto.c | 5 ++---
repair/phase6.c | 2 +-
5 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/db/iunlink.c b/db/iunlink.c
index 0dc68b7240c1a3..55ba5af5a3c563 100644
--- a/db/iunlink.c
+++ b/db/iunlink.c
@@ -223,7 +223,7 @@ create_unlinked(
return error;
}
- error = -libxfs_dialloc(&tp, 0, args.mode, &ino);
+ error = -libxfs_dialloc(&tp, &args, &ino);
if (error) {
dbprintf(_("alloc inode: %s\n"), strerror(error));
goto out_cancel;
diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c
index c526f677e072b4..83e3d7d7c5a1b3 100644
--- a/libxfs/xfs_ialloc.c
+++ b/libxfs/xfs_ialloc.c
@@ -1850,11 +1850,12 @@ xfs_dialloc_try_ag(
int
xfs_dialloc(
struct xfs_trans **tpp,
- xfs_ino_t parent,
- umode_t mode,
+ const struct xfs_icreate_args *args,
xfs_ino_t *new_ino)
{
struct xfs_mount *mp = (*tpp)->t_mountp;
+ xfs_ino_t parent = args->pip ? args->pip->i_ino : 0;
+ umode_t mode = args->mode & S_IFMT;
xfs_agnumber_t agno;
int error = 0;
xfs_agnumber_t start_agno;
diff --git a/libxfs/xfs_ialloc.h b/libxfs/xfs_ialloc.h
index b549627e3a6150..3a1323155a455a 100644
--- a/libxfs/xfs_ialloc.h
+++ b/libxfs/xfs_ialloc.h
@@ -33,11 +33,13 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
}
+struct xfs_icreate_args;
+
/*
* Allocate an inode on disk. Mode is used to tell whether the new inode will
* need space, and whether it is a directory.
*/
-int xfs_dialloc(struct xfs_trans **tpp, xfs_ino_t parent, umode_t mode,
+int xfs_dialloc(struct xfs_trans **tpp, const struct xfs_icreate_args *args,
xfs_ino_t *new_ino);
int xfs_difree(struct xfs_trans *tp, struct xfs_perag *pag,
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 8a51bfb264cedf..42ac3e10929b52 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -428,7 +428,6 @@ creatproto(
};
struct xfs_inode *ip;
struct inode *inode;
- xfs_ino_t parent_ino = dp ? dp->i_ino : 0;
xfs_ino_t ino;
int error;
@@ -440,7 +439,7 @@ creatproto(
* Call the space management code to pick the on-disk inode to be
* allocated.
*/
- error = -libxfs_dialloc(tpp, parent_ino, mode, &ino);
+ error = -libxfs_dialloc(tpp, &args, &ino);
if (error)
return error;
@@ -769,7 +768,7 @@ create_sb_metadata_file(
if (error)
res_failed(error);
- error = -libxfs_dialloc(&tp, 0, args.mode, &ino);
+ error = -libxfs_dialloc(&tp, &args, &ino);
if (error)
goto fail;
diff --git a/repair/phase6.c b/repair/phase6.c
index ba28edaa41c24c..b48f18b06a5c81 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -873,7 +873,7 @@ mk_orphanage(
if (i)
res_failed(i);
- error = -libxfs_dialloc(&tp, mp->m_sb.sb_rootino, args.mode, &ino);
+ error = -libxfs_dialloc(&tp, &args, &ino);
if (error)
do_error(_("%s inode allocation failed %d\n"),
ORPHANAGE, error);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 07/37] xfs: remove xfs_validate_rtextents
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (5 preceding siblings ...)
2024-10-21 22:00 ` [PATCH 06/37] xfs: pass the icreate args object to xfs_dialloc Darrick J. Wong
@ 2024-10-21 22:00 ` Darrick J. Wong
2024-10-21 22:01 ` [PATCH 08/37] xfs: factor out a xfs_validate_rt_geometry helper Darrick J. Wong
` (29 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:00 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_sb.c | 2 +-
libxfs/xfs_types.h | 12 ------------
2 files changed, 1 insertion(+), 13 deletions(-)
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index bedb36a0620dff..a50c9c06c3f19c 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -511,7 +511,7 @@ xfs_validate_sb_common(
rbmblocks = howmany_64(sbp->sb_rextents,
NBBY * sbp->sb_blocksize);
- if (!xfs_validate_rtextents(rexts) ||
+ if (sbp->sb_rextents == 0 ||
sbp->sb_rextents != rexts ||
sbp->sb_rextslog != xfs_compute_rextslog(rexts) ||
sbp->sb_rbmblocks != rbmblocks) {
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index 76eb9e328835f8..a8cd44d03ef648 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -235,16 +235,4 @@ bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
xfs_fileoff_t len);
-/* Do we support an rt volume having this number of rtextents? */
-static inline bool
-xfs_validate_rtextents(
- xfs_rtbxlen_t rtextents)
-{
- /* No runt rt volumes */
- if (rtextents == 0)
- return false;
-
- return true;
-}
-
#endif /* __XFS_TYPES_H__ */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 08/37] xfs: factor out a xfs_validate_rt_geometry helper
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (6 preceding siblings ...)
2024-10-21 22:00 ` [PATCH 07/37] xfs: remove xfs_validate_rtextents Darrick J. Wong
@ 2024-10-21 22:01 ` Darrick J. Wong
2024-10-21 22:01 ` [PATCH 09/37] xfs: remove the limit argument to xfs_rtfind_back Darrick J. Wong
` (28 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:01 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_sb.c | 64 ++++++++++++++++++++++++++++++-------------------------
libxfs/xfs_sb.h | 1 +
2 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index a50c9c06c3f19c..c3185a4daeb4aa 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -229,6 +229,38 @@ xfs_validate_sb_read(
return 0;
}
+static uint64_t
+xfs_sb_calc_rbmblocks(
+ struct xfs_sb *sbp)
+{
+ return howmany_64(sbp->sb_rextents, NBBY * sbp->sb_blocksize);
+}
+
+/* Validate the realtime geometry */
+bool
+xfs_validate_rt_geometry(
+ struct xfs_sb *sbp)
+{
+ if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
+ sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE)
+ return false;
+
+ if (sbp->sb_rblocks == 0) {
+ if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
+ sbp->sb_rextslog != 0 || sbp->sb_frextents != 0)
+ return false;
+ return true;
+ }
+
+ if (sbp->sb_rextents == 0 ||
+ sbp->sb_rextents != div_u64(sbp->sb_rblocks, sbp->sb_rextsize) ||
+ sbp->sb_rextslog != xfs_compute_rextslog(sbp->sb_rextents) ||
+ sbp->sb_rbmblocks != xfs_sb_calc_rbmblocks(sbp))
+ return false;
+
+ return true;
+}
+
/* Check all the superblock fields we care about when writing one out. */
STATIC int
xfs_validate_sb_write(
@@ -488,39 +520,13 @@ xfs_validate_sb_common(
}
}
- /* Validate the realtime geometry; stolen from xfs_repair */
- if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
- sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) {
+ if (!xfs_validate_rt_geometry(sbp)) {
xfs_notice(mp,
- "realtime extent sanity check failed");
+ "realtime %sgeometry check failed",
+ sbp->sb_rblocks ? "" : "zeroed ");
return -EFSCORRUPTED;
}
- if (sbp->sb_rblocks == 0) {
- if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
- sbp->sb_rextslog != 0 || sbp->sb_frextents != 0) {
- xfs_notice(mp,
- "realtime zeroed geometry check failed");
- return -EFSCORRUPTED;
- }
- } else {
- uint64_t rexts;
- uint64_t rbmblocks;
-
- rexts = div_u64(sbp->sb_rblocks, sbp->sb_rextsize);
- rbmblocks = howmany_64(sbp->sb_rextents,
- NBBY * sbp->sb_blocksize);
-
- if (sbp->sb_rextents == 0 ||
- sbp->sb_rextents != rexts ||
- sbp->sb_rextslog != xfs_compute_rextslog(rexts) ||
- sbp->sb_rbmblocks != rbmblocks) {
- xfs_notice(mp,
- "realtime geometry sanity check failed");
- return -EFSCORRUPTED;
- }
- }
-
/*
* Either (sb_unit and !hasdalign) or (!sb_unit and hasdalign)
* would imply the image is corrupted.
diff --git a/libxfs/xfs_sb.h b/libxfs/xfs_sb.h
index 37b1ed1bc2095e..796f02191dfd2e 100644
--- a/libxfs/xfs_sb.h
+++ b/libxfs/xfs_sb.h
@@ -38,6 +38,7 @@ extern int xfs_sb_get_secondary(struct xfs_mount *mp,
bool xfs_validate_stripe_geometry(struct xfs_mount *mp,
__s64 sunit, __s64 swidth, int sectorsize, bool may_repair,
bool silent);
+bool xfs_validate_rt_geometry(struct xfs_sb *sbp);
uint8_t xfs_compute_rextslog(xfs_rtbxlen_t rtextents);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 09/37] xfs: remove the limit argument to xfs_rtfind_back
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (7 preceding siblings ...)
2024-10-21 22:01 ` [PATCH 08/37] xfs: factor out a xfs_validate_rt_geometry helper Darrick J. Wong
@ 2024-10-21 22:01 ` Darrick J. Wong
2024-10-21 22:01 ` [PATCH 10/37] xfs: assert a valid limit in xfs_rtfind_forw Darrick J. Wong
` (27 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:01 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 9 ++++-----
libxfs/xfs_rtbitmap.h | 2 +-
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 58a3ba992f51cc..c7613f2de7b0a0 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -137,14 +137,13 @@ xfs_rtbuf_get(
}
/*
- * Searching backward from start to limit, find the first block whose
- * allocated/free state is different from start's.
+ * Searching backward from start find the first block whose allocated/free state
+ * is different from start's.
*/
int
xfs_rtfind_back(
struct xfs_rtalloc_args *args,
xfs_rtxnum_t start, /* starting rtext to look at */
- xfs_rtxnum_t limit, /* last rtext to look at */
xfs_rtxnum_t *rtx) /* out: start rtext found */
{
struct xfs_mount *mp = args->mp;
@@ -173,7 +172,7 @@ xfs_rtfind_back(
*/
word = xfs_rtx_to_rbmword(mp, start);
bit = (int)(start & (XFS_NBWORD - 1));
- len = start - limit + 1;
+ len = start + 1;
/*
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
@@ -696,7 +695,7 @@ xfs_rtfree_range(
* We need to find the beginning and end of the extent so we can
* properly update the summary.
*/
- error = xfs_rtfind_back(args, start, 0, &preblock);
+ error = xfs_rtfind_back(args, start, &preblock);
if (error) {
return error;
}
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 6186585f2c376d..1e04f0954a0fa7 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -316,7 +316,7 @@ xfs_rtsummary_read_buf(
int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat);
int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
- xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock);
+ xfs_rtxnum_t *rtblock);
int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock);
int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 10/37] xfs: assert a valid limit in xfs_rtfind_forw
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (8 preceding siblings ...)
2024-10-21 22:01 ` [PATCH 09/37] xfs: remove the limit argument to xfs_rtfind_back Darrick J. Wong
@ 2024-10-21 22:01 ` Darrick J. Wong
2024-10-21 22:01 ` [PATCH 11/37] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf Darrick J. Wong
` (26 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:01 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index c7613f2de7b0a0..f578b0d34b36d3 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -313,6 +313,8 @@ xfs_rtfind_forw(
xfs_rtword_t incore;
unsigned int word; /* word number in the buffer */
+ ASSERT(start <= limit);
+
/*
* Compute and read in starting bitmap block for starting block.
*/
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 11/37] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (9 preceding siblings ...)
2024-10-21 22:01 ` [PATCH 10/37] xfs: assert a valid limit in xfs_rtfind_forw Darrick J. Wong
@ 2024-10-21 22:01 ` Darrick J. Wong
2024-10-21 22:02 ` [PATCH 12/37] xfs: factor out rtbitmap/summary initialization helpers Darrick J. Wong
` (25 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:01 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 31 ++++++++++++++++++++++++++++++-
libxfs/xfs_rtbitmap.h | 22 ++--------------------
2 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index f578b0d34b36d3..fc904547147e93 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -67,7 +67,7 @@ xfs_rtbuf_cache_relse(
* Get a buffer for the bitmap or summary file block specified.
* The buffer is returned read and locked.
*/
-int
+static int
xfs_rtbuf_get(
struct xfs_rtalloc_args *args,
xfs_fileoff_t block, /* block number in bitmap or summary */
@@ -136,6 +136,35 @@ xfs_rtbuf_get(
return 0;
}
+int
+xfs_rtbitmap_read_buf(
+ struct xfs_rtalloc_args *args,
+ xfs_fileoff_t block)
+{
+ struct xfs_mount *mp = args->mp;
+
+ if (XFS_IS_CORRUPT(mp, block >= mp->m_sb.sb_rbmblocks)) {
+ xfs_rt_mark_sick(mp, XFS_SICK_RT_BITMAP);
+ return -EFSCORRUPTED;
+ }
+
+ return xfs_rtbuf_get(args, block, 0);
+}
+
+int
+xfs_rtsummary_read_buf(
+ struct xfs_rtalloc_args *args,
+ xfs_fileoff_t block)
+{
+ struct xfs_mount *mp = args->mp;
+
+ if (XFS_IS_CORRUPT(mp, block >= XFS_B_TO_FSB(mp, mp->m_rsumsize))) {
+ xfs_rt_mark_sick(args->mp, XFS_SICK_RT_SUMMARY);
+ return -EFSCORRUPTED;
+ }
+ return xfs_rtbuf_get(args, block, 1);
+}
+
/*
* Searching backward from start find the first block whose allocated/free state
* is different from start's.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 1e04f0954a0fa7..e87e2099cff5e0 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -293,26 +293,8 @@ typedef int (*xfs_rtalloc_query_range_fn)(
#ifdef CONFIG_XFS_RT
void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args);
-
-int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block,
- int issum);
-
-static inline int
-xfs_rtbitmap_read_buf(
- struct xfs_rtalloc_args *args,
- xfs_fileoff_t block)
-{
- return xfs_rtbuf_get(args, block, 0);
-}
-
-static inline int
-xfs_rtsummary_read_buf(
- struct xfs_rtalloc_args *args,
- xfs_fileoff_t block)
-{
- return xfs_rtbuf_get(args, block, 1);
-}
-
+int xfs_rtbitmap_read_buf(struct xfs_rtalloc_args *args, xfs_fileoff_t block);
+int xfs_rtsummary_read_buf(struct xfs_rtalloc_args *args, xfs_fileoff_t block);
int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat);
int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 12/37] xfs: factor out rtbitmap/summary initialization helpers
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (10 preceding siblings ...)
2024-10-21 22:01 ` [PATCH 11/37] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf Darrick J. Wong
@ 2024-10-21 22:02 ` Darrick J. Wong
2024-10-21 22:02 ` [PATCH 13/37] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock Darrick J. Wong
` (24 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:02 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++
libxfs/xfs_rtbitmap.h | 3 +
2 files changed, 129 insertions(+)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index fc904547147e93..9d771af677adb1 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -13,6 +13,8 @@
#include "xfs_mount.h"
#include "xfs_inode.h"
#include "xfs_bmap.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_trans_space.h"
#include "xfs_trans.h"
#include "xfs_rtbitmap.h"
#include "xfs_health.h"
@@ -1253,3 +1255,127 @@ xfs_rtbitmap_unlock_shared(
if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
}
+
+static int
+xfs_rtfile_alloc_blocks(
+ struct xfs_inode *ip,
+ xfs_fileoff_t offset_fsb,
+ xfs_filblks_t count_fsb,
+ struct xfs_bmbt_irec *map)
+{
+ struct xfs_mount *mp = ip->i_mount;
+ struct xfs_trans *tp;
+ int nmap = 1;
+ int error;
+
+ error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc,
+ XFS_GROWFSRT_SPACE_RES(mp, count_fsb), 0, 0, &tp);
+ if (error)
+ return error;
+
+ xfs_ilock(ip, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+
+ error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
+ XFS_IEXT_ADD_NOSPLIT_CNT);
+ if (error)
+ goto out_trans_cancel;
+
+ error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb,
+ XFS_BMAPI_METADATA, 0, map, &nmap);
+ if (error)
+ goto out_trans_cancel;
+
+ return xfs_trans_commit(tp);
+
+out_trans_cancel:
+ xfs_trans_cancel(tp);
+ return error;
+}
+
+/* Get a buffer for the block. */
+static int
+xfs_rtfile_initialize_block(
+ struct xfs_inode *ip,
+ xfs_fsblock_t fsbno,
+ void *data)
+{
+ struct xfs_mount *mp = ip->i_mount;
+ struct xfs_trans *tp;
+ struct xfs_buf *bp;
+ const size_t copylen = mp->m_blockwsize << XFS_WORDLOG;
+ enum xfs_blft buf_type;
+ int error;
+
+ if (ip == mp->m_rsumip)
+ buf_type = XFS_BLFT_RTSUMMARY_BUF;
+ else
+ buf_type = XFS_BLFT_RTBITMAP_BUF;
+
+ error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero, 0, 0, 0, &tp);
+ if (error)
+ return error;
+ xfs_ilock(ip, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+
+ error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
+ XFS_FSB_TO_DADDR(mp, fsbno), mp->m_bsize, 0, &bp);
+ if (error) {
+ xfs_trans_cancel(tp);
+ return error;
+ }
+
+ xfs_trans_buf_set_type(tp, bp, buf_type);
+ bp->b_ops = &xfs_rtbuf_ops;
+ if (data)
+ memcpy(bp->b_addr, data, copylen);
+ else
+ memset(bp->b_addr, 0, copylen);
+ xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
+ return xfs_trans_commit(tp);
+}
+
+/*
+ * Allocate space to the bitmap or summary file, and zero it, for growfs.
+ * @data must be a contiguous buffer large enough to fill all blocks in the
+ * file; or NULL to initialize the contents to zeroes.
+ */
+int
+xfs_rtfile_initialize_blocks(
+ struct xfs_inode *ip, /* inode (bitmap/summary) */
+ xfs_fileoff_t offset_fsb, /* offset to start from */
+ xfs_fileoff_t end_fsb, /* offset to allocate to */
+ void *data) /* data to fill the blocks */
+{
+ struct xfs_mount *mp = ip->i_mount;
+ const size_t copylen = mp->m_blockwsize << XFS_WORDLOG;
+
+ while (offset_fsb < end_fsb) {
+ struct xfs_bmbt_irec map;
+ xfs_filblks_t i;
+ int error;
+
+ error = xfs_rtfile_alloc_blocks(ip, offset_fsb,
+ end_fsb - offset_fsb, &map);
+ if (error)
+ return error;
+
+ /*
+ * Now we need to clear the allocated blocks.
+ *
+ * Do this one block per transaction, to keep it simple.
+ */
+ for (i = 0; i < map.br_blockcount; i++) {
+ error = xfs_rtfile_initialize_block(ip,
+ map.br_startblock + i, data);
+ if (error)
+ return error;
+ if (data)
+ data += copylen;
+ }
+
+ offset_fsb = map.br_startoff + map.br_blockcount;
+ }
+
+ return 0;
+}
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index e87e2099cff5e0..0d5ab5e2cb6a32 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -343,6 +343,9 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
unsigned int rsumlevels, xfs_extlen_t rbmblocks);
+int xfs_rtfile_initialize_blocks(struct xfs_inode *ip,
+ xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb, void *data);
+
void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp);
void xfs_rtbitmap_unlock(struct xfs_mount *mp);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 13/37] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (11 preceding siblings ...)
2024-10-21 22:02 ` [PATCH 12/37] xfs: factor out rtbitmap/summary initialization helpers Darrick J. Wong
@ 2024-10-21 22:02 ` Darrick J. Wong
2024-10-21 22:02 ` [PATCH 14/37] xfs: ensure rtx mask/shift are correct after growfs Darrick J. Wong
` (23 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:02 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_bmap.c | 3 ++-
libxfs/xfs_rtbitmap.c | 24 +++++++++++++-----------
libxfs/xfs_rtbitmap.h | 6 ++++--
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 4b10f169f1eb94..1f63dc775ea393 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -5370,7 +5370,8 @@ xfs_bmap_del_extent_real(
*/
if (!(tp->t_flags & XFS_TRANS_RTBITMAP_LOCKED)) {
tp->t_flags |= XFS_TRANS_RTBITMAP_LOCKED;
- xfs_rtbitmap_lock(tp, mp);
+ xfs_rtbitmap_lock(mp);
+ xfs_rtbitmap_trans_join(tp);
}
error = xfs_rtfree_blocks(tp, del->br_startblock,
del->br_blockcount);
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 9d771af677adb1..c86de2aa13cea9 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1199,23 +1199,25 @@ xfs_rtsummary_wordcount(
return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
}
-/*
- * Lock both realtime free space metadata inodes for a freespace update. If a
- * transaction is given, the inodes will be joined to the transaction and the
- * ILOCKs will be released on transaction commit.
- */
+/* Lock both realtime free space metadata inodes for a freespace update. */
void
xfs_rtbitmap_lock(
- struct xfs_trans *tp,
struct xfs_mount *mp)
{
xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
- if (tp)
- xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
-
xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
- if (tp)
- xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
+}
+
+/*
+ * Join both realtime free space metadata inodes to the transaction. The
+ * ILOCKs will be released on transaction commit.
+ */
+void
+xfs_rtbitmap_trans_join(
+ struct xfs_trans *tp)
+{
+ xfs_trans_ijoin(tp, tp->t_mountp->m_rbmip, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, tp->t_mountp->m_rsumip, XFS_ILOCK_EXCL);
}
/* Unlock both realtime free space metadata inodes after a freespace update. */
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 0d5ab5e2cb6a32..523d3d3c12c608 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -346,8 +346,9 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
int xfs_rtfile_initialize_blocks(struct xfs_inode *ip,
xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb, void *data);
-void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp);
+void xfs_rtbitmap_lock(struct xfs_mount *mp);
void xfs_rtbitmap_unlock(struct xfs_mount *mp);
+void xfs_rtbitmap_trans_join(struct xfs_trans *tp);
/* Lock the rt bitmap inode in shared mode */
#define XFS_RBMLOCK_BITMAP (1U << 0)
@@ -376,7 +377,8 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
# define xfs_rtbitmap_wordcount(mp, r) (0)
# define xfs_rtsummary_blockcount(mp, l, b) (0)
# define xfs_rtsummary_wordcount(mp, l, b) (0)
-# define xfs_rtbitmap_lock(tp, mp) do { } while (0)
+# define xfs_rtbitmap_lock(mp) do { } while (0)
+# define xfs_rtbitmap_trans_join(tp) do { } while (0)
# define xfs_rtbitmap_unlock(mp) do { } while (0)
# define xfs_rtbitmap_lock_shared(mp, lf) do { } while (0)
# define xfs_rtbitmap_unlock_shared(mp, lf) do { } while (0)
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 14/37] xfs: ensure rtx mask/shift are correct after growfs
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (12 preceding siblings ...)
2024-10-21 22:02 ` [PATCH 13/37] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock Darrick J. Wong
@ 2024-10-21 22:02 ` Darrick J. Wong
2024-10-21 22:02 ` [PATCH 15/37] xfs: remove xfs_rtb_to_rtxrem Darrick J. Wong
` (22 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:02 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_sb.c | 12 ++++++++++--
libxfs/xfs_sb.h | 2 ++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index c3185a4daeb4aa..5f7ff4fa4e49b1 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -962,6 +962,15 @@ const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
.verify_write = xfs_sb_write_verify,
};
+void
+xfs_mount_sb_set_rextsize(
+ struct xfs_mount *mp,
+ struct xfs_sb *sbp)
+{
+ mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize);
+ mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize);
+}
+
/*
* xfs_mount_common
*
@@ -986,8 +995,7 @@ xfs_sb_mount_common(
mp->m_blockmask = sbp->sb_blocksize - 1;
mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
mp->m_blockwmask = mp->m_blockwsize - 1;
- mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize);
- mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize);
+ xfs_mount_sb_set_rextsize(mp, sbp);
mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
diff --git a/libxfs/xfs_sb.h b/libxfs/xfs_sb.h
index 796f02191dfd2e..885c837559914d 100644
--- a/libxfs/xfs_sb.h
+++ b/libxfs/xfs_sb.h
@@ -17,6 +17,8 @@ extern void xfs_log_sb(struct xfs_trans *tp);
extern int xfs_sync_sb(struct xfs_mount *mp, bool wait);
extern int xfs_sync_sb_buf(struct xfs_mount *mp);
extern void xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
+void xfs_mount_sb_set_rextsize(struct xfs_mount *mp,
+ struct xfs_sb *sbp);
extern void xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from);
extern void xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from);
extern void xfs_sb_quota_from_disk(struct xfs_sb *sbp);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 15/37] xfs: remove xfs_rtb_to_rtxrem
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (13 preceding siblings ...)
2024-10-21 22:02 ` [PATCH 14/37] xfs: ensure rtx mask/shift are correct after growfs Darrick J. Wong
@ 2024-10-21 22:02 ` Darrick J. Wong
2024-10-21 22:03 ` [PATCH 16/37] xfs: simplify xfs_rtalloc_query_range Darrick J. Wong
` (21 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:02 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 9 ++++-----
libxfs/xfs_rtbitmap.h | 18 ------------------
2 files changed, 4 insertions(+), 23 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index c86de2aa13cea9..74029d4431e1ca 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1020,25 +1020,24 @@ xfs_rtfree_blocks(
xfs_filblks_t rtlen)
{
struct xfs_mount *mp = tp->t_mountp;
- xfs_rtxnum_t start;
- xfs_filblks_t len;
xfs_extlen_t mod;
ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
- len = xfs_rtb_to_rtxrem(mp, rtlen, &mod);
+ mod = xfs_rtb_to_rtxoff(mp, rtlen);
if (mod) {
ASSERT(mod == 0);
return -EIO;
}
- start = xfs_rtb_to_rtxrem(mp, rtbno, &mod);
+ mod = xfs_rtb_to_rtxoff(mp, rtbno);
if (mod) {
ASSERT(mod == 0);
return -EIO;
}
- return xfs_rtfree_extent(tp, start, len);
+ return xfs_rtfree_extent(tp, xfs_rtb_to_rtx(mp, rtbno),
+ xfs_rtb_to_rtx(mp, rtlen));
}
/* Find all the free records within a given range. */
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 523d3d3c12c608..69ddacd4b01e6f 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -86,24 +86,6 @@ xfs_rtb_to_rtxoff(
return do_div(rtbno, mp->m_sb.sb_rextsize);
}
-/*
- * Crack an rt block number into an rt extent number and an offset within that
- * rt extent. Returns the rt extent number directly and the offset in @off.
- */
-static inline xfs_rtxnum_t
-xfs_rtb_to_rtxrem(
- struct xfs_mount *mp,
- xfs_rtblock_t rtbno,
- xfs_extlen_t *off)
-{
- if (likely(mp->m_rtxblklog >= 0)) {
- *off = rtbno & mp->m_rtxblkmask;
- return rtbno >> mp->m_rtxblklog;
- }
-
- return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
-}
-
/*
* Convert an rt block number into an rt extent number, rounding up to the next
* rt extent if the rt block is not aligned to an rt extent boundary.
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 16/37] xfs: simplify xfs_rtalloc_query_range
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (14 preceding siblings ...)
2024-10-21 22:02 ` [PATCH 15/37] xfs: remove xfs_rtb_to_rtxrem Darrick J. Wong
@ 2024-10-21 22:03 ` Darrick J. Wong
2024-10-21 22:03 ` [PATCH 17/37] xfs: clean up the ISVALID macro in xfs_bmap_adjacent Darrick J. Wong
` (20 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:03 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_rtbitmap.c | 42 +++++++++++++++++-------------------------
libxfs/xfs_rtbitmap.h | 3 +--
2 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 74029d4431e1ca..3f534a4724a26b 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1045,8 +1045,8 @@ int
xfs_rtalloc_query_range(
struct xfs_mount *mp,
struct xfs_trans *tp,
- const struct xfs_rtalloc_rec *low_rec,
- const struct xfs_rtalloc_rec *high_rec,
+ xfs_rtxnum_t start,
+ xfs_rtxnum_t end,
xfs_rtalloc_query_range_fn fn,
void *priv)
{
@@ -1054,45 +1054,42 @@ xfs_rtalloc_query_range(
.mp = mp,
.tp = tp,
};
- struct xfs_rtalloc_rec rec;
- xfs_rtxnum_t rtstart;
- xfs_rtxnum_t rtend;
- xfs_rtxnum_t high_key;
- int is_free;
int error = 0;
- if (low_rec->ar_startext > high_rec->ar_startext)
+ if (start > end)
return -EINVAL;
- if (low_rec->ar_startext >= mp->m_sb.sb_rextents ||
- low_rec->ar_startext == high_rec->ar_startext)
+ if (start == end || start >= mp->m_sb.sb_rextents)
return 0;
- high_key = min(high_rec->ar_startext, mp->m_sb.sb_rextents - 1);
+ end = min(end, mp->m_sb.sb_rextents - 1);
/* Iterate the bitmap, looking for discrepancies. */
- rtstart = low_rec->ar_startext;
- while (rtstart <= high_key) {
+ while (start <= end) {
+ struct xfs_rtalloc_rec rec;
+ int is_free;
+ xfs_rtxnum_t rtend;
+
/* Is the first block free? */
- error = xfs_rtcheck_range(&args, rtstart, 1, 1, &rtend,
+ error = xfs_rtcheck_range(&args, start, 1, 1, &rtend,
&is_free);
if (error)
break;
/* How long does the extent go for? */
- error = xfs_rtfind_forw(&args, rtstart, high_key, &rtend);
+ error = xfs_rtfind_forw(&args, start, end, &rtend);
if (error)
break;
if (is_free) {
- rec.ar_startext = rtstart;
- rec.ar_extcount = rtend - rtstart + 1;
+ rec.ar_startext = start;
+ rec.ar_extcount = rtend - start + 1;
error = fn(mp, tp, &rec, priv);
if (error)
break;
}
- rtstart = rtend + 1;
+ start = rtend + 1;
}
xfs_rtbuf_cache_relse(&args);
@@ -1107,13 +1104,8 @@ xfs_rtalloc_query_all(
xfs_rtalloc_query_range_fn fn,
void *priv)
{
- struct xfs_rtalloc_rec keys[2];
-
- keys[0].ar_startext = 0;
- keys[1].ar_startext = mp->m_sb.sb_rextents - 1;
- keys[0].ar_extcount = keys[1].ar_extcount = 0;
-
- return xfs_rtalloc_query_range(mp, tp, &keys[0], &keys[1], fn, priv);
+ return xfs_rtalloc_query_range(mp, tp, 0, mp->m_sb.sb_rextents - 1, fn,
+ priv);
}
/* Is the given extent all free? */
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 69ddacd4b01e6f..0dbc9bb40668a2 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -292,8 +292,7 @@ int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log,
int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxlen_t len);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
- const struct xfs_rtalloc_rec *low_rec,
- const struct xfs_rtalloc_rec *high_rec,
+ xfs_rtxnum_t start, xfs_rtxnum_t end,
xfs_rtalloc_query_range_fn fn, void *priv);
int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtalloc_query_range_fn fn,
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 17/37] xfs: clean up the ISVALID macro in xfs_bmap_adjacent
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (15 preceding siblings ...)
2024-10-21 22:03 ` [PATCH 16/37] xfs: simplify xfs_rtalloc_query_range Darrick J. Wong
@ 2024-10-21 22:03 ` Darrick J. Wong
2024-10-21 22:03 ` [PATCH 18/37] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount Darrick J. Wong
` (19 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:03 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_bmap.c | 55 +++++++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 23 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 1f63dc775ea393..e2267aa1a11d4e 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -3106,6 +3106,23 @@ xfs_bmap_extsize_align(
return 0;
}
+static inline bool
+xfs_bmap_adjacent_valid(
+ struct xfs_bmalloca *ap,
+ xfs_fsblock_t x,
+ xfs_fsblock_t y)
+{
+ struct xfs_mount *mp = ap->ip->i_mount;
+
+ if (XFS_IS_REALTIME_INODE(ap->ip) &&
+ (ap->datatype & XFS_ALLOC_USERDATA))
+ return x < mp->m_sb.sb_rblocks;
+
+ return XFS_FSB_TO_AGNO(mp, x) == XFS_FSB_TO_AGNO(mp, y) &&
+ XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount &&
+ XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks;
+}
+
#define XFS_ALLOC_GAP_UNITS 4
/* returns true if ap->blkno was modified */
@@ -3113,36 +3130,25 @@ bool
xfs_bmap_adjacent(
struct xfs_bmalloca *ap) /* bmap alloc argument struct */
{
- xfs_fsblock_t adjust; /* adjustment to block numbers */
- xfs_mount_t *mp; /* mount point structure */
- int rt; /* true if inode is realtime */
+ xfs_fsblock_t adjust; /* adjustment to block numbers */
-#define ISVALID(x,y) \
- (rt ? \
- (x) < mp->m_sb.sb_rblocks : \
- XFS_FSB_TO_AGNO(mp, x) == XFS_FSB_TO_AGNO(mp, y) && \
- XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount && \
- XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks)
-
- mp = ap->ip->i_mount;
- rt = XFS_IS_REALTIME_INODE(ap->ip) &&
- (ap->datatype & XFS_ALLOC_USERDATA);
/*
* If allocating at eof, and there's a previous real block,
* try to use its last block as our starting point.
*/
if (ap->eof && ap->prev.br_startoff != NULLFILEOFF &&
!isnullstartblock(ap->prev.br_startblock) &&
- ISVALID(ap->prev.br_startblock + ap->prev.br_blockcount,
- ap->prev.br_startblock)) {
+ xfs_bmap_adjacent_valid(ap,
+ ap->prev.br_startblock + ap->prev.br_blockcount,
+ ap->prev.br_startblock)) {
ap->blkno = ap->prev.br_startblock + ap->prev.br_blockcount;
/*
* Adjust for the gap between prevp and us.
*/
adjust = ap->offset -
(ap->prev.br_startoff + ap->prev.br_blockcount);
- if (adjust &&
- ISVALID(ap->blkno + adjust, ap->prev.br_startblock))
+ if (adjust && xfs_bmap_adjacent_valid(ap, ap->blkno + adjust,
+ ap->prev.br_startblock))
ap->blkno += adjust;
return true;
}
@@ -3165,7 +3171,8 @@ xfs_bmap_adjacent(
!isnullstartblock(ap->prev.br_startblock) &&
(prevbno = ap->prev.br_startblock +
ap->prev.br_blockcount) &&
- ISVALID(prevbno, ap->prev.br_startblock)) {
+ xfs_bmap_adjacent_valid(ap, prevbno,
+ ap->prev.br_startblock)) {
/*
* Calculate gap to end of previous block.
*/
@@ -3181,8 +3188,8 @@ xfs_bmap_adjacent(
* number, then just use the end of the previous block.
*/
if (prevdiff <= XFS_ALLOC_GAP_UNITS * ap->length &&
- ISVALID(prevbno + prevdiff,
- ap->prev.br_startblock))
+ xfs_bmap_adjacent_valid(ap, prevbno + prevdiff,
+ ap->prev.br_startblock))
prevbno += adjust;
else
prevdiff += adjust;
@@ -3214,9 +3221,11 @@ xfs_bmap_adjacent(
* offset by our length.
*/
if (gotdiff <= XFS_ALLOC_GAP_UNITS * ap->length &&
- ISVALID(gotbno - gotdiff, gotbno))
+ xfs_bmap_adjacent_valid(ap, gotbno - gotdiff,
+ gotbno))
gotbno -= adjust;
- else if (ISVALID(gotbno - ap->length, gotbno)) {
+ else if (xfs_bmap_adjacent_valid(ap, gotbno - ap->length,
+ gotbno)) {
gotbno -= ap->length;
gotdiff += adjust - ap->length;
} else
@@ -3244,7 +3253,7 @@ xfs_bmap_adjacent(
return true;
}
}
-#undef ISVALID
+
return false;
}
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 18/37] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (16 preceding siblings ...)
2024-10-21 22:03 ` [PATCH 17/37] xfs: clean up the ISVALID macro in xfs_bmap_adjacent Darrick J. Wong
@ 2024-10-21 22:03 ` Darrick J. Wong
2024-10-21 22:03 ` [PATCH 19/37] xfs: replace m_rsumsize with m_rsumblocks Darrick J. Wong
` (18 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:03 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
db/check.c | 3 +--
libxfs/xfs_rtbitmap.c | 31 -------------------------------
libxfs/xfs_rtbitmap.h | 7 -------
repair/rt.c | 5 ++---
4 files changed, 3 insertions(+), 43 deletions(-)
diff --git a/db/check.c b/db/check.c
index bceaf318d75ed8..00ef3c1d4b508c 100644
--- a/db/check.c
+++ b/db/check.c
@@ -1958,8 +1958,7 @@ init(
dbmap[c] = xcalloc(mp->m_sb.sb_rblocks, sizeof(**dbmap));
inomap[c] = xcalloc(mp->m_sb.sb_rblocks, sizeof(**inomap));
- words = libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
- mp->m_sb.sb_rbmblocks);
+ words = mp->m_rsumsize >> XFS_WORDLOG;
sumfile = xcalloc(words, sizeof(union xfs_suminfo_raw));
sumcompute = xcalloc(words, sizeof(union xfs_suminfo_raw));
}
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 3f534a4724a26b..1c657da907132e 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1146,21 +1146,6 @@ xfs_rtbitmap_blockcount(
return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
}
-/*
- * Compute the number of rtbitmap words needed to populate every block of a
- * bitmap that is large enough to track the given number of rt extents.
- */
-unsigned long long
-xfs_rtbitmap_wordcount(
- struct xfs_mount *mp,
- xfs_rtbxlen_t rtextents)
-{
- xfs_filblks_t blocks;
-
- blocks = xfs_rtbitmap_blockcount(mp, rtextents);
- return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
-}
-
/* Compute the number of rtsummary blocks needed to track the given rt space. */
xfs_filblks_t
xfs_rtsummary_blockcount(
@@ -1174,22 +1159,6 @@ xfs_rtsummary_blockcount(
return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
}
-/*
- * Compute the number of rtsummary info words needed to populate every block of
- * a summary file that is large enough to track the given rt space.
- */
-unsigned long long
-xfs_rtsummary_wordcount(
- struct xfs_mount *mp,
- unsigned int rsumlevels,
- xfs_extlen_t rbmblocks)
-{
- xfs_filblks_t blocks;
-
- blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
- return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
-}
-
/* Lock both realtime free space metadata inodes for a freespace update. */
void
xfs_rtbitmap_lock(
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 0dbc9bb40668a2..140513d1d6bcf1 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -316,13 +316,8 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
rtextents);
-unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
- xfs_rtbxlen_t rtextents);
-
xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
unsigned int rsumlevels, xfs_extlen_t rbmblocks);
-unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
- unsigned int rsumlevels, xfs_extlen_t rbmblocks);
int xfs_rtfile_initialize_blocks(struct xfs_inode *ip,
xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb, void *data);
@@ -355,9 +350,7 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
/* shut up gcc */
return 0;
}
-# define xfs_rtbitmap_wordcount(mp, r) (0)
# define xfs_rtsummary_blockcount(mp, l, b) (0)
-# define xfs_rtsummary_wordcount(mp, l, b) (0)
# define xfs_rtbitmap_lock(mp) do { } while (0)
# define xfs_rtbitmap_trans_join(tp) do { } while (0)
# define xfs_rtbitmap_unlock(mp) do { } while (0)
diff --git a/repair/rt.c b/repair/rt.c
index 4c81e2114c7735..879946ab0b154e 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -27,14 +27,13 @@ rtinit(xfs_mount_t *mp)
* information. The rtbitmap buffer must be large enough to compare
* against any unused bytes in the last block of the file.
*/
- wordcnt = libxfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
+ wordcnt = XFS_FSB_TO_B(mp, mp->m_sb.sb_rbmblocks) >> XFS_WORDLOG;
btmcompute = calloc(wordcnt, sizeof(union xfs_rtword_raw));
if (!btmcompute)
do_error(
_("couldn't allocate memory for incore realtime bitmap.\n"));
- wordcnt = libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
- mp->m_sb.sb_rbmblocks);
+ wordcnt = mp->m_rsumsize >> XFS_WORDLOG;
sumcompute = calloc(wordcnt, sizeof(union xfs_suminfo_raw));
if (!sumcompute)
do_error(
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 19/37] xfs: replace m_rsumsize with m_rsumblocks
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (17 preceding siblings ...)
2024-10-21 22:03 ` [PATCH 18/37] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount Darrick J. Wong
@ 2024-10-21 22:03 ` Darrick J. Wong
2024-10-21 22:04 ` [PATCH 20/37] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc Darrick J. Wong
` (17 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:03 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
db/check.c | 2 +-
include/xfs_mount.h | 2 +-
libxfs/init.c | 4 +---
libxfs/xfs_rtbitmap.c | 2 +-
libxfs/xfs_trans_resv.c | 2 +-
mkfs/proto.c | 12 +++++-------
repair/dinode.c | 7 ++++---
repair/phase6.c | 16 ++++++----------
repair/rt.c | 4 ++--
9 files changed, 22 insertions(+), 29 deletions(-)
diff --git a/db/check.c b/db/check.c
index 00ef3c1d4b508c..0e91fded0c4236 100644
--- a/db/check.c
+++ b/db/check.c
@@ -1958,7 +1958,7 @@ init(
dbmap[c] = xcalloc(mp->m_sb.sb_rblocks, sizeof(**dbmap));
inomap[c] = xcalloc(mp->m_sb.sb_rblocks, sizeof(**inomap));
- words = mp->m_rsumsize >> XFS_WORDLOG;
+ words = XFS_FSB_TO_B(mp, mp->m_rsumblocks) >> XFS_WORDLOG;
sumfile = xcalloc(words, sizeof(union xfs_suminfo_raw));
sumcompute = xcalloc(words, sizeof(union xfs_suminfo_raw));
}
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index a60474a8db3f22..7571df12fba3f8 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -50,7 +50,7 @@ typedef struct xfs_mount {
xfs_agnumber_t m_maxagi; /* highest inode alloc group */
struct xfs_ino_geometry m_ino_geo; /* inode geometry */
uint m_rsumlevels; /* rt summary levels */
- uint m_rsumsize; /* size of rt summary, bytes */
+ xfs_filblks_t m_rsumblocks; /* size of rt summary, FSBs */
/*
* Optional cache of rt summary level per bitmap block with the
* invariant that m_rsum_cache[bbno] <= the minimum i for which
diff --git a/libxfs/init.c b/libxfs/init.c
index 90a539e04161bb..6ab5ef54bb69cb 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -293,7 +293,6 @@ rtmount_init(
{
struct xfs_buf *bp; /* buffer for last block of subvolume */
xfs_daddr_t d; /* address of last block of subvolume */
- unsigned int rsumblocks;
int error;
if (mp->m_sb.sb_rblocks == 0)
@@ -319,9 +318,8 @@ rtmount_init(
return -1;
}
mp->m_rsumlevels = mp->m_sb.sb_rextslog + 1;
- rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels,
+ mp->m_rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels,
mp->m_sb.sb_rbmblocks);
- mp->m_rsumsize = XFS_FSB_TO_B(mp, rsumblocks);
mp->m_rbmip = mp->m_rsumip = NULL;
/*
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 1c657da907132e..cff3030d1662b7 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -160,7 +160,7 @@ xfs_rtsummary_read_buf(
{
struct xfs_mount *mp = args->mp;
- if (XFS_IS_CORRUPT(mp, block >= XFS_B_TO_FSB(mp, mp->m_rsumsize))) {
+ if (XFS_IS_CORRUPT(mp, block >= mp->m_rsumblocks)) {
xfs_rt_mark_sick(args->mp, XFS_SICK_RT_SUMMARY);
return -EFSCORRUPTED;
}
diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c
index 6b87bf4d554c6a..156f9578d281a0 100644
--- a/libxfs/xfs_trans_resv.c
+++ b/libxfs/xfs_trans_resv.c
@@ -915,7 +915,7 @@ xfs_calc_growrtfree_reservation(
return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
xfs_calc_inode_res(mp, 2) +
xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
- xfs_calc_buf_res(1, mp->m_rsumsize);
+ xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, mp->m_rsumblocks));
}
/*
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 42ac3e10929b52..06010980c5b313 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -813,7 +813,7 @@ rtsummary_create(
{
struct xfs_mount *mp = ip->i_mount;
- ip->i_disk_size = mp->m_rsumsize;
+ ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;
mp->m_sb.sb_rsumino = ip->i_ino;
mp->m_rsumip = ip;
@@ -874,25 +874,23 @@ rtsummary_init(
struct xfs_trans *tp;
struct xfs_bmbt_irec *ep;
xfs_fileoff_t bno;
- xfs_extlen_t nsumblocks;
uint blocks;
int i;
int nmap;
int error;
- nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
- blocks = nsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
+ blocks = mp->m_rsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
if (error)
res_failed(error);
libxfs_trans_ijoin(tp, mp->m_rsumip, 0);
bno = 0;
- while (bno < nsumblocks) {
+ while (bno < mp->m_rsumblocks) {
nmap = XFS_BMAP_MAX_NMAP;
error = -libxfs_bmapi_write(tp, mp->m_rsumip, bno,
- (xfs_extlen_t)(nsumblocks - bno),
- 0, nsumblocks, map, &nmap);
+ (xfs_extlen_t)(mp->m_rsumblocks - bno),
+ 0, mp->m_rsumblocks, map, &nmap);
if (error)
fail(_("Allocation of the realtime summary failed"),
error);
diff --git a/repair/dinode.c b/repair/dinode.c
index e36de9bf1a1be0..aae3cb7a40b981 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -1736,10 +1736,11 @@ _("realtime bitmap inode %" PRIu64 " has bad size %" PRId64 " (should be %" PRIu
break;
case XR_INO_RTSUM:
- if (size != mp->m_rsumsize) {
+ if (size != XFS_FSB_TO_B(mp, mp->m_rsumblocks)) {
do_warn(
-_("realtime summary inode %" PRIu64 " has bad size %" PRId64 " (should be %d)\n"),
- lino, size, mp->m_rsumsize);
+_("realtime summary inode %" PRIu64 " has bad size %" PRIu64 " (should be %" PRIu64 ")\n"),
+ lino, size,
+ XFS_FSB_TO_B(mp, mp->m_rsumblocks));
return 1;
}
break;
diff --git a/repair/phase6.c b/repair/phase6.c
index b48f18b06a5c81..c96b50cf6a69dd 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -633,12 +633,10 @@ fill_rsumino(xfs_mount_t *mp)
int nmap;
int error;
xfs_fileoff_t bno;
- xfs_fileoff_t end_bno;
xfs_bmbt_irec_t map;
smp = sumcompute;
bno = 0;
- end_bno = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
error = -libxfs_trans_alloc_rollable(mp, 10, &tp);
if (error)
@@ -651,7 +649,7 @@ fill_rsumino(xfs_mount_t *mp)
error);
}
- while (bno < end_bno) {
+ while (bno < mp->m_rsumblocks) {
struct xfs_rtalloc_args args = {
.mp = mp,
.tp = tp,
@@ -711,7 +709,6 @@ mk_rsumino(xfs_mount_t *mp)
int i;
int nmap;
int error;
- int nsumblocks;
xfs_fileoff_t bno;
xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP];
uint blocks;
@@ -732,7 +729,7 @@ mk_rsumino(xfs_mount_t *mp)
/* Reset the rt summary inode. */
reset_sbroot_ino(tp, S_IFREG, ip);
- ip->i_disk_size = mp->m_rsumsize;
+ ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;
libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
error = -libxfs_trans_commit(tp);
if (error)
@@ -742,19 +739,18 @@ mk_rsumino(xfs_mount_t *mp)
* then allocate blocks for file and fill with zeroes (stolen
* from mkfs)
*/
- nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
- blocks = nsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
+ blocks = mp->m_rsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
if (error)
res_failed(error);
libxfs_trans_ijoin(tp, ip, 0);
bno = 0;
- while (bno < nsumblocks) {
+ while (bno < mp->m_rsumblocks) {
nmap = XFS_BMAP_MAX_NMAP;
error = -libxfs_bmapi_write(tp, ip, bno,
- (xfs_extlen_t)(nsumblocks - bno),
- 0, nsumblocks, map, &nmap);
+ (xfs_extlen_t)(mp->m_rsumblocks - bno),
+ 0, mp->m_rsumblocks, map, &nmap);
if (error) {
do_error(
_("couldn't allocate realtime summary inode, error = %d\n"),
diff --git a/repair/rt.c b/repair/rt.c
index 879946ab0b154e..721c363cc1dd10 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -33,7 +33,7 @@ rtinit(xfs_mount_t *mp)
do_error(
_("couldn't allocate memory for incore realtime bitmap.\n"));
- wordcnt = mp->m_rsumsize >> XFS_WORDLOG;
+ wordcnt = XFS_FSB_TO_B(mp, mp->m_rsumblocks) >> XFS_WORDLOG;
sumcompute = calloc(wordcnt, sizeof(union xfs_suminfo_raw));
if (!sumcompute)
do_error(
@@ -228,5 +228,5 @@ check_rtsummary(
return;
check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute,
- XFS_B_TO_FSB(mp, mp->m_rsumsize));
+ mp->m_rsumblocks);
}
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 20/37] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (18 preceding siblings ...)
2024-10-21 22:03 ` [PATCH 19/37] xfs: replace m_rsumsize with m_rsumblocks Darrick J. Wong
@ 2024-10-21 22:04 ` Darrick J. Wong
2024-10-21 22:04 ` [PATCH 21/37] xfs: replace shouty XFS_BM{BT,DR} macros Darrick J. Wong
` (16 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:04 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
libxfs/xfs_inode_fork.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c
index cd5e2e72954292..8f06e5bc72b3ac 100644
--- a/libxfs/xfs_inode_fork.c
+++ b/libxfs/xfs_inode_fork.c
@@ -461,15 +461,15 @@ xfs_iroot_realloc(
}
/*
- * Only copy the records and pointers if there are any.
+ * Only copy the keys and pointers if there are any.
*/
if (new_max > 0) {
/*
- * First copy the records.
+ * First copy the keys.
*/
- op = (char *)XFS_BMBT_REC_ADDR(mp, ifp->if_broot, 1);
- np = (char *)XFS_BMBT_REC_ADDR(mp, new_broot, 1);
- memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_rec_t));
+ op = (char *)XFS_BMBT_KEY_ADDR(mp, ifp->if_broot, 1);
+ np = (char *)XFS_BMBT_KEY_ADDR(mp, new_broot, 1);
+ memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_key_t));
/*
* Then copy the pointers.
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 21/37] xfs: replace shouty XFS_BM{BT,DR} macros
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (19 preceding siblings ...)
2024-10-21 22:04 ` [PATCH 20/37] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc Darrick J. Wong
@ 2024-10-21 22:04 ` Darrick J. Wong
2024-10-21 22:04 ` [PATCH 22/37] xfs: standardize the btree maxrecs function parameters Darrick J. Wong
` (15 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:04 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
db/bmap.c | 10 +-
db/bmap_inflate.c | 2
db/bmroot.c | 8 +-
db/check.c | 8 +-
db/frag.c | 8 +-
db/metadump.c | 16 ++--
libxfs/xfs_attr_leaf.c | 8 +-
libxfs/xfs_bmap.c | 40 +++++----
libxfs/xfs_bmap_btree.c | 18 ++--
libxfs/xfs_bmap_btree.h | 204 ++++++++++++++++++++++++++++++++---------------
libxfs/xfs_inode_fork.c | 30 +++----
libxfs/xfs_trans_resv.c | 2
repair/bmap_repair.c | 2
repair/dinode.c | 10 +-
repair/prefetch.c | 8 +-
repair/scan.c | 6 +
16 files changed, 228 insertions(+), 152 deletions(-)
diff --git a/db/bmap.c b/db/bmap.c
index 874135f001ea00..7915772aaee4e0 100644
--- a/db/bmap.c
+++ b/db/bmap.c
@@ -78,8 +78,8 @@ bmap(
push_cur();
rblock = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
fsize = XFS_DFORK_SIZE(dip, mp, whichfork);
- pp = XFS_BMDR_PTR_ADDR(rblock, 1, libxfs_bmdr_maxrecs(fsize, 0));
- kp = XFS_BMDR_KEY_ADDR(rblock, 1);
+ pp = xfs_bmdr_ptr_addr(rblock, 1, libxfs_bmdr_maxrecs(fsize, 0));
+ kp = xfs_bmdr_key_addr(rblock, 1);
bno = select_child(curoffset, kp, pp,
be16_to_cpu(rblock->bb_numrecs));
for (;;) {
@@ -88,9 +88,9 @@ bmap(
block = (struct xfs_btree_block *)iocur_top->data;
if (be16_to_cpu(block->bb_level) == 0)
break;
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1,
+ pp = xfs_bmbt_ptr_addr(mp, block, 1,
libxfs_bmbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0));
- kp = XFS_BMBT_KEY_ADDR(mp, block, 1);
+ kp = xfs_bmbt_key_addr(mp, block, 1);
bno = select_child(curoffset, kp, pp,
be16_to_cpu(block->bb_numrecs));
}
@@ -98,7 +98,7 @@ bmap(
nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib);
nextents = be16_to_cpu(block->bb_numrecs);
xp = (xfs_bmbt_rec_t *)
- XFS_BMBT_REC_ADDR(mp, block, 1);
+ xfs_bmbt_rec_addr(mp, block, 1);
for (ep = xp; ep < &xp[nextents] && n < nex; ep++) {
if (!bmap_one_extent(ep, &curoffset, eoffset,
&n, bep)) {
diff --git a/db/bmap_inflate.c b/db/bmap_inflate.c
index 4de534dccf34b2..1de6d3439ab3d3 100644
--- a/db/bmap_inflate.c
+++ b/db/bmap_inflate.c
@@ -269,7 +269,7 @@ iroot_size(
unsigned int nr_this_level,
void *priv)
{
- return XFS_BMAP_BROOT_SPACE_CALC(cur->bc_mp, nr_this_level);
+ return xfs_bmap_broot_space_calc(cur->bc_mp, nr_this_level);
}
static int
diff --git a/db/bmroot.c b/db/bmroot.c
index 246e390a8a39e7..7ef07da181e6ff 100644
--- a/db/bmroot.c
+++ b/db/bmroot.c
@@ -89,7 +89,7 @@ bmroota_key_offset(
block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
ASSERT(dip->di_forkoff != 0 && (char *)block == XFS_DFORK_APTR(dip));
ASSERT(be16_to_cpu(block->bb_level) > 0);
- kp = XFS_BMDR_KEY_ADDR(block, idx);
+ kp = xfs_bmdr_key_addr(block, idx);
return bitize((int)((char *)kp - (char *)block));
}
@@ -127,7 +127,7 @@ bmroota_ptr_offset(
block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
ASSERT(dip->di_forkoff != 0 && (char *)block == XFS_DFORK_APTR(dip));
ASSERT(be16_to_cpu(block->bb_level) > 0);
- pp = XFS_BMDR_PTR_ADDR(block, idx,
+ pp = xfs_bmdr_ptr_addr(block, idx,
libxfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip, mp), 0));
return bitize((int)((char *)pp - (char *)block));
}
@@ -185,7 +185,7 @@ bmrootd_key_offset(
ASSERT(obj == iocur_top->data);
block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
ASSERT(be16_to_cpu(block->bb_level) > 0);
- kp = XFS_BMDR_KEY_ADDR(block, idx);
+ kp = xfs_bmdr_key_addr(block, idx);
return bitize((int)((char *)kp - (char *)block));
}
@@ -222,7 +222,7 @@ bmrootd_ptr_offset(
dip = obj;
block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
ASSERT(be16_to_cpu(block->bb_level) > 0);
- pp = XFS_BMDR_PTR_ADDR(block, idx,
+ pp = xfs_bmdr_ptr_addr(block, idx,
libxfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip, mp), 0));
return bitize((int)((char *)pp - (char *)block));
}
diff --git a/db/check.c b/db/check.c
index 0e91fded0c4236..0a6e5c3280e1cf 100644
--- a/db/check.c
+++ b/db/check.c
@@ -2321,13 +2321,13 @@ process_btinode(
return;
}
if (be16_to_cpu(dib->bb_level) == 0) {
- xfs_bmbt_rec_t *rp = XFS_BMDR_REC_ADDR(dib, 1);
+ xfs_bmbt_rec_t *rp = xfs_bmdr_rec_addr(dib, 1);
process_bmbt_reclist(rp, be16_to_cpu(dib->bb_numrecs), type,
id, totd, blkmapp);
*nex += be16_to_cpu(dib->bb_numrecs);
return;
} else {
- pp = XFS_BMDR_PTR_ADDR(dib, 1, libxfs_bmdr_maxrecs(
+ pp = xfs_bmdr_ptr_addr(dib, 1, libxfs_bmdr_maxrecs(
XFS_DFORK_SIZE(dip, mp, whichfork), 0));
for (i = 0; i < be16_to_cpu(dib->bb_numrecs); i++)
scan_lbtree(get_unaligned_be64(&pp[i]),
@@ -4357,7 +4357,7 @@ scanfunc_bmap(
error++;
return;
}
- rp = XFS_BMBT_REC_ADDR(mp, block, 1);
+ rp = xfs_bmbt_rec_addr(mp, block, 1);
*nex += be16_to_cpu(block->bb_numrecs);
process_bmbt_reclist(rp, be16_to_cpu(block->bb_numrecs), type, id, totd,
blkmapp);
@@ -4373,7 +4373,7 @@ scanfunc_bmap(
error++;
return;
}
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[0]);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[0]);
for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++)
scan_lbtree(be64_to_cpu(pp[i]), level, scanfunc_bmap, type, id,
totd, toti, nex, blkmapp, 0, btype);
diff --git a/db/frag.c b/db/frag.c
index 4efc6ad07f8752..1165e824a375e7 100644
--- a/db/frag.c
+++ b/db/frag.c
@@ -243,11 +243,11 @@ process_btinode(
dib = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
if (be16_to_cpu(dib->bb_level) == 0) {
- xfs_bmbt_rec_t *rp = XFS_BMDR_REC_ADDR(dib, 1);
+ xfs_bmbt_rec_t *rp = xfs_bmdr_rec_addr(dib, 1);
process_bmbt_reclist(rp, be16_to_cpu(dib->bb_numrecs), extmapp);
return;
}
- pp = XFS_BMDR_PTR_ADDR(dib, 1,
+ pp = xfs_bmdr_ptr_addr(dib, 1,
libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
for (i = 0; i < be16_to_cpu(dib->bb_numrecs); i++)
scan_lbtree(get_unaligned_be64(&pp[i]),
@@ -437,7 +437,7 @@ scanfunc_bmap(
nrecs, typtab[btype].name);
return;
}
- rp = XFS_BMBT_REC_ADDR(mp, block, 1);
+ rp = xfs_bmbt_rec_addr(mp, block, 1);
process_bmbt_reclist(rp, nrecs, extmapp);
return;
}
@@ -447,7 +447,7 @@ scanfunc_bmap(
nrecs, typtab[btype].name);
return;
}
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[0]);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[0]);
for (i = 0; i < nrecs; i++)
scan_lbtree(be64_to_cpu(pp[i]), level, scanfunc_bmap, extmapp,
btype);
diff --git a/db/metadump.c b/db/metadump.c
index 424544f9f03224..5c57c1293a53cb 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -249,8 +249,8 @@ zero_btree_node(
if (nrecs > mp->m_bmap_dmxr[1])
return;
- bkp = XFS_BMBT_KEY_ADDR(mp, block, 1);
- bpp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
+ bkp = xfs_bmbt_key_addr(mp, block, 1);
+ bpp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[1]);
zp1 = (char *)&bkp[nrecs];
zp2 = (char *)&bpp[nrecs];
key_end = (char *)bpp;
@@ -315,7 +315,7 @@ zero_btree_leaf(
if (nrecs > mp->m_bmap_dmxr[0])
return;
- brp = XFS_BMBT_REC_ADDR(mp, block, 1);
+ brp = xfs_bmbt_rec_addr(mp, block, 1);
zp = (char *)&brp[nrecs];
break;
case TYP_INOBT:
@@ -2113,7 +2113,7 @@ scanfunc_bmap(
typtab[btype].name, agno, agbno);
return 1;
}
- return process_bmbt_reclist(XFS_BMBT_REC_ADDR(mp, block, 1),
+ return process_bmbt_reclist(xfs_bmbt_rec_addr(mp, block, 1),
nrecs, *(typnm_t*)arg);
}
@@ -2123,7 +2123,7 @@ scanfunc_bmap(
nrecs, typtab[btype].name, agno, agbno);
return 1;
}
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[1]);
for (i = 0; i < nrecs; i++) {
xfs_agnumber_t ag;
xfs_agblock_t bno;
@@ -2176,7 +2176,7 @@ process_btinode(
}
if (level == 0) {
- return process_bmbt_reclist(XFS_BMDR_REC_ADDR(dib, 1),
+ return process_bmbt_reclist(xfs_bmdr_rec_addr(dib, 1),
nrecs, itype);
}
@@ -2189,13 +2189,13 @@ process_btinode(
return 1;
}
- pp = XFS_BMDR_PTR_ADDR(dib, 1, maxrecs);
+ pp = xfs_bmdr_ptr_addr(dib, 1, maxrecs);
if (metadump.zero_stale_data) {
char *top;
/* Unused btree key space */
- top = (char*)XFS_BMDR_KEY_ADDR(dib, nrecs + 1);
+ top = (char*)xfs_bmdr_key_addr(dib, nrecs + 1);
memset(top, 0, (char*)pp - top);
/* Unused btree ptr space */
diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c
index ce20d81a486988..97b71b6500bdc9 100644
--- a/libxfs/xfs_attr_leaf.c
+++ b/libxfs/xfs_attr_leaf.c
@@ -683,7 +683,7 @@ xfs_attr_shortform_bytesfit(
*/
if (!dp->i_forkoff && dp->i_df.if_bytes >
xfs_default_attroffset(dp))
- dsize = XFS_BMDR_SPACE_CALC(MINDBTPTRS);
+ dsize = xfs_bmdr_space_calc(MINDBTPTRS);
break;
case XFS_DINODE_FMT_BTREE:
/*
@@ -697,7 +697,7 @@ xfs_attr_shortform_bytesfit(
return 0;
return dp->i_forkoff;
}
- dsize = XFS_BMAP_BROOT_SPACE(mp, dp->i_df.if_broot);
+ dsize = xfs_bmap_bmdr_space(dp->i_df.if_broot);
break;
}
@@ -705,11 +705,11 @@ xfs_attr_shortform_bytesfit(
* A data fork btree root must have space for at least
* MINDBTPTRS key/ptr pairs if the data fork is small or empty.
*/
- minforkoff = max_t(int64_t, dsize, XFS_BMDR_SPACE_CALC(MINDBTPTRS));
+ minforkoff = max_t(int64_t, dsize, xfs_bmdr_space_calc(MINDBTPTRS));
minforkoff = roundup(minforkoff, 8) >> 3;
/* attr fork btree root can have at least this many key/ptr pairs */
- maxforkoff = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
+ maxforkoff = XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS);
maxforkoff = maxforkoff >> 3; /* rounded down */
if (offset >= maxforkoff)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index e2267aa1a11d4e..a85a75da954c4e 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -73,9 +73,9 @@ xfs_bmap_compute_maxlevels(
maxleafents = xfs_iext_max_nextents(xfs_has_large_extent_counts(mp),
whichfork);
if (whichfork == XFS_DATA_FORK)
- sz = XFS_BMDR_SPACE_CALC(MINDBTPTRS);
+ sz = xfs_bmdr_space_calc(MINDBTPTRS);
else
- sz = XFS_BMDR_SPACE_CALC(MINABTPTRS);
+ sz = xfs_bmdr_space_calc(MINABTPTRS);
maxrootrecs = xfs_bmdr_maxrecs(sz, 0);
minleafrecs = mp->m_bmap_dmnr[0];
@@ -96,8 +96,8 @@ xfs_bmap_compute_attr_offset(
struct xfs_mount *mp)
{
if (mp->m_sb.sb_inodesize == 256)
- return XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
- return XFS_BMDR_SPACE_CALC(6 * MINABTPTRS);
+ return XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS);
+ return xfs_bmdr_space_calc(6 * MINABTPTRS);
}
STATIC int /* error */
@@ -292,7 +292,7 @@ xfs_check_block(
prevp = NULL;
for( i = 1; i <= xfs_btree_get_numrecs(block); i++) {
dmxr = mp->m_bmap_dmxr[0];
- keyp = XFS_BMBT_KEY_ADDR(mp, block, i);
+ keyp = xfs_bmbt_key_addr(mp, block, i);
if (prevp) {
ASSERT(be64_to_cpu(prevp->br_startoff) <
@@ -304,15 +304,15 @@ xfs_check_block(
* Compare the block numbers to see if there are dups.
*/
if (root)
- pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, i, sz);
+ pp = xfs_bmap_broot_ptr_addr(mp, block, i, sz);
else
- pp = XFS_BMBT_PTR_ADDR(mp, block, i, dmxr);
+ pp = xfs_bmbt_ptr_addr(mp, block, i, dmxr);
for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) {
if (root)
- thispa = XFS_BMAP_BROOT_PTR_ADDR(mp, block, j, sz);
+ thispa = xfs_bmap_broot_ptr_addr(mp, block, j, sz);
else
- thispa = XFS_BMBT_PTR_ADDR(mp, block, j, dmxr);
+ thispa = xfs_bmbt_ptr_addr(mp, block, j, dmxr);
if (*thispa == *pp) {
xfs_warn(mp, "%s: thispa(%d) == pp(%d) %lld",
__func__, j, i,
@@ -367,7 +367,7 @@ xfs_bmap_check_leaf_extents(
level = be16_to_cpu(block->bb_level);
ASSERT(level > 0);
xfs_check_block(block, mp, 1, ifp->if_broot_bytes);
- pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes);
+ pp = xfs_bmap_broot_ptr_addr(mp, block, 1, ifp->if_broot_bytes);
bno = be64_to_cpu(*pp);
ASSERT(bno != NULLFSBLOCK);
@@ -400,7 +400,7 @@ xfs_bmap_check_leaf_extents(
*/
xfs_check_block(block, mp, 0, 0);
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[1]);
bno = be64_to_cpu(*pp);
if (XFS_IS_CORRUPT(mp, !xfs_verify_fsbno(mp, bno))) {
xfs_btree_mark_sick(cur);
@@ -440,14 +440,14 @@ xfs_bmap_check_leaf_extents(
* conform with the first entry in this one.
*/
- ep = XFS_BMBT_REC_ADDR(mp, block, 1);
+ ep = xfs_bmbt_rec_addr(mp, block, 1);
if (i) {
ASSERT(xfs_bmbt_disk_get_startoff(&last) +
xfs_bmbt_disk_get_blockcount(&last) <=
xfs_bmbt_disk_get_startoff(ep));
}
for (j = 1; j < num_recs; j++) {
- nextp = XFS_BMBT_REC_ADDR(mp, block, j + 1);
+ nextp = xfs_bmbt_rec_addr(mp, block, j + 1);
ASSERT(xfs_bmbt_disk_get_startoff(ep) +
xfs_bmbt_disk_get_blockcount(ep) <=
xfs_bmbt_disk_get_startoff(nextp));
@@ -580,7 +580,7 @@ xfs_bmap_btree_to_extents(
ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1);
ASSERT(xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0) == 1);
- pp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, ifp->if_broot_bytes);
+ pp = xfs_bmap_broot_ptr_addr(mp, rblock, 1, ifp->if_broot_bytes);
cbno = be64_to_cpu(*pp);
#ifdef DEBUG
if (XFS_IS_CORRUPT(cur->bc_mp, !xfs_verify_fsbno(mp, cbno))) {
@@ -708,7 +708,7 @@ xfs_bmap_extents_to_btree(
for_each_xfs_iext(ifp, &icur, &rec) {
if (isnullstartblock(rec.br_startblock))
continue;
- arp = XFS_BMBT_REC_ADDR(mp, ablock, 1 + cnt);
+ arp = xfs_bmbt_rec_addr(mp, ablock, 1 + cnt);
xfs_bmbt_disk_set_all(arp, &rec);
cnt++;
}
@@ -718,10 +718,10 @@ xfs_bmap_extents_to_btree(
/*
* Fill in the root key and pointer.
*/
- kp = XFS_BMBT_KEY_ADDR(mp, block, 1);
- arp = XFS_BMBT_REC_ADDR(mp, ablock, 1);
+ kp = xfs_bmbt_key_addr(mp, block, 1);
+ arp = xfs_bmbt_rec_addr(mp, ablock, 1);
kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp));
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, xfs_bmbt_get_maxrecs(cur,
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, xfs_bmbt_get_maxrecs(cur,
be16_to_cpu(block->bb_level)));
*pp = cpu_to_be64(args.fsbno);
@@ -890,7 +890,7 @@ xfs_bmap_add_attrfork_btree(
mp = ip->i_mount;
- if (XFS_BMAP_BMDR_SPACE(block) <= xfs_inode_data_fork_size(ip))
+ if (xfs_bmap_bmdr_space(block) <= xfs_inode_data_fork_size(ip))
*flags |= XFS_ILOG_DBROOT;
else {
cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK);
@@ -1154,7 +1154,7 @@ xfs_iread_bmbt_block(
}
/* Copy records into the incore cache. */
- frp = XFS_BMBT_REC_ADDR(mp, block, 1);
+ frp = xfs_bmbt_rec_addr(mp, block, 1);
for (j = 0; j < num_recs; j++, frp++, ir->loaded++) {
struct xfs_bmbt_irec new;
xfs_failaddr_t fa;
diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c
index a14ca35953d735..cac644c8ce35a5 100644
--- a/libxfs/xfs_bmap_btree.c
+++ b/libxfs/xfs_bmap_btree.c
@@ -64,10 +64,10 @@ xfs_bmdr_to_bmbt(
ASSERT(be16_to_cpu(rblock->bb_level) > 0);
rblock->bb_numrecs = dblock->bb_numrecs;
dmxr = xfs_bmdr_maxrecs(dblocklen, 0);
- fkp = XFS_BMDR_KEY_ADDR(dblock, 1);
- tkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
- fpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
- tpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
+ fkp = xfs_bmdr_key_addr(dblock, 1);
+ tkp = xfs_bmbt_key_addr(mp, rblock, 1);
+ fpp = xfs_bmdr_ptr_addr(dblock, 1, dmxr);
+ tpp = xfs_bmap_broot_ptr_addr(mp, rblock, 1, rblocklen);
dmxr = be16_to_cpu(dblock->bb_numrecs);
memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
@@ -167,10 +167,10 @@ xfs_bmbt_to_bmdr(
dblock->bb_level = rblock->bb_level;
dblock->bb_numrecs = rblock->bb_numrecs;
dmxr = xfs_bmdr_maxrecs(dblocklen, 0);
- fkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
- tkp = XFS_BMDR_KEY_ADDR(dblock, 1);
- fpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
- tpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
+ fkp = xfs_bmbt_key_addr(mp, rblock, 1);
+ tkp = xfs_bmdr_key_addr(dblock, 1);
+ fpp = xfs_bmap_broot_ptr_addr(mp, rblock, 1, rblocklen);
+ tpp = xfs_bmdr_ptr_addr(dblock, 1, dmxr);
dmxr = be16_to_cpu(dblock->bb_numrecs);
memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
@@ -650,7 +650,7 @@ xfs_bmbt_maxrecs(
int blocklen,
int leaf)
{
- blocklen -= XFS_BMBT_BLOCK_LEN(mp);
+ blocklen -= xfs_bmbt_block_len(mp);
return xfs_bmbt_block_maxrecs(blocklen, leaf);
}
diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h
index de1b73f1225ca7..d006798d591bc2 100644
--- a/libxfs/xfs_bmap_btree.h
+++ b/libxfs/xfs_bmap_btree.h
@@ -13,70 +13,6 @@ struct xfs_inode;
struct xfs_trans;
struct xbtree_ifakeroot;
-/*
- * Btree block header size depends on a superblock flag.
- */
-#define XFS_BMBT_BLOCK_LEN(mp) \
- (xfs_has_crc(((mp))) ? \
- XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)
-
-#define XFS_BMBT_REC_ADDR(mp, block, index) \
- ((xfs_bmbt_rec_t *) \
- ((char *)(block) + \
- XFS_BMBT_BLOCK_LEN(mp) + \
- ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
-
-#define XFS_BMBT_KEY_ADDR(mp, block, index) \
- ((xfs_bmbt_key_t *) \
- ((char *)(block) + \
- XFS_BMBT_BLOCK_LEN(mp) + \
- ((index) - 1) * sizeof(xfs_bmbt_key_t)))
-
-#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
- ((xfs_bmbt_ptr_t *) \
- ((char *)(block) + \
- XFS_BMBT_BLOCK_LEN(mp) + \
- (maxrecs) * sizeof(xfs_bmbt_key_t) + \
- ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
-
-#define XFS_BMDR_REC_ADDR(block, index) \
- ((xfs_bmdr_rec_t *) \
- ((char *)(block) + \
- sizeof(struct xfs_bmdr_block) + \
- ((index) - 1) * sizeof(xfs_bmdr_rec_t)))
-
-#define XFS_BMDR_KEY_ADDR(block, index) \
- ((xfs_bmdr_key_t *) \
- ((char *)(block) + \
- sizeof(struct xfs_bmdr_block) + \
- ((index) - 1) * sizeof(xfs_bmdr_key_t)))
-
-#define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
- ((xfs_bmdr_ptr_t *) \
- ((char *)(block) + \
- sizeof(struct xfs_bmdr_block) + \
- (maxrecs) * sizeof(xfs_bmdr_key_t) + \
- ((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
-
-/*
- * These are to be used when we know the size of the block and
- * we don't have a cursor.
- */
-#define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \
- XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0))
-
-#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
- (int)(XFS_BMBT_BLOCK_LEN(mp) + \
- ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
-
-#define XFS_BMAP_BROOT_SPACE(mp, bb) \
- (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
-#define XFS_BMDR_SPACE_CALC(nrecs) \
- (int)(sizeof(xfs_bmdr_block_t) + \
- ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
-#define XFS_BMAP_BMDR_SPACE(bb) \
- (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
-
/*
* Maximum number of bmap btree levels.
*/
@@ -121,4 +57,144 @@ void xfs_bmbt_destroy_cur_cache(void);
void xfs_bmbt_init_block(struct xfs_inode *ip, struct xfs_btree_block *buf,
struct xfs_buf *bp, __u16 level, __u16 numrecs);
+/*
+ * Btree block header size depends on a superblock flag.
+ */
+static inline size_t
+xfs_bmbt_block_len(struct xfs_mount *mp)
+{
+ return xfs_has_crc(mp) ?
+ XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN;
+}
+
+/* Addresses of key, pointers, and records within an incore bmbt block. */
+
+static inline struct xfs_bmbt_rec *
+xfs_bmbt_rec_addr(
+ struct xfs_mount *mp,
+ struct xfs_btree_block *block,
+ unsigned int index)
+{
+ return (struct xfs_bmbt_rec *)
+ ((char *)block + xfs_bmbt_block_len(mp) +
+ (index - 1) * sizeof(struct xfs_bmbt_rec));
+}
+
+static inline struct xfs_bmbt_key *
+xfs_bmbt_key_addr(
+ struct xfs_mount *mp,
+ struct xfs_btree_block *block,
+ unsigned int index)
+{
+ return (struct xfs_bmbt_key *)
+ ((char *)block + xfs_bmbt_block_len(mp) +
+ (index - 1) * sizeof(struct xfs_bmbt_key *));
+}
+
+static inline xfs_bmbt_ptr_t *
+xfs_bmbt_ptr_addr(
+ struct xfs_mount *mp,
+ struct xfs_btree_block *block,
+ unsigned int index,
+ unsigned int maxrecs)
+{
+ return (xfs_bmbt_ptr_t *)
+ ((char *)block + xfs_bmbt_block_len(mp) +
+ maxrecs * sizeof(struct xfs_bmbt_key) +
+ (index - 1) * sizeof(xfs_bmbt_ptr_t));
+}
+
+/* Addresses of key, pointers, and records within an ondisk bmbt block. */
+
+static inline struct xfs_bmbt_rec *
+xfs_bmdr_rec_addr(
+ struct xfs_bmdr_block *block,
+ unsigned int index)
+{
+ return (struct xfs_bmbt_rec *)
+ ((char *)(block + 1) +
+ (index - 1) * sizeof(struct xfs_bmbt_rec));
+}
+
+static inline struct xfs_bmbt_key *
+xfs_bmdr_key_addr(
+ struct xfs_bmdr_block *block,
+ unsigned int index)
+{
+ return (struct xfs_bmbt_key *)
+ ((char *)(block + 1) +
+ (index - 1) * sizeof(struct xfs_bmbt_key));
+}
+
+static inline xfs_bmbt_ptr_t *
+xfs_bmdr_ptr_addr(
+ struct xfs_bmdr_block *block,
+ unsigned int index,
+ unsigned int maxrecs)
+{
+ return (xfs_bmbt_ptr_t *)
+ ((char *)(block + 1) +
+ maxrecs * sizeof(struct xfs_bmbt_key) +
+ (index - 1) * sizeof(xfs_bmbt_ptr_t));
+}
+
+/*
+ * Address of pointers within the incore btree root.
+ *
+ * These are to be used when we know the size of the block and
+ * we don't have a cursor.
+ */
+static inline xfs_bmbt_ptr_t *
+xfs_bmap_broot_ptr_addr(
+ struct xfs_mount *mp,
+ struct xfs_btree_block *bb,
+ unsigned int i,
+ unsigned int sz)
+{
+ return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0));
+}
+
+/*
+ * Compute the space required for the incore btree root containing the given
+ * number of records.
+ */
+static inline size_t
+xfs_bmap_broot_space_calc(
+ struct xfs_mount *mp,
+ unsigned int nrecs)
+{
+ return xfs_bmbt_block_len(mp) +
+ (nrecs * (sizeof(struct xfs_bmbt_key) + sizeof(xfs_bmbt_ptr_t)));
+}
+
+/*
+ * Compute the space required for the incore btree root given the ondisk
+ * btree root block.
+ */
+static inline size_t
+xfs_bmap_broot_space(
+ struct xfs_mount *mp,
+ struct xfs_bmdr_block *bb)
+{
+ return xfs_bmap_broot_space_calc(mp, be16_to_cpu(bb->bb_numrecs));
+}
+
+/* Compute the space required for the ondisk root block. */
+static inline size_t
+xfs_bmdr_space_calc(unsigned int nrecs)
+{
+ return sizeof(struct xfs_bmdr_block) +
+ (nrecs * (sizeof(struct xfs_bmbt_key) + sizeof(xfs_bmbt_ptr_t)));
+}
+
+/*
+ * Compute the space required for the ondisk root block given an incore root
+ * block.
+ */
+static inline size_t
+xfs_bmap_bmdr_space(struct xfs_btree_block *bb)
+{
+ return xfs_bmdr_space_calc(be16_to_cpu(bb->bb_numrecs));
+}
+
#endif /* __XFS_BMAP_BTREE_H__ */
diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c
index 8f06e5bc72b3ac..fd79da64e43a8d 100644
--- a/libxfs/xfs_inode_fork.c
+++ b/libxfs/xfs_inode_fork.c
@@ -183,7 +183,7 @@ xfs_iformat_btree(
ifp = xfs_ifork_ptr(ip, whichfork);
dfp = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
- size = XFS_BMAP_BROOT_SPACE(mp, dfp);
+ size = xfs_bmap_broot_space(mp, dfp);
nrecs = be16_to_cpu(dfp->bb_numrecs);
level = be16_to_cpu(dfp->bb_level);
@@ -196,7 +196,7 @@ xfs_iformat_btree(
*/
if (unlikely(ifp->if_nextents <= XFS_IFORK_MAXEXT(ip, whichfork) ||
nrecs == 0 ||
- XFS_BMDR_SPACE_CALC(nrecs) >
+ xfs_bmdr_space_calc(nrecs) >
XFS_DFORK_SIZE(dip, mp, whichfork) ||
ifp->if_nextents > ip->i_nblocks) ||
level == 0 || level > XFS_BM_MAXLEVELS(mp, whichfork)) {
@@ -407,7 +407,7 @@ xfs_iroot_realloc(
* allocate it now and get out.
*/
if (ifp->if_broot_bytes == 0) {
- new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, rec_diff);
+ new_size = xfs_bmap_broot_space_calc(mp, rec_diff);
ifp->if_broot = kmalloc(new_size,
GFP_KERNEL | __GFP_NOFAIL);
ifp->if_broot_bytes = (int)new_size;
@@ -422,15 +422,15 @@ xfs_iroot_realloc(
*/
cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0);
new_max = cur_max + rec_diff;
- new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max);
+ new_size = xfs_bmap_broot_space_calc(mp, new_max);
ifp->if_broot = krealloc(ifp->if_broot, new_size,
GFP_KERNEL | __GFP_NOFAIL);
- op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
+ op = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
ifp->if_broot_bytes);
- np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
+ np = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
(int)new_size);
ifp->if_broot_bytes = (int)new_size;
- ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
+ ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
xfs_inode_fork_size(ip, whichfork));
memmove(np, op, cur_max * (uint)sizeof(xfs_fsblock_t));
return;
@@ -446,7 +446,7 @@ xfs_iroot_realloc(
new_max = cur_max + rec_diff;
ASSERT(new_max >= 0);
if (new_max > 0)
- new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max);
+ new_size = xfs_bmap_broot_space_calc(mp, new_max);
else
new_size = 0;
if (new_size > 0) {
@@ -455,7 +455,7 @@ xfs_iroot_realloc(
* First copy over the btree block header.
*/
memcpy(new_broot, ifp->if_broot,
- XFS_BMBT_BLOCK_LEN(ip->i_mount));
+ xfs_bmbt_block_len(ip->i_mount));
} else {
new_broot = NULL;
}
@@ -467,16 +467,16 @@ xfs_iroot_realloc(
/*
* First copy the keys.
*/
- op = (char *)XFS_BMBT_KEY_ADDR(mp, ifp->if_broot, 1);
- np = (char *)XFS_BMBT_KEY_ADDR(mp, new_broot, 1);
+ op = (char *)xfs_bmbt_key_addr(mp, ifp->if_broot, 1);
+ np = (char *)xfs_bmbt_key_addr(mp, new_broot, 1);
memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_key_t));
/*
* Then copy the pointers.
*/
- op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
+ op = (char *)xfs_bmap_broot_ptr_addr(mp, ifp->if_broot, 1,
ifp->if_broot_bytes);
- np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, new_broot, 1,
+ np = (char *)xfs_bmap_broot_ptr_addr(mp, new_broot, 1,
(int)new_size);
memcpy(np, op, new_max * (uint)sizeof(xfs_fsblock_t));
}
@@ -484,7 +484,7 @@ xfs_iroot_realloc(
ifp->if_broot = new_broot;
ifp->if_broot_bytes = (int)new_size;
if (ifp->if_broot)
- ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
+ ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
xfs_inode_fork_size(ip, whichfork));
return;
}
@@ -653,7 +653,7 @@ xfs_iflush_fork(
if ((iip->ili_fields & brootflag[whichfork]) &&
(ifp->if_broot_bytes > 0)) {
ASSERT(ifp->if_broot != NULL);
- ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
+ ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
xfs_inode_fork_size(ip, whichfork));
xfs_bmbt_to_bmdr(mp, ifp->if_broot, ifp->if_broot_bytes,
(xfs_bmdr_block_t *)cp,
diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c
index 156f9578d281a0..3da18fb4027420 100644
--- a/libxfs/xfs_trans_resv.c
+++ b/libxfs/xfs_trans_resv.c
@@ -127,7 +127,7 @@ xfs_calc_inode_res(
(4 * sizeof(struct xlog_op_header) +
sizeof(struct xfs_inode_log_format) +
mp->m_sb.sb_inodesize +
- 2 * XFS_BMBT_BLOCK_LEN(mp));
+ 2 * xfs_bmbt_block_len(mp));
}
/*
diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c
index 317061aa564f56..b341caf627d5fd 100644
--- a/repair/bmap_repair.c
+++ b/repair/bmap_repair.c
@@ -284,7 +284,7 @@ xrep_bmap_iroot_size(
{
ASSERT(level > 0);
- return XFS_BMAP_BROOT_SPACE_CALC(cur->bc_mp, nr_this_level);
+ return xfs_bmap_broot_space_calc(cur->bc_mp, nr_this_level);
}
/* Update the inode counters. */
diff --git a/repair/dinode.c b/repair/dinode.c
index aae3cb7a40b981..ac81c487a20b8a 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -809,19 +809,19 @@ _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
/*
* use bmdr/dfork_dsize since the root block is in the data fork
*/
- if (XFS_BMDR_SPACE_CALC(numrecs) > XFS_DFORK_SIZE(dip, mp, whichfork)) {
+ if (xfs_bmdr_space_calc(numrecs) > XFS_DFORK_SIZE(dip, mp, whichfork)) {
do_warn(
- _("indicated size of %s btree root (%d bytes) greater than space in "
+ _("indicated size of %s btree root (%zu bytes) greater than space in "
"inode %" PRIu64 " %s fork\n"),
- forkname, XFS_BMDR_SPACE_CALC(numrecs), lino, forkname);
+ forkname, xfs_bmdr_space_calc(numrecs), lino, forkname);
return(1);
}
init_bm_cursor(&cursor, level + 1);
- pp = XFS_BMDR_PTR_ADDR(dib, 1,
+ pp = xfs_bmdr_ptr_addr(dib, 1,
libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
- pkey = XFS_BMDR_KEY_ADDR(dib, 1);
+ pkey = xfs_bmdr_key_addr(dib, 1);
last_key = NULLFILEOFF;
for (i = 0; i < numrecs; i++) {
diff --git a/repair/prefetch.c b/repair/prefetch.c
index 22efd54bf9ebf3..998797e3696bac 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -328,13 +328,13 @@ pf_scanfunc_bmap(
if (numrecs > mp->m_bmap_dmxr[0] || !isadir)
return 0;
return pf_read_bmbt_reclist(args,
- XFS_BMBT_REC_ADDR(mp, block, 1), numrecs);
+ xfs_bmbt_rec_addr(mp, block, 1), numrecs);
}
if (numrecs > mp->m_bmap_dmxr[1])
return 0;
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[1]);
for (i = 0; i < numrecs; i++) {
dbno = get_unaligned_be64(&pp[i]);
@@ -372,11 +372,11 @@ pf_read_btinode(
/*
* use bmdr/dfork_dsize since the root block is in the data fork
*/
- if (XFS_BMDR_SPACE_CALC(numrecs) > XFS_DFORK_DSIZE(dino, mp))
+ if (xfs_bmdr_space_calc(numrecs) > XFS_DFORK_DSIZE(dino, mp))
return;
dsize = XFS_DFORK_DSIZE(dino, mp);
- pp = XFS_BMDR_PTR_ADDR(dib, 1, libxfs_bmdr_maxrecs(dsize, 0));
+ pp = xfs_bmdr_ptr_addr(dib, 1, libxfs_bmdr_maxrecs(dsize, 0));
for (i = 0; i < numrecs; i++) {
dbno = get_unaligned_be64(&pp[i]);
diff --git a/repair/scan.c b/repair/scan.c
index 8352b3ccff7d7e..b115dd4948b969 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -416,7 +416,7 @@ _("inode %" PRIu64 " bad # of bmap records (%" PRIu64 ", min - %u, max - %u)\n")
mp->m_bmap_dmxr[0]);
return(1);
}
- rp = XFS_BMBT_REC_ADDR(mp, block, 1);
+ rp = xfs_bmbt_rec_addr(mp, block, 1);
*nex += numrecs;
/*
* XXX - if we were going to fix up the btree record,
@@ -466,8 +466,8 @@ _("inode %" PRIu64 " bad # of bmap records (%" PRIu64 ", min - %u, max - %u)\n")
ino, numrecs, mp->m_bmap_dmnr[1], mp->m_bmap_dmxr[1]);
return(1);
}
- pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
- pkey = XFS_BMBT_KEY_ADDR(mp, block, 1);
+ pp = xfs_bmbt_ptr_addr(mp, block, 1, mp->m_bmap_dmxr[1]);
+ pkey = xfs_bmbt_key_addr(mp, block, 1);
last_key = NULLFILEOFF;
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 22/37] xfs: standardize the btree maxrecs function parameters
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (20 preceding siblings ...)
2024-10-21 22:04 ` [PATCH 21/37] xfs: replace shouty XFS_BM{BT,DR} macros Darrick J. Wong
@ 2024-10-21 22:04 ` Darrick J. Wong
2024-10-21 22:04 ` [PATCH 23/37] xfs: use kvmalloc for xattr buffers Darrick J. Wong
` (14 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:04 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Darrick J. Wong <djwong@kernel.org>
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>
---
db/btheight.c | 18 ++++--------------
libxfs/xfs_alloc_btree.c | 6 +++---
libxfs/xfs_alloc_btree.h | 3 ++-
libxfs/xfs_bmap.c | 2 +-
libxfs/xfs_bmap_btree.c | 6 +++---
libxfs/xfs_bmap_btree.h | 5 +++--
libxfs/xfs_ialloc.c | 4 ++--
libxfs/xfs_ialloc_btree.c | 6 +++---
libxfs/xfs_ialloc_btree.h | 3 ++-
libxfs/xfs_inode_fork.c | 4 ++--
libxfs/xfs_refcount_btree.c | 5 +++--
libxfs/xfs_refcount_btree.h | 3 ++-
libxfs/xfs_rmap_btree.c | 7 ++++---
libxfs/xfs_rmap_btree.h | 3 ++-
libxfs/xfs_sb.c | 16 ++++++++--------
repair/phase5.c | 16 ++++++++--------
16 files changed, 52 insertions(+), 55 deletions(-)
diff --git a/db/btheight.c b/db/btheight.c
index 0b421ab50a3a76..6643489c82c4c9 100644
--- a/db/btheight.c
+++ b/db/btheight.c
@@ -12,21 +12,11 @@
#include "input.h"
#include "libfrog/convert.h"
-static int refc_maxrecs(struct xfs_mount *mp, int blocklen, int leaf)
-{
- return libxfs_refcountbt_maxrecs(blocklen, leaf != 0);
-}
-
-static int rmap_maxrecs(struct xfs_mount *mp, int blocklen, int leaf)
-{
- return libxfs_rmapbt_maxrecs(blocklen, leaf);
-}
-
struct btmap {
const char *tag;
unsigned int (*maxlevels)(void);
- int (*maxrecs)(struct xfs_mount *mp, int blocklen,
- int leaf);
+ unsigned int (*maxrecs)(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
} maps[] = {
{
.tag = "bnobt",
@@ -56,12 +46,12 @@ struct btmap {
{
.tag = "refcountbt",
.maxlevels = libxfs_refcountbt_maxlevels_ondisk,
- .maxrecs = refc_maxrecs,
+ .maxrecs = libxfs_refcountbt_maxrecs,
},
{
.tag = "rmapbt",
.maxlevels = libxfs_rmapbt_maxlevels_ondisk,
- .maxrecs = rmap_maxrecs,
+ .maxrecs = libxfs_rmapbt_maxrecs,
},
};
diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c
index 9140dec00645f0..4a711f2463cd30 100644
--- a/libxfs/xfs_alloc_btree.c
+++ b/libxfs/xfs_alloc_btree.c
@@ -567,11 +567,11 @@ xfs_allocbt_block_maxrecs(
/*
* Calculate number of records in an alloc btree block.
*/
-int
+unsigned int
xfs_allocbt_maxrecs(
struct xfs_mount *mp,
- int blocklen,
- int leaf)
+ unsigned int blocklen,
+ bool leaf)
{
blocklen -= XFS_ALLOC_BLOCK_LEN(mp);
return xfs_allocbt_block_maxrecs(blocklen, leaf);
diff --git a/libxfs/xfs_alloc_btree.h b/libxfs/xfs_alloc_btree.h
index 155b47f231ab2f..12647f9aaa6d79 100644
--- a/libxfs/xfs_alloc_btree.h
+++ b/libxfs/xfs_alloc_btree.h
@@ -53,7 +53,8 @@ struct xfs_btree_cur *xfs_bnobt_init_cursor(struct xfs_mount *mp,
struct xfs_btree_cur *xfs_cntbt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_buf *bp,
struct xfs_perag *pag);
-extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
+unsigned int xfs_allocbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
unsigned long long len);
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index a85a75da954c4e..4ee8d9b07a0ca7 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -578,7 +578,7 @@ xfs_bmap_btree_to_extents(
ASSERT(ifp->if_format == XFS_DINODE_FMT_BTREE);
ASSERT(be16_to_cpu(rblock->bb_level) == 1);
ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1);
- ASSERT(xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0) == 1);
+ ASSERT(xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, false) == 1);
pp = xfs_bmap_broot_ptr_addr(mp, rblock, 1, ifp->if_broot_bytes);
cbno = be64_to_cpu(*pp);
diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c
index cac644c8ce35a5..62e79d8fc49784 100644
--- a/libxfs/xfs_bmap_btree.c
+++ b/libxfs/xfs_bmap_btree.c
@@ -644,11 +644,11 @@ xfs_bmbt_commit_staged_btree(
/*
* Calculate number of records in a bmap btree block.
*/
-int
+unsigned int
xfs_bmbt_maxrecs(
struct xfs_mount *mp,
- int blocklen,
- int leaf)
+ unsigned int blocklen,
+ bool leaf)
{
blocklen -= xfs_bmbt_block_len(mp);
return xfs_bmbt_block_maxrecs(blocklen, leaf);
diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h
index d006798d591bc2..49a3bae3f6ecec 100644
--- a/libxfs/xfs_bmap_btree.h
+++ b/libxfs/xfs_bmap_btree.h
@@ -35,7 +35,8 @@ extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
-extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
+unsigned int xfs_bmbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
int whichfork, xfs_ino_t new_owner,
@@ -151,7 +152,7 @@ xfs_bmap_broot_ptr_addr(
unsigned int i,
unsigned int sz)
{
- return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0));
+ return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, false));
}
/*
diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c
index 83e3d7d7c5a1b3..141b2d397b1fe7 100644
--- a/libxfs/xfs_ialloc.c
+++ b/libxfs/xfs_ialloc.c
@@ -2943,8 +2943,8 @@ xfs_ialloc_setup_geometry(
/* Compute inode btree geometry. */
igeo->agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
- igeo->inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 1);
- igeo->inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 0);
+ igeo->inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, true);
+ igeo->inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, false);
igeo->inobt_mnr[0] = igeo->inobt_mxr[0] / 2;
igeo->inobt_mnr[1] = igeo->inobt_mxr[1] / 2;
diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c
index 489c080fb22d05..ffca4a80219d6d 100644
--- a/libxfs/xfs_ialloc_btree.c
+++ b/libxfs/xfs_ialloc_btree.c
@@ -571,11 +571,11 @@ xfs_inobt_block_maxrecs(
/*
* Calculate number of records in an inobt btree block.
*/
-int
+unsigned int
xfs_inobt_maxrecs(
struct xfs_mount *mp,
- int blocklen,
- int leaf)
+ unsigned int blocklen,
+ bool leaf)
{
blocklen -= XFS_INOBT_BLOCK_LEN(mp);
return xfs_inobt_block_maxrecs(blocklen, leaf);
diff --git a/libxfs/xfs_ialloc_btree.h b/libxfs/xfs_ialloc_btree.h
index 6472ec1ecbb458..300edf5bc00949 100644
--- a/libxfs/xfs_ialloc_btree.h
+++ b/libxfs/xfs_ialloc_btree.h
@@ -50,7 +50,8 @@ struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag,
struct xfs_trans *tp, struct xfs_buf *agbp);
struct xfs_btree_cur *xfs_finobt_init_cursor(struct xfs_perag *pag,
struct xfs_trans *tp, struct xfs_buf *agbp);
-extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
+unsigned int xfs_inobt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
/* ir_holemask to inode allocation bitmap conversion */
uint64_t xfs_inobt_irec_to_allocmask(const struct xfs_inobt_rec_incore *irec);
diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c
index fd79da64e43a8d..a71a5e98bf408b 100644
--- a/libxfs/xfs_inode_fork.c
+++ b/libxfs/xfs_inode_fork.c
@@ -420,7 +420,7 @@ xfs_iroot_realloc(
* location. The records don't change location because
* they are kept butted up against the btree block header.
*/
- cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0);
+ cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, false);
new_max = cur_max + rec_diff;
new_size = xfs_bmap_broot_space_calc(mp, new_max);
ifp->if_broot = krealloc(ifp->if_broot, new_size,
@@ -442,7 +442,7 @@ xfs_iroot_realloc(
* records, just get rid of the root and clear the status bit.
*/
ASSERT((ifp->if_broot != NULL) && (ifp->if_broot_bytes > 0));
- cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0);
+ cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, false);
new_max = cur_max + rec_diff;
ASSERT(new_max >= 0);
if (new_max > 0)
diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c
index 162f9e6896a590..9028dea06b0c07 100644
--- a/libxfs/xfs_refcount_btree.c
+++ b/libxfs/xfs_refcount_btree.c
@@ -416,9 +416,10 @@ xfs_refcountbt_block_maxrecs(
/*
* Calculate the number of records in a refcount btree block.
*/
-int
+unsigned int
xfs_refcountbt_maxrecs(
- int blocklen,
+ struct xfs_mount *mp,
+ unsigned int blocklen,
bool leaf)
{
blocklen -= XFS_REFCOUNT_BLOCK_LEN;
diff --git a/libxfs/xfs_refcount_btree.h b/libxfs/xfs_refcount_btree.h
index 1e0ab25f6c6808..beb93bef6a8141 100644
--- a/libxfs/xfs_refcount_btree.h
+++ b/libxfs/xfs_refcount_btree.h
@@ -48,7 +48,8 @@ struct xbtree_afakeroot;
extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_buf *agbp,
struct xfs_perag *pag);
-extern int xfs_refcountbt_maxrecs(int blocklen, bool leaf);
+unsigned int xfs_refcountbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
extern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp);
extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp,
diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c
index f1732b72d13db1..ada58e92645020 100644
--- a/libxfs/xfs_rmap_btree.c
+++ b/libxfs/xfs_rmap_btree.c
@@ -730,10 +730,11 @@ xfs_rmapbt_block_maxrecs(
/*
* Calculate number of records in an rmap btree block.
*/
-int
+unsigned int
xfs_rmapbt_maxrecs(
- int blocklen,
- int leaf)
+ struct xfs_mount *mp,
+ unsigned int blocklen,
+ bool leaf)
{
blocklen -= XFS_RMAP_BLOCK_LEN;
return xfs_rmapbt_block_maxrecs(blocklen, leaf);
diff --git a/libxfs/xfs_rmap_btree.h b/libxfs/xfs_rmap_btree.h
index eb90d89e808666..119b1567cd0ee8 100644
--- a/libxfs/xfs_rmap_btree.h
+++ b/libxfs/xfs_rmap_btree.h
@@ -47,7 +47,8 @@ struct xfs_btree_cur *xfs_rmapbt_init_cursor(struct xfs_mount *mp,
struct xfs_perag *pag);
void xfs_rmapbt_commit_staged_btree(struct xfs_btree_cur *cur,
struct xfs_trans *tp, struct xfs_buf *agbp);
-int xfs_rmapbt_maxrecs(int blocklen, int leaf);
+unsigned int xfs_rmapbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
+ bool leaf);
extern void xfs_rmapbt_compute_maxlevels(struct xfs_mount *mp);
extern xfs_extlen_t xfs_rmapbt_calc_size(struct xfs_mount *mp,
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index 5f7ff4fa4e49b1..0603e5087f2e46 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -997,23 +997,23 @@ xfs_sb_mount_common(
mp->m_blockwmask = mp->m_blockwsize - 1;
xfs_mount_sb_set_rextsize(mp, sbp);
- mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
- mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
+ mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, true);
+ mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, false);
mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2;
mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2;
- mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1);
- mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0);
+ mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, true);
+ mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, false);
mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2;
mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2;
- mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 1);
- mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 0);
+ mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(mp, sbp->sb_blocksize, true);
+ mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(mp, sbp->sb_blocksize, false);
mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2;
mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2;
- mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true);
- mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false);
+ mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(mp, sbp->sb_blocksize, true);
+ mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(mp, sbp->sb_blocksize, false);
mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2;
mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2;
diff --git a/repair/phase5.c b/repair/phase5.c
index 52666ad8823312..d18ec095b0524b 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -641,21 +641,21 @@ phase5(xfs_mount_t *mp)
#ifdef XR_BLD_FREE_TRACE
fprintf(stderr, "inobt level 1, maxrec = %d, minrec = %d\n",
- libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
- libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
+ libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, false),
+ libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, false) / 2);
fprintf(stderr, "inobt level 0 (leaf), maxrec = %d, minrec = %d\n",
- libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
- libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
+ libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, true),
+ libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, true) / 2);
fprintf(stderr, "xr inobt level 0 (leaf), maxrec = %d\n",
XR_INOBT_BLOCK_MAXRECS(mp, 0));
fprintf(stderr, "xr inobt level 1 (int), maxrec = %d\n",
XR_INOBT_BLOCK_MAXRECS(mp, 1));
fprintf(stderr, "bnobt level 1, maxrec = %d, minrec = %d\n",
- libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
- libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
+ libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, false),
+ libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, false) / 2);
fprintf(stderr, "bnobt level 0 (leaf), maxrec = %d, minrec = %d\n",
- libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
- libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
+ libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, true),
+ libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, true) / 2);
#endif
/*
* make sure the root and realtime inodes show up allocated
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 23/37] xfs: use kvmalloc for xattr buffers
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (21 preceding siblings ...)
2024-10-21 22:04 ` [PATCH 22/37] xfs: standardize the btree maxrecs function parameters Darrick J. Wong
@ 2024-10-21 22:04 ` Darrick J. Wong
2024-10-21 22:05 ` [PATCH 24/37] xfs: remove unnecessary check Darrick J. Wong
` (13 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:04 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Dave Chinner <dchinner@redhat.com>
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>
---
include/kmem.h | 6 ++++++
libxfs/xfs_attr_leaf.c | 15 ++++++---------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/include/kmem.h b/include/kmem.h
index 8dfb2fb0b45020..8739d824008e2a 100644
--- a/include/kmem.h
+++ b/include/kmem.h
@@ -59,12 +59,18 @@ static inline void *kmalloc(size_t size, gfp_t flags)
}
#define kzalloc(size, gfp) kvmalloc((size), (gfp) | __GFP_ZERO)
+#define kvzalloc(size, gfp) kzalloc((size), (gfp))
static inline void kfree(const void *ptr)
{
free((void *)ptr);
}
+static inline void kvfree(const void *ptr)
+{
+ kfree(ptr);
+}
+
__attribute__((format(printf,2,3)))
char *kasprintf(gfp_t gfp, const char *fmt, ...);
diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c
index 97b71b6500bdc9..db2e48d719d36f 100644
--- a/libxfs/xfs_attr_leaf.c
+++ b/libxfs/xfs_attr_leaf.c
@@ -1135,10 +1135,7 @@ xfs_attr3_leaf_to_shortform(
trace_xfs_attr_leaf_to_sf(args);
- tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
- if (!tmpbuffer)
- return -ENOMEM;
-
+ tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
memcpy(tmpbuffer, bp->b_addr, args->geo->blksize);
leaf = (xfs_attr_leafblock_t *)tmpbuffer;
@@ -1202,7 +1199,7 @@ xfs_attr3_leaf_to_shortform(
error = 0;
out:
- kfree(tmpbuffer);
+ kvfree(tmpbuffer);
return error;
}
@@ -1610,7 +1607,7 @@ xfs_attr3_leaf_compact(
trace_xfs_attr_leaf_compact(args);
- tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
+ tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
memcpy(tmpbuffer, bp->b_addr, args->geo->blksize);
memset(bp->b_addr, 0, args->geo->blksize);
leaf_src = (xfs_attr_leafblock_t *)tmpbuffer;
@@ -1648,7 +1645,7 @@ xfs_attr3_leaf_compact(
*/
xfs_trans_log_buf(trans, bp, 0, args->geo->blksize - 1);
- kfree(tmpbuffer);
+ kvfree(tmpbuffer);
}
/*
@@ -2327,7 +2324,7 @@ xfs_attr3_leaf_unbalance(
struct xfs_attr_leafblock *tmp_leaf;
struct xfs_attr3_icleaf_hdr tmphdr;
- tmp_leaf = kzalloc(state->args->geo->blksize,
+ tmp_leaf = kvzalloc(state->args->geo->blksize,
GFP_KERNEL | __GFP_NOFAIL);
/*
@@ -2368,7 +2365,7 @@ xfs_attr3_leaf_unbalance(
}
memcpy(save_leaf, tmp_leaf, state->args->geo->blksize);
savehdr = tmphdr; /* struct copy */
- kfree(tmp_leaf);
+ kvfree(tmp_leaf);
}
xfs_attr3_leaf_hdr_to_disk(state->args->geo, save_leaf, &savehdr);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 24/37] xfs: remove unnecessary check
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (22 preceding siblings ...)
2024-10-21 22:04 ` [PATCH 23/37] xfs: use kvmalloc for xattr buffers Darrick J. Wong
@ 2024-10-21 22:05 ` Darrick J. Wong
2024-10-21 22:05 ` [PATCH 25/37] xfs: use kfree_rcu_mightsleep to free the perag structures Darrick J. Wong
` (12 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:05 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Dan Carpenter <dan.carpenter@linaro.org>
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>
---
libxfs/xfs_inode_util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libxfs/xfs_inode_util.c b/libxfs/xfs_inode_util.c
index 74d2b5960bf0f2..92bfdf0715f02e 100644
--- a/libxfs/xfs_inode_util.c
+++ b/libxfs/xfs_inode_util.c
@@ -305,7 +305,7 @@ xfs_inode_init(
!vfsgid_in_group_p(i_gid_into_vfsgid(args->idmap, inode)))
inode->i_mode &= ~S_ISGID;
- ip->i_projid = pip ? xfs_get_initial_prid(pip) : 0;
+ ip->i_projid = xfs_get_initial_prid(pip);
}
ip->i_disk_size = 0;
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 25/37] xfs: use kfree_rcu_mightsleep to free the perag structures
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (23 preceding siblings ...)
2024-10-21 22:05 ` [PATCH 24/37] xfs: remove unnecessary check Darrick J. Wong
@ 2024-10-21 22:05 ` Darrick J. Wong
2024-10-21 22:05 ` [PATCH 26/37] xfs: move the tagged perag lookup helpers to xfs_icache.c Darrick J. Wong
` (11 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:05 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
include/kmem.h | 5 +++++
libxfs/xfs_ag.c | 12 +-----------
libxfs/xfs_ag.h | 3 ---
3 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/include/kmem.h b/include/kmem.h
index 8739d824008e2a..16a7957f1acee3 100644
--- a/include/kmem.h
+++ b/include/kmem.h
@@ -71,6 +71,11 @@ static inline void kvfree(const void *ptr)
kfree(ptr);
}
+static inline void kfree_rcu_mightsleep(const void *ptr)
+{
+ kfree(ptr);
+}
+
__attribute__((format(printf,2,3)))
char *kasprintf(gfp_t gfp, const char *fmt, ...);
diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c
index ed9ac7f58d1aba..1b65ba983ad542 100644
--- a/libxfs/xfs_ag.c
+++ b/libxfs/xfs_ag.c
@@ -233,16 +233,6 @@ xfs_initialize_perag_data(
return error;
}
-STATIC void
-__xfs_free_perag(
- struct rcu_head *head)
-{
- struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head);
-
- ASSERT(!delayed_work_pending(&pag->pag_blockgc_work));
- kfree(pag);
-}
-
/*
* Free up the per-ag resources associated with the mount structure.
*/
@@ -268,7 +258,7 @@ xfs_free_perag(
xfs_perag_rele(pag);
XFS_IS_CORRUPT(pag->pag_mount,
atomic_read(&pag->pag_active_ref) != 0);
- call_rcu(&pag->rcu_head, __xfs_free_perag);
+ kfree_rcu_mightsleep(pag);
}
}
diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h
index 35de09a2516c70..d62c266c0b44d5 100644
--- a/libxfs/xfs_ag.h
+++ b/libxfs/xfs_ag.h
@@ -63,9 +63,6 @@ struct xfs_perag {
/* Blocks reserved for the reverse mapping btree. */
struct xfs_ag_resv pag_rmapbt_resv;
- /* for rcu-safe freeing */
- struct rcu_head rcu_head;
-
/* Precalculated geometry info */
xfs_agblock_t block_count;
xfs_agblock_t min_block;
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 26/37] xfs: move the tagged perag lookup helpers to xfs_icache.c
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (24 preceding siblings ...)
2024-10-21 22:05 ` [PATCH 25/37] xfs: use kfree_rcu_mightsleep to free the perag structures Darrick J. Wong
@ 2024-10-21 22:05 ` Darrick J. Wong
2024-10-21 22:05 ` [PATCH 27/37] xfs: convert perag lookup to xarray Darrick J. Wong
` (10 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:05 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_ag.c | 51 ---------------------------------------------------
libxfs/xfs_ag.h | 11 -----------
2 files changed, 62 deletions(-)
diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c
index 1b65ba983ad542..a63d9c0dc6fe44 100644
--- a/libxfs/xfs_ag.c
+++ b/libxfs/xfs_ag.c
@@ -54,31 +54,6 @@ xfs_perag_get(
return pag;
}
-/*
- * search from @first to find the next perag with the given tag set.
- */
-struct xfs_perag *
-xfs_perag_get_tag(
- struct xfs_mount *mp,
- xfs_agnumber_t first,
- unsigned int tag)
-{
- struct xfs_perag *pag;
- int found;
-
- rcu_read_lock();
- found = radix_tree_gang_lookup_tag(&mp->m_perag_tree,
- (void **)&pag, first, 1, tag);
- if (found <= 0) {
- rcu_read_unlock();
- return NULL;
- }
- trace_xfs_perag_get_tag(pag, _RET_IP_);
- atomic_inc(&pag->pag_ref);
- rcu_read_unlock();
- return pag;
-}
-
/* Get a passive reference to the given perag. */
struct xfs_perag *
xfs_perag_hold(
@@ -125,32 +100,6 @@ xfs_perag_grab(
return pag;
}
-/*
- * search from @first to find the next perag with the given tag set.
- */
-struct xfs_perag *
-xfs_perag_grab_tag(
- struct xfs_mount *mp,
- xfs_agnumber_t first,
- int tag)
-{
- struct xfs_perag *pag;
- int found;
-
- rcu_read_lock();
- found = radix_tree_gang_lookup_tag(&mp->m_perag_tree,
- (void **)&pag, first, 1, tag);
- if (found <= 0) {
- rcu_read_unlock();
- return NULL;
- }
- trace_xfs_perag_grab_tag(pag, _RET_IP_);
- if (!atomic_inc_not_zero(&pag->pag_active_ref))
- pag = NULL;
- rcu_read_unlock();
- return pag;
-}
-
void
xfs_perag_rele(
struct xfs_perag *pag)
diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h
index d62c266c0b44d5..d9cccd093b60e0 100644
--- a/libxfs/xfs_ag.h
+++ b/libxfs/xfs_ag.h
@@ -153,15 +153,11 @@ void xfs_free_perag(struct xfs_mount *mp);
/* Passive AG references */
struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);
-struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno,
- unsigned int tag);
struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag);
void xfs_perag_put(struct xfs_perag *pag);
/* Active AG references */
struct xfs_perag *xfs_perag_grab(struct xfs_mount *, xfs_agnumber_t);
-struct xfs_perag *xfs_perag_grab_tag(struct xfs_mount *, xfs_agnumber_t,
- int tag);
void xfs_perag_rele(struct xfs_perag *pag);
/*
@@ -263,13 +259,6 @@ xfs_perag_next(
(agno) = 0; \
for_each_perag_from((mp), (agno), (pag))
-#define for_each_perag_tag(mp, agno, pag, tag) \
- for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \
- (pag) != NULL; \
- (agno) = (pag)->pag_agno + 1, \
- xfs_perag_rele(pag), \
- (pag) = xfs_perag_grab_tag((mp), (agno), (tag)))
-
static inline struct xfs_perag *
xfs_perag_next_wrap(
struct xfs_perag *pag,
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 27/37] xfs: convert perag lookup to xarray
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (25 preceding siblings ...)
2024-10-21 22:05 ` [PATCH 26/37] xfs: move the tagged perag lookup helpers to xfs_icache.c Darrick J. Wong
@ 2024-10-21 22:05 ` Darrick J. Wong
2024-10-21 22:06 ` [PATCH 28/37] xfs: ensure st_blocks never goes to zero during COW writes Darrick J. Wong
` (9 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:05 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
include/xfs_mount.h | 2 +-
libxfs/init.c | 2 +-
libxfs/xfs_ag.c | 31 ++++++++-----------------------
3 files changed, 10 insertions(+), 25 deletions(-)
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index 7571df12fba3f8..e2add8a648f887 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -91,7 +91,7 @@ typedef struct xfs_mount {
xfs_extlen_t m_ag_prealloc_blocks; /* reserved ag blocks */
uint m_alloc_set_aside; /* space we can't use */
uint m_ag_max_usable; /* max space per AG */
- struct radix_tree_root m_perag_tree;
+ struct xarray m_perags;
uint64_t m_features; /* active filesystem features */
uint64_t m_low_space[XFS_LOWSP_MAX];
uint64_t m_rtxblkmask; /* rt extent block mask */
diff --git a/libxfs/init.c b/libxfs/init.c
index 6ab5ef54bb69cb..1e45f091dbb5bf 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -662,7 +662,7 @@ libxfs_mount(
mp->m_finobt_nores = true;
xfs_set_inode32(mp);
mp->m_sb = *sb;
- INIT_RADIX_TREE(&mp->m_perag_tree, GFP_KERNEL);
+ xa_init(&mp->m_perags);
sbp = &mp->m_sb;
spin_lock_init(&mp->m_sb_lock);
spin_lock_init(&mp->m_agirotor_lock);
diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c
index a63d9c0dc6fe44..516c76790cc0d8 100644
--- a/libxfs/xfs_ag.c
+++ b/libxfs/xfs_ag.c
@@ -44,7 +44,7 @@ xfs_perag_get(
struct xfs_perag *pag;
rcu_read_lock();
- pag = radix_tree_lookup(&mp->m_perag_tree, agno);
+ pag = xa_load(&mp->m_perags, agno);
if (pag) {
trace_xfs_perag_get(pag, _RET_IP_);
ASSERT(atomic_read(&pag->pag_ref) >= 0);
@@ -90,7 +90,7 @@ xfs_perag_grab(
struct xfs_perag *pag;
rcu_read_lock();
- pag = radix_tree_lookup(&mp->m_perag_tree, agno);
+ pag = xa_load(&mp->m_perags, agno);
if (pag) {
trace_xfs_perag_grab(pag, _RET_IP_);
if (!atomic_inc_not_zero(&pag->pag_active_ref))
@@ -193,9 +193,7 @@ xfs_free_perag(
xfs_agnumber_t agno;
for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
- spin_lock(&mp->m_perag_lock);
- pag = radix_tree_delete(&mp->m_perag_tree, agno);
- spin_unlock(&mp->m_perag_lock);
+ pag = xa_erase(&mp->m_perags, agno);
ASSERT(pag);
XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0);
xfs_defer_drain_free(&pag->pag_intents_drain);
@@ -284,9 +282,7 @@ xfs_free_unused_perag_range(
xfs_agnumber_t index;
for (index = agstart; index < agend; index++) {
- spin_lock(&mp->m_perag_lock);
- pag = radix_tree_delete(&mp->m_perag_tree, index);
- spin_unlock(&mp->m_perag_lock);
+ pag = xa_erase(&mp->m_perags, index);
if (!pag)
break;
xfs_buf_cache_destroy(&pag->pag_bcache);
@@ -327,20 +323,11 @@ xfs_initialize_perag(
pag->pag_agno = index;
pag->pag_mount = mp;
- error = radix_tree_preload(GFP_KERNEL | __GFP_RETRY_MAYFAIL);
- if (error)
- goto out_free_pag;
-
- spin_lock(&mp->m_perag_lock);
- if (radix_tree_insert(&mp->m_perag_tree, index, pag)) {
- WARN_ON_ONCE(1);
- spin_unlock(&mp->m_perag_lock);
- radix_tree_preload_end();
- error = -EEXIST;
+ error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL);
+ if (error) {
+ WARN_ON_ONCE(error == -EBUSY);
goto out_free_pag;
}
- spin_unlock(&mp->m_perag_lock);
- radix_tree_preload_end();
#ifdef __KERNEL__
/* Place kernel structure only init below this point. */
@@ -388,9 +375,7 @@ xfs_initialize_perag(
out_remove_pag:
xfs_defer_drain_free(&pag->pag_intents_drain);
- spin_lock(&mp->m_perag_lock);
- radix_tree_delete(&mp->m_perag_tree, index);
- spin_unlock(&mp->m_perag_lock);
+ pag = xa_erase(&mp->m_perags, index);
out_free_pag:
kfree(pag);
out_unwind_new_pags:
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 28/37] xfs: ensure st_blocks never goes to zero during COW writes
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (26 preceding siblings ...)
2024-10-21 22:05 ` [PATCH 27/37] xfs: convert perag lookup to xarray Darrick J. Wong
@ 2024-10-21 22:06 ` Darrick J. Wong
2024-10-21 22:06 ` [PATCH 29/37] xfs: enable block size larger than page size support Darrick J. Wong
` (8 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:06 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/defer_item.c | 14 ++++++++++++++
libxfs/xfs_bmap.c | 1 +
2 files changed, 15 insertions(+)
diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c
index 98a291c7b785e1..2b48ed14d67bcb 100644
--- a/libxfs/defer_item.c
+++ b/libxfs/defer_item.c
@@ -520,6 +520,17 @@ xfs_bmap_defer_add(
trace_xfs_bmap_defer(bi);
xfs_bmap_update_get_group(tp->t_mountp, bi);
+
+ /*
+ * Ensure the deferred mapping is pre-recorded in i_delayed_blks.
+ *
+ * Otherwise stat can report zero blocks for an inode that actually has
+ * data when the entire mapping is in the process of being overwritten
+ * using the out of place write path. This is undone in xfs_bmapi_remap
+ * after it has incremented di_nblocks for a successful operation.
+ */
+ if (bi->bi_type == XFS_BMAP_MAP)
+ bi->bi_owner->i_delayed_blks += bi->bi_bmap.br_blockcount;
xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type);
}
@@ -541,6 +552,9 @@ xfs_bmap_update_cancel_item(
{
struct xfs_bmap_intent *bi = bi_entry(item);
+ if (bi->bi_type == XFS_BMAP_MAP)
+ bi->bi_owner->i_delayed_blks -= bi->bi_bmap.br_blockcount;
+
xfs_bmap_update_put_group(bi);
kmem_cache_free(xfs_bmap_intent_cache, bi);
}
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 4ee8d9b07a0ca7..c014325a5d7d9c 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -4850,6 +4850,7 @@ xfs_bmapi_remap(
}
ip->i_nblocks += len;
+ ip->i_delayed_blks -= len; /* see xfs_bmap_defer_add */
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
if (ifp->if_format == XFS_DINODE_FMT_BTREE)
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 29/37] xfs: enable block size larger than page size support
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (27 preceding siblings ...)
2024-10-21 22:06 ` [PATCH 28/37] xfs: ensure st_blocks never goes to zero during COW writes Darrick J. Wong
@ 2024-10-21 22:06 ` Darrick J. Wong
2024-10-21 22:06 ` [PATCH 30/37] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname Darrick J. Wong
` (7 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:06 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Pankaj Raghav <p.raghav@samsung.com>
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 # fix folded
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>
---
libxfs/init.c | 5 +++++
libxfs/libxfs_priv.h | 1 +
libxfs/xfs_ialloc.c | 5 +++++
libxfs/xfs_shared.h | 3 +++
4 files changed, 14 insertions(+)
diff --git a/libxfs/init.c b/libxfs/init.c
index 1e45f091dbb5bf..733ab3f1abc557 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -22,6 +22,7 @@
#include "xfs_rmap_btree.h"
#include "xfs_refcount_btree.h"
#include "libfrog/platform.h"
+#include "libfrog/util.h"
#include "libxfs/xfile.h"
#include "libxfs/buf_mem.h"
@@ -44,6 +45,8 @@ int use_xfs_buf_lock; /* global flag: use xfs_buf locks for MT */
static int nextfakedev = -1; /* device number to give to next fake device */
+unsigned int PAGE_SHIFT;
+
/*
* Checks whether a given device has a mounted, writable
* filesystem, returns 1 if it does & fatal (just warns
@@ -257,6 +260,8 @@ libxfs_close_devices(
int
libxfs_init(struct libxfs_init *a)
{
+ if (!PAGE_SHIFT)
+ PAGE_SHIFT = log2_roundup(PAGE_SIZE);
xfs_check_ondisk_structs();
xmbuf_libinit();
rcu_init();
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index fa025aeb09712b..97f5003ea53862 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -224,6 +224,7 @@ uint32_t get_random_u32(void);
#endif
#define PAGE_SIZE getpagesize()
+extern unsigned int PAGE_SHIFT;
#define inode_peek_iversion(inode) (inode)->i_version
#define inode_set_iversion_queried(inode, version) do { \
diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c
index 141b2d397b1fe7..43af698fa90903 100644
--- a/libxfs/xfs_ialloc.c
+++ b/libxfs/xfs_ialloc.c
@@ -3029,6 +3029,11 @@ xfs_ialloc_setup_geometry(
igeo->ialloc_align = mp->m_dalign;
else
igeo->ialloc_align = 0;
+
+ if (mp->m_sb.sb_blocksize > PAGE_SIZE)
+ igeo->min_folio_order = mp->m_sb.sb_blocklog - PAGE_SHIFT;
+ else
+ igeo->min_folio_order = 0;
}
/* Compute the location of the root directory inode that is laid out by mkfs. */
diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h
index 2f7413afbf46cd..33b84a3a83ff63 100644
--- a/libxfs/xfs_shared.h
+++ b/libxfs/xfs_shared.h
@@ -224,6 +224,9 @@ struct xfs_ino_geometry {
/* precomputed value for di_flags2 */
uint64_t new_diflags2;
+ /* minimum folio order of a page cache allocation */
+ unsigned int min_folio_order;
+
};
#endif /* __XFS_SHARED_H__ */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 30/37] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (28 preceding siblings ...)
2024-10-21 22:06 ` [PATCH 29/37] xfs: enable block size larger than page size support Darrick J. Wong
@ 2024-10-21 22:06 ` Darrick J. Wong
2024-10-21 22:07 ` [PATCH 31/37] xfs: return bool from xfs_attr3_leaf_add Darrick J. Wong
` (6 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:06 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
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>
---
libxfs/xfs_attr.c | 176 ++++++++++++++++++++++-------------------------------
1 file changed, 74 insertions(+), 102 deletions(-)
diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index 9e1cce5776b3df..21c708beac60c7 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -50,7 +50,6 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
-STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args);
/*
* Internal routines when attribute list is more than one block.
@@ -436,6 +435,33 @@ xfs_attr_hashval(
return xfs_attr_hashname(name, namelen);
}
+/* Save the current remote block info and clear the current pointers. */
+static void
+xfs_attr_save_rmt_blk(
+ struct xfs_da_args *args)
+{
+ args->blkno2 = args->blkno;
+ args->index2 = args->index;
+ args->rmtblkno2 = args->rmtblkno;
+ args->rmtblkcnt2 = args->rmtblkcnt;
+ args->rmtvaluelen2 = args->rmtvaluelen;
+ args->rmtblkno = 0;
+ args->rmtblkcnt = 0;
+ args->rmtvaluelen = 0;
+}
+
+/* Set stored info about a remote block */
+static void
+xfs_attr_restore_rmt_blk(
+ struct xfs_da_args *args)
+{
+ args->blkno = args->blkno2;
+ args->index = args->index2;
+ args->rmtblkno = args->rmtblkno2;
+ args->rmtblkcnt = args->rmtblkcnt2;
+ args->rmtvaluelen = args->rmtvaluelen2;
+}
+
/*
* PPTR_REPLACE operations require the caller to set the old and new names and
* values explicitly. Update the canonical fields to the new name and value
@@ -481,49 +507,77 @@ xfs_attr_complete_op(
return replace_state;
}
+/*
+ * Try to add an attribute to an inode in leaf form.
+ */
static int
xfs_attr_leaf_addname(
struct xfs_attr_intent *attr)
{
struct xfs_da_args *args = attr->xattri_da_args;
+ struct xfs_buf *bp;
int error;
ASSERT(xfs_attr_is_leaf(args->dp));
+ error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp);
+ if (error)
+ return error;
+
/*
- * Use the leaf buffer we may already hold locked as a result of
- * a sf-to-leaf conversion.
+ * Look up the xattr name to set the insertion point for the new xattr.
*/
- error = xfs_attr_leaf_try_add(args);
-
- if (error == -ENOSPC) {
- error = xfs_attr3_leaf_to_node(args);
- if (error)
- return error;
+ error = xfs_attr3_leaf_lookup_int(bp, args);
+ switch (error) {
+ case -ENOATTR:
+ if (args->op_flags & XFS_DA_OP_REPLACE)
+ goto out_brelse;
+ break;
+ case -EEXIST:
+ if (!(args->op_flags & XFS_DA_OP_REPLACE))
+ goto out_brelse;
+ trace_xfs_attr_leaf_replace(args);
/*
- * We're not in leaf format anymore, so roll the transaction and
- * retry the add to the newly allocated node block.
+ * Save the existing remote attr state so that the current
+ * values reflect the state of the new attribute we are about to
+ * add, not the attribute we just found and will remove later.
*/
- attr->xattri_dela_state = XFS_DAS_NODE_ADD;
- goto out;
+ xfs_attr_save_rmt_blk(args);
+ break;
+ case 0:
+ break;
+ default:
+ goto out_brelse;
}
- if (error)
- return error;
/*
* We need to commit and roll if we need to allocate remote xattr blocks
* or perform more xattr manipulations. Otherwise there is nothing more
* to do and we can return success.
*/
- if (args->rmtblkno)
+ error = xfs_attr3_leaf_add(bp, args);
+ if (error) {
+ if (error != -ENOSPC)
+ return error;
+ error = xfs_attr3_leaf_to_node(args);
+ if (error)
+ return error;
+
+ attr->xattri_dela_state = XFS_DAS_NODE_ADD;
+ } else if (args->rmtblkno) {
attr->xattri_dela_state = XFS_DAS_LEAF_SET_RMT;
- else
- attr->xattri_dela_state = xfs_attr_complete_op(attr,
- XFS_DAS_LEAF_REPLACE);
-out:
+ } else {
+ attr->xattri_dela_state =
+ xfs_attr_complete_op(attr, XFS_DAS_LEAF_REPLACE);
+ }
+
trace_xfs_attr_leaf_addname_return(attr->xattri_dela_state, args->dp);
return error;
+
+out_brelse:
+ xfs_trans_brelse(args->trans, bp);
+ return error;
}
/*
@@ -1169,88 +1223,6 @@ xfs_attr_shortform_addname(
* External routines when attribute list is one block
*========================================================================*/
-/* Save the current remote block info and clear the current pointers. */
-static void
-xfs_attr_save_rmt_blk(
- struct xfs_da_args *args)
-{
- args->blkno2 = args->blkno;
- args->index2 = args->index;
- args->rmtblkno2 = args->rmtblkno;
- args->rmtblkcnt2 = args->rmtblkcnt;
- args->rmtvaluelen2 = args->rmtvaluelen;
- args->rmtblkno = 0;
- args->rmtblkcnt = 0;
- args->rmtvaluelen = 0;
-}
-
-/* Set stored info about a remote block */
-static void
-xfs_attr_restore_rmt_blk(
- struct xfs_da_args *args)
-{
- args->blkno = args->blkno2;
- args->index = args->index2;
- args->rmtblkno = args->rmtblkno2;
- args->rmtblkcnt = args->rmtblkcnt2;
- args->rmtvaluelen = args->rmtvaluelen2;
-}
-
-/*
- * Tries to add an attribute to an inode in leaf form
- *
- * This function is meant to execute as part of a delayed operation and leaves
- * the transaction handling to the caller. On success the attribute is added
- * and the inode and transaction are left dirty. If there is not enough space,
- * the attr data is converted to node format and -ENOSPC is returned. Caller is
- * responsible for handling the dirty inode and transaction or adding the attr
- * in node format.
- */
-STATIC int
-xfs_attr_leaf_try_add(
- struct xfs_da_args *args)
-{
- struct xfs_buf *bp;
- int error;
-
- error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp);
- if (error)
- return error;
-
- /*
- * Look up the xattr name to set the insertion point for the new xattr.
- */
- error = xfs_attr3_leaf_lookup_int(bp, args);
- switch (error) {
- case -ENOATTR:
- if (args->op_flags & XFS_DA_OP_REPLACE)
- goto out_brelse;
- break;
- case -EEXIST:
- if (!(args->op_flags & XFS_DA_OP_REPLACE))
- goto out_brelse;
-
- trace_xfs_attr_leaf_replace(args);
- /*
- * Save the existing remote attr state so that the current
- * values reflect the state of the new attribute we are about to
- * add, not the attribute we just found and will remove later.
- */
- xfs_attr_save_rmt_blk(args);
- break;
- case 0:
- break;
- default:
- goto out_brelse;
- }
-
- return xfs_attr3_leaf_add(bp, args);
-
-out_brelse:
- xfs_trans_brelse(args->trans, bp);
- return error;
-}
-
/*
* Return EEXIST if attr is found, or ENOATTR if not
*/
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 31/37] xfs: return bool from xfs_attr3_leaf_add
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (29 preceding siblings ...)
2024-10-21 22:06 ` [PATCH 30/37] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname Darrick J. Wong
@ 2024-10-21 22:07 ` Darrick J. Wong
2024-10-21 22:07 ` [PATCH 32/37] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split Darrick J. Wong
` (5 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:07 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: 346c1d46d4c631c0c88592d371f585214d714da4
xfs_attr3_leaf_add only has two potential return values, indicating if the
entry could be added or not. Replace the errno return with a bool so that
ENOSPC from it can't easily be confused with a real ENOSPC.
Remove the return value from the xfs_attr3_leaf_add_work helper entirely,
as it always return 0.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_attr.c | 13 +++++--------
libxfs/xfs_attr_leaf.c | 37 +++++++++++++++++++------------------
libxfs/xfs_attr_leaf.h | 2 +-
3 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index 21c708beac60c7..9ac7124b0a7bc1 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -556,10 +556,7 @@ xfs_attr_leaf_addname(
* or perform more xattr manipulations. Otherwise there is nothing more
* to do and we can return success.
*/
- error = xfs_attr3_leaf_add(bp, args);
- if (error) {
- if (error != -ENOSPC)
- return error;
+ if (!xfs_attr3_leaf_add(bp, args)) {
error = xfs_attr3_leaf_to_node(args);
if (error)
return error;
@@ -573,7 +570,7 @@ xfs_attr_leaf_addname(
}
trace_xfs_attr_leaf_addname_return(attr->xattri_dela_state, args->dp);
- return error;
+ return 0;
out_brelse:
xfs_trans_brelse(args->trans, bp);
@@ -1398,21 +1395,21 @@ xfs_attr_node_try_addname(
{
struct xfs_da_state *state = attr->xattri_da_state;
struct xfs_da_state_blk *blk;
- int error;
+ int error = 0;
trace_xfs_attr_node_addname(state->args);
blk = &state->path.blk[state->path.active-1];
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
- error = xfs_attr3_leaf_add(blk->bp, state->args);
- if (error == -ENOSPC) {
+ if (!xfs_attr3_leaf_add(blk->bp, state->args)) {
if (state->path.active == 1) {
/*
* Its really a single leaf node, but it had
* out-of-line values so it looked like it *might*
* have been a b-tree. Let the caller deal with this.
*/
+ error = -ENOSPC;
goto out;
}
diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c
index db2e48d719d36f..3028ef0cd3cb2c 100644
--- a/libxfs/xfs_attr_leaf.c
+++ b/libxfs/xfs_attr_leaf.c
@@ -44,7 +44,7 @@
*/
STATIC int xfs_attr3_leaf_create(struct xfs_da_args *args,
xfs_dablk_t which_block, struct xfs_buf **bpp);
-STATIC int xfs_attr3_leaf_add_work(struct xfs_buf *leaf_buffer,
+STATIC void xfs_attr3_leaf_add_work(struct xfs_buf *leaf_buffer,
struct xfs_attr3_icleaf_hdr *ichdr,
struct xfs_da_args *args, int freemap_index);
STATIC void xfs_attr3_leaf_compact(struct xfs_da_args *args,
@@ -992,10 +992,8 @@ xfs_attr_shortform_to_leaf(
xfs_attr_sethash(&nargs);
error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */
ASSERT(error == -ENOATTR);
- error = xfs_attr3_leaf_add(bp, &nargs);
- ASSERT(error != -ENOSPC);
- if (error)
- goto out;
+ if (!xfs_attr3_leaf_add(bp, &nargs))
+ ASSERT(0);
sfe = xfs_attr_sf_nextentry(sfe);
}
error = 0;
@@ -1337,8 +1335,9 @@ xfs_attr3_leaf_split(
struct xfs_da_state_blk *oldblk,
struct xfs_da_state_blk *newblk)
{
- xfs_dablk_t blkno;
- int error;
+ bool added;
+ xfs_dablk_t blkno;
+ int error;
trace_xfs_attr_leaf_split(state->args);
@@ -1373,10 +1372,10 @@ xfs_attr3_leaf_split(
*/
if (state->inleaf) {
trace_xfs_attr_leaf_add_old(state->args);
- error = xfs_attr3_leaf_add(oldblk->bp, state->args);
+ added = xfs_attr3_leaf_add(oldblk->bp, state->args);
} else {
trace_xfs_attr_leaf_add_new(state->args);
- error = xfs_attr3_leaf_add(newblk->bp, state->args);
+ added = xfs_attr3_leaf_add(newblk->bp, state->args);
}
/*
@@ -1384,13 +1383,15 @@ xfs_attr3_leaf_split(
*/
oldblk->hashval = xfs_attr_leaf_lasthash(oldblk->bp, NULL);
newblk->hashval = xfs_attr_leaf_lasthash(newblk->bp, NULL);
- return error;
+ if (!added)
+ return -ENOSPC;
+ return 0;
}
/*
* Add a name to the leaf attribute list structure.
*/
-int
+bool
xfs_attr3_leaf_add(
struct xfs_buf *bp,
struct xfs_da_args *args)
@@ -1399,6 +1400,7 @@ xfs_attr3_leaf_add(
struct xfs_attr3_icleaf_hdr ichdr;
int tablesize;
int entsize;
+ bool added = true;
int sum;
int tmp;
int i;
@@ -1427,7 +1429,7 @@ xfs_attr3_leaf_add(
if (ichdr.freemap[i].base < ichdr.firstused)
tmp += sizeof(xfs_attr_leaf_entry_t);
if (ichdr.freemap[i].size >= tmp) {
- tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, i);
+ xfs_attr3_leaf_add_work(bp, &ichdr, args, i);
goto out_log_hdr;
}
sum += ichdr.freemap[i].size;
@@ -1439,7 +1441,7 @@ xfs_attr3_leaf_add(
* no good and we should just give up.
*/
if (!ichdr.holes && sum < entsize)
- return -ENOSPC;
+ return false;
/*
* Compact the entries to coalesce free space.
@@ -1452,24 +1454,24 @@ xfs_attr3_leaf_add(
* free region, in freemap[0]. If it is not big enough, give up.
*/
if (ichdr.freemap[0].size < (entsize + sizeof(xfs_attr_leaf_entry_t))) {
- tmp = -ENOSPC;
+ added = false;
goto out_log_hdr;
}
- tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
+ xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
out_log_hdr:
xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, &leaf->hdr,
xfs_attr3_leaf_hdr_size(leaf)));
- return tmp;
+ return added;
}
/*
* Add a name to a leaf attribute list structure.
*/
-STATIC int
+STATIC void
xfs_attr3_leaf_add_work(
struct xfs_buf *bp,
struct xfs_attr3_icleaf_hdr *ichdr,
@@ -1587,7 +1589,6 @@ xfs_attr3_leaf_add_work(
}
}
ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index);
- return 0;
}
/*
diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h
index bac219589896ad..589f810eedc0d8 100644
--- a/libxfs/xfs_attr_leaf.h
+++ b/libxfs/xfs_attr_leaf.h
@@ -76,7 +76,7 @@ int xfs_attr3_leaf_split(struct xfs_da_state *state,
int xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
struct xfs_da_args *args);
int xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
-int xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
+bool xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args);
int xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 32/37] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (30 preceding siblings ...)
2024-10-21 22:07 ` [PATCH 31/37] xfs: return bool from xfs_attr3_leaf_add Darrick J. Wong
@ 2024-10-21 22:07 ` Darrick J. Wong
2024-10-21 22:07 ` [PATCH 33/37] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname Darrick J. Wong
` (4 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:07 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: a5f73342abe1f796140f6585e43e2aa7bc1b7975
xfs_attr3_leaf_split propagates the need for an extra btree split as
-ENOSPC to it's only caller, but the same return value can also be
returned from xfs_da_grow_inode when it fails to find free space.
Distinguish the two cases by returning 1 for the extra split case instead
of overloading -ENOSPC.
This can be triggered relatively easily with the pending realtime group
support and a file system with a lot of small zones that use metadata
space on the main device. In this case every about 5-10th run of
xfs/538 runs into the following assert:
ASSERT(oldblk->magic == XFS_ATTR_LEAF_MAGIC);
in xfs_attr3_leaf_split caused by an allocation failure. Note that
the allocation failure is caused by another bug that will be fixed
subsequently, but this commit at least sorts out the error handling.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_attr_leaf.c | 5 ++++-
libxfs/xfs_da_btree.c | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c
index 3028ef0cd3cb2c..01a87b45a6a5c0 100644
--- a/libxfs/xfs_attr_leaf.c
+++ b/libxfs/xfs_attr_leaf.c
@@ -1328,6 +1328,9 @@ xfs_attr3_leaf_create(
/*
* Split the leaf node, rebalance, then add the new entry.
+ *
+ * Returns 0 if the entry was added, 1 if a further split is needed or a
+ * negative error number otherwise.
*/
int
xfs_attr3_leaf_split(
@@ -1384,7 +1387,7 @@ xfs_attr3_leaf_split(
oldblk->hashval = xfs_attr_leaf_lasthash(oldblk->bp, NULL);
newblk->hashval = xfs_attr_leaf_lasthash(newblk->bp, NULL);
if (!added)
- return -ENOSPC;
+ return 1;
return 0;
}
diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c
index 820e8575246b50..38f345a923c757 100644
--- a/libxfs/xfs_da_btree.c
+++ b/libxfs/xfs_da_btree.c
@@ -589,9 +589,8 @@ xfs_da3_split(
switch (oldblk->magic) {
case XFS_ATTR_LEAF_MAGIC:
error = xfs_attr3_leaf_split(state, oldblk, newblk);
- if ((error != 0) && (error != -ENOSPC)) {
+ if (error < 0)
return error; /* GROT: attr is inconsistent */
- }
if (!error) {
addblk = newblk;
break;
@@ -613,6 +612,8 @@ xfs_da3_split(
error = xfs_attr3_leaf_split(state, newblk,
&state->extrablk);
}
+ if (error == 1)
+ return -ENOSPC;
if (error)
return error; /* GROT: attr inconsistent */
addblk = newblk;
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 33/37] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (31 preceding siblings ...)
2024-10-21 22:07 ` [PATCH 32/37] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split Darrick J. Wong
@ 2024-10-21 22:07 ` Darrick J. Wong
2024-10-21 22:07 ` [PATCH 34/37] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate Darrick J. Wong
` (3 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:07 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: b3f4e84e2f438a119b7ca8684a25452b3e57c0f0
Just like xfs_attr3_leaf_split, xfs_attr_node_try_addname can return
-ENOSPC both for an actual failure to allocate a disk block, but also
to signal the caller to convert the format of the attr fork. Use magic
1 to ask for the conversion here as well.
Note that unlike the similar issue in xfs_attr3_leaf_split, this one was
only found by code review.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_attr.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index 9ac7124b0a7bc1..150aaddf7f9fed 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -596,7 +596,7 @@ xfs_attr_node_addname(
return error;
error = xfs_attr_node_try_addname(attr);
- if (error == -ENOSPC) {
+ if (error == 1) {
error = xfs_attr3_leaf_to_node(args);
if (error)
return error;
@@ -1385,9 +1385,12 @@ xfs_attr_node_addname_find_attr(
/*
* Add a name to a Btree-format attribute list.
*
- * This will involve walking down the Btree, and may involve splitting
- * leaf nodes and even splitting intermediate nodes up to and including
- * the root node (a special case of an intermediate node).
+ * This will involve walking down the Btree, and may involve splitting leaf
+ * nodes and even splitting intermediate nodes up to and including the root
+ * node (a special case of an intermediate node).
+ *
+ * If the tree was still in single leaf format and needs to converted to
+ * real node format return 1 and let the caller handle that.
*/
static int
xfs_attr_node_try_addname(
@@ -1409,7 +1412,7 @@ xfs_attr_node_try_addname(
* out-of-line values so it looked like it *might*
* have been a b-tree. Let the caller deal with this.
*/
- error = -ENOSPC;
+ error = 1;
goto out;
}
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 34/37] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (32 preceding siblings ...)
2024-10-21 22:07 ` [PATCH 33/37] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname Darrick J. Wong
@ 2024-10-21 22:07 ` Darrick J. Wong
2024-10-21 22:08 ` [PATCH 35/37] xfs: don't ifdef around the exact minlen allocations Darrick J. Wong
` (2 subsequent siblings)
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:07 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: 865469cd41bce2b04bef9539cbf70676878bc8df
Userdata and metadata allocations end up in the same allocation helpers.
Remove the separate xfs_bmap_alloc_userdata function to make this more
clear.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 73 ++++++++++++++++++++---------------------------------
1 file changed, 28 insertions(+), 45 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index c014325a5d7d9c..af493836ecc7ea 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -4170,43 +4170,6 @@ xfs_bmapi_reserve_delalloc(
return error;
}
-static int
-xfs_bmap_alloc_userdata(
- struct xfs_bmalloca *bma)
-{
- struct xfs_mount *mp = bma->ip->i_mount;
- int whichfork = xfs_bmapi_whichfork(bma->flags);
- int error;
-
- /*
- * Set the data type being allocated. For the data fork, the first data
- * in the file is treated differently to all other allocations. For the
- * attribute fork, we only need to ensure the allocated range is not on
- * the busy list.
- */
- bma->datatype = XFS_ALLOC_NOBUSY;
- if (whichfork == XFS_DATA_FORK || whichfork == XFS_COW_FORK) {
- bma->datatype |= XFS_ALLOC_USERDATA;
- if (bma->offset == 0)
- bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
-
- if (mp->m_dalign && bma->length >= mp->m_dalign) {
- error = xfs_bmap_isaeof(bma, whichfork);
- if (error)
- return error;
- }
-
- if (XFS_IS_REALTIME_INODE(bma->ip))
- return xfs_bmap_rtalloc(bma);
- }
-
- if (unlikely(XFS_TEST_ERROR(false, mp,
- XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT)))
- return xfs_bmap_exact_minlen_extent_alloc(bma);
-
- return xfs_bmap_btalloc(bma);
-}
-
static int
xfs_bmapi_allocate(
struct xfs_bmalloca *bma)
@@ -4224,15 +4187,35 @@ xfs_bmapi_allocate(
else
bma->minlen = 1;
- if (bma->flags & XFS_BMAPI_METADATA) {
- if (unlikely(XFS_TEST_ERROR(false, mp,
- XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT)))
- error = xfs_bmap_exact_minlen_extent_alloc(bma);
- else
- error = xfs_bmap_btalloc(bma);
- } else {
- error = xfs_bmap_alloc_userdata(bma);
+ if (!(bma->flags & XFS_BMAPI_METADATA)) {
+ /*
+ * For the data and COW fork, the first data in the file is
+ * treated differently to all other allocations. For the
+ * attribute fork, we only need to ensure the allocated range
+ * is not on the busy list.
+ */
+ bma->datatype = XFS_ALLOC_NOBUSY;
+ if (whichfork == XFS_DATA_FORK || whichfork == XFS_COW_FORK) {
+ bma->datatype |= XFS_ALLOC_USERDATA;
+ if (bma->offset == 0)
+ bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
+
+ if (mp->m_dalign && bma->length >= mp->m_dalign) {
+ error = xfs_bmap_isaeof(bma, whichfork);
+ if (error)
+ return error;
+ }
+ }
}
+
+ if ((bma->datatype & XFS_ALLOC_USERDATA) &&
+ XFS_IS_REALTIME_INODE(bma->ip))
+ error = xfs_bmap_rtalloc(bma);
+ else if (unlikely(XFS_TEST_ERROR(false, mp,
+ XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT)))
+ error = xfs_bmap_exact_minlen_extent_alloc(bma);
+ else
+ error = xfs_bmap_btalloc(bma);
if (error)
return error;
if (bma->blkno == NULLFSBLOCK)
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 35/37] xfs: don't ifdef around the exact minlen allocations
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (33 preceding siblings ...)
2024-10-21 22:07 ` [PATCH 34/37] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate Darrick J. Wong
@ 2024-10-21 22:08 ` Darrick J. Wong
2024-10-21 22:08 ` [PATCH 36/37] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc Darrick J. Wong
2024-10-21 22:08 ` [PATCH 37/37] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc Darrick J. Wong
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:08 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: b611fddc0435738e64453bbf1dadd4b12a801858
Exact minlen allocations only exist as an error injection tool for debug
builds. Currently this is implemented using ifdefs, which means the code
isn't even compiled for non-XFS_DEBUG builds. Enhance the compile test
coverage by always building the code and use the compilers' dead code
elimination to remove it from the generated binary instead.
The only downside is that the alloc_minlen_only field is unconditionally
added to struct xfs_alloc_args now, but by moving it around and packing
it tightly this doesn't actually increase the size of the structure.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_alloc.c | 7 ++-----
libxfs/xfs_alloc.h | 4 +---
libxfs/xfs_bmap.c | 6 ------
3 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c
index 3806a6bc0835a7..61453709ae515c 100644
--- a/libxfs/xfs_alloc.c
+++ b/libxfs/xfs_alloc.c
@@ -2762,7 +2762,6 @@ xfs_alloc_commit_autoreap(
xfs_defer_item_unpause(tp, aarp->dfp);
}
-#ifdef DEBUG
/*
* Check if an AGF has a free extent record whose length is equal to
* args->minlen.
@@ -2802,7 +2801,6 @@ xfs_exact_minlen_extent_available(
return error;
}
-#endif
/*
* Decide whether to use this allocation group for this allocation.
@@ -2876,15 +2874,14 @@ xfs_alloc_fix_freelist(
if (!xfs_alloc_space_available(args, need, alloc_flags))
goto out_agbp_relse;
-#ifdef DEBUG
- if (args->alloc_minlen_only) {
+ if (IS_ENABLED(CONFIG_XFS_DEBUG) && args->alloc_minlen_only) {
int stat;
error = xfs_exact_minlen_extent_available(args, agbp, &stat);
if (error || !stat)
goto out_agbp_relse;
}
-#endif
+
/*
* Make the freelist shorter if it's too long.
*
diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h
index fae170825be064..0165452e7cd055 100644
--- a/libxfs/xfs_alloc.h
+++ b/libxfs/xfs_alloc.h
@@ -53,11 +53,9 @@ typedef struct xfs_alloc_arg {
int datatype; /* mask defining data type treatment */
char wasdel; /* set if allocation was prev delayed */
char wasfromfl; /* set if allocation is from freelist */
+ bool alloc_minlen_only; /* allocate exact minlen extent */
struct xfs_owner_info oinfo; /* owner of blocks being allocated */
enum xfs_ag_resv_type resv; /* block reservation to use */
-#ifdef DEBUG
- bool alloc_minlen_only; /* allocate exact minlen extent */
-#endif
} xfs_alloc_arg_t;
/*
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index af493836ecc7ea..3c4922424f3fd0 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -3471,7 +3471,6 @@ xfs_bmap_process_allocated_extent(
xfs_bmap_alloc_account(ap);
}
-#ifdef DEBUG
static int
xfs_bmap_exact_minlen_extent_alloc(
struct xfs_bmalloca *ap)
@@ -3533,11 +3532,6 @@ xfs_bmap_exact_minlen_extent_alloc(
return 0;
}
-#else
-
-#define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED)
-
-#endif
/*
* If we are not low on available data blocks and we are allocating at
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 36/37] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (34 preceding siblings ...)
2024-10-21 22:08 ` [PATCH 35/37] xfs: don't ifdef around the exact minlen allocations Darrick J. Wong
@ 2024-10-21 22:08 ` Darrick J. Wong
2024-10-21 22:08 ` [PATCH 37/37] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc Darrick J. Wong
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:08 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: 405ee87c6938f67e6ab62a3f8f85b3c60a093886
xfs_bmap_exact_minlen_extent_alloc duplicates the args setup in
xfs_bmap_btalloc. Switch to call it from xfs_bmap_btalloc after
doing the basic setup.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 61 +++++++++++------------------------------------------
1 file changed, 13 insertions(+), 48 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 3c4922424f3fd0..02f26854c53cfe 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -3473,28 +3473,17 @@ xfs_bmap_process_allocated_extent(
static int
xfs_bmap_exact_minlen_extent_alloc(
- struct xfs_bmalloca *ap)
+ struct xfs_bmalloca *ap,
+ struct xfs_alloc_arg *args)
{
- struct xfs_mount *mp = ap->ip->i_mount;
- struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp };
- xfs_fileoff_t orig_offset;
- xfs_extlen_t orig_length;
- int error;
-
- ASSERT(ap->length);
-
if (ap->minlen != 1) {
- ap->blkno = NULLFSBLOCK;
- ap->length = 0;
+ args->fsbno = NULLFSBLOCK;
return 0;
}
- orig_offset = ap->offset;
- orig_length = ap->length;
-
- args.alloc_minlen_only = 1;
-
- xfs_bmap_compute_alignments(ap, &args);
+ args->alloc_minlen_only = 1;
+ args->minlen = args->maxlen = ap->minlen;
+ args->total = ap->total;
/*
* Unlike the longest extent available in an AG, we don't track
@@ -3504,33 +3493,9 @@ xfs_bmap_exact_minlen_extent_alloc(
* we need not be concerned about a drop in performance in
* "debug only" code paths.
*/
- ap->blkno = XFS_AGB_TO_FSB(mp, 0, 0);
+ ap->blkno = XFS_AGB_TO_FSB(ap->ip->i_mount, 0, 0);
- args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
- args.minlen = args.maxlen = ap->minlen;
- args.total = ap->total;
-
- args.alignment = 1;
- args.minalignslop = 0;
-
- args.minleft = ap->minleft;
- args.wasdel = ap->wasdel;
- args.resv = XFS_AG_RESV_NONE;
- args.datatype = ap->datatype;
-
- error = xfs_alloc_vextent_first_ag(&args, ap->blkno);
- if (error)
- return error;
-
- if (args.fsbno != NULLFSBLOCK) {
- xfs_bmap_process_allocated_extent(ap, &args, orig_offset,
- orig_length);
- } else {
- ap->blkno = NULLFSBLOCK;
- ap->length = 0;
- }
-
- return 0;
+ return xfs_alloc_vextent_first_ag(args, ap->blkno);
}
/*
@@ -3789,8 +3754,11 @@ xfs_bmap_btalloc(
/* Trim the allocation back to the maximum an AG can fit. */
args.maxlen = min(ap->length, mp->m_ag_max_usable);
- if ((ap->datatype & XFS_ALLOC_USERDATA) &&
- xfs_inode_is_filestream(ap->ip))
+ if (unlikely(XFS_TEST_ERROR(false, mp,
+ XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT)))
+ error = xfs_bmap_exact_minlen_extent_alloc(ap, &args);
+ else if ((ap->datatype & XFS_ALLOC_USERDATA) &&
+ xfs_inode_is_filestream(ap->ip))
error = xfs_bmap_btalloc_filestreams(ap, &args, stripe_align);
else
error = xfs_bmap_btalloc_best_length(ap, &args, stripe_align);
@@ -4205,9 +4173,6 @@ xfs_bmapi_allocate(
if ((bma->datatype & XFS_ALLOC_USERDATA) &&
XFS_IS_REALTIME_INODE(bma->ip))
error = xfs_bmap_rtalloc(bma);
- else if (unlikely(XFS_TEST_ERROR(false, mp,
- XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT)))
- error = xfs_bmap_exact_minlen_extent_alloc(bma);
else
error = xfs_bmap_btalloc(bma);
if (error)
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 37/37] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
` (35 preceding siblings ...)
2024-10-21 22:08 ` [PATCH 36/37] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc Darrick J. Wong
@ 2024-10-21 22:08 ` Darrick J. Wong
36 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-21 22:08 UTC (permalink / raw)
To: cem, djwong, aalbersh; +Cc: linux-xfs
From: Christoph Hellwig <hch@lst.de>
Source kernel commit: 6aac77059881e4419df499392c995bf02fb9630b
Currently the debug-only xfs_bmap_exact_minlen_extent_alloc allocation
variant fails to drop into the lowmode last resort allocator, and
thus can sometimes fail allocations for which the caller has a
transaction block reservation.
Fix this by using xfs_bmap_btalloc_low_space to do the actual allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 02f26854c53cfe..aec378ff4a9193 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -3495,7 +3495,13 @@ xfs_bmap_exact_minlen_extent_alloc(
*/
ap->blkno = XFS_AGB_TO_FSB(ap->ip->i_mount, 0, 0);
- return xfs_alloc_vextent_first_ag(args, ap->blkno);
+ /*
+ * Call xfs_bmap_btalloc_low_space here as it first does a "normal" AG
+ * iteration and then drops args->total to args->minlen, which might be
+ * required to find an allocation for the transaction reservation when
+ * the file system is very full.
+ */
+ return xfs_bmap_btalloc_low_space(ap, args);
}
/*
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default
2024-10-21 21:59 ` [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default Darrick J. Wong
@ 2024-10-22 5:56 ` Christoph Hellwig
0 siblings, 0 replies; 44+ messages in thread
From: Christoph Hellwig @ 2024-10-22 5:56 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: cem, aalbersh, linux-xfs
On Mon, Oct 21, 2024 at 02:59:11PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> 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.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 02/37] libxfs: compile with a C++ compiler
2024-10-21 21:59 ` [PATCH 02/37] libxfs: compile with a C++ compiler Darrick J. Wong
@ 2024-10-22 5:57 ` Christoph Hellwig
2024-10-22 17:46 ` Darrick J. Wong
0 siblings, 1 reply; 44+ messages in thread
From: Christoph Hellwig @ 2024-10-22 5:57 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: cem, aalbersh, linux-xfs
On Mon, Oct 21, 2024 at 02:59:27PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> 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.
The subject line looks weird. This is test compiling the public headers
with a C++ compiler, not libxfs itself. Maybe make this a bit more
clear?
The change itself looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 03/37] libxfs: port IS_ENABLED from the kernel
2024-10-21 21:59 ` [PATCH 03/37] libxfs: port IS_ENABLED from the kernel Darrick J. Wong
@ 2024-10-22 5:58 ` Christoph Hellwig
0 siblings, 0 replies; 44+ messages in thread
From: Christoph Hellwig @ 2024-10-22 5:58 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: cem, aalbersh, linux-xfs
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4
2024-10-21 21:56 [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Darrick J. Wong
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
@ 2024-10-22 5:59 ` Christoph Hellwig
1 sibling, 0 replies; 44+ messages in thread
From: Christoph Hellwig @ 2024-10-22 5:59 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Andrey Albershteyn, xfs
On Mon, Oct 21, 2024 at 02:56:27PM -0700, Darrick J. Wong wrote:
> Hi Andrey,
>
> Here's the libxfs sync to catch xfsprogs up to 6.12-rc4. I have a bunch
> of tool changes as well, but I'll hold off on sending those until dave &
> hch have a chance to look at last week's kernel patchbomb.
>
> The only unreviewed patches are these:
>
> [PATCHSET] libxfs: new code for 6.12
> [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default
> [PATCH 03/37] libxfs: port IS_ENABLED from the kernel
>
> The first patch brings our C usage in line with the kernel; and the
> second one is needed for a bug fix that got merged between rc2 and 3.
The entire series looks fine, the libxfs resync outside the above
patches looked pretty simple this time.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 02/37] libxfs: compile with a C++ compiler
2024-10-22 5:57 ` Christoph Hellwig
@ 2024-10-22 17:46 ` Darrick J. Wong
0 siblings, 0 replies; 44+ messages in thread
From: Darrick J. Wong @ 2024-10-22 17:46 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: cem, aalbersh, linux-xfs
On Mon, Oct 21, 2024 at 10:57:55PM -0700, Christoph Hellwig wrote:
> On Mon, Oct 21, 2024 at 02:59:27PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > 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.
>
> The subject line looks weird. This is test compiling the public headers
> with a C++ compiler, not libxfs itself. Maybe make this a bit more
> clear?
Ok, changed the subject to "libxfs: test compiling public headers with a
C++ compiler".
> The change itself looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
Thanks!
--D
^ permalink raw reply [flat|nested] 44+ messages in thread
end of thread, other threads:[~2024-10-22 17:46 UTC | newest]
Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-21 21:56 [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Darrick J. Wong
2024-10-21 21:58 ` [PATCHSET] libxfs: new code for 6.12 Darrick J. Wong
2024-10-21 21:59 ` [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default Darrick J. Wong
2024-10-22 5:56 ` Christoph Hellwig
2024-10-21 21:59 ` [PATCH 02/37] libxfs: compile with a C++ compiler Darrick J. Wong
2024-10-22 5:57 ` Christoph Hellwig
2024-10-22 17:46 ` Darrick J. Wong
2024-10-21 21:59 ` [PATCH 03/37] libxfs: port IS_ENABLED from the kernel Darrick J. Wong
2024-10-22 5:58 ` Christoph Hellwig
2024-10-21 21:59 ` [PATCH 04/37] libfrog: add xarray emulation Darrick J. Wong
2024-10-21 22:00 ` [PATCH 05/37] xfs: introduce new file range commit ioctls Darrick J. Wong
2024-10-21 22:00 ` [PATCH 06/37] xfs: pass the icreate args object to xfs_dialloc Darrick J. Wong
2024-10-21 22:00 ` [PATCH 07/37] xfs: remove xfs_validate_rtextents Darrick J. Wong
2024-10-21 22:01 ` [PATCH 08/37] xfs: factor out a xfs_validate_rt_geometry helper Darrick J. Wong
2024-10-21 22:01 ` [PATCH 09/37] xfs: remove the limit argument to xfs_rtfind_back Darrick J. Wong
2024-10-21 22:01 ` [PATCH 10/37] xfs: assert a valid limit in xfs_rtfind_forw Darrick J. Wong
2024-10-21 22:01 ` [PATCH 11/37] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf Darrick J. Wong
2024-10-21 22:02 ` [PATCH 12/37] xfs: factor out rtbitmap/summary initialization helpers Darrick J. Wong
2024-10-21 22:02 ` [PATCH 13/37] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock Darrick J. Wong
2024-10-21 22:02 ` [PATCH 14/37] xfs: ensure rtx mask/shift are correct after growfs Darrick J. Wong
2024-10-21 22:02 ` [PATCH 15/37] xfs: remove xfs_rtb_to_rtxrem Darrick J. Wong
2024-10-21 22:03 ` [PATCH 16/37] xfs: simplify xfs_rtalloc_query_range Darrick J. Wong
2024-10-21 22:03 ` [PATCH 17/37] xfs: clean up the ISVALID macro in xfs_bmap_adjacent Darrick J. Wong
2024-10-21 22:03 ` [PATCH 18/37] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount Darrick J. Wong
2024-10-21 22:03 ` [PATCH 19/37] xfs: replace m_rsumsize with m_rsumblocks Darrick J. Wong
2024-10-21 22:04 ` [PATCH 20/37] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc Darrick J. Wong
2024-10-21 22:04 ` [PATCH 21/37] xfs: replace shouty XFS_BM{BT,DR} macros Darrick J. Wong
2024-10-21 22:04 ` [PATCH 22/37] xfs: standardize the btree maxrecs function parameters Darrick J. Wong
2024-10-21 22:04 ` [PATCH 23/37] xfs: use kvmalloc for xattr buffers Darrick J. Wong
2024-10-21 22:05 ` [PATCH 24/37] xfs: remove unnecessary check Darrick J. Wong
2024-10-21 22:05 ` [PATCH 25/37] xfs: use kfree_rcu_mightsleep to free the perag structures Darrick J. Wong
2024-10-21 22:05 ` [PATCH 26/37] xfs: move the tagged perag lookup helpers to xfs_icache.c Darrick J. Wong
2024-10-21 22:05 ` [PATCH 27/37] xfs: convert perag lookup to xarray Darrick J. Wong
2024-10-21 22:06 ` [PATCH 28/37] xfs: ensure st_blocks never goes to zero during COW writes Darrick J. Wong
2024-10-21 22:06 ` [PATCH 29/37] xfs: enable block size larger than page size support Darrick J. Wong
2024-10-21 22:06 ` [PATCH 30/37] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname Darrick J. Wong
2024-10-21 22:07 ` [PATCH 31/37] xfs: return bool from xfs_attr3_leaf_add Darrick J. Wong
2024-10-21 22:07 ` [PATCH 32/37] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split Darrick J. Wong
2024-10-21 22:07 ` [PATCH 33/37] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname Darrick J. Wong
2024-10-21 22:07 ` [PATCH 34/37] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate Darrick J. Wong
2024-10-21 22:08 ` [PATCH 35/37] xfs: don't ifdef around the exact minlen allocations Darrick J. Wong
2024-10-21 22:08 ` [PATCH 36/37] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc Darrick J. Wong
2024-10-21 22:08 ` [PATCH 37/37] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc Darrick J. Wong
2024-10-22 5:59 ` [PATCHBOMB] xfsprogs: catch us up to 6.12-rc4 Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox