diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-06-30 03:55:12 +0200 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-07-15 05:14:04 +0200 |
commit | 8a56dd9685d6531d09b370ab22a61b9687131875 (patch) | |
tree | 19e926d07632915c5fd47bd7a0a0de426ab1d8b1 /fs/f2fs/data.c | |
parent | f2fs: flush journal nat entries for nat_bits during unmount (diff) | |
download | linux-8a56dd9685d6531d09b370ab22a61b9687131875.tar.xz linux-8a56dd9685d6531d09b370ab22a61b9687131875.zip |
f2fs: allow wrong configured dio to buffered write
This fixes to support dio having unaligned buffers as buffered writes.
xfs_io -f -d -c "pwrite 0 512" $testfile
-> okay
xfs_io -f -d -c "pwrite 1 512" $testfile
-> EINVAL
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/data.c')
-rw-r--r-- | fs/f2fs/data.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 8f931d699287..5e53d210e222 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2371,14 +2371,20 @@ unlock_out: static int check_direct_IO(struct inode *inode, struct iov_iter *iter, loff_t offset) { - unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; - - if (offset & blocksize_mask) - return -EINVAL; - - if (iov_iter_alignment(iter) & blocksize_mask) - return -EINVAL; - + unsigned i_blkbits = READ_ONCE(inode->i_blkbits); + unsigned blkbits = i_blkbits; + unsigned blocksize_mask = (1 << blkbits) - 1; + unsigned long align = offset | iov_iter_alignment(iter); + struct block_device *bdev = inode->i_sb->s_bdev; + + if (align & blocksize_mask) { + if (bdev) + blkbits = blksize_bits(bdev_logical_block_size(bdev)); + blocksize_mask = (1 << blkbits) - 1; + if (align & blocksize_mask) + return -EINVAL; + return 1; + } return 0; } @@ -2396,7 +2402,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) err = check_direct_IO(inode, iter, offset); if (err) - return err; + return err < 0 ? err : 0; if (f2fs_force_buffered_io(inode, rw)) return 0; |