O_SYNC error handling fix
Subsystems (3)
PATCH 1/1 O_SYNC error handling fix
If we hit errors during generic_osync_inode(), generic_file_buffered_write will still return written ? written : status; This patch ensures the -EIO gets back up to userland at all times.
mm/filemap.c +15 -2
@@ -2026,7 +2026,6 @@ generic_file_buffered_write(struct kiocbbalance_dirty_pages_ratelimited (mapping);cond_resched (); }while (count); - *ppos = pos;if (cached_page)page_cache_release (cached_page);
@@ -2047,10 +2046,24 @@ generic_file_buffered_write(struct kiocb* to buffered writes (block instantiation inside i_size). So we sync * the file data here, to try to honour O_DIRECT expectations. */ -if (unlikely (file->f_flags &O_DIRECT ) && written) +if (unlikely (file->f_flags &O_DIRECT ) && status >=0 && written) status =filemap_write_and_wait (mapping);pagevec_lru_add (&lru_pvec); + +/* +* We must let know userspace if something hasn't been written +* correctly. If we got an I/O error it means we got an hardware +* failure, anything can be happening to the on-disk data, +* letting know userspace that a bit of data might have been +* written correctly on disk is a very low priority, compared +* to letting know userspace that some data has _not_ been +* written at all. +*/ +if (unlikely (status == -EIO )) +return status; + *ppos = pos; +return written ? written : status; }EXPORT_SYMBOL (generic_file_buffered_write);
Quoted 33 lines · Chris Mason
If we hit errors during
generic_osync_inode(),generic_file_buffered_writewill still return written ? written : status; This patch ensures the-EIOgets back up to userland at all times.diff -r
7e48cbfbccadmm/filemap.cmm/filemap.c +8
-2@@ -2026,7 +2026,6 @@ generic_file_buffered_write(struct kiocbbalance_dirty_pages_ratelimited (mapping);cond_resched (); }while (count); - *ppos = pos;if (cached_page)page_cache_release (cached_page);@@ -2047,10 +2046,24 @@ generic_file_buffered_write(struct kiocb* to buffered writes (block instantiation inside i_size). So we sync * the file data here, to try to honour O_DIRECT expectations. */ -if (unlikely (file->f_flags &O_DIRECT ) && written) +if (unlikely (file->f_flags &O_DIRECT ) && status >=0 && written) status =filemap_write_and_wait (mapping);pagevec_lru_add (&lru_pvec); + +/* +* We must let know userspace if something hasn't been written +* correctly. If we got an I/O error it means we got an hardware +* failure, anything can be happening to the on-disk data, +* letting know userspace that a bit of data might have been +* written correctly on disk is a very low priority, compared
mm/filemap.c generic_file_buffered_write(struct kiocb · line 2069
Quoted 10 lines
mm/filemap.c +7
-0+* to letting know userspace that some data has _not_ been +* written at all. +*/ +if (unlikely (status == -EIO )) +return status; + *ppos = pos; +return written ? written : status; }EXPORT_SYMBOL (generic_file_buffered_write);
The patch does more than this. It also changes the O_DIRECT logic and it also refuses to update the file position on I/O errors.
Probably reasonable changes, but I'd like to have your description of why these changes were made please.
The patch also makes write() non-linuxy. We normally return a short write on errors. In this case I'd say that returning 0 (and not updating f_pos) would be appropriate?
Quoted 4 lines · Andrew Morton
Quoted 3 lines · Chris Mason
If we hit errors during
generic_osync_inode(),generic_file_buffered_writewill still return written ? written : status;
This patch ensures the-EIOgets back up to userland at all times.
[ ... ]
Quoted 3 lines
The patch does more than this. It also changes the
O_DIRECTlogic and it also refuses to update the file position on I/O errors.
True, I can get rid of the O_DIRECT change, it was just to preserve the status variable for the -EIO test.
Quoted 4 lines
Probably reasonable changes, but I'd like to have your description of why these changes were made please.
Skipping the file position update was because we are not returning the short write. We want the next write to happen at the appropriate place given the number of bytes we've told userland went out.
Quoted 4 lines
The patch also makes
write()non-linuxy. We normally return a short write on errors. In this case I'd say that returning 0 (and not updatingf_pos) would be appropriate?
With O_SYNC we've no way of knowing which bytes didn't make it down to the disk. I can special case the -EIO check for just O_SYNC. I think that along with changing around the O_DIRECT bits will make us both happy?
-chris
Quoted 3 lines · Chris Mason
I can special case the
-EIOcheck for justO_SYNC. I think that along
with changing around theO_DIRECTbits will make us both happy?
I guess so...
It seems I'm full of crap anyway. We already return -EFOO on failing O_SYNC writes, no?