aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@osandov.com>2015-03-16 07:33:52 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2015-04-11 22:29:45 -0400
commit6f67376318abea58589ebe6d69dffeabb6f6c26a (patch)
tree1d3e6b00735aed811dcaeee2ccf7fa65eebc406d
parenta95cd6311512bd954e88684eb39373f7f4b0a984 (diff)
direct_IO: use iov_iter_rw() instead of rw everywhere
The rw parameter to direct_IO is redundant with iov_iter->type, and treated slightly differently just about everywhere it's used: some users do rw & WRITE, and others do rw == WRITE where they should be doing a bitwise check. Simplify this with the new iov_iter_rw() helper, which always returns either READ or WRITE. Signed-off-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/staging/lustre/lustre/llite/rw26.c18
-rw-r--r--fs/9p/vfs_addr.c2
-rw-r--r--fs/affs/file.c4
-rw-r--r--fs/btrfs/inode.c10
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--fs/ext3/inode.c8
-rw-r--r--fs/ext4/ext4.h4
-rw-r--r--fs/ext4/indirect.c10
-rw-r--r--fs/ext4/inode.c20
-rw-r--r--fs/f2fs/data.c16
-rw-r--r--fs/fat/inode.c4
-rw-r--r--fs/fuse/file.c13
-rw-r--r--fs/gfs2/aops.c7
-rw-r--r--fs/hfs/inode.c2
-rw-r--r--fs/hfsplus/inode.c2
-rw-r--r--fs/jfs/inode.c2
-rw-r--r--fs/nfs/direct.c2
-rw-r--r--fs/nilfs2/inode.c4
-rw-r--r--fs/ocfs2/aops.c2
-rw-r--r--fs/reiserfs/inode.c2
-rw-r--r--fs/udf/inode.c2
-rw-r--r--fs/xfs/xfs_aops.c2
22 files changed, 69 insertions, 69 deletions
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c
index 2f21304046aa..3aa9de6bcc40 100644
--- a/drivers/staging/lustre/lustre/llite/rw26.c
+++ b/drivers/staging/lustre/lustre/llite/rw26.c
@@ -399,7 +399,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
399 * size changing by concurrent truncates and writes. 399 * size changing by concurrent truncates and writes.
400 * 1. Need inode mutex to operate transient pages. 400 * 1. Need inode mutex to operate transient pages.
401 */ 401 */
402 if (rw == READ) 402 if (iov_iter_rw(iter) == READ)
403 mutex_lock(&inode->i_mutex); 403 mutex_lock(&inode->i_mutex);
404 404
405 LASSERT(obj->cob_transient_pages == 0); 405 LASSERT(obj->cob_transient_pages == 0);
@@ -408,7 +408,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
408 size_t offs; 408 size_t offs;
409 409
410 count = min_t(size_t, iov_iter_count(iter), size); 410 count = min_t(size_t, iov_iter_count(iter), size);
411 if (rw == READ) { 411 if (iov_iter_rw(iter) == READ) {
412 if (file_offset >= i_size_read(inode)) 412 if (file_offset >= i_size_read(inode))
413 break; 413 break;
414 if (file_offset + count > i_size_read(inode)) 414 if (file_offset + count > i_size_read(inode))
@@ -418,11 +418,11 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
418 result = iov_iter_get_pages_alloc(iter, &pages, count, &offs); 418 result = iov_iter_get_pages_alloc(iter, &pages, count, &offs);
419 if (likely(result > 0)) { 419 if (likely(result > 0)) {
420 int n = DIV_ROUND_UP(result + offs, PAGE_SIZE); 420 int n = DIV_ROUND_UP(result + offs, PAGE_SIZE);
421 result = ll_direct_IO_26_seg(env, io, rw, inode, 421 result = ll_direct_IO_26_seg(env, io, iov_iter_rw(iter),
422 file->f_mapping, 422 inode, file->f_mapping,
423 result, file_offset, 423 result, file_offset, pages,
424 pages, n); 424 n);
425 ll_free_user_pages(pages, n, rw==READ); 425 ll_free_user_pages(pages, n, iov_iter_rw(iter) == READ);
426 } 426 }
427 if (unlikely(result <= 0)) { 427 if (unlikely(result <= 0)) {
428 /* If we can't allocate a large enough buffer 428 /* If we can't allocate a large enough buffer
@@ -449,11 +449,11 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
449 } 449 }
450out: 450out:
451 LASSERT(obj->cob_transient_pages == 0); 451 LASSERT(obj->cob_transient_pages == 0);
452 if (rw == READ) 452 if (iov_iter_rw(iter) == READ)
453 mutex_unlock(&inode->i_mutex); 453 mutex_unlock(&inode->i_mutex);
454 454
455 if (tot_bytes > 0) { 455 if (tot_bytes > 0) {
456 if (rw == WRITE) { 456 if (iov_iter_rw(iter) == WRITE) {
457 struct lov_stripe_md *lsm; 457 struct lov_stripe_md *lsm;
458 458
459 lsm = ccc_inode_lsm_get(inode); 459 lsm = ccc_inode_lsm_get(inode);
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
index 2e38f9a5b472..dd5543b1d183 100644
--- a/fs/9p/vfs_addr.c
+++ b/fs/9p/vfs_addr.c
@@ -253,7 +253,7 @@ v9fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos)
253 struct file *file = iocb->ki_filp; 253 struct file *file = iocb->ki_filp;
254 ssize_t n; 254 ssize_t n;
255 int err = 0; 255 int err = 0;
256 if (rw & WRITE) { 256 if (iov_iter_rw(iter) == WRITE) {
257 n = p9_client_write(file->private_data, pos, iter, &err); 257 n = p9_client_write(file->private_data, pos, iter, &err);
258 if (n) { 258 if (n) {
259 struct inode *inode = file_inode(file); 259 struct inode *inode = file_inode(file);
diff --git a/fs/affs/file.c b/fs/affs/file.c
index 1edc0d4b40db..7f05a468d594 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -398,7 +398,7 @@ affs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
398 size_t count = iov_iter_count(iter); 398 size_t count = iov_iter_count(iter);
399 ssize_t ret; 399 ssize_t ret;
400 400
401 if (rw == WRITE) { 401 if (iov_iter_rw(iter) == WRITE) {
402 loff_t size = offset + count; 402 loff_t size = offset + count;
403 403
404 if (AFFS_I(inode)->mmu_private < size) 404 if (AFFS_I(inode)->mmu_private < size)
@@ -406,7 +406,7 @@ affs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
406 } 406 }
407 407
408 ret = blockdev_direct_IO(iocb, inode, iter, offset, affs_get_block); 408 ret = blockdev_direct_IO(iocb, inode, iter, offset, affs_get_block);
409 if (ret < 0 && (rw & WRITE)) 409 if (ret < 0 && iov_iter_rw(iter) == WRITE)
410 affs_write_failed(mapping, offset + count); 410 affs_write_failed(mapping, offset + count);
411 return ret; 411 return ret;
412} 412}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index e9a3ff8a85fd..ca69e83d4f3c 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8081,7 +8081,7 @@ free_ordered:
8081 bio_endio(dio_bio, ret); 8081 bio_endio(dio_bio, ret);
8082} 8082}
8083 8083
8084static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, 8084static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb,
8085 const struct iov_iter *iter, loff_t offset) 8085 const struct iov_iter *iter, loff_t offset)
8086{ 8086{
8087 int seg; 8087 int seg;
@@ -8096,7 +8096,7 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io
8096 goto out; 8096 goto out;
8097 8097
8098 /* If this is a write we don't need to check anymore */ 8098 /* If this is a write we don't need to check anymore */
8099 if (rw & WRITE) 8099 if (iov_iter_rw(iter) == WRITE)
8100 return 0; 8100 return 0;
8101 /* 8101 /*
8102 * Check to make sure we don't have duplicate iov_base's in this 8102 * Check to make sure we don't have duplicate iov_base's in this
@@ -8126,7 +8126,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
8126 bool relock = false; 8126 bool relock = false;
8127 ssize_t ret; 8127 ssize_t ret;
8128 8128
8129 if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iter, offset)) 8129 if (check_direct_IO(BTRFS_I(inode)->root, iocb, iter, offset))
8130 return 0; 8130 return 0;
8131 8131
8132 atomic_inc(&inode->i_dio_count); 8132 atomic_inc(&inode->i_dio_count);
@@ -8144,7 +8144,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
8144 filemap_fdatawrite_range(inode->i_mapping, offset, 8144 filemap_fdatawrite_range(inode->i_mapping, offset,
8145 offset + count - 1); 8145 offset + count - 1);
8146 8146
8147 if (rw & WRITE) { 8147 if (iov_iter_rw(iter) == WRITE) {
8148 /* 8148 /*
8149 * If the write DIO is beyond the EOF, we need update 8149 * If the write DIO is beyond the EOF, we need update
8150 * the isize, but it is protected by i_mutex. So we can 8150 * the isize, but it is protected by i_mutex. So we can
@@ -8178,7 +8178,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
8178 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev, 8178 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev,
8179 iter, offset, btrfs_get_blocks_direct, NULL, 8179 iter, offset, btrfs_get_blocks_direct, NULL,
8180 btrfs_submit_direct, flags); 8180 btrfs_submit_direct, flags);
8181 if (rw & WRITE) { 8181 if (iov_iter_rw(iter) == WRITE) {
8182 current->journal_info = NULL; 8182 current->journal_info = NULL;
8183 if (ret < 0 && ret != -EIOCBQUEUED) 8183 if (ret < 0 && ret != -EIOCBQUEUED)
8184 btrfs_delalloc_release_space(inode, count); 8184 btrfs_delalloc_release_space(inode, count);
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 14e8d1752685..685e514c57dd 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -866,7 +866,7 @@ ext2_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
866 else 866 else
867 ret = blockdev_direct_IO(iocb, inode, iter, offset, 867 ret = blockdev_direct_IO(iocb, inode, iter, offset,
868 ext2_get_block); 868 ext2_get_block);
869 if (ret < 0 && (rw & WRITE)) 869 if (ret < 0 && iov_iter_rw(iter) == WRITE)
870 ext2_write_failed(mapping, offset + count); 870 ext2_write_failed(mapping, offset + count);
871 return ret; 871 return ret;
872} 872}
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 6fb376c8d938..c70839d26ccd 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1832,9 +1832,9 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1832 size_t count = iov_iter_count(iter); 1832 size_t count = iov_iter_count(iter);
1833 int retries = 0; 1833 int retries = 0;
1834 1834
1835 trace_ext3_direct_IO_enter(inode, offset, count, rw); 1835 trace_ext3_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
1836 1836
1837 if (rw == WRITE) { 1837 if (iov_iter_rw(iter) == WRITE) {
1838 loff_t final_size = offset + count; 1838 loff_t final_size = offset + count;
1839 1839
1840 if (final_size > inode->i_size) { 1840 if (final_size > inode->i_size) {
@@ -1861,7 +1861,7 @@ retry:
1861 * In case of error extending write may have instantiated a few 1861 * In case of error extending write may have instantiated a few
1862 * blocks outside i_size. Trim these off again. 1862 * blocks outside i_size. Trim these off again.
1863 */ 1863 */
1864 if (unlikely((rw & WRITE) && ret < 0)) { 1864 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
1865 loff_t isize = i_size_read(inode); 1865 loff_t isize = i_size_read(inode);
1866 loff_t end = offset + count; 1866 loff_t end = offset + count;
1867 1867
@@ -1908,7 +1908,7 @@ retry:
1908 ret = err; 1908 ret = err;
1909 } 1909 }
1910out: 1910out:
1911 trace_ext3_direct_IO_exit(inode, offset, count, rw, ret); 1911 trace_ext3_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
1912 return ret; 1912 return ret;
1913} 1913}
1914 1914
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index f63c3d5805c4..2031c994024e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2152,8 +2152,8 @@ extern void ext4_da_update_reserve_space(struct inode *inode,
2152/* indirect.c */ 2152/* indirect.c */
2153extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 2153extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
2154 struct ext4_map_blocks *map, int flags); 2154 struct ext4_map_blocks *map, int flags);
2155extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, 2155extern ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
2156 struct iov_iter *iter, loff_t offset); 2156 loff_t offset);
2157extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock); 2157extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
2158extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 2158extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
2159extern void ext4_ind_truncate(handle_t *, struct inode *inode); 2159extern void ext4_ind_truncate(handle_t *, struct inode *inode);
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index cd81d01da0b0..3580629e42d3 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -642,8 +642,8 @@ out:
642 * crashes then stale disk data _may_ be exposed inside the file. But current 642 * crashes then stale disk data _may_ be exposed inside the file. But current
643 * VFS code falls back into buffered path in that case so we are safe. 643 * VFS code falls back into buffered path in that case so we are safe.
644 */ 644 */
645ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, 645ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
646 struct iov_iter *iter, loff_t offset) 646 loff_t offset)
647{ 647{
648 struct file *file = iocb->ki_filp; 648 struct file *file = iocb->ki_filp;
649 struct inode *inode = file->f_mapping->host; 649 struct inode *inode = file->f_mapping->host;
@@ -654,7 +654,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
654 size_t count = iov_iter_count(iter); 654 size_t count = iov_iter_count(iter);
655 int retries = 0; 655 int retries = 0;
656 656
657 if (rw == WRITE) { 657 if (iov_iter_rw(iter) == WRITE) {
658 loff_t final_size = offset + count; 658 loff_t final_size = offset + count;
659 659
660 if (final_size > inode->i_size) { 660 if (final_size > inode->i_size) {
@@ -676,7 +676,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
676 } 676 }
677 677
678retry: 678retry:
679 if (rw == READ && ext4_should_dioread_nolock(inode)) { 679 if (iov_iter_rw(iter) == READ && ext4_should_dioread_nolock(inode)) {
680 /* 680 /*
681 * Nolock dioread optimization may be dynamically disabled 681 * Nolock dioread optimization may be dynamically disabled
682 * via ext4_inode_block_unlocked_dio(). Check inode's state 682 * via ext4_inode_block_unlocked_dio(). Check inode's state
@@ -707,7 +707,7 @@ locked:
707 ret = blockdev_direct_IO(iocb, inode, iter, offset, 707 ret = blockdev_direct_IO(iocb, inode, iter, offset,
708 ext4_get_block); 708 ext4_get_block);
709 709
710 if (unlikely((rw & WRITE) && ret < 0)) { 710 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
711 loff_t isize = i_size_read(inode); 711 loff_t isize = i_size_read(inode);
712 loff_t end = offset + count; 712 loff_t end = offset + count;
713 713
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 76b8cba5d041..cf6ba6536035 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2952,8 +2952,8 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
2952 * if the machine crashes during the write. 2952 * if the machine crashes during the write.
2953 * 2953 *
2954 */ 2954 */
2955static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, 2955static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
2956 struct iov_iter *iter, loff_t offset) 2956 loff_t offset)
2957{ 2957{
2958 struct file *file = iocb->ki_filp; 2958 struct file *file = iocb->ki_filp;
2959 struct inode *inode = file->f_mapping->host; 2959 struct inode *inode = file->f_mapping->host;
@@ -2966,8 +2966,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
2966 ext4_io_end_t *io_end = NULL; 2966 ext4_io_end_t *io_end = NULL;
2967 2967
2968 /* Use the old path for reads and writes beyond i_size. */ 2968 /* Use the old path for reads and writes beyond i_size. */
2969 if (rw != WRITE || final_size > inode->i_size) 2969 if (iov_iter_rw(iter) != WRITE || final_size > inode->i_size)
2970 return ext4_ind_direct_IO(rw, iocb, iter, offset); 2970 return ext4_ind_direct_IO(iocb, iter, offset);
2971 2971
2972 BUG_ON(iocb->private == NULL); 2972 BUG_ON(iocb->private == NULL);
2973 2973
@@ -2976,7 +2976,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
2976 * conversion. This also disallows race between truncate() and 2976 * conversion. This also disallows race between truncate() and
2977 * overwrite DIO as i_dio_count needs to be incremented under i_mutex. 2977 * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
2978 */ 2978 */
2979 if (rw == WRITE) 2979 if (iov_iter_rw(iter) == WRITE)
2980 atomic_inc(&inode->i_dio_count); 2980 atomic_inc(&inode->i_dio_count);
2981 2981
2982 /* If we do a overwrite dio, i_mutex locking can be released */ 2982 /* If we do a overwrite dio, i_mutex locking can be released */
@@ -3078,7 +3078,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3078 } 3078 }
3079 3079
3080retake_lock: 3080retake_lock:
3081 if (rw == WRITE) 3081 if (iov_iter_rw(iter) == WRITE)
3082 inode_dio_done(inode); 3082 inode_dio_done(inode);
3083 /* take i_mutex locking again if we do a ovewrite dio */ 3083 /* take i_mutex locking again if we do a ovewrite dio */
3084 if (overwrite) { 3084 if (overwrite) {
@@ -3107,12 +3107,12 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
3107 if (ext4_has_inline_data(inode)) 3107 if (ext4_has_inline_data(inode))
3108 return 0; 3108 return 0;
3109 3109
3110 trace_ext4_direct_IO_enter(inode, offset, count, rw); 3110 trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
3111 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) 3111 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3112 ret = ext4_ext_direct_IO(rw, iocb, iter, offset); 3112 ret = ext4_ext_direct_IO(iocb, iter, offset);
3113 else 3113 else
3114 ret = ext4_ind_direct_IO(rw, iocb, iter, offset); 3114 ret = ext4_ind_direct_IO(iocb, iter, offset);
3115 trace_ext4_direct_IO_exit(inode, offset, count, rw, ret); 3115 trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
3116 return ret; 3116 return ret;
3117} 3117}
3118 3118
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index e16adebcb9b6..ce25f62edfa7 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1118,12 +1118,12 @@ static int f2fs_write_end(struct file *file,
1118 return copied; 1118 return copied;
1119} 1119}
1120 1120
1121static int check_direct_IO(struct inode *inode, int rw, 1121static int check_direct_IO(struct inode *inode, struct iov_iter *iter,
1122 struct iov_iter *iter, loff_t offset) 1122 loff_t offset)
1123{ 1123{
1124 unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; 1124 unsigned blocksize_mask = inode->i_sb->s_blocksize - 1;
1125 1125
1126 if (rw == READ) 1126 if (iov_iter_rw(iter) == READ)
1127 return 0; 1127 return 0;
1128 1128
1129 if (offset & blocksize_mask) 1129 if (offset & blocksize_mask)
@@ -1151,19 +1151,19 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb,
1151 return err; 1151 return err;
1152 } 1152 }
1153 1153
1154 if (check_direct_IO(inode, rw, iter, offset)) 1154 if (check_direct_IO(inode, iter, offset))
1155 return 0; 1155 return 0;
1156 1156
1157 trace_f2fs_direct_IO_enter(inode, offset, count, rw); 1157 trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
1158 1158
1159 if (rw & WRITE) 1159 if (iov_iter_rw(iter) == WRITE)
1160 __allocate_data_blocks(inode, offset, count); 1160 __allocate_data_blocks(inode, offset, count);
1161 1161
1162 err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block); 1162 err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block);
1163 if (err < 0 && (rw & WRITE)) 1163 if (err < 0 && iov_iter_rw(iter) == WRITE)
1164 f2fs_write_failed(mapping, offset + count); 1164 f2fs_write_failed(mapping, offset + count);
1165 1165
1166 trace_f2fs_direct_IO_exit(inode, offset, count, rw, err); 1166 trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err);
1167 1167
1168 return err; 1168 return err;
1169} 1169}
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index a1a39f571e78..342d791b28db 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -255,7 +255,7 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
255 size_t count = iov_iter_count(iter); 255 size_t count = iov_iter_count(iter);
256 ssize_t ret; 256 ssize_t ret;
257 257
258 if (rw == WRITE) { 258 if (iov_iter_rw(iter) == WRITE) {
259 /* 259 /*
260 * FIXME: blockdev_direct_IO() doesn't use ->write_begin(), 260 * FIXME: blockdev_direct_IO() doesn't use ->write_begin(),
261 * so we need to update the ->mmu_private to block boundary. 261 * so we need to update the ->mmu_private to block boundary.
@@ -275,7 +275,7 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
275 * condition of fat_get_block() and ->truncate(). 275 * condition of fat_get_block() and ->truncate().
276 */ 276 */
277 ret = blockdev_direct_IO(iocb, inode, iter, offset, fat_get_block); 277 ret = blockdev_direct_IO(iocb, inode, iter, offset, fat_get_block);
278 if (ret < 0 && (rw & WRITE)) 278 if (ret < 0 && iov_iter_rw(iter) == WRITE)
279 fat_write_failed(mapping, offset + count); 279 fat_write_failed(mapping, offset + count);
280 280
281 return ret; 281 return ret;
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e1afdd7abf90..c1a67da6a8a0 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2800,11 +2800,11 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
2800 inode = file->f_mapping->host; 2800 inode = file->f_mapping->host;
2801 i_size = i_size_read(inode); 2801 i_size = i_size_read(inode);
2802 2802
2803 if ((rw == READ) && (offset > i_size)) 2803 if ((iov_iter_rw(iter) == READ) && (offset > i_size))
2804 return 0; 2804 return 0;
2805 2805
2806 /* optimization for short read */ 2806 /* optimization for short read */
2807 if (async_dio && rw != WRITE && offset + count > i_size) { 2807 if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) {
2808 if (offset >= i_size) 2808 if (offset >= i_size)
2809 return 0; 2809 return 0;
2810 count = min_t(loff_t, count, fuse_round_up(i_size - offset)); 2810 count = min_t(loff_t, count, fuse_round_up(i_size - offset));
@@ -2819,7 +2819,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
2819 io->bytes = -1; 2819 io->bytes = -1;
2820 io->size = 0; 2820 io->size = 0;
2821 io->offset = offset; 2821 io->offset = offset;
2822 io->write = (rw == WRITE); 2822 io->write = (iov_iter_rw(iter) == WRITE);
2823 io->err = 0; 2823 io->err = 0;
2824 io->file = file; 2824 io->file = file;
2825 /* 2825 /*
@@ -2834,13 +2834,14 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
2834 * to wait on real async I/O requests, so we must submit this request 2834 * to wait on real async I/O requests, so we must submit this request
2835 * synchronously. 2835 * synchronously.
2836 */ 2836 */
2837 if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE) 2837 if (!is_sync_kiocb(iocb) && (offset + count > i_size) &&
2838 iov_iter_rw(iter) == WRITE)
2838 io->async = false; 2839 io->async = false;
2839 2840
2840 if (io->async && is_sync_kiocb(iocb)) 2841 if (io->async && is_sync_kiocb(iocb))
2841 io->done = &wait; 2842 io->done = &wait;
2842 2843
2843 if (rw == WRITE) { 2844 if (iov_iter_rw(iter) == WRITE) {
2844 ret = generic_write_checks(file, &pos, &count, 0); 2845 ret = generic_write_checks(file, &pos, &count, 0);
2845 if (!ret) { 2846 if (!ret) {
2846 iov_iter_truncate(iter, count); 2847 iov_iter_truncate(iter, count);
@@ -2865,7 +2866,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
2865 2866
2866 kfree(io); 2867 kfree(io);
2867 2868
2868 if (rw == WRITE) { 2869 if (iov_iter_rw(iter) == WRITE) {
2869 if (ret > 0) 2870 if (ret > 0)
2870 fuse_write_update_size(inode, pos); 2871 fuse_write_update_size(inode, pos);
2871 else if (ret < 0 && offset + count > i_size) 2872 else if (ret < 0 && offset + count > i_size)
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 59983a18cab4..e22e6e686a11 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -1016,13 +1016,12 @@ out:
1016/** 1016/**
1017 * gfs2_ok_for_dio - check that dio is valid on this file 1017 * gfs2_ok_for_dio - check that dio is valid on this file
1018 * @ip: The inode 1018 * @ip: The inode
1019 * @rw: READ or WRITE
1020 * @offset: The offset at which we are reading or writing 1019 * @offset: The offset at which we are reading or writing
1021 * 1020 *
1022 * Returns: 0 (to ignore the i/o request and thus fall back to buffered i/o) 1021 * Returns: 0 (to ignore the i/o request and thus fall back to buffered i/o)
1023 * 1 (to accept the i/o request) 1022 * 1 (to accept the i/o request)
1024 */ 1023 */
1025static int gfs2_ok_for_dio(struct gfs2_inode *ip, int rw, loff_t offset) 1024static int gfs2_ok_for_dio(struct gfs2_inode *ip, loff_t offset)
1026{ 1025{
1027 /* 1026 /*
1028 * Should we return an error here? I can't see that O_DIRECT for 1027 * Should we return an error here? I can't see that O_DIRECT for
@@ -1061,7 +1060,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
1061 rv = gfs2_glock_nq(&gh); 1060 rv = gfs2_glock_nq(&gh);
1062 if (rv) 1061 if (rv)
1063 return rv; 1062 return rv;
1064 rv = gfs2_ok_for_dio(ip, rw, offset); 1063 rv = gfs2_ok_for_dio(ip, offset);
1065 if (rv != 1) 1064 if (rv != 1)
1066 goto out; /* dio not valid, fall back to buffered i/o */ 1065 goto out; /* dio not valid, fall back to buffered i/o */
1067 1066
@@ -1091,7 +1090,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
1091 rv = filemap_write_and_wait_range(mapping, lstart, end); 1090 rv = filemap_write_and_wait_range(mapping, lstart, end);
1092 if (rv) 1091 if (rv)
1093 goto out; 1092 goto out;
1094 if (rw == WRITE) 1093 if (iov_iter_rw(iter) == WRITE)
1095 truncate_inode_pages_range(mapping, lstart, end); 1094 truncate_inode_pages_range(mapping, lstart, end);
1096 } 1095 }
1097 1096
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index e92d175d1fd7..0085d527a55c 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -139,7 +139,7 @@ static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb,
139 * In case of error extending write may have instantiated a few 139 * In case of error extending write may have instantiated a few
140 * blocks outside i_size. Trim these off again. 140 * blocks outside i_size. Trim these off again.
141 */ 141 */
142 if (unlikely((rw & WRITE) && ret < 0)) { 142 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
143 loff_t isize = i_size_read(inode); 143 loff_t isize = i_size_read(inode);
144 loff_t end = offset + count; 144 loff_t end = offset + count;
145 145
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 2a98dc07c22c..afcde36b506b 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -137,7 +137,7 @@ static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb,
137 * In case of error extending write may have instantiated a few 137 * In case of error extending write may have instantiated a few
138 * blocks outside i_size. Trim these off again. 138 * blocks outside i_size. Trim these off again.
139 */ 139 */
140 if (unlikely((rw & WRITE) && ret < 0)) { 140 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
141 loff_t isize = i_size_read(inode); 141 loff_t isize = i_size_read(inode);
142 loff_t end = offset + count; 142 loff_t end = offset + count;
143 143
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index c20f7883543f..e7047b63ffc5 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -345,7 +345,7 @@ static ssize_t jfs_direct_IO(int rw, struct kiocb *iocb,
345 * In case of error extending write may have instantiated a few 345 * In case of error extending write may have instantiated a few
346 * blocks outside i_size. Trim these off again. 346 * blocks outside i_size. Trim these off again.
347 */ 347 */
348 if (unlikely((rw & WRITE) && ret < 0)) { 348 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
349 loff_t isize = i_size_read(inode); 349 loff_t isize = i_size_read(inode);
350 loff_t end = offset + count; 350 loff_t end = offset + count;
351 351
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index c3929fb2ab26..e8482b8f4830 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -267,7 +267,7 @@ ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t
267#else 267#else
268 VM_BUG_ON(iov_iter_count(iter) != PAGE_SIZE); 268 VM_BUG_ON(iov_iter_count(iter) != PAGE_SIZE);
269 269
270 if (rw == READ) 270 if (iov_iter_rw(iter) == READ)
271 return nfs_file_direct_read(iocb, iter, pos); 271 return nfs_file_direct_read(iocb, iter, pos);
272 return nfs_file_direct_write(iocb, iter, pos); 272 return nfs_file_direct_write(iocb, iter, pos);
273#endif /* CONFIG_NFS_SWAP */ 273#endif /* CONFIG_NFS_SWAP */
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 3727b8caa46e..4726f1493d5d 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -314,7 +314,7 @@ nilfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
314 size_t count = iov_iter_count(iter); 314 size_t count = iov_iter_count(iter);
315 ssize_t size; 315 ssize_t size;
316 316
317 if (rw == WRITE) 317 if (iov_iter_rw(iter) == WRITE)
318 return 0; 318 return 0;
319 319
320 /* Needs synchronization with the cleaner */ 320 /* Needs synchronization with the cleaner */
@@ -324,7 +324,7 @@ nilfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
324 * In case of error extending write may have instantiated a few 324 * In case of error extending write may have instantiated a few
325 * blocks outside i_size. Trim these off again. 325 * blocks outside i_size. Trim these off again.
326 */ 326 */
327 if (unlikely((rw & WRITE) && size < 0)) { 327 if (unlikely(iov_iter_rw(iter) == WRITE && size < 0)) {
328 loff_t isize = i_size_read(inode); 328 loff_t isize = i_size_read(inode);
329 loff_t end = offset + count; 329 loff_t end = offset + count;
330 330
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 68cb199fb2b6..0ee9474cca46 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -842,7 +842,7 @@ static ssize_t ocfs2_direct_IO(int rw,
842 if (i_size_read(inode) <= offset && !full_coherency) 842 if (i_size_read(inode) <= offset && !full_coherency)
843 return 0; 843 return 0;
844 844
845 if (rw == READ) 845 if (iov_iter_rw(iter) == READ)
846 return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, 846 return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
847 iter, offset, 847 iter, offset,
848 ocfs2_direct_IO_get_blocks, 848 ocfs2_direct_IO_get_blocks,
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index a51e9177b056..d61ab13244a8 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -3293,7 +3293,7 @@ static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb,
3293 * In case of error extending write may have instantiated a few 3293 * In case of error extending write may have instantiated a few
3294 * blocks outside i_size. Trim these off again. 3294 * blocks outside i_size. Trim these off again.
3295 */ 3295 */
3296 if (unlikely((rw & WRITE) && ret < 0)) { 3296 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
3297 loff_t isize = i_size_read(inode); 3297 loff_t isize = i_size_read(inode);
3298 loff_t end = offset + count; 3298 loff_t end = offset + count;
3299 3299
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 3adf49c01c19..a685aea93068 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -226,7 +226,7 @@ static ssize_t udf_direct_IO(int rw, struct kiocb *iocb,
226 ssize_t ret; 226 ssize_t ret;
227 227
228 ret = blockdev_direct_IO(iocb, inode, iter, offset, udf_get_block); 228 ret = blockdev_direct_IO(iocb, inode, iter, offset, udf_get_block);
229 if (unlikely(ret < 0 && (rw & WRITE))) 229 if (unlikely(ret < 0 && iov_iter_rw(iter) == WRITE))
230 udf_write_failed(mapping, offset + count); 230 udf_write_failed(mapping, offset + count);
231 return ret; 231 return ret;
232} 232}
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 5ca504c66e85..532d5279df2f 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -1503,7 +1503,7 @@ xfs_vm_direct_IO(
1503 struct inode *inode = iocb->ki_filp->f_mapping->host; 1503 struct inode *inode = iocb->ki_filp->f_mapping->host;
1504 struct block_device *bdev = xfs_find_bdev_for_inode(inode); 1504 struct block_device *bdev = xfs_find_bdev_for_inode(inode);
1505 1505
1506 if (rw & WRITE) { 1506 if (iov_iter_rw(iter) == WRITE) {
1507 return __blockdev_direct_IO(iocb, inode, bdev, iter, offset, 1507 return __blockdev_direct_IO(iocb, inode, bdev, iter, offset,
1508 xfs_get_blocks_direct, 1508 xfs_get_blocks_direct,
1509 xfs_end_io_direct_write, NULL, 1509 xfs_end_io_direct_write, NULL,