From: Theodore Ts'o Date: Wed, 4 Jul 2018 04:23:10 +0000 (-0400) Subject: libext2fs: call fsync(2) to clear stale errors for a new a unix I/O channel X-Git-Tag: v1.44.3-rc2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8236b49d0fb056847da5fb95b2709e63e6be7c6;p=thirdparty%2Fe2fsprogs.git libext2fs: call fsync(2) to clear stale errors for a new a unix I/O channel 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 --- diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 53fbd28bf..18a2e5f75 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;