]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: actually check for errors coming from close()
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 31 May 2018 19:09:54 +0000 (14:09 -0500)
Report errors reported by close().

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/phase1.c
scrub/phase3.c
scrub/phase5.c
scrub/phase6.c
scrub/vfs.c

index c2b9067aaa8475d24700b7574cd428b9eaaa17bd..87847259e37428449427f878f28930e84c710b25 100644 (file)
@@ -60,6 +60,8 @@ bool
 xfs_cleanup_fs(
        struct scrub_ctx        *ctx)
 {
+       int                     error;
+
        if (ctx->fshandle)
                free_handle(ctx->fshandle, ctx->fshandle_len);
        if (ctx->rtdev)
@@ -69,7 +71,9 @@ xfs_cleanup_fs(
        if (ctx->datadev)
                disk_close(ctx->datadev);
        fshandle_destroy();
-       close(ctx->mnt_fd);
+       error = close(ctx->mnt_fd);
+       if (error)
+               str_errno(ctx, _("closing mountpoint fd"));
        fs_table_destroy();
 
        return true;
index 68c95e67b0df41efd354d69be0552f602fe83c8d..cbaa80baefbd613e4eb32fc4ca657094af2c303f 100644 (file)
@@ -53,6 +53,25 @@ struct scrub_inode_ctx {
        bool                    moveon;
 };
 
+/* Report a filesystem error that the vfs fed us on close. */
+static void
+xfs_scrub_inode_vfs_error(
+       struct scrub_ctx        *ctx,
+       struct xfs_bstat        *bstat)
+{
+       char                    descr[DESCR_BUFSZ];
+       xfs_agnumber_t          agno;
+       xfs_agino_t             agino;
+       int                     old_errno = errno;
+
+       agno = bstat->bs_ino / (1ULL << (ctx->inopblog + ctx->agblklog));
+       agino = bstat->bs_ino % (1ULL << (ctx->inopblog + ctx->agblklog));
+       snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"),
+                       (uint64_t)bstat->bs_ino, agno, agino);
+       errno = old_errno;
+       str_errno(ctx, descr);
+}
+
 /* Verify the contents, xattrs, and extent maps of an inode. */
 static int
 xfs_scrub_inode(
@@ -65,6 +84,7 @@ xfs_scrub_inode(
        struct ptcounter        *icount = ictx->icount;
        bool                    moveon = true;
        int                     fd = -1;
+       int                     error;
 
        background_sleep();
 
@@ -116,8 +136,11 @@ xfs_scrub_inode(
 out:
        ptcounter_add(icount, 1);
        progress_add(1);
-       if (fd >= 0)
-               close(fd);
+       if (fd >= 0) {
+               error = close(fd);
+               if (error)
+                       xfs_scrub_inode_vfs_error(ctx, bstat);
+       }
        if (!moveon)
                ictx->moveon = false;
        return ictx->moveon ? 0 : XFS_ITERATE_INODES_ABORT;
index 01038f77858a728f986758d7b4c0eb4b6672edcb..456f38e2250c4bef4a196b398928bcc149ea4e26 100644 (file)
@@ -250,6 +250,7 @@ xfs_scrub_connections(
        xfs_agnumber_t          agno;
        xfs_agino_t             agino;
        int                     fd = -1;
+       int                     error;
 
        agno = bstat->bs_ino / (1ULL << (ctx->inopblog + ctx->agblklog));
        agino = bstat->bs_ino % (1ULL << (ctx->inopblog + ctx->agblklog));
@@ -285,8 +286,11 @@ xfs_scrub_connections(
 
 out:
        progress_add(1);
-       if (fd >= 0)
-               close(fd);
+       if (fd >= 0) {
+               error = close(fd);
+               if (error)
+                       str_errno(ctx, descr);
+       }
        if (!moveon)
                *pmoveon = false;
        return *pmoveon ? 0 : XFS_ITERATE_INODES_ABORT;
index b533cbbdd3ceb55b726f7e2f42b6a7e3339ce59a..26540155e2fdbdd47bbb88e3cb8a1fac9259b72b 100644 (file)
@@ -212,7 +212,9 @@ _("Disappeared during read error reporting."));
 
        /* Go find the badness. */
        moveon = xfs_report_verify_fd(ctx, descr, fd, arg);
-       close(fd);
+       error = close(fd);
+       if (error)
+               str_errno(ctx, descr);
 
        return moveon ? 0 : XFS_ITERATE_INODES_ABORT;
 }
@@ -243,6 +245,7 @@ xfs_report_verify_dirent(
 {
        bool                    moveon;
        int                     fd;
+       int                     error;
 
        /* Ignore things we can't open. */
        if (!S_ISREG(sb->st_mode) && !S_ISDIR(sb->st_mode))
@@ -268,8 +271,9 @@ xfs_report_verify_dirent(
                goto out;
 
 out:
-       close(fd);
-
+       error = close(fd);
+       if (error)
+               str_errno(ctx, path);
        return moveon;
 }
 
index cfb58782f6b6694c12efaccd5ba371dd862fcc5c..77df287493f3d0ca501727a1fa54e3bb73188c29 100644 (file)
@@ -86,7 +86,9 @@ scan_fs_dir(
        /* Caller-specific directory checks. */
        if (!sft->dir_fn(ctx, sftd->path, dir_fd, sft->arg)) {
                sft->moveon = false;
-               close(dir_fd);
+               error = close(dir_fd);
+               if (error)
+                       str_errno(ctx, sftd->path);
                goto out;
        }