diff mbox series

[20/21] xfs_scrub: report media scrub failures to the kernel

Message ID 173568778769.2710211.7691395007928091819.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [01/21] xfs: create hooks for monitoring health updates | expand

Commit Message

Darrick J. Wong Dec. 31, 2024, 11:52 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

If the media scan finds that media have been lost, report this to the
kernel so that the healthmon code can pass that along to xfs_scrubbed.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 scrub/phase6.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/scrub/phase6.c b/scrub/phase6.c
index 5a1f29738680e5..b5f6f3c1d4bc63 100644
--- a/scrub/phase6.c
+++ b/scrub/phase6.c
@@ -671,6 +671,29 @@  clean_pool(
 	return ret;
 }
 
+static void
+report_ioerr_to_kernel(
+	struct scrub_ctx		*ctx,
+	struct disk			*disk,
+	uint64_t			start,
+	uint64_t			length)
+{
+	struct xfs_media_error		me = {
+		.daddr			= start,
+		.bbcount		= length,
+	};
+	dev_t				dev = disk_to_dev(ctx, disk);
+
+	if (dev == ctx->fsinfo.fs_datadev)
+		me.flags |= XFS_MEDIA_ERROR_DATADEV;
+	else if (dev == ctx->fsinfo.fs_rtdev)
+		me.flags |= XFS_MEDIA_ERROR_RTDEV;
+	else if (dev == ctx->fsinfo.fs_logdev)
+		me.flags |= XFS_MEDIA_ERROR_LOGDEV;
+
+	ioctl(ctx->mnt.fd, XFS_IOC_MEDIA_ERROR, &me);
+}
+
 /* Remember a media error for later. */
 static void
 remember_ioerr(
@@ -695,6 +718,8 @@  remember_ioerr(
 		return;
 	}
 
+	report_ioerr_to_kernel(ctx, disk, start, length);
+
 	tree = bitmap_for_disk(ctx, disk, vs);
 	if (!tree) {
 		str_liberror(ctx, ENOENT, _("finding bad block bitmap"));