From patchwork Mon Sep 2 18:24:09 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: 13787587 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 0880F19CC03 for ; Mon, 2 Sep 2024 18:24: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=1725301451; cv=none; b=dYNPOtmkBJPT14siJ5MNB48qDyzDeOB7OgNeW73cif/5B+Ky4mfG7T9Jf/E2w0scG6dDALqRRO6O4mTgbpD3BcRb8Xeyzl6k1FmkXmSIqEwRXRtGCrVv2/qyk2Pohejk0I7fmko0GbivPxQAIa63J4LtC808x/92Z8cQGt+uQrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301451; c=relaxed/simple; bh=CVfftGum2GJoKIAbGyyglUwjm1hLQTgmOfgpqJ1bshY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZWpxZAtC5exIuipdKpoxLWnYrrJDEtFV236D0PjNW37da5sl8+hbxIFheb59AiErY7knHhgMOlNXw1EEmt4LuH0sxp7Va+lUQhwOiggOZ4DFZAz2p2STfzcLxitAFb/+HiM9sfO60UVGtT4OhB+C1RZz5DfkRk+2ojEXB8y8JmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z25UDkoA; 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="Z25UDkoA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A16C4CEC2; Mon, 2 Sep 2024 18:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301450; bh=CVfftGum2GJoKIAbGyyglUwjm1hLQTgmOfgpqJ1bshY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Z25UDkoAQucstqCJ5cuu87or1izcVqDxUSMXliBkKPgLnW+uH4y4jPmynxCyGxEUW oEHSttWlNAoXJNexpt8oHEOcAkqdBUhLEc85Iq0qRHfDKxMX5u/VwkCwJqnryHWMfL n0QMoNpEF/8fhpOhhBFy5TLJP8yXtQDdMdnXuVHwFIt4wHDVOgKDUa9GuWow7duMd2 diK7YOmu+DJagE4DJ8+do5G/jDl3P79rTWgnqrAkD0ZVJI6ayRaIg9EJMxZ0FzSFxD 57kP/QitNGOq3qcWQx3m9h1ocW8BDxuJ28si2dcFfMemrNE/yUE169Ofke6plSWmGM 5s7itjdYzJWOg== Date: Mon, 02 Sep 2024 11:24:09 -0700 Subject: [PATCH 01/12] xfs: remove xfs_validate_rtextents From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105732.3325146.16253808020422691018.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 6b56f0f6d4c1..f2fb6035fd21 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -514,7 +514,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 76eb9e328835..a8cd44d03ef6 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 ebeab8e4dab1..d28395abdd02 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -903,7 +903,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 Mon Sep 2 18:24: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: 13787588 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 B4BA219CC17 for ; Mon, 2 Sep 2024 18:24: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=1725301466; cv=none; b=qhLA2Km5qwYT60vbpFMuqoRzEYw7l/uHuXZFVRpx/PuUjdEsilt/wzHm3HfiMTeQpSONVgVQPrSQqKNh0tDRU+5cAP593FTrvsp5FNIs4nYpdshKzNgOkf4+5udXodkPX3QWX8LOtSQG/C+CHxlIfk0+XqOR7RE2OtT/EsPiPWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301466; c=relaxed/simple; bh=mZEXf4VioodfNCWINwkiz/omqXIaTarqpiIT3Bwu0Vk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Li2eJZrO6nfTbFxdiO3sFcR14HWYHmauOAB2wrZggq9qioUxbVuoHxzCu/8d7GYMxWt4uQ5aq0nKeZz9PJA7u51BPggkcvX+b+ExeqAlBaRFyLEO4cNw22xmCQoNyXsXSvxRb6EO7ITk6wYNZ/njG/usWGHY+tpOk/0vR9n+o5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XiQyWU1Q; 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="XiQyWU1Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 217CBC4CEC7; Mon, 2 Sep 2024 18:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301466; bh=mZEXf4VioodfNCWINwkiz/omqXIaTarqpiIT3Bwu0Vk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XiQyWU1Q+x09ff/D2VFQI7mnzwwzdOFZ/okxNNoig54aLzoFzMSOT6LLhv0PiymWm Hy3sxDCtrSfmTH8E25QEoP1le9WyAMfo7hjLW3kcEY0V+O4uwz9gqMAxlSHEkZZ//5 51LmpDX+mwkxrOtNZHeDUW6FpL4uSLwcCW24ufiH58SOvwQv9+xDJyL8viGe2Qgpj5 3YtQMuHCLBrraRtF1rVhRSWZX7HfvjpS6vUorJpcMfkdAwl2LcxhNNXs3tuz1EQAZR QDWtSpdfVlkdS+nElNLFpaKC2BwAgF3X831Rbm0VKsWYutl4LmkMRp3VxerJvBotbW oyXjz/CM8ChZA== Date: Mon, 02 Sep 2024 11:24:25 -0700 Subject: [PATCH 02/12] xfs: factor out a xfs_validate_rt_geometry helper From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105749.3325146.15482918038952714808.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 f2fb6035fd21..f9c3045f71e0 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -232,6 +232,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( @@ -491,39 +523,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 37b1ed1bc209..796f02191dfd 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 Mon Sep 2 18:24: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: 13787589 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 E877D19CC0A for ; Mon, 2 Sep 2024 18:24:41 +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=1725301482; cv=none; b=MiT/uY7431IhTfqRzOo0ipLuYsPNa4Y5KYCpyhZzUOnOMGrkmddJm2GtYFrOruiEL0N40nDAV/ec0gTE/u1anF/P86+drcuNEvxuSdWpcTr01J6n0OdYgtNgIOPPBSnb2c7cAW2qy1Pp/CdR7xC1oLkvIqD3FGK/eW/hZA+hl30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301482; c=relaxed/simple; bh=MKOfmd3IPxxxV40cPS7kGn0Id5rJrkaGf9nI2zhSRKU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rcPxLqXtFs0hQrd4Z4fsxncihcmDgu7zXiTdedhhjIB5MjuPDo8XwxTKAvNofX7E61X3fr63EqOZrfYxIvtWn7fDfhhZrSkcOufdpuU7LraJKVI+JUzoT1Lo8+whUmipEe9Vg+qQygSReNdHtZRd15T72aNuz+9dmcKsCfG+vAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JULRdaGw; 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="JULRdaGw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFE6FC4CEC2; Mon, 2 Sep 2024 18:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301481; bh=MKOfmd3IPxxxV40cPS7kGn0Id5rJrkaGf9nI2zhSRKU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JULRdaGwnG9NyeNn4t+XYB6jYKMUwiLTkbicD8c6VGLODqOC7OF80pu6zcGnroCwY fKdGuIAHY/i2JbN1PdGSP8J2CjcWztDCaOibT6V9tNzkIvJMBHf6izx2a43dwdOPKY hI4TACMHV2Q0y2XFjFcUoOYNx4w1RH5lRhaY9luVL5GuyXNGhJW5r0Un+xWy1sdCBR l+CG2EK3JxE9+u+4Cs9ZwLEw9toH/ug88ro10Sxoi2p0CRJVJuIvaO56/Xtpl3wNgh TV68UCBGa4v0VmePl1g0+k8nHz8aKrKbZlRSdfyNSxQbIxFs5Yu4UdG40KjZH1CekW OKG/4Olr/aA6w== Date: Mon, 02 Sep 2024 11:24:41 -0700 Subject: [PATCH 03/12] xfs: make the RT rsum_cache mandatory From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105765.3325146.266426096031623491.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 d28395abdd02..26eab1b408c8 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -767,21 +767,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; } /* @@ -939,8 +938,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. @@ -1268,7 +1270,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; return 0; out_rele_summary: From patchwork Mon Sep 2 18:24:56 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: 13787590 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 85D6E19CC10 for ; Mon, 2 Sep 2024 18:24: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=1725301497; cv=none; b=ZgtjHvqvGB/au1cWV3K8yD4T7AqSh6AuPlevsxNZWc96TprWxBrtrEXBz7C+6zbbv4VGKD8q+j8M76cPQFkQlehB8jUdQ4HeaBs2CgCuXJcra9POoE67Htq3ghtT8vmV0h2iZxlpvGe4MZuj6IjsZRccAFHMJcy1VXMzg1fPl/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301497; c=relaxed/simple; bh=s3CbncoiCGEnLIyni8gzhm4R/gaBqkvHEDBz8emzatA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r1hKuM6pVL/QH528KDfSnFo8jXxnjPGyP3uXJr2QA3EbOjq1xd90KVDKmJBTSZBv4bKnFmYvs3VFWDNuB+D7t0YBZMGted2p3N65eqecvBIMgWJu+tXD8EvlnvwpIzjAmoiDa6tz+JmelWrsQZ9iPOAlNrSkbD2cE0arDwkZ8cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LykO7/vA; 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="LykO7/vA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61133C4CEC2; Mon, 2 Sep 2024 18:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301497; bh=s3CbncoiCGEnLIyni8gzhm4R/gaBqkvHEDBz8emzatA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LykO7/vAS7W/LzfptfXYTU+1IiPZP9rFEAGXY/RbMmST/U0vAFoDvLv3bibjHvbcr HjuMHkAz7uYqpHq+KukNZtjqY2d0n2dAmZLTbpQYPKzQJiMhCcCAo4js41PJTxwWc+ 4MrFOy0yN+dNb5NL3oe+PZTn0kxKmn4sTFghS4PsZrh6RHoX9MEFVpnq8qRJ8W9YN/ PGdeILLcJniUaiLVlGo+kCNpMPG39Sw9voVFLi3Q/cbczbHRZIH2UoudtAGCCItsr+ CMbwt7IkC7+ckVzMMgHZUP0pxjBMrzV9NjxDOjHEwBGIh9NifA2KgPgZ7H1dMxELPI ebEXv/gEYW1dw== Date: Mon, 02 Sep 2024 11:24:56 -0700 Subject: [PATCH 04/12] xfs: remove the limit argument to xfs_rtfind_back From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105781.3325146.12002294989045841517.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 386b672c5058..9feeefe53948 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 6186585f2c37..1e04f0954a0f 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 26eab1b408c8..3728445b0b1c 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -142,7 +142,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 Mon Sep 2 18:25: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: 13787591 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 85BDB19CC0D for ; Mon, 2 Sep 2024 18:25: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=1725301513; cv=none; b=koileYt6XHR/UHBkB2u9wlTQW5TzGEpbQpw6HwT/XuthwpeHJ5KqpnYPeGfO97+c+QypiHGApW1EV/LPGfHTBE6nBIlN2xq1aqlupATiSm6ZICcF7dQmBLvsrRJ/ROSyGTJQhplyAy3pK08bRH9XFWhbRsiBPWpl7pNO9Xr+txA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301513; c=relaxed/simple; bh=cUbGGxmKXf2I5Bw3QtVnXAU3/G5jMcQr4/6Vb4vRsjk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nju3N/GzRJP+eNHjk3o1OR+5RIupbyZSWrAy4aKY2z6yFcWeMxjaEqqLWJpQDvDGLaYW5XcOP/Hsv08opkbYUvV+bufg2KP+979BtL0S+OwASMgbe0QRlml18yb8iD14/anw/cORpcz6GgLKbte+cyk7mCwDwy7bBnrRicm8nlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eeQwatmM; 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="eeQwatmM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AAF2C4CEC2; Mon, 2 Sep 2024 18:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301513; bh=cUbGGxmKXf2I5Bw3QtVnXAU3/G5jMcQr4/6Vb4vRsjk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eeQwatmMJQTJrYHk8VlVcQ8isP3A9gDMMlb9eWB++xTJwkSQ86gUW6eoyf0Q1xFOC yASOvMo3GLO6ReN+v6QMj37vPFrAp/a3YbESqnGuoWrsuCkZbN3rphprjJpMLpZh7T AAwAj5Spnoiq8E4exUzJ7m6aaBgFbWDIb0a79cmMTNNm30rzMwSJqx4a7TAM+t+3TR DkbaYYf76ICeC8vn3MDBEsEC1MI6zE7y8zSoJReAPEl1Uwe2FUqlUDcEtNwQ2Rk/9D eFaovPeoSEBla62zrER55+n9yBZFqJvJw1KbOCBlkt8Tu3EOvi4ZEuGmJtbp1MTWVN TYuBVK3Ar0ZyA== Date: Mon, 02 Sep 2024 11:25:12 -0700 Subject: [PATCH 05/12] xfs: assert a valid limit in xfs_rtfind_forw From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105798.3325146.17687169972955086973.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 9feeefe53948..4de97c4e8ebd 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 Mon Sep 2 18:25: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: 13787592 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 DD6893D7A for ; Mon, 2 Sep 2024 18:25: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=1725301528; cv=none; b=ARdVuimPS/NtcD0B8+DeOfPFM130rxxH/IOI+0Fqqy0fESsA3vW1oIDPW9sUksXrX0e+OYs4XWds0FrmkCPECcvY7bNmOQVlIIrl/SHcyGGa5xMT60eQt2IeYT6+Sg+R0Pe5StnWd/Cwf0r4byNOIrUm6UlSfKLGf1PfD5fdNBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301528; c=relaxed/simple; bh=xZPY8Kh7pZjZ2J378H930uJQoyLgQtYGTmH+AoJ0NNQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ajKK/6qpIsdgpkr0/CdC+/pvjKNrHBnK1X4hcIPzmK8Hi/HsOp5//sACaF06yP2IGKTWzRZVrJv8+FX9D+DH/QRuH4m18tOa6+dJ//VlhdFOXbVWerqPm0NMAhmK5XB5RMQuY/QCZD5KvS1J/xxi7Ak/BfleeKbHNiNlHimeytk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lDa+GE+k; 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="lDa+GE+k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B36EFC4CEC2; Mon, 2 Sep 2024 18:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301528; bh=xZPY8Kh7pZjZ2J378H930uJQoyLgQtYGTmH+AoJ0NNQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lDa+GE+kZWFTXQWDzkxj7KtsRsyszhyd6ZqRt5bH20rnAe881Do+GDXwLdIMYP2nL u78x8FbzY5LhoShXcDb6lexPHA/QCnisYcX/b953HI/gMAT8zo7TxeEi6x0UAmq2JL /LZ0CxCU1XPxQ6/UdQwj8x0nryg2c5ndxMm0yBYyqn0RVY4TxGpr+WoL1ApirKGPXO 5JAT1L++wdLRhhGE5w5ZdqkTW1d2HWFpEyVLv0n0EAVJdQqsJpia0uj/1elbsG2btc sYONA6z2wi9wTIALyZCWv0kdFmjOs4G05UltWxE734SFQjf2jat1x7w1oxBqinqD3+ 8CSALNN+9B5hA== Date: Mon, 02 Sep 2024 11:25:28 -0700 Subject: [PATCH 06/12] xfs: add bounds checking to xfs_rt{bitmap,summary}_read_buf From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105814.3325146.16042341552598162859.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 4de97c4e8ebd..02d6668d860f 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 1e04f0954a0f..e87e2099cff5 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 Mon Sep 2 18:25: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: 13787593 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 735C219CC0A for ; Mon, 2 Sep 2024 18:25: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=1725301544; cv=none; b=SOcB7qAzGqGOjwFEn5e7oW8IdZl+EgjLA7Rg50FlDmcIXGIjtcg98vTdz/ejGdKadIfXaKiG/3p9KkdTfWxWZ1Ry+yvWzslf8HWUUHWrjrf+WVP0CWVLmCl5dg1aTzQ5wl046ZGP1cyiLgcq2u0BeLNYFQLILNuqtnoEpJwQF5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301544; c=relaxed/simple; bh=d1jThLlJPM79KgQhe4SW9k7gu8YIQCnuT0RU3IyUe44=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C3yhjQ4kF/7qhbOsGV/0rUBXrMVeq6L0iAVQsiwOfH5WdfnmrxvQ+LWxH/BLRQuuDwwjfzxDpUIWhBEsIuhWE0StB14iJWPoCMAatkvfcXUHC/sHVC6Ukh1yoIqPHKV3iTQoZcYRlyUkxo6JZfxFfIJRzMSS07bakTV2PHH1Hy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ExbkQ95A; 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="ExbkQ95A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53327C4CEC2; Mon, 2 Sep 2024 18:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301544; bh=d1jThLlJPM79KgQhe4SW9k7gu8YIQCnuT0RU3IyUe44=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ExbkQ95Aoh6NKckuLY3GAHAMo46SA94WvyvyeuHxBoeWC7/krwyEpSxmljk43PZFR Xn63YbZnIq9uHbF9ICdtT4nfRwnHmkR+lqPbG9p6IC2dNiJAfHvJxUOpt3WTa0K1o6 IolMzBlo8JrhN8ooPXU1nroox40TMGKIT+JZ6byjnwocSoHNG9PKWQa2J7B0SjoKO7 hTFvC0veHdHGAfFtSwGT4I+YfM22pm8EGrgRj7CnYjErvp1EKTWQV+iNZFtqQrobDL uFeeHdF6ah5ed+EBTv2UUMD1IIx+xMCu2jFpamyu0z8tpHNz8luyc0V5//a3rckE9x TzS2VNLussx/A== Date: Mon, 02 Sep 2024 11:25:43 -0700 Subject: [PATCH 07/12] xfs: cleanup the calling convention for xfs_rtpick_extent From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105831.3325146.1820766471312447244.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 3728445b0b1c..64ba4bcf6e29 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1300,12 +1300,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 */ @@ -1336,8 +1335,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 @@ -1444,9 +1442,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 Mon Sep 2 18:25: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: 13787594 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 1EFE919CC0A for ; Mon, 2 Sep 2024 18:26: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=1725301560; cv=none; b=gxKIZ2XXWhjg20embjn0NjvgdwbQBQ8h+DWbPhcEQn44+zxNBPLP32JFNa0G6AGf2fbxVBxcexR6lqwbUhn7YMaodrYMbRNPQUddLkKmSxRp5nYXQwSgLU+Xi24MqsRmJ/MFtMLfhC4MqxTX3mtHLK7PMcCqtRbPsb4FUpvOahs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301560; c=relaxed/simple; bh=lgu2W3aursCk2hlJFtwLS2lDg2yJq4YTrKILmZdIY/Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EscI8UZmyvHDXxVoG9cR4DU3JWSyfzm8g6ORDjabExqloEF4aN0Pfs8xrVHNB1AXCvi4E6UemzMfHO9CCcBeAswaO+FwQfsCmlwqyQ/gMDGTdUhhDhJgl5xtvW/9959Ylet0XKoHvKkobycvtSU/1BwvpQthqwrukrIHDxYjvCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BaiMjylg; 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="BaiMjylg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9EEEC4CEC7; Mon, 2 Sep 2024 18:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301560; bh=lgu2W3aursCk2hlJFtwLS2lDg2yJq4YTrKILmZdIY/Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BaiMjylgCwkCwjpX4X4wof6NwTl28fMwoq56ILHbqbbU7U963tNAn5q7eP6Wfwf2d bWmHrAV8qZCNa2d0kjMrw98+RA8Ecp9KP7C7FUKPQ7RSqtv/+oAjfjD/sdTZMBYomb u01BHZujJkkyDoO2jkS39X1UNodYLY2FF3wpInAXH+evWSxEPkfJMjLmbXWhFgcYQz EP2J6UtTFIAPb+LcMPJEuVOABz8LEBndRGhN3IC8AXU3i5aQQf23/UKg0hQYm1l9RS 6EtDJdKqkRhBBigHZxuMjLxB7Jm+S8+n2pAutSj0XCDqoUO7RNE2Rvb5ZLU0QVUW3l G31hjvB7dT0AQ== Date: Mon, 02 Sep 2024 11:25:59 -0700 Subject: [PATCH 08/12] xfs: push the calls to xfs_rtallocate_range out to xfs_bmap_rtalloc From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105847.3325146.13409655825015257356.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 64ba4bcf6e29..59e599af74f4 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -259,9 +259,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; } /* @@ -312,12 +312,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; @@ -371,12 +367,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; @@ -429,7 +419,6 @@ xfs_rtallocate_extent_near( if (error != -ENOSPC) return error; - bbno = xfs_rtx_to_rbmblock(mp, start); i = 0; j = -1; @@ -552,11 +541,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) @@ -1467,9 +1456,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 @@ -1497,14 +1489,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 Mon Sep 2 18:26: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: 13787595 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 C6BB419CC26 for ; Mon, 2 Sep 2024 18:26: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=1725301575; cv=none; b=SEmyMgFHKcIBLmrROiMF98h2IlJVqBm5gnYPgxc2UZZ6mmz/FTfEL7gA8LahfA/FrMKGCeBCEbBqy3n0RGlvTbyt1EXwAViedsNSw76YHV7gs9iU4AOgV7kmsxbKU15uSpuxYvXjVtquuDteUxXsVWqSTBXtxRrR+Ol+IAU8LJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301575; c=relaxed/simple; bh=KHZYZ927+7yyV5GBG+foExygJP99hAl19iC2HtCS618=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KruJkep7jbp57N3p3QvWiDZ3jRcczOCVpaDiJmt5gjbIDVHFjV4iY+7ve8S0wmVZUjmcGDchS6dZOlsGZbEoCeIj3Ck4a/tyx36yxR8EaH/C35+dzyIfbqIlYzaoomG6CTbU8KJjzIgFVSv+apBLgPKgS/u5+w3rFKXMgDncsmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i1EurU08; 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="i1EurU08" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D8A5C4CEC7; Mon, 2 Sep 2024 18:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301575; bh=KHZYZ927+7yyV5GBG+foExygJP99hAl19iC2HtCS618=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=i1EurU08DZIp/nlyUwc79oX+gJV/NmUqM23pKipAMhu3SUb0kQRuRIwg/Kw+LzPuU FnLYT7rS0ejWEhtXJrIHaG7N8g80xC9c1+7npQGsLgLjgBrAdGb1Q7lAykhUQmrCqS qWaRpZWaYKtHVML3YjY/cFU7HPZ0RI2H8wJoZE+Rd+bfZRHdRts2COJZQH8rOIJOG/ 0c+OKUnp5ZZz+MFjN1EyoTMfGFDserZSZPfi5xtU+Th5ZOhxejRzR9W9XIe85D2Fcd vxcQd+hk240dxzmWsRr4ySj0GmjZe5NC3UKhkno1YVEmOejU4+pDBF02p8aLc642RB BNiAG91MTDfSA== Date: Mon, 02 Sep 2024 11:26:15 -0700 Subject: [PATCH 09/12] xfs: factor out a xfs_growfs_rt_bmblock helper From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105864.3325146.154561084498822609.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 59e599af74f4..febd039718ee 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -805,9 +805,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. @@ -820,23 +959,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; @@ -855,11 +985,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. */ @@ -872,15 +1001,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; @@ -889,17 +1017,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, @@ -927,149 +1053,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); @@ -1081,11 +1085,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 Mon Sep 2 18:26: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: 13787596 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 8319819CC0A for ; Mon, 2 Sep 2024 18:26: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=1725301591; cv=none; b=MGYifsHsIyw5HTraAQm7Qj0ePLPN0nvQMayng3WZNYgh4lrkwDLba3TMal30BFmGCEw1opHCYghz7DiDlcvKRDPBh4rL3c2sFDBUgdhRJQV57qsTuAQCMyw9QZSgtqiwGS/jfd45CSwfq5fdk+o30dQY9z3gby9D3ApZcErMDHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301591; c=relaxed/simple; bh=gz9mvcBNrKM8wp+CbBRRfrEthdil0oyVGQaATShjTu8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NGwpttZn8fBIgwLApw8sFXUlLU4O8aDTpb0TkCce+2s2ATH+SzzhDcixpgzR95uW3CqXECRdIpsanQEyrTjyCMyKCNdeaGJHAY/ZThpxMdVFHlZzBR+4Fe+V3EUCFReCK2nX6vVr+c8TMXxJtjb99XT0vb5qR93EpisBS7mcvbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vPYv5pQH; 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="vPYv5pQH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A6DC4CEC2; Mon, 2 Sep 2024 18:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301591; bh=gz9mvcBNrKM8wp+CbBRRfrEthdil0oyVGQaATShjTu8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vPYv5pQHIhTRBQLNZ5ys4wVBS5IMyxF3i3xmykWpY4j/m8Ha1+JfJB1S6zmn0S+Zf sizRcCtK4qA38FxqfWGuuSAZYBFR8N5pZWXHWK1KfkAv5x/TrhQPw6Pb+O95a/rovT fXTnPP4GsJPd6g73S6O2zMeXxqP8KEB1r1ZAD0A7pa019yazqmGBHbLrxFp+w88xjr ADyiZu+AXQP7KNY+qC0HPuC01QYoZqaQYfxl+7R1+1THMMclJ9r6LCwdHY9cDwKzUV 21XC88uBNF8iNHNXjQQ7tNubgiZlqEbv37vR4/XtWo3VZQyYK6Kt6ahOa5x0Xcm+B4 qyMICO4tPduhQ== Date: Mon, 02 Sep 2024 11:26:30 -0700 Subject: [PATCH 10/12] xfs: factor out a xfs_last_rt_bmblock helper From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105879.3325146.1820867524326666305.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 febd039718ee..45a0d29949ea 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -948,6 +948,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. */ @@ -1059,16 +1076,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 Mon Sep 2 18:26: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: 13787597 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 817E519CC01 for ; Mon, 2 Sep 2024 18:26: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=1725301607; cv=none; b=pJwAf18uIb9Vp8mmWB/EwrBuz1L5ahrYOVjwgObfA3oJWPkJPk1qEN3QZdbwdNtIlNV9aR3UWt3tM2q12ZauHoPZWK58vlHsXexRT2skNxjeEO2rXdqi6HIWONZ+CnlBdLOQFN/QtwfNubsJwivzc6vut/dcWn5UcSQUFqikvs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301607; c=relaxed/simple; bh=QHkDHUOwTuaE1l3De4HUNIMpS1+h1kjir6H+ZT8VT5g=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XMTekuJuWYtvsfo2EHENDMlrXMqslq/kIC3XTQzDU+BUBUIrbpco6EcZD8SEaLRH/S7Jpgxl0sZQtuGXgb4bPS4owDOAjiPwXDrVpcR6zGukVQifiYyz+zvDU+ziCrVAMdSbl1ZpsU25nWnbrbUw49yTbl1bYzjmNmxHNfjpMW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MCNSB9P1; 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="MCNSB9P1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E0A4C4CEC2; Mon, 2 Sep 2024 18:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301607; bh=QHkDHUOwTuaE1l3De4HUNIMpS1+h1kjir6H+ZT8VT5g=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MCNSB9P1ycFnMr/Glu/0bZHveDYbdbn9djZULrDGH/2e/Ew/TAVrYXxp29C13z056 XFluJbbhsPWqz+May7fXHou9tTMKGTims2ZP/RClUybTX+2GBrN5jrwslrzV07RC60 VUNPvb1aEG7z78SU77MPJ2RdmlLd9cs4R8uWeYcCmiEeHtC23VrweKAlXDDIs8nfPl skep9YWN65e3H60NkjkOoqBG8fqvIXXCu4dQUjavZhe75zL0jmjXn9UPgTLKSXsxvJ nfkVIWG8GbmAKoFZ/IlJFInijcrFoSkYI0BL3c+JKfuFJ/dVvXyZGnXpTkbyEMB5VL sXiORoBSFHBhA== Date: Mon, 02 Sep 2024 11:26:46 -0700 Subject: [PATCH 11/12] xfs: factor out rtbitmap/summary initialization helpers From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105896.3325146.12802416528674832541.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 02d6668d860f..715d2c54ce02 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 e87e2099cff5..0d5ab5e2cb6a 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 45a0d29949ea..114807cd80ba 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -641,121 +641,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, @@ -1062,10 +947,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 Mon Sep 2 18:27: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: 13787598 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 2AF0519CC01 for ; Mon, 2 Sep 2024 18:27: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=1725301623; cv=none; b=niGir1xs/JYbOF4bSudF0xmCaQBUH3ox6HVmsRHGF3nWwa1yCWkReR7p8zNeqnnS+nSBE/4r1FNOqKh5l2e2eQ46HjhEF+GzSBWZsh9UlK3gI5xTGjHsdbPuIZQmtYmkWBlb0KdQDOl9iw1DZ18hLpZY4i5e/+KKaILLBaG8eAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301623; c=relaxed/simple; bh=vll+YiwWDzOS1k9+LF0fxb4ZwegCBoNmuHScKA1npLw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RP3/xFNW9ndty03TDzNKvZmnyBoNhnXOtDlG0l/k9TWTkuteoBnvjbBQHIGm77Hz+hFM9zO3o0CfkV2+L49YrGp332KGwO082LFdujAZfK03bP0baNs+P2wDgfE0dsVQBsqQAPqQ9pf7Mv3QA2tJhWAu7BW8nfNQO6AYVksycKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gipQ1UYg; 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="gipQ1UYg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF4BDC4CEC2; Mon, 2 Sep 2024 18:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301622; bh=vll+YiwWDzOS1k9+LF0fxb4ZwegCBoNmuHScKA1npLw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gipQ1UYgkKSCR41p1Aqznh+/DPUbgKLrLAjdvkRsk3x4/4ckxMQuESKmbRhZCyC43 YQuoT7QiFJWHZe7md8E0LD+sgw5AdkRFRWds+zuBBrJfFQ1/Ds/FYVyKIzgknb0hnb K/cr70y4auMPmXTHYLauG37mkCSiMcgzHauAPo8N7tunza1rZNf2/Ejd4trX1R9Mjj SXuKCf7Ev/Wva/2PEaiHDDGITG1LEHOCu9S8vKOjretr7OO1p/2I1Q3GLeDU424XwR aSSwEI8ZnnqxU9CiMUWSSyQb94xojXIyZdFp0JKkf8SGP3wL+VsnEhkcdkNwfSyz5b QCGh3DGErl0Hw== Date: Mon, 02 Sep 2024 11:27:02 -0700 Subject: [PATCH 12/12] xfs: push transaction join out of xfs_rtbitmap_lock and xfs_rtgroup_lock From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105912.3325146.12989713947634840583.stgit@frogsfrogsfrogs> In-Reply-To: <172530105692.3325146.16430332012430234510.stgit@frogsfrogsfrogs> References: <172530105692.3325146.16430332012430234510.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 7df74c35d9f9..112c7ee2d493 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5376,7 +5376,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 715d2c54ce02..d7c731aeee12 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 0d5ab5e2cb6a..523d3d3c12c6 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 114807cd80ba..d290749b0304 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -739,7 +739,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 @@ -1313,7 +1314,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; }