Skip to content

Commit

Permalink
direct_IO: use iov_iter_rw() instead of rw everywhere
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
osandov authored and Al Viro committed Apr 12, 2015
1 parent a95cd63 commit 6f67376
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 69 deletions.
18 changes: 9 additions & 9 deletions drivers/staging/lustre/lustre/llite/rw26.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
* size changing by concurrent truncates and writes.
* 1. Need inode mutex to operate transient pages.
*/
if (rw == READ)
if (iov_iter_rw(iter) == READ)
mutex_lock(&inode->i_mutex);

LASSERT(obj->cob_transient_pages == 0);
Expand All @@ -408,7 +408,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
size_t offs;

count = min_t(size_t, iov_iter_count(iter), size);
if (rw == READ) {
if (iov_iter_rw(iter) == READ) {
if (file_offset >= i_size_read(inode))
break;
if (file_offset + count > i_size_read(inode))
Expand All @@ -418,11 +418,11 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
result = iov_iter_get_pages_alloc(iter, &pages, count, &offs);
if (likely(result > 0)) {
int n = DIV_ROUND_UP(result + offs, PAGE_SIZE);
result = ll_direct_IO_26_seg(env, io, rw, inode,
file->f_mapping,
result, file_offset,
pages, n);
ll_free_user_pages(pages, n, rw==READ);
result = ll_direct_IO_26_seg(env, io, iov_iter_rw(iter),
inode, file->f_mapping,
result, file_offset, pages,
n);
ll_free_user_pages(pages, n, iov_iter_rw(iter) == READ);
}
if (unlikely(result <= 0)) {
/* If we can't allocate a large enough buffer
Expand All @@ -449,11 +449,11 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
}
out:
LASSERT(obj->cob_transient_pages == 0);
if (rw == READ)
if (iov_iter_rw(iter) == READ)
mutex_unlock(&inode->i_mutex);

if (tot_bytes > 0) {
if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
struct lov_stripe_md *lsm;

lsm = ccc_inode_lsm_get(inode);
Expand Down
2 changes: 1 addition & 1 deletion fs/9p/vfs_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ v9fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos)
struct file *file = iocb->ki_filp;
ssize_t n;
int err = 0;
if (rw & WRITE) {
if (iov_iter_rw(iter) == WRITE) {
n = p9_client_write(file->private_data, pos, iter, &err);
if (n) {
struct inode *inode = file_inode(file);
Expand Down
4 changes: 2 additions & 2 deletions fs/affs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ affs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
size_t count = iov_iter_count(iter);
ssize_t ret;

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
loff_t size = offset + count;

if (AFFS_I(inode)->mmu_private < size)
return 0;
}

ret = blockdev_direct_IO(iocb, inode, iter, offset, affs_get_block);
if (ret < 0 && (rw & WRITE))
if (ret < 0 && iov_iter_rw(iter) == WRITE)
affs_write_failed(mapping, offset + count);
return ret;
}
Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8081,7 +8081,7 @@ static void btrfs_submit_direct(int rw, struct bio *dio_bio,
bio_endio(dio_bio, ret);
}

static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb,
static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb,
const struct iov_iter *iter, loff_t offset)
{
int seg;
Expand All @@ -8096,7 +8096,7 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io
goto out;

/* If this is a write we don't need to check anymore */
if (rw & WRITE)
if (iov_iter_rw(iter) == WRITE)
return 0;
/*
* Check to make sure we don't have duplicate iov_base's in this
Expand Down Expand Up @@ -8126,7 +8126,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
bool relock = false;
ssize_t ret;

if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iter, offset))
if (check_direct_IO(BTRFS_I(inode)->root, iocb, iter, offset))
return 0;

atomic_inc(&inode->i_dio_count);
Expand All @@ -8144,7 +8144,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
filemap_fdatawrite_range(inode->i_mapping, offset,
offset + count - 1);

if (rw & WRITE) {
if (iov_iter_rw(iter) == WRITE) {
/*
* If the write DIO is beyond the EOF, we need update
* the isize, but it is protected by i_mutex. So we can
Expand Down Expand Up @@ -8178,7 +8178,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev,
iter, offset, btrfs_get_blocks_direct, NULL,
btrfs_submit_direct, flags);
if (rw & WRITE) {
if (iov_iter_rw(iter) == WRITE) {
current->journal_info = NULL;
if (ret < 0 && ret != -EIOCBQUEUED)
btrfs_delalloc_release_space(inode, count);
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ ext2_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
else
ret = blockdev_direct_IO(iocb, inode, iter, offset,
ext2_get_block);
if (ret < 0 && (rw & WRITE))
if (ret < 0 && iov_iter_rw(iter) == WRITE)
ext2_write_failed(mapping, offset + count);
return ret;
}
Expand Down
8 changes: 4 additions & 4 deletions fs/ext3/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,9 +1832,9 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
size_t count = iov_iter_count(iter);
int retries = 0;

trace_ext3_direct_IO_enter(inode, offset, count, rw);
trace_ext3_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
loff_t final_size = offset + count;

if (final_size > inode->i_size) {
Expand All @@ -1861,7 +1861,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
* In case of error extending write may have instantiated a few
* blocks outside i_size. Trim these off again.
*/
if (unlikely((rw & WRITE) && ret < 0)) {
if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
loff_t isize = i_size_read(inode);
loff_t end = offset + count;

Expand Down Expand Up @@ -1908,7 +1908,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
ret = err;
}
out:
trace_ext3_direct_IO_exit(inode, offset, count, rw, ret);
trace_ext3_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -2152,8 +2152,8 @@ extern void ext4_da_update_reserve_space(struct inode *inode,
/* indirect.c */
extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
struct iov_iter *iter, loff_t offset);
extern ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
loff_t offset);
extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
extern void ext4_ind_truncate(handle_t *, struct inode *inode);
Expand Down
10 changes: 5 additions & 5 deletions fs/ext4/indirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
* crashes then stale disk data _may_ be exposed inside the file. But current
* VFS code falls back into buffered path in that case so we are safe.
*/
ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
struct iov_iter *iter, loff_t offset)
ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
loff_t offset)
{
struct file *file = iocb->ki_filp;
struct inode *inode = file->f_mapping->host;
Expand All @@ -654,7 +654,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
size_t count = iov_iter_count(iter);
int retries = 0;

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
loff_t final_size = offset + count;

if (final_size > inode->i_size) {
Expand All @@ -676,7 +676,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
}

retry:
if (rw == READ && ext4_should_dioread_nolock(inode)) {
if (iov_iter_rw(iter) == READ && ext4_should_dioread_nolock(inode)) {
/*
* Nolock dioread optimization may be dynamically disabled
* via ext4_inode_block_unlocked_dio(). Check inode's state
Expand Down Expand Up @@ -707,7 +707,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
ret = blockdev_direct_IO(iocb, inode, iter, offset,
ext4_get_block);

if (unlikely((rw & WRITE) && ret < 0)) {
if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
loff_t isize = i_size_read(inode);
loff_t end = offset + count;

Expand Down
20 changes: 10 additions & 10 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2952,8 +2952,8 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
* if the machine crashes during the write.
*
*/
static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
struct iov_iter *iter, loff_t offset)
static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
loff_t offset)
{
struct file *file = iocb->ki_filp;
struct inode *inode = file->f_mapping->host;
Expand All @@ -2966,8 +2966,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
ext4_io_end_t *io_end = NULL;

/* Use the old path for reads and writes beyond i_size. */
if (rw != WRITE || final_size > inode->i_size)
return ext4_ind_direct_IO(rw, iocb, iter, offset);
if (iov_iter_rw(iter) != WRITE || final_size > inode->i_size)
return ext4_ind_direct_IO(iocb, iter, offset);

BUG_ON(iocb->private == NULL);

Expand All @@ -2976,7 +2976,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
* conversion. This also disallows race between truncate() and
* overwrite DIO as i_dio_count needs to be incremented under i_mutex.
*/
if (rw == WRITE)
if (iov_iter_rw(iter) == WRITE)
atomic_inc(&inode->i_dio_count);

/* If we do a overwrite dio, i_mutex locking can be released */
Expand Down Expand Up @@ -3078,7 +3078,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
}

retake_lock:
if (rw == WRITE)
if (iov_iter_rw(iter) == WRITE)
inode_dio_done(inode);
/* take i_mutex locking again if we do a ovewrite dio */
if (overwrite) {
Expand Down Expand Up @@ -3107,12 +3107,12 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
if (ext4_has_inline_data(inode))
return 0;

trace_ext4_direct_IO_enter(inode, offset, count, rw);
trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
ret = ext4_ext_direct_IO(rw, iocb, iter, offset);
ret = ext4_ext_direct_IO(iocb, iter, offset);
else
ret = ext4_ind_direct_IO(rw, iocb, iter, offset);
trace_ext4_direct_IO_exit(inode, offset, count, rw, ret);
ret = ext4_ind_direct_IO(iocb, iter, offset);
trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
return ret;
}

Expand Down
16 changes: 8 additions & 8 deletions fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,12 +1118,12 @@ static int f2fs_write_end(struct file *file,
return copied;
}

static int check_direct_IO(struct inode *inode, int rw,
struct iov_iter *iter, loff_t offset)
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 (rw == READ)
if (iov_iter_rw(iter) == READ)
return 0;

if (offset & blocksize_mask)
Expand Down Expand Up @@ -1151,19 +1151,19 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb,
return err;
}

if (check_direct_IO(inode, rw, iter, offset))
if (check_direct_IO(inode, iter, offset))
return 0;

trace_f2fs_direct_IO_enter(inode, offset, count, rw);
trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));

if (rw & WRITE)
if (iov_iter_rw(iter) == WRITE)
__allocate_data_blocks(inode, offset, count);

err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block);
if (err < 0 && (rw & WRITE))
if (err < 0 && iov_iter_rw(iter) == WRITE)
f2fs_write_failed(mapping, offset + count);

trace_f2fs_direct_IO_exit(inode, offset, count, rw, err);
trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err);

return err;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
size_t count = iov_iter_count(iter);
ssize_t ret;

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
/*
* FIXME: blockdev_direct_IO() doesn't use ->write_begin(),
* so we need to update the ->mmu_private to block boundary.
Expand All @@ -275,7 +275,7 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
* condition of fat_get_block() and ->truncate().
*/
ret = blockdev_direct_IO(iocb, inode, iter, offset, fat_get_block);
if (ret < 0 && (rw & WRITE))
if (ret < 0 && iov_iter_rw(iter) == WRITE)
fat_write_failed(mapping, offset + count);

return ret;
Expand Down
13 changes: 7 additions & 6 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2800,11 +2800,11 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
inode = file->f_mapping->host;
i_size = i_size_read(inode);

if ((rw == READ) && (offset > i_size))
if ((iov_iter_rw(iter) == READ) && (offset > i_size))
return 0;

/* optimization for short read */
if (async_dio && rw != WRITE && offset + count > i_size) {
if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) {
if (offset >= i_size)
return 0;
count = min_t(loff_t, count, fuse_round_up(i_size - offset));
Expand All @@ -2819,7 +2819,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
io->bytes = -1;
io->size = 0;
io->offset = offset;
io->write = (rw == WRITE);
io->write = (iov_iter_rw(iter) == WRITE);
io->err = 0;
io->file = file;
/*
Expand All @@ -2834,13 +2834,14 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
* to wait on real async I/O requests, so we must submit this request
* synchronously.
*/
if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE)
if (!is_sync_kiocb(iocb) && (offset + count > i_size) &&
iov_iter_rw(iter) == WRITE)
io->async = false;

if (io->async && is_sync_kiocb(iocb))
io->done = &wait;

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
ret = generic_write_checks(file, &pos, &count, 0);
if (!ret) {
iov_iter_truncate(iter, count);
Expand All @@ -2865,7 +2866,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,

kfree(io);

if (rw == WRITE) {
if (iov_iter_rw(iter) == WRITE) {
if (ret > 0)
fuse_write_update_size(inode, pos);
else if (ret < 0 && offset + count > i_size)
Expand Down
Loading

0 comments on commit 6f67376

Please sign in to comment.