From 251b42a1dc641fac3fe412515233d60456180011 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:46 +0300 Subject: fs: remove do_readv_writev opencode it in both callers to simplify the call stack a bit. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/read_write.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'fs') diff --git a/fs/read_write.c b/fs/read_write.c index 19d4d88fa285..94cb71058098 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -951,51 +951,50 @@ out: return ret; } -static ssize_t do_readv_writev(int type, struct file *file, - const struct iovec __user *uvector, - unsigned long nr_segs, loff_t *pos, - int flags) +ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, + unsigned long vlen, loff_t *pos, int flags) { struct iovec iovstack[UIO_FASTIOV]; struct iovec *iov = iovstack; struct iov_iter iter; ssize_t ret; - ret = import_iovec(type, uvector, nr_segs, - ARRAY_SIZE(iovstack), &iov, &iter); - if (ret < 0) - return ret; - - ret = __do_readv_writev(type, file, &iter, pos, flags); - kfree(iov); - - return ret; -} - -ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, - unsigned long vlen, loff_t *pos, int flags) -{ if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!(file->f_mode & FMODE_CAN_READ)) return -EINVAL; - return do_readv_writev(READ, file, vec, vlen, pos, flags); -} + ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); + if (ret < 0) + return ret; + ret = __do_readv_writev(READ, file, &iter, pos, flags); + kfree(iov); + return ret; +} EXPORT_SYMBOL(vfs_readv); ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, unsigned long vlen, loff_t *pos, int flags) { + struct iovec iovstack[UIO_FASTIOV]; + struct iovec *iov = iovstack; + struct iov_iter iter; + ssize_t ret; + if (!(file->f_mode & FMODE_WRITE)) return -EBADF; if (!(file->f_mode & FMODE_CAN_WRITE)) return -EINVAL; - return do_readv_writev(WRITE, file, vec, vlen, pos, flags); -} + ret = import_iovec(WRITE, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); + if (ret < 0) + return ret; + ret = __do_readv_writev(WRITE, file, &iter, pos, flags); + kfree(iov); + return ret; +} EXPORT_SYMBOL(vfs_writev); static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec, -- cgit v1.2.3 From 26c87fb7d10dadc59a475c7809adc05303bf951e Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:47 +0300 Subject: fs: remove do_compat_readv_writev opencode it in both callers to simplify the call stack a bit. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/read_write.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'fs') diff --git a/fs/read_write.c b/fs/read_write.c index 94cb71058098..5cbdf23d924f 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1142,32 +1142,13 @@ SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec, } #ifdef CONFIG_COMPAT - -static ssize_t compat_do_readv_writev(int type, struct file *file, - const struct compat_iovec __user *uvector, - unsigned long nr_segs, loff_t *pos, - int flags) -{ - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; - struct iov_iter iter; - ssize_t ret; - - ret = compat_import_iovec(type, uvector, nr_segs, - UIO_FASTIOV, &iov, &iter); - if (ret < 0) - return ret; - - ret = __do_readv_writev(type, file, &iter, pos, flags); - kfree(iov); - - return ret; -} - static size_t compat_readv(struct file *file, const struct compat_iovec __user *vec, unsigned long vlen, loff_t *pos, int flags) { + struct iovec iovstack[UIO_FASTIOV]; + struct iovec *iov = iovstack; + struct iov_iter iter; ssize_t ret = -EBADF; if (!(file->f_mode & FMODE_READ)) @@ -1177,8 +1158,11 @@ static size_t compat_readv(struct file *file, if (!(file->f_mode & FMODE_CAN_READ)) goto out; - ret = compat_do_readv_writev(READ, file, vec, vlen, pos, flags); - + ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter); + if (ret < 0) + goto out; + ret = __do_readv_writev(READ, file, &iter, pos, flags); + kfree(iov); out: if (ret > 0) add_rchar(current, ret); @@ -1275,6 +1259,9 @@ static size_t compat_writev(struct file *file, const struct compat_iovec __user *vec, unsigned long vlen, loff_t *pos, int flags) { + struct iovec iovstack[UIO_FASTIOV]; + struct iovec *iov = iovstack; + struct iov_iter iter; ssize_t ret = -EBADF; if (!(file->f_mode & FMODE_WRITE)) @@ -1284,8 +1271,11 @@ static size_t compat_writev(struct file *file, if (!(file->f_mode & FMODE_CAN_WRITE)) goto out; - ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos, flags); - + ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter); + if (ret < 0) + goto out; + ret = __do_readv_writev(WRITE, file, &iter, pos, flags); + kfree(iov); out: if (ret > 0) add_wchar(current, ret); -- cgit v1.2.3 From 19c735868dd018fd432d0df43aaf2d5ecb7c1256 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:48 +0300 Subject: fs: remove __do_readv_writev Split it into one helper each for reads vs writes. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/read_write.c | 60 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'fs') diff --git a/fs/read_write.c b/fs/read_write.c index 5cbdf23d924f..f453c9a485b9 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -916,8 +916,8 @@ out: } #endif -static ssize_t __do_readv_writev(int type, struct file *file, - struct iov_iter *iter, loff_t *pos, int flags) +static ssize_t do_iter_read(struct file *file, struct iov_iter *iter, + loff_t *pos, int flags) { size_t tot_len; ssize_t ret = 0; @@ -925,29 +925,41 @@ static ssize_t __do_readv_writev(int type, struct file *file, tot_len = iov_iter_count(iter); if (!tot_len) goto out; - ret = rw_verify_area(type, file, pos, tot_len); + ret = rw_verify_area(READ, file, pos, tot_len); if (ret < 0) - goto out; - - if (type != READ) - file_start_write(file); + return ret; - if ((type == READ && file->f_op->read_iter) || - (type == WRITE && file->f_op->write_iter)) - ret = do_iter_readv_writev(file, iter, pos, type, flags); + if (file->f_op->read_iter) + ret = do_iter_readv_writev(file, iter, pos, READ, flags); else - ret = do_loop_readv_writev(file, iter, pos, type, flags); + ret = do_loop_readv_writev(file, iter, pos, READ, flags); +out: + if (ret >= 0) + fsnotify_access(file); + return ret; +} - if (type != READ) - file_end_write(file); +static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, + loff_t *pos, int flags) +{ + size_t tot_len; + ssize_t ret = 0; -out: - if ((ret + (type == READ)) > 0) { - if (type == READ) - fsnotify_access(file); - else - fsnotify_modify(file); - } + tot_len = iov_iter_count(iter); + if (!tot_len) + return 0; + ret = rw_verify_area(WRITE, file, pos, tot_len); + if (ret < 0) + return ret; + + file_start_write(file); + if (file->f_op->write_iter) + ret = do_iter_readv_writev(file, iter, pos, WRITE, flags); + else + ret = do_loop_readv_writev(file, iter, pos, WRITE, flags); + file_end_write(file); + if (ret > 0) + fsnotify_modify(file); return ret; } @@ -968,7 +980,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, if (ret < 0) return ret; - ret = __do_readv_writev(READ, file, &iter, pos, flags); + ret = do_iter_read(file, &iter, pos, flags); kfree(iov); return ret; } @@ -991,7 +1003,7 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, if (ret < 0) return ret; - ret = __do_readv_writev(WRITE, file, &iter, pos, flags); + ret = do_iter_write(file, &iter, pos, flags); kfree(iov); return ret; } @@ -1161,7 +1173,7 @@ static size_t compat_readv(struct file *file, ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter); if (ret < 0) goto out; - ret = __do_readv_writev(READ, file, &iter, pos, flags); + ret = do_iter_read(file, &iter, pos, flags); kfree(iov); out: if (ret > 0) @@ -1274,7 +1286,7 @@ static size_t compat_writev(struct file *file, ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter); if (ret < 0) goto out; - ret = __do_readv_writev(WRITE, file, &iter, pos, flags); + ret = do_iter_write(file, &iter, pos, flags); kfree(iov); out: if (ret > 0) -- cgit v1.2.3 From edab5fe38c2c17a7d7ea5f82e1d9503bfc79a8ac Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:49 +0300 Subject: fs: move more code into do_iter_read/do_iter_write The checks for the permissions and can read / write flags are common for the callers. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/read_write.c | 73 ++++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 45 deletions(-) (limited to 'fs') diff --git a/fs/read_write.c b/fs/read_write.c index f453c9a485b9..64b61a032a56 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -922,6 +922,11 @@ static ssize_t do_iter_read(struct file *file, struct iov_iter *iter, size_t tot_len; ssize_t ret = 0; + if (!(file->f_mode & FMODE_READ)) + return -EBADF; + if (!(file->f_mode & FMODE_CAN_READ)) + return -EINVAL; + tot_len = iov_iter_count(iter); if (!tot_len) goto out; @@ -945,6 +950,11 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, size_t tot_len; ssize_t ret = 0; + if (!(file->f_mode & FMODE_WRITE)) + return -EBADF; + if (!(file->f_mode & FMODE_CAN_WRITE)) + return -EINVAL; + tot_len = iov_iter_count(iter); if (!tot_len) return 0; @@ -971,17 +981,12 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, struct iov_iter iter; ssize_t ret; - if (!(file->f_mode & FMODE_READ)) - return -EBADF; - if (!(file->f_mode & FMODE_CAN_READ)) - return -EINVAL; - ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); - if (ret < 0) - return ret; + if (ret >= 0) { + ret = do_iter_read(file, &iter, pos, flags); + kfree(iov); + } - ret = do_iter_read(file, &iter, pos, flags); - kfree(iov); return ret; } EXPORT_SYMBOL(vfs_readv); @@ -994,17 +999,11 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, struct iov_iter iter; ssize_t ret; - if (!(file->f_mode & FMODE_WRITE)) - return -EBADF; - if (!(file->f_mode & FMODE_CAN_WRITE)) - return -EINVAL; - ret = import_iovec(WRITE, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); - if (ret < 0) - return ret; - - ret = do_iter_write(file, &iter, pos, flags); - kfree(iov); + if (ret >= 0) { + ret = do_iter_write(file, &iter, pos, flags); + kfree(iov); + } return ret; } EXPORT_SYMBOL(vfs_writev); @@ -1161,21 +1160,13 @@ static size_t compat_readv(struct file *file, struct iovec iovstack[UIO_FASTIOV]; struct iovec *iov = iovstack; struct iov_iter iter; - ssize_t ret = -EBADF; - - if (!(file->f_mode & FMODE_READ)) - goto out; - - ret = -EINVAL; - if (!(file->f_mode & FMODE_CAN_READ)) - goto out; + ssize_t ret; ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter); - if (ret < 0) - goto out; - ret = do_iter_read(file, &iter, pos, flags); - kfree(iov); -out: + if (ret >= 0) { + ret = do_iter_read(file, &iter, pos, flags); + kfree(iov); + } if (ret > 0) add_rchar(current, ret); inc_syscr(current); @@ -1274,21 +1265,13 @@ static size_t compat_writev(struct file *file, struct iovec iovstack[UIO_FASTIOV]; struct iovec *iov = iovstack; struct iov_iter iter; - ssize_t ret = -EBADF; - - if (!(file->f_mode & FMODE_WRITE)) - goto out; - - ret = -EINVAL; - if (!(file->f_mode & FMODE_CAN_WRITE)) - goto out; + ssize_t ret; ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter); - if (ret < 0) - goto out; - ret = do_iter_write(file, &iter, pos, flags); - kfree(iov); -out: + if (ret >= 0) { + ret = do_iter_write(file, &iter, pos, flags); + kfree(iov); + } if (ret > 0) add_wchar(current, ret); inc_syscw(current); -- cgit v1.2.3 From 18e9710ee59ce3bd2a2512ddcd3f7ceebe8b8d17 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:51 +0300 Subject: fs: implement vfs_iter_read using do_iter_read De-dupliate some code and allow for passing the flags argument to vfs_iter_read. Additional it properly updates atime now. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- drivers/block/loop.c | 4 ++-- drivers/target/target_core_file.c | 2 +- fs/coda/file.c | 2 +- fs/read_write.c | 29 +++++++++-------------------- include/linux/fs.h | 3 ++- 5 files changed, 15 insertions(+), 25 deletions(-) (limited to 'fs') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ebbd0c3fe0ed..b64649bec64e 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -342,7 +342,7 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq, rq_for_each_segment(bvec, rq, iter) { iov_iter_bvec(&i, ITER_BVEC, &bvec, 1, bvec.bv_len); - len = vfs_iter_read(lo->lo_backing_file, &i, &pos); + len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0); if (len < 0) return len; @@ -383,7 +383,7 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq, b.bv_len = bvec.bv_len; iov_iter_bvec(&i, ITER_BVEC, &b, 1, b.bv_len); - len = vfs_iter_read(lo->lo_backing_file, &i, &pos); + len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0); if (len < 0) { ret = len; goto out_free_page; diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 73b8f93a5fef..2befc0d7fdb1 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -275,7 +275,7 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd, if (is_write) ret = vfs_iter_write(fd, &iter, &pos); else - ret = vfs_iter_read(fd, &iter, &pos); + ret = vfs_iter_read(fd, &iter, &pos, 0); if (is_write) { if (ret < 0 || ret != data_length) { diff --git a/fs/coda/file.c b/fs/coda/file.c index 9d956cd6d46f..f1102822bcfd 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -34,7 +34,7 @@ coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to) BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); - return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos); + return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0); } static ssize_t diff --git a/fs/read_write.c b/fs/read_write.c index 64b61a032a56..4dab30b62f0e 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -356,26 +356,6 @@ out_putf: } #endif -ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos) -{ - struct kiocb kiocb; - ssize_t ret; - - if (!file->f_op->read_iter) - return -EINVAL; - - init_sync_kiocb(&kiocb, file); - kiocb.ki_pos = *ppos; - - iter->type |= READ; - ret = call_read_iter(file, &kiocb, iter); - BUG_ON(ret == -EIOCBQUEUED); - if (ret > 0) - *ppos = kiocb.ki_pos; - return ret; -} -EXPORT_SYMBOL(vfs_iter_read); - ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos) { struct kiocb kiocb; @@ -944,6 +924,15 @@ out: return ret; } +ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, + int flags) +{ + if (!file->f_op->read_iter) + return -EINVAL; + return do_iter_read(file, iter, ppos, flags); +} +EXPORT_SYMBOL(vfs_iter_read); + static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, loff_t *pos, int flags) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 803e5a9b2654..3f6a4f4efb32 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2789,7 +2789,8 @@ extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *); extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t); -ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos); +ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, + int flags); ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos); /* fs/block_dev.c */ -- cgit v1.2.3 From abbb65899aecfc97bda64b6816d1e501754cfe1f Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:52 +0300 Subject: fs: implement vfs_iter_write using do_iter_write De-dupliate some code and allow for passing the flags argument to vfs_iter_write. Additionally it now properly updates timestamps. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- drivers/block/loop.c | 2 +- drivers/target/target_core_file.c | 4 ++-- fs/coda/file.c | 2 +- fs/read_write.c | 29 +++++++++-------------------- fs/splice.c | 2 +- include/linux/fs.h | 3 ++- 6 files changed, 16 insertions(+), 26 deletions(-) (limited to 'fs') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index b64649bec64e..2a0d997efda4 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -266,7 +266,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos) iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len); file_start_write(file); - bw = vfs_iter_write(file, &i, ppos); + bw = vfs_iter_write(file, &i, ppos, 0); file_end_write(file); if (likely(bw == bvec->bv_len)) diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 2befc0d7fdb1..e921948415c7 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -273,7 +273,7 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd, iov_iter_bvec(&iter, ITER_BVEC, bvec, sgl_nents, len); if (is_write) - ret = vfs_iter_write(fd, &iter, &pos); + ret = vfs_iter_write(fd, &iter, &pos, 0); else ret = vfs_iter_read(fd, &iter, &pos, 0); @@ -409,7 +409,7 @@ fd_execute_write_same(struct se_cmd *cmd) } iov_iter_bvec(&iter, ITER_BVEC, bvec, nolb, len); - ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos); + ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, 0); kfree(bvec); if (ret < 0 || ret != len) { diff --git a/fs/coda/file.c b/fs/coda/file.c index f1102822bcfd..363402fcb3ed 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -51,7 +51,7 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) host_file = cfi->cfi_container; file_start_write(host_file); inode_lock(coda_inode); - ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos); + ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0); coda_inode->i_size = file_inode(host_file)->i_size; coda_inode->i_blocks = (coda_inode->i_size + 511) >> 9; coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode); diff --git a/fs/read_write.c b/fs/read_write.c index 4dab30b62f0e..acfd3dc63d57 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -356,26 +356,6 @@ out_putf: } #endif -ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos) -{ - struct kiocb kiocb; - ssize_t ret; - - if (!file->f_op->write_iter) - return -EINVAL; - - init_sync_kiocb(&kiocb, file); - kiocb.ki_pos = *ppos; - - iter->type |= WRITE; - ret = call_write_iter(file, &kiocb, iter); - BUG_ON(ret == -EIOCBQUEUED); - if (ret > 0) - *ppos = kiocb.ki_pos; - return ret; -} -EXPORT_SYMBOL(vfs_iter_write); - int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count) { struct inode *inode; @@ -962,6 +942,15 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, return ret; } +ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos, + int flags) +{ + if (!file->f_op->write_iter) + return -EINVAL; + return do_iter_write(file, iter, ppos, flags); +} +EXPORT_SYMBOL(vfs_iter_write); + ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, unsigned long vlen, loff_t *pos, int flags) { diff --git a/fs/splice.c b/fs/splice.c index 540c4a44756c..ae41201d0325 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -762,7 +762,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, iov_iter_bvec(&from, ITER_BVEC | WRITE, array, n, sd.total_len - left); - ret = vfs_iter_write(out, &from, &sd.pos); + ret = vfs_iter_write(out, &from, &sd.pos, 0); if (ret <= 0) break; diff --git a/include/linux/fs.h b/include/linux/fs.h index 3f6a4f4efb32..c67f1f8ee789 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2791,7 +2791,8 @@ extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t); ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, int flags); -ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos); +ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos, + int flags); /* fs/block_dev.c */ extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to); -- cgit v1.2.3 From 73da852e3831bdc7a38d8d5fba178f35c923b264 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:53 +0300 Subject: nfsd: use vfs_iter_read/write Instead of messing with the address limit to use vfs_read/vfs_writev. Note that this requires that exported file implement ->read_iter and ->write_iter. All currently exportable file systems do this. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/nfsd/vfs.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'fs') diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 2be32955d7f2..37a03c456b38 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -911,13 +911,12 @@ __be32 nfsd_splice_read(struct svc_rqst *rqstp, __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen, unsigned long *count) { - mm_segment_t oldfs; + struct iov_iter iter; int host_err; - oldfs = get_fs(); - set_fs(KERNEL_DS); - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset, 0); - set_fs(oldfs); + iov_iter_kvec(&iter, READ | ITER_KVEC, vec, vlen, *count); + host_err = vfs_iter_read(file, &iter, &offset, 0); + return nfsd_finish_read(file, count, host_err); } @@ -974,7 +973,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, unsigned long *cnt, int stable) { struct svc_export *exp; - mm_segment_t oldfs; + struct iov_iter iter; __be32 err = 0; int host_err; int use_wgather; @@ -1000,10 +999,8 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, if (stable && !use_wgather) flags |= RWF_SYNC; - /* Write the data. */ - oldfs = get_fs(); set_fs(KERNEL_DS); - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos, flags); - set_fs(oldfs); + iov_iter_kvec(&iter, WRITE | ITER_KVEC, vec, vlen, *cnt); + host_err = vfs_iter_write(file, &iter, &pos, flags); if (host_err < 0) goto out_nfserr; *cnt = host_err; -- cgit v1.2.3 From a4058c5bce8aded1a12a59990e84e481a96fb490 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:54 +0300 Subject: nfsd: remove nfsd_vfs_read Simpler done in the only caller. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/nfsd/vfs.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'fs') diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 37a03c456b38..0d19ab1b9404 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -920,16 +920,6 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen, return nfsd_finish_read(file, count, host_err); } -static __be32 -nfsd_vfs_read(struct svc_rqst *rqstp, struct file *file, - loff_t offset, struct kvec *vec, int vlen, unsigned long *count) -{ - if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &rqstp->rq_flags)) - return nfsd_splice_read(rqstp, file, offset, count); - else - return nfsd_readv(file, offset, vec, vlen, count); -} - /* * Gathered writes: If another process is currently writing to the file, * there's a high chance this is another nfsd (triggered by a bulk write @@ -1041,7 +1031,12 @@ __be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, ra = nfsd_init_raparms(file); trace_read_opened(rqstp, fhp, offset, vlen); - err = nfsd_vfs_read(rqstp, file, offset, vec, vlen, count); + + if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &rqstp->rq_flags)) + err = nfsd_splice_read(rqstp, file, offset, count); + else + err = nfsd_readv(file, offset, vec, vlen, count); + trace_read_io_done(rqstp, fhp, offset, vlen); if (ra) -- cgit v1.2.3