Commit 67041680 authored by Al Viro's avatar Al Viro Committed by Sasha Levin

ocfs2: _really_ sync the right range

[ Upstream commit 64b4e252 ]

"ocfs2 syncs the wrong range" had been broken; prior to it the
code was doing the wrong thing in case of O_APPEND, all right,
but _after_ it we were syncing the wrong range in 100% cases.
*ppos, aka iocb->ki_pos is incremented prior to that point,
so we are always doing sync on the area _after_ the one we'd
written to.

Spotted by Joseph Qi <joseph.qi@huawei.com> back in January;
unfortunately, I'd missed his mail back then ;-/

Cc: stable@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent a260abd1
...@@ -2374,10 +2374,14 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, ...@@ -2374,10 +2374,14 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
/* buffered aio wouldn't have proper lock coverage today */ /* buffered aio wouldn't have proper lock coverage today */
BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT));
if (unlikely(written <= 0))
goto no_sync;
if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) || if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||
((file->f_flags & O_DIRECT) && !direct_io)) { ((file->f_flags & O_DIRECT) && !direct_io)) {
ret = filemap_fdatawrite_range(file->f_mapping, *ppos, ret = filemap_fdatawrite_range(file->f_mapping,
*ppos + count - 1); iocb->ki_pos - written,
iocb->ki_pos - 1);
if (ret < 0) if (ret < 0)
written = ret; written = ret;
...@@ -2390,10 +2394,12 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, ...@@ -2390,10 +2394,12 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
} }
if (!ret) if (!ret)
ret = filemap_fdatawait_range(file->f_mapping, *ppos, ret = filemap_fdatawait_range(file->f_mapping,
*ppos + count - 1); iocb->ki_pos - written,
iocb->ki_pos - 1);
} }
no_sync:
/* /*
* deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
* function pointer which is called when o_direct io completes so that * function pointer which is called when o_direct io completes so that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment