From 19c735868dd018fd432d0df43aaf2d5ecb7c1256 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 27 May 2017 11:16:48 +0300 Subject: [PATCH] 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 | 62 +++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-) 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 @@ ssize_t compat_rw_copy_check_uvector(int type, } #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; + return ret; - if (type != READ) - file_start_write(file); - - 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); - - if (type != READ) - file_end_write(file); - + ret = do_loop_readv_writev(file, iter, pos, READ, flags); out: - if ((ret + (type == READ)) > 0) { - if (type == READ) - fsnotify_access(file); - else - fsnotify_modify(file); - } + if (ret >= 0) + fsnotify_access(file); + return ret; +} + +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; + + 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)