From patchwork Mon Sep 2 18:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787599 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 8DACD19CC1A for ; Mon, 2 Sep 2024 18:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301638; cv=none; b=gx/MZTnfedBGKQk6DDQh1YD0T6DZjym5RfRNFuElFdV8umtAKC1bXXYFm3SHxKlIAwzd0LVvEJy/6nVci/q91GQRDRz/NINvv7quuWH38iyL9wrOugWkZFALqHibpeu9eU079O/8KpwhKneA5wAj/+QO/y9ezBwMceLpppMNyjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301638; c=relaxed/simple; bh=Xq2CVfXq5/jH5OWoyy+QoB4g7ZrcptOrUS/7WMrWFMk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dQK7UwkA72eIaYQ5jhwdldDRsm1L7AKsvPj2E/isoROAItpKjeqMi9C2llUoDbtugkEn1UVMx0UtxogSJ+M0qOZ5hpaR7WcWnmu3+B//V7vBu1icMwO0rxXNWoiIlspw2661PjW0BPULU+gMh/GLAltz7wY/uCfDL5Z2YjN3t2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JWEoYQe4; 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="JWEoYQe4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63CD4C4CEC2; Mon, 2 Sep 2024 18:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301638; bh=Xq2CVfXq5/jH5OWoyy+QoB4g7ZrcptOrUS/7WMrWFMk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JWEoYQe45okZqm9NSSADBUyTBtt9ZxxZE8YwTQ/xo8IDVeTZQ9SfJsginFN3DYSdj NEj4KiJEQUm+nYDkVmB9fF5plHtAkS/MJmHlQ0q8FnGhhHsFsW+HsR34L/9qZvVWbF 27jyH0LmDb2p/s1Xfrq5efXR7MLdSig/Gdweek5ldP+okZDC1l7KBIv3VDt67/38sa c+sYavk7adTPFuDaJb9roxTMWr757NudSFutNojl6KDRazLl4auLcvz/qZi+IThvUt /5d1leB60iPSZocmk6xmfB5rvakEj0QEjSxYgzXT4yNHAfXF5pK9r/yPFiHHJok8H7 sU4A7zCxVTm5w== Date: Mon, 02 Sep 2024 11:27:17 -0700 Subject: [PATCH 01/10] xfs: use the recalculated transaction reservation in xfs_growfs_rt_bmblock From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106275.3325667.10445292103387033909.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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 After going great length to calculate the transaction reservation for the new geometry, we should also use it to allocate the transaction it was calculated for. Fixes: 578bd4ce7100 ("xfs: recompute growfsrtfree transaction reservation while growing rt volume") Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index d290749b0304..a9f08d96f1fe 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -730,10 +730,12 @@ xfs_growfs_rt_bmblock( xfs_rtsummary_blockcount(mp, nmp->m_rsumlevels, nmp->m_sb.sb_rbmblocks)); - /* recompute growfsrt reservation from new rsumsize */ + /* + * Recompute the growfsrt reservation from the new rsumsize, so that the + * transaction below use the new, potentially larger value. + * */ xfs_trans_resv_calc(nmp, &nmp->m_resv); - - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtfree, 0, 0, 0, + error = xfs_trans_alloc(mp, &M_RES(nmp)->tr_growrtfree, 0, 0, 0, &args.tp); if (error) goto out_free; From patchwork Mon Sep 2 18:27:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787600 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 36FCF3D7A for ; Mon, 2 Sep 2024 18:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301654; cv=none; b=uSRkU41fr2MVOpFCN2JoPHCjnGhHp7FMlMMxVKUZ4HEbhyGlUEXvcGmVPOjdB+HjaYT7mPTvaKdkHWtuDXDk8gJ98ZgMXGU+6aVI3twsXJnGNLlNX7KEmru1ySqyntaSGmYJ8n0atjdppt9pqZBW+8e9ofaomac4U+Jwsjc2sM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301654; c=relaxed/simple; bh=tjlWmGjkR52OhhgMTuBYmKtpp/NyJTXxAsU3PEsSLR4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VPXvBFELZqYuwJoSSPO2jJBELgSqoKgs6Q96Hgp+ElM4u3nBmCKq3ZRwJdJne55h/P2VGcygLSZyWteC4w9yAzbMCNdXYlY7tiCI4M8VX0ZvR92qnr5QZf0p3Yh5RaBbUKlq9lhV8JNMFmuhgPR2ozoUqdNCVg0vV2fZdkyk7Ug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B4ol3Krg; 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="B4ol3Krg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12D25C4CEC2; Mon, 2 Sep 2024 18:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301654; bh=tjlWmGjkR52OhhgMTuBYmKtpp/NyJTXxAsU3PEsSLR4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=B4ol3Krgnpr/dbUu08hjpe0FwbqrXhCXdDsGKUEaOqy09IMhyp9p6AFTg3b7rvcjZ ynoQ84OjUcufJvEg5wtLcFuMt58/v96e6l/wUGz4NuF0vcDsZFn5x4pQrrtw/k5dgo 9zBP0Uir/8xe5M5ImT4SrUxYZlAJiBD0jkyJn77geIf9TtJDidjHbGG3f/N+6JQU94 2ePy6aSqfRyAiXnzG02CdqwaXbOUyfJ89SIvZfpSD+Jl8080IB9lA+7F1WH2nkByFC GLs7kTU29AZIpE6P9VeSujog5sWGh5z7pXx+wf71qRurqlfTT5oPzT3VVGN0ZvKOD9 qzuP0Mcqlx7vQ== Date: Mon, 02 Sep 2024 11:27:33 -0700 Subject: [PATCH 02/10] xfs: ensure rtx mask/shift are correct after growfs From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106292.3325667.13014911083029207640.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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 When growfs sets an extent size, it doesn't updated the m_rtxblklog and m_rtxblkmask values, which could lead to incorrect usage of them if they were set before and can't be used for the new extent size. Add a xfs_mount_sb_set_rextsize helper that updates the two fields, and also use it when calculating the new RT geometry instead of disabling the optimization there. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_sb.c | 12 ++++++++++-- fs/xfs/libxfs/xfs_sb.h | 2 ++ fs/xfs/xfs_rtalloc.c | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index f9c3045f71e0..a6fa9aedb28b 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -965,6 +965,15 @@ const struct xfs_buf_ops xfs_sb_quiet_buf_ops = { .verify_write = xfs_sb_write_verify, }; +void +xfs_mount_sb_set_rextsize( + struct xfs_mount *mp, + struct xfs_sb *sbp) +{ + mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); + mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); +} + /* * xfs_mount_common * @@ -989,8 +998,7 @@ xfs_sb_mount_common( mp->m_blockmask = sbp->sb_blocksize - 1; mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; mp->m_blockwmask = mp->m_blockwsize - 1; - mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); - mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); + xfs_mount_sb_set_rextsize(mp, sbp); mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1); mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0); diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h index 796f02191dfd..885c83755991 100644 --- a/fs/xfs/libxfs/xfs_sb.h +++ b/fs/xfs/libxfs/xfs_sb.h @@ -17,6 +17,8 @@ extern void xfs_log_sb(struct xfs_trans *tp); extern int xfs_sync_sb(struct xfs_mount *mp, bool wait); extern int xfs_sync_sb_buf(struct xfs_mount *mp); extern void xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp); +void xfs_mount_sb_set_rextsize(struct xfs_mount *mp, + struct xfs_sb *sbp); extern void xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from); extern void xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from); extern void xfs_sb_quota_from_disk(struct xfs_sb *sbp); diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index a9f08d96f1fe..4bbb50d5a4b7 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -719,8 +719,8 @@ xfs_growfs_rt_bmblock( /* * 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; + xfs_mount_sb_set_rextsize(nmp, &nmp->m_sb); 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); @@ -807,10 +807,11 @@ xfs_growfs_rt_bmblock( xfs_trans_mod_sb(args.tp, XFS_TRANS_SB_FREXTENTS, freed_rtx); /* - * Update mp values into the real mp structure. + * Update the calculated values in the real mount structure. */ mp->m_rsumlevels = nmp->m_rsumlevels; mp->m_rsumsize = nmp->m_rsumsize; + xfs_mount_sb_set_rextsize(mp, &mp->m_sb); /* * Recompute the growfsrt reservation from the new rsumsize. From patchwork Mon Sep 2 18:27:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787601 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 2FC9719CC01 for ; Mon, 2 Sep 2024 18:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301670; cv=none; b=Dta73pnB5LtdxuiVY2zBqhiAgx0VCp9N/jFDqFl142DyanUUf1F0qTpYnLFEReC6PR+9t2EPl0czh8OLwo4kVtt3WT5itEbN9hBFJJN1Dv8zrJMcCnMpUPQz4QZwQTA610GPZWQoAZVgpW3CIqwr3sN199Ql8eaucTRaYJSBlzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301670; c=relaxed/simple; bh=SJBW7y5P4k09cJeC63tXqABJUnlR9tq/2WaCcAYh4ow=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QBLsPhCtXeJxnXXvQg9OSoKbEXwfjrqW0XfE5yf9FfjcVlmwHV2ybe95FBhwzAoD2ULbdMfCIFY1T9rd/qtPL2y+dCZ5otxRJoQjGneNd/baWjbpV1SAAW8FiduJU2Sga9OLl32BzcpS2kUMSXHmOy3PhxB/nf/yD+0GYov3jOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LDrMCZum; 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="LDrMCZum" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADB80C4CEC2; Mon, 2 Sep 2024 18:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301669; bh=SJBW7y5P4k09cJeC63tXqABJUnlR9tq/2WaCcAYh4ow=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LDrMCZumcOhjzxQyrUngAyZtFuxFshS23aSy9cprtjI//LeawXYyS5urGpFUPt2ei OWoU7aoG4/2hldKjDJcP3aHPyPly897ds1FVv6p+xfnn4u9aQqgqiBep6Q/Bh6+BvM VinzB/m04bruv8IRRu1mUnfufifS/OpB8xGmBIRwd2jFwvxTezwjdGvmAWLa7SEAcs hXDpWi+MiLNVDw5UfHhz8y3RZGDHeVBpbvUJq3s53isgMPtt07AvAuPLc0ahO0dMXM 0v9tjraaSsRculCmbXhzShj/2rJ4z3c3pBOFI8F3ceJ4iEMODmk73zmeI1dEZykPlU giG9gRJlQlDMQ== Date: Mon, 02 Sep 2024 11:27:49 -0700 Subject: [PATCH 03/10] xfs: don't return too-short extents from xfs_rtallocate_extent_block From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106308.3325667.11584195823309747266.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong If xfs_rtallocate_extent_block is asked for a variable-sized allocation, it will try to return the best-sized free extent, which is apparently the largest one that it finds starting in this rtbitmap block. It will then trim the size of the extent as needed to align it with prod. However, it misses one thing -- rounding down the best-fit candidate to the required alignment could make the extent shorter than minlen. In the case where minlen > 1, we'd rather the caller relaxed its alignment requirements and tried again, as the allocator already supports that. Returning a too-short extent that causes xfs_bmapi_write to return ENOSR if there aren't enough nmaps to handle multiple new allocations, which can then cause filesystem shutdowns. I haven't seen this happen on any production systems, but then I don't think it's very common to set a per-file extent size hint on realtime files. I tripped it while working on the rtgroups feature and pounding on the realtime allocator enthusiastically. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 4bbb50d5a4b7..c65ee8d1d38d 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -289,16 +289,9 @@ xfs_rtallocate_extent_block( return error; } - /* - * Searched the whole thing & didn't find a maxlen free extent. - */ - if (minlen > maxlen || besti == -1) { - /* - * Allocation failed. Set *nextp to the next block to try. - */ - *nextp = next; - return -ENOSPC; - } + /* Searched the whole thing & didn't find a maxlen free extent. */ + if (minlen > maxlen || besti == -1) + goto nospace; /* * If size should be a multiple of prod, make that so. @@ -311,12 +304,20 @@ xfs_rtallocate_extent_block( bestlen -= p; } + /* Don't return a too-short extent. */ + if (bestlen < minlen) + goto nospace; + /* * Pick besti for bestlen & return that. */ *len = bestlen; *rtx = besti; return 0; +nospace: + /* Allocation failed. Set *nextp to the next block to try. */ + *nextp = next; + return -ENOSPC; } /* From patchwork Mon Sep 2 18:28:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787602 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 E219719CC01 for ; Mon, 2 Sep 2024 18:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301686; cv=none; b=RODtCulCLmpKDBxjlDy4rr/eHB3AMf3E9rr1YFVNoBTTNKRh6zExFB9hoy4x6dQ1wkg3IG10QjwDGFh9jfETJg4uCT4u11dcF2uTs7GbWgOBHLY/s47iCI57f1GRSh5Rmkal5cs43weanVwyZYNkpsoeK2d6yCZCmV/f3BHjLb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301686; c=relaxed/simple; bh=89vM3RFVE+tcTmJjPeOCaaJWn65IA/Qe4Geyg6AOX9s=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C53auXTWRKr+byNGOlhS/WzA7iF0elVPo9hErkGlg1voDZJgnaG7HxAA1kPoqqFE7NSrnwbZWF7OO3suW3lv1+eVUVzJtLljkmjDc62PswJGlHSqgh7vgfd5S9/9ZiW2AlYpAlU+mB2aGVjy+2YFikLElmXVARKjun7NQtCfG9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lwIdVrzx; 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="lwIdVrzx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61885C4CEC2; Mon, 2 Sep 2024 18:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301685; bh=89vM3RFVE+tcTmJjPeOCaaJWn65IA/Qe4Geyg6AOX9s=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lwIdVrzxFeauvtNN+qMrrjetwBazwrINbp7vLdU2GUZ0+tGj0zBs7p61W4RE98kx8 CqCYUfyJ5W+LJiayaKiPSF+E37BLUkaTS6i/cgV9THTBTy1t54BrjvpRjeOcKg9r0K S+b4WbRXm3gRw7n9vDfGCamNmN52JnGIMfsFd+WF7kMgTRFfVc5cq+g/0yzmXSVEE8 kjcM4MW//ilfmfM9SQYFOG1ZVPFiSZpcs+SXZe35vinWmv7pdPXB1COUr6PtEhod3o nFq6ceXoNt+DzuVKjinCj8k75wU7/AfzktucA5hmIcuHAxvKBRJPc0fI3wbFKJXq5w k2B+BX69lLX6Q== Date: Mon, 02 Sep 2024 11:28:04 -0700 Subject: [PATCH 04/10] xfs: don't scan off the end of the rt volume in xfs_rtallocate_extent_block From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106324.3325667.17423376504109071004.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong The loop conditional here is not quite correct because an rtbitmap block can represent rtextents beyond the end of the rt volume. There's no way that it makes sense to scan for free space beyond EOFS, so don't do it. This overrun has been present since v2.6.0. Also fix the type of bestlen, which was incorrectly converted. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index c65ee8d1d38d..58081ce5247b 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -229,22 +229,20 @@ xfs_rtallocate_extent_block( xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { struct xfs_mount *mp = args->mp; - xfs_rtxnum_t besti; /* best rtext found so far */ - xfs_rtxnum_t bestlen;/* best length found so far */ + xfs_rtxnum_t besti = -1; /* best rtext found so far */ xfs_rtxnum_t end; /* last rtext in chunk */ - int error; xfs_rtxnum_t i; /* current rtext trying */ xfs_rtxnum_t next; /* next rtext to try */ + xfs_rtxlen_t bestlen = 0; /* best length found so far */ int stat; /* status from internal calls */ + int error; /* - * Loop over all the extents starting in this bitmap block, - * looking for one that's long enough. + * Loop over all the extents starting in this bitmap block up to the + * end of the rt volume, looking for one that's long enough. */ - for (i = xfs_rbmblock_to_rtx(mp, bbno), besti = -1, bestlen = 0, - end = xfs_rbmblock_to_rtx(mp, bbno + 1) - 1; - i <= end; - i++) { + end = min(mp->m_sb.sb_rextents, xfs_rbmblock_to_rtx(mp, bbno + 1)) - 1; + for (i = xfs_rbmblock_to_rtx(mp, bbno); i <= end; i++) { /* Make sure we don't scan off the end of the rt volume. */ maxlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod); From patchwork Mon Sep 2 18:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787603 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 2F56C19CC01 for ; Mon, 2 Sep 2024 18:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301701; cv=none; b=Ak/IZHlyZpyYHLN9iGsUpLem74UOoen/d1LTlbI6MugAiVJUUK8PhC/HPbGmMMwFD3UWGq4h9oh+0akVqOshQooV9pw7EcozQuA3lA1XW+ZQpEc18juiWmrZxnYiVQJVB4nUcZyvsflP8YJKJcRdbFb8K9vAf91K8N1KHyvHoDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301701; c=relaxed/simple; bh=XkCkUJuVh+ssGc433Kd37Lt/P8FkkU33xZj5mRnWFFs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EeXWHoB7RPR9AEOxShwrze0CMrmG87s3nkXVG9XJI4AcV1cN5v4W8VWp6CUpyKdvfKZcz/PEcprBMV1ZAErUrOE+0LXAXxh4JzZErECqk5/JK8kLcJz2I2zbYR8443thHxZz6n9JmSt7kzoKi7BuulCsPFsfriAlD1thipTop/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ID5+DFs6; 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="ID5+DFs6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2CDFC4CEC2; Mon, 2 Sep 2024 18:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301701; bh=XkCkUJuVh+ssGc433Kd37Lt/P8FkkU33xZj5mRnWFFs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ID5+DFs64T4pYgX27NSmCRbUAdNzUjuh+/fXsQQxZfDT4TW8jtUsuTBYmCWYIuacd jnPTtDy7C5OKizNIr2K8EIekebvoqs5350E93WCQWjg0zCQQV4m/m+xhIBacIv5/lW kbkzh681J3xVpyuzQPKChcdZU8204+JXJ/em6iSm976CMFaq4+zqiUhnDfXKkg4zjH uz0B34+T9T6zg+LhgbUeGeKCXH0l/KuYTsK3R9VU+h+oLPLBMfd1l+9mwj3zOP7Hd3 2dmCZuYYo/b/G2rWzx50I5NU+j+ImFT6nvSFM+8sS5XuKIvISFgwwmwV2L00e700Ie 1pxPG/pYn4tOQ== Date: Mon, 02 Sep 2024 11:28:20 -0700 Subject: [PATCH 05/10] xfs: refactor aligning bestlen to prod From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106340.3325667.13658709448715994650.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong There are two places in xfs_rtalloc.c where we want to make sure that a count of rt extents is aligned with a particular prod(uct) factor. In one spot, we actually use rounddown(), albeit unnecessarily if prod < 2. In the other case, we open-code this rounding inefficiently by promoting the 32-bit length value to a 64-bit value and then performing a 64-bit division to figure out the subtraction. Refactor this into a single helper that uses the correct types and division method for the type, and skips the division entirely unless prod is large enough to make a difference. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- 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 58081ce5247b..11c58f12bcb2 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -194,6 +194,17 @@ xfs_rtallocate_range( return xfs_rtmodify_range(args, start, len, 0); } +/* Reduce @rtxlen until it is a multiple of @prod. */ +static inline xfs_rtxlen_t +xfs_rtalloc_align_len( + xfs_rtxlen_t rtxlen, + xfs_rtxlen_t prod) +{ + if (unlikely(prod > 1)) + return rounddown(rtxlen, prod); + return rtxlen; +} + /* * Make sure we don't run off the end of the rt volume. Be careful that * adjusting maxlen downwards doesn't cause us to fail the alignment checks. @@ -208,7 +219,7 @@ xfs_rtallocate_clamp_len( xfs_rtxlen_t ret; ret = min(mp->m_sb.sb_rextents, startrtx + rtxlen) - startrtx; - return rounddown(ret, prod); + return xfs_rtalloc_align_len(ret, prod); } /* @@ -292,17 +303,10 @@ xfs_rtallocate_extent_block( goto nospace; /* - * If size should be a multiple of prod, make that so. + * Ensure bestlen is a multiple of prod, but don't return a too-short + * extent. */ - if (prod > 1) { - xfs_rtxlen_t p; /* amount to trim length by */ - - div_u64_rem(bestlen, prod, &p); - if (p) - bestlen -= p; - } - - /* Don't return a too-short extent. */ + bestlen = xfs_rtalloc_align_len(bestlen, prod); if (bestlen < minlen) goto nospace; From patchwork Mon Sep 2 18:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787604 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 15F8A19CC04 for ; Mon, 2 Sep 2024 18:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301717; cv=none; b=auRKO8cCpjH+6m2Xzbp78G3UpagrM/x5fPXyGvJbjfJRMLdQUhLoZ7zovDLyjxVR05xL+tdFvxDE/rgmNfjfzGPByiGy5aOMu3p2+ecqrFHTwQHuOC/EQLsx1zts6+cVHwqi0rypl/XztKIzOd+3JbX78tudyqNf4jb7hwDpob8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301717; c=relaxed/simple; bh=t6tPc6p8TS2/3b/EvqtjVnEdumgRX+NfYyiWT2vFMOk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V3sg9ISjJrku1rBG/yfqWQ0H8OZPWwUvCR9y6UvypiSPVSdg7ab+L9fLyHKjZvJleFyuDe3DL0tF1Cxo3xK8HIl+K97W5zzH4yYLj4l05/YOiKMgp4u6vsUIcB5i3avftiORfR8eYKXyKYPIQ6E9ZID5EUsQQggNhUxcN0xq7iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PhwLH+Vl; 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="PhwLH+Vl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9569AC4CEC2; Mon, 2 Sep 2024 18:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301716; bh=t6tPc6p8TS2/3b/EvqtjVnEdumgRX+NfYyiWT2vFMOk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PhwLH+VlVw4RYEIQUVJaghek8bIKVdJQsh44+RYfq4Riej5tSyZ17rRM3gR2YCdAy rRcs+hX8SUmKzFxZ6BeZJyIuPlLXVoAE+VTetZsQftAz8Wvq8JpRbrt937jgPFlsqN fIYXKaD5dKT4kGXp5jtBl2Ui+hNdkAJPcVZe2I1CPVK6lt+LcmhKrUyPcITywoR2xb RyxUrXwm/UnNiCEmgW2KwGgVRDUpW0PX4C2OeMxhDDl8TO9ZzA5NGgQyCGSXj2s7ic PxmnUWGgylx81kRUDHCBBLizV5+OF8o5zfrVRihSnOz92uvGxYufrzhDwj+bVkYnX8 W91o882UTa+NA== Date: Mon, 02 Sep 2024 11:28:36 -0700 Subject: [PATCH 06/10] xfs: clean up xfs_rtallocate_extent_exact a bit From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106357.3325667.17804735130300124284.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong Before we start doing more surgery on the rt allocator, let's clean up the exact allocator so that it doesn't change its arguments and uses the helper introduced in the previous patch. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 11c58f12bcb2..af357704895d 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -338,10 +338,10 @@ xfs_rtallocate_extent_exact( xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { - int error; - xfs_rtxlen_t i; /* extent length trimmed due to prod */ - int isfree; /* extent is free */ xfs_rtxnum_t next; /* next rtext to try (dummy) */ + xfs_rtxlen_t alloclen; /* candidate length */ + int isfree; /* extent is free */ + int error; ASSERT(minlen % prod == 0); ASSERT(maxlen % prod == 0); @@ -352,25 +352,26 @@ xfs_rtallocate_extent_exact( if (error) return error; - if (!isfree) { - /* - * If not, allocate what there is, if it's at least minlen. - */ - maxlen = next - start; - if (maxlen < minlen) - return -ENOSPC; - - /* - * Trim off tail of extent, if prod is specified. - */ - if (prod > 1 && (i = maxlen % prod)) { - maxlen -= i; - if (maxlen < minlen) - return -ENOSPC; - } + if (isfree) { + /* start to maxlen is all free; allocate it. */ + *len = maxlen; + *rtx = start; + return 0; } - *len = maxlen; + /* + * If not, allocate what there is, if it's at least minlen. + */ + alloclen = next - start; + if (alloclen < minlen) + return -ENOSPC; + + /* Ensure alloclen is a multiple of prod. */ + alloclen = xfs_rtalloc_align_len(alloclen, prod); + if (alloclen < minlen) + return -ENOSPC; + + *len = alloclen; *rtx = start; return 0; } From patchwork Mon Sep 2 18:28:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787605 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 58A955680 for ; Mon, 2 Sep 2024 18:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301732; cv=none; b=lx49MehRgKtVotno1lHnqCt6CxsVuC8GhvFHVoxelhcVnQrMUq9K4NApFMAZGF4vak71kGWHQ2Pf70meERS9gZS2K6n6lC9qE91XRzYRfFXg8q6BA7Ibpnxvieb+8yutW9Nx6h3FFP138uqGIh3SYt61OVv9QqYViAxUGZcdW8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301732; c=relaxed/simple; bh=U1VhHsU7ZONDqTwVBFS6swHjKxPOKhSxxvXPdrrEeR0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NAbAyPt/XyHbibf/PhP+lraYaaV3YnhKgaUD26tY0G4QX3X/YhaKoFAZqdc9nQc9x8mPGqAdRvgtR9lWtmheb5U11K3fDVXJohi+1HfzeOPK10CuBF/DSn8szs6GfXexrIvAN7qesy515gx40446yrCD1jzZ7Vlx6f0gENPuNKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VBn0YY+6; 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="VBn0YY+6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A345C4CEC2; Mon, 2 Sep 2024 18:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301732; bh=U1VhHsU7ZONDqTwVBFS6swHjKxPOKhSxxvXPdrrEeR0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VBn0YY+6+a5QJloyHpp6IPWKRjzakDG0VAe3YRaQMmGyS9NZQQ50gwJqTGvnUhQLC hwhQ6AvCrzKE79wqQeMEcOz4i7wasl5RI/r3Sgv6sFxB4Ygn25+mKzRBPrJAEQfpqV lUGFoqtCkDjztIh4FlNkOSfOHwdgPCZNMeBBun3dTdcAoPFZX86cAMrEs3cicXgrTP kJNsq/8PsGYmqLg+6+vOGkwh5DZuEQUqYgUvxX747DWDA1s3yj1FNI9YjWyUr/orI2 +ljUn0z00rraUFc5MZ6LFCFSnSIUgA0c4FshKkclWTnDd64UzrusvP7ub8a6vc8GZc DiqQKe1xoO7MQ== Date: Mon, 02 Sep 2024 11:28:51 -0700 Subject: [PATCH 07/10] xfs: reduce excessive clamping of maxlen in xfs_rtallocate_extent_near From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106373.3325667.13490918837169434701.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong The near rt allocator employs two allocation strategies -- first it tries to allocate at exactly @start. If that fails, it will pivot back and forth around that starting point looking for an appropriately sized free space. However, I clamped maxlen ages ago to prevent the exact allocation scan from running off the end of the rt volume. This, I realize, was excessive. If the allocation request is (say) for 32 rtx but the start position is 5 rtx from the end of the volume, we clamp maxlen to 5. If the exact allocation fails, we then pivot back and forth looking for 5 rtx, even though the original intent was to try to get 32 rtx. If we then find 5 rtx when we could have gotten 32 rtx, we've not done as well as we could have. This may be moot if the caller immediately comes back for more space, but it might not be. Either way, we can do better here. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index af357704895d..d27bfec08ef8 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -338,23 +338,29 @@ xfs_rtallocate_extent_exact( xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { + struct xfs_mount *mp = args->mp; xfs_rtxnum_t next; /* next rtext to try (dummy) */ xfs_rtxlen_t alloclen; /* candidate length */ + xfs_rtxlen_t scanlen; /* number of free rtx to look for */ int isfree; /* extent is free */ int error; ASSERT(minlen % prod == 0); ASSERT(maxlen % prod == 0); - /* - * Check if the range in question (for maxlen) is free. - */ - error = xfs_rtcheck_range(args, start, maxlen, 1, &next, &isfree); + + /* Make sure we don't run off the end of the rt volume. */ + scanlen = xfs_rtallocate_clamp_len(mp, start, maxlen, prod); + if (scanlen < minlen) + return -ENOSPC; + + /* Check if the range in question (for scanlen) is free. */ + error = xfs_rtcheck_range(args, start, scanlen, 1, &next, &isfree); if (error) return error; if (isfree) { - /* start to maxlen is all free; allocate it. */ - *len = maxlen; + /* start to scanlen is all free; allocate it. */ + *len = scanlen; *rtx = start; return 0; } @@ -410,11 +416,6 @@ xfs_rtallocate_extent_near( if (start >= mp->m_sb.sb_rextents) start = mp->m_sb.sb_rextents - 1; - /* Make sure we don't run off the end of the rt volume. */ - maxlen = xfs_rtallocate_clamp_len(mp, start, maxlen, prod); - if (maxlen < minlen) - return -ENOSPC; - /* * Try the exact allocation first. */ From patchwork Mon Sep 2 18:29:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787606 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 31E0819CC04 for ; Mon, 2 Sep 2024 18:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301748; cv=none; b=YqEWp5QfnQnxZS+kPBy2kn1IQEB0DYEZB+ty02hkvMKXCw866rMik1a/qU8WNp6qhq0f40HEB7cMA31XMkkjz5qs3xqJZTVVeD4mW4dGG9p7Y7tQnDpYa+WZrESB8coyMHKfhP//jCv1iLlJgvElbvby2L+se/ofe2zvUamavbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301748; c=relaxed/simple; bh=3sIdlBYkG592+tuhX8+J4D0TGI3nZiv6KsmPJX8bEa0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A9CRu2V4cX6f4PhvTY3bjr0MklrcAeKk4sGBu2DOF35EcQSfCpROt1HEavci+colIUfK7PEkHZJ5US1370c0dE4QQ+TRoxNODHerqNvbs1SmX33H9zXkV/SaII9oyBaKf6CY30BmOaZCLjaMl9zI6I5/EobS1PHpx85bsh3D7HQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dz7OdJh+; 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="Dz7OdJh+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D119AC4CEC2; Mon, 2 Sep 2024 18:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301747; bh=3sIdlBYkG592+tuhX8+J4D0TGI3nZiv6KsmPJX8bEa0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Dz7OdJh+wtPqAySWE3FEhS0FAkBxrp2vKXfnzB8k/d9GnkanLCQTev+w5o01+lJyj 5Ncp3VPjAS5+7NjmsvixaUHRPgdlhyw2jNxGSVuiO5+a8mC1Ep+L6VGJYtQoAK4IX/ caE389wqQujtVweHyZgg3g5QWjxQSB/yAmd8lY6D+GGI4LS4DYn8xce5J72ok05K0v ELsTpdJ9Hj9aQmBl8sswAyP/W0QYAPPwBDFoxlJIa47+r3qldHqW0Wn+9zhaKdZFca NRvhbysfydVnS+YxwZgLgDVF2w+jHs+/imY5+M4toOWiVNffSvEuofU/KPyX5xcZjT eS++FhOZH50kA== Date: Mon, 02 Sep 2024 11:29:07 -0700 Subject: [PATCH 08/10] xfs: fix broken variable-sized allocation detection in xfs_rtallocate_extent_block From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106389.3325667.16691450577382253644.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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: Darrick J. Wong This function tries to find a suitable free space extent starting from a particular rtbitmap block. Some time ago, I added a clamping function to prevent the free space scans from running off the end of the bitmap, but I didn't quite get the logic right. Let's say there's an allocation request with a minlen of 5 and a maxlen of 32 and we're scanning the last rtbitmap block. If we come within 4 rtx of the end of the rt volume, maxlen will get clamped to 4. If the next 3 rtx are free, we could have satisfied the allocation, but the code setting partial besti/bestlen for "minlen < maxlen" will think that we're doing a non-variable allocation and ignore it. The root of this problem is overwriting maxlen; I should have stuffed the results in a different variable, which would not have introduced this bug. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index d27bfec08ef8..72123e2337d8 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -244,6 +244,7 @@ xfs_rtallocate_extent_block( xfs_rtxnum_t end; /* last rtext in chunk */ xfs_rtxnum_t i; /* current rtext trying */ xfs_rtxnum_t next; /* next rtext to try */ + xfs_rtxlen_t scanlen; /* number of free rtx to look for */ xfs_rtxlen_t bestlen = 0; /* best length found so far */ int stat; /* status from internal calls */ int error; @@ -255,20 +256,22 @@ xfs_rtallocate_extent_block( end = min(mp->m_sb.sb_rextents, xfs_rbmblock_to_rtx(mp, bbno + 1)) - 1; for (i = xfs_rbmblock_to_rtx(mp, bbno); i <= end; i++) { /* Make sure we don't scan off the end of the rt volume. */ - maxlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod); + scanlen = xfs_rtallocate_clamp_len(mp, i, maxlen, prod); + if (scanlen < minlen) + break; /* - * See if there's a free extent of maxlen starting at i. + * See if there's a free extent of scanlen starting at i. * If it's not so then next will contain the first non-free. */ - error = xfs_rtcheck_range(args, i, maxlen, 1, &next, &stat); + error = xfs_rtcheck_range(args, i, scanlen, 1, &next, &stat); if (error) return error; if (stat) { /* - * i for maxlen is all free, allocate and return that. + * i to scanlen is all free, allocate and return that. */ - *len = maxlen; + *len = scanlen; *rtx = i; return 0; } @@ -299,7 +302,7 @@ xfs_rtallocate_extent_block( } /* Searched the whole thing & didn't find a maxlen free extent. */ - if (minlen > maxlen || besti == -1) + if (besti == -1) goto nospace; /* From patchwork Mon Sep 2 18:29:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787607 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 9E2A919CC04 for ; Mon, 2 Sep 2024 18:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301763; cv=none; b=n983HaN0JT/etsir3CIr0Qy4fgK392LAub4kDmGJKhW5rea44TopxB8FPuig2+7natSQek2bJCmAlkYlu6WB2CjolK8eOT+gZN+yJlGQd85wS+BkNtbACPlJ8nZCvG2q6jQ8juCILp6JoeBM0NL2n2CGsj24iroGSVAo/GCx/aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301763; c=relaxed/simple; bh=sTy5TSJGSEi37euAB2/sI+kJrqMP4MUXQHA18+G+hMs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MEi0ukF0zY946OWKPsPQfYPziOf3/x5/8b7n3VXTvUHfUcO0lnnhEebCfY3l/Ce83gO5jZKoFUWKJxQ6+ujmtSLSuAQUgr8Xc2MzlaUFIkeGEx8D857J06NSWrWbO3HYwfnKmqzxTzmdhc3MRMmMJ1ds0hxSJHIFtV2Hzahg3ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CCRcYUGR; 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="CCRcYUGR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 789D8C4CEC2; Mon, 2 Sep 2024 18:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301763; bh=sTy5TSJGSEi37euAB2/sI+kJrqMP4MUXQHA18+G+hMs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CCRcYUGR8/y+NM6fyuQ5vxFr508MpTu/223175ZAh3lczTBOTAjS7+oNw8jHQhUOu e032zHFCxF41wGSl+m9WUmKIdtcSm5JrWhGJAHCFp5hK9eq3BEciLcE7BwXJBUjTMW YcFatftVC2ICTeBS4FIy99MXFVPHUTlRftXJ6FMedcelFsen7YuGBjuz7NSCG3/m+f hfbsYUZSRtsVzkSklW+ayhbBA2LGep9YH+hnDymBP+rxcqDNq/9V8ueVUgcEJjR16j xgAurWM2/LN3pn+XTfcMdqTlM7gXXxNVsQLhzArZioBprb1I3t309eAWAE25bUam2I AMUBA8RFqL7Ow== Date: Mon, 02 Sep 2024 11:29:23 -0700 Subject: [PATCH 09/10] xfs: remove xfs_rtb_to_rtxrem From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106406.3325667.17621512722551301352.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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 Simplify the number of block number conversion helpers by removing xfs_rtb_to_rtxrem. Any recent compiler is smart enough to eliminate the double divisions if using separate xfs_rtb_to_rtx and xfs_rtb_to_rtxoff calls. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rtbitmap.c | 9 ++++----- fs/xfs/libxfs/xfs_rtbitmap.h | 18 ------------------ 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index d7c731aeee12..431ef62939ca 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1022,25 +1022,24 @@ xfs_rtfree_blocks( xfs_filblks_t rtlen) { struct xfs_mount *mp = tp->t_mountp; - xfs_rtxnum_t start; - xfs_filblks_t len; xfs_extlen_t mod; ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN); - len = xfs_rtb_to_rtxrem(mp, rtlen, &mod); + mod = xfs_rtb_to_rtxoff(mp, rtlen); if (mod) { ASSERT(mod == 0); return -EIO; } - start = xfs_rtb_to_rtxrem(mp, rtbno, &mod); + mod = xfs_rtb_to_rtxoff(mp, rtbno); if (mod) { ASSERT(mod == 0); return -EIO; } - return xfs_rtfree_extent(tp, start, len); + return xfs_rtfree_extent(tp, xfs_rtb_to_rtx(mp, rtbno), + xfs_rtb_to_rtx(mp, rtlen)); } /* Find all the free records within a given range. */ diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 523d3d3c12c6..69ddacd4b01e 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -86,24 +86,6 @@ xfs_rtb_to_rtxoff( return do_div(rtbno, mp->m_sb.sb_rextsize); } -/* - * Crack an rt block number into an rt extent number and an offset within that - * rt extent. Returns the rt extent number directly and the offset in @off. - */ -static inline xfs_rtxnum_t -xfs_rtb_to_rtxrem( - struct xfs_mount *mp, - xfs_rtblock_t rtbno, - xfs_extlen_t *off) -{ - if (likely(mp->m_rtxblklog >= 0)) { - *off = rtbno & mp->m_rtxblkmask; - return rtbno >> mp->m_rtxblklog; - } - - return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off); -} - /* * Convert an rt block number into an rt extent number, rounding up to the next * rt extent if the rt block is not aligned to an rt extent boundary. From patchwork Mon Sep 2 18:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787608 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 A49FA19CC05 for ; Mon, 2 Sep 2024 18:29:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301779; cv=none; b=VrXb6H0nB3ZyK066r4sOVXXlhSW8mNEwxdXFzeE1QwyzOEt8hPtApkRfSYgmYANHkpkJKOK13BiLMkGT+yzxYmKo+XJaFDSfih0L7NksLACmbuwJ8uM8tuPE491H0cFr6jIX4p831bJnoTF8L7FDd3CBNCGXB38yYVLX4iO4PcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301779; c=relaxed/simple; bh=A5q5LC1SdsPBUAqG1L+25SeQQuWKScLiXjm0XNp7VDw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DR/Yb6yuor5ukUdlldvry1TestlcCdE2Tj+YWWA7GOSXmmPwODdNqBsvw+EJ7wBmVQqyqRICW8p5kBsmGSHBmvWjWVC0MbdnOs5IrqB35xFuAXKnpwFoSw444/qK29iGdaBCJ29p+0mTtzDpwXAzP1jn33+4R8gEqQPnd8y8elg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FFF7sdB6; 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="FFF7sdB6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 287FDC4CEC2; Mon, 2 Sep 2024 18:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301779; bh=A5q5LC1SdsPBUAqG1L+25SeQQuWKScLiXjm0XNp7VDw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FFF7sdB6oYIcx3B/39CFbOS0UrwRWcE2f8Q28JS9adhi6goX/31eANDnZ51MslNiv jKpCOKTpBUTLnaK3vtQhK8lQDZt0zgDKoUGg9sEuiMhfYhP+yz6hPRvR0kRFuw4i0n fwDxBiI9TqZaNCPiHmvTui5fclAMxYtKT63IAQoI2Nt8EBwoZSAYPA05oSVwDWdeJW X/vaWDM7mEcjkhWWNqTFJCGaUkVIo8CLUts6s2ek7CrSpIua5YYJ7mqqSV++SX71BW tApCCsrXqlWRKEXeHlidVAnrn4G1WeC8NVRDYFv71LPSaxHdDq72KUIoOJrVGVCJW2 1zMBViFJCibaA== Date: Mon, 02 Sep 2024 11:29:38 -0700 Subject: [PATCH 10/10] xfs: simplify xfs_rtalloc_query_range From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106422.3325667.16190120341957890448.stgit@frogsfrogsfrogs> In-Reply-To: <172530106239.3325667.7882117478756551258.stgit@frogsfrogsfrogs> References: <172530106239.3325667.7882117478756551258.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 There isn't much of a good reason to pass the xfs_rtalloc_rec structures that describe extents to xfs_rtalloc_query_range as we really just want a lower and upper bound xfs_rtxnum_t. Pass the rtxnum directly and simply the interface. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rtbitmap.c | 42 +++++++++++++++++------------------------- fs/xfs/libxfs/xfs_rtbitmap.h | 3 +-- fs/xfs/xfs_discard.c | 15 +++++++-------- fs/xfs/xfs_fsmap.c | 11 +++++------ 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 431ef62939ca..c58eb75ef0fa 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1047,8 +1047,8 @@ int xfs_rtalloc_query_range( struct xfs_mount *mp, struct xfs_trans *tp, - const struct xfs_rtalloc_rec *low_rec, - const struct xfs_rtalloc_rec *high_rec, + xfs_rtxnum_t start, + xfs_rtxnum_t end, xfs_rtalloc_query_range_fn fn, void *priv) { @@ -1056,45 +1056,42 @@ xfs_rtalloc_query_range( .mp = mp, .tp = tp, }; - struct xfs_rtalloc_rec rec; - xfs_rtxnum_t rtstart; - xfs_rtxnum_t rtend; - xfs_rtxnum_t high_key; - int is_free; int error = 0; - if (low_rec->ar_startext > high_rec->ar_startext) + if (start > end) return -EINVAL; - if (low_rec->ar_startext >= mp->m_sb.sb_rextents || - low_rec->ar_startext == high_rec->ar_startext) + if (start == end || start >= mp->m_sb.sb_rextents) return 0; - high_key = min(high_rec->ar_startext, mp->m_sb.sb_rextents - 1); + end = min(end, mp->m_sb.sb_rextents - 1); /* Iterate the bitmap, looking for discrepancies. */ - rtstart = low_rec->ar_startext; - while (rtstart <= high_key) { + while (start <= end) { + struct xfs_rtalloc_rec rec; + int is_free; + xfs_rtxnum_t rtend; + /* Is the first block free? */ - error = xfs_rtcheck_range(&args, rtstart, 1, 1, &rtend, + error = xfs_rtcheck_range(&args, start, 1, 1, &rtend, &is_free); if (error) break; /* How long does the extent go for? */ - error = xfs_rtfind_forw(&args, rtstart, high_key, &rtend); + error = xfs_rtfind_forw(&args, start, end, &rtend); if (error) break; if (is_free) { - rec.ar_startext = rtstart; - rec.ar_extcount = rtend - rtstart + 1; + rec.ar_startext = start; + rec.ar_extcount = rtend - start + 1; error = fn(mp, tp, &rec, priv); if (error) break; } - rtstart = rtend + 1; + start = rtend + 1; } xfs_rtbuf_cache_relse(&args); @@ -1109,13 +1106,8 @@ xfs_rtalloc_query_all( xfs_rtalloc_query_range_fn fn, void *priv) { - struct xfs_rtalloc_rec keys[2]; - - keys[0].ar_startext = 0; - keys[1].ar_startext = mp->m_sb.sb_rextents - 1; - keys[0].ar_extcount = keys[1].ar_extcount = 0; - - return xfs_rtalloc_query_range(mp, tp, &keys[0], &keys[1], fn, priv); + return xfs_rtalloc_query_range(mp, tp, 0, mp->m_sb.sb_rextents - 1, fn, + priv); } /* Is the given extent all free? */ diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 69ddacd4b01e..0dbc9bb40668 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -292,8 +292,7 @@ int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log, int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, xfs_rtxlen_t len); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, - const struct xfs_rtalloc_rec *low_rec, - const struct xfs_rtalloc_rec *high_rec, + xfs_rtxnum_t start, xfs_rtxnum_t end, xfs_rtalloc_query_range_fn fn, void *priv); int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtalloc_query_range_fn fn, diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 25f5dffeab2a..bf1e3f330018 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -554,11 +554,10 @@ xfs_trim_rtdev_extents( xfs_daddr_t end, xfs_daddr_t minlen) { - struct xfs_rtalloc_rec low = { }; - struct xfs_rtalloc_rec high = { }; struct xfs_trim_rtdev tr = { .minlen_fsb = XFS_BB_TO_FSB(mp, minlen), }; + xfs_rtxnum_t low, high; struct xfs_trans *tp; xfs_daddr_t rtdev_daddr; int error; @@ -584,17 +583,17 @@ xfs_trim_rtdev_extents( XFS_FSB_TO_BB(mp, mp->m_sb.sb_rblocks) - 1); /* Convert the rt blocks to rt extents */ - low.ar_startext = xfs_rtb_to_rtxup(mp, XFS_BB_TO_FSB(mp, start)); - high.ar_startext = xfs_rtb_to_rtx(mp, XFS_BB_TO_FSBT(mp, end)); + low = xfs_rtb_to_rtxup(mp, XFS_BB_TO_FSB(mp, start)); + high = xfs_rtb_to_rtx(mp, XFS_BB_TO_FSBT(mp, end)); /* * Walk the free ranges between low and high. The query_range function * trims the extents returned. */ do { - tr.stop_rtx = low.ar_startext + (mp->m_sb.sb_blocksize * NBBY); + tr.stop_rtx = low + (mp->m_sb.sb_blocksize * NBBY); xfs_rtbitmap_lock_shared(mp, XFS_RBMLOCK_BITMAP); - error = xfs_rtalloc_query_range(mp, tp, &low, &high, + error = xfs_rtalloc_query_range(mp, tp, low, high, xfs_trim_gather_rtextent, &tr); if (error == -ECANCELED) @@ -615,8 +614,8 @@ xfs_trim_rtdev_extents( if (error) break; - low.ar_startext = tr.restart_rtx; - } while (!xfs_trim_should_stop() && low.ar_startext <= high.ar_startext); + low = tr.restart_rtx; + } while (!xfs_trim_should_stop() && low <= high); xfs_trans_cancel(tp); return error; diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 71f32354944e..e15446626875 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -520,11 +520,11 @@ xfs_getfsmap_rtdev_rtbitmap( struct xfs_getfsmap_info *info) { - struct xfs_rtalloc_rec alow = { 0 }; struct xfs_rtalloc_rec ahigh = { 0 }; struct xfs_mount *mp = tp->t_mountp; xfs_rtblock_t start_rtb; xfs_rtblock_t end_rtb; + xfs_rtxnum_t high; uint64_t eofs; int error; @@ -553,10 +553,9 @@ xfs_getfsmap_rtdev_rtbitmap( * Set up query parameters to return free rtextents covering the range * we want. */ - alow.ar_startext = xfs_rtb_to_rtx(mp, start_rtb); - ahigh.ar_startext = xfs_rtb_to_rtxup(mp, end_rtb); - error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh, - xfs_getfsmap_rtdev_rtbitmap_helper, info); + high = xfs_rtb_to_rtxup(mp, end_rtb); + error = xfs_rtalloc_query_range(mp, tp, xfs_rtb_to_rtx(mp, start_rtb), + high, xfs_getfsmap_rtdev_rtbitmap_helper, info); if (error) goto err; @@ -565,7 +564,7 @@ xfs_getfsmap_rtdev_rtbitmap( * rmap starting at the block after the end of the query range. */ info->last = true; - ahigh.ar_startext = min(mp->m_sb.sb_rextents, ahigh.ar_startext); + ahigh.ar_startext = min(mp->m_sb.sb_rextents, high); error = xfs_getfsmap_rtdev_rtbitmap_helper(mp, tp, &ahigh, info); if (error)