From: Christoph Hellwig Date: Mon, 16 Mar 2026 21:20:05 +0000 (-0700) Subject: scrub: don't allocate disk for ioctl-based media verify X-Git-Tag: v7.0.0~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d0ba8a9348ae5e45087578557afe72dc4d231ff2;p=xfsprogs-dev.git scrub: don't allocate disk for ioctl-based media verify When the kernel provides the data verification ioctl there is no point in allocating struct disk and thus opening the underlying devices. Refactor the code so that we don't have to do that, with the added benefit of keeping the read verification self-contained in read_verify.c for the case where the kernel provides the ioctl. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" [djwong: break up patch] Signed-off-by: "Darrick J. Wong" --- diff --git a/scrub/phase1.c b/scrub/phase1.c index abc59489..f4d50d01 100644 --- a/scrub/phase1.c +++ b/scrub/phase1.c @@ -213,8 +213,39 @@ no_property: goto summarize; } +/* + * We can't do XFS_IOC_VERIFY_MEDIA media verification, so we need to fall back + * to reading the disk. We already opened the data device, now we need to open + * the rt and log devices for media verification. + */ +static int +configure_xfs_verify_fallback( + struct scrub_ctx *ctx) +{ + if (ctx->fsinfo.fs_log) { + ctx->verify_disks[XFS_DEV_LOG] = disk_open(ctx->fsinfo.fs_log); + if (!ctx->verify_disks[XFS_DEV_LOG]) { + str_error(ctx, ctx->mntpoint, + _("Unable to open external log device.")); + return ECANCELED; + } + } + + if (ctx->fsinfo.fs_rt) { + ctx->verify_disks[XFS_DEV_RT] = disk_open(ctx->fsinfo.fs_rt); + if (!ctx->verify_disks[XFS_DEV_RT]) { + str_error(ctx, ctx->mntpoint, + _("Unable to open realtime device.")); + return ECANCELED; + } + } + + ctx->no_verify_ioctl = true; + return 0; +} + /* Does the XFS driver support media scanning its own disks? */ -static void +static bool configure_xfs_verify( struct scrub_ctx *ctx) { @@ -225,8 +256,7 @@ configure_xfs_verify( .me_dev = XFS_DEV_DATA, }; - if (ioctl(ctx->mnt.fd, XFS_IOC_VERIFY_MEDIA, &me)) - ctx->no_verify_ioctl = true; + return ioctl(ctx->mnt.fd, XFS_IOC_VERIFY_MEDIA, &me) == 0; } /* @@ -378,25 +408,20 @@ _("Unable to find realtime device path.")); fflush(stdout); } - if (ctx->fsinfo.fs_log) { - ctx->verify_disks[XFS_DEV_LOG] = disk_open(ctx->fsinfo.fs_log); - if (!ctx->verify_disks[XFS_DEV_LOG]) { - str_error(ctx, ctx->mntpoint, - _("Unable to open external log device.")); - return ECANCELED; - } - } - if (ctx->fsinfo.fs_rt) { - ctx->verify_disks[XFS_DEV_RT] = disk_open(ctx->fsinfo.fs_rt); - if (!ctx->verify_disks[XFS_DEV_RT]) { - str_error(ctx, ctx->mntpoint, - _("Unable to open realtime device.")); - return ECANCELED; - } + if (configure_xfs_verify(ctx)) { + /* + * ioctl-based media verification is enabled and we already set + * nr_io_threads from the data device, so we no longer need to + * keep this open. + */ + disk_close(ctx->verify_disks[XFS_DEV_DATA]); + ctx->verify_disks[XFS_DEV_DATA] = NULL; + } else { + error = configure_xfs_verify_fallback(ctx); + if (error) + return error; } - configure_xfs_verify(ctx); - /* * Everything's set up, which means any failures recorded after * this point are most probably corruption errors (as opposed to