Commit 608eb3ce authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: replace open-coded bitmap weight logic

Add a xbitmap_hweight helper function so that we can get rid of the
open-coded loop.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 00b10d48
......@@ -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:
......
......@@ -297,3 +297,18 @@ xbitmap_set_btblocks(
return xfs_btree_visit_blocks(cur, xbitmap_collect_btblock,
XFS_BTREE_VISIT_ALL, 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;
}
......@@ -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__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment