From patchwork Mon Sep 2 18:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787609 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 46DA63D7A for ; Mon, 2 Sep 2024 18:29:54 +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=1725301795; cv=none; b=DlPui11EoEOLz/MF3t9N8smBJ6QuElTp9hrhxBcjc6/aaGvc/Chv8smTxZw5YYLE6kCfsccGBlnnWAQYZIdvamTPj2ruMCSE1sJVaWoxYEojx5p3xnCXDiogtcGq1VfmwLQjkoXPCSW1/oHG1k88bD36Qf6G8EXEHPoSKoc8IFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301795; c=relaxed/simple; bh=6uJO1MkRj8qVzQaLs2DBsb6oKmHaUCi0NI2/K0VHn1Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xso4j9Pkt0dr1eWt0Mcv7+rTzrZWN5xqnuCUiGJIAWGeozSy5iDntICzlNjrn37WRhOAJR9J/EmCJkpOI0JBpUsOyui0Q7XEee/XZr0jCDSimsDWXUY0GmOhQ7xliAwzwZ8tQd23HF4DQmt9nHJob+T2GMrRRpivdWi0RFP/53c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tWUHFNDM; 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="tWUHFNDM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1C0FC4CEC2; Mon, 2 Sep 2024 18:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301794; bh=6uJO1MkRj8qVzQaLs2DBsb6oKmHaUCi0NI2/K0VHn1Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tWUHFNDMeXZxkTjvHzVDQ7EJaR2vi8iOcn3KzFQ7yYXaSS/98x6SBrPIaPAVXUuFZ ht+gPpu6YOh7IGqlxctn2lDAgl94v/ZjvUdsaqwKl7+5ABbbxuGH+sYrWatsMQAprC QwTzGzpKhRHP0QTxSd+ZNt7RSD8NgZMona0YuP/O94z++KFp2Rtg7kYg5YAGb3L3Xr fXPrT3NxhsWOZFtsgk4sa670j8hJqQ2SJiXAEUEjfOKJ1u7WXX0n2GnNiO7YmLhGm4 xAK2oTlF7XxpRU4GcUnXRhmcvaB21e7PqupMzZKEDHlAE58w8RJLu4IdJArSSCh+0y EDRo1Ihyg2hpQ== Date: Mon, 02 Sep 2024 11:29:54 -0700 Subject: [PATCH 01/10] xfs: clean up the ISVALID macro in xfs_bmap_adjacent From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106785.3326080.12914405736026411956.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 Turn the ISVALID macro defined and used inside in xfs_bmap_adjacent that relies on implict context into a proper inline function. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 55 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 112c7ee2d493..434433ed29dc 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3112,6 +3112,23 @@ xfs_bmap_extsize_align( return 0; } +static inline bool +xfs_bmap_adjacent_valid( + struct xfs_bmalloca *ap, + xfs_fsblock_t x, + xfs_fsblock_t y) +{ + struct xfs_mount *mp = ap->ip->i_mount; + + if (XFS_IS_REALTIME_INODE(ap->ip) && + (ap->datatype & XFS_ALLOC_USERDATA)) + return x < mp->m_sb.sb_rblocks; + + return XFS_FSB_TO_AGNO(mp, x) == XFS_FSB_TO_AGNO(mp, y) && + XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount && + XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks; +} + #define XFS_ALLOC_GAP_UNITS 4 /* returns true if ap->blkno was modified */ @@ -3119,36 +3136,25 @@ bool xfs_bmap_adjacent( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { - xfs_fsblock_t adjust; /* adjustment to block numbers */ - xfs_mount_t *mp; /* mount point structure */ - int rt; /* true if inode is realtime */ + xfs_fsblock_t adjust; /* adjustment to block numbers */ -#define ISVALID(x,y) \ - (rt ? \ - (x) < mp->m_sb.sb_rblocks : \ - XFS_FSB_TO_AGNO(mp, x) == XFS_FSB_TO_AGNO(mp, y) && \ - XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount && \ - XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks) - - mp = ap->ip->i_mount; - rt = XFS_IS_REALTIME_INODE(ap->ip) && - (ap->datatype & XFS_ALLOC_USERDATA); /* * If allocating at eof, and there's a previous real block, * try to use its last block as our starting point. */ if (ap->eof && ap->prev.br_startoff != NULLFILEOFF && !isnullstartblock(ap->prev.br_startblock) && - ISVALID(ap->prev.br_startblock + ap->prev.br_blockcount, - ap->prev.br_startblock)) { + xfs_bmap_adjacent_valid(ap, + ap->prev.br_startblock + ap->prev.br_blockcount, + ap->prev.br_startblock)) { ap->blkno = ap->prev.br_startblock + ap->prev.br_blockcount; /* * Adjust for the gap between prevp and us. */ adjust = ap->offset - (ap->prev.br_startoff + ap->prev.br_blockcount); - if (adjust && - ISVALID(ap->blkno + adjust, ap->prev.br_startblock)) + if (adjust && xfs_bmap_adjacent_valid(ap, ap->blkno + adjust, + ap->prev.br_startblock)) ap->blkno += adjust; return true; } @@ -3171,7 +3177,8 @@ xfs_bmap_adjacent( !isnullstartblock(ap->prev.br_startblock) && (prevbno = ap->prev.br_startblock + ap->prev.br_blockcount) && - ISVALID(prevbno, ap->prev.br_startblock)) { + xfs_bmap_adjacent_valid(ap, prevbno, + ap->prev.br_startblock)) { /* * Calculate gap to end of previous block. */ @@ -3187,8 +3194,8 @@ xfs_bmap_adjacent( * number, then just use the end of the previous block. */ if (prevdiff <= XFS_ALLOC_GAP_UNITS * ap->length && - ISVALID(prevbno + prevdiff, - ap->prev.br_startblock)) + xfs_bmap_adjacent_valid(ap, prevbno + prevdiff, + ap->prev.br_startblock)) prevbno += adjust; else prevdiff += adjust; @@ -3220,9 +3227,11 @@ xfs_bmap_adjacent( * offset by our length. */ if (gotdiff <= XFS_ALLOC_GAP_UNITS * ap->length && - ISVALID(gotbno - gotdiff, gotbno)) + xfs_bmap_adjacent_valid(ap, gotbno - gotdiff, + gotbno)) gotbno -= adjust; - else if (ISVALID(gotbno - ap->length, gotbno)) { + else if (xfs_bmap_adjacent_valid(ap, gotbno - ap->length, + gotbno)) { gotbno -= ap->length; gotdiff += adjust - ap->length; } else @@ -3250,7 +3259,7 @@ xfs_bmap_adjacent( return true; } } -#undef ISVALID + return false; } From patchwork Mon Sep 2 18:30:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787610 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 E31421A303C for ; Mon, 2 Sep 2024 18:30: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=1725301811; cv=none; b=Dk/E5CpytkUrUO4jGoY+5ZPUK6vbyNfss8DGt9zGlAtAA/Sy+sJ291PD/cFgv4UBk9MdDWjJkgx1cf0sypdS94QXqTkeq+wEXm2f8OoZ3HYQB0WhzfHvFL7/SIol7E2ADM9eV8EE2oHu94Lg5IjNfTbws2C9ZmGrFIPGpLt9Aec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301811; c=relaxed/simple; bh=ziRhO4LritZ4KdIg66JYOtGa4b9U4d82fqN54FxyFng=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fmYAYNGTpMkJnkumXoVVw2R6X0AVYOjCzXRPprj09vC4ShQ6mOYXBOttHp5DwQEsnanO92PPADiqGUuhfWWJB390OLNLz3jeHFlzEOjehuaWQY0lGqnY0y5rJql0F0MpxTFVAbbkDgY/vNPgAR1SohYcTpcJi7hVNZEsUTRMtY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f0gKwfi/; 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="f0gKwfi/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71DC5C4CEC2; Mon, 2 Sep 2024 18:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301810; bh=ziRhO4LritZ4KdIg66JYOtGa4b9U4d82fqN54FxyFng=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=f0gKwfi/BSpSMmHLvvtCWv+7O+4mpYJTa4pr46XlVQK/KMim834ybrKgjvCUGqETK /PSv2z9fJ0jobM3OHjeoLu+yhSyN+mIqGLcyRbo3ZQCLV6/BxLhwVT3cDUaQ2m3+jr V5LRTUbVx1u8w+MAPWxVZPszmGm25VRDzYSSnWIAv8aleaazjT13QP/G4nMRRHzMHC wmO1yJCK9/dpaTrs5Q24NUmuDqhBnt+8RwePWcmYZNIUh9+8xMYt3ykMzNv/nllnL4 +Hhf86Rt1Ki+rKPh9uhkm1+1p5fB1kzkskwCpHikzDUVa9dlCrhp1phxMBTi1ay5CL V2jk8OiJ08RSw== Date: Mon, 02 Sep 2024 11:30:10 -0700 Subject: [PATCH 02/10] xfs: factor out a xfs_rtallocate helper From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106801.3326080.14582295004318273135.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 out a helper from xfs_rtallocate that performs the actual allocation. This keeps the scope of the xfs_rtalloc_args structure contained, and prepares for rtgroups support. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 81 +++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 72123e2337d8..12cf7cb3c02c 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1263,6 +1263,51 @@ xfs_rtalloc_align_minmax( *raminlen = newminlen; } +static int +xfs_rtallocate( + struct xfs_trans *tp, + xfs_rtxnum_t start, + xfs_rtxlen_t minlen, + xfs_rtxlen_t maxlen, + xfs_rtxlen_t prod, + bool wasdel, + xfs_rtblock_t *bno, + xfs_extlen_t *blen) +{ + struct xfs_rtalloc_args args = { + .mp = tp->t_mountp, + .tp = tp, + }; + xfs_rtxnum_t rtx; + xfs_rtxlen_t len = 0; + int error; + + if (start) { + error = xfs_rtallocate_extent_near(&args, start, minlen, maxlen, + &len, prod, &rtx); + } else { + error = xfs_rtallocate_extent_size(&args, minlen, maxlen, &len, + prod, &rtx); + } + + if (error) + goto out_release; + + error = xfs_rtallocate_range(&args, rtx, len); + if (error) + goto out_release; + + xfs_trans_mod_sb(tp, wasdel ? + XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS, + -(long)len); + *bno = xfs_rtx_to_rtb(args.mp, rtx); + *blen = xfs_rtxlen_to_extlen(args.mp, len); + +out_release: + xfs_rtbuf_cache_relse(&args); + return error; +} + int xfs_bmap_rtalloc( struct xfs_bmalloca *ap) @@ -1270,7 +1315,6 @@ xfs_bmap_rtalloc( struct xfs_mount *mp = ap->ip->i_mount; xfs_fileoff_t orig_offset = ap->offset; xfs_rtxnum_t start; /* allocation hint rtextent no */ - xfs_rtxnum_t rtx; /* actually allocated rtextent no */ xfs_rtxlen_t prod = 0; /* product factor for allocators */ xfs_extlen_t mod = 0; /* product factor for allocators */ xfs_rtxlen_t ralen = 0; /* realtime allocation length */ @@ -1280,10 +1324,6 @@ xfs_bmap_rtalloc( xfs_rtxlen_t raminlen; bool rtlocked = false; bool ignore_locality = false; - struct xfs_rtalloc_args args = { - .mp = mp, - .tp = ap->tp, - }; int error; align = xfs_get_extsz_hint(ap->ip); @@ -1357,19 +1397,9 @@ xfs_bmap_rtalloc( xfs_rtalloc_align_minmax(&raminlen, &ralen, &prod); } - if (start) { - error = xfs_rtallocate_extent_near(&args, start, raminlen, - ralen, &ralen, prod, &rtx); - } else { - error = xfs_rtallocate_extent_size(&args, raminlen, - ralen, &ralen, prod, &rtx); - } - - if (error) { - xfs_rtbuf_cache_relse(&args); - if (error != -ENOSPC) - return error; - + error = xfs_rtallocate(ap->tp, start, raminlen, ralen, prod, ap->wasdel, + &ap->blkno, &ap->length); + if (error == -ENOSPC) { if (align > mp->m_sb.sb_rextsize) { /* * We previously enlarged the request length to try to @@ -1397,20 +1427,9 @@ xfs_bmap_rtalloc( ap->length = 0; return 0; } - - error = xfs_rtallocate_range(&args, rtx, ralen); if (error) - goto out_release; + return error; - 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); - -out_release: - xfs_rtbuf_cache_relse(&args); - return error; + return 0; } From patchwork Mon Sep 2 18:30: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: 13787611 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 9854219CC04 for ; Mon, 2 Sep 2024 18:30: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=1725301827; cv=none; b=JKwedtZmMpUaG5Nd3SJGH7bxQchSJV1V0Muc7vYdxLIMeCfJ8SPAFgwcMzdfAx1uM7+xhQY6joAOermm2dxLoSZ62lAKX1/2VqEXXmsnHwNM8JnAE4GJjXOQEnrfRa5tfA0qnU9G46hE/1yLY8YQkBkI2PiJjJ8IsdUhelXeVio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301827; c=relaxed/simple; bh=Y2fNuAFzHXmvGno8tyiMdW6YWlLtgpAw1MiwmPRKcjY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sRiqz2WV5WvOwCyp1RgySZo4sUSHaIbkAEV5F928iOeEoMy+U0vyRgBzsA//wTMxhdt+fZySatrbZ6W0eFe3HqOrHdFj+wsrpsADuCGiaJLsiN+r9iPaFFaDJEqx1j0LYcwhHNBHRrcF+K4+l1jSQUj7eJ83dXOAjHFBQ6trun4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XFWZBIcd; 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="XFWZBIcd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20A64C4CEC7; Mon, 2 Sep 2024 18:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301826; bh=Y2fNuAFzHXmvGno8tyiMdW6YWlLtgpAw1MiwmPRKcjY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XFWZBIcdJzRthLwvz8bZcW41w5SS+iXTZbn4MZ7tlwmvZr+8iBIamD2CYeDfawH83 O8iW2JtRjqI43jm83qzK8Lx63bQ8clUB2tGfWUBikWGFoJQKJwz8LzXGIlQEMWSqmM 2a5ZWgkITpEn1Bzu2ZhPdLrfyRQ3Xy9g3MrBZ8uKsSQssIECy/m0V1Rbl2HRCBrFDE sShMqxyot5odRRCN865De+ZPsEnnpCrmPSgNk8/cLYJZvnf08RwT3CTwxaVpQcAd1X d67yX0yez+VoAA8nfXYuZkn6qsBBH/IiwjUXUGTSyPtxvZSDFi8PQ10u2Xv0GNKT8x XbHUTOHfz6tNg== Date: Mon, 02 Sep 2024 11:30:25 -0700 Subject: [PATCH 03/10] xfs: rework the rtalloc fallback handling From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106818.3326080.8590032731537560388.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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_rtallocate currently has two fallbacks, when an allocation fails: 1) drop the requested extent size alignment, if any, and retry 2) ignore the locality hint Oddly enough it does those in order, as trying a different location is more in line with what the user asked for, and does it in a very unstructured way. Lift the fallback to try to allocate without the locality hint into xfs_rtallocate to both perform them in a more sensible order and to clean up the code. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 69 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 12cf7cb3c02c..a6b9ba572cdc 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1271,6 +1271,8 @@ xfs_rtallocate( xfs_rtxlen_t maxlen, xfs_rtxlen_t prod, bool wasdel, + bool initial_user_data, + bool *rtlocked, xfs_rtblock_t *bno, xfs_extlen_t *blen) { @@ -1280,12 +1282,38 @@ xfs_rtallocate( }; xfs_rtxnum_t rtx; xfs_rtxlen_t len = 0; - int error; + int error = 0; + + /* + * Lock out modifications to both the RT bitmap and summary inodes. + */ + if (!*rtlocked) { + xfs_rtbitmap_lock(args.mp); + xfs_rtbitmap_trans_join(tp); + *rtlocked = true; + } + + /* + * For an allocation to an empty file at offset 0, pick an extent that + * will space things out in the rt area. + */ + if (!start && initial_user_data) + start = xfs_rtpick_extent(args.mp, tp, maxlen); if (start) { error = xfs_rtallocate_extent_near(&args, start, minlen, maxlen, &len, prod, &rtx); - } else { + /* + * If we can't allocate near a specific rt extent, try again + * without locality criteria. + */ + if (error == -ENOSPC) { + xfs_rtbuf_cache_relse(&args); + error = 0; + } + } + + if (!error) { error = xfs_rtallocate_extent_size(&args, minlen, maxlen, &len, prod, &rtx); } @@ -1314,7 +1342,7 @@ xfs_bmap_rtalloc( { struct xfs_mount *mp = ap->ip->i_mount; xfs_fileoff_t orig_offset = ap->offset; - xfs_rtxnum_t start; /* allocation hint rtextent no */ + xfs_rtxnum_t start = 0; /* allocation hint rtextent no */ xfs_rtxlen_t prod = 0; /* product factor for allocators */ xfs_extlen_t mod = 0; /* product factor for allocators */ xfs_rtxlen_t ralen = 0; /* realtime allocation length */ @@ -1323,7 +1351,6 @@ xfs_bmap_rtalloc( xfs_extlen_t minlen = mp->m_sb.sb_rextsize; xfs_rtxlen_t raminlen; bool rtlocked = false; - bool ignore_locality = false; int error; align = xfs_get_extsz_hint(ap->ip); @@ -1361,28 +1388,8 @@ xfs_bmap_rtalloc( ASSERT(raminlen > 0); ASSERT(raminlen <= ralen); - /* - * Lock out modifications to both the RT bitmap and summary inodes - */ - if (!rtlocked) { - xfs_rtbitmap_lock(mp); - xfs_rtbitmap_trans_join(ap->tp); - rtlocked = true; - } - - if (ignore_locality) { - start = 0; - } else if (xfs_bmap_adjacent(ap)) { + if (xfs_bmap_adjacent(ap)) start = xfs_rtb_to_rtx(mp, ap->blkno); - } else if (ap->datatype & XFS_ALLOC_INITIAL_USER_DATA) { - /* - * If it's an allocation to an empty file at offset 0, pick an - * extent that will space things out in the rt area. - */ - start = xfs_rtpick_extent(mp, ap->tp, ralen); - } else { - start = 0; - } /* * Only bother calculating a real prod factor if offset & length are @@ -1398,7 +1405,8 @@ xfs_bmap_rtalloc( } error = xfs_rtallocate(ap->tp, start, raminlen, ralen, prod, ap->wasdel, - &ap->blkno, &ap->length); + ap->datatype & XFS_ALLOC_INITIAL_USER_DATA, &rtlocked, + &ap->blkno, &ap->length); if (error == -ENOSPC) { if (align > mp->m_sb.sb_rextsize) { /* @@ -1414,15 +1422,6 @@ xfs_bmap_rtalloc( goto retry; } - if (!ignore_locality && start != 0) { - /* - * If we can't allocate near a specific rt extent, try - * again without locality criteria. - */ - ignore_locality = true; - goto retry; - } - ap->blkno = NULLFSBLOCK; ap->length = 0; return 0; From patchwork Mon Sep 2 18:30: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: 13787612 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 33AE519CC04 for ; Mon, 2 Sep 2024 18:30: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=1725301842; cv=none; b=e6KAJo2/s9ecst1UyqCjJR4cvd36jHeZ31Lz66xkl8dTMuBzTALVz1JPSsiRWm6WWtFSxpbgSQJpr6Y9b8EgUpaEBDLj+CVdzWOtLj8bXPnbrg2zwxEfaZInGSDrKDi0z+2vO7HMs2L9EWTP1/xWCRYIKXMqkFXqdcvX4XqWg7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301842; c=relaxed/simple; bh=GVq7uQQUr5RGKteM7Tq4sfkmxeNlMEzTKRSd9dNB5DI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V0tk2y8IzyfG8Co16bkARl3oSumR7jhDKQkmWo2Pnk3RKWEsnWM82aLf2/Y0e6mq7qjR6cob1gt+9C9HNbjCyrt96MRcE/zdjA3Qxiz/jHariGyMiLY82Wx1YdYc3cUJtmUD0Z9uURpoU11Muu4oiGT9JFrF4wbYOfalNPZVV7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LVBRI8bo; 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="LVBRI8bo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2A6C4CEC2; Mon, 2 Sep 2024 18:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301841; bh=GVq7uQQUr5RGKteM7Tq4sfkmxeNlMEzTKRSd9dNB5DI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LVBRI8boU4qrjZBobTfSSmORVjyiZbURhWNOTYQg/wgxbn+yk89aVxI/A9MRuVFmt 3Pk3Zi2gNbbKyytOSNEFx3UyKW+oRstTlqlkrcGHLUekjFSkXq5Sojs3K6m9+3hZko QgKXgtEe2MyRz5BoKS2At+T7h+MHb3FCUNjc70X4K41Q0IRLBW9PtzZ5W4ZcRDhSa4 6B5MZefHw9HI7acgJBKoIbeygftSi2Mybcg55krMUO0Z1nbyVKBVQeiFiTEv+9Nii/ 7hb9Upjvak/JZz+lw3DFlcDMDIPj7BD/SZBcghidqU5/35m/kk+5APGrAV9xiGx8KF f/T5NPWY7XhRA== Date: Mon, 02 Sep 2024 11:30:41 -0700 Subject: [PATCH 04/10] xfs: factor out a xfs_rtallocate_align helper From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106833.3326080.2641612257297215834.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 code to calculate the aligned allocation request from xfs_bmap_rtalloc into a separate self-contained helper. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 93 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index a6b9ba572cdc..61e0c5b7a327 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1336,30 +1336,33 @@ xfs_rtallocate( return error; } -int -xfs_bmap_rtalloc( - struct xfs_bmalloca *ap) +static int +xfs_rtallocate_align( + struct xfs_bmalloca *ap, + xfs_rtxlen_t *ralen, + xfs_rtxlen_t *raminlen, + xfs_rtxlen_t *prod, + bool *noalign) { struct xfs_mount *mp = ap->ip->i_mount; xfs_fileoff_t orig_offset = ap->offset; - xfs_rtxnum_t start = 0; /* allocation hint rtextent no */ - xfs_rtxlen_t prod = 0; /* product factor for allocators */ - xfs_extlen_t mod = 0; /* product factor for allocators */ - xfs_rtxlen_t ralen = 0; /* realtime allocation length */ - xfs_extlen_t align; /* minimum allocation alignment */ - xfs_extlen_t orig_length = ap->length; xfs_extlen_t minlen = mp->m_sb.sb_rextsize; - xfs_rtxlen_t raminlen; - bool rtlocked = false; + xfs_extlen_t align; /* minimum allocation alignment */ + xfs_extlen_t mod; /* product factor for allocators */ int error; - align = xfs_get_extsz_hint(ap->ip); - if (!align) - align = 1; -retry: - error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, - align, 1, ap->eof, 0, - ap->conv, &ap->offset, &ap->length); + if (*noalign) { + align = mp->m_sb.sb_rextsize; + } else { + align = xfs_get_extsz_hint(ap->ip); + if (!align) + align = 1; + if (align == mp->m_sb.sb_rextsize) + *noalign = true; + } + + error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 1, + ap->eof, 0, ap->conv, &ap->offset, &ap->length); if (error) return error; ASSERT(ap->length); @@ -1383,32 +1386,54 @@ xfs_bmap_rtalloc( * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't * adjust the starting point to match it. */ - ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN)); - raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen)); - ASSERT(raminlen > 0); - ASSERT(raminlen <= ralen); - - if (xfs_bmap_adjacent(ap)) - start = xfs_rtb_to_rtx(mp, ap->blkno); + *ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN)); + *raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen)); + ASSERT(*raminlen > 0); + ASSERT(*raminlen <= *ralen); /* * Only bother calculating a real prod factor if offset & length are * perfectly aligned, otherwise it will just get us in trouble. */ div_u64_rem(ap->offset, align, &mod); - if (mod || ap->length % align) { - prod = 1; - } else { - prod = xfs_extlen_to_rtxlen(mp, align); - if (prod > 1) - xfs_rtalloc_align_minmax(&raminlen, &ralen, &prod); - } + if (mod || ap->length % align) + *prod = 1; + else + *prod = xfs_extlen_to_rtxlen(mp, align); + + if (*prod > 1) + xfs_rtalloc_align_minmax(raminlen, ralen, prod); + return 0; +} + +int +xfs_bmap_rtalloc( + struct xfs_bmalloca *ap) +{ + struct xfs_mount *mp = ap->ip->i_mount; + xfs_fileoff_t orig_offset = ap->offset; + xfs_rtxnum_t start = 0; /* allocation hint rtextent no */ + xfs_rtxlen_t prod = 0; /* product factor for allocators */ + xfs_rtxlen_t ralen = 0; /* realtime allocation length */ + xfs_extlen_t orig_length = ap->length; + xfs_rtxlen_t raminlen; + bool rtlocked = false; + bool noalign = false; + int error; + +retry: + error = xfs_rtallocate_align(ap, &ralen, &raminlen, &prod, &noalign); + if (error) + return error; + + if (xfs_bmap_adjacent(ap)) + start = xfs_rtb_to_rtx(mp, ap->blkno); error = xfs_rtallocate(ap->tp, start, raminlen, ralen, prod, ap->wasdel, ap->datatype & XFS_ALLOC_INITIAL_USER_DATA, &rtlocked, &ap->blkno, &ap->length); if (error == -ENOSPC) { - if (align > mp->m_sb.sb_rextsize) { + if (!noalign) { /* * We previously enlarged the request length to try to * satisfy an extent size hint. The allocator didn't @@ -1418,7 +1443,7 @@ xfs_bmap_rtalloc( */ ap->offset = orig_offset; ap->length = orig_length; - minlen = align = mp->m_sb.sb_rextsize; + noalign = true; goto retry; } From patchwork Mon Sep 2 18:30: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: 13787614 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 CDAC819CC31 for ; Mon, 2 Sep 2024 18:30: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=1725301857; cv=none; b=USi+oLyt2ktWegtsNhia3HeXoZySUKymjswcBh40o67eTO5wk+e9hDXv36JY9wohK3Pgl55PQ+ShVyIecy3iqRJBh0hy84dHffWDFjHlQkSoHaetBvL3IfbhKxVMWCIehRIht7+UqSwOyfauAuHdmiDjErAtYDFMpCmR4Y020uE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301857; c=relaxed/simple; bh=oCmmToF60RFu8+JN137VcifPP51o1/FMqzC76K6uJbI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n6jN1XI/btGKEcT+BdJwuY9WaZ1bHlOP5hQILlg4jqqsSzFNgnunG9d8xYN/05CyKQoVpY14BkbuibVK7FZP+2GwjnFAWxR5bR9bmqNEWX3y7+TlFa6AnYIH3/kaCXVJQxwqUMp2lU9icfHXcLxoZRDU+8Z/HVwtV0CqjIDDOVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lONVzLlX; 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="lONVzLlX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F8DCC4CEC2; Mon, 2 Sep 2024 18:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301857; bh=oCmmToF60RFu8+JN137VcifPP51o1/FMqzC76K6uJbI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lONVzLlX0j+NMlbF/GkYhJSlR8apcV1ZpkbW1ZVD0KBuo5MTtwQ2yrtI3Bq3Tk9Mc IIWE3hUVycDaEVMM5plaY3gnSe1BuHt9Q30e6S2AzVcYf5QltclFBJ8Rt8eTw3D9Qj o5Y1k80A7ILext8MHpagA7P+362ewB67lAoQpuE+X8XjPGEkX4dE0FVL1J8fwxesQa wKfD1JqHTF/V7SVYh2AcYMiIAYSczfoQ3Zi4PpWe/euxajlpvvmmp5FZUJ1Q4ByXgw 4qiCSwZ3zP1Ax1+V81WshhnLnZRaLLQbeEL9BYjoOknhybN5XaKGpd7wncB5AsgVTl E63uUxSEPBJ2g== Date: Mon, 02 Sep 2024 11:30:56 -0700 Subject: [PATCH 05/10] xfs: make the rtalloc start hint a xfs_rtblock_t From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106848.3326080.1417046683456610512.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 0 is a valid start RT extent, and with pending changes it will become both more common and non-unique. Switch to pass a xfs_rtblock_t instead so that we can use NULLRTBLOCK to determine if a hint was set or not. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_rtalloc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 61e0c5b7a327..29edb8044b00 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1266,7 +1266,7 @@ xfs_rtalloc_align_minmax( static int xfs_rtallocate( struct xfs_trans *tp, - xfs_rtxnum_t start, + xfs_rtblock_t bno_hint, xfs_rtxlen_t minlen, xfs_rtxlen_t maxlen, xfs_rtxlen_t prod, @@ -1280,6 +1280,7 @@ xfs_rtallocate( .mp = tp->t_mountp, .tp = tp, }; + xfs_rtxnum_t start = 0; xfs_rtxnum_t rtx; xfs_rtxlen_t len = 0; int error = 0; @@ -1297,7 +1298,9 @@ xfs_rtallocate( * For an allocation to an empty file at offset 0, pick an extent that * will space things out in the rt area. */ - if (!start && initial_user_data) + if (bno_hint) + start = xfs_rtb_to_rtx(args.mp, bno_hint); + else if (initial_user_data) start = xfs_rtpick_extent(args.mp, tp, maxlen); if (start) { @@ -1410,15 +1413,16 @@ int xfs_bmap_rtalloc( struct xfs_bmalloca *ap) { - struct xfs_mount *mp = ap->ip->i_mount; xfs_fileoff_t orig_offset = ap->offset; - xfs_rtxnum_t start = 0; /* allocation hint rtextent no */ xfs_rtxlen_t prod = 0; /* product factor for allocators */ xfs_rtxlen_t ralen = 0; /* realtime allocation length */ + xfs_rtblock_t bno_hint = NULLRTBLOCK; xfs_extlen_t orig_length = ap->length; xfs_rtxlen_t raminlen; bool rtlocked = false; bool noalign = false; + bool initial_user_data = + ap->datatype & XFS_ALLOC_INITIAL_USER_DATA; int error; retry: @@ -1427,10 +1431,10 @@ xfs_bmap_rtalloc( return error; if (xfs_bmap_adjacent(ap)) - start = xfs_rtb_to_rtx(mp, ap->blkno); + bno_hint = ap->blkno; - error = xfs_rtallocate(ap->tp, start, raminlen, ralen, prod, ap->wasdel, - ap->datatype & XFS_ALLOC_INITIAL_USER_DATA, &rtlocked, + error = xfs_rtallocate(ap->tp, bno_hint, raminlen, ralen, prod, + ap->wasdel, initial_user_data, &rtlocked, &ap->blkno, &ap->length); if (error == -ENOSPC) { if (!noalign) { From patchwork Mon Sep 2 18:31: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: 13787615 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 2A5065680 for ; Mon, 2 Sep 2024 18:31: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=1725301873; cv=none; b=KdvYQu3GX4FwaiKZB0R8FupOIEmweFXvNy21b3o/DtGdFfCjmRDr9O6QNphGbkecrUjYzA++KUi+2jCy0RSMzRNkGru6Kqk7VdevMqkoqsmlAcEs2W9I3Be8JMiHb23seuYgJwNxIxtDD6SRJ/r6jhLeq251LhwPl0hFOCOuf3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301873; c=relaxed/simple; bh=8K+T8hUDe3kLobGyJGMCX+DhSoGBD/ofG7q0VuLb1Uw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rqBnb7oxmWcBkHS4B1VFs5CavP51T584VmJsOfDfO7xO/5kb9H5QVBzuuXp9KGv9SS7vnJzqVzZlCMfdd9Hl+s1kap+SpRBl+BsQpRq2DS4BS+4hzh8EkNxeIHtVfgzhNZfauuCScTmYiju062yRs0u0RKpSCiEklW8aasAiQyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P1U77ajd; 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="P1U77ajd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04A3BC4CEC2; Mon, 2 Sep 2024 18:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301873; bh=8K+T8hUDe3kLobGyJGMCX+DhSoGBD/ofG7q0VuLb1Uw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P1U77ajdegpFjnwsKo44SJMd1bxq/sG8nYzfrAjmbMJBgxMNmnlb3WKzZGGhlypi7 AZNYVLzHsojGJO53vGHeFLfOjf26y/H1PlMZRgXPZuby2pPstPyt9BrI+RRTvcQnVH 6dnI/BeaIf9DOgbp/HRdsHmOQ7yy6tWPS2sgHf7MVrvjncJPqpUHvbDZ1kD1FaF7tc NDVkfBQCfXn1gGOLlCx3CQZsb8QzVK1Mu6WmYNWmaDtp9vu4jd6/666YiY8sCu+5Ou 92BBDdSH/+ro8Y3a4a717hXmug2ajXs1eAqeMjO9K/fxhT1VrZl4GcwkBzp8RKwj3S M8XImD7DHXwUA== Date: Mon, 02 Sep 2024 11:31:12 -0700 Subject: [PATCH 06/10] xfs: add xchk_setup_nothing and xchk_nothing helpers From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106865.3326080.8457881111716349121.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 Add common helpers for no-op scrubbing methods. Signed-off-by: Darrick J. Wong [hch: split from a larger patch] Signed-off-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/common.h | 29 +++++++++-------------------- fs/xfs/scrub/scrub.h | 29 +++++++++-------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h index 3d5f1f6b4b7b..47148cc4a833 100644 --- a/fs/xfs/scrub/common.h +++ b/fs/xfs/scrub/common.h @@ -53,6 +53,11 @@ int xchk_checkpoint_log(struct xfs_mount *mp); bool xchk_should_check_xref(struct xfs_scrub *sc, int *error, struct xfs_btree_cur **curpp); +static inline int xchk_setup_nothing(struct xfs_scrub *sc) +{ + return -ENOENT; +} + /* Setup functions */ int xchk_setup_agheader(struct xfs_scrub *sc); int xchk_setup_fs(struct xfs_scrub *sc); @@ -72,16 +77,8 @@ int xchk_setup_dirtree(struct xfs_scrub *sc); int xchk_setup_rtbitmap(struct xfs_scrub *sc); int xchk_setup_rtsummary(struct xfs_scrub *sc); #else -static inline int -xchk_setup_rtbitmap(struct xfs_scrub *sc) -{ - return -ENOENT; -} -static inline int -xchk_setup_rtsummary(struct xfs_scrub *sc) -{ - return -ENOENT; -} +# define xchk_setup_rtbitmap xchk_setup_nothing +# define xchk_setup_rtsummary xchk_setup_nothing #endif #ifdef CONFIG_XFS_QUOTA int xchk_ino_dqattach(struct xfs_scrub *sc); @@ -93,16 +90,8 @@ xchk_ino_dqattach(struct xfs_scrub *sc) { return 0; } -static inline int -xchk_setup_quota(struct xfs_scrub *sc) -{ - return -ENOENT; -} -static inline int -xchk_setup_quotacheck(struct xfs_scrub *sc) -{ - return -ENOENT; -} +# define xchk_setup_quota xchk_setup_nothing +# define xchk_setup_quotacheck xchk_setup_nothing #endif int xchk_setup_fscounters(struct xfs_scrub *sc); int xchk_setup_nlinks(struct xfs_scrub *sc); diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h index 1bc33f010d0e..5993fcaffb2c 100644 --- a/fs/xfs/scrub/scrub.h +++ b/fs/xfs/scrub/scrub.h @@ -231,6 +231,11 @@ xchk_should_terminate( return false; } +static inline int xchk_nothing(struct xfs_scrub *sc) +{ + return -ENOENT; +} + /* Metadata scrubbers */ int xchk_tester(struct xfs_scrub *sc); int xchk_superblock(struct xfs_scrub *sc); @@ -254,31 +259,15 @@ int xchk_dirtree(struct xfs_scrub *sc); int xchk_rtbitmap(struct xfs_scrub *sc); int xchk_rtsummary(struct xfs_scrub *sc); #else -static inline int -xchk_rtbitmap(struct xfs_scrub *sc) -{ - return -ENOENT; -} -static inline int -xchk_rtsummary(struct xfs_scrub *sc) -{ - return -ENOENT; -} +# define xchk_rtbitmap xchk_nothing +# define xchk_rtsummary xchk_nothing #endif #ifdef CONFIG_XFS_QUOTA int xchk_quota(struct xfs_scrub *sc); int xchk_quotacheck(struct xfs_scrub *sc); #else -static inline int -xchk_quota(struct xfs_scrub *sc) -{ - return -ENOENT; -} -static inline int -xchk_quotacheck(struct xfs_scrub *sc) -{ - return -ENOENT; -} +# define xchk_quota xchk_nothing +# define xchk_quotacheck xchk_nothing #endif int xchk_fscounters(struct xfs_scrub *sc); int xchk_nlinks(struct xfs_scrub *sc); From patchwork Mon Sep 2 18:31: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: 13787616 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 F2FFF5680 for ; Mon, 2 Sep 2024 18:31: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=1725301889; cv=none; b=XaQO6ORudeJoVK2bzfqP5JLRK2TU8UdM6fhR2MSI3IvvlEkdUHrH9TTwDXa6N5Cx5EHsdixeC0dxcg2rECPPi+lcc73LacuR70jlIijOfRskSG+AOQeRL6V+IA42poLZYzBQlfE9w7UP3PeXu2wFQLMqL2Z+OCtAdt0P++6HG+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301889; c=relaxed/simple; bh=0lNZzySYQGI4zCqXwTpEsDhQudXf8B3ZCofP60QyiD4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FD9gevPg2dVUBGRLFg7ufjVgycsr3SH0Tfdz2a+isdmjAfB+5aIhj/IC4HzShY8BLYESFBXDxHjEykNeV7wFvry3x4c8i0NTE77uId85rM+FWAXDp8725mUOv3TBOFzJTQ3ltPw7aeN3KnzEdeBC1i3I8+QBRSH2LxfB6dkbzio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=baNPILqV; 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="baNPILqV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94AD2C4CEC2; Mon, 2 Sep 2024 18:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301888; bh=0lNZzySYQGI4zCqXwTpEsDhQudXf8B3ZCofP60QyiD4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=baNPILqVr2gp4p4MoBiTa2DXvVGQnL7821xWkl6D2IMvyvGn93u3uigkvFpSailDq F7YOn+nPXpII+mpSG5NXRcnpPvh6A8jNx0zHUvgqewH+3BumcKYPIEf3XbzUirm+AV jsoWlZooOfSvMJFRunjL8UyVILixVi6vrzu2+83m8he8G0awjgw3sMHpqCnHGyoO/E vMia6yUXuIxKYRvv+dUbJI4LVG7EIJHMLywjYznhNFuCiZ0M+BO0XvTGnzFRnte0HP zuz+JUBSDMJ2SFHk2bObpk5+Crne+I62wRAI6OheEQuyR6SV1pH4Ytcr1os+r9it69 737CcTQig5RTA== Date: Mon, 02 Sep 2024 11:31:28 -0700 Subject: [PATCH 07/10] xfs: remove xfs_{rtbitmap,rtsummary}_wordcount From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106881.3326080.7304548688608203352.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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_rtbitmap_wordcount and xfs_rtsummary_wordcount are currently unused, so remove them to simplify refactoring other rtbitmap helpers. They can be added back or simply open coded when actually needed. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rtbitmap.c | 31 ------------------------------- fs/xfs/libxfs/xfs_rtbitmap.h | 7 ------- 2 files changed, 38 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index c58eb75ef0fa..76706e8bbc4e 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1148,21 +1148,6 @@ xfs_rtbitmap_blockcount( return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize); } -/* - * Compute the number of rtbitmap words needed to populate every block of a - * bitmap that is large enough to track the given number of rt extents. - */ -unsigned long long -xfs_rtbitmap_wordcount( - struct xfs_mount *mp, - xfs_rtbxlen_t rtextents) -{ - xfs_filblks_t blocks; - - blocks = xfs_rtbitmap_blockcount(mp, rtextents); - return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG; -} - /* Compute the number of rtsummary blocks needed to track the given rt space. */ xfs_filblks_t xfs_rtsummary_blockcount( @@ -1176,22 +1161,6 @@ xfs_rtsummary_blockcount( return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG); } -/* - * Compute the number of rtsummary info words needed to populate every block of - * a summary file that is large enough to track the given rt space. - */ -unsigned long long -xfs_rtsummary_wordcount( - struct xfs_mount *mp, - unsigned int rsumlevels, - xfs_extlen_t rbmblocks) -{ - xfs_filblks_t blocks; - - blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks); - return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG; -} - /* Lock both realtime free space metadata inodes for a freespace update. */ void xfs_rtbitmap_lock( diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 0dbc9bb40668..140513d1d6bc 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -316,13 +316,8 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents); -unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp, - xfs_rtbxlen_t rtextents); - xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp, unsigned int rsumlevels, xfs_extlen_t rbmblocks); -unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, - unsigned int rsumlevels, xfs_extlen_t rbmblocks); int xfs_rtfile_initialize_blocks(struct xfs_inode *ip, xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb, void *data); @@ -355,9 +350,7 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) /* shut up gcc */ return 0; } -# define xfs_rtbitmap_wordcount(mp, r) (0) # define xfs_rtsummary_blockcount(mp, l, b) (0) -# define xfs_rtsummary_wordcount(mp, l, b) (0) # define xfs_rtbitmap_lock(mp) do { } while (0) # define xfs_rtbitmap_trans_join(tp) do { } while (0) # define xfs_rtbitmap_unlock(mp) do { } while (0) From patchwork Mon Sep 2 18:31: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: 13787617 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 B650A19CC04 for ; Mon, 2 Sep 2024 18:31: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=1725301904; cv=none; b=ptCYpbqPmAwvFJ9KQUaNNytMGjRoWQaNWUziqWstLF77elmcmrG1pNZ+GCdzqscVJktQNSFdHCZvioOl2StZoaRhZG//575lpQO4wRtvO4jAE0oJio5odENnEuUNOhJeKhVkvTmAgn0aRqjnNu5iuTJ8lMTBayWygZDBYvsJ8M8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301904; c=relaxed/simple; bh=Yovf9JS3TglfVZYxI2YdkT3wrm6mJQILKZAz5RENbvQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ILL2BgI4wu7Q6o+zA1hqNvgTuplEXn4EfUPcmp6c8tI1DIpgNf5O7vo4tZ+l3Lj8YJUPYWS2hNWhPEeqJxR3nWEpvAPtVyEcwGbsrnqElcgDXIa4/Mx0jKAy2J5T/BXwyYlcnZO28NuDHMiaM9RMtHznKdbWzqUB2R9rJTEAO1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gWFKIJQF; 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="gWFKIJQF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E67C4CEC2; Mon, 2 Sep 2024 18:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301904; bh=Yovf9JS3TglfVZYxI2YdkT3wrm6mJQILKZAz5RENbvQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gWFKIJQFHVZFr+BOwE2K1ny94nxZ9wR3mqJAnNT3E9Wr5eCNJXGbCc31J7GIW+WMV h62hazeilrgpNFM+cnsvW5bvGMs2Cig/VHUJjpGPmCK23+8yG53g8slKiAR7GMtfw5 OUOp0kHxaWSmFzuS+kk4Uho2fazLe/+KGio0VJhW3I7N2Dl421LtBtyz2vUZaaXRQ/ 4558dvn5nxDsQ0nElKmqYA352T/6uFUDaWG02VLDTFETGlLjPNRMwlLeD2MR51wpm4 RWtKHQ0LON0zMYviOez2Voex9lusgjXa3v4GJqSGjp6eNB9LI2jhrX+hLAkuCmIWEa eaMAnLw6LRqvA== Date: Mon, 02 Sep 2024 11:31:43 -0700 Subject: [PATCH 08/10] xfs: replace m_rsumsize with m_rsumblocks From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106897.3326080.10746319260657295000.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 Track the RT summary file size in blocks, just like the RT bitmap file. While we have users of both units, blocks are used slightly more often and this matches the bitmap file for consistency. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rtbitmap.c | 2 +- fs/xfs/libxfs/xfs_trans_resv.c | 2 +- fs/xfs/scrub/rtsummary.c | 11 +++++------ fs/xfs/scrub/rtsummary.h | 2 +- fs/xfs/scrub/rtsummary_repair.c | 12 +++++------- fs/xfs/xfs_mount.h | 2 +- fs/xfs/xfs_rtalloc.c | 13 +++++-------- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 76706e8bbc4e..27a4472402ba 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -162,7 +162,7 @@ xfs_rtsummary_read_buf( { struct xfs_mount *mp = args->mp; - if (XFS_IS_CORRUPT(mp, block >= XFS_B_TO_FSB(mp, mp->m_rsumsize))) { + if (XFS_IS_CORRUPT(mp, block >= mp->m_rsumblocks)) { xfs_rt_mark_sick(args->mp, XFS_SICK_RT_SUMMARY); return -EFSCORRUPTED; } diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 45aaf169806a..2e6d7bb3b5a2 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -918,7 +918,7 @@ xfs_calc_growrtfree_reservation( return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + xfs_calc_inode_res(mp, 2) + xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) + - xfs_calc_buf_res(1, mp->m_rsumsize); + xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, mp->m_rsumblocks)); } /* diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index 3fee603f5244..7c7366c98338 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -63,7 +63,8 @@ xchk_setup_rtsummary( * us to avoid pinning kernel memory for this purpose. */ descr = xchk_xfile_descr(sc, "realtime summary file"); - error = xfile_create(descr, mp->m_rsumsize, &sc->xfile); + error = xfile_create(descr, XFS_FSB_TO_B(mp, mp->m_rsumblocks), + &sc->xfile); kfree(descr); if (error) return error; @@ -95,16 +96,14 @@ xchk_setup_rtsummary( * volume. Hence it is safe to compute and check the geometry values. */ if (mp->m_sb.sb_rblocks) { - xfs_filblks_t rsumblocks; int rextslog; rts->rextents = xfs_rtb_to_rtx(mp, mp->m_sb.sb_rblocks); rextslog = xfs_compute_rextslog(rts->rextents); rts->rsumlevels = rextslog + 1; rts->rbmblocks = xfs_rtbitmap_blockcount(mp, rts->rextents); - rsumblocks = xfs_rtsummary_blockcount(mp, rts->rsumlevels, + rts->rsumblocks = xfs_rtsummary_blockcount(mp, rts->rsumlevels, rts->rbmblocks); - rts->rsumsize = XFS_FSB_TO_B(mp, rsumblocks); } return 0; } @@ -316,7 +315,7 @@ xchk_rtsummary( } /* Is m_rsumsize correct? */ - if (mp->m_rsumsize != rts->rsumsize) { + if (mp->m_rsumblocks != rts->rsumblocks) { xchk_ino_set_corrupt(sc, mp->m_rsumip->i_ino); goto out_rbm; } @@ -332,7 +331,7 @@ xchk_rtsummary( * growfsrt expands the summary file before updating sb_rextents, so * the file can be larger than rsumsize. */ - if (mp->m_rsumip->i_disk_size < rts->rsumsize) { + if (mp->m_rsumip->i_disk_size < XFS_FSB_TO_B(mp, rts->rsumblocks)) { xchk_ino_set_corrupt(sc, mp->m_rsumip->i_ino); goto out_rbm; } diff --git a/fs/xfs/scrub/rtsummary.h b/fs/xfs/scrub/rtsummary.h index e1d50304d8d4..e44b04cb6e2d 100644 --- a/fs/xfs/scrub/rtsummary.h +++ b/fs/xfs/scrub/rtsummary.h @@ -14,7 +14,7 @@ struct xchk_rtsummary { uint64_t rextents; uint64_t rbmblocks; - uint64_t rsumsize; + xfs_filblks_t rsumblocks; unsigned int rsumlevels; unsigned int resblks; diff --git a/fs/xfs/scrub/rtsummary_repair.c b/fs/xfs/scrub/rtsummary_repair.c index d9e971c4c79f..7deeb948cb70 100644 --- a/fs/xfs/scrub/rtsummary_repair.c +++ b/fs/xfs/scrub/rtsummary_repair.c @@ -56,7 +56,7 @@ xrep_setup_rtsummary( * transaction (which we cannot drop because we cannot drop the * rtsummary ILOCK) and cannot ask for more reservation. */ - blocks = XFS_B_TO_FSB(mp, mp->m_rsumsize); + blocks = mp->m_rsumblocks; blocks += xfs_bmbt_calc_size(mp, blocks) * 2; if (blocks > UINT_MAX) return -EOPNOTSUPP; @@ -100,7 +100,6 @@ xrep_rtsummary( { struct xchk_rtsummary *rts = sc->buf; struct xfs_mount *mp = sc->mp; - xfs_filblks_t rsumblocks; int error; /* We require the rmapbt to rebuild anything. */ @@ -131,10 +130,9 @@ xrep_rtsummary( } /* Make sure we have space allocated for the entire summary file. */ - rsumblocks = XFS_B_TO_FSB(mp, rts->rsumsize); xfs_trans_ijoin(sc->tp, sc->ip, 0); xfs_trans_ijoin(sc->tp, sc->tempip, 0); - error = xrep_tempfile_prealloc(sc, 0, rsumblocks); + error = xrep_tempfile_prealloc(sc, 0, rts->rsumblocks); if (error) return error; @@ -143,11 +141,11 @@ xrep_rtsummary( return error; /* Copy the rtsummary file that we generated. */ - error = xrep_tempfile_copyin(sc, 0, rsumblocks, + error = xrep_tempfile_copyin(sc, 0, rts->rsumblocks, xrep_rtsummary_prep_buf, rts); if (error) return error; - error = xrep_tempfile_set_isize(sc, rts->rsumsize); + error = xrep_tempfile_set_isize(sc, XFS_FSB_TO_B(mp, rts->rsumblocks)); if (error) return error; @@ -168,7 +166,7 @@ xrep_rtsummary( memset(mp->m_rsum_cache, 0xFF, mp->m_sb.sb_rbmblocks); mp->m_rsumlevels = rts->rsumlevels; - mp->m_rsumsize = rts->rsumsize; + mp->m_rsumblocks = rts->rsumblocks; /* Free the old rtsummary blocks if they're not in use. */ return xrep_reap_ifork(sc, sc->tempip, XFS_DATA_FORK); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index d0567dfbc036..7bf635cccaa1 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -147,7 +147,7 @@ typedef struct xfs_mount { int m_logbufs; /* number of log buffers */ int m_logbsize; /* size of each log buffer */ uint m_rsumlevels; /* rt summary levels */ - uint m_rsumsize; /* size of rt summary, bytes */ + xfs_filblks_t m_rsumblocks; /* size of rt summary, FSBs */ int m_fixedfsid[2]; /* unchanged for life of FS */ uint m_qflags; /* quota status flags */ uint64_t m_features; /* active filesystem features */ diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 29edb8044b00..3a2005a1e673 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -734,9 +734,8 @@ xfs_growfs_rt_bmblock( 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)); + nmp->m_rsumblocks = xfs_rtsummary_blockcount(mp, nmp->m_rsumlevels, + nmp->m_sb.sb_rbmblocks); /* * Recompute the growfsrt reservation from the new rsumsize, so that the @@ -766,7 +765,7 @@ xfs_growfs_rt_bmblock( * so that inode inactivation won't punch what it thinks are "posteof" * blocks. */ - rsumip->i_disk_size = nmp->m_rsumsize; + rsumip->i_disk_size = nmp->m_rsumblocks * nmp->m_sb.sb_blocksize; i_size_write(VFS_I(rsumip), rsumip->i_disk_size); xfs_trans_log_inode(args.tp, rsumip, XFS_ILOG_CORE); @@ -818,7 +817,7 @@ xfs_growfs_rt_bmblock( * Update the calculated values in the real mount structure. */ mp->m_rsumlevels = nmp->m_rsumlevels; - mp->m_rsumsize = nmp->m_rsumsize; + mp->m_rsumblocks = nmp->m_rsumblocks; xfs_mount_sb_set_rextsize(mp, &mp->m_sb); /* @@ -1022,7 +1021,6 @@ xfs_rtmount_init( struct xfs_buf *bp; /* buffer for last block of subvolume */ struct xfs_sb *sbp; /* filesystem superblock copy in mount */ xfs_daddr_t d; /* address of last block of subvolume */ - unsigned int rsumblocks; int error; sbp = &mp->m_sb; @@ -1034,9 +1032,8 @@ xfs_rtmount_init( return -ENODEV; } mp->m_rsumlevels = sbp->sb_rextslog + 1; - rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels, + mp->m_rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels, mp->m_sb.sb_rbmblocks); - mp->m_rsumsize = XFS_FSB_TO_B(mp, rsumblocks); mp->m_rbmip = mp->m_rsumip = NULL; /* * Check that the realtime section is an ok size. From patchwork Mon Sep 2 18:31: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: 13787618 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 13D1419CC04 for ; Mon, 2 Sep 2024 18:32: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=1725301920; cv=none; b=iqpfsVMiW4OYX3hAyM3a3RHuEtFi3Pb2hZN2Z0qCGDSdwwOFGn4kSNDAMhn7P12qMW2CzzpzLkSP7kKfbeyf/4uQzmttT3ebItJ1kiuGxv9tB07gW5+B8QQAtrz3XrkyNOHPAgvdFAVlkflP1qZnuzHc7dmq0uAWyv0pAATqVkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301920; c=relaxed/simple; bh=PLSvqTWky3Mj7Et94DcI+AANmhVH+bn/gGVSBPfnpXI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WCHSo/12/cHBmxLUzFwB+uyYbCbcd6KljhlJ+Ctp11a6yY+aADOBJULh6FrOe0OmpUstHFkQ2WLf843aNgzLKGQ/qh8nlq0gY/hDXDiod4oUfx4O4k+887m2oulY0rqGa63qkieAWFHjvuP4eCU920NsdXoCkalE5FIc9lE9p64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZW+0FRmL; 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="ZW+0FRmL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E120AC4CEC2; Mon, 2 Sep 2024 18:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301919; bh=PLSvqTWky3Mj7Et94DcI+AANmhVH+bn/gGVSBPfnpXI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZW+0FRmLZGJ2YoLlHhs4k5T677If//hXOi7rbHn9mcLSNBRw86dTsW6e+YVgqirG4 B0u4ijo4JOVHpsF72S1q1BdVbXheDp98B506gQIRM6n6Jb++OzdYwA2sMva/llsYdd vTOPigaeYUxPKBmQ+h1XypxvOQbxItvcY9N3TBDijAkxk5S+FNKMFNAG9JYEzXO1XL 7E+gV8hyX+nTRTu4dQnLVT3+7YnqgiDQy8ua6tgEopmVjNNzFz3cTgBg3KNHaUmtoB jrCV+mxI7fDVH5W+9EqFwfU2Ldq4dGhyG0mZdS2dlCyCWwYxKJI6y6p+44FUVELljy E0tGgt6Hd6jbw== Date: Mon, 02 Sep 2024 11:31:59 -0700 Subject: [PATCH 09/10] xfs: rearrange xfs_fsmap.c a little bit From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106914.3326080.18443901492043365071.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 order of the functions in this file has gotten a little confusing over the years. Specifically, the two data device implementations (bnobt and rmapbt) could be adjacent in the source code instead of split in two by the logdev and rtdev fsmap implementations. We're about to add more functionality to this file, so rearrange things now. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_fsmap.c | 268 ++++++++++++++++++++++++++-------------------------- 1 file changed, 134 insertions(+), 134 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index e15446626875..615253406fde 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -441,140 +441,6 @@ xfs_getfsmap_set_irec_flags( irec->rm_flags |= XFS_RMAP_UNWRITTEN; } -/* Execute a getfsmap query against the log device. */ -STATIC int -xfs_getfsmap_logdev( - struct xfs_trans *tp, - const struct xfs_fsmap *keys, - struct xfs_getfsmap_info *info) -{ - struct xfs_mount *mp = tp->t_mountp; - struct xfs_rmap_irec rmap; - xfs_daddr_t rec_daddr, len_daddr; - xfs_fsblock_t start_fsb, end_fsb; - uint64_t eofs; - - eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); - if (keys[0].fmr_physical >= eofs) - return 0; - start_fsb = XFS_BB_TO_FSBT(mp, - keys[0].fmr_physical + keys[0].fmr_length); - end_fsb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical)); - - /* Adjust the low key if we are continuing from where we left off. */ - if (keys[0].fmr_length > 0) - info->low_daddr = XFS_FSB_TO_BB(mp, start_fsb); - - trace_xfs_fsmap_low_key_linear(mp, info->dev, start_fsb); - trace_xfs_fsmap_high_key_linear(mp, info->dev, end_fsb); - - if (start_fsb > 0) - return 0; - - /* Fabricate an rmap entry for the external log device. */ - rmap.rm_startblock = 0; - rmap.rm_blockcount = mp->m_sb.sb_logblocks; - rmap.rm_owner = XFS_RMAP_OWN_LOG; - rmap.rm_offset = 0; - rmap.rm_flags = 0; - - rec_daddr = XFS_FSB_TO_BB(mp, rmap.rm_startblock); - len_daddr = XFS_FSB_TO_BB(mp, rmap.rm_blockcount); - return xfs_getfsmap_helper(tp, info, &rmap, rec_daddr, len_daddr); -} - -#ifdef CONFIG_XFS_RT -/* Transform a rtbitmap "record" into a fsmap */ -STATIC int -xfs_getfsmap_rtdev_rtbitmap_helper( - struct xfs_mount *mp, - struct xfs_trans *tp, - const struct xfs_rtalloc_rec *rec, - void *priv) -{ - struct xfs_getfsmap_info *info = priv; - struct xfs_rmap_irec irec; - xfs_rtblock_t rtbno; - xfs_daddr_t rec_daddr, len_daddr; - - rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext); - rec_daddr = XFS_FSB_TO_BB(mp, rtbno); - irec.rm_startblock = rtbno; - - rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount); - len_daddr = XFS_FSB_TO_BB(mp, rtbno); - irec.rm_blockcount = rtbno; - - irec.rm_owner = XFS_RMAP_OWN_NULL; /* "free" */ - irec.rm_offset = 0; - irec.rm_flags = 0; - - return xfs_getfsmap_helper(tp, info, &irec, rec_daddr, len_daddr); -} - -/* Execute a getfsmap query against the realtime device rtbitmap. */ -STATIC int -xfs_getfsmap_rtdev_rtbitmap( - struct xfs_trans *tp, - const struct xfs_fsmap *keys, - struct xfs_getfsmap_info *info) -{ - - 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; - - eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents)); - if (keys[0].fmr_physical >= eofs) - return 0; - start_rtb = XFS_BB_TO_FSBT(mp, - keys[0].fmr_physical + keys[0].fmr_length); - end_rtb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical)); - - info->missing_owner = XFS_FMR_OWN_UNKNOWN; - - /* Adjust the low key if we are continuing from where we left off. */ - if (keys[0].fmr_length > 0) { - info->low_daddr = XFS_FSB_TO_BB(mp, start_rtb); - if (info->low_daddr >= eofs) - return 0; - } - - trace_xfs_fsmap_low_key_linear(mp, info->dev, start_rtb); - trace_xfs_fsmap_high_key_linear(mp, info->dev, end_rtb); - - xfs_rtbitmap_lock_shared(mp, XFS_RBMLOCK_BITMAP); - - /* - * Set up query parameters to return free rtextents covering the range - * we want. - */ - 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; - - /* - * Report any gaps at the end of the rtbitmap by simulating a null - * rmap starting at the block after the end of the query range. - */ - info->last = true; - ahigh.ar_startext = min(mp->m_sb.sb_rextents, high); - - error = xfs_getfsmap_rtdev_rtbitmap_helper(mp, tp, &ahigh, info); - if (error) - goto err; -err: - xfs_rtbitmap_unlock_shared(mp, XFS_RBMLOCK_BITMAP); - return error; -} -#endif /* CONFIG_XFS_RT */ - static inline bool rmap_not_shareable(struct xfs_mount *mp, const struct xfs_rmap_irec *r) { @@ -799,6 +665,140 @@ xfs_getfsmap_datadev_bnobt( xfs_getfsmap_datadev_bnobt_query, &akeys[0]); } +/* Execute a getfsmap query against the log device. */ +STATIC int +xfs_getfsmap_logdev( + struct xfs_trans *tp, + const struct xfs_fsmap *keys, + struct xfs_getfsmap_info *info) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_rmap_irec rmap; + xfs_daddr_t rec_daddr, len_daddr; + xfs_fsblock_t start_fsb, end_fsb; + uint64_t eofs; + + eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); + if (keys[0].fmr_physical >= eofs) + return 0; + start_fsb = XFS_BB_TO_FSBT(mp, + keys[0].fmr_physical + keys[0].fmr_length); + end_fsb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical)); + + /* Adjust the low key if we are continuing from where we left off. */ + if (keys[0].fmr_length > 0) + info->low_daddr = XFS_FSB_TO_BB(mp, start_fsb); + + trace_xfs_fsmap_low_key_linear(mp, info->dev, start_fsb); + trace_xfs_fsmap_high_key_linear(mp, info->dev, end_fsb); + + if (start_fsb > 0) + return 0; + + /* Fabricate an rmap entry for the external log device. */ + rmap.rm_startblock = 0; + rmap.rm_blockcount = mp->m_sb.sb_logblocks; + rmap.rm_owner = XFS_RMAP_OWN_LOG; + rmap.rm_offset = 0; + rmap.rm_flags = 0; + + rec_daddr = XFS_FSB_TO_BB(mp, rmap.rm_startblock); + len_daddr = XFS_FSB_TO_BB(mp, rmap.rm_blockcount); + return xfs_getfsmap_helper(tp, info, &rmap, rec_daddr, len_daddr); +} + +#ifdef CONFIG_XFS_RT +/* Transform a rtbitmap "record" into a fsmap */ +STATIC int +xfs_getfsmap_rtdev_rtbitmap_helper( + struct xfs_mount *mp, + struct xfs_trans *tp, + const struct xfs_rtalloc_rec *rec, + void *priv) +{ + struct xfs_getfsmap_info *info = priv; + struct xfs_rmap_irec irec; + xfs_rtblock_t rtbno; + xfs_daddr_t rec_daddr, len_daddr; + + rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext); + rec_daddr = XFS_FSB_TO_BB(mp, rtbno); + irec.rm_startblock = rtbno; + + rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount); + len_daddr = XFS_FSB_TO_BB(mp, rtbno); + irec.rm_blockcount = rtbno; + + irec.rm_owner = XFS_RMAP_OWN_NULL; /* "free" */ + irec.rm_offset = 0; + irec.rm_flags = 0; + + return xfs_getfsmap_helper(tp, info, &irec, rec_daddr, len_daddr); +} + +/* Execute a getfsmap query against the realtime device rtbitmap. */ +STATIC int +xfs_getfsmap_rtdev_rtbitmap( + struct xfs_trans *tp, + const struct xfs_fsmap *keys, + struct xfs_getfsmap_info *info) +{ + + 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; + + eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents)); + if (keys[0].fmr_physical >= eofs) + return 0; + start_rtb = XFS_BB_TO_FSBT(mp, + keys[0].fmr_physical + keys[0].fmr_length); + end_rtb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical)); + + info->missing_owner = XFS_FMR_OWN_UNKNOWN; + + /* Adjust the low key if we are continuing from where we left off. */ + if (keys[0].fmr_length > 0) { + info->low_daddr = XFS_FSB_TO_BB(mp, start_rtb); + if (info->low_daddr >= eofs) + return 0; + } + + trace_xfs_fsmap_low_key_linear(mp, info->dev, start_rtb); + trace_xfs_fsmap_high_key_linear(mp, info->dev, end_rtb); + + xfs_rtbitmap_lock_shared(mp, XFS_RBMLOCK_BITMAP); + + /* + * Set up query parameters to return free rtextents covering the range + * we want. + */ + 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; + + /* + * Report any gaps at the end of the rtbitmap by simulating a null + * rmap starting at the block after the end of the query range. + */ + info->last = true; + ahigh.ar_startext = min(mp->m_sb.sb_rextents, high); + + error = xfs_getfsmap_rtdev_rtbitmap_helper(mp, tp, &ahigh, info); + if (error) + goto err; +err: + xfs_rtbitmap_unlock_shared(mp, XFS_RBMLOCK_BITMAP); + return error; +} +#endif /* CONFIG_XFS_RT */ + /* Do we recognize the device? */ STATIC bool xfs_getfsmap_is_valid_device( From patchwork Mon Sep 2 18:32: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: 13787619 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 1287519CC04 for ; Mon, 2 Sep 2024 18:32: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=1725301936; cv=none; b=oJx+g5BSDGfNdcfIJxbpVXeST7JlTNGEpo+2S75cbFzWr37Mqfd4EJIQW81ylYxZi8srD2i7vy2jLrZEo7FxAQY1U17lqVG0uoASYzp9aa71AIkuRmw/8dI108FGfI+72w8zpgZXo6UisMQM7qQMS+3twStWjrYA6TphMeGZE/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301936; c=relaxed/simple; bh=haRgdh+s5nTLR6J5ufLuRVIb/UuwCX2+mg1WZoh6/aE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TPKIZVi4oQzWJLxg7TLZDzW6mJfYaOUORbgKCU/j1u7UaqjXD/lbjfZoWCG15fsik636du+mUVD3gW8dzfbYMY5gD9R/nh3lUW5wdKWls7Yit9dzUA+D3Mv1v5Hpu3CALxGigKjsjl2V0Bxdp1YKIXUbtiW7oAbnQRUhbJO01J0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FZmFNina; 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="FZmFNina" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8968EC4CEC2; Mon, 2 Sep 2024 18:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301935; bh=haRgdh+s5nTLR6J5ufLuRVIb/UuwCX2+mg1WZoh6/aE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FZmFNinabrW8F5cgIXXEW12kbuePULO0awYfkoi0irMA5XfuBOFciA5xq2tEQ8yJs lbeXtckiXPFuvpbBzw8M1I1Ybq4dIm8wMAXZKPApV0JOIfKlu9/IdHvuJBSoNnmhi4 480oj2yyRM7aWSvEoc0u+R8+lDi6c+FjozxwX9DeuyQErqwo8/849itqY2sQ+6FOPU zDbafWQr/ZEmCJuSLmqFrah5panJ/PzXtniAIR7mm+n56pbiA57Ju1cQnar9CE8tWb /+BMNaxPVXqRhPbnKaH9i57e6JJr9ZeosJ23UGeKZJOESSe2qjXiiI8EGnGgWZ1ivA suIgQtzt88Tww== Date: Mon, 02 Sep 2024 11:32:15 -0700 Subject: [PATCH 10/10] xfs: move xfs_ioc_getfsmap out of xfs_ioctl.c From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530106930.3326080.442944321188284872.stgit@frogsfrogsfrogs> In-Reply-To: <172530106749.3326080.9105141649726807892.stgit@frogsfrogsfrogs> References: <172530106749.3326080.9105141649726807892.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 Move this function out of xfs_ioctl.c to reduce the clutter in there, and make the entire getfsmap implementation self-contained in a single file. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_fsmap.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_fsmap.h | 6 +- fs/xfs/xfs_ioctl.c | 130 -------------------------------------------------- 3 files changed, 134 insertions(+), 136 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 615253406fde..ae18ab86e608 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -44,7 +44,7 @@ xfs_fsmap_from_internal( } /* Convert an fsmap to an xfs_fsmap. */ -void +static void xfs_fsmap_to_internal( struct xfs_fsmap *dest, struct fsmap *src) @@ -889,7 +889,7 @@ xfs_getfsmap_check_keys( * xfs_getfsmap_info.low/high -- per-AG low/high keys computed from * dkeys; used to query the metadata. */ -int +STATIC int xfs_getfsmap( struct xfs_mount *mp, struct xfs_fsmap_head *head, @@ -1019,3 +1019,133 @@ xfs_getfsmap( head->fmh_oflags = FMH_OF_DEV_T; return error; } + +int +xfs_ioc_getfsmap( + struct xfs_inode *ip, + struct fsmap_head __user *arg) +{ + struct xfs_fsmap_head xhead = {0}; + struct fsmap_head head; + struct fsmap *recs; + unsigned int count; + __u32 last_flags = 0; + bool done = false; + int error; + + if (copy_from_user(&head, arg, sizeof(struct fsmap_head))) + return -EFAULT; + if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) || + memchr_inv(head.fmh_keys[0].fmr_reserved, 0, + sizeof(head.fmh_keys[0].fmr_reserved)) || + memchr_inv(head.fmh_keys[1].fmr_reserved, 0, + sizeof(head.fmh_keys[1].fmr_reserved))) + return -EINVAL; + + /* + * Use an internal memory buffer so that we don't have to copy fsmap + * data to userspace while holding locks. Start by trying to allocate + * up to 128k for the buffer, but fall back to a single page if needed. + */ + count = min_t(unsigned int, head.fmh_count, + 131072 / sizeof(struct fsmap)); + recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL); + if (!recs) { + count = min_t(unsigned int, head.fmh_count, + PAGE_SIZE / sizeof(struct fsmap)); + recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL); + if (!recs) + return -ENOMEM; + } + + xhead.fmh_iflags = head.fmh_iflags; + xfs_fsmap_to_internal(&xhead.fmh_keys[0], &head.fmh_keys[0]); + xfs_fsmap_to_internal(&xhead.fmh_keys[1], &head.fmh_keys[1]); + + trace_xfs_getfsmap_low_key(ip->i_mount, &xhead.fmh_keys[0]); + trace_xfs_getfsmap_high_key(ip->i_mount, &xhead.fmh_keys[1]); + + head.fmh_entries = 0; + do { + struct fsmap __user *user_recs; + struct fsmap *last_rec; + + user_recs = &arg->fmh_recs[head.fmh_entries]; + xhead.fmh_entries = 0; + xhead.fmh_count = min_t(unsigned int, count, + head.fmh_count - head.fmh_entries); + + /* Run query, record how many entries we got. */ + error = xfs_getfsmap(ip->i_mount, &xhead, recs); + switch (error) { + case 0: + /* + * There are no more records in the result set. Copy + * whatever we got to userspace and break out. + */ + done = true; + break; + case -ECANCELED: + /* + * The internal memory buffer is full. Copy whatever + * records we got to userspace and go again if we have + * not yet filled the userspace buffer. + */ + error = 0; + break; + default: + goto out_free; + } + head.fmh_entries += xhead.fmh_entries; + head.fmh_oflags = xhead.fmh_oflags; + + /* + * If the caller wanted a record count or there aren't any + * new records to return, we're done. + */ + if (head.fmh_count == 0 || xhead.fmh_entries == 0) + break; + + /* Copy all the records we got out to userspace. */ + if (copy_to_user(user_recs, recs, + xhead.fmh_entries * sizeof(struct fsmap))) { + error = -EFAULT; + goto out_free; + } + + /* Remember the last record flags we copied to userspace. */ + last_rec = &recs[xhead.fmh_entries - 1]; + last_flags = last_rec->fmr_flags; + + /* Set up the low key for the next iteration. */ + xfs_fsmap_to_internal(&xhead.fmh_keys[0], last_rec); + trace_xfs_getfsmap_low_key(ip->i_mount, &xhead.fmh_keys[0]); + } while (!done && head.fmh_entries < head.fmh_count); + + /* + * If there are no more records in the query result set and we're not + * in counting mode, mark the last record returned with the LAST flag. + */ + if (done && head.fmh_count > 0 && head.fmh_entries > 0) { + struct fsmap __user *user_rec; + + last_flags |= FMR_OF_LAST; + user_rec = &arg->fmh_recs[head.fmh_entries - 1]; + + if (copy_to_user(&user_rec->fmr_flags, &last_flags, + sizeof(last_flags))) { + error = -EFAULT; + goto out_free; + } + } + + /* copy back header */ + if (copy_to_user(arg, &head, sizeof(struct fsmap_head))) { + error = -EFAULT; + goto out_free; + } + +out_free: + kvfree(recs); + return error; +} diff --git a/fs/xfs/xfs_fsmap.h b/fs/xfs/xfs_fsmap.h index a0775788e7b1..a0bcc38486a5 100644 --- a/fs/xfs/xfs_fsmap.h +++ b/fs/xfs/xfs_fsmap.h @@ -7,6 +7,7 @@ #define __XFS_FSMAP_H__ struct fsmap; +struct fsmap_head; /* internal fsmap representation */ struct xfs_fsmap { @@ -27,9 +28,6 @@ struct xfs_fsmap_head { struct xfs_fsmap fmh_keys[2]; /* low and high keys */ }; -void xfs_fsmap_to_internal(struct xfs_fsmap *dest, struct fsmap *src); - -int xfs_getfsmap(struct xfs_mount *mp, struct xfs_fsmap_head *head, - struct fsmap *out_recs); +int xfs_ioc_getfsmap(struct xfs_inode *ip, struct fsmap_head __user *arg); #endif /* __XFS_FSMAP_H__ */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 90b3ee21e7fe..7226d27e8afc 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -876,136 +876,6 @@ xfs_ioc_getbmap( return error; } -STATIC int -xfs_ioc_getfsmap( - struct xfs_inode *ip, - struct fsmap_head __user *arg) -{ - struct xfs_fsmap_head xhead = {0}; - struct fsmap_head head; - struct fsmap *recs; - unsigned int count; - __u32 last_flags = 0; - bool done = false; - int error; - - if (copy_from_user(&head, arg, sizeof(struct fsmap_head))) - return -EFAULT; - if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) || - memchr_inv(head.fmh_keys[0].fmr_reserved, 0, - sizeof(head.fmh_keys[0].fmr_reserved)) || - memchr_inv(head.fmh_keys[1].fmr_reserved, 0, - sizeof(head.fmh_keys[1].fmr_reserved))) - return -EINVAL; - - /* - * Use an internal memory buffer so that we don't have to copy fsmap - * data to userspace while holding locks. Start by trying to allocate - * up to 128k for the buffer, but fall back to a single page if needed. - */ - count = min_t(unsigned int, head.fmh_count, - 131072 / sizeof(struct fsmap)); - recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL); - if (!recs) { - count = min_t(unsigned int, head.fmh_count, - PAGE_SIZE / sizeof(struct fsmap)); - recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL); - if (!recs) - return -ENOMEM; - } - - xhead.fmh_iflags = head.fmh_iflags; - xfs_fsmap_to_internal(&xhead.fmh_keys[0], &head.fmh_keys[0]); - xfs_fsmap_to_internal(&xhead.fmh_keys[1], &head.fmh_keys[1]); - - trace_xfs_getfsmap_low_key(ip->i_mount, &xhead.fmh_keys[0]); - trace_xfs_getfsmap_high_key(ip->i_mount, &xhead.fmh_keys[1]); - - head.fmh_entries = 0; - do { - struct fsmap __user *user_recs; - struct fsmap *last_rec; - - user_recs = &arg->fmh_recs[head.fmh_entries]; - xhead.fmh_entries = 0; - xhead.fmh_count = min_t(unsigned int, count, - head.fmh_count - head.fmh_entries); - - /* Run query, record how many entries we got. */ - error = xfs_getfsmap(ip->i_mount, &xhead, recs); - switch (error) { - case 0: - /* - * There are no more records in the result set. Copy - * whatever we got to userspace and break out. - */ - done = true; - break; - case -ECANCELED: - /* - * The internal memory buffer is full. Copy whatever - * records we got to userspace and go again if we have - * not yet filled the userspace buffer. - */ - error = 0; - break; - default: - goto out_free; - } - head.fmh_entries += xhead.fmh_entries; - head.fmh_oflags = xhead.fmh_oflags; - - /* - * If the caller wanted a record count or there aren't any - * new records to return, we're done. - */ - if (head.fmh_count == 0 || xhead.fmh_entries == 0) - break; - - /* Copy all the records we got out to userspace. */ - if (copy_to_user(user_recs, recs, - xhead.fmh_entries * sizeof(struct fsmap))) { - error = -EFAULT; - goto out_free; - } - - /* Remember the last record flags we copied to userspace. */ - last_rec = &recs[xhead.fmh_entries - 1]; - last_flags = last_rec->fmr_flags; - - /* Set up the low key for the next iteration. */ - xfs_fsmap_to_internal(&xhead.fmh_keys[0], last_rec); - trace_xfs_getfsmap_low_key(ip->i_mount, &xhead.fmh_keys[0]); - } while (!done && head.fmh_entries < head.fmh_count); - - /* - * If there are no more records in the query result set and we're not - * in counting mode, mark the last record returned with the LAST flag. - */ - if (done && head.fmh_count > 0 && head.fmh_entries > 0) { - struct fsmap __user *user_rec; - - last_flags |= FMR_OF_LAST; - user_rec = &arg->fmh_recs[head.fmh_entries - 1]; - - if (copy_to_user(&user_rec->fmr_flags, &last_flags, - sizeof(last_flags))) { - error = -EFAULT; - goto out_free; - } - } - - /* copy back header */ - if (copy_to_user(arg, &head, sizeof(struct fsmap_head))) { - error = -EFAULT; - goto out_free; - } - -out_free: - kvfree(recs); - return error; -} - int xfs_ioc_swapext( xfs_swapext_t *sxp)