Re: [PATCH v2 2/4] xfs: add an error tag to inject a ->writeback_submit() failure
From: Darrick J. Wong
Date: Thu Sep 24 2026 - 14:58:54 EST
On Thu, Sep 24, 2026 at 11:11:52AM +0200, Andrea Parri wrote:
> The only in-tree way for xfs_writeback_submit() to fail is a failing
> xfs_reflink_convert_cow(), which requires a shared (reflinked) CoW
> extent. There was previously no way to exercise that failure path
> from userspace, which made it hard to write an xfstest for it, e.g.
> for "iomap: don't resubmit an ioend after ->writeback_submit()
> failed".
>
> Add XFS_ERRTAG_WB_COW_CONVERT_ERROR to force xfs_reflink_convert_cow()
> to fail with -EIO, so that ->writeback_submit() failure and its
> callers' error handling can be exercised with error injection alone,
> without needing a corrupted or racy COW fork.
>
> Suggested-by: Christoph Hellwig <hch@xxxxxxxxxxxxx>
> Assisted-by: LLM
> Signed-off-by: Andrea Parri <parri.andrea@xxxxxxxxx>
Looks good to me,
Reviewed-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>
--D
> ---
> fs/xfs/libxfs/xfs_errortag.h | 6 ++++--
> fs/xfs/xfs_reflink.c | 5 +++++
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h
> index 6de207fed2d89..e6b0864051b0a 100644
> --- a/fs/xfs/libxfs/xfs_errortag.h
> +++ b/fs/xfs/libxfs/xfs_errortag.h
> @@ -75,7 +75,8 @@
> #define XFS_ERRTAG_METAFILE_RESV_CRITICAL 45
> #define XFS_ERRTAG_FORCE_ZERO_RANGE 46
> #define XFS_ERRTAG_ZONE_RESET 47
> -#define XFS_ERRTAG_MAX 48
> +#define XFS_ERRTAG_WB_COW_CONVERT_ERROR 48
> +#define XFS_ERRTAG_MAX 49
>
> /*
> * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
> @@ -137,7 +138,8 @@ XFS_ERRTAG(WRITE_DELAY_MS, write_delay_ms, 3000) \
> XFS_ERRTAG(EXCHMAPS_FINISH_ONE, exchmaps_finish_one, 1) \
> XFS_ERRTAG(METAFILE_RESV_CRITICAL, metafile_resv_crit, 4) \
> XFS_ERRTAG(FORCE_ZERO_RANGE, force_zero_range, 4) \
> -XFS_ERRTAG(ZONE_RESET, zone_reset, 1)
> +XFS_ERRTAG(ZONE_RESET, zone_reset, 1) \
> +XFS_ERRTAG(WB_COW_CONVERT_ERROR, wb_cow_convert_error, 1)
> #endif /* XFS_ERRTAG */
>
> #endif /* __XFS_ERRORTAG_H_ */
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index 4801361366359..104542b10d9e0 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -34,6 +34,8 @@
> #include "xfs_rtalloc.h"
> #include "xfs_rtgroup.h"
> #include "xfs_metafile.h"
> +#include "xfs_errortag.h"
> +#include "xfs_error.h"
>
> /*
> * Copy on Write of Shared Blocks
> @@ -346,6 +348,9 @@ xfs_reflink_convert_cow(
>
> ASSERT(count != 0);
>
> + if (XFS_TEST_ERROR(mp, XFS_ERRTAG_WB_COW_CONVERT_ERROR))
> + return -EIO;
> +
> xfs_ilock(ip, XFS_ILOCK_EXCL);
> error = xfs_reflink_convert_cow_locked(ip, offset_fsb, count_fsb);
> xfs_iunlock(ip, XFS_ILOCK_EXCL);
> --
> 2.53.0
>
>