From patchwork Mon Oct 21 21:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844738 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BEEE1D0F76 for ; Mon, 21 Oct 2024 21:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547952; cv=none; b=LMyM4CChLGI3l/5VOoDv1+fKJ+aowMTtfNI0yYk2sg89msie9wI3jPzBq22xHyszhPJ34aM4GJDuY1IEN6cmiaUWOEFXg+PJiNb97dx0mGs9VxDVjPTVlCNn27OgpLY8LTRf3ZiBNKiiCMtVCDCFfFVYQgZpVZwUaxpXGpJT8R4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547952; c=relaxed/simple; bh=MwDHne73kBPcwK+qWYDuoanEycpw9K1O6FnhZSmNozg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MJ9j8hQezply1v1scNbmbPzOepnjATfUC8NFJUvPAsWzfMR8D/TJYFmbaHPgNBE7JNSvGrdWigkX5m+7KfbtX23st6DuDNC+yk4ZLXGZrJxvEBKEDtsFXnAT9BlXhGBXXiszkoHZ4kg+9AqU8EfQAwP2VPLUcBJBGDDMx2KeOKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R6meZg8G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R6meZg8G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D88E9C4CEC3; Mon, 21 Oct 2024 21:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729547951; bh=MwDHne73kBPcwK+qWYDuoanEycpw9K1O6FnhZSmNozg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=R6meZg8G27h9Ch3o+3GrT98TdQZlyOp6LmbBF5vknahIDULxlFUWnf77cSkk5R1Pf QxGHaCdBHkIOubqrejcD4LSqw3Z3y+t/DnUUpXz/P4Mj6E4wRQjWQnJwORulcOgThV tmtUkOS+wQbGcVC7g6/NXiKBQWp+CycGAlyVuARfngE5A4U5A9XV2exzpdmZnxwtya JXbLllXlQsPQkruEIyutawPlDbuCMOOOWnhFZaAEP05E+PL48HQFlsHl+NkBjerWHj aDgR0loYjGxtcKLKpqzS+Bzb3sbrc2homluW7rYNgueZ1tek88FgY4ym7dYT+QZQ5i QebIzjtZKplIA== Date: Mon, 21 Oct 2024 14:59:11 -0700 Subject: [PATCH 01/37] libxfs: require -std=gnu11 for compilation by default From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783487.34558.3883793884591579863.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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 From patchwork Mon Oct 21 21:59:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844739 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB4F31E25F3 for ; Mon, 21 Oct 2024 21:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547967; cv=none; b=YklVJmeBNOzy4e3DlUGcsE6i2KGkQZIkaGpSGxTSi+FPjfLq56p9q0Q8WzRZvRRyJNFZWSI+lJsOZ1kkZ6B30ZMsAwP/nlWWXj7HiKbshTMOybkD87yqQdyScTpM2aVmm/y4ESnRtsbD7/+c1Ywsz0g7zJXFr/6IqE8s+0z4If4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547967; c=relaxed/simple; bh=O4sbKkydiEx+d2vw5ow4wTV+Jb4CRQxlaMzX7rb4Ur8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cTB7ufkzzzto1xkme0R8DzGmBj4bCjC/cgxEXK7kWVNNTf985lzndHD4Hz0edrpOMJalT8C5I4x553U3Kwfb2XsXUugFKJwnvdgVPKMvKicnv4UT1CoaZ7CzMgsllM6kNaGINLKMtJ9FPShrsvwU2RMsqfq0G3jjpAeSFyxe3sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b+VlYv0M; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b+VlYv0M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D9AEC4CEE6; Mon, 21 Oct 2024 21:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729547967; bh=O4sbKkydiEx+d2vw5ow4wTV+Jb4CRQxlaMzX7rb4Ur8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=b+VlYv0Msa4BlLWCOLQ86amKDdWbkTGeic7gq0MrmziYRZEMtT9auReNkYijZVCCh otj+uNKGFrEXCtvo63ywH1JY75lgAwPQwkrg4fNV/E1sgqRm4n3S/z8zvALLiVw3VF aFJ6ezubGCBCMl8fdOzSPvAaW286Jll47hDv6w0hnqfTdfq0LEpVYgYDm7+cbxLLoG uUgnRp3lCSV39rYytefa86eO/hRiMvi42CIUMUBOf2npJdXCka4Mve+sXkHfbvzE9o IBU4BZfoB0Qc+ztY51pMAX9sHEI67blwvvJb9NCV12V+pl6YTGvq7xgx7Hrp2SvlaH qEzghrtO9bD1w== Date: Mon, 21 Oct 2024 14:59:27 -0700 Subject: [PATCH 02/37] libxfs: compile with a C++ compiler From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783502.34558.4926204658396667428.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Tested-by: Sam James Reviewed-by: Sam James Reviewed-by: Christoph Hellwig --- 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 + */ + +/* 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 + */ + +/* 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 From patchwork Mon Oct 21 21:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844740 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FF7C200C97 for ; Mon, 21 Oct 2024 21:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547983; cv=none; b=Yp501AvnBLBRILgF8AusN4WTa5+UExUnF2bQSxTe8JPiXlzsKltwlgZhmrvC+5Vu5OUI3xrgq1Iy77CoQELhyHt6jkm8Ap14OEkLJHggf540j4jXg22GFFvi+bhO82CQkSS9Qz12rm2UPcsZbobo+jVIKtWL32TQE5qQOd2veyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547983; c=relaxed/simple; bh=JQLGJpFBOGKVwneAIfeXNaS757pLhKyadE4hKQCyQMA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FMdSjSNriOuNJSekLLtV/H+XXCNZzzDdcKW8YoqFj5fUa7fyw3elOntkmUjBJqnkhA2ukSuWRhfIzsPSDBz7qRQJHTq29d3fksHnI9yHMiUXoM7KNoybQGUJYooZtcOzGuN7a3XAARCnFtXChtifguCDwcYRusFIxNs9d05O7Ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iOMtJvV8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iOMtJvV8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28D3BC4CEE6; Mon, 21 Oct 2024 21:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729547983; bh=JQLGJpFBOGKVwneAIfeXNaS757pLhKyadE4hKQCyQMA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=iOMtJvV8szT5F5t71wbZEBpVqNJIX1/HRhhx63GoW+RbQ/SAaxGgByyHIeusmBf7i tWR457ED9t/mR5Q4yfPufZ82gLj1Gw+1DsLQugxzasDybPRCII2I4RKTsxUWYze4J8 6WHBYCTKMPu+OFA2xPakfXzn7hBy/T+ux9HQib5IBQEp+X/0wZe1NccyrEt4H7Y2q5 ChLz5p+f9dDO8ZhRHpsZyhvQWrocrlsXBQC5HQUAUgBDxrgLMM08Ba4xEv7uM7HPLX I+NP0wjFA3+ozDW3J9l5JWUFu4zqDlizhXC2OSlSYbj7dLuNjDnJkJHeBZC8BHNyrO XLz7iOfW8VPig== Date: Mon, 21 Oct 2024 14:59:42 -0700 Subject: [PATCH 03/37] libxfs: port IS_ENABLED from the kernel From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783517.34558.6960888274382502007.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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" From patchwork Mon Oct 21 21:59:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844741 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 366CA2CA9 for ; Mon, 21 Oct 2024 21:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547999; cv=none; b=JOUjAohNjS7u4mcVzm15X3h2xH8NE/vy7fNx+woMG18h5h+HqcoqiSgXBrkppA/KUoHmGLid5T7P+XD7lU5vyOZ85/duIIObPnjF+A4Lg++FMeFDLy4Cj0jgjCwhIj2BLk0NZy3HYaK0C1yW+HcivH7TEvbO7KxP7+RyHMgoTZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729547999; c=relaxed/simple; bh=p8s03YUPGL5T3AUYprap2ZNhUpLsCpMbOZdOciQjSvA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iHJr6a3Dt15roax9/b6OzygWfw0RxpqYAXrJ4TaeRHgVRFInjQh1dsBrxhwbrHl5cJNFLLYdw0ypXKC0mmgBnT48Kjna6eSM7e1sduPCS1ITkIR8ofGL07OaFUvAdLWO4esZdKw7vIJSbSW3TJC2tCjUTvXzVBs+91JoK3YyPTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XGTh92Lx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XGTh92Lx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC8A2C4CEC3; Mon, 21 Oct 2024 21:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729547998; bh=p8s03YUPGL5T3AUYprap2ZNhUpLsCpMbOZdOciQjSvA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XGTh92LxSgd1XaSqNFpsmKXYBE29ZPdXpmGWPh4XdACDjyBbmMlETRlXXhL1kKWxA 3tZiMYtZJEddfdiiC+1oh6uQP1RIRoaDp+eBicQWNpMP9zVsOnWI1yVQs0nMedfcqH 7nq4X4yEH+9iSXBijWDyPvQQhaA/GF3vJLCBUP6IuewM79hNj7uj3Q/Z3f/eW1e4gv EqD5lDVjgXeKavEer5lNZdqDkkoDuSRkD2q8op68ucaBj1YpT7XsbGXLro0EUUrhJ7 bG2Ko4031ytR/rMTzueNKqVgDaxy/V7jIHSHfhOPNkcD2ToaJAAAQKFVO5YtOWa2ei jBCk8AXq1gSew== Date: Mon, 21 Oct 2024 14:59:58 -0700 Subject: [PATCH 04/37] libfrog: add xarray emulation From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783532.34558.3574729108397726957.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Implement the simple parts of the kernel xarray API on-top of the libfrog radix-tree. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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__ */ From patchwork Mon Oct 21 22:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844742 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8641194AF6 for ; Mon, 21 Oct 2024 22:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548014; cv=none; b=Do4OcToedR53XZwWyZZzB+x9UlzcCK5ctlzPxHD8HPWsyDegp11OTZ6LNoO4IuDEHoldFMwdPAt6ei82YS5j+Y1ElcKBLxZtGIRFEzrKknHUE+WKQb6oIPNzZzJnIw+kO+oyzv5YN5zW3bhdj//yI15G1qSvv6raxyGZVyYzpmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548014; c=relaxed/simple; bh=lzVoYZzuy3JOoP9rud6PBrHJYBfHfKzj9rizo7qWaHU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hniV19LjjCequMOLYo3tOsU/TqZBeRaHgZt8ZgjX+Joq4Boc3aeMtnSTQSL0pAuWhH8rNPCB2091zSlpEc0MVJCqccvcnQpz9kRqGIq6JNSdg/PUwmRJPZpYoDpCR7cxeQl5psuN+LU379jPQX5dLO3n7Bo+E+vbKFbJPu4/u3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FuMUgFFX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FuMUgFFX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60794C4CEC3; Mon, 21 Oct 2024 22:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548014; bh=lzVoYZzuy3JOoP9rud6PBrHJYBfHfKzj9rizo7qWaHU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FuMUgFFX4Lw7QgOJAYJ3+dZyy/MO27GO5Lb1s9BTlQNfSJ4Zh5VR6qMY2HUjrWQ7Z S/mQGaKF+xjcgFBgZ9VxRRN8auxFNum30A2cG/zIfB3z58DxVZ0JUaIR9pIM2w9rs7 UBU3Mj+DwkylWSbryk6988y9q/FLS4PcbeDla/klym8rvYcpGnvqzbOqRuCe3WvZij WapmxpGbw2rEUZo/CEhou6whsUAhaCSdZRCXz/VOHSN0Gt0EWIfZum0N3uur2/y5SX r3M9h8g0/52aItCmFL297NT1cRlUush6ixwY90TNctWyPPF8F1RS0jAtmt2GF6COwC qiF9Z8TR7A7GA== Date: Mon, 21 Oct 2024 15:00:13 -0700 Subject: [PATCH 05/37] xfs: introduce new file range commit ioctls From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783547.34558.563053329709168007.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Acked-by: Jeff Layton Reviewed-by: Christoph Hellwig --- 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 */ From patchwork Mon Oct 21 22:00:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844743 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FAB41E04AB for ; Mon, 21 Oct 2024 22:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548030; cv=none; b=Oz4tDL+Q4EOOe72gQ+KsICTN/g31YU9Ult+S28lWQ3YtaY24E60LnMjSb0iAGsT0YCj0EO7faiVX5LouL9vnrLwscHWwGbBGJXP/ZwBP38ug5e+xTVOAgqslIjUOFdnxvDzN6BBBcz+mf5erGECigaJuLZ0e2GquR674oS0mlE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548030; c=relaxed/simple; bh=mtDnYIlDEa0PDjO4XIepg+t8AOQUSBrP/Y9TrPiaYNs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bPmA8yBuii4sDXAbsufXKgfm16EYLjNQ74qE1nrnkwUyTnX0C1NX7/fbPsc8gt1+X4BqAGxvgQm7Tl//n8zz03eFykrzv3+fNti3utUFMgFQNzf1cn6M064fQSnhNM2/C1iAgwxx2YTd4aTrEONXCgPZKlSirEx7HbtquIlucko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VcVpsK3+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VcVpsK3+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00003C4CEC3; Mon, 21 Oct 2024 22:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548030; bh=mtDnYIlDEa0PDjO4XIepg+t8AOQUSBrP/Y9TrPiaYNs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VcVpsK3+0T3gHg53N2ikda47Hs9/6m2tGYSOqHCCIyWU+jKKBcBvaejyLGuSIHUAr iHkBZ7ogRnST7Qt8TiRAjzEjBmnPaQs0k4yQL2hAmup1pYjPw6nKD4jv50b4A2ovnX fuQGNjWaB56JEzs7sF/rXCBlftJIuJJMh3LlUICj5wIGpEGdYw0ftGHO5EayFDqGbU vWj5KPZ7Q23xseCB4HAUSFxzHc8KMCSJb2T87IC6Zl8tnk6bwSa5uZ2bG3y+kDa5Rh uAe+JwucJGtFc9L+MGCgIg+ItZI6EpNMc3Tg4grJ/9GNLobEZTwiXJncVl+EURvige EqEledgHhPSsw== Date: Mon, 21 Oct 2024 15:00:29 -0700 Subject: [PATCH 06/37] xfs: pass the icreate args object to xfs_dialloc From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783563.34558.10905035940882314521.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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); From patchwork Mon Oct 21 22:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844744 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B97D11E1027 for ; Mon, 21 Oct 2024 22:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548045; cv=none; b=h1VQeWXnBXdzv6MVzPTL4fsBPzN5JceKt8bLoe1qJADUJVcRZwb0N7+6VIVh+MmHR2Ffroem72omsEtR11fYOH8slh370LVo1rC3B0FwHMdytb2MCIzY90sekhrgWbKr9hwjkVVuaiSY2QkCx/YxMIm0EXfpJ9h+ex4hD79WC6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548045; c=relaxed/simple; bh=x/VHeZr1db/0cnjY3yrszpmQfhlEnFBp3ghbmgpQIAw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vx7VWdrGgbuDgphkMZOFXFau1fZwD+sA7cXH+5FffFepdQGdpKy29LYK/FtkgbCR60PNg8FPH5mwmHg7nLTZxtCkeVh4ER1l62N1sFSb7ycGUnc8AhI3lI/tktqyIuhfVAlFNBBq9P4EUx8vRadOeRPUxIobaTYTe8SyoVve+ns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cngetNL/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cngetNL/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 926E4C4CEC3; Mon, 21 Oct 2024 22:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548045; bh=x/VHeZr1db/0cnjY3yrszpmQfhlEnFBp3ghbmgpQIAw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cngetNL/NVYFknKHXbeE+J7ODml7kc36utmJjiASSJBBsWZarUoORdb7qieTLhjIX MM1Ad3y1TqWHzMROXTrUch6wHjf3diaMM2X/dqleJQhyKwJTTqigNZubD9CMgUNHUQ WdXzlOki4vXKzizvbGE/dy4k2v/ZIcDZq20/KgSavEGmy3qKLW0r/B9xD9AaYBm1qQ k3PTkzxj7AS+Vjetif5Zr+2PNhZLA28E73yIrJXmfAcKoz8OwZ0U6Zx/oX1eX88vDF BtK0iUnsAljrDYI8rTY7pHKktkEyc9+6HZgrldHeeK18Ag5ziZDPQgOR6onHLlPkjt Rgc0JSr+ZaiJQ== Date: Mon, 21 Oct 2024 15:00:45 -0700 Subject: [PATCH 07/37] xfs: remove xfs_validate_rtextents From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783578.34558.6394842867679427215.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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__ */ From patchwork Mon Oct 21 22:01:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844745 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FD972CA9 for ; Mon, 21 Oct 2024 22:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548061; cv=none; b=dv8VtSGShggk+LgWes12NRuo9rpjkTnsZ/RYAqDcEuot1HDyqCZnJ4P0EdMZARBbuRwMO6FNfut2OarSXjtTteYgGi51dF46FEqlQ9pUsYD5mYQdPVjSLM7MKXuLsk58Cd3Rrd2MMSVMVdmnZBFJfJavHGQg2xxWgfsgYZN3pTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548061; c=relaxed/simple; bh=neVwpzzWoEfhxcLgi6U1ic6a2Tpij+mBOGXRufzDgmM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YMbLeGJA5CckFG9uSCcvzhAduaj0HetUl6cSBSdeAvbOFVh2HDfYCyXnDyw0pWNQbMI9263IF3M3/Qn61YIFAqpgyKIW4CxZCUbTbH3Vt5J+0cHvj8rl/HT76I0JL6NgHUWeyxEjrmtloE8H+xKBPSRIz5E2nFcmwIWrb7bNCLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VhpoNc1Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VhpoNc1Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AD7BC4CEC3; Mon, 21 Oct 2024 22:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548061; bh=neVwpzzWoEfhxcLgi6U1ic6a2Tpij+mBOGXRufzDgmM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VhpoNc1YhGeIu0pWvZotqVawY9aztuP/qNI16uF+ztl0uDnOsoNFV/5LuiPVhEIZU LqnMnENZSpY+Xop/9GKfoWvQD44vh2lRYPjzreNaGkOA/1AlLPo4V9q0QrVSLpNZ/6 o4pb1CNaTwaxNavFuiU0N45OMF1rA2AaxtvCmnicDDQ27Dg66q56wNOl3YQocRNX5v psy+6zAo0u9cQQGcxQPhjErj8QHp/1jQp604UeoovMKsSqSEnw42kx3tz6e5Bm4sL5 FzyqCAvZl+bCvAeMDcNqC2sF+17fXkojjPsh7eBaOhOlg2ABo0Ldu5BX2Idc0TqGCV Ut1s0NzagCW8w== Date: Mon, 21 Oct 2024 15:01:00 -0700 Subject: [PATCH 08/37] xfs: factor out a xfs_validate_rt_geometry helper From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783593.34558.10965735688692303380.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong [djwong: u64 return value for calc_rbmblocks] Signed-off-by: Darrick J. Wong --- 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); From patchwork Mon Oct 21 22:01:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844746 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03A64194AF6 for ; Mon, 21 Oct 2024 22:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548077; cv=none; b=QQByR5pbYaxpT9xxWzjL+ZjuxpSM8rFfC4SHYfmbjeIjP0Fs70bQ1oX5GZznqJcXusWKhTEUyEQ/JYuxegu4D/f0aCjydRpcUenF4XMub39LXtelSRdijdImatTQvJiMxqjTyHm5ksDxYLLl0H9Mxbz0eQrnzMxxM3q29mvTSl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548077; c=relaxed/simple; bh=9pSWW6myBYphmV/7ZWKjzJDBWqRUuXQMijVw2gnl2yQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LjA896sbhp8aPkI1iEt6N3GjlKsRk7HU7o3hr2Hz+I80QQy+eFRQxqHOMFyeZGL17767Pr+1e7kwI3N2Jfz2JxI+qRV4tdu2r4y0qO8K1gOAqAZP/PlyPcso/C5b8SB7DDsI3z3FkrgnKCAZs1+p0NH1mHk5nOT55jxSqfHX2+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IvqvUR9D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IvqvUR9D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEF16C4CEC3; Mon, 21 Oct 2024 22:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548076; bh=9pSWW6myBYphmV/7ZWKjzJDBWqRUuXQMijVw2gnl2yQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IvqvUR9DX9AVBEVtfta/ipuxr4TJExzTvS4cZw2P2KRr+sjT5hGDUJ3Mkc2cgXfmG pVF7EeXVjTAxQHaceCpTS7Npl20QmpotL+PVGMSMeyacuCzC991So0THEt08FCYQvE ZZKmdmuccnpCgySsQCOLxewIO9xJIHku0k81vwsqe/so8xgCGrvrEH84mt/lYdjWGF aplSKYcl8TXVEvm9oONEF2JMH3C7KGRi4BIS+SyYWl7pGHALm/rJrUGi9CDuq3h9sI 9Kh6azR/M6D+c8DtNcqXI6oWLQjfVPvW6G2k3Gb15DDBvpSdAtI5K70tWmPk2+R8wI wLE7SQEejgv6g== Date: Mon, 21 Oct 2024 15:01:16 -0700 Subject: [PATCH 09/37] xfs: remove the limit argument to xfs_rtfind_back From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783608.34558.107625526634874383.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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, From patchwork Mon Oct 21 22:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844747 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C5C919581F for ; Mon, 21 Oct 2024 22:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548093; cv=none; b=ggtZbOBn7UlxCPOk9ETnNDfdqu894cDXOywit+bb7LstmA5zk3i7qQuy+pBC36N5r0utV8J2JrmOX8luhmQTKIetonuYtNOtECNJnKBYB1odaFtz3O1lAaJGk6e1kgkhaEJHdR7jTmDZVkPh3O4lYimCYXbGqPa43Pe4hOW893U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548093; c=relaxed/simple; bh=RIiq8wv6cT21v+OF5Npukq//GNb2e8AddT2Ptw9IdAg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vun4k1Z83maEIXsMv/oN9X6b3ifLjeNgaL5IqzabapL7RBiTEmLxd+9NJbnYmYOjGH/0Qo3VHE09uJZIxZNJ34TK/HDXb9f5H7N3iYF+fKPSvgz3lcYbLe4UxlAXwzPN/9JAr6iXiMIs4nFXwAVlXpFc1dK5wAaPUq2UsxFMyaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XvhcJYU5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XvhcJYU5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 889B9C4CEC3; Mon, 21 Oct 2024 22:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548092; bh=RIiq8wv6cT21v+OF5Npukq//GNb2e8AddT2Ptw9IdAg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XvhcJYU5w4X0pEdNx4bzFmjH4WE4HTJfn/gQmaqqwskYEOgykRau3Shwv5ae1MmSH 4ws/LP93dVw9HhqEe2mOApio2bRObrqw3TshwaB+mB8PQ1oGHUBxR/eyEbD97cAOsf YvskawurngnQ1DLudxFaWOBpkIYj/podTKEMKod8E1SblC15XJl3rs8WD3Y65ReANj PwV56Kr8j+llxQX8PW21CJS7uTVShoj+YHc/bd0IXdAcwAH93JXiNKgLZtotE/+JU7 Wbnj4s9J0Y8eqZ4xEbhB9nw/1OT7Ye0guF8yJvOas0iVDOM2aFBBve6Tl7hCZZS1mp 1ig8ME8KAmTqQ== Date: Mon, 21 Oct 2024 15:01:32 -0700 Subject: [PATCH 10/37] xfs: assert a valid limit in xfs_rtfind_forw From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783623.34558.992158853295468624.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 6d2db12d56a389b3e8efa236976f8dc3a8ae00f0 Protect against developers passing stupid limits when refactoring the RT code once again. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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. */ From patchwork Mon Oct 21 22:01:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844748 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE1AB2CA9 for ; Mon, 21 Oct 2024 22:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548108; cv=none; b=qcUXgcbOJdR/2+pBRzjeOducABFss9x3UbR0WdQT5EorwuluELZtCoP4ejKf352qx2NdmuGLoRHvvAfHuUlou3VSl+6+mASdj1XtuwZFfL3Ywo6YhJbbmZvSUCstkYfGCgXqb5tK7lNky1/a8XqMYuw2oZg5+dCeggGWrS23S9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548108; c=relaxed/simple; bh=vAaI00AcFFFoGiGg4HfoHHSkdd7pZjID/WpJHDG1SI8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EHtNF1sxGa9KGcVIimT2ZwRyhCN6g412eg4EfTTi7S8jfqwkvxFKn/Y6CaShgHpBcvLVYbHKnx3CIgHqsZ95tqjdO7HyUdBS6tTMiOcTVoKK57M8HRg/lLyt3k9Ks40fRPX0Ilvnm/xnru3JOFkxoM3ZE9TJ9Iem2YfpSiUOGM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O3F0+I6b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O3F0+I6b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 283EEC4CEC3; Mon, 21 Oct 2024 22:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548108; bh=vAaI00AcFFFoGiGg4HfoHHSkdd7pZjID/WpJHDG1SI8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=O3F0+I6b+EZrvzVQ7BCCUnOIC7ClNIMwUXz29PJLf7gtT4GlHUlN/HGrdGyfSKxvO 8I2AmBcFUD+nFiJTWzK8qA/W9hib1IgVzfX5W8s5x23pq8oEO4SIkVsRTo6G1SeMnz PkYive3dAm+oi7fZM/sBcTr8VpZPwogo4VO25KKUwGqnvo4yvjmEDrwpbKW2r+FWOR b7QiGb9gmSp3It4gWzxhT247U93nrHGivI6gNVzqpbizFWqaJHe4xf7oCrtk1UoA7z WkO0H/Zrm6ZMvrOzNidG3AKXDgIX8OrP7OKI5f0yGcvKRW2D/mHMHWLkmjnbdiy5df 3/x/EEk3M++Mg== Date: Mon, 21 Oct 2024 15:01:47 -0700 Subject: [PATCH 11/37] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783638.34558.17263401819655377944.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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, From patchwork Mon Oct 21 22:02:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844749 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB45B1FB3FE for ; Mon, 21 Oct 2024 22:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548124; cv=none; b=CAlGyRkgqM736S1skvJyPpfpro7QI70VN6VopiL3O2Ac9TMZaV2TQ0JnFsqXGxdaGAJ5/Crdw8qBxPqyJJyMcUmBLCRXYIVphYhb7vFxismJSpUFDu/3ItHa7veMKQ8skTLqYR1sbRbTnaV4BAyLfcGLHo+HbkClRigPCpd0sCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548124; c=relaxed/simple; bh=8svOkqyDhvtmoKyRmdlfVLGDCIW5e05QT/GBbirxhQA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d6R9vRFlmHsAIhN+nBfc/Fj9aWGRFg9Xym3DCjB7aTPtt9+dMYeNLptMuKOfdWiV9Ul1pbyYpM+ZO7irmaumblEx/F2D1Sy8fIctz/4dqbYLYBOVLnpBk9ww1214LDA/XNXjM2Q9NKnrqRMAc+H7Sh8lXjf0mXZCSHTk2sCNCuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OJuMBrhG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OJuMBrhG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEE0BC4CEC3; Mon, 21 Oct 2024 22:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548123; bh=8svOkqyDhvtmoKyRmdlfVLGDCIW5e05QT/GBbirxhQA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OJuMBrhGYhHPqh/4A+5KZgVTPSa4gyhGuf4L9/CEYQ8wGnvQVhK/y/cigFlIvSIKB 38YS/VLDCchw9fplpWlVKzVnST5p/kfNk6C6EZPQ8En6OLY+grAuIiiJiDrj5/ecoM TJ8oWIuXJFO0vl8F1A3zmkJ+25ouDNlJHMjbq7eTqGW558nUhbuDtInkGZgslvhcTe nd5cjw9Q9w4KdYvTvT+iXXW3erFEsWfzZpm97YBks9B1dirLvRnozMAMsFeNejCVD5 Ggz6OKNxAJrRwDWxgqkv3lBDCQUVOuMS1m0dGp9SuMoR4XOikcqRcPcXgtoGDgC6rA cKZBBE4hcZffg== Date: Mon, 21 Oct 2024 15:02:03 -0700 Subject: [PATCH 12/37] xfs: factor out rtbitmap/summary initialization helpers From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783653.34558.3753357064906149840.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong [djwong: minor documentation and data advance tweaks] Signed-off-by: Darrick J. Wong --- 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); From patchwork Mon Oct 21 22:02:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844750 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 957081FDF85 for ; Mon, 21 Oct 2024 22:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548139; cv=none; b=a/9iUYxfa/u8DgjqMn/agz94wCWJ+ZVX/NkLOtBubJsph+KdhjawxYfJnJgnh+Vtk/nSnjqFW4jw/ymD5hxsQ3notzefydIGTxZ9ZL/1I3hlU2A5MyByeVkuaGGk1hAKPPsdpaAJXd7h/Xpm4/mOQyFZxtmMIEZiaKeABdqrC/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548139; c=relaxed/simple; bh=puQ75ii0lltlveV/actzFuGRC1zAWDrLanJfuUqHLrI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g0X6rsjpOgTqCjQpBSh+mFYJsMJ3GmheHI5A4cH4J7mdfZpz8CHpgLtN+OutMKi/ouMx3XS7d0rZseF2HYt2yHrLohlhZ27MIe6Af4WspjNbT7hWgBvcfuiGGny9reAJNuToLIXrwz3yFfN9916aaiWpwbr/tDHNMSmVIb95njE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ADDPxJPt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ADDPxJPt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DEA6C4CEC3; Mon, 21 Oct 2024 22:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548139; bh=puQ75ii0lltlveV/actzFuGRC1zAWDrLanJfuUqHLrI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ADDPxJPtkwQpKyxk/3xSocaIo8Y02qd9CZFU9NbjQCeZjKKEdLfbIcMIULFphpPM5 +wPBO7xUk4thq6kTlhqaIjE7PtPnZFonmQBWsGuuEC14w8dBO2kfttUJuwbFJ4y2X8 b8eoDAA+ev7LeKFyCrrd4rX3GDh838lVf4hQ2vnpWSJ1NQ4kBdVapp7Imx0PHwhlYg MO8f0jCVTEjjtgPiXN2s6WoMeXjz8svOmcpk8EnoL3O19OBPc8V5gfx1iCyLUvr+i0 XsQlnnA7sfRQJDTyrn4HnvlWBmhJyKUgogKbn0OtLQEOYHiEcZG1vIkELIkExRF7CK KI7pI/FBv+UQA== Date: Mon, 21 Oct 2024 15:02:18 -0700 Subject: [PATCH 13/37] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783668.34558.7651064684450347098.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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) From patchwork Mon Oct 21 22:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844751 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBBBA198A24 for ; Mon, 21 Oct 2024 22:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548155; cv=none; b=O9crzvyzEkAr/p/ADcs3rT8Tep2U44JtiUHvGD75DFVXxLDoY1bSgTF/L8tvIc+NaSTc74L5eRoCaPTWGh3V+uffDX6X5pkFoATgR5xEpkCZKpPTHgs9TuCeUDjqz5ALdtEMYbOhpMHo2oCgSVMn3YY2G215tgov+BcMTr8rrpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548155; c=relaxed/simple; bh=Rvd9PTX3D8ti/tL+t2nPfT1geOYz0RJd4cjK1H5gnsc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SUDkq1FHFwUXPrsqUm9gW4zGFJudx/7OTffCNt989bDBI57HTgVZpYKIIZnx/lm0P2Q6X+0odyp6kcWmigN5qcOrJATi65UFnLY6MH7vlNxzg3T7wbEiT8cNFYmpctnWuGyoUE+D35VrvyowXibLZE3u3dkry+teoSPMRjLQLCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tDqcgWFi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tDqcgWFi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52E0FC4CEC3; Mon, 21 Oct 2024 22:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548155; bh=Rvd9PTX3D8ti/tL+t2nPfT1geOYz0RJd4cjK1H5gnsc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tDqcgWFi6sgP2eYUfdv9Kx0ra4rf3R46BKEF4srX+ZBoNWEP4aTmVGzsNr6ELZEpJ C9Or4RG7eukFON7NlvyfTrTgPh7fexUe5DLqbszNab7MLKrisC2g0g0/sOwMQtp3UW l5Sem7rEguNDrOgZUUDNOxw24hzrDZKZ/A81xwnxYI5qlEe4u4zjmk1gVnB+K9Six4 +ZXavfOUuMStbA8EY8XBUHp2tBjS0vMxf0noaVl5fOqRTBSs8OKlsmJT6mqZyEsVCe gYMCvMkGR3rV/qsWfXrmEGqLZlzOdPPJBV2qlAJdEmiE9taz8ajj7wUoseOS3OHuDS ggyiA8BzZEIKQ== Date: Mon, 21 Oct 2024 15:02:34 -0700 Subject: [PATCH 14/37] xfs: ensure rtx mask/shift are correct after growfs From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783683.34558.7324732496611226094.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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); From patchwork Mon Oct 21 22:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844752 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 226851FDFA0 for ; Mon, 21 Oct 2024 22:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548171; cv=none; b=juu+UYvY5y3XeNIupP8uZHBJdsiFiElVl4rSA8ZHet2kp1B+SdoAvy6d61+A1H+/b5KUe0CYy33HiwifxUfLFSvE11AgOqPBZKgNbWiGNwrT2hIMFvjEcGpMYZEMd+ZBWYL2nstVt2KCkBZy89kK9b0G5pr0mvz5M9XMxF9N5Ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548171; c=relaxed/simple; bh=AuqRh3OrtuH/JvbRD6WrnZHL53jxm6CypTiWutKsO5U=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NkUpRp1ikgVTbmGF+y80pJNggzT0Hve6z7mWtHwvS/LjKzM0nBr0er9uI2ZdeQouWcIzyF/I923ENVHlXAABpJe4AKu163ICkiprS0qrOjy5ztTKkm9bYEpIWmvq9Mmyzu0YwumWmSgf9sony2W4tixfpOkjhxTcJABva89q7Z0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ngw5kZUo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ngw5kZUo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F037AC4CEC3; Mon, 21 Oct 2024 22:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548171; bh=AuqRh3OrtuH/JvbRD6WrnZHL53jxm6CypTiWutKsO5U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ngw5kZUorJCOs1w54zP7KoaTD5hLvjDHp+PNXaRe9CGKeXKkCfR+/efUpTzdxY3Zz wyPAg3yQrjNfEyD8ltxOX92jaB1ZifJrqjkQ7DTIKQE8ZVa4mwFDHf3hr8vDAI97jJ NRxXbslNvX9hXz8m4q+x+e3HuzFlFs+vWqhJ4LPOBsanlwxwxcLYkA1/VQYQAf1cxt tNBJtWVjGqUSnqYl0EX+IVm0Z1fUls5Rl+A5nCmIBytHFhI4CdnnzZ5YL7B9QMej9I /8pJlXQYtFSsqCFzRTcnL4HLPxdsJhlaR9kdlVrvi1/f18g2M1jZ/05kjIkb7HVMP/ vhREw9h2nHbLA== Date: Mon, 21 Oct 2024 15:02:50 -0700 Subject: [PATCH 15/37] xfs: remove xfs_rtb_to_rtxrem From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783698.34558.6399418785062063785.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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. From patchwork Mon Oct 21 22:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844753 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17C7F19581F for ; Mon, 21 Oct 2024 22:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548187; cv=none; b=OqDYW0KsnM6phLkbfAN0DtSy0AndPv67YjzfK0Dys9p0BNxwsZcEa7BKDkErszCfQvmWsG6v+G3XIHK1ReuAVmIgxS2HpV0SQKxjLqKKbQVI3TnCUdv++kX18/9u2DyVvNFsp3q8cZV4FUK2gariub79LoXr516blW0PmXN2rHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548187; c=relaxed/simple; bh=aDphQeYyK23f/42cdKznjfHvSdtjC+v4pkbxc5/PtP0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DfHRcdWMaO0DcYVM9FNtt+GLt5EOZoUtIl05CmkofM8jYIyRJCQg4z0AuvoeyOsjZlqbPPekIRN4lDUF0MO54Jd09NaMI38phSsNZt1qehCYg4qza/76BRdrcETXCJ4ABYNqkVVCj+hS0ozmNh3Tw3HV5HxCmFMMeJ1LxfJVgOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EDivApYx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EDivApYx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F705C4CEC3; Mon, 21 Oct 2024 22:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548186; bh=aDphQeYyK23f/42cdKznjfHvSdtjC+v4pkbxc5/PtP0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EDivApYxLuaYt1k08LnsMfTxAwLAudjW4a6XVpK3qpN7qerbolAwG/HYDd7+htmz8 N18EU6Y3GgTbX0l1MpKMdbUjg1HUhj+EkcBBs70vpQ+DuwTZXg5WPpfFzdbzms7yPH /wNr5o8fYD+KagNuasdc9b8NXHAW4byuaIwrIhdVqKFjuFG+nHeG77Ukcd9p+CBXex 93j/1w/9pgSXquUHnLDB63QAxeTia2fPWdQ/CS11P19FXKmxwRMEWD9MJvGGhI73sV e+ALquwyKKbX1+FD5Yu7yeGIM/DNYmPE1l3+n1Tn8SQTtkwt9VYvWuw9DsCM+3VNtf f6k+hmVTEQwNA== Date: Mon, 21 Oct 2024 15:03:06 -0700 Subject: [PATCH 16/37] xfs: simplify xfs_rtalloc_query_range From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783713.34558.17245720172191250363.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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, From patchwork Mon Oct 21 22:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844754 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D1002CA9 for ; Mon, 21 Oct 2024 22:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548202; cv=none; b=XV7GPFR78790YkNnrVctm2X4Yg8JoI0jnGIS7Yhj/4HjHadkrRczrhZzvzQbWuC3RRL6LOSi6m6FpKKwKf/MBPV8F+bXHdcCAsmz9rrRkVzvXQNsClNGikZVjq4Rp66ozRb6tLliofOj1MHjxUBYLS4olzt3iTE9fee26ndQ+No= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548202; c=relaxed/simple; bh=RqVGnlsjdzM4k+hiPQ00Hj7eqU6yxfXEbY7XmeDmQcI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P8KsTHaC1d95Nj+H1h2Jz2loRoS/tge3sTKn9WPdw2jRuAygjIWXjuVjmjOKZetPQusiMQXcDqJ2nvQqvfW5SK3cXZ+YHHhYBEtYnOe+7d6eC171JlqZjwRhfJ6TEWYeM+TAecan5s8wUGZSSYEezJK+OOLXXJ1snEQlc9FWwnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P5/HYXrA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P5/HYXrA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36CBAC4CEC3; Mon, 21 Oct 2024 22:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548202; bh=RqVGnlsjdzM4k+hiPQ00Hj7eqU6yxfXEbY7XmeDmQcI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P5/HYXrApB71Bx0VGgraqeJbNKncOfOkOpgWe+xsAmzkEdPLYC+sArkQGsuhg5CqD oLaO2ACEqRPeY5OGhZeoY3Km7beHH2nyDECWTjzlnm4ToWbpXn1qrlzDWe2mlJ4QEZ xylrWfB+ay85/hzuVfLhpkLjphI9csb3Q7dMmcb0xxFU/K9lQmDOjkeEj+NA4wq+Us YsiRCkPTnG+yLbO7kOdLPf9DOC3ejEt3ScqZ5IC3OaQW5CC1cdBorFYqakLd/iiU5K XFjQMBjvRRu3GIjdYBCKdKVLIri2alBcOf2CHe2Sx3wDEbt1CDAeeSyN9vkb8FFvnd wGhH6IWpPohIQ== Date: Mon, 21 Oct 2024 15:03:21 -0700 Subject: [PATCH 17/37] xfs: clean up the ISVALID macro in xfs_bmap_adjacent From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783728.34558.8770350925708639337.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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; } From patchwork Mon Oct 21 22:03:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844755 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08AB01C461F for ; Mon, 21 Oct 2024 22:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548218; cv=none; b=GRM7Ul5RzNi748Olfcm3X2QzzLmAZ8PXB/xXMBEfe5Z0gnT9Ex+wd/Ezyi4/PZ+j4YlupCwJGGsMs9CaSzqydjkp0LphQfHe25b2WuuvfhMEsm63ilz3Qlq6+SV0DaDbywPVpfjAjzzxROJsBj62mjIyfCo9l2xxJvohDF1KWWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548218; c=relaxed/simple; bh=oG+f4AX5lGEUmIbRkYV4kNB8pd7rIdbFVAcjbDq1x/A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rqg0EoCVQTx7ESNNEVO9RJqSS8qD3uAxGTd9FxE+emcqWhOIiq2Y6dxBxfr/eX31yZf11Ojf9ufYNO655SCd3VWZfghPqzYIm//PIB+VKT/q5yrPgfmzuHO/KTE67BpBoRfprr4JIHV0rtI/brHBafPCQ22P8z+9LpYB18+DQNE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bom1kNBY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bom1kNBY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE479C4CEC3; Mon, 21 Oct 2024 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548217; bh=oG+f4AX5lGEUmIbRkYV4kNB8pd7rIdbFVAcjbDq1x/A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Bom1kNBYIUM/W60mFXTuVjxowSPZN9fp5owuxAE912L0Ul0aNSLaFjIY0yhCo4J3P ScHGpcPa+9IIgmEEH5tzIeBCOdpGsxE8ZuRMrWcayb78zjFdw2sx7ys49rbDLtPYlK XTiS0YKl2kzY46ZxSt/9fMV2Ge4jXe7S/g5p7Qa+d/hW3lRwMljItCYjsNK4AZGnuA Z0HpRNaDQIkHo6IqnYJOfmi/nSoJUVJSjUfZcccnq8c/xLgR/zwqP0AooupfTzB2Z3 uPpaI08hkoYtwuiu+JpbmKlrJfRfL3y0v5QT1wrvjYx862r9r/69m86odB/WkDIgtM rSpdrbYU6ix+w== Date: Mon, 21 Oct 2024 15:03:37 -0700 Subject: [PATCH 18/37] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783743.34558.2324020419510529947.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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( From patchwork Mon Oct 21 22:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844756 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76AE13C69E for ; Mon, 21 Oct 2024 22:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548234; cv=none; b=ZyjWZIZrbPKDQbyCKBRj8e3i4nlPqQQaFAPM5Eoaxz7N+cs+vcnz73FiTLmSLvEgFGDK5RQKFsBXQOZH4ziCZ2mjwYlJ6eZKCXbFo5W6FQ7Pq0dDaS/IVx3I/5Ufz1/RXLtyX74fn5NRhEk/vp1E1b57pJWaCJQiDkQzOrtpUss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548234; c=relaxed/simple; bh=OMxzYsbIJD+uw4JocWoS2/benWEaVdp+QZf8tOsxbuk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XYPRBAGiGla6KfTt2pINjBqZbCLRQsw2lmiY33p815hofStD/X9Nb5WF6fTUHobjieC0RHzDSa869TXcwkPeWKvrdaJ2Uhs7n7PlEIce/wOnTRX810Af8FXzJSpSRA/IbExD2xTZSEKn6hIxTalaO54Zm6YgDyYbOMmL2D0JvPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AcL3+q1Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AcL3+q1Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7263CC4CEC3; Mon, 21 Oct 2024 22:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548233; bh=OMxzYsbIJD+uw4JocWoS2/benWEaVdp+QZf8tOsxbuk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AcL3+q1QwckxOlP1NtJMC+Jk6Gs/cUY9oIeUb+BN1izZEjReZOYJHbnpYxcMKbwWD cMetjcA2/E/P79P8YZBqEoYhMpge66Gpj2gAz3hiJJ2VFug7b1NGzE1fGzXhHB7X6E wnuE5amHdbIyLAFB9uzNxaN4XZlCXEngqVZTR/Cce3IomHXCnsrOsKmVUssIF3ws9N l2yDe2smwbNcfk9WYA/46HUCsD1VgwlV0hYILjiSFKfkIiQR5sejQc4GvmJN5UtQQC mmIA8gRWkEtRQ0qh6tJTKNwDTVmYDTyiI+d4NkqBzeBJZwaDk4QSTXLDmzW933+FuP LUPkWH18AOM9Q== Date: Mon, 21 Oct 2024 15:03:53 -0700 Subject: [PATCH 19/37] xfs: replace m_rsumsize with m_rsumblocks From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783758.34558.10605030674779595885.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- 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); } From patchwork Mon Oct 21 22:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844757 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70CAB2CA9 for ; Mon, 21 Oct 2024 22:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548249; cv=none; b=Ba2sNpsmd6SGZGi719Qx0DJwN9xkADDaRFQLLAKdXAYYqcRvqAqVAA6JhMAqXgejdM0mbB1UVsDfITrIFDRRLekS07haRJhJkXzpKh20irwazoFhmOFICe7jyfo+tw2YZiGFe/l2ZReHqlujDJwLXphGxXkRaBGIT5LmuW0TyXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548249; c=relaxed/simple; bh=kgqlXPZJXrEv14UCZxjnwMZSGjAvtIJcgawEhVNUCpU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ywn41+upRR2C4iN21NS2G2oxg5rr2RuVndHJW6VFk+emnchrtniG8Jg7+gLqjp/qj6OeFvG7ithvnFKgnmJq6SVd+UoaweqgcP/n0Tp79FirOs5MQIEM54N8r1c44j3Rg+OiGa0k4Oh/1XOXcbfeHIScs94HmkFFLKarFjQTiN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uXSjTXzb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uXSjTXzb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49517C4CEC3; Mon, 21 Oct 2024 22:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548249; bh=kgqlXPZJXrEv14UCZxjnwMZSGjAvtIJcgawEhVNUCpU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uXSjTXzbYwGIiuxaCa/dFU0nuqJDnFadqrRqTRkIUEGiFpPsEUKE2TsJ+MPkrUQU3 WYv8Yr+nOTbu0Ist5jXzkBqw7BNhp8nyrkg/rj0dApcQUrGW87GmNQK8Jdj0+6EJ2j /878oaapqyvFvpfV0eFFfOghrJUYSqkynCjNnBm40pF1DWKW3W+e0B8C6+GoX8hkVp 3AVO6eXikS+1/RTHbWhQw22ZkOMPXGwyS+74xWCwPOjhQUPRBJ/dE/Yv8OgbbBzsxq KiD2SDvGhy42L+USIx2W7agEyCNMOAt+7YLvxvIY3s1UPFzeQTbCLTlxGJDyNwSLKm QkjAXwV+6kHrg== Date: Mon, 21 Oct 2024 15:04:08 -0700 Subject: [PATCH 20/37] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783773.34558.13134276284969632973.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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. From patchwork Mon Oct 21 22:04:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844758 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16C442CA9 for ; Mon, 21 Oct 2024 22:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548265; cv=none; b=Qm1GCgK6+8HMfn1xWeb3DpGVTbQbHdn335mv10PQJCDJp1yIZLNI3iPuHXC7MB5EEJYTlPPm1ua2VRsvPiaSXbK5Wc6Vhnculwtmir3x17dkRtEq9K0vJIbD3hyf83KK1Wm1TcecDEzkMAkZM0R4INrBmU418WEOiMxQG0tNBt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548265; c=relaxed/simple; bh=lzLKw6fIq8ctRStjUW9gKBPWY2KCzfzOfZQbW1pkWXU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hwwEJOC0I8NikuROhaxHXB7PH59+Q3QVh9Mf4Aww69cq7TU6BakEv+TVQWMS1gsrkfl1HVigqnvFa1Ga0LXPSCtFU2DiDfe5ngkTYjh6lXnxtP87XXvXsisfPTqk46cKMH1ck/6PpTHkCqO0nJCNb90Oj/oHuvCS5YkDv9HS6jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EJEM+Sl9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EJEM+Sl9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1ACBC4CEC3; Mon, 21 Oct 2024 22:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548265; bh=lzLKw6fIq8ctRStjUW9gKBPWY2KCzfzOfZQbW1pkWXU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EJEM+Sl9Flwj+PtJGlZTxQ90nGpAJDdlWYnDa6KPr0QqVr54Bh0D0pqlZhRt56wcY Cw4XxIy5Z6jb1r/dXAUolUlDMzvfKbbqfnzCqH7QaeL+v2ZVwRsKw1C9JebzaBtTR+ idfI/3SeRcca/a39T2FOsuiRiRvkbffj+STJ7J3wD0h6RDtUBsg1u5xsxkZCw0T9et VdXdiEVc9mFwOrbVI/S3zlv1k/39laIe8dIFqY7UPRloyPLCCUfgwAzds1zZUQ5Ppa iiyE1hbKBaOIWugiR1WPt7+5mRuO++f3b5+cqB3BtO48rKX/R/JYfKcawzQclTW0GD 9i/zlMozDZRPA== Date: Mon, 21 Oct 2024 15:04:24 -0700 Subject: [PATCH 21/37] xfs: replace shouty XFS_BM{BT,DR} macros From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783788.34558.2397297691023111980.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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; From patchwork Mon Oct 21 22:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844759 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0519E2CA9 for ; Mon, 21 Oct 2024 22:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548281; cv=none; b=R1hmO3f46T7mH87U4po5mWWgdomCRDyVOcXPnHlcbodNXFiq58fQiOiRybE0N5QkHWf80pooZYMVnoYOK4YXzo4nXoEffibDoKcdvxJUDP/j0I1KmASDuM8g6liuLsRvxUCtO9LF/xNWJEwNlnIkznaRRq3H86MH2z4QELWOjMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548281; c=relaxed/simple; bh=EkPPmN6EQjA2v34CdC404WfKpOHTXHLekHSl+Wu3CPg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ur/VMFuKX1rvBrGfzfV3yXtxFpRELKvE4e8tjrLOlqh1DONAMz3yequ2muvV2yberjXxZY1t4HSTC4baxe17cbOaY3EJm89+I6q4jbCmoadeGVXPg9VJ3gQjH6xkNfoXZF474qGehTmvQdyu/JT6bYw7E5pw6vJ0vXAodCk2tK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D9aj0GD/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D9aj0GD/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89CC8C4CEC3; Mon, 21 Oct 2024 22:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548280; bh=EkPPmN6EQjA2v34CdC404WfKpOHTXHLekHSl+Wu3CPg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=D9aj0GD/AZYPUpjxif51YCkIJ9sVMkhgTSBDAe44ptJf8R23aG1c3fADDgz2Laf4W SxYE8Jtu53bJ9nG7SCJ4r76Lw6vs8Q31WZD96trKpgjlr1MTgEmQVqwGIVqjJp+Rx8 IEiRU6asj7NS2D97qa5r9pUv5ZBBI1XtZ9bRoXS+Ippav01/gz84TMBAjnNNbMJf3D RLb5QKRKpV+ogTS4yDX53uTPfyvKh+O9hqda8Zs9kq/JyUTWP94tRM+DHxpePsVpQK cYbE5VKLcxA1LYU1AUsDdroTQmn1gqXUjwMqpoC02mHFD+rt3ERcgFLeUTZ3G7qI5T EUqQidt2L2XSg== Date: Mon, 21 Oct 2024 15:04:40 -0700 Subject: [PATCH 22/37] xfs: standardize the btree maxrecs function parameters From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783804.34558.513117039396977201.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- 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 From patchwork Mon Oct 21 22:04:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844760 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8DE51E2846 for ; Mon, 21 Oct 2024 22:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548297; cv=none; b=Xw9Vyn59y9uEuC0zlnYCoF/RmEiQOMj7JwVTOHy3d5MVQieSYwkqXptMSYjnHj4q16ajkEcrZrcIT3snpt+cj5HKU6nSHkayCBlqdB3b00KfRb8aZzA5tHuqq35ADBvLsv79JL0+5cYjZU7QzkcSQkpej8OTyj+52Q0e5R+a+qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548297; c=relaxed/simple; bh=8jmw6n/nScN7o36XFdkmO8Q6GCTOrnBze95n3w2Z8eQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gDJfq71BDobvH0o8BULoVTaRIdFvcI0PIz3fvVIU3oSDnxW7piI9eXfgZlu87NvDugofYDtU07WGJNM6y9NEDWB2elcawF0fbbY50dEihH0Lx3vijrglgWgYpjO13QwmAsdcltKT/xXVt175QDoUc3OR/dCBFt+ex5wG1FdLv1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qvdb3osC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qvdb3osC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64718C4CEC3; Mon, 21 Oct 2024 22:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548296; bh=8jmw6n/nScN7o36XFdkmO8Q6GCTOrnBze95n3w2Z8eQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Qvdb3osCoC9VLBZiweweD8nhVph5n5DGpWH05dvFbhgAg2orr059m4G8PyjZGsLio FVH8ylQX6/J8a4rimE05wtB1pp2Mpr2uajmWL+moD3hSt9JV0/CJQo0wURWb/rBRy+ XNI9xU0QlY2kmFKOu5ns1fDo6G+8aQi5O623vE1MTLWi9f/nULeuCjIzbNKoQ39q+z ksHBqIZicqLnhlHGOG2SZDi09s52WlWMrXY/J9LAm0OEcmkp+FRC6mtvSbSSG71MXt 3W6UAimIjd9H0RVklrUyfm+wCUKvFlbM3qOMzFV20hYhIOoBnZJXeOKl2+Z7A4wBaN 4V7gBoQJHVSVw== Date: Mon, 21 Oct 2024 15:04:55 -0700 Subject: [PATCH 23/37] xfs: use kvmalloc for xattr buffers From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783819.34558.5375099362641927547.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Dave Chinner 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 Fixes: f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()") Signed-off-by: Dave Chinner Link: https://lore.kernel.org/r/20240822135018.1931258-8-kernel@pankajraghav.com Reviewed-by: Darrick J. Wong Reviewed-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Signed-off-by: Christoph Hellwig Acked-by: Darrick J. Wong Reviewed-by: Daniel Gomez Reviewed-by: Dave Chinner Reviewed-by: Matthew Wilcox (Oracle) Signed-off-by: Christian Brauner --- 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); From patchwork Mon Oct 21 22:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844761 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 793C01E0DE9 for ; Mon, 21 Oct 2024 22:05:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548312; cv=none; b=si9Wzx7CBqk45jkmM1P9AuSv4ByeHDHWTAmmnoRboCt2l49QK9d0eU+7OHP4bK6BClTNgEf/O2dcLToyt6TXtNNcUVEzI8wjyNXSL8sdH7P+0Ctdg0Y/8e0033uVcagO6McKb5/PjmUcSGkdlEy7Gk3Qmk+c987fGDk0CkF+P60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548312; c=relaxed/simple; bh=17HU7dAC0sPq6dTovl+2c7ds9+4XBTYKqbTpAuKBSuI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Evs7gWwnm2oS54Evxf95FSLp+DujDQqfyWQr8B9rHTAndwl3O9ICGgPF//Ky2fY/DXKe1Y7MGlSlgFeoPyb7+CL+u996i7gnYh190FDyYRGdrci/TZHWVAzf7peWixh/PiX1FMlwutIh565POzBT7Z8fa2wpNoaOvVqU+UXLXK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OIn+qiIs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OIn+qiIs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E54B9C4CEC3; Mon, 21 Oct 2024 22:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548312; bh=17HU7dAC0sPq6dTovl+2c7ds9+4XBTYKqbTpAuKBSuI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OIn+qiIs4C2pVsjlH9UImpT/7g4LLIFexUV993aZloC3mMyxS6dz7xV324MyWr5o1 OO9AKvF96sjJGiJa7+O8jbo+pcL3e6ni6zoKDFhFsFpnMFD4ns978vHNroFKqw/RQk PXKjHx0y9UeMemdE4sVhdsjvoNSgdcZeEoepTJK/QfOWdinAedd13NC0yrnaaEdCuS Uul9Vc+ZpoxjsbUWRrxsXzdiHELqbzUxciCHW00PLf9wmOjyTJPGI+ZtnerX8U1o+Z LBbzNJ288okFOKE83VlXWknATG/LR2xOd2JTkZ2anpFEoeGP4/wHFikt3KeWmJ/7sK iO/TslCIF0v4g== Date: Mon, 21 Oct 2024 15:05:11 -0700 Subject: [PATCH 24/37] xfs: remove unnecessary check From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783834.34558.7499025596498842496.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Dan Carpenter 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 Reviewed-by: Darrick J. Wong Reviewed-by: Chaitanya Kulkarni Signed-off-by: Chandan Babu R --- 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; From patchwork Mon Oct 21 22:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844762 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB3001991DB for ; Mon, 21 Oct 2024 22:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548327; cv=none; b=EWwNr/BFnQgmqPrncGa6tIh3B/vHiDqyAOAloGx6agXKfM6m4MTw7VOqEv5SMOE+zSRV5kRoxdwK/5gNE0Jcwj/2BicqVl623NfY8IXVRG+syeXyUEz35I6yWpKct8hwQogKvv1dJipb8RlM9Feo+VzdJgGMS52L2YNYNl+cr7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548327; c=relaxed/simple; bh=AMqM1j5GaO/aiseja1ns/LzFZ/uFcNUULdpBuFYEq/c=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=toIB7zMtmrfVZzST6qw7M2ZsAYr5e75OfUciafHIX5UHGHGoJIFyyTWLmR7e+yMmQRQFL5GNEFFzVC9NWuSOmEdgUWrLJluzeDYcaVHXIrqLTDtKpmNZhUzVwDU6ojt27OYIZZrmQrTWNG0j6V33qpieI1ile+im2q/054Av95E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LNbVjQGw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LNbVjQGw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 859C2C4CEC3; Mon, 21 Oct 2024 22:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548327; bh=AMqM1j5GaO/aiseja1ns/LzFZ/uFcNUULdpBuFYEq/c=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LNbVjQGwSsj6LdJE63mKVzuUTMfhPdruLDcXLGBrJmP/MxEp+zo3qCAIeiWkdI9lh OgpTfzuPocWNwb+lljop/T3OsrwTS8CbBgj31aMVc1vyYbEXytMI7foJG0ImxzzzKr HNoIf9djsIXUywZJlQRtzZxzZ5ug3caG5y1G9OzMndw6qtEa4eibnSTB9mmHISyISo 9dyEu68I8c/QWH97R/UxiujzGfBeo3W877M8sz2jCuiqmLWn9Ong9uwEDVacLK9mV5 6iOIUoi9h8h66Dd+C7RBBj7GfzRDXerQRKApHicg37PPgHsRnl617ZxpTI88EJQcBW att73v1fIhTLg== Date: Mon, 21 Oct 2024 15:05:27 -0700 Subject: [PATCH 25/37] xfs: use kfree_rcu_mightsleep to free the perag structures From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783849.34558.10330735119806284063.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- 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; From patchwork Mon Oct 21 22:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844763 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E002CA9 for ; Mon, 21 Oct 2024 22:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548343; cv=none; b=ZVslshLF1JeDn75Q5lwVGQEk0+9TVnU+x8CYqleIcYBVxrnFu+KY3fGSTij8X3SxOdeJyghx1QHKSMf2ktodUrOCs7qYNS7rcA7RMWWleIkpbXdEJAX/oocA9GP7KJs5CCfw7u6P4652aTWK/bjyeQ01g7ae+3UI9JB+AU09mlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548343; c=relaxed/simple; bh=Qmn9OrxK4wzDuVTLItqmshC7ZRAaMO3p3BfMEhMTcD0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FDw7LGwHvpdHAInBZxtfiepKqiQx9EFUaiOrTk/D7/CbxmxpVedyOy3W72ke8z5ktKCeSAKyHljfc+frwD3ggtvW4DyeCSvoUG6mIqbWiQ5MitemFrS8+gAwtHMlzeAtQjsONdoaSiH2NfijS/RH50ZOiTqOUbVI/RX2VqTDd6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nYDcY0x/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nYDcY0x/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28BF1C4CEE4; Mon, 21 Oct 2024 22:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548343; bh=Qmn9OrxK4wzDuVTLItqmshC7ZRAaMO3p3BfMEhMTcD0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nYDcY0x/hXPt42bGsWegifEgNKEnwqmBNguo5INefxMQjqnJ4lV4ODttv2+f9g0tY PVOn9ksi4Ik2LFFFN1xqRiOgU+g4LjAxNKFOdJmH2RuyiAxu+YUu+PHXT+hbG19Wi0 YEvu+2287Bzn8w2PcV7Nb+cD7oG3r1oIfmAwHwPMViFOf4dS75sPr56i+d1xKhydqh R6/qX2R6Ms12roSWYghO27ob10YXvHbZShjrtmRF1RatbOuJfZf3WYkkyB1hjXYVzH DJ0rMPNZ8LW4sP77de2ExoBR0578Fq2Y1C++6yl5U10Sz2LjL6yz/f/+/VlJtWzxzw yPvYHvzy2509Q== Date: Mon, 21 Oct 2024 15:05:42 -0700 Subject: [PATCH 26/37] xfs: move the tagged perag lookup helpers to xfs_icache.c From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783864.34558.8851584390068717884.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- 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, From patchwork Mon Oct 21 22:05:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844764 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30C752CA9 for ; Mon, 21 Oct 2024 22:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548359; cv=none; b=sOb5qd5JSJPiWNlsftxWUTlbkfzfRRdHvRrnt/oWbMT42BzofNuP1dqWbl1DoYdsjTRUvc1JVnCoPIMRQZyRe+UrKbtHUgEYc1+KEB2o4K2e6kRWz2n7Lz/K2frk1kXovH4yNsbhVStBsWtPcXyy3BbGbMvKyEZDzyJMDld0mUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548359; c=relaxed/simple; bh=Z5PTxTzZvT5FHq50HAYjqs84TOGr+Llh5TenJ5GDO48=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ed5ZPjgt7iPv/rlnTzKtkx5daUOcOxTqfKa/lxU87uXKjZrqGkcFizoCDySBMRmiPaLnQNIQgKWk6ysFq99COtFSZ/7BafvA8tB3goSAC2GJNFkQAv2+jzwUtm4vEzDvcY7lJcnVXA/n7Uo2TMA75qn5K5F6xXwpUo22A6meGbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MJ0Nn9WO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MJ0Nn9WO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0E72C4CEC3; Mon, 21 Oct 2024 22:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548358; bh=Z5PTxTzZvT5FHq50HAYjqs84TOGr+Llh5TenJ5GDO48=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MJ0Nn9WOa7rKbUIPmMAIwRX8L3fmg2gdKa69oRQNhqdFWnJ4vC7CCDjI5DeHgrATA CyUpCHm11QvR/F/GuItKZTZyxUeTbob0+EyCOODJMrOKvlObhvpwtn0gungj8v2jSK n3xWyoSPx28LOBo0v6t/JnLs/CsMxnSNV22BzgxHud/bpsGYh8elOTSPU4BHuOIkL0 XXWC3kEM42lzjFrIUfGLkLcAn40w/q7YfvOhdI5ExEWLmmf87X9Lt6dOw83qp3332x ArnGsRCm+UxsFm537Q/+Q/dqn931QtyIH9As/mMN36XkGyIZms/kcySHv7+/6DUw2e DiKOnUPakbBPA== Date: Mon, 21 Oct 2024 15:05:58 -0700 Subject: [PATCH 27/37] xfs: convert perag lookup to xarray From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783879.34558.17948109160181557361.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- 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: From patchwork Mon Oct 21 22:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844765 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7B552CA9 for ; Mon, 21 Oct 2024 22:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548374; cv=none; b=Z9LPFcoPy+RG60SYRDvmNA1i/VhvqVCYI0sOJQxUjViU2Y8BSpxG40PLRI0H7f10loyBv1z73kKdptzB0QYepAGfuqEpxr+vDAKJIwNF/nHkK8Gmka9UadmSuntO0qFfaNFnCrnZKln3gdRWh/2UP/GQWFlkkaCzQ+Na0MeDgow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548374; c=relaxed/simple; bh=lkGovIsttTsWnI5XxwaiAlstodfHJn2lT63mm52PJu0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RBu5BxhEme8F9yoTI6dnoKv/bTjHZgLylQNQvCExbTUb7D7yu8gnc1+ood+jLWfN226ejAlvsp/3AbF/r9PoNEnq3xsz8b6SzTx0Gq5SJJvznP7BTKJQVQVGGoy/soXhIzRm4xf6b/oVToX/Y1iSmmV5bVD9RY4hwtFfUAfIBGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E8+GwuhN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E8+GwuhN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62862C4CEC3; Mon, 21 Oct 2024 22:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548374; bh=lkGovIsttTsWnI5XxwaiAlstodfHJn2lT63mm52PJu0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=E8+GwuhNyvHVgTi92Gmf0bjbXA93TUT3p8VtDtnY3ELkyowilteOq1zHSqzVVfWsJ NMiNhp9lwz2szwkt4GKDSJO3tNOnGzZAovvs0+gh5cz0beUsXUKO/j6qPEx8bF9G7c IhLTOcHg1Kw55iDmyG65UeFYoHa+PZC3Zhh0hCyz1sv8Mm4p8q3SQCBWuFh6dc2kxV m64kEuAMegQ8S22E36RpQ9yfRksdcfUWvsgqqhgGCOpB3eBxykattAUBdyOZni6eVF DIp/IG3AmYpTyIsTFJfpY69MydumLGTrnAmpXA/SaDLCpZNxbFYbpYZTsJdEDdFXuv /HbdTXujwHYTg== Date: Mon, 21 Oct 2024 15:06:13 -0700 Subject: [PATCH 28/37] xfs: ensure st_blocks never goes to zero during COW writes From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783894.34558.13885243332803707200.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R --- 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) From patchwork Mon Oct 21 22:06:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844766 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E5922CA9 for ; Mon, 21 Oct 2024 22:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548390; cv=none; b=au6/l7BLVNRpinEh/ZuD5nlEebdXDM/Mvx0SVMlbgoOBPm3prI8bKCllcmDD0hsBfV58Zr4TBXoqsdHNEphRvkeCaFDdN2RtRUI/VNc+hudBF2mfn8a+nCC6VS+TvT8UvGIqBVUrOL4XYNic+Io9iz/uVfcFnPQYDcfRP5KafkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548390; c=relaxed/simple; bh=9fpdVgVmxelGa+5Taqc1vU3DXk1nGqO28B8J1NmTmU0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UGIlS4vIv780OooicvTJdQ4I+eS2dGCESiVL64T3w3lQwYa6h0rfWRpB9sG8NBH6YBRMtrD/ZqOarypxFwsuXxe7IN7ZInTecwzQi4jQzDTdqsUajoT7jvPv9Ejx8IrxHfuG5/kpLtZYPGTZ/2lPOSIb1uivy08c+dJGLn1s34c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XWm45S3Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XWm45S3Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09C7CC4CEC3; Mon, 21 Oct 2024 22:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548390; bh=9fpdVgVmxelGa+5Taqc1vU3DXk1nGqO28B8J1NmTmU0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XWm45S3ZEsU+feSJFh5ucI9tBSl4IblPSewvR3LoFk7JPjlgFP2yp8vQe3vhta7bt BH87rRw5vxcgVstCbnfZsPiylaOBGr6RWXAtX009afs22wf7aaijqxmLIUVQan1jD3 NZPUI4AXWu3MBx83hZWiY72uvCTbThWaUwfX0BrRhh0ks9LB2k8GHtnElc2JXfeaQB W6TUNz6ci8oAayh4UjQ4tuMeHuptdeULLeX5uI4XyACFBsk/p7EijDIAh7QZ9MoXX+ BLvSyLj0hDTyNviwqZ6gIujQ40VMuIGg58IZ9vTZpkEhoro7LqR6eRZokOtt0P6YJY UGGkw0RN+3xhA== Date: Mon, 21 Oct 2024 15:06:29 -0700 Subject: [PATCH 29/37] xfs: enable block size larger than page size support From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783910.34558.16123618243296622128.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pankaj Raghav 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 Signed-off-by: Luis Chamberlain 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 Reviewed-by: Dave Chinner Signed-off-by: Christian Brauner --- 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__ */ From patchwork Mon Oct 21 22:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844767 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAAD62CA9 for ; Mon, 21 Oct 2024 22:06:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548405; cv=none; b=JCQWr/gFHHpNXJRrySOfqVEd8TfrBsW4TtNBPjz3fx7Cg5O6aWRaQbztVhi8pVlT0ROWR6LSozOSTQN6wtvnVpA5MxnvY2ok5/uEbD0LHAQ8n5jvfsI/yJ4Kf7f4vThwGHyAw8RuQxDsqaL2DLe+SRzGWMcdbbeeJVJRSCQmUjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548405; c=relaxed/simple; bh=118/3KLdqtx9r1gFXye0oHE02j++kJbovvk0tJ/SVV4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oKNlkcW1WWkMvRl5SsrulZTgUPYXJMifvyaeMWv6NI5WCbEYbUYZY2Q6PiYM/7SbM8wwKsmoYweXK+7O3Wa4fVf+QlTs9C6cRkuBi3b9QXuXQu1oXtA/A4VJHaNCH6cJpksrrX31F2FGzPgzJhSWXUMcXqPqIaRPsURlOEc7DV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pP/Y0l6g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pP/Y0l6g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 953E0C4CEC3; Mon, 21 Oct 2024 22:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548405; bh=118/3KLdqtx9r1gFXye0oHE02j++kJbovvk0tJ/SVV4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pP/Y0l6gGaJCW/kd3yLe5xv6C4PqKWeZ8gx6nxee/svHZB3LNtJiynb3rxqng5tgB z00yt/BQ0HKnVD7mXTCFno/sVd1F5f8jTdIkNr+wn937ZdN+JCBx8vKCzLCJ/oTelB s40IkUJw6RZh59YTnOuAOUdCEU/ML1ATzhfpBHUdDB1tnutQgFbdo6zZzW3iGzt4y7 oaIIV8GtHsloWZB4G+G0TOSInJssXwi27u2mkMHq0aKFW9yv6BB+16RsagpQVa8mpp 13Dwkze3tunxv73VnIV1HWm7zvCEQkVOyhjQH8tanVbvT71+FSd8Fw5qmP+GlOT0an axrwxmRuwyqaQ== Date: Mon, 21 Oct 2024 15:06:45 -0700 Subject: [PATCH 30/37] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783925.34558.18119147785639660667.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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 */ From patchwork Mon Oct 21 22:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844768 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AE8A2CA9 for ; Mon, 21 Oct 2024 22:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548421; cv=none; b=AggrTPlka2rIeu7TEXsuopOxMnbH0JqIoXZiguSxQ0jpHM6SHfrSxDDiDgZIsF5BXzX/miJ18/3Xg8psrCOtfn0uRQYJ2iZPnZYwcucIknswwaZeeURcOMHG5AKfHvDVLO5G/l879+s3aP6v2fpHF6/39FmUtdA68501YtxGoOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548421; c=relaxed/simple; bh=7dNQiJfyRSMyRqjETsUSLQcg+OCcblkIYpXKKxSVboQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RPb5OOQbSaNiNiB1srRPg2reUzIZQLUwDen7j4hlYUIzIr2wSpoLHf5Mu1jyzj4ViLjiKCaXX7SroIrl6gqLKWgsFuJffe4+EgUhstfM4TQVopjjZzo8V5/C1jFeenyLipQH3LZN+9lMbRM1b/9WG6/CNXOfW5YwqRpz3PQemgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q+XMWZKJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q+XMWZKJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 362F8C4CEE4; Mon, 21 Oct 2024 22:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548421; bh=7dNQiJfyRSMyRqjETsUSLQcg+OCcblkIYpXKKxSVboQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Q+XMWZKJCZdZPMZEfjcEOxoayaiFg0AXIOmMMEAoyDRlVdrrDbreRsMRXdQnT0GJt unOLoFriBcZ0uPJrqyrswEKK+Yl/8DKRl/1wdKDneUgo7bTc8mXfjmc2h1dQdxCuV8 rXucXq7HmedS+H3o1w5bcRPjGvoXD/q/RnTpOcoCVEj7Ljzdkup4wMxKdgxMYH5x2L JbNmsKd6s4XI/bJxfynLrl7rCGXevMdCh8BC/yDqVbwdzLUf16mw/KqZaTN7MF2Iw1 LjdjJruEbcAEInHRrOXxZ9e+xnCrGghhGN3pw2XMQdAWbLzK2kqDoILZDMOigvHAAu Q8FlCR45xQovg== Date: Mon, 21 Oct 2024 15:07:00 -0700 Subject: [PATCH 31/37] xfs: return bool from xfs_attr3_leaf_add From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783940.34558.9452060147958145742.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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); From patchwork Mon Oct 21 22:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844769 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28EB42CA9 for ; Mon, 21 Oct 2024 22:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548437; cv=none; b=Nz2xrLCWLbGPSccU7bxxOPPjc2y4uNGZ6CRL97Me/Q9JczGQcowMIuUU4vsV0IiNoUtvWk5JadNehy6MyXw69JbAyYvdGdsy1RiE11EHNsqWrHKIksWMnfCNKoqS/ljYadC1edh575TMo5IcRmzH4NTEfD6WbDEl7VHy29rQMcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548437; c=relaxed/simple; bh=QjOsC+90r0vhbovJLIgdY+DUlCwrCsbx6nB5mqkFRV4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t1rAurLEO6fEeBsVKh+baMLioP9CYVM0vo35OnWvHjnxrWAxDNsoM/xJwRl/8Cq19Y7oYJUleS8J/XZtrexIfydMiOzRbhAIeVAeYeNxy/JnEx4jJz+6YN3zSLYC+pMGcv1XDxVG2EWnXdSKppVElVdYWJXl6SOpV//V6lfyVMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u7t1wRnK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u7t1wRnK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05EE3C4CEC3; Mon, 21 Oct 2024 22:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548437; bh=QjOsC+90r0vhbovJLIgdY+DUlCwrCsbx6nB5mqkFRV4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=u7t1wRnKJrhhFakUYkoG+Jk/yYQuRIaPd0M1afwmFgLM262+6Pj4JGeVZG8mQsp2T XJi73okdCHYc0jNB8Dx30HQpaKpnYH5WtSuOa93EIiROHAZJjstQLkR0uyhV3Lcjin J9Yg8XXRT3MlG/R5cU5GuCFuwx8OBtzUWy4TTS4xlURykOvMgecerDddjPWZZ3IMtz 9nvNbn8HxHIVRN6+uW8Trwu6DYadVUI3yeHMighwzHAVMVC7xibso0XY5irYi9wF4r +OCelD0MVgLLdO7+mSMRPyVjyLa6uVPnuzXX0Q7YK3SrbchglGKyPchuxMZbdwXBv6 k1EBYDS/OY2Rg== Date: Mon, 21 Oct 2024 15:07:16 -0700 Subject: [PATCH 32/37] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783955.34558.4456747066669935339.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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; From patchwork Mon Oct 21 22:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844770 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D1702CA9 for ; Mon, 21 Oct 2024 22:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548453; cv=none; b=rTG08ja331Q3zU5yEPl3kH7lxpuv+UNDQE62BWfI7xxpfTsbXAdHWaEj21jzj4yCfxx6veQ08P8DNP7w9A+ic84xXA8Eb62o30y5ZLgP2DSc+PrbTop6v7/YZVrzFaFCMBreCLHc78UrY+MdaP/2FxNd57zCLPiMWP1lSwfXTts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548453; c=relaxed/simple; bh=CX0zA8QDeUJtuMzKPiMQjrlq4wtusGGSrqsuxGS/RQE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RHoCTDwLacP/GA5YSox1CBWw9nUH5B3SM5DWLIazgsnrLZ2vSpWGdPUAQFpOyDtjhBN0Ht1QEr2osKijEu9UMK3zdTho6fUPESV0cAzShGNThNvFMzLWJmat87kI96+YK67LLlvAZIrAHeWurSeq8XeWM8lat59GZzP8hY86e2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UqCpyz69; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UqCpyz69" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B586C4CEC3; Mon, 21 Oct 2024 22:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548452; bh=CX0zA8QDeUJtuMzKPiMQjrlq4wtusGGSrqsuxGS/RQE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UqCpyz69EuLlkPbtuHfmF4rJDB4cIQGB90a/2/6AXAe70TUiUm0HS1mpla/S63J12 30MYi7/Tk4eUkBBqwA2BCmcsuar0nu6CGkYh+4ZcuTg7eE1f1Kkg4uqmWwh20xC1Hq Rv+Xu1smi/NJuUsWjlWgHX84n/v9B4fzlDrc9buXLu1AZuEk9jdpgLhQpAUA3aq2OQ XlDzq9gSEkahbjo2BtZiC0JpUNecUAKCGoLs58iYZJrgqh595hiAAER1qnDzq3MWBL ZKF2bB3lql3mJUZ9vdQ0vHEJTQ9/Bf88G+wuOoQRcDkKIRmsEvyBofILb1s9J5oJM0 yOrwwNg9tn9Qg== Date: Mon, 21 Oct 2024 15:07:32 -0700 Subject: [PATCH 33/37] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783970.34558.12079523515599805667.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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; } From patchwork Mon Oct 21 22:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844771 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABCD41E2839 for ; Mon, 21 Oct 2024 22:07:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548468; cv=none; b=IpAVVF0mDyuqc4A4LE9YUmtSlCDyzTih1vwchzSN+UK1MQY9AqfEgHxrQ+5ojlxpSBq6U29JAduHQe3Og51kCwNA9gf/4IMXt9tF3OvmF9bxkFM6R+1wBh5vJwqGogyba3//z6kjO3aPPlgbsUshhbm2R9AQSRf6w6rPrFqQpLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548468; c=relaxed/simple; bh=i6gmFKAHib8GzGEajsTQd9oJCZtEooSS4SIJarCB+vQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LUO6rhgi60ugPJSzGyTAxtWWji8FAIHRWIXQcp4564osru43cyDZ4fB26WzWm/8pOi0xNPYZXxoyGXCSsPvH8W+8OuMGrZGlbQH+t1fyK5GG3W9lAmyF6WxvyX8yaeHVg+RB8YMlLnkM+3OZq7Z6XjcoKTQMi0NsxBfe/UL2T5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G6U0v6RH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G6U0v6RH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E021C4CEE4; Mon, 21 Oct 2024 22:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548468; bh=i6gmFKAHib8GzGEajsTQd9oJCZtEooSS4SIJarCB+vQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=G6U0v6RHxdnt5qaOHtLq9F2sslLy/jaPRrk1a+jVZQKtyFWBeI98EMyACqig32oNQ psW/lzMKn3SXkbr8wJbNQ1VcTm99lsHJgZnBGiy8g5j1UqG1ZMUBMZqMw+DPOy1x0t x6WRNSfbsBzuSRBDYsktOIsdO2Rw1jVGB32sALCvWkxBpTjz4N1L1zBbfyOh7zrC5Q HA+tM/C2U1F+NV8UA2RQIqGz5x5MNuE8dKsPkTpNGT4+JkaK7HJUFvXT7SlWHwX38f Zre2aGJwkBHo2skSrd6cXzC0W6pkkzxEo87QmrnfUgNFHrQsc0iXBl78AKtfsDOBpT /OK8R0TkA5Xzw== Date: Mon, 21 Oct 2024 15:07:47 -0700 Subject: [PATCH 34/37] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954783985.34558.1097911190499766488.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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) From patchwork Mon Oct 21 22:08:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844772 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED1952CA9 for ; Mon, 21 Oct 2024 22:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548484; cv=none; b=VLuKvd50M6FByndvf0PUBWFFtp6zUtHz+iQudyeeIqKcddpO8DQucd/KMn0xfjDNuM4qV0KD7f77JGsYVwNG7alCthPMp7i+RH7rYYhmdejK7nM/9vzUBb9ZAylZbULq8HlNsfxQclh3lLpaVa+5tyux8zy92XrAkGGAr0Hp9vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548484; c=relaxed/simple; bh=boiVlnQxhES0BwY8QAKEQCXjPoKUQWcAkStRUX+XxmE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TlYozI/N6BKpnAQqHYLFOt89OnvXuY3QAPbNGU3oFHzQB4Gos1k9UzXde8bx5xjjurUMURVLOJCmTiqnapFNGmp7yAAWyyCWirGcMhxFA+3GwdMQG5/gHjVH401WiZoPDRQa+W/PWaNvquKkqiVXMYdwq0HP355GntCveP0GRVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pVRn5zkI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pVRn5zkI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4805C4CEC3; Mon, 21 Oct 2024 22:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548483; bh=boiVlnQxhES0BwY8QAKEQCXjPoKUQWcAkStRUX+XxmE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pVRn5zkINOiSS5Q+Rq+UlApnxjbqDOuxO2X45Hp0Pr55LPqqA72fJn1IzF2juC4UP Yu1iVbyqQUlUyC68t3yIZoCu2wiz5655XlZ5zsywyYiI1OUSnElRtj5wXdcLbwTOPi GeTfxYI+ajA+XqWnWxrQswC4RsKozqXaoR6vP+X5LoYGpJidCqoHgdCDjN0joeTTMB JcrVysq90d4F+pT1WA1zjFdDh6wjkEzlUbCgtTdSBYFMDqgFCOVzvXSIEfpkbMKlgm oA/PDh7fkkxy0TpUWnsst7bWECcNHl+LCwSeq8IBAvCaOt9SJID1o00Icm9n1DVpta 77mAM+8XXaYjQ== Date: Mon, 21 Oct 2024 15:08:03 -0700 Subject: [PATCH 35/37] xfs: don't ifdef around the exact minlen allocations From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954784001.34558.14414142539970772501.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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 From patchwork Mon Oct 21 22:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844773 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C4872CA9 for ; Mon, 21 Oct 2024 22:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548499; cv=none; b=EjMNDjF68+4B9B/F4FaBR8+7lG9iTG9Kg2MTI1Jx/pfPuNgn6ZBHw2onXpx4+vZvYqmwPros8WBHtUdi2c0GmCjqdYGBzHu6zq7cEPbZIaJoEsM2HTVNHxU/CJfJR8gc2yukbLD5WOXxYmlm4Ro63MGEKTee6Xa9MMSxj1hLm1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548499; c=relaxed/simple; bh=gljjXFH81UV8Kku1UmvWTGlfcPv4duH1tPlozJDvJC4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XV1fgElfjpCYtahlg6ksUGh7EmJG89Qk3aRCdQy2KqtM/D0vtfHMjwsNk3Wtcn2GUdu2g+Cti2rn/U7TB0ez6T2DYuQSPcoPtMKtGdPNCdPhSk+rvJvqHAQKF24ahFiOIjI8oaU4tsbHdaXTod/muTFEMDEa1tIDCH+XPRudRoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ic/N7tmj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ic/N7tmj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67159C4CEC3; Mon, 21 Oct 2024 22:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548499; bh=gljjXFH81UV8Kku1UmvWTGlfcPv4duH1tPlozJDvJC4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ic/N7tmjToX4BSVw3h08Ak1ssBbf/MAyC9zvD/L3li8DE9vj1NApvcqGdnTl7LuNF mLdB25ZsG/lijkHQCQkSpnbpCtp4PCu6gSsw1t8fC1aiMiEDHq+OWRQQ/SwzwQNsnU 5e8Aau17QG1pG8BKk2k7BLpLkdbiPtFA/IPfmzTDHjfDDC/NdDJOHBA9i8MFLHfy2S 2/vn1HFnZH89E6OBCe0fl0U26tqJobfnwwpd165itCvsXlY+dIAC1dNtsZGawk04IW fnO/tNpnvwel20RM+5bhahN3bsPNo04P3EMI4MAnbdp5jyqz4JDzjLsNg++FizDXfY C2HkyXiRG6mkQ== Date: Mon, 21 Oct 2024 15:08:18 -0700 Subject: [PATCH 36/37] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954784016.34558.2635913694225058412.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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) From patchwork Mon Oct 21 22:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13844774 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F2BA2CA9 for ; Mon, 21 Oct 2024 22:08:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548515; cv=none; b=hCFvPeAfAwlT0dtMNLx4UtTJ+PEz/3sxrnLE7Ccut2PzqRPLIaI4/WJzbUQVMNSsWSQR48zzeG0W/qMOCy8Gvu0F1hJYwK3MsmrKXtGZoKMO0Zv7lxuWF0gceTm5vq/uxSZr6Js6uRL/B2hUV+lG1TbdkrIqKeh1qOwAoczcqV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729548515; c=relaxed/simple; bh=6v9xPp+HF59XYUVGsO+s6XMsOPw8OoyuO9rkykcOyWM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L/jFWKp3DxgIgnZG12+7kk9l0MXgXBo88I3wIWfFKNJtluu5S32aMa/xJ2P+Z0Ljduh+r4YOKdTCoJf1PlpOWt/IPyixFxkHSEirekpxKCe1B766mdDLiXnF1a41leL0U30xhoO0myY0FnFQTsmnnEpjfhJr8+uQzUx6a8F+qsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tHBU8lEz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tHBU8lEz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 098A2C4CEC3; Mon, 21 Oct 2024 22:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729548515; bh=6v9xPp+HF59XYUVGsO+s6XMsOPw8OoyuO9rkykcOyWM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tHBU8lEzRFbiqdz6idNz55vxTp/o8FwAtfX52fHzuslJckvPuatXdgiL/lCv4xHGM /AxeARzPKtHEA7tYZgfzk499GXIzySZEB5PqTxQdmsCe/hpo8Bjsa5jBZ35BUzhQed Px2Sx+JUbTOCeDOgQAL0N1f1Jk6pQWC3ycAxZDQtFU5PsRizI3YhvVoo0wfN4XcQDF eDfzMWoXHMr3C9gS3dBWPvAnP3DbRHgHNMcAeqIBPlF1Lu8J4p19ceR8F51IljPBAA qlVLhm43uCRAENrwi5hVYKSzBNTqz3pSWPfHiG59z2m6mll61BjlBkPAtvW3zxdpZh 5x2c+R+q9TEFg== Date: Mon, 21 Oct 2024 15:08:34 -0700 Subject: [PATCH 37/37] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172954784031.34558.14069851291289347323.stgit@frogsfrogsfrogs> In-Reply-To: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> References: <172954783428.34558.6301509765231998083.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- 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); } /*