diff mbox series

[14/43] xfs: add a xfs_rtrmap_first_unwritten_rgbno helper

Message ID 20241211085636.1380516-15-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/43] xfs: constify feature checks | expand

Commit Message

Christoph Hellwig Dec. 11, 2024, 8:54 a.m. UTC
Add a helper to find the last offset mapped in the rtrmap.  This will be
used by the zoned code to find out where to start writing again on
conventional devices without hardware zone support.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_rtrmap_btree.c | 16 ++++++++++++++++
 fs/xfs/libxfs/xfs_rtrmap_btree.h |  2 ++
 2 files changed, 18 insertions(+)

Comments

Darrick J. Wong Dec. 12, 2024, 9:48 p.m. UTC | #1
On Wed, Dec 11, 2024 at 09:54:39AM +0100, Christoph Hellwig wrote:
> Add a helper to find the last offset mapped in the rtrmap.  This will be
> used by the zoned code to find out where to start writing again on
> conventional devices without hardware zone support.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/libxfs/xfs_rtrmap_btree.c | 16 ++++++++++++++++
>  fs/xfs/libxfs/xfs_rtrmap_btree.h |  2 ++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c
> index 04b9c76380ad..b2bb0dd53b00 100644
> --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c
> +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c
> @@ -1033,3 +1033,19 @@ xfs_rtrmapbt_init_rtsb(
>  	xfs_btree_del_cursor(cur, error);
>  	return error;
>  }
> +
> +xfs_rgblock_t
> +xfs_rtrmap_first_unwritten_rgbno(
> +	struct xfs_rtgroup	*rtg)

Might want to leave a comment here saying that this only applies to
zoned realtime devices because they are written start to end, not
randomly.  Otherwise this looks ok to me, having peered into the future
to see how it got used. :)

--D

> +{
> +	struct xfs_btree_block	*block = rtg_rmap(rtg)->i_df.if_broot;
> +	union xfs_btree_key	key = {};
> +	struct xfs_btree_cur	*cur;
> +
> +	if (block->bb_numrecs == 0)
> +		return 0;
> +	cur = xfs_rtrmapbt_init_cursor(NULL, rtg);
> +	xfs_btree_get_keys(cur, block, &key);
> +	xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
> +	return be32_to_cpu(key.__rmap_bigkey[1].rm_startblock) + 1;
> +}
> diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.h b/fs/xfs/libxfs/xfs_rtrmap_btree.h
> index 6a2d432b55ad..d5cca8fcf4a3 100644
> --- a/fs/xfs/libxfs/xfs_rtrmap_btree.h
> +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.h
> @@ -207,4 +207,6 @@ struct xfs_btree_cur *xfs_rtrmapbt_mem_cursor(struct xfs_rtgroup *rtg,
>  int xfs_rtrmapbt_mem_init(struct xfs_mount *mp, struct xfbtree *xfbtree,
>  		struct xfs_buftarg *btp, xfs_rgnumber_t rgno);
>  
> +xfs_rgblock_t xfs_rtrmap_first_unwritten_rgbno(struct xfs_rtgroup *rtg);
> +
>  #endif	/* __XFS_RTRMAP_BTREE_H__ */
> -- 
> 2.45.2
> 
>
Christoph Hellwig Dec. 13, 2024, 5:16 a.m. UTC | #2
On Thu, Dec 12, 2024 at 01:48:51PM -0800, Darrick J. Wong wrote:
> >  }
> > +
> > +xfs_rgblock_t
> > +xfs_rtrmap_first_unwritten_rgbno(
> > +	struct xfs_rtgroup	*rtg)
> 
> Might want to leave a comment here saying that this only applies to
> zoned realtime devices because they are written start to end, not
> randomly.  Otherwise this looks ok to me, having peered into the future
> to see how it got used. :)

Yes.  Or rename it and make it return the highest tracked rgbno and
return NULLRGBLOCK, so that all the meaning assigned to that stays
in the caller, which might be less confusing.
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c
index 04b9c76380ad..b2bb0dd53b00 100644
--- a/fs/xfs/libxfs/xfs_rtrmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c
@@ -1033,3 +1033,19 @@  xfs_rtrmapbt_init_rtsb(
 	xfs_btree_del_cursor(cur, error);
 	return error;
 }
+
+xfs_rgblock_t
+xfs_rtrmap_first_unwritten_rgbno(
+	struct xfs_rtgroup	*rtg)
+{
+	struct xfs_btree_block	*block = rtg_rmap(rtg)->i_df.if_broot;
+	union xfs_btree_key	key = {};
+	struct xfs_btree_cur	*cur;
+
+	if (block->bb_numrecs == 0)
+		return 0;
+	cur = xfs_rtrmapbt_init_cursor(NULL, rtg);
+	xfs_btree_get_keys(cur, block, &key);
+	xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
+	return be32_to_cpu(key.__rmap_bigkey[1].rm_startblock) + 1;
+}
diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.h b/fs/xfs/libxfs/xfs_rtrmap_btree.h
index 6a2d432b55ad..d5cca8fcf4a3 100644
--- a/fs/xfs/libxfs/xfs_rtrmap_btree.h
+++ b/fs/xfs/libxfs/xfs_rtrmap_btree.h
@@ -207,4 +207,6 @@  struct xfs_btree_cur *xfs_rtrmapbt_mem_cursor(struct xfs_rtgroup *rtg,
 int xfs_rtrmapbt_mem_init(struct xfs_mount *mp, struct xfbtree *xfbtree,
 		struct xfs_buftarg *btp, xfs_rgnumber_t rgno);
 
+xfs_rgblock_t xfs_rtrmap_first_unwritten_rgbno(struct xfs_rtgroup *rtg);
+
 #endif	/* __XFS_RTRMAP_BTREE_H__ */