From patchwork Fri Aug 23 00:09:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774389 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 426EE8460 for ; Fri, 23 Aug 2024 00:09:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371752; cv=none; b=OhnmrcM59ZBrdNvLMaoa6eC9wUJl42hgaM/reT/NAfR025NHiKz/9GIQEtgdwI/Z0Jk0J0rAseAxJvWbFosdXZmKfEfJYdiE5Z5/sI7sk0Dm6uT1gFWepJJYK3QzPg+aFUH4WPmUkfJupjNoyOTblqmJi16aOKVmYwiAhfKjijA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371752; c=relaxed/simple; bh=XhduGXii+ygpCt2VdEygsatv8gUI8pz4yXFGXIvShZE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PejbLUDOnEWdqAtrFFM0/bFkWtvGiIjnE0PDFlRctW7nQCQzKzQYm10HtA7wNbbwfriW3Xn9x1w5ZhHd6nJUe8o1pPKOvByA4bgBbje5+ZrvlM/Phk0VgiJnLs6BMUfiY95xgIWuHOwWidNVumph04Ea5GvN09K7xWoXGGN2Y80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VvC7bQc/; 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="VvC7bQc/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B742C32782; Fri, 23 Aug 2024 00:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371752; bh=XhduGXii+ygpCt2VdEygsatv8gUI8pz4yXFGXIvShZE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VvC7bQc/KT6SdMg11BcVBnGtbkDHDKd+xFM22mLw8aRThgM8Oz1dFpN1eWRHctnDJ 9ANAcmrbiwNgvfgQ01a51KAQZqTK2E1sFjB20M+pcJVddjhl6kxuPaZcG+4ihqlbxS M6RELZ7BH3qV+hQH4gOq00XD2/hGNKO6W5qpuUkVV0MxWWLoVIZC42b/dlih+0Uy0G hkGoPern+Atm4Z+a6t9bp1FKIVk69aIHdgnFTmBRH1E28QmkFvaizAX5yU3fJXlDId Dh+cRUYv5h0OZNHtUmMj/e2OLqNcgyxsoRfz5neh2k20vQdTf0hsRzMbWKmfNCSlFY gQNthHoO+hk4Q== Date: Thu, 22 Aug 2024 17:09:11 -0700 Subject: [PATCH 01/12] xfs: remove xfs_validate_rtextents From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086036.58604.3933092156936521313.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_sb.c | 2 +- fs/xfs/libxfs/xfs_types.h | 12 ------------ fs/xfs/xfs_rtalloc.c | 2 +- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 1dcbf8ade39f8..b781e5f836e4c 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -516,7 +516,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/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h index 76eb9e328835f..a8cd44d03ef64 100644 --- a/fs/xfs/libxfs/xfs_types.h +++ b/fs/xfs/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__ */ diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index b4c3c5a3171bf..2acb75336b7b9 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -905,7 +905,7 @@ xfs_growfs_rt( */ nrextents = nrblocks; do_div(nrextents, in->extsize); - if (!xfs_validate_rtextents(nrextents)) { + if (nrextents == 0) { error = -EINVAL; goto out_unlock; } From patchwork Fri Aug 23 00:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774390 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 3E558947E for ; Fri, 23 Aug 2024 00:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371768; cv=none; b=iSgFgzKhrIG8LDGWf2d9BrsQTngMcP4DI0UcRWvDM/oVoPywSjHUWUV4ifwafLtwudnT/MeMOqI0qKTAjyiFIdp9P9NkXO+6Y/UnGep8W/V0dNDMGb2O7MG7JcviCmqQRF7z3bmIL+EUzhHVGJ7bJNztOmiXXnQprgK3/WFPEuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371768; c=relaxed/simple; bh=VY4m2PWxkhA2lkL09B+mWR3QyDA3zQf+Hhl6DingQF4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qy46aLf0m9/vWJirGUr+73gk7uQ2Ab171G9OOsXd1OolbAyky5TWkWx4IyFGbPfgUDcaV+GqNaXz2lTXqQgoZ/5Dtzv6LwCNdyN3Gi1DrpAiSXHv0TYaQ7HXdYcKg0XpKy+PIwIh3gTYYyg20fU0AqQ5KYbifaUEctEtAvXZTZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cNb8JPn9; 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="cNb8JPn9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABD39C4AF0E; Fri, 23 Aug 2024 00:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371767; bh=VY4m2PWxkhA2lkL09B+mWR3QyDA3zQf+Hhl6DingQF4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cNb8JPn99fjCdh+B85Dse2lFHkIZ3A3yEz1f6Dn64GBB6ZzASFgeMphijduDy5Le/ k6A18oARoGKRnEnqOAh3ZuMzR1v1hS1R3vzDBK5WMVL7fimRf1Vi7T+RJZEsrFYw1N A4COSTa5YyT5GejCP0Ms+jcuzOgzXsBnrE/DQffQHdHVfDSu8S9c6vnixvWlJA19UB Hk+2uVbfNN1y+80BYNnT63QPqySJywCOhp7gdfJHCBBBny3MNeI1wTULN/VY8ZEVUo 37iQaLW9O9u+Ryl9g1w5mMkGr5VM74anQ1Orfyywemkp3XcQdbWXGzDFRHbh4ySBGC lGlIhKd7hg8YQ== Date: Thu, 22 Aug 2024 17:09:27 -0700 Subject: [PATCH 02/12] xfs: factor out a xfs_validate_rt_geometry helper From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086053.58604.11507018611823623127.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_sb.c | 64 ++++++++++++++++++++++++++---------------------- fs/xfs/libxfs/xfs_sb.h | 1 + 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index b781e5f836e4c..a4221afb012b6 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -234,6 +234,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( @@ -493,39 +525,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/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h index 37b1ed1bc2095..796f02191dfd2 100644 --- a/fs/xfs/libxfs/xfs_sb.h +++ b/fs/xfs/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 Fri Aug 23 00:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774391 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 6A14C800 for ; Fri, 23 Aug 2024 00:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371783; cv=none; b=aocjNaAk4gHW1PUXmnH+mGviAJMwwnztiuzmIP71dpZs1L99irrFMCpje8lP54XSs6pUkCVFn2FXCV9VVnZ+6iXOsMmvTvR3AXxWefdGdf43tAcOSJ9O1jSAkzhHAPoHBZHOPE/VsMvN9K8p5SlJVwmitGaWhYpnZ0WEqAsVkbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371783; c=relaxed/simple; bh=GZqnQmoUmCB+iuKBdKWgvaKjgd7BjOjQVqOLsztmxe0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wg50bcR2Z1jW7xsOGSP1tPAEPx2f4l55DpBa/4IdK36QD48e/S8O+qBdRnxNZxpxDyYOdyIAclMUsMY/yr2F4XP+sf1lRbR9o4ckzQV2JNPPpWUM+xBgfX59RzXQB8SIByrCJ4F4BqfidfV7NgaRRDlmc6RtOIDiiYg9+KZBkOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mPGuNbd8; 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="mPGuNbd8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47753C32782; Fri, 23 Aug 2024 00:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371783; bh=GZqnQmoUmCB+iuKBdKWgvaKjgd7BjOjQVqOLsztmxe0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mPGuNbd80m02a18hfFim0iTYBFPVbgOy2tPAWWC/QPis6lpPir2T03XPUwJz+eDyU oHUy5CUgbfM42N61p0VXCHjPEqGVIBqq5GB7nzfFTtAwBIX79KBG3CaoYDUzdGldTN ftK6hNulurTcRhA/d0cpw5YbrGZnuHDInASYOpo2D9gVZLWmRV/dh+wTTrP6Ucin/V 5iZprNLcT5p+/d8B9u1iCc2nvJyPtFJAxbID33gqOC/kEZyls76GN8wWvz7HMmRpFq ltq2F905aCBgysvLXRra1Gd6x9wwie0n3Nsj3iLFcs1SBzlEweZVeudA8SNdM5bSAr WOyVYlrMuUJ+w== Date: Thu, 22 Aug 2024 17:09:42 -0700 Subject: [PATCH 03/12] xfs: make the RT rsum_cache mandatory From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086070.58604.6724403084646621017.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Currently the RT mount code simply ignores an allocation failure for the rsum_cache. The code mostly works fine with it, but not having it leads to nasty corner cases in the growfs code that we don't really handle well. Switch to failing the mount if we can't allocate the memory, the file system would not exactly be useful in such a constrained environment to start with. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 2acb75336b7b9..f5a39cfd9bcb8 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -769,21 +769,20 @@ xfs_growfs_rt_alloc( return error; } -static void +static int xfs_alloc_rsum_cache( - xfs_mount_t *mp, /* file system mount structure */ - xfs_extlen_t rbmblocks) /* number of rt bitmap blocks */ + struct xfs_mount *mp, + xfs_extlen_t rbmblocks) { /* * The rsum cache is initialized to the maximum value, which is * trivially an upper bound on the maximum level with any free extents. - * We can continue without the cache if it couldn't be allocated. */ mp->m_rsum_cache = kvmalloc(rbmblocks, GFP_KERNEL); - if (mp->m_rsum_cache) - memset(mp->m_rsum_cache, -1, rbmblocks); - else - xfs_warn(mp, "could not allocate realtime summary cache"); + if (!mp->m_rsum_cache) + return -ENOMEM; + memset(mp->m_rsum_cache, -1, rbmblocks); + return 0; } /* @@ -941,8 +940,11 @@ xfs_growfs_rt( goto out_unlock; rsum_cache = mp->m_rsum_cache; - if (nrbmblocks != sbp->sb_rbmblocks) - xfs_alloc_rsum_cache(mp, nrbmblocks); + if (nrbmblocks != sbp->sb_rbmblocks) { + error = xfs_alloc_rsum_cache(mp, nrbmblocks); + if (error) + goto out_unlock; + } /* * Allocate a new (fake) mount/sb. @@ -1271,7 +1273,9 @@ xfs_rtmount_inodes( if (error) goto out_rele_summary; - xfs_alloc_rsum_cache(mp, sbp->sb_rbmblocks); + error = xfs_alloc_rsum_cache(mp, sbp->sb_rbmblocks); + if (error) + goto out_rele_summary; xfs_trans_cancel(tp); return 0; From patchwork Fri Aug 23 00:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774392 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 01ADF4A01 for ; Fri, 23 Aug 2024 00:09: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=1724371799; cv=none; b=uNS96V58cdaqp/Pa+UOKVVvoWdX78dfPQVnpvnmAHe6xbmpI9xlAJUpkxOcvQLEZ4C5ph3mpxFR1mmz9EmVqoR5D5iN78Nyr1PKHZ9SHckJ6xh1+2OJajSpQ0TP0qrJ7EiTlqLBDJ0rVG3io15kC1waB+AehPEX54VkNv68bxmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371799; c=relaxed/simple; bh=KptZAa270lf6dYovWTgAvK/MlMurlUNAsVYt/DEsu10=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h0uGxBpEDfKC5Pn6wxBmakOEhNshM68DmLdw9vpKT/p6omVen5Y+IA+pQC+eIii3Lte5PaWGPixjp2cD0Fkf2SlnpdyqP9SyvtE9laxYskgybBs+qU/dsaXQ68f7mxXE8z4q8wJtirJ6nZ8bT1kghiktpl2O2riYxLN5uoAsok0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pNtVbBjZ; 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="pNtVbBjZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D01D2C32782; Fri, 23 Aug 2024 00:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371798; bh=KptZAa270lf6dYovWTgAvK/MlMurlUNAsVYt/DEsu10=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pNtVbBjZT7d9e4FnDBGHjzFvzMAMdISgfQTYbqxxz2RXylbOwZhG+Qxa3tUA7O9Lk Hr+/9X9lTCvE9IhqXIXbmDfJ23ih9eFyiSa9ovHmP1xDCFGsKvGYrq6NMG+i3Vl743 8TkAV3pPaZtCgIdwXmEGllTQygBnCzsXYQ20hNLV0uCvoTs6dMxweiw1I/4o8y93OG zkdkaCxPHUSkUyNKiHUagqn8T8SlXhthiwzvlsROAaSm1u9Wz9lr6iWAwaX6jpdIz9 FJtTefu43qU+2caZaY34xnQ7zWAzTUsnlguFwmsyliStiL30xK7RtNOWfAqLgNaPdv ZOKzJ2M2Li2qg== Date: Thu, 22 Aug 2024 17:09:58 -0700 Subject: [PATCH 04/12] xfs: remove the limit argument to xfs_rtfind_back From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086087.58604.8991781061508700414.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_rtbitmap.c | 9 ++++----- fs/xfs/libxfs/xfs_rtbitmap.h | 2 +- fs/xfs/xfs_rtalloc.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 386b672c50589..9feeefe539488 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -139,14 +139,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; @@ -175,7 +174,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. @@ -698,7 +697,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/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 6186585f2c376..1e04f0954a0fa 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/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, diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index f5a39cfd9bcb8..aaa969433ba8a 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -144,7 +144,7 @@ xfs_rtallocate_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; From patchwork Fri Aug 23 00:10:14 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: 13774393 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 EDC4219E for ; Fri, 23 Aug 2024 00:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371815; cv=none; b=K4szb+xLILK6RwAOuxcHcbyrnPSmT/qQGX1SzvTIXQP2Rt54c14Yy60ZQU6X7bL/o78PPnNsERxPZOLvjXOvY90gKpMqrnjhVlOs51wa/nREW44agTUSYSgqs4d9oGX2k2S2iEoVRuh2Ig7Fw7RuqEe4Eh59OHDOdmyWn+qB0aA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371815; c=relaxed/simple; bh=3UwhoiQBhu4B3wCFOUoBCiBRZd8gvVXzqqfvqWcpLzQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Yoo6WEHlKK1/u6e+po3CbQVqDM7Md+mu7ON/5IKfD54XHTaig/uUusDK2AjOt3Wy2jAX1nb1Tn2JC0w/cxjUgSftr2OjhflNfUB23sXxfZ4p53X8+aBPrTDeCIwpyvOPgH3uINAvV5asqXcxqjDXAkO7YoGzDPJB0NzePxysXxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SpXp+bBZ; 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="SpXp+bBZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C617C32782; Fri, 23 Aug 2024 00:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371814; bh=3UwhoiQBhu4B3wCFOUoBCiBRZd8gvVXzqqfvqWcpLzQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SpXp+bBZMaYDJ0X9mms2HV6bgcBRt0ZqEbmMMmeIgy/W9EKdIAXf5uM/HXeekNpV0 4K+sbmCBKZl1ozTgqN+BKk8h2jk55uyf9zDY4KvX1SuVKpAB7+PCrNh76kDMGGq7ap fv9QxziFrrJvPr7YHlD/jo8w9xTV077Ilc0ZfYcT3QLInqyVNGTkSNSDiMWKsyRIDy NRm2kyOgjFC1As9RYwCAbeSRt63LFxJRvoy7QHbJORBBBw75P+JELtDWzQVvia/HHg wNlZ1xcROleUjV4ZxZcTbJR3YUF78dsHHAMY9BKGhD+E81ibNtDNndp4ne4nGAk96Z waJEF+pnSvagw== Date: Thu, 22 Aug 2024 17:10:14 -0700 Subject: [PATCH 05/12] xfs: assert a valid limit in xfs_rtfind_forw From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086105.58604.1010536391875756505.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_rtbitmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 9feeefe539488..4de97c4e8ebdd 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -315,6 +315,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 Fri Aug 23 00:10:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774394 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 00920195 for ; Fri, 23 Aug 2024 00:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371832; cv=none; b=naheitcc58LKZLDJKa1T62q58uyg/JZbG5SCvKtFREafGKKeq3gF2eTyUdu5/kQuusYIAOe0ZTLjkn3VJBzG1VS8M5r5kxy+78XF0TpYshl8gpVBv4sdefWGToCSvG4SWuJgr9CHg+17pyyNNfft1nXM4ZGAr8TRvMoNTlNyJnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371832; c=relaxed/simple; bh=aN5wP2FqSxOPm9N4SjlpFha67ROC2kBcgW3OI2knSNY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oz3zCVzxUhGJ7IO0M0EWIzQTyf7KKUzAMUzhK4jJFUXY33UDNWLMuIiAd+tLETfJgL3Bli/OgF2HldJ+krKozTXwTgrC0IzQXDLLDZi/qPFrc9l/u3IO/2TuNRItHwdGf+pfW0VVilHV1SPn3vxhxjTfMGTUCYa9L9uW+KBFdZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ugzbZZZN; 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="ugzbZZZN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B9BDC32782; Fri, 23 Aug 2024 00:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371830; bh=aN5wP2FqSxOPm9N4SjlpFha67ROC2kBcgW3OI2knSNY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ugzbZZZNn722J5XFS+q57khFJPSTYfv7nHGOffIuZ/zZavnIo3gT4qEGYQEkxbgoc AGhexw87XON29Dp+tbLBbILgDDFS4dOgTPeDYOayd4+gyj3G26jSnNCCu6BQpZCNbb SDmDUlKgmSO8CbpMnn0VpztjTtZzzR+t+8mCuIYZTus6G1sShWhAaI7Gg/tgLvW7nJ HAAu4eAJypgj+kwW1pb+FMmHzMiRYhnMHsjXMzvs2E2AUknBGKxY4LbdRWjDVTH7Da M8sbe1LQtNGvvkvnyVxpg9mtWIdcuExqkBgjerWPuppTdQx8VbGevWySzcK+pEhOr2 1UP4DxrH0khTg== Date: Thu, 22 Aug 2024 17:10:29 -0700 Subject: [PATCH 06/12] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086122.58604.5538134784944300406.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_rtbitmap.c | 31 ++++++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_rtbitmap.h | 22 ++-------------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 4de97c4e8ebdd..02d6668d860fd 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -69,7 +69,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 */ @@ -138,6 +138,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/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 1e04f0954a0fa..e87e2099cff5e 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/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 Fri Aug 23 00:10:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774395 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 3F0C0195 for ; Fri, 23 Aug 2024 00:10: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=1724371847; cv=none; b=lE3Lx8k91b1jEeP3/B2Nlu6wKo0ZpIX3WhS5tU266LLNGC7DAUzCKpOB8Wg/DZivm2WuQcOeHfy1ot5jM/7qfDuTndLdm59GINmHLnjpGb280cUtn5H4wvFASJjBBsgb/yqn+A5LQx2HAKpKqiAwriS808hZivSc5jiZKKd1TcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371847; c=relaxed/simple; bh=hMaYFX1/S+cV07J1bb4Hyzo4by/2tw109a9qnFX8OM4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sUXolWTCIM+GcDsGqG6ZFmlpDgUQqFroVN1NHdFmt5/QEnE7Fwxy+wHt/O+CmTyIxhdI5Hkrkyz5Ui1b7snoMGOHta/jvEX7Fvv7vFe9Y9W/Q7cPR91kh0bNWWyifDpisrP+WOk7UANJ1xmmR3i5FE8EbR7ntVD6UvPOI89+azE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Walbqk4G; 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="Walbqk4G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A24C7C32782; Fri, 23 Aug 2024 00:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371845; bh=hMaYFX1/S+cV07J1bb4Hyzo4by/2tw109a9qnFX8OM4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Walbqk4GbwxtaGXHKMVZGwOuHpMLZ3BjUKCnyhzxqZTih8sJYEDUhqNDiEdd6/5Q8 hiJ1w0fliC2Y2l6kCTY4EFYUQD96Q6b+ucEqP46xaffdr/pg2Ua3JI0LQ9xNZEVeia PKF6T0BS5mBzfUM8o7OvgREqKG5WqSJi85OM8s6ZZGiRXLdF/1stxhXYKbdJrAo0bX OAN4HWHnTDjkulV4vLheZqbPOFmQcthP/639bO2EoayTnrpzw7vYvf0eaX5ap0XjYz RQrP9F2Uk8Xysu7QQNsv9cVRpeFAlPlx49R+tregzslboNiwF+V7KSVQuJLOvaHcht 2sI51dZ1ilNPw== Date: Thu, 22 Aug 2024 17:10:45 -0700 Subject: [PATCH 07/12] xfs: cleanup the calling convention for xfs_rtpick_extent From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086139.58604.9757741400946849728.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig xfs_rtpick_extent never returns an error. Do away with the error return and directly return the picked extent instead of doing that through a call by reference argument. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index aaa969433ba8a..8da59d941db3c 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1306,12 +1306,11 @@ xfs_rtunmount_inodes( * of rtextents and the fraction. * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ... */ -static int +static xfs_rtxnum_t xfs_rtpick_extent( xfs_mount_t *mp, /* file system mount point */ xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxlen_t len, /* allocation length (rtextents) */ - xfs_rtxnum_t *pick) /* result rt extent */ + xfs_rtxlen_t len) /* allocation length (rtextents) */ { xfs_rtxnum_t b; /* result rtext */ int log2; /* log of sequence number */ @@ -1342,8 +1341,7 @@ xfs_rtpick_extent( ts.tv_sec = seq + 1; inode_set_atime_to_ts(VFS_I(mp->m_rbmip), ts); xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE); - *pick = b; - return 0; + return b; } static void @@ -1450,9 +1448,7 @@ xfs_bmap_rtalloc( * If it's an allocation to an empty file at offset 0, pick an * extent that will space things out in the rt area. */ - error = xfs_rtpick_extent(mp, ap->tp, ralen, &start); - if (error) - return error; + start = xfs_rtpick_extent(mp, ap->tp, ralen); } else { start = 0; } From patchwork Fri Aug 23 00:11: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: 13774396 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 D0DA619E for ; Fri, 23 Aug 2024 00:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371861; cv=none; b=Wjq1UiSemOgJVJgGPZOs768V3D8OoCkFDQOQjIMl9IbeGj0D2mAoCH22WbtZ0UovHQb9Z6X5BCN1oMDIXwBkOJRBHPYgJefUS+91/kCPWkQ2C5T3i/1hl4F3Y205wRk228Cn+1LICaaZpRfAHeCI3Ear/xjuf4kWQ7yZbgFNmjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371861; c=relaxed/simple; bh=Jb6oyT0bHIIh5pcdl6ot7lwnPxbmcS0wdBQiFWX/SqA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aGXE8PHYpQwcw4NQFew5+5JSP8c2p21dJ/+tRLPZbwne1/Q5tYYBoaCz/zjzoY4dSU+d9u/GEGq7Ish/HSJpIQcxoVkfSfDJQjhdn2ZBBxOitDHcgkIamc2yOve8hINmypoYJ2pByPxQRTmfyZz9rlmoyj6h+CcsWwXvg1rWMo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BPRn3W+N; 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="BPRn3W+N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F5DC32782; Fri, 23 Aug 2024 00:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371861; bh=Jb6oyT0bHIIh5pcdl6ot7lwnPxbmcS0wdBQiFWX/SqA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BPRn3W+NLHLHp9A2DVNzofJKOSMfkV0HDY3dDUk50h+61MyU5eCWHdugDIshZ6zqF KNSW1cTc3jcsjXrkOLIw8gOVK2kWwnZ8opWf4opkoBdbWVHUoyYTdFTGTbQEI1st1j B95398+9x/RTqyTQy8NPD1j+a0MdlDtZYR7TkcI09q70OqV37oyeXlDd43sXbsgsEi 1pV5WDshXLDj8kG9aHbBnyfAQRAtOgkjhJhfKNtFM1aDPbT5JEdd0uB6B6m1YfBIXA 7RHZ6nj09QEfKpH83GQZ+ffSFaAbOM/hrUFdViSobztUa7wOQR7q5HdO6Tobb0F38A KkHSfmcDEPl3g== Date: Thu, 22 Aug 2024 17:11:00 -0700 Subject: [PATCH 08/12] xfs: push the calls to xfs_rtallocate_range out to xfs_bmap_rtalloc From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086157.58604.7854626171219976171.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Currently the various low-level RT allocator functions call into xfs_rtallocate_range directly, which ties them into the locking protocol for the RT bitmap. As these helpers already return the allocated range, lift the call to xfs_rtallocate_range into xfs_bmap_rtalloc so that it happens as high as possible in the stack, which will simplify future changes to the locking protocol. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 8da59d941db3c..a98e22c76280b 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -261,9 +261,9 @@ xfs_rtallocate_extent_block( /* * i for maxlen is all free, allocate and return that. */ - bestlen = maxlen; - besti = i; - goto allocate; + *len = maxlen; + *rtx = i; + return 0; } /* @@ -314,12 +314,8 @@ xfs_rtallocate_extent_block( } /* - * Allocate besti for bestlen & return that. + * Pick besti for bestlen & return that. */ -allocate: - error = xfs_rtallocate_range(args, besti, bestlen); - if (error) - return error; *len = bestlen; *rtx = besti; return 0; @@ -373,12 +369,6 @@ xfs_rtallocate_extent_exact( } } - /* - * Allocate what we can and return it. - */ - error = xfs_rtallocate_range(args, start, maxlen); - if (error) - return error; *len = maxlen; *rtx = start; return 0; @@ -431,7 +421,6 @@ xfs_rtallocate_extent_near( if (error != -ENOSPC) return error; - bbno = xfs_rtx_to_rbmblock(mp, start); i = 0; j = -1; @@ -554,11 +543,11 @@ xfs_rtalloc_sumlevel( xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { xfs_fileoff_t i; /* bitmap block number */ + int error; for (i = 0; i < args->mp->m_sb.sb_rbmblocks; i++) { xfs_suminfo_t sum; /* summary information for extents */ xfs_rtxnum_t n; /* next rtext to be tried */ - int error; error = xfs_rtget_summary(args, l, i, &sum); if (error) @@ -1473,9 +1462,12 @@ xfs_bmap_rtalloc( error = xfs_rtallocate_extent_size(&args, raminlen, ralen, &ralen, prod, &rtx); } - xfs_rtbuf_cache_relse(&args); - if (error == -ENOSPC) { + if (error) { + xfs_rtbuf_cache_relse(&args); + if (error != -ENOSPC) + return error; + if (align > mp->m_sb.sb_rextsize) { /* * We previously enlarged the request length to try to @@ -1503,14 +1495,20 @@ xfs_bmap_rtalloc( ap->length = 0; return 0; } + + error = xfs_rtallocate_range(&args, rtx, ralen); if (error) - return error; + goto out_release; xfs_trans_mod_sb(ap->tp, ap->wasdel ? XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS, -(long)ralen); + ap->blkno = xfs_rtx_to_rtb(mp, rtx); ap->length = xfs_rtxlen_to_extlen(mp, ralen); xfs_bmap_alloc_account(ap); - return 0; + +out_release: + xfs_rtbuf_cache_relse(&args); + return error; } From patchwork Fri Aug 23 00:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774397 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 75905195 for ; Fri, 23 Aug 2024 00:11:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371877; cv=none; b=Eo0YJwl2xsJLkaCrzsiUK7REox6Yxk6jac0xxlyrQVhu4fOvi3vaERYsDJCErc/2TGn6+yHX4yi61DdpT92baekWnNYj+DysWllY4eVYIDAtA6jMXDb/tuFzoTLlOqDl8vj+JPv5qMzIRzpWwqBiUdS6dbH/1PQ7fHFowElJonw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371877; c=relaxed/simple; bh=otpFKQNJJrxGcu4mH8bRc3tS27jAQRfem2c3NNk7oFE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kuw8072Cx66Jhnio9V/hofgEpujT6mpiZVjV5j4zWtLEjnBXmEoDBNm7vS6CcDJDkOoe7MBa5qLGdfT2YkPxzzrTcHftwAZWPu8QjEeByH5Sqei3I407uG87bt30vwKO8EFMjDUHqraXSoDnFjmDYeAk1xfYVW4017wG4Bq1vP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YVjsqjtb; 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="YVjsqjtb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05097C32782; Fri, 23 Aug 2024 00:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371877; bh=otpFKQNJJrxGcu4mH8bRc3tS27jAQRfem2c3NNk7oFE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YVjsqjtbaHTfUlFpfBomH/i2orfUd5OOL7KRJSpBS0BGuSkjF+bUbDOx52oDseU4P Xssz8gvmAJpwNqi+rT5S9AgkvhQTr1KoZ7l5nazW1wEpg7oEdQ72CHyhvX+cwOSU+M +EJZ+G/uZQb5XtblYB8vllZwrGZXtH2jlQjverZpPgKDVOljAHfEUwsPxqUbjXmIYT z+8u3m/5i2FWuMtLyO/b+3QhzqDwzjOc7uaXO8PvPAlgJpQliIlbNUCv2eUkB4Xljz I1A8Hs6NdX+QnosYjS2nFmUJi5QAASNm4JPabUG7jnTCU/3RlV/K68rZWWR2v35+KN 5tjKfS6B3PvcA== Date: Thu, 22 Aug 2024 17:11:16 -0700 Subject: [PATCH 09/12] xfs: factor out a xfs_growfs_rt_bmblock helper From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086174.58604.171404452828623959.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Add a helper to contain the per-rtbitmap block logic in xfs_growfs_rt. Note that this helper now allocates a new fake mount structure for each rtbitmap block iteration instead of reusing the memory for an entire growfs call. Compared to all the other work done when freeing the blocks the overhead for this is in the noise and it keeps the code nicely modular. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 317 +++++++++++++++++++++++++------------------------- 1 file changed, 158 insertions(+), 159 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index a98e22c76280b..5a637166cc788 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -807,9 +807,148 @@ xfs_growfs_rt_fixup_extsize( return error; } -/* - * Visible (exported) functions. - */ +static int +xfs_growfs_rt_bmblock( + struct xfs_mount *mp, + xfs_rfsblock_t nrblocks, + xfs_agblock_t rextsize, + xfs_fileoff_t bmbno) +{ + struct xfs_inode *rbmip = mp->m_rbmip; + struct xfs_inode *rsumip = mp->m_rsumip; + struct xfs_rtalloc_args args = { + .mp = mp, + }; + struct xfs_rtalloc_args nargs = { + }; + struct xfs_mount *nmp; + xfs_rfsblock_t nrblocks_step; + xfs_rtbxlen_t freed_rtx; + int error; + + + nrblocks_step = (bmbno + 1) * NBBY * mp->m_sb.sb_blocksize * rextsize; + + nmp = nargs.mp = kmemdup(mp, sizeof(*mp), GFP_KERNEL); + if (!nmp) + return -ENOMEM; + + /* + * Calculate new sb and mount fields for this round. + */ + nmp->m_rtxblklog = -1; /* don't use shift or masking */ + nmp->m_sb.sb_rextsize = rextsize; + nmp->m_sb.sb_rbmblocks = bmbno + 1; + nmp->m_sb.sb_rblocks = min(nrblocks, nrblocks_step); + nmp->m_sb.sb_rextents = xfs_rtb_to_rtx(nmp, nmp->m_sb.sb_rblocks); + nmp->m_sb.sb_rextslog = xfs_compute_rextslog(nmp->m_sb.sb_rextents); + nmp->m_rsumlevels = nmp->m_sb.sb_rextslog + 1; + nmp->m_rsumsize = XFS_FSB_TO_B(mp, + xfs_rtsummary_blockcount(mp, nmp->m_rsumlevels, + nmp->m_sb.sb_rbmblocks)); + + /* recompute growfsrt reservation from new rsumsize */ + xfs_trans_resv_calc(nmp, &nmp->m_resv); + + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtfree, 0, 0, 0, + &args.tp); + if (error) + goto out_free; + nargs.tp = args.tp; + + xfs_rtbitmap_lock(args.tp, mp); + + /* + * Update the bitmap inode's size ondisk and incore. We need to update + * the incore size so that inode inactivation won't punch what it thinks + * are "posteof" blocks. + */ + rbmip->i_disk_size = nmp->m_sb.sb_rbmblocks * nmp->m_sb.sb_blocksize; + i_size_write(VFS_I(rbmip), rbmip->i_disk_size); + xfs_trans_log_inode(args.tp, rbmip, XFS_ILOG_CORE); + + /* + * Update the summary inode's size. We need to update the incore size + * so that inode inactivation won't punch what it thinks are "posteof" + * blocks. + */ + rsumip->i_disk_size = nmp->m_rsumsize; + i_size_write(VFS_I(rsumip), rsumip->i_disk_size); + xfs_trans_log_inode(args.tp, rsumip, XFS_ILOG_CORE); + + /* + * Copy summary data from old to new sizes when the real size (not + * block-aligned) changes. + */ + if (mp->m_sb.sb_rbmblocks != nmp->m_sb.sb_rbmblocks || + mp->m_rsumlevels != nmp->m_rsumlevels) { + error = xfs_rtcopy_summary(&args, &nargs); + if (error) + goto out_cancel; + } + + /* + * Update superblock fields. + */ + if (nmp->m_sb.sb_rextsize != mp->m_sb.sb_rextsize) + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_REXTSIZE, + nmp->m_sb.sb_rextsize - mp->m_sb.sb_rextsize); + if (nmp->m_sb.sb_rbmblocks != mp->m_sb.sb_rbmblocks) + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_RBMBLOCKS, + nmp->m_sb.sb_rbmblocks - mp->m_sb.sb_rbmblocks); + if (nmp->m_sb.sb_rblocks != mp->m_sb.sb_rblocks) + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_RBLOCKS, + nmp->m_sb.sb_rblocks - mp->m_sb.sb_rblocks); + if (nmp->m_sb.sb_rextents != mp->m_sb.sb_rextents) + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_REXTENTS, + nmp->m_sb.sb_rextents - mp->m_sb.sb_rextents); + if (nmp->m_sb.sb_rextslog != mp->m_sb.sb_rextslog) + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_REXTSLOG, + nmp->m_sb.sb_rextslog - mp->m_sb.sb_rextslog); + + /* + * Free the new extent. + */ + freed_rtx = nmp->m_sb.sb_rextents - mp->m_sb.sb_rextents; + error = xfs_rtfree_range(&nargs, mp->m_sb.sb_rextents, freed_rtx); + xfs_rtbuf_cache_relse(&nargs); + if (error) + goto out_cancel; + + /* + * Mark more blocks free in the superblock. + */ + xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_FREXTENTS, freed_rtx); + + /* + * Update mp values into the real mp structure. + */ + mp->m_rsumlevels = nmp->m_rsumlevels; + mp->m_rsumsize = nmp->m_rsumsize; + + /* + * Recompute the growfsrt reservation from the new rsumsize. + */ + xfs_trans_resv_calc(mp, &mp->m_resv); + + error = xfs_trans_commit(args.tp); + if (error) + goto out_free; + + /* + * Ensure the mount RT feature flag is now set. + */ + mp->m_features |= XFS_FEAT_REALTIME; + + kfree(nmp); + return 0; + +out_cancel: + xfs_trans_cancel(args.tp); +out_free: + kfree(nmp); + return error; +} /* * Grow the realtime area of the filesystem. @@ -822,23 +961,14 @@ xfs_growfs_rt( xfs_fileoff_t bmbno; /* bitmap block number */ struct xfs_buf *bp; /* temporary buffer */ int error; /* error return value */ - xfs_mount_t *nmp; /* new (fake) mount structure */ - xfs_rfsblock_t nrblocks; /* new number of realtime blocks */ xfs_extlen_t nrbmblocks; /* new number of rt bitmap blocks */ xfs_rtxnum_t nrextents; /* new number of realtime extents */ - uint8_t nrextslog; /* new log2 of sb_rextents */ xfs_extlen_t nrsumblocks; /* new number of summary blocks */ - uint nrsumlevels; /* new rt summary levels */ - uint nrsumsize; /* new size of rt summary, bytes */ - xfs_sb_t *nsbp; /* new superblock */ xfs_extlen_t rbmblocks; /* current number of rt bitmap blocks */ xfs_extlen_t rsumblocks; /* current number of rt summary blks */ - xfs_sb_t *sbp; /* old superblock */ uint8_t *rsum_cache; /* old summary cache */ xfs_agblock_t old_rextsize = mp->m_sb.sb_rextsize; - sbp = &mp->m_sb; - if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -857,11 +987,10 @@ xfs_growfs_rt( goto out_unlock; /* Shrink not supported. */ - if (in->newblocks <= sbp->sb_rblocks) + if (in->newblocks <= mp->m_sb.sb_rblocks) goto out_unlock; - /* Can only change rt extent size when adding rt volume. */ - if (sbp->sb_rblocks > 0 && in->extsize != sbp->sb_rextsize) + if (mp->m_sb.sb_rblocks > 0 && in->extsize != mp->m_sb.sb_rextsize) goto out_unlock; /* Range check the extent size. */ @@ -874,15 +1003,14 @@ xfs_growfs_rt( if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp) || xfs_has_quota(mp)) goto out_unlock; - nrblocks = in->newblocks; - error = xfs_sb_validate_fsb_count(sbp, nrblocks); + error = xfs_sb_validate_fsb_count(&mp->m_sb, in->newblocks); if (error) goto out_unlock; /* * Read in the last block of the device, make sure it exists. */ error = xfs_buf_read_uncached(mp->m_rtdev_targp, - XFS_FSB_TO_BB(mp, nrblocks - 1), + XFS_FSB_TO_BB(mp, in->newblocks - 1), XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL); if (error) goto out_unlock; @@ -891,17 +1019,15 @@ xfs_growfs_rt( /* * Calculate new parameters. These are the final values to be reached. */ - nrextents = nrblocks; - do_div(nrextents, in->extsize); + nrextents = div_u64(in->newblocks, in->extsize); if (nrextents == 0) { error = -EINVAL; goto out_unlock; } nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents); - nrextslog = xfs_compute_rextslog(nrextents); - nrsumlevels = nrextslog + 1; - nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels, nrbmblocks); - nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks); + nrsumblocks = xfs_rtsummary_blockcount(mp, + xfs_compute_rextslog(nrextents) + 1, nrbmblocks); + /* * New summary size can't be more than half the size of * the log. This prevents us from getting a log overflow, @@ -929,149 +1055,27 @@ xfs_growfs_rt( goto out_unlock; rsum_cache = mp->m_rsum_cache; - if (nrbmblocks != sbp->sb_rbmblocks) { + if (nrbmblocks != mp->m_sb.sb_rbmblocks) { error = xfs_alloc_rsum_cache(mp, nrbmblocks); if (error) goto out_unlock; } - /* - * Allocate a new (fake) mount/sb. - */ - nmp = kmalloc(sizeof(*nmp), GFP_KERNEL | __GFP_NOFAIL); /* * Loop over the bitmap blocks. * We will do everything one bitmap block at a time. * Skip the current block if it is exactly full. * This also deals with the case where there were no rtextents before. */ - for (bmbno = sbp->sb_rbmblocks - - ((sbp->sb_rextents & ((1 << mp->m_blkbit_log) - 1)) != 0); - bmbno < nrbmblocks; - bmbno++) { - struct xfs_rtalloc_args args = { - .mp = mp, - }; - struct xfs_rtalloc_args nargs = { - .mp = nmp, - }; - struct xfs_trans *tp; - xfs_rfsblock_t nrblocks_step; - - *nmp = *mp; - nsbp = &nmp->m_sb; - /* - * Calculate new sb and mount fields for this round. - */ - nsbp->sb_rextsize = in->extsize; - nmp->m_rtxblklog = -1; /* don't use shift or masking */ - nsbp->sb_rbmblocks = bmbno + 1; - nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize * - nsbp->sb_rextsize; - nsbp->sb_rblocks = min(nrblocks, nrblocks_step); - nsbp->sb_rextents = xfs_rtb_to_rtx(nmp, nsbp->sb_rblocks); - ASSERT(nsbp->sb_rextents != 0); - nsbp->sb_rextslog = xfs_compute_rextslog(nsbp->sb_rextents); - nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; - nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels, - nsbp->sb_rbmblocks); - nmp->m_rsumsize = nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks); - /* recompute growfsrt reservation from new rsumsize */ - xfs_trans_resv_calc(nmp, &nmp->m_resv); - - /* - * Start a transaction, get the log reservation. - */ - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtfree, 0, 0, 0, - &tp); + bmbno = mp->m_sb.sb_rbmblocks; + if (xfs_rtx_to_rbmword(mp, mp->m_sb.sb_rextents) != 0) + bmbno--; + for (; bmbno < nrbmblocks; bmbno++) { + error = xfs_growfs_rt_bmblock(mp, in->newblocks, in->extsize, + bmbno); if (error) - break; - args.tp = tp; - nargs.tp = tp; - - /* - * Lock out other callers by grabbing the bitmap and summary - * inode locks and joining them to the transaction. - */ - xfs_rtbitmap_lock(tp, mp); - /* - * Update the bitmap inode's size ondisk and incore. We need - * to update the incore size so that inode inactivation won't - * punch what it thinks are "posteof" blocks. - */ - mp->m_rbmip->i_disk_size = - nsbp->sb_rbmblocks * nsbp->sb_blocksize; - i_size_write(VFS_I(mp->m_rbmip), mp->m_rbmip->i_disk_size); - xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE); - /* - * Update the summary inode's size. We need to update the - * incore size so that inode inactivation won't punch what it - * thinks are "posteof" blocks. - */ - mp->m_rsumip->i_disk_size = nmp->m_rsumsize; - i_size_write(VFS_I(mp->m_rsumip), mp->m_rsumip->i_disk_size); - xfs_trans_log_inode(tp, mp->m_rsumip, XFS_ILOG_CORE); - /* - * Copy summary data from old to new sizes. - * Do this when the real size (not block-aligned) changes. - */ - if (sbp->sb_rbmblocks != nsbp->sb_rbmblocks || - mp->m_rsumlevels != nmp->m_rsumlevels) { - error = xfs_rtcopy_summary(&args, &nargs); - if (error) - goto error_cancel; - } - /* - * Update superblock fields. - */ - if (nsbp->sb_rextsize != sbp->sb_rextsize) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_REXTSIZE, - nsbp->sb_rextsize - sbp->sb_rextsize); - if (nsbp->sb_rbmblocks != sbp->sb_rbmblocks) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_RBMBLOCKS, - nsbp->sb_rbmblocks - sbp->sb_rbmblocks); - if (nsbp->sb_rblocks != sbp->sb_rblocks) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_RBLOCKS, - nsbp->sb_rblocks - sbp->sb_rblocks); - if (nsbp->sb_rextents != sbp->sb_rextents) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_REXTENTS, - nsbp->sb_rextents - sbp->sb_rextents); - if (nsbp->sb_rextslog != sbp->sb_rextslog) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_REXTSLOG, - nsbp->sb_rextslog - sbp->sb_rextslog); - /* - * Free new extent. - */ - error = xfs_rtfree_range(&nargs, sbp->sb_rextents, - nsbp->sb_rextents - sbp->sb_rextents); - xfs_rtbuf_cache_relse(&nargs); - if (error) { -error_cancel: - xfs_trans_cancel(tp); - break; - } - /* - * Mark more blocks free in the superblock. - */ - xfs_trans_mod_sb(tp, XFS_TRANS_SB_FREXTENTS, - nsbp->sb_rextents - sbp->sb_rextents); - /* - * Update mp values into the real mp structure. - */ - mp->m_rsumlevels = nrsumlevels; - mp->m_rsumsize = nrsumsize; - /* recompute growfsrt reservation from new rsumsize */ - xfs_trans_resv_calc(mp, &mp->m_resv); - - error = xfs_trans_commit(tp); - if (error) - break; - - /* Ensure the mount RT feature flag is now set. */ - mp->m_features |= XFS_FEAT_REALTIME; + goto out_free; } - if (error) - goto out_free; if (old_rextsize != in->extsize) { error = xfs_growfs_rt_fixup_extsize(mp); @@ -1083,11 +1087,6 @@ xfs_growfs_rt( error = xfs_update_secondary_sbs(mp); out_free: - /* - * Free the fake mp structure. - */ - kfree(nmp); - /* * If we had to allocate a new rsum_cache, we either need to free the * old one (if we succeeded) or free the new one and restore the old one From patchwork Fri Aug 23 00:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774398 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 C4151195 for ; Fri, 23 Aug 2024 00:11:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371892; cv=none; b=kCOsZ5BmzjAfeDXoY7KIr/dBbQv+ZiO8H1aOomF7GrsLAv01zK/RVI9Q9g01MdnCbY0LZu2kJXTtxNw9NoSWJua/AUQD6tDAC7iCDQVuWRmufSv4D1OJYXWJFX18RtoqIKPPjpLb14Hj7ZRogU2e2qsbF0NYVtCykSN35rKLXco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371892; c=relaxed/simple; bh=xFNNsQWboymbRGTHO07M3xy+kyzbZgmondCLWi2RXlQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tnnWx3hKVEZMi8M6Cs5m4Crq3RoDFxBQfGUvnTvuetgDHodSsQUQ7TwXmqn2ALMiUKyF1I9bCjKw8pYTwhq0g5vq0YDBsBbrkPQzpkO+HLCEtbpaVA4BsBj+Q/mrM/ugqBP2WAuK56ur/J6WPV57KVom35kjtnGPqaNg73mWXJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rO0QMsyU; 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="rO0QMsyU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 943B4C32782; Fri, 23 Aug 2024 00:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371892; bh=xFNNsQWboymbRGTHO07M3xy+kyzbZgmondCLWi2RXlQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rO0QMsyUYH6nlTWJ99lb6mWkpB5X0V5P0NnJuSJgA+UxWsDnpNnBP7r/3swpgcw5i y4mGXwU+2P5CO/tmLdZ6NbqlLamY02mbYphavdp9ynHbxfdp+7Z1jVj/6sDDujWgLy 9HvmBRbOx4fbvCxGCxR174RcYwxKp7vSG6BbvyO8oulgxaeXH/KVhOgJcYWVLvc8YH lSMNLF1dKaeSv4DiwPGr3RKn36UI5PsCrY+gygwbJthhlhxsEWyDpC9Yqvr7e2ekdO WvKppOBJZ9w0Y0J7ntayQ875g5WhMaxDRUhL032G8A4trl15EUzBFdzk/MVJf76x43 AeXLvHILD+HRQ== Date: Thu, 22 Aug 2024 17:11:32 -0700 Subject: [PATCH 10/12] xfs: factor out a xfs_last_rt_bmblock helper From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086191.58604.6683754743526908512.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Add helper to calculate the last currently used rt bitmap block to better structure the growfs code and prepare for future changes to it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 5a637166cc788..5bead4db164e9 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -950,6 +950,23 @@ xfs_growfs_rt_bmblock( return error; } +/* + * Calculate the last rbmblock currently used. + * + * This also deals with the case where there were no rtextents before. + */ +static xfs_fileoff_t +xfs_last_rt_bmblock( + struct xfs_mount *mp) +{ + xfs_fileoff_t bmbno = mp->m_sb.sb_rbmblocks; + + /* Skip the current block if it is exactly full. */ + if (xfs_rtx_to_rbmword(mp, mp->m_sb.sb_rextents) != 0) + bmbno--; + return bmbno; +} + /* * Grow the realtime area of the filesystem. */ @@ -1061,16 +1078,8 @@ xfs_growfs_rt( goto out_unlock; } - /* - * Loop over the bitmap blocks. - * We will do everything one bitmap block at a time. - * Skip the current block if it is exactly full. - * This also deals with the case where there were no rtextents before. - */ - bmbno = mp->m_sb.sb_rbmblocks; - if (xfs_rtx_to_rbmword(mp, mp->m_sb.sb_rextents) != 0) - bmbno--; - for (; bmbno < nrbmblocks; bmbno++) { + /* Initialize the free space bitmap one bitmap block at a time. */ + for (bmbno = xfs_last_rt_bmblock(mp); bmbno < nrbmblocks; bmbno++) { error = xfs_growfs_rt_bmblock(mp, in->newblocks, in->extsize, bmbno); if (error) From patchwork Fri Aug 23 00:11: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: 13774402 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 62900195 for ; Fri, 23 Aug 2024 00:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371908; cv=none; b=JaARk7C+NUG8HadpbcvJnddOJYkEQ+YAUCSF1nycVDXlPnO4jzVRCY/8OMJORJ7j0ds9S6wvgqDmvTYpqBSt1tHqjaweiXooPregYfLR5FUxbxEzRTYOa/U9z81aelmA7Tnjguf36CgLr0saB4c0CdmELsyOp9tC4xrrBykE+0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371908; c=relaxed/simple; bh=FzWFaLSWQVLYtMu05hHXWbQ/jdTrGuq2XzGaa6r5+UY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ikRazxuE6XJrXsofZhAGZ3D0gZNuuuDo1RYxTZ/tFKKk0+FOOyKHQj+j1sxSdziFtHkt1O4oYNwskAyBesoPtjZWpbQksi3xp0PSfM+FfqfHNti4LK45PskCQPv/Bb6a71FhJM5fzpJ5xm2yHucOAICVcTdMThDJlMY96TTaec8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Drh6zXFp; 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="Drh6zXFp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 390E7C32782; Fri, 23 Aug 2024 00:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371908; bh=FzWFaLSWQVLYtMu05hHXWbQ/jdTrGuq2XzGaa6r5+UY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Drh6zXFprMfuUFUJmJrd1z7JojefRsVjcWTuKvApJj4+mfIfX0gzvZYhiayRpKOgg TD+Gzm/2od+mSkkZpSsq73xUNKL6Qx6FpB196nZmjEE0M7hsRL5APGTt9bMeWkKOP7 bxR2hFpK2+OIEgoL7y3xw9j2WU8Mq8SD0VakN3cIpIlX49d9Evc6QYNWI6sK/kUa1L dn/qb23PNvv5P4D6fNyGGvELn5A/c1WMZ2eXlsJmlmZbQn1YYRcelx7LNXilDDixhJ krVhkPEKDwEZqguuoHbzHyxUz0Gs0e+rXb4hljAvJAB4qMbd/gcuFW+Ks6bGdxtw9U WKn5aGef++MUQ== Date: Thu, 22 Aug 2024 17:11:47 -0700 Subject: [PATCH 11/12] xfs: factor out rtbitmap/summary initialization helpers From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086208.58604.13633887639855830783.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_rtbitmap.c | 126 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtbitmap.h | 3 + fs/xfs/xfs_rtalloc.c | 121 +--------------------------------------- 3 files changed, 133 insertions(+), 117 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 02d6668d860fd..715d2c54ce029 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/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_rtalloc.h" #include "xfs_error.h" @@ -1255,3 +1257,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/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index e87e2099cff5e..0d5ab5e2cb6a3 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/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); diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 5bead4db164e9..52ed8448d9925 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -643,121 +643,6 @@ xfs_rtallocate_extent_size( return -ENOSPC; } -/* - * Allocate space to the bitmap or summary file, and zero it, for growfs. - */ -STATIC int -xfs_growfs_rt_alloc( - struct xfs_mount *mp, /* file system mount point */ - xfs_extlen_t oblocks, /* old count of blocks */ - xfs_extlen_t nblocks, /* new count of blocks */ - struct xfs_inode *ip) /* inode (bitmap/summary) */ -{ - xfs_fileoff_t bno; /* block number in file */ - struct xfs_buf *bp; /* temporary buffer for zeroing */ - xfs_daddr_t d; /* disk block address */ - int error; /* error return value */ - xfs_fsblock_t fsbno; /* filesystem block for bno */ - struct xfs_bmbt_irec map; /* block map output */ - int nmap; /* number of block maps */ - int resblks; /* space reservation */ - enum xfs_blft buf_type; - struct xfs_trans *tp; - - if (ip == mp->m_rsumip) - buf_type = XFS_BLFT_RTSUMMARY_BUF; - else - buf_type = XFS_BLFT_RTBITMAP_BUF; - - /* - * Allocate space to the file, as necessary. - */ - while (oblocks < nblocks) { - resblks = XFS_GROWFSRT_SPACE_RES(mp, nblocks - oblocks); - /* - * Reserve space & log for one extent added to the file. - */ - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc, resblks, - 0, 0, &tp); - if (error) - return error; - /* - * Lock the inode. - */ - 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; - - /* - * Allocate blocks to the bitmap file. - */ - nmap = 1; - error = xfs_bmapi_write(tp, ip, oblocks, nblocks - oblocks, - XFS_BMAPI_METADATA, 0, &map, &nmap); - if (error) - goto out_trans_cancel; - /* - * Free any blocks freed up in the transaction, then commit. - */ - error = xfs_trans_commit(tp); - if (error) - return error; - /* - * Now we need to clear the allocated blocks. - * Do this one block per transaction, to keep it simple. - */ - for (bno = map.br_startoff, fsbno = map.br_startblock; - bno < map.br_startoff + map.br_blockcount; - bno++, fsbno++) { - /* - * Reserve log for one block zeroing. - */ - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero, - 0, 0, 0, &tp); - if (error) - return error; - /* - * Lock the bitmap inode. - */ - xfs_ilock(ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); - /* - * Get a buffer for the block. - */ - d = XFS_FSB_TO_DADDR(mp, fsbno); - error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, - mp->m_bsize, 0, &bp); - if (error) - goto out_trans_cancel; - - xfs_trans_buf_set_type(tp, bp, buf_type); - bp->b_ops = &xfs_rtbuf_ops; - memset(bp->b_addr, 0, mp->m_sb.sb_blocksize); - xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); - /* - * Commit the transaction. - */ - error = xfs_trans_commit(tp); - if (error) - return error; - } - /* - * Go on to the next extent, if any. - */ - oblocks = map.br_startoff + map.br_blockcount; - } - - return 0; - -out_trans_cancel: - xfs_trans_cancel(tp); - return error; -} - static int xfs_alloc_rsum_cache( struct xfs_mount *mp, @@ -1064,10 +949,12 @@ xfs_growfs_rt( /* * Allocate space to the bitmap and summary files, as necessary. */ - error = xfs_growfs_rt_alloc(mp, rbmblocks, nrbmblocks, mp->m_rbmip); + error = xfs_rtfile_initialize_blocks(mp->m_rbmip, rbmblocks, + nrbmblocks, NULL); if (error) goto out_unlock; - error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip); + error = xfs_rtfile_initialize_blocks(mp->m_rsumip, rsumblocks, + nrsumblocks, NULL); if (error) goto out_unlock; From patchwork Fri Aug 23 00:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13774403 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 60FCDA2A for ; Fri, 23 Aug 2024 00:12: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=1724371924; cv=none; b=l/3yQ1yTFzcDrgFDVOjO6oYg7nzLZP5wfROd8vusEBg7fhdYgO+KX+bFKdmpJNA/SoTzbEn1vJV4djkl/uustq5NdTSbsXvV/GxHSxIFWJfAZGGph862WmQqvzIZ5w0rIJ6PnuefQ8qjjF9hZGChSo/dcoxCLMXqFDo8pjJNI94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371924; c=relaxed/simple; bh=KGcXK24m9dZJNB+A3EDjCJnZgzf9FGB3JLjy5XYcrLI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U3iKJ/JFCa/wJ3BOnjkxyKINRXzzS1aiO1pjosoC5o8zIdCI2fOr3CySh886J+YvvHMNDeYih5ahYuRpJpeETsaOrixHQyU/ujvMQ37cRWFK5JrG/8wHZzgbzOudsb7dolHiAn60mvv2O1dGImyoYRI62HM9W5P9gAbcyWbxSX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gSdAjA2S; 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="gSdAjA2S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D173DC32782; Fri, 23 Aug 2024 00:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371923; bh=KGcXK24m9dZJNB+A3EDjCJnZgzf9FGB3JLjy5XYcrLI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gSdAjA2SFn0dK5OGrTxAGkFsjLHWL/310ITK8poAOCpuTXdgZA1Lm0Ai1mHS56OMx rbY+cHwo7LTgagnjAF4k3WPCJkOO1a5WywKEd56qgxZYRC6wdqThO49n00tHI4FqWG q45E+3sQlEhdUFKBSTfNLrtgaIDVqDhWoJmiGR+2vYzyhQfeUzvmBDNWeTieb/rT2P 3F52s7V/XUL42oMPtfAvmrUYfnaKCIN9nJWCP9oJ9WThkd86dMJEOpTd+fUtEK61kY tUV/ZCz44Rz5NEr6MZzxs/SJb8gH+xpz+NV0DiwJgPXooVAEuaaKwum4GKWywAC+dI CYtk0czzSrNvg== Date: Thu, 22 Aug 2024 17:12:03 -0700 Subject: [PATCH 12/12] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437086225.58604.13666040100912659325.stgit@frogsfrogsfrogs> In-Reply-To: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> References: <172437085987.58604.7735951538617329546.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig 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 --- fs/xfs/libxfs/xfs_bmap.c | 3 ++- fs/xfs/libxfs/xfs_rtbitmap.c | 24 +++++++++++++----------- fs/xfs/libxfs/xfs_rtbitmap.h | 6 ++++-- fs/xfs/xfs_rtalloc.c | 6 ++++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index b79803784b766..314fc7d55659a 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5379,7 +5379,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/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 715d2c54ce029..d7c731aeee12d 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1201,23 +1201,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/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 0d5ab5e2cb6a3..523d3d3c12c60 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/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) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 52ed8448d9925..e809a8649c60c 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -741,7 +741,8 @@ xfs_growfs_rt_bmblock( goto out_free; nargs.tp = args.tp; - xfs_rtbitmap_lock(args.tp, mp); + xfs_rtbitmap_lock(mp); + xfs_rtbitmap_trans_join(args.tp); /* * Update the bitmap inode's size ondisk and incore. We need to update @@ -1319,7 +1320,8 @@ xfs_bmap_rtalloc( * Lock out modifications to both the RT bitmap and summary inodes */ if (!rtlocked) { - xfs_rtbitmap_lock(ap->tp, mp); + xfs_rtbitmap_lock(mp); + xfs_rtbitmap_trans_join(ap->tp); rtlocked = true; }