fs: implement vfs_iter_write using do_iter_write
authorChristoph Hellwig <hch@lst.de>
Sat, 27 May 2017 08:16:52 +0000 (11:16 +0300)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 29 Jun 2017 21:49:23 +0000 (17:49 -0400)
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 <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/block/loop.c
drivers/target/target_core_file.c
fs/coda/file.c
fs/read_write.c
fs/splice.c
include/linux/fs.h

index b64649bec64ef8ab779f8b1ec58d57946b3f9d8f..2a0d997efda46e198499084c3fd187aaf2ccc88e 100644 (file)
@@ -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))
index 2befc0d7fdb1c9dcde92a64cc4bb075d624018aa..e921948415c72bdcd7bde1c3b255c120d225f784 100644 (file)
@@ -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) {
index f1102822bcfd586b6a49b97a280dd57685ec2957..363402fcb3ed090dde17642dd569fac72365f0b4 100644 (file)
@@ -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);
index 4dab30b62f0e357e2af9406f59176723cce17729..acfd3dc63d5704474d4701cec0f46309ebf8e36a 100644 (file)
@@ -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)
 {
index 540c4a44756c20cdd0e7e2f3eb3db98712858210..ae41201d032581a7c03f00a5cc86287782e000d4 100644 (file)
@@ -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;
 
index 3f6a4f4efb3231272acc7efd23d5ba2da4c1d942..c67f1f8ee789bd58febf7c0b1f991e4557bb2100 100644 (file)
@@ -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);