Blame SOURCES/e2fsprogs-1.43.3-libext2fs-don-t-ignore-fsync-errors.patch

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