@@ -4422,7 +4422,7 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp,
if (ret < 0)
goto out_iov;
- init_sync_kiocb(&kiocb, file);
+ init_kiocb(&kiocb, file, READ);
kiocb.ki_pos = pos;
ret = btrfs_encoded_read(&kiocb, &iter, &args);
@@ -4523,7 +4523,7 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
if (ret < 0)
goto out_end_write;
- init_sync_kiocb(&kiocb, file);
+ init_kiocb(&kiocb, file, WRITE);
ret = kiocb_set_rw_flags(&kiocb, 0);
if (ret)
goto out_end_write;
@@ -382,7 +382,7 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo
struct iov_iter iter;
ssize_t ret;
- init_sync_kiocb(&kiocb, filp);
+ init_kiocb(&kiocb, filp, READ);
kiocb.ki_pos = (ppos ? *ppos : 0);
iov_iter_ubuf(&iter, ITER_DEST, buf, len);
@@ -422,7 +422,7 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
if (unlikely(!file->f_op->read_iter || file->f_op->read))
return warn_unsupported(file, "read");
- init_sync_kiocb(&kiocb, file);
+ init_kiocb(&kiocb, file, READ);
kiocb.ki_pos = pos ? *pos : 0;
iov_iter_kvec(&iter, ITER_DEST, &iov, 1, iov.iov_len);
ret = file->f_op->read_iter(&kiocb, &iter);
@@ -484,7 +484,7 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t
struct iov_iter iter;
ssize_t ret;
- init_sync_kiocb(&kiocb, filp);
+ init_kiocb(&kiocb, filp, WRITE);
kiocb.ki_pos = (ppos ? *ppos : 0);
iov_iter_ubuf(&iter, ITER_SOURCE, (void __user *)buf, len);
@@ -512,7 +512,7 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po
if (unlikely(!file->f_op->write_iter || file->f_op->write))
return warn_unsupported(file, "write");
- init_sync_kiocb(&kiocb, file);
+ init_kiocb(&kiocb, file, WRITE);
kiocb.ki_pos = pos ? *pos : 0;
ret = file->f_op->write_iter(&kiocb, from);
if (ret > 0) {
@@ -723,7 +723,7 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
struct kiocb kiocb;
ssize_t ret;
- init_sync_kiocb(&kiocb, filp);
+ init_kiocb(&kiocb, filp, type);
ret = kiocb_set_rw_flags(&kiocb, flags);
if (ret)
return ret;
@@ -155,7 +155,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
struct iov_iter iter;
ssize_t ret;
- init_sync_kiocb(&kiocb, file);
+ init_kiocb(&kiocb, file, READ);
iov_iter_init(&iter, ITER_DEST, &iov, 1, size);
kiocb.ki_pos = *ppos;
@@ -362,7 +362,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos,
/* Do the I/O */
iov_iter_bvec(&to, ITER_DEST, bv, npages, len);
- init_sync_kiocb(&kiocb, in);
+ init_kiocb(&kiocb, in, READ);
kiocb.ki_pos = *ppos;
ret = call_read_iter(in, &kiocb, &to);
@@ -2017,13 +2017,17 @@ static inline bool HAS_UNMAPPED_ID(struct mnt_idmap *idmap,
!vfsgid_valid(i_gid_into_vfsgid(idmap, inode));
}
-static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
+static inline void init_kiocb(struct kiocb *kiocb, struct file *filp,
+ unsigned int rw)
{
*kiocb = (struct kiocb) {
.ki_filp = filp,
.ki_flags = filp->f_iocb_flags,
.ki_ioprio = get_current_ioprio(),
};
+
+ if (rw == WRITE)
+ kiocb->ki_flags |= IOCB_WRITE;
}
static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
@@ -2905,7 +2905,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos,
if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes))
return 0;
- init_sync_kiocb(&iocb, in);
+ init_kiocb(&iocb, in, READ);
iocb.ki_pos = *ppos;
/* Work out how much data we can actually add into the pipe */
@@ -312,7 +312,7 @@ static void swap_writepage_fs(struct page *page, struct writeback_control *wbc)
}
if (!sio) {
sio = mempool_alloc(sio_pool, GFP_NOIO);
- init_sync_kiocb(&sio->iocb, swap_file);
+ init_kiocb(&sio->iocb, swap_file, WRITE);
sio->iocb.ki_complete = sio_write_complete;
sio->iocb.ki_pos = pos;
sio->pages = 0;
@@ -443,7 +443,7 @@ static void swap_readpage_fs(struct page *page,
}
if (!sio) {
sio = mempool_alloc(sio_pool, GFP_KERNEL);
- init_sync_kiocb(&sio->iocb, sis->swap_file);
+ init_kiocb(&sio->iocb, sis->swap_file, READ);
sio->iocb.ki_pos = pos;
sio->iocb.ki_complete = sio_read_complete;
sio->pages = 0;
IOCB_WRITE is set by aio, io_uring and cachefiles before submitting a write operation to the VFS, but it isn't set by, say, the write() system call. Fix this by adding an extra argument to init_sync_kiocb() to indicate the direction and setting that to READ or WRITE, which will cause IOCB_WRITE to be set as appropriate. Whilst we're at it, rename init_sync_kiocb() to init_kiocb(). This will allow drivers to use IOCB_WRITE instead of the iterator data source to determine the I/O direction. Signed-off-by: David Howells <dhowells@redhat.com> cc: Christoph Hellwig <hch@lst.de> cc: Jens Axboe <axboe@kernel.dk> cc: Christian Brauner <christian@brauner.io> cc: Alexander Viro <viro@zeniv.linux.org.uk> cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- fs/btrfs/ioctl.c | 4 ++-- fs/read_write.c | 10 +++++----- fs/seq_file.c | 2 +- fs/splice.c | 2 +- include/linux/fs.h | 6 +++++- mm/filemap.c | 2 +- mm/page_io.c | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-)