Re: [PATCH] xfs: restore bi_bdev in xfs_zone_gc_write_chunk

"Darrick J. Wong" <[email protected]>
Newsgroups org.kernel.vger.linux-xfs
Message-ID <20260813151150.GE3556460@frogsfrogsfrogs>
On Thu, Aug 13, 2026 at 04:56:12PM +0200, Christoph Hellwig wrote:
> xfs_zone_gc_write_chunk relies on bi_bdev to still be valid, which is not
> true when XFS is used on top of a stacked block device.  This can lead to
> misdirected GC writes, writing of plain text when using dm-crypt, or
> miscalculated I/O limits in xfs_zone_gc_split_write.
> 
> Fix this by reassigning bi_bdev.

ewww, what??

Should bio_reuse take a bdev parameter and set_dev itself?  I had no
idea that bi_bdev could get changed by the time the bio completes.

> Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
> Signed-off-by: Christoph Hellwig <[email protected]>

From a purely defensive standpoint this makes sense, so

Cc: <[email protected]> # v6.15
Reviewed-by: "Darrick J. Wong" <[email protected]>

--D

> ---
>  fs/xfs/xfs_zone_gc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
> index 7ab8f2218c6a..5cc5ad1e3483 100644
> --- a/fs/xfs/xfs_zone_gc.c
> +++ b/fs/xfs/xfs_zone_gc.c
> @@ -869,6 +869,11 @@ xfs_zone_gc_write_chunk(
>  	WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
>  	list_move_tail(&chunk->entry, &data->writing);
>  
> +	/*
> +	 * If we run on top of stacked block device, the read I/O might have
> +	 * reset bi_bdev, restore it to the one we want.
> +	 */
> +	bio_set_dev(&chunk->bio, mp->m_rtdev_targp->bt_bdev);
>  	bio_reuse(&chunk->bio, REQ_OP_WRITE);
>  	while ((split_chunk = xfs_zone_gc_split_write(data, chunk)))
>  		xfs_zone_gc_submit_write(data, split_chunk);
> -- 
> 2.53.0
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.