]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: don't ignore fsync errors
authorEric Sandeen <sandeen@redhat.com>
Tue, 20 Dec 2016 15:23:29 +0000 (09:23 -0600)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 13 Jan 2017 17:31:00 +0000 (12:31 -0500)
Today, if mke2fs experiences IO errors (say, on a thin device
which filled up during mkfs), mke2fs is silent and returns
success even though the filesystem was not properly created.

Catch errors from the io_channel_flush() callchain to
fix this up.  Fix formatting of the printed error as
well:

...
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information:
Warning, had trouble writing out superblocks.
# echo $?
5

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/closefs.c
lib/ext2fs/unix_io.c
misc/mke2fs.c

index b69fa09608fe60d4ea74933e38a33d7bd050a830..b255759ee04464c6c4e191ab7349bad415233b11 100644 (file)
@@ -429,16 +429,22 @@ write_primary_superblock_only:
        if (retval)
                return retval;
 
-       if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
+       if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) {
                retval = io_channel_flush(fs->io);
+               if (retval)
+                       goto errout;
+       }
        retval = write_primary_superblock(fs, super_shadow);
        if (retval)
                goto errout;
 
        fs->flags &= ~EXT2_FLAG_DIRTY;
 
-       if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
+       if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) {
                retval = io_channel_flush(fs->io);
+               if (retval)
+                       goto errout;
+       }
 errout:
        fs->super->s_state = fs_state;
 #ifdef WORDS_BIGENDIAN
index 429ea24115da963df83f95c829012814384587e8..f4e6148c40a1dfd74310e46ac3fb94f4f5bc14b3 100644 (file)
@@ -1030,7 +1030,8 @@ static errcode_t unix_flush(io_channel channel)
 #ifndef NO_IO_CACHE
        retval = flush_cached_blocks(channel, data, 0);
 #endif
-       fsync(data->dev);
+       if (!retval && fsync(data->dev) != 0)
+               return errno;
        return retval;
 }
 
index 9f18c839f7a91df9d35aafe3d9c4aa65200a45b8..49c6e94d03de532ca2496c2145e224de8ac3ad56 100644 (file)
@@ -3227,7 +3227,7 @@ no_journal:
        retval = ext2fs_close_free(&fs);
        if (retval) {
                fprintf(stderr, "%s",
-                       _("\nWarning, had trouble writing out superblocks."));
+                       _("\nWarning, had trouble writing out superblocks.\n"));
        } else if (!quiet) {
                printf("%s", _("done\n\n"));
                if (!getenv("MKE2FS_SKIP_CHECK_MSG"))