mm/fs: get PG_error out of the writeback reporting business
Subsystems (11)
v2 cover mm/fs: get PG_error out of the writeback reporting business
v2:
- still ClearPageError during __filemap_fdatawait_range
- clear AS_* errors when reporting errors during write initiation
- set mapping errors when launder_page fails
- set mapping errors when writeback fails during migration
- set mapping errors when DAX writeback fails
- Documentation patch to give guidance about writeback errors
Here is v2 of this set. The main difference is some new patches to ensure that mapping errors get set in a few rather obscure places when writeback fails, and a patch (based on Jan's suggestion) to clear out the address space errors when initiating writeback fails with -EIO. I also left the code clearing PG_error in __filemap_fdatawait_range. We may want to remove that eventually, but we need to ensure that it gets cleared in some way when writeback fails.
I've done a bit of testing with this (mostly xfstests on xfs), and it seems to work ok AFAICT.
Original cover letter follows:
------------------------------8<-----------------------------
I recently did some work to wire up -ENOSPC handling in ceph, and found I could get back -EIO errors in some cases when I should have instead gotten -ENOSPC. The problem was that the ceph writeback code would set PG_error on a writeback error, and that error would clobber the mapping error.
While I fixed that problem by simply not setting that bit on errors, that led me down a rabbit hole of looking at how PG_error is being handled in the kernel.
This patch series is a few fixes for things that I 100% noticed by inspection. I don't have a great way to test these since they involve error handling. I can certainly doctor up a kernel to inject errors in this code and test by hand however if these look plausible up front.
Jeff Layton (9):
mm: fix mapping_set_error call in me_pagecache_dirty
mm: drop "wait" parameter from write_one_page
mm: clear any AS_* errors when returning error on any fsync or close
nilfs2: set the mapping error when calling SetPageError on writeback
dax: set error in mapping when writeback fails
mm: set mapping error when launder_pages fails
mm: ensure that we set mapping error if writeout() fails
mm: don't TestClearPageError in __filemap_fdatawait_range
Documentation: document what to do on a writeback error
Documentation/filesystems/vfs.txt | 7 +++++++ fs/dax.c | 4 +++- fs/exofs/dir.c | 2 +- fs/ext2/dir.c | 2 +- fs/jfs/jfs_metapage.c | 4 ++-- fs/minix/dir.c | 2 +- fs/nilfs2/segment.c | 1 + fs/sysv/dir.c | 2 +- fs/ufs/dir.c | 2 +- include/linux/mm.h | 2 +- mm/filemap.c | 40 ++++++++++++++++++++++----------------- mm/memory-failure.c | 2 +- mm/migrate.c | 6 +++++- mm/page-writeback.c | 14 +++++++------- mm/truncate.c | 6 +++++- 15 files changed, 60 insertions(+), 36 deletions(-)
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 1/9 mm: fix mapping_set_error call in me_pagecache_dirty
The error code should be negative. Since this ends up in the default case anyway, this is harmless, but it's less confusing to negate it.
--- mm/memory-failure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
@@ -674,7 +674,7 @@ static int me_pagecache_dirty(struct page *p, unsigned long pfn)* the first EIO, but we're not worse than other parts * of the kernel. */ -mapping_set_error (mapping,EIO ); +mapping_set_error (mapping, -EIO ); }return me_pagecache_clean (p, pfn);
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 1/9] mm: fix mapping_set_error call in me_pagecache_dirty
Quoted 4 lines · Jeff Layton
The error code should be negative. Since this ends up in the default case anyway, this is harmless, but it's less confusing to negate it.
Signed-off-by Jeff Layton <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 2/9 mm: drop "wait" parameter from write_one_page
In reply to Jeff LaytonThe callers all set it to 1. Also, make it clear that this function will not set any sort of AS_* error, and that the caller must do so if necessary. No existing caller uses this on normal files, so none of them need it.
--- fs/exofs/dir.c | 2 +- fs/ext2/dir.c | 2 +- fs/jfs/jfs_metapage.c | 4 ++-- fs/minix/dir.c | 2 +- fs/sysv/dir.c | 2 +- fs/ufs/dir.c | 2 +- include/linux/mm.h | 2 +- mm/page-writeback.c | 14 +++++++------- 8 files changed, 15 insertions(+), 15 deletions(-)
fs/exofs/dir.c +1 -1
@@ -72,7 +72,7 @@ static int exofs_commit_chunk(struct page *page, loff_t pos, unsigned len)set_page_dirty (page);if (IS_DIRSYNC (dir)) - err =write_one_page (page,1 ); + err =write_one_page (page);else unlock_page (page);
fs/ext2/dir.c +1 -1
@@ -100,7 +100,7 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len) }if (IS_DIRSYNC (dir)) { - err =write_one_page (page,1 ); + err =write_one_page (page);if (!err) err =sync_inode_metadata (dir,1 ); }else {
fs/jfs/jfs_metapage.c +2 -2
@@ -711,7 +711,7 @@ void force_metapage(struct metapage *mp)get_page (page);lock_page (page);set_page_dirty (page); -write_one_page (page,1 ); +write_one_page (page);clear_bit (META_forcewrite, &mp->flag);put_page (page); }
@@ -756,7 +756,7 @@ void release_metapage(struct metapage * mp)set_page_dirty (page);if (test_bit (META_sync, &mp->flag)) {clear_bit (META_sync, &mp->flag); -write_one_page (page,1 ); +write_one_page (page);lock_page (page);/* write_one_page unlocks the page */ } }else if (mp->lsn)/* discard_metapage doesn't remove it */
fs/minix/dir.c +1 -1
@@ -57,7 +57,7 @@ static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len)mark_inode_dirty (dir); }if (IS_DIRSYNC (dir)) - err =write_one_page (page,1 ); + err =write_one_page (page);else unlock_page (page);return err;
fs/sysv/dir.c +1 -1
@@ -45,7 +45,7 @@ static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len)mark_inode_dirty (dir); }if (IS_DIRSYNC (dir)) - err =write_one_page (page,1 ); + err =write_one_page (page);else unlock_page (page);return err;
fs/ufs/dir.c +1 -1
@@ -53,7 +53,7 @@ static int ufs_commit_chunk(struct page *page, loff_t pos, unsigned len)mark_inode_dirty (dir); }if (IS_DIRSYNC (dir)) - err =write_one_page (page,1 ); + err =write_one_page (page);else unlock_page (page);return err;
include/linux/mm.h +1 -1
@@ -2164,7 +2164,7 @@ extern void filemap_map_pages(struct vm_fault *vmf,extern int filemap_page_mkwrite (struct vm_fault *vmf);/* mm/page-writeback.c */ -int write_one_page (struct page *page,int wait); +int write_one_page (struct page *page);void task_dirty_inc (struct task_struct *tsk);/* readahead.c */
mm/page-writeback.c +7 -7
@@ -2361,15 +2361,16 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) }/** -* write_one_page - write out a single page and optionally wait on I/O +* write_one_page - write out a single page and wait on I/O * @page: the page to write -* @wait: if true, wait on writeout * * The page must be locked by the caller and will be unlocked upon return. * -* write_one_page() returns a negative error code if I/O failed. +* write_one_page() returns a negative error code if I/O failed. Note that +* the address_space is not marked for error. The caller must do this if +* needed. */ -int write_one_page (struct page *page,int wait) +int write_one_page (struct page *page) {struct address_space *mapping = page->mapping;int ret =0 ;
@@ -2380,13 +2381,12 @@ int write_one_page(struct page *page, int wait)BUG_ON (!PageLocked (page)); -if (wait) -wait_on_page_writeback (page); +wait_on_page_writeback (page);if (clear_page_dirty_for_io (page)) {get_page (page); ret = mapping->a_ops->writepage (page, &wbc); -if (ret ==0 && wait) { +if (ret ==0 ) {wait_on_page_writeback (page);if (PageError (page)) ret = -EIO ;
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2/9] mm: drop "wait" parameter from write_one_page
Quoted 6 lines · Jeff Layton
The callers all set it to 1. Also, make it clear that this function will not set any sort of AS_* error, and that the caller must do so if necessary. No existing caller uses this on normal files, so none of them need it.
Signed-off-by Jeff Layton <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 3/9 mm: clear any AS_* errors when returning error on any fsync or close
In reply to Jeff LaytonCurrently we don't clear the address space error when there is a -EIO error on fsynci, due to writeback initiation failure. If writes fail with -EIO and the mapping is 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.
--- mm/filemap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
mm/filemap.c +18 -2
@@ -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)) {
@@ -499,10 +499,18 @@ int filemap_write_and_wait(struct address_space *mapping)* But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ -if (err != -EIO ) { +if (likely (err != -EIO )) {int err2 =filemap_fdatawait (mapping);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);
@@ -537,6 +545,14 @@ int filemap_write_and_wait_range(struct address_space *mapping, lstart, lend);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 3/9] mm: clear any AS_* errors when returning error on any fsync or close
Quoted 9 lines · Jeff Layton
Currently we don't clear the address space error when there is a
-EIOerror on fsynci, due to writeback initiation failure. If writes fail with-EIOand the mapping is flagged with anAS_EIOorAS_ENOSPCerror, 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
-EIOinfilemap_write_and_waitandfilemap_write_and_wait_range.
This change appears to assume that filemap_write_and_wait* is only called from fsync() (or similar) and the return status is always checked.
A __must_check annotation might be helpful.
It would catch v9_fs_file_lock(), afs_setattr() and others.
While I think your change is probably heading in the right direction, there seem to be some loose ends still.
Thanks,
NeilBrown
Quoted 57 lines
Suggested-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- mm/filemap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)mm/filemap.c +18
-2@@ -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)) {@@ -499,10 +499,18 @@ int filemap_write_and_wait(struct address_space *mapping)* But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ -if (err != -EIO ) { +if (likely (err != -EIO )) {int err2 =filemap_fdatawait (mapping);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);@@ -537,6 +545,14 @@ int filemap_write_and_wait_range(struct address_space *mapping, lstart, lend);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);Signature · 1 line
2.9.3
Re: [PATCH v2 3/9] mm: clear any AS_* errors when returning error on any fsync or close
Quoted 12 lines · NeilBrown
Quoted 9 lines · Jeff Layton
Currently we don't clear the address space error when there is a
-EIOerror on fsynci, due to writeback initiation failure. If writes fail with-EIOand the mapping is flagged with anAS_EIOorAS_ENOSPCerror, 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
-EIOinfilemap_write_and_waitandfilemap_write_and_wait_range.
Quoted 6 lines
This change appears to assume that filemap_write_and_wait* is only called from
fsync()(or similar) and the return status is always checked.A
__must_checkannotation might be helpful.
Yes, good idea.
Quoted 2 lines
It would catch
v9_fs_file_lock(),afs_setattr()and others.
Ouch -- good catch.
Actually, those look like bugs in the code as it exists today. If some background page writeback fails, but no write initiation fails on that call, then those callers are discarding errors that should have been reported at fsync.
Quoted 3 lines
While I think your change is probably heading in the right direction, there seem to be some loose ends still.
Yes...I probably should be prefacing all of these patches with [RFC] at this point.
I think I'm starting to grasp the problem (and its scope), but we might have to think about how to approach this more strategically. Given that we have this wrong in so many places, I think that probably means that the interfaces we have make it easy to do so. I need to consider how to correct that.
Quoted 59 lines
Quoted 59 lines
Suggested-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- mm/filemap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)mm/filemap.c +18
-2@@ -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)) {@@ -499,10 +499,18 @@ int filemap_write_and_wait(struct address_space *mapping)* But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ -if (err != -EIO ) { +if (likely (err != -EIO )) {int err2 =filemap_fdatawait (mapping);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);@@ -537,6 +545,14 @@ int filemap_write_and_wait_range(struct address_space *mapping, lstart, lend);if (!err) err = err2; + }else { +/* +* Clear the error in the address space since we're +* returning an error here. -EIO takes precedence over +* everything else though, so we can just discard +* the return here. +*/ +filemap_check_errors (mapping); } }else { err =filemap_check_errors (mapping);Signature · 1 line
2.9.3
Signature · 7 lines
Jeff Layton <[email protected]> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 3/9] mm: clear any AS_* errors when returning error on any fsync or close
In reply to Jeff LaytonQuoted 2 lines · Jeff Layton
Currently we don't clear the address space error when there is a
-EIOerror on fsynci, due to writeback initiation failure. If writes fail
fsync
Quoted 28 lines
with
-EIOand the mapping is flagged with anAS_EIOorAS_ENOSPCerror, 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
-EIOinfilemap_write_and_waitandfilemap_write_and_wait_range.Suggested-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- mm/filemap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)mm/filemap.c +1
-1@@ -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)) {
mm/filemap.c int filemap_write_and_wait(struct address_space *mapping) · line 502
Quoted 5 lines
mm/filemap.c +1
-1@@ -499,10 +499,18 @@ int filemap_write_and_wait(struct address_space *mapping)* But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ -if (err != -EIO ) { +if (likely (err != -EIO )) {
The above two cleanup changes were made only to filemap_write_and_wait(), but should also probably be done to filemap_write_and_wait_range() to keep them as consistent as possible?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 3/9] mm: clear any AS_* errors when returning error on any fsync or close
Quoted 31 lines · Ross Zwisler
Quoted 2 lines · Jeff Layton
Currently we don't clear the address space error when there is a
-EIOerror on fsynci, due to writeback initiation failure. If writes failfsync
Quoted 25 lines
with
-EIOand the mapping is flagged with anAS_EIOorAS_ENOSPCerror, 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
-EIOinfilemap_write_and_waitandfilemap_write_and_wait_range.Suggested-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- mm/filemap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)mm/filemap.c +1
-1@@ -488,7 +488,7 @@ EXPORT_SYMBOL(filemap_fdatawait);int filemap_write_and_wait (struct address_space *mapping) { -int err =0 ; +int err;
Quoted 12 lines
mm/filemap.c int filemap_write_and_wait(struct address_space *mapping) · line 502
Quoted 8 lines
mm/filemap.c +1
-1if ((!dax_mapping (mapping) && mapping->nrpages) || (dax_mapping (mapping) && mapping->nrexceptional)) {@@ -499,10 +499,18 @@ int filemap_write_and_wait(struct address_space *mapping)* But the -EIO is special case, it may indicate the worst * thing (e.g. bug) happened, so we avoid waiting for it. */ -if (err != -EIO ) { +if (likely (err != -EIO )) {The above two cleanup changes were made only to
filemap_write_and_wait(), but should also probably be done tofilemap_write_and_wait_range()to keep them as consistent as possible?
Thanks, I fixed that in the patch in my tree. Unfortunately, as Neil pointed out, there is a bigger problem here...
There are a lot of callers of the filemap_write_and_wait* functions that never check the return code at all, and some others that call this from codepaths that where we can't report errors properly. Yet, the mapping error gets cleared out anyway, which means that fsync will probably never see it.
So while I doubt this patch will make anything worse, I think we have to look at fixing those problems first. We need to ensure that when filemap_check_errors is called, that we're in a codepath where we can actually report the error to something that can interpret it properly. Basically, only in write, fsync, msync or close codepaths. For the others, we need to use something like filemap_fdatawait_keep_errors so that we don't end up dropping writeback errors onto the floor.
I'm going to look at fixing that up first (maybe as a preliminary series to this one). There are a lot of callers though, and I don't see a way around having to go and review all of these callsites individually. Maybe it's be best to just lift the filemap_check_errors calls higher in the call stack to ensure that? Not sure...
Anyway...I'm first trying to collect a list of what I think needs fixing here, and figure out how to break all of this up into manageable pieces and order it sanely.
Signature · 7 lines
Jeff Layton <[email protected]> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 4/9 nilfs2: set the mapping error when calling SetPageError on writeback
In reply to Jeff LaytonIn a later patch, we're going to want to make the fsync codepath not do a TestClearPageError call as that can override the error set in the address space. To do that though, we need to ensure that filesystems that are relying on the PG_error bit for reporting writeback errors also set an error in the address space.
Ensure that this is set in nilfs2.
--- fs/nilfs2/segment.c | 1 + 1 file changed, 1 insertion(+)
fs/nilfs2/segment.c +1 -0
@@ -1745,6 +1745,7 @@ static void nilfs_end_page_io(struct page *page, int err) }else {__set_page_dirty_nobuffers (page);SetPageError (page); +mapping_set_error (page_mapping (page), err); }end_page_writeback (page);
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 5/9 dax: set error in mapping when writeback fails
In reply to Jeff LaytonIn order to get proper error codes from fsync, we must set an error in the mapping range when writeback fails.
--- fs/dax.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/dax.c +3 -1
@@ -892,8 +892,10 @@ int dax_writeback_mapping_range(struct address_space *mapping, ret =dax_writeback_one (bdev, mapping, indices[i], pvec.pages[i]); -if (ret <0 ) +if (ret <0 ) { +mapping_set_error (mapping, ret);return ret; + } } }return 0 ;
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 5/9] dax: set error in mapping when writeback fails
Quoted 4 lines · Jeff Layton
In order to get proper error codes from fsync, we must set an error in the mapping range when writeback fails.
Signed-off-by Jeff Layton <[email protected]>
Yep, paired with the changes to filmap_write_and_wait() and filemap_write_and_wait_range(), this seems fine.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 6/9 mm: set mapping error when launder_pages fails
In reply to Jeff LaytonIf launder_page fails, then we hit a problem writing back some inode data. Ensure that we communicate that fact in a subsequent fsync since another task could still have it open for write.
--- mm/truncate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/truncate.c +5 -1
@@ -594,11 +594,15 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)static int do_launder_page (struct address_space *mapping,struct page *page) { +int ret; +if (!PageDirty (page))return 0 ;if (page->mapping != mapping || mapping->a_ops->launder_page ==NULL )return 0 ; -return mapping->a_ops->launder_page (page); + ret = mapping->a_ops->launder_page (page); +mapping_set_error (mapping, ret); +return ret; }/**
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 6/9] mm: set mapping error when launder_pages fails
T24gV2VkLCAyMDE3LTAzLTA4IGF0IDExOjI5IC0wNTAwLCBKZWZmIExheXRvbiB3cm90ZToNCj4g SWYgbGF1bmRlcl9wYWdlIGZhaWxzLCB0aGVuIHdlIGhpdCBhIHByb2JsZW0gd3JpdGluZyBiYWNr IHNvbWUgaW5vZGUNCj4gZGF0YS4gRW5zdXJlIHRoYXQgd2UgY29tbXVuaWNhdGUgdGhhdCBmYWN0 IGluIGEgc3Vic2VxdWVudCBmc3luYw0KPiBzaW5jZQ0KPiBhbm90aGVyIHRhc2sgY291bGQgc3Rp bGwgaGF2ZSBpdCBvcGVuIGZvciB3cml0ZS4NCj4gDQo+IFNpZ25lZC1v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+IMKgfQ0KPiDCoA0KPiDCoC8qKg0KDQpOby4gQXQg dGhhdCBsYXllciwgeW91IGRvbid0IGtub3cgdGhhdCB0aGlzIGlzIGEgcGFnZSBlcnJvci4gSW4g dGhlIE5GUw0KY2FzZSwgaXQgY291bGQsIGZvciBpbnN0YW5jZSwganVzdCBhcyB3ZWxsIGJlIGEg ZmF0YWwgc2lnbmFsLg0KDQotLSANClRyb25kIE15a2xlYnVzdA0KTGludXggTkZTIGNsaWVudCBt YWludGFpbmVyLCBQcmltYXJ5RGF0YQ0KdHJvbmQubXlrbGVidXN0QHByaW1hcnlkYXRhLmNvbQ0K
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 6/9] mm: set mapping error when launder_pages fails
Quoted 30 lines · Trond Myklebust
Quoted 29 lines · Jeff Layton
If
launder_pagefails, then we hit a problem writing back some inode data. Ensure that we communicate that fact in a subsequent fsync since
another task could still have it open for write.Signed-off-by Jeff Layton <[email protected]>---
mm/truncate.c | 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)mm/truncate.c +0
-0@@ -594,11 +594,15 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
static intdo_launder_page(struct address_space *mapping, struct page *page)
{mm/truncate.c +2
-0+int ret; +if (!PageDirty(page))
return 0;
if (page->mapping!= mapping ||mapping->a_ops->launder_page== NULL)
return 0;mm/truncate.c +1
-1-return mapping->a_ops->launder_page (page); + ret = mapping->a_ops->launder_page (page);
Quoted 9 lines
Quoted 5 lines
mm/truncate.c +2
-0+mapping_set_error (mapping, ret); +return ret;}
/**No. At that layer, you don't know that this is a page error. In the NFS case, it could, for instance, just as well be a fatal signal.
Ok...don't we have the same problem with writepage then? Most of the writepage callers will set an error in the mapping if writepage returns any sort of error? A fatal signal in that codepath could cause the same problem, it seems. We don't dip into direct reclaim so much anymore, so maybe signals aren't an issue there?
The alternative here would be to push this down into the callers. I worry a bit though about getting this right across filesystems though. It'd be preferable it if we could keep the mapping_set_error call in generic VFS code instead, but if not then I'll just plan to do that.
Thanks,
Signature · 7 lines
Jeff Layton <[email protected]> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 6/9] mm: set mapping error when launder_pages fails
T24gV2VkLCAyMDE3LTAzLTA4IGF0IDEzOjM4IC0wNTAwLCBKZWZmIExheXRvbiB3cm90ZToNCj4g T24gV2VkLCAyMDE3LTAzLTA4IGF0IDE4OjAxICswMDAwLCBUcm9uZCBNeWtsZWJ1c3Qgd3JvdGU6 DQo+ID4gT24gV2VkLCAyMDE3LTAzLTA4IGF0IDExOjI5IC0wNTAwLCBKZWZmIExheXRvbiB3cm90 ZToNCj4gPiA+IElmIGxhdW5kZXJfcGFnZSBmYWlscywgdGhlbiB3ZSBoaXQgYSBwcm9ibGVtIHdy aXRpbmcgYmFjayBzb21lDQo+ID4gPiBpbm9kZQ0KPiA+ID4gZGF0YS4gRW5zdXJlIHRoYXQgd2Ug Y29tbXVuaWNhdGUgdGhhdCBmYWN0IGluIGEgc3Vic2VxdWVudCBmc3luYw0KPiA+ID4gc2luY2UN Cj4gPiA+IGFub3RoZXIgdGFzayBjb3VsZCBzdGlsbCBoYXZlIGl0IG9wZW4gZm9yIHdyaXRlLg0K PiA+ID4gDQo+ID4gPiBTaWduZWQtb2ZmLWJ5OiBKZWZmIExheXRvbiA8amxheXRvbkByZWRoYXQu Y29tPg0KPiA+ID4gLS0tDQo+ID4gPiDCoG1tL3RydW5jYXRlLmMgfCA2ICsrKysrLQ0KPiA+ID4g wqAxIGZpbGUgY2hhbmdlZCwgNSBpbnNlcnRpb25zKCspLCAxIGRlbGV0aW9uKC0pDQo+ID4gPiAN Cj4gPiA+IGRpZmYgLS1naXQgYS9tbS90cnVuY2F0ZS5jI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vc3MgZmls ZXN5c3RlbXMNCj4gdGhvdWdoLg0KPiBJdCdkIGJlIHByZWZlcmFibGUgaXQgaWYgd2UgY291bGQg a2VlcCB0aGUgbWFwcGluZ19zZXRfZXJyb3IgY2FsbCBpbg0KPiBnZW5lcmljIFZGUyBjb2RlIGlu c3RlYWQsIGJ1dCBpZiBub3QgdGhlbiBJJ2xsIGp1c3QgcGxhbiB0byBkbyB0aGF0Lg0KPiANCg0K DQoNCi0tIA0KVHJvbmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXIsIFBy aW1hcnlEYXRhDQp0cm9uZC5teWtsZWJ1c3RAcHJpbWFyeWRhdGEuY29tDQo=
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 6/9] mm: set mapping error when launder_pages fails
In reply to Trond MyklebustQuoted 30 lines · Trond Myklebust
Quoted 29 lines · Jeff Layton
If
launder_pagefails, then we hit a problem writing back some inode data. Ensure that we communicate that fact in a subsequent fsync since
another task could still have it open for write.Signed-off-by Jeff Layton <[email protected]>---
mm/truncate.c | 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)mm/truncate.c +0
-0@@ -594,11 +594,15 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
static intdo_launder_page(struct address_space *mapping, struct page *page)
{mm/truncate.c +2
-0+int ret; +if (!PageDirty(page))
return 0;
if (page->mapping!= mapping ||mapping->a_ops->launder_page== NULL)
return 0;mm/truncate.c +1
-1-return mapping->a_ops->launder_page (page); + ret = mapping->a_ops->launder_page (page);
Quoted 9 lines
Quoted 5 lines
mm/truncate.c +2
-0+mapping_set_error (mapping, ret); +return ret;}
/**No. At that layer, you don't know that this is a page error. In the NFS case, it could, for instance, just as well be a fatal signal.
In that case, would 'ret' be ERESTARTSYS or EAGAIN or similar? Should mapping_set_error() ignore those?
Thanks,
NeilBrown
Quoted 4 lines
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, PrimaryData [email protected]
PATCH v2 7/9 mm: ensure that we set mapping error if writeout() fails
In reply to Jeff LaytonIf writepage fails during a page migration, then we need to ensure that fsync will see it by flagging the mapping.
--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/migrate.c +5 -1
@@ -789,7 +789,11 @@ static int writeout(struct address_space *mapping, struct page *page)/* unlocked. Relock */ lock_page (page); -return (rc <0 ) ? -EIO : -EAGAIN ; +if (rc <0 ) { +mapping_set_error (mapping, rc); +return -EIO ; + } +return -EAGAIN ; }/*
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 8/9 mm: don't TestClearPageError in __filemap_fdatawait_range
In reply to Jeff LaytonThe -EIO returned here can end up overriding whatever error is marked in the address space. This means that an -ENOSPC error (AS_ENOSPC) can end up being turned into -EIO if a page gets PG_error set on it during error handling.
Read errors are also sometimes tracked on a per-page level using PG_error. Suppose we have a read error on a page, and then that page is subsequently dirtied by overwriting the whole page. Writeback doesn't clear PG_error, so we can then end up successfully writing back that page and still return -EIO on fsync.
Worse yet, PG_error is cleared during a sync() syscall, but the -EIO return from this code is silently discarded. Any subsystem that is relying on PG_error to report errors during fsync or close is already broken due to this. All you need is a stray sync() call on the box at the wrong time and you've lost the error.
Since the handling of the PG_error flag is somewhat inconsistent across subsystems, let's just rely on marking the address space when there are writeback errors. Change the TestClearPageError call to ClearPageError, and make __filemap_fdatawait_range a void return function.
--- mm/filemap.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
mm/filemap.c +5 -15
@@ -376,17 +376,16 @@ int filemap_flush(struct address_space *mapping) }EXPORT_SYMBOL (filemap_flush); -static int __filemap_fdatawait_range (struct address_space *mapping, +static void __filemap_fdatawait_range (struct address_space *mapping,loff_t start_byte,loff_t end_byte) {pgoff_t index = start_byte >>PAGE_SHIFT ;pgoff_t end = end_byte >>PAGE_SHIFT ;struct pagevec pvec;int nr_pages; -int ret =0 ;if (end_byte < start_byte) - goto out; +return ;pagevec_init (&pvec,0 ); while ((index <= end) &&
@@ -403,14 +402,11 @@ static int __filemap_fdatawait_range(struct address_space *mapping,continue ;wait_on_page_writeback (page); -if (TestClearPageError (page)) - ret = -EIO ; +ClearPageError (page); }pagevec_release (&pvec);cond_resched (); } -out: -return ret; }/**
@@ -430,14 +426,8 @@ static int __filemap_fdatawait_range(struct address_space *mapping,int filemap_fdatawait_range (struct address_space *mapping,loff_t start_byte,loff_t end_byte) { -int ret, ret2; - - ret =__filemap_fdatawait_range (mapping, start_byte, end_byte); - ret2 =filemap_check_errors (mapping); -if (!ret) - ret = ret2; - -return ret; +__filemap_fdatawait_range (mapping, start_byte, end_byte); +return filemap_check_errors (mapping); }EXPORT_SYMBOL (filemap_fdatawait_range);
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 9/9 Documentation: document what to do on a writeback error
In reply to Jeff LaytonThere's no real guidance on this for filesystem authors, so add a paragraph to vfs.txt that explains how this should be handled.
--- Documentation/filesystems/vfs.txt | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/filesystems/vfs.txt +7 -0
@@ -577,6 +577,13 @@ should clear PG_Dirty and set PG_Writeback. It can be actually written at any point after PG_Dirty is clear. Once it is known to be safe, PG_Writeback is cleared. +If there is an error during writeback, then the address_space should be +marked with an AS_EIO or AS_ENOSPC error, in order to ensure that the +error will be reported to the application at fsync or close. Most +writepage callers will do this automatically if writepage returns an +error, but writepages implementations generally need to ensure this +themselves. + Writeback makes use of a writeback_control structure... struct address_space_operations
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>