From patchwork Thu Feb 15 12:08:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13558282 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 598C612C528 for ; Thu, 15 Feb 2024 12:09:35 +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=1707998975; cv=none; b=PGbfWzgr8kj5v6BPmHpVZNJ2WBCezoeLxZDXkHk6aZs80FMk6QUOW24E3vrgkaJ0WQBMbqZwPiNnNiNic6w97Qxu4xwXn21zWoujlNY7vvNk38pAhxw7EwV5etD0uICQFwuYcnhcrtyCnV6fB4LVV4Ut/q8DcxNz0rkbeXTu88A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707998975; c=relaxed/simple; bh=sforYTTci2irX6gJYBl8Bz1X0/VBmVBV2BtOtGD7Ux0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mNEVjoA9yRDhp1LcRnmiL43CRzNAd9EdqYswTMNMJuRxA1rVUhpG5F96FxR2CGSPL4JlL3qGPq9F5LrySZrW8XZOrgMOom94PL24Xis0yrd+u6tPbG1qB/dn3FKx6U0XcIWcIN5e1Zzrr5Gy+lmILeVDizoiWCXDMNhttu6ny4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CD19kbNo; 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="CD19kbNo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95779C433C7 for ; Thu, 15 Feb 2024 12:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707998975; bh=sforYTTci2irX6gJYBl8Bz1X0/VBmVBV2BtOtGD7Ux0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CD19kbNoRQHif13tH9DlFcCzk8Y92PC829k31man3xtJbROZOQx4lbBOADBLFUYtc O954XhAOIma140M2qd5bp3SezgZb0Mj/ld+4F2Rcy/XMTFE740pMrG7nbMKTe7Rwa4 3LCUA+52Op7kF5quhyGQr2MCKb7WYXatd1I90TfELccFqbtyUUbI+YXpcgp67hX9GF VzyilQc6Z5b7ICGHjCp5QvWa2AS8N1Fh2R7gLmy5Fky6j4yJdGK7xJmLkkdMcayIiu MtRoMISZ7ZSnZE9kHttzG4BHbMEBwi/PihR8OrgsjpinJrmfTe5SX/37BrQY/LpD4y Ask91JqBtXCfQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Subject: [PATCH 19/35] xfs: convert open-coded xfs_rtword_t pointer accesses to helper Date: Thu, 15 Feb 2024 13:08:31 +0100 Message-ID: <20240215120907.1542854-20-cem@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215120907.1542854-1-cem@kernel.org> References: <20240215120907.1542854-1-cem@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Darrick J. Wong" Source kernel commit: a9948626849c2c65dfd201b5e9d855e62937de61 There are a bunch of places where we use open-coded logic to find a pointer to an xfs_rtword_t within a rt bitmap buffer. Convert all that to helper functions for better type safety. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.c | 59 +++++++++++++++++++++++-------------------- libxfs/xfs_rtbitmap.h | 11 ++++++++ 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 6776e45c1..fce88c759 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -101,7 +101,6 @@ xfs_rtfind_back( int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ struct xfs_buf *bp; /* buf for the block */ - xfs_rtword_t *bufp; /* starting word in buffer */ int error; /* error value */ xfs_rtxnum_t firstbit; /* first useful bit in the word */ xfs_rtxnum_t i; /* current bit number rel. to start */ @@ -119,12 +118,12 @@ xfs_rtfind_back( if (error) { return error; } - bufp = bp->b_addr; + /* * Get the first word's index & point to it. */ word = xfs_rtx_to_rbmword(mp, start); - b = &bufp[word]; + b = xfs_rbmblock_wordptr(bp, word); bit = (int)(start & (XFS_NBWORD - 1)); len = start - limit + 1; /* @@ -171,9 +170,9 @@ xfs_rtfind_back( if (error) { return error; } - bufp = bp->b_addr; + word = mp->m_blockwsize - 1; - b = &bufp[word]; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the previous word in the buffer. @@ -217,9 +216,9 @@ xfs_rtfind_back( if (error) { return error; } - bufp = bp->b_addr; + word = mp->m_blockwsize - 1; - b = &bufp[word]; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the previous word in the buffer. @@ -276,7 +275,6 @@ xfs_rtfind_forw( int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ struct xfs_buf *bp; /* buf for the block */ - xfs_rtword_t *bufp; /* starting word in buffer */ int error; /* error value */ xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t lastbit; /* last useful bit in the word */ @@ -294,12 +292,12 @@ xfs_rtfind_forw( if (error) { return error; } - bufp = bp->b_addr; + /* * Get the first word's index & point to it. */ word = xfs_rtx_to_rbmword(mp, start); - b = &bufp[word]; + b = xfs_rbmblock_wordptr(bp, word); bit = (int)(start & (XFS_NBWORD - 1)); len = limit - start + 1; /* @@ -345,8 +343,9 @@ xfs_rtfind_forw( if (error) { return error; } - b = bufp = bp->b_addr; + word = 0; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the previous word in the buffer. @@ -390,8 +389,9 @@ xfs_rtfind_forw( if (error) { return error; } - b = bufp = bp->b_addr; + word = 0; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the next word in the buffer. @@ -539,7 +539,6 @@ xfs_rtmodify_range( int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ struct xfs_buf *bp; /* buf for the block */ - xfs_rtword_t *bufp; /* starting word in buffer */ int error; /* error value */ xfs_rtword_t *first; /* first used word in the buffer */ int i; /* current bit number rel. to start */ @@ -558,12 +557,12 @@ xfs_rtmodify_range( if (error) { return error; } - bufp = bp->b_addr; + /* * Compute the starting word's address, and starting bit. */ word = xfs_rtx_to_rbmword(mp, start); - first = b = &bufp[word]; + first = b = xfs_rbmblock_wordptr(bp, word); bit = (int)(start & (XFS_NBWORD - 1)); /* * 0 (allocated) => all zeroes; 1 (free) => all ones. @@ -597,14 +596,15 @@ xfs_rtmodify_range( * Get the next one. */ xfs_trans_log_buf(tp, bp, - (uint)((char *)first - (char *)bufp), - (uint)((char *)b - (char *)bufp)); + (uint)((char *)first - (char *)bp->b_addr), + (uint)((char *)b - (char *)bp->b_addr)); error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); if (error) { return error; } - first = b = bufp = bp->b_addr; + word = 0; + first = b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the next word in the buffer @@ -637,14 +637,15 @@ xfs_rtmodify_range( * Get the next one. */ xfs_trans_log_buf(tp, bp, - (uint)((char *)first - (char *)bufp), - (uint)((char *)b - (char *)bufp)); + (uint)((char *)first - (char *)bp->b_addr), + (uint)((char *)b - (char *)bp->b_addr)); error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); if (error) { return error; } - first = b = bufp = bp->b_addr; + word = 0; + first = b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the next word in the buffer @@ -674,8 +675,9 @@ xfs_rtmodify_range( * Log any remaining changed bytes. */ if (b > first) - xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp), - (uint)((char *)b - (char *)bufp - 1)); + xfs_trans_log_buf(tp, bp, + (uint)((char *)first - (char *)bp->b_addr), + (uint)((char *)b - (char *)bp->b_addr - 1)); return 0; } @@ -773,7 +775,6 @@ xfs_rtcheck_range( int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ struct xfs_buf *bp; /* buf for the block */ - xfs_rtword_t *bufp; /* starting word in buffer */ int error; /* error value */ xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t lastbit; /* last useful bit in word */ @@ -792,12 +793,12 @@ xfs_rtcheck_range( if (error) { return error; } - bufp = bp->b_addr; + /* * Compute the starting word's address, and starting bit. */ word = xfs_rtx_to_rbmword(mp, start); - b = &bufp[word]; + b = xfs_rbmblock_wordptr(bp, word); bit = (int)(start & (XFS_NBWORD - 1)); /* * 0 (allocated) => all zero's; 1 (free) => all one's. @@ -843,8 +844,9 @@ xfs_rtcheck_range( if (error) { return error; } - b = bufp = bp->b_addr; + word = 0; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the next word in the buffer. @@ -889,8 +891,9 @@ xfs_rtcheck_range( if (error) { return error; } - b = bufp = bp->b_addr; + word = 0; + b = xfs_rbmblock_wordptr(bp, word); } else { /* * Go on to the next word in the buffer. diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index a382b38c6..3252ed217 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -158,6 +158,17 @@ xfs_rbmblock_to_rtx( return rbmoff << mp->m_blkbit_log; } +/* Return a pointer to a bitmap word within a rt bitmap block. */ +static inline xfs_rtword_t * +xfs_rbmblock_wordptr( + struct xfs_buf *bp, + unsigned int index) +{ + xfs_rtword_t *words = bp->b_addr; + + return words + index; +} + /* * Functions for walking free space rtextents in the realtime bitmap. */