[1/2] mm: clear any AS_* errors when returning from filemap_write_and_wait{_range}
diff mbox

Message ID 20170530111046.8069-2-jlayton@redhat.com
State New
Headers show

Commit Message

Jeff Layton May 30, 2017, 11:10 a.m. UTC
Currently we don't clear the address space error when there is a -EIO
error on fsync due to writeback initiation failure. If initiating writes
fails with -EIO and the mapping is already flagged with an AS_EIO or
AS_ENOSPC error, then we can end up returning errors on two fsync calls,
even when a write between them succeeded (or there was no write).

Ensure that we also clear out any mapping errors when initiating
writeback fails with -EIO in filemap_write_and_wait and
filemap_write_and_wait_range.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 mm/filemap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/mm/filemap.c b/mm/filemap.c
index 6f1be573a5e6..39ff92d7ecdd 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -488,7 +488,7 @@  EXPORT_SYMBOL(filemap_fdatawait);
 
 int filemap_write_and_wait(struct address_space *mapping)
 {
-	int err = 0;
+	int err;
 
 	if ((!dax_mapping(mapping) && mapping->nrpages) ||
 	    (dax_mapping(mapping) && mapping->nrexceptional)) {
@@ -503,6 +503,8 @@  int filemap_write_and_wait(struct address_space *mapping)
 			int err2 = filemap_fdatawait(mapping);
 			if (!err)
 				err = err2;
+		} else {
+			filemap_check_errors(mapping);
 		}
 	} else {
 		err = filemap_check_errors(mapping);
@@ -525,7 +527,7 @@  EXPORT_SYMBOL(filemap_write_and_wait);
 int filemap_write_and_wait_range(struct address_space *mapping,
 				 loff_t lstart, loff_t lend)
 {
-	int err = 0;
+	int err;
 
 	if ((!dax_mapping(mapping) && mapping->nrpages) ||
 	    (dax_mapping(mapping) && mapping->nrexceptional)) {
@@ -537,6 +539,8 @@  int filemap_write_and_wait_range(struct address_space *mapping,
 						lstart, lend);
 			if (!err)
 				err = err2;
+		} else {
+			filemap_check_errors(mapping);
 		}
 	} else {
 		err = filemap_check_errors(mapping);