diff options
author | Goldwyn Rodrigues <rgoldwyn@suse.com> | 2017-07-04 22:33:07 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-07-10 15:29:44 +0200 |
commit | ff0fa73247e442518936baa43c3f037b17f10fa7 (patch) | |
tree | 03cb6c5e75f63c117fbadec630830f5624b3ca2b /fs/btrfs | |
parent | f95a0d6a95b12a79b7492da7ab687ae4cd741124 (diff) | |
download | op-kernel-dev-ff0fa73247e442518936baa43c3f037b17f10fa7.zip op-kernel-dev-ff0fa73247e442518936baa43c3f037b17f10fa7.tar.gz |
btrfs: nowait aio: Correct assignment of pos
Assigning pos for usage early messes up in append mode, where the pos is
re-assigned in generic_write_checks(). Assign pos later to get the
correct position to write from iocb->ki_pos.
Since check_can_nocow also uses the value of pos, we shift
generic_write_checks() before check_can_nocow(). Checks with IOCB_DIRECT
are present in generic_write_checks(), so checking for IOCB_NOWAIT is
enough.
Also, put locking sequence in the fast path.
This fixes a user visible bug, as reported:
"apparently breaks several shell related features on my system.
In zsh history stopped working, because no new entries are added
anymore.
I fist noticed the issue when I tried to build mplayer. It uses a shell
script to generate a help_mp.h file:
[...]
Here is a simple testcase:
% echo "foo" >> test
% echo "foo" >> test
% cat test
foo
%
"
Fixes: edf064e7c6fe ("btrfs: nowait aio support")
CC: Jens Axboe <axboe@kernel.dk>
Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Link: https://lkml.kernel.org/r/20170704042306.GA274@x4
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/file.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 59e2dcc..ad53832 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1875,16 +1875,25 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, ssize_t num_written = 0; bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host); ssize_t err; - loff_t pos = iocb->ki_pos; + loff_t pos; size_t count = iov_iter_count(from); loff_t oldsize; int clean_page = 0; - if ((iocb->ki_flags & IOCB_NOWAIT) && - (iocb->ki_flags & IOCB_DIRECT)) { - /* Don't sleep on inode rwsem */ - if (!inode_trylock(inode)) + if (!inode_trylock(inode)) { + if (iocb->ki_flags & IOCB_NOWAIT) return -EAGAIN; + inode_lock(inode); + } + + err = generic_write_checks(iocb, from); + if (err <= 0) { + inode_unlock(inode); + return err; + } + + pos = iocb->ki_pos; + if (iocb->ki_flags & IOCB_NOWAIT) { /* * We will allocate space in case nodatacow is not set, * so bail @@ -1895,13 +1904,6 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, inode_unlock(inode); return -EAGAIN; } - } else - inode_lock(inode); - - err = generic_write_checks(iocb, from); - if (err <= 0) { - inode_unlock(inode); - return err; } current->backing_dev_info = inode_to_bdi(inode); |