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

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