File libext2fs-call-fsync-2-to-clear-stale-errors-for-a-n.patch of Package e2fsprogs

From e8236b49d0fb056847da5fb95b2709e63e6be7c6 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <tytso@mit.edu>
Date: Wed, 4 Jul 2018 00:23:10 -0400
Subject: [PATCH] libext2fs: call fsync(2) to clear stale errors for a new a
 unix I/O channel
References: bsc#1145716

Newer versions of Linux will retain errors and allow them to be
returned by fsync() or close(), even if the error happened before the
file descriptor was opened.  This was to accomodate Postgres's
"interesting" method of error collection.

Unfortunately, for e2fsck, we never want to see stale errors, as this
can cause xfstests (such generic/347) to fail with a false positive.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Acked-by: Jan Kara <jack@suse.cz>
---
 lib/ext2fs/unix_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 53fbd28bf803..18a2e5f75c07 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -569,6 +569,14 @@ static errcode_t unix_open_channel(const char *name, int fd,
 	if (safe_getenv("UNIX_IO_FORCE_BOUNCE"))
 		flags |= IO_FLAG_FORCE_BOUNCE;
 
+#ifdef __linux__
+	/*
+	 * We need to make sure any previous errors in the block
+	 * device are thrown away, sigh.
+	 */
+	(void) fsync(fd);
+#endif
+
 	retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
 	if (retval)
 		goto cleanup;
-- 
2.16.4

openSUSE Build Service is sponsored by