Skip to content

Commit e4fd1de

Browse files
author
Darrick J. Wong
committed
xfs: create agblock bitmap helper to count the number of set regions
In the next patch, the rmap btree repair code will need to estimate the size of the new ondisk rmapbt. The size is a function of the number of records that will be written to disk, and the size of the recordset is the number of observations made while scanning the filesystem plus the number of OWN_AG records that will be injected into the rmap btree. OWN_AG rmap records track the free space btrees, the AGFL, and the new rmap btree itself. The repair tool uses a bitmap to record the space used for all four structures, which is why we need a function to count the number of set regions. A reviewer requested that this be pulled into a separate patch with its own justification, so here it is. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 5049ff4 commit e4fd1de

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

fs/xfs/scrub/agb_bitmap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ int xagb_bitmap_set_btblocks(struct xagb_bitmap *bitmap,
6565
int xagb_bitmap_set_btcur_path(struct xagb_bitmap *bitmap,
6666
struct xfs_btree_cur *cur);
6767

68+
static inline uint32_t xagb_bitmap_count_set_regions(struct xagb_bitmap *b)
69+
{
70+
return xbitmap32_count_set_regions(&b->agbitmap);
71+
}
72+
6873
#endif /* __XFS_SCRUB_AGB_BITMAP_H__ */

fs/xfs/scrub/bitmap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,17 @@ xbitmap32_test(
566566
*len = bn->bn_start - start;
567567
return false;
568568
}
569+
570+
/* Count the number of set regions in this bitmap. */
571+
uint32_t
572+
xbitmap32_count_set_regions(
573+
struct xbitmap32 *bitmap)
574+
{
575+
struct xbitmap32_node *bn;
576+
uint32_t nr = 0;
577+
578+
for_each_xbitmap32_extent(bn, bitmap)
579+
nr++;
580+
581+
return nr;
582+
}

fs/xfs/scrub/bitmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@ int xbitmap32_walk(struct xbitmap32 *bitmap, xbitmap32_walk_fn fn,
6262
bool xbitmap32_empty(struct xbitmap32 *bitmap);
6363
bool xbitmap32_test(struct xbitmap32 *bitmap, uint32_t start, uint32_t *len);
6464

65+
uint32_t xbitmap32_count_set_regions(struct xbitmap32 *bitmap);
66+
6567
#endif /* __XFS_SCRUB_BITMAP_H__ */

0 commit comments

Comments
 (0)