2 Subject: make sure O_SYNC writes properly return -EIO
5 Make sure to honor the error status of synchronous writeback during
8 Acked-by: Jeff Mahoney <jeffm@suse.com>
11 mm/filemap.c | 17 +++++++++++++++--
12 1 file changed, 15 insertions(+), 2 deletions(-)
16 @@ -2497,7 +2497,7 @@ generic_file_buffered_write(struct kiocb
18 if (likely(status >= 0)) {
20 - *ppos = pos + status;
24 * For now, when the user asks for O_SYNC, we'll actually give
25 @@ -2515,10 +2515,23 @@ generic_file_buffered_write(struct kiocb
26 * to buffered writes (block instantiation inside i_size). So we sync
27 * the file data here, to try to honour O_DIRECT expectations.
29 - if (unlikely(file->f_flags & O_DIRECT) && written)
30 + if (unlikely(file->f_flags & O_DIRECT) && status >= 0 && written)
31 status = filemap_write_and_wait_range(mapping,
32 pos, pos + written - 1);
35 + * We must let know userspace if something hasn't been written
36 + * correctly. If we got an I/O error it means we got an hardware
37 + * failure, anything can be happening to the on-disk data,
38 + * letting know userspace that a bit of data might have been
39 + * written correctly on disk is a very low priority, compared
40 + * to letting know userspace that some data has _not_ been
43 + if (unlikely(status == -EIO))
47 return written ? written : status;
49 EXPORT_SYMBOL(generic_file_buffered_write);