linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libext2fs: don't ignore fsync errors
@ 2016-12-20 15:23 Eric Sandeen
  2017-01-13 17:31 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2016-12-20 15:23 UTC (permalink / raw)
  To: linux-ext4@vger.kernel.org

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>
---

I'm not actually sure what's supposed to be returned
from unix_flush; it's an errcode_t; is a standard error
number (EIO) ok or is there a libcom_err for that?
Anyway, seems to work ok.

diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index b69fa09..b255759 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -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
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 429ea24..f4e6148 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -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;
 }
 
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 9f18c83..49c6e94 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -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"))



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libext2fs: don't ignore fsync errors
  2016-12-20 15:23 [PATCH] libext2fs: don't ignore fsync errors Eric Sandeen
@ 2017-01-13 17:31 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2017-01-13 17:31 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-ext4@vger.kernel.org

On Tue, Dec 20, 2016 at 09:23:29AM -0600, Eric Sandeen wrote:
> 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>

Applied, thanks.

					- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-13 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-20 15:23 [PATCH] libext2fs: don't ignore fsync errors Eric Sandeen
2017-01-13 17:31 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).