diff mbox series

[04/43] xfs: skip always_cow inodes in xfs_reflink_trim_around_shared

Message ID 20250206064511.2323878-5-hch@lst.de (mailing list archive)
State Not Applicable, archived
Headers show
Series [01/43] xfs: factor out a xfs_rt_check_size helper | expand

Commit Message

hch Feb. 6, 2025, 6:44 a.m. UTC
xfs_reflink_trim_around_shared tries to find shared blocks in the
refcount btree.  Always_cow inodes don't have that tree, so don't
bother.

For the existing always_cow code this is a minor optimization.  For
the upcoming zoned code that can do COW without the rtreflink code it
avoids triggering a NULL pointer dereference.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Darrick J. Wong Feb. 6, 2025, 8:13 p.m. UTC | #1
On Thu, Feb 06, 2025 at 07:44:20AM +0100, Christoph Hellwig wrote:
> xfs_reflink_trim_around_shared tries to find shared blocks in the
> refcount btree.  Always_cow inodes don't have that tree, so don't
> bother.
> 
> For the existing always_cow code this is a minor optimization.  For
> the upcoming zoned code that can do COW without the rtreflink code it
> avoids triggering a NULL pointer dereference.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hmm.  So this is to support doing COW on non-reflink zoned filesystems?
How then do we protect the refcount intent log items from being replayed
on an oler kernel?  Are they effectively protected by the zoned feature
bit XFS_SB_FEAT_INCOMPAT_ZONED?

If so then
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_reflink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index 59f7fc16eb80..3e778e077d09 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -235,7 +235,7 @@ xfs_reflink_trim_around_shared(
>  	int			error = 0;
>  
>  	/* Holes, unwritten, and delalloc extents cannot be shared */
> -	if (!xfs_is_cow_inode(ip) || !xfs_bmap_is_written_extent(irec)) {
> +	if (!xfs_is_reflink_inode(ip) || !xfs_bmap_is_written_extent(irec)) {
>  		*shared = false;
>  		return 0;
>  	}
> -- 
> 2.45.2
> 
>
hch Feb. 7, 2025, 4:15 a.m. UTC | #2
On Thu, Feb 06, 2025 at 12:13:51PM -0800, Darrick J. Wong wrote:
> Hmm.  So this is to support doing COW on non-reflink zoned filesystems?

Yes.

> How then do we protect the refcount intent log items from being replayed
> on an oler kernel?

There are no refcount intent log items for this case.
Darrick J. Wong Feb. 7, 2025, 4:22 a.m. UTC | #3
On Fri, Feb 07, 2025 at 05:15:42AM +0100, Christoph Hellwig wrote:
> On Thu, Feb 06, 2025 at 12:13:51PM -0800, Darrick J. Wong wrote:
> > Hmm.  So this is to support doing COW on non-reflink zoned filesystems?
> 
> Yes.
> 
> > How then do we protect the refcount intent log items from being replayed
> > on an oler kernel?
> 
> There are no refcount intent log items for this case.

Er... right, there aren't any refcount log items because there's no
refcount btree.  Looking through the rest of the code, though, the same
question about protection against recovery by old kernels applies to the
bmap intent item logged in xfs_zoned_map_extent.  And I think it has the
same answer -- zoned storage is an incompat feature bit that's newer
than the bmap intent items, so we're protected.

I got there clumsily, but here I am :P
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D
diff mbox series

Patch

diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 59f7fc16eb80..3e778e077d09 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -235,7 +235,7 @@  xfs_reflink_trim_around_shared(
 	int			error = 0;
 
 	/* Holes, unwritten, and delalloc extents cannot be shared */
-	if (!xfs_is_cow_inode(ip) || !xfs_bmap_is_written_extent(irec)) {
+	if (!xfs_is_reflink_inode(ip) || !xfs_bmap_is_written_extent(irec)) {
 		*shared = false;
 		return 0;
 	}