]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
scrub: don't allocate disk for ioctl-based media verify
authorChristoph Hellwig <hch@lst.de>
Mon, 16 Mar 2026 21:20:05 +0000 (14:20 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 9 Apr 2026 22:30:19 +0000 (15:30 -0700)
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 <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
[djwong: break up patch]
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
scrub/phase1.c

index abc594898bf2c5eb5be923be5d729f2e5ad8c404..f4d50d016c2ebd4fa7c20e97ef137654626d4663 100644 (file)
@@ -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