[2/4] xfs: replace open-coded bitmap weight logic
diff mbox series

Message ID 157063975219.2913318.17554625502389919068.stgit@magnolia
State New
Headers show
Series
  • xfs: rework online repair incore bitmap
Related show

Commit Message

Darrick J. Wong Oct. 9, 2019, 4:49 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Add a xbitmap_hweight helper function so that we can get rid of the
open-coded loop.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/scrub/agheader_repair.c |   12 ++----------
 fs/xfs/scrub/bitmap.c          |   15 +++++++++++++++
 fs/xfs/scrub/bitmap.h          |    1 +
 3 files changed, 18 insertions(+), 10 deletions(-)

Comments

Brian Foster Oct. 21, 2019, 2:34 p.m. UTC | #1
On Wed, Oct 09, 2019 at 09:49:12AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add a xbitmap_hweight helper function so that we can get rid of the
> open-coded loop.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/scrub/agheader_repair.c |   12 ++----------
>  fs/xfs/scrub/bitmap.c          |   15 +++++++++++++++
>  fs/xfs/scrub/bitmap.h          |    1 +
>  3 files changed, 18 insertions(+), 10 deletions(-)
> 
> 
> diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c
> index 9fbb6035f4e2..f35596cc26fb 100644
> --- a/fs/xfs/scrub/agheader_repair.c
> +++ b/fs/xfs/scrub/agheader_repair.c
> @@ -482,8 +482,6 @@ xrep_agfl_collect_blocks(
>  	struct xrep_agfl	ra;
>  	struct xfs_mount	*mp = sc->mp;
>  	struct xfs_btree_cur	*cur;
> -	struct xbitmap_range	*br;
> -	struct xbitmap_range	*n;
>  	int			error;
>  
>  	ra.sc = sc;
> @@ -527,14 +525,8 @@ xrep_agfl_collect_blocks(
>  	 * Calculate the new AGFL size.  If we found more blocks than fit in
>  	 * the AGFL we'll free them later.
>  	 */
> -	*flcount = 0;
> -	for_each_xbitmap_extent(br, n, agfl_extents) {
> -		*flcount += br->len;
> -		if (*flcount > xfs_agfl_size(mp))
> -			break;
> -	}
> -	if (*flcount > xfs_agfl_size(mp))
> -		*flcount = xfs_agfl_size(mp);
> +	*flcount = min_t(uint64_t, xbitmap_hweight(agfl_extents),
> +			 xfs_agfl_size(mp));
>  	return 0;
>  
>  err:
> diff --git a/fs/xfs/scrub/bitmap.c b/fs/xfs/scrub/bitmap.c
> index 5b07b46c89c9..8b704d7b5855 100644
> --- a/fs/xfs/scrub/bitmap.c
> +++ b/fs/xfs/scrub/bitmap.c
> @@ -296,3 +296,18 @@ xbitmap_set_btblocks(
>  {
>  	return xfs_btree_visit_blocks(cur, xbitmap_collect_btblock, bitmap);
>  }
> +
> +/* How many bits are set in this bitmap? */
> +uint64_t
> +xbitmap_hweight(
> +	struct xbitmap		*bitmap)
> +{
> +	struct xbitmap_range	*bmr;
> +	struct xbitmap_range	*n;
> +	uint64_t		ret = 0;
> +
> +	for_each_xbitmap_extent(bmr, n, bitmap)
> +		ret += bmr->len;
> +
> +	return ret;
> +}
> diff --git a/fs/xfs/scrub/bitmap.h b/fs/xfs/scrub/bitmap.h
> index 8db4017ac78e..900646b72de1 100644
> --- a/fs/xfs/scrub/bitmap.h
> +++ b/fs/xfs/scrub/bitmap.h
> @@ -32,5 +32,6 @@ int xbitmap_set_btcur_path(struct xbitmap *bitmap,
>  		struct xfs_btree_cur *cur);
>  int xbitmap_set_btblocks(struct xbitmap *bitmap,
>  		struct xfs_btree_cur *cur);
> +uint64_t xbitmap_hweight(struct xbitmap *bitmap);
>  
>  #endif	/* __XFS_SCRUB_BITMAP_H__ */
>

Patch
diff mbox series

diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c
index 9fbb6035f4e2..f35596cc26fb 100644
--- a/fs/xfs/scrub/agheader_repair.c
+++ b/fs/xfs/scrub/agheader_repair.c
@@ -482,8 +482,6 @@  xrep_agfl_collect_blocks(
 	struct xrep_agfl	ra;
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_btree_cur	*cur;
-	struct xbitmap_range	*br;
-	struct xbitmap_range	*n;
 	int			error;
 
 	ra.sc = sc;
@@ -527,14 +525,8 @@  xrep_agfl_collect_blocks(
 	 * Calculate the new AGFL size.  If we found more blocks than fit in
 	 * the AGFL we'll free them later.
 	 */
-	*flcount = 0;
-	for_each_xbitmap_extent(br, n, agfl_extents) {
-		*flcount += br->len;
-		if (*flcount > xfs_agfl_size(mp))
-			break;
-	}
-	if (*flcount > xfs_agfl_size(mp))
-		*flcount = xfs_agfl_size(mp);
+	*flcount = min_t(uint64_t, xbitmap_hweight(agfl_extents),
+			 xfs_agfl_size(mp));
 	return 0;
 
 err:
diff --git a/fs/xfs/scrub/bitmap.c b/fs/xfs/scrub/bitmap.c
index 5b07b46c89c9..8b704d7b5855 100644
--- a/fs/xfs/scrub/bitmap.c
+++ b/fs/xfs/scrub/bitmap.c
@@ -296,3 +296,18 @@  xbitmap_set_btblocks(
 {
 	return xfs_btree_visit_blocks(cur, xbitmap_collect_btblock, bitmap);
 }
+
+/* How many bits are set in this bitmap? */
+uint64_t
+xbitmap_hweight(
+	struct xbitmap		*bitmap)
+{
+	struct xbitmap_range	*bmr;
+	struct xbitmap_range	*n;
+	uint64_t		ret = 0;
+
+	for_each_xbitmap_extent(bmr, n, bitmap)
+		ret += bmr->len;
+
+	return ret;
+}
diff --git a/fs/xfs/scrub/bitmap.h b/fs/xfs/scrub/bitmap.h
index 8db4017ac78e..900646b72de1 100644
--- a/fs/xfs/scrub/bitmap.h
+++ b/fs/xfs/scrub/bitmap.h
@@ -32,5 +32,6 @@  int xbitmap_set_btcur_path(struct xbitmap *bitmap,
 		struct xfs_btree_cur *cur);
 int xbitmap_set_btblocks(struct xbitmap *bitmap,
 		struct xfs_btree_cur *cur);
+uint64_t xbitmap_hweight(struct xbitmap *bitmap);
 
 #endif	/* __XFS_SCRUB_BITMAP_H__ */