|
|
d0702a |
From 2ded6409b3a22e68c19236153f0456e1c079d0da Mon Sep 17 00:00:00 2001
|
|
|
d0702a |
From: Eric Sandeen <sandeen@redhat.com>
|
|
|
d0702a |
Date: Tue, 20 Dec 2016 09:23:29 -0600
|
|
|
d0702a |
Subject: [PATCH] libext2fs: don't ignore fsync errors
|
|
|
d0702a |
|
|
|
d0702a |
Today, if mke2fs experiences IO errors (say, on a thin device
|
|
|
d0702a |
which filled up during mkfs), mke2fs is silent and returns
|
|
|
d0702a |
success even though the filesystem was not properly created.
|
|
|
d0702a |
|
|
|
d0702a |
Catch errors from the io_channel_flush() callchain to
|
|
|
d0702a |
fix this up. Fix formatting of the printed error as
|
|
|
d0702a |
well:
|
|
|
d0702a |
|
|
|
d0702a |
...
|
|
|
d0702a |
Creating journal (262144 blocks): done
|
|
|
d0702a |
Writing superblocks and filesystem accounting information:
|
|
|
d0702a |
Warning, had trouble writing out superblocks.
|
|
|
d0702a |
# echo $?
|
|
|
d0702a |
5
|
|
|
d0702a |
|
|
|
d0702a |
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
|
|
|
d0702a |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
d0702a |
---
|
|
|
d0702a |
lib/ext2fs/closefs.c | 10 ++++++++--
|
|
|
d0702a |
lib/ext2fs/unix_io.c | 3 ++-
|
|
|
d0702a |
misc/mke2fs.c | 2 +-
|
|
|
d0702a |
3 files changed, 11 insertions(+), 4 deletions(-)
|
|
|
d0702a |
|
|
|
d0702a |
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
|
|
|
d0702a |
index a73c53f..000ebd8 100644
|
|
|
d0702a |
--- a/lib/ext2fs/closefs.c
|
|
|
d0702a |
+++ b/lib/ext2fs/closefs.c
|
|
|
d0702a |
@@ -410,16 +410,22 @@ write_primary_superblock_only:
|
|
|
d0702a |
ext2fs_swap_super(super_shadow);
|
|
|
d0702a |
#endif
|
|
|
d0702a |
|
|
|
d0702a |
- if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
|
|
|
d0702a |
+ if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) {
|
|
|
d0702a |
retval = io_channel_flush(fs->io);
|
|
|
d0702a |
+ if (retval)
|
|
|
d0702a |
+ goto errout;
|
|
|
d0702a |
+ }
|
|
|
d0702a |
retval = write_primary_superblock(fs, super_shadow);
|
|
|
d0702a |
if (retval)
|
|
|
d0702a |
goto errout;
|
|
|
d0702a |
|
|
|
d0702a |
fs->flags &= ~EXT2_FLAG_DIRTY;
|
|
|
d0702a |
|
|
|
d0702a |
- if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC))
|
|
|
d0702a |
+ if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) {
|
|
|
d0702a |
retval = io_channel_flush(fs->io);
|
|
|
d0702a |
+ if (retval)
|
|
|
d0702a |
+ goto errout;
|
|
|
d0702a |
+ }
|
|
|
d0702a |
errout:
|
|
|
d0702a |
fs->super->s_state = fs_state;
|
|
|
d0702a |
#ifdef WORDS_BIGENDIAN
|
|
|
d0702a |
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
|
|
|
d0702a |
index 19be630..a2069f0 100644
|
|
|
d0702a |
--- a/lib/ext2fs/unix_io.c
|
|
|
d0702a |
+++ b/lib/ext2fs/unix_io.c
|
|
|
d0702a |
@@ -885,7 +885,8 @@ static errcode_t unix_flush(io_channel channel)
|
|
|
d0702a |
#ifndef NO_IO_CACHE
|
|
|
d0702a |
retval = flush_cached_blocks(channel, data, 0);
|
|
|
d0702a |
#endif
|
|
|
d0702a |
- fsync(data->dev);
|
|
|
d0702a |
+ if (!retval && fsync(data->dev) != 0)
|
|
|
d0702a |
+ return errno;
|
|
|
d0702a |
return retval;
|
|
|
d0702a |
}
|
|
|
d0702a |
|
|
|
d0702a |
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
|
|
|
d0702a |
index 3e3ef95..8952a5f 100644
|
|
|
d0702a |
--- a/misc/mke2fs.c
|
|
|
d0702a |
+++ b/misc/mke2fs.c
|
|
|
d0702a |
@@ -2764,7 +2764,7 @@ no_journal:
|
|
|
d0702a |
retval = ext2fs_close(fs);
|
|
|
d0702a |
if (retval) {
|
|
|
d0702a |
fprintf(stderr, "%s",
|
|
|
d0702a |
- _("\nWarning, had trouble writing out superblocks."));
|
|
|
d0702a |
+ _("\nWarning, had trouble writing out superblocks.\n"));
|
|
|
d0702a |
} else if (!quiet) {
|
|
|
d0702a |
printf("%s", _("done\n\n"));
|
|
|
d0702a |
if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
|
|
|
d0702a |
--
|
|
|
d0702a |
2.7.4
|
|
|
d0702a |
|