From patchwork Thu Oct 31 23:08:57 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: 13858420 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 6A6F419F430 for ; Thu, 31 Oct 2024 23:08: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=1730416138; cv=none; b=EthiYWh8T1KUKnbRzPcLrt01KbwC2CvkhveNMPQ8Kmwnr44niz+V+1uj7SjGxC0zSMt6B9jUm1D+Mk9LD6ylPEnUfshHWgyYQupWcbMzU3vGeAg+Df/h62X3WCrmCLF9forfpaG+zBhSUAKwxbIR5U+dhgXEjCNdFcBdA0Kqz1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416138; c=relaxed/simple; bh=TZ7PdVmUBavRMaqPeLY+6pWGngpv4zjn3ds1Oja8kNQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=akUlaMoMFjDLM59xrUg1opnnpays7I2HjpkDM6Dc5G6WEP4l/gUlOHNmRDD+FLCD+z1r1NZBtHx80UJsueZbbpvvs1E41GHJ+3sa5EtyWjNNMRhe5rmU79V52efsgNIrqMBnnifWiM0Ah8YS9Dlgh5GQwPCNp5rBRxkYOqnzuNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dVlJSzGi; 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="dVlJSzGi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1E6BC4CED1; Thu, 31 Oct 2024 23:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416138; bh=TZ7PdVmUBavRMaqPeLY+6pWGngpv4zjn3ds1Oja8kNQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dVlJSzGiempHL2jT1wRxk9YkMYulUJ/ChK5rIsApdo+XPNyD0AIgjZt4wgDvTic2j 2H5HEew5d4XRD74D/CL/g+NjIyCFHd2Kci6wO8bGptROLrYI/xqbTy/KXS5beWqo4R Hf5jzBtogxCmzbhCLdpBa32mrlLIdmu+ayZCWqspoLwqW/CT2dow9gRA8zt6OWSvnm M1SCwcfRhpVY057fYBKoL75bOeCqJO1u5SaVjQs/DbI7kaclpa2mX6noCU3NGWP8hA YqZ0Esp1fC4KDMvzVNzVA624qem4nPPn12uyC/LCMsjBuNHbNVaMJAa8QJ9AJW2tIH 3O6FyNwaB9JJQ== Date: Thu, 31 Oct 2024 16:08:57 -0700 Subject: [PATCH 01/41] libxfs: require -std=gnu11 for compilation by default From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041565936.962545.8816035398454923868.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:09: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: 13858421 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 343531D0E0D for ; Thu, 31 Oct 2024 23:09:13 +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=1730416155; cv=none; b=XDjy9/x3fbvkOC0/VAqCRtKKXkk1CAHcxLIDL/bcL7ldRZM3Xu+rPrrDFlT+kvhKPBBcSHCrQiGnV3bAyYUNucrvjjDKTY8qS9eplVWvNVK/VtJmQ2j9bVQ8NGBxqvFoJltUYsiUTml/x6OK3Kk8dsD34gFRy3SOf0ZFve5qzbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416155; c=relaxed/simple; bh=KlNPHhwgk8I1JVpcTWdsy5uOdM0lsRQukjXvme2UCMs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SIo+MVPrTGLHf8cJ6J7M+eteBfZ7jVP47hzxXGpb42KwpqkZiPq1ZwSZZms+ONZaFB54yjOQ+NQH2qd4gHpEFLQc8fJGm0YC82UGiZ8v+pOl79xm4jO3uTSPxgGu6/UDzsSAI6cQ2Jbbp4a3Ea/AT/GHSnCDA4cpf5hh8CFOmME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IapS62Dv; 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="IapS62Dv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1FBFC4CEC3; Thu, 31 Oct 2024 23:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416153; bh=KlNPHhwgk8I1JVpcTWdsy5uOdM0lsRQukjXvme2UCMs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IapS62DvF3hfa2j1OXlr0vXtm/oRqpj2LC1MOvl3HH3184YG/zWyFCVBtlcrSWvV0 5Na3YTslJnUVqNgJ8BbeqcNurcq7fvMTAGFrcEg4SlC54wJl6j9RoPJHndQpSi0kXh jsDZBsklpjtsFVMaff48ZLtcg0F6RGw8GMKbnXXy38uLSCZ1u5WhFT8nh6h7BXLC+7 EGRnITJOMcHdWk7qL8TtAOoL4v+8Hexu2NuV+KupcmOzNSprv7k2Y8ogm4hKhIth05 8R2ycH/dry1Kji9S5w98uN0qxI4wsbgeLHDNwhkzn9yDu3PZVL2TAZHTTKE7cVKRE8 ENY/ZesqTW/Zw== Date: Thu, 31 Oct 2024 16:09:13 -0700 Subject: [PATCH 02/41] libxfs: test compiling public headers with a C++ compiler From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041565951.962545.8838198084463603108.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:09:28 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: 13858422 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 6989319F430 for ; Thu, 31 Oct 2024 23:09:29 +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=1730416169; cv=none; b=mIC/AUai28OBn+M78kqiFI5pkZjx3V5TRmKvMKCB6BILaOGNCM8vZz9gR7QzzZbr5QQ9bAgkMHdoEIJWrHzxDJDKoUwPUtXcKuqb8A27NfDNZAxR+zLlPN+CtRNO9axemyAjwn42L+7wGWSC43lWfrlszN9HiohAVusypc2a+hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416169; c=relaxed/simple; bh=AvupfvqBbEXm1z2RTQKpSV1aNaAUhwyInA6IbhkHULo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GUaclJxp6JwimQvpatQRT6MoubFE3g5NngUx9o1Nk3sUM9cvHX6KO9EZyn7JnA0LiCgYlBNH+g1YNrxEcalCfXJQd749mEmqLhRCG4JHkjg8raBBHlZrcy2LJBsW2AFA531qnVr9tDnOLXnt16wcJ7aIWieCGsjZvSiimC56jeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mRvxaor1; 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="mRvxaor1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B5B5C4CEC3; Thu, 31 Oct 2024 23:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416169; bh=AvupfvqBbEXm1z2RTQKpSV1aNaAUhwyInA6IbhkHULo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mRvxaor1QfIwbNAjWnHUCNRFEVG4zXFzm7CUJOCzjHNzb2ZG/AoZRYMzV46Vy2959 5HOivlL0CPc5OtO5uHdHMJHvIlGAkOPAhbqOJ+4aJUs5Z/7C1bEAcfgFOMrY055PMf 03FAFHXtefUXg7LEC9kthUuKJciY2xh5mPEpU3IjJdpyLCm7IbDH0A6x/WWGDRJzd6 FtbDicLWjsUamRThfLVD65oEYoctLmV2JeyRvS5WYNEoQC9fqdJqKJbywp2QdiQiHI VnMBcA898zWdRV1hsChtmEv3UNOdV1LqrXzoIfmqdLyZCbQdZe8EgZY+ry9wibKFd6 Oq0PyzdtJ5dIA== Date: Thu, 31 Oct 2024 16:09:28 -0700 Subject: [PATCH 03/41] libxfs: port IS_ENABLED from the kernel From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041565966.962545.15186064957543201505.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:09:44 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: 13858423 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 5C5C4197A87 for ; Thu, 31 Oct 2024 23:09: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=1730416185; cv=none; b=YlBwBSmQaaq5TlBTqZg0wbycICFZsF11EYz1x2eM6ozej0guU0gWFvVqC3mdgjCbRSUVV82RcZOTp+vdSgW3wOHWhDpTZo+r9w2TfcAaSpyyzJe1RnbHDpy0PXeTpFTSkdjmwP7g3k3n2I9BnGr2vKY7c0yEyuj0+Pj35o4STAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416185; c=relaxed/simple; bh=p8s03YUPGL5T3AUYprap2ZNhUpLsCpMbOZdOciQjSvA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HXDs57PT52Zd0FBwA385cBU66eCQNVnpIGEQQjRRjzo0QT5X8ThpflPdmKX7UqZu4gNRB3utziXJ8zLxXuN7qMZOFOwdzhPdeSMZF9hRE66GlC+EKfe5fconC7y5DhdOzezXBiOspt8judZFx8WMbnFq1qafJuqHBs6YTdoWjik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hxZmlLBI; 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="hxZmlLBI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9CD7C4CEC3; Thu, 31 Oct 2024 23:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416184; bh=p8s03YUPGL5T3AUYprap2ZNhUpLsCpMbOZdOciQjSvA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hxZmlLBIh1VBAdmySaoXNwGi1hn9ib8jaQCYYLQlNa+f82jDWECKtIZcMiMTeHL0j J/fu7BiJE0z+KjK1fDGTkgF1iKrFjKhbTwzAWRFvx/qmSPKOImdTuUNi+tRY9elmT7 16McgonTkxuHMoiA0kuJ+ILAh8IBlsEAr8sSJFegI+mZeSGkFA+50LKXVsnk6a/thO ukvofB6GtvWFWCrm7S59DSY7sW9XtAQU7lYP3dXlx9USWLumM6MNgjbsHnrZrcj+SJ Wi0gVMoS2BvUATIeVYOC3RcF7un6NrPEWs85x8y9EdsBfXAH8LfQ9B7ffgCJxT5CvY LPgaW2vkQmdmg== Date: Thu, 31 Oct 2024 16:09:44 -0700 Subject: [PATCH 04/41] libfrog: add xarray emulation From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041565981.962545.11363601112621213881.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:10: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: 13858424 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 B8B3519F430 for ; Thu, 31 Oct 2024 23:10:00 +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=1730416200; cv=none; b=Vs6lfsqtlo6vvqIIS/3x7AkSCFbZ7wC01s4NxwoP59lovx+0bq6cLa4EUwAtiYlBC20+9PY41AiTxdxqVlp07ShSS7fClgkoeizulUpm8m/yoQbnJHaLJfS16Mu94hIyCdV4rsTHQmgGKIYVuxzIp91tYf49cYpmcxizaJwtni8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416200; c=relaxed/simple; bh=lzVoYZzuy3JOoP9rud6PBrHJYBfHfKzj9rizo7qWaHU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U1XkqDXBOIp/DqGQblP1j/MPEaad9tXd+Y3siqNMrNoyM9kJgYQpuKVckw8SlzcFeyAkYNQpuIXrmTtvGwC7n7OolUFy2wLWC4Yy3rwR7UNDe9E5OeFiM5JI4qTJPRSAlDSmEdRUuSvhYkgTFssngcrao0RxnoAmZxA22t8qXrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YkOU/8ou; 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="YkOU/8ou" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F44AC4CEC3; Thu, 31 Oct 2024 23:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416200; bh=lzVoYZzuy3JOoP9rud6PBrHJYBfHfKzj9rizo7qWaHU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YkOU/8ouoSKmxqOHEK/0oW/1lK8kB4PwvhSLB5GBLSCCuVLLEaeYulUh+gyGyzEuZ 92N3TVDZrCrSRhicXxGCaEffM30pRPZiW215tI3CP5ZZfQxQEjx9Dv8WhiYFGcDVbN BKMDISd6bZakgBH6106Kc0isyZgyTqMmHeXTq9kCQp8dmQCOul0g3ckSeDk9sQ2w+F HPoPtSMKDZOHS4R2sCQtnl+fcrKR67+3Kmj5F6iT25poUzhJ+HH6vEmsTRkNBkOIkk 3rkRYjXlsdNkMnCYKzBxDgXNuPk9uH3AMGIT9MMuJ/gTKO017oklS6p1tfVhnA0fEJ Mu4Dkbn3XUazg== Date: Thu, 31 Oct 2024 16:10:00 -0700 Subject: [PATCH 05/41] xfs: introduce new file range commit ioctls From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041565996.962545.14170969491883990692.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:10:15 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: 13858425 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 A811719F430 for ; Thu, 31 Oct 2024 23:10:16 +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=1730416216; cv=none; b=mMEGi8YnCJUqK1b6vLPZoRYR2GWLyi6Rqdou3Gw6YDk1KMLlPla/8HGpZ4EfcQpWuhFzDxFdwO5SaN3pPj4Nt9/2AUW5hdSF2qV9Dsk2a5tJ84SJnBARnvHT1BrVv6e2yDmOVcWFbpS6FZbUingI7fLCa8uqxdPgPi1hcjGSD/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416216; c=relaxed/simple; bh=mtDnYIlDEa0PDjO4XIepg+t8AOQUSBrP/Y9TrPiaYNs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CYVz2Y8ygj0/WN5Ccd/XzxpeyilY3dHAPrHLRNAvNymyuE9myTrfp64imK5FvjBz21qeDCZ1NaYxqMBrUOab4VjwGtgNZcRGtzgctSBgJHSDk23EY3PRsWcpPtPMfmIA/LVgfd33cWpnnm5uBI5KkgIpYBI0RO73TC16yZHq5B4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnazq27Q; 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="nnazq27Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB6EC4CECF; Thu, 31 Oct 2024 23:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416216; bh=mtDnYIlDEa0PDjO4XIepg+t8AOQUSBrP/Y9TrPiaYNs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nnazq27Q0FY6XcQGNOP4Xx4c+zJrlLKwV601G0GuEarOMFC/kvIeKpyXyH8V5zuTJ pmYlXDSdMpaE6/S71O3ZrUgbn1ghtO2ndpYSUGgHwhdbpxIVfZGqZnkCZ0xSaOLeNr jGi+FZZ64TL1+TmHSsfcfGwkllUxZVHEjvVdSAeBcNhHUWueXtPbuaKosdmZf374LF 92cWYDyS55ACgwpZLri8I4GAYuxVDxCeko6Yagl1Ds/oP9y5IXh9XHM0WOOZz9h5ko KIyaJCcBwVS4cOlxlwNXjjsm5ko2W4Q3PeLDthDIkIycfMAroAp8WqeiR68FeOudRv s0nuYzXTrvnFQ== Date: Thu, 31 Oct 2024 16:10:15 -0700 Subject: [PATCH 06/41] xfs: pass the icreate args object to xfs_dialloc From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566011.962545.7956432226389299300.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:10:31 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: 13858426 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 0181319F430 for ; Thu, 31 Oct 2024 23:10:31 +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=1730416232; cv=none; b=BkzMk1sF+Q/uc0QJ0EDbjmY2k9BNzNQ7vCJrO9StAf63KTGUbRtIrpuPzFwLIDDn5/RADeNF4wuI/PApYb3IAGBmqor9oLCC05NZZwBWPmrOIO4EkQwWu/r2mwUBFEqx8RdXOPMNS+StXUAGVa6UN47hid93IsJgK3qi150xELg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416232; c=relaxed/simple; bh=x/VHeZr1db/0cnjY3yrszpmQfhlEnFBp3ghbmgpQIAw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oXJBoude38NedrHjpv4iwxSa+VOqvwVKIXRBozHQdeifjt1t8QuXuQpl0esXzu/PGpramFwdn+z4rW6Fk1vkjHfkJ7UlnG795pMKs8r1D7wC8lxbPR1x2D5fxvkZbMxZWd9qqDRyUWxrB1sAh4/sazONwkJdnfVyUviiDMSQNfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bDIDq7ia; 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="bDIDq7ia" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C981CC4CEC3; Thu, 31 Oct 2024 23:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416231; bh=x/VHeZr1db/0cnjY3yrszpmQfhlEnFBp3ghbmgpQIAw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bDIDq7iaAKYeYHl1gKxx3bz2bp+QycpOozm1PTdtaHbbIxeXmgV8bCL1TBnKSE6aj FPLXFWq8q4oXnJyd0/PS4EoUrlTMGD08qEOGzmAuA9pD8lJM2hq3MVTlQfZ4t8vE7T 0NXhKu8tsbet7pzYiDb65jQofJ8RZsspk5fr5yjTVIeOFN/xmIH5ThjUcP8Mmt6yxm C4cyYwlRHIO/VRv6IyCV41ApeDwsx3DD4JxP8oYfhwGo1VD0dJl8xGSHnR7QB+kUJB 5QLPmp+XxJYxiWngNWXj6sBpLGSIlz/p9rja0vyPRxNbtd11Byn8tdZyP2l03vAtNH FlmFevEMm6vpg== Date: Thu, 31 Oct 2024 16:10:31 -0700 Subject: [PATCH 07/41] xfs: remove xfs_validate_rtextents From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566027.962545.11315128066429511227.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:10: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: 13858427 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 9958B1D0F7E for ; Thu, 31 Oct 2024 23:10:47 +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=1730416247; cv=none; b=b9Rr5rbPDHmU85GBjBB2e6fsfa+KC9SqHKNpvc9b+tUNw3yD7XNwIG/1/t/oC9xJDhVKQb4peCaiOjn9SjDpxDzXlnvPxFFtfgRtZcMeOXCbHAtINMeR9yCuvj/BqxFy4Bm7QF2po8xuNY5ih/Dn7QMf/+v7F4PeF8W5TEki7Sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416247; c=relaxed/simple; bh=neVwpzzWoEfhxcLgi6U1ic6a2Tpij+mBOGXRufzDgmM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fEILlRCmUhXAxlwH27G9pn05ff53xepUzhtz3iKx8wY6+rqG90UJWWm89HTIQP+9QYifRSj+1KMULkKyeyj/BTVGS4oQbOLh8jlOV9ZSv9yKJ2H29uzvKP7TPFUGHWS0RyRACVdJlEHlzTyhvZz9MmU+iq8gQjK58BQyhYwrZVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=izdqR2/2; 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="izdqR2/2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D683C4CED2; Thu, 31 Oct 2024 23:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416247; bh=neVwpzzWoEfhxcLgi6U1ic6a2Tpij+mBOGXRufzDgmM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=izdqR2/2T7XoZIyIIy0YzEFTLG+XywFbsR8ho1sbqaCwmBLABQdq11jr6Z2jdkpNk agd1gfx8BoxBvSCRxAxTBvMcePb4/pyNQvi/H7JP6vmMYXDBtXeATKLAfh2/YgltTn 1c20F4AsCqVo/TY2tGXGTgO0uO6lr/1NwgfbeN5Sh/ophWEVECMv5vCDDnNTanybwq Qcwxmtmz5Q0k6ONnhEINDTr9lOArb7UJRY4bGgIkfrHs804p699xc9KLzfadBEvOZw R3/RSALIHBy3GsQPGyj3xsNEss3hXLJfLvtxPqw0OCcjoZia4KFZ8sfOGRvpgK6p7o CCSDL4cfhb85w== Date: Thu, 31 Oct 2024 16:10:47 -0700 Subject: [PATCH 08/41] xfs: factor out a xfs_validate_rt_geometry helper From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566042.962545.15976875332001408193.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:11:02 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: 13858428 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 985D11CDFB4 for ; Thu, 31 Oct 2024 23:11: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=1730416263; cv=none; b=gGKjDXe/6gmZRcXNhz9Jpi3Ealb7oMstJIjj1cpZx331kT8Zi972CZCvoyFq77OPkkPvN0Yr2Lt+6xfdqjb0ZlbJzFBhGEUxe+b8PrCrmwCoxpLM/BZeXob5lBFGCm83tpWetPD6cFK0JeegTllvCcC7PLad91Fw1ZZTYa6ALqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416263; c=relaxed/simple; bh=9pSWW6myBYphmV/7ZWKjzJDBWqRUuXQMijVw2gnl2yQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cmd02TYzffURSl+D/r8SoMi10Meg7S4vSnwcQ/ruE6Jg5ax+CoHNnIwlGom9or/lB4GM48ZR/1uFceVLVg0ZPcGmWgzCdl4L+xtR3ApJnU973tstvgmHKdFJ0Zup2nBZeEX3JAH8YcWpmuVs7PMR/HHnoDqeL12acFIL+Zgr7Jo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JUuUtmCb; 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="JUuUtmCb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11EF7C4CEC3; Thu, 31 Oct 2024 23:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416263; bh=9pSWW6myBYphmV/7ZWKjzJDBWqRUuXQMijVw2gnl2yQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JUuUtmCbuf5KP/PMnnL2LDTxAvSBA8MPaFssyJ3Y9XSVHnyaSBcMFISgqMQmynUF8 08jwlOA/43cUvI7fe8OjCeWLeZVC54s3w41IeiEaC4cj4Gam5Xma/OKLvjUg+qGTyc N6mjnjJWN3mrg6PBY8/5NN/ST96wmlJdehjzQgQ7Ren38bIE1rzf5v04ZtEWZ8QOgl 3d3IagATHiHV6DcPayvFvc7IRCPG2duMBquc1jg2y20FhhWQeMC75TW5C17XJ6B49Z OSA7+MFY6eutqOoUPRYFSyWGtGwmoa09doCBR1hifXMVMmLgml9sNCI7rMjMFS5myi nYSbxTQzneX+A== Date: Thu, 31 Oct 2024 16:11:02 -0700 Subject: [PATCH 09/41] xfs: remove the limit argument to xfs_rtfind_back From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566057.962545.5860918064169333508.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:11: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: 13858429 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 D32031CC8AF for ; Thu, 31 Oct 2024 23:11:18 +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=1730416278; cv=none; b=Bj1lh2DSGTCmUWcaDMtK8KnwlMmVRxsuoPifDBFWXvg86k+IshQn7hlqRefkQF5LXGXbrKyG7oD4ZjOm8SJFnhCpP/4IDZs+rT1cTeWEKKu3E0MluiERgagDefRyt2QWP2IoUaAV9RIzhZ9NUxRp617QD1yXMOhjaKNFA2K34Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416278; c=relaxed/simple; bh=RIiq8wv6cT21v+OF5Npukq//GNb2e8AddT2Ptw9IdAg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Oc06WZlXQcl0g5znPfeEfy2CFFamqo/nGMDzkizc+WKHaYf1i7jKkOqTKMS29lwJIWLSyI1fr2IGHYQxUzVI2V3pwumi5av0yrDUQND6Kxe66WygpdaKKRfAEMRFEXhDfMUjwc6vQf7MmT7CCI5qtrQgE1MasYuCCjb2rV+dXQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J27z5B7z; 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="J27z5B7z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A808BC4CEC3; Thu, 31 Oct 2024 23:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416278; bh=RIiq8wv6cT21v+OF5Npukq//GNb2e8AddT2Ptw9IdAg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=J27z5B7zVe0Bz9hcbMCuKcMO3u1PUBQLB3EH/abQ0OhdgnXwb3hso12kLRENHgowF s+Woaj5uSLHBm8l8LQpGzctURz7WEmHeu4GmZL9UnlisCzeN1iO4N8LpHMdhCW5FKu eoPNP+WZ1bpT4fK8Bt5x+WqJnU2AEvCFmyDJKvAhG+b+ZAVvASng8KMSoEO5qAkLzL LZcG6NLKdXiHeAW4oIN41998JFC5F6PL2GUvZu8QhDq6h+tfWEPNKU4kpkJquaM5ku c7jm8schc5Us3+uFbo8aXSv3FPG99xNK34cXztMNJ2GOyBZukDHIS19WENWBEufbBd xLfoEmiDa0Lsg== Date: Thu, 31 Oct 2024 16:11:18 -0700 Subject: [PATCH 10/41] xfs: assert a valid limit in xfs_rtfind_forw From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566073.962545.18309774070518861945.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:11:33 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: 13858430 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 D5A111CDFB4 for ; Thu, 31 Oct 2024 23:11:34 +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=1730416294; cv=none; b=p3HnlmnFKCyNlgqZS6XJycGKQG36r3pw+g806lL2gABkWtyFsbvNr9s7pJZhtHQBZ7+PJI2Hp8uaTt5YOorcKarvOAQNjDJaeiwyx1pfX0LigCvyW1+0bvi44o0a9vjlMRbjq4uyZbWM4FDZsxarpu3b5kgt+TpGhtp07Binp7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416294; c=relaxed/simple; bh=vAaI00AcFFFoGiGg4HfoHHSkdd7pZjID/WpJHDG1SI8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZqGZnrbbYkyv7/5OxwZ7ec+GC4U77wow0rlvBmeHibf1UMT1Hbt2L4flolRx3JYDZLJ4ORtVImh0U2QjCsm2QYPj2vP6yZIJu810Si2JBvndQIPcPdwLsNx4Dh03FgcfEbe/sYO76vEQflGNFoooJArSPMYnKsITrFE7+cKZJrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SDkOvgp2; 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="SDkOvgp2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F7B9C4CEC3; Thu, 31 Oct 2024 23:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416294; bh=vAaI00AcFFFoGiGg4HfoHHSkdd7pZjID/WpJHDG1SI8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SDkOvgp24qp6/UtOx8Uql9c1mGLoFtWHSpokUlYTMuqxoGBbfDmjDSauBfCDT8bdr qeGdRd6HzksU69St1Nyh5ssENXVk+RvQ1B307gemGSZW9RN1VmEqkhEkiw4qKjByuL IgvVJMLW6zSNyhkLQKENXYxXO5Y5zliORIDWZ8Wqw9YUynIa7UqX7lGtkZZvoeWZcR 18CRcU3ysDS5EYtAHN+R8PX27HuKFJkDkdi2YuToFbD2LJTKWwVH4QWsdDEEPEvMbZ kw3B401TZjMVIRFF2ksO0QI25lSPPbvA34v7WeQfHqHzx2VP95eF3kgx0QOIOGIP9l +zF8igbjYoufw== Date: Thu, 31 Oct 2024 16:11:33 -0700 Subject: [PATCH 11/41] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566088.962545.11332836383456959576.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:11:49 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: 13858431 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 2C44F19F430 for ; Thu, 31 Oct 2024 23:11:50 +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=1730416310; cv=none; b=h++GAjiHIOLzS299s3/Ch9tEDbijfXm55tnSVTnDNh19MTWt0piuFzrS761n8PWxm6//Np+tFelAxL9+dgY0zaTNqKQ38e4058UnA9CowtWcLXJnIxF8Fw+85pibnJMJHNOczxR1MKrwI3bXgTCaUNzz2UK3WxIgYDFNe/+aKro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416310; c=relaxed/simple; bh=8svOkqyDhvtmoKyRmdlfVLGDCIW5e05QT/GBbirxhQA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YPI7RREncR1orLvQmGnmujgzIri73+WYLEv0fi+7NUFFn2HHJ4Lj7IqprVq6EDGNqGsTq/NT+t78HprYnM7b/ardhpmVbp6E+kewwqWLXiwfyw+6KzwV9wcorYHVl4sn/rWv0Lp6O92Xg3pxhbcor9BAelg/Wdq9zLevbY4gW2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eSCQ4YWf; 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="eSCQ4YWf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01FD9C4CEC3; Thu, 31 Oct 2024 23:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416310; bh=8svOkqyDhvtmoKyRmdlfVLGDCIW5e05QT/GBbirxhQA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eSCQ4YWfgX0TZPiQ35rH0MLsujaYIpfj9w0OOzjfLQSFNO3XpxGtCLFVBz+sTVAnU 9vW6I9VywpBo7JqGTKodo3WbShI9qdmAomigGJWqtMjRqz5AYDBEXJJ4JASqzCSJiL vgb7YiSplof8134fBd6jgkj5FtH2UVM8U8aNgZq390+ghtadeK/AU5eAwAaPSwC8a7 MfKXtHLCdsgPEZGjrcGYqMVDJ1oYI405oToE/0PEM8JTS4dXF3fPi5NWEJSGYZxkoY 2zbvC7oS0usu1EhZiYvNYQGzAkxb9AuoZfrWr9rdKwOn3v94J689cnODcHN9dznmLg BgYZUEygDGKWA== Date: Thu, 31 Oct 2024 16:11:49 -0700 Subject: [PATCH 12/41] xfs: factor out rtbitmap/summary initialization helpers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566102.962545.10982856844842387054.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:12:05 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: 13858432 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 C142419F430 for ; Thu, 31 Oct 2024 23:12:05 +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=1730416325; cv=none; b=Vxj0ba3LBv7IOQ+Npk+cDUwbnCoaXU/bB6TuYfEMevRfuDkQxDEzdl5FQonWPNHLHwOoj1A+HdKd3HAYJWx5i971oCV/jinugOIB2RsZrRS+rqkDT6F0bgV1w+IMlc0/NMvGJt6LdvmKZZBhZ4I4POkhI751PwpNm1u9vS2vOts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416325; c=relaxed/simple; bh=puQ75ii0lltlveV/actzFuGRC1zAWDrLanJfuUqHLrI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BKCldNI+Y+04vYvJHPgla+oEnttpcVyoJfx6ZdqAoB87tQg7oyzpH8qtnL3ubonwWJMYHhTOl8avobw8rDGvhPifTqvt7Ux35VAySN4z2NeghcUQmwFa8YYxOVEI2fiADOW4lW/U+Eos7YZz0rRzzOb6+4CA7fWDvU0i8y4VCVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oNupHn6q; 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="oNupHn6q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 951B8C4CEC3; Thu, 31 Oct 2024 23:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416325; bh=puQ75ii0lltlveV/actzFuGRC1zAWDrLanJfuUqHLrI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oNupHn6qxby0xP094s6ywD3rm2g5qS+scd0necCAuAJhyUC6uC22MuUQx1nfVhuCm JCBcLqvUt7zxbQQdbPnRCpf4dMMXa7ypYRWW5Mh3pcQZhqZJVtxBB3yb+KVF+6uMOw hy5wvpZItji77FLXuG8E94//YYCkEWQ6Rsng/rRZ2f0cs1nXDNUBnEhIIOXEaxNWWn wOjIVL1wQqB4926+1ZLskV8V6064RccVWeCHpURjnQyRyxWURy7rXOkvhCSEdLT1zx ATh2Uen315H5NYplUQ8xl9uQwh0SSaRp/zTQ2W2WEhCE5vhBEelUxibs1QQYEXWY3g Y5mVebWU/5JfQ== Date: Thu, 31 Oct 2024 16:12:05 -0700 Subject: [PATCH 13/41] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566117.962545.15007403731898758310.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:12:20 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: 13858433 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 9C9B31D0F7E for ; Thu, 31 Oct 2024 23:12:21 +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=1730416341; cv=none; b=HUKDval9JnW0EQ1NrE148U/rxM2VNvJhDhrcjIP1EGP9rlaUkN7xFrcuyB6ts8OcU5GAscgVrBokT9xKYBzRMtVgR+AphLhUsfRtmDZkoNwfbNh0yNZVJBI959lfgMUQqI5E5Pen+fyC2wQaFDK8NZ6jiPPEKGS60uYfy1Bv++w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416341; c=relaxed/simple; bh=Rvd9PTX3D8ti/tL+t2nPfT1geOYz0RJd4cjK1H5gnsc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TAcDE0BFppkUdLPIa2PT8UahBafpaYZrViMSmu/vDxSgHWYODU2vOTp6jmaV9nE1fNHynW/Y3RC/ypVx52omhYrxM0m7OgZ5mAVWQnSj95whutZ/hi58d09dvxIVWOooXzLHuXIkXhcKnJWB4ekAI9yU+usa2wedxiN3TJD9wf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l4blBJBs; 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="l4blBJBs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30525C4CEC3; Thu, 31 Oct 2024 23:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416341; bh=Rvd9PTX3D8ti/tL+t2nPfT1geOYz0RJd4cjK1H5gnsc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=l4blBJBsxyXnFhoMfEiV+dCQD3M8bUH0Db+198unTG4+Z4VVgzMcZpnfcdY9BBEvW Xmwq+aCPIKGoELY0Cg/k3ggCJg8MwairrJrJRS7XT6hzO5htscNQW5SwJBQUKUSDO7 C5PG/EWu+mUwnH5qChKRjBTOqG7eYWPZUny6noEBsLaD3Cl7flThuNMumJc+HDA/Zt STW0U6DlkAiCtjYdoJ6vGgWw1SFUP3onPQyfRZQ5sgQAUGQlT9cwvqLB/+mEI1+Ram V/0gMJB34A+iL1EpbE3UiJGO+E6MTvI56BGinBz4ikK+qgqzbEwcXJfw7atCcwKhbP ZjfQSGZFfr81g== Date: Thu, 31 Oct 2024 16:12:20 -0700 Subject: [PATCH 14/41] xfs: ensure rtx mask/shift are correct after growfs From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566133.962545.4618811593843103724.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:12:36 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: 13858434 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 6CEBD19F430 for ; Thu, 31 Oct 2024 23:12:37 +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=1730416357; cv=none; b=eCdj42m17j0/CeFhyUh0nUOokwxKB+TIVRkL0wikZ1IdV4pm35yuGC8T1HzajevVpsuQOlfNiL9Gj0miAulPyAwOEvgJUx8uoSNvewm5h6C+KTrmvhLZoaZhChYV+/Iu18lGXTWl6JHVRtkg1z8S6JWCaYtHGTRhxCcrS3ETOng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416357; c=relaxed/simple; bh=AuqRh3OrtuH/JvbRD6WrnZHL53jxm6CypTiWutKsO5U=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l3qAqYnoFvsLAZTkSY3i7R6SqDj4zvoRhqAUTgTqcSnw5xQOcthzndzwcRH0lTuhI01Peong/bJLLmDH/fOOO9ywlxISaZkI4e1spgLq4IsT5aBIWnWB0ztT/lgukxhMg1tMrwCoomQzgIJLtxVxdyU1NcNWWccUfhBAY79R4zk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CL5ppxkn; 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="CL5ppxkn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D815DC4CEC3; Thu, 31 Oct 2024 23:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416356; bh=AuqRh3OrtuH/JvbRD6WrnZHL53jxm6CypTiWutKsO5U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CL5ppxknKRTurBp+7OvsFHzkIXkMx1ljqU0/BbsJkHorxFgcqaK6hxBWc4e409ETt SGBhSvprYi56ObBJKneHTNEDvRyJNVWo8563VNwE0nWeOBVJo7A1HSFWt/FlE0aSPJ uvmvbuy/dQEpyxVRWrpnkj+X7UonXFe4qBhz7uUc/opG8CBB/C3RKJylftOAMm7LiQ fD6+IDm1nEd2j6HCPDNpnafbEDUdCYm9gGyaf/PONaBiMzDKbd3VK8tevrkZjl8yEy MFMMQ3kfMQsA0lczrJ/hjZJies0TospRk5EMyvUS8oBhQ2ECx2YCw0kf0tOgI6mtij TGxk/7Gll0Csg== Date: Thu, 31 Oct 2024 16:12:36 -0700 Subject: [PATCH 15/41] xfs: remove xfs_rtb_to_rtxrem From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566148.962545.7142397402329862218.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:12:52 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: 13858441 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 A210F19F430 for ; Thu, 31 Oct 2024 23:12:52 +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=1730416372; cv=none; b=onGpz9eh1pf3sDjqOaCUI0+61ZhVrJD/7yc2m/x8q5e6ANdZQgo9xDH+ssOPSt7YiKuC5BLdt3bNbK2CRLJ1C6fkoDXm0mr1KkQmTP+PDWfWXbvImtMuRmIZRFkuICLpp007aJd/R5oGdUw4yOjt4vAMIYskSq151xzumpobE60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416372; 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=Rq06wePhUeiZNEzLCRjXybTo94Db01rayqxBlT9IossAZXZHxeYJS3r1Hlofjx5ksZRITOu1HwKGQDgXy/JrT8dA50oSEo8zfZQmkIzU49rxldDbiFadMHL2FGSeDTvNPraUBH9TzH1uFe8qZiDf0A+iCWsq0pdw8d/2R7Tldew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cdpBONI1; 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="cdpBONI1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CF10C4CEC3; Thu, 31 Oct 2024 23:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416372; bh=aDphQeYyK23f/42cdKznjfHvSdtjC+v4pkbxc5/PtP0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cdpBONI11XbD+IyNvreOkVHtuqcwCdij/OAqLB5N+4DG8EKgzf8Dg3fwJH7CyXd8I sH6eaSZjJgvJhywR/1cJRdZGsRoGLrINXRwhgToA9EggVwjw+THxf90jS9BAtRQdQV wfpReJ3VNmh6yy1sy8/U0pR/ot94JPrnuVGhaJW1FfZLLOVDk2Z8G7DT/BbRXFzhXo W98ASyBDt4R8qaw9Rgn9Gd5xTqEsKcuCxXaH8AIoBEXHvhTTvpUm3GwVGbF4jKVASy wknbvWcnaIfYHwjo7XdHpz7BqDePyFQpBNIR1CnYr92zUVVbgQ/qRq2ePVUPYwKg1j oZNEtDYkEKQRw== Date: Thu, 31 Oct 2024 16:12:52 -0700 Subject: [PATCH 16/41] xfs: simplify xfs_rtalloc_query_range From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566163.962545.16668768520023131640.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:13:07 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: 13858442 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 40D8E19F430 for ; Thu, 31 Oct 2024 23:13:08 +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=1730416388; cv=none; b=ez+VAoh6A48LXIyEFn8fi6getJHt23Hgaaw0i5g1aDB0W+VK8bZciEdLWygpQGGx5sRD0KHcJXGy2YiEnc5xKEcrY1kvVA3MR/Kf9B5YQCLSrl/cxSZPhxejH9sWY+JY27mHRnCqYwbUBiHAy1tJSK2iqDntlbn7rJ0O4gKAs6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416388; c=relaxed/simple; bh=RqVGnlsjdzM4k+hiPQ00Hj7eqU6yxfXEbY7XmeDmQcI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cquEfgHEweuZ58ZqaetX8yTP+rQavwkMWRQW3iDolG94db7/0N4JRWhDg/RTO3lh+SRAUrYYQXWH89kNIeosYNs/HiL65Ggj2N0hSxGlxc9tRBqRt1X/y1ZvFnHiKtl7q77NyUgbi6jTbURJbVb6p6UtpiVYILHUy4iGZPdZ38U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E0fKCB+9; 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="E0fKCB+9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14E33C4CEC3; Thu, 31 Oct 2024 23:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416388; bh=RqVGnlsjdzM4k+hiPQ00Hj7eqU6yxfXEbY7XmeDmQcI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=E0fKCB+9ZKWM701bYHUmtTan7JuLiKTdegIkj6OeAdW9sCyEJBsK6YlMeJ17ACGii Tqy1I1589+pCUBWjWskKij6t3vKwiyPFvz/DUGymmGbdTas1w+Kg1ODnXxFocuWIul Q1eHvGy2BK0FZPtgjTjKRUPUTBjm21CPqqQmam7qkEx/Ka8y6YQbvuS8qAs9m2aiGS 3mR+f+if3FG6lmWUuObmO5q2+P3zYQZzSDhRUadoB8nYn7FGvkrSh+TBmvx+06d//+ PLSU3PLfLbaHpVKO2TkNA5bY8tB8hyUyVOZ6M9Bj1giVzez717LOx4BXk7Ehh6g2It b5Hsl2D2O1PNA== Date: Thu, 31 Oct 2024 16:13:07 -0700 Subject: [PATCH 17/41] xfs: clean up the ISVALID macro in xfs_bmap_adjacent From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566177.962545.15497863708448833258.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:13:23 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: 13858443 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 2BE9919F430 for ; Thu, 31 Oct 2024 23:13:23 +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=1730416404; cv=none; b=G61U1aPQUb++w8OM26jjztCH85iwyYi+OPxH7bTv9h/bYhxuCRH2qvBMBtLzM5a5zObrCXwtYKJW674DQv69y1SDdo8qTG/H+8mCPM9t79gE283aopIW3Xx4fT6kPCYkb4pULg+wr5ZEyi5tj8HY568Gddv5VOtx0Ih1Y4ywlsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416404; c=relaxed/simple; bh=oG+f4AX5lGEUmIbRkYV4kNB8pd7rIdbFVAcjbDq1x/A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q5dE5n1cPWUN63gLgcaCJ1j8cGSiR8dqz84pKYIgaqXMpIFNF6FeH+0YOCLOfAmX4Y99MUYRxxt/sP43PnZ4oz4GTlUTTcjeuCsW8JF7t93I3WJpNZedgyLDVvb5WY5mqXqFN4YX1zDVGO4CuJ8WW4J30EIAMNfGPzqmwhDqCK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ci26pZPq; 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="ci26pZPq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7147C4CECF; Thu, 31 Oct 2024 23:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416403; bh=oG+f4AX5lGEUmIbRkYV4kNB8pd7rIdbFVAcjbDq1x/A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ci26pZPqqazNXERmAEJY3Tu3+DnPVcDs24wEZH3bXBWEpF2XQpaI0WCc4COU+YNG0 86WVduZzyKDnag4vQAGBc6lo9d5yUsR+tlowNQyEQhVsnjmPqDdG+pABbgA8kR1DUE JJRP+GxbI2ES9TutDm5dbARSAgPHbwBcQJ3ZqawnHREa6S8/YNicr7DD6BSuZW6wNu +zSt42Gz7d5zwPZ7CcAcjm8/I+pUogTeftnT4ll4PceinrqfhVYEfH9gMjcdNxgrSe Uvef1KTAB7dooJqkAA5di+nz/o9MUAOGTlx2n/SdvzHBANMtLnthF3Es5BxFwttjsa v3mdEVALf0U7A== Date: Thu, 31 Oct 2024 16:13:23 -0700 Subject: [PATCH 18/41] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566192.962545.17596134285171375124.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:13:38 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: 13858444 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 8112B1E2313 for ; Thu, 31 Oct 2024 23:13:39 +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=1730416419; cv=none; b=ktU2AP+a9PWMWnn3BUSOWD1DdHKCG7qXcMRwHJ67WPdaVUi6GSShci3lJOj+QAD1k3H9B6Va+t5YOaDx56PRE8mKoml9BQ2VaxIrIwEdo46W84HcarIsTwt0FMU9pf8nOc7I8cnuFghwAD61t0m0iKYplcXz6uNJUMWMh3qOBVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416419; 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=i8w/sYD15+5UxQYHbtEyaYB6FulGGso4PrHd0C0gsgfSN4a+GDqZpW87LPKAQpIc0sHr2l1X2sKxT72F9jI6H6DxwUDbtn4uf/4AXKlEdJeE/LKWwOJxc/In8e4H53Zr2zH9qsKAncQWmwubZuIFldIdOsiJIZqa3Kt9OF3m4Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ub1SvTCg; 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="ub1SvTCg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 565F1C4CED3; Thu, 31 Oct 2024 23:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416419; bh=OMxzYsbIJD+uw4JocWoS2/benWEaVdp+QZf8tOsxbuk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ub1SvTCgSJb7XTqCb84IOzJa6G+jTO7SmN4Shre3Kup7c7zIminplt1wIbyKsF71I O++hAUo2wBZz60MdhNDQWHj0OdCBUHaId/KXJVIjpJbekTK0nzZQ/NM24XwqgFnOo1 +SkZMQ1C+vRazNk3kLw43jH1z3q6rek0MB3daerKnFpfrDYC50GwnOKRk0KJ3gIr+G trkIJwouud2t63r9pdnZMJOSiMOi6136Z+L2DOcoLMsg0UKkc1nm2Ln7wuVYXX9oMQ b1f1k1LBKgAcxKYpuhpaWHYU7GEv08Y3vTgkS82oLZIXFHXNZzVSTkD7QoLtQ2cYjR FDhID26xTmukw== Date: Thu, 31 Oct 2024 16:13:38 -0700 Subject: [PATCH 19/41] xfs: replace m_rsumsize with m_rsumblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566208.962545.13909277438256627573.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:13:54 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: 13858445 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 2D6A51E2007 for ; Thu, 31 Oct 2024 23:13:55 +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=1730416435; cv=none; b=bQ9kU8orbGiD+BrXi5dPSbvh9qpIuUi9ht26vY769Xr019YPDwtqKoByLt7kYl2kxZSFEfLcw3RxhUSGLR9bnPRWnqo8qv54k9lEPpJShLWnEJODM4SQ3K2QQNFKBjw1Va7fna1th7BEhUzLdpy30/imUXkUo/rk4n+AwNHw+cQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416435; c=relaxed/simple; bh=kgqlXPZJXrEv14UCZxjnwMZSGjAvtIJcgawEhVNUCpU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fq2/NAtF9KF6gPk93/kP6Gaapgqfr4FLp1XfEt5OC3cIn5dJJBHQ78vj16Qte7cxq15/nGUHbxOhKlbWym+fz+yTczqlthHsN7us4yb14qnet6jY3ZYqckVnVgwD9Hp/jqsqRYimUZxBCbIFpzRjQfMhjvSbUorl9hcvIMcBNtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KuINVTLo; 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="KuINVTLo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 021F6C4CEC3; Thu, 31 Oct 2024 23:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416435; bh=kgqlXPZJXrEv14UCZxjnwMZSGjAvtIJcgawEhVNUCpU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KuINVTLoolb2ROr7sdwdJ9SJoLWHWtAIzCcM4Eym39PKg3rm9zAIyWXJguzv7B8EC PHgGXRFq86sjjCryYqSHwZ57jKdj0J0x5EUk6CplX3nd7AshkZ9gP1sDK02V6HBbXB kuo+7bm5hWySgT81f7r8pmABJSoKVgXhhDFQ5RkARuoGJX3RDQSSP5iatbOEVIEO2p AxLuMVpCCJ2jORXo7uCOTZpqjgb9+3xPkatxwWcdN23kZ+ihLVodHRGT/8tqJsu8+N h/atXr4aNt8GBTNutYBNnXjhUQ7SzZluNmRwCk1RfaLF+H8sRip9VuLSHG2dgqzI57 pgOp7hqzX7RXQ== Date: Thu, 31 Oct 2024 16:13:54 -0700 Subject: [PATCH 20/41] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566223.962545.8866628096975435349.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:14:10 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: 13858446 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 193971DBB36 for ; Thu, 31 Oct 2024 23:14:10 +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=1730416451; cv=none; b=gV8Nr9vvjKF4xvrpO6i476UUWymdFMUqOfjQx7xiqsiQ51sl8tcxkWJ1fiZgqHZ6pVzrP4MgB0lyev+8lgnp2jz1Enpavw9YUC4uII/Lh3/gDHCLDIiJ2ymrcvKvxMZytqOGhjoZnGsn/LtSLrc4nL4kXFXwq1jeBvHbzhn/HYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416451; c=relaxed/simple; bh=lzLKw6fIq8ctRStjUW9gKBPWY2KCzfzOfZQbW1pkWXU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oFxfYLTWff4+cVMgRcAzVLO038OsjmsoEw/8UrvrxovtoXdOc6vT1DJUILUWsjdLLhaWR3p3tJ0p8a1Ans481yzLO5w5JYPz0EOLI8NkWkjzWDL+xtElLC1EtbPyOz7LrG+GgeBlMb6G1MErZkZwOZ6YKHyQRk4lhsJkigpQt88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r/k1b07H; 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="r/k1b07H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C224C4CED1; Thu, 31 Oct 2024 23:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416450; bh=lzLKw6fIq8ctRStjUW9gKBPWY2KCzfzOfZQbW1pkWXU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=r/k1b07HkaR+95BzCnXvytntbBdhIk4whprD2kPeDQ85UidGY+RaZvlat6NODcTEp EU6MHZ6bBh7gmqoDo6HKAGXGswc/uewV7icu7ygAGhHvhoDqlTg5RpYfZtBUlkquMb dXRLR+pfiXZcEaPBnhKk0QxkR9WZlu1opPnxAfncOQ4v1UtXgoaDT/Ehs7iMiWvaK2 L63/hkQU+Qi1Fk+zZdQvRblW1J83JOq2iU3UDynX2nDUC8vMoS9D58WhrEvcGUDSCX E+/iFzr6e9JHYCkcXF7H0ivvjVYL9AT+H36Ww81GMkok2ZKxWYroX9sjF1cxA7136N tTq6i1RAQXTXw== Date: Thu, 31 Oct 2024 16:14:10 -0700 Subject: [PATCH 21/41] xfs: replace shouty XFS_BM{BT,DR} macros From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566238.962545.2544606469028986862.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:14:25 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: 13858447 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 69F541DBB36 for ; Thu, 31 Oct 2024 23:14:26 +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=1730416466; cv=none; b=CSjY26MopSf7wrzQ0AlS4gDCUeqPW0AJWP772JPBS2joYiW/wBlbNG+IAuqndP0LeK9/vzVfo+oCNZdQFqcDKljtXx5P/OxHq0qIeFAUhcaFcZMJ8KcO8l05c0dt6qbqwhiC0ooMfBxT2qE4obh8ZK3AbvkiCfmMU5hgHDXGpS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416466; c=relaxed/simple; bh=EkPPmN6EQjA2v34CdC404WfKpOHTXHLekHSl+Wu3CPg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gZ7/9vsPqeYK4SbSEa9vybLjDkW+SwzxtH/uOfJhqYzyJ+VmfAgb9x1OGLmqXww+Haf69sLvnd41Vw8ALoOX6IF/4K/5hx5heYige1AER+ITqW0af5zCJhuvZuT80/lSPsp581Auc7273mfQhw3kbIzWxzzL7E/wYtKmES285+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FViMppOW; 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="FViMppOW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41E92C4CED1; Thu, 31 Oct 2024 23:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416466; bh=EkPPmN6EQjA2v34CdC404WfKpOHTXHLekHSl+Wu3CPg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FViMppOWhXBSlhQGGmkim6Y3hhASLXk+PY6VlWCjIATIiMMfZnP12+XfpjMxCAtll 3GfHlcs4cMawv8CyVnk4KGnkig0xaujLJEAA34D8DUZgTws5yKuB9L0T0F8cTk977N 5FTXhm/vAS+RwFyWYXawXTgLQWi9SYqwC0ROc0dBYZaEMigRKfsu5gjedQCd2DY1NN 64TtYNxO12OXJzKdg0PB8SiCGukxhDk6nuUVuqio6THriO9+GCn/8zatS+FTgb8BfT 5CW34zVp/0pwwTIsBOlfwK8IbJfKRDBuFJc5BEFFoRChV6N4ZLYXIFRKiJI00jvc4G 4GWr7dSkpBcCw== Date: Thu, 31 Oct 2024 16:14:25 -0700 Subject: [PATCH 22/41] xfs: standardize the btree maxrecs function parameters From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566254.962545.17619819344085733033.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:14:41 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: 13858448 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 13DE21D0F66 for ; Thu, 31 Oct 2024 23:14:42 +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=1730416482; cv=none; b=YLuEmZzOz4NUoJj/r2Y2ZTQI6PP3xz5ITCYX5BK0F/Rj6TQBfT+lWv9J0dBd+M0quWr7qva2S3gpBNzZAqj9M3iTJopRJRiMWgrL1PpAkv7lxe4BdSx2i6g/3FEDdmyUu50H5wT7b87DxNhG2vF/snP6u6xbuxNIXuxOu0a940I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416482; c=relaxed/simple; bh=8jmw6n/nScN7o36XFdkmO8Q6GCTOrnBze95n3w2Z8eQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hVCUhpMDdAxrB5KCp1FoN2mAJLKdEIRnnUA87ioErfy8P9onwZ4cRdn1xJLbrKcIxBFkBJ6AfCahwMJijvvyLM5KN6AFpFOnCKXX/3zhUJvGdta11QK7lDK10cVwjrQUt8rw2Y38hZtTVmjvg6z0xIf2jd9dZIzbffmk0V2NhKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KGkm8xRu; 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="KGkm8xRu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB7B8C4CEC3; Thu, 31 Oct 2024 23:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416481; bh=8jmw6n/nScN7o36XFdkmO8Q6GCTOrnBze95n3w2Z8eQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KGkm8xRu4ltr4g1kavu+kg647Go/alonUeeRrh1KhVTM4CdDvrBc2T7oaOGSK6DQi k/c0IDKVAeFJI2PpIJuyDagKu0M2Ceru38rcTL72IVD+EMjoSex0YBPqWjgg4ZSaZs 6N9iUaYn7bbtcU3gU1LJ+EEOK/g0RrFKJIBzH2kpx0r0FEBKzd4HPgZ/8u+HrMsl9H /SbBKeS3L8065b02TpR801QwMKuVTyAsgxj82/MI1QRelLGFzjOQoGu2Vt9cN4MGaK tl2uMBPZGPyFUXuiM+vAL/EV5sD0gdKn/zSnyGuslDwUxHeOW5Q3absD7U65KLiRqU eJQM9v/g9+ZOA== Date: Thu, 31 Oct 2024 16:14:41 -0700 Subject: [PATCH 23/41] xfs: use kvmalloc for xattr buffers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566269.962545.16846087285452039344.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:14:57 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: 13858449 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 1A9671D0E0D for ; Thu, 31 Oct 2024 23:14:57 +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=1730416498; cv=none; b=BArtUxqtouCYZWoQMmO41gPD3KI45hisKKsMBUuozwHQ3ztpBp0rVa1QBsAvGAHvIeXjZI1y8DJFAtwECx5+0Hjh66aKT6Vq2dTog/DFT3dIEU8jvHA7ZOtJHdZADGa8T2U73nJMT8PRFwtlvWjsAfMzrnO5XNyBaS2YegPpdvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416498; c=relaxed/simple; bh=17HU7dAC0sPq6dTovl+2c7ds9+4XBTYKqbTpAuKBSuI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ObvWRzR+ZJh0b88LK4WHWmKLhKrNGdCwTThYniyJKKKW9C01eYXMsAHDefHCFC9UAQ7H1HKpwgiYF5dahqmRIPhSeJs7cGD9BxhuAeZosstAgWTi+NCicOH+CoP/j2SZyr1YxiMmHIegtk/+cBT1PQPNbbfNIc+1HA+ZkvAcdVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F9jnrK+s; 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="F9jnrK+s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84FACC4CEC3; Thu, 31 Oct 2024 23:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416497; bh=17HU7dAC0sPq6dTovl+2c7ds9+4XBTYKqbTpAuKBSuI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=F9jnrK+sh+nNQ7CWzxrZY7dJfazZiq52eysPnR+IGJFWyUBC7hcf4GqrkatMTEVEA 5GLEQ/KJPZ0C7yIbgIxeHhQ/1CVZ57/8/SnGP/eeGBAq9Sps881LTY9Zo1mF8qXFg+ 1SQImF1VnXJo7BnUnS/nS+byCGYThfrXstqXM1DLyWAZTf5DGJHMh2FBaltjT2iuwl 2FElOhbL0FFMk/L/0jDHnX9wnyt35NsOpWkVv+r9ID8DmKYPKJbXATnVAJpAi9/dML 5ZVL1hv1mnAV2QaY3wBuV7RQoQfLMHr3973Va9dzCm7b3bGTWS3KnpVbJBf5OVq66f WoQ7Gtju94eUQ== Date: Thu, 31 Oct 2024 16:14:57 -0700 Subject: [PATCH 24/41] xfs: remove unnecessary check From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566284.962545.2375464901774938397.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:15:12 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: 13858450 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 A48091C2DB8 for ; Thu, 31 Oct 2024 23:15:13 +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=1730416513; cv=none; b=LKO4FN2TWIHNYad0VYY1qCOjDngZwc1Qfry247UPUSL9M47PPUyXE0YGDuIhmjLUQhcOVLHEEMdsKpZB2R8yFgolSOtkGoiPAtmYN+P34pklle22/EDXZ/FEu9io7F1l4sp94+CsCVJgQwSPVfW+xHDf8KvxnMWRHCoRoJvPpvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416513; 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=nVanDHrc8ktGJV37nzPFeJW4hl2xi3qxvHSdgnY0QFyUEAAUSp2a1vl0ak5uFYC1ZYfEhu3d8PbnwX5okXGUq50N9u41AdEHIusr28updSrpCVqOkUsD1JOPGx+NrbpenxpPY4WEnLXCi0TGJO8+4Efs6sBOPtqzTzFeE10B1nc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sAcXvQHd; 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="sAcXvQHd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24F02C4CEC3; Thu, 31 Oct 2024 23:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416513; bh=AMqM1j5GaO/aiseja1ns/LzFZ/uFcNUULdpBuFYEq/c=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sAcXvQHdH8ZlsojvBhshuqHNGk9JCogVooG//hwWnp+Qm88L8habYvZJbvXHnZbdI E8xPSmUMPhK+fRxmm04jP6Xb3LINFGLsIyvpC+0dJceLGKLjfJLLP+eA2UVHHDMJBM 5VaHbIcD5sE/n2mRfv8hnafErjAs5Jb1FT+TvX8nfxg8uf9IfIi6d2xfkQ5sleNmym uTB+f88ER+E9LYrY7ObfGSVhlFb4xgxdARBPjTddc9Vextduskypz4dUiqwWzD+yuH oaLXXM9m5EYk3PpuyyihpIUTeo62SogWUorkbwiBCsj2OXx/qNL3t/ZIacWwnkYQ+V dp1Zy6bBdkyfQ== Date: Thu, 31 Oct 2024 16:15:12 -0700 Subject: [PATCH 25/41] xfs: use kfree_rcu_mightsleep to free the perag structures From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566299.962545.8979393701897603900.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:15:28 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: 13858451 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 3FB091E5718 for ; Thu, 31 Oct 2024 23:15:28 +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=1730416529; cv=none; b=u9Y2dFmILJHUXrm8vepuaBVDkz/De2DLYoYhG68RqfFzvQk95HX4Vvfz2RJRqX1LDl+Q+yeyyQLnwhdJgj1ZZpY47UuxweTiskKY1QmJaR2guV9WpRLOyqYxBWs2BFOfVKI45tzn+FL3XyGY2Zj6IAxckNfISNmG5QNzSKEmks8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416529; c=relaxed/simple; bh=Qmn9OrxK4wzDuVTLItqmshC7ZRAaMO3p3BfMEhMTcD0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nvaMLt7/Pkg6rCyo7ARPp3wlswpjwah3StuKv4jeLUM/AJD5xv9dT745weFVLAvSoXJfTFCqJIyKKOOB2pISy/a7Bc7ACzz6J/yEtKxJTLy/5pTWmhbX+sTgOElhIYRBFpfMNNNbqGwxKDFV+Xr5+Q35RtKULm/uOmc6p8L7+8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g46R6MpG; 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="g46R6MpG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA373C4CED1; Thu, 31 Oct 2024 23:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416528; bh=Qmn9OrxK4wzDuVTLItqmshC7ZRAaMO3p3BfMEhMTcD0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=g46R6MpGvH8Dnnsu38vfzUDQ1W6DPOQyIwJMGLlcV5eUdTPHaZbD0LVF3dMK4GxqC AwwW5hay1U+FUlmGkEfSwEh9Hs/iQ2q1sFLrcVPSE2lWSRsna7XHVogMxxGq8oQ9N8 OgsoGU278z3QS22A5ZBYG9iCSJ6DO40e88BeEUm6q3j4nQlKs1wTIe21hbBMe1vHu2 SrhQZcWj+jY2l48hSHx1mZV0OJ2MusxfgwjQDmly11LktAl4yvaDk2M7Uc0Kj9CX31 GTRWzfO45qcF+5sExX45dzXja9oWv0q0sKTUvGxZxQ5eVWZXLgubbNXvF88WB67exE jHMav1TiL6fcg== Date: Thu, 31 Oct 2024 16:15:28 -0700 Subject: [PATCH 26/41] xfs: move the tagged perag lookup helpers to xfs_icache.c From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566314.962545.11718050456087618636.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:15:43 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: 13858452 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 03FDAECF for ; Thu, 31 Oct 2024 23:15:44 +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=1730416545; cv=none; b=RgUFbuymPIxw/OIcx27W1qGHQBDKsQqR5wzr1mdSyzh3mX87OepwK994RQVAnGCqISRVZe55MVBhkClLnj0BSOOHnRFGmqbchphNMsVqmuaBVE8TyRg/qS3CB65Yp97mFEZ/7IlTUvTPjfEUHImVq0l3fxB+VIqAtCVFgp9qO+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416545; c=relaxed/simple; bh=Z5PTxTzZvT5FHq50HAYjqs84TOGr+Llh5TenJ5GDO48=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kn9LnPUTXudX8YeooJGUm7KFGCKU1RFdXnYyNgaA380RQu/XiD5RiYveh6Y9s+qa90N1Axhc/g6zVDc5QbZ6fm59geufscbXaoH1jnYB1sZmfKiXId9MUDV5d3qE+3bBQXvMRF5AmjXtBDFJdiiNJPi1jgdNax3GBGMZIy3MOgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgIVKL2d; 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="XgIVKL2d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F42FC4CEC3; Thu, 31 Oct 2024 23:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416544; bh=Z5PTxTzZvT5FHq50HAYjqs84TOGr+Llh5TenJ5GDO48=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XgIVKL2dZSHzGLJsWFBqCk26LiUwpoMIvekSO695YVNdGu4kpwSKciUHHAY1GKGhx /UFNvFlY6pK5+Vw+y275y9u/Qs+tOI6i+J1rw9wG5zOsr3hfsYjVHafuiwiT+p9l2C Hh6oIpliF0p4C6rtbvptrF7yHufP7g/7WxSlQveTvtz7s9dSWABq38Na4NoRxcr2cA 28CVoJ1K6RIVZn0p5MQ4EHo5U/OqiujfjJjb5ZsbSjKWBvcxiH9GxXALV+HLY/eVly NVhH9snguQ0Vr8++BjTuVz3m0FAhuWRJQyhp0YaKl7Ul/ybexaDMMvQWUswh+j65mW Dsb1Gfki04pHA== Date: Thu, 31 Oct 2024 16:15:43 -0700 Subject: [PATCH 27/41] xfs: convert perag lookup to xarray From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566330.962545.17602652106829132814.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:15:59 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: 13858453 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 69E9C1CDA30 for ; Thu, 31 Oct 2024 23:16:00 +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=1730416560; cv=none; b=jJVXdEhlAqN2Q5DB2q1ehU9OziUZIT/HWCKzbWKbXqwQ1u+SKYdR8qpjz46Iu8Q3n3Jzt4bvC96ycSojBo48/dC1bQGUGffqjk6/liBWj+4d05mHBmgSImJbZY3WutXEJmEnRwhQTlHr2ho2can7H9D3bpdrsRX1pp8B+w21x7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416560; c=relaxed/simple; bh=lkGovIsttTsWnI5XxwaiAlstodfHJn2lT63mm52PJu0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l3s2fGOhPqJsCR4MlkfrRSM1WMmrqY+1y5RBcNqf2fGNORN/r1H926l/Qax3DAKnypuhzFaxIeB6PBAA047flKMp1DLL4oxuVoIMV0pBILTbNGjGsKvgPJ5W9eyfWC0rIdBS8cWvAa/UOndEEGgonO98qkVyPZHbXZlMWw7+wOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ExVC1KN5; 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="ExVC1KN5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02431C4CEC3; Thu, 31 Oct 2024 23:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416560; bh=lkGovIsttTsWnI5XxwaiAlstodfHJn2lT63mm52PJu0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ExVC1KN5aur+gTjn84j51y+2QDGyhflIfc2sEd2UPP/Tz+L5Y77jbxEjfykAFqM+X SXaOVHHCAGjIVKSt2/z6KYBy66U9Bmk5G0yD90VaVtRSIncQNtPY9cMhvph62rxdRr PIYspNg0fxrk7Z7q7vAMUu4DWJheKaaz95featTejzjt5LkU0HJynneVWp+0Xg6MC/ VGObfNWx52X5APdWRwRI5AvMk2igWuPx5TDYALP3LDxLyFZrWrQHV8noTSYhNVKaTE LqvoMXTsxKO4Y4b+pbT7RcuFmQ/+8KmVWytqo8Nf5GT+8nhNfQiiBijVeHSdvMi/v/ lDZl2+uepQx0w== Date: Thu, 31 Oct 2024 16:15:59 -0700 Subject: [PATCH 28/41] xfs: ensure st_blocks never goes to zero during COW writes From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566344.962545.6846033905640077089.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:16:15 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: 13858454 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 12F5E1D0DE6 for ; Thu, 31 Oct 2024 23:16:15 +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=1730416576; cv=none; b=jgbLfipulst1GXPp0bJxvZVpfm8MEHR9MYnaR8zEnsyh2jlmvex5GIKhPcsGYMkrkxUmtLaiW5RBkrvT4mooy4t+GNhTcoEX3Rq+LNYCrAjAJ+FR4HMO134cFgdTyxYQGFOKJ0L65ASRjrMGyasr7lQq0R5nqjW+/XSNlKfiW1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416576; c=relaxed/simple; bh=9fpdVgVmxelGa+5Taqc1vU3DXk1nGqO28B8J1NmTmU0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XsvmBl+GU/YoYdGTJ6YOrBmEaqp6Vpt6SIVqSxyK8QUxuCSh6ER1h0gdMk9Ko1s/3R2MS6DCh6HAHZbejcnJJgPdSGjRAN/oBj+bSjvnOpjlRXCox/tAMVffOn4rcZSRSvw7i6jWXdJ3qi0em3GpnTOvwzwdnvlWiT+VF+2jElw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g42Z3rQn; 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="g42Z3rQn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99043C4CEC3; Thu, 31 Oct 2024 23:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416575; bh=9fpdVgVmxelGa+5Taqc1vU3DXk1nGqO28B8J1NmTmU0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=g42Z3rQnkpydWHkDJcIoPi2LSGTYogJtHXqQK2Zo7XW6cuqystXCG31cM+tOhXCcr cQcU9H3dHFQ5VvXlG02cW+0f2Wth6nWm0NZdjfPiINyFZlbeYvhsTOQrSgnGUKthql Me+dA0N/HmZLJ2WZVwAa13R/eDBXz9X2JASA87gtYEDogikLIG4y2PrIyumgYS3RSq mV+K+4P/BumccRzTHHNksn3YI/ZOeljXCdkKHw+IFf0u/O091/4ssqTVZ9MYJaQze8 fNPMUesi0DX/gEWjxUh4NRrxunZtH31v5oXPEPvXSrFhXHEi9WLxBvwPK+5r678NDk qRiBp5B0hCdOA== Date: Thu, 31 Oct 2024 16:16:15 -0700 Subject: [PATCH 29/41] xfs: enable block size larger than page size support From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566360.962545.12986251378292080145.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:16:30 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: 13858455 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 71CCB197A81 for ; Thu, 31 Oct 2024 23:16:31 +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=1730416591; cv=none; b=YDOM6wtcjTdTcxC2Q9RTx4wY0Z0TKvbPM8K0bRrLCbSTamHi/N2ZyMxJjioRaB6f6k1XapO6QmHNbKSggXFbZbHJkVE8HQGB6ZI32lKu7NVBEODoa/AikjdFojLE3oSQxAtENAHfJlsFw6Nfky8q8PHi/eCX62ix4AcWzUBhnRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416591; 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=Vk0g6jf2fkn2XPXzrtSnEeT5x12EDlXMCI4v2azigrip/GtT30JRIKFKbIE4Np4ihMyCuCF9dVemFqcYpTRRGXInfVbHek0+NXaUQXBHkE3Rj9afUwgJXvaU6Bp+9mMU+rcbaldkv7Fv1CuROXVrGpGh04qpH4+PgNUV8lBpstA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OSxhn8et; 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="OSxhn8et" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FE3FC4CEC3; Thu, 31 Oct 2024 23:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416591; bh=118/3KLdqtx9r1gFXye0oHE02j++kJbovvk0tJ/SVV4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OSxhn8etUNfWn67k1wDbfANDVdWSrRX0qSNIaNS1E4mGSyUwWtz4Uks39Upz3VvwS vnTSPyphNhNNAuURPSJc4AXah3MnzV7xTv8xBg1LZOtmhq1Hpjcahdk1j4lVSe3HD6 25XlqOWxUh2v2SqALeBgXncAUzDCpx0DSUXDkK5p+WHPMAV7oeFvV0gSY0JFZo5J0V wC4mT8XJf0qOAhLlNDTvtWIkjt3vDbNMNLWKC2wa1+/Vr+MiHVYF5nvTDPJB/F3xB5 2H/qjMq6WL6VbGToyFqsef8MxDCwkCjVX6qc5ekLWUbyFhqEydB6ndNxhDxz9WE/dZ +oPVT1FPRI1RQ== Date: Thu, 31 Oct 2024 16:16:30 -0700 Subject: [PATCH 30/41] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566375.962545.14418281308095251932.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:16:46 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: 13858456 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 62CE3197A81 for ; Thu, 31 Oct 2024 23:16:47 +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=1730416607; cv=none; b=IE61hUqgbxyYHnYVgMsurBip5OWYy4f7LhTdDDhrZ5gjdizif7uEjS1hO8tOrlXK/LM2YpX/zE+NwI6r/rPcoLcNEoXyDMh7cSLe2WXv5mjCPzQ8fujtr0Zx3Z74Ya3CT1LWRwbOTxLtO64EpcaUXWYkWKVQkMyr2hDiKoUgoZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416607; c=relaxed/simple; bh=7dNQiJfyRSMyRqjETsUSLQcg+OCcblkIYpXKKxSVboQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hcYVjtT79EQaTzZbpNJwNImOyZM+jntKnocnS+/oxhMK+ppaCPopwTFawVdj3tzNFi+gklVOp8/LbV0qmeKWjDhuGe2CSrEaBWa1tO7eqUjOyLTRoQg7MYIP9T7/NqJwC/R2YDdCGth3kGOnfESeELlOhKt4aBSSvQOFfplG1V0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J4lqdmDF; 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="J4lqdmDF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E88B9C4CEC3; Thu, 31 Oct 2024 23:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416607; bh=7dNQiJfyRSMyRqjETsUSLQcg+OCcblkIYpXKKxSVboQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=J4lqdmDFj99QLZilmxkOLkxkMRQlLldRHhQ/tjHqMuYS8pTT6U3m03X+eFL2elh9P QZDt67BN4U65rF7aw825/+g+Ewk/hkQsBVBlh18DCv7Wb+oe5KBt7zEtXvwWjdyKkL 8w1nDmx+Q1u9cPnt5yrN/202tvhnQK0KWJ4s8ZhX489gZvtay2+v/Cb3GqPf7jhGqs 9HNhmNnclEobhMAaYR85jBJju0GK7n0PF7z0pOIvN8nfGyBiZzxsVQOwHcZZeKSyGc +o7nWMyW+19cPg76niyXCX5ib1Ts1LEqJ61cLusmrrGDAphH7NoYHzoZ9n5+mmzknC gt1LbJnorZC/g== Date: Thu, 31 Oct 2024 16:16:46 -0700 Subject: [PATCH 31/41] xfs: return bool from xfs_attr3_leaf_add From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566391.962545.10263576370884991001.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:17:02 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: 13858457 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 B2701197A81 for ; Thu, 31 Oct 2024 23:17:02 +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=1730416622; cv=none; b=UIzBAwuhfH03o9QNio3Ekc8PXPstJqPmO/bedaT6Jp1fkkOlbOicVH0mGXA8eGE5RRO9x0PifmVHPBJsPXaFOkRP4O+Ej27CEA0DpLpNzHsirlbxK7i+aEhfgRR4Xdi6EcwsBZ997xPG4mfAYXVkUajW2Qk/8yE8EEhs2scMPfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416622; c=relaxed/simple; bh=QjOsC+90r0vhbovJLIgdY+DUlCwrCsbx6nB5mqkFRV4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sFDZKQ4b2A2U76xpz3J5BrQ25YDtvFtNe6iflrKQjfswJK6EcRQqasAHun972H7HFxY8NUKOF2StxpAfasYN+duBoN/VQ/Hc1hUjRV1vEdHpUiJPhp4+P0Z5O3moFJfZEG0w5S2roZX/4669a2nGRcyfesNM7RuEGRojSjzhevo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bPuPPA0w; 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="bPuPPA0w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B30DC4CECF; Thu, 31 Oct 2024 23:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416622; bh=QjOsC+90r0vhbovJLIgdY+DUlCwrCsbx6nB5mqkFRV4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bPuPPA0wqpoTxxlhlJcujXwG0KCFxRBgKItTyPNBHSTFKBTuwF/YcldOG+VDVaZs6 RPjT+7oCf+LOu1bfGAhmglv+uyv01EYhm/Ybl4rnB3Ga2A5HDd6Z0vMeCSZ24r2vVf 3/SHr0hx7IeXC4TgLrZiS5lS9omIKyDCJ9gvmo5N9hk/IA7J6/AXpZeVmHb9UdQ89W 2t721pAqoPPBxqKrJcdHqDgfLIgG0kufkOfYGcfwQgUwvxcKOCW2+27NEf/kAbm/zm l7TgAXTu4+aiFCYKj+hVye1bf6zUAmmmvoi1OyU5zer2oj6+Yuq8fvpAmOBzLfbpsn Z/kluc9XA50PA== Date: Thu, 31 Oct 2024 16:17:02 -0700 Subject: [PATCH 32/41] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566406.962545.8342598520984515549.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:17:17 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: 13858458 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 541F5197A81 for ; Thu, 31 Oct 2024 23:17:18 +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=1730416638; cv=none; b=QH9l3JFnbY8bXXXSAQI447VO702opu0/NXB4ozKstNIBwuRq8v1QXPN1NP4u/KOLnreuEbcjyI8K8R/2if8Po9g7IVO3t5e8ryRoLieypMVEbvwrdDxRyA1g7sPmThF1C5fEDjmhScueXztcEk6Gw/78tGrqojKcE/fp5Ba/7bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416638; c=relaxed/simple; bh=CX0zA8QDeUJtuMzKPiMQjrlq4wtusGGSrqsuxGS/RQE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P/0ZESTR7/SRPH7auvsMSh04saP2mEVIWdPnqwDe7MYk1ZZSm12s6aWmNAtCZ9F96t6MzANfirkNlBQYfAASX0Wm/FJDxS6LOqNWlINvfzLEHNYsWMdqQJ65iaoAAGqmHr+85OhjhNYfuKstkvD7/AdntFpY0H8sgC7VcSI8zTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tiAbyQnk; 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="tiAbyQnk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F11FC4CEC3; Thu, 31 Oct 2024 23:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416638; bh=CX0zA8QDeUJtuMzKPiMQjrlq4wtusGGSrqsuxGS/RQE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tiAbyQnkDA31mDjiKncknHp8GH4xhIB7z/TLdRrnHm8Do4wXkp+XFB+SxxU2/jJJu hF0rr8sUF0y2GNfrO4bSvHiQN3ftFO8s7Hca5oZek4LsGJyi9/cTvDJLhoEJevtxLO FxHA7I3UGy9+K0/rVOy84HOyc3D2V3VjGj+G0YNPZA0Q3pn5acUWgDAmQkHzFpfPS0 Uisdaoik8LYdBWdeXt4oeCkEh34uXkswbxDrW4ntVmWXu8p18xglJuwz4DgZz7KDPn kWzxsfOlBw9bBwe0S9de9oHr5uSXVHTqBSxx8ye02+a0ZL1zX/Nq/tXENz4Dube3Ux 1D7jwdAqC+aWA== Date: Thu, 31 Oct 2024 16:17:17 -0700 Subject: [PATCH 33/41] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566421.962545.10997599089245855400.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:17:33 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: 13858459 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 E9E62197A81 for ; Thu, 31 Oct 2024 23:17:33 +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=1730416654; cv=none; b=e8f9azeaDEo/Q+WPQB9W2rgZcnYxJbxPk5U/vJWk/at+bRN1lLJi8VyZ7nbm2ly8XZ8VSsvMerV/3u0Sxg8jGvkXCewo6xiEZAChh5hWZZLatz2q543nQ9xc/1D6kaIcMHdderupzt4Qh+aS1SXn9OswAdzWLZSVBND/rhffW6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416654; c=relaxed/simple; bh=i6gmFKAHib8GzGEajsTQd9oJCZtEooSS4SIJarCB+vQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=egBylTYzapziGaTcPCk4iUGYpTT9LFhknpCZ5y/bgV1PohzRZFKnoplH7ATj5VHwG6GY1Xssx3g2ynaENbX8X5/U1tSWXBG37LJlN4DSxwM+55Bd2Jh6lB6v1LJOQMFWQBCTmAJJSXpXQwQ9mCz0a0WoukVmBj951ptx6U5Ysn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=En4aXGEH; 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="En4aXGEH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5706C4CECF; Thu, 31 Oct 2024 23:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416653; bh=i6gmFKAHib8GzGEajsTQd9oJCZtEooSS4SIJarCB+vQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=En4aXGEHwb4X+4FHCHOFe6UaaD2k5Y1mBe87IBiEgmGfdVkibzcTHv1PJ0XTE2xui cROLN9w2QLYQ/y4UlrMd8dRWcRQVblGxogHU06I3AK1ZB3/0COkD6bO5SduTKaT3xi 3frlZ21/czlOWohoAQJdw/iBZuQ64fgZZx56+BdaDDwEwdUwi23Y7zcDl7ZOwQ1/dS 3CmzLNLpLZWSSpb7s1v4WR+0JvS5lsJoxVaqON8Yo5lFtptjgrb47nc7NhkqDfzY4N 9DjZpNLfzMDU3wQMSny73751EewuGZE11LL8MrDDBNPnHmJoQhX2pgcJKWq76jaRcz b9dza3AlsaelA== Date: Thu, 31 Oct 2024 16:17:33 -0700 Subject: [PATCH 34/41] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566437.962545.12425668382329285908.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:17:48 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: 13858461 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 8FD6E1E2007 for ; Thu, 31 Oct 2024 23:17:49 +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=1730416669; cv=none; b=Db4keQCw4ma4l6X0QoPcbfgxXJWx1WmrtetH13iHAhNDMdSRGLy+kwqj3VR2w8ZFaGwNwi/PZQY6xF200EI6kzFinioF6Z7fP+gi4Ww8mdH9L7Fp+K6VYvQaQrZTpPJdGUXu2ucbfHKazRp6Kb7B21bfImhYaOAp8GOLrXecsx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416669; c=relaxed/simple; bh=boiVlnQxhES0BwY8QAKEQCXjPoKUQWcAkStRUX+XxmE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LX4jT2mLn175TSb8AwrnF7g0GCfC8g5kk6OuNe+SaVYmx2BbYvvSTXRObPe1fqw5tFtv6IeR4gSCtcajDU2nk6FGynwxhSLKSAUkzdVpdWTKBjjaKT+FGnlHT1DD+q13K3RGuz3Ug8wOBrmDHuFkr5ML3k3Dlhi2Q0kVCHF7zJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WL+Pqo2x; 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="WL+Pqo2x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68009C4CEC3; Thu, 31 Oct 2024 23:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416669; bh=boiVlnQxhES0BwY8QAKEQCXjPoKUQWcAkStRUX+XxmE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WL+Pqo2x0gQwmSFVk4G+goXjTPms83W2asgk62+2POV7BNKZDWu4pr0yWUEHXxuLG QzUWdYOZ+3nS8al1bjYY4xTvBeQTNL6RaAL7onZIpRXKSHOBbmGMzr+X4332w8RU0Z aBD3zZtNTyZRioSeh/+9YZNpPTun/sI4ePHiwkDkMW1b/ZFKaXGDDylfMm0YZ2t9aL Ox1W6ozXtT9qvqJJvXYdj/kK9NwSm8xt5Hzy4xBYhACcxHhz/ph1dTXpD7zlL0fmdo M20y+AMgmnxQWLL7LjR8X8LCQxjejpqSUDwFAKUU9kHFg1bE+1vP/7CgD4fyZuhrBQ D/1X6c9rwGIbw== Date: Thu, 31 Oct 2024 16:17:48 -0700 Subject: [PATCH 35/41] xfs: don't ifdef around the exact minlen allocations From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566451.962545.2404664233498981452.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:18:04 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: 13858462 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 79B231E1A37 for ; Thu, 31 Oct 2024 23:18:05 +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=1730416685; cv=none; b=Ki4Cuz6Xv2RMzOT8LydNoiUDCUoh4vIcIcZpW0aOoHU9cJEuGlryt0XlkMLN8LCoU5d3sO0/Ploj6l/dZb+G9zCjrpF+LV1ADlxyEyW6gkAWiYWSeiJcOD8qhtrJvnVdBgOlUmWSW9VkrqWcilnAFUVQcf2dGrrgKmd0Dt/9444= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416685; c=relaxed/simple; bh=gljjXFH81UV8Kku1UmvWTGlfcPv4duH1tPlozJDvJC4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kzhoDYYK007+GXnqKmWYTahQMKaIK3f1rWNcquXblDmtsMotRX0Kwoswj0MjuXobcokIA56Tg99i0fD540LMqe6AokelugQZB0yWA60hJ5vs12wYNYVOGUNjo6PcalW6FRROIcA41axCQCcYcdzMzBgCl/euzlRNg9jjdqtWMWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ciDgH8UK; 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="ciDgH8UK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C19BC4CEC3; Thu, 31 Oct 2024 23:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416685; bh=gljjXFH81UV8Kku1UmvWTGlfcPv4duH1tPlozJDvJC4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ciDgH8UKDJ6Qgp0Vl5psVvIXFoP0ozJX1hYZRhlqMinlOy+2Vg8TB/g6YHe2sYtVy bzcK97uDz4fwdhWAM2l8cC9INqEGo8SWjKtwgXLAzZgRaE9EgtvBWxbPuUJUXaxdfe EqXES/3EqNQia7Sn2O9JZGWhpqdJfi/6bhYGx79ULl6i9l0GIC7y0W0Iqer4WbWck4 o9K6eYL3qPt03udhSlJhjCH7ccGPEAXTaWy9ro4JB/zwCa2S8guqiq/+8IKfmrVQOk pMDyNOxBgLsS3BugQuuQjs4QUGx+WDvMyON4uRipwlhSKXztbjUQNpM51WNGwGuZIx 2sxWWaLSc9NpA== Date: Thu, 31 Oct 2024 16:18:04 -0700 Subject: [PATCH 36/41] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566467.962545.14625825074524844035.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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 Thu Oct 31 23:18:20 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: 13858463 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 D13371E231B for ; Thu, 31 Oct 2024 23:18:20 +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=1730416700; cv=none; b=DcHEt6uRUssF+BUHaqi0Hgu9y9QuIuo1tgJfgbaf63krnls3W5ecQ3tbR1oLBZiHOCmXTsoFVUjEG7gl7ZYLl3AHChxUbMkF2zB3JgItlxU1WNk1elJo+kydrsgtQh9qEDHYb4E6QNmHfITHWlyQNj1LL39XYqe0xIvYirgh35s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416700; c=relaxed/simple; bh=6v9xPp+HF59XYUVGsO+s6XMsOPw8OoyuO9rkykcOyWM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cxJLZuBqpHi4YOBearALXnFwDKwylrscPu9SvYBw7uk7+n5QLgcNBcOgw1zRU5K0ZHzoKgUmJ2lwPItWv7zFWB5KvJuF50eOqunBnwqCeOXPBGP10N4b4RTGaC+5ZYhHOZuaKhqjvEGuiKihqb+V0jeHfxBvu2BamVI2gYoRc/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fjFTkTP0; 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="fjFTkTP0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7C0DC4CEC3; Thu, 31 Oct 2024 23:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416700; bh=6v9xPp+HF59XYUVGsO+s6XMsOPw8OoyuO9rkykcOyWM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fjFTkTP06UUnDf/nXoBJdOWFamRhjphHfPTYtweF+crak3fjYB0mn52dhTVEpDqUl Fd1bDrttsliCcfBOImeN4U+DmMcXFH9eNiSgH8yW4nFIc4idq0utlLkKDzBPjc0t2g yOB3VsOcuh5UwfsuGeotUMqK5SG4QoO0kvADwzfNgeQoP7VNiAf3Siue5/hyt6jfDH uglcuDW9mBnx67/LXZr8alN2m50KppPc6FyyvIRMxytgYMKoeI6WUyxN4K5EmqBZi4 aneTySJmir0aYNrViNFK6E0Uczlg0Obcu7Akm+xeAz72D6wbANG6/nmSuvMsyp5ZHp NhC5uatZIlIkg== Date: Thu, 31 Oct 2024 16:18:20 -0700 Subject: [PATCH 37/41] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566481.962545.4521489448593443680.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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); } /* From patchwork Thu Oct 31 23:18:35 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: 13858464 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 B236D1DFD81 for ; Thu, 31 Oct 2024 23:18:36 +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=1730416716; cv=none; b=QCYo1BK2t6MTQ99uO5rNjboPcbbyude4HtrJAEKba2KreLgDUEV9IXOthDuaXVaJEtGEDrJ8CvT0Mr96vU31km27piu0+2UnGHO3xb/Xk53SNlGCVGd7GJ0A/efSSy8dmKUujLlGEOWKbRF9WnaGMhiPHk0H3H1Abk4GWZ7OR0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416716; c=relaxed/simple; bh=tGQcT9es3TRziV+P7+TXZrQR+seYjHdeyRpio1O2os0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mdl4iTkPE5aPzvyyJY12pLNLQ9Qrcds7r+IAkyWmSzzfF1Hkgh3RKvasuOcChBiJAGXR2mlLuJzrzeoaHjWvKvy/yiHbXTugpFdiyZf/RfbOmLYlS1jiEmtY5+vdckXswMD+t+qCShKi5oMnFGZwmVo/wDitbqCKUXu9kbg2uJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QkHrLN7b; 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="QkHrLN7b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CE0BC4CEC3; Thu, 31 Oct 2024 23:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416716; bh=tGQcT9es3TRziV+P7+TXZrQR+seYjHdeyRpio1O2os0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QkHrLN7bNDFXVkJzAr76I4Z2/+4oi3uAyOaDeEVDiV3/Spi2EwxVOhObn56zvByJx IGrjN3Gbg+l+Pog26yaJiSY3kUv07UUOGhLSTd6dkC/KpSQmUIUKlwrV3sZvoxIK1N z4gpg3ypWHvEXBhNrEU42RylfnTg3GcwpxJ4frCcNkDR7JaZ+F44P96X3qBMgi1BVc d8lMuPkLZ23b4C1jWGr1nr9xMKliA2W8WIKizhgW5LRMIYDfF1vfCtzcj1Y0FHNQTy iExIaHgrC4INQY4FwL+ZaaHt5W3m9hLDupg363eGrBeGJn1CY15qPiyu/RHDQOCVov k+Rq6mMYvBLxg== Date: Thu, 31 Oct 2024 16:18:35 -0700 Subject: [PATCH 38/41] xfs: pass the exact range to initialize to xfs_initialize_perag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566497.962545.4939568317650293032.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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: 82742f8c3f1a93787a05a00aca50c2a565231f84 Currently only the new agcount is passed to xfs_initialize_perag, which requires lookups of existing AGs to skip them and complicates error handling. Also pass the previous agcount so that the range that xfs_initialize_perag operates on is exactly defined. That way the extra lookups can be avoided, and error handling can clean up the exact range from the old count to the last added perag structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 28 ++++++---------------------- libxfs/xfs_ag.h | 5 +++-- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 516c76790cc0d8..3bbfefe5e46935 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -294,27 +294,16 @@ xfs_free_unused_perag_range( int xfs_initialize_perag( struct xfs_mount *mp, - xfs_agnumber_t agcount, + xfs_agnumber_t old_agcount, + xfs_agnumber_t new_agcount, xfs_rfsblock_t dblocks, xfs_agnumber_t *maxagi) { struct xfs_perag *pag; xfs_agnumber_t index; - xfs_agnumber_t first_initialised = NULLAGNUMBER; int error; - /* - * Walk the current per-ag tree so we don't try to initialise AGs - * that already exist (growfs case). Allocate and insert all the - * AGs we don't find ready for initialisation. - */ - for (index = 0; index < agcount; index++) { - pag = xfs_perag_get(mp, index); - if (pag) { - xfs_perag_put(pag); - continue; - } - + for (index = old_agcount; index < new_agcount; index++) { pag = kzalloc(sizeof(*pag), GFP_KERNEL | __GFP_RETRY_MAYFAIL); if (!pag) { error = -ENOMEM; @@ -351,21 +340,17 @@ xfs_initialize_perag( /* Active ref owned by mount indicates AG is online. */ atomic_set(&pag->pag_active_ref, 1); - /* first new pag is fully initialized */ - if (first_initialised == NULLAGNUMBER) - first_initialised = index; - /* * Pre-calculated geometry */ - pag->block_count = __xfs_ag_block_count(mp, index, agcount, + pag->block_count = __xfs_ag_block_count(mp, index, new_agcount, dblocks); pag->min_block = XFS_AGFL_BLOCK(mp); __xfs_agino_range(mp, pag->block_count, &pag->agino_min, &pag->agino_max); } - index = xfs_set_inode_alloc(mp, agcount); + index = xfs_set_inode_alloc(mp, new_agcount); if (maxagi) *maxagi = index; @@ -379,8 +364,7 @@ xfs_initialize_perag( out_free_pag: kfree(pag); out_unwind_new_pags: - /* unwind any prior newly initialized pags */ - xfs_free_unused_perag_range(mp, first_initialised, agcount); + xfs_free_unused_perag_range(mp, old_agcount, index); return error; } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index d9cccd093b60e0..69fc31e7b84728 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -146,8 +146,9 @@ __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart, xfs_agnumber_t agend); -int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount, - xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); +int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, + xfs_agnumber_t agcount, xfs_rfsblock_t dcount, + xfs_agnumber_t *maxagi); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); void xfs_free_perag(struct xfs_mount *mp); From patchwork Thu Oct 31 23:18:51 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: 13858465 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 731E91D0DE6 for ; Thu, 31 Oct 2024 23:18:52 +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=1730416732; cv=none; b=B12iESuxT7IhttKJ0o3WgxAh/O7NdjpmsEtC9IYnK4IxiMAHNZcgaxw9IwR5nfavrAbxfKR5YKl2zxYBBvoNZUnXD9nz0dGswfI1Abxc9lcXwOYISJv04uViFYYRoSZBqq7rOarZaPHYd8fMPQrYfO17n3UKgcL2wJ4FJbIrt8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416732; c=relaxed/simple; bh=6NroAplWALLEeAyjg48XYUwcYT3J15sjccejh+39Mt4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nFz0aeUEskCI9yXvGkP/+Vxt80OPEQWSx9uH6QgX2Ut69CJiC0pP0VYFUTerkBGFHQH+OQqFuKafbT+4x4OdVYrXY/eQDakF48WsnexdLF3ogMNdkGAQTEWwV0cLp97Rg4dmfytvfeCdFURTB3gMzuBQkprRuYDuzxNHEOYRZdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rst7vR67; 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="Rst7vR67" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFBC4C4CEC3; Thu, 31 Oct 2024 23:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416732; bh=6NroAplWALLEeAyjg48XYUwcYT3J15sjccejh+39Mt4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Rst7vR67Kly+/6Ahn3iMTwFL3olX+//VcBBgD7tgnDomo6lXtoJfYyg7lxPPiCLfm R+DotPF+tQqmHV18xLrx1+zkFz+eecGHrIusHQ0Q/nieGZw/BZyU0eihYKPHNOz3O5 rKRYa1uobhIguu5AywsbBFWbsfiWrTVH5RZ+tVk5XWRy1L9H6O7g0YRc2+aXzHntE+ xL3CDEZXUzksXANWlyQqL26/HS+lmCHtMXmIQb2HI9nF+BBEr34msddQK90WA3uKNv sEIgTif57Vn0EnxGuZTLYD+aRN3yNh/IO1E3ZRsgSJtVnFHLGh/ojEvx9uxOi0N4LE OMLb1kjLB7OeA== Date: Thu, 31 Oct 2024 16:18:51 -0700 Subject: [PATCH 39/41] xfs: merge the perag freeing helpers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566512.962545.11813970395122379028.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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: aa67ec6a25617e36eba4fb28a88159f500a6cac6 There is no good reason to have two different routines for freeing perag structures for the unmount and error cases. Add two arguments to specify the range of AGs to free to xfs_free_perag, and use that to replace xfs_free_unused_perag_range. The addition RCU grace period for the error case is harmless, and the extra check for the AG to actually exist is not required now that the callers pass the exact known allocated range. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- libxfs/init.c | 6 +++--- libxfs/libxfs_api_defs.h | 2 +- libxfs/xfs_ag.c | 40 ++++++++++------------------------------ libxfs/xfs_ag.h | 5 ++--- 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 733ab3f1abc557..483cd99546052f 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -789,8 +789,8 @@ libxfs_mount( libxfs_buf_relse(bp); } - error = libxfs_initialize_perag(mp, sbp->sb_agcount, sbp->sb_dblocks, - &mp->m_maxagi); + error = libxfs_initialize_perag(mp, 0, sbp->sb_agcount, + sbp->sb_dblocks, &mp->m_maxagi); if (error) { fprintf(stderr, _("%s: perag init failed\n"), progname); @@ -930,7 +930,7 @@ libxfs_umount( * first place. */ if (xfs_is_perag_data_loaded(mp)) - libxfs_free_perag(mp); + libxfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount); xfs_da_unmount(mp); diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index a4173e5f7a595c..b9986a00681c1e 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -166,7 +166,7 @@ #define xfs_finobt_init_cursor libxfs_finobt_init_cursor #define xfs_free_extent libxfs_free_extent #define xfs_free_extent_later libxfs_free_extent_later -#define xfs_free_perag libxfs_free_perag +#define xfs_free_perag_range libxfs_free_perag_range #define xfs_fs_geometry libxfs_fs_geometry #define xfs_get_initial_prid libxfs_get_initial_prid #define xfs_highbit32 libxfs_highbit32 diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 3bbfefe5e46935..a9993215bf9a30 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -183,17 +183,20 @@ xfs_initialize_perag_data( } /* - * Free up the per-ag resources associated with the mount structure. + * Free up the per-ag resources within the specified AG range. */ void -xfs_free_perag( - struct xfs_mount *mp) +xfs_free_perag_range( + struct xfs_mount *mp, + xfs_agnumber_t first_agno, + xfs_agnumber_t end_agno) + { - struct xfs_perag *pag; xfs_agnumber_t agno; - for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { - pag = xa_erase(&mp->m_perags, agno); + for (agno = first_agno; agno < end_agno; agno++) { + struct xfs_perag *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); @@ -268,29 +271,6 @@ xfs_agino_range( return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last); } -/* - * Free perag within the specified AG range, it is only used to free unused - * perags under the error handling path. - */ -void -xfs_free_unused_perag_range( - struct xfs_mount *mp, - xfs_agnumber_t agstart, - xfs_agnumber_t agend) -{ - struct xfs_perag *pag; - xfs_agnumber_t index; - - for (index = agstart; index < agend; index++) { - pag = xa_erase(&mp->m_perags, index); - if (!pag) - break; - xfs_buf_cache_destroy(&pag->pag_bcache); - xfs_defer_drain_free(&pag->pag_intents_drain); - kfree(pag); - } -} - int xfs_initialize_perag( struct xfs_mount *mp, @@ -364,7 +344,7 @@ xfs_initialize_perag( out_free_pag: kfree(pag); out_unwind_new_pags: - xfs_free_unused_perag_range(mp, old_agcount, index); + xfs_free_perag_range(mp, old_agcount, index); return error; } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 69fc31e7b84728..6e68d6a3161a0f 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -144,13 +144,12 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA) __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES) __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) -void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart, - xfs_agnumber_t agend); int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, xfs_agnumber_t agcount, xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); +void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno, + xfs_agnumber_t end_agno); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); -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); From patchwork Thu Oct 31 23:19:07 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: 13858466 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 1D2271CF5FF for ; Thu, 31 Oct 2024 23:19:07 +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=1730416748; cv=none; b=PX1FydMsyiKCq1cDVoWN5r75/Usny6OUru0TtXMkDxem7xse0Hx0/2xNnpOWPb8MZImh4YEJEUcH2l7iud+9F4L6DD3RBMfzqFAyCOSkTkz8CtCJi0IojwaTdOenKmgZtR+9jwGS3uGO9SoMRbPbQEuGhp3fu/Wptgpd6d/9KUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416748; c=relaxed/simple; bh=RvN95GapFt+G4kAiKYmFIesJJeLx4msFOEJ3+nGhBXs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IeOoJloOC//QtHIBl4EGZ8bBJuGQ++/NMpAuKiehZU8PDPd6ZQNhlQv+JHkwlIuh1QoEsqNAw0a6Tm3vEq4mxKUjv3g7ptURM11rDfLTelNXnVs5EOQ9BeqGQJ7AagsfgDHrL73XDG0D3F1VRNe10xF3EF+JKZBKQvNJsX1XIlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vRgG18r5; 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="vRgG18r5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95485C4CEC3; Thu, 31 Oct 2024 23:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416747; bh=RvN95GapFt+G4kAiKYmFIesJJeLx4msFOEJ3+nGhBXs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vRgG18r5+qsrx54loJ/j1szOq+DvZ5Kbwiqp00CVKiWgrrc/6weFxk/Hz6UKWsvhL gOAIPxpEQIyEHtK3GVbebfGNSjpSZmIhUoLbo4/EW4uhm2FksoEbguvhzDnuaPIvGr 59Hgw9QvwtYyFQ+lFpENmRWwuiUqOEDkzDOywZiz1OPytSlDbmPWuUZtpH2Z/vGALC tsHyXnl95jjTCPjMjd3/NXOrB8wc2tf0bzHJxfzGQjpxTMT1U7xEyV/Bcpq7lXZ0XH +zHU98M/hBqZYN7v5HMMk4uXfQ1z2TdNp+2kB529MC98t/dSL3EHaKkQMmQw4uRy3M kGenqsFYLUMGQ== Date: Thu, 31 Oct 2024 16:19:07 -0700 Subject: [PATCH 40/41] xfs: don't use __GFP_RETRY_MAYFAIL in xfs_initialize_perag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566528.962545.12921537556581219315.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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: 069cf5e32b700f94c6ac60f6171662bdfb04f325 __GFP_RETRY_MAYFAIL increases the likelyhood of allocations to fail, which isn't really helpful during log recovery. Remove the flag and stick to the default GFP_KERNEL policies. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index a9993215bf9a30..a22c2be153a50c 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -284,7 +284,7 @@ xfs_initialize_perag( int error; for (index = old_agcount; index < new_agcount; index++) { - pag = kzalloc(sizeof(*pag), GFP_KERNEL | __GFP_RETRY_MAYFAIL); + pag = kzalloc(sizeof(*pag), GFP_KERNEL); if (!pag) { error = -ENOMEM; goto out_unwind_new_pags; From patchwork Thu Oct 31 23:19:22 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: 13858467 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 B1BFD1E2609 for ; Thu, 31 Oct 2024 23:19:23 +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=1730416763; cv=none; b=Z4aKJV0SPbM86MjDPgnx6TojfbjSairc/wvbj6KBR5KlQTkIvwKIAPcNhJVnUYmizbrUmbQAEz5fUXuOAE6Sm5m//JPT0Erg9ZQrdHI9JXobJzIkbAsum7WSmiSRw7hLtzqOAI3Qhi439JW9xhQ7xQ6NVcfD8cgjUZXZi2qEucc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730416763; c=relaxed/simple; bh=88T5JNLfeHZi+5wRLkmnq5IGQELdjVRGa8xlsIk32K4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pnvZfxZE54Wwu5M0poBuk/H1NWEIOL4RHZS4OCnUWJHNdJarYAuhX7KNKz87YG8ws3HZ4ytMbb0F9wxr8txKaN+q7NAfvm5yEKP4kwfekFqnWMNYz/5oOQ2rEVgALlDXAMJE00PfeyUrKr4JVFavh0EmqV1OXhNLKn5WQHcMU/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DCjessrL; 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="DCjessrL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42EDAC4CEC3; Thu, 31 Oct 2024 23:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730416763; bh=88T5JNLfeHZi+5wRLkmnq5IGQELdjVRGa8xlsIk32K4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DCjessrLnvFNd0/oV3JWY7YlxvIpGsyWHZA35KByyxY8QOxEX8b5AyOgqXAFu4iw/ WNFa4NoFr8Yzvk8l5ZGG/jOEtv7QWMaduHAvD9lHaR4vpGF2HzGSfaDafYoI1A0BWI HOcjK5/i0m1OeJ+/dMP6Fucwfo5Jp6MpOKKRoWXi3YVtWN1S2Pr6QC8utu1Qyaw5Hi UxdL5jAZNSjzwi+P0/1oSIhmMdxDnjVjm3y7QRzrdKUKBuxDFWvwcxUeYOOxuqs0Kk smu5d4EzcOk7kp0vSO7QPGpgmnqkqpKZiJIfBCCRWe2CSJHWMNsvTX+nondFWwBqSf 8iEB5Xa7ZSm3g== Date: Thu, 31 Oct 2024 16:19:22 -0700 Subject: [PATCH 41/41] xfs: update the pag for the last AG at recovery time From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173041566543.962545.13384145870546499319.stgit@frogsfrogsfrogs> In-Reply-To: <173041565874.962545.15559186670255081566.stgit@frogsfrogsfrogs> References: <173041565874.962545.15559186670255081566.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: 4a201dcfa1ff0dcfe4348c40f3ad8bd68b97eb6c Currently log recovery never updates the in-core perag values for the last allocation group when they were grown by growfs. This leads to btree record validation failures for the alloc, ialloc or finotbt trees if a transaction references this new space. Found by Brian's new growfs recovery stress test. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 17 +++++++++++++++++ libxfs/xfs_ag.h | 1 + 2 files changed, 18 insertions(+) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index a22c2be153a50c..79ee483b42695a 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -271,6 +271,23 @@ xfs_agino_range( return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last); } +int +xfs_update_last_ag_size( + struct xfs_mount *mp, + xfs_agnumber_t prev_agcount) +{ + struct xfs_perag *pag = xfs_perag_grab(mp, prev_agcount - 1); + + if (!pag) + return -EFSCORRUPTED; + pag->block_count = __xfs_ag_block_count(mp, prev_agcount - 1, + mp->m_sb.sb_agcount, mp->m_sb.sb_dblocks); + __xfs_agino_range(mp, pag->block_count, &pag->agino_min, + &pag->agino_max); + xfs_perag_rele(pag); + return 0; +} + int xfs_initialize_perag( struct xfs_mount *mp, diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 6e68d6a3161a0f..9edfe0e9643964 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -150,6 +150,7 @@ int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno, xfs_agnumber_t end_agno); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); +int xfs_update_last_ag_size(struct xfs_mount *mp, xfs_agnumber_t prev_agcount); /* Passive AG references */ struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);