fs: introduce new writeback error reporting and convert existing API as a wrapper around it
Subsystems (25)
v4 cover fs: introduce new writeback error reporting and convert existing API as a wrapper around it
v4: several more cleanup patches
documentation and kerneldoc comment updates fix bugs in gfs2 patches
make sync_file_range use same error reporting semantics bugfixes in buffer.c
convert nfs to new scheme (maybe bogus, can be dropped)
v3: wb_err_t -> errseq_t conversion
clean up places that re-set errors after calling filemap_* functions
v2: introduce wb_err_t, use atomics
Apologies for the wide posting here, but this touches a lot of areas. This is v3 of the patchset to improve how we're tracking and reporting errors that occur during pagecache writeback.
There are several situations where the kernel can "lose" errors that occur during writeback, such that fsync will return success even though it failed to write back some data previously. The basic idea here is to have the kernel be more deliberate about the point from which errors are checked to ensure that that doesn't happen.
Additionally, this set changes the behavior of fsync in Linux to report writeback errors on all fds instead of just the first one. This allows writers to reliably tell whether their data made it to the backing device without having to coordinate fsync calls with other writers.
This set sprawls over a large swath of kernel code. I think the first 12 patches in the series are pretty straightforward and are more or less ready for merge.
The real changes start with patch 13. That adds support for errseq_t, builds a new writeback error tracking API on top of that, and converts the existing code to use it. After that, there are a few cleanup patches to eliminate some unneeded error re-setting, etc.
Finally, there are several patches that attempt to codify the semantics in the documentation and make it clear what filesystems should do when there are writeback errors.
Unfortunately, testing this across so many filesystems is rather difficult. I have a xfstest for block-based filesystems that uses dm_error that I'll repost soon. It works well with xfs and ext4 and those now pass after this patchset. btrfs still fails however, so it may need some more work to get this right. I also don't have a good general method for testing this on network filesystems (yet!).
I'd like to see better testing here and am open to suggestions. I will note that the POSIX fsync spec says this:
"It is reasonable to assert that the key aspects of fsync() are unreasonable to test in a test suite. That does not make the function any less valuable, just more difficult to test. [...] It would also not be unreasonable to omit testing for fsync(), allowing it to be treated as a quality-of-implementation issue."
Of course, they're talking about a POSIX conformance test, but I think the same point applies here.
At this point, I'd like to start getting some of the preliminary patches merged (the first 12 or so). Most of those aren't terribly controversial and seem like reasonable bugfixes and cleanups. If any subsystem maintainers want to pick those up, then please do.
After that, I'd like to get the larger changes into linux-next with an aim for merge in v4.13 or v4.14 (depending on how testing goes).
Feedback is of course welcome.
Jeff Layton (27):
fs: remove unneeded forward definition of mm_struct from fs.h
mm: drop "wait" parameter from write_one_page
mm: fix mapping_set_error call in me_pagecache_dirty
buffer: use mapping_set_error instead of setting the flag
btrfs: btrfs_wait_tree_block_writeback can be void return
fs: check for writeback errors after syncing out buffers in
generic_file_fsync
orangefs: don't call filemap_write_and_wait from fsync
dax: set errors in mapping when writeback fails
nilfs2: set the mapping error when calling SetPageError on writeback 9p: set mapping error when writeback fails in launder_page
fuse: set mapping error in writepage_locked when it fails
cifs: set mapping error when page writeback fails in writepage or
launder_pages
lib: add errseq_t type and infrastructure for handling it
fs: new infrastructure for writeback error handling and reporting
fs: retrofit old error reporting API onto new infrastructure
fs: adapt sync_file_range to new reporting infrastructure
mm: remove AS_EIO and AS_ENOSPC flags
mm: don't TestClearPageError in __filemap_fdatawait_range
buffer: set errors in mapping at the time that the error occurs
cifs: cleanup writeback handling errors and comments
mm: clean up error handling in write_one_page
jbd2: don't reset error in journal_finish_inode_data_buffers
gfs2: clean up some filemap_* calls
nfs: convert to new errseq_t based error tracking for writeback errors
Documentation: flesh out the section in vfs.txt on storing and
reporting writeback errors
mm: flesh out comments over mapping_set_error
mm: clean up comments in me_pagecache_dirty
Documentation/filesystems/vfs.txt | 49 +++++++++- drivers/dax/dax.c | 1 + fs/9p/vfs_addr.c | 5 +- fs/block_dev.c | 1 + fs/btrfs/disk-io.c | 6 +- fs/btrfs/disk-io.h | 2 +- fs/btrfs/file.c | 10 +- fs/btrfs/tree-log.c | 9 +- fs/buffer.c | 19 ++-- fs/cifs/cifsfs.c | 4 +- fs/cifs/file.c | 19 ++-- fs/cifs/inode.c | 22 ++--- fs/dax.c | 4 +- fs/exofs/dir.c | 2 +- fs/ext2/dir.c | 2 +- fs/ext2/file.c | 2 +- fs/f2fs/file.c | 3 + fs/f2fs/node.c | 6 +- fs/file_table.c | 1 + fs/fuse/file.c | 8 +- fs/gfs2/glops.c | 17 +--- fs/gfs2/lops.c | 6 +- fs/gfs2/super.c | 6 +- fs/jbd2/commit.c | 13 +-- fs/jfs/jfs_metapage.c | 4 +- fs/libfs.c | 3 + fs/minix/dir.c | 2 +- fs/nfs/file.c | 19 ++-- fs/nfs/inode.c | 5 +- fs/nfs/write.c | 2 +- fs/nilfs2/segment.c | 1 + fs/open.c | 3 + fs/orangefs/file.c | 5 +- fs/sync.c | 13 ++- fs/sysv/dir.c | 2 +- fs/ufs/dir.c | 2 +- include/linux/buffer_head.h | 1 + include/linux/errseq.h | 19 ++++ include/linux/fs.h | 45 +++++++-- include/linux/mm.h | 2 +- include/linux/nfs_fs.h | 3 +- include/linux/pagemap.h | 32 +++--- lib/Makefile | 2 +- lib/errseq.c | 199 ++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 103 ++++++++++++-------- mm/memory-failure.c | 37 ++----- mm/page-writeback.c | 23 +++-- 47 files changed, 512 insertions(+), 232 deletions(-) create mode 100644 include/linux/errseq.h create mode 100644 lib/errseq.c
Signature · 1 line
2.9.3
PATCH v4 1/27 fs: remove unneeded forward definition of mm_struct from fs.h
--- include/linux/fs.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/fs.h +0 -2
@@ -1252,8 +1252,6 @@ extern void f_delown(struct file *filp);extern pid_t f_getown (struct file *filp);extern int send_sigurg (struct fown_struct *fown); -struct mm_struct ; -/* * Umount options */
Signature · 1 line
2.9.3
Re: [PATCH v4 01/27] fs: remove unneeded forward definition of mm_struct from fs.h
Quoted 1 line · Jeff Layton
Signed-off-by Jeff Layton <[email protected]>
Looks good. You can add:
Honza
Quoted 21 lines
--- include/linux/fs.h | 2 -- 1 file changed, 2 deletions(-)include/linux/fs.h +0
-2@@ -1252,8 +1252,6 @@ extern void f_delown(struct file *filp);extern pid_t f_getown (struct file *filp);extern int send_sigurg (struct fown_struct *fown); -struct mm_struct ; -/* * Umount options */ Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 2/27 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.
Also, add __must_check here since, in general, the callers need to handle an error here in some fashion.
--- 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
@@ -2187,7 +2187,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 __must_check 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 · 1 line
2.9.3
PATCH v4 3/27 mm: fix mapping_set_error call in me_pagecache_dirty
In reply to Jeff LaytonThe 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. Also, later patches will require a negative error code here.
--- 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 · 1 line
2.9.3
PATCH v4 4/27 buffer: use mapping_set_error instead of setting the flag
In reply to Jeff Layton--- fs/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/buffer.c +1 -1
@@ -483,7 +483,7 @@ static void __remove_assoc_queue(struct buffer_head *bh)list_del_init (&bh->b_assoc_buffers);WARN_ON (!bh->b_assoc_map);if (buffer_write_io_error (bh)) -set_bit (AS_EIO , &bh->b_assoc_map->flags); +mapping_set_error (bh->b_assoc_map, -EIO ); bh->b_assoc_map =NULL ; }
Signature · 1 line
2.9.3
PATCH v4 5/27 btrfs: btrfs_wait_tree_block_writeback can be void return
In reply to Jeff LaytonNothing checks its return value.
--- fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/disk-io.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +3 -3
@@ -1222,10 +1222,10 @@ int btrfs_write_tree_block(struct extent_buffer *buf) buf->start + buf->len - 1); } -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf) +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf) { -return filemap_fdatawait_range (buf->pages[0 ]->mapping, - buf->start, buf->start + buf->len -1 ); +filemap_fdatawait_range (buf->pages[0 ]->mapping, + buf->start, buf->start + buf->len -1 ); } struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
fs/btrfs/disk-io.h +1 -1
@@ -127,7 +127,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, extent_submit_bio_hook_t *submit_bio_done);unsigned long btrfs_async_submit_limit (struct btrfs_fs_info *info);int btrfs_write_tree_block (struct extent_buffer *buf); -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf); +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf);int btrfs_init_log_root_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info); int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
Signature · 1 line
2.9.3
Re: [PATCH v4 05/27] btrfs: btrfs_wait_tree_block_writeback can be void return
Quoted 3 lines · Jeff Layton
Nothing checks its return value.
Signed-off-by Jeff Layton <[email protected]>
Looks good to me. You can add:
Honza
Quoted 40 lines
--- fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/disk-io.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)fs/btrfs/disk-io.c +3
-3@@ -1222,10 +1222,10 @@ int btrfs_write_tree_block(struct extent_buffer *buf) buf->start + buf->len - 1); } -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf) +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf) { -return filemap_fdatawait_range (buf->pages[0 ]->mapping, - buf->start, buf->start + buf->len -1 ); +filemap_fdatawait_range (buf->pages[0 ]->mapping, + buf->start, buf->start + buf->len -1 ); } struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,fs/btrfs/disk-io.h +1
-1@@ -127,7 +127,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, extent_submit_bio_hook_t *submit_bio_done);unsigned long btrfs_async_submit_limit (struct btrfs_fs_info *info);int btrfs_write_tree_block (struct extent_buffer *buf); -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf); +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf);int btrfs_init_log_root_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info); int btrfs_add_log_tree(struct btrfs_trans_handle *trans,Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 05/27] btrfs: btrfs_wait_tree_block_writeback can be void return
In reply to Jeff LaytonQuoted 1 line · Jeff Layton
Nothing checks its return value.
-liubo
Quoted 41 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/disk-io.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)fs/btrfs/disk-io.c +3
-3@@ -1222,10 +1222,10 @@ int btrfs_write_tree_block(struct extent_buffer *buf) buf->start + buf->len - 1); } -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf) +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf) { -return filemap_fdatawait_range (buf->pages[0 ]->mapping, - buf->start, buf->start + buf->len -1 ); +filemap_fdatawait_range (buf->pages[0 ]->mapping, + buf->start, buf->start + buf->len -1 ); } struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,fs/btrfs/disk-io.h +1
-1@@ -127,7 +127,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, extent_submit_bio_hook_t *submit_bio_done);unsigned long btrfs_async_submit_limit (struct btrfs_fs_info *info);int btrfs_write_tree_block (struct extent_buffer *buf); -int btrfs_wait_tree_block_writeback (struct extent_buffer *buf); +void btrfs_wait_tree_block_writeback (struct extent_buffer *buf);int btrfs_init_log_root_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info); int btrfs_add_log_tree(struct btrfs_trans_handle *trans,Signature · 1 line
2.9.3
PATCH v4 6/27 fs: check for writeback errors after syncing out buffers in generic_file_fsync
In reply to Jeff Laytonext2 currently does a test+clear of the AS_EIO flag, which is is problematic for some coming changes.
What we really need to do instead is call filemap_check_errors in __generic_file_fsync after syncing out the buffers. That will be sufficient for this case, and help other callers detect these errors properly as well.
With that, we don't need to twiddle it in ext2.
--- fs/ext2/file.c | 2 +- fs/libfs.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
fs/ext2/file.c +1 -1
@@ -177,7 +177,7 @@ int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync)struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; ret =generic_file_fsync (file, start, end, datasync); -if (ret == -EIO ||test_and_clear_bit (AS_EIO , &mapping->flags)) { +if (ret == -EIO ) {/* We don't really know where the IO error happened... */ ext2_error (sb, __func__,"detected IO error when writing metadata buffers" );
fs/libfs.c +2 -1
@@ -991,7 +991,8 @@ int __generic_file_fsync(struct file *file, loff_t start, loff_t end, out:inode_unlock (inode); -return ret; + err =filemap_check_errors (inode->i_mapping); +return ret ? ret : err; }EXPORT_SYMBOL (__generic_file_fsync);
Signature · 1 line
2.9.3
Re: [PATCH v4 06/27] fs: check for writeback errors after syncing out buffers in generic_file_fsync
Quoted 8 lines · Jeff Layton
ext2 currently does a test+clear of the
AS_EIOflag, which is is problematic for some coming changes.What we really need to do instead is call
filemap_check_errorsin__generic_file_fsyncafter syncing out the buffers. That will be sufficient for this case, and help other callers detect these errors properly as well.
Quoted 6 lines
With that, we don't need to twiddle it in ext2.
Suggested-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Jan Kara <[email protected]>
PATCH v4 7/27 orangefs: don't call filemap_write_and_wait from fsync
In reply to Jeff LaytonOrangefs doesn't do buffered writes yet, so there's no point in initiating and waiting for writeback.
--- fs/orangefs/file.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/orangefs/file.c +1 -4
@@ -646,14 +646,11 @@ static int orangefs_fsync(struct file *file,loff_t end, int datasync) { - int ret = -EINVAL; + int ret;struct orangefs_inode_s *orangefs_inode =ORANGEFS_I (file_inode (file));struct orangefs_kernel_op_s *new_op =NULL ; -/* required call */ -filemap_write_and_wait_range (file->f_mapping, start, end); - new_op =op_alloc (ORANGEFS_VFS_OP_FSYNC );if (!new_op)return -ENOMEM ;
Signature · 1 line
2.9.3
PATCH v4 8/27 dax: set errors in mapping when writeback fails
In reply to Jeff LaytonJan's description for this patch is much better than mine, so I'm quoting it verbatim here:
DAX currently doesn't set errors in the mapping when cache flushing fails in dax_writeback_mapping_range(). Since this function can get called only from fsync(2) or sync(2), this is actually as good as it can currently get since we correctly propagate the error up from dax_writeback_mapping_range() to filemap_fdatawrite(). However in the future better writeback error handling will enable us to properly report these errors on fsync(2) even if there are multiple file descriptors open against the file or if sync(2) gets called before fsync(2). So convert DAX to using standard error reporting through the mapping.
--- fs/dax.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/dax.c +3 -1
@@ -901,8 +901,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 · 1 line
2.9.3
PATCH v4 9/27 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 · 1 line
2.9.3
PATCH v4 10/27 9p: set mapping error when writeback fails in launder_page
In reply to Jeff Laytonlaunder_page is just writeback under the page lock. We still need to mark the mapping for errors there when they occur.
--- fs/9p/vfs_addr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/9p/vfs_addr.c +4 -1
@@ -223,8 +223,11 @@ static int v9fs_launder_page(struct page *page)v9fs_fscache_wait_on_page_write (inode, page);if (clear_page_dirty_for_io (page)) { retval =v9fs_vfs_writepage_locked (page); -if (retval) +if (retval) { +if (retval != -EAGAIN ) +mapping_set_error (page->mapping, retval);return retval; + } }return 0 ; }
Signature · 1 line
2.9.3
PATCH v4 11/27 fuse: set mapping error in writepage_locked when it fails
In reply to Jeff LaytonThis ensures that we see errors on fsync when writeback fails.
--- fs/fuse/file.c | 1 + 1 file changed, 1 insertion(+)
fs/fuse/file.c +1 -0
@@ -1669,6 +1669,7 @@ static int fuse_writepage_locked(struct page *page) err_free:fuse_request_free (req); err: +mapping_set_error (page->mapping, error);end_page_writeback (page);return error; }
Signature · 1 line
2.9.3
Re: [PATCH v4 11/27] fuse: set mapping error in writepage_locked when it fails
Quoted 4 lines · Jeff Layton
This ensures that we see errors on fsync when writeback fails.
Signed-off-by Jeff Layton <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>
Looks good to me. You can add:
Honza
Quoted 20 lines
--- fs/fuse/file.c | 1 + 1 file changed, 1 insertion(+)fs/fuse/file.c +1
-0@@ -1669,6 +1669,7 @@ static int fuse_writepage_locked(struct page *page) err_free:fuse_request_free (req); err: +mapping_set_error (page->mapping, error);end_page_writeback (page);return error; }Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 12/27 cifs: set mapping error when page writeback fails in writepage or launder_pages
In reply to Jeff Layton--- fs/cifs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/cifs/file.c +7 -5
@@ -2234,14 +2234,16 @@ cifs_writepage_locked(struct page *page, struct writeback_control *wbc)set_page_writeback (page); retry_write: rc =cifs_partialpagewrite (page,0 ,PAGE_SIZE ); -if (rc == -EAGAIN && wbc->sync_mode ==WB_SYNC_ALL ) - goto retry_write; -else if (rc == -EAGAIN ) +if (rc == -EAGAIN ) { +if (wbc->sync_mode ==WB_SYNC_ALL ) + goto retry_write;redirty_page_for_writepage (wbc, page); -else if (rc !=0 ) + }else if (rc !=0 ) {SetPageError (page); -else +mapping_set_error (page->mapping, rc); + }else {SetPageUptodate (page); + }end_page_writeback (page);put_page (page);free_xid (xid);
Signature · 1 line
2.9.3
Re: [PATCH v4 12/27] cifs: set mapping error when page writeback fails in writepage or launder_pages
Quoted 2 lines · Jeff Layton
Signed-off-by Jeff Layton <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>
Looks good to me. You can add:
Honza
Quoted 34 lines
--- fs/cifs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)fs/cifs/file.c +7
-5@@ -2234,14 +2234,16 @@ cifs_writepage_locked(struct page *page, struct writeback_control *wbc)set_page_writeback (page); retry_write: rc =cifs_partialpagewrite (page,0 ,PAGE_SIZE ); -if (rc == -EAGAIN && wbc->sync_mode ==WB_SYNC_ALL ) - goto retry_write; -else if (rc == -EAGAIN ) +if (rc == -EAGAIN ) { +if (wbc->sync_mode ==WB_SYNC_ALL ) + goto retry_write;redirty_page_for_writepage (wbc, page); -else if (rc !=0 ) + }else if (rc !=0 ) {SetPageError (page); -else +mapping_set_error (page->mapping, rc); + }else {SetPageUptodate (page); + }end_page_writeback (page);put_page (page);free_xid (xid);Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 13/27 lib: add errseq_t type and infrastructure for handling it
In reply to Jeff LaytonAn errseq_t is a way of recording errors in one place, and allowing any number of "subscribers" to tell whether an error has been set again since a previous time.
It's implemented as an unsigned 32-bit value that is managed with atomic operations. The low order bits are designated to hold an error code (max size of MAX_ERRNO). The upper bits are used as a counter.
The API works with consumers sampling an errseq_t value at a particular point in time. Later, that value can be used to tell whether new errors have been set since that time.
Note that there is a 1 in 512k risk of collisions here if new errors are being recorded frequently, since we have so few bits to use as a counter. To mitigate this, one bit is used as a flag to tell whether the value has been sampled since a new value was recorded. That allows us to avoid bumping the counter if no one has sampled it since it was last bumped.
Later patches will build on this infrastructure to change how writeback errors are tracked in the kernel.
--- include/linux/errseq.h | 19 +++++ lib/Makefile | 2 +- lib/errseq.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 include/linux/errseq.h create mode 100644 lib/errseq.c
include/linux/errseq.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef _LINUX_ERRSEQ_H +#define _LINUX_ERRSEQ_H + +/* See lib/errseq.c for more info */ + +typedef u32 errseq_t ; + +void __errseq_set (errseq_t *eseq,int err); +static inline void errseq_set (errseq_t *eseq,int err) +{ +/* Optimize for the common case of no error */ +if (unlikely (err)) +__errseq_set (eseq, err); +} + +errseq_t errseq_sample (errseq_t *eseq); +int errseq_check (errseq_t *eseq,errseq_t since); +int errseq_check_and_advance (errseq_t *eseq,errseq_t *since); +#endif
lib/Makefile +1 -1
@@ -41,7 +41,7 @@ obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \ gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o \ - once.o refcount.o + once.o refcount.o errseq.o obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += hexdump.o
lib/errseq.c new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
Quoted 19 lines · Jeff Layton
An
errseq_tis a way of recording errors in one place, and allowing any number of "subscribers" to tell whether an error has been set again since a previous time.It's implemented as an unsigned 32-bit value that is managed with atomic operations. The low order bits are designated to hold an error code (max size of
MAX_ERRNO). The upper bits are used as a counter.The API works with consumers sampling an
errseq_tvalue at a particular point in time. Later, that value can be used to tell whether new errors have been set since that time.Note that there is a 1 in 512k risk of collisions here if new errors are being recorded frequently, since we have so few bits to use as a counter. To mitigate this, one bit is used as a flag to tell whether the value has been sampled since a new value was recorded. That allows us to avoid bumping the counter if no one has sampled it since it was last bumped.
Quoted 4 lines
Later patches will build on this infrastructure to change how writeback errors are tracked in the kernel.
Signed-off-by Jeff Layton <[email protected]>
I like that this is a separate lib/*.c - nicely structured too.
Thanks,
NeilBrown
Quoted 258 lines
--- include/linux/errseq.h | 19 +++++ lib/Makefile | 2 +- lib/errseq.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 include/linux/errseq.h create mode 100644 lib/errseq.cinclude/linux/errseq.h new file +19
-0@@ -0,0 +1,19 @@ +#ifndef _LINUX_ERRSEQ_H +#define _LINUX_ERRSEQ_H + +/* See lib/errseq.c for more info */ + +typedef u32 errseq_t ; + +void __errseq_set (errseq_t *eseq,int err); +static inline void errseq_set (errseq_t *eseq,int err) +{ +/* Optimize for the common case of no error */ +if (unlikely (err)) +__errseq_set (eseq, err); +} + +errseq_t errseq_sample (errseq_t *eseq); +int errseq_check (errseq_t *eseq,errseq_t since); +int errseq_check_and_advance (errseq_t *eseq,errseq_t *since); +#endif lib/Makefile +1
-1@@ -41,7 +41,7 @@ obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \ gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o \ - once.o refcount.o + once.o refcount.o errseq.o obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += hexdump.olib/errseq.c new file +199
-0@@ -0,0 +1,199 @@ +#include <linux/err.h> +#include <linux/bug.h> +#include <linux/atomic.h> +#include <linux/errseq.h> + +/* +* An errseq_t is a way of recording errors in one place, and allowing any +* number of "subscribers" to tell whether it has changed since an arbitrary +* time of their choosing. +* +* It's implemented as an unsigned 32-bit value. The low order bits are +* designated to hold an error code (between 0 and -MAX_ERRNO). The upper bits +* are used as a counter. This is done with atomics instead of locking so that +* these functions can be called from any context. +* +* The general idea is for consumers to sample an errseq_t value at a +* particular point in time. Later, that value can be used to tell whether any +* new errors have occurred since that time. +* +* Note that there is a risk of collisions, if new errors are being recorded +* frequently, since we have so few bits to use as a counter. +* +* To mitigate this, one bit is used as a flag to tell whether the value has +* been sampled since a new value was recorded. That allows us to avoid bumping +* the counter if no one has sampled it since the last time an error was +* recorded. +* +* A new errseq_t should always be zeroed out. A errseq_t value of all zeroes +* is the special (but common) case where there has never been an error. An all +* zero value thus serves as the "epoch" if one wishes to know whether there +* has ever been an error set since it was first initialized. +*/ + +/* The low bits are designated for error code (max of MAX_ERRNO) */ +#define ERRSEQ_SHIFT ilog2(MAX_ERRNO + 1) + +/* This bit is used as a flag to indicate whether the value has been seen */ +#define ERRSEQ_SEEN (1 << ERRSEQ_SHIFT) + +/* The "ones" bit for the counter */ +#define ERRSEQ_CTR_INC (1 << (ERRSEQ_SHIFT + 1)) + +/** +* __errseq_set - set a errseq_t for later reporting +* @eseq: errseq_t field that should be set +* @err: error to set +* +* This function sets the error in *eseq, and increments the sequence counter +* if the last sequence was sampled at some point in the past. +* +* Any error set will always overwrite an existing error. +* +* Most callers will want to use the errseq_set inline wrapper to efficiently +* handle the common case where err is 0. +*/ +void __errseq_set (errseq_t *eseq,int err) +{ +errseq_t old; + +/* MAX_ERRNO must be able to serve as a mask */ +BUILD_BUG_ON_NOT_POWER_OF_2 (MAX_ERRNO +1 ); + +/* +* Ensure the error code actually fits where we want it to go. If it +* doesn't then just throw a warning and don't record anything. We +* also don't accept zero here as that would effectively clear a +* previous error. +*/ +if (WARN (unlikely (err ==0 || (unsigned int )-err >MAX_ERRNO ), +"err = %d\n" , err)) +return ; + + old =READ_ONCE (*eseq); +for (;;) { +errseq_t new, cur; + +/* Clear out error bits and set new error */ + new = (old & ~(MAX_ERRNO |ERRSEQ_SEEN )) | -err; + +/* Only increment if someone has looked at it */ +if (old &ERRSEQ_SEEN ) + new +=ERRSEQ_CTR_INC ; + +/* If there would be no change, then call it done */ +if (new == old) +break ; + +/* Try to swap the new value into place */ + cur =cmpxchg (eseq, old, new); + +/* +* Call it success if we did the swap or someone else beat us +* to it for the same value. +*/ +if (likely (cur == old || cur == new)) +break ; + +/* Raced with an update, try again */ + old = cur; + } +} +EXPORT_SYMBOL (__errseq_set); + +/** +* errseq_sample - grab current errseq_t value +* @eseq: pointer to errseq_t to be sampled +* +* This function allows callers to sample an errseq_t value, marking it as +* "seen" if required. +*/ +errseq_t errseq_sample (errseq_t *eseq) +{ +errseq_t old =READ_ONCE (*eseq); +errseq_t new = old; + +/* +* For the common case of no errors ever having been set, we can skip +* marking the SEEN bit. Once an error has been set, the value will +* never go back to zero. +*/ +if (old !=0 ) { + new |=ERRSEQ_SEEN ; +if (old != new) +cmpxchg (eseq, old, new); + } +return new; +} +EXPORT_SYMBOL (errseq_sample); + +/** +* errseq_check - has an error occurred since a particular point in time? +* @eseq: pointer to errseq_t value to be checked +* @since: previously-sampled errseq_t from which to check +* +* Grab the value that eseq points to, and see if it has changed "since" +* the given value was sampled. The "since" value is not advanced, so there +* is no need to mark the value as seen. +* +* Returns the latest error set in the errseq_t or 0 if it hasn't changed. +*/ +int errseq_check (errseq_t *eseq,errseq_t since) +{ +errseq_t cur =READ_ONCE (*eseq); + +if (likely (cur == since)) +return 0 ; +return -(cur &MAX_ERRNO ); +} +EXPORT_SYMBOL (errseq_check); + +/** +* errseq_check_and_advance - check an errseq_t and advance it to the current value +* @eseq: pointer to value being checked reported +* @since: pointer to previously-sampled errseq_t to check against and advance +* +* Grab the eseq value, and see whether it matches the value that "since" +* points to. If it does, then just return 0. +* +* If it doesn't, then the value has changed. Set the "seen" flag, and try to +* swap it into place as the new eseq value. Then, set that value as the new +* "since" value, and return whatever the error portion is set to. +* +* Note that no locking is provided here for concurrent updates to the "since" +* value. The caller must provide that if necessary. Because of this, callers +* may want to do a lockless errseq_check before taking the lock and calling +* this. +*/ +int errseq_check_and_advance (errseq_t *eseq,errseq_t *since) +{ +int err =0 ; +errseq_t old, new; + +/* +* Most callers will want to use the inline wrapper to check this, +* so that the common case of no error is handled without needing +* to lock. +*/ + old =READ_ONCE (*eseq); +if (old != *since) { +/* +* Set the flag and try to swap it into place if it has +* changed. +* +* We don't care about the outcome of the swap here. If the +* swap doesn't occur, then it has either been updated by a +* writer who is bumping the seq count anyway, or another +* reader who is just setting the "seen" flag. Either outcome +* is OK, and we can advance "since" and return an error based +* on what we have. +*/ + new = old |ERRSEQ_SEEN ; +if (new != old) +cmpxchg (eseq, old, new); + *since = new; + err = -(new &MAX_ERRNO ); + } +return err; +} +EXPORT_SYMBOL (errseq_check_and_advance);Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20170510/5ff2a5af/attachment.sig>
Re: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
Quoted 21 lines · NeilBrown
Quoted 19 lines · Jeff Layton
An
errseq_tis a way of recording errors in one place, and allowing any number of "subscribers" to tell whether an error has been set again since a previous time.It's implemented as an unsigned 32-bit value that is managed with atomic operations. The low order bits are designated to hold an error code (max size of
MAX_ERRNO). The upper bits are used as a counter.The API works with consumers sampling an
errseq_tvalue at a particular point in time. Later, that value can be used to tell whether new errors have been set since that time.Note that there is a 1 in 512k risk of collisions here if new errors are being recorded frequently, since we have so few bits to use as a counter. To mitigate this, one bit is used as a flag to tell whether the value has been sampled since a new value was recorded. That allows us to avoid bumping the counter if no one has sampled it since it was last bumped.
Quoted 10 lines
Quoted 4 lines
Later patches will build on this infrastructure to change how writeback errors are tracked in the kernel.
Signed-off-by Jeff Layton <[email protected]>I like that this is a separate
lib/*.c- nicely structured too.Reviewed-by NeilBrown <[email protected]>
Thanks, yeah...it occurred to me that this scheme is not really specific to writeback errors. While I can't think of another use-case for errseq_t's right offhand, I think this makes for cleaner layering and should make it easy to use in other ways should they arise.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
In reply to Jeff LaytonQuoted 19 lines · Jeff Layton
An
errseq_tis a way of recording errors in one place, and allowing any number of "subscribers" to tell whether an error has been set again since a previous time.It's implemented as an unsigned 32-bit value that is managed with atomic operations. The low order bits are designated to hold an error code (max size of
MAX_ERRNO). The upper bits are used as a counter.The API works with consumers sampling an
errseq_tvalue at a particular point in time. Later, that value can be used to tell whether new errors have been set since that time.Note that there is a 1 in 512k risk of collisions here if new errors are being recorded frequently, since we have so few bits to use as a counter. To mitigate this, one bit is used as a flag to tell whether the value has been sampled since a new value was recorded. That allows us to avoid bumping the counter if no one has sampled it since it was last bumped.
Quoted 4 lines
Later patches will build on this infrastructure to change how writeback errors are tracked in the kernel.
Signed-off-by Jeff Layton <[email protected]>
The patch looks good to me. Feel free to add:
Just two nits below:
...
lib/errseq.c line 177
Quoted 10 lines
lib/errseq.c new file +10
-0+int errseq_check_and_advance (errseq_t *eseq,errseq_t *since) +{ +int err =0 ; +errseq_t old, new; + +/* +* Most callers will want to use the inline wrapper to check this, +* so that the common case of no error is handled without needing +* to lock. +*/
I'm not sure which locking you are speaking about here. Is the comment stale?
lib/errseq.c line 186
Quoted 9 lines
lib/errseq.c new file +9
-0+ old =READ_ONCE (*eseq); +if (old != *since) { +/* +* Set the flag and try to swap it into place if it has +* changed. +* +* We don't care about the outcome of the swap here. If the +* swap doesn't occur, then it has either been updated by a +* writer who is bumping the seq count anyway, or another
"bumping the seq count anyway" part is not quite true. Writer may see ERRSEQ_SEEN not set and so just update the error code and leave seq count as is. But since you compare full errseq_t for equality, this works out as designed...
lib/errseq.c line 199
Quoted 13 lines
lib/errseq.c new file +13
-0+* reader who is just setting the "seen" flag. Either outcome +* is OK, and we can advance "since" and return an error based +* on what we have. +*/ + new = old |ERRSEQ_SEEN ; +if (new != old) +cmpxchg (eseq, old, new); + *since = new; + err = -(new &MAX_ERRNO ); + } +return err; +} +EXPORT_SYMBOL (errseq_check_and_advance);
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
Quoted 31 lines · Jan Kara
Quoted 19 lines · Jeff Layton
An
errseq_tis a way of recording errors in one place, and allowing any number of "subscribers" to tell whether an error has been set again since a previous time.It's implemented as an unsigned 32-bit value that is managed with atomic operations. The low order bits are designated to hold an error code (max size of
MAX_ERRNO). The upper bits are used as a counter.The API works with consumers sampling an
errseq_tvalue at a particular point in time. Later, that value can be used to tell whether new errors have been set since that time.Note that there is a 1 in 512k risk of collisions here if new errors are being recorded frequently, since we have so few bits to use as a counter. To mitigate this, one bit is used as a flag to tell whether the value has been sampled since a new value was recorded. That allows us to avoid bumping the counter if no one has sampled it since it was last bumped.
Quoted 4 lines
Later patches will build on this infrastructure to change how writeback errors are tracked in the kernel.
Signed-off-by Jeff Layton <[email protected]>The patch looks good to me. Feel free to add:
Reviewed-by Jan Kara <[email protected]>Just two nits below:
...
Quoted 14 lines
lib/errseq.c line 177
Quoted 10 lines
lib/errseq.c new file +10
-0+int errseq_check_and_advance (errseq_t *eseq,errseq_t *since) +{ +int err =0 ; +errseq_t old, new; + +/* +* Most callers will want to use the inline wrapper to check this, +* so that the common case of no error is handled without needing +* to lock. +*/ I'm not sure which locking you are speaking about here. Is the comment stale?
No it's not stale, just unclear. In the kerneldoc comment, I have this blurb:
* Note that no locking is provided here for concurrent updates to the "since"
* value. The caller must provide that if necessary. Because of this, callers
* may want to do a lockless errseq_check before taking the lock and calling
* this.
...so the lock here refers to any locking that the caller needs to do to serialize changes to "since" in this function. For the usual case of file->f_wb_err, we use f_lock to protect it so by doing an errseq_check beforehand we can avoid taking the f_lock and calling this function if the value hasn't changed.
I'll see if I can rephrase that to be more clear.
Quoted 6 lines
Quoted 6 lines
lib/errseq.c new file +6
-0+ old =READ_ONCE (*eseq); +if (old != *since) { +/* +* Set the flag and try to swap it into place if it has +* changed. +*
Quoted 9 lines
lib/errseq.c line 186
Quoted 3 lines
lib/errseq.c new file +3
-0+* We don't care about the outcome of the swap here. If the +* swap doesn't occur, then it has either been updated by a +* writer who is bumping the seq count anyway, or another "bumping the seq count anyway" part is not quite true. Writer may see
ERRSEQ_SEENnot set and so just update the error code and leave seq count as is. But since you compare fullerrseq_tfor equality, this works out as designed...
Yes, I think the code is correct, but the comment is not clear. Maybe "bumping the seq count or resetting the error code, or..."
In any case, I'll clean up the comments for the next respin here.
Quoted 7 lines
Quoted 7 lines
lib/errseq.c new file +7
-0+* reader who is just setting the "seen" flag. Either outcome +* is OK, and we can advance "since" and return an error based +* on what we have. +*/ + new = old |ERRSEQ_SEEN ; +if (new != old) +cmpxchg (eseq, old, new);
Quoted 8 lines
lib/errseq.c line 199
Quoted 6 lines
lib/errseq.c new file +6
-0+ *since = new; + err = -(new &MAX_ERRNO ); + } +return err; +} +EXPORT_SYMBOL (errseq_check_and_advance);Honza
Thanks!
Signature · 1 line
Jeff Layton <[email protected]>
Matthew Wilcox
maintainerRe: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
In reply to Jeff Laytonlib/errseq.c line 9
Quoted 11 lines · Jeff Layton
+++
b/lib/errseq.clib/errseq.c new file +9
-0@@ -0,0 +1,199 @@ +#include <linux/err.h> +#include <linux/bug.h> +#include <linux/atomic.h> +#include <linux/errseq.h> + +/* +* An errseq_t is a way of recording errors in one place, and allowing any +* number of "subscribers" to tell whether it has changed since an arbitrary +* time of their choosing.
You use the word "time" in several places in the documentation, but I think it's clearer to say "sampling point" or "sample", since you're not using jiffies or nanoseconds. For example, I'd phrase this paragraph this way:
* An errseq_t is a way of recording errors in one place, and allowing any
* number of "subscribers" to tell whether it has changed since they last
* sampled it.
lib/errseq.c line 18
Quoted 3 lines
lib/errseq.c new file +3
-0+* The general idea is for consumers to sample an errseq_t value at a +* particular point in time. Later, that value can be used to tell whether any +* new errors have occurred since that time.
* The general idea is for consumers to sample an errseq_t value. That
* value can be used to tell whether any new errors have occurred since
* the last time it was sampled.
lib/errseq.c line 40
Quoted 1 line
lib/errseq.c new file +1
-0+/* The "ones" bit for the counter */
Maybe "The lowest bit of the counter"?
Review line 15
Quoted 2 lines
(quoted diff) +2
-0+/** + * errseq_check - has an error occurred since a particular point in time?
"has an error occurred since the last time it was sampled"
lib/errseq.c line 153
Quoted 3 lines
lib/errseq.c new file +3
-0+/** +* errseq_check_and_advance - check an errseq_t and advance it to the current value +* @eseq: pointer to value being checked reported
"value being checked reported"?
Quoted 19 lines
lib/errseq.c new file +19
-0+int errseq_check_and_advance (errseq_t *eseq,errseq_t *since) +{ +int err =0 ; +errseq_t old, new; + +/* +* Most callers will want to use the inline wrapper to check this, +* so that the common case of no error is handled without needing +* to lock. +*/ + old =READ_ONCE (*eseq); +if (old != *since) { +/* +* Set the flag and try to swap it into place if it has +* changed. +* +* We don't care about the outcome of the swap here. If the +* swap doesn't occur, then it has either been updated by a +* writer who is bumping the seq count anyway, or another
lib/errseq.c line 196
Quoted 10 lines
lib/errseq.c new file +10
-0+* reader who is just setting the "seen" flag. Either outcome +* is OK, and we can advance "since" and return an error based +* on what we have. +*/ + new = old |ERRSEQ_SEEN ; +if (new != old) +cmpxchg (eseq, old, new); + *since = new; + err = -(new &MAX_ERRNO ); + }
I probably need to read through the patchset some more to understand this. Naively, surely "since" should be updated to the current value of 'eseq' if we failed the cmpxchg()?
Re: [PATCH v4 13/27] lib: add errseq_t type and infrastructure for handling it
Quoted 36 lines · Matthew Wilcox
lib/errseq.c line 9
Quoted 11 lines · Jeff Layton
+++
b/lib/errseq.clib/errseq.c new file +9
-0@@ -0,0 +1,199 @@ +#include <linux/err.h> +#include <linux/bug.h> +#include <linux/atomic.h> +#include <linux/errseq.h> + +/* +* An errseq_t is a way of recording errors in one place, and allowing any +* number of "subscribers" to tell whether it has changed since an arbitrary +* time of their choosing. You use the word "time" in several places in the documentation, but I think it's clearer to say "sampling point" or "sample", since you're not using jiffies or nanoseconds. For example, I'd phrase this paragraph this way:
* An
errseq_tis a way of recording errors in one place, and allowing any
* number of "subscribers" to tell whether it has changed since they last
* sampled it.lib/errseq.c line 18
Quoted 3 lines
lib/errseq.c new file +3
-0+* The general idea is for consumers to sample an errseq_t value at a +* particular point in time. Later, that value can be used to tell whether any +* new errors have occurred since that time. * The general idea is for consumers to sample an
errseq_tvalue. That
* value can be used to tell whether any new errors have occurred since
* the last time it was sampled.lib/errseq.c line 40
Quoted 1 line
lib/errseq.c new file +1
-0+/* The "ones" bit for the counter */ Maybe "The lowest bit of the counter"?
Review line 15
Quoted 2 lines
(quoted diff) +2
-0+/** + * errseq_check - has an error occurred since a particular point in time?
Quoted 8 lines
"has an error occurred since the last time it was sampled"
lib/errseq.c line 153
Quoted 3 lines
lib/errseq.c new file +3
-0+/** +* errseq_check_and_advance - check an errseq_t and advance it to the current value +* @eseq: pointer to value being checked reported "value being checked reported"?
Thanks. I'm cleaning up the comments like you suggest.
Quoted 25 lines
Quoted 25 lines
lib/errseq.c new file +25
-0+int errseq_check_and_advance (errseq_t *eseq,errseq_t *since) +{ +int err =0 ; +errseq_t old, new; + +/* +* Most callers will want to use the inline wrapper to check this, +* so that the common case of no error is handled without needing +* to lock. +*/ + old =READ_ONCE (*eseq); +if (old != *since) { +/* +* Set the flag and try to swap it into place if it has +* changed. +* +* We don't care about the outcome of the swap here. If the +* swap doesn't occur, then it has either been updated by a +* writer who is bumping the seq count anyway, or another +* reader who is just setting the "seen" flag. Either outcome +* is OK, and we can advance "since" and return an error based +* on what we have. +*/ + new = old |ERRSEQ_SEEN ; +if (new != old)
Quoted 8 lines
lib/errseq.c line 196
Quoted 4 lines
lib/errseq.c new file +4
-0+cmpxchg (eseq, old, new); + *since = new; + err = -(new &MAX_ERRNO ); + }I probably need to read through the patchset some more to understand this. Naively, surely "since" should be updated to the current value of 'eseq' if we failed the
cmpxchg()?
I don't think so. If we want to do that, then we'll need to redrive the cmpxchg to set the SEEN flag if it's now clear. Storing the value in "since" is effectively sampling it, so you do have to mark it seen.
The good news is that I think that "new" is just as valid a value to store here as *eseq would be. It ends up representing an errseq_t value that never actually got stored in eseq, but that's OK with the way this works.
Signature · 1 line
Jeff Layton <[email protected]>
PATCH v4 14/27 fs: new infrastructure for writeback error handling and reporting
In reply to Jeff LaytonMost filesystems currently use mapping_set_error and filemap_check_errors for setting and reporting/clearing writeback errors at the mapping level. filemap_check_errors is indirectly called from most of the filemap_fdatawait_* functions and from filemap_write_and_wait*. These functions are called from all sorts of contexts to wait on writeback to finish -- e.g. mostly in fsync, but also in truncate calls, getattr, etc.
The non-fsync callers are problematic. We should be reporting writeback errors during fsync, but many places spread over the tree clear out errors before they can be properly reported, or report errors at nonsensical times.
If I get -EIO on a stat() call, there is no reason for me to assume that it is because some previous writeback failed. The fact that it also clears out the error such that a subsequent fsync returns 0 is a bug, and a nasty one since that's potentially silent data corruption.
This patch adds a small bit of new infrastructure for setting and reporting errors during address_space writeback. While the above was my original impetus for adding this, I think it's also the case that current fsync semantics are just problematic for userland. Most applications that call fsync do so to ensure that the data they wrote has hit the backing store.
In the case where there are multiple writers to the file at the same time, this is really hard to determine. The first one to call fsync will see any stored error, and the rest get back 0. The processes with open fds may not be associated with one another in any way. They could even be in different containers, so ensuring coordination between all fsync callers is not really an option.
One way to remedy this would be to track what file descriptor was used to dirty the file, but that's rather cumbersome and would likely be slow. However, there is a simpler way to improve the semantics here without incurring too much overhead.
This set adds an errseq_t to struct address_space, and a corresponding one is added to struct file. Writeback errors are recorded in the mapping's errseq_t, and the one in struct file is used as the "since" value.
This changes the semantics of the Linux fsync implementation such that applications can now use it to determine whether there were any writeback errors since fsync(fd) was last called (or since the file was opened in the case of fsync having never been called).
Note that those writeback errors may have occurred when writing data that was dirtied via an entirely different fd, but that's the case now with the current mapping_set_error/filemap_check_error infrastructure. This will at least prevent you from getting a false report of success.
The new behavior is still consistent with the POSIX spec, and is more reliable for application developers. This patch just adds some basic infrastructure for doing this. Later patches will change the existing code to use this new infrastructure.
--- Documentation/filesystems/vfs.txt | 10 +++++++++- drivers/dax/dax.c | 1 + fs/block_dev.c | 1 + fs/file_table.c | 1 + fs/open.c | 3 +++ include/linux/fs.h | 24 ++++++++++++++++++++++++ mm/filemap.c | 38 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 1 deletion(-)
Documentation/filesystems/vfs.txt +9 -1
@@ -576,6 +576,11 @@ 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 error (typically using filemap_set_wb_error), in order to +ensure that the error can later be reported to the application when an +fsync is issued. + Writeback makes use of a writeback_control structure... struct address_space_operations
@@ -888,7 +893,10 @@ otherwise noted. release: called when the last reference to an open file is closed - fsync: called by the fsync(2) system call + fsync: called by the fsync(2) system call. Filesystems that use the + pagecache should call filemap_report_wb_error before returning + to ensure that any errors that occurred during writeback are + reported and the file's error sequence advanced. fasync: called by the fcntl(2) system call when asynchronous (non-blocking) mode is enabled for a file
drivers/dax/dax.c +1 -0
@@ -668,6 +668,7 @@ static int dax_open(struct inode *inode, struct file *filp) inode->i_mapping = dax_dev->inode->i_mapping; inode->i_mapping->host = dax_dev->inode; filp->f_mapping = inode->i_mapping; + filp->f_wb_err =filemap_sample_wb_error (filp->f_mapping); filp->private_data = dax_dev; inode->i_flags =S_DAX ;
fs/block_dev.c +1 -0
@@ -1857,6 +1857,7 @@ static int blkdev_open(struct inode * inode, struct file * filp)return -ENOMEM ; filp->f_mapping = bdev->bd_inode->i_mapping; + filp->f_wb_err =filemap_sample_wb_error (filp->f_mapping);return blkdev_get (bdev, filp->f_mode, filp); }
fs/file_table.c +1 -0
@@ -168,6 +168,7 @@ struct file *alloc_file(const struct path *path, fmode_t mode, file->f_path = *path; file->f_inode = path->dentry->d_inode; file->f_mapping = path->dentry->d_inode->i_mapping; + file->f_wb_err =filemap_sample_wb_error (file->f_mapping);if ((mode &FMODE_READ ) &&likely (fop->read || fop->read_iter)) mode |=FMODE_CAN_READ ;
fs/open.c +3 -0
@@ -709,6 +709,9 @@ static int do_dentry_open(struct file *f, f->f_inode = inode; f->f_mapping = inode->i_mapping; +/* Ensure that we skip any errors that predate opening of the file */ + f->f_wb_err =filemap_sample_wb_error (f->f_mapping); +if (unlikely (f->f_flags &O_PATH )) { f->f_mode =FMODE_PATH ; f->f_op = &empty_fops;
include/linux/fs.h +24 -0
@@ -31,6 +31,7 @@#include <linux/workqueue.h> #include <linux/percpu-rwsem.h> #include <linux/delayed_call.h> +#include <linux/errseq.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h>
@@ -394,6 +395,7 @@ struct address_space {gfp_t gfp_mask;/* implicit gfp mask for allocations */ struct list_head private_list;/* ditto */ void *private_data;/* ditto */ +errseq_t wb_err; } __attribute__((aligned(sizeof(long))));/* * On most architectures that alignment is already the case; but
@@ -846,6 +848,7 @@ struct file {* Must not be taken from IRQ context. */ spinlock_t f_lock; +errseq_t f_wb_err;atomic_long_t f_count;unsigned int f_flags;fmode_t f_mode;
@@ -2519,6 +2522,27 @@ extern int __filemap_fdatawrite_range(struct address_space *mapping,extern int filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end);extern int filemap_check_errors (struct address_space *mapping); +extern int __must_check filemap_report_wb_error (struct file *file); + +/** +* filemap_check_wb_error - has an error occurred since the mark was sampled? +* @mapping: mapping to check for writeback errors +* @since: previously-sampled errseq_t +* +* Grab the errseq_t value from the mapping, and see if it has changed "since" +* the given value was sampled. +* +* If it has then report the latest error set, otherwise return 0. +*/ +static inline int filemap_check_wb_error (struct address_space *mapping,errseq_t since) +{ +return errseq_check (&mapping->wb_err, since); +} + +static inline errseq_t filemap_sample_wb_error (struct address_space *mapping) +{ +return errseq_sample (&mapping->wb_err); +}extern int vfs_fsync_range (struct file *file,loff_t start,loff_t end,int datasync);
mm/filemap.c +38 -0
@@ -546,6 +546,44 @@ int filemap_write_and_wait_range(struct address_space *mapping,EXPORT_SYMBOL (filemap_write_and_wait_range);/** +* filemap_report_wb_error - report wb error (if any) that was previously set +* @file: struct file on which the error is being reported +* +* When userland calls fsync (or something like nfsd does the equivalent), we +* want to report any writeback errors that occurred since the last fsync (or +* since the file was opened if there haven't been any). +* +* Grab the wb_err from the mapping. If it matches what we have in the file, +* then just quickly return 0. The file is all caught up. +* +* If it doesn't match, then take the mapping value, set the "seen" flag in +* it and try to swap it into place. If it works, or another task beat us +* to it with the new value, then update the f_wb_err and return the error +* portion. The error at this point must be reported via proper channels +* (a'la fsync, or NFS COMMIT operation, etc.). +* +* While we handle mapping->wb_err with atomic operations, the f_wb_err +* value is protected by the f_lock since we must ensure that it reflects +* the latest value swapped in for this file descriptor. +*/ +int filemap_report_wb_error (struct file *file) +{ +int err =0 ; +struct address_space *mapping = file->f_mapping; + +/* Locklessly handle the common case where nothing has changed */ +if (errseq_check (&mapping->wb_err,READ_ONCE (file->f_wb_err))) { +/* Something changed, must use slow path */ +spin_lock (&file->f_lock); + err =errseq_check_and_advance (&mapping->wb_err, + &file->f_wb_err); +spin_unlock (&file->f_lock); + } +return err; +} +EXPORT_SYMBOL (filemap_report_wb_error); + +/** * replace_page_cache_page - replace a pagecache page with a new one * @old: page to be replaced * @new: page to replace with
Signature · 1 line
2.9.3
Re: [PATCH v4 14/27] fs: new infrastructure for writeback error handling and reporting
Quoted 52 lines · Jeff Layton
Most filesystems currently use
mapping_set_errorandfilemap_check_errorsfor setting and reporting/clearing writeback errors at the mapping level.filemap_check_errorsis indirectly called from most of the filemap_fdatawait_* functions and from filemap_write_and_wait*. These functions are called from all sorts of contexts to wait on writeback to finish -- e.g. mostly in fsync, but also in truncate calls, getattr, etc.The non-fsync callers are problematic. We should be reporting writeback errors during fsync, but many places spread over the tree clear out errors before they can be properly reported, or report errors at nonsensical times.
If I get
-EIOon astat()call, there is no reason for me to assume that it is because some previous writeback failed. The fact that it also clears out the error such that a subsequent fsync returns 0 is a bug, and a nasty one since that's potentially silent data corruption.This patch adds a small bit of new infrastructure for setting and reporting errors during
address_spacewriteback. While the above was my original impetus for adding this, I think it's also the case that current fsync semantics are just problematic for userland. Most applications that call fsync do so to ensure that the data they wrote has hit the backing store.In the case where there are multiple writers to the file at the same time, this is really hard to determine. The first one to call fsync will see any stored error, and the rest get back 0. The processes with open fds may not be associated with one another in any way. They could even be in different containers, so ensuring coordination between all fsync callers is not really an option.
One way to remedy this would be to track what file descriptor was used to dirty the file, but that's rather cumbersome and would likely be slow. However, there is a simpler way to improve the semantics here without incurring too much overhead.
This set adds an
errseq_tto structaddress_space, and a corresponding one is added to struct file. Writeback errors are recorded in the mapping'serrseq_t, and the one in struct file is used as the "since" value.This changes the semantics of the Linux fsync implementation such that applications can now use it to determine whether there were any writeback errors since fsync(fd) was last called (or since the file was opened in the case of fsync having never been called).
Note that those writeback errors may have occurred when writing data that was dirtied via an entirely different fd, but that's the case now with the current mapping_set_error/filemap_check_error infrastructure. This will at least prevent you from getting a false report of success.
Quoted 6 lines
The new behavior is still consistent with the POSIX spec, and is more reliable for application developers. This patch just adds some basic infrastructure for doing this. Later patches will change the existing code to use this new infrastructure.
Signed-off-by Jeff Layton <[email protected]>
Just one nit below. Otherwise the patch looks good to me. You can add:
fs/file_table.c struct file *alloc_file(const struct path *path, fmode_t mode, · line 171
Quoted 9 lines
fs/file_table.c +1
-0@@ -168,6 +168,7 @@ struct file *alloc_file(const struct path *path, fmode_t mode, file->f_path = *path; file->f_inode = path->dentry->d_inode; file->f_mapping = path->dentry->d_inode->i_mapping; + file->f_wb_err =filemap_sample_wb_error (file->f_mapping);
Why do you sample here when you also sample in do_dentry_open()? I didn't find any alloc_file() callers that would possibly care about writeback errors...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 14/27] fs: new infrastructure for writeback error handling and reporting
Quoted 78 lines · Jan Kara
Quoted 52 lines · Jeff Layton
Most filesystems currently use
mapping_set_errorandfilemap_check_errorsfor setting and reporting/clearing writeback errors at the mapping level.filemap_check_errorsis indirectly called from most of the filemap_fdatawait_* functions and from filemap_write_and_wait*. These functions are called from all sorts of contexts to wait on writeback to finish -- e.g. mostly in fsync, but also in truncate calls, getattr, etc.The non-fsync callers are problematic. We should be reporting writeback errors during fsync, but many places spread over the tree clear out errors before they can be properly reported, or report errors at nonsensical times.
If I get
-EIOon astat()call, there is no reason for me to assume that it is because some previous writeback failed. The fact that it also clears out the error such that a subsequent fsync returns 0 is a bug, and a nasty one since that's potentially silent data corruption.This patch adds a small bit of new infrastructure for setting and reporting errors during
address_spacewriteback. While the above was my original impetus for adding this, I think it's also the case that current fsync semantics are just problematic for userland. Most applications that call fsync do so to ensure that the data they wrote has hit the backing store.In the case where there are multiple writers to the file at the same time, this is really hard to determine. The first one to call fsync will see any stored error, and the rest get back 0. The processes with open fds may not be associated with one another in any way. They could even be in different containers, so ensuring coordination between all fsync callers is not really an option.
One way to remedy this would be to track what file descriptor was used to dirty the file, but that's rather cumbersome and would likely be slow. However, there is a simpler way to improve the semantics here without incurring too much overhead.
This set adds an
errseq_tto structaddress_space, and a corresponding one is added to struct file. Writeback errors are recorded in the mapping'serrseq_t, and the one in struct file is used as the "since" value.This changes the semantics of the Linux fsync implementation such that applications can now use it to determine whether there were any writeback errors since fsync(fd) was last called (or since the file was opened in the case of fsync having never been called).
Note that those writeback errors may have occurred when writing data that was dirtied via an entirely different fd, but that's the case now with the current mapping_set_error/filemap_check_error infrastructure. This will at least prevent you from getting a false report of success.
Quoted 6 lines
The new behavior is still consistent with the POSIX spec, and is more reliable for application developers. This patch just adds some basic infrastructure for doing this. Later patches will change the existing code to use this new infrastructure.
Signed-off-by Jeff Layton <[email protected]>Just one nit below. Otherwise the patch looks good to me. You can add:
Reviewed-by Jan Kara <[email protected]>fs/file_table.c struct file *alloc_file(const struct path *path, fmode_t mode, · line 171
Quoted 9 lines
fs/file_table.c +1
-0@@ -168,6 +168,7 @@ struct file *alloc_file(const struct path *path, fmode_t mode, file->f_path = *path; file->f_inode = path->dentry->d_inode; file->f_mapping = path->dentry->d_inode->i_mapping; + file->f_wb_err =filemap_sample_wb_error (file->f_mapping);Why do you sample here when you also sample in
do_dentry_open()? I didn't find anyalloc_file()callers that would possibly care about writeback errors...
Quoted 1 line
Honza
I basically used the setting of f_mapping as a guideline as to where to sample it for initialization. My thinking was that if f_mapping ever ended up different then you'd probably also want f_wb_err to be resampled anyway.
I can drop this hunk if you think we don't need it.
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
maintainerRe: [PATCH v4 14/27] fs: new infrastructure for writeback error handling and reporting
Quoted 16 lines · Jeff Layton
Quoted 15 lines · Jan Kara
fs/file_table.c struct file *alloc_file(const struct path *path, fmode_t mode, · line 171
Quoted 9 lines · Jeff Layton
fs/file_table.c +1
-0@@ -168,6 +168,7 @@ struct file *alloc_file(const struct path *path, fmode_t mode, file->f_path = *path; file->f_inode = path->dentry->d_inode; file->f_mapping = path->dentry->d_inode->i_mapping; + file->f_wb_err =filemap_sample_wb_error (file->f_mapping);Why do you sample here when you also sample in
do_dentry_open()? I didn't find anyalloc_file()callers that would possibly care about writeback errors...
Quoted 6 lines
Quoted 1 line
Honza
I basically used the setting of
f_mappingas a guideline as to where to sample it for initialization. My thinking was that iff_mappingever ended up different then you'd probably also wantf_wb_errto be resampled anyway.
OK, makes sense.
Quoted 1 line
I can drop this hunk if you think we don't need it.
I don't really care. I was just wondering whether I'm missing something...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 15/27 fs: retrofit old error reporting API onto new infrastructure
In reply to Jeff LaytonNow that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping, filemap_set_wb_error is a drop-in replacement for mapping_set_error. Turn that function into a simple wrapper around the new one.
Because we want to ensure that writeback errors are always reported at fsync time, inject filemap_report_wb_error calls much closer to the syscall boundary, in call_fsync.
For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by filemap_report_wb_error. In both cases, we advance the file->f_wb_err to the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.
The final piece of the puzzle is what to do about filemap_check_errors calls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".
Since we now handle advancing the file->f_wb_err value at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance an errseq_t.
A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled errseq_t value).
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current mapping->wb_err value, and use that as an arbitrary point from which to check for errors.
That's probably not "correct" in all cases, particularly in the case of something like filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.
A lot of those callers will likely want to change to a model where they sample the errseq_t much earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.
That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
--- Documentation/filesystems/vfs.txt | 9 +++---- fs/btrfs/file.c | 10 ++------ fs/btrfs/tree-log.c | 9 ++----- fs/f2fs/file.c | 3 +++ fs/f2fs/node.c | 6 +---- fs/fuse/file.c | 7 ++++-- fs/libfs.c | 6 +++-- include/linux/fs.h | 19 +++++++++------ include/linux/pagemap.h | 8 ++---- mm/filemap.c | 51 +++++++++++++++++---------------------- 10 files changed, 57 insertions(+), 71 deletions(-)
Documentation/filesystems/vfs.txt +4 -5
@@ -577,7 +577,7 @@ 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 error (typically using filemap_set_wb_error), in order to +marked with an error (typically using mapping_set_error), in order to ensure that the error can later be reported to the application when an fsync is issued.
@@ -893,10 +893,9 @@ otherwise noted. release: called when the last reference to an open file is closed - fsync: called by the fsync(2) system call. Filesystems that use the - pagecache should call filemap_report_wb_error before returning - to ensure that any errors that occurred during writeback are - reported and the file's error sequence advanced. + fsync: called by the fsync(2) system call. Errors that were previously + recorded using mapping_set_error will automatically be returned to + the application and the file's error sequence advanced. fasync: called by the fcntl(2) system call when asynchronous (non-blocking) mode is enabled for a file
fs/btrfs/file.c +2 -8
@@ -1962,6 +1962,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)int ret =0 ;bool full_sync =0 ;u64 len; +errseq_t wb_since =READ_ONCE (file->f_wb_err);/* * The range length can be represented by u64, we have to do the typecasts
@@ -2079,14 +2080,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)*/ clear_bit (BTRFS_INODE_NEEDS_FULL_SYNC , &BTRFS_I (inode)->runtime_flags); -/* -* An ordered extent might have started before and completed -* already with io errors, in which case the inode was not -* updated and we end up here. So check the inode's mapping -* flags for any errors that might have happened while doing -* writeback of file data. -*/ - ret =filemap_check_errors (inode->i_mapping); + ret =filemap_check_wb_error (inode->i_mapping, wb_since);inode_unlock (inode); goto out; }
fs/btrfs/tree-log.c +2 -7
@@ -3972,12 +3972,6 @@ static int wait_ordered_extents(struct btrfs_trans_handle *trans, test_bit(BTRFS_ORDERED_IOERR, &ordered->flags)));if (test_bit (BTRFS_ORDERED_IOERR , &ordered->flags)) { -/* -* Clear the AS_EIO/AS_ENOSPC flags from the inode's -* i_mapping flags, so that the next fsync won't get -* an outdated io error too. -*/ -filemap_check_errors (inode->i_mapping); *ordered_io_error = true;break ; }
@@ -4171,6 +4165,7 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,u64 test_gen;int ret =0 ;int num =0 ; +errseq_t since =filemap_sample_wb_error (inode->vfs_inode.i_mapping);INIT_LIST_HEAD (&extents);
@@ -4214,7 +4209,7 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,* without writing to the log tree and the fsync must report the * file data write error and not commit the current transaction. */ - ret =filemap_check_errors (inode->vfs_inode.i_mapping); + ret =filemap_check_wb_error (inode->vfs_inode.i_mapping, since);if (ret) ctx->io_err = ret; process:
fs/f2fs/file.c +3 -0
@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;
@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;
fs/f2fs/node.c +1 -5
@@ -1630,7 +1630,7 @@ int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino) {pgoff_t index =0 , end =ULONG_MAX ;struct pagevec pvec; -int ret2, ret =0 ; +int ret =0 ;pagevec_init (&pvec,0 );
@@ -1658,10 +1658,6 @@ int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino)pagevec_release (&pvec);cond_resched (); } - - ret2 =filemap_check_errors (NODE_MAPPING (sbi)); -if (!ret) - ret = ret2;return ret; }
fs/fuse/file.c +5 -2
@@ -398,6 +398,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)struct fuse_req *req;struct fuse_flush_in inarg;int err; +errseq_t since =READ_ONCE (file->f_wb_err);if (is_bad_inode (inode))return -EIO ;
@@ -413,7 +414,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)fuse_sync_writes (inode);inode_unlock (inode); - err =filemap_check_errors (file->f_mapping); + err =filemap_check_wb_error (file->f_mapping, since);if (err)return err;
@@ -446,6 +447,7 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,FUSE_ARGS (args);struct fuse_fsync_in inarg;int err; +errseq_t since;if (is_bad_inode (inode))return -EIO ;
@@ -461,6 +463,7 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,if (err) goto out; + since =READ_ONCE (file->f_wb_err);fuse_sync_writes (inode);/*
@@ -468,7 +471,7 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,* filemap_write_and_wait_range() does not catch errors. * We have to do this directly after fuse_sync_writes() */ - err =filemap_check_errors (file->f_mapping); + err =filemap_check_wb_error (file->f_mapping, since);if (err) goto out;
fs/libfs.c +4 -2
@@ -991,8 +991,10 @@ int __generic_file_fsync(struct file *file, loff_t start, loff_t end, out:inode_unlock (inode); - err =filemap_check_errors (inode->i_mapping); -return ret ? ret : err; +if (!ret) + ret =filemap_check_wb_error (inode->i_mapping, +READ_ONCE (file->f_wb_err)); +return ret; }EXPORT_SYMBOL (__generic_file_fsync);
include/linux/fs.h +12 -7
@@ -1739,12 +1739,6 @@ static inline int call_mmap(struct file *file, struct vm_area_struct *vma)return file->f_op->mmap (file, vma); } -static inline int call_fsync (struct file *file,loff_t start,loff_t end, -int datasync) -{ -return file->f_op->fsync (file, start, end, datasync); -} - ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, unsigned long nr_segs, unsigned long fast_segs, struct iovec *fast_pointer,
@@ -2512,6 +2506,8 @@ extern int filemap_fdatawrite(struct address_space *);extern int filemap_flush (struct address_space *);extern int filemap_fdatawait (struct address_space *);extern void filemap_fdatawait_keep_errors (struct address_space *); +extern int filemap_fdatawait_range_since (struct address_space *,loff_t lstart, +loff_t lend,errseq_t since);extern int filemap_fdatawait_range (struct address_space *,loff_t lstart,loff_t lend);extern int filemap_write_and_wait (struct address_space *mapping);
@@ -2521,7 +2517,6 @@ extern int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, loff_t end, int sync_mode);extern int filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end); -extern int filemap_check_errors (struct address_space *mapping);extern int __must_check filemap_report_wb_error (struct file *file);/**
@@ -2544,6 +2539,16 @@ static inline errseq_t filemap_sample_wb_error(struct address_space *mapping)return errseq_sample (&mapping->wb_err); } +static inline int call_fsync (struct file *file,loff_t start,loff_t end, +int datasync) +{ +int ret, ret2; + + ret = file->f_op->fsync (file, start, end, datasync); + ret2 =filemap_report_wb_error (file); +return ret ? ret : ret2; +} +extern int vfs_fsync_range (struct file *file,loff_t start,loff_t end,int datasync);extern int vfs_fsync (struct file *file,int datasync);
include/linux/pagemap.h +2 -6
@@ -14,6 +14,7 @@#include <linux/bitops.h> #include <linux/hardirq.h> /* for in_interrupt() */ #include <linux/hugetlb_inline.h> +#include <linux/errseq.h> /* * Bits in mapping->flags.
@@ -30,12 +31,7 @@ enum mapping_flags {static inline void mapping_set_error (struct address_space *mapping,int error) { -if (unlikely (error)) { -if (error == -ENOSPC ) -set_bit (AS_ENOSPC , &mapping->flags); -else -set_bit (AS_EIO , &mapping->flags); - } +return errseq_set (&mapping->wb_err, error); }static inline void mapping_set_unevictable (struct address_space *mapping)
mm/filemap.c +22 -29
112 lines not on this page · raw message
Signature · 1 line
2.9.3
Jan Kara
maintainerRe: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).
Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.
I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them to fdatawait_range_since()?
Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>
...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;
fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;
So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping and NODE_MAPPING(sbi) which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 44 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.
Quoted 7 lines
I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?
Yes that is a danger.
In fact, late last week I was finally able to make my xfstest work with btrfs, and started hitting oopses with it because of the way the error reporting changed. I rolled up a patch to fix that (and it simplifies the code some, IMO), but other callers of filemap_fdatawait may have similar problems here.
I'll pick up working on this again in a more piecemeal way. I had originally looked at doing that, but there are some problematic places (e.g. buffer.c), where the code is shared by a bunch of different filesystems that makes it difficult.
We may end up needing some sort of FS_WB_ERRSEQ flag to do this correctly, at least until the transition to errseq_t is done.
Quoted 33 lines
Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 15 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, }
Quoted 17 lines
fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 5 lines
fs/f2fs/file.c +2
-0ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...
Got it -- since there are two mappings, there are two errseq_t's and you'd need a since cursor for each. I don't really like having to add a second 32-bit word to struct file, but I also don't see a real alternative right offhand. May be able to stash it in file->private_data for some of these filesystems.
In any case, I'll ponder how to do this in a more piecemeal way.
Thanks for all of the review so far!
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
In reply to Jan KaraQuoted 101 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...
Quoted 1 line
Honza
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Then we could just have write_inode operations call mapping_set_error on inode->i_mapping when they're going to return an error. That should be functionally equivalent, I'd think.
The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
maintainerRe: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 108 lines · Jeff Layton
Quoted 101 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...Quoted 1 line
Honza
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Quoted 7 lines
Then we could just have
write_inodeoperations callmapping_set_erroroninode->i_mappingwhen they're going to return an error. That should be functionally equivalent, I'd think.The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
So for ext2 / ext4 in nojournal mode this should work - we track all relevant metadata in mapping->private_list. But I cannot really comment on other filesystems like f2fs...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 113 lines · Jan Kara
Quoted 112 lines · Jeff Layton
Quoted 101 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...Quoted 1 line
Honza
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Then we could just have
write_inodeoperations callmapping_set_erroroninode->i_mappingwhen they're going to return an error. That should be functionally equivalent, I'd think.
Quoted 8 lines
Quoted 3 lines
The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
So for ext2 / ext4 in nojournal mode this should work - we track all relevant metadata in
mapping->private_list. But I cannot really comment on other filesystems like f2fs...
Actually, I think that may be problematic...
We could end up calling ext2_write_inode with sync_mode != WB_SYNC_ALL, which just dirties the buffer without starting writeback. Then, have VM subsystem write back the buffer due to memory pressure and have that fail. Trying to set the error in write_inode would miss that situation.
I think we'll have to track two errseq_t's for those filesystems, like you had originally suggested. The main question is where to put the second errseq_t
For ext2, I stored it in file->private_data pointer since it wasn't being used. For those filesystems that are already using private_data, I'll just plan to add a field to whatever structure they're using.
(Maybe I could make private_data a union with an errseq_t for those that don't use that field? That might be cleaner than the casting I'm doing now)
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
maintainerRe: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 123 lines · Jeff Layton
Quoted 113 lines · Jan Kara
Quoted 112 lines · Jeff Layton
Quoted 101 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...Quoted 1 line
Honza
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Then we could just have
write_inodeoperations callmapping_set_erroroninode->i_mappingwhen they're going to return an error. That should be functionally equivalent, I'd think.Quoted 8 lines
Quoted 3 lines
The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
So for ext2 / ext4 in nojournal mode this should work - we track all relevant metadata in
mapping->private_list. But I cannot really comment on other filesystems like f2fs...
Quoted 6 lines
Actually, I think that may be problematic...
We could end up calling
ext2_write_inodewithsync_mode!=WB_SYNC_ALL, which just dirties the buffer without starting writeback. Then, have VM subsystem write back the buffer due to memory pressure and have that fail. Trying to set the error inwrite_inodewould miss that situation.
Two notes here:
1) Inode is a bad example because there isn't 1:1 mapping between buffers containing inodes and mappings - one buffer contains several inodes. I wanted to add that for inodes specifically it does not matter as they get special handling but actually fsync seems to be currently unreliable for them - if we first wrote them in WB_SYNC_NONE mode, they will be just written in bdev's page cache, but following fsync(2) will do nothing as they will be clean. Anyway, this is unrelated problem.
2) For metadata like indirect blocks where you indeed have 1:1 mapping, you can do the error setting in ->end_io handler based on bh->b_assoc_map and that should do what you need, shouldn't it?
If I'm indeed right, then for buffers which have 1:1 mapping we are fine and if we find a solution for inodes, we could avoid the second errseq_t.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 133 lines · Jan Kara
Quoted 123 lines · Jeff Layton
Quoted 113 lines · Jan Kara
Quoted 112 lines · Jeff Layton
Quoted 101 lines · Jan Kara
Quoted 39 lines · Jeff Layton
Now that we have a better way to store and report errors that occur during writeback, we need to convert the existing codebase to use it. We could just adapt all of the filesystem code and related infrastructure to the new API, but that's a lot of churn.
When it comes to setting errors in the mapping,
filemap_set_wb_erroris a drop-in replacement formapping_set_error. Turn that function into a simple wrapper around the new one.Because we want to ensure that writeback errors are always reported at fsync time, inject
filemap_report_wb_errorcalls much closer to the syscall boundary, incall_fsync.For fsync calls (and things like the nfsd equivalent), we either return the error that the fsync operation returns, or the one returned by
filemap_report_wb_error. In both cases, we advance thefile->f_wb_errto the latest value. This allows us to provide new fsync semantics that will return errors that may have occurred previously and been viewed via other file descriptors.The final piece of the puzzle is what to do about
filemap_check_errorscalls that are being called directly or via filemap_* functions. Here, we must take a little "creative license".Since we now handle advancing the
file->f_wb_errvalue at the generic filesystem layer, we no longer need those callers to clear errors out of the mapping or advance anerrseq_t.A lot of the existing codebase relies on being getting an error back from those functions when there is a writeback problem, so we do still want to have them report writeback errors somehow.
When reporting writeback errors, we will always report errors that have occurred since a particular point in time. With the old writeback error reporting, the time we used was "since it was last tested/cleared" which is entirely arbitrary and potentially racy. Now, we can at least report the latest error that has occurred since an arbitrary point in time (represented as a sampled
errseq_tvalue).Quoted 3 lines
In the case where we don't have a struct file to work with, this patch just has the wrappers sample the current
mapping->wb_errvalue, and use that as an arbitrary point from which to check for errors.I think this is really dangerous and we shouldn't do this. You are quite likely to lose IO errors in such calls because you will ignore all errors that happened during previous background writeback or even for IO that managed to complete before we called
filemap_fdatawait(). Maybe we need to keep the original set-clear-bit IO error reporting for these cases, until we can convert them tofdatawait_range_since()?Quoted 15 lines
That's probably not "correct" in all cases, particularly in the case of something like
filemap_fdatawait, but I'm not sure it's any worse than what we already have, and this gives us a basis from which to work.A lot of those callers will likely want to change to a model where they sample the
errseq_tmuch earlier (perhaps when starting a transaction), store it in an appropriate place and then use that value later when checking to see if an error occurred.That will almost certainly take some involvement from other subsystem maintainers. I'm quite open to adding new API functions to help enable this if that would be helpful, but I don't really want to do that until I better understand what's needed.
Signed-off-by Jeff Layton <[email protected]>...
Quoted 13 lines
fs/f2fs/file.c +1
-0@@ -187,6 +187,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, .nr_to_write = LONG_MAX, .for_reclaim = 0, }; +errseq_t since =READ_ONCE (file->f_wb_err);if (unlikely (f2fs_readonly (inode->i_sb)))return 0 ;fs/f2fs/file.c static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, · line 272
Quoted 7 lines
fs/f2fs/file.c +2
-0@@ -265,6 +266,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, } ret =wait_on_node_pages_writeback (sbi, ino); +if (ret ==0 ) + ret =filemap_check_wb_error (NODE_MAPPING (sbi), since);if (ret) goto out;So this conversion looks wrong and actually points to a larger issue with the scheme. The problem is there are two mappings that come into play here
- file_inode(file)->i_mapping which is the data mapping andNODE_MAPPING(sbi)which is the metadata mapping (and this is not a problem specific to f2fs. For example ext2 also uses this scheme where block devices' mapping is the metadata mapping). And we need to merge error information from these two mappings so for the stamping scheme to work, we'd need two stamps stored in struct file. One for data mapping and one for metadata mapping. Or maybe there's some more clever scheme but for now I don't see one...Quoted 1 line
Honza
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Then we could just have
write_inodeoperations callmapping_set_erroroninode->i_mappingwhen they're going to return an error. That should be functionally equivalent, I'd think.Quoted 8 lines
Quoted 3 lines
The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
So for ext2 / ext4 in nojournal mode this should work - we track all relevant metadata in
mapping->private_list. But I cannot really comment on other filesystems like f2fs...Quoted 6 lines
Actually, I think that may be problematic...
We could end up calling
ext2_write_inodewithsync_mode!=WB_SYNC_ALL, which just dirties the buffer without starting writeback. Then, have VM subsystem write back the buffer due to memory pressure and have that fail. Trying to set the error inwrite_inodewould miss that situation.Two notes here:
Quoted 8 lines
1) Inode is a bad example because there isn't 1:1 mapping between buffers containing inodes and mappings - one buffer contains several inodes. I wanted to add that for inodes specifically it does not matter as they get special handling but actually fsync seems to be currently unreliable for them - if we first wrote them in
WB_SYNC_NONEmode, they will be just written in bdev's page cache, but following fsync(2) will do nothing as they will be clean. Anyway, this is unrelated problem.
Yes, that's what I was trying to articulate above. I'm not sure it's unrelated though. Moving to errseq_t based handling there based on the blockdev mapping seems like it'd solve that. That does require an extra errseq_t though.
(I assume that on ext2 inode writeback, bh->b_page->mapping->host points to the bdev inode?)
Quoted 4 lines
2) For metadata like indirect blocks where you indeed have 1:1 mapping, you can do the error setting in ->end_io handler based on
bh->b_assoc_mapand that should do what you need, shouldn't it?
That would probably work, and I think the mark_buffer_write_io_error function that I was adding should already be doing the right thing there.
Quoted 3 lines
If I'm indeed right, then for buffers which have 1:1 mapping we are fine and if we find a solution for inodes, we could avoid the second
errseq_t.
Yeah, I'm just still not seeing a good way to track error in inode metadata writeback without an extra errseq_t though. I don't suppose that a buffer holding inode metadata has a list of those inodes, does it? Then we could walk the list and flag each one with the error. Without something like that, I think we're stuck with an extra errseq_t.
BTW, thanks for the help so far. I haven't spent much time in local fs metadata handling up until now, so this has been very helpful.
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
maintainerRe: [PATCH v4 15/27] fs: retrofit old error reporting API onto new infrastructure
Quoted 38 lines · Jeff Layton
Quoted 28 lines · Jan Kara
Quoted 18 lines · Jeff Layton
Quoted 8 lines · Jan Kara
Quoted 8 lines
In the case of something like ext2, could we instead get away with just marking the data mapping of the inode with an error if the metadata writeout fails?
Then we could just have
write_inodeoperations callmapping_set_erroroninode->i_mappingwhen they're going to return an error. That should be functionally equivalent, I'd think.Quoted 8 lines
Quoted 3 lines
The catch there is that that requires a 1:1 data:metadata mapping, and I'm not sure that that is the case (or will always be, even if it is now).
So for ext2 / ext4 in nojournal mode this should work - we track all relevant metadata in
mapping->private_list. But I cannot really comment on other filesystems like f2fs...Quoted 6 lines
Actually, I think that may be problematic...
We could end up calling
ext2_write_inodewithsync_mode!=WB_SYNC_ALL, which just dirties the buffer without starting writeback. Then, have VM subsystem write back the buffer due to memory pressure and have that fail. Trying to set the error inwrite_inodewould miss that situation.Two notes here:
Quoted 8 lines
1) Inode is a bad example because there isn't 1:1 mapping between buffers containing inodes and mappings - one buffer contains several inodes. I wanted to add that for inodes specifically it does not matter as they get special handling but actually fsync seems to be currently unreliable for them - if we first wrote them in
WB_SYNC_NONEmode, they will be just written in bdev's page cache, but following fsync(2) will do nothing as they will be clean. Anyway, this is unrelated problem.
Quoted 4 lines
Yes, that's what I was trying to articulate above. I'm not sure it's unrelated though. Moving to
errseq_tbased handling there based on the blockdev mapping seems like it'd solve that.�That does require an extraerrseq_tthough.
Well, it might help solving the error handling case but it doesn't solve the fundamental problem that the inode buffer even doesn't have to be written to disk by the time fsync(2) returns.
Quoted 2 lines
(I assume that on ext2 inode writeback,
bh->b_page->mapping->hostpoints to the bdev inode?)
Yes, it does.
Quoted 8 lines
Quoted 4 lines
2) For metadata like indirect blocks where you indeed have 1:1 mapping, you can do the error setting in ->end_io handler based on
bh->b_assoc_mapand that should do what you need, shouldn't it?That would probably work, and I think the
mark_buffer_write_io_errorfunction that I was adding should already be doing the right thing there.
Agreed.
Quoted 8 lines
Quoted 2 lines
If I'm indeed right, then for buffers which have 1:1 mapping we are fine and if we find a solution for inodes, we could avoid the second
errseq_t.Yeah, I'm just still not seeing a good way to track error in inode metadata writeback without an extra
errseq_tthough. I don't suppose that a buffer holding inode metadata has a list of those inodes, does it? Then we could walk the list and flag each one with the error. Without something like that, I think we're stuck with an extraerrseq_t.
No, the buffer doesn't have a list of associated inodes. For ext2/4 it is doable to actually track down all the inodes but I don't think we want to complicate this series by implementing such mechanism for each filesystem that needs this. So let's start with a generic solution that uses second errseq_t for the metadata mapping. It is somewhat rough (error in writeback of any metadata block will fail fsync(2) for all open files) but we can later improve on this for each fs which cares enough about better error reporting.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 16/27 fs: adapt sync_file_range to new reporting infrastructure
In reply to Jeff LaytonSince it returns errors in a way similar to fsync, have it use the same method for returning previously-reported writeback errors.
--- fs/sync.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/sync.c +9 -4
@@ -271,8 +271,11 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd)* * * SYNC_FILE_RANGE_WAIT_BEFORE and SYNC_FILE_RANGE_WAIT_AFTER will detect any -* I/O errors or ENOSPC conditions and will return those to the caller, after -* clearing the EIO and ENOSPC flags in the address_space. +* error condition that occurred prior to or after writeback, and will return +* that to the caller, while advancing the file's errseq_t cursor. Note that +* any errors returned here may have occurred in an area of the file that is +* not covered by the given range as most filesystems track writeback errors +* on a per-address_space basis * * It should be noted that none of these operations write out the file's * metadata. So unless the application is strictly performing overwrites of
@@ -282,7 +285,7 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd)SYSCALL_DEFINE4 (sync_file_range, int, fd, loff_t, offset, loff_t, nbytes, unsigned int, flags) { -int ret; +int ret, ret2;struct fd f;struct address_space *mapping;loff_t endbyte;/* inclusive */
@@ -356,7 +359,9 @@ SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,if (flags &SYNC_FILE_RANGE_WAIT_AFTER ) ret =filemap_fdatawait_range (mapping, offset, endbyte); - + ret2 =filemap_report_wb_error (f.file); +if (!ret) + ret = ret2; out_put:fdput (f); out:
Signature · 1 line
2.9.3
PATCH v4 17/27 mm: remove AS_EIO and AS_ENOSPC flags
In reply to Jeff LaytonThey're no longer used.
--- include/linux/pagemap.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
include/linux/pagemap.h +4 -6
@@ -20,13 +20,11 @@* Bits in mapping->flags. */ enum mapping_flags { -AS_EIO =0 ,/* IO error on async write */ -AS_ENOSPC =1 ,/* ENOSPC on async write */ -AS_MM_ALL_LOCKS =2 ,/* under mm_take_all_locks() */ -AS_UNEVICTABLE =3 ,/* e.g., ramdisk, SHM_LOCK */ -AS_EXITING =4 ,/* final truncate in progress */ +AS_MM_ALL_LOCKS =0 ,/* under mm_take_all_locks() */ +AS_UNEVICTABLE =1 ,/* e.g., ramdisk, SHM_LOCK */ +AS_EXITING =2 ,/* final truncate in progress */ /* writeback related tags are not used */ -AS_NO_WRITEBACK_TAGS =5 , +AS_NO_WRITEBACK_TAGS =3 , };static inline void mapping_set_error (struct address_space *mapping,int error)
Signature · 1 line
2.9.3
PATCH v4 18/27 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, and be returned at fsync time, even when there is a more appropriate error stored in the mapping.
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 that is silently discarded. Any subsystem that is relying on PG_error to report errors during fsync can easily lose writeback errors due to this. All you need is a stray sync() call to wait for writeback to complete 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
@@ -363,17 +363,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) &&
@@ -390,14 +389,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; }/**
@@ -414,14 +410,8 @@ static int __filemap_fdatawait_range(struct address_space *mapping,int filemap_fdatawait_range_since (struct address_space *mapping,loff_t start_byte,loff_t end_byte,errseq_t since) { -int ret, ret2; - - ret =__filemap_fdatawait_range (mapping, start_byte, end_byte); - ret2 =filemap_check_wb_error (mapping, since); -if (!ret) - ret = ret2; - -return ret; +__filemap_fdatawait_range (mapping, start_byte, end_byte); +return filemap_check_wb_error (mapping, since); }EXPORT_SYMBOL (filemap_fdatawait_range_since);
Signature · 1 line
2.9.3
PATCH v4 19/27 buffer: set errors in mapping at the time that the error occurs
In reply to Jeff LaytonI noticed on xfs that I could still sometimes get back an error on fsync on a fd that was opened after the error condition had been cleared.
The problem is that the buffer code sets the write_io_error flag and then later checks that flag to set the error in the mapping. That flag perisists for quite a while however. If the file is later opened with O_TRUNC, the buffers will then be invalidated and the mapping's error set such that a subsequent fsync will return error. I think this is incorrect, as there was no writeback between the open and fsync.
Add a new mark_buffer_write_io_error operation that sets the flag and the error in the mapping at the same time. Replace all calls to set_buffer_write_io_error with mark_buffer_write_io_error, and remove the places that check this flag in order to set the error in the mapping.
This sets the error in the mapping earlier, at the time that it's first detected.
--- fs/buffer.c | 19 +++++++++++++------ fs/gfs2/lops.c | 2 +- include/linux/buffer_head.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-)
fs/buffer.c +13 -6
@@ -179,7 +179,7 @@ void end_buffer_write_sync(struct buffer_head *bh, int uptodate)set_buffer_uptodate (bh); }else {buffer_io_error (bh,", lost sync page write" ); -set_buffer_write_io_error (bh); +mark_buffer_write_io_error (bh);clear_buffer_uptodate (bh); }unlock_buffer (bh);
@@ -354,7 +354,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) }else {buffer_io_error (bh,", lost async page write" );mapping_set_error (page->mapping, -EIO ); -set_buffer_write_io_error (bh); +mark_buffer_write_io_error (bh);clear_buffer_uptodate (bh);SetPageError (page); }
@@ -482,8 +482,6 @@ static void __remove_assoc_queue(struct buffer_head *bh) {list_del_init (&bh->b_assoc_buffers);WARN_ON (!bh->b_assoc_map); -if (buffer_write_io_error (bh)) -mapping_set_error (bh->b_assoc_map, -EIO ); bh->b_assoc_map =NULL ; }
@@ -1182,6 +1180,17 @@ void mark_buffer_dirty(struct buffer_head *bh) }EXPORT_SYMBOL (mark_buffer_dirty); +void mark_buffer_write_io_error (struct buffer_head *bh) +{ +set_buffer_write_io_error (bh); +/* FIXME: do we need to set this in both places? */ +if (bh->b_page && bh->b_page->mapping) +mapping_set_error (bh->b_page->mapping, -EIO ); +if (bh->b_assoc_map) +mapping_set_error (bh->b_assoc_map, -EIO ); +} +EXPORT_SYMBOL (mark_buffer_write_io_error); +/* * Decrement a buffer_head's reference count. If all buffers against a page * have zero reference count, are clean and unlocked, and if the page is clean
@@ -3291,8 +3300,6 @@ drop_buffers(struct page *page, struct buffer_head **buffers_to_free) bh = head; do { - if (buffer_write_io_error(bh) && page->mapping) - mapping_set_error(page->mapping, -EIO); if (buffer_busy(bh)) goto failed; bh = bh->b_this_page;
fs/gfs2/lops.c +1 -1
@@ -182,7 +182,7 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct bio_vec *bvec, bh = bh->b_this_page; do { if (error) - set_buffer_write_io_error(bh); + mark_buffer_write_io_error(bh); unlock_buffer(bh); next = bh->b_this_page; size -= bh->b_size;
include/linux/buffer_head.h +1 -0
@@ -149,6 +149,7 @@ void buffer_check_dirty_writeback(struct page *page,*/ void mark_buffer_dirty (struct buffer_head *bh); +void mark_buffer_write_io_error (struct buffer_head *bh);void init_buffer (struct buffer_head *,bh_end_io_t *,void *);void touch_buffer (struct buffer_head *bh); void set_bh_page(struct buffer_head *bh,
Signature · 1 line
2.9.3
Re: [PATCH v4 19/27] buffer: set errors in mapping at the time that the error occurs
Quoted 16 lines · Jeff Layton
I noticed on xfs that I could still sometimes get back an error on fsync on a fd that was opened after the error condition had been cleared.
The problem is that the buffer code sets the
write_io_errorflag and then later checks that flag to set the error in the mapping. That flag perisists for quite a while however. If the file is later opened withO_TRUNC, the buffers will then be invalidated and the mapping's error set such that a subsequent fsync will return error. I think this is incorrect, as there was no writeback between the open and fsync.Add a new
mark_buffer_write_io_erroroperation that sets the flag and the error in the mapping at the same time. Replace all calls toset_buffer_write_io_errorwithmark_buffer_write_io_error, and remove the places that check this flag in order to set the error in the mapping.
Quoted 4 lines
This sets the error in the mapping earlier, at the time that it's first detected.
Signed-off-by Jeff Layton <[email protected]>
Looks good to me. You can add:
Small nits below.
fs/buffer.c void end_buffer_async_write(struct buffer_head *bh, int uptodate) · line 357
Quoted 6 lines
fs/buffer.c +1
-1@@ -354,7 +354,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) }else {buffer_io_error (bh,", lost async page write" );mapping_set_error (page->mapping, -EIO ); -set_buffer_write_io_error (bh); +mark_buffer_write_io_error (bh);
No need to call mapping_set_error() here when it gets called in mark_buffer_write_io_error() again?
Quoted 4 lines
fs/buffer.c +0
-0@@ -1182,6 +1180,17 @@ void mark_buffer_dirty(struct buffer_head *bh) }EXPORT_SYMBOL (mark_buffer_dirty);
fs/buffer.c void mark_buffer_dirty(struct buffer_head *bh) · line 1192
Quoted 10 lines
fs/buffer.c +10
-0+void mark_buffer_write_io_error (struct buffer_head *bh) +{ +set_buffer_write_io_error (bh); +/* FIXME: do we need to set this in both places? */ +if (bh->b_page && bh->b_page->mapping) +mapping_set_error (bh->b_page->mapping, -EIO ); +if (bh->b_assoc_map) +mapping_set_error (bh->b_assoc_map, -EIO ); +} +EXPORT_SYMBOL (mark_buffer_write_io_error);
So buffers that are shared by several inodes cannot have bh->b_assoc_map set. So for filesystems that have metadata like this setting in bh->b_assoc_map doesn't really help and they have to check blockdevice's mapping anyway. OTOH if filesystem doesn't have such type of metadata relevant for fsync, this could help it. So maybe it is worth it.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 20/27 cifs: cleanup writeback handling errors and comments
In reply to Jeff LaytonNow that writeback errors are handled on a per-file basis using the new sequence counter method at the vfs layer, we no longer need to re-set errors in the mapping after doing writeback in non-fsync codepaths.
Also, fix up some bogus comments.
--- fs/cifs/cifsfs.c | 4 +--- fs/cifs/file.c | 7 ++----- fs/cifs/inode.c | 22 +++++++--------------- 3 files changed, 10 insertions(+), 23 deletions(-)
fs/cifs/cifsfs.c +1 -3
@@ -829,10 +829,8 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)if (!CIFS_CACHE_READ (CIFS_I (inode)) && inode->i_mapping && inode->i_mapping->nrpages !=0 ) { rc =filemap_fdatawait (inode->i_mapping); -if (rc) { -mapping_set_error (inode->i_mapping, rc); +if (rc)return rc; - } }/* * Some applications poll for the file length in this strange
fs/cifs/file.c +2 -5
@@ -722,9 +722,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) cinode =CIFS_I (inode);if (can_flush) { - rc =filemap_write_and_wait (inode->i_mapping); -mapping_set_error (inode->i_mapping, rc); - +filemap_write_and_wait (inode->i_mapping);if (tcon->unix_ext) rc =cifs_get_inode_info_unix (&inode, full_path, inode->i_sb, xid);
@@ -3906,8 +3904,7 @@ void cifs_oplock_break(struct work_struct *work)break_lease (inode,O_WRONLY ); rc =filemap_fdatawrite (inode->i_mapping);if (!CIFS_CACHE_READ (cinode)) { - rc =filemap_fdatawait (inode->i_mapping); -mapping_set_error (inode->i_mapping, rc); +filemap_fdatawait (inode->i_mapping);cifs_zap_mapping (inode); }cifs_dbg (FYI ,"Oplock flush inode %p rc %d\n" , inode, rc);
fs/cifs/inode.c +7 -15
@@ -2008,10 +2008,8 @@ int cifs_getattr(const struct path *path, struct kstat *stat,if (!CIFS_CACHE_READ (CIFS_I (inode)) && inode->i_mapping && inode->i_mapping->nrpages !=0 ) { rc =filemap_fdatawait (inode->i_mapping); -if (rc) { -mapping_set_error (inode->i_mapping, rc); +if (rc)return rc; - } } rc =cifs_revalidate_dentry_attr (dentry);
@@ -2171,15 +2169,12 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)* Attempt to flush data before changing attributes. We need to do * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the * ownership or mode then we may also need to do this. Here, we take -* the safe way out and just do the flush on all setattr requests. If -* the flush returns error, store it to report later and continue. +* the safe way out and just do the flush on all setattr requests. * * BB: This should be smarter. Why bother flushing pages that -* will be truncated anyway? Also, should we error out here if -* the flush returns error? +* will be truncated anyway? */ - rc =filemap_write_and_wait (inode->i_mapping); -mapping_set_error (inode->i_mapping, rc); +filemap_write_and_wait (inode->i_mapping); rc =0 ;if (attrs->ia_valid &ATTR_SIZE ) {
@@ -2314,15 +2309,12 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)* Attempt to flush data before changing attributes. We need to do * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the * ownership or mode then we may also need to do this. Here, we take -* the safe way out and just do the flush on all setattr requests. If -* the flush returns error, store it to report later and continue. +* the safe way out and just do the flush on all setattr requests. * * BB: This should be smarter. Why bother flushing pages that -* will be truncated anyway? Also, should we error out here if -* the flush returns error? +* will be truncated anyway? */ - rc =filemap_write_and_wait (inode->i_mapping); -mapping_set_error (inode->i_mapping, rc); +filemap_write_and_wait (inode->i_mapping); rc =0 ;if (attrs->ia_valid &ATTR_SIZE ) {
Signature · 1 line
2.9.3
PATCH v4 21/27 mm: clean up error handling in write_one_page
In reply to Jeff LaytonDon't try to check PageError since that's potentially racy and not necessarily going to be set after writepage errors out.
Instead, sample the mapping error early on, and use that value to tell us whether we got a writeback error since then.
--- mm/page-writeback.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
mm/page-writeback.c +5 -6
@@ -2373,11 +2373,12 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc)int write_one_page (struct page *page) {struct address_space *mapping = page->mapping; -int ret =0 ; +int ret =0 , ret2;struct writeback_control wbc = { .sync_mode =WB_SYNC_ALL , .nr_to_write =1 , }; +errseq_t since =filemap_sample_wb_error (mapping);BUG_ON (!PageLocked (page));
@@ -2386,16 +2387,14 @@ int write_one_page(struct page *page)if (clear_page_dirty_for_io (page)) {get_page (page); ret = mapping->a_ops->writepage (page, &wbc); -if (ret ==0 ) { +if (ret ==0 )wait_on_page_writeback (page); -if (PageError (page)) - ret = -EIO ; - }put_page (page); }else {unlock_page (page); } -return ret; + ret2 =filemap_check_wb_error (mapping, since); +return ret ? : ret2; }EXPORT_SYMBOL (write_one_page);
Signature · 1 line
2.9.3
Re: [PATCH v4 21/27] mm: clean up error handling in write_one_page
Quoted 7 lines · Jeff Layton
Don't try to check PageError since that's potentially racy and not necessarily going to be set after writepage errors out.
Instead, sample the mapping error early on, and use that value to tell us whether we got a writeback error since then.
Signed-off-by Jeff Layton <[email protected]>
Looks good to me. You can add:
Honza
Quoted 46 lines
--- mm/page-writeback.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)mm/page-writeback.c +5
-6@@ -2373,11 +2373,12 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc)int write_one_page (struct page *page) {struct address_space *mapping = page->mapping; -int ret =0 ; +int ret =0 , ret2;struct writeback_control wbc = { .sync_mode =WB_SYNC_ALL , .nr_to_write =1 , }; +errseq_t since =filemap_sample_wb_error (mapping);BUG_ON (!PageLocked (page));@@ -2386,16 +2387,14 @@ int write_one_page(struct page *page)if (clear_page_dirty_for_io (page)) {get_page (page); ret = mapping->a_ops->writepage (page, &wbc); -if (ret ==0 ) { +if (ret ==0 )wait_on_page_writeback (page); -if (PageError (page)) - ret = -EIO ; - }put_page (page); }else {unlock_page (page); } -return ret; + ret2 =filemap_check_wb_error (mapping, since); +return ret ? : ret2; }EXPORT_SYMBOL (write_one_page);Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 22/27 jbd2: don't reset error in journal_finish_inode_data_buffers
In reply to Jeff LaytonNow that we don't clear writeback errors after fetching them, there is no need to reset them. This is also potentially racy.
--- fs/jbd2/commit.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
fs/jbd2/commit.c +2 -11
@@ -264,17 +264,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal, jinode->i_flags |=JI_COMMIT_RUNNING ;spin_unlock (&journal->j_list_lock); err =filemap_fdatawait (jinode->i_vfs_inode->i_mapping); -if (err) { -/* -* Because AS_EIO is cleared by -* filemap_fdatawait_range(), set it again so -* that user process can get -EIO from fsync(). -*/ -mapping_set_error (jinode->i_vfs_inode->i_mapping, -EIO ); - -if (!ret) - ret = err; - } +if (err && !ret) + ret = err;spin_lock (&journal->j_list_lock); jinode->i_flags &= ~JI_COMMIT_RUNNING ;smp_mb ();
Signature · 1 line
2.9.3
Re: [PATCH v4 22/27] jbd2: don't reset error in journal_finish_inode_data_buffers
Quoted 4 lines · Jeff Layton
Now that we don't clear writeback errors after fetching them, there is no need to reset them. This is also potentially racy.
Signed-off-by Jeff Layton <[email protected]>
Looks good. You can add:
Honza
Quoted 32 lines
--- fs/jbd2/commit.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)fs/jbd2/commit.c +2
-11@@ -264,17 +264,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal, jinode->i_flags |=JI_COMMIT_RUNNING ;spin_unlock (&journal->j_list_lock); err =filemap_fdatawait (jinode->i_vfs_inode->i_mapping); -if (err) { -/* -* Because AS_EIO is cleared by -* filemap_fdatawait_range(), set it again so -* that user process can get -EIO from fsync(). -*/ -mapping_set_error (jinode->i_vfs_inode->i_mapping, -EIO ); - -if (!ret) - ret = err; - } +if (err && !ret) + ret = err;spin_lock (&journal->j_list_lock); jinode->i_flags &= ~JI_COMMIT_RUNNING ;smp_mb ();Signature · 1 line
2.9.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 23/27 gfs2: clean up some filemap_* calls
In reply to Jeff LaytonIn some places, it's trying to reset the mapping error after calling filemap_fdatawait. That's no longer required. Also, turn several filemap_fdatawrite+filemap_fdatawait calls into filemap_write_and_wait. That will at least return writeback errors that occur during the write phase.
--- fs/gfs2/glops.c | 17 ++++------------- fs/gfs2/lops.c | 4 +--- fs/gfs2/super.c | 6 ++---- 3 files changed, 7 insertions(+), 20 deletions(-)
fs/gfs2/glops.c +4 -13
@@ -145,7 +145,6 @@ static void rgrp_go_sync(struct gfs2_glock *gl)struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;struct address_space *mapping = &sdp->sd_aspace;struct gfs2_rgrpd *rgd; -int error;spin_lock (&gl->gl_lockref.lock); rgd = gl->gl_object;
@@ -158,9 +157,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)GLOCK_BUG_ON (gl, gl->gl_state !=LM_ST_EXCLUSIVE );gfs2_log_flush (sdp, gl,NORMAL_FLUSH ); -filemap_fdatawrite_range (mapping, gl->gl_vm.start, gl->gl_vm.end); - error =filemap_fdatawait_range (mapping, gl->gl_vm.start, gl->gl_vm.end); -mapping_set_error (mapping, error); +filemap_write_and_wait_range (mapping, gl->gl_vm.start, gl->gl_vm.end);gfs2_ail_empty_gl (gl);spin_lock (&gl->gl_lockref.lock);
@@ -207,7 +204,6 @@ static void inode_go_sync(struct gfs2_glock *gl) {struct gfs2_inode *ip = gl->gl_object;struct address_space *metamapping =gfs2_glock2aspace (gl); -int error;if (ip && !S_ISREG (ip->i_inode.i_mode)) ip =NULL ;
@@ -223,14 +219,9 @@ static void inode_go_sync(struct gfs2_glock *gl)gfs2_log_flush (gl->gl_name.ln_sbd, gl,NORMAL_FLUSH );filemap_fdatawrite (metamapping); -if (ip) { -struct address_space *mapping = ip->i_inode.i_mapping; -filemap_fdatawrite (mapping); - error =filemap_fdatawait (mapping); -mapping_set_error (mapping, error); - } - error =filemap_fdatawait (metamapping); -mapping_set_error (metamapping, error); +if (ip) +filemap_write_and_wait (ip->i_inode.i_mapping); +filemap_fdatawait (metamapping);gfs2_ail_empty_gl (gl);/* * Writeback of the data mapping may cause the dirty flag to be set
fs/gfs2/lops.c +1 -3
@@ -586,9 +586,7 @@ static void gfs2_meta_sync(struct gfs2_glock *gl)if (mapping ==NULL ) mapping = &sdp->sd_aspace; -filemap_fdatawrite (mapping); - error =filemap_fdatawait (mapping); - + error =filemap_write_and_wait (mapping);if (error)gfs2_io_error (gl->gl_name.ln_sbd); }
fs/gfs2/super.c +2 -4
@@ -1593,10 +1593,8 @@ static void gfs2_evict_inode(struct inode *inode) out_truncate:gfs2_log_flush (sdp, ip->i_gl,NORMAL_FLUSH ); metamapping =gfs2_glock2aspace (ip->i_gl); -if (test_bit (GLF_DIRTY , &ip->i_gl->gl_flags)) { -filemap_fdatawrite (metamapping); -filemap_fdatawait (metamapping); - } +if (test_bit (GLF_DIRTY , &ip->i_gl->gl_flags)) +filemap_write_and_wait (metamapping);write_inode_now (inode,1 );gfs2_ail_flush (ip->i_gl,0 );
Signature · 1 line
2.9.3
Re: [PATCH v4 23/27] gfs2: clean up some filemap_* calls
----- Original Message -----
| In some places, it's trying to reset the mapping error after calling | filemap_fdatawait. That's no longer required. Also, turn several | filemap_fdatawrite+filemap_fdatawait calls into filemap_write_and_wait. | That will at least return writeback errors that occur during the write | phase. | | Signed-off-by: Jeff Layton <[email protected]> | ---
Hi Jeff,
This version looks better. ACK.
Regards,
Bob Peterson
Red Hat File Systems
RFC PATCH v4 24/27 nfs: convert to new errseq_t based error tracking for writeback errors
In reply to Jeff LaytonDrop the ERROR_WRITE flag and convert the error field in the context to a errseq_t. Add a new wb_err_cursor to track the reporting of the errseq_t. In principle, we could use the f_wb_err field in struct file for that, but that's problematic with the stock reporting in call_fsync.
--- fs/nfs/file.c | 19 +++++++++++-------- fs/nfs/inode.c | 5 +++-- fs/nfs/write.c | 2 +- include/linux/nfs_fs.h | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-)
I did this on a lark to see how it would be, but I don't think this is really better than what's there already. There may be a better way to provide the right semantics without using an errseq_t here.
fs/nfs/file.c +11 -8
@@ -212,21 +212,24 @@ nfs_file_fsync_commit(struct file *file, loff_t start, loff_t end, int datasync) {struct nfs_open_context *ctx =nfs_file_open_context (file);struct inode *inode =file_inode (file); -int have_error, do_resend, status; -int ret =0 ; +int do_resend, status; +int ret;dprintk ("NFS: fsync file(%pD2) datasync %d\n" , file, datasync);nfs_inc_stats (inode,NFSIOS_VFSFSYNC ); do_resend =test_and_clear_bit (NFS_CONTEXT_RESEND_WRITES , &ctx->flags); - have_error =test_and_clear_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags); +clear_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags); status =nfs_commit_inode (inode,FLUSH_SYNC ); - have_error |=test_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags); -if (have_error) { - ret =xchg (&ctx->error,0 ); -if (ret) - goto out; + ret =errseq_check (&ctx->wb_err,READ_ONCE (ctx->wb_err_cursor)); +if (ret) { +/* Use f_lock to serialize changes to wb_err_cursor */ +spin_lock (&file->f_lock); + ret =errseq_check_and_advance (&ctx->wb_err, &ctx->wb_err_cursor); +spin_unlock (&file->f_lock); } +if (ret) + goto out;if (status <0 ) { ret = status; goto out;
fs/nfs/inode.c +3 -2
@@ -869,7 +869,8 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, ctx->state =NULL ; ctx->mode = f_mode; ctx->flags =0 ; - ctx->error =0 ; + ctx->wb_err =0 ; + ctx->wb_err_cursor =0 ; ctx->flock_owner = (fl_owner_t )filp;nfs_init_lock_context (&ctx->lock_context); ctx->lock_context.open_context = ctx;
@@ -978,7 +979,7 @@ void nfs_file_clear_open_context(struct file *filp)* We fatal error on write before. Try to writeback * every page again. */ -if (ctx->error <0 ) +if (errseq_check (&ctx->wb_err, ctx->wb_err_cursor))invalidate_inode_pages2 (inode->i_mapping); filp->private_data =NULL ;spin_lock (&inode->i_lock);
fs/nfs/write.c +1 -1
@@ -94,7 +94,7 @@ static void nfs_writehdr_free(struct nfs_pgio_header *hdr)static void nfs_context_set_write_error (struct nfs_open_context *ctx,int error) { - ctx->error = error; +errseq_set (&ctx->wb_err, error);smp_wmb ();set_bit (NFS_CONTEXT_ERROR_WRITE , &ctx->flags); }
include/linux/nfs_fs.h +2 -1
@@ -76,7 +76,8 @@ struct nfs_open_context {#define NFS_CONTEXT_ERROR_WRITE (0)#define NFS_CONTEXT_RESEND_WRITES (1)#define NFS_CONTEXT_BAD (2) -int error; +errseq_t wb_err;/* where wb errors are tracked */ +errseq_t wb_err_cursor;/* reporting cursor */ struct list_head list;struct nfs4_threshold *mdsthreshold;
Signature · 1 line
2.9.3
PATCH v4 25/27 Documentation: flesh out the section in vfs.txt on storing and reporting writeback errors
In reply to Jeff LaytonI waxed a little loquacious here, but I figured that more detail was better, and writeback error handling is so hard to get right.
--- Documentation/filesystems/vfs.txt | 54 ++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-)
Documentation/filesystems/vfs.txt +45 -9
@@ -576,12 +576,46 @@ 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 error (typically using mapping_set_error), in order to -ensure that the error can later be reported to the application when an -fsync is issued. - -Writeback makes use of a writeback_control structure... +Writeback makes use of a writeback_control structure to direct the +operations. This gives the the writepage and writepages operations some +information about the nature of and reason for the writeback request, +and the constraints under which it is being done. It is also used to +return information back to the caller about the result of a writepage or +writepages request. + +Handling errors during writeback +-------------------------------- +Most applications that utilize the pagecache will periodically call +fsync to ensure that data written has made it to the backing store. +When there is an error during writeback, that error should be reported +when fsync is called. After an error has been reported to fsync, +subsequent fsync calls on the same file descriptor should return 0, +unless further writeback errors have occurred since the previous fsync. + +Ideally, the kernel would report it only on file descriptions on which +writes were done that subsequently failed to be written back. The +generic pagecache infrastructure does not track the file descriptions +that have dirtied each individual page however, so determining which +file descriptors should get back an error is not possible. + +Instead, the generic writeback error tracking infrastructure in the +kernel settles for reporting errors to fsync on all file descriptions +that were open at the time that the error occurred. In a situation with +multiple writers, all of them will get back an error on a subsequent fsync, +even if all of the writes done through that particular file descriptor +succeeded (or even if there were no writes on that file descriptor at all). + +Filesystems that wish to use this infrastructure should call +mapping_set_error to record the error in the address_space when it +occurs. The generic vfs code will then handle reporting the error when +fsync is called, even if the fsync file operation returned 0. + +Filesystems are free to track errors internally if they choose (i.e. if +they do keep track of how the pages were dirtied), but they should aim +to provide the same (or better) error reporting semantics for when there +are multiple writers. Those filesystems should avoid calling +mapping_set_error in order to ensure that errors stored in the mapping +aren't improperly reported by the generic filesystem code. struct address_space_operations -------------------------------
@@ -810,7 +844,8 @@ struct address_space_operations { The File Object =============== -A file object represents a file opened by a process. +A file object represents a file opened by a process. This is also known +as an "open file description" in POSIX parlance. struct file_operations
@@ -893,9 +928,10 @@ otherwise noted. release: called when the last reference to an open file is closed - fsync: called by the fsync(2) system call. Errors that were previously + fsync: called by the fsync(2) system call. Errors that were previously recorded using mapping_set_error will automatically be returned to - the application and the file's error sequence advanced. + the application and the struct file's error sequence advanced. + See the section above on handling writeback errors. fasync: called by the fcntl(2) system call when asynchronous (non-blocking) mode is enabled for a file
Signature · 1 line
2.9.3
Re: [PATCH v4 25/27] Documentation: flesh out the section in vfs.txt on storing and reporting writeback errors
Quoted 42 lines · Jeff Layton
I waxed a little loquacious here, but I figured that more detail was better, and writeback error handling is so hard to get right.
Cc Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- Documentation/filesystems/vfs.txt | 54 ++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-)Documentation/filesystems/vfs.txt +19
-6@@ -576,12 +576,46 @@ 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 error (typically using mapping_set_error), in order to -ensure that the error can later be reported to the application when an -fsync is issued. - -Writeback makes use of a writeback_control structure... +Writeback makes use of a writeback_control structure to direct the +operations. This gives the the writepage and writepages operations some +information about the nature of and reason for the writeback request, +and the constraints under which it is being done. It is also used to +return information back to the caller about the result of a writepage or +writepages request. + +Handling errors during writeback +-------------------------------- +Most applications that utilize the pagecache will periodically call +fsync to ensure that data written has made it to the backing store. +When there is an error during writeback, that error should be reported +when fsync is called. After an error has been reported to fsync, +subsequent fsync calls on the same file descriptor should return 0, +unless further writeback errors have occurred since the previous fsync. + +Ideally, the kernel would report it only on file descriptions on which +writes were done that subsequently failed to be written back. The +generic pagecache infrastructure does not track the file descriptions
Documentation/filesystems/vfs.txt should clear PG_Dirty and set PG_Writeback. It can be actually · line 607
Quoted 10 lines
Documentation/filesystems/vfs.txt +10
-0+that have dirtied each individual page however, so determining which +file descriptors should get back an error is not possible. + +Instead, the generic writeback error tracking infrastructure in the +kernel settles for reporting errors to fsync on all file descriptions +that were open at the time that the error occurred. In a situation with +multiple writers, all of them will get back an error on a subsequent fsync, +even if all of the writes done through that particular file descriptor +succeeded (or even if there were no writes on that file descriptor at all). +
(cc'ing Michael Kerrisk)
Once this is closer to merge, I think we'll also want to update the fsync(2) manpage with something similar to the 3 paragraphs above, and also with an explanation of the behavior that applications can expect from earlier kernels.
Quoted 37 lines
Documentation/filesystems/vfs.txt +16
-3+Filesystems that wish to use this infrastructure should call +mapping_set_error to record the error in the address_space when it +occurs. The generic vfs code will then handle reporting the error when +fsync is called, even if the fsync file operation returned 0. + +Filesystems are free to track errors internally if they choose (i.e. if +they do keep track of how the pages were dirtied), but they should aim +to provide the same (or better) error reporting semantics for when there +are multiple writers. Those filesystems should avoid calling +mapping_set_error in order to ensure that errors stored in the mapping +aren't improperly reported by the generic filesystem code. struct address_space_operations -------------------------------@@ -810,7 +844,8 @@ struct address_space_operations { The File Object =============== -A file object represents a file opened by a process. +A file object represents a file opened by a process. This is also known +as an "open file description" in POSIX parlance. struct file_operations@@ -893,9 +928,10 @@ otherwise noted. release: called when the last reference to an open file is closed - fsync: called by the fsync(2) system call. Errors that were previously + fsync: called by the fsync(2) system call. Errors that were previously recorded using mapping_set_error will automatically be returned to - the application and the file's error sequence advanced. + the application and the struct file's error sequence advanced. + See the section above on handling writeback errors. fasync: called by the fcntl(2) system call when asynchronous (non-blocking) mode is enabled for a file
Signature · 1 line
Jeff Layton <[email protected]>
PATCH v4 26/27 mm: flesh out comments over mapping_set_error
In reply to Jeff Layton--- include/linux/pagemap.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/pagemap.h +14 -0
@@ -27,6 +27,20 @@ enum mapping_flags { AS_NO_WRITEBACK_TAGS = 3, }; +/** +* mapping_set_error - record a writeback error in the address_space +* @mapping - the mapping in which an error should be set +* @error - the error to set in the mapping +* +* When writeback fails in some way, we must record that error so that +* userspace can be informed when fsync and the like are called. We endeavor +* to report errors on any file that was open at the time of the error. Some +* internal callers also need to know when writeback errors have occurred. +* +* When a writeback error occurs, most will filesystems will want to call +* mapping_set_error to record the error in the mapping so that it will be +* automatically reported whenever fsync is called on the file. +*/ static inline void mapping_set_error (struct address_space *mapping,int error) {return errseq_set (&mapping->wb_err, error);
Signature · 1 line
2.9.3
PATCH v4 27/27 mm: clean up comments in me_pagecache_dirty
In reply to Jeff LaytonThis no longer applies with the new writeback error tracking and reporting infrastructure.
--- mm/memory-failure.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-)
mm/memory-failure.c +5 -30
@@ -642,37 +642,12 @@ static int me_pagecache_dirty(struct page *p, unsigned long pfn)if (mapping) {/* * IO error will be reported by write(), fsync(), etc. -* who check the mapping. -* This way the application knows that something went -* wrong with its dirty file data. +* who check the mapping. This way the application knows that +* something went wrong when writing back its dirty file data. * -* There's one open issue: -* -* The EIO will be only reported on the next IO -* operation and then cleared through the IO map. -* Normally Linux has two mechanisms to pass IO error -* first through the AS_EIO flag in the address space -* and then through the PageError flag in the page. -* Since we drop pages on memory failure handling the -* only mechanism open to use is through AS_AIO. -* -* This has the disadvantage that it gets cleared on -* the first operation that returns an error, while -* the PageError bit is more sticky and only cleared -* when the page is reread or dropped. If an -* application assumes it will always get error on -* fsync, but does other operations on the fd before -* and the page is dropped between then the error -* will not be properly reported. -* -* This can already happen even without hwpoisoned -* pages: first on metadata IO errors (which only -* report through AS_EIO) or when the page is dropped -* at the wrong time. -* -* So right now we assume that the application DTRT on -* the first EIO, but we're not worse than other parts -* of the kernel. +* Note that errors are reported only once per file +* description, but should be reported on all open file +* descriptions for this inode. */ mapping_set_error (mapping, -EIO ); }
Signature · 1 line
2.9.3