On Wed, Apr 29, 2020 at 01:21:51PM -0400, Brian Foster wrote: > Introduce an error tag to randomly fail async buffer writes. This is > primarily to facilitate testing of the XFS error configuration > mechanism. > > Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx> > Reviewed-by: Allison Collins <allison.henderson@xxxxxxxxxx> > Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx> Reviewed-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --D > --- > fs/xfs/libxfs/xfs_errortag.h | 4 +++- > fs/xfs/xfs_buf.c | 6 ++++++ > fs/xfs/xfs_error.c | 3 +++ > 3 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h > index 79e6c4fb1d8a..2486dab19023 100644 > --- a/fs/xfs/libxfs/xfs_errortag.h > +++ b/fs/xfs/libxfs/xfs_errortag.h > @@ -55,7 +55,8 @@ > #define XFS_ERRTAG_FORCE_SCRUB_REPAIR 32 > #define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 > #define XFS_ERRTAG_IUNLINK_FALLBACK 34 > -#define XFS_ERRTAG_MAX 35 > +#define XFS_ERRTAG_BUF_IOERROR 35 > +#define XFS_ERRTAG_MAX 36 > > /* > * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. > @@ -95,5 +96,6 @@ > #define XFS_RANDOM_FORCE_SCRUB_REPAIR 1 > #define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 > #define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10) > +#define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT > > #endif /* __XFS_ERRORTAG_H_ */ > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index 8f0f605de579..61629efd56ee 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -1289,6 +1289,12 @@ xfs_buf_bio_end_io( > struct bio *bio) > { > struct xfs_buf *bp = (struct xfs_buf *)bio->bi_private; > + struct xfs_mount *mp = bp->b_mount; > + > + if (!bio->bi_status && > + (bp->b_flags & XBF_WRITE) && (bp->b_flags & XBF_ASYNC) && > + XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BUF_IOERROR)) > + bio->bi_status = BLK_STS_IOERR; > > /* > * don't overwrite existing errors - otherwise we can lose errors on > diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c > index a21e9cc6516a..7f6e20899473 100644 > --- a/fs/xfs/xfs_error.c > +++ b/fs/xfs/xfs_error.c > @@ -53,6 +53,7 @@ static unsigned int xfs_errortag_random_default[] = { > XFS_RANDOM_FORCE_SCRUB_REPAIR, > XFS_RANDOM_FORCE_SUMMARY_RECALC, > XFS_RANDOM_IUNLINK_FALLBACK, > + XFS_RANDOM_BUF_IOERROR, > }; > > struct xfs_errortag_attr { > @@ -162,6 +163,7 @@ XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF); > XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); > XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); > XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); > +XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); > > static struct attribute *xfs_errortag_attrs[] = { > XFS_ERRORTAG_ATTR_LIST(noerror), > @@ -199,6 +201,7 @@ static struct attribute *xfs_errortag_attrs[] = { > XFS_ERRORTAG_ATTR_LIST(force_repair), > XFS_ERRORTAG_ATTR_LIST(bad_summary), > XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), > + XFS_ERRORTAG_ATTR_LIST(buf_ioerror), > NULL, > }; > > -- > 2.21.1 >