Whamcloud - gitweb
libext2fs: call fsync(2) to clear stale errors for a new a unix I/O channel
authorTheodore Ts'o <tytso@mit.edu>
Wed, 4 Jul 2018 04:23:10 +0000 (00:23 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 4 Jul 2018 04:23:10 +0000 (00:23 -0400)
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>
lib/ext2fs/unix_io.c

index 53fbd28..18a2e5f 100644 (file)
@@ -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;