diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-12 13:30:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-12 13:30:18 -0400 |
commit | 16b9057804c02e2d351e9c8f606e909b43cbd9e7 (patch) | |
tree | a3ac6e1d9d57a8abf4267e5ead3f2de1309335eb | |
parent | 5c02c392cd2320e8d612376d6b72b6548a680923 (diff) | |
parent | c2338f2dc7c1e9f6202f370c64ffd7f44f3d4b51 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs updates from Al Viro:
"This the bunch that sat in -next + lock_parent() fix. This is the
minimal set; there's more pending stuff.
In particular, I really hope to get acct.c fixes merged this cycle -
we need that to deal sanely with delayed-mntput stuff. In the next
pile, hopefully - that series is fairly short and localized
(kernel/acct.c, fs/super.c and fs/namespace.c). In this pile: more
iov_iter work. Most of prereqs for ->splice_write with sane locking
order are there and Kent's dio rewrite would also fit nicely on top of
this pile"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (70 commits)
lock_parent: don't step on stale ->d_parent of all-but-freed one
kill generic_file_splice_write()
ceph: switch to iter_file_splice_write()
shmem: switch to iter_file_splice_write()
nfs: switch to iter_splice_write_file()
fs/splice.c: remove unneeded exports
ocfs2: switch to iter_file_splice_write()
->splice_write() via ->write_iter()
bio_vec-backed iov_iter
optimize copy_page_{to,from}_iter()
bury generic_file_aio_{read,write}
lustre: get rid of messing with iovecs
ceph: switch to ->write_iter()
ceph_sync_direct_write: stop poking into iov_iter guts
ceph_sync_read: stop poking into iov_iter guts
new helper: copy_page_from_iter()
fuse: switch to ->write_iter()
btrfs: switch to ->write_iter()
ocfs2: switch to ->write_iter()
xfs: switch to ->write_iter()
...
102 files changed, 1796 insertions, 2028 deletions
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index eba790134253..b18dd1779029 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking | |||
@@ -196,8 +196,7 @@ prototypes: | |||
196 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); | 196 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); |
197 | int (*releasepage) (struct page *, int); | 197 | int (*releasepage) (struct page *, int); |
198 | void (*freepage)(struct page *); | 198 | void (*freepage)(struct page *); |
199 | int (*direct_IO)(int, struct kiocb *, const struct iovec *iov, | 199 | int (*direct_IO)(int, struct kiocb *, struct iov_iter *iter, loff_t offset); |
200 | loff_t offset, unsigned long nr_segs); | ||
201 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, void **, | 200 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, void **, |
202 | unsigned long *); | 201 | unsigned long *); |
203 | int (*migratepage)(struct address_space *, struct page *, struct page *); | 202 | int (*migratepage)(struct address_space *, struct page *, struct page *); |
@@ -431,6 +430,8 @@ prototypes: | |||
431 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 430 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
432 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 431 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
433 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 432 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
433 | ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); | ||
434 | ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); | ||
434 | int (*iterate) (struct file *, struct dir_context *); | 435 | int (*iterate) (struct file *, struct dir_context *); |
435 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 436 | unsigned int (*poll) (struct file *, struct poll_table_struct *); |
436 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 437 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index 617f6d70c077..a1d0d7a30165 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt | |||
@@ -589,8 +589,7 @@ struct address_space_operations { | |||
589 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); | 589 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); |
590 | int (*releasepage) (struct page *, int); | 590 | int (*releasepage) (struct page *, int); |
591 | void (*freepage)(struct page *); | 591 | void (*freepage)(struct page *); |
592 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, | 592 | ssize_t (*direct_IO)(int, struct kiocb *, struct iov_iter *iter, loff_t offset); |
593 | loff_t offset, unsigned long nr_segs); | ||
594 | struct page* (*get_xip_page)(struct address_space *, sector_t, | 593 | struct page* (*get_xip_page)(struct address_space *, sector_t, |
595 | int); | 594 | int); |
596 | /* migrate the contents of a page to the specified target */ | 595 | /* migrate the contents of a page to the specified target */ |
@@ -807,6 +806,8 @@ struct file_operations { | |||
807 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 806 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
808 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 807 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
809 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 808 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
809 | ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); | ||
810 | ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); | ||
810 | int (*iterate) (struct file *, struct dir_context *); | 811 | int (*iterate) (struct file *, struct dir_context *); |
811 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 812 | unsigned int (*poll) (struct file *, struct poll_table_struct *); |
812 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 813 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
@@ -837,11 +838,15 @@ otherwise noted. | |||
837 | 838 | ||
838 | read: called by read(2) and related system calls | 839 | read: called by read(2) and related system calls |
839 | 840 | ||
840 | aio_read: called by io_submit(2) and other asynchronous I/O operations | 841 | aio_read: vectored, possibly asynchronous read |
842 | |||
843 | read_iter: possibly asynchronous read with iov_iter as destination | ||
841 | 844 | ||
842 | write: called by write(2) and related system calls | 845 | write: called by write(2) and related system calls |
843 | 846 | ||
844 | aio_write: called by io_submit(2) and other asynchronous I/O operations | 847 | aio_write: vectored, possibly asynchronous write |
848 | |||
849 | write_iter: possibly asynchronous write with iov_iter as source | ||
845 | 850 | ||
846 | iterate: called when the VFS needs to read the directory contents | 851 | iterate: called when the VFS needs to read the directory contents |
847 | 852 | ||
diff --git a/drivers/char/raw.c b/drivers/char/raw.c index 6e8d65e9b1d3..0102dc788608 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c | |||
@@ -284,10 +284,10 @@ static long raw_ctl_compat_ioctl(struct file *file, unsigned int cmd, | |||
284 | #endif | 284 | #endif |
285 | 285 | ||
286 | static const struct file_operations raw_fops = { | 286 | static const struct file_operations raw_fops = { |
287 | .read = do_sync_read, | 287 | .read = new_sync_read, |
288 | .aio_read = generic_file_aio_read, | 288 | .read_iter = generic_file_read_iter, |
289 | .write = do_sync_write, | 289 | .write = new_sync_write, |
290 | .aio_write = blkdev_aio_write, | 290 | .write_iter = blkdev_write_iter, |
291 | .fsync = blkdev_fsync, | 291 | .fsync = blkdev_fsync, |
292 | .open = raw_open, | 292 | .open = raw_open, |
293 | .release = raw_release, | 293 | .release = raw_release, |
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 42e8a770e631..4f0d83648e5a 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c | |||
@@ -575,12 +575,12 @@ static int alloc_device(struct nandsim *ns) | |||
575 | cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600); | 575 | cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600); |
576 | if (IS_ERR(cfile)) | 576 | if (IS_ERR(cfile)) |
577 | return PTR_ERR(cfile); | 577 | return PTR_ERR(cfile); |
578 | if (!cfile->f_op->read && !cfile->f_op->aio_read) { | 578 | if (!(cfile->f_mode & FMODE_CAN_READ)) { |
579 | NS_ERR("alloc_device: cache file not readable\n"); | 579 | NS_ERR("alloc_device: cache file not readable\n"); |
580 | err = -EINVAL; | 580 | err = -EINVAL; |
581 | goto err_close; | 581 | goto err_close; |
582 | } | 582 | } |
583 | if (!cfile->f_op->write && !cfile->f_op->aio_write) { | 583 | if (!(cfile->f_mode & FMODE_CAN_WRITE)) { |
584 | NS_ERR("alloc_device: cache file not writeable\n"); | 584 | NS_ERR("alloc_device: cache file not writeable\n"); |
585 | err = -EINVAL; | 585 | err = -EINVAL; |
586 | goto err_close; | 586 | goto err_close; |
diff --git a/drivers/staging/lustre/lustre/include/lclient.h b/drivers/staging/lustre/lustre/include/lclient.h index 827209ea6bd0..386a36c00f57 100644 --- a/drivers/staging/lustre/lustre/include/lclient.h +++ b/drivers/staging/lustre/lustre/include/lclient.h | |||
@@ -82,16 +82,7 @@ struct ccc_io { | |||
82 | /** | 82 | /** |
83 | * I/O vector information to or from which read/write is going. | 83 | * I/O vector information to or from which read/write is going. |
84 | */ | 84 | */ |
85 | struct iovec *cui_iov; | 85 | struct iov_iter *cui_iter; |
86 | unsigned long cui_nrsegs; | ||
87 | /** | ||
88 | * Total iov count for left IO. | ||
89 | */ | ||
90 | unsigned long cui_tot_nrsegs; | ||
91 | /** | ||
92 | * Old length for iov that was truncated partially. | ||
93 | */ | ||
94 | size_t cui_iov_olen; | ||
95 | /** | 86 | /** |
96 | * Total size for the left IO. | 87 | * Total size for the left IO. |
97 | */ | 88 | */ |
diff --git a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c index dc24cfa58037..1b0c216bc568 100644 --- a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c +++ b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c | |||
@@ -720,31 +720,12 @@ int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io, | |||
720 | void ccc_io_update_iov(const struct lu_env *env, | 720 | void ccc_io_update_iov(const struct lu_env *env, |
721 | struct ccc_io *cio, struct cl_io *io) | 721 | struct ccc_io *cio, struct cl_io *io) |
722 | { | 722 | { |
723 | int i; | ||
724 | size_t size = io->u.ci_rw.crw_count; | 723 | size_t size = io->u.ci_rw.crw_count; |
725 | 724 | ||
726 | cio->cui_iov_olen = 0; | 725 | if (!cl_is_normalio(env, io) || cio->cui_iter == NULL) |
727 | if (!cl_is_normalio(env, io) || cio->cui_tot_nrsegs == 0) | ||
728 | return; | 726 | return; |
729 | 727 | ||
730 | for (i = 0; i < cio->cui_tot_nrsegs; i++) { | 728 | iov_iter_truncate(cio->cui_iter, size); |
731 | struct iovec *iv = &cio->cui_iov[i]; | ||
732 | |||
733 | if (iv->iov_len < size) | ||
734 | size -= iv->iov_len; | ||
735 | else { | ||
736 | if (iv->iov_len > size) { | ||
737 | cio->cui_iov_olen = iv->iov_len; | ||
738 | iv->iov_len = size; | ||
739 | } | ||
740 | break; | ||
741 | } | ||
742 | } | ||
743 | |||
744 | cio->cui_nrsegs = i + 1; | ||
745 | LASSERTF(cio->cui_tot_nrsegs >= cio->cui_nrsegs, | ||
746 | "tot_nrsegs: %lu, nrsegs: %lu\n", | ||
747 | cio->cui_tot_nrsegs, cio->cui_nrsegs); | ||
748 | } | 729 | } |
749 | 730 | ||
750 | int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io, | 731 | int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io, |
@@ -775,30 +756,7 @@ void ccc_io_advance(const struct lu_env *env, | |||
775 | if (!cl_is_normalio(env, io)) | 756 | if (!cl_is_normalio(env, io)) |
776 | return; | 757 | return; |
777 | 758 | ||
778 | LASSERT(cio->cui_tot_nrsegs >= cio->cui_nrsegs); | 759 | iov_iter_reexpand(cio->cui_iter, cio->cui_tot_count -= nob); |
779 | LASSERT(cio->cui_tot_count >= nob); | ||
780 | |||
781 | cio->cui_iov += cio->cui_nrsegs; | ||
782 | cio->cui_tot_nrsegs -= cio->cui_nrsegs; | ||
783 | cio->cui_tot_count -= nob; | ||
784 | |||
785 | /* update the iov */ | ||
786 | if (cio->cui_iov_olen > 0) { | ||
787 | struct iovec *iv; | ||
788 | |||
789 | cio->cui_iov--; | ||
790 | cio->cui_tot_nrsegs++; | ||
791 | iv = &cio->cui_iov[0]; | ||
792 | if (io->ci_continue) { | ||
793 | iv->iov_base += iv->iov_len; | ||
794 | LASSERT(cio->cui_iov_olen > iv->iov_len); | ||
795 | iv->iov_len = cio->cui_iov_olen - iv->iov_len; | ||
796 | } else { | ||
797 | /* restore the iov_len, in case of restart io. */ | ||
798 | iv->iov_len = cio->cui_iov_olen; | ||
799 | } | ||
800 | cio->cui_iov_olen = 0; | ||
801 | } | ||
802 | } | 760 | } |
803 | 761 | ||
804 | /** | 762 | /** |
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c index c4ddec2b3589..716e1ee0104f 100644 --- a/drivers/staging/lustre/lustre/llite/file.c +++ b/drivers/staging/lustre/lustre/llite/file.c | |||
@@ -1114,9 +1114,7 @@ restart: | |||
1114 | 1114 | ||
1115 | switch (vio->cui_io_subtype) { | 1115 | switch (vio->cui_io_subtype) { |
1116 | case IO_NORMAL: | 1116 | case IO_NORMAL: |
1117 | cio->cui_iov = args->u.normal.via_iov; | 1117 | cio->cui_iter = args->u.normal.via_iter; |
1118 | cio->cui_nrsegs = args->u.normal.via_nrsegs; | ||
1119 | cio->cui_tot_nrsegs = cio->cui_nrsegs; | ||
1120 | cio->cui_iocb = args->u.normal.via_iocb; | 1118 | cio->cui_iocb = args->u.normal.via_iocb; |
1121 | if ((iot == CIT_WRITE) && | 1119 | if ((iot == CIT_WRITE) && |
1122 | !(cio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) { | 1120 | !(cio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) { |
@@ -1180,58 +1178,23 @@ out: | |||
1180 | return result; | 1178 | return result; |
1181 | } | 1179 | } |
1182 | 1180 | ||
1183 | static ssize_t ll_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | 1181 | static ssize_t ll_file_read_iter(struct kiocb *iocb, struct iov_iter *to) |
1184 | unsigned long nr_segs, loff_t pos) | ||
1185 | { | 1182 | { |
1186 | struct lu_env *env; | 1183 | struct lu_env *env; |
1187 | struct vvp_io_args *args; | 1184 | struct vvp_io_args *args; |
1188 | size_t count = 0; | ||
1189 | ssize_t result; | 1185 | ssize_t result; |
1190 | int refcheck; | 1186 | int refcheck; |
1191 | 1187 | ||
1192 | result = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE); | ||
1193 | if (result) | ||
1194 | return result; | ||
1195 | |||
1196 | env = cl_env_get(&refcheck); | 1188 | env = cl_env_get(&refcheck); |
1197 | if (IS_ERR(env)) | 1189 | if (IS_ERR(env)) |
1198 | return PTR_ERR(env); | 1190 | return PTR_ERR(env); |
1199 | 1191 | ||
1200 | args = vvp_env_args(env, IO_NORMAL); | 1192 | args = vvp_env_args(env, IO_NORMAL); |
1201 | args->u.normal.via_iov = (struct iovec *)iov; | 1193 | args->u.normal.via_iter = to; |
1202 | args->u.normal.via_nrsegs = nr_segs; | ||
1203 | args->u.normal.via_iocb = iocb; | 1194 | args->u.normal.via_iocb = iocb; |
1204 | 1195 | ||
1205 | result = ll_file_io_generic(env, args, iocb->ki_filp, CIT_READ, | 1196 | result = ll_file_io_generic(env, args, iocb->ki_filp, CIT_READ, |
1206 | &iocb->ki_pos, count); | 1197 | &iocb->ki_pos, iov_iter_count(to)); |
1207 | cl_env_put(env, &refcheck); | ||
1208 | return result; | ||
1209 | } | ||
1210 | |||
1211 | static ssize_t ll_file_read(struct file *file, char *buf, size_t count, | ||
1212 | loff_t *ppos) | ||
1213 | { | ||
1214 | struct lu_env *env; | ||
1215 | struct iovec *local_iov; | ||
1216 | struct kiocb *kiocb; | ||
1217 | ssize_t result; | ||
1218 | int refcheck; | ||
1219 | |||
1220 | env = cl_env_get(&refcheck); | ||
1221 | if (IS_ERR(env)) | ||
1222 | return PTR_ERR(env); | ||
1223 | |||
1224 | local_iov = &vvp_env_info(env)->vti_local_iov; | ||
1225 | kiocb = &vvp_env_info(env)->vti_kiocb; | ||
1226 | local_iov->iov_base = (void __user *)buf; | ||
1227 | local_iov->iov_len = count; | ||
1228 | init_sync_kiocb(kiocb, file); | ||
1229 | kiocb->ki_pos = *ppos; | ||
1230 | kiocb->ki_nbytes = count; | ||
1231 | |||
1232 | result = ll_file_aio_read(kiocb, local_iov, 1, kiocb->ki_pos); | ||
1233 | *ppos = kiocb->ki_pos; | ||
1234 | |||
1235 | cl_env_put(env, &refcheck); | 1198 | cl_env_put(env, &refcheck); |
1236 | return result; | 1199 | return result; |
1237 | } | 1200 | } |
@@ -1239,64 +1202,27 @@ static ssize_t ll_file_read(struct file *file, char *buf, size_t count, | |||
1239 | /* | 1202 | /* |
1240 | * Write to a file (through the page cache). | 1203 | * Write to a file (through the page cache). |
1241 | */ | 1204 | */ |
1242 | static ssize_t ll_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 1205 | static ssize_t ll_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
1243 | unsigned long nr_segs, loff_t pos) | ||
1244 | { | 1206 | { |
1245 | struct lu_env *env; | 1207 | struct lu_env *env; |
1246 | struct vvp_io_args *args; | 1208 | struct vvp_io_args *args; |
1247 | size_t count = 0; | ||
1248 | ssize_t result; | 1209 | ssize_t result; |
1249 | int refcheck; | 1210 | int refcheck; |
1250 | 1211 | ||
1251 | result = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ); | ||
1252 | if (result) | ||
1253 | return result; | ||
1254 | |||
1255 | env = cl_env_get(&refcheck); | 1212 | env = cl_env_get(&refcheck); |
1256 | if (IS_ERR(env)) | 1213 | if (IS_ERR(env)) |
1257 | return PTR_ERR(env); | 1214 | return PTR_ERR(env); |
1258 | 1215 | ||
1259 | args = vvp_env_args(env, IO_NORMAL); | 1216 | args = vvp_env_args(env, IO_NORMAL); |
1260 | args->u.normal.via_iov = (struct iovec *)iov; | 1217 | args->u.normal.via_iter = from; |
1261 | args->u.normal.via_nrsegs = nr_segs; | ||
1262 | args->u.normal.via_iocb = iocb; | 1218 | args->u.normal.via_iocb = iocb; |
1263 | 1219 | ||
1264 | result = ll_file_io_generic(env, args, iocb->ki_filp, CIT_WRITE, | 1220 | result = ll_file_io_generic(env, args, iocb->ki_filp, CIT_WRITE, |
1265 | &iocb->ki_pos, count); | 1221 | &iocb->ki_pos, iov_iter_count(from)); |
1266 | cl_env_put(env, &refcheck); | 1222 | cl_env_put(env, &refcheck); |
1267 | return result; | 1223 | return result; |
1268 | } | 1224 | } |
1269 | 1225 | ||
1270 | static ssize_t ll_file_write(struct file *file, const char *buf, size_t count, | ||
1271 | loff_t *ppos) | ||
1272 | { | ||
1273 | struct lu_env *env; | ||
1274 | struct iovec *local_iov; | ||
1275 | struct kiocb *kiocb; | ||
1276 | ssize_t result; | ||
1277 | int refcheck; | ||
1278 | |||
1279 | env = cl_env_get(&refcheck); | ||
1280 | if (IS_ERR(env)) | ||
1281 | return PTR_ERR(env); | ||
1282 | |||
1283 | local_iov = &vvp_env_info(env)->vti_local_iov; | ||
1284 | kiocb = &vvp_env_info(env)->vti_kiocb; | ||
1285 | local_iov->iov_base = (void __user *)buf; | ||
1286 | local_iov->iov_len = count; | ||
1287 | init_sync_kiocb(kiocb, file); | ||
1288 | kiocb->ki_pos = *ppos; | ||
1289 | kiocb->ki_nbytes = count; | ||
1290 | |||
1291 | result = ll_file_aio_write(kiocb, local_iov, 1, kiocb->ki_pos); | ||
1292 | *ppos = kiocb->ki_pos; | ||
1293 | |||
1294 | cl_env_put(env, &refcheck); | ||
1295 | return result; | ||
1296 | } | ||
1297 | |||
1298 | |||
1299 | |||
1300 | /* | 1226 | /* |
1301 | * Send file content (through pagecache) somewhere with helper | 1227 | * Send file content (through pagecache) somewhere with helper |
1302 | */ | 1228 | */ |
@@ -3143,10 +3069,10 @@ int ll_inode_permission(struct inode *inode, int mask) | |||
3143 | 3069 | ||
3144 | /* -o localflock - only provides locally consistent flock locks */ | 3070 | /* -o localflock - only provides locally consistent flock locks */ |
3145 | struct file_operations ll_file_operations = { | 3071 | struct file_operations ll_file_operations = { |
3146 | .read = ll_file_read, | 3072 | .read = new_sync_read, |
3147 | .aio_read = ll_file_aio_read, | 3073 | .read_iter = ll_file_read_iter, |
3148 | .write = ll_file_write, | 3074 | .write = new_sync_write, |
3149 | .aio_write = ll_file_aio_write, | 3075 | .write_iter = ll_file_write_iter, |
3150 | .unlocked_ioctl = ll_file_ioctl, | 3076 | .unlocked_ioctl = ll_file_ioctl, |
3151 | .open = ll_file_open, | 3077 | .open = ll_file_open, |
3152 | .release = ll_file_release, | 3078 | .release = ll_file_release, |
@@ -3158,10 +3084,10 @@ struct file_operations ll_file_operations = { | |||
3158 | }; | 3084 | }; |
3159 | 3085 | ||
3160 | struct file_operations ll_file_operations_flock = { | 3086 | struct file_operations ll_file_operations_flock = { |
3161 | .read = ll_file_read, | 3087 | .read = new_sync_read, |
3162 | .aio_read = ll_file_aio_read, | 3088 | .read_iter = ll_file_read_iter, |
3163 | .write = ll_file_write, | 3089 | .write = new_sync_write, |
3164 | .aio_write = ll_file_aio_write, | 3090 | .write_iter = ll_file_write_iter, |
3165 | .unlocked_ioctl = ll_file_ioctl, | 3091 | .unlocked_ioctl = ll_file_ioctl, |
3166 | .open = ll_file_open, | 3092 | .open = ll_file_open, |
3167 | .release = ll_file_release, | 3093 | .release = ll_file_release, |
@@ -3176,10 +3102,10 @@ struct file_operations ll_file_operations_flock = { | |||
3176 | 3102 | ||
3177 | /* These are for -o noflock - to return ENOSYS on flock calls */ | 3103 | /* These are for -o noflock - to return ENOSYS on flock calls */ |
3178 | struct file_operations ll_file_operations_noflock = { | 3104 | struct file_operations ll_file_operations_noflock = { |
3179 | .read = ll_file_read, | 3105 | .read = new_sync_read, |
3180 | .aio_read = ll_file_aio_read, | 3106 | .read_iter = ll_file_read_iter, |
3181 | .write = ll_file_write, | 3107 | .write = new_sync_write, |
3182 | .aio_write = ll_file_aio_write, | 3108 | .write_iter = ll_file_write_iter, |
3183 | .unlocked_ioctl = ll_file_ioctl, | 3109 | .unlocked_ioctl = ll_file_ioctl, |
3184 | .open = ll_file_open, | 3110 | .open = ll_file_open, |
3185 | .release = ll_file_release, | 3111 | .release = ll_file_release, |
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h index dde7632ba01f..140ee947ba49 100644 --- a/drivers/staging/lustre/lustre/llite/llite_internal.h +++ b/drivers/staging/lustre/lustre/llite/llite_internal.h | |||
@@ -917,8 +917,7 @@ struct vvp_io_args { | |||
917 | union { | 917 | union { |
918 | struct { | 918 | struct { |
919 | struct kiocb *via_iocb; | 919 | struct kiocb *via_iocb; |
920 | struct iovec *via_iov; | 920 | struct iov_iter *via_iter; |
921 | unsigned long via_nrsegs; | ||
922 | } normal; | 921 | } normal; |
923 | struct { | 922 | struct { |
924 | struct pipe_inode_info *via_pipe; | 923 | struct pipe_inode_info *via_pipe; |
diff --git a/drivers/staging/lustre/lustre/llite/rw.c b/drivers/staging/lustre/lustre/llite/rw.c index f0122c568a09..56162103cc79 100644 --- a/drivers/staging/lustre/lustre/llite/rw.c +++ b/drivers/staging/lustre/lustre/llite/rw.c | |||
@@ -151,8 +151,7 @@ static struct ll_cl_context *ll_cl_init(struct file *file, | |||
151 | result = cl_io_rw_init(env, io, CIT_WRITE, pos, PAGE_CACHE_SIZE); | 151 | result = cl_io_rw_init(env, io, CIT_WRITE, pos, PAGE_CACHE_SIZE); |
152 | if (result == 0) { | 152 | if (result == 0) { |
153 | cio->cui_fd = LUSTRE_FPRIVATE(file); | 153 | cio->cui_fd = LUSTRE_FPRIVATE(file); |
154 | cio->cui_iov = NULL; | 154 | cio->cui_iter = NULL; |
155 | cio->cui_nrsegs = 0; | ||
156 | result = cl_io_iter_init(env, io); | 155 | result = cl_io_iter_init(env, io); |
157 | if (result == 0) { | 156 | if (result == 0) { |
158 | result = cl_io_lock(env, io); | 157 | result = cl_io_lock(env, io); |
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c index 55ca8d3c3e46..af84c1aaa5f8 100644 --- a/drivers/staging/lustre/lustre/llite/rw26.c +++ b/drivers/staging/lustre/lustre/llite/rw26.c | |||
@@ -218,14 +218,11 @@ static void ll_free_user_pages(struct page **pages, int npages, int do_dirty) | |||
218 | int i; | 218 | int i; |
219 | 219 | ||
220 | for (i = 0; i < npages; i++) { | 220 | for (i = 0; i < npages; i++) { |
221 | if (pages[i] == NULL) | ||
222 | break; | ||
223 | if (do_dirty) | 221 | if (do_dirty) |
224 | set_page_dirty_lock(pages[i]); | 222 | set_page_dirty_lock(pages[i]); |
225 | page_cache_release(pages[i]); | 223 | page_cache_release(pages[i]); |
226 | } | 224 | } |
227 | 225 | kvfree(pages); | |
228 | OBD_FREE_LARGE(pages, npages * sizeof(*pages)); | ||
229 | } | 226 | } |
230 | 227 | ||
231 | ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, | 228 | ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, |
@@ -363,18 +360,16 @@ static ssize_t ll_direct_IO_26_seg(const struct lu_env *env, struct cl_io *io, | |||
363 | #define MAX_DIO_SIZE ((MAX_MALLOC / sizeof(struct brw_page) * PAGE_CACHE_SIZE) & \ | 360 | #define MAX_DIO_SIZE ((MAX_MALLOC / sizeof(struct brw_page) * PAGE_CACHE_SIZE) & \ |
364 | ~(DT_MAX_BRW_SIZE - 1)) | 361 | ~(DT_MAX_BRW_SIZE - 1)) |
365 | static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb, | 362 | static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb, |
366 | const struct iovec *iov, loff_t file_offset, | 363 | struct iov_iter *iter, loff_t file_offset) |
367 | unsigned long nr_segs) | ||
368 | { | 364 | { |
369 | struct lu_env *env; | 365 | struct lu_env *env; |
370 | struct cl_io *io; | 366 | struct cl_io *io; |
371 | struct file *file = iocb->ki_filp; | 367 | struct file *file = iocb->ki_filp; |
372 | struct inode *inode = file->f_mapping->host; | 368 | struct inode *inode = file->f_mapping->host; |
373 | struct ccc_object *obj = cl_inode2ccc(inode); | 369 | struct ccc_object *obj = cl_inode2ccc(inode); |
374 | long count = iov_length(iov, nr_segs); | 370 | ssize_t count = iov_iter_count(iter); |
375 | long tot_bytes = 0, result = 0; | 371 | ssize_t tot_bytes = 0, result = 0; |
376 | struct ll_inode_info *lli = ll_i2info(inode); | 372 | struct ll_inode_info *lli = ll_i2info(inode); |
377 | unsigned long seg = 0; | ||
378 | long size = MAX_DIO_SIZE; | 373 | long size = MAX_DIO_SIZE; |
379 | int refcheck; | 374 | int refcheck; |
380 | 375 | ||
@@ -392,11 +387,8 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb, | |||
392 | MAX_DIO_SIZE >> PAGE_CACHE_SHIFT); | 387 | MAX_DIO_SIZE >> PAGE_CACHE_SHIFT); |
393 | 388 | ||
394 | /* Check that all user buffers are aligned as well */ | 389 | /* Check that all user buffers are aligned as well */ |
395 | for (seg = 0; seg < nr_segs; seg++) { | 390 | if (iov_iter_alignment(iter) & ~CFS_PAGE_MASK) |
396 | if (((unsigned long)iov[seg].iov_base & ~CFS_PAGE_MASK) || | 391 | return -EINVAL; |
397 | (iov[seg].iov_len & ~CFS_PAGE_MASK)) | ||
398 | return -EINVAL; | ||
399 | } | ||
400 | 392 | ||
401 | env = cl_env_get(&refcheck); | 393 | env = cl_env_get(&refcheck); |
402 | LASSERT(!IS_ERR(env)); | 394 | LASSERT(!IS_ERR(env)); |
@@ -411,63 +403,49 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb, | |||
411 | mutex_lock(&inode->i_mutex); | 403 | mutex_lock(&inode->i_mutex); |
412 | 404 | ||
413 | LASSERT(obj->cob_transient_pages == 0); | 405 | LASSERT(obj->cob_transient_pages == 0); |
414 | for (seg = 0; seg < nr_segs; seg++) { | 406 | while (iov_iter_count(iter)) { |
415 | long iov_left = iov[seg].iov_len; | 407 | struct page **pages; |
416 | unsigned long user_addr = (unsigned long)iov[seg].iov_base; | 408 | size_t offs; |
417 | 409 | ||
410 | count = min_t(size_t, iov_iter_count(iter), size); | ||
418 | if (rw == READ) { | 411 | if (rw == READ) { |
419 | if (file_offset >= i_size_read(inode)) | 412 | if (file_offset >= i_size_read(inode)) |
420 | break; | 413 | break; |
421 | if (file_offset + iov_left > i_size_read(inode)) | 414 | if (file_offset + count > i_size_read(inode)) |
422 | iov_left = i_size_read(inode) - file_offset; | 415 | count = i_size_read(inode) - file_offset; |
423 | } | 416 | } |
424 | 417 | ||
425 | while (iov_left > 0) { | 418 | result = iov_iter_get_pages_alloc(iter, &pages, count, &offs); |
426 | struct page **pages; | 419 | if (likely(result > 0)) { |
427 | int page_count, max_pages = 0; | 420 | int n = (result + offs + PAGE_SIZE - 1) / PAGE_SIZE; |
428 | long bytes; | 421 | result = ll_direct_IO_26_seg(env, io, rw, inode, |
429 | 422 | file->f_mapping, | |
430 | bytes = min(size, iov_left); | 423 | result, file_offset, |
431 | page_count = ll_get_user_pages(rw, user_addr, bytes, | 424 | pages, n); |
432 | &pages, &max_pages); | 425 | ll_free_user_pages(pages, n, rw==READ); |
433 | if (likely(page_count > 0)) { | 426 | } |
434 | if (unlikely(page_count < max_pages)) | 427 | if (unlikely(result <= 0)) { |
435 | bytes = page_count << PAGE_CACHE_SHIFT; | 428 | /* If we can't allocate a large enough buffer |
436 | result = ll_direct_IO_26_seg(env, io, rw, inode, | 429 | * for the request, shrink it to a smaller |
437 | file->f_mapping, | 430 | * PAGE_SIZE multiple and try again. |
438 | bytes, file_offset, | 431 | * We should always be able to kmalloc for a |
439 | pages, page_count); | 432 | * page worth of page pointers = 4MB on i386. */ |
440 | ll_free_user_pages(pages, max_pages, rw==READ); | 433 | if (result == -ENOMEM && |
441 | } else if (page_count == 0) { | 434 | size > (PAGE_CACHE_SIZE / sizeof(*pages)) * |
442 | GOTO(out, result = -EFAULT); | 435 | PAGE_CACHE_SIZE) { |
443 | } else { | 436 | size = ((((size / 2) - 1) | |
444 | result = page_count; | 437 | ~CFS_PAGE_MASK) + 1) & |
445 | } | 438 | CFS_PAGE_MASK; |
446 | if (unlikely(result <= 0)) { | 439 | CDEBUG(D_VFSTRACE,"DIO size now %lu\n", |
447 | /* If we can't allocate a large enough buffer | 440 | size); |
448 | * for the request, shrink it to a smaller | 441 | continue; |
449 | * PAGE_SIZE multiple and try again. | ||
450 | * We should always be able to kmalloc for a | ||
451 | * page worth of page pointers = 4MB on i386. */ | ||
452 | if (result == -ENOMEM && | ||
453 | size > (PAGE_CACHE_SIZE / sizeof(*pages)) * | ||
454 | PAGE_CACHE_SIZE) { | ||
455 | size = ((((size / 2) - 1) | | ||
456 | ~CFS_PAGE_MASK) + 1) & | ||
457 | CFS_PAGE_MASK; | ||
458 | CDEBUG(D_VFSTRACE,"DIO size now %lu\n", | ||
459 | size); | ||
460 | continue; | ||
461 | } | ||
462 | |||
463 | GOTO(out, result); | ||
464 | } | 442 | } |
465 | 443 | ||
466 | tot_bytes += result; | 444 | GOTO(out, result); |
467 | file_offset += result; | ||
468 | iov_left -= result; | ||
469 | user_addr += result; | ||
470 | } | 445 | } |
446 | iov_iter_advance(iter, result); | ||
447 | tot_bytes += result; | ||
448 | file_offset += result; | ||
471 | } | 449 | } |
472 | out: | 450 | out: |
473 | LASSERT(obj->cob_transient_pages == 0); | 451 | LASSERT(obj->cob_transient_pages == 0); |
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c index 7dd2b4723c5f..0e0b404cb5e6 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_io.c +++ b/drivers/staging/lustre/lustre/llite/vvp_io.c | |||
@@ -211,27 +211,26 @@ static int vvp_mmap_locks(const struct lu_env *env, | |||
211 | struct cl_lock_descr *descr = &cti->cti_descr; | 211 | struct cl_lock_descr *descr = &cti->cti_descr; |
212 | ldlm_policy_data_t policy; | 212 | ldlm_policy_data_t policy; |
213 | unsigned long addr; | 213 | unsigned long addr; |
214 | unsigned long seg; | ||
215 | ssize_t count; | 214 | ssize_t count; |
216 | int result; | 215 | int result; |
216 | struct iov_iter i; | ||
217 | struct iovec iov; | ||
217 | 218 | ||
218 | LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE); | 219 | LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE); |
219 | 220 | ||
220 | if (!cl_is_normalio(env, io)) | 221 | if (!cl_is_normalio(env, io)) |
221 | return 0; | 222 | return 0; |
222 | 223 | ||
223 | if (vio->cui_iov == NULL) /* nfs or loop back device write */ | 224 | if (vio->cui_iter == NULL) /* nfs or loop back device write */ |
224 | return 0; | 225 | return 0; |
225 | 226 | ||
226 | /* No MM (e.g. NFS)? No vmas too. */ | 227 | /* No MM (e.g. NFS)? No vmas too. */ |
227 | if (mm == NULL) | 228 | if (mm == NULL) |
228 | return 0; | 229 | return 0; |
229 | 230 | ||
230 | for (seg = 0; seg < vio->cui_nrsegs; seg++) { | 231 | iov_for_each(iov, i, *(vio->cui_iter)) { |
231 | const struct iovec *iv = &vio->cui_iov[seg]; | 232 | addr = (unsigned long)iov.iov_base; |
232 | 233 | count = iov.iov_len; | |
233 | addr = (unsigned long)iv->iov_base; | ||
234 | count = iv->iov_len; | ||
235 | if (count == 0) | 234 | if (count == 0) |
236 | continue; | 235 | continue; |
237 | 236 | ||
@@ -527,9 +526,7 @@ static int vvp_io_read_start(const struct lu_env *env, | |||
527 | switch (vio->cui_io_subtype) { | 526 | switch (vio->cui_io_subtype) { |
528 | case IO_NORMAL: | 527 | case IO_NORMAL: |
529 | LASSERT(cio->cui_iocb->ki_pos == pos); | 528 | LASSERT(cio->cui_iocb->ki_pos == pos); |
530 | result = generic_file_aio_read(cio->cui_iocb, | 529 | result = generic_file_read_iter(cio->cui_iocb, cio->cui_iter); |
531 | cio->cui_iov, cio->cui_nrsegs, | ||
532 | cio->cui_iocb->ki_pos); | ||
533 | break; | 530 | break; |
534 | case IO_SPLICE: | 531 | case IO_SPLICE: |
535 | result = generic_file_splice_read(file, &pos, | 532 | result = generic_file_splice_read(file, &pos, |
@@ -595,12 +592,11 @@ static int vvp_io_write_start(const struct lu_env *env, | |||
595 | 592 | ||
596 | CDEBUG(D_VFSTRACE, "write: [%lli, %lli)\n", pos, pos + (long long)cnt); | 593 | CDEBUG(D_VFSTRACE, "write: [%lli, %lli)\n", pos, pos + (long long)cnt); |
597 | 594 | ||
598 | if (cio->cui_iov == NULL) /* from a temp io in ll_cl_init(). */ | 595 | if (cio->cui_iter == NULL) /* from a temp io in ll_cl_init(). */ |
599 | result = 0; | 596 | result = 0; |
600 | else | 597 | else |
601 | result = generic_file_aio_write(cio->cui_iocb, | 598 | result = generic_file_write_iter(cio->cui_iocb, cio->cui_iter); |
602 | cio->cui_iov, cio->cui_nrsegs, | 599 | |
603 | cio->cui_iocb->ki_pos); | ||
604 | if (result > 0) { | 600 | if (result > 0) { |
605 | if (result < cnt) | 601 | if (result < cnt) |
606 | io->ci_continue = 0; | 602 | io->ci_continue = 0; |
@@ -1162,10 +1158,9 @@ int vvp_io_init(const struct lu_env *env, struct cl_object *obj, | |||
1162 | * results." -- Single Unix Spec */ | 1158 | * results." -- Single Unix Spec */ |
1163 | if (count == 0) | 1159 | if (count == 0) |
1164 | result = 1; | 1160 | result = 1; |
1165 | else { | 1161 | else |
1166 | cio->cui_tot_count = count; | 1162 | cio->cui_tot_count = count; |
1167 | cio->cui_tot_nrsegs = 0; | 1163 | |
1168 | } | ||
1169 | /* for read/write, we store the jobid in the inode, and | 1164 | /* for read/write, we store the jobid in the inode, and |
1170 | * it'll be fetched by osc when building RPC. | 1165 | * it'll be fetched by osc when building RPC. |
1171 | * | 1166 | * |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index ff205a7bc55c..648f9e489b39 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -220,11 +220,11 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
220 | * If we can't read the file, it's no good. | 220 | * If we can't read the file, it's no good. |
221 | * If we can't write the file, use it read-only. | 221 | * If we can't write the file, use it read-only. |
222 | */ | 222 | */ |
223 | if (!(filp->f_op->read || filp->f_op->aio_read)) { | 223 | if (!(filp->f_mode & FMODE_CAN_READ)) { |
224 | LINFO(curlun, "file not readable: %s\n", filename); | 224 | LINFO(curlun, "file not readable: %s\n", filename); |
225 | goto out; | 225 | goto out; |
226 | } | 226 | } |
227 | if (!(filp->f_op->write || filp->f_op->aio_write)) | 227 | if (!(filp->f_mode & FMODE_CAN_WRITE)) |
228 | ro = 1; | 228 | ro = 1; |
229 | 229 | ||
230 | size = i_size_read(inode->i_mapping->host); | 230 | size = i_size_read(inode->i_mapping->host); |
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index c71e88602ff4..cc1cfae726b3 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c | |||
@@ -259,8 +259,7 @@ static int v9fs_launder_page(struct page *page) | |||
259 | * | 259 | * |
260 | */ | 260 | */ |
261 | static ssize_t | 261 | static ssize_t |
262 | v9fs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 262 | v9fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos) |
263 | loff_t pos, unsigned long nr_segs) | ||
264 | { | 263 | { |
265 | /* | 264 | /* |
266 | * FIXME | 265 | * FIXME |
@@ -269,7 +268,7 @@ v9fs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
269 | */ | 268 | */ |
270 | p9_debug(P9_DEBUG_VFS, "v9fs_direct_IO: v9fs_direct_IO (%s) off/no(%lld/%lu) EINVAL\n", | 269 | p9_debug(P9_DEBUG_VFS, "v9fs_direct_IO: v9fs_direct_IO (%s) off/no(%lld/%lu) EINVAL\n", |
271 | iocb->ki_filp->f_path.dentry->d_name.name, | 270 | iocb->ki_filp->f_path.dentry->d_name.name, |
272 | (long long)pos, nr_segs); | 271 | (long long)pos, iter->nr_segs); |
273 | 272 | ||
274 | return -EINVAL; | 273 | return -EINVAL; |
275 | } | 274 | } |
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 96e550760699..520c11c2dcca 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
@@ -692,7 +692,7 @@ v9fs_cached_file_read(struct file *filp, char __user *data, size_t count, | |||
692 | { | 692 | { |
693 | if (filp->f_flags & O_DIRECT) | 693 | if (filp->f_flags & O_DIRECT) |
694 | return v9fs_direct_read(filp, data, count, offset); | 694 | return v9fs_direct_read(filp, data, count, offset); |
695 | return do_sync_read(filp, data, count, offset); | 695 | return new_sync_read(filp, data, count, offset); |
696 | } | 696 | } |
697 | 697 | ||
698 | /** | 698 | /** |
@@ -760,7 +760,7 @@ err_out: | |||
760 | 760 | ||
761 | buff_write: | 761 | buff_write: |
762 | mutex_unlock(&inode->i_mutex); | 762 | mutex_unlock(&inode->i_mutex); |
763 | return do_sync_write(filp, data, count, offsetp); | 763 | return new_sync_write(filp, data, count, offsetp); |
764 | } | 764 | } |
765 | 765 | ||
766 | /** | 766 | /** |
@@ -778,7 +778,7 @@ v9fs_cached_file_write(struct file *filp, const char __user * data, | |||
778 | 778 | ||
779 | if (filp->f_flags & O_DIRECT) | 779 | if (filp->f_flags & O_DIRECT) |
780 | return v9fs_direct_write(filp, data, count, offset); | 780 | return v9fs_direct_write(filp, data, count, offset); |
781 | return do_sync_write(filp, data, count, offset); | 781 | return new_sync_write(filp, data, count, offset); |
782 | } | 782 | } |
783 | 783 | ||
784 | 784 | ||
@@ -847,8 +847,8 @@ const struct file_operations v9fs_cached_file_operations = { | |||
847 | .llseek = generic_file_llseek, | 847 | .llseek = generic_file_llseek, |
848 | .read = v9fs_cached_file_read, | 848 | .read = v9fs_cached_file_read, |
849 | .write = v9fs_cached_file_write, | 849 | .write = v9fs_cached_file_write, |
850 | .aio_read = generic_file_aio_read, | 850 | .read_iter = generic_file_read_iter, |
851 | .aio_write = generic_file_aio_write, | 851 | .write_iter = generic_file_write_iter, |
852 | .open = v9fs_file_open, | 852 | .open = v9fs_file_open, |
853 | .release = v9fs_dir_release, | 853 | .release = v9fs_dir_release, |
854 | .lock = v9fs_file_lock, | 854 | .lock = v9fs_file_lock, |
@@ -860,8 +860,8 @@ const struct file_operations v9fs_cached_file_operations_dotl = { | |||
860 | .llseek = generic_file_llseek, | 860 | .llseek = generic_file_llseek, |
861 | .read = v9fs_cached_file_read, | 861 | .read = v9fs_cached_file_read, |
862 | .write = v9fs_cached_file_write, | 862 | .write = v9fs_cached_file_write, |
863 | .aio_read = generic_file_aio_read, | 863 | .read_iter = generic_file_read_iter, |
864 | .aio_write = generic_file_aio_write, | 864 | .write_iter = generic_file_write_iter, |
865 | .open = v9fs_file_open, | 865 | .open = v9fs_file_open, |
866 | .release = v9fs_dir_release, | 866 | .release = v9fs_dir_release, |
867 | .lock = v9fs_file_lock_dotl, | 867 | .lock = v9fs_file_lock_dotl, |
diff --git a/fs/adfs/file.c b/fs/adfs/file.c index a36da5382b40..07c9edce5aa7 100644 --- a/fs/adfs/file.c +++ b/fs/adfs/file.c | |||
@@ -23,12 +23,12 @@ | |||
23 | 23 | ||
24 | const struct file_operations adfs_file_operations = { | 24 | const struct file_operations adfs_file_operations = { |
25 | .llseek = generic_file_llseek, | 25 | .llseek = generic_file_llseek, |
26 | .read = do_sync_read, | 26 | .read = new_sync_read, |
27 | .aio_read = generic_file_aio_read, | 27 | .read_iter = generic_file_read_iter, |
28 | .mmap = generic_file_mmap, | 28 | .mmap = generic_file_mmap, |
29 | .fsync = generic_file_fsync, | 29 | .fsync = generic_file_fsync, |
30 | .write = do_sync_write, | 30 | .write = new_sync_write, |
31 | .aio_write = generic_file_aio_write, | 31 | .write_iter = generic_file_write_iter, |
32 | .splice_read = generic_file_splice_read, | 32 | .splice_read = generic_file_splice_read, |
33 | }; | 33 | }; |
34 | 34 | ||
diff --git a/fs/affs/file.c b/fs/affs/file.c index 0270303388ee..a7fe57d2cd9a 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c | |||
@@ -27,10 +27,10 @@ static int affs_file_release(struct inode *inode, struct file *filp); | |||
27 | 27 | ||
28 | const struct file_operations affs_file_operations = { | 28 | const struct file_operations affs_file_operations = { |
29 | .llseek = generic_file_llseek, | 29 | .llseek = generic_file_llseek, |
30 | .read = do_sync_read, | 30 | .read = new_sync_read, |
31 | .aio_read = generic_file_aio_read, | 31 | .read_iter = generic_file_read_iter, |
32 | .write = do_sync_write, | 32 | .write = new_sync_write, |
33 | .aio_write = generic_file_aio_write, | 33 | .write_iter = generic_file_write_iter, |
34 | .mmap = generic_file_mmap, | 34 | .mmap = generic_file_mmap, |
35 | .open = affs_file_open, | 35 | .open = affs_file_open, |
36 | .release = affs_file_release, | 36 | .release = affs_file_release, |
diff --git a/fs/afs/file.c b/fs/afs/file.c index 66d50fe2ee45..932ce07948b3 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c | |||
@@ -31,10 +31,10 @@ const struct file_operations afs_file_operations = { | |||
31 | .open = afs_open, | 31 | .open = afs_open, |
32 | .release = afs_release, | 32 | .release = afs_release, |
33 | .llseek = generic_file_llseek, | 33 | .llseek = generic_file_llseek, |
34 | .read = do_sync_read, | 34 | .read = new_sync_read, |
35 | .write = do_sync_write, | 35 | .write = new_sync_write, |
36 | .aio_read = generic_file_aio_read, | 36 | .read_iter = generic_file_read_iter, |
37 | .aio_write = afs_file_write, | 37 | .write_iter = afs_file_write, |
38 | .mmap = generic_file_readonly_mmap, | 38 | .mmap = generic_file_readonly_mmap, |
39 | .splice_read = generic_file_splice_read, | 39 | .splice_read = generic_file_splice_read, |
40 | .fsync = afs_fsync, | 40 | .fsync = afs_fsync, |
diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 590b55f46d61..71d5982312f3 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h | |||
@@ -747,8 +747,7 @@ extern int afs_write_end(struct file *file, struct address_space *mapping, | |||
747 | extern int afs_writepage(struct page *, struct writeback_control *); | 747 | extern int afs_writepage(struct page *, struct writeback_control *); |
748 | extern int afs_writepages(struct address_space *, struct writeback_control *); | 748 | extern int afs_writepages(struct address_space *, struct writeback_control *); |
749 | extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); | 749 | extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); |
750 | extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, | 750 | extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); |
751 | unsigned long, loff_t); | ||
752 | extern int afs_writeback_all(struct afs_vnode *); | 751 | extern int afs_writeback_all(struct afs_vnode *); |
753 | extern int afs_fsync(struct file *, loff_t, loff_t, int); | 752 | extern int afs_fsync(struct file *, loff_t, loff_t, int); |
754 | 753 | ||
diff --git a/fs/afs/write.c b/fs/afs/write.c index a890db4b9898..ab6adfd52516 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c | |||
@@ -625,15 +625,14 @@ void afs_pages_written_back(struct afs_vnode *vnode, struct afs_call *call) | |||
625 | /* | 625 | /* |
626 | * write to an AFS file | 626 | * write to an AFS file |
627 | */ | 627 | */ |
628 | ssize_t afs_file_write(struct kiocb *iocb, const struct iovec *iov, | 628 | ssize_t afs_file_write(struct kiocb *iocb, struct iov_iter *from) |
629 | unsigned long nr_segs, loff_t pos) | ||
630 | { | 629 | { |
631 | struct afs_vnode *vnode = AFS_FS_I(file_inode(iocb->ki_filp)); | 630 | struct afs_vnode *vnode = AFS_FS_I(file_inode(iocb->ki_filp)); |
632 | ssize_t result; | 631 | ssize_t result; |
633 | size_t count = iov_length(iov, nr_segs); | 632 | size_t count = iov_iter_count(from); |
634 | 633 | ||
635 | _enter("{%x.%u},{%zu},%lu,", | 634 | _enter("{%x.%u},{%zu},", |
636 | vnode->fid.vid, vnode->fid.vnode, count, nr_segs); | 635 | vnode->fid.vid, vnode->fid.vnode, count); |
637 | 636 | ||
638 | if (IS_SWAPFILE(&vnode->vfs_inode)) { | 637 | if (IS_SWAPFILE(&vnode->vfs_inode)) { |
639 | printk(KERN_INFO | 638 | printk(KERN_INFO |
@@ -644,7 +643,7 @@ ssize_t afs_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
644 | if (!count) | 643 | if (!count) |
645 | return 0; | 644 | return 0; |
646 | 645 | ||
647 | result = generic_file_aio_write(iocb, iov, nr_segs, pos); | 646 | result = generic_file_write_iter(iocb, from); |
648 | if (IS_ERR_VALUE(result)) { | 647 | if (IS_ERR_VALUE(result)) { |
649 | _leave(" = %zd", result); | 648 | _leave(" = %zd", result); |
650 | return result; | 649 | return result; |
@@ -1241,6 +1241,7 @@ SYSCALL_DEFINE1(io_destroy, aio_context_t, ctx) | |||
1241 | 1241 | ||
1242 | typedef ssize_t (aio_rw_op)(struct kiocb *, const struct iovec *, | 1242 | typedef ssize_t (aio_rw_op)(struct kiocb *, const struct iovec *, |
1243 | unsigned long, loff_t); | 1243 | unsigned long, loff_t); |
1244 | typedef ssize_t (rw_iter_op)(struct kiocb *, struct iov_iter *); | ||
1244 | 1245 | ||
1245 | static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb, | 1246 | static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb, |
1246 | int rw, char __user *buf, | 1247 | int rw, char __user *buf, |
@@ -1298,7 +1299,9 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode, | |||
1298 | int rw; | 1299 | int rw; |
1299 | fmode_t mode; | 1300 | fmode_t mode; |
1300 | aio_rw_op *rw_op; | 1301 | aio_rw_op *rw_op; |
1302 | rw_iter_op *iter_op; | ||
1301 | struct iovec inline_vec, *iovec = &inline_vec; | 1303 | struct iovec inline_vec, *iovec = &inline_vec; |
1304 | struct iov_iter iter; | ||
1302 | 1305 | ||
1303 | switch (opcode) { | 1306 | switch (opcode) { |
1304 | case IOCB_CMD_PREAD: | 1307 | case IOCB_CMD_PREAD: |
@@ -1306,6 +1309,7 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode, | |||
1306 | mode = FMODE_READ; | 1309 | mode = FMODE_READ; |
1307 | rw = READ; | 1310 | rw = READ; |
1308 | rw_op = file->f_op->aio_read; | 1311 | rw_op = file->f_op->aio_read; |
1312 | iter_op = file->f_op->read_iter; | ||
1309 | goto rw_common; | 1313 | goto rw_common; |
1310 | 1314 | ||
1311 | case IOCB_CMD_PWRITE: | 1315 | case IOCB_CMD_PWRITE: |
@@ -1313,12 +1317,13 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode, | |||
1313 | mode = FMODE_WRITE; | 1317 | mode = FMODE_WRITE; |
1314 | rw = WRITE; | 1318 | rw = WRITE; |
1315 | rw_op = file->f_op->aio_write; | 1319 | rw_op = file->f_op->aio_write; |
1320 | iter_op = file->f_op->write_iter; | ||
1316 | goto rw_common; | 1321 | goto rw_common; |
1317 | rw_common: | 1322 | rw_common: |
1318 | if (unlikely(!(file->f_mode & mode))) | 1323 | if (unlikely(!(file->f_mode & mode))) |
1319 | return -EBADF; | 1324 | return -EBADF; |
1320 | 1325 | ||
1321 | if (!rw_op) | 1326 | if (!rw_op && !iter_op) |
1322 | return -EINVAL; | 1327 | return -EINVAL; |
1323 | 1328 | ||
1324 | ret = (opcode == IOCB_CMD_PREADV || | 1329 | ret = (opcode == IOCB_CMD_PREADV || |
@@ -1347,7 +1352,12 @@ rw_common: | |||
1347 | if (rw == WRITE) | 1352 | if (rw == WRITE) |
1348 | file_start_write(file); | 1353 | file_start_write(file); |
1349 | 1354 | ||
1350 | ret = rw_op(req, iovec, nr_segs, req->ki_pos); | 1355 | if (iter_op) { |
1356 | iov_iter_init(&iter, rw, iovec, nr_segs, req->ki_nbytes); | ||
1357 | ret = iter_op(req, &iter); | ||
1358 | } else { | ||
1359 | ret = rw_op(req, iovec, nr_segs, req->ki_pos); | ||
1360 | } | ||
1351 | 1361 | ||
1352 | if (rw == WRITE) | 1362 | if (rw == WRITE) |
1353 | file_end_write(file); | 1363 | file_end_write(file); |
diff --git a/fs/bfs/file.c b/fs/bfs/file.c index ae2892218335..e7f88ace1a25 100644 --- a/fs/bfs/file.c +++ b/fs/bfs/file.c | |||
@@ -23,10 +23,10 @@ | |||
23 | 23 | ||
24 | const struct file_operations bfs_file_operations = { | 24 | const struct file_operations bfs_file_operations = { |
25 | .llseek = generic_file_llseek, | 25 | .llseek = generic_file_llseek, |
26 | .read = do_sync_read, | 26 | .read = new_sync_read, |
27 | .aio_read = generic_file_aio_read, | 27 | .read_iter = generic_file_read_iter, |
28 | .write = do_sync_write, | 28 | .write = new_sync_write, |
29 | .aio_write = generic_file_aio_write, | 29 | .write_iter = generic_file_write_iter, |
30 | .mmap = generic_file_mmap, | 30 | .mmap = generic_file_mmap, |
31 | .splice_read = generic_file_splice_read, | 31 | .splice_read = generic_file_splice_read, |
32 | }; | 32 | }; |
diff --git a/fs/block_dev.c b/fs/block_dev.c index 83fba15cc394..6d7274619bf9 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -165,14 +165,15 @@ blkdev_get_block(struct inode *inode, sector_t iblock, | |||
165 | } | 165 | } |
166 | 166 | ||
167 | static ssize_t | 167 | static ssize_t |
168 | blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 168 | blkdev_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, |
169 | loff_t offset, unsigned long nr_segs) | 169 | loff_t offset) |
170 | { | 170 | { |
171 | struct file *file = iocb->ki_filp; | 171 | struct file *file = iocb->ki_filp; |
172 | struct inode *inode = file->f_mapping->host; | 172 | struct inode *inode = file->f_mapping->host; |
173 | 173 | ||
174 | return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset, | 174 | return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iter, |
175 | nr_segs, blkdev_get_block, NULL, NULL, 0); | 175 | offset, blkdev_get_block, |
176 | NULL, NULL, 0); | ||
176 | } | 177 | } |
177 | 178 | ||
178 | int __sync_blockdev(struct block_device *bdev, int wait) | 179 | int __sync_blockdev(struct block_device *bdev, int wait) |
@@ -1571,43 +1572,38 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
1571 | * Does not take i_mutex for the write and thus is not for general purpose | 1572 | * Does not take i_mutex for the write and thus is not for general purpose |
1572 | * use. | 1573 | * use. |
1573 | */ | 1574 | */ |
1574 | ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, | 1575 | ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) |
1575 | unsigned long nr_segs, loff_t pos) | ||
1576 | { | 1576 | { |
1577 | struct file *file = iocb->ki_filp; | 1577 | struct file *file = iocb->ki_filp; |
1578 | struct blk_plug plug; | 1578 | struct blk_plug plug; |
1579 | ssize_t ret; | 1579 | ssize_t ret; |
1580 | 1580 | ||
1581 | BUG_ON(iocb->ki_pos != pos); | ||
1582 | |||
1583 | blk_start_plug(&plug); | 1581 | blk_start_plug(&plug); |
1584 | ret = __generic_file_aio_write(iocb, iov, nr_segs); | 1582 | ret = __generic_file_write_iter(iocb, from); |
1585 | if (ret > 0) { | 1583 | if (ret > 0) { |
1586 | ssize_t err; | 1584 | ssize_t err; |
1587 | 1585 | err = generic_write_sync(file, iocb->ki_pos - ret, ret); | |
1588 | err = generic_write_sync(file, pos, ret); | ||
1589 | if (err < 0) | 1586 | if (err < 0) |
1590 | ret = err; | 1587 | ret = err; |
1591 | } | 1588 | } |
1592 | blk_finish_plug(&plug); | 1589 | blk_finish_plug(&plug); |
1593 | return ret; | 1590 | return ret; |
1594 | } | 1591 | } |
1595 | EXPORT_SYMBOL_GPL(blkdev_aio_write); | 1592 | EXPORT_SYMBOL_GPL(blkdev_write_iter); |
1596 | 1593 | ||
1597 | static ssize_t blkdev_aio_read(struct kiocb *iocb, const struct iovec *iov, | 1594 | static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) |
1598 | unsigned long nr_segs, loff_t pos) | ||
1599 | { | 1595 | { |
1600 | struct file *file = iocb->ki_filp; | 1596 | struct file *file = iocb->ki_filp; |
1601 | struct inode *bd_inode = file->f_mapping->host; | 1597 | struct inode *bd_inode = file->f_mapping->host; |
1602 | loff_t size = i_size_read(bd_inode); | 1598 | loff_t size = i_size_read(bd_inode); |
1599 | loff_t pos = iocb->ki_pos; | ||
1603 | 1600 | ||
1604 | if (pos >= size) | 1601 | if (pos >= size) |
1605 | return 0; | 1602 | return 0; |
1606 | 1603 | ||
1607 | size -= pos; | 1604 | size -= pos; |
1608 | if (size < iocb->ki_nbytes) | 1605 | iov_iter_truncate(to, size); |
1609 | nr_segs = iov_shorten((struct iovec *)iov, nr_segs, size); | 1606 | return generic_file_read_iter(iocb, to); |
1610 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
1611 | } | 1607 | } |
1612 | 1608 | ||
1613 | /* | 1609 | /* |
@@ -1639,10 +1635,10 @@ const struct file_operations def_blk_fops = { | |||
1639 | .open = blkdev_open, | 1635 | .open = blkdev_open, |
1640 | .release = blkdev_close, | 1636 | .release = blkdev_close, |
1641 | .llseek = block_llseek, | 1637 | .llseek = block_llseek, |
1642 | .read = do_sync_read, | 1638 | .read = new_sync_read, |
1643 | .write = do_sync_write, | 1639 | .write = new_sync_write, |
1644 | .aio_read = blkdev_aio_read, | 1640 | .read_iter = blkdev_read_iter, |
1645 | .aio_write = blkdev_aio_write, | 1641 | .write_iter = blkdev_write_iter, |
1646 | .mmap = generic_file_mmap, | 1642 | .mmap = generic_file_mmap, |
1647 | .fsync = blkdev_fsync, | 1643 | .fsync = blkdev_fsync, |
1648 | .unlocked_ioctl = block_ioctl, | 1644 | .unlocked_ioctl = block_ioctl, |
@@ -1650,7 +1646,7 @@ const struct file_operations def_blk_fops = { | |||
1650 | .compat_ioctl = compat_blkdev_ioctl, | 1646 | .compat_ioctl = compat_blkdev_ioctl, |
1651 | #endif | 1647 | #endif |
1652 | .splice_read = generic_file_splice_read, | 1648 | .splice_read = generic_file_splice_read, |
1653 | .splice_write = generic_file_splice_write, | 1649 | .splice_write = iter_file_splice_write, |
1654 | }; | 1650 | }; |
1655 | 1651 | ||
1656 | int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) | 1652 | int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e472441feb5d..1f2b99cb55ea 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -448,7 +448,7 @@ static noinline int btrfs_copy_from_user(loff_t pos, int num_pages, | |||
448 | write_bytes -= copied; | 448 | write_bytes -= copied; |
449 | total_copied += copied; | 449 | total_copied += copied; |
450 | 450 | ||
451 | /* Return to btrfs_file_aio_write to fault page */ | 451 | /* Return to btrfs_file_write_iter to fault page */ |
452 | if (unlikely(copied == 0)) | 452 | if (unlikely(copied == 0)) |
453 | break; | 453 | break; |
454 | 454 | ||
@@ -1675,27 +1675,22 @@ again: | |||
1675 | } | 1675 | } |
1676 | 1676 | ||
1677 | static ssize_t __btrfs_direct_write(struct kiocb *iocb, | 1677 | static ssize_t __btrfs_direct_write(struct kiocb *iocb, |
1678 | const struct iovec *iov, | 1678 | struct iov_iter *from, |
1679 | unsigned long nr_segs, loff_t pos, | 1679 | loff_t pos) |
1680 | size_t count, size_t ocount) | ||
1681 | { | 1680 | { |
1682 | struct file *file = iocb->ki_filp; | 1681 | struct file *file = iocb->ki_filp; |
1683 | struct iov_iter i; | ||
1684 | ssize_t written; | 1682 | ssize_t written; |
1685 | ssize_t written_buffered; | 1683 | ssize_t written_buffered; |
1686 | loff_t endbyte; | 1684 | loff_t endbyte; |
1687 | int err; | 1685 | int err; |
1688 | 1686 | ||
1689 | written = generic_file_direct_write(iocb, iov, &nr_segs, pos, | 1687 | written = generic_file_direct_write(iocb, from, pos); |
1690 | count, ocount); | ||
1691 | 1688 | ||
1692 | if (written < 0 || written == count) | 1689 | if (written < 0 || !iov_iter_count(from)) |
1693 | return written; | 1690 | return written; |
1694 | 1691 | ||
1695 | pos += written; | 1692 | pos += written; |
1696 | count -= written; | 1693 | written_buffered = __btrfs_buffered_write(file, from, pos); |
1697 | iov_iter_init(&i, iov, nr_segs, count, written); | ||
1698 | written_buffered = __btrfs_buffered_write(file, &i, pos); | ||
1699 | if (written_buffered < 0) { | 1694 | if (written_buffered < 0) { |
1700 | err = written_buffered; | 1695 | err = written_buffered; |
1701 | goto out; | 1696 | goto out; |
@@ -1730,9 +1725,8 @@ static void update_time_for_write(struct inode *inode) | |||
1730 | inode_inc_iversion(inode); | 1725 | inode_inc_iversion(inode); |
1731 | } | 1726 | } |
1732 | 1727 | ||
1733 | static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | 1728 | static ssize_t btrfs_file_write_iter(struct kiocb *iocb, |
1734 | const struct iovec *iov, | 1729 | struct iov_iter *from) |
1735 | unsigned long nr_segs, loff_t pos) | ||
1736 | { | 1730 | { |
1737 | struct file *file = iocb->ki_filp; | 1731 | struct file *file = iocb->ki_filp; |
1738 | struct inode *inode = file_inode(file); | 1732 | struct inode *inode = file_inode(file); |
@@ -1741,18 +1735,12 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
1741 | u64 end_pos; | 1735 | u64 end_pos; |
1742 | ssize_t num_written = 0; | 1736 | ssize_t num_written = 0; |
1743 | ssize_t err = 0; | 1737 | ssize_t err = 0; |
1744 | size_t count, ocount; | 1738 | size_t count = iov_iter_count(from); |
1745 | bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host); | 1739 | bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host); |
1740 | loff_t pos = iocb->ki_pos; | ||
1746 | 1741 | ||
1747 | mutex_lock(&inode->i_mutex); | 1742 | mutex_lock(&inode->i_mutex); |
1748 | 1743 | ||
1749 | err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ); | ||
1750 | if (err) { | ||
1751 | mutex_unlock(&inode->i_mutex); | ||
1752 | goto out; | ||
1753 | } | ||
1754 | count = ocount; | ||
1755 | |||
1756 | current->backing_dev_info = inode->i_mapping->backing_dev_info; | 1744 | current->backing_dev_info = inode->i_mapping->backing_dev_info; |
1757 | err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode)); | 1745 | err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode)); |
1758 | if (err) { | 1746 | if (err) { |
@@ -1765,6 +1753,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
1765 | goto out; | 1753 | goto out; |
1766 | } | 1754 | } |
1767 | 1755 | ||
1756 | iov_iter_truncate(from, count); | ||
1757 | |||
1768 | err = file_remove_suid(file); | 1758 | err = file_remove_suid(file); |
1769 | if (err) { | 1759 | if (err) { |
1770 | mutex_unlock(&inode->i_mutex); | 1760 | mutex_unlock(&inode->i_mutex); |
@@ -1806,14 +1796,9 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, | |||
1806 | atomic_inc(&BTRFS_I(inode)->sync_writers); | 1796 | atomic_inc(&BTRFS_I(inode)->sync_writers); |
1807 | 1797 | ||
1808 | if (unlikely(file->f_flags & O_DIRECT)) { | 1798 | if (unlikely(file->f_flags & O_DIRECT)) { |
1809 | num_written = __btrfs_direct_write(iocb, iov, nr_segs, | 1799 | num_written = __btrfs_direct_write(iocb, from, pos); |
1810 | pos, count, ocount); | ||
1811 | } else { | 1800 | } else { |
1812 | struct iov_iter i; | 1801 | num_written = __btrfs_buffered_write(file, from, pos); |
1813 | |||
1814 | iov_iter_init(&i, iov, nr_segs, count, num_written); | ||
1815 | |||
1816 | num_written = __btrfs_buffered_write(file, &i, pos); | ||
1817 | if (num_written > 0) | 1802 | if (num_written > 0) |
1818 | iocb->ki_pos = pos + num_written; | 1803 | iocb->ki_pos = pos + num_written; |
1819 | } | 1804 | } |
@@ -2740,11 +2725,11 @@ out: | |||
2740 | 2725 | ||
2741 | const struct file_operations btrfs_file_operations = { | 2726 | const struct file_operations btrfs_file_operations = { |
2742 | .llseek = btrfs_file_llseek, | 2727 | .llseek = btrfs_file_llseek, |
2743 | .read = do_sync_read, | 2728 | .read = new_sync_read, |
2744 | .write = do_sync_write, | 2729 | .write = new_sync_write, |
2745 | .aio_read = generic_file_aio_read, | 2730 | .read_iter = generic_file_read_iter, |
2746 | .splice_read = generic_file_splice_read, | 2731 | .splice_read = generic_file_splice_read, |
2747 | .aio_write = btrfs_file_aio_write, | 2732 | .write_iter = btrfs_file_write_iter, |
2748 | .mmap = btrfs_file_mmap, | 2733 | .mmap = btrfs_file_mmap, |
2749 | .open = generic_file_open, | 2734 | .open = generic_file_open, |
2750 | .release = btrfs_release_file, | 2735 | .release = btrfs_release_file, |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7fa5f7fd7bc7..8925f66a1411 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -7445,39 +7445,30 @@ free_ordered: | |||
7445 | } | 7445 | } |
7446 | 7446 | ||
7447 | static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, | 7447 | static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, |
7448 | const struct iovec *iov, loff_t offset, | 7448 | const struct iov_iter *iter, loff_t offset) |
7449 | unsigned long nr_segs) | ||
7450 | { | 7449 | { |
7451 | int seg; | 7450 | int seg; |
7452 | int i; | 7451 | int i; |
7453 | size_t size; | ||
7454 | unsigned long addr; | ||
7455 | unsigned blocksize_mask = root->sectorsize - 1; | 7452 | unsigned blocksize_mask = root->sectorsize - 1; |
7456 | ssize_t retval = -EINVAL; | 7453 | ssize_t retval = -EINVAL; |
7457 | loff_t end = offset; | ||
7458 | 7454 | ||
7459 | if (offset & blocksize_mask) | 7455 | if (offset & blocksize_mask) |
7460 | goto out; | 7456 | goto out; |
7461 | 7457 | ||
7462 | /* Check the memory alignment. Blocks cannot straddle pages */ | 7458 | if (iov_iter_alignment(iter) & blocksize_mask) |
7463 | for (seg = 0; seg < nr_segs; seg++) { | 7459 | goto out; |
7464 | addr = (unsigned long)iov[seg].iov_base; | ||
7465 | size = iov[seg].iov_len; | ||
7466 | end += size; | ||
7467 | if ((addr & blocksize_mask) || (size & blocksize_mask)) | ||
7468 | goto out; | ||
7469 | |||
7470 | /* If this is a write we don't need to check anymore */ | ||
7471 | if (rw & WRITE) | ||
7472 | continue; | ||
7473 | 7460 | ||
7474 | /* | 7461 | /* If this is a write we don't need to check anymore */ |
7475 | * Check to make sure we don't have duplicate iov_base's in this | 7462 | if (rw & WRITE) |
7476 | * iovec, if so return EINVAL, otherwise we'll get csum errors | 7463 | return 0; |
7477 | * when reading back. | 7464 | /* |
7478 | */ | 7465 | * Check to make sure we don't have duplicate iov_base's in this |
7479 | for (i = seg + 1; i < nr_segs; i++) { | 7466 | * iovec, if so return EINVAL, otherwise we'll get csum errors |
7480 | if (iov[seg].iov_base == iov[i].iov_base) | 7467 | * when reading back. |
7468 | */ | ||
7469 | for (seg = 0; seg < iter->nr_segs; seg++) { | ||
7470 | for (i = seg + 1; i < iter->nr_segs; i++) { | ||
7471 | if (iter->iov[seg].iov_base == iter->iov[i].iov_base) | ||
7481 | goto out; | 7472 | goto out; |
7482 | } | 7473 | } |
7483 | } | 7474 | } |
@@ -7487,8 +7478,7 @@ out: | |||
7487 | } | 7478 | } |
7488 | 7479 | ||
7489 | static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | 7480 | static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, |
7490 | const struct iovec *iov, loff_t offset, | 7481 | struct iov_iter *iter, loff_t offset) |
7491 | unsigned long nr_segs) | ||
7492 | { | 7482 | { |
7493 | struct file *file = iocb->ki_filp; | 7483 | struct file *file = iocb->ki_filp; |
7494 | struct inode *inode = file->f_mapping->host; | 7484 | struct inode *inode = file->f_mapping->host; |
@@ -7498,8 +7488,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
7498 | bool relock = false; | 7488 | bool relock = false; |
7499 | ssize_t ret; | 7489 | ssize_t ret; |
7500 | 7490 | ||
7501 | if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iov, | 7491 | if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iter, offset)) |
7502 | offset, nr_segs)) | ||
7503 | return 0; | 7492 | return 0; |
7504 | 7493 | ||
7505 | atomic_inc(&inode->i_dio_count); | 7494 | atomic_inc(&inode->i_dio_count); |
@@ -7511,7 +7500,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
7511 | * we need to flush the dirty pages again to make absolutely sure | 7500 | * we need to flush the dirty pages again to make absolutely sure |
7512 | * that any outstanding dirty pages are on disk. | 7501 | * that any outstanding dirty pages are on disk. |
7513 | */ | 7502 | */ |
7514 | count = iov_length(iov, nr_segs); | 7503 | count = iov_iter_count(iter); |
7515 | if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, | 7504 | if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, |
7516 | &BTRFS_I(inode)->runtime_flags)) | 7505 | &BTRFS_I(inode)->runtime_flags)) |
7517 | filemap_fdatawrite_range(inode->i_mapping, offset, count); | 7506 | filemap_fdatawrite_range(inode->i_mapping, offset, count); |
@@ -7538,7 +7527,7 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, | |||
7538 | 7527 | ||
7539 | ret = __blockdev_direct_IO(rw, iocb, inode, | 7528 | ret = __blockdev_direct_IO(rw, iocb, inode, |
7540 | BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev, | 7529 | BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev, |
7541 | iov, offset, nr_segs, btrfs_get_blocks_direct, NULL, | 7530 | iter, offset, btrfs_get_blocks_direct, NULL, |
7542 | btrfs_submit_direct, flags); | 7531 | btrfs_submit_direct, flags); |
7543 | if (rw & WRITE) { | 7532 | if (rw & WRITE) { |
7544 | if (ret < 0 && ret != -EIOCBQUEUED) | 7533 | if (ret < 0 && ret != -EIOCBQUEUED) |
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 65a30e817dd8..4f3f69079f36 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c | |||
@@ -1187,8 +1187,8 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, | |||
1187 | * never get called. | 1187 | * never get called. |
1188 | */ | 1188 | */ |
1189 | static ssize_t ceph_direct_io(int rw, struct kiocb *iocb, | 1189 | static ssize_t ceph_direct_io(int rw, struct kiocb *iocb, |
1190 | const struct iovec *iov, | 1190 | struct iov_iter *iter, |
1191 | loff_t pos, unsigned long nr_segs) | 1191 | loff_t pos) |
1192 | { | 1192 | { |
1193 | WARN_ON(1); | 1193 | WARN_ON(1); |
1194 | return -EINVAL; | 1194 | return -EINVAL; |
diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 88a6df4cbe6d..302085100c28 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c | |||
@@ -418,7 +418,7 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *i, | |||
418 | struct page **pages; | 418 | struct page **pages; |
419 | u64 off = iocb->ki_pos; | 419 | u64 off = iocb->ki_pos; |
420 | int num_pages, ret; | 420 | int num_pages, ret; |
421 | size_t len = i->count; | 421 | size_t len = iov_iter_count(i); |
422 | 422 | ||
423 | dout("sync_read on file %p %llu~%u %s\n", file, off, | 423 | dout("sync_read on file %p %llu~%u %s\n", file, off, |
424 | (unsigned)len, | 424 | (unsigned)len, |
@@ -436,25 +436,26 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *i, | |||
436 | 436 | ||
437 | if (file->f_flags & O_DIRECT) { | 437 | if (file->f_flags & O_DIRECT) { |
438 | while (iov_iter_count(i)) { | 438 | while (iov_iter_count(i)) { |
439 | void __user *data = i->iov[0].iov_base + i->iov_offset; | 439 | size_t start; |
440 | size_t len = i->iov[0].iov_len - i->iov_offset; | 440 | ssize_t n; |
441 | 441 | ||
442 | num_pages = calc_pages_for((unsigned long)data, len); | 442 | n = iov_iter_get_pages_alloc(i, &pages, INT_MAX, &start); |
443 | pages = ceph_get_direct_page_vector(data, | 443 | if (n < 0) |
444 | num_pages, true); | 444 | return n; |
445 | if (IS_ERR(pages)) | ||
446 | return PTR_ERR(pages); | ||
447 | 445 | ||
448 | ret = striped_read(inode, off, len, | 446 | num_pages = (n + start + PAGE_SIZE - 1) / PAGE_SIZE; |
447 | |||
448 | ret = striped_read(inode, off, n, | ||
449 | pages, num_pages, checkeof, | 449 | pages, num_pages, checkeof, |
450 | 1, (unsigned long)data & ~PAGE_MASK); | 450 | 1, start); |
451 | |||
451 | ceph_put_page_vector(pages, num_pages, true); | 452 | ceph_put_page_vector(pages, num_pages, true); |
452 | 453 | ||
453 | if (ret <= 0) | 454 | if (ret <= 0) |
454 | break; | 455 | break; |
455 | off += ret; | 456 | off += ret; |
456 | iov_iter_advance(i, ret); | 457 | iov_iter_advance(i, ret); |
457 | if (ret < len) | 458 | if (ret < n) |
458 | break; | 459 | break; |
459 | } | 460 | } |
460 | } else { | 461 | } else { |
@@ -466,25 +467,14 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *i, | |||
466 | num_pages, checkeof, 0, 0); | 467 | num_pages, checkeof, 0, 0); |
467 | if (ret > 0) { | 468 | if (ret > 0) { |
468 | int l, k = 0; | 469 | int l, k = 0; |
469 | size_t left = len = ret; | 470 | size_t left = ret; |
470 | 471 | ||
471 | while (left) { | 472 | while (left) { |
472 | void __user *data = i->iov[0].iov_base | 473 | int copy = min_t(size_t, PAGE_SIZE, left); |
473 | + i->iov_offset; | 474 | l = copy_page_to_iter(pages[k++], 0, copy, i); |
474 | l = min(i->iov[0].iov_len - i->iov_offset, | 475 | off += l; |
475 | left); | 476 | left -= l; |
476 | 477 | if (l < copy) | |
477 | ret = ceph_copy_page_vector_to_user(&pages[k], | ||
478 | data, off, | ||
479 | l); | ||
480 | if (ret > 0) { | ||
481 | iov_iter_advance(i, ret); | ||
482 | left -= ret; | ||
483 | off += ret; | ||
484 | k = calc_pages_for(iocb->ki_pos, | ||
485 | len - left + 1) - 1; | ||
486 | BUG_ON(k >= num_pages && left); | ||
487 | } else | ||
488 | break; | 478 | break; |
489 | } | 479 | } |
490 | } | 480 | } |
@@ -541,8 +531,7 @@ static void ceph_sync_write_unsafe(struct ceph_osd_request *req, bool unsafe) | |||
541 | * objects, rollback on failure, etc.) | 531 | * objects, rollback on failure, etc.) |
542 | */ | 532 | */ |
543 | static ssize_t | 533 | static ssize_t |
544 | ceph_sync_direct_write(struct kiocb *iocb, const struct iovec *iov, | 534 | ceph_sync_direct_write(struct kiocb *iocb, struct iov_iter *from) |
545 | unsigned long nr_segs, size_t count) | ||
546 | { | 535 | { |
547 | struct file *file = iocb->ki_filp; | 536 | struct file *file = iocb->ki_filp; |
548 | struct inode *inode = file_inode(file); | 537 | struct inode *inode = file_inode(file); |
@@ -556,11 +545,10 @@ ceph_sync_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
556 | int written = 0; | 545 | int written = 0; |
557 | int flags; | 546 | int flags; |
558 | int check_caps = 0; | 547 | int check_caps = 0; |
559 | int page_align; | ||
560 | int ret; | 548 | int ret; |
561 | struct timespec mtime = CURRENT_TIME; | 549 | struct timespec mtime = CURRENT_TIME; |
562 | loff_t pos = iocb->ki_pos; | 550 | loff_t pos = iocb->ki_pos; |
563 | struct iov_iter i; | 551 | size_t count = iov_iter_count(from); |
564 | 552 | ||
565 | if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) | 553 | if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) |
566 | return -EROFS; | 554 | return -EROFS; |
@@ -582,13 +570,10 @@ ceph_sync_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
582 | CEPH_OSD_FLAG_ONDISK | | 570 | CEPH_OSD_FLAG_ONDISK | |
583 | CEPH_OSD_FLAG_WRITE; | 571 | CEPH_OSD_FLAG_WRITE; |
584 | 572 | ||
585 | iov_iter_init(&i, iov, nr_segs, count, 0); | 573 | while (iov_iter_count(from) > 0) { |
586 | 574 | u64 len = iov_iter_single_seg_count(from); | |
587 | while (iov_iter_count(&i) > 0) { | 575 | size_t start; |
588 | void __user *data = i.iov->iov_base + i.iov_offset; | 576 | ssize_t n; |
589 | u64 len = i.iov->iov_len - i.iov_offset; | ||
590 | |||
591 | page_align = (unsigned long)data & ~PAGE_MASK; | ||
592 | 577 | ||
593 | snapc = ci->i_snap_realm->cached_context; | 578 | snapc = ci->i_snap_realm->cached_context; |
594 | vino = ceph_vino(inode); | 579 | vino = ceph_vino(inode); |
@@ -604,20 +589,21 @@ ceph_sync_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
604 | break; | 589 | break; |
605 | } | 590 | } |
606 | 591 | ||
607 | num_pages = calc_pages_for(page_align, len); | 592 | n = iov_iter_get_pages_alloc(from, &pages, len, &start); |
608 | pages = ceph_get_direct_page_vector(data, num_pages, false); | 593 | if (unlikely(n < 0)) { |
609 | if (IS_ERR(pages)) { | 594 | ret = n; |
610 | ret = PTR_ERR(pages); | 595 | ceph_osdc_put_request(req); |
611 | goto out; | 596 | break; |
612 | } | 597 | } |
613 | 598 | ||
599 | num_pages = (n + start + PAGE_SIZE - 1) / PAGE_SIZE; | ||
614 | /* | 600 | /* |
615 | * throw out any page cache pages in this range. this | 601 | * throw out any page cache pages in this range. this |
616 | * may block. | 602 | * may block. |
617 | */ | 603 | */ |
618 | truncate_inode_pages_range(inode->i_mapping, pos, | 604 | truncate_inode_pages_range(inode->i_mapping, pos, |
619 | (pos+len) | (PAGE_CACHE_SIZE-1)); | 605 | (pos+n) | (PAGE_CACHE_SIZE-1)); |
620 | osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align, | 606 | osd_req_op_extent_osd_data_pages(req, 0, pages, n, start, |
621 | false, false); | 607 | false, false); |
622 | 608 | ||
623 | /* BUG_ON(vino.snap != CEPH_NOSNAP); */ | 609 | /* BUG_ON(vino.snap != CEPH_NOSNAP); */ |
@@ -629,22 +615,20 @@ ceph_sync_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
629 | 615 | ||
630 | ceph_put_page_vector(pages, num_pages, false); | 616 | ceph_put_page_vector(pages, num_pages, false); |
631 | 617 | ||
632 | out: | ||
633 | ceph_osdc_put_request(req); | 618 | ceph_osdc_put_request(req); |
634 | if (ret == 0) { | 619 | if (ret) |
635 | pos += len; | ||
636 | written += len; | ||
637 | iov_iter_advance(&i, (size_t)len); | ||
638 | |||
639 | if (pos > i_size_read(inode)) { | ||
640 | check_caps = ceph_inode_set_size(inode, pos); | ||
641 | if (check_caps) | ||
642 | ceph_check_caps(ceph_inode(inode), | ||
643 | CHECK_CAPS_AUTHONLY, | ||
644 | NULL); | ||
645 | } | ||
646 | } else | ||
647 | break; | 620 | break; |
621 | pos += n; | ||
622 | written += n; | ||
623 | iov_iter_advance(from, n); | ||
624 | |||
625 | if (pos > i_size_read(inode)) { | ||
626 | check_caps = ceph_inode_set_size(inode, pos); | ||
627 | if (check_caps) | ||
628 | ceph_check_caps(ceph_inode(inode), | ||
629 | CHECK_CAPS_AUTHONLY, | ||
630 | NULL); | ||
631 | } | ||
648 | } | 632 | } |
649 | 633 | ||
650 | if (ret != -EOLDSNAPC && written > 0) { | 634 | if (ret != -EOLDSNAPC && written > 0) { |
@@ -662,8 +646,7 @@ out: | |||
662 | * correct atomic write, we should e.g. take write locks on all | 646 | * correct atomic write, we should e.g. take write locks on all |
663 | * objects, rollback on failure, etc.) | 647 | * objects, rollback on failure, etc.) |
664 | */ | 648 | */ |
665 | static ssize_t ceph_sync_write(struct kiocb *iocb, const struct iovec *iov, | 649 | static ssize_t ceph_sync_write(struct kiocb *iocb, struct iov_iter *from) |
666 | unsigned long nr_segs, size_t count) | ||
667 | { | 650 | { |
668 | struct file *file = iocb->ki_filp; | 651 | struct file *file = iocb->ki_filp; |
669 | struct inode *inode = file_inode(file); | 652 | struct inode *inode = file_inode(file); |
@@ -681,7 +664,7 @@ static ssize_t ceph_sync_write(struct kiocb *iocb, const struct iovec *iov, | |||
681 | int ret; | 664 | int ret; |
682 | struct timespec mtime = CURRENT_TIME; | 665 | struct timespec mtime = CURRENT_TIME; |
683 | loff_t pos = iocb->ki_pos; | 666 | loff_t pos = iocb->ki_pos; |
684 | struct iov_iter i; | 667 | size_t count = iov_iter_count(from); |
685 | 668 | ||
686 | if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) | 669 | if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) |
687 | return -EROFS; | 670 | return -EROFS; |
@@ -703,9 +686,7 @@ static ssize_t ceph_sync_write(struct kiocb *iocb, const struct iovec *iov, | |||
703 | CEPH_OSD_FLAG_WRITE | | 686 | CEPH_OSD_FLAG_WRITE | |
704 | CEPH_OSD_FLAG_ACK; | 687 | CEPH_OSD_FLAG_ACK; |
705 | 688 | ||
706 | iov_iter_init(&i, iov, nr_segs, count, 0); | 689 | while ((len = iov_iter_count(from)) > 0) { |
707 | |||
708 | while ((len = iov_iter_count(&i)) > 0) { | ||
709 | size_t left; | 690 | size_t left; |
710 | int n; | 691 | int n; |
711 | 692 | ||
@@ -737,13 +718,12 @@ static ssize_t ceph_sync_write(struct kiocb *iocb, const struct iovec *iov, | |||
737 | left = len; | 718 | left = len; |
738 | for (n = 0; n < num_pages; n++) { | 719 | for (n = 0; n < num_pages; n++) { |
739 | size_t plen = min_t(size_t, left, PAGE_SIZE); | 720 | size_t plen = min_t(size_t, left, PAGE_SIZE); |
740 | ret = iov_iter_copy_from_user(pages[n], &i, 0, plen); | 721 | ret = copy_page_from_iter(pages[n], 0, plen, from); |
741 | if (ret != plen) { | 722 | if (ret != plen) { |
742 | ret = -EFAULT; | 723 | ret = -EFAULT; |
743 | break; | 724 | break; |
744 | } | 725 | } |
745 | left -= ret; | 726 | left -= ret; |
746 | iov_iter_advance(&i, ret); | ||
747 | } | 727 | } |
748 | 728 | ||
749 | if (ret < 0) { | 729 | if (ret < 0) { |
@@ -796,8 +776,7 @@ out: | |||
796 | * | 776 | * |
797 | * Hmm, the sync read case isn't actually async... should it be? | 777 | * Hmm, the sync read case isn't actually async... should it be? |
798 | */ | 778 | */ |
799 | static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, | 779 | static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) |
800 | unsigned long nr_segs, loff_t pos) | ||
801 | { | 780 | { |
802 | struct file *filp = iocb->ki_filp; | 781 | struct file *filp = iocb->ki_filp; |
803 | struct ceph_file_info *fi = filp->private_data; | 782 | struct ceph_file_info *fi = filp->private_data; |
@@ -823,40 +802,20 @@ again: | |||
823 | if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 || | 802 | if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 || |
824 | (iocb->ki_filp->f_flags & O_DIRECT) || | 803 | (iocb->ki_filp->f_flags & O_DIRECT) || |
825 | (fi->flags & CEPH_F_SYNC)) { | 804 | (fi->flags & CEPH_F_SYNC)) { |
826 | struct iov_iter i; | ||
827 | 805 | ||
828 | dout("aio_sync_read %p %llx.%llx %llu~%u got cap refs on %s\n", | 806 | dout("aio_sync_read %p %llx.%llx %llu~%u got cap refs on %s\n", |
829 | inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, | 807 | inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, |
830 | ceph_cap_string(got)); | 808 | ceph_cap_string(got)); |
831 | 809 | ||
832 | if (!read) { | ||
833 | ret = generic_segment_checks(iov, &nr_segs, | ||
834 | &len, VERIFY_WRITE); | ||
835 | if (ret) | ||
836 | goto out; | ||
837 | } | ||
838 | |||
839 | iov_iter_init(&i, iov, nr_segs, len, read); | ||
840 | |||
841 | /* hmm, this isn't really async... */ | 810 | /* hmm, this isn't really async... */ |
842 | ret = ceph_sync_read(iocb, &i, &checkeof); | 811 | ret = ceph_sync_read(iocb, to, &checkeof); |
843 | } else { | 812 | } else { |
844 | /* | ||
845 | * We can't modify the content of iov, | ||
846 | * so we only read from beginning. | ||
847 | */ | ||
848 | if (read) { | ||
849 | iocb->ki_pos = pos; | ||
850 | len = iocb->ki_nbytes; | ||
851 | read = 0; | ||
852 | } | ||
853 | dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", | 813 | dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", |
854 | inode, ceph_vinop(inode), pos, (unsigned)len, | 814 | inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, |
855 | ceph_cap_string(got)); | 815 | ceph_cap_string(got)); |
856 | 816 | ||
857 | ret = generic_file_aio_read(iocb, iov, nr_segs, pos); | 817 | ret = generic_file_read_iter(iocb, to); |
858 | } | 818 | } |
859 | out: | ||
860 | dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", | 819 | dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", |
861 | inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret); | 820 | inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret); |
862 | ceph_put_cap_refs(ci, got); | 821 | ceph_put_cap_refs(ci, got); |
@@ -872,6 +831,7 @@ out: | |||
872 | ", reading more\n", iocb->ki_pos, | 831 | ", reading more\n", iocb->ki_pos, |
873 | inode->i_size); | 832 | inode->i_size); |
874 | 833 | ||
834 | iov_iter_advance(to, ret); | ||
875 | read += ret; | 835 | read += ret; |
876 | len -= ret; | 836 | len -= ret; |
877 | checkeof = 0; | 837 | checkeof = 0; |
@@ -895,8 +855,7 @@ out: | |||
895 | * | 855 | * |
896 | * If we are near ENOSPC, write synchronously. | 856 | * If we are near ENOSPC, write synchronously. |
897 | */ | 857 | */ |
898 | static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, | 858 | static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) |
899 | unsigned long nr_segs, loff_t pos) | ||
900 | { | 859 | { |
901 | struct file *file = iocb->ki_filp; | 860 | struct file *file = iocb->ki_filp; |
902 | struct ceph_file_info *fi = file->private_data; | 861 | struct ceph_file_info *fi = file->private_data; |
@@ -904,18 +863,15 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
904 | struct ceph_inode_info *ci = ceph_inode(inode); | 863 | struct ceph_inode_info *ci = ceph_inode(inode); |
905 | struct ceph_osd_client *osdc = | 864 | struct ceph_osd_client *osdc = |
906 | &ceph_sb_to_client(inode->i_sb)->client->osdc; | 865 | &ceph_sb_to_client(inode->i_sb)->client->osdc; |
907 | ssize_t count, written = 0; | 866 | ssize_t count = iov_iter_count(from), written = 0; |
908 | int err, want, got; | 867 | int err, want, got; |
868 | loff_t pos = iocb->ki_pos; | ||
909 | 869 | ||
910 | if (ceph_snap(inode) != CEPH_NOSNAP) | 870 | if (ceph_snap(inode) != CEPH_NOSNAP) |
911 | return -EROFS; | 871 | return -EROFS; |
912 | 872 | ||
913 | mutex_lock(&inode->i_mutex); | 873 | mutex_lock(&inode->i_mutex); |
914 | 874 | ||
915 | err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ); | ||
916 | if (err) | ||
917 | goto out; | ||
918 | |||
919 | /* We can write back this queue in page reclaim */ | 875 | /* We can write back this queue in page reclaim */ |
920 | current->backing_dev_info = file->f_mapping->backing_dev_info; | 876 | current->backing_dev_info = file->f_mapping->backing_dev_info; |
921 | 877 | ||
@@ -925,6 +881,7 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
925 | 881 | ||
926 | if (count == 0) | 882 | if (count == 0) |
927 | goto out; | 883 | goto out; |
884 | iov_iter_truncate(from, count); | ||
928 | 885 | ||
929 | err = file_remove_suid(file); | 886 | err = file_remove_suid(file); |
930 | if (err) | 887 | if (err) |
@@ -956,23 +913,26 @@ retry_snap: | |||
956 | 913 | ||
957 | if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 || | 914 | if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 || |
958 | (file->f_flags & O_DIRECT) || (fi->flags & CEPH_F_SYNC)) { | 915 | (file->f_flags & O_DIRECT) || (fi->flags & CEPH_F_SYNC)) { |
916 | struct iov_iter data; | ||
959 | mutex_unlock(&inode->i_mutex); | 917 | mutex_unlock(&inode->i_mutex); |
918 | /* we might need to revert back to that point */ | ||
919 | data = *from; | ||
960 | if (file->f_flags & O_DIRECT) | 920 | if (file->f_flags & O_DIRECT) |
961 | written = ceph_sync_direct_write(iocb, iov, | 921 | written = ceph_sync_direct_write(iocb, &data); |
962 | nr_segs, count); | ||
963 | else | 922 | else |
964 | written = ceph_sync_write(iocb, iov, nr_segs, count); | 923 | written = ceph_sync_write(iocb, &data); |
965 | if (written == -EOLDSNAPC) { | 924 | if (written == -EOLDSNAPC) { |
966 | dout("aio_write %p %llx.%llx %llu~%u" | 925 | dout("aio_write %p %llx.%llx %llu~%u" |
967 | "got EOLDSNAPC, retrying\n", | 926 | "got EOLDSNAPC, retrying\n", |
968 | inode, ceph_vinop(inode), | 927 | inode, ceph_vinop(inode), |
969 | pos, (unsigned)iov->iov_len); | 928 | pos, (unsigned)count); |
970 | mutex_lock(&inode->i_mutex); | 929 | mutex_lock(&inode->i_mutex); |
971 | goto retry_snap; | 930 | goto retry_snap; |
972 | } | 931 | } |
932 | if (written > 0) | ||
933 | iov_iter_advance(from, written); | ||
973 | } else { | 934 | } else { |
974 | loff_t old_size = inode->i_size; | 935 | loff_t old_size = inode->i_size; |
975 | struct iov_iter from; | ||
976 | /* | 936 | /* |
977 | * No need to acquire the i_truncate_mutex. Because | 937 | * No need to acquire the i_truncate_mutex. Because |
978 | * the MDS revokes Fwb caps before sending truncate | 938 | * the MDS revokes Fwb caps before sending truncate |
@@ -980,8 +940,7 @@ retry_snap: | |||
980 | * are pending vmtruncate. So write and vmtruncate | 940 | * are pending vmtruncate. So write and vmtruncate |
981 | * can not run at the same time | 941 | * can not run at the same time |
982 | */ | 942 | */ |
983 | iov_iter_init(&from, iov, nr_segs, count, 0); | 943 | written = generic_perform_write(file, from, pos); |
984 | written = generic_perform_write(file, &from, pos); | ||
985 | if (likely(written >= 0)) | 944 | if (likely(written >= 0)) |
986 | iocb->ki_pos = pos + written; | 945 | iocb->ki_pos = pos + written; |
987 | if (inode->i_size > old_size) | 946 | if (inode->i_size > old_size) |
@@ -999,7 +958,7 @@ retry_snap: | |||
999 | } | 958 | } |
1000 | 959 | ||
1001 | dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n", | 960 | dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n", |
1002 | inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len, | 961 | inode, ceph_vinop(inode), pos, (unsigned)count, |
1003 | ceph_cap_string(got)); | 962 | ceph_cap_string(got)); |
1004 | ceph_put_cap_refs(ci, got); | 963 | ceph_put_cap_refs(ci, got); |
1005 | 964 | ||
@@ -1276,16 +1235,16 @@ const struct file_operations ceph_file_fops = { | |||
1276 | .open = ceph_open, | 1235 | .open = ceph_open, |
1277 | .release = ceph_release, | 1236 | .release = ceph_release, |
1278 | .llseek = ceph_llseek, | 1237 | .llseek = ceph_llseek, |
1279 | .read = do_sync_read, | 1238 | .read = new_sync_read, |
1280 | .write = do_sync_write, | 1239 | .write = new_sync_write, |
1281 | .aio_read = ceph_aio_read, | 1240 | .read_iter = ceph_read_iter, |
1282 | .aio_write = ceph_aio_write, | 1241 | .write_iter = ceph_write_iter, |
1283 | .mmap = ceph_mmap, | 1242 | .mmap = ceph_mmap, |
1284 | .fsync = ceph_fsync, | 1243 | .fsync = ceph_fsync, |
1285 | .lock = ceph_lock, | 1244 | .lock = ceph_lock, |
1286 | .flock = ceph_flock, | 1245 | .flock = ceph_flock, |
1287 | .splice_read = generic_file_splice_read, | 1246 | .splice_read = generic_file_splice_read, |
1288 | .splice_write = generic_file_splice_write, | 1247 | .splice_write = iter_file_splice_write, |
1289 | .unlocked_ioctl = ceph_ioctl, | 1248 | .unlocked_ioctl = ceph_ioctl, |
1290 | .compat_ioctl = ceph_ioctl, | 1249 | .compat_ioctl = ceph_ioctl, |
1291 | .fallocate = ceph_fallocate, | 1250 | .fallocate = ceph_fallocate, |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 6aaa8112c538..2c90d07c0b3a 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -725,8 +725,7 @@ out_nls: | |||
725 | goto out; | 725 | goto out; |
726 | } | 726 | } |
727 | 727 | ||
728 | static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 728 | static ssize_t cifs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
729 | unsigned long nr_segs, loff_t pos) | ||
730 | { | 729 | { |
731 | struct inode *inode = file_inode(iocb->ki_filp); | 730 | struct inode *inode = file_inode(iocb->ki_filp); |
732 | struct cifsInodeInfo *cinode = CIFS_I(inode); | 731 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
@@ -737,14 +736,14 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
737 | if (written) | 736 | if (written) |
738 | return written; | 737 | return written; |
739 | 738 | ||
740 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); | 739 | written = generic_file_write_iter(iocb, from); |
741 | 740 | ||
742 | if (CIFS_CACHE_WRITE(CIFS_I(inode))) | 741 | if (CIFS_CACHE_WRITE(CIFS_I(inode))) |
743 | goto out; | 742 | goto out; |
744 | 743 | ||
745 | rc = filemap_fdatawrite(inode->i_mapping); | 744 | rc = filemap_fdatawrite(inode->i_mapping); |
746 | if (rc) | 745 | if (rc) |
747 | cifs_dbg(FYI, "cifs_file_aio_write: %d rc on %p inode\n", | 746 | cifs_dbg(FYI, "cifs_file_write_iter: %d rc on %p inode\n", |
748 | rc, inode); | 747 | rc, inode); |
749 | 748 | ||
750 | out: | 749 | out: |
@@ -880,10 +879,10 @@ const struct inode_operations cifs_symlink_inode_ops = { | |||
880 | }; | 879 | }; |
881 | 880 | ||
882 | const struct file_operations cifs_file_ops = { | 881 | const struct file_operations cifs_file_ops = { |
883 | .read = do_sync_read, | 882 | .read = new_sync_read, |
884 | .write = do_sync_write, | 883 | .write = new_sync_write, |
885 | .aio_read = generic_file_aio_read, | 884 | .read_iter = generic_file_read_iter, |
886 | .aio_write = cifs_file_aio_write, | 885 | .write_iter = cifs_file_write_iter, |
887 | .open = cifs_open, | 886 | .open = cifs_open, |
888 | .release = cifs_close, | 887 | .release = cifs_close, |
889 | .lock = cifs_lock, | 888 | .lock = cifs_lock, |
@@ -899,10 +898,10 @@ const struct file_operations cifs_file_ops = { | |||
899 | }; | 898 | }; |
900 | 899 | ||
901 | const struct file_operations cifs_file_strict_ops = { | 900 | const struct file_operations cifs_file_strict_ops = { |
902 | .read = do_sync_read, | 901 | .read = new_sync_read, |
903 | .write = do_sync_write, | 902 | .write = new_sync_write, |
904 | .aio_read = cifs_strict_readv, | 903 | .read_iter = cifs_strict_readv, |
905 | .aio_write = cifs_strict_writev, | 904 | .write_iter = cifs_strict_writev, |
906 | .open = cifs_open, | 905 | .open = cifs_open, |
907 | .release = cifs_close, | 906 | .release = cifs_close, |
908 | .lock = cifs_lock, | 907 | .lock = cifs_lock, |
@@ -919,10 +918,10 @@ const struct file_operations cifs_file_strict_ops = { | |||
919 | 918 | ||
920 | const struct file_operations cifs_file_direct_ops = { | 919 | const struct file_operations cifs_file_direct_ops = { |
921 | /* BB reevaluate whether they can be done with directio, no cache */ | 920 | /* BB reevaluate whether they can be done with directio, no cache */ |
922 | .read = do_sync_read, | 921 | .read = new_sync_read, |
923 | .write = do_sync_write, | 922 | .write = new_sync_write, |
924 | .aio_read = cifs_user_readv, | 923 | .read_iter = cifs_user_readv, |
925 | .aio_write = cifs_user_writev, | 924 | .write_iter = cifs_user_writev, |
926 | .open = cifs_open, | 925 | .open = cifs_open, |
927 | .release = cifs_close, | 926 | .release = cifs_close, |
928 | .lock = cifs_lock, | 927 | .lock = cifs_lock, |
@@ -938,10 +937,10 @@ const struct file_operations cifs_file_direct_ops = { | |||
938 | }; | 937 | }; |
939 | 938 | ||
940 | const struct file_operations cifs_file_nobrl_ops = { | 939 | const struct file_operations cifs_file_nobrl_ops = { |
941 | .read = do_sync_read, | 940 | .read = new_sync_read, |
942 | .write = do_sync_write, | 941 | .write = new_sync_write, |
943 | .aio_read = generic_file_aio_read, | 942 | .read_iter = generic_file_read_iter, |
944 | .aio_write = cifs_file_aio_write, | 943 | .write_iter = cifs_file_write_iter, |
945 | .open = cifs_open, | 944 | .open = cifs_open, |
946 | .release = cifs_close, | 945 | .release = cifs_close, |
947 | .fsync = cifs_fsync, | 946 | .fsync = cifs_fsync, |
@@ -956,10 +955,10 @@ const struct file_operations cifs_file_nobrl_ops = { | |||
956 | }; | 955 | }; |
957 | 956 | ||
958 | const struct file_operations cifs_file_strict_nobrl_ops = { | 957 | const struct file_operations cifs_file_strict_nobrl_ops = { |
959 | .read = do_sync_read, | 958 | .read = new_sync_read, |
960 | .write = do_sync_write, | 959 | .write = new_sync_write, |
961 | .aio_read = cifs_strict_readv, | 960 | .read_iter = cifs_strict_readv, |
962 | .aio_write = cifs_strict_writev, | 961 | .write_iter = cifs_strict_writev, |
963 | .open = cifs_open, | 962 | .open = cifs_open, |
964 | .release = cifs_close, | 963 | .release = cifs_close, |
965 | .fsync = cifs_strict_fsync, | 964 | .fsync = cifs_strict_fsync, |
@@ -975,10 +974,10 @@ const struct file_operations cifs_file_strict_nobrl_ops = { | |||
975 | 974 | ||
976 | const struct file_operations cifs_file_direct_nobrl_ops = { | 975 | const struct file_operations cifs_file_direct_nobrl_ops = { |
977 | /* BB reevaluate whether they can be done with directio, no cache */ | 976 | /* BB reevaluate whether they can be done with directio, no cache */ |
978 | .read = do_sync_read, | 977 | .read = new_sync_read, |
979 | .write = do_sync_write, | 978 | .write = new_sync_write, |
980 | .aio_read = cifs_user_readv, | 979 | .read_iter = cifs_user_readv, |
981 | .aio_write = cifs_user_writev, | 980 | .write_iter = cifs_user_writev, |
982 | .open = cifs_open, | 981 | .open = cifs_open, |
983 | .release = cifs_close, | 982 | .release = cifs_close, |
984 | .fsync = cifs_fsync, | 983 | .fsync = cifs_fsync, |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 8fe51166d6e3..70f178a7c759 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -95,14 +95,10 @@ extern const struct file_operations cifs_file_strict_nobrl_ops; | |||
95 | extern int cifs_open(struct inode *inode, struct file *file); | 95 | extern int cifs_open(struct inode *inode, struct file *file); |
96 | extern int cifs_close(struct inode *inode, struct file *file); | 96 | extern int cifs_close(struct inode *inode, struct file *file); |
97 | extern int cifs_closedir(struct inode *inode, struct file *file); | 97 | extern int cifs_closedir(struct inode *inode, struct file *file); |
98 | extern ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, | 98 | extern ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to); |
99 | unsigned long nr_segs, loff_t pos); | 99 | extern ssize_t cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to); |
100 | extern ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | 100 | extern ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from); |
101 | unsigned long nr_segs, loff_t pos); | 101 | extern ssize_t cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from); |
102 | extern ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | ||
103 | unsigned long nr_segs, loff_t pos); | ||
104 | extern ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | ||
105 | unsigned long nr_segs, loff_t pos); | ||
106 | extern int cifs_lock(struct file *, int, struct file_lock *); | 102 | extern int cifs_lock(struct file *, int, struct file_lock *); |
107 | extern int cifs_fsync(struct file *, loff_t, loff_t, int); | 103 | extern int cifs_fsync(struct file *, loff_t, loff_t, int); |
108 | extern int cifs_strict_fsync(struct file *, loff_t, loff_t, int); | 104 | extern int cifs_strict_fsync(struct file *, loff_t, loff_t, int); |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 208f56eca4bf..e90a1e9aa627 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -2385,14 +2385,12 @@ cifs_uncached_retry_writev(struct cifs_writedata *wdata) | |||
2385 | } | 2385 | } |
2386 | 2386 | ||
2387 | static ssize_t | 2387 | static ssize_t |
2388 | cifs_iovec_write(struct file *file, const struct iovec *iov, | 2388 | cifs_iovec_write(struct file *file, struct iov_iter *from, loff_t *poffset) |
2389 | unsigned long nr_segs, loff_t *poffset) | ||
2390 | { | 2389 | { |
2391 | unsigned long nr_pages, i; | 2390 | unsigned long nr_pages, i; |
2392 | size_t bytes, copied, len, cur_len; | 2391 | size_t bytes, copied, len, cur_len; |
2393 | ssize_t total_written = 0; | 2392 | ssize_t total_written = 0; |
2394 | loff_t offset; | 2393 | loff_t offset; |
2395 | struct iov_iter it; | ||
2396 | struct cifsFileInfo *open_file; | 2394 | struct cifsFileInfo *open_file; |
2397 | struct cifs_tcon *tcon; | 2395 | struct cifs_tcon *tcon; |
2398 | struct cifs_sb_info *cifs_sb; | 2396 | struct cifs_sb_info *cifs_sb; |
@@ -2401,14 +2399,16 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2401 | int rc; | 2399 | int rc; |
2402 | pid_t pid; | 2400 | pid_t pid; |
2403 | 2401 | ||
2404 | len = iov_length(iov, nr_segs); | 2402 | len = iov_iter_count(from); |
2405 | if (!len) | ||
2406 | return 0; | ||
2407 | |||
2408 | rc = generic_write_checks(file, poffset, &len, 0); | 2403 | rc = generic_write_checks(file, poffset, &len, 0); |
2409 | if (rc) | 2404 | if (rc) |
2410 | return rc; | 2405 | return rc; |
2411 | 2406 | ||
2407 | if (!len) | ||
2408 | return 0; | ||
2409 | |||
2410 | iov_iter_truncate(from, len); | ||
2411 | |||
2412 | INIT_LIST_HEAD(&wdata_list); | 2412 | INIT_LIST_HEAD(&wdata_list); |
2413 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2413 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2414 | open_file = file->private_data; | 2414 | open_file = file->private_data; |
@@ -2424,7 +2424,6 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2424 | else | 2424 | else |
2425 | pid = current->tgid; | 2425 | pid = current->tgid; |
2426 | 2426 | ||
2427 | iov_iter_init(&it, iov, nr_segs, len, 0); | ||
2428 | do { | 2427 | do { |
2429 | size_t save_len; | 2428 | size_t save_len; |
2430 | 2429 | ||
@@ -2444,11 +2443,10 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2444 | 2443 | ||
2445 | save_len = cur_len; | 2444 | save_len = cur_len; |
2446 | for (i = 0; i < nr_pages; i++) { | 2445 | for (i = 0; i < nr_pages; i++) { |
2447 | bytes = min_t(const size_t, cur_len, PAGE_SIZE); | 2446 | bytes = min_t(size_t, cur_len, PAGE_SIZE); |
2448 | copied = iov_iter_copy_from_user(wdata->pages[i], &it, | 2447 | copied = copy_page_from_iter(wdata->pages[i], 0, bytes, |
2449 | 0, bytes); | 2448 | from); |
2450 | cur_len -= copied; | 2449 | cur_len -= copied; |
2451 | iov_iter_advance(&it, copied); | ||
2452 | /* | 2450 | /* |
2453 | * If we didn't copy as much as we expected, then that | 2451 | * If we didn't copy as much as we expected, then that |
2454 | * may mean we trod into an unmapped area. Stop copying | 2452 | * may mean we trod into an unmapped area. Stop copying |
@@ -2546,11 +2544,11 @@ restart_loop: | |||
2546 | return total_written ? total_written : (ssize_t)rc; | 2544 | return total_written ? total_written : (ssize_t)rc; |
2547 | } | 2545 | } |
2548 | 2546 | ||
2549 | ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | 2547 | ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from) |
2550 | unsigned long nr_segs, loff_t pos) | ||
2551 | { | 2548 | { |
2552 | ssize_t written; | 2549 | ssize_t written; |
2553 | struct inode *inode; | 2550 | struct inode *inode; |
2551 | loff_t pos = iocb->ki_pos; | ||
2554 | 2552 | ||
2555 | inode = file_inode(iocb->ki_filp); | 2553 | inode = file_inode(iocb->ki_filp); |
2556 | 2554 | ||
@@ -2560,7 +2558,7 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2560 | * write request. | 2558 | * write request. |
2561 | */ | 2559 | */ |
2562 | 2560 | ||
2563 | written = cifs_iovec_write(iocb->ki_filp, iov, nr_segs, &pos); | 2561 | written = cifs_iovec_write(iocb->ki_filp, from, &pos); |
2564 | if (written > 0) { | 2562 | if (written > 0) { |
2565 | set_bit(CIFS_INO_INVALID_MAPPING, &CIFS_I(inode)->flags); | 2563 | set_bit(CIFS_INO_INVALID_MAPPING, &CIFS_I(inode)->flags); |
2566 | iocb->ki_pos = pos; | 2564 | iocb->ki_pos = pos; |
@@ -2570,8 +2568,7 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2570 | } | 2568 | } |
2571 | 2569 | ||
2572 | static ssize_t | 2570 | static ssize_t |
2573 | cifs_writev(struct kiocb *iocb, const struct iovec *iov, | 2571 | cifs_writev(struct kiocb *iocb, struct iov_iter *from) |
2574 | unsigned long nr_segs, loff_t pos) | ||
2575 | { | 2572 | { |
2576 | struct file *file = iocb->ki_filp; | 2573 | struct file *file = iocb->ki_filp; |
2577 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | 2574 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
@@ -2589,10 +2586,10 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2589 | mutex_lock(&inode->i_mutex); | 2586 | mutex_lock(&inode->i_mutex); |
2590 | if (file->f_flags & O_APPEND) | 2587 | if (file->f_flags & O_APPEND) |
2591 | lock_pos = i_size_read(inode); | 2588 | lock_pos = i_size_read(inode); |
2592 | if (!cifs_find_lock_conflict(cfile, lock_pos, iov_length(iov, nr_segs), | 2589 | if (!cifs_find_lock_conflict(cfile, lock_pos, iov_iter_count(from), |
2593 | server->vals->exclusive_lock_type, NULL, | 2590 | server->vals->exclusive_lock_type, NULL, |
2594 | CIFS_WRITE_OP)) { | 2591 | CIFS_WRITE_OP)) { |
2595 | rc = __generic_file_aio_write(iocb, iov, nr_segs); | 2592 | rc = __generic_file_write_iter(iocb, from); |
2596 | mutex_unlock(&inode->i_mutex); | 2593 | mutex_unlock(&inode->i_mutex); |
2597 | 2594 | ||
2598 | if (rc > 0) { | 2595 | if (rc > 0) { |
@@ -2610,8 +2607,7 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2610 | } | 2607 | } |
2611 | 2608 | ||
2612 | ssize_t | 2609 | ssize_t |
2613 | cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | 2610 | cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from) |
2614 | unsigned long nr_segs, loff_t pos) | ||
2615 | { | 2611 | { |
2616 | struct inode *inode = file_inode(iocb->ki_filp); | 2612 | struct inode *inode = file_inode(iocb->ki_filp); |
2617 | struct cifsInodeInfo *cinode = CIFS_I(inode); | 2613 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
@@ -2629,11 +2625,10 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2629 | if (cap_unix(tcon->ses) && | 2625 | if (cap_unix(tcon->ses) && |
2630 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) | 2626 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) |
2631 | && ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) { | 2627 | && ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) { |
2632 | written = generic_file_aio_write( | 2628 | written = generic_file_write_iter(iocb, from); |
2633 | iocb, iov, nr_segs, pos); | ||
2634 | goto out; | 2629 | goto out; |
2635 | } | 2630 | } |
2636 | written = cifs_writev(iocb, iov, nr_segs, pos); | 2631 | written = cifs_writev(iocb, from); |
2637 | goto out; | 2632 | goto out; |
2638 | } | 2633 | } |
2639 | /* | 2634 | /* |
@@ -2642,7 +2637,7 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2642 | * affected pages because it may cause a error with mandatory locks on | 2637 | * affected pages because it may cause a error with mandatory locks on |
2643 | * these pages but not on the region from pos to ppos+len-1. | 2638 | * these pages but not on the region from pos to ppos+len-1. |
2644 | */ | 2639 | */ |
2645 | written = cifs_user_writev(iocb, iov, nr_segs, pos); | 2640 | written = cifs_user_writev(iocb, from); |
2646 | if (written > 0 && CIFS_CACHE_READ(cinode)) { | 2641 | if (written > 0 && CIFS_CACHE_READ(cinode)) { |
2647 | /* | 2642 | /* |
2648 | * Windows 7 server can delay breaking level2 oplock if a write | 2643 | * Windows 7 server can delay breaking level2 oplock if a write |
@@ -2831,32 +2826,25 @@ cifs_uncached_read_into_pages(struct TCP_Server_Info *server, | |||
2831 | return total_read > 0 ? total_read : result; | 2826 | return total_read > 0 ? total_read : result; |
2832 | } | 2827 | } |
2833 | 2828 | ||
2834 | ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, | 2829 | ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to) |
2835 | unsigned long nr_segs, loff_t pos) | ||
2836 | { | 2830 | { |
2837 | struct file *file = iocb->ki_filp; | 2831 | struct file *file = iocb->ki_filp; |
2838 | ssize_t rc; | 2832 | ssize_t rc; |
2839 | size_t len, cur_len; | 2833 | size_t len, cur_len; |
2840 | ssize_t total_read = 0; | 2834 | ssize_t total_read = 0; |
2841 | loff_t offset = pos; | 2835 | loff_t offset = iocb->ki_pos; |
2842 | unsigned int npages; | 2836 | unsigned int npages; |
2843 | struct cifs_sb_info *cifs_sb; | 2837 | struct cifs_sb_info *cifs_sb; |
2844 | struct cifs_tcon *tcon; | 2838 | struct cifs_tcon *tcon; |
2845 | struct cifsFileInfo *open_file; | 2839 | struct cifsFileInfo *open_file; |
2846 | struct cifs_readdata *rdata, *tmp; | 2840 | struct cifs_readdata *rdata, *tmp; |
2847 | struct list_head rdata_list; | 2841 | struct list_head rdata_list; |
2848 | struct iov_iter to; | ||
2849 | pid_t pid; | 2842 | pid_t pid; |
2850 | 2843 | ||
2851 | if (!nr_segs) | 2844 | len = iov_iter_count(to); |
2852 | return 0; | ||
2853 | |||
2854 | len = iov_length(iov, nr_segs); | ||
2855 | if (!len) | 2845 | if (!len) |
2856 | return 0; | 2846 | return 0; |
2857 | 2847 | ||
2858 | iov_iter_init(&to, iov, nr_segs, len, 0); | ||
2859 | |||
2860 | INIT_LIST_HEAD(&rdata_list); | 2848 | INIT_LIST_HEAD(&rdata_list); |
2861 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2849 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2862 | open_file = file->private_data; | 2850 | open_file = file->private_data; |
@@ -2914,7 +2902,7 @@ error: | |||
2914 | if (!list_empty(&rdata_list)) | 2902 | if (!list_empty(&rdata_list)) |
2915 | rc = 0; | 2903 | rc = 0; |
2916 | 2904 | ||
2917 | len = iov_iter_count(&to); | 2905 | len = iov_iter_count(to); |
2918 | /* the loop below should proceed in the order of increasing offsets */ | 2906 | /* the loop below should proceed in the order of increasing offsets */ |
2919 | list_for_each_entry_safe(rdata, tmp, &rdata_list, list) { | 2907 | list_for_each_entry_safe(rdata, tmp, &rdata_list, list) { |
2920 | again: | 2908 | again: |
@@ -2931,7 +2919,7 @@ error: | |||
2931 | goto again; | 2919 | goto again; |
2932 | } | 2920 | } |
2933 | } else { | 2921 | } else { |
2934 | rc = cifs_readdata_to_iov(rdata, &to); | 2922 | rc = cifs_readdata_to_iov(rdata, to); |
2935 | } | 2923 | } |
2936 | 2924 | ||
2937 | } | 2925 | } |
@@ -2939,7 +2927,7 @@ error: | |||
2939 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); | 2927 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); |
2940 | } | 2928 | } |
2941 | 2929 | ||
2942 | total_read = len - iov_iter_count(&to); | 2930 | total_read = len - iov_iter_count(to); |
2943 | 2931 | ||
2944 | cifs_stats_bytes_read(tcon, total_read); | 2932 | cifs_stats_bytes_read(tcon, total_read); |
2945 | 2933 | ||
@@ -2948,15 +2936,14 @@ error: | |||
2948 | rc = 0; | 2936 | rc = 0; |
2949 | 2937 | ||
2950 | if (total_read) { | 2938 | if (total_read) { |
2951 | iocb->ki_pos = pos + total_read; | 2939 | iocb->ki_pos += total_read; |
2952 | return total_read; | 2940 | return total_read; |
2953 | } | 2941 | } |
2954 | return rc; | 2942 | return rc; |
2955 | } | 2943 | } |
2956 | 2944 | ||
2957 | ssize_t | 2945 | ssize_t |
2958 | cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | 2946 | cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to) |
2959 | unsigned long nr_segs, loff_t pos) | ||
2960 | { | 2947 | { |
2961 | struct inode *inode = file_inode(iocb->ki_filp); | 2948 | struct inode *inode = file_inode(iocb->ki_filp); |
2962 | struct cifsInodeInfo *cinode = CIFS_I(inode); | 2949 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
@@ -2975,22 +2962,22 @@ cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | |||
2975 | * pos+len-1. | 2962 | * pos+len-1. |
2976 | */ | 2963 | */ |
2977 | if (!CIFS_CACHE_READ(cinode)) | 2964 | if (!CIFS_CACHE_READ(cinode)) |
2978 | return cifs_user_readv(iocb, iov, nr_segs, pos); | 2965 | return cifs_user_readv(iocb, to); |
2979 | 2966 | ||
2980 | if (cap_unix(tcon->ses) && | 2967 | if (cap_unix(tcon->ses) && |
2981 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && | 2968 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && |
2982 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | 2969 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) |
2983 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | 2970 | return generic_file_read_iter(iocb, to); |
2984 | 2971 | ||
2985 | /* | 2972 | /* |
2986 | * We need to hold the sem to be sure nobody modifies lock list | 2973 | * We need to hold the sem to be sure nobody modifies lock list |
2987 | * with a brlock that prevents reading. | 2974 | * with a brlock that prevents reading. |
2988 | */ | 2975 | */ |
2989 | down_read(&cinode->lock_sem); | 2976 | down_read(&cinode->lock_sem); |
2990 | if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), | 2977 | if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(to), |
2991 | tcon->ses->server->vals->shared_lock_type, | 2978 | tcon->ses->server->vals->shared_lock_type, |
2992 | NULL, CIFS_READ_OP)) | 2979 | NULL, CIFS_READ_OP)) |
2993 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); | 2980 | rc = generic_file_read_iter(iocb, to); |
2994 | up_read(&cinode->lock_sem); | 2981 | up_read(&cinode->lock_sem); |
2995 | return rc; | 2982 | return rc; |
2996 | } | 2983 | } |
@@ -3703,8 +3690,8 @@ void cifs_oplock_break(struct work_struct *work) | |||
3703 | * Direct IO is not yet supported in the cached mode. | 3690 | * Direct IO is not yet supported in the cached mode. |
3704 | */ | 3691 | */ |
3705 | static ssize_t | 3692 | static ssize_t |
3706 | cifs_direct_io(int rw, struct kiocb *iocb, const struct iovec *iov, | 3693 | cifs_direct_io(int rw, struct kiocb *iocb, struct iov_iter *iter, |
3707 | loff_t pos, unsigned long nr_segs) | 3694 | loff_t pos) |
3708 | { | 3695 | { |
3709 | /* | 3696 | /* |
3710 | * FIXME | 3697 | * FIXME |
diff --git a/fs/dcache.c b/fs/dcache.c index 1792d6075b4f..06f65857a855 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -532,10 +532,12 @@ static inline struct dentry *lock_parent(struct dentry *dentry) | |||
532 | struct dentry *parent = dentry->d_parent; | 532 | struct dentry *parent = dentry->d_parent; |
533 | if (IS_ROOT(dentry)) | 533 | if (IS_ROOT(dentry)) |
534 | return NULL; | 534 | return NULL; |
535 | if (unlikely((int)dentry->d_lockref.count < 0)) | ||
536 | return NULL; | ||
535 | if (likely(spin_trylock(&parent->d_lock))) | 537 | if (likely(spin_trylock(&parent->d_lock))) |
536 | return parent; | 538 | return parent; |
537 | spin_unlock(&dentry->d_lock); | ||
538 | rcu_read_lock(); | 539 | rcu_read_lock(); |
540 | spin_unlock(&dentry->d_lock); | ||
539 | again: | 541 | again: |
540 | parent = ACCESS_ONCE(dentry->d_parent); | 542 | parent = ACCESS_ONCE(dentry->d_parent); |
541 | spin_lock(&parent->d_lock); | 543 | spin_lock(&parent->d_lock); |
diff --git a/fs/direct-io.c b/fs/direct-io.c index 31ba0935e32e..98040ba388ac 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -77,7 +77,6 @@ struct dio_submit { | |||
77 | unsigned blocks_available; /* At block_in_file. changes */ | 77 | unsigned blocks_available; /* At block_in_file. changes */ |
78 | int reap_counter; /* rate limit reaping */ | 78 | int reap_counter; /* rate limit reaping */ |
79 | sector_t final_block_in_request;/* doesn't change */ | 79 | sector_t final_block_in_request;/* doesn't change */ |
80 | unsigned first_block_in_page; /* doesn't change, Used only once */ | ||
81 | int boundary; /* prev block is at a boundary */ | 80 | int boundary; /* prev block is at a boundary */ |
82 | get_block_t *get_block; /* block mapping function */ | 81 | get_block_t *get_block; /* block mapping function */ |
83 | dio_submit_t *submit_io; /* IO submition function */ | 82 | dio_submit_t *submit_io; /* IO submition function */ |
@@ -98,19 +97,14 @@ struct dio_submit { | |||
98 | sector_t cur_page_block; /* Where it starts */ | 97 | sector_t cur_page_block; /* Where it starts */ |
99 | loff_t cur_page_fs_offset; /* Offset in file */ | 98 | loff_t cur_page_fs_offset; /* Offset in file */ |
100 | 99 | ||
101 | /* | 100 | struct iov_iter *iter; |
102 | * Page fetching state. These variables belong to dio_refill_pages(). | ||
103 | */ | ||
104 | int curr_page; /* changes */ | ||
105 | int total_pages; /* doesn't change */ | ||
106 | unsigned long curr_user_address;/* changes */ | ||
107 | |||
108 | /* | 101 | /* |
109 | * Page queue. These variables belong to dio_refill_pages() and | 102 | * Page queue. These variables belong to dio_refill_pages() and |
110 | * dio_get_page(). | 103 | * dio_get_page(). |
111 | */ | 104 | */ |
112 | unsigned head; /* next page to process */ | 105 | unsigned head; /* next page to process */ |
113 | unsigned tail; /* last valid page + 1 */ | 106 | unsigned tail; /* last valid page + 1 */ |
107 | size_t from, to; | ||
114 | }; | 108 | }; |
115 | 109 | ||
116 | /* dio_state communicated between submission path and end_io */ | 110 | /* dio_state communicated between submission path and end_io */ |
@@ -163,15 +157,10 @@ static inline unsigned dio_pages_present(struct dio_submit *sdio) | |||
163 | */ | 157 | */ |
164 | static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) | 158 | static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) |
165 | { | 159 | { |
166 | int ret; | 160 | ssize_t ret; |
167 | int nr_pages; | ||
168 | 161 | ||
169 | nr_pages = min(sdio->total_pages - sdio->curr_page, DIO_PAGES); | 162 | ret = iov_iter_get_pages(sdio->iter, dio->pages, DIO_PAGES * PAGE_SIZE, |
170 | ret = get_user_pages_fast( | 163 | &sdio->from); |
171 | sdio->curr_user_address, /* Where from? */ | ||
172 | nr_pages, /* How many pages? */ | ||
173 | dio->rw == READ, /* Write to memory? */ | ||
174 | &dio->pages[0]); /* Put results here */ | ||
175 | 164 | ||
176 | if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) { | 165 | if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) { |
177 | struct page *page = ZERO_PAGE(0); | 166 | struct page *page = ZERO_PAGE(0); |
@@ -186,18 +175,19 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) | |||
186 | dio->pages[0] = page; | 175 | dio->pages[0] = page; |
187 | sdio->head = 0; | 176 | sdio->head = 0; |
188 | sdio->tail = 1; | 177 | sdio->tail = 1; |
189 | ret = 0; | 178 | sdio->from = 0; |
190 | goto out; | 179 | sdio->to = PAGE_SIZE; |
180 | return 0; | ||
191 | } | 181 | } |
192 | 182 | ||
193 | if (ret >= 0) { | 183 | if (ret >= 0) { |
194 | sdio->curr_user_address += ret * PAGE_SIZE; | 184 | iov_iter_advance(sdio->iter, ret); |
195 | sdio->curr_page += ret; | 185 | ret += sdio->from; |
196 | sdio->head = 0; | 186 | sdio->head = 0; |
197 | sdio->tail = ret; | 187 | sdio->tail = (ret + PAGE_SIZE - 1) / PAGE_SIZE; |
198 | ret = 0; | 188 | sdio->to = ((ret - 1) & (PAGE_SIZE - 1)) + 1; |
189 | return 0; | ||
199 | } | 190 | } |
200 | out: | ||
201 | return ret; | 191 | return ret; |
202 | } | 192 | } |
203 | 193 | ||
@@ -208,8 +198,9 @@ out: | |||
208 | * L1 cache. | 198 | * L1 cache. |
209 | */ | 199 | */ |
210 | static inline struct page *dio_get_page(struct dio *dio, | 200 | static inline struct page *dio_get_page(struct dio *dio, |
211 | struct dio_submit *sdio) | 201 | struct dio_submit *sdio, size_t *from, size_t *to) |
212 | { | 202 | { |
203 | int n; | ||
213 | if (dio_pages_present(sdio) == 0) { | 204 | if (dio_pages_present(sdio) == 0) { |
214 | int ret; | 205 | int ret; |
215 | 206 | ||
@@ -218,7 +209,10 @@ static inline struct page *dio_get_page(struct dio *dio, | |||
218 | return ERR_PTR(ret); | 209 | return ERR_PTR(ret); |
219 | BUG_ON(dio_pages_present(sdio) == 0); | 210 | BUG_ON(dio_pages_present(sdio) == 0); |
220 | } | 211 | } |
221 | return dio->pages[sdio->head++]; | 212 | n = sdio->head++; |
213 | *from = n ? 0 : sdio->from; | ||
214 | *to = (n == sdio->tail - 1) ? sdio->to : PAGE_SIZE; | ||
215 | return dio->pages[n]; | ||
222 | } | 216 | } |
223 | 217 | ||
224 | /** | 218 | /** |
@@ -422,8 +416,8 @@ static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio) | |||
422 | */ | 416 | */ |
423 | static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) | 417 | static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio) |
424 | { | 418 | { |
425 | while (dio_pages_present(sdio)) | 419 | while (sdio->head < sdio->tail) |
426 | page_cache_release(dio_get_page(dio, sdio)); | 420 | page_cache_release(dio->pages[sdio->head++]); |
427 | } | 421 | } |
428 | 422 | ||
429 | /* | 423 | /* |
@@ -912,23 +906,18 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, | |||
912 | struct buffer_head *map_bh) | 906 | struct buffer_head *map_bh) |
913 | { | 907 | { |
914 | const unsigned blkbits = sdio->blkbits; | 908 | const unsigned blkbits = sdio->blkbits; |
915 | const unsigned blocks_per_page = PAGE_SIZE >> blkbits; | ||
916 | struct page *page; | ||
917 | unsigned block_in_page; | ||
918 | int ret = 0; | 909 | int ret = 0; |
919 | 910 | ||
920 | /* The I/O can start at any block offset within the first page */ | ||
921 | block_in_page = sdio->first_block_in_page; | ||
922 | |||
923 | while (sdio->block_in_file < sdio->final_block_in_request) { | 911 | while (sdio->block_in_file < sdio->final_block_in_request) { |
924 | page = dio_get_page(dio, sdio); | 912 | struct page *page; |
913 | size_t from, to; | ||
914 | page = dio_get_page(dio, sdio, &from, &to); | ||
925 | if (IS_ERR(page)) { | 915 | if (IS_ERR(page)) { |
926 | ret = PTR_ERR(page); | 916 | ret = PTR_ERR(page); |
927 | goto out; | 917 | goto out; |
928 | } | 918 | } |
929 | 919 | ||
930 | while (block_in_page < blocks_per_page) { | 920 | while (from < to) { |
931 | unsigned offset_in_page = block_in_page << blkbits; | ||
932 | unsigned this_chunk_bytes; /* # of bytes mapped */ | 921 | unsigned this_chunk_bytes; /* # of bytes mapped */ |
933 | unsigned this_chunk_blocks; /* # of blocks */ | 922 | unsigned this_chunk_blocks; /* # of blocks */ |
934 | unsigned u; | 923 | unsigned u; |
@@ -999,10 +988,10 @@ do_holes: | |||
999 | page_cache_release(page); | 988 | page_cache_release(page); |
1000 | goto out; | 989 | goto out; |
1001 | } | 990 | } |
1002 | zero_user(page, block_in_page << blkbits, | 991 | zero_user(page, from, 1 << blkbits); |
1003 | 1 << blkbits); | ||
1004 | sdio->block_in_file++; | 992 | sdio->block_in_file++; |
1005 | block_in_page++; | 993 | from += 1 << blkbits; |
994 | dio->result += 1 << blkbits; | ||
1006 | goto next_block; | 995 | goto next_block; |
1007 | } | 996 | } |
1008 | 997 | ||
@@ -1019,7 +1008,7 @@ do_holes: | |||
1019 | * can add to this page | 1008 | * can add to this page |
1020 | */ | 1009 | */ |
1021 | this_chunk_blocks = sdio->blocks_available; | 1010 | this_chunk_blocks = sdio->blocks_available; |
1022 | u = (PAGE_SIZE - offset_in_page) >> blkbits; | 1011 | u = (to - from) >> blkbits; |
1023 | if (this_chunk_blocks > u) | 1012 | if (this_chunk_blocks > u) |
1024 | this_chunk_blocks = u; | 1013 | this_chunk_blocks = u; |
1025 | u = sdio->final_block_in_request - sdio->block_in_file; | 1014 | u = sdio->final_block_in_request - sdio->block_in_file; |
@@ -1031,7 +1020,7 @@ do_holes: | |||
1031 | if (this_chunk_blocks == sdio->blocks_available) | 1020 | if (this_chunk_blocks == sdio->blocks_available) |
1032 | sdio->boundary = buffer_boundary(map_bh); | 1021 | sdio->boundary = buffer_boundary(map_bh); |
1033 | ret = submit_page_section(dio, sdio, page, | 1022 | ret = submit_page_section(dio, sdio, page, |
1034 | offset_in_page, | 1023 | from, |
1035 | this_chunk_bytes, | 1024 | this_chunk_bytes, |
1036 | sdio->next_block_for_io, | 1025 | sdio->next_block_for_io, |
1037 | map_bh); | 1026 | map_bh); |
@@ -1042,7 +1031,8 @@ do_holes: | |||
1042 | sdio->next_block_for_io += this_chunk_blocks; | 1031 | sdio->next_block_for_io += this_chunk_blocks; |
1043 | 1032 | ||
1044 | sdio->block_in_file += this_chunk_blocks; | 1033 | sdio->block_in_file += this_chunk_blocks; |
1045 | block_in_page += this_chunk_blocks; | 1034 | from += this_chunk_bytes; |
1035 | dio->result += this_chunk_bytes; | ||
1046 | sdio->blocks_available -= this_chunk_blocks; | 1036 | sdio->blocks_available -= this_chunk_blocks; |
1047 | next_block: | 1037 | next_block: |
1048 | BUG_ON(sdio->block_in_file > sdio->final_block_in_request); | 1038 | BUG_ON(sdio->block_in_file > sdio->final_block_in_request); |
@@ -1052,7 +1042,6 @@ next_block: | |||
1052 | 1042 | ||
1053 | /* Drop the ref which was taken in get_user_pages() */ | 1043 | /* Drop the ref which was taken in get_user_pages() */ |
1054 | page_cache_release(page); | 1044 | page_cache_release(page); |
1055 | block_in_page = 0; | ||
1056 | } | 1045 | } |
1057 | out: | 1046 | out: |
1058 | return ret; | 1047 | return ret; |
@@ -1107,24 +1096,20 @@ static inline int drop_refcount(struct dio *dio) | |||
1107 | */ | 1096 | */ |
1108 | static inline ssize_t | 1097 | static inline ssize_t |
1109 | do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 1098 | do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
1110 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 1099 | struct block_device *bdev, struct iov_iter *iter, loff_t offset, |
1111 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 1100 | get_block_t get_block, dio_iodone_t end_io, |
1112 | dio_submit_t submit_io, int flags) | 1101 | dio_submit_t submit_io, int flags) |
1113 | { | 1102 | { |
1114 | int seg; | ||
1115 | size_t size; | ||
1116 | unsigned long addr; | ||
1117 | unsigned i_blkbits = ACCESS_ONCE(inode->i_blkbits); | 1103 | unsigned i_blkbits = ACCESS_ONCE(inode->i_blkbits); |
1118 | unsigned blkbits = i_blkbits; | 1104 | unsigned blkbits = i_blkbits; |
1119 | unsigned blocksize_mask = (1 << blkbits) - 1; | 1105 | unsigned blocksize_mask = (1 << blkbits) - 1; |
1120 | ssize_t retval = -EINVAL; | 1106 | ssize_t retval = -EINVAL; |
1121 | loff_t end = offset; | 1107 | loff_t end = offset + iov_iter_count(iter); |
1122 | struct dio *dio; | 1108 | struct dio *dio; |
1123 | struct dio_submit sdio = { 0, }; | 1109 | struct dio_submit sdio = { 0, }; |
1124 | unsigned long user_addr; | ||
1125 | size_t bytes; | ||
1126 | struct buffer_head map_bh = { 0, }; | 1110 | struct buffer_head map_bh = { 0, }; |
1127 | struct blk_plug plug; | 1111 | struct blk_plug plug; |
1112 | unsigned long align = offset | iov_iter_alignment(iter); | ||
1128 | 1113 | ||
1129 | if (rw & WRITE) | 1114 | if (rw & WRITE) |
1130 | rw = WRITE_ODIRECT; | 1115 | rw = WRITE_ODIRECT; |
@@ -1134,32 +1119,16 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1134 | * the early prefetch in the caller enough time. | 1119 | * the early prefetch in the caller enough time. |
1135 | */ | 1120 | */ |
1136 | 1121 | ||
1137 | if (offset & blocksize_mask) { | 1122 | if (align & blocksize_mask) { |
1138 | if (bdev) | 1123 | if (bdev) |
1139 | blkbits = blksize_bits(bdev_logical_block_size(bdev)); | 1124 | blkbits = blksize_bits(bdev_logical_block_size(bdev)); |
1140 | blocksize_mask = (1 << blkbits) - 1; | 1125 | blocksize_mask = (1 << blkbits) - 1; |
1141 | if (offset & blocksize_mask) | 1126 | if (align & blocksize_mask) |
1142 | goto out; | 1127 | goto out; |
1143 | } | 1128 | } |
1144 | 1129 | ||
1145 | /* Check the memory alignment. Blocks cannot straddle pages */ | ||
1146 | for (seg = 0; seg < nr_segs; seg++) { | ||
1147 | addr = (unsigned long)iov[seg].iov_base; | ||
1148 | size = iov[seg].iov_len; | ||
1149 | end += size; | ||
1150 | if (unlikely((addr & blocksize_mask) || | ||
1151 | (size & blocksize_mask))) { | ||
1152 | if (bdev) | ||
1153 | blkbits = blksize_bits( | ||
1154 | bdev_logical_block_size(bdev)); | ||
1155 | blocksize_mask = (1 << blkbits) - 1; | ||
1156 | if ((addr & blocksize_mask) || (size & blocksize_mask)) | ||
1157 | goto out; | ||
1158 | } | ||
1159 | } | ||
1160 | |||
1161 | /* watch out for a 0 len io from a tricksy fs */ | 1130 | /* watch out for a 0 len io from a tricksy fs */ |
1162 | if (rw == READ && end == offset) | 1131 | if (rw == READ && !iov_iter_count(iter)) |
1163 | return 0; | 1132 | return 0; |
1164 | 1133 | ||
1165 | dio = kmem_cache_alloc(dio_cache, GFP_KERNEL); | 1134 | dio = kmem_cache_alloc(dio_cache, GFP_KERNEL); |
@@ -1249,6 +1218,10 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1249 | spin_lock_init(&dio->bio_lock); | 1218 | spin_lock_init(&dio->bio_lock); |
1250 | dio->refcount = 1; | 1219 | dio->refcount = 1; |
1251 | 1220 | ||
1221 | sdio.iter = iter; | ||
1222 | sdio.final_block_in_request = | ||
1223 | (offset + iov_iter_count(iter)) >> blkbits; | ||
1224 | |||
1252 | /* | 1225 | /* |
1253 | * In case of non-aligned buffers, we may need 2 more | 1226 | * In case of non-aligned buffers, we may need 2 more |
1254 | * pages since we need to zero out first and last block. | 1227 | * pages since we need to zero out first and last block. |
@@ -1256,47 +1229,13 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1256 | if (unlikely(sdio.blkfactor)) | 1229 | if (unlikely(sdio.blkfactor)) |
1257 | sdio.pages_in_io = 2; | 1230 | sdio.pages_in_io = 2; |
1258 | 1231 | ||
1259 | for (seg = 0; seg < nr_segs; seg++) { | 1232 | sdio.pages_in_io += iov_iter_npages(iter, INT_MAX); |
1260 | user_addr = (unsigned long)iov[seg].iov_base; | ||
1261 | sdio.pages_in_io += | ||
1262 | ((user_addr + iov[seg].iov_len + PAGE_SIZE-1) / | ||
1263 | PAGE_SIZE - user_addr / PAGE_SIZE); | ||
1264 | } | ||
1265 | 1233 | ||
1266 | blk_start_plug(&plug); | 1234 | blk_start_plug(&plug); |
1267 | 1235 | ||
1268 | for (seg = 0; seg < nr_segs; seg++) { | 1236 | retval = do_direct_IO(dio, &sdio, &map_bh); |
1269 | user_addr = (unsigned long)iov[seg].iov_base; | 1237 | if (retval) |
1270 | sdio.size += bytes = iov[seg].iov_len; | 1238 | dio_cleanup(dio, &sdio); |
1271 | |||
1272 | /* Index into the first page of the first block */ | ||
1273 | sdio.first_block_in_page = (user_addr & ~PAGE_MASK) >> blkbits; | ||
1274 | sdio.final_block_in_request = sdio.block_in_file + | ||
1275 | (bytes >> blkbits); | ||
1276 | /* Page fetching state */ | ||
1277 | sdio.head = 0; | ||
1278 | sdio.tail = 0; | ||
1279 | sdio.curr_page = 0; | ||
1280 | |||
1281 | sdio.total_pages = 0; | ||
1282 | if (user_addr & (PAGE_SIZE-1)) { | ||
1283 | sdio.total_pages++; | ||
1284 | bytes -= PAGE_SIZE - (user_addr & (PAGE_SIZE - 1)); | ||
1285 | } | ||
1286 | sdio.total_pages += (bytes + PAGE_SIZE - 1) / PAGE_SIZE; | ||
1287 | sdio.curr_user_address = user_addr; | ||
1288 | |||
1289 | retval = do_direct_IO(dio, &sdio, &map_bh); | ||
1290 | |||
1291 | dio->result += iov[seg].iov_len - | ||
1292 | ((sdio.final_block_in_request - sdio.block_in_file) << | ||
1293 | blkbits); | ||
1294 | |||
1295 | if (retval) { | ||
1296 | dio_cleanup(dio, &sdio); | ||
1297 | break; | ||
1298 | } | ||
1299 | } /* end iovec loop */ | ||
1300 | 1239 | ||
1301 | if (retval == -ENOTBLK) { | 1240 | if (retval == -ENOTBLK) { |
1302 | /* | 1241 | /* |
@@ -1365,8 +1304,8 @@ out: | |||
1365 | 1304 | ||
1366 | ssize_t | 1305 | ssize_t |
1367 | __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 1306 | __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
1368 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 1307 | struct block_device *bdev, struct iov_iter *iter, loff_t offset, |
1369 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 1308 | get_block_t get_block, dio_iodone_t end_io, |
1370 | dio_submit_t submit_io, int flags) | 1309 | dio_submit_t submit_io, int flags) |
1371 | { | 1310 | { |
1372 | /* | 1311 | /* |
@@ -1381,9 +1320,8 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1381 | prefetch(bdev->bd_queue); | 1320 | prefetch(bdev->bd_queue); |
1382 | prefetch((char *)bdev->bd_queue + SMP_CACHE_BYTES); | 1321 | prefetch((char *)bdev->bd_queue + SMP_CACHE_BYTES); |
1383 | 1322 | ||
1384 | return do_blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 1323 | return do_blockdev_direct_IO(rw, iocb, inode, bdev, iter, offset, |
1385 | nr_segs, get_block, end_io, | 1324 | get_block, end_io, submit_io, flags); |
1386 | submit_io, flags); | ||
1387 | } | 1325 | } |
1388 | 1326 | ||
1389 | EXPORT_SYMBOL(__blockdev_direct_IO); | 1327 | EXPORT_SYMBOL(__blockdev_direct_IO); |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index b1eaa7a1f82c..db0fad3269c0 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -45,14 +45,13 @@ | |||
45 | * The function to be used for directory reads is ecryptfs_read. | 45 | * The function to be used for directory reads is ecryptfs_read. |
46 | */ | 46 | */ |
47 | static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, | 47 | static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, |
48 | const struct iovec *iov, | 48 | struct iov_iter *to) |
49 | unsigned long nr_segs, loff_t pos) | ||
50 | { | 49 | { |
51 | ssize_t rc; | 50 | ssize_t rc; |
52 | struct path *path; | 51 | struct path *path; |
53 | struct file *file = iocb->ki_filp; | 52 | struct file *file = iocb->ki_filp; |
54 | 53 | ||
55 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); | 54 | rc = generic_file_read_iter(iocb, to); |
56 | /* | 55 | /* |
57 | * Even though this is a async interface, we need to wait | 56 | * Even though this is a async interface, we need to wait |
58 | * for IO to finish to update atime | 57 | * for IO to finish to update atime |
@@ -352,10 +351,10 @@ const struct file_operations ecryptfs_dir_fops = { | |||
352 | 351 | ||
353 | const struct file_operations ecryptfs_main_fops = { | 352 | const struct file_operations ecryptfs_main_fops = { |
354 | .llseek = generic_file_llseek, | 353 | .llseek = generic_file_llseek, |
355 | .read = do_sync_read, | 354 | .read = new_sync_read, |
356 | .aio_read = ecryptfs_read_update_atime, | 355 | .read_iter = ecryptfs_read_update_atime, |
357 | .write = do_sync_write, | 356 | .write = new_sync_write, |
358 | .aio_write = generic_file_aio_write, | 357 | .write_iter = generic_file_write_iter, |
359 | .iterate = ecryptfs_readdir, | 358 | .iterate = ecryptfs_readdir, |
360 | .unlocked_ioctl = ecryptfs_unlocked_ioctl, | 359 | .unlocked_ioctl = ecryptfs_unlocked_ioctl, |
361 | #ifdef CONFIG_COMPAT | 360 | #ifdef CONFIG_COMPAT |
diff --git a/fs/exofs/file.c b/fs/exofs/file.c index 491c6c078e7f..71bf8e4fb5d4 100644 --- a/fs/exofs/file.c +++ b/fs/exofs/file.c | |||
@@ -67,17 +67,17 @@ static int exofs_flush(struct file *file, fl_owner_t id) | |||
67 | 67 | ||
68 | const struct file_operations exofs_file_operations = { | 68 | const struct file_operations exofs_file_operations = { |
69 | .llseek = generic_file_llseek, | 69 | .llseek = generic_file_llseek, |
70 | .read = do_sync_read, | 70 | .read = new_sync_read, |
71 | .write = do_sync_write, | 71 | .write = new_sync_write, |
72 | .aio_read = generic_file_aio_read, | 72 | .read_iter = generic_file_read_iter, |
73 | .aio_write = generic_file_aio_write, | 73 | .write_iter = generic_file_write_iter, |
74 | .mmap = generic_file_mmap, | 74 | .mmap = generic_file_mmap, |
75 | .open = generic_file_open, | 75 | .open = generic_file_open, |
76 | .release = exofs_release_file, | 76 | .release = exofs_release_file, |
77 | .fsync = exofs_file_fsync, | 77 | .fsync = exofs_file_fsync, |
78 | .flush = exofs_flush, | 78 | .flush = exofs_flush, |
79 | .splice_read = generic_file_splice_read, | 79 | .splice_read = generic_file_splice_read, |
80 | .splice_write = generic_file_splice_write, | 80 | .splice_write = iter_file_splice_write, |
81 | }; | 81 | }; |
82 | 82 | ||
83 | const struct inode_operations exofs_file_inode_operations = { | 83 | const struct inode_operations exofs_file_inode_operations = { |
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index d1c244d67667..3f9cafd73931 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c | |||
@@ -964,7 +964,7 @@ static void exofs_invalidatepage(struct page *page, unsigned int offset, | |||
964 | 964 | ||
965 | /* TODO: Should be easy enough to do proprly */ | 965 | /* TODO: Should be easy enough to do proprly */ |
966 | static ssize_t exofs_direct_IO(int rw, struct kiocb *iocb, | 966 | static ssize_t exofs_direct_IO(int rw, struct kiocb *iocb, |
967 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 967 | struct iov_iter *iter, loff_t offset) |
968 | { | 968 | { |
969 | return 0; | 969 | return 0; |
970 | } | 970 | } |
diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 44c36e590765..7c87b22a7228 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c | |||
@@ -62,10 +62,10 @@ int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
62 | */ | 62 | */ |
63 | const struct file_operations ext2_file_operations = { | 63 | const struct file_operations ext2_file_operations = { |
64 | .llseek = generic_file_llseek, | 64 | .llseek = generic_file_llseek, |
65 | .read = do_sync_read, | 65 | .read = new_sync_read, |
66 | .write = do_sync_write, | 66 | .write = new_sync_write, |
67 | .aio_read = generic_file_aio_read, | 67 | .read_iter = generic_file_read_iter, |
68 | .aio_write = generic_file_aio_write, | 68 | .write_iter = generic_file_write_iter, |
69 | .unlocked_ioctl = ext2_ioctl, | 69 | .unlocked_ioctl = ext2_ioctl, |
70 | #ifdef CONFIG_COMPAT | 70 | #ifdef CONFIG_COMPAT |
71 | .compat_ioctl = ext2_compat_ioctl, | 71 | .compat_ioctl = ext2_compat_ioctl, |
@@ -75,7 +75,7 @@ const struct file_operations ext2_file_operations = { | |||
75 | .release = ext2_release_file, | 75 | .release = ext2_release_file, |
76 | .fsync = ext2_fsync, | 76 | .fsync = ext2_fsync, |
77 | .splice_read = generic_file_splice_read, | 77 | .splice_read = generic_file_splice_read, |
78 | .splice_write = generic_file_splice_write, | 78 | .splice_write = iter_file_splice_write, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | #ifdef CONFIG_EXT2_FS_XIP | 81 | #ifdef CONFIG_EXT2_FS_XIP |
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index b1d2a4675d42..36d35c36311d 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c | |||
@@ -850,18 +850,18 @@ static sector_t ext2_bmap(struct address_space *mapping, sector_t block) | |||
850 | } | 850 | } |
851 | 851 | ||
852 | static ssize_t | 852 | static ssize_t |
853 | ext2_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 853 | ext2_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, |
854 | loff_t offset, unsigned long nr_segs) | 854 | loff_t offset) |
855 | { | 855 | { |
856 | struct file *file = iocb->ki_filp; | 856 | struct file *file = iocb->ki_filp; |
857 | struct address_space *mapping = file->f_mapping; | 857 | struct address_space *mapping = file->f_mapping; |
858 | struct inode *inode = mapping->host; | 858 | struct inode *inode = mapping->host; |
859 | size_t count = iov_iter_count(iter); | ||
859 | ssize_t ret; | 860 | ssize_t ret; |
860 | 861 | ||
861 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 862 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, ext2_get_block); |
862 | ext2_get_block); | ||
863 | if (ret < 0 && (rw & WRITE)) | 863 | if (ret < 0 && (rw & WRITE)) |
864 | ext2_write_failed(mapping, offset + iov_length(iov, nr_segs)); | 864 | ext2_write_failed(mapping, offset + count); |
865 | return ret; | 865 | return ret; |
866 | } | 866 | } |
867 | 867 | ||
diff --git a/fs/ext3/file.c b/fs/ext3/file.c index aad05311392a..a062fa1e1b11 100644 --- a/fs/ext3/file.c +++ b/fs/ext3/file.c | |||
@@ -50,10 +50,10 @@ static int ext3_release_file (struct inode * inode, struct file * filp) | |||
50 | 50 | ||
51 | const struct file_operations ext3_file_operations = { | 51 | const struct file_operations ext3_file_operations = { |
52 | .llseek = generic_file_llseek, | 52 | .llseek = generic_file_llseek, |
53 | .read = do_sync_read, | 53 | .read = new_sync_read, |
54 | .write = do_sync_write, | 54 | .write = new_sync_write, |
55 | .aio_read = generic_file_aio_read, | 55 | .read_iter = generic_file_read_iter, |
56 | .aio_write = generic_file_aio_write, | 56 | .write_iter = generic_file_write_iter, |
57 | .unlocked_ioctl = ext3_ioctl, | 57 | .unlocked_ioctl = ext3_ioctl, |
58 | #ifdef CONFIG_COMPAT | 58 | #ifdef CONFIG_COMPAT |
59 | .compat_ioctl = ext3_compat_ioctl, | 59 | .compat_ioctl = ext3_compat_ioctl, |
@@ -63,7 +63,7 @@ const struct file_operations ext3_file_operations = { | |||
63 | .release = ext3_release_file, | 63 | .release = ext3_release_file, |
64 | .fsync = ext3_sync_file, | 64 | .fsync = ext3_sync_file, |
65 | .splice_read = generic_file_splice_read, | 65 | .splice_read = generic_file_splice_read, |
66 | .splice_write = generic_file_splice_write, | 66 | .splice_write = iter_file_splice_write, |
67 | }; | 67 | }; |
68 | 68 | ||
69 | const struct inode_operations ext3_file_inode_operations = { | 69 | const struct inode_operations ext3_file_inode_operations = { |
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 695abe738a24..2c6ccc49ba27 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -1821,8 +1821,7 @@ static int ext3_releasepage(struct page *page, gfp_t wait) | |||
1821 | * VFS code falls back into buffered path in that case so we are safe. | 1821 | * VFS code falls back into buffered path in that case so we are safe. |
1822 | */ | 1822 | */ |
1823 | static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | 1823 | static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, |
1824 | const struct iovec *iov, loff_t offset, | 1824 | struct iov_iter *iter, loff_t offset) |
1825 | unsigned long nr_segs) | ||
1826 | { | 1825 | { |
1827 | struct file *file = iocb->ki_filp; | 1826 | struct file *file = iocb->ki_filp; |
1828 | struct inode *inode = file->f_mapping->host; | 1827 | struct inode *inode = file->f_mapping->host; |
@@ -1830,10 +1829,10 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | |||
1830 | handle_t *handle; | 1829 | handle_t *handle; |
1831 | ssize_t ret; | 1830 | ssize_t ret; |
1832 | int orphan = 0; | 1831 | int orphan = 0; |
1833 | size_t count = iov_length(iov, nr_segs); | 1832 | size_t count = iov_iter_count(iter); |
1834 | int retries = 0; | 1833 | int retries = 0; |
1835 | 1834 | ||
1836 | trace_ext3_direct_IO_enter(inode, offset, iov_length(iov, nr_segs), rw); | 1835 | trace_ext3_direct_IO_enter(inode, offset, count, rw); |
1837 | 1836 | ||
1838 | if (rw == WRITE) { | 1837 | if (rw == WRITE) { |
1839 | loff_t final_size = offset + count; | 1838 | loff_t final_size = offset + count; |
@@ -1857,15 +1856,14 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | |||
1857 | } | 1856 | } |
1858 | 1857 | ||
1859 | retry: | 1858 | retry: |
1860 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 1859 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, ext3_get_block); |
1861 | ext3_get_block); | ||
1862 | /* | 1860 | /* |
1863 | * In case of error extending write may have instantiated a few | 1861 | * In case of error extending write may have instantiated a few |
1864 | * blocks outside i_size. Trim these off again. | 1862 | * blocks outside i_size. Trim these off again. |
1865 | */ | 1863 | */ |
1866 | if (unlikely((rw & WRITE) && ret < 0)) { | 1864 | if (unlikely((rw & WRITE) && ret < 0)) { |
1867 | loff_t isize = i_size_read(inode); | 1865 | loff_t isize = i_size_read(inode); |
1868 | loff_t end = offset + iov_length(iov, nr_segs); | 1866 | loff_t end = offset + count; |
1869 | 1867 | ||
1870 | if (end > isize) | 1868 | if (end > isize) |
1871 | ext3_truncate_failed_direct_write(inode); | 1869 | ext3_truncate_failed_direct_write(inode); |
@@ -1910,8 +1908,7 @@ retry: | |||
1910 | ret = err; | 1908 | ret = err; |
1911 | } | 1909 | } |
1912 | out: | 1910 | out: |
1913 | trace_ext3_direct_IO_exit(inode, offset, | 1911 | trace_ext3_direct_IO_exit(inode, offset, count, rw, ret); |
1914 | iov_length(iov, nr_segs), rw, ret); | ||
1915 | return ret; | 1912 | return ret; |
1916 | } | 1913 | } |
1917 | 1914 | ||
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 1479e2ae00d2..7cc5a0e23688 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -2140,8 +2140,7 @@ extern void ext4_da_update_reserve_space(struct inode *inode, | |||
2140 | extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, | 2140 | extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, |
2141 | struct ext4_map_blocks *map, int flags); | 2141 | struct ext4_map_blocks *map, int flags); |
2142 | extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, | 2142 | extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, |
2143 | const struct iovec *iov, loff_t offset, | 2143 | struct iov_iter *iter, loff_t offset); |
2144 | unsigned long nr_segs); | ||
2145 | extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock); | 2144 | extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock); |
2146 | extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); | 2145 | extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); |
2147 | extern void ext4_ind_truncate(handle_t *, struct inode *inode); | 2146 | extern void ext4_ind_truncate(handle_t *, struct inode *inode); |
diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 4e8bc284ec0e..8695f70af1ef 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c | |||
@@ -74,26 +74,22 @@ static void ext4_unwritten_wait(struct inode *inode) | |||
74 | * or one thread will zero the other's data, causing corruption. | 74 | * or one thread will zero the other's data, causing corruption. |
75 | */ | 75 | */ |
76 | static int | 76 | static int |
77 | ext4_unaligned_aio(struct inode *inode, const struct iovec *iov, | 77 | ext4_unaligned_aio(struct inode *inode, struct iov_iter *from, loff_t pos) |
78 | unsigned long nr_segs, loff_t pos) | ||
79 | { | 78 | { |
80 | struct super_block *sb = inode->i_sb; | 79 | struct super_block *sb = inode->i_sb; |
81 | int blockmask = sb->s_blocksize - 1; | 80 | int blockmask = sb->s_blocksize - 1; |
82 | size_t count = iov_length(iov, nr_segs); | ||
83 | loff_t final_size = pos + count; | ||
84 | 81 | ||
85 | if (pos >= i_size_read(inode)) | 82 | if (pos >= i_size_read(inode)) |
86 | return 0; | 83 | return 0; |
87 | 84 | ||
88 | if ((pos & blockmask) || (final_size & blockmask)) | 85 | if ((pos | iov_iter_alignment(from)) & blockmask) |
89 | return 1; | 86 | return 1; |
90 | 87 | ||
91 | return 0; | 88 | return 0; |
92 | } | 89 | } |
93 | 90 | ||
94 | static ssize_t | 91 | static ssize_t |
95 | ext4_file_write(struct kiocb *iocb, const struct iovec *iov, | 92 | ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
96 | unsigned long nr_segs, loff_t pos) | ||
97 | { | 93 | { |
98 | struct file *file = iocb->ki_filp; | 94 | struct file *file = iocb->ki_filp; |
99 | struct inode *inode = file_inode(iocb->ki_filp); | 95 | struct inode *inode = file_inode(iocb->ki_filp); |
@@ -101,10 +97,9 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
101 | struct blk_plug plug; | 97 | struct blk_plug plug; |
102 | int o_direct = file->f_flags & O_DIRECT; | 98 | int o_direct = file->f_flags & O_DIRECT; |
103 | int overwrite = 0; | 99 | int overwrite = 0; |
104 | size_t length = iov_length(iov, nr_segs); | 100 | size_t length = iov_iter_count(from); |
105 | ssize_t ret; | 101 | ssize_t ret; |
106 | 102 | loff_t pos = iocb->ki_pos; | |
107 | BUG_ON(iocb->ki_pos != pos); | ||
108 | 103 | ||
109 | /* | 104 | /* |
110 | * Unaligned direct AIO must be serialized; see comment above | 105 | * Unaligned direct AIO must be serialized; see comment above |
@@ -114,7 +109,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
114 | ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) && | 109 | ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) && |
115 | !is_sync_kiocb(iocb) && | 110 | !is_sync_kiocb(iocb) && |
116 | (file->f_flags & O_APPEND || | 111 | (file->f_flags & O_APPEND || |
117 | ext4_unaligned_aio(inode, iov, nr_segs, pos))) { | 112 | ext4_unaligned_aio(inode, from, pos))) { |
118 | aio_mutex = ext4_aio_mutex(inode); | 113 | aio_mutex = ext4_aio_mutex(inode); |
119 | mutex_lock(aio_mutex); | 114 | mutex_lock(aio_mutex); |
120 | ext4_unwritten_wait(inode); | 115 | ext4_unwritten_wait(inode); |
@@ -138,10 +133,8 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
138 | goto errout; | 133 | goto errout; |
139 | } | 134 | } |
140 | 135 | ||
141 | if (pos + length > sbi->s_bitmap_maxbytes) { | 136 | if (pos + length > sbi->s_bitmap_maxbytes) |
142 | nr_segs = iov_shorten((struct iovec *)iov, nr_segs, | 137 | iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos); |
143 | sbi->s_bitmap_maxbytes - pos); | ||
144 | } | ||
145 | } | 138 | } |
146 | 139 | ||
147 | if (o_direct) { | 140 | if (o_direct) { |
@@ -179,7 +172,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
179 | } | 172 | } |
180 | } | 173 | } |
181 | 174 | ||
182 | ret = __generic_file_aio_write(iocb, iov, nr_segs); | 175 | ret = __generic_file_write_iter(iocb, from); |
183 | mutex_unlock(&inode->i_mutex); | 176 | mutex_unlock(&inode->i_mutex); |
184 | 177 | ||
185 | if (ret > 0) { | 178 | if (ret > 0) { |
@@ -594,10 +587,10 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence) | |||
594 | 587 | ||
595 | const struct file_operations ext4_file_operations = { | 588 | const struct file_operations ext4_file_operations = { |
596 | .llseek = ext4_llseek, | 589 | .llseek = ext4_llseek, |
597 | .read = do_sync_read, | 590 | .read = new_sync_read, |
598 | .write = do_sync_write, | 591 | .write = new_sync_write, |
599 | .aio_read = generic_file_aio_read, | 592 | .read_iter = generic_file_read_iter, |
600 | .aio_write = ext4_file_write, | 593 | .write_iter = ext4_file_write_iter, |
601 | .unlocked_ioctl = ext4_ioctl, | 594 | .unlocked_ioctl = ext4_ioctl, |
602 | #ifdef CONFIG_COMPAT | 595 | #ifdef CONFIG_COMPAT |
603 | .compat_ioctl = ext4_compat_ioctl, | 596 | .compat_ioctl = ext4_compat_ioctl, |
@@ -607,7 +600,7 @@ const struct file_operations ext4_file_operations = { | |||
607 | .release = ext4_release_file, | 600 | .release = ext4_release_file, |
608 | .fsync = ext4_sync_file, | 601 | .fsync = ext4_sync_file, |
609 | .splice_read = generic_file_splice_read, | 602 | .splice_read = generic_file_splice_read, |
610 | .splice_write = generic_file_splice_write, | 603 | .splice_write = iter_file_splice_write, |
611 | .fallocate = ext4_fallocate, | 604 | .fallocate = ext4_fallocate, |
612 | }; | 605 | }; |
613 | 606 | ||
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 594009f5f523..8a57e9fcd1b9 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c | |||
@@ -639,8 +639,7 @@ out: | |||
639 | * VFS code falls back into buffered path in that case so we are safe. | 639 | * VFS code falls back into buffered path in that case so we are safe. |
640 | */ | 640 | */ |
641 | ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, | 641 | ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, |
642 | const struct iovec *iov, loff_t offset, | 642 | struct iov_iter *iter, loff_t offset) |
643 | unsigned long nr_segs) | ||
644 | { | 643 | { |
645 | struct file *file = iocb->ki_filp; | 644 | struct file *file = iocb->ki_filp; |
646 | struct inode *inode = file->f_mapping->host; | 645 | struct inode *inode = file->f_mapping->host; |
@@ -648,7 +647,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, | |||
648 | handle_t *handle; | 647 | handle_t *handle; |
649 | ssize_t ret; | 648 | ssize_t ret; |
650 | int orphan = 0; | 649 | int orphan = 0; |
651 | size_t count = iov_length(iov, nr_segs); | 650 | size_t count = iov_iter_count(iter); |
652 | int retries = 0; | 651 | int retries = 0; |
653 | 652 | ||
654 | if (rw == WRITE) { | 653 | if (rw == WRITE) { |
@@ -687,18 +686,17 @@ retry: | |||
687 | goto locked; | 686 | goto locked; |
688 | } | 687 | } |
689 | ret = __blockdev_direct_IO(rw, iocb, inode, | 688 | ret = __blockdev_direct_IO(rw, iocb, inode, |
690 | inode->i_sb->s_bdev, iov, | 689 | inode->i_sb->s_bdev, iter, offset, |
691 | offset, nr_segs, | ||
692 | ext4_get_block, NULL, NULL, 0); | 690 | ext4_get_block, NULL, NULL, 0); |
693 | inode_dio_done(inode); | 691 | inode_dio_done(inode); |
694 | } else { | 692 | } else { |
695 | locked: | 693 | locked: |
696 | ret = blockdev_direct_IO(rw, iocb, inode, iov, | 694 | ret = blockdev_direct_IO(rw, iocb, inode, iter, |
697 | offset, nr_segs, ext4_get_block); | 695 | offset, ext4_get_block); |
698 | 696 | ||
699 | if (unlikely((rw & WRITE) && ret < 0)) { | 697 | if (unlikely((rw & WRITE) && ret < 0)) { |
700 | loff_t isize = i_size_read(inode); | 698 | loff_t isize = i_size_read(inode); |
701 | loff_t end = offset + iov_length(iov, nr_segs); | 699 | loff_t end = offset + count; |
702 | 700 | ||
703 | if (end > isize) | 701 | if (end > isize) |
704 | ext4_truncate_failed_write(inode); | 702 | ext4_truncate_failed_write(inode); |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7fcd68ee9155..8a064734e6eb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -3093,13 +3093,12 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, | |||
3093 | * | 3093 | * |
3094 | */ | 3094 | */ |
3095 | static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | 3095 | static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, |
3096 | const struct iovec *iov, loff_t offset, | 3096 | struct iov_iter *iter, loff_t offset) |
3097 | unsigned long nr_segs) | ||
3098 | { | 3097 | { |
3099 | struct file *file = iocb->ki_filp; | 3098 | struct file *file = iocb->ki_filp; |
3100 | struct inode *inode = file->f_mapping->host; | 3099 | struct inode *inode = file->f_mapping->host; |
3101 | ssize_t ret; | 3100 | ssize_t ret; |
3102 | size_t count = iov_length(iov, nr_segs); | 3101 | size_t count = iov_iter_count(iter); |
3103 | int overwrite = 0; | 3102 | int overwrite = 0; |
3104 | get_block_t *get_block_func = NULL; | 3103 | get_block_t *get_block_func = NULL; |
3105 | int dio_flags = 0; | 3104 | int dio_flags = 0; |
@@ -3108,7 +3107,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3108 | 3107 | ||
3109 | /* Use the old path for reads and writes beyond i_size. */ | 3108 | /* Use the old path for reads and writes beyond i_size. */ |
3110 | if (rw != WRITE || final_size > inode->i_size) | 3109 | if (rw != WRITE || final_size > inode->i_size) |
3111 | return ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs); | 3110 | return ext4_ind_direct_IO(rw, iocb, iter, offset); |
3112 | 3111 | ||
3113 | BUG_ON(iocb->private == NULL); | 3112 | BUG_ON(iocb->private == NULL); |
3114 | 3113 | ||
@@ -3175,8 +3174,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3175 | dio_flags = DIO_LOCKING; | 3174 | dio_flags = DIO_LOCKING; |
3176 | } | 3175 | } |
3177 | ret = __blockdev_direct_IO(rw, iocb, inode, | 3176 | ret = __blockdev_direct_IO(rw, iocb, inode, |
3178 | inode->i_sb->s_bdev, iov, | 3177 | inode->i_sb->s_bdev, iter, |
3179 | offset, nr_segs, | 3178 | offset, |
3180 | get_block_func, | 3179 | get_block_func, |
3181 | ext4_end_io_dio, | 3180 | ext4_end_io_dio, |
3182 | NULL, | 3181 | NULL, |
@@ -3230,11 +3229,11 @@ retake_lock: | |||
3230 | } | 3229 | } |
3231 | 3230 | ||
3232 | static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | 3231 | static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, |
3233 | const struct iovec *iov, loff_t offset, | 3232 | struct iov_iter *iter, loff_t offset) |
3234 | unsigned long nr_segs) | ||
3235 | { | 3233 | { |
3236 | struct file *file = iocb->ki_filp; | 3234 | struct file *file = iocb->ki_filp; |
3237 | struct inode *inode = file->f_mapping->host; | 3235 | struct inode *inode = file->f_mapping->host; |
3236 | size_t count = iov_iter_count(iter); | ||
3238 | ssize_t ret; | 3237 | ssize_t ret; |
3239 | 3238 | ||
3240 | /* | 3239 | /* |
@@ -3247,13 +3246,12 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | |||
3247 | if (ext4_has_inline_data(inode)) | 3246 | if (ext4_has_inline_data(inode)) |
3248 | return 0; | 3247 | return 0; |
3249 | 3248 | ||
3250 | trace_ext4_direct_IO_enter(inode, offset, iov_length(iov, nr_segs), rw); | 3249 | trace_ext4_direct_IO_enter(inode, offset, count, rw); |
3251 | if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) | 3250 | if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) |
3252 | ret = ext4_ext_direct_IO(rw, iocb, iov, offset, nr_segs); | 3251 | ret = ext4_ext_direct_IO(rw, iocb, iter, offset); |
3253 | else | 3252 | else |
3254 | ret = ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs); | 3253 | ret = ext4_ind_direct_IO(rw, iocb, iter, offset); |
3255 | trace_ext4_direct_IO_exit(inode, offset, | 3254 | trace_ext4_direct_IO_exit(inode, offset, count, rw, ret); |
3256 | iov_length(iov, nr_segs), rw, ret); | ||
3257 | return ret; | 3255 | return ret; |
3258 | } | 3256 | } |
3259 | 3257 | ||
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c1fb6dd10911..0924521306b4 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -1017,10 +1017,9 @@ static int f2fs_write_end(struct file *file, | |||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | static int check_direct_IO(struct inode *inode, int rw, | 1019 | static int check_direct_IO(struct inode *inode, int rw, |
1020 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 1020 | struct iov_iter *iter, loff_t offset) |
1021 | { | 1021 | { |
1022 | unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; | 1022 | unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; |
1023 | int i; | ||
1024 | 1023 | ||
1025 | if (rw == READ) | 1024 | if (rw == READ) |
1026 | return 0; | 1025 | return 0; |
@@ -1028,14 +1027,14 @@ static int check_direct_IO(struct inode *inode, int rw, | |||
1028 | if (offset & blocksize_mask) | 1027 | if (offset & blocksize_mask) |
1029 | return -EINVAL; | 1028 | return -EINVAL; |
1030 | 1029 | ||
1031 | for (i = 0; i < nr_segs; i++) | 1030 | if (iov_iter_alignment(iter) & blocksize_mask) |
1032 | if (iov[i].iov_len & blocksize_mask) | 1031 | return -EINVAL; |
1033 | return -EINVAL; | 1032 | |
1034 | return 0; | 1033 | return 0; |
1035 | } | 1034 | } |
1036 | 1035 | ||
1037 | static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, | 1036 | static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, |
1038 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 1037 | struct iov_iter *iter, loff_t offset) |
1039 | { | 1038 | { |
1040 | struct file *file = iocb->ki_filp; | 1039 | struct file *file = iocb->ki_filp; |
1041 | struct inode *inode = file->f_mapping->host; | 1040 | struct inode *inode = file->f_mapping->host; |
@@ -1044,14 +1043,14 @@ static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb, | |||
1044 | if (f2fs_has_inline_data(inode)) | 1043 | if (f2fs_has_inline_data(inode)) |
1045 | return 0; | 1044 | return 0; |
1046 | 1045 | ||
1047 | if (check_direct_IO(inode, rw, iov, offset, nr_segs)) | 1046 | if (check_direct_IO(inode, rw, iter, offset)) |
1048 | return 0; | 1047 | return 0; |
1049 | 1048 | ||
1050 | /* clear fsync mark to recover these blocks */ | 1049 | /* clear fsync mark to recover these blocks */ |
1051 | fsync_mark_clear(F2FS_SB(inode->i_sb), inode->i_ino); | 1050 | fsync_mark_clear(F2FS_SB(inode->i_sb), inode->i_ino); |
1052 | 1051 | ||
1053 | return blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 1052 | return blockdev_direct_IO(rw, iocb, inode, iter, offset, |
1054 | get_data_block); | 1053 | get_data_block); |
1055 | } | 1054 | } |
1056 | 1055 | ||
1057 | static void f2fs_invalidate_data_page(struct page *page, unsigned int offset, | 1056 | static void f2fs_invalidate_data_page(struct page *page, unsigned int offset, |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 9c49c593d8eb..c58e33075719 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -808,10 +808,10 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
808 | 808 | ||
809 | const struct file_operations f2fs_file_operations = { | 809 | const struct file_operations f2fs_file_operations = { |
810 | .llseek = f2fs_llseek, | 810 | .llseek = f2fs_llseek, |
811 | .read = do_sync_read, | 811 | .read = new_sync_read, |
812 | .write = do_sync_write, | 812 | .write = new_sync_write, |
813 | .aio_read = generic_file_aio_read, | 813 | .read_iter = generic_file_read_iter, |
814 | .aio_write = generic_file_aio_write, | 814 | .write_iter = generic_file_write_iter, |
815 | .open = generic_file_open, | 815 | .open = generic_file_open, |
816 | .mmap = f2fs_file_mmap, | 816 | .mmap = f2fs_file_mmap, |
817 | .fsync = f2fs_sync_file, | 817 | .fsync = f2fs_sync_file, |
@@ -821,5 +821,5 @@ const struct file_operations f2fs_file_operations = { | |||
821 | .compat_ioctl = f2fs_compat_ioctl, | 821 | .compat_ioctl = f2fs_compat_ioctl, |
822 | #endif | 822 | #endif |
823 | .splice_read = generic_file_splice_read, | 823 | .splice_read = generic_file_splice_read, |
824 | .splice_write = generic_file_splice_write, | 824 | .splice_write = iter_file_splice_write, |
825 | }; | 825 | }; |
diff --git a/fs/fat/file.c b/fs/fat/file.c index 9b104f543056..85f79a89e747 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c | |||
@@ -170,10 +170,10 @@ int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) | |||
170 | 170 | ||
171 | const struct file_operations fat_file_operations = { | 171 | const struct file_operations fat_file_operations = { |
172 | .llseek = generic_file_llseek, | 172 | .llseek = generic_file_llseek, |
173 | .read = do_sync_read, | 173 | .read = new_sync_read, |
174 | .write = do_sync_write, | 174 | .write = new_sync_write, |
175 | .aio_read = generic_file_aio_read, | 175 | .read_iter = generic_file_read_iter, |
176 | .aio_write = generic_file_aio_write, | 176 | .write_iter = generic_file_write_iter, |
177 | .mmap = generic_file_mmap, | 177 | .mmap = generic_file_mmap, |
178 | .release = fat_file_release, | 178 | .release = fat_file_release, |
179 | .unlocked_ioctl = fat_generic_ioctl, | 179 | .unlocked_ioctl = fat_generic_ioctl, |
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 9c83594d7fb5..756aead10d96 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c | |||
@@ -247,12 +247,13 @@ static int fat_write_end(struct file *file, struct address_space *mapping, | |||
247 | } | 247 | } |
248 | 248 | ||
249 | static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | 249 | static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, |
250 | const struct iovec *iov, | 250 | struct iov_iter *iter, |
251 | loff_t offset, unsigned long nr_segs) | 251 | loff_t offset) |
252 | { | 252 | { |
253 | struct file *file = iocb->ki_filp; | 253 | struct file *file = iocb->ki_filp; |
254 | struct address_space *mapping = file->f_mapping; | 254 | struct address_space *mapping = file->f_mapping; |
255 | struct inode *inode = mapping->host; | 255 | struct inode *inode = mapping->host; |
256 | size_t count = iov_iter_count(iter); | ||
256 | ssize_t ret; | 257 | ssize_t ret; |
257 | 258 | ||
258 | if (rw == WRITE) { | 259 | if (rw == WRITE) { |
@@ -265,7 +266,7 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | |||
265 | * | 266 | * |
266 | * Return 0, and fallback to normal buffered write. | 267 | * Return 0, and fallback to normal buffered write. |
267 | */ | 268 | */ |
268 | loff_t size = offset + iov_length(iov, nr_segs); | 269 | loff_t size = offset + count; |
269 | if (MSDOS_I(inode)->mmu_private < size) | 270 | if (MSDOS_I(inode)->mmu_private < size) |
270 | return 0; | 271 | return 0; |
271 | } | 272 | } |
@@ -274,10 +275,9 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | |||
274 | * FAT need to use the DIO_LOCKING for avoiding the race | 275 | * FAT need to use the DIO_LOCKING for avoiding the race |
275 | * condition of fat_get_block() and ->truncate(). | 276 | * condition of fat_get_block() and ->truncate(). |
276 | */ | 277 | */ |
277 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 278 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, fat_get_block); |
278 | fat_get_block); | ||
279 | if (ret < 0 && (rw & WRITE)) | 279 | if (ret < 0 && (rw & WRITE)) |
280 | fat_write_failed(mapping, offset + iov_length(iov, nr_segs)); | 280 | fat_write_failed(mapping, offset + count); |
281 | 281 | ||
282 | return ret; | 282 | return ret; |
283 | } | 283 | } |
@@ -44,15 +44,10 @@ static void *alloc_fdmem(size_t size) | |||
44 | return vmalloc(size); | 44 | return vmalloc(size); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void free_fdmem(void *ptr) | ||
48 | { | ||
49 | is_vmalloc_addr(ptr) ? vfree(ptr) : kfree(ptr); | ||
50 | } | ||
51 | |||
52 | static void __free_fdtable(struct fdtable *fdt) | 47 | static void __free_fdtable(struct fdtable *fdt) |
53 | { | 48 | { |
54 | free_fdmem(fdt->fd); | 49 | kvfree(fdt->fd); |
55 | free_fdmem(fdt->open_fds); | 50 | kvfree(fdt->open_fds); |
56 | kfree(fdt); | 51 | kfree(fdt); |
57 | } | 52 | } |
58 | 53 | ||
@@ -130,7 +125,7 @@ static struct fdtable * alloc_fdtable(unsigned int nr) | |||
130 | return fdt; | 125 | return fdt; |
131 | 126 | ||
132 | out_arr: | 127 | out_arr: |
133 | free_fdmem(fdt->fd); | 128 | kvfree(fdt->fd); |
134 | out_fdt: | 129 | out_fdt: |
135 | kfree(fdt); | 130 | kfree(fdt); |
136 | out: | 131 | out: |
diff --git a/fs/file_table.c b/fs/file_table.c index 40bf4660f0a3..385bfd31512a 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -175,6 +175,12 @@ struct file *alloc_file(struct path *path, fmode_t mode, | |||
175 | file->f_path = *path; | 175 | file->f_path = *path; |
176 | file->f_inode = path->dentry->d_inode; | 176 | file->f_inode = path->dentry->d_inode; |
177 | file->f_mapping = path->dentry->d_inode->i_mapping; | 177 | file->f_mapping = path->dentry->d_inode->i_mapping; |
178 | if ((mode & FMODE_READ) && | ||
179 | likely(fop->read || fop->aio_read || fop->read_iter)) | ||
180 | mode |= FMODE_CAN_READ; | ||
181 | if ((mode & FMODE_WRITE) && | ||
182 | likely(fop->write || fop->aio_write || fop->write_iter)) | ||
183 | mode |= FMODE_CAN_WRITE; | ||
178 | file->f_mode = mode; | 184 | file->f_mode = mode; |
179 | file->f_op = fop; | 185 | file->f_op = fop; |
180 | if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | 186 | if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) |
diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c index 13b691a8a7d2..966ace8b243f 100644 --- a/fs/fuse/cuse.c +++ b/fs/fuse/cuse.c | |||
@@ -94,8 +94,10 @@ static ssize_t cuse_read(struct file *file, char __user *buf, size_t count, | |||
94 | loff_t pos = 0; | 94 | loff_t pos = 0; |
95 | struct iovec iov = { .iov_base = buf, .iov_len = count }; | 95 | struct iovec iov = { .iov_base = buf, .iov_len = count }; |
96 | struct fuse_io_priv io = { .async = 0, .file = file }; | 96 | struct fuse_io_priv io = { .async = 0, .file = file }; |
97 | struct iov_iter ii; | ||
98 | iov_iter_init(&ii, READ, &iov, 1, count); | ||
97 | 99 | ||
98 | return fuse_direct_io(&io, &iov, 1, count, &pos, FUSE_DIO_CUSE); | 100 | return fuse_direct_io(&io, &ii, &pos, FUSE_DIO_CUSE); |
99 | } | 101 | } |
100 | 102 | ||
101 | static ssize_t cuse_write(struct file *file, const char __user *buf, | 103 | static ssize_t cuse_write(struct file *file, const char __user *buf, |
@@ -104,12 +106,14 @@ static ssize_t cuse_write(struct file *file, const char __user *buf, | |||
104 | loff_t pos = 0; | 106 | loff_t pos = 0; |
105 | struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = count }; | 107 | struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = count }; |
106 | struct fuse_io_priv io = { .async = 0, .file = file }; | 108 | struct fuse_io_priv io = { .async = 0, .file = file }; |
109 | struct iov_iter ii; | ||
110 | iov_iter_init(&ii, WRITE, &iov, 1, count); | ||
107 | 111 | ||
108 | /* | 112 | /* |
109 | * No locking or generic_write_checks(), the server is | 113 | * No locking or generic_write_checks(), the server is |
110 | * responsible for locking and sanity checks. | 114 | * responsible for locking and sanity checks. |
111 | */ | 115 | */ |
112 | return fuse_direct_io(&io, &iov, 1, count, &pos, | 116 | return fuse_direct_io(&io, &ii, &pos, |
113 | FUSE_DIO_WRITE | FUSE_DIO_CUSE); | 117 | FUSE_DIO_WRITE | FUSE_DIO_CUSE); |
114 | } | 118 | } |
115 | 119 | ||
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 903cbc9cd6bd..6e16dad13e9b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -933,8 +933,7 @@ out: | |||
933 | return err; | 933 | return err; |
934 | } | 934 | } |
935 | 935 | ||
936 | static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | 936 | static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to) |
937 | unsigned long nr_segs, loff_t pos) | ||
938 | { | 937 | { |
939 | struct inode *inode = iocb->ki_filp->f_mapping->host; | 938 | struct inode *inode = iocb->ki_filp->f_mapping->host; |
940 | struct fuse_conn *fc = get_fuse_conn(inode); | 939 | struct fuse_conn *fc = get_fuse_conn(inode); |
@@ -945,14 +944,14 @@ static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | |||
945 | * i_size is up to date). | 944 | * i_size is up to date). |
946 | */ | 945 | */ |
947 | if (fc->auto_inval_data || | 946 | if (fc->auto_inval_data || |
948 | (pos + iov_length(iov, nr_segs) > i_size_read(inode))) { | 947 | (iocb->ki_pos + iov_iter_count(to) > i_size_read(inode))) { |
949 | int err; | 948 | int err; |
950 | err = fuse_update_attributes(inode, NULL, iocb->ki_filp, NULL); | 949 | err = fuse_update_attributes(inode, NULL, iocb->ki_filp, NULL); |
951 | if (err) | 950 | if (err) |
952 | return err; | 951 | return err; |
953 | } | 952 | } |
954 | 953 | ||
955 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | 954 | return generic_file_read_iter(iocb, to); |
956 | } | 955 | } |
957 | 956 | ||
958 | static void fuse_write_fill(struct fuse_req *req, struct fuse_file *ff, | 957 | static void fuse_write_fill(struct fuse_req *req, struct fuse_file *ff, |
@@ -1181,19 +1180,17 @@ static ssize_t fuse_perform_write(struct file *file, | |||
1181 | return res > 0 ? res : err; | 1180 | return res > 0 ? res : err; |
1182 | } | 1181 | } |
1183 | 1182 | ||
1184 | static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 1183 | static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
1185 | unsigned long nr_segs, loff_t pos) | ||
1186 | { | 1184 | { |
1187 | struct file *file = iocb->ki_filp; | 1185 | struct file *file = iocb->ki_filp; |
1188 | struct address_space *mapping = file->f_mapping; | 1186 | struct address_space *mapping = file->f_mapping; |
1189 | size_t count = 0; | 1187 | size_t count = iov_iter_count(from); |
1190 | size_t ocount = 0; | ||
1191 | ssize_t written = 0; | 1188 | ssize_t written = 0; |
1192 | ssize_t written_buffered = 0; | 1189 | ssize_t written_buffered = 0; |
1193 | struct inode *inode = mapping->host; | 1190 | struct inode *inode = mapping->host; |
1194 | ssize_t err; | 1191 | ssize_t err; |
1195 | struct iov_iter i; | ||
1196 | loff_t endbyte = 0; | 1192 | loff_t endbyte = 0; |
1193 | loff_t pos = iocb->ki_pos; | ||
1197 | 1194 | ||
1198 | if (get_fuse_conn(inode)->writeback_cache) { | 1195 | if (get_fuse_conn(inode)->writeback_cache) { |
1199 | /* Update size (EOF optimization) and mode (SUID clearing) */ | 1196 | /* Update size (EOF optimization) and mode (SUID clearing) */ |
@@ -1201,17 +1198,9 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1201 | if (err) | 1198 | if (err) |
1202 | return err; | 1199 | return err; |
1203 | 1200 | ||
1204 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | 1201 | return generic_file_write_iter(iocb, from); |
1205 | } | 1202 | } |
1206 | 1203 | ||
1207 | WARN_ON(iocb->ki_pos != pos); | ||
1208 | |||
1209 | ocount = 0; | ||
1210 | err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ); | ||
1211 | if (err) | ||
1212 | return err; | ||
1213 | |||
1214 | count = ocount; | ||
1215 | mutex_lock(&inode->i_mutex); | 1204 | mutex_lock(&inode->i_mutex); |
1216 | 1205 | ||
1217 | /* We can write back this queue in page reclaim */ | 1206 | /* We can write back this queue in page reclaim */ |
@@ -1224,6 +1213,7 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1224 | if (count == 0) | 1213 | if (count == 0) |
1225 | goto out; | 1214 | goto out; |
1226 | 1215 | ||
1216 | iov_iter_truncate(from, count); | ||
1227 | err = file_remove_suid(file); | 1217 | err = file_remove_suid(file); |
1228 | if (err) | 1218 | if (err) |
1229 | goto out; | 1219 | goto out; |
@@ -1233,16 +1223,13 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1233 | goto out; | 1223 | goto out; |
1234 | 1224 | ||
1235 | if (file->f_flags & O_DIRECT) { | 1225 | if (file->f_flags & O_DIRECT) { |
1236 | written = generic_file_direct_write(iocb, iov, &nr_segs, pos, | 1226 | written = generic_file_direct_write(iocb, from, pos); |
1237 | count, ocount); | 1227 | if (written < 0 || !iov_iter_count(from)) |
1238 | if (written < 0 || written == count) | ||
1239 | goto out; | 1228 | goto out; |
1240 | 1229 | ||
1241 | pos += written; | 1230 | pos += written; |
1242 | count -= written; | ||
1243 | 1231 | ||
1244 | iov_iter_init(&i, iov, nr_segs, count, written); | 1232 | written_buffered = fuse_perform_write(file, mapping, from, pos); |
1245 | written_buffered = fuse_perform_write(file, mapping, &i, pos); | ||
1246 | if (written_buffered < 0) { | 1233 | if (written_buffered < 0) { |
1247 | err = written_buffered; | 1234 | err = written_buffered; |
1248 | goto out; | 1235 | goto out; |
@@ -1261,8 +1248,7 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1261 | written += written_buffered; | 1248 | written += written_buffered; |
1262 | iocb->ki_pos = pos + written_buffered; | 1249 | iocb->ki_pos = pos + written_buffered; |
1263 | } else { | 1250 | } else { |
1264 | iov_iter_init(&i, iov, nr_segs, count, 0); | 1251 | written = fuse_perform_write(file, mapping, from, pos); |
1265 | written = fuse_perform_write(file, mapping, &i, pos); | ||
1266 | if (written >= 0) | 1252 | if (written >= 0) |
1267 | iocb->ki_pos = pos + written; | 1253 | iocb->ki_pos = pos + written; |
1268 | } | 1254 | } |
@@ -1300,7 +1286,7 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii, | |||
1300 | size_t nbytes = 0; /* # bytes already packed in req */ | 1286 | size_t nbytes = 0; /* # bytes already packed in req */ |
1301 | 1287 | ||
1302 | /* Special case for kernel I/O: can copy directly into the buffer */ | 1288 | /* Special case for kernel I/O: can copy directly into the buffer */ |
1303 | if (segment_eq(get_fs(), KERNEL_DS)) { | 1289 | if (ii->type & ITER_KVEC) { |
1304 | unsigned long user_addr = fuse_get_user_addr(ii); | 1290 | unsigned long user_addr = fuse_get_user_addr(ii); |
1305 | size_t frag_size = fuse_get_frag_size(ii, *nbytesp); | 1291 | size_t frag_size = fuse_get_frag_size(ii, *nbytesp); |
1306 | 1292 | ||
@@ -1316,35 +1302,26 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii, | |||
1316 | 1302 | ||
1317 | while (nbytes < *nbytesp && req->num_pages < req->max_pages) { | 1303 | while (nbytes < *nbytesp && req->num_pages < req->max_pages) { |
1318 | unsigned npages; | 1304 | unsigned npages; |
1319 | unsigned long user_addr = fuse_get_user_addr(ii); | 1305 | size_t start; |
1320 | unsigned offset = user_addr & ~PAGE_MASK; | ||
1321 | size_t frag_size = fuse_get_frag_size(ii, *nbytesp - nbytes); | ||
1322 | int ret; | ||
1323 | |||
1324 | unsigned n = req->max_pages - req->num_pages; | 1306 | unsigned n = req->max_pages - req->num_pages; |
1325 | frag_size = min_t(size_t, frag_size, n << PAGE_SHIFT); | 1307 | ssize_t ret = iov_iter_get_pages(ii, |
1326 | 1308 | &req->pages[req->num_pages], | |
1327 | npages = (frag_size + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; | 1309 | n * PAGE_SIZE, &start); |
1328 | npages = clamp(npages, 1U, n); | ||
1329 | |||
1330 | ret = get_user_pages_fast(user_addr, npages, !write, | ||
1331 | &req->pages[req->num_pages]); | ||
1332 | if (ret < 0) | 1310 | if (ret < 0) |
1333 | return ret; | 1311 | return ret; |
1334 | 1312 | ||
1335 | npages = ret; | 1313 | iov_iter_advance(ii, ret); |
1336 | frag_size = min_t(size_t, frag_size, | 1314 | nbytes += ret; |
1337 | (npages << PAGE_SHIFT) - offset); | 1315 | |
1338 | iov_iter_advance(ii, frag_size); | 1316 | ret += start; |
1317 | npages = (ret + PAGE_SIZE - 1) / PAGE_SIZE; | ||
1339 | 1318 | ||
1340 | req->page_descs[req->num_pages].offset = offset; | 1319 | req->page_descs[req->num_pages].offset = start; |
1341 | fuse_page_descs_length_init(req, req->num_pages, npages); | 1320 | fuse_page_descs_length_init(req, req->num_pages, npages); |
1342 | 1321 | ||
1343 | req->num_pages += npages; | 1322 | req->num_pages += npages; |
1344 | req->page_descs[req->num_pages - 1].length -= | 1323 | req->page_descs[req->num_pages - 1].length -= |
1345 | (npages << PAGE_SHIFT) - offset - frag_size; | 1324 | (PAGE_SIZE - ret) & (PAGE_SIZE - 1); |
1346 | |||
1347 | nbytes += frag_size; | ||
1348 | } | 1325 | } |
1349 | 1326 | ||
1350 | if (write) | 1327 | if (write) |
@@ -1359,24 +1336,11 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii, | |||
1359 | 1336 | ||
1360 | static inline int fuse_iter_npages(const struct iov_iter *ii_p) | 1337 | static inline int fuse_iter_npages(const struct iov_iter *ii_p) |
1361 | { | 1338 | { |
1362 | struct iov_iter ii = *ii_p; | 1339 | return iov_iter_npages(ii_p, FUSE_MAX_PAGES_PER_REQ); |
1363 | int npages = 0; | ||
1364 | |||
1365 | while (iov_iter_count(&ii) && npages < FUSE_MAX_PAGES_PER_REQ) { | ||
1366 | unsigned long user_addr = fuse_get_user_addr(&ii); | ||
1367 | unsigned offset = user_addr & ~PAGE_MASK; | ||
1368 | size_t frag_size = iov_iter_single_seg_count(&ii); | ||
1369 | |||
1370 | npages += (frag_size + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
1371 | iov_iter_advance(&ii, frag_size); | ||
1372 | } | ||
1373 | |||
1374 | return min(npages, FUSE_MAX_PAGES_PER_REQ); | ||
1375 | } | 1340 | } |
1376 | 1341 | ||
1377 | ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | 1342 | ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, |
1378 | unsigned long nr_segs, size_t count, loff_t *ppos, | 1343 | loff_t *ppos, int flags) |
1379 | int flags) | ||
1380 | { | 1344 | { |
1381 | int write = flags & FUSE_DIO_WRITE; | 1345 | int write = flags & FUSE_DIO_WRITE; |
1382 | int cuse = flags & FUSE_DIO_CUSE; | 1346 | int cuse = flags & FUSE_DIO_CUSE; |
@@ -1386,18 +1350,16 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | |||
1386 | struct fuse_conn *fc = ff->fc; | 1350 | struct fuse_conn *fc = ff->fc; |
1387 | size_t nmax = write ? fc->max_write : fc->max_read; | 1351 | size_t nmax = write ? fc->max_write : fc->max_read; |
1388 | loff_t pos = *ppos; | 1352 | loff_t pos = *ppos; |
1353 | size_t count = iov_iter_count(iter); | ||
1389 | pgoff_t idx_from = pos >> PAGE_CACHE_SHIFT; | 1354 | pgoff_t idx_from = pos >> PAGE_CACHE_SHIFT; |
1390 | pgoff_t idx_to = (pos + count - 1) >> PAGE_CACHE_SHIFT; | 1355 | pgoff_t idx_to = (pos + count - 1) >> PAGE_CACHE_SHIFT; |
1391 | ssize_t res = 0; | 1356 | ssize_t res = 0; |
1392 | struct fuse_req *req; | 1357 | struct fuse_req *req; |
1393 | struct iov_iter ii; | ||
1394 | |||
1395 | iov_iter_init(&ii, iov, nr_segs, count, 0); | ||
1396 | 1358 | ||
1397 | if (io->async) | 1359 | if (io->async) |
1398 | req = fuse_get_req_for_background(fc, fuse_iter_npages(&ii)); | 1360 | req = fuse_get_req_for_background(fc, fuse_iter_npages(iter)); |
1399 | else | 1361 | else |
1400 | req = fuse_get_req(fc, fuse_iter_npages(&ii)); | 1362 | req = fuse_get_req(fc, fuse_iter_npages(iter)); |
1401 | if (IS_ERR(req)) | 1363 | if (IS_ERR(req)) |
1402 | return PTR_ERR(req); | 1364 | return PTR_ERR(req); |
1403 | 1365 | ||
@@ -1413,7 +1375,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | |||
1413 | size_t nres; | 1375 | size_t nres; |
1414 | fl_owner_t owner = current->files; | 1376 | fl_owner_t owner = current->files; |
1415 | size_t nbytes = min(count, nmax); | 1377 | size_t nbytes = min(count, nmax); |
1416 | int err = fuse_get_user_pages(req, &ii, &nbytes, write); | 1378 | int err = fuse_get_user_pages(req, iter, &nbytes, write); |
1417 | if (err) { | 1379 | if (err) { |
1418 | res = err; | 1380 | res = err; |
1419 | break; | 1381 | break; |
@@ -1443,9 +1405,9 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | |||
1443 | fuse_put_request(fc, req); | 1405 | fuse_put_request(fc, req); |
1444 | if (io->async) | 1406 | if (io->async) |
1445 | req = fuse_get_req_for_background(fc, | 1407 | req = fuse_get_req_for_background(fc, |
1446 | fuse_iter_npages(&ii)); | 1408 | fuse_iter_npages(iter)); |
1447 | else | 1409 | else |
1448 | req = fuse_get_req(fc, fuse_iter_npages(&ii)); | 1410 | req = fuse_get_req(fc, fuse_iter_npages(iter)); |
1449 | if (IS_ERR(req)) | 1411 | if (IS_ERR(req)) |
1450 | break; | 1412 | break; |
1451 | } | 1413 | } |
@@ -1460,9 +1422,8 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | |||
1460 | EXPORT_SYMBOL_GPL(fuse_direct_io); | 1422 | EXPORT_SYMBOL_GPL(fuse_direct_io); |
1461 | 1423 | ||
1462 | static ssize_t __fuse_direct_read(struct fuse_io_priv *io, | 1424 | static ssize_t __fuse_direct_read(struct fuse_io_priv *io, |
1463 | const struct iovec *iov, | 1425 | struct iov_iter *iter, |
1464 | unsigned long nr_segs, loff_t *ppos, | 1426 | loff_t *ppos) |
1465 | size_t count) | ||
1466 | { | 1427 | { |
1467 | ssize_t res; | 1428 | ssize_t res; |
1468 | struct file *file = io->file; | 1429 | struct file *file = io->file; |
@@ -1471,7 +1432,7 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io, | |||
1471 | if (is_bad_inode(inode)) | 1432 | if (is_bad_inode(inode)) |
1472 | return -EIO; | 1433 | return -EIO; |
1473 | 1434 | ||
1474 | res = fuse_direct_io(io, iov, nr_segs, count, ppos, 0); | 1435 | res = fuse_direct_io(io, iter, ppos, 0); |
1475 | 1436 | ||
1476 | fuse_invalidate_attr(inode); | 1437 | fuse_invalidate_attr(inode); |
1477 | 1438 | ||
@@ -1483,22 +1444,26 @@ static ssize_t fuse_direct_read(struct file *file, char __user *buf, | |||
1483 | { | 1444 | { |
1484 | struct fuse_io_priv io = { .async = 0, .file = file }; | 1445 | struct fuse_io_priv io = { .async = 0, .file = file }; |
1485 | struct iovec iov = { .iov_base = buf, .iov_len = count }; | 1446 | struct iovec iov = { .iov_base = buf, .iov_len = count }; |
1486 | return __fuse_direct_read(&io, &iov, 1, ppos, count); | 1447 | struct iov_iter ii; |
1448 | iov_iter_init(&ii, READ, &iov, 1, count); | ||
1449 | return __fuse_direct_read(&io, &ii, ppos); | ||
1487 | } | 1450 | } |
1488 | 1451 | ||
1489 | static ssize_t __fuse_direct_write(struct fuse_io_priv *io, | 1452 | static ssize_t __fuse_direct_write(struct fuse_io_priv *io, |
1490 | const struct iovec *iov, | 1453 | struct iov_iter *iter, |
1491 | unsigned long nr_segs, loff_t *ppos) | 1454 | loff_t *ppos) |
1492 | { | 1455 | { |
1493 | struct file *file = io->file; | 1456 | struct file *file = io->file; |
1494 | struct inode *inode = file_inode(file); | 1457 | struct inode *inode = file_inode(file); |
1495 | size_t count = iov_length(iov, nr_segs); | 1458 | size_t count = iov_iter_count(iter); |
1496 | ssize_t res; | 1459 | ssize_t res; |
1497 | 1460 | ||
1461 | |||
1498 | res = generic_write_checks(file, ppos, &count, 0); | 1462 | res = generic_write_checks(file, ppos, &count, 0); |
1499 | if (!res) | 1463 | if (!res) { |
1500 | res = fuse_direct_io(io, iov, nr_segs, count, ppos, | 1464 | iov_iter_truncate(iter, count); |
1501 | FUSE_DIO_WRITE); | 1465 | res = fuse_direct_io(io, iter, ppos, FUSE_DIO_WRITE); |
1466 | } | ||
1502 | 1467 | ||
1503 | fuse_invalidate_attr(inode); | 1468 | fuse_invalidate_attr(inode); |
1504 | 1469 | ||
@@ -1512,13 +1477,15 @@ static ssize_t fuse_direct_write(struct file *file, const char __user *buf, | |||
1512 | struct inode *inode = file_inode(file); | 1477 | struct inode *inode = file_inode(file); |
1513 | ssize_t res; | 1478 | ssize_t res; |
1514 | struct fuse_io_priv io = { .async = 0, .file = file }; | 1479 | struct fuse_io_priv io = { .async = 0, .file = file }; |
1480 | struct iov_iter ii; | ||
1481 | iov_iter_init(&ii, WRITE, &iov, 1, count); | ||
1515 | 1482 | ||
1516 | if (is_bad_inode(inode)) | 1483 | if (is_bad_inode(inode)) |
1517 | return -EIO; | 1484 | return -EIO; |
1518 | 1485 | ||
1519 | /* Don't allow parallel writes to the same file */ | 1486 | /* Don't allow parallel writes to the same file */ |
1520 | mutex_lock(&inode->i_mutex); | 1487 | mutex_lock(&inode->i_mutex); |
1521 | res = __fuse_direct_write(&io, &iov, 1, ppos); | 1488 | res = __fuse_direct_write(&io, &ii, ppos); |
1522 | if (res > 0) | 1489 | if (res > 0) |
1523 | fuse_write_update_size(inode, *ppos); | 1490 | fuse_write_update_size(inode, *ppos); |
1524 | mutex_unlock(&inode->i_mutex); | 1491 | mutex_unlock(&inode->i_mutex); |
@@ -2372,7 +2339,7 @@ static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov, | |||
2372 | if (!bytes) | 2339 | if (!bytes) |
2373 | return 0; | 2340 | return 0; |
2374 | 2341 | ||
2375 | iov_iter_init(&ii, iov, nr_segs, bytes, 0); | 2342 | iov_iter_init(&ii, to_user ? READ : WRITE, iov, nr_segs, bytes); |
2376 | 2343 | ||
2377 | while (iov_iter_count(&ii)) { | 2344 | while (iov_iter_count(&ii)) { |
2378 | struct page *page = pages[page_idx++]; | 2345 | struct page *page = pages[page_idx++]; |
@@ -2894,8 +2861,8 @@ static inline loff_t fuse_round_up(loff_t off) | |||
2894 | } | 2861 | } |
2895 | 2862 | ||
2896 | static ssize_t | 2863 | static ssize_t |
2897 | fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 2864 | fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, |
2898 | loff_t offset, unsigned long nr_segs) | 2865 | loff_t offset) |
2899 | { | 2866 | { |
2900 | ssize_t ret = 0; | 2867 | ssize_t ret = 0; |
2901 | struct file *file = iocb->ki_filp; | 2868 | struct file *file = iocb->ki_filp; |
@@ -2904,7 +2871,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
2904 | loff_t pos = 0; | 2871 | loff_t pos = 0; |
2905 | struct inode *inode; | 2872 | struct inode *inode; |
2906 | loff_t i_size; | 2873 | loff_t i_size; |
2907 | size_t count = iov_length(iov, nr_segs); | 2874 | size_t count = iov_iter_count(iter); |
2908 | struct fuse_io_priv *io; | 2875 | struct fuse_io_priv *io; |
2909 | 2876 | ||
2910 | pos = offset; | 2877 | pos = offset; |
@@ -2919,6 +2886,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
2919 | if (offset >= i_size) | 2886 | if (offset >= i_size) |
2920 | return 0; | 2887 | return 0; |
2921 | count = min_t(loff_t, count, fuse_round_up(i_size - offset)); | 2888 | count = min_t(loff_t, count, fuse_round_up(i_size - offset)); |
2889 | iov_iter_truncate(iter, count); | ||
2922 | } | 2890 | } |
2923 | 2891 | ||
2924 | io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); | 2892 | io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); |
@@ -2948,9 +2916,9 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
2948 | io->async = false; | 2916 | io->async = false; |
2949 | 2917 | ||
2950 | if (rw == WRITE) | 2918 | if (rw == WRITE) |
2951 | ret = __fuse_direct_write(io, iov, nr_segs, &pos); | 2919 | ret = __fuse_direct_write(io, iter, &pos); |
2952 | else | 2920 | else |
2953 | ret = __fuse_direct_read(io, iov, nr_segs, &pos, count); | 2921 | ret = __fuse_direct_read(io, iter, &pos); |
2954 | 2922 | ||
2955 | if (io->async) { | 2923 | if (io->async) { |
2956 | fuse_aio_complete(io, ret < 0 ? ret : 0, -1); | 2924 | fuse_aio_complete(io, ret < 0 ? ret : 0, -1); |
@@ -3061,10 +3029,10 @@ out: | |||
3061 | 3029 | ||
3062 | static const struct file_operations fuse_file_operations = { | 3030 | static const struct file_operations fuse_file_operations = { |
3063 | .llseek = fuse_file_llseek, | 3031 | .llseek = fuse_file_llseek, |
3064 | .read = do_sync_read, | 3032 | .read = new_sync_read, |
3065 | .aio_read = fuse_file_aio_read, | 3033 | .read_iter = fuse_file_read_iter, |
3066 | .write = do_sync_write, | 3034 | .write = new_sync_write, |
3067 | .aio_write = fuse_file_aio_write, | 3035 | .write_iter = fuse_file_write_iter, |
3068 | .mmap = fuse_file_mmap, | 3036 | .mmap = fuse_file_mmap, |
3069 | .open = fuse_open, | 3037 | .open = fuse_open, |
3070 | .flush = fuse_flush, | 3038 | .flush = fuse_flush, |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 7aa5c75e0de1..e8e47a6ab518 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -880,9 +880,8 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, | |||
880 | /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ | 880 | /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ |
881 | #define FUSE_DIO_CUSE (1 << 1) | 881 | #define FUSE_DIO_CUSE (1 << 1) |
882 | 882 | ||
883 | ssize_t fuse_direct_io(struct fuse_io_priv *io, const struct iovec *iov, | 883 | ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, |
884 | unsigned long nr_segs, size_t count, loff_t *ppos, | 884 | loff_t *ppos, int flags); |
885 | int flags); | ||
886 | long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, | 885 | long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, |
887 | unsigned int flags); | 886 | unsigned int flags); |
888 | long fuse_ioctl_common(struct file *file, unsigned int cmd, | 887 | long fuse_ioctl_common(struct file *file, unsigned int cmd, |
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 492123cda64a..805b37fed638 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c | |||
@@ -1040,8 +1040,7 @@ static int gfs2_ok_for_dio(struct gfs2_inode *ip, int rw, loff_t offset) | |||
1040 | 1040 | ||
1041 | 1041 | ||
1042 | static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, | 1042 | static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, |
1043 | const struct iovec *iov, loff_t offset, | 1043 | struct iov_iter *iter, loff_t offset) |
1044 | unsigned long nr_segs) | ||
1045 | { | 1044 | { |
1046 | struct file *file = iocb->ki_filp; | 1045 | struct file *file = iocb->ki_filp; |
1047 | struct inode *inode = file->f_mapping->host; | 1046 | struct inode *inode = file->f_mapping->host; |
@@ -1081,7 +1080,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, | |||
1081 | */ | 1080 | */ |
1082 | if (mapping->nrpages) { | 1081 | if (mapping->nrpages) { |
1083 | loff_t lstart = offset & (PAGE_CACHE_SIZE - 1); | 1082 | loff_t lstart = offset & (PAGE_CACHE_SIZE - 1); |
1084 | loff_t len = iov_length(iov, nr_segs); | 1083 | loff_t len = iov_iter_count(iter); |
1085 | loff_t end = PAGE_ALIGN(offset + len) - 1; | 1084 | loff_t end = PAGE_ALIGN(offset + len) - 1; |
1086 | 1085 | ||
1087 | rv = 0; | 1086 | rv = 0; |
@@ -1096,9 +1095,9 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, | |||
1096 | truncate_inode_pages_range(mapping, lstart, end); | 1095 | truncate_inode_pages_range(mapping, lstart, end); |
1097 | } | 1096 | } |
1098 | 1097 | ||
1099 | rv = __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 1098 | rv = __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, |
1100 | offset, nr_segs, gfs2_get_block_direct, | 1099 | iter, offset, |
1101 | NULL, NULL, 0); | 1100 | gfs2_get_block_direct, NULL, NULL, 0); |
1102 | out: | 1101 | out: |
1103 | gfs2_glock_dq(&gh); | 1102 | gfs2_glock_dq(&gh); |
1104 | gfs2_holder_uninit(&gh); | 1103 | gfs2_holder_uninit(&gh); |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 6ab0cfb2e891..4fc3a3046174 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -684,7 +684,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, | |||
684 | } | 684 | } |
685 | 685 | ||
686 | /** | 686 | /** |
687 | * gfs2_file_aio_write - Perform a write to a file | 687 | * gfs2_file_write_iter - Perform a write to a file |
688 | * @iocb: The io context | 688 | * @iocb: The io context |
689 | * @iov: The data to write | 689 | * @iov: The data to write |
690 | * @nr_segs: Number of @iov segments | 690 | * @nr_segs: Number of @iov segments |
@@ -697,11 +697,9 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, | |||
697 | * | 697 | * |
698 | */ | 698 | */ |
699 | 699 | ||
700 | static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 700 | static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
701 | unsigned long nr_segs, loff_t pos) | ||
702 | { | 701 | { |
703 | struct file *file = iocb->ki_filp; | 702 | struct file *file = iocb->ki_filp; |
704 | size_t writesize = iov_length(iov, nr_segs); | ||
705 | struct gfs2_inode *ip = GFS2_I(file_inode(file)); | 703 | struct gfs2_inode *ip = GFS2_I(file_inode(file)); |
706 | int ret; | 704 | int ret; |
707 | 705 | ||
@@ -709,7 +707,7 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
709 | if (ret) | 707 | if (ret) |
710 | return ret; | 708 | return ret; |
711 | 709 | ||
712 | gfs2_size_hint(file, pos, writesize); | 710 | gfs2_size_hint(file, iocb->ki_pos, iov_iter_count(from)); |
713 | 711 | ||
714 | if (file->f_flags & O_APPEND) { | 712 | if (file->f_flags & O_APPEND) { |
715 | struct gfs2_holder gh; | 713 | struct gfs2_holder gh; |
@@ -720,7 +718,7 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
720 | gfs2_glock_dq_uninit(&gh); | 718 | gfs2_glock_dq_uninit(&gh); |
721 | } | 719 | } |
722 | 720 | ||
723 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | 721 | return generic_file_write_iter(iocb, from); |
724 | } | 722 | } |
725 | 723 | ||
726 | static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, | 724 | static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, |
@@ -1058,10 +1056,10 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) | |||
1058 | 1056 | ||
1059 | const struct file_operations gfs2_file_fops = { | 1057 | const struct file_operations gfs2_file_fops = { |
1060 | .llseek = gfs2_llseek, | 1058 | .llseek = gfs2_llseek, |
1061 | .read = do_sync_read, | 1059 | .read = new_sync_read, |
1062 | .aio_read = generic_file_aio_read, | 1060 | .read_iter = generic_file_read_iter, |
1063 | .write = do_sync_write, | 1061 | .write = new_sync_write, |
1064 | .aio_write = gfs2_file_aio_write, | 1062 | .write_iter = gfs2_file_write_iter, |
1065 | .unlocked_ioctl = gfs2_ioctl, | 1063 | .unlocked_ioctl = gfs2_ioctl, |
1066 | .mmap = gfs2_mmap, | 1064 | .mmap = gfs2_mmap, |
1067 | .open = gfs2_open, | 1065 | .open = gfs2_open, |
@@ -1070,7 +1068,7 @@ const struct file_operations gfs2_file_fops = { | |||
1070 | .lock = gfs2_lock, | 1068 | .lock = gfs2_lock, |
1071 | .flock = gfs2_flock, | 1069 | .flock = gfs2_flock, |
1072 | .splice_read = generic_file_splice_read, | 1070 | .splice_read = generic_file_splice_read, |
1073 | .splice_write = generic_file_splice_write, | 1071 | .splice_write = iter_file_splice_write, |
1074 | .setlease = gfs2_setlease, | 1072 | .setlease = gfs2_setlease, |
1075 | .fallocate = gfs2_fallocate, | 1073 | .fallocate = gfs2_fallocate, |
1076 | }; | 1074 | }; |
@@ -1090,17 +1088,17 @@ const struct file_operations gfs2_dir_fops = { | |||
1090 | 1088 | ||
1091 | const struct file_operations gfs2_file_fops_nolock = { | 1089 | const struct file_operations gfs2_file_fops_nolock = { |
1092 | .llseek = gfs2_llseek, | 1090 | .llseek = gfs2_llseek, |
1093 | .read = do_sync_read, | 1091 | .read = new_sync_read, |
1094 | .aio_read = generic_file_aio_read, | 1092 | .read_iter = generic_file_read_iter, |
1095 | .write = do_sync_write, | 1093 | .write = new_sync_write, |
1096 | .aio_write = gfs2_file_aio_write, | 1094 | .write_iter = gfs2_file_write_iter, |
1097 | .unlocked_ioctl = gfs2_ioctl, | 1095 | .unlocked_ioctl = gfs2_ioctl, |
1098 | .mmap = gfs2_mmap, | 1096 | .mmap = gfs2_mmap, |
1099 | .open = gfs2_open, | 1097 | .open = gfs2_open, |
1100 | .release = gfs2_release, | 1098 | .release = gfs2_release, |
1101 | .fsync = gfs2_fsync, | 1099 | .fsync = gfs2_fsync, |
1102 | .splice_read = generic_file_splice_read, | 1100 | .splice_read = generic_file_splice_read, |
1103 | .splice_write = generic_file_splice_write, | 1101 | .splice_write = iter_file_splice_write, |
1104 | .setlease = generic_setlease, | 1102 | .setlease = generic_setlease, |
1105 | .fallocate = gfs2_fallocate, | 1103 | .fallocate = gfs2_fallocate, |
1106 | }; | 1104 | }; |
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 9e2fecd62f62..d0929bc81782 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c | |||
@@ -125,15 +125,15 @@ static int hfs_releasepage(struct page *page, gfp_t mask) | |||
125 | } | 125 | } |
126 | 126 | ||
127 | static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb, | 127 | static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb, |
128 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 128 | struct iov_iter *iter, loff_t offset) |
129 | { | 129 | { |
130 | struct file *file = iocb->ki_filp; | 130 | struct file *file = iocb->ki_filp; |
131 | struct address_space *mapping = file->f_mapping; | 131 | struct address_space *mapping = file->f_mapping; |
132 | struct inode *inode = file_inode(file)->i_mapping->host; | 132 | struct inode *inode = file_inode(file)->i_mapping->host; |
133 | size_t count = iov_iter_count(iter); | ||
133 | ssize_t ret; | 134 | ssize_t ret; |
134 | 135 | ||
135 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 136 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, hfs_get_block); |
136 | hfs_get_block); | ||
137 | 137 | ||
138 | /* | 138 | /* |
139 | * In case of error extending write may have instantiated a few | 139 | * In case of error extending write may have instantiated a few |
@@ -141,7 +141,7 @@ static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb, | |||
141 | */ | 141 | */ |
142 | if (unlikely((rw & WRITE) && ret < 0)) { | 142 | if (unlikely((rw & WRITE) && ret < 0)) { |
143 | loff_t isize = i_size_read(inode); | 143 | loff_t isize = i_size_read(inode); |
144 | loff_t end = offset + iov_length(iov, nr_segs); | 144 | loff_t end = offset + count; |
145 | 145 | ||
146 | if (end > isize) | 146 | if (end > isize) |
147 | hfs_write_failed(mapping, end); | 147 | hfs_write_failed(mapping, end); |
@@ -674,10 +674,10 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, | |||
674 | 674 | ||
675 | static const struct file_operations hfs_file_operations = { | 675 | static const struct file_operations hfs_file_operations = { |
676 | .llseek = generic_file_llseek, | 676 | .llseek = generic_file_llseek, |
677 | .read = do_sync_read, | 677 | .read = new_sync_read, |
678 | .aio_read = generic_file_aio_read, | 678 | .read_iter = generic_file_read_iter, |
679 | .write = do_sync_write, | 679 | .write = new_sync_write, |
680 | .aio_write = generic_file_aio_write, | 680 | .write_iter = generic_file_write_iter, |
681 | .mmap = generic_file_mmap, | 681 | .mmap = generic_file_mmap, |
682 | .splice_read = generic_file_splice_read, | 682 | .splice_read = generic_file_splice_read, |
683 | .fsync = hfs_file_fsync, | 683 | .fsync = hfs_file_fsync, |
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index a4f45bd88a63..0cf786f2d046 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c | |||
@@ -123,14 +123,15 @@ static int hfsplus_releasepage(struct page *page, gfp_t mask) | |||
123 | } | 123 | } |
124 | 124 | ||
125 | static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb, | 125 | static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb, |
126 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 126 | struct iov_iter *iter, loff_t offset) |
127 | { | 127 | { |
128 | struct file *file = iocb->ki_filp; | 128 | struct file *file = iocb->ki_filp; |
129 | struct address_space *mapping = file->f_mapping; | 129 | struct address_space *mapping = file->f_mapping; |
130 | struct inode *inode = file_inode(file)->i_mapping->host; | 130 | struct inode *inode = file_inode(file)->i_mapping->host; |
131 | size_t count = iov_iter_count(iter); | ||
131 | ssize_t ret; | 132 | ssize_t ret; |
132 | 133 | ||
133 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 134 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, |
134 | hfsplus_get_block); | 135 | hfsplus_get_block); |
135 | 136 | ||
136 | /* | 137 | /* |
@@ -139,7 +140,7 @@ static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb, | |||
139 | */ | 140 | */ |
140 | if (unlikely((rw & WRITE) && ret < 0)) { | 141 | if (unlikely((rw & WRITE) && ret < 0)) { |
141 | loff_t isize = i_size_read(inode); | 142 | loff_t isize = i_size_read(inode); |
142 | loff_t end = offset + iov_length(iov, nr_segs); | 143 | loff_t end = offset + count; |
143 | 144 | ||
144 | if (end > isize) | 145 | if (end > isize) |
145 | hfsplus_write_failed(mapping, end); | 146 | hfsplus_write_failed(mapping, end); |
@@ -340,10 +341,10 @@ static const struct inode_operations hfsplus_file_inode_operations = { | |||
340 | 341 | ||
341 | static const struct file_operations hfsplus_file_operations = { | 342 | static const struct file_operations hfsplus_file_operations = { |
342 | .llseek = generic_file_llseek, | 343 | .llseek = generic_file_llseek, |
343 | .read = do_sync_read, | 344 | .read = new_sync_read, |
344 | .aio_read = generic_file_aio_read, | 345 | .read_iter = generic_file_read_iter, |
345 | .write = do_sync_write, | 346 | .write = new_sync_write, |
346 | .aio_write = generic_file_aio_write, | 347 | .write_iter = generic_file_write_iter, |
347 | .mmap = generic_file_mmap, | 348 | .mmap = generic_file_mmap, |
348 | .splice_read = generic_file_splice_read, | 349 | .splice_read = generic_file_splice_read, |
349 | .fsync = hfsplus_file_fsync, | 350 | .fsync = hfsplus_file_fsync, |
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 9c470fde9878..bb529f3b7f2b 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c | |||
@@ -378,11 +378,11 @@ static int hostfs_fsync(struct file *file, loff_t start, loff_t end, | |||
378 | 378 | ||
379 | static const struct file_operations hostfs_file_fops = { | 379 | static const struct file_operations hostfs_file_fops = { |
380 | .llseek = generic_file_llseek, | 380 | .llseek = generic_file_llseek, |
381 | .read = do_sync_read, | 381 | .read = new_sync_read, |
382 | .splice_read = generic_file_splice_read, | 382 | .splice_read = generic_file_splice_read, |
383 | .aio_read = generic_file_aio_read, | 383 | .read_iter = generic_file_read_iter, |
384 | .aio_write = generic_file_aio_write, | 384 | .write_iter = generic_file_write_iter, |
385 | .write = do_sync_write, | 385 | .write = new_sync_write, |
386 | .mmap = generic_file_mmap, | 386 | .mmap = generic_file_mmap, |
387 | .open = hostfs_file_open, | 387 | .open = hostfs_file_open, |
388 | .release = hostfs_file_release, | 388 | .release = hostfs_file_release, |
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 67c1a61e0955..7f54e5f76cec 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c | |||
@@ -197,10 +197,10 @@ const struct address_space_operations hpfs_aops = { | |||
197 | const struct file_operations hpfs_file_ops = | 197 | const struct file_operations hpfs_file_ops = |
198 | { | 198 | { |
199 | .llseek = generic_file_llseek, | 199 | .llseek = generic_file_llseek, |
200 | .read = do_sync_read, | 200 | .read = new_sync_read, |
201 | .aio_read = generic_file_aio_read, | 201 | .read_iter = generic_file_read_iter, |
202 | .write = do_sync_write, | 202 | .write = new_sync_write, |
203 | .aio_write = generic_file_aio_write, | 203 | .write_iter = generic_file_write_iter, |
204 | .mmap = generic_file_mmap, | 204 | .mmap = generic_file_mmap, |
205 | .release = hpfs_file_release, | 205 | .release = hpfs_file_release, |
206 | .fsync = hpfs_file_fsync, | 206 | .fsync = hpfs_file_fsync, |
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index 256cd19a3b78..64989ca9ba90 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c | |||
@@ -51,10 +51,10 @@ const struct file_operations jffs2_file_operations = | |||
51 | { | 51 | { |
52 | .llseek = generic_file_llseek, | 52 | .llseek = generic_file_llseek, |
53 | .open = generic_file_open, | 53 | .open = generic_file_open, |
54 | .read = do_sync_read, | 54 | .read = new_sync_read, |
55 | .aio_read = generic_file_aio_read, | 55 | .read_iter = generic_file_read_iter, |
56 | .write = do_sync_write, | 56 | .write = new_sync_write, |
57 | .aio_write = generic_file_aio_write, | 57 | .write_iter = generic_file_write_iter, |
58 | .unlocked_ioctl=jffs2_ioctl, | 58 | .unlocked_ioctl=jffs2_ioctl, |
59 | .mmap = generic_file_readonly_mmap, | 59 | .mmap = generic_file_readonly_mmap, |
60 | .fsync = jffs2_fsync, | 60 | .fsync = jffs2_fsync, |
diff --git a/fs/jfs/file.c b/fs/jfs/file.c index 794da944d5cd..33aa0cc1f8b8 100644 --- a/fs/jfs/file.c +++ b/fs/jfs/file.c | |||
@@ -151,13 +151,13 @@ const struct inode_operations jfs_file_inode_operations = { | |||
151 | const struct file_operations jfs_file_operations = { | 151 | const struct file_operations jfs_file_operations = { |
152 | .open = jfs_open, | 152 | .open = jfs_open, |
153 | .llseek = generic_file_llseek, | 153 | .llseek = generic_file_llseek, |
154 | .write = do_sync_write, | 154 | .write = new_sync_write, |
155 | .read = do_sync_read, | 155 | .read = new_sync_read, |
156 | .aio_read = generic_file_aio_read, | 156 | .read_iter = generic_file_read_iter, |
157 | .aio_write = generic_file_aio_write, | 157 | .write_iter = generic_file_write_iter, |
158 | .mmap = generic_file_mmap, | 158 | .mmap = generic_file_mmap, |
159 | .splice_read = generic_file_splice_read, | 159 | .splice_read = generic_file_splice_read, |
160 | .splice_write = generic_file_splice_write, | 160 | .splice_write = iter_file_splice_write, |
161 | .fsync = jfs_fsync, | 161 | .fsync = jfs_fsync, |
162 | .release = jfs_release, | 162 | .release = jfs_release, |
163 | .unlocked_ioctl = jfs_ioctl, | 163 | .unlocked_ioctl = jfs_ioctl, |
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c index 6f8fe72c2a7a..bd3df1ca3c9b 100644 --- a/fs/jfs/inode.c +++ b/fs/jfs/inode.c | |||
@@ -331,15 +331,15 @@ static sector_t jfs_bmap(struct address_space *mapping, sector_t block) | |||
331 | } | 331 | } |
332 | 332 | ||
333 | static ssize_t jfs_direct_IO(int rw, struct kiocb *iocb, | 333 | static ssize_t jfs_direct_IO(int rw, struct kiocb *iocb, |
334 | const struct iovec *iov, loff_t offset, unsigned long nr_segs) | 334 | struct iov_iter *iter, loff_t offset) |
335 | { | 335 | { |
336 | struct file *file = iocb->ki_filp; | 336 | struct file *file = iocb->ki_filp; |
337 | struct address_space *mapping = file->f_mapping; | 337 | struct address_space *mapping = file->f_mapping; |
338 | struct inode *inode = file->f_mapping->host; | 338 | struct inode *inode = file->f_mapping->host; |
339 | size_t count = iov_iter_count(iter); | ||
339 | ssize_t ret; | 340 | ssize_t ret; |
340 | 341 | ||
341 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 342 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, jfs_get_block); |
342 | jfs_get_block); | ||
343 | 343 | ||
344 | /* | 344 | /* |
345 | * In case of error extending write may have instantiated a few | 345 | * In case of error extending write may have instantiated a few |
@@ -347,7 +347,7 @@ static ssize_t jfs_direct_IO(int rw, struct kiocb *iocb, | |||
347 | */ | 347 | */ |
348 | if (unlikely((rw & WRITE) && ret < 0)) { | 348 | if (unlikely((rw & WRITE) && ret < 0)) { |
349 | loff_t isize = i_size_read(inode); | 349 | loff_t isize = i_size_read(inode); |
350 | loff_t end = offset + iov_length(iov, nr_segs); | 350 | loff_t end = offset + count; |
351 | 351 | ||
352 | if (end > isize) | 352 | if (end > isize) |
353 | jfs_write_failed(mapping, end); | 353 | jfs_write_failed(mapping, end); |
diff --git a/fs/logfs/file.c b/fs/logfs/file.c index 57914fc32b62..8538752df2f6 100644 --- a/fs/logfs/file.c +++ b/fs/logfs/file.c | |||
@@ -264,15 +264,15 @@ const struct inode_operations logfs_reg_iops = { | |||
264 | }; | 264 | }; |
265 | 265 | ||
266 | const struct file_operations logfs_reg_fops = { | 266 | const struct file_operations logfs_reg_fops = { |
267 | .aio_read = generic_file_aio_read, | 267 | .read_iter = generic_file_read_iter, |
268 | .aio_write = generic_file_aio_write, | 268 | .write_iter = generic_file_write_iter, |
269 | .fsync = logfs_fsync, | 269 | .fsync = logfs_fsync, |
270 | .unlocked_ioctl = logfs_ioctl, | 270 | .unlocked_ioctl = logfs_ioctl, |
271 | .llseek = generic_file_llseek, | 271 | .llseek = generic_file_llseek, |
272 | .mmap = generic_file_readonly_mmap, | 272 | .mmap = generic_file_readonly_mmap, |
273 | .open = generic_file_open, | 273 | .open = generic_file_open, |
274 | .read = do_sync_read, | 274 | .read = new_sync_read, |
275 | .write = do_sync_write, | 275 | .write = new_sync_write, |
276 | }; | 276 | }; |
277 | 277 | ||
278 | const struct address_space_operations logfs_reg_aops = { | 278 | const struct address_space_operations logfs_reg_aops = { |
diff --git a/fs/minix/file.c b/fs/minix/file.c index adc6f5494231..a967de085ac0 100644 --- a/fs/minix/file.c +++ b/fs/minix/file.c | |||
@@ -14,10 +14,10 @@ | |||
14 | */ | 14 | */ |
15 | const struct file_operations minix_file_operations = { | 15 | const struct file_operations minix_file_operations = { |
16 | .llseek = generic_file_llseek, | 16 | .llseek = generic_file_llseek, |
17 | .read = do_sync_read, | 17 | .read = new_sync_read, |
18 | .aio_read = generic_file_aio_read, | 18 | .read_iter = generic_file_read_iter, |
19 | .write = do_sync_write, | 19 | .write = new_sync_write, |
20 | .aio_write = generic_file_aio_write, | 20 | .write_iter = generic_file_write_iter, |
21 | .mmap = generic_file_mmap, | 21 | .mmap = generic_file_mmap, |
22 | .fsync = generic_file_fsync, | 22 | .fsync = generic_file_fsync, |
23 | .splice_read = generic_file_splice_read, | 23 | .splice_read = generic_file_splice_read, |
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 4ad7bc388679..8f98138cbc43 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
@@ -212,20 +212,20 @@ static int nfs_direct_cmp_commit_data_verf(struct nfs_direct_req *dreq, | |||
212 | * shunt off direct read and write requests before the VFS gets them, | 212 | * shunt off direct read and write requests before the VFS gets them, |
213 | * so this method is only ever called for swap. | 213 | * so this method is only ever called for swap. |
214 | */ | 214 | */ |
215 | ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs) | 215 | ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos) |
216 | { | 216 | { |
217 | #ifndef CONFIG_NFS_SWAP | 217 | #ifndef CONFIG_NFS_SWAP |
218 | dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n", | 218 | dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n", |
219 | iocb->ki_filp, (long long) pos, nr_segs); | 219 | iocb->ki_filp, (long long) pos, iter->nr_segs); |
220 | 220 | ||
221 | return -EINVAL; | 221 | return -EINVAL; |
222 | #else | 222 | #else |
223 | VM_BUG_ON(iocb->ki_nbytes != PAGE_SIZE); | 223 | VM_BUG_ON(iocb->ki_nbytes != PAGE_SIZE); |
224 | 224 | ||
225 | if (rw == READ || rw == KERNEL_READ) | 225 | if (rw == READ || rw == KERNEL_READ) |
226 | return nfs_file_direct_read(iocb, iov, nr_segs, pos, | 226 | return nfs_file_direct_read(iocb, iter, pos, |
227 | rw == READ ? true : false); | 227 | rw == READ ? true : false); |
228 | return nfs_file_direct_write(iocb, iov, nr_segs, pos, | 228 | return nfs_file_direct_write(iocb, iter, pos, |
229 | rw == WRITE ? true : false); | 229 | rw == WRITE ? true : false); |
230 | #endif /* CONFIG_NFS_SWAP */ | 230 | #endif /* CONFIG_NFS_SWAP */ |
231 | } | 231 | } |
@@ -414,60 +414,37 @@ static const struct nfs_pgio_completion_ops nfs_direct_read_completion_ops = { | |||
414 | * handled automatically by nfs_direct_read_result(). Otherwise, if | 414 | * handled automatically by nfs_direct_read_result(). Otherwise, if |
415 | * no requests have been sent, just return an error. | 415 | * no requests have been sent, just return an error. |
416 | */ | 416 | */ |
417 | static ssize_t nfs_direct_read_schedule_segment(struct nfs_pageio_descriptor *desc, | ||
418 | const struct iovec *iov, | ||
419 | loff_t pos, bool uio) | ||
420 | { | ||
421 | struct nfs_direct_req *dreq = desc->pg_dreq; | ||
422 | struct nfs_open_context *ctx = dreq->ctx; | ||
423 | struct inode *inode = ctx->dentry->d_inode; | ||
424 | unsigned long user_addr = (unsigned long)iov->iov_base; | ||
425 | size_t count = iov->iov_len; | ||
426 | size_t rsize = NFS_SERVER(inode)->rsize; | ||
427 | unsigned int pgbase; | ||
428 | int result; | ||
429 | ssize_t started = 0; | ||
430 | struct page **pagevec = NULL; | ||
431 | unsigned int npages; | ||
432 | |||
433 | do { | ||
434 | size_t bytes; | ||
435 | int i; | ||
436 | 417 | ||
437 | pgbase = user_addr & ~PAGE_MASK; | 418 | static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, |
438 | bytes = min(max_t(size_t, rsize, PAGE_SIZE), count); | 419 | struct iov_iter *iter, |
420 | loff_t pos) | ||
421 | { | ||
422 | struct nfs_pageio_descriptor desc; | ||
423 | struct inode *inode = dreq->inode; | ||
424 | ssize_t result = -EINVAL; | ||
425 | size_t requested_bytes = 0; | ||
426 | size_t rsize = max_t(size_t, NFS_SERVER(inode)->rsize, PAGE_SIZE); | ||
439 | 427 | ||
440 | result = -ENOMEM; | 428 | nfs_pageio_init_read(&desc, dreq->inode, false, |
441 | npages = nfs_page_array_len(pgbase, bytes); | 429 | &nfs_direct_read_completion_ops); |
442 | if (!pagevec) | 430 | get_dreq(dreq); |
443 | pagevec = kmalloc(npages * sizeof(struct page *), | 431 | desc.pg_dreq = dreq; |
444 | GFP_KERNEL); | 432 | atomic_inc(&inode->i_dio_count); |
445 | if (!pagevec) | ||
446 | break; | ||
447 | if (uio) { | ||
448 | down_read(¤t->mm->mmap_sem); | ||
449 | result = get_user_pages(current, current->mm, user_addr, | ||
450 | npages, 1, 0, pagevec, NULL); | ||
451 | up_read(¤t->mm->mmap_sem); | ||
452 | if (result < 0) | ||
453 | break; | ||
454 | } else { | ||
455 | WARN_ON(npages != 1); | ||
456 | result = get_kernel_page(user_addr, 1, pagevec); | ||
457 | if (WARN_ON(result != 1)) | ||
458 | break; | ||
459 | } | ||
460 | 433 | ||
461 | if ((unsigned)result < npages) { | 434 | while (iov_iter_count(iter)) { |
462 | bytes = result * PAGE_SIZE; | 435 | struct page **pagevec; |
463 | if (bytes <= pgbase) { | 436 | size_t bytes; |
464 | nfs_direct_release_pages(pagevec, result); | 437 | size_t pgbase; |
465 | break; | 438 | unsigned npages, i; |
466 | } | ||
467 | bytes -= pgbase; | ||
468 | npages = result; | ||
469 | } | ||
470 | 439 | ||
440 | result = iov_iter_get_pages_alloc(iter, &pagevec, | ||
441 | rsize, &pgbase); | ||
442 | if (result < 0) | ||
443 | break; | ||
444 | |||
445 | bytes = result; | ||
446 | iov_iter_advance(iter, bytes); | ||
447 | npages = (result + pgbase + PAGE_SIZE - 1) / PAGE_SIZE; | ||
471 | for (i = 0; i < npages; i++) { | 448 | for (i = 0; i < npages; i++) { |
472 | struct nfs_page *req; | 449 | struct nfs_page *req; |
473 | unsigned int req_len = min_t(size_t, bytes, PAGE_SIZE - pgbase); | 450 | unsigned int req_len = min_t(size_t, bytes, PAGE_SIZE - pgbase); |
@@ -480,56 +457,21 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_pageio_descriptor *de | |||
480 | } | 457 | } |
481 | req->wb_index = pos >> PAGE_SHIFT; | 458 | req->wb_index = pos >> PAGE_SHIFT; |
482 | req->wb_offset = pos & ~PAGE_MASK; | 459 | req->wb_offset = pos & ~PAGE_MASK; |
483 | if (!nfs_pageio_add_request(desc, req)) { | 460 | if (!nfs_pageio_add_request(&desc, req)) { |
484 | result = desc->pg_error; | 461 | result = desc.pg_error; |
485 | nfs_release_request(req); | 462 | nfs_release_request(req); |
486 | break; | 463 | break; |
487 | } | 464 | } |
488 | pgbase = 0; | 465 | pgbase = 0; |
489 | bytes -= req_len; | 466 | bytes -= req_len; |
490 | started += req_len; | 467 | requested_bytes += req_len; |
491 | user_addr += req_len; | ||
492 | pos += req_len; | 468 | pos += req_len; |
493 | count -= req_len; | ||
494 | dreq->bytes_left -= req_len; | 469 | dreq->bytes_left -= req_len; |
495 | } | 470 | } |
496 | /* The nfs_page now hold references to these pages */ | ||
497 | nfs_direct_release_pages(pagevec, npages); | 471 | nfs_direct_release_pages(pagevec, npages); |
498 | } while (count != 0 && result >= 0); | 472 | kvfree(pagevec); |
499 | |||
500 | kfree(pagevec); | ||
501 | |||
502 | if (started) | ||
503 | return started; | ||
504 | return result < 0 ? (ssize_t) result : -EFAULT; | ||
505 | } | ||
506 | |||
507 | static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | ||
508 | const struct iovec *iov, | ||
509 | unsigned long nr_segs, | ||
510 | loff_t pos, bool uio) | ||
511 | { | ||
512 | struct nfs_pageio_descriptor desc; | ||
513 | struct inode *inode = dreq->inode; | ||
514 | ssize_t result = -EINVAL; | ||
515 | size_t requested_bytes = 0; | ||
516 | unsigned long seg; | ||
517 | |||
518 | nfs_pageio_init_read(&desc, dreq->inode, false, | ||
519 | &nfs_direct_read_completion_ops); | ||
520 | get_dreq(dreq); | ||
521 | desc.pg_dreq = dreq; | ||
522 | atomic_inc(&inode->i_dio_count); | ||
523 | |||
524 | for (seg = 0; seg < nr_segs; seg++) { | ||
525 | const struct iovec *vec = &iov[seg]; | ||
526 | result = nfs_direct_read_schedule_segment(&desc, vec, pos, uio); | ||
527 | if (result < 0) | 473 | if (result < 0) |
528 | break; | 474 | break; |
529 | requested_bytes += result; | ||
530 | if ((size_t)result < vec->iov_len) | ||
531 | break; | ||
532 | pos += vec->iov_len; | ||
533 | } | 475 | } |
534 | 476 | ||
535 | nfs_pageio_complete(&desc); | 477 | nfs_pageio_complete(&desc); |
@@ -552,8 +494,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | |||
552 | /** | 494 | /** |
553 | * nfs_file_direct_read - file direct read operation for NFS files | 495 | * nfs_file_direct_read - file direct read operation for NFS files |
554 | * @iocb: target I/O control block | 496 | * @iocb: target I/O control block |
555 | * @iov: vector of user buffers into which to read data | 497 | * @iter: vector of user buffers into which to read data |
556 | * @nr_segs: size of iov vector | ||
557 | * @pos: byte offset in file where reading starts | 498 | * @pos: byte offset in file where reading starts |
558 | * | 499 | * |
559 | * We use this function for direct reads instead of calling | 500 | * We use this function for direct reads instead of calling |
@@ -570,8 +511,8 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | |||
570 | * client must read the updated atime from the server back into its | 511 | * client must read the updated atime from the server back into its |
571 | * cache. | 512 | * cache. |
572 | */ | 513 | */ |
573 | ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | 514 | ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter, |
574 | unsigned long nr_segs, loff_t pos, bool uio) | 515 | loff_t pos, bool uio) |
575 | { | 516 | { |
576 | struct file *file = iocb->ki_filp; | 517 | struct file *file = iocb->ki_filp; |
577 | struct address_space *mapping = file->f_mapping; | 518 | struct address_space *mapping = file->f_mapping; |
@@ -579,9 +520,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
579 | struct nfs_direct_req *dreq; | 520 | struct nfs_direct_req *dreq; |
580 | struct nfs_lock_context *l_ctx; | 521 | struct nfs_lock_context *l_ctx; |
581 | ssize_t result = -EINVAL; | 522 | ssize_t result = -EINVAL; |
582 | size_t count; | 523 | size_t count = iov_iter_count(iter); |
583 | |||
584 | count = iov_length(iov, nr_segs); | ||
585 | nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count); | 524 | nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count); |
586 | 525 | ||
587 | dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n", | 526 | dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n", |
@@ -604,7 +543,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
604 | goto out_unlock; | 543 | goto out_unlock; |
605 | 544 | ||
606 | dreq->inode = inode; | 545 | dreq->inode = inode; |
607 | dreq->bytes_left = iov_length(iov, nr_segs); | 546 | dreq->bytes_left = count; |
608 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); | 547 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); |
609 | l_ctx = nfs_get_lock_context(dreq->ctx); | 548 | l_ctx = nfs_get_lock_context(dreq->ctx); |
610 | if (IS_ERR(l_ctx)) { | 549 | if (IS_ERR(l_ctx)) { |
@@ -615,8 +554,8 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
615 | if (!is_sync_kiocb(iocb)) | 554 | if (!is_sync_kiocb(iocb)) |
616 | dreq->iocb = iocb; | 555 | dreq->iocb = iocb; |
617 | 556 | ||
618 | NFS_I(inode)->read_io += iov_length(iov, nr_segs); | 557 | NFS_I(inode)->read_io += count; |
619 | result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos, uio); | 558 | result = nfs_direct_read_schedule_iovec(dreq, iter, pos); |
620 | 559 | ||
621 | mutex_unlock(&inode->i_mutex); | 560 | mutex_unlock(&inode->i_mutex); |
622 | 561 | ||
@@ -772,108 +711,6 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode | |||
772 | } | 711 | } |
773 | #endif | 712 | #endif |
774 | 713 | ||
775 | /* | ||
776 | * NB: Return the value of the first error return code. Subsequent | ||
777 | * errors after the first one are ignored. | ||
778 | */ | ||
779 | /* | ||
780 | * For each wsize'd chunk of the user's buffer, dispatch an NFS WRITE | ||
781 | * operation. If nfs_writedata_alloc() or get_user_pages() fails, | ||
782 | * bail and stop sending more writes. Write length accounting is | ||
783 | * handled automatically by nfs_direct_write_result(). Otherwise, if | ||
784 | * no requests have been sent, just return an error. | ||
785 | */ | ||
786 | static ssize_t nfs_direct_write_schedule_segment(struct nfs_pageio_descriptor *desc, | ||
787 | const struct iovec *iov, | ||
788 | loff_t pos, bool uio) | ||
789 | { | ||
790 | struct nfs_direct_req *dreq = desc->pg_dreq; | ||
791 | struct nfs_open_context *ctx = dreq->ctx; | ||
792 | struct inode *inode = ctx->dentry->d_inode; | ||
793 | unsigned long user_addr = (unsigned long)iov->iov_base; | ||
794 | size_t count = iov->iov_len; | ||
795 | size_t wsize = NFS_SERVER(inode)->wsize; | ||
796 | unsigned int pgbase; | ||
797 | int result; | ||
798 | ssize_t started = 0; | ||
799 | struct page **pagevec = NULL; | ||
800 | unsigned int npages; | ||
801 | |||
802 | do { | ||
803 | size_t bytes; | ||
804 | int i; | ||
805 | |||
806 | pgbase = user_addr & ~PAGE_MASK; | ||
807 | bytes = min(max_t(size_t, wsize, PAGE_SIZE), count); | ||
808 | |||
809 | result = -ENOMEM; | ||
810 | npages = nfs_page_array_len(pgbase, bytes); | ||
811 | if (!pagevec) | ||
812 | pagevec = kmalloc(npages * sizeof(struct page *), GFP_KERNEL); | ||
813 | if (!pagevec) | ||
814 | break; | ||
815 | |||
816 | if (uio) { | ||
817 | down_read(¤t->mm->mmap_sem); | ||
818 | result = get_user_pages(current, current->mm, user_addr, | ||
819 | npages, 0, 0, pagevec, NULL); | ||
820 | up_read(¤t->mm->mmap_sem); | ||
821 | if (result < 0) | ||
822 | break; | ||
823 | } else { | ||
824 | WARN_ON(npages != 1); | ||
825 | result = get_kernel_page(user_addr, 0, pagevec); | ||
826 | if (WARN_ON(result != 1)) | ||
827 | break; | ||
828 | } | ||
829 | |||
830 | if ((unsigned)result < npages) { | ||
831 | bytes = result * PAGE_SIZE; | ||
832 | if (bytes <= pgbase) { | ||
833 | nfs_direct_release_pages(pagevec, result); | ||
834 | break; | ||
835 | } | ||
836 | bytes -= pgbase; | ||
837 | npages = result; | ||
838 | } | ||
839 | |||
840 | for (i = 0; i < npages; i++) { | ||
841 | struct nfs_page *req; | ||
842 | unsigned int req_len = min_t(size_t, bytes, PAGE_SIZE - pgbase); | ||
843 | |||
844 | req = nfs_create_request(dreq->ctx, pagevec[i], NULL, | ||
845 | pgbase, req_len); | ||
846 | if (IS_ERR(req)) { | ||
847 | result = PTR_ERR(req); | ||
848 | break; | ||
849 | } | ||
850 | nfs_lock_request(req); | ||
851 | req->wb_index = pos >> PAGE_SHIFT; | ||
852 | req->wb_offset = pos & ~PAGE_MASK; | ||
853 | if (!nfs_pageio_add_request(desc, req)) { | ||
854 | result = desc->pg_error; | ||
855 | nfs_unlock_and_release_request(req); | ||
856 | break; | ||
857 | } | ||
858 | pgbase = 0; | ||
859 | bytes -= req_len; | ||
860 | started += req_len; | ||
861 | user_addr += req_len; | ||
862 | pos += req_len; | ||
863 | count -= req_len; | ||
864 | dreq->bytes_left -= req_len; | ||
865 | } | ||
866 | /* The nfs_page now hold references to these pages */ | ||
867 | nfs_direct_release_pages(pagevec, npages); | ||
868 | } while (count != 0 && result >= 0); | ||
869 | |||
870 | kfree(pagevec); | ||
871 | |||
872 | if (started) | ||
873 | return started; | ||
874 | return result < 0 ? (ssize_t) result : -EFAULT; | ||
875 | } | ||
876 | |||
877 | static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | 714 | static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) |
878 | { | 715 | { |
879 | struct nfs_direct_req *dreq = hdr->dreq; | 716 | struct nfs_direct_req *dreq = hdr->dreq; |
@@ -956,16 +793,27 @@ static const struct nfs_pgio_completion_ops nfs_direct_write_completion_ops = { | |||
956 | .completion = nfs_direct_write_completion, | 793 | .completion = nfs_direct_write_completion, |
957 | }; | 794 | }; |
958 | 795 | ||
796 | |||
797 | /* | ||
798 | * NB: Return the value of the first error return code. Subsequent | ||
799 | * errors after the first one are ignored. | ||
800 | */ | ||
801 | /* | ||
802 | * For each wsize'd chunk of the user's buffer, dispatch an NFS WRITE | ||
803 | * operation. If nfs_writedata_alloc() or get_user_pages() fails, | ||
804 | * bail and stop sending more writes. Write length accounting is | ||
805 | * handled automatically by nfs_direct_write_result(). Otherwise, if | ||
806 | * no requests have been sent, just return an error. | ||
807 | */ | ||
959 | static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | 808 | static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, |
960 | const struct iovec *iov, | 809 | struct iov_iter *iter, |
961 | unsigned long nr_segs, | 810 | loff_t pos) |
962 | loff_t pos, bool uio) | ||
963 | { | 811 | { |
964 | struct nfs_pageio_descriptor desc; | 812 | struct nfs_pageio_descriptor desc; |
965 | struct inode *inode = dreq->inode; | 813 | struct inode *inode = dreq->inode; |
966 | ssize_t result = 0; | 814 | ssize_t result = 0; |
967 | size_t requested_bytes = 0; | 815 | size_t requested_bytes = 0; |
968 | unsigned long seg; | 816 | size_t wsize = max_t(size_t, NFS_SERVER(inode)->wsize, PAGE_SIZE); |
969 | 817 | ||
970 | nfs_pageio_init_write(&desc, inode, FLUSH_COND_STABLE, false, | 818 | nfs_pageio_init_write(&desc, inode, FLUSH_COND_STABLE, false, |
971 | &nfs_direct_write_completion_ops); | 819 | &nfs_direct_write_completion_ops); |
@@ -973,16 +821,49 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
973 | get_dreq(dreq); | 821 | get_dreq(dreq); |
974 | atomic_inc(&inode->i_dio_count); | 822 | atomic_inc(&inode->i_dio_count); |
975 | 823 | ||
976 | NFS_I(dreq->inode)->write_io += iov_length(iov, nr_segs); | 824 | NFS_I(inode)->write_io += iov_iter_count(iter); |
977 | for (seg = 0; seg < nr_segs; seg++) { | 825 | while (iov_iter_count(iter)) { |
978 | const struct iovec *vec = &iov[seg]; | 826 | struct page **pagevec; |
979 | result = nfs_direct_write_schedule_segment(&desc, vec, pos, uio); | 827 | size_t bytes; |
828 | size_t pgbase; | ||
829 | unsigned npages, i; | ||
830 | |||
831 | result = iov_iter_get_pages_alloc(iter, &pagevec, | ||
832 | wsize, &pgbase); | ||
980 | if (result < 0) | 833 | if (result < 0) |
981 | break; | 834 | break; |
982 | requested_bytes += result; | 835 | |
983 | if ((size_t)result < vec->iov_len) | 836 | bytes = result; |
837 | iov_iter_advance(iter, bytes); | ||
838 | npages = (result + pgbase + PAGE_SIZE - 1) / PAGE_SIZE; | ||
839 | for (i = 0; i < npages; i++) { | ||
840 | struct nfs_page *req; | ||
841 | unsigned int req_len = min_t(size_t, bytes, PAGE_SIZE - pgbase); | ||
842 | |||
843 | req = nfs_create_request(dreq->ctx, pagevec[i], NULL, | ||
844 | pgbase, req_len); | ||
845 | if (IS_ERR(req)) { | ||
846 | result = PTR_ERR(req); | ||
847 | break; | ||
848 | } | ||
849 | nfs_lock_request(req); | ||
850 | req->wb_index = pos >> PAGE_SHIFT; | ||
851 | req->wb_offset = pos & ~PAGE_MASK; | ||
852 | if (!nfs_pageio_add_request(&desc, req)) { | ||
853 | result = desc.pg_error; | ||
854 | nfs_unlock_and_release_request(req); | ||
855 | break; | ||
856 | } | ||
857 | pgbase = 0; | ||
858 | bytes -= req_len; | ||
859 | requested_bytes += req_len; | ||
860 | pos += req_len; | ||
861 | dreq->bytes_left -= req_len; | ||
862 | } | ||
863 | nfs_direct_release_pages(pagevec, npages); | ||
864 | kvfree(pagevec); | ||
865 | if (result < 0) | ||
984 | break; | 866 | break; |
985 | pos += vec->iov_len; | ||
986 | } | 867 | } |
987 | nfs_pageio_complete(&desc); | 868 | nfs_pageio_complete(&desc); |
988 | 869 | ||
@@ -1004,8 +885,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
1004 | /** | 885 | /** |
1005 | * nfs_file_direct_write - file direct write operation for NFS files | 886 | * nfs_file_direct_write - file direct write operation for NFS files |
1006 | * @iocb: target I/O control block | 887 | * @iocb: target I/O control block |
1007 | * @iov: vector of user buffers from which to write data | 888 | * @iter: vector of user buffers from which to write data |
1008 | * @nr_segs: size of iov vector | ||
1009 | * @pos: byte offset in file where writing starts | 889 | * @pos: byte offset in file where writing starts |
1010 | * | 890 | * |
1011 | * We use this function for direct writes instead of calling | 891 | * We use this function for direct writes instead of calling |
@@ -1023,8 +903,8 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
1023 | * Note that O_APPEND is not supported for NFS direct writes, as there | 903 | * Note that O_APPEND is not supported for NFS direct writes, as there |
1024 | * is no atomic O_APPEND write facility in the NFS protocol. | 904 | * is no atomic O_APPEND write facility in the NFS protocol. |
1025 | */ | 905 | */ |
1026 | ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | 906 | ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, |
1027 | unsigned long nr_segs, loff_t pos, bool uio) | 907 | loff_t pos, bool uio) |
1028 | { | 908 | { |
1029 | ssize_t result = -EINVAL; | 909 | ssize_t result = -EINVAL; |
1030 | struct file *file = iocb->ki_filp; | 910 | struct file *file = iocb->ki_filp; |
@@ -1033,9 +913,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
1033 | struct nfs_direct_req *dreq; | 913 | struct nfs_direct_req *dreq; |
1034 | struct nfs_lock_context *l_ctx; | 914 | struct nfs_lock_context *l_ctx; |
1035 | loff_t end; | 915 | loff_t end; |
1036 | size_t count; | 916 | size_t count = iov_iter_count(iter); |
1037 | |||
1038 | count = iov_length(iov, nr_segs); | ||
1039 | end = (pos + count - 1) >> PAGE_CACHE_SHIFT; | 917 | end = (pos + count - 1) >> PAGE_CACHE_SHIFT; |
1040 | 918 | ||
1041 | nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); | 919 | nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); |
@@ -1086,7 +964,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
1086 | if (!is_sync_kiocb(iocb)) | 964 | if (!is_sync_kiocb(iocb)) |
1087 | dreq->iocb = iocb; | 965 | dreq->iocb = iocb; |
1088 | 966 | ||
1089 | result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, uio); | 967 | result = nfs_direct_write_schedule_iovec(dreq, iter, pos); |
1090 | 968 | ||
1091 | if (mapping->nrpages) { | 969 | if (mapping->nrpages) { |
1092 | invalidate_inode_pages2_range(mapping, | 970 | invalidate_inode_pages2_range(mapping, |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index c1edf7336315..4042ff58fe3f 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
@@ -165,22 +165,21 @@ nfs_file_flush(struct file *file, fl_owner_t id) | |||
165 | EXPORT_SYMBOL_GPL(nfs_file_flush); | 165 | EXPORT_SYMBOL_GPL(nfs_file_flush); |
166 | 166 | ||
167 | ssize_t | 167 | ssize_t |
168 | nfs_file_read(struct kiocb *iocb, const struct iovec *iov, | 168 | nfs_file_read(struct kiocb *iocb, struct iov_iter *to) |
169 | unsigned long nr_segs, loff_t pos) | ||
170 | { | 169 | { |
171 | struct inode *inode = file_inode(iocb->ki_filp); | 170 | struct inode *inode = file_inode(iocb->ki_filp); |
172 | ssize_t result; | 171 | ssize_t result; |
173 | 172 | ||
174 | if (iocb->ki_filp->f_flags & O_DIRECT) | 173 | if (iocb->ki_filp->f_flags & O_DIRECT) |
175 | return nfs_file_direct_read(iocb, iov, nr_segs, pos, true); | 174 | return nfs_file_direct_read(iocb, to, iocb->ki_pos, true); |
176 | 175 | ||
177 | dprintk("NFS: read(%pD2, %lu@%lu)\n", | 176 | dprintk("NFS: read(%pD2, %zu@%lu)\n", |
178 | iocb->ki_filp, | 177 | iocb->ki_filp, |
179 | (unsigned long) iov_length(iov, nr_segs), (unsigned long) pos); | 178 | iov_iter_count(to), (unsigned long) iocb->ki_pos); |
180 | 179 | ||
181 | result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping); | 180 | result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping); |
182 | if (!result) { | 181 | if (!result) { |
183 | result = generic_file_aio_read(iocb, iov, nr_segs, pos); | 182 | result = generic_file_read_iter(iocb, to); |
184 | if (result > 0) | 183 | if (result > 0) |
185 | nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result); | 184 | nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result); |
186 | } | 185 | } |
@@ -635,24 +634,24 @@ static int nfs_need_sync_write(struct file *filp, struct inode *inode) | |||
635 | return 0; | 634 | return 0; |
636 | } | 635 | } |
637 | 636 | ||
638 | ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, | 637 | ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) |
639 | unsigned long nr_segs, loff_t pos) | ||
640 | { | 638 | { |
641 | struct file *file = iocb->ki_filp; | 639 | struct file *file = iocb->ki_filp; |
642 | struct inode *inode = file_inode(file); | 640 | struct inode *inode = file_inode(file); |
643 | unsigned long written = 0; | 641 | unsigned long written = 0; |
644 | ssize_t result; | 642 | ssize_t result; |
645 | size_t count = iov_length(iov, nr_segs); | 643 | size_t count = iov_iter_count(from); |
644 | loff_t pos = iocb->ki_pos; | ||
646 | 645 | ||
647 | result = nfs_key_timeout_notify(file, inode); | 646 | result = nfs_key_timeout_notify(file, inode); |
648 | if (result) | 647 | if (result) |
649 | return result; | 648 | return result; |
650 | 649 | ||
651 | if (file->f_flags & O_DIRECT) | 650 | if (file->f_flags & O_DIRECT) |
652 | return nfs_file_direct_write(iocb, iov, nr_segs, pos, true); | 651 | return nfs_file_direct_write(iocb, from, pos, true); |
653 | 652 | ||
654 | dprintk("NFS: write(%pD2, %lu@%Ld)\n", | 653 | dprintk("NFS: write(%pD2, %zu@%Ld)\n", |
655 | file, (unsigned long) count, (long long) pos); | 654 | file, count, (long long) pos); |
656 | 655 | ||
657 | result = -EBUSY; | 656 | result = -EBUSY; |
658 | if (IS_SWAPFILE(inode)) | 657 | if (IS_SWAPFILE(inode)) |
@@ -670,7 +669,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
670 | if (!count) | 669 | if (!count) |
671 | goto out; | 670 | goto out; |
672 | 671 | ||
673 | result = generic_file_aio_write(iocb, iov, nr_segs, pos); | 672 | result = generic_file_write_iter(iocb, from); |
674 | if (result > 0) | 673 | if (result > 0) |
675 | written = result; | 674 | written = result; |
676 | 675 | ||
@@ -691,36 +690,6 @@ out_swapfile: | |||
691 | } | 690 | } |
692 | EXPORT_SYMBOL_GPL(nfs_file_write); | 691 | EXPORT_SYMBOL_GPL(nfs_file_write); |
693 | 692 | ||
694 | ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe, | ||
695 | struct file *filp, loff_t *ppos, | ||
696 | size_t count, unsigned int flags) | ||
697 | { | ||
698 | struct inode *inode = file_inode(filp); | ||
699 | unsigned long written = 0; | ||
700 | ssize_t ret; | ||
701 | |||
702 | dprintk("NFS splice_write(%pD2, %lu@%llu)\n", | ||
703 | filp, (unsigned long) count, (unsigned long long) *ppos); | ||
704 | |||
705 | /* | ||
706 | * The combination of splice and an O_APPEND destination is disallowed. | ||
707 | */ | ||
708 | |||
709 | ret = generic_file_splice_write(pipe, filp, ppos, count, flags); | ||
710 | if (ret > 0) | ||
711 | written = ret; | ||
712 | |||
713 | if (ret >= 0 && nfs_need_sync_write(filp, inode)) { | ||
714 | int err = vfs_fsync(filp, 0); | ||
715 | if (err < 0) | ||
716 | ret = err; | ||
717 | } | ||
718 | if (ret > 0) | ||
719 | nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); | ||
720 | return ret; | ||
721 | } | ||
722 | EXPORT_SYMBOL_GPL(nfs_file_splice_write); | ||
723 | |||
724 | static int | 693 | static int |
725 | do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local) | 694 | do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local) |
726 | { | 695 | { |
@@ -935,10 +904,10 @@ EXPORT_SYMBOL_GPL(nfs_setlease); | |||
935 | 904 | ||
936 | const struct file_operations nfs_file_operations = { | 905 | const struct file_operations nfs_file_operations = { |
937 | .llseek = nfs_file_llseek, | 906 | .llseek = nfs_file_llseek, |
938 | .read = do_sync_read, | 907 | .read = new_sync_read, |
939 | .write = do_sync_write, | 908 | .write = new_sync_write, |
940 | .aio_read = nfs_file_read, | 909 | .read_iter = nfs_file_read, |
941 | .aio_write = nfs_file_write, | 910 | .write_iter = nfs_file_write, |
942 | .mmap = nfs_file_mmap, | 911 | .mmap = nfs_file_mmap, |
943 | .open = nfs_file_open, | 912 | .open = nfs_file_open, |
944 | .flush = nfs_file_flush, | 913 | .flush = nfs_file_flush, |
@@ -947,7 +916,7 @@ const struct file_operations nfs_file_operations = { | |||
947 | .lock = nfs_lock, | 916 | .lock = nfs_lock, |
948 | .flock = nfs_flock, | 917 | .flock = nfs_flock, |
949 | .splice_read = nfs_file_splice_read, | 918 | .splice_read = nfs_file_splice_read, |
950 | .splice_write = nfs_file_splice_write, | 919 | .splice_write = iter_file_splice_write, |
951 | .check_flags = nfs_check_flags, | 920 | .check_flags = nfs_check_flags, |
952 | .setlease = nfs_setlease, | 921 | .setlease = nfs_setlease, |
953 | }; | 922 | }; |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 8b69cba1bb04..82ddbf46660e 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -327,16 +327,14 @@ int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *) | |||
327 | int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); | 327 | int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); |
328 | loff_t nfs_file_llseek(struct file *, loff_t, int); | 328 | loff_t nfs_file_llseek(struct file *, loff_t, int); |
329 | int nfs_file_flush(struct file *, fl_owner_t); | 329 | int nfs_file_flush(struct file *, fl_owner_t); |
330 | ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 330 | ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); |
331 | ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, | 331 | ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, |
332 | size_t, unsigned int); | 332 | size_t, unsigned int); |
333 | int nfs_file_mmap(struct file *, struct vm_area_struct *); | 333 | int nfs_file_mmap(struct file *, struct vm_area_struct *); |
334 | ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 334 | ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); |
335 | int nfs_file_release(struct inode *, struct file *); | 335 | int nfs_file_release(struct inode *, struct file *); |
336 | int nfs_lock(struct file *, int, struct file_lock *); | 336 | int nfs_lock(struct file *, int, struct file_lock *); |
337 | int nfs_flock(struct file *, int, struct file_lock *); | 337 | int nfs_flock(struct file *, int, struct file_lock *); |
338 | ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *, | ||
339 | size_t, unsigned int); | ||
340 | int nfs_check_flags(int); | 338 | int nfs_check_flags(int); |
341 | int nfs_setlease(struct file *, long, struct file_lock **); | 339 | int nfs_setlease(struct file *, long, struct file_lock **); |
342 | 340 | ||
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 464db9dd6318..a816f0627a6c 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c | |||
@@ -117,10 +117,10 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
117 | 117 | ||
118 | const struct file_operations nfs4_file_operations = { | 118 | const struct file_operations nfs4_file_operations = { |
119 | .llseek = nfs_file_llseek, | 119 | .llseek = nfs_file_llseek, |
120 | .read = do_sync_read, | 120 | .read = new_sync_read, |
121 | .write = do_sync_write, | 121 | .write = new_sync_write, |
122 | .aio_read = nfs_file_read, | 122 | .read_iter = nfs_file_read, |
123 | .aio_write = nfs_file_write, | 123 | .write_iter = nfs_file_write, |
124 | .mmap = nfs_file_mmap, | 124 | .mmap = nfs_file_mmap, |
125 | .open = nfs4_file_open, | 125 | .open = nfs4_file_open, |
126 | .flush = nfs_file_flush, | 126 | .flush = nfs_file_flush, |
@@ -129,7 +129,7 @@ const struct file_operations nfs4_file_operations = { | |||
129 | .lock = nfs_lock, | 129 | .lock = nfs_lock, |
130 | .flock = nfs_flock, | 130 | .flock = nfs_flock, |
131 | .splice_read = nfs_file_splice_read, | 131 | .splice_read = nfs_file_splice_read, |
132 | .splice_write = nfs_file_splice_write, | 132 | .splice_write = iter_file_splice_write, |
133 | .check_flags = nfs_check_flags, | 133 | .check_flags = nfs_check_flags, |
134 | .setlease = nfs_setlease, | 134 | .setlease = nfs_setlease, |
135 | }; | 135 | }; |
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index f3a82fbcae02..24978153c0c4 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c | |||
@@ -152,10 +152,10 @@ static int nilfs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
152 | */ | 152 | */ |
153 | const struct file_operations nilfs_file_operations = { | 153 | const struct file_operations nilfs_file_operations = { |
154 | .llseek = generic_file_llseek, | 154 | .llseek = generic_file_llseek, |
155 | .read = do_sync_read, | 155 | .read = new_sync_read, |
156 | .write = do_sync_write, | 156 | .write = new_sync_write, |
157 | .aio_read = generic_file_aio_read, | 157 | .read_iter = generic_file_read_iter, |
158 | .aio_write = generic_file_aio_write, | 158 | .write_iter = generic_file_write_iter, |
159 | .unlocked_ioctl = nilfs_ioctl, | 159 | .unlocked_ioctl = nilfs_ioctl, |
160 | #ifdef CONFIG_COMPAT | 160 | #ifdef CONFIG_COMPAT |
161 | .compat_ioctl = nilfs_compat_ioctl, | 161 | .compat_ioctl = nilfs_compat_ioctl, |
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index b9c5726120e3..6252b173a465 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c | |||
@@ -298,19 +298,20 @@ static int nilfs_write_end(struct file *file, struct address_space *mapping, | |||
298 | } | 298 | } |
299 | 299 | ||
300 | static ssize_t | 300 | static ssize_t |
301 | nilfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 301 | nilfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, |
302 | loff_t offset, unsigned long nr_segs) | 302 | loff_t offset) |
303 | { | 303 | { |
304 | struct file *file = iocb->ki_filp; | 304 | struct file *file = iocb->ki_filp; |
305 | struct address_space *mapping = file->f_mapping; | 305 | struct address_space *mapping = file->f_mapping; |
306 | struct inode *inode = file->f_mapping->host; | 306 | struct inode *inode = file->f_mapping->host; |
307 | size_t count = iov_iter_count(iter); | ||
307 | ssize_t size; | 308 | ssize_t size; |
308 | 309 | ||
309 | if (rw == WRITE) | 310 | if (rw == WRITE) |
310 | return 0; | 311 | return 0; |
311 | 312 | ||
312 | /* Needs synchronization with the cleaner */ | 313 | /* Needs synchronization with the cleaner */ |
313 | size = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 314 | size = blockdev_direct_IO(rw, iocb, inode, iter, offset, |
314 | nilfs_get_block); | 315 | nilfs_get_block); |
315 | 316 | ||
316 | /* | 317 | /* |
@@ -319,7 +320,7 @@ nilfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
319 | */ | 320 | */ |
320 | if (unlikely((rw & WRITE) && size < 0)) { | 321 | if (unlikely((rw & WRITE) && size < 0)) { |
321 | loff_t isize = i_size_read(inode); | 322 | loff_t isize = i_size_read(inode); |
322 | loff_t end = offset + iov_length(iov, nr_segs); | 323 | loff_t end = offset + count; |
323 | 324 | ||
324 | if (end > isize) | 325 | if (end > isize) |
325 | nilfs_write_failed(mapping, end); | 326 | nilfs_write_failed(mapping, end); |
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 86ddab916b66..5c9e2c81cb11 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c | |||
@@ -2090,10 +2090,7 @@ static ssize_t ntfs_file_aio_write_nolock(struct kiocb *iocb, | |||
2090 | size_t count; /* after file limit checks */ | 2090 | size_t count; /* after file limit checks */ |
2091 | ssize_t written, err; | 2091 | ssize_t written, err; |
2092 | 2092 | ||
2093 | count = 0; | 2093 | count = iov_length(iov, nr_segs); |
2094 | err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ); | ||
2095 | if (err) | ||
2096 | return err; | ||
2097 | pos = *ppos; | 2094 | pos = *ppos; |
2098 | /* We can write back this queue in page reclaim. */ | 2095 | /* We can write back this queue in page reclaim. */ |
2099 | current->backing_dev_info = mapping->backing_dev_info; | 2096 | current->backing_dev_info = mapping->backing_dev_info; |
@@ -2202,8 +2199,8 @@ static int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end, | |||
2202 | 2199 | ||
2203 | const struct file_operations ntfs_file_ops = { | 2200 | const struct file_operations ntfs_file_ops = { |
2204 | .llseek = generic_file_llseek, /* Seek inside file. */ | 2201 | .llseek = generic_file_llseek, /* Seek inside file. */ |
2205 | .read = do_sync_read, /* Read from file. */ | 2202 | .read = new_sync_read, /* Read from file. */ |
2206 | .aio_read = generic_file_aio_read, /* Async read from file. */ | 2203 | .read_iter = generic_file_read_iter, /* Async read from file. */ |
2207 | #ifdef NTFS_RW | 2204 | #ifdef NTFS_RW |
2208 | .write = do_sync_write, /* Write to file. */ | 2205 | .write = do_sync_write, /* Write to file. */ |
2209 | .aio_write = ntfs_file_aio_write, /* Async write to file. */ | 2206 | .aio_write = ntfs_file_aio_write, /* Async write to file. */ |
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index d310d12a9adc..4a231a166cf8 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -599,9 +599,8 @@ static int ocfs2_releasepage(struct page *page, gfp_t wait) | |||
599 | 599 | ||
600 | static ssize_t ocfs2_direct_IO(int rw, | 600 | static ssize_t ocfs2_direct_IO(int rw, |
601 | struct kiocb *iocb, | 601 | struct kiocb *iocb, |
602 | const struct iovec *iov, | 602 | struct iov_iter *iter, |
603 | loff_t offset, | 603 | loff_t offset) |
604 | unsigned long nr_segs) | ||
605 | { | 604 | { |
606 | struct file *file = iocb->ki_filp; | 605 | struct file *file = iocb->ki_filp; |
607 | struct inode *inode = file_inode(file)->i_mapping->host; | 606 | struct inode *inode = file_inode(file)->i_mapping->host; |
@@ -618,7 +617,7 @@ static ssize_t ocfs2_direct_IO(int rw, | |||
618 | return 0; | 617 | return 0; |
619 | 618 | ||
620 | return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, | 619 | return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, |
621 | iov, offset, nr_segs, | 620 | iter, offset, |
622 | ocfs2_direct_IO_get_blocks, | 621 | ocfs2_direct_IO_get_blocks, |
623 | ocfs2_dio_end_io, NULL, 0); | 622 | ocfs2_dio_end_io, NULL, 0); |
624 | } | 623 | } |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 8eb6e5732d3b..2930e231f3f9 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -2233,16 +2233,13 @@ out: | |||
2233 | return ret; | 2233 | return ret; |
2234 | } | 2234 | } |
2235 | 2235 | ||
2236 | static ssize_t ocfs2_file_aio_write(struct kiocb *iocb, | 2236 | static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, |
2237 | const struct iovec *iov, | 2237 | struct iov_iter *from) |
2238 | unsigned long nr_segs, | ||
2239 | loff_t pos) | ||
2240 | { | 2238 | { |
2241 | int ret, direct_io, appending, rw_level, have_alloc_sem = 0; | 2239 | int ret, direct_io, appending, rw_level, have_alloc_sem = 0; |
2242 | int can_do_direct, has_refcount = 0; | 2240 | int can_do_direct, has_refcount = 0; |
2243 | ssize_t written = 0; | 2241 | ssize_t written = 0; |
2244 | size_t ocount; /* original count */ | 2242 | size_t count = iov_iter_count(from); |
2245 | size_t count; /* after file limit checks */ | ||
2246 | loff_t old_size, *ppos = &iocb->ki_pos; | 2243 | loff_t old_size, *ppos = &iocb->ki_pos; |
2247 | u32 old_clusters; | 2244 | u32 old_clusters; |
2248 | struct file *file = iocb->ki_filp; | 2245 | struct file *file = iocb->ki_filp; |
@@ -2256,7 +2253,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb, | |||
2256 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2253 | (unsigned long long)OCFS2_I(inode)->ip_blkno, |
2257 | file->f_path.dentry->d_name.len, | 2254 | file->f_path.dentry->d_name.len, |
2258 | file->f_path.dentry->d_name.name, | 2255 | file->f_path.dentry->d_name.name, |
2259 | (unsigned int)nr_segs); | 2256 | (unsigned int)from->nr_segs); /* GRRRRR */ |
2260 | 2257 | ||
2261 | if (iocb->ki_nbytes == 0) | 2258 | if (iocb->ki_nbytes == 0) |
2262 | return 0; | 2259 | return 0; |
@@ -2354,29 +2351,21 @@ relock: | |||
2354 | /* communicate with ocfs2_dio_end_io */ | 2351 | /* communicate with ocfs2_dio_end_io */ |
2355 | ocfs2_iocb_set_rw_locked(iocb, rw_level); | 2352 | ocfs2_iocb_set_rw_locked(iocb, rw_level); |
2356 | 2353 | ||
2357 | ret = generic_segment_checks(iov, &nr_segs, &ocount, | ||
2358 | VERIFY_READ); | ||
2359 | if (ret) | ||
2360 | goto out_dio; | ||
2361 | |||
2362 | count = ocount; | ||
2363 | ret = generic_write_checks(file, ppos, &count, | 2354 | ret = generic_write_checks(file, ppos, &count, |
2364 | S_ISBLK(inode->i_mode)); | 2355 | S_ISBLK(inode->i_mode)); |
2365 | if (ret) | 2356 | if (ret) |
2366 | goto out_dio; | 2357 | goto out_dio; |
2367 | 2358 | ||
2359 | iov_iter_truncate(from, count); | ||
2368 | if (direct_io) { | 2360 | if (direct_io) { |
2369 | written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos, | 2361 | written = generic_file_direct_write(iocb, from, *ppos); |
2370 | count, ocount); | ||
2371 | if (written < 0) { | 2362 | if (written < 0) { |
2372 | ret = written; | 2363 | ret = written; |
2373 | goto out_dio; | 2364 | goto out_dio; |
2374 | } | 2365 | } |
2375 | } else { | 2366 | } else { |
2376 | struct iov_iter from; | ||
2377 | iov_iter_init(&from, iov, nr_segs, count, 0); | ||
2378 | current->backing_dev_info = file->f_mapping->backing_dev_info; | 2367 | current->backing_dev_info = file->f_mapping->backing_dev_info; |
2379 | written = generic_perform_write(file, &from, *ppos); | 2368 | written = generic_perform_write(file, from, *ppos); |
2380 | if (likely(written >= 0)) | 2369 | if (likely(written >= 0)) |
2381 | iocb->ki_pos = *ppos + written; | 2370 | iocb->ki_pos = *ppos + written; |
2382 | current->backing_dev_info = NULL; | 2371 | current->backing_dev_info = NULL; |
@@ -2441,84 +2430,6 @@ out_sems: | |||
2441 | return ret; | 2430 | return ret; |
2442 | } | 2431 | } |
2443 | 2432 | ||
2444 | static int ocfs2_splice_to_file(struct pipe_inode_info *pipe, | ||
2445 | struct file *out, | ||
2446 | struct splice_desc *sd) | ||
2447 | { | ||
2448 | int ret; | ||
2449 | |||
2450 | ret = ocfs2_prepare_inode_for_write(out, &sd->pos, | ||
2451 | sd->total_len, 0, NULL, NULL); | ||
2452 | if (ret < 0) { | ||
2453 | mlog_errno(ret); | ||
2454 | return ret; | ||
2455 | } | ||
2456 | |||
2457 | return splice_from_pipe_feed(pipe, sd, pipe_to_file); | ||
2458 | } | ||
2459 | |||
2460 | static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe, | ||
2461 | struct file *out, | ||
2462 | loff_t *ppos, | ||
2463 | size_t len, | ||
2464 | unsigned int flags) | ||
2465 | { | ||
2466 | int ret; | ||
2467 | struct address_space *mapping = out->f_mapping; | ||
2468 | struct inode *inode = mapping->host; | ||
2469 | struct splice_desc sd = { | ||
2470 | .total_len = len, | ||
2471 | .flags = flags, | ||
2472 | .pos = *ppos, | ||
2473 | .u.file = out, | ||
2474 | }; | ||
2475 | |||
2476 | |||
2477 | trace_ocfs2_file_splice_write(inode, out, out->f_path.dentry, | ||
2478 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
2479 | out->f_path.dentry->d_name.len, | ||
2480 | out->f_path.dentry->d_name.name, len); | ||
2481 | |||
2482 | pipe_lock(pipe); | ||
2483 | |||
2484 | splice_from_pipe_begin(&sd); | ||
2485 | do { | ||
2486 | ret = splice_from_pipe_next(pipe, &sd); | ||
2487 | if (ret <= 0) | ||
2488 | break; | ||
2489 | |||
2490 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); | ||
2491 | ret = ocfs2_rw_lock(inode, 1); | ||
2492 | if (ret < 0) | ||
2493 | mlog_errno(ret); | ||
2494 | else { | ||
2495 | ret = ocfs2_splice_to_file(pipe, out, &sd); | ||
2496 | ocfs2_rw_unlock(inode, 1); | ||
2497 | } | ||
2498 | mutex_unlock(&inode->i_mutex); | ||
2499 | } while (ret > 0); | ||
2500 | splice_from_pipe_end(pipe, &sd); | ||
2501 | |||
2502 | pipe_unlock(pipe); | ||
2503 | |||
2504 | if (sd.num_spliced) | ||
2505 | ret = sd.num_spliced; | ||
2506 | |||
2507 | if (ret > 0) { | ||
2508 | int err; | ||
2509 | |||
2510 | err = generic_write_sync(out, *ppos, ret); | ||
2511 | if (err) | ||
2512 | ret = err; | ||
2513 | else | ||
2514 | *ppos += ret; | ||
2515 | |||
2516 | balance_dirty_pages_ratelimited(mapping); | ||
2517 | } | ||
2518 | |||
2519 | return ret; | ||
2520 | } | ||
2521 | |||
2522 | static ssize_t ocfs2_file_splice_read(struct file *in, | 2433 | static ssize_t ocfs2_file_splice_read(struct file *in, |
2523 | loff_t *ppos, | 2434 | loff_t *ppos, |
2524 | struct pipe_inode_info *pipe, | 2435 | struct pipe_inode_info *pipe, |
@@ -2534,7 +2445,7 @@ static ssize_t ocfs2_file_splice_read(struct file *in, | |||
2534 | in->f_path.dentry->d_name.name, len); | 2445 | in->f_path.dentry->d_name.name, len); |
2535 | 2446 | ||
2536 | /* | 2447 | /* |
2537 | * See the comment in ocfs2_file_aio_read() | 2448 | * See the comment in ocfs2_file_read_iter() |
2538 | */ | 2449 | */ |
2539 | ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level); | 2450 | ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level); |
2540 | if (ret < 0) { | 2451 | if (ret < 0) { |
@@ -2549,10 +2460,8 @@ bail: | |||
2549 | return ret; | 2460 | return ret; |
2550 | } | 2461 | } |
2551 | 2462 | ||
2552 | static ssize_t ocfs2_file_aio_read(struct kiocb *iocb, | 2463 | static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, |
2553 | const struct iovec *iov, | 2464 | struct iov_iter *to) |
2554 | unsigned long nr_segs, | ||
2555 | loff_t pos) | ||
2556 | { | 2465 | { |
2557 | int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0; | 2466 | int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0; |
2558 | struct file *filp = iocb->ki_filp; | 2467 | struct file *filp = iocb->ki_filp; |
@@ -2561,7 +2470,8 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb, | |||
2561 | trace_ocfs2_file_aio_read(inode, filp, filp->f_path.dentry, | 2470 | trace_ocfs2_file_aio_read(inode, filp, filp->f_path.dentry, |
2562 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | 2471 | (unsigned long long)OCFS2_I(inode)->ip_blkno, |
2563 | filp->f_path.dentry->d_name.len, | 2472 | filp->f_path.dentry->d_name.len, |
2564 | filp->f_path.dentry->d_name.name, nr_segs); | 2473 | filp->f_path.dentry->d_name.name, |
2474 | to->nr_segs); /* GRRRRR */ | ||
2565 | 2475 | ||
2566 | 2476 | ||
2567 | if (!inode) { | 2477 | if (!inode) { |
@@ -2606,13 +2516,13 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb, | |||
2606 | } | 2516 | } |
2607 | ocfs2_inode_unlock(inode, lock_level); | 2517 | ocfs2_inode_unlock(inode, lock_level); |
2608 | 2518 | ||
2609 | ret = generic_file_aio_read(iocb, iov, nr_segs, iocb->ki_pos); | 2519 | ret = generic_file_read_iter(iocb, to); |
2610 | trace_generic_file_aio_read_ret(ret); | 2520 | trace_generic_file_aio_read_ret(ret); |
2611 | 2521 | ||
2612 | /* buffered aio wouldn't have proper lock coverage today */ | 2522 | /* buffered aio wouldn't have proper lock coverage today */ |
2613 | BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT)); | 2523 | BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT)); |
2614 | 2524 | ||
2615 | /* see ocfs2_file_aio_write */ | 2525 | /* see ocfs2_file_write_iter */ |
2616 | if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { | 2526 | if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { |
2617 | rw_level = -1; | 2527 | rw_level = -1; |
2618 | have_alloc_sem = 0; | 2528 | have_alloc_sem = 0; |
@@ -2705,14 +2615,14 @@ const struct inode_operations ocfs2_special_file_iops = { | |||
2705 | */ | 2615 | */ |
2706 | const struct file_operations ocfs2_fops = { | 2616 | const struct file_operations ocfs2_fops = { |
2707 | .llseek = ocfs2_file_llseek, | 2617 | .llseek = ocfs2_file_llseek, |
2708 | .read = do_sync_read, | 2618 | .read = new_sync_read, |
2709 | .write = do_sync_write, | 2619 | .write = new_sync_write, |
2710 | .mmap = ocfs2_mmap, | 2620 | .mmap = ocfs2_mmap, |
2711 | .fsync = ocfs2_sync_file, | 2621 | .fsync = ocfs2_sync_file, |
2712 | .release = ocfs2_file_release, | 2622 | .release = ocfs2_file_release, |
2713 | .open = ocfs2_file_open, | 2623 | .open = ocfs2_file_open, |
2714 | .aio_read = ocfs2_file_aio_read, | 2624 | .read_iter = ocfs2_file_read_iter, |
2715 | .aio_write = ocfs2_file_aio_write, | 2625 | .write_iter = ocfs2_file_write_iter, |
2716 | .unlocked_ioctl = ocfs2_ioctl, | 2626 | .unlocked_ioctl = ocfs2_ioctl, |
2717 | #ifdef CONFIG_COMPAT | 2627 | #ifdef CONFIG_COMPAT |
2718 | .compat_ioctl = ocfs2_compat_ioctl, | 2628 | .compat_ioctl = ocfs2_compat_ioctl, |
@@ -2720,7 +2630,7 @@ const struct file_operations ocfs2_fops = { | |||
2720 | .lock = ocfs2_lock, | 2630 | .lock = ocfs2_lock, |
2721 | .flock = ocfs2_flock, | 2631 | .flock = ocfs2_flock, |
2722 | .splice_read = ocfs2_file_splice_read, | 2632 | .splice_read = ocfs2_file_splice_read, |
2723 | .splice_write = ocfs2_file_splice_write, | 2633 | .splice_write = iter_file_splice_write, |
2724 | .fallocate = ocfs2_fallocate, | 2634 | .fallocate = ocfs2_fallocate, |
2725 | }; | 2635 | }; |
2726 | 2636 | ||
@@ -2753,21 +2663,21 @@ const struct file_operations ocfs2_dops = { | |||
2753 | */ | 2663 | */ |
2754 | const struct file_operations ocfs2_fops_no_plocks = { | 2664 | const struct file_operations ocfs2_fops_no_plocks = { |
2755 | .llseek = ocfs2_file_llseek, | 2665 | .llseek = ocfs2_file_llseek, |
2756 | .read = do_sync_read, | 2666 | .read = new_sync_read, |
2757 | .write = do_sync_write, | 2667 | .write = new_sync_write, |
2758 | .mmap = ocfs2_mmap, | 2668 | .mmap = ocfs2_mmap, |
2759 | .fsync = ocfs2_sync_file, | 2669 | .fsync = ocfs2_sync_file, |
2760 | .release = ocfs2_file_release, | 2670 | .release = ocfs2_file_release, |
2761 | .open = ocfs2_file_open, | 2671 | .open = ocfs2_file_open, |
2762 | .aio_read = ocfs2_file_aio_read, | 2672 | .read_iter = ocfs2_file_read_iter, |
2763 | .aio_write = ocfs2_file_aio_write, | 2673 | .write_iter = ocfs2_file_write_iter, |
2764 | .unlocked_ioctl = ocfs2_ioctl, | 2674 | .unlocked_ioctl = ocfs2_ioctl, |
2765 | #ifdef CONFIG_COMPAT | 2675 | #ifdef CONFIG_COMPAT |
2766 | .compat_ioctl = ocfs2_compat_ioctl, | 2676 | .compat_ioctl = ocfs2_compat_ioctl, |
2767 | #endif | 2677 | #endif |
2768 | .flock = ocfs2_flock, | 2678 | .flock = ocfs2_flock, |
2769 | .splice_read = ocfs2_file_splice_read, | 2679 | .splice_read = ocfs2_file_splice_read, |
2770 | .splice_write = ocfs2_file_splice_write, | 2680 | .splice_write = iter_file_splice_write, |
2771 | .fallocate = ocfs2_fallocate, | 2681 | .fallocate = ocfs2_fallocate, |
2772 | }; | 2682 | }; |
2773 | 2683 | ||
diff --git a/fs/omfs/file.c b/fs/omfs/file.c index 54d57d6ba68d..902e88527fce 100644 --- a/fs/omfs/file.c +++ b/fs/omfs/file.c | |||
@@ -337,10 +337,10 @@ static sector_t omfs_bmap(struct address_space *mapping, sector_t block) | |||
337 | 337 | ||
338 | const struct file_operations omfs_file_operations = { | 338 | const struct file_operations omfs_file_operations = { |
339 | .llseek = generic_file_llseek, | 339 | .llseek = generic_file_llseek, |
340 | .read = do_sync_read, | 340 | .read = new_sync_read, |
341 | .write = do_sync_write, | 341 | .write = new_sync_write, |
342 | .aio_read = generic_file_aio_read, | 342 | .read_iter = generic_file_read_iter, |
343 | .aio_write = generic_file_aio_write, | 343 | .write_iter = generic_file_write_iter, |
344 | .mmap = generic_file_mmap, | 344 | .mmap = generic_file_mmap, |
345 | .fsync = generic_file_fsync, | 345 | .fsync = generic_file_fsync, |
346 | .splice_read = generic_file_splice_read, | 346 | .splice_read = generic_file_splice_read, |
@@ -725,6 +725,12 @@ static int do_dentry_open(struct file *f, | |||
725 | } | 725 | } |
726 | if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | 726 | if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) |
727 | i_readcount_inc(inode); | 727 | i_readcount_inc(inode); |
728 | if ((f->f_mode & FMODE_READ) && | ||
729 | likely(f->f_op->read || f->f_op->aio_read || f->f_op->read_iter)) | ||
730 | f->f_mode |= FMODE_CAN_READ; | ||
731 | if ((f->f_mode & FMODE_WRITE) && | ||
732 | likely(f->f_op->write || f->f_op->aio_write || f->f_op->write_iter)) | ||
733 | f->f_mode |= FMODE_CAN_WRITE; | ||
728 | 734 | ||
729 | f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); | 735 | f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); |
730 | 736 | ||
@@ -116,50 +116,6 @@ void pipe_wait(struct pipe_inode_info *pipe) | |||
116 | pipe_lock(pipe); | 116 | pipe_lock(pipe); |
117 | } | 117 | } |
118 | 118 | ||
119 | static int | ||
120 | pipe_iov_copy_from_user(void *to, struct iovec *iov, unsigned long len, | ||
121 | int atomic) | ||
122 | { | ||
123 | unsigned long copy; | ||
124 | |||
125 | while (len > 0) { | ||
126 | while (!iov->iov_len) | ||
127 | iov++; | ||
128 | copy = min_t(unsigned long, len, iov->iov_len); | ||
129 | |||
130 | if (atomic) { | ||
131 | if (__copy_from_user_inatomic(to, iov->iov_base, copy)) | ||
132 | return -EFAULT; | ||
133 | } else { | ||
134 | if (copy_from_user(to, iov->iov_base, copy)) | ||
135 | return -EFAULT; | ||
136 | } | ||
137 | to += copy; | ||
138 | len -= copy; | ||
139 | iov->iov_base += copy; | ||
140 | iov->iov_len -= copy; | ||
141 | } | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Pre-fault in the user memory, so we can use atomic copies. | ||
147 | */ | ||
148 | static void iov_fault_in_pages_read(struct iovec *iov, unsigned long len) | ||
149 | { | ||
150 | while (!iov->iov_len) | ||
151 | iov++; | ||
152 | |||
153 | while (len > 0) { | ||
154 | unsigned long this_len; | ||
155 | |||
156 | this_len = min_t(unsigned long, len, iov->iov_len); | ||
157 | fault_in_pages_readable(iov->iov_base, this_len); | ||
158 | len -= this_len; | ||
159 | iov++; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | static void anon_pipe_buf_release(struct pipe_inode_info *pipe, | 119 | static void anon_pipe_buf_release(struct pipe_inode_info *pipe, |
164 | struct pipe_buffer *buf) | 120 | struct pipe_buffer *buf) |
165 | { | 121 | { |
@@ -271,24 +227,18 @@ static const struct pipe_buf_operations packet_pipe_buf_ops = { | |||
271 | }; | 227 | }; |
272 | 228 | ||
273 | static ssize_t | 229 | static ssize_t |
274 | pipe_read(struct kiocb *iocb, const struct iovec *_iov, | 230 | pipe_read(struct kiocb *iocb, struct iov_iter *to) |
275 | unsigned long nr_segs, loff_t pos) | ||
276 | { | 231 | { |
232 | size_t total_len = iov_iter_count(to); | ||
277 | struct file *filp = iocb->ki_filp; | 233 | struct file *filp = iocb->ki_filp; |
278 | struct pipe_inode_info *pipe = filp->private_data; | 234 | struct pipe_inode_info *pipe = filp->private_data; |
279 | int do_wakeup; | 235 | int do_wakeup; |
280 | ssize_t ret; | 236 | ssize_t ret; |
281 | struct iovec *iov = (struct iovec *)_iov; | ||
282 | size_t total_len; | ||
283 | struct iov_iter iter; | ||
284 | 237 | ||
285 | total_len = iov_length(iov, nr_segs); | ||
286 | /* Null read succeeds. */ | 238 | /* Null read succeeds. */ |
287 | if (unlikely(total_len == 0)) | 239 | if (unlikely(total_len == 0)) |
288 | return 0; | 240 | return 0; |
289 | 241 | ||
290 | iov_iter_init(&iter, iov, nr_segs, total_len, 0); | ||
291 | |||
292 | do_wakeup = 0; | 242 | do_wakeup = 0; |
293 | ret = 0; | 243 | ret = 0; |
294 | __pipe_lock(pipe); | 244 | __pipe_lock(pipe); |
@@ -312,7 +262,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov, | |||
312 | break; | 262 | break; |
313 | } | 263 | } |
314 | 264 | ||
315 | written = copy_page_to_iter(buf->page, buf->offset, chars, &iter); | 265 | written = copy_page_to_iter(buf->page, buf->offset, chars, to); |
316 | if (unlikely(written < chars)) { | 266 | if (unlikely(written < chars)) { |
317 | if (!ret) | 267 | if (!ret) |
318 | ret = -EFAULT; | 268 | ret = -EFAULT; |
@@ -386,24 +336,19 @@ static inline int is_packetized(struct file *file) | |||
386 | } | 336 | } |
387 | 337 | ||
388 | static ssize_t | 338 | static ssize_t |
389 | pipe_write(struct kiocb *iocb, const struct iovec *_iov, | 339 | pipe_write(struct kiocb *iocb, struct iov_iter *from) |
390 | unsigned long nr_segs, loff_t ppos) | ||
391 | { | 340 | { |
392 | struct file *filp = iocb->ki_filp; | 341 | struct file *filp = iocb->ki_filp; |
393 | struct pipe_inode_info *pipe = filp->private_data; | 342 | struct pipe_inode_info *pipe = filp->private_data; |
394 | ssize_t ret; | 343 | ssize_t ret = 0; |
395 | int do_wakeup; | 344 | int do_wakeup = 0; |
396 | struct iovec *iov = (struct iovec *)_iov; | 345 | size_t total_len = iov_iter_count(from); |
397 | size_t total_len; | ||
398 | ssize_t chars; | 346 | ssize_t chars; |
399 | 347 | ||
400 | total_len = iov_length(iov, nr_segs); | ||
401 | /* Null write succeeds. */ | 348 | /* Null write succeeds. */ |
402 | if (unlikely(total_len == 0)) | 349 | if (unlikely(total_len == 0)) |
403 | return 0; | 350 | return 0; |
404 | 351 | ||
405 | do_wakeup = 0; | ||
406 | ret = 0; | ||
407 | __pipe_lock(pipe); | 352 | __pipe_lock(pipe); |
408 | 353 | ||
409 | if (!pipe->readers) { | 354 | if (!pipe->readers) { |
@@ -422,38 +367,19 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov, | |||
422 | int offset = buf->offset + buf->len; | 367 | int offset = buf->offset + buf->len; |
423 | 368 | ||
424 | if (ops->can_merge && offset + chars <= PAGE_SIZE) { | 369 | if (ops->can_merge && offset + chars <= PAGE_SIZE) { |
425 | int error, atomic = 1; | 370 | int error = ops->confirm(pipe, buf); |
426 | void *addr; | ||
427 | |||
428 | error = ops->confirm(pipe, buf); | ||
429 | if (error) | 371 | if (error) |
430 | goto out; | 372 | goto out; |
431 | 373 | ||
432 | iov_fault_in_pages_read(iov, chars); | 374 | ret = copy_page_from_iter(buf->page, offset, chars, from); |
433 | redo1: | 375 | if (unlikely(ret < chars)) { |
434 | if (atomic) | 376 | error = -EFAULT; |
435 | addr = kmap_atomic(buf->page); | ||
436 | else | ||
437 | addr = kmap(buf->page); | ||
438 | error = pipe_iov_copy_from_user(offset + addr, iov, | ||
439 | chars, atomic); | ||
440 | if (atomic) | ||
441 | kunmap_atomic(addr); | ||
442 | else | ||
443 | kunmap(buf->page); | ||
444 | ret = error; | ||
445 | do_wakeup = 1; | ||
446 | if (error) { | ||
447 | if (atomic) { | ||
448 | atomic = 0; | ||
449 | goto redo1; | ||
450 | } | ||
451 | goto out; | 377 | goto out; |
452 | } | 378 | } |
379 | do_wakeup = 1; | ||
453 | buf->len += chars; | 380 | buf->len += chars; |
454 | total_len -= chars; | ||
455 | ret = chars; | 381 | ret = chars; |
456 | if (!total_len) | 382 | if (!iov_iter_count(from)) |
457 | goto out; | 383 | goto out; |
458 | } | 384 | } |
459 | } | 385 | } |
@@ -472,8 +398,7 @@ redo1: | |||
472 | int newbuf = (pipe->curbuf + bufs) & (pipe->buffers-1); | 398 | int newbuf = (pipe->curbuf + bufs) & (pipe->buffers-1); |
473 | struct pipe_buffer *buf = pipe->bufs + newbuf; | 399 | struct pipe_buffer *buf = pipe->bufs + newbuf; |
474 | struct page *page = pipe->tmp_page; | 400 | struct page *page = pipe->tmp_page; |
475 | char *src; | 401 | int copied; |
476 | int error, atomic = 1; | ||
477 | 402 | ||
478 | if (!page) { | 403 | if (!page) { |
479 | page = alloc_page(GFP_HIGHUSER); | 404 | page = alloc_page(GFP_HIGHUSER); |
@@ -489,40 +414,19 @@ redo1: | |||
489 | * FIXME! Is this really true? | 414 | * FIXME! Is this really true? |
490 | */ | 415 | */ |
491 | do_wakeup = 1; | 416 | do_wakeup = 1; |
492 | chars = PAGE_SIZE; | 417 | copied = copy_page_from_iter(page, 0, PAGE_SIZE, from); |
493 | if (chars > total_len) | 418 | if (unlikely(copied < PAGE_SIZE && iov_iter_count(from))) { |
494 | chars = total_len; | ||
495 | |||
496 | iov_fault_in_pages_read(iov, chars); | ||
497 | redo2: | ||
498 | if (atomic) | ||
499 | src = kmap_atomic(page); | ||
500 | else | ||
501 | src = kmap(page); | ||
502 | |||
503 | error = pipe_iov_copy_from_user(src, iov, chars, | ||
504 | atomic); | ||
505 | if (atomic) | ||
506 | kunmap_atomic(src); | ||
507 | else | ||
508 | kunmap(page); | ||
509 | |||
510 | if (unlikely(error)) { | ||
511 | if (atomic) { | ||
512 | atomic = 0; | ||
513 | goto redo2; | ||
514 | } | ||
515 | if (!ret) | 419 | if (!ret) |
516 | ret = error; | 420 | ret = -EFAULT; |
517 | break; | 421 | break; |
518 | } | 422 | } |
519 | ret += chars; | 423 | ret += copied; |
520 | 424 | ||
521 | /* Insert it into the buffer array */ | 425 | /* Insert it into the buffer array */ |
522 | buf->page = page; | 426 | buf->page = page; |
523 | buf->ops = &anon_pipe_buf_ops; | 427 | buf->ops = &anon_pipe_buf_ops; |
524 | buf->offset = 0; | 428 | buf->offset = 0; |
525 | buf->len = chars; | 429 | buf->len = copied; |
526 | buf->flags = 0; | 430 | buf->flags = 0; |
527 | if (is_packetized(filp)) { | 431 | if (is_packetized(filp)) { |
528 | buf->ops = &packet_pipe_buf_ops; | 432 | buf->ops = &packet_pipe_buf_ops; |
@@ -531,8 +435,7 @@ redo2: | |||
531 | pipe->nrbufs = ++bufs; | 435 | pipe->nrbufs = ++bufs; |
532 | pipe->tmp_page = NULL; | 436 | pipe->tmp_page = NULL; |
533 | 437 | ||
534 | total_len -= chars; | 438 | if (!iov_iter_count(from)) |
535 | if (!total_len) | ||
536 | break; | 439 | break; |
537 | } | 440 | } |
538 | if (bufs < pipe->buffers) | 441 | if (bufs < pipe->buffers) |
@@ -1044,10 +947,10 @@ err: | |||
1044 | const struct file_operations pipefifo_fops = { | 947 | const struct file_operations pipefifo_fops = { |
1045 | .open = fifo_open, | 948 | .open = fifo_open, |
1046 | .llseek = no_llseek, | 949 | .llseek = no_llseek, |
1047 | .read = do_sync_read, | 950 | .read = new_sync_read, |
1048 | .aio_read = pipe_read, | 951 | .read_iter = pipe_read, |
1049 | .write = do_sync_write, | 952 | .write = new_sync_write, |
1050 | .aio_write = pipe_write, | 953 | .write_iter = pipe_write, |
1051 | .poll = pipe_poll, | 954 | .poll = pipe_poll, |
1052 | .unlocked_ioctl = pipe_ioctl, | 955 | .unlocked_ioctl = pipe_ioctl, |
1053 | .release = pipe_release, | 956 | .release = pipe_release, |
diff --git a/fs/ramfs/file-mmu.c b/fs/ramfs/file-mmu.c index 1e56a4e8cf7c..4f56de822d2f 100644 --- a/fs/ramfs/file-mmu.c +++ b/fs/ramfs/file-mmu.c | |||
@@ -31,14 +31,14 @@ | |||
31 | #include "internal.h" | 31 | #include "internal.h" |
32 | 32 | ||
33 | const struct file_operations ramfs_file_operations = { | 33 | const struct file_operations ramfs_file_operations = { |
34 | .read = do_sync_read, | 34 | .read = new_sync_read, |
35 | .aio_read = generic_file_aio_read, | 35 | .read_iter = generic_file_read_iter, |
36 | .write = do_sync_write, | 36 | .write = new_sync_write, |
37 | .aio_write = generic_file_aio_write, | 37 | .write_iter = generic_file_write_iter, |
38 | .mmap = generic_file_mmap, | 38 | .mmap = generic_file_mmap, |
39 | .fsync = noop_fsync, | 39 | .fsync = noop_fsync, |
40 | .splice_read = generic_file_splice_read, | 40 | .splice_read = generic_file_splice_read, |
41 | .splice_write = generic_file_splice_write, | 41 | .splice_write = iter_file_splice_write, |
42 | .llseek = generic_file_llseek, | 42 | .llseek = generic_file_llseek, |
43 | }; | 43 | }; |
44 | 44 | ||
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 0b3d8e4cb2fa..dda012ad4208 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c | |||
@@ -37,13 +37,13 @@ static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma); | |||
37 | const struct file_operations ramfs_file_operations = { | 37 | const struct file_operations ramfs_file_operations = { |
38 | .mmap = ramfs_nommu_mmap, | 38 | .mmap = ramfs_nommu_mmap, |
39 | .get_unmapped_area = ramfs_nommu_get_unmapped_area, | 39 | .get_unmapped_area = ramfs_nommu_get_unmapped_area, |
40 | .read = do_sync_read, | 40 | .read = new_sync_read, |
41 | .aio_read = generic_file_aio_read, | 41 | .read_iter = generic_file_read_iter, |
42 | .write = do_sync_write, | 42 | .write = new_sync_write, |
43 | .aio_write = generic_file_aio_write, | 43 | .write_iter = generic_file_write_iter, |
44 | .fsync = noop_fsync, | 44 | .fsync = noop_fsync, |
45 | .splice_read = generic_file_splice_read, | 45 | .splice_read = generic_file_splice_read, |
46 | .splice_write = generic_file_splice_write, | 46 | .splice_write = iter_file_splice_write, |
47 | .llseek = generic_file_llseek, | 47 | .llseek = generic_file_llseek, |
48 | }; | 48 | }; |
49 | 49 | ||
diff --git a/fs/read_write.c b/fs/read_write.c index 31c6efa43183..009d8542a889 100644 --- a/fs/read_write.c +++ b/fs/read_write.c | |||
@@ -25,11 +25,12 @@ | |||
25 | typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *); | 25 | typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *); |
26 | typedef ssize_t (*iov_fn_t)(struct kiocb *, const struct iovec *, | 26 | typedef ssize_t (*iov_fn_t)(struct kiocb *, const struct iovec *, |
27 | unsigned long, loff_t); | 27 | unsigned long, loff_t); |
28 | typedef ssize_t (*iter_fn_t)(struct kiocb *, struct iov_iter *); | ||
28 | 29 | ||
29 | const struct file_operations generic_ro_fops = { | 30 | const struct file_operations generic_ro_fops = { |
30 | .llseek = generic_file_llseek, | 31 | .llseek = generic_file_llseek, |
31 | .read = do_sync_read, | 32 | .read = new_sync_read, |
32 | .aio_read = generic_file_aio_read, | 33 | .read_iter = generic_file_read_iter, |
33 | .mmap = generic_file_readonly_mmap, | 34 | .mmap = generic_file_readonly_mmap, |
34 | .splice_read = generic_file_splice_read, | 35 | .splice_read = generic_file_splice_read, |
35 | }; | 36 | }; |
@@ -390,13 +391,34 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *pp | |||
390 | 391 | ||
391 | EXPORT_SYMBOL(do_sync_read); | 392 | EXPORT_SYMBOL(do_sync_read); |
392 | 393 | ||
394 | ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos) | ||
395 | { | ||
396 | struct iovec iov = { .iov_base = buf, .iov_len = len }; | ||
397 | struct kiocb kiocb; | ||
398 | struct iov_iter iter; | ||
399 | ssize_t ret; | ||
400 | |||
401 | init_sync_kiocb(&kiocb, filp); | ||
402 | kiocb.ki_pos = *ppos; | ||
403 | kiocb.ki_nbytes = len; | ||
404 | iov_iter_init(&iter, READ, &iov, 1, len); | ||
405 | |||
406 | ret = filp->f_op->read_iter(&kiocb, &iter); | ||
407 | if (-EIOCBQUEUED == ret) | ||
408 | ret = wait_on_sync_kiocb(&kiocb); | ||
409 | *ppos = kiocb.ki_pos; | ||
410 | return ret; | ||
411 | } | ||
412 | |||
413 | EXPORT_SYMBOL(new_sync_read); | ||
414 | |||
393 | ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) | 415 | ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) |
394 | { | 416 | { |
395 | ssize_t ret; | 417 | ssize_t ret; |
396 | 418 | ||
397 | if (!(file->f_mode & FMODE_READ)) | 419 | if (!(file->f_mode & FMODE_READ)) |
398 | return -EBADF; | 420 | return -EBADF; |
399 | if (!file->f_op->read && !file->f_op->aio_read) | 421 | if (!(file->f_mode & FMODE_CAN_READ)) |
400 | return -EINVAL; | 422 | return -EINVAL; |
401 | if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) | 423 | if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) |
402 | return -EFAULT; | 424 | return -EFAULT; |
@@ -406,8 +428,10 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) | |||
406 | count = ret; | 428 | count = ret; |
407 | if (file->f_op->read) | 429 | if (file->f_op->read) |
408 | ret = file->f_op->read(file, buf, count, pos); | 430 | ret = file->f_op->read(file, buf, count, pos); |
409 | else | 431 | else if (file->f_op->aio_read) |
410 | ret = do_sync_read(file, buf, count, pos); | 432 | ret = do_sync_read(file, buf, count, pos); |
433 | else | ||
434 | ret = new_sync_read(file, buf, count, pos); | ||
411 | if (ret > 0) { | 435 | if (ret > 0) { |
412 | fsnotify_access(file); | 436 | fsnotify_access(file); |
413 | add_rchar(current, ret); | 437 | add_rchar(current, ret); |
@@ -439,13 +463,34 @@ ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, lof | |||
439 | 463 | ||
440 | EXPORT_SYMBOL(do_sync_write); | 464 | EXPORT_SYMBOL(do_sync_write); |
441 | 465 | ||
466 | ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) | ||
467 | { | ||
468 | struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len }; | ||
469 | struct kiocb kiocb; | ||
470 | struct iov_iter iter; | ||
471 | ssize_t ret; | ||
472 | |||
473 | init_sync_kiocb(&kiocb, filp); | ||
474 | kiocb.ki_pos = *ppos; | ||
475 | kiocb.ki_nbytes = len; | ||
476 | iov_iter_init(&iter, WRITE, &iov, 1, len); | ||
477 | |||
478 | ret = filp->f_op->write_iter(&kiocb, &iter); | ||
479 | if (-EIOCBQUEUED == ret) | ||
480 | ret = wait_on_sync_kiocb(&kiocb); | ||
481 | *ppos = kiocb.ki_pos; | ||
482 | return ret; | ||
483 | } | ||
484 | |||
485 | EXPORT_SYMBOL(new_sync_write); | ||
486 | |||
442 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | 487 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) |
443 | { | 488 | { |
444 | mm_segment_t old_fs; | 489 | mm_segment_t old_fs; |
445 | const char __user *p; | 490 | const char __user *p; |
446 | ssize_t ret; | 491 | ssize_t ret; |
447 | 492 | ||
448 | if (!file->f_op->write && !file->f_op->aio_write) | 493 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
449 | return -EINVAL; | 494 | return -EINVAL; |
450 | 495 | ||
451 | old_fs = get_fs(); | 496 | old_fs = get_fs(); |
@@ -455,8 +500,10 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t | |||
455 | count = MAX_RW_COUNT; | 500 | count = MAX_RW_COUNT; |
456 | if (file->f_op->write) | 501 | if (file->f_op->write) |
457 | ret = file->f_op->write(file, p, count, pos); | 502 | ret = file->f_op->write(file, p, count, pos); |
458 | else | 503 | else if (file->f_op->aio_write) |
459 | ret = do_sync_write(file, p, count, pos); | 504 | ret = do_sync_write(file, p, count, pos); |
505 | else | ||
506 | ret = new_sync_write(file, p, count, pos); | ||
460 | set_fs(old_fs); | 507 | set_fs(old_fs); |
461 | if (ret > 0) { | 508 | if (ret > 0) { |
462 | fsnotify_modify(file); | 509 | fsnotify_modify(file); |
@@ -472,7 +519,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ | |||
472 | 519 | ||
473 | if (!(file->f_mode & FMODE_WRITE)) | 520 | if (!(file->f_mode & FMODE_WRITE)) |
474 | return -EBADF; | 521 | return -EBADF; |
475 | if (!file->f_op->write && !file->f_op->aio_write) | 522 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
476 | return -EINVAL; | 523 | return -EINVAL; |
477 | if (unlikely(!access_ok(VERIFY_READ, buf, count))) | 524 | if (unlikely(!access_ok(VERIFY_READ, buf, count))) |
478 | return -EFAULT; | 525 | return -EFAULT; |
@@ -483,8 +530,10 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ | |||
483 | file_start_write(file); | 530 | file_start_write(file); |
484 | if (file->f_op->write) | 531 | if (file->f_op->write) |
485 | ret = file->f_op->write(file, buf, count, pos); | 532 | ret = file->f_op->write(file, buf, count, pos); |
486 | else | 533 | else if (file->f_op->aio_write) |
487 | ret = do_sync_write(file, buf, count, pos); | 534 | ret = do_sync_write(file, buf, count, pos); |
535 | else | ||
536 | ret = new_sync_write(file, buf, count, pos); | ||
488 | if (ret > 0) { | 537 | if (ret > 0) { |
489 | fsnotify_modify(file); | 538 | fsnotify_modify(file); |
490 | add_wchar(current, ret); | 539 | add_wchar(current, ret); |
@@ -601,6 +650,25 @@ unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to) | |||
601 | } | 650 | } |
602 | EXPORT_SYMBOL(iov_shorten); | 651 | EXPORT_SYMBOL(iov_shorten); |
603 | 652 | ||
653 | static ssize_t do_iter_readv_writev(struct file *filp, int rw, const struct iovec *iov, | ||
654 | unsigned long nr_segs, size_t len, loff_t *ppos, iter_fn_t fn) | ||
655 | { | ||
656 | struct kiocb kiocb; | ||
657 | struct iov_iter iter; | ||
658 | ssize_t ret; | ||
659 | |||
660 | init_sync_kiocb(&kiocb, filp); | ||
661 | kiocb.ki_pos = *ppos; | ||
662 | kiocb.ki_nbytes = len; | ||
663 | |||
664 | iov_iter_init(&iter, rw, iov, nr_segs, len); | ||
665 | ret = fn(&kiocb, &iter); | ||
666 | if (ret == -EIOCBQUEUED) | ||
667 | ret = wait_on_sync_kiocb(&kiocb); | ||
668 | *ppos = kiocb.ki_pos; | ||
669 | return ret; | ||
670 | } | ||
671 | |||
604 | static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov, | 672 | static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov, |
605 | unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn) | 673 | unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn) |
606 | { | 674 | { |
@@ -738,6 +806,7 @@ static ssize_t do_readv_writev(int type, struct file *file, | |||
738 | ssize_t ret; | 806 | ssize_t ret; |
739 | io_fn_t fn; | 807 | io_fn_t fn; |
740 | iov_fn_t fnv; | 808 | iov_fn_t fnv; |
809 | iter_fn_t iter_fn; | ||
741 | 810 | ||
742 | ret = rw_copy_check_uvector(type, uvector, nr_segs, | 811 | ret = rw_copy_check_uvector(type, uvector, nr_segs, |
743 | ARRAY_SIZE(iovstack), iovstack, &iov); | 812 | ARRAY_SIZE(iovstack), iovstack, &iov); |
@@ -753,13 +822,18 @@ static ssize_t do_readv_writev(int type, struct file *file, | |||
753 | if (type == READ) { | 822 | if (type == READ) { |
754 | fn = file->f_op->read; | 823 | fn = file->f_op->read; |
755 | fnv = file->f_op->aio_read; | 824 | fnv = file->f_op->aio_read; |
825 | iter_fn = file->f_op->read_iter; | ||
756 | } else { | 826 | } else { |
757 | fn = (io_fn_t)file->f_op->write; | 827 | fn = (io_fn_t)file->f_op->write; |
758 | fnv = file->f_op->aio_write; | 828 | fnv = file->f_op->aio_write; |
829 | iter_fn = file->f_op->write_iter; | ||
759 | file_start_write(file); | 830 | file_start_write(file); |
760 | } | 831 | } |
761 | 832 | ||
762 | if (fnv) | 833 | if (iter_fn) |
834 | ret = do_iter_readv_writev(file, type, iov, nr_segs, tot_len, | ||
835 | pos, iter_fn); | ||
836 | else if (fnv) | ||
763 | ret = do_sync_readv_writev(file, iov, nr_segs, tot_len, | 837 | ret = do_sync_readv_writev(file, iov, nr_segs, tot_len, |
764 | pos, fnv); | 838 | pos, fnv); |
765 | else | 839 | else |
@@ -785,7 +859,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, | |||
785 | { | 859 | { |
786 | if (!(file->f_mode & FMODE_READ)) | 860 | if (!(file->f_mode & FMODE_READ)) |
787 | return -EBADF; | 861 | return -EBADF; |
788 | if (!file->f_op->aio_read && !file->f_op->read) | 862 | if (!(file->f_mode & FMODE_CAN_READ)) |
789 | return -EINVAL; | 863 | return -EINVAL; |
790 | 864 | ||
791 | return do_readv_writev(READ, file, vec, vlen, pos); | 865 | return do_readv_writev(READ, file, vec, vlen, pos); |
@@ -798,7 +872,7 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, | |||
798 | { | 872 | { |
799 | if (!(file->f_mode & FMODE_WRITE)) | 873 | if (!(file->f_mode & FMODE_WRITE)) |
800 | return -EBADF; | 874 | return -EBADF; |
801 | if (!file->f_op->aio_write && !file->f_op->write) | 875 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
802 | return -EINVAL; | 876 | return -EINVAL; |
803 | 877 | ||
804 | return do_readv_writev(WRITE, file, vec, vlen, pos); | 878 | return do_readv_writev(WRITE, file, vec, vlen, pos); |
@@ -912,6 +986,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file, | |||
912 | ssize_t ret; | 986 | ssize_t ret; |
913 | io_fn_t fn; | 987 | io_fn_t fn; |
914 | iov_fn_t fnv; | 988 | iov_fn_t fnv; |
989 | iter_fn_t iter_fn; | ||
915 | 990 | ||
916 | ret = compat_rw_copy_check_uvector(type, uvector, nr_segs, | 991 | ret = compat_rw_copy_check_uvector(type, uvector, nr_segs, |
917 | UIO_FASTIOV, iovstack, &iov); | 992 | UIO_FASTIOV, iovstack, &iov); |
@@ -927,13 +1002,18 @@ static ssize_t compat_do_readv_writev(int type, struct file *file, | |||
927 | if (type == READ) { | 1002 | if (type == READ) { |
928 | fn = file->f_op->read; | 1003 | fn = file->f_op->read; |
929 | fnv = file->f_op->aio_read; | 1004 | fnv = file->f_op->aio_read; |
1005 | iter_fn = file->f_op->read_iter; | ||
930 | } else { | 1006 | } else { |
931 | fn = (io_fn_t)file->f_op->write; | 1007 | fn = (io_fn_t)file->f_op->write; |
932 | fnv = file->f_op->aio_write; | 1008 | fnv = file->f_op->aio_write; |
1009 | iter_fn = file->f_op->write_iter; | ||
933 | file_start_write(file); | 1010 | file_start_write(file); |
934 | } | 1011 | } |
935 | 1012 | ||
936 | if (fnv) | 1013 | if (iter_fn) |
1014 | ret = do_iter_readv_writev(file, type, iov, nr_segs, tot_len, | ||
1015 | pos, iter_fn); | ||
1016 | else if (fnv) | ||
937 | ret = do_sync_readv_writev(file, iov, nr_segs, tot_len, | 1017 | ret = do_sync_readv_writev(file, iov, nr_segs, tot_len, |
938 | pos, fnv); | 1018 | pos, fnv); |
939 | else | 1019 | else |
@@ -964,7 +1044,7 @@ static size_t compat_readv(struct file *file, | |||
964 | goto out; | 1044 | goto out; |
965 | 1045 | ||
966 | ret = -EINVAL; | 1046 | ret = -EINVAL; |
967 | if (!file->f_op->aio_read && !file->f_op->read) | 1047 | if (!(file->f_mode & FMODE_CAN_READ)) |
968 | goto out; | 1048 | goto out; |
969 | 1049 | ||
970 | ret = compat_do_readv_writev(READ, file, vec, vlen, pos); | 1050 | ret = compat_do_readv_writev(READ, file, vec, vlen, pos); |
@@ -1041,7 +1121,7 @@ static size_t compat_writev(struct file *file, | |||
1041 | goto out; | 1121 | goto out; |
1042 | 1122 | ||
1043 | ret = -EINVAL; | 1123 | ret = -EINVAL; |
1044 | if (!file->f_op->aio_write && !file->f_op->write) | 1124 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
1045 | goto out; | 1125 | goto out; |
1046 | 1126 | ||
1047 | ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); | 1127 | ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); |
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c index 5f6c32c668b6..db9e80ba53a0 100644 --- a/fs/reiserfs/file.c +++ b/fs/reiserfs/file.c | |||
@@ -243,8 +243,8 @@ drop_write_lock: | |||
243 | } | 243 | } |
244 | 244 | ||
245 | const struct file_operations reiserfs_file_operations = { | 245 | const struct file_operations reiserfs_file_operations = { |
246 | .read = do_sync_read, | 246 | .read = new_sync_read, |
247 | .write = do_sync_write, | 247 | .write = new_sync_write, |
248 | .unlocked_ioctl = reiserfs_ioctl, | 248 | .unlocked_ioctl = reiserfs_ioctl, |
249 | #ifdef CONFIG_COMPAT | 249 | #ifdef CONFIG_COMPAT |
250 | .compat_ioctl = reiserfs_compat_ioctl, | 250 | .compat_ioctl = reiserfs_compat_ioctl, |
@@ -253,10 +253,10 @@ const struct file_operations reiserfs_file_operations = { | |||
253 | .open = reiserfs_file_open, | 253 | .open = reiserfs_file_open, |
254 | .release = reiserfs_file_release, | 254 | .release = reiserfs_file_release, |
255 | .fsync = reiserfs_sync_file, | 255 | .fsync = reiserfs_sync_file, |
256 | .aio_read = generic_file_aio_read, | 256 | .read_iter = generic_file_read_iter, |
257 | .aio_write = generic_file_aio_write, | 257 | .write_iter = generic_file_write_iter, |
258 | .splice_read = generic_file_splice_read, | 258 | .splice_read = generic_file_splice_read, |
259 | .splice_write = generic_file_splice_write, | 259 | .splice_write = iter_file_splice_write, |
260 | .llseek = generic_file_llseek, | 260 | .llseek = generic_file_llseek, |
261 | }; | 261 | }; |
262 | 262 | ||
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index e3ca04894919..63b2b0ec49e6 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c | |||
@@ -3279,15 +3279,15 @@ static int reiserfs_releasepage(struct page *page, gfp_t unused_gfp_flags) | |||
3279 | * to do in this section of the code. | 3279 | * to do in this section of the code. |
3280 | */ | 3280 | */ |
3281 | static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, | 3281 | static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, |
3282 | const struct iovec *iov, loff_t offset, | 3282 | struct iov_iter *iter, loff_t offset) |
3283 | unsigned long nr_segs) | ||
3284 | { | 3283 | { |
3285 | struct file *file = iocb->ki_filp; | 3284 | struct file *file = iocb->ki_filp; |
3286 | struct inode *inode = file->f_mapping->host; | 3285 | struct inode *inode = file->f_mapping->host; |
3286 | size_t count = iov_iter_count(iter); | ||
3287 | ssize_t ret; | 3287 | ssize_t ret; |
3288 | 3288 | ||
3289 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 3289 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, |
3290 | reiserfs_get_blocks_direct_io); | 3290 | reiserfs_get_blocks_direct_io); |
3291 | 3291 | ||
3292 | /* | 3292 | /* |
3293 | * In case of error extending write may have instantiated a few | 3293 | * In case of error extending write may have instantiated a few |
@@ -3295,7 +3295,7 @@ static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, | |||
3295 | */ | 3295 | */ |
3296 | if (unlikely((rw & WRITE) && ret < 0)) { | 3296 | if (unlikely((rw & WRITE) && ret < 0)) { |
3297 | loff_t isize = i_size_read(inode); | 3297 | loff_t isize = i_size_read(inode); |
3298 | loff_t end = offset + iov_length(iov, nr_segs); | 3298 | loff_t end = offset + count; |
3299 | 3299 | ||
3300 | if ((end > isize) && inode_newsize_ok(inode, isize) == 0) { | 3300 | if ((end > isize) && inode_newsize_ok(inode, isize) == 0) { |
3301 | truncate_setsize(inode, isize); | 3301 | truncate_setsize(inode, isize); |
diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c index f373bde8f545..ea06c7554860 100644 --- a/fs/romfs/mmap-nommu.c +++ b/fs/romfs/mmap-nommu.c | |||
@@ -72,8 +72,8 @@ static int romfs_mmap(struct file *file, struct vm_area_struct *vma) | |||
72 | 72 | ||
73 | const struct file_operations romfs_ro_fops = { | 73 | const struct file_operations romfs_ro_fops = { |
74 | .llseek = generic_file_llseek, | 74 | .llseek = generic_file_llseek, |
75 | .read = do_sync_read, | 75 | .read = new_sync_read, |
76 | .aio_read = generic_file_aio_read, | 76 | .read_iter = generic_file_read_iter, |
77 | .splice_read = generic_file_splice_read, | 77 | .splice_read = generic_file_splice_read, |
78 | .mmap = romfs_mmap, | 78 | .mmap = romfs_mmap, |
79 | .get_unmapped_area = romfs_get_unmapped_area, | 79 | .get_unmapped_area = romfs_get_unmapped_area, |
diff --git a/fs/splice.c b/fs/splice.c index e246954ea48c..f5cb9ba84510 100644 --- a/fs/splice.c +++ b/fs/splice.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/gfp.h> | 32 | #include <linux/gfp.h> |
33 | #include <linux/socket.h> | 33 | #include <linux/socket.h> |
34 | #include <linux/compat.h> | 34 | #include <linux/compat.h> |
35 | #include <linux/aio.h> | ||
35 | #include "internal.h" | 36 | #include "internal.h" |
36 | 37 | ||
37 | /* | 38 | /* |
@@ -717,63 +718,6 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe, | |||
717 | sd->len, &pos, more); | 718 | sd->len, &pos, more); |
718 | } | 719 | } |
719 | 720 | ||
720 | /* | ||
721 | * This is a little more tricky than the file -> pipe splicing. There are | ||
722 | * basically three cases: | ||
723 | * | ||
724 | * - Destination page already exists in the address space and there | ||
725 | * are users of it. For that case we have no other option that | ||
726 | * copying the data. Tough luck. | ||
727 | * - Destination page already exists in the address space, but there | ||
728 | * are no users of it. Make sure it's uptodate, then drop it. Fall | ||
729 | * through to last case. | ||
730 | * - Destination page does not exist, we can add the pipe page to | ||
731 | * the page cache and avoid the copy. | ||
732 | * | ||
733 | * If asked to move pages to the output file (SPLICE_F_MOVE is set in | ||
734 | * sd->flags), we attempt to migrate pages from the pipe to the output | ||
735 | * file address space page cache. This is possible if no one else has | ||
736 | * the pipe page referenced outside of the pipe and page cache. If | ||
737 | * SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create | ||
738 | * a new page in the output file page cache and fill/dirty that. | ||
739 | */ | ||
740 | int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf, | ||
741 | struct splice_desc *sd) | ||
742 | { | ||
743 | struct file *file = sd->u.file; | ||
744 | struct address_space *mapping = file->f_mapping; | ||
745 | unsigned int offset, this_len; | ||
746 | struct page *page; | ||
747 | void *fsdata; | ||
748 | int ret; | ||
749 | |||
750 | offset = sd->pos & ~PAGE_CACHE_MASK; | ||
751 | |||
752 | this_len = sd->len; | ||
753 | if (this_len + offset > PAGE_CACHE_SIZE) | ||
754 | this_len = PAGE_CACHE_SIZE - offset; | ||
755 | |||
756 | ret = pagecache_write_begin(file, mapping, sd->pos, this_len, | ||
757 | AOP_FLAG_UNINTERRUPTIBLE, &page, &fsdata); | ||
758 | if (unlikely(ret)) | ||
759 | goto out; | ||
760 | |||
761 | if (buf->page != page) { | ||
762 | char *src = kmap_atomic(buf->page); | ||
763 | char *dst = kmap_atomic(page); | ||
764 | |||
765 | memcpy(dst + offset, src + buf->offset, this_len); | ||
766 | flush_dcache_page(page); | ||
767 | kunmap_atomic(dst); | ||
768 | kunmap_atomic(src); | ||
769 | } | ||
770 | ret = pagecache_write_end(file, mapping, sd->pos, this_len, this_len, | ||
771 | page, fsdata); | ||
772 | out: | ||
773 | return ret; | ||
774 | } | ||
775 | EXPORT_SYMBOL(pipe_to_file); | ||
776 | |||
777 | static void wakeup_pipe_writers(struct pipe_inode_info *pipe) | 721 | static void wakeup_pipe_writers(struct pipe_inode_info *pipe) |
778 | { | 722 | { |
779 | smp_mb(); | 723 | smp_mb(); |
@@ -802,7 +746,7 @@ static void wakeup_pipe_writers(struct pipe_inode_info *pipe) | |||
802 | * locking is required around copying the pipe buffers to the | 746 | * locking is required around copying the pipe buffers to the |
803 | * destination. | 747 | * destination. |
804 | */ | 748 | */ |
805 | int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, | 749 | static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, |
806 | splice_actor *actor) | 750 | splice_actor *actor) |
807 | { | 751 | { |
808 | int ret; | 752 | int ret; |
@@ -849,7 +793,6 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, | |||
849 | 793 | ||
850 | return 1; | 794 | return 1; |
851 | } | 795 | } |
852 | EXPORT_SYMBOL(splice_from_pipe_feed); | ||
853 | 796 | ||
854 | /** | 797 | /** |
855 | * splice_from_pipe_next - wait for some data to splice from | 798 | * splice_from_pipe_next - wait for some data to splice from |
@@ -861,7 +804,7 @@ EXPORT_SYMBOL(splice_from_pipe_feed); | |||
861 | * value (one) if pipe buffers are available. It will return zero | 804 | * value (one) if pipe buffers are available. It will return zero |
862 | * or -errno if no more data needs to be spliced. | 805 | * or -errno if no more data needs to be spliced. |
863 | */ | 806 | */ |
864 | int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) | 807 | static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) |
865 | { | 808 | { |
866 | while (!pipe->nrbufs) { | 809 | while (!pipe->nrbufs) { |
867 | if (!pipe->writers) | 810 | if (!pipe->writers) |
@@ -886,7 +829,6 @@ int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) | |||
886 | 829 | ||
887 | return 1; | 830 | return 1; |
888 | } | 831 | } |
889 | EXPORT_SYMBOL(splice_from_pipe_next); | ||
890 | 832 | ||
891 | /** | 833 | /** |
892 | * splice_from_pipe_begin - start splicing from pipe | 834 | * splice_from_pipe_begin - start splicing from pipe |
@@ -897,12 +839,11 @@ EXPORT_SYMBOL(splice_from_pipe_next); | |||
897 | * splice_from_pipe_next() and splice_from_pipe_feed() to | 839 | * splice_from_pipe_next() and splice_from_pipe_feed() to |
898 | * initialize the necessary fields of @sd. | 840 | * initialize the necessary fields of @sd. |
899 | */ | 841 | */ |
900 | void splice_from_pipe_begin(struct splice_desc *sd) | 842 | static void splice_from_pipe_begin(struct splice_desc *sd) |
901 | { | 843 | { |
902 | sd->num_spliced = 0; | 844 | sd->num_spliced = 0; |
903 | sd->need_wakeup = false; | 845 | sd->need_wakeup = false; |
904 | } | 846 | } |
905 | EXPORT_SYMBOL(splice_from_pipe_begin); | ||
906 | 847 | ||
907 | /** | 848 | /** |
908 | * splice_from_pipe_end - finish splicing from pipe | 849 | * splice_from_pipe_end - finish splicing from pipe |
@@ -914,12 +855,11 @@ EXPORT_SYMBOL(splice_from_pipe_begin); | |||
914 | * be called after a loop containing splice_from_pipe_next() and | 855 | * be called after a loop containing splice_from_pipe_next() and |
915 | * splice_from_pipe_feed(). | 856 | * splice_from_pipe_feed(). |
916 | */ | 857 | */ |
917 | void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) | 858 | static void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) |
918 | { | 859 | { |
919 | if (sd->need_wakeup) | 860 | if (sd->need_wakeup) |
920 | wakeup_pipe_writers(pipe); | 861 | wakeup_pipe_writers(pipe); |
921 | } | 862 | } |
922 | EXPORT_SYMBOL(splice_from_pipe_end); | ||
923 | 863 | ||
924 | /** | 864 | /** |
925 | * __splice_from_pipe - splice data from a pipe to given actor | 865 | * __splice_from_pipe - splice data from a pipe to given actor |
@@ -985,7 +925,7 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, | |||
985 | } | 925 | } |
986 | 926 | ||
987 | /** | 927 | /** |
988 | * generic_file_splice_write - splice data from a pipe to a file | 928 | * iter_file_splice_write - splice data from a pipe to a file |
989 | * @pipe: pipe info | 929 | * @pipe: pipe info |
990 | * @out: file to write to | 930 | * @out: file to write to |
991 | * @ppos: position in @out | 931 | * @ppos: position in @out |
@@ -995,40 +935,122 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, | |||
995 | * Description: | 935 | * Description: |
996 | * Will either move or copy pages (determined by @flags options) from | 936 | * Will either move or copy pages (determined by @flags options) from |
997 | * the given pipe inode to the given file. | 937 | * the given pipe inode to the given file. |
938 | * This one is ->write_iter-based. | ||
998 | * | 939 | * |
999 | */ | 940 | */ |
1000 | ssize_t | 941 | ssize_t |
1001 | generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out, | 942 | iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, |
1002 | loff_t *ppos, size_t len, unsigned int flags) | 943 | loff_t *ppos, size_t len, unsigned int flags) |
1003 | { | 944 | { |
1004 | struct address_space *mapping = out->f_mapping; | ||
1005 | struct inode *inode = mapping->host; | ||
1006 | struct splice_desc sd = { | 945 | struct splice_desc sd = { |
1007 | .total_len = len, | 946 | .total_len = len, |
1008 | .flags = flags, | 947 | .flags = flags, |
1009 | .pos = *ppos, | 948 | .pos = *ppos, |
1010 | .u.file = out, | 949 | .u.file = out, |
1011 | }; | 950 | }; |
951 | int nbufs = pipe->buffers; | ||
952 | struct bio_vec *array = kcalloc(nbufs, sizeof(struct bio_vec), | ||
953 | GFP_KERNEL); | ||
1012 | ssize_t ret; | 954 | ssize_t ret; |
1013 | 955 | ||
956 | if (unlikely(!array)) | ||
957 | return -ENOMEM; | ||
958 | |||
1014 | pipe_lock(pipe); | 959 | pipe_lock(pipe); |
1015 | 960 | ||
1016 | splice_from_pipe_begin(&sd); | 961 | splice_from_pipe_begin(&sd); |
1017 | do { | 962 | while (sd.total_len) { |
963 | struct iov_iter from; | ||
964 | struct kiocb kiocb; | ||
965 | size_t left; | ||
966 | int n, idx; | ||
967 | |||
1018 | ret = splice_from_pipe_next(pipe, &sd); | 968 | ret = splice_from_pipe_next(pipe, &sd); |
1019 | if (ret <= 0) | 969 | if (ret <= 0) |
1020 | break; | 970 | break; |
1021 | 971 | ||
1022 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); | 972 | if (unlikely(nbufs < pipe->buffers)) { |
1023 | ret = file_remove_suid(out); | 973 | kfree(array); |
1024 | if (!ret) { | 974 | nbufs = pipe->buffers; |
1025 | ret = file_update_time(out); | 975 | array = kcalloc(nbufs, sizeof(struct bio_vec), |
1026 | if (!ret) | 976 | GFP_KERNEL); |
1027 | ret = splice_from_pipe_feed(pipe, &sd, | 977 | if (!array) { |
1028 | pipe_to_file); | 978 | ret = -ENOMEM; |
979 | break; | ||
980 | } | ||
1029 | } | 981 | } |
1030 | mutex_unlock(&inode->i_mutex); | 982 | |
1031 | } while (ret > 0); | 983 | /* build the vector */ |
984 | left = sd.total_len; | ||
985 | for (n = 0, idx = pipe->curbuf; left && n < pipe->nrbufs; n++, idx++) { | ||
986 | struct pipe_buffer *buf = pipe->bufs + idx; | ||
987 | size_t this_len = buf->len; | ||
988 | |||
989 | if (this_len > left) | ||
990 | this_len = left; | ||
991 | |||
992 | if (idx == pipe->buffers - 1) | ||
993 | idx = -1; | ||
994 | |||
995 | ret = buf->ops->confirm(pipe, buf); | ||
996 | if (unlikely(ret)) { | ||
997 | if (ret == -ENODATA) | ||
998 | ret = 0; | ||
999 | goto done; | ||
1000 | } | ||
1001 | |||
1002 | array[n].bv_page = buf->page; | ||
1003 | array[n].bv_len = this_len; | ||
1004 | array[n].bv_offset = buf->offset; | ||
1005 | left -= this_len; | ||
1006 | } | ||
1007 | |||
1008 | /* ... iov_iter */ | ||
1009 | from.type = ITER_BVEC | WRITE; | ||
1010 | from.bvec = array; | ||
1011 | from.nr_segs = n; | ||
1012 | from.count = sd.total_len - left; | ||
1013 | from.iov_offset = 0; | ||
1014 | |||
1015 | /* ... and iocb */ | ||
1016 | init_sync_kiocb(&kiocb, out); | ||
1017 | kiocb.ki_pos = sd.pos; | ||
1018 | kiocb.ki_nbytes = sd.total_len - left; | ||
1019 | |||
1020 | /* now, send it */ | ||
1021 | ret = out->f_op->write_iter(&kiocb, &from); | ||
1022 | if (-EIOCBQUEUED == ret) | ||
1023 | ret = wait_on_sync_kiocb(&kiocb); | ||
1024 | |||
1025 | if (ret <= 0) | ||
1026 | break; | ||
1027 | |||
1028 | sd.num_spliced += ret; | ||
1029 | sd.total_len -= ret; | ||
1030 | *ppos = sd.pos = kiocb.ki_pos; | ||
1031 | |||
1032 | /* dismiss the fully eaten buffers, adjust the partial one */ | ||
1033 | while (ret) { | ||
1034 | struct pipe_buffer *buf = pipe->bufs + pipe->curbuf; | ||
1035 | if (ret >= buf->len) { | ||
1036 | const struct pipe_buf_operations *ops = buf->ops; | ||
1037 | ret -= buf->len; | ||
1038 | buf->len = 0; | ||
1039 | buf->ops = NULL; | ||
1040 | ops->release(pipe, buf); | ||
1041 | pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1); | ||
1042 | pipe->nrbufs--; | ||
1043 | if (pipe->files) | ||
1044 | sd.need_wakeup = true; | ||
1045 | } else { | ||
1046 | buf->offset += ret; | ||
1047 | buf->len -= ret; | ||
1048 | ret = 0; | ||
1049 | } | ||
1050 | } | ||
1051 | } | ||
1052 | done: | ||
1053 | kfree(array); | ||
1032 | splice_from_pipe_end(pipe, &sd); | 1054 | splice_from_pipe_end(pipe, &sd); |
1033 | 1055 | ||
1034 | pipe_unlock(pipe); | 1056 | pipe_unlock(pipe); |
@@ -1036,21 +1058,10 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out, | |||
1036 | if (sd.num_spliced) | 1058 | if (sd.num_spliced) |
1037 | ret = sd.num_spliced; | 1059 | ret = sd.num_spliced; |
1038 | 1060 | ||
1039 | if (ret > 0) { | ||
1040 | int err; | ||
1041 | |||
1042 | err = generic_write_sync(out, *ppos, ret); | ||
1043 | if (err) | ||
1044 | ret = err; | ||
1045 | else | ||
1046 | *ppos += ret; | ||
1047 | balance_dirty_pages_ratelimited(mapping); | ||
1048 | } | ||
1049 | |||
1050 | return ret; | 1061 | return ret; |
1051 | } | 1062 | } |
1052 | 1063 | ||
1053 | EXPORT_SYMBOL(generic_file_splice_write); | 1064 | EXPORT_SYMBOL(iter_file_splice_write); |
1054 | 1065 | ||
1055 | static int write_pipe_buf(struct pipe_inode_info *pipe, struct pipe_buffer *buf, | 1066 | static int write_pipe_buf(struct pipe_inode_info *pipe, struct pipe_buffer *buf, |
1056 | struct splice_desc *sd) | 1067 | struct splice_desc *sd) |
@@ -1549,7 +1560,7 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *uiov, | |||
1549 | goto out; | 1560 | goto out; |
1550 | 1561 | ||
1551 | count = ret; | 1562 | count = ret; |
1552 | iov_iter_init(&iter, iov, nr_segs, count, 0); | 1563 | iov_iter_init(&iter, READ, iov, nr_segs, count); |
1553 | 1564 | ||
1554 | sd.len = 0; | 1565 | sd.len = 0; |
1555 | sd.total_len = count; | 1566 | sd.total_len = count; |
diff --git a/fs/sysv/file.c b/fs/sysv/file.c index 9d4dc6831792..b00811c75b24 100644 --- a/fs/sysv/file.c +++ b/fs/sysv/file.c | |||
@@ -21,10 +21,10 @@ | |||
21 | */ | 21 | */ |
22 | const struct file_operations sysv_file_operations = { | 22 | const struct file_operations sysv_file_operations = { |
23 | .llseek = generic_file_llseek, | 23 | .llseek = generic_file_llseek, |
24 | .read = do_sync_read, | 24 | .read = new_sync_read, |
25 | .aio_read = generic_file_aio_read, | 25 | .read_iter = generic_file_read_iter, |
26 | .write = do_sync_write, | 26 | .write = new_sync_write, |
27 | .aio_write = generic_file_aio_write, | 27 | .write_iter = generic_file_write_iter, |
28 | .mmap = generic_file_mmap, | 28 | .mmap = generic_file_mmap, |
29 | .fsync = generic_file_fsync, | 29 | .fsync = generic_file_fsync, |
30 | .splice_read = generic_file_splice_read, | 30 | .splice_read = generic_file_splice_read, |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 0ab7f7dfb98b..b5b593c45270 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -1364,17 +1364,17 @@ static inline int mctime_update_needed(const struct inode *inode, | |||
1364 | 1364 | ||
1365 | /** | 1365 | /** |
1366 | * update_ctime - update mtime and ctime of an inode. | 1366 | * update_ctime - update mtime and ctime of an inode. |
1367 | * @c: UBIFS file-system description object | ||
1368 | * @inode: inode to update | 1367 | * @inode: inode to update |
1369 | * | 1368 | * |
1370 | * This function updates mtime and ctime of the inode if it is not equivalent to | 1369 | * This function updates mtime and ctime of the inode if it is not equivalent to |
1371 | * current time. Returns zero in case of success and a negative error code in | 1370 | * current time. Returns zero in case of success and a negative error code in |
1372 | * case of failure. | 1371 | * case of failure. |
1373 | */ | 1372 | */ |
1374 | static int update_mctime(struct ubifs_info *c, struct inode *inode) | 1373 | static int update_mctime(struct inode *inode) |
1375 | { | 1374 | { |
1376 | struct timespec now = ubifs_current_time(inode); | 1375 | struct timespec now = ubifs_current_time(inode); |
1377 | struct ubifs_inode *ui = ubifs_inode(inode); | 1376 | struct ubifs_inode *ui = ubifs_inode(inode); |
1377 | struct ubifs_info *c = inode->i_sb->s_fs_info; | ||
1378 | 1378 | ||
1379 | if (mctime_update_needed(inode, &now)) { | 1379 | if (mctime_update_needed(inode, &now)) { |
1380 | int err, release; | 1380 | int err, release; |
@@ -1397,18 +1397,13 @@ static int update_mctime(struct ubifs_info *c, struct inode *inode) | |||
1397 | return 0; | 1397 | return 0; |
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | static ssize_t ubifs_aio_write(struct kiocb *iocb, const struct iovec *iov, | 1400 | static ssize_t ubifs_write_iter(struct kiocb *iocb, struct iov_iter *from) |
1401 | unsigned long nr_segs, loff_t pos) | ||
1402 | { | 1401 | { |
1403 | int err; | 1402 | int err = update_mctime(file_inode(iocb->ki_filp)); |
1404 | struct inode *inode = iocb->ki_filp->f_mapping->host; | ||
1405 | struct ubifs_info *c = inode->i_sb->s_fs_info; | ||
1406 | |||
1407 | err = update_mctime(c, inode); | ||
1408 | if (err) | 1403 | if (err) |
1409 | return err; | 1404 | return err; |
1410 | 1405 | ||
1411 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | 1406 | return generic_file_write_iter(iocb, from); |
1412 | } | 1407 | } |
1413 | 1408 | ||
1414 | static int ubifs_set_page_dirty(struct page *page) | 1409 | static int ubifs_set_page_dirty(struct page *page) |
@@ -1582,15 +1577,15 @@ const struct inode_operations ubifs_symlink_inode_operations = { | |||
1582 | 1577 | ||
1583 | const struct file_operations ubifs_file_operations = { | 1578 | const struct file_operations ubifs_file_operations = { |
1584 | .llseek = generic_file_llseek, | 1579 | .llseek = generic_file_llseek, |
1585 | .read = do_sync_read, | 1580 | .read = new_sync_read, |
1586 | .write = do_sync_write, | 1581 | .write = new_sync_write, |
1587 | .aio_read = generic_file_aio_read, | 1582 | .read_iter = generic_file_read_iter, |
1588 | .aio_write = ubifs_aio_write, | 1583 | .write_iter = ubifs_write_iter, |
1589 | .mmap = ubifs_file_mmap, | 1584 | .mmap = ubifs_file_mmap, |
1590 | .fsync = ubifs_fsync, | 1585 | .fsync = ubifs_fsync, |
1591 | .unlocked_ioctl = ubifs_ioctl, | 1586 | .unlocked_ioctl = ubifs_ioctl, |
1592 | .splice_read = generic_file_splice_read, | 1587 | .splice_read = generic_file_splice_read, |
1593 | .splice_write = generic_file_splice_write, | 1588 | .splice_write = iter_file_splice_write, |
1594 | #ifdef CONFIG_COMPAT | 1589 | #ifdef CONFIG_COMPAT |
1595 | .compat_ioctl = ubifs_compat_ioctl, | 1590 | .compat_ioctl = ubifs_compat_ioctl, |
1596 | #endif | 1591 | #endif |
diff --git a/fs/udf/file.c b/fs/udf/file.c index d2c170f8b035..d80738fdf424 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c | |||
@@ -119,8 +119,8 @@ static int udf_adinicb_write_end(struct file *file, | |||
119 | } | 119 | } |
120 | 120 | ||
121 | static ssize_t udf_adinicb_direct_IO(int rw, struct kiocb *iocb, | 121 | static ssize_t udf_adinicb_direct_IO(int rw, struct kiocb *iocb, |
122 | const struct iovec *iov, | 122 | struct iov_iter *iter, |
123 | loff_t offset, unsigned long nr_segs) | 123 | loff_t offset) |
124 | { | 124 | { |
125 | /* Fallback to buffered I/O. */ | 125 | /* Fallback to buffered I/O. */ |
126 | return 0; | 126 | return 0; |
@@ -134,8 +134,7 @@ const struct address_space_operations udf_adinicb_aops = { | |||
134 | .direct_IO = udf_adinicb_direct_IO, | 134 | .direct_IO = udf_adinicb_direct_IO, |
135 | }; | 135 | }; |
136 | 136 | ||
137 | static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 137 | static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
138 | unsigned long nr_segs, loff_t ppos) | ||
139 | { | 138 | { |
140 | ssize_t retval; | 139 | ssize_t retval; |
141 | struct file *file = iocb->ki_filp; | 140 | struct file *file = iocb->ki_filp; |
@@ -150,7 +149,7 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
150 | if (file->f_flags & O_APPEND) | 149 | if (file->f_flags & O_APPEND) |
151 | pos = inode->i_size; | 150 | pos = inode->i_size; |
152 | else | 151 | else |
153 | pos = ppos; | 152 | pos = iocb->ki_pos; |
154 | 153 | ||
155 | if (inode->i_sb->s_blocksize < | 154 | if (inode->i_sb->s_blocksize < |
156 | (udf_file_entry_alloc_offset(inode) + | 155 | (udf_file_entry_alloc_offset(inode) + |
@@ -171,7 +170,7 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
171 | } else | 170 | } else |
172 | up_write(&iinfo->i_data_sem); | 171 | up_write(&iinfo->i_data_sem); |
173 | 172 | ||
174 | retval = __generic_file_aio_write(iocb, iov, nr_segs); | 173 | retval = __generic_file_write_iter(iocb, from); |
175 | mutex_unlock(&inode->i_mutex); | 174 | mutex_unlock(&inode->i_mutex); |
176 | 175 | ||
177 | if (retval > 0) { | 176 | if (retval > 0) { |
@@ -252,13 +251,13 @@ static int udf_release_file(struct inode *inode, struct file *filp) | |||
252 | } | 251 | } |
253 | 252 | ||
254 | const struct file_operations udf_file_operations = { | 253 | const struct file_operations udf_file_operations = { |
255 | .read = do_sync_read, | 254 | .read = new_sync_read, |
256 | .aio_read = generic_file_aio_read, | 255 | .read_iter = generic_file_read_iter, |
257 | .unlocked_ioctl = udf_ioctl, | 256 | .unlocked_ioctl = udf_ioctl, |
258 | .open = generic_file_open, | 257 | .open = generic_file_open, |
259 | .mmap = generic_file_mmap, | 258 | .mmap = generic_file_mmap, |
260 | .write = do_sync_write, | 259 | .write = new_sync_write, |
261 | .aio_write = udf_file_aio_write, | 260 | .write_iter = udf_file_write_iter, |
262 | .release = udf_release_file, | 261 | .release = udf_release_file, |
263 | .fsync = generic_file_fsync, | 262 | .fsync = generic_file_fsync, |
264 | .splice_read = generic_file_splice_read, | 263 | .splice_read = generic_file_splice_read, |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 5d643706212f..236cd48184c2 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
@@ -217,18 +217,18 @@ static int udf_write_begin(struct file *file, struct address_space *mapping, | |||
217 | } | 217 | } |
218 | 218 | ||
219 | static ssize_t udf_direct_IO(int rw, struct kiocb *iocb, | 219 | static ssize_t udf_direct_IO(int rw, struct kiocb *iocb, |
220 | const struct iovec *iov, | 220 | struct iov_iter *iter, |
221 | loff_t offset, unsigned long nr_segs) | 221 | loff_t offset) |
222 | { | 222 | { |
223 | struct file *file = iocb->ki_filp; | 223 | struct file *file = iocb->ki_filp; |
224 | struct address_space *mapping = file->f_mapping; | 224 | struct address_space *mapping = file->f_mapping; |
225 | struct inode *inode = mapping->host; | 225 | struct inode *inode = mapping->host; |
226 | size_t count = iov_iter_count(iter); | ||
226 | ssize_t ret; | 227 | ssize_t ret; |
227 | 228 | ||
228 | ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs, | 229 | ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, udf_get_block); |
229 | udf_get_block); | ||
230 | if (unlikely(ret < 0 && (rw & WRITE))) | 230 | if (unlikely(ret < 0 && (rw & WRITE))) |
231 | udf_write_failed(mapping, offset + iov_length(iov, nr_segs)); | 231 | udf_write_failed(mapping, offset + count); |
232 | return ret; | 232 | return ret; |
233 | } | 233 | } |
234 | 234 | ||
diff --git a/fs/ufs/file.c b/fs/ufs/file.c index 33afa20d4509..c84ec010a676 100644 --- a/fs/ufs/file.c +++ b/fs/ufs/file.c | |||
@@ -35,10 +35,10 @@ | |||
35 | 35 | ||
36 | const struct file_operations ufs_file_operations = { | 36 | const struct file_operations ufs_file_operations = { |
37 | .llseek = generic_file_llseek, | 37 | .llseek = generic_file_llseek, |
38 | .read = do_sync_read, | 38 | .read = new_sync_read, |
39 | .aio_read = generic_file_aio_read, | 39 | .read_iter = generic_file_read_iter, |
40 | .write = do_sync_write, | 40 | .write = new_sync_write, |
41 | .aio_write = generic_file_aio_write, | 41 | .write_iter = generic_file_write_iter, |
42 | .mmap = generic_file_mmap, | 42 | .mmap = generic_file_mmap, |
43 | .open = generic_file_open, | 43 | .open = generic_file_open, |
44 | .fsync = generic_file_fsync, | 44 | .fsync = generic_file_fsync, |
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index e32640eedea6..faaf716e2080 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c | |||
@@ -1486,9 +1486,8 @@ STATIC ssize_t | |||
1486 | xfs_vm_direct_IO( | 1486 | xfs_vm_direct_IO( |
1487 | int rw, | 1487 | int rw, |
1488 | struct kiocb *iocb, | 1488 | struct kiocb *iocb, |
1489 | const struct iovec *iov, | 1489 | struct iov_iter *iter, |
1490 | loff_t offset, | 1490 | loff_t offset) |
1491 | unsigned long nr_segs) | ||
1492 | { | 1491 | { |
1493 | struct inode *inode = iocb->ki_filp->f_mapping->host; | 1492 | struct inode *inode = iocb->ki_filp->f_mapping->host; |
1494 | struct block_device *bdev = xfs_find_bdev_for_inode(inode); | 1493 | struct block_device *bdev = xfs_find_bdev_for_inode(inode); |
@@ -1496,7 +1495,7 @@ xfs_vm_direct_IO( | |||
1496 | ssize_t ret; | 1495 | ssize_t ret; |
1497 | 1496 | ||
1498 | if (rw & WRITE) { | 1497 | if (rw & WRITE) { |
1499 | size_t size = iov_length(iov, nr_segs); | 1498 | size_t size = iov_iter_count(iter); |
1500 | 1499 | ||
1501 | /* | 1500 | /* |
1502 | * We cannot preallocate a size update transaction here as we | 1501 | * We cannot preallocate a size update transaction here as we |
@@ -1508,17 +1507,15 @@ xfs_vm_direct_IO( | |||
1508 | if (offset + size > XFS_I(inode)->i_d.di_size) | 1507 | if (offset + size > XFS_I(inode)->i_d.di_size) |
1509 | ioend->io_isdirect = 1; | 1508 | ioend->io_isdirect = 1; |
1510 | 1509 | ||
1511 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov, | 1510 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iter, |
1512 | offset, nr_segs, | 1511 | offset, xfs_get_blocks_direct, |
1513 | xfs_get_blocks_direct, | ||
1514 | xfs_end_io_direct_write, NULL, | 1512 | xfs_end_io_direct_write, NULL, |
1515 | DIO_ASYNC_EXTEND); | 1513 | DIO_ASYNC_EXTEND); |
1516 | if (ret != -EIOCBQUEUED && iocb->private) | 1514 | if (ret != -EIOCBQUEUED && iocb->private) |
1517 | goto out_destroy_ioend; | 1515 | goto out_destroy_ioend; |
1518 | } else { | 1516 | } else { |
1519 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov, | 1517 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iter, |
1520 | offset, nr_segs, | 1518 | offset, xfs_get_blocks_direct, |
1521 | xfs_get_blocks_direct, | ||
1522 | NULL, NULL, 0); | 1519 | NULL, NULL, 0); |
1523 | } | 1520 | } |
1524 | 1521 | ||
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 1b8160dc04d1..1f66779d7a46 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c | |||
@@ -229,34 +229,27 @@ xfs_file_fsync( | |||
229 | } | 229 | } |
230 | 230 | ||
231 | STATIC ssize_t | 231 | STATIC ssize_t |
232 | xfs_file_aio_read( | 232 | xfs_file_read_iter( |
233 | struct kiocb *iocb, | 233 | struct kiocb *iocb, |
234 | const struct iovec *iovp, | 234 | struct iov_iter *to) |
235 | unsigned long nr_segs, | ||
236 | loff_t pos) | ||
237 | { | 235 | { |
238 | struct file *file = iocb->ki_filp; | 236 | struct file *file = iocb->ki_filp; |
239 | struct inode *inode = file->f_mapping->host; | 237 | struct inode *inode = file->f_mapping->host; |
240 | struct xfs_inode *ip = XFS_I(inode); | 238 | struct xfs_inode *ip = XFS_I(inode); |
241 | struct xfs_mount *mp = ip->i_mount; | 239 | struct xfs_mount *mp = ip->i_mount; |
242 | size_t size = 0; | 240 | size_t size = iov_iter_count(to); |
243 | ssize_t ret = 0; | 241 | ssize_t ret = 0; |
244 | int ioflags = 0; | 242 | int ioflags = 0; |
245 | xfs_fsize_t n; | 243 | xfs_fsize_t n; |
244 | loff_t pos = iocb->ki_pos; | ||
246 | 245 | ||
247 | XFS_STATS_INC(xs_read_calls); | 246 | XFS_STATS_INC(xs_read_calls); |
248 | 247 | ||
249 | BUG_ON(iocb->ki_pos != pos); | ||
250 | |||
251 | if (unlikely(file->f_flags & O_DIRECT)) | 248 | if (unlikely(file->f_flags & O_DIRECT)) |
252 | ioflags |= IO_ISDIRECT; | 249 | ioflags |= IO_ISDIRECT; |
253 | if (file->f_mode & FMODE_NOCMTIME) | 250 | if (file->f_mode & FMODE_NOCMTIME) |
254 | ioflags |= IO_INVIS; | 251 | ioflags |= IO_INVIS; |
255 | 252 | ||
256 | ret = generic_segment_checks(iovp, &nr_segs, &size, VERIFY_WRITE); | ||
257 | if (ret < 0) | ||
258 | return ret; | ||
259 | |||
260 | if (unlikely(ioflags & IO_ISDIRECT)) { | 253 | if (unlikely(ioflags & IO_ISDIRECT)) { |
261 | xfs_buftarg_t *target = | 254 | xfs_buftarg_t *target = |
262 | XFS_IS_REALTIME_INODE(ip) ? | 255 | XFS_IS_REALTIME_INODE(ip) ? |
@@ -309,7 +302,7 @@ xfs_file_aio_read( | |||
309 | 302 | ||
310 | trace_xfs_file_read(ip, size, pos, ioflags); | 303 | trace_xfs_file_read(ip, size, pos, ioflags); |
311 | 304 | ||
312 | ret = generic_file_aio_read(iocb, iovp, nr_segs, pos); | 305 | ret = generic_file_read_iter(iocb, to); |
313 | if (ret > 0) | 306 | if (ret > 0) |
314 | XFS_STATS_ADD(xs_read_bytes, ret); | 307 | XFS_STATS_ADD(xs_read_bytes, ret); |
315 | 308 | ||
@@ -350,47 +343,6 @@ xfs_file_splice_read( | |||
350 | } | 343 | } |
351 | 344 | ||
352 | /* | 345 | /* |
353 | * xfs_file_splice_write() does not use xfs_rw_ilock() because | ||
354 | * generic_file_splice_write() takes the i_mutex itself. This, in theory, | ||
355 | * couuld cause lock inversions between the aio_write path and the splice path | ||
356 | * if someone is doing concurrent splice(2) based writes and write(2) based | ||
357 | * writes to the same inode. The only real way to fix this is to re-implement | ||
358 | * the generic code here with correct locking orders. | ||
359 | */ | ||
360 | STATIC ssize_t | ||
361 | xfs_file_splice_write( | ||
362 | struct pipe_inode_info *pipe, | ||
363 | struct file *outfilp, | ||
364 | loff_t *ppos, | ||
365 | size_t count, | ||
366 | unsigned int flags) | ||
367 | { | ||
368 | struct inode *inode = outfilp->f_mapping->host; | ||
369 | struct xfs_inode *ip = XFS_I(inode); | ||
370 | int ioflags = 0; | ||
371 | ssize_t ret; | ||
372 | |||
373 | XFS_STATS_INC(xs_write_calls); | ||
374 | |||
375 | if (outfilp->f_mode & FMODE_NOCMTIME) | ||
376 | ioflags |= IO_INVIS; | ||
377 | |||
378 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) | ||
379 | return -EIO; | ||
380 | |||
381 | xfs_ilock(ip, XFS_IOLOCK_EXCL); | ||
382 | |||
383 | trace_xfs_file_splice_write(ip, count, *ppos, ioflags); | ||
384 | |||
385 | ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags); | ||
386 | if (ret > 0) | ||
387 | XFS_STATS_ADD(xs_write_bytes, ret); | ||
388 | |||
389 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | ||
390 | return ret; | ||
391 | } | ||
392 | |||
393 | /* | ||
394 | * This routine is called to handle zeroing any space in the last block of the | 346 | * This routine is called to handle zeroing any space in the last block of the |
395 | * file that is beyond the EOF. We do this since the size is being increased | 347 | * file that is beyond the EOF. We do this since the size is being increased |
396 | * without writing anything to that block and we don't want to read the | 348 | * without writing anything to that block and we don't want to read the |
@@ -625,10 +577,7 @@ restart: | |||
625 | STATIC ssize_t | 577 | STATIC ssize_t |
626 | xfs_file_dio_aio_write( | 578 | xfs_file_dio_aio_write( |
627 | struct kiocb *iocb, | 579 | struct kiocb *iocb, |
628 | const struct iovec *iovp, | 580 | struct iov_iter *from) |
629 | unsigned long nr_segs, | ||
630 | loff_t pos, | ||
631 | size_t ocount) | ||
632 | { | 581 | { |
633 | struct file *file = iocb->ki_filp; | 582 | struct file *file = iocb->ki_filp; |
634 | struct address_space *mapping = file->f_mapping; | 583 | struct address_space *mapping = file->f_mapping; |
@@ -636,9 +585,10 @@ xfs_file_dio_aio_write( | |||
636 | struct xfs_inode *ip = XFS_I(inode); | 585 | struct xfs_inode *ip = XFS_I(inode); |
637 | struct xfs_mount *mp = ip->i_mount; | 586 | struct xfs_mount *mp = ip->i_mount; |
638 | ssize_t ret = 0; | 587 | ssize_t ret = 0; |
639 | size_t count = ocount; | ||
640 | int unaligned_io = 0; | 588 | int unaligned_io = 0; |
641 | int iolock; | 589 | int iolock; |
590 | size_t count = iov_iter_count(from); | ||
591 | loff_t pos = iocb->ki_pos; | ||
642 | struct xfs_buftarg *target = XFS_IS_REALTIME_INODE(ip) ? | 592 | struct xfs_buftarg *target = XFS_IS_REALTIME_INODE(ip) ? |
643 | mp->m_rtdev_targp : mp->m_ddev_targp; | 593 | mp->m_rtdev_targp : mp->m_ddev_targp; |
644 | 594 | ||
@@ -677,6 +627,7 @@ xfs_file_dio_aio_write( | |||
677 | ret = xfs_file_aio_write_checks(file, &pos, &count, &iolock); | 627 | ret = xfs_file_aio_write_checks(file, &pos, &count, &iolock); |
678 | if (ret) | 628 | if (ret) |
679 | goto out; | 629 | goto out; |
630 | iov_iter_truncate(from, count); | ||
680 | 631 | ||
681 | if (mapping->nrpages) { | 632 | if (mapping->nrpages) { |
682 | ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, | 633 | ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, |
@@ -698,8 +649,7 @@ xfs_file_dio_aio_write( | |||
698 | } | 649 | } |
699 | 650 | ||
700 | trace_xfs_file_direct_write(ip, count, iocb->ki_pos, 0); | 651 | trace_xfs_file_direct_write(ip, count, iocb->ki_pos, 0); |
701 | ret = generic_file_direct_write(iocb, iovp, | 652 | ret = generic_file_direct_write(iocb, from, pos); |
702 | &nr_segs, pos, count, ocount); | ||
703 | 653 | ||
704 | out: | 654 | out: |
705 | xfs_rw_iunlock(ip, iolock); | 655 | xfs_rw_iunlock(ip, iolock); |
@@ -712,10 +662,7 @@ out: | |||
712 | STATIC ssize_t | 662 | STATIC ssize_t |
713 | xfs_file_buffered_aio_write( | 663 | xfs_file_buffered_aio_write( |
714 | struct kiocb *iocb, | 664 | struct kiocb *iocb, |
715 | const struct iovec *iovp, | 665 | struct iov_iter *from) |
716 | unsigned long nr_segs, | ||
717 | loff_t pos, | ||
718 | size_t count) | ||
719 | { | 666 | { |
720 | struct file *file = iocb->ki_filp; | 667 | struct file *file = iocb->ki_filp; |
721 | struct address_space *mapping = file->f_mapping; | 668 | struct address_space *mapping = file->f_mapping; |
@@ -724,7 +671,8 @@ xfs_file_buffered_aio_write( | |||
724 | ssize_t ret; | 671 | ssize_t ret; |
725 | int enospc = 0; | 672 | int enospc = 0; |
726 | int iolock = XFS_IOLOCK_EXCL; | 673 | int iolock = XFS_IOLOCK_EXCL; |
727 | struct iov_iter from; | 674 | loff_t pos = iocb->ki_pos; |
675 | size_t count = iov_iter_count(from); | ||
728 | 676 | ||
729 | xfs_rw_ilock(ip, iolock); | 677 | xfs_rw_ilock(ip, iolock); |
730 | 678 | ||
@@ -732,13 +680,13 @@ xfs_file_buffered_aio_write( | |||
732 | if (ret) | 680 | if (ret) |
733 | goto out; | 681 | goto out; |
734 | 682 | ||
735 | iov_iter_init(&from, iovp, nr_segs, count, 0); | 683 | iov_iter_truncate(from, count); |
736 | /* We can write back this queue in page reclaim */ | 684 | /* We can write back this queue in page reclaim */ |
737 | current->backing_dev_info = mapping->backing_dev_info; | 685 | current->backing_dev_info = mapping->backing_dev_info; |
738 | 686 | ||
739 | write_retry: | 687 | write_retry: |
740 | trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, 0); | 688 | trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, 0); |
741 | ret = generic_perform_write(file, &from, pos); | 689 | ret = generic_perform_write(file, from, pos); |
742 | if (likely(ret >= 0)) | 690 | if (likely(ret >= 0)) |
743 | iocb->ki_pos = pos + ret; | 691 | iocb->ki_pos = pos + ret; |
744 | /* | 692 | /* |
@@ -759,40 +707,29 @@ out: | |||
759 | } | 707 | } |
760 | 708 | ||
761 | STATIC ssize_t | 709 | STATIC ssize_t |
762 | xfs_file_aio_write( | 710 | xfs_file_write_iter( |
763 | struct kiocb *iocb, | 711 | struct kiocb *iocb, |
764 | const struct iovec *iovp, | 712 | struct iov_iter *from) |
765 | unsigned long nr_segs, | ||
766 | loff_t pos) | ||
767 | { | 713 | { |
768 | struct file *file = iocb->ki_filp; | 714 | struct file *file = iocb->ki_filp; |
769 | struct address_space *mapping = file->f_mapping; | 715 | struct address_space *mapping = file->f_mapping; |
770 | struct inode *inode = mapping->host; | 716 | struct inode *inode = mapping->host; |
771 | struct xfs_inode *ip = XFS_I(inode); | 717 | struct xfs_inode *ip = XFS_I(inode); |
772 | ssize_t ret; | 718 | ssize_t ret; |
773 | size_t ocount = 0; | 719 | size_t ocount = iov_iter_count(from); |
774 | 720 | ||
775 | XFS_STATS_INC(xs_write_calls); | 721 | XFS_STATS_INC(xs_write_calls); |
776 | 722 | ||
777 | BUG_ON(iocb->ki_pos != pos); | ||
778 | |||
779 | ret = generic_segment_checks(iovp, &nr_segs, &ocount, VERIFY_READ); | ||
780 | if (ret) | ||
781 | return ret; | ||
782 | |||
783 | if (ocount == 0) | 723 | if (ocount == 0) |
784 | return 0; | 724 | return 0; |
785 | 725 | ||
786 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { | 726 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) |
787 | ret = -EIO; | 727 | return -EIO; |
788 | goto out; | ||
789 | } | ||
790 | 728 | ||
791 | if (unlikely(file->f_flags & O_DIRECT)) | 729 | if (unlikely(file->f_flags & O_DIRECT)) |
792 | ret = xfs_file_dio_aio_write(iocb, iovp, nr_segs, pos, ocount); | 730 | ret = xfs_file_dio_aio_write(iocb, from); |
793 | else | 731 | else |
794 | ret = xfs_file_buffered_aio_write(iocb, iovp, nr_segs, pos, | 732 | ret = xfs_file_buffered_aio_write(iocb, from); |
795 | ocount); | ||
796 | 733 | ||
797 | if (ret > 0) { | 734 | if (ret > 0) { |
798 | ssize_t err; | 735 | ssize_t err; |
@@ -804,8 +741,6 @@ xfs_file_aio_write( | |||
804 | if (err < 0) | 741 | if (err < 0) |
805 | ret = err; | 742 | ret = err; |
806 | } | 743 | } |
807 | |||
808 | out: | ||
809 | return ret; | 744 | return ret; |
810 | } | 745 | } |
811 | 746 | ||
@@ -1461,12 +1396,12 @@ xfs_file_llseek( | |||
1461 | 1396 | ||
1462 | const struct file_operations xfs_file_operations = { | 1397 | const struct file_operations xfs_file_operations = { |
1463 | .llseek = xfs_file_llseek, | 1398 | .llseek = xfs_file_llseek, |
1464 | .read = do_sync_read, | 1399 | .read = new_sync_read, |
1465 | .write = do_sync_write, | 1400 | .write = new_sync_write, |
1466 | .aio_read = xfs_file_aio_read, | 1401 | .read_iter = xfs_file_read_iter, |
1467 | .aio_write = xfs_file_aio_write, | 1402 | .write_iter = xfs_file_write_iter, |
1468 | .splice_read = xfs_file_splice_read, | 1403 | .splice_read = xfs_file_splice_read, |
1469 | .splice_write = xfs_file_splice_write, | 1404 | .splice_write = iter_file_splice_write, |
1470 | .unlocked_ioctl = xfs_file_ioctl, | 1405 | .unlocked_ioctl = xfs_file_ioctl, |
1471 | #ifdef CONFIG_COMPAT | 1406 | #ifdef CONFIG_COMPAT |
1472 | .compat_ioctl = xfs_file_compat_ioctl, | 1407 | .compat_ioctl = xfs_file_compat_ioctl, |
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 6910458915cf..152f82782630 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h | |||
@@ -1118,7 +1118,6 @@ DEFINE_RW_EVENT(xfs_file_read); | |||
1118 | DEFINE_RW_EVENT(xfs_file_buffered_write); | 1118 | DEFINE_RW_EVENT(xfs_file_buffered_write); |
1119 | DEFINE_RW_EVENT(xfs_file_direct_write); | 1119 | DEFINE_RW_EVENT(xfs_file_direct_write); |
1120 | DEFINE_RW_EVENT(xfs_file_splice_read); | 1120 | DEFINE_RW_EVENT(xfs_file_splice_read); |
1121 | DEFINE_RW_EVENT(xfs_file_splice_write); | ||
1122 | 1121 | ||
1123 | DECLARE_EVENT_CLASS(xfs_page_class, | 1122 | DECLARE_EVENT_CLASS(xfs_page_class, |
1124 | TP_PROTO(struct inode *inode, struct page *page, unsigned long off, | 1123 | TP_PROTO(struct inode *inode, struct page *page, unsigned long off, |
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d8e4cea23a25..66c2167f04a9 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h | |||
@@ -5,8 +5,6 @@ | |||
5 | #ifndef __LINUX_BLK_TYPES_H | 5 | #ifndef __LINUX_BLK_TYPES_H |
6 | #define __LINUX_BLK_TYPES_H | 6 | #define __LINUX_BLK_TYPES_H |
7 | 7 | ||
8 | #ifdef CONFIG_BLOCK | ||
9 | |||
10 | #include <linux/types.h> | 8 | #include <linux/types.h> |
11 | 9 | ||
12 | struct bio_set; | 10 | struct bio_set; |
@@ -28,6 +26,8 @@ struct bio_vec { | |||
28 | unsigned int bv_offset; | 26 | unsigned int bv_offset; |
29 | }; | 27 | }; |
30 | 28 | ||
29 | #ifdef CONFIG_BLOCK | ||
30 | |||
31 | struct bvec_iter { | 31 | struct bvec_iter { |
32 | sector_t bi_sector; /* device address in 512 byte | 32 | sector_t bi_sector; /* device address in 512 byte |
33 | sectors */ | 33 | sectors */ |
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h index 2f49aa4c4f7f..279b0afac1c1 100644 --- a/include/linux/ceph/libceph.h +++ b/include/linux/ceph/libceph.h | |||
@@ -222,8 +222,6 @@ extern void ceph_copy_to_page_vector(struct page **pages, | |||
222 | extern void ceph_copy_from_page_vector(struct page **pages, | 222 | extern void ceph_copy_from_page_vector(struct page **pages, |
223 | void *data, | 223 | void *data, |
224 | loff_t off, size_t len); | 224 | loff_t off, size_t len); |
225 | extern int ceph_copy_page_vector_to_user(struct page **pages, void __user *data, | ||
226 | loff_t off, size_t len); | ||
227 | extern void ceph_zero_page_vector_range(int off, int len, struct page **pages); | 225 | extern void ceph_zero_page_vector_range(int off, int len, struct page **pages); |
228 | 226 | ||
229 | 227 | ||
diff --git a/include/linux/fs.h b/include/linux/fs.h index c3f46e499dd0..338e6f758c6d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -128,6 +128,10 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, | |||
128 | #define FMODE_ATOMIC_POS ((__force fmode_t)0x8000) | 128 | #define FMODE_ATOMIC_POS ((__force fmode_t)0x8000) |
129 | /* Write access to underlying fs */ | 129 | /* Write access to underlying fs */ |
130 | #define FMODE_WRITER ((__force fmode_t)0x10000) | 130 | #define FMODE_WRITER ((__force fmode_t)0x10000) |
131 | /* Has read method(s) */ | ||
132 | #define FMODE_CAN_READ ((__force fmode_t)0x20000) | ||
133 | /* Has write method(s) */ | ||
134 | #define FMODE_CAN_WRITE ((__force fmode_t)0x40000) | ||
131 | 135 | ||
132 | /* File was opened by fanotify and shouldn't generate fanotify events */ | 136 | /* File was opened by fanotify and shouldn't generate fanotify events */ |
133 | #define FMODE_NONOTIFY ((__force fmode_t)0x1000000) | 137 | #define FMODE_NONOTIFY ((__force fmode_t)0x1000000) |
@@ -343,8 +347,7 @@ struct address_space_operations { | |||
343 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); | 347 | void (*invalidatepage) (struct page *, unsigned int, unsigned int); |
344 | int (*releasepage) (struct page *, gfp_t); | 348 | int (*releasepage) (struct page *, gfp_t); |
345 | void (*freepage)(struct page *); | 349 | void (*freepage)(struct page *); |
346 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, | 350 | ssize_t (*direct_IO)(int, struct kiocb *, struct iov_iter *iter, loff_t offset); |
347 | loff_t offset, unsigned long nr_segs); | ||
348 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, | 351 | int (*get_xip_mem)(struct address_space *, pgoff_t, int, |
349 | void **, unsigned long *); | 352 | void **, unsigned long *); |
350 | /* | 353 | /* |
@@ -1448,6 +1451,8 @@ struct block_device_operations; | |||
1448 | #define HAVE_COMPAT_IOCTL 1 | 1451 | #define HAVE_COMPAT_IOCTL 1 |
1449 | #define HAVE_UNLOCKED_IOCTL 1 | 1452 | #define HAVE_UNLOCKED_IOCTL 1 |
1450 | 1453 | ||
1454 | struct iov_iter; | ||
1455 | |||
1451 | struct file_operations { | 1456 | struct file_operations { |
1452 | struct module *owner; | 1457 | struct module *owner; |
1453 | loff_t (*llseek) (struct file *, loff_t, int); | 1458 | loff_t (*llseek) (struct file *, loff_t, int); |
@@ -1455,6 +1460,8 @@ struct file_operations { | |||
1455 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 1460 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
1456 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 1461 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
1457 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 1462 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
1463 | ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); | ||
1464 | ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); | ||
1458 | int (*iterate) (struct file *, struct dir_context *); | 1465 | int (*iterate) (struct file *, struct dir_context *); |
1459 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 1466 | unsigned int (*poll) (struct file *, struct poll_table_struct *); |
1460 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 1467 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
@@ -2404,20 +2411,18 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); | |||
2404 | extern int generic_file_remap_pages(struct vm_area_struct *, unsigned long addr, | 2411 | extern int generic_file_remap_pages(struct vm_area_struct *, unsigned long addr, |
2405 | unsigned long size, pgoff_t pgoff); | 2412 | unsigned long size, pgoff_t pgoff); |
2406 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); | 2413 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); |
2407 | extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 2414 | extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); |
2408 | extern ssize_t __generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long); | 2415 | extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); |
2409 | extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); | 2416 | extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); |
2410 | extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, | 2417 | extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *, loff_t); |
2411 | unsigned long *, loff_t, size_t, size_t); | ||
2412 | extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t); | 2418 | extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t); |
2413 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); | 2419 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); |
2414 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); | 2420 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); |
2415 | extern int generic_segment_checks(const struct iovec *iov, | 2421 | extern ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); |
2416 | unsigned long *nr_segs, size_t *count, int access_flags); | 2422 | extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); |
2417 | 2423 | ||
2418 | /* fs/block_dev.c */ | 2424 | /* fs/block_dev.c */ |
2419 | extern ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, | 2425 | extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from); |
2420 | unsigned long nr_segs, loff_t pos); | ||
2421 | extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end, | 2426 | extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end, |
2422 | int datasync); | 2427 | int datasync); |
2423 | extern void block_sync_page(struct page *page); | 2428 | extern void block_sync_page(struct page *page); |
@@ -2427,7 +2432,7 @@ extern ssize_t generic_file_splice_read(struct file *, loff_t *, | |||
2427 | struct pipe_inode_info *, size_t, unsigned int); | 2432 | struct pipe_inode_info *, size_t, unsigned int); |
2428 | extern ssize_t default_file_splice_read(struct file *, loff_t *, | 2433 | extern ssize_t default_file_splice_read(struct file *, loff_t *, |
2429 | struct pipe_inode_info *, size_t, unsigned int); | 2434 | struct pipe_inode_info *, size_t, unsigned int); |
2430 | extern ssize_t generic_file_splice_write(struct pipe_inode_info *, | 2435 | extern ssize_t iter_file_splice_write(struct pipe_inode_info *, |
2431 | struct file *, loff_t *, size_t, unsigned int); | 2436 | struct file *, loff_t *, size_t, unsigned int); |
2432 | extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, | 2437 | extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, |
2433 | struct file *out, loff_t *, size_t len, unsigned int flags); | 2438 | struct file *out, loff_t *, size_t len, unsigned int flags); |
@@ -2477,16 +2482,16 @@ enum { | |||
2477 | void dio_end_io(struct bio *bio, int error); | 2482 | void dio_end_io(struct bio *bio, int error); |
2478 | 2483 | ||
2479 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 2484 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
2480 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 2485 | struct block_device *bdev, struct iov_iter *iter, loff_t offset, |
2481 | unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, | 2486 | get_block_t get_block, dio_iodone_t end_io, |
2482 | dio_submit_t submit_io, int flags); | 2487 | dio_submit_t submit_io, int flags); |
2483 | 2488 | ||
2484 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, | 2489 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, |
2485 | struct inode *inode, const struct iovec *iov, loff_t offset, | 2490 | struct inode *inode, struct iov_iter *iter, loff_t offset, |
2486 | unsigned long nr_segs, get_block_t get_block) | 2491 | get_block_t get_block) |
2487 | { | 2492 | { |
2488 | return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 2493 | return __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iter, |
2489 | offset, nr_segs, get_block, NULL, NULL, | 2494 | offset, get_block, NULL, NULL, |
2490 | DIO_LOCKING | DIO_SKIP_HOLES); | 2495 | DIO_LOCKING | DIO_SKIP_HOLES); |
2491 | } | 2496 | } |
2492 | #endif | 2497 | #endif |
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 919576b8e2cf..e30f6059ecd6 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h | |||
@@ -459,13 +459,12 @@ extern int nfs3_removexattr (struct dentry *, const char *name); | |||
459 | /* | 459 | /* |
460 | * linux/fs/nfs/direct.c | 460 | * linux/fs/nfs/direct.c |
461 | */ | 461 | */ |
462 | extern ssize_t nfs_direct_IO(int, struct kiocb *, const struct iovec *, loff_t, | 462 | extern ssize_t nfs_direct_IO(int, struct kiocb *, struct iov_iter *, loff_t); |
463 | unsigned long); | ||
464 | extern ssize_t nfs_file_direct_read(struct kiocb *iocb, | 463 | extern ssize_t nfs_file_direct_read(struct kiocb *iocb, |
465 | const struct iovec *iov, unsigned long nr_segs, | 464 | struct iov_iter *iter, |
466 | loff_t pos, bool uio); | 465 | loff_t pos, bool uio); |
467 | extern ssize_t nfs_file_direct_write(struct kiocb *iocb, | 466 | extern ssize_t nfs_file_direct_write(struct kiocb *iocb, |
468 | const struct iovec *iov, unsigned long nr_segs, | 467 | struct iov_iter *iter, |
469 | loff_t pos, bool uio); | 468 | loff_t pos, bool uio); |
470 | 469 | ||
471 | /* | 470 | /* |
diff --git a/include/linux/splice.h b/include/linux/splice.h index 0e43906d2fda..da2751d3b93d 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h | |||
@@ -70,16 +70,6 @@ extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, | |||
70 | splice_actor *); | 70 | splice_actor *); |
71 | extern ssize_t __splice_from_pipe(struct pipe_inode_info *, | 71 | extern ssize_t __splice_from_pipe(struct pipe_inode_info *, |
72 | struct splice_desc *, splice_actor *); | 72 | struct splice_desc *, splice_actor *); |
73 | extern int splice_from_pipe_feed(struct pipe_inode_info *, struct splice_desc *, | ||
74 | splice_actor *); | ||
75 | extern int splice_from_pipe_next(struct pipe_inode_info *, | ||
76 | struct splice_desc *); | ||
77 | extern void splice_from_pipe_begin(struct splice_desc *); | ||
78 | extern void splice_from_pipe_end(struct pipe_inode_info *, | ||
79 | struct splice_desc *); | ||
80 | extern int pipe_to_file(struct pipe_inode_info *, struct pipe_buffer *, | ||
81 | struct splice_desc *); | ||
82 | |||
83 | extern ssize_t splice_to_pipe(struct pipe_inode_info *, | 73 | extern ssize_t splice_to_pipe(struct pipe_inode_info *, |
84 | struct splice_pipe_desc *); | 74 | struct splice_pipe_desc *); |
85 | extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, | 75 | extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, |
diff --git a/include/linux/uio.h b/include/linux/uio.h index 199bcc34241b..e2231e47cec1 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h | |||
@@ -19,11 +19,21 @@ struct kvec { | |||
19 | size_t iov_len; | 19 | size_t iov_len; |
20 | }; | 20 | }; |
21 | 21 | ||
22 | enum { | ||
23 | ITER_IOVEC = 0, | ||
24 | ITER_KVEC = 2, | ||
25 | ITER_BVEC = 4, | ||
26 | }; | ||
27 | |||
22 | struct iov_iter { | 28 | struct iov_iter { |
23 | const struct iovec *iov; | 29 | int type; |
24 | unsigned long nr_segs; | ||
25 | size_t iov_offset; | 30 | size_t iov_offset; |
26 | size_t count; | 31 | size_t count; |
32 | union { | ||
33 | const struct iovec *iov; | ||
34 | const struct bio_vec *bvec; | ||
35 | }; | ||
36 | unsigned long nr_segs; | ||
27 | }; | 37 | }; |
28 | 38 | ||
29 | /* | 39 | /* |
@@ -53,6 +63,7 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) | |||
53 | } | 63 | } |
54 | 64 | ||
55 | #define iov_for_each(iov, iter, start) \ | 65 | #define iov_for_each(iov, iter, start) \ |
66 | if (!((start).type & ITER_BVEC)) \ | ||
56 | for (iter = (start); \ | 67 | for (iter = (start); \ |
57 | (iter).count && \ | 68 | (iter).count && \ |
58 | ((iov = iov_iter_iovec(&(iter))), 1); \ | 69 | ((iov = iov_iter_iovec(&(iter))), 1); \ |
@@ -62,32 +73,44 @@ unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to); | |||
62 | 73 | ||
63 | size_t iov_iter_copy_from_user_atomic(struct page *page, | 74 | size_t iov_iter_copy_from_user_atomic(struct page *page, |
64 | struct iov_iter *i, unsigned long offset, size_t bytes); | 75 | struct iov_iter *i, unsigned long offset, size_t bytes); |
65 | size_t iov_iter_copy_from_user(struct page *page, | ||
66 | struct iov_iter *i, unsigned long offset, size_t bytes); | ||
67 | void iov_iter_advance(struct iov_iter *i, size_t bytes); | 76 | void iov_iter_advance(struct iov_iter *i, size_t bytes); |
68 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); | 77 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); |
69 | size_t iov_iter_single_seg_count(const struct iov_iter *i); | 78 | size_t iov_iter_single_seg_count(const struct iov_iter *i); |
70 | size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, | 79 | size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, |
71 | struct iov_iter *i); | 80 | struct iov_iter *i); |
81 | size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, | ||
82 | struct iov_iter *i); | ||
83 | unsigned long iov_iter_alignment(const struct iov_iter *i); | ||
84 | void iov_iter_init(struct iov_iter *i, int direction, const struct iovec *iov, | ||
85 | unsigned long nr_segs, size_t count); | ||
86 | ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, | ||
87 | size_t maxsize, size_t *start); | ||
88 | ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, | ||
89 | size_t maxsize, size_t *start); | ||
90 | int iov_iter_npages(const struct iov_iter *i, int maxpages); | ||
72 | 91 | ||
73 | static inline void iov_iter_init(struct iov_iter *i, | 92 | static inline size_t iov_iter_count(struct iov_iter *i) |
74 | const struct iovec *iov, unsigned long nr_segs, | ||
75 | size_t count, size_t written) | ||
76 | { | 93 | { |
77 | i->iov = iov; | 94 | return i->count; |
78 | i->nr_segs = nr_segs; | 95 | } |
79 | i->iov_offset = 0; | ||
80 | i->count = count + written; | ||
81 | 96 | ||
82 | iov_iter_advance(i, written); | 97 | static inline void iov_iter_truncate(struct iov_iter *i, size_t count) |
98 | { | ||
99 | if (i->count > count) | ||
100 | i->count = count; | ||
83 | } | 101 | } |
84 | 102 | ||
85 | static inline size_t iov_iter_count(struct iov_iter *i) | 103 | /* |
104 | * reexpand a previously truncated iterator; count must be no more than how much | ||
105 | * we had shrunk it. | ||
106 | */ | ||
107 | static inline void iov_iter_reexpand(struct iov_iter *i, size_t count) | ||
86 | { | 108 | { |
87 | return i->count; | 109 | i->count = count; |
88 | } | 110 | } |
89 | 111 | ||
90 | int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len); | 112 | int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len); |
91 | int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len); | 113 | int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len); |
92 | 114 | ||
115 | |||
93 | #endif | 116 | #endif |
diff --git a/mm/filemap.c b/mm/filemap.c index 7fadf1c62838..dafb06f70a09 100644 --- a/mm/filemap.c +++ b/mm/filemap.c | |||
@@ -1665,96 +1665,42 @@ out: | |||
1665 | return written ? written : error; | 1665 | return written ? written : error; |
1666 | } | 1666 | } |
1667 | 1667 | ||
1668 | /* | ||
1669 | * Performs necessary checks before doing a write | ||
1670 | * @iov: io vector request | ||
1671 | * @nr_segs: number of segments in the iovec | ||
1672 | * @count: number of bytes to write | ||
1673 | * @access_flags: type of access: %VERIFY_READ or %VERIFY_WRITE | ||
1674 | * | ||
1675 | * Adjust number of segments and amount of bytes to write (nr_segs should be | ||
1676 | * properly initialized first). Returns appropriate error code that caller | ||
1677 | * should return or zero in case that write should be allowed. | ||
1678 | */ | ||
1679 | int generic_segment_checks(const struct iovec *iov, | ||
1680 | unsigned long *nr_segs, size_t *count, int access_flags) | ||
1681 | { | ||
1682 | unsigned long seg; | ||
1683 | size_t cnt = 0; | ||
1684 | for (seg = 0; seg < *nr_segs; seg++) { | ||
1685 | const struct iovec *iv = &iov[seg]; | ||
1686 | |||
1687 | /* | ||
1688 | * If any segment has a negative length, or the cumulative | ||
1689 | * length ever wraps negative then return -EINVAL. | ||
1690 | */ | ||
1691 | cnt += iv->iov_len; | ||
1692 | if (unlikely((ssize_t)(cnt|iv->iov_len) < 0)) | ||
1693 | return -EINVAL; | ||
1694 | if (access_ok(access_flags, iv->iov_base, iv->iov_len)) | ||
1695 | continue; | ||
1696 | if (seg == 0) | ||
1697 | return -EFAULT; | ||
1698 | *nr_segs = seg; | ||
1699 | cnt -= iv->iov_len; /* This segment is no good */ | ||
1700 | break; | ||
1701 | } | ||
1702 | *count = cnt; | ||
1703 | return 0; | ||
1704 | } | ||
1705 | EXPORT_SYMBOL(generic_segment_checks); | ||
1706 | |||
1707 | /** | 1668 | /** |
1708 | * generic_file_aio_read - generic filesystem read routine | 1669 | * generic_file_read_iter - generic filesystem read routine |
1709 | * @iocb: kernel I/O control block | 1670 | * @iocb: kernel I/O control block |
1710 | * @iov: io vector request | 1671 | * @iter: destination for the data read |
1711 | * @nr_segs: number of segments in the iovec | ||
1712 | * @pos: current file position | ||
1713 | * | 1672 | * |
1714 | * This is the "read()" routine for all filesystems | 1673 | * This is the "read_iter()" routine for all filesystems |
1715 | * that can use the page cache directly. | 1674 | * that can use the page cache directly. |
1716 | */ | 1675 | */ |
1717 | ssize_t | 1676 | ssize_t |
1718 | generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | 1677 | generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) |
1719 | unsigned long nr_segs, loff_t pos) | ||
1720 | { | 1678 | { |
1721 | struct file *filp = iocb->ki_filp; | 1679 | struct file *file = iocb->ki_filp; |
1722 | ssize_t retval; | 1680 | ssize_t retval = 0; |
1723 | size_t count; | ||
1724 | loff_t *ppos = &iocb->ki_pos; | 1681 | loff_t *ppos = &iocb->ki_pos; |
1725 | struct iov_iter i; | 1682 | loff_t pos = *ppos; |
1726 | |||
1727 | count = 0; | ||
1728 | retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE); | ||
1729 | if (retval) | ||
1730 | return retval; | ||
1731 | iov_iter_init(&i, iov, nr_segs, count, 0); | ||
1732 | 1683 | ||
1733 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ | 1684 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ |
1734 | if (filp->f_flags & O_DIRECT) { | 1685 | if (file->f_flags & O_DIRECT) { |
1686 | struct address_space *mapping = file->f_mapping; | ||
1687 | struct inode *inode = mapping->host; | ||
1688 | size_t count = iov_iter_count(iter); | ||
1735 | loff_t size; | 1689 | loff_t size; |
1736 | struct address_space *mapping; | ||
1737 | struct inode *inode; | ||
1738 | 1690 | ||
1739 | mapping = filp->f_mapping; | ||
1740 | inode = mapping->host; | ||
1741 | if (!count) | 1691 | if (!count) |
1742 | goto out; /* skip atime */ | 1692 | goto out; /* skip atime */ |
1743 | size = i_size_read(inode); | 1693 | size = i_size_read(inode); |
1744 | retval = filemap_write_and_wait_range(mapping, pos, | 1694 | retval = filemap_write_and_wait_range(mapping, pos, |
1745 | pos + iov_length(iov, nr_segs) - 1); | 1695 | pos + count - 1); |
1746 | if (!retval) { | 1696 | if (!retval) { |
1747 | retval = mapping->a_ops->direct_IO(READ, iocb, | 1697 | struct iov_iter data = *iter; |
1748 | iov, pos, nr_segs); | 1698 | retval = mapping->a_ops->direct_IO(READ, iocb, &data, pos); |
1749 | } | 1699 | } |
1700 | |||
1750 | if (retval > 0) { | 1701 | if (retval > 0) { |
1751 | *ppos = pos + retval; | 1702 | *ppos = pos + retval; |
1752 | count -= retval; | 1703 | iov_iter_advance(iter, retval); |
1753 | /* | ||
1754 | * If we did a short DIO read we need to skip the | ||
1755 | * section of the iov that we've already read data into. | ||
1756 | */ | ||
1757 | iov_iter_advance(&i, retval); | ||
1758 | } | 1704 | } |
1759 | 1705 | ||
1760 | /* | 1706 | /* |
@@ -1765,17 +1711,17 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, | |||
1765 | * and return. Otherwise fallthrough to buffered io for | 1711 | * and return. Otherwise fallthrough to buffered io for |
1766 | * the rest of the read. | 1712 | * the rest of the read. |
1767 | */ | 1713 | */ |
1768 | if (retval < 0 || !count || *ppos >= size) { | 1714 | if (retval < 0 || !iov_iter_count(iter) || *ppos >= size) { |
1769 | file_accessed(filp); | 1715 | file_accessed(file); |
1770 | goto out; | 1716 | goto out; |
1771 | } | 1717 | } |
1772 | } | 1718 | } |
1773 | 1719 | ||
1774 | retval = do_generic_file_read(filp, ppos, &i, retval); | 1720 | retval = do_generic_file_read(file, ppos, iter, retval); |
1775 | out: | 1721 | out: |
1776 | return retval; | 1722 | return retval; |
1777 | } | 1723 | } |
1778 | EXPORT_SYMBOL(generic_file_aio_read); | 1724 | EXPORT_SYMBOL(generic_file_read_iter); |
1779 | 1725 | ||
1780 | #ifdef CONFIG_MMU | 1726 | #ifdef CONFIG_MMU |
1781 | /** | 1727 | /** |
@@ -2386,9 +2332,7 @@ int pagecache_write_end(struct file *file, struct address_space *mapping, | |||
2386 | EXPORT_SYMBOL(pagecache_write_end); | 2332 | EXPORT_SYMBOL(pagecache_write_end); |
2387 | 2333 | ||
2388 | ssize_t | 2334 | ssize_t |
2389 | generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | 2335 | generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos) |
2390 | unsigned long *nr_segs, loff_t pos, | ||
2391 | size_t count, size_t ocount) | ||
2392 | { | 2336 | { |
2393 | struct file *file = iocb->ki_filp; | 2337 | struct file *file = iocb->ki_filp; |
2394 | struct address_space *mapping = file->f_mapping; | 2338 | struct address_space *mapping = file->f_mapping; |
@@ -2396,11 +2340,9 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
2396 | ssize_t written; | 2340 | ssize_t written; |
2397 | size_t write_len; | 2341 | size_t write_len; |
2398 | pgoff_t end; | 2342 | pgoff_t end; |
2343 | struct iov_iter data; | ||
2399 | 2344 | ||
2400 | if (count != ocount) | 2345 | write_len = iov_iter_count(from); |
2401 | *nr_segs = iov_shorten((struct iovec *)iov, *nr_segs, count); | ||
2402 | |||
2403 | write_len = iov_length(iov, *nr_segs); | ||
2404 | end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT; | 2346 | end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT; |
2405 | 2347 | ||
2406 | written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1); | 2348 | written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1); |
@@ -2427,7 +2369,8 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
2427 | } | 2369 | } |
2428 | } | 2370 | } |
2429 | 2371 | ||
2430 | written = mapping->a_ops->direct_IO(WRITE, iocb, iov, pos, *nr_segs); | 2372 | data = *from; |
2373 | written = mapping->a_ops->direct_IO(WRITE, iocb, &data, pos); | ||
2431 | 2374 | ||
2432 | /* | 2375 | /* |
2433 | * Finally, try again to invalidate clean pages which might have been | 2376 | * Finally, try again to invalidate clean pages which might have been |
@@ -2444,6 +2387,7 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
2444 | 2387 | ||
2445 | if (written > 0) { | 2388 | if (written > 0) { |
2446 | pos += written; | 2389 | pos += written; |
2390 | iov_iter_advance(from, written); | ||
2447 | if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { | 2391 | if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { |
2448 | i_size_write(inode, pos); | 2392 | i_size_write(inode, pos); |
2449 | mark_inode_dirty(inode); | 2393 | mark_inode_dirty(inode); |
@@ -2568,10 +2512,9 @@ again: | |||
2568 | EXPORT_SYMBOL(generic_perform_write); | 2512 | EXPORT_SYMBOL(generic_perform_write); |
2569 | 2513 | ||
2570 | /** | 2514 | /** |
2571 | * __generic_file_aio_write - write data to a file | 2515 | * __generic_file_write_iter - write data to a file |
2572 | * @iocb: IO state structure (file, offset, etc.) | 2516 | * @iocb: IO state structure (file, offset, etc.) |
2573 | * @iov: vector with data to write | 2517 | * @from: iov_iter with data to write |
2574 | * @nr_segs: number of segments in the vector | ||
2575 | * | 2518 | * |
2576 | * This function does all the work needed for actually writing data to a | 2519 | * This function does all the work needed for actually writing data to a |
2577 | * file. It does all basic checks, removes SUID from the file, updates | 2520 | * file. It does all basic checks, removes SUID from the file, updates |
@@ -2585,26 +2528,16 @@ EXPORT_SYMBOL(generic_perform_write); | |||
2585 | * A caller has to handle it. This is mainly due to the fact that we want to | 2528 | * A caller has to handle it. This is mainly due to the fact that we want to |
2586 | * avoid syncing under i_mutex. | 2529 | * avoid syncing under i_mutex. |
2587 | */ | 2530 | */ |
2588 | ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 2531 | ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
2589 | unsigned long nr_segs) | ||
2590 | { | 2532 | { |
2591 | struct file *file = iocb->ki_filp; | 2533 | struct file *file = iocb->ki_filp; |
2592 | struct address_space * mapping = file->f_mapping; | 2534 | struct address_space * mapping = file->f_mapping; |
2593 | size_t ocount; /* original count */ | ||
2594 | size_t count; /* after file limit checks */ | ||
2595 | struct inode *inode = mapping->host; | 2535 | struct inode *inode = mapping->host; |
2596 | loff_t pos = iocb->ki_pos; | 2536 | loff_t pos = iocb->ki_pos; |
2597 | ssize_t written = 0; | 2537 | ssize_t written = 0; |
2598 | ssize_t err; | 2538 | ssize_t err; |
2599 | ssize_t status; | 2539 | ssize_t status; |
2600 | struct iov_iter from; | 2540 | size_t count = iov_iter_count(from); |
2601 | |||
2602 | ocount = 0; | ||
2603 | err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ); | ||
2604 | if (err) | ||
2605 | return err; | ||
2606 | |||
2607 | count = ocount; | ||
2608 | 2541 | ||
2609 | /* We can write back this queue in page reclaim */ | 2542 | /* We can write back this queue in page reclaim */ |
2610 | current->backing_dev_info = mapping->backing_dev_info; | 2543 | current->backing_dev_info = mapping->backing_dev_info; |
@@ -2615,6 +2548,8 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2615 | if (count == 0) | 2548 | if (count == 0) |
2616 | goto out; | 2549 | goto out; |
2617 | 2550 | ||
2551 | iov_iter_truncate(from, count); | ||
2552 | |||
2618 | err = file_remove_suid(file); | 2553 | err = file_remove_suid(file); |
2619 | if (err) | 2554 | if (err) |
2620 | goto out; | 2555 | goto out; |
@@ -2623,17 +2558,13 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2623 | if (err) | 2558 | if (err) |
2624 | goto out; | 2559 | goto out; |
2625 | 2560 | ||
2626 | iov_iter_init(&from, iov, nr_segs, count, 0); | ||
2627 | |||
2628 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ | 2561 | /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ |
2629 | if (unlikely(file->f_flags & O_DIRECT)) { | 2562 | if (unlikely(file->f_flags & O_DIRECT)) { |
2630 | loff_t endbyte; | 2563 | loff_t endbyte; |
2631 | 2564 | ||
2632 | written = generic_file_direct_write(iocb, iov, &from.nr_segs, pos, | 2565 | written = generic_file_direct_write(iocb, from, pos); |
2633 | count, ocount); | ||
2634 | if (written < 0 || written == count) | 2566 | if (written < 0 || written == count) |
2635 | goto out; | 2567 | goto out; |
2636 | iov_iter_advance(&from, written); | ||
2637 | 2568 | ||
2638 | /* | 2569 | /* |
2639 | * direct-io write to a hole: fall through to buffered I/O | 2570 | * direct-io write to a hole: fall through to buffered I/O |
@@ -2642,7 +2573,7 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2642 | pos += written; | 2573 | pos += written; |
2643 | count -= written; | 2574 | count -= written; |
2644 | 2575 | ||
2645 | status = generic_perform_write(file, &from, pos); | 2576 | status = generic_perform_write(file, from, pos); |
2646 | /* | 2577 | /* |
2647 | * If generic_perform_write() returned a synchronous error | 2578 | * If generic_perform_write() returned a synchronous error |
2648 | * then we want to return the number of bytes which were | 2579 | * then we want to return the number of bytes which were |
@@ -2674,7 +2605,7 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2674 | */ | 2605 | */ |
2675 | } | 2606 | } |
2676 | } else { | 2607 | } else { |
2677 | written = generic_perform_write(file, &from, pos); | 2608 | written = generic_perform_write(file, from, pos); |
2678 | if (likely(written >= 0)) | 2609 | if (likely(written >= 0)) |
2679 | iocb->ki_pos = pos + written; | 2610 | iocb->ki_pos = pos + written; |
2680 | } | 2611 | } |
@@ -2682,30 +2613,25 @@ out: | |||
2682 | current->backing_dev_info = NULL; | 2613 | current->backing_dev_info = NULL; |
2683 | return written ? written : err; | 2614 | return written ? written : err; |
2684 | } | 2615 | } |
2685 | EXPORT_SYMBOL(__generic_file_aio_write); | 2616 | EXPORT_SYMBOL(__generic_file_write_iter); |
2686 | 2617 | ||
2687 | /** | 2618 | /** |
2688 | * generic_file_aio_write - write data to a file | 2619 | * generic_file_write_iter - write data to a file |
2689 | * @iocb: IO state structure | 2620 | * @iocb: IO state structure |
2690 | * @iov: vector with data to write | 2621 | * @from: iov_iter with data to write |
2691 | * @nr_segs: number of segments in the vector | ||
2692 | * @pos: position in file where to write | ||
2693 | * | 2622 | * |
2694 | * This is a wrapper around __generic_file_aio_write() to be used by most | 2623 | * This is a wrapper around __generic_file_write_iter() to be used by most |
2695 | * filesystems. It takes care of syncing the file in case of O_SYNC file | 2624 | * filesystems. It takes care of syncing the file in case of O_SYNC file |
2696 | * and acquires i_mutex as needed. | 2625 | * and acquires i_mutex as needed. |
2697 | */ | 2626 | */ |
2698 | ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | 2627 | ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
2699 | unsigned long nr_segs, loff_t pos) | ||
2700 | { | 2628 | { |
2701 | struct file *file = iocb->ki_filp; | 2629 | struct file *file = iocb->ki_filp; |
2702 | struct inode *inode = file->f_mapping->host; | 2630 | struct inode *inode = file->f_mapping->host; |
2703 | ssize_t ret; | 2631 | ssize_t ret; |
2704 | 2632 | ||
2705 | BUG_ON(iocb->ki_pos != pos); | ||
2706 | |||
2707 | mutex_lock(&inode->i_mutex); | 2633 | mutex_lock(&inode->i_mutex); |
2708 | ret = __generic_file_aio_write(iocb, iov, nr_segs); | 2634 | ret = __generic_file_write_iter(iocb, from); |
2709 | mutex_unlock(&inode->i_mutex); | 2635 | mutex_unlock(&inode->i_mutex); |
2710 | 2636 | ||
2711 | if (ret > 0) { | 2637 | if (ret > 0) { |
@@ -2717,7 +2643,7 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
2717 | } | 2643 | } |
2718 | return ret; | 2644 | return ret; |
2719 | } | 2645 | } |
2720 | EXPORT_SYMBOL(generic_file_aio_write); | 2646 | EXPORT_SYMBOL(generic_file_write_iter); |
2721 | 2647 | ||
2722 | /** | 2648 | /** |
2723 | * try_to_release_page() - release old fs-specific metadata on a page | 2649 | * try_to_release_page() - release old fs-specific metadata on a page |
diff --git a/mm/iov_iter.c b/mm/iov_iter.c index 10e46cd721de..7b5dbd1517b5 100644 --- a/mm/iov_iter.c +++ b/mm/iov_iter.c | |||
@@ -1,8 +1,10 @@ | |||
1 | #include <linux/export.h> | 1 | #include <linux/export.h> |
2 | #include <linux/uio.h> | 2 | #include <linux/uio.h> |
3 | #include <linux/pagemap.h> | 3 | #include <linux/pagemap.h> |
4 | #include <linux/slab.h> | ||
5 | #include <linux/vmalloc.h> | ||
4 | 6 | ||
5 | size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, | 7 | static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes, |
6 | struct iov_iter *i) | 8 | struct iov_iter *i) |
7 | { | 9 | { |
8 | size_t skip, copy, left, wanted; | 10 | size_t skip, copy, left, wanted; |
@@ -72,13 +74,97 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, | |||
72 | } | 74 | } |
73 | kunmap(page); | 75 | kunmap(page); |
74 | done: | 76 | done: |
77 | if (skip == iov->iov_len) { | ||
78 | iov++; | ||
79 | skip = 0; | ||
80 | } | ||
81 | i->count -= wanted - bytes; | ||
82 | i->nr_segs -= iov - i->iov; | ||
83 | i->iov = iov; | ||
84 | i->iov_offset = skip; | ||
85 | return wanted - bytes; | ||
86 | } | ||
87 | |||
88 | static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t bytes, | ||
89 | struct iov_iter *i) | ||
90 | { | ||
91 | size_t skip, copy, left, wanted; | ||
92 | const struct iovec *iov; | ||
93 | char __user *buf; | ||
94 | void *kaddr, *to; | ||
95 | |||
96 | if (unlikely(bytes > i->count)) | ||
97 | bytes = i->count; | ||
98 | |||
99 | if (unlikely(!bytes)) | ||
100 | return 0; | ||
101 | |||
102 | wanted = bytes; | ||
103 | iov = i->iov; | ||
104 | skip = i->iov_offset; | ||
105 | buf = iov->iov_base + skip; | ||
106 | copy = min(bytes, iov->iov_len - skip); | ||
107 | |||
108 | if (!fault_in_pages_readable(buf, copy)) { | ||
109 | kaddr = kmap_atomic(page); | ||
110 | to = kaddr + offset; | ||
111 | |||
112 | /* first chunk, usually the only one */ | ||
113 | left = __copy_from_user_inatomic(to, buf, copy); | ||
114 | copy -= left; | ||
115 | skip += copy; | ||
116 | to += copy; | ||
117 | bytes -= copy; | ||
118 | |||
119 | while (unlikely(!left && bytes)) { | ||
120 | iov++; | ||
121 | buf = iov->iov_base; | ||
122 | copy = min(bytes, iov->iov_len); | ||
123 | left = __copy_from_user_inatomic(to, buf, copy); | ||
124 | copy -= left; | ||
125 | skip = copy; | ||
126 | to += copy; | ||
127 | bytes -= copy; | ||
128 | } | ||
129 | if (likely(!bytes)) { | ||
130 | kunmap_atomic(kaddr); | ||
131 | goto done; | ||
132 | } | ||
133 | offset = to - kaddr; | ||
134 | buf += copy; | ||
135 | kunmap_atomic(kaddr); | ||
136 | copy = min(bytes, iov->iov_len - skip); | ||
137 | } | ||
138 | /* Too bad - revert to non-atomic kmap */ | ||
139 | kaddr = kmap(page); | ||
140 | to = kaddr + offset; | ||
141 | left = __copy_from_user(to, buf, copy); | ||
142 | copy -= left; | ||
143 | skip += copy; | ||
144 | to += copy; | ||
145 | bytes -= copy; | ||
146 | while (unlikely(!left && bytes)) { | ||
147 | iov++; | ||
148 | buf = iov->iov_base; | ||
149 | copy = min(bytes, iov->iov_len); | ||
150 | left = __copy_from_user(to, buf, copy); | ||
151 | copy -= left; | ||
152 | skip = copy; | ||
153 | to += copy; | ||
154 | bytes -= copy; | ||
155 | } | ||
156 | kunmap(page); | ||
157 | done: | ||
158 | if (skip == iov->iov_len) { | ||
159 | iov++; | ||
160 | skip = 0; | ||
161 | } | ||
75 | i->count -= wanted - bytes; | 162 | i->count -= wanted - bytes; |
76 | i->nr_segs -= iov - i->iov; | 163 | i->nr_segs -= iov - i->iov; |
77 | i->iov = iov; | 164 | i->iov = iov; |
78 | i->iov_offset = skip; | 165 | i->iov_offset = skip; |
79 | return wanted - bytes; | 166 | return wanted - bytes; |
80 | } | 167 | } |
81 | EXPORT_SYMBOL(copy_page_to_iter); | ||
82 | 168 | ||
83 | static size_t __iovec_copy_from_user_inatomic(char *vaddr, | 169 | static size_t __iovec_copy_from_user_inatomic(char *vaddr, |
84 | const struct iovec *iov, size_t base, size_t bytes) | 170 | const struct iovec *iov, size_t base, size_t bytes) |
@@ -107,7 +193,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr, | |||
107 | * were successfully copied. If a fault is encountered then return the number of | 193 | * were successfully copied. If a fault is encountered then return the number of |
108 | * bytes which were copied. | 194 | * bytes which were copied. |
109 | */ | 195 | */ |
110 | size_t iov_iter_copy_from_user_atomic(struct page *page, | 196 | static size_t copy_from_user_atomic_iovec(struct page *page, |
111 | struct iov_iter *i, unsigned long offset, size_t bytes) | 197 | struct iov_iter *i, unsigned long offset, size_t bytes) |
112 | { | 198 | { |
113 | char *kaddr; | 199 | char *kaddr; |
@@ -127,36 +213,8 @@ size_t iov_iter_copy_from_user_atomic(struct page *page, | |||
127 | 213 | ||
128 | return copied; | 214 | return copied; |
129 | } | 215 | } |
130 | EXPORT_SYMBOL(iov_iter_copy_from_user_atomic); | ||
131 | |||
132 | /* | ||
133 | * This has the same sideeffects and return value as | ||
134 | * iov_iter_copy_from_user_atomic(). | ||
135 | * The difference is that it attempts to resolve faults. | ||
136 | * Page must not be locked. | ||
137 | */ | ||
138 | size_t iov_iter_copy_from_user(struct page *page, | ||
139 | struct iov_iter *i, unsigned long offset, size_t bytes) | ||
140 | { | ||
141 | char *kaddr; | ||
142 | size_t copied; | ||
143 | |||
144 | kaddr = kmap(page); | ||
145 | if (likely(i->nr_segs == 1)) { | ||
146 | int left; | ||
147 | char __user *buf = i->iov->iov_base + i->iov_offset; | ||
148 | left = __copy_from_user(kaddr + offset, buf, bytes); | ||
149 | copied = bytes - left; | ||
150 | } else { | ||
151 | copied = __iovec_copy_from_user_inatomic(kaddr + offset, | ||
152 | i->iov, i->iov_offset, bytes); | ||
153 | } | ||
154 | kunmap(page); | ||
155 | return copied; | ||
156 | } | ||
157 | EXPORT_SYMBOL(iov_iter_copy_from_user); | ||
158 | 216 | ||
159 | void iov_iter_advance(struct iov_iter *i, size_t bytes) | 217 | static void advance_iovec(struct iov_iter *i, size_t bytes) |
160 | { | 218 | { |
161 | BUG_ON(i->count < bytes); | 219 | BUG_ON(i->count < bytes); |
162 | 220 | ||
@@ -191,7 +249,6 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes) | |||
191 | i->nr_segs = nr_segs; | 249 | i->nr_segs = nr_segs; |
192 | } | 250 | } |
193 | } | 251 | } |
194 | EXPORT_SYMBOL(iov_iter_advance); | ||
195 | 252 | ||
196 | /* | 253 | /* |
197 | * Fault in the first iovec of the given iov_iter, to a maximum length | 254 | * Fault in the first iovec of the given iov_iter, to a maximum length |
@@ -204,21 +261,483 @@ EXPORT_SYMBOL(iov_iter_advance); | |||
204 | */ | 261 | */ |
205 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes) | 262 | int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes) |
206 | { | 263 | { |
207 | char __user *buf = i->iov->iov_base + i->iov_offset; | 264 | if (!(i->type & ITER_BVEC)) { |
208 | bytes = min(bytes, i->iov->iov_len - i->iov_offset); | 265 | char __user *buf = i->iov->iov_base + i->iov_offset; |
209 | return fault_in_pages_readable(buf, bytes); | 266 | bytes = min(bytes, i->iov->iov_len - i->iov_offset); |
267 | return fault_in_pages_readable(buf, bytes); | ||
268 | } | ||
269 | return 0; | ||
210 | } | 270 | } |
211 | EXPORT_SYMBOL(iov_iter_fault_in_readable); | 271 | EXPORT_SYMBOL(iov_iter_fault_in_readable); |
212 | 272 | ||
273 | static unsigned long alignment_iovec(const struct iov_iter *i) | ||
274 | { | ||
275 | const struct iovec *iov = i->iov; | ||
276 | unsigned long res; | ||
277 | size_t size = i->count; | ||
278 | size_t n; | ||
279 | |||
280 | if (!size) | ||
281 | return 0; | ||
282 | |||
283 | res = (unsigned long)iov->iov_base + i->iov_offset; | ||
284 | n = iov->iov_len - i->iov_offset; | ||
285 | if (n >= size) | ||
286 | return res | size; | ||
287 | size -= n; | ||
288 | res |= n; | ||
289 | while (size > (++iov)->iov_len) { | ||
290 | res |= (unsigned long)iov->iov_base | iov->iov_len; | ||
291 | size -= iov->iov_len; | ||
292 | } | ||
293 | res |= (unsigned long)iov->iov_base | size; | ||
294 | return res; | ||
295 | } | ||
296 | |||
297 | void iov_iter_init(struct iov_iter *i, int direction, | ||
298 | const struct iovec *iov, unsigned long nr_segs, | ||
299 | size_t count) | ||
300 | { | ||
301 | /* It will get better. Eventually... */ | ||
302 | if (segment_eq(get_fs(), KERNEL_DS)) | ||
303 | direction |= ITER_KVEC; | ||
304 | i->type = direction; | ||
305 | i->iov = iov; | ||
306 | i->nr_segs = nr_segs; | ||
307 | i->iov_offset = 0; | ||
308 | i->count = count; | ||
309 | } | ||
310 | EXPORT_SYMBOL(iov_iter_init); | ||
311 | |||
312 | static ssize_t get_pages_iovec(struct iov_iter *i, | ||
313 | struct page **pages, size_t maxsize, | ||
314 | size_t *start) | ||
315 | { | ||
316 | size_t offset = i->iov_offset; | ||
317 | const struct iovec *iov = i->iov; | ||
318 | size_t len; | ||
319 | unsigned long addr; | ||
320 | int n; | ||
321 | int res; | ||
322 | |||
323 | len = iov->iov_len - offset; | ||
324 | if (len > i->count) | ||
325 | len = i->count; | ||
326 | if (len > maxsize) | ||
327 | len = maxsize; | ||
328 | addr = (unsigned long)iov->iov_base + offset; | ||
329 | len += *start = addr & (PAGE_SIZE - 1); | ||
330 | addr &= ~(PAGE_SIZE - 1); | ||
331 | n = (len + PAGE_SIZE - 1) / PAGE_SIZE; | ||
332 | res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, pages); | ||
333 | if (unlikely(res < 0)) | ||
334 | return res; | ||
335 | return (res == n ? len : res * PAGE_SIZE) - *start; | ||
336 | } | ||
337 | |||
338 | static ssize_t get_pages_alloc_iovec(struct iov_iter *i, | ||
339 | struct page ***pages, size_t maxsize, | ||
340 | size_t *start) | ||
341 | { | ||
342 | size_t offset = i->iov_offset; | ||
343 | const struct iovec *iov = i->iov; | ||
344 | size_t len; | ||
345 | unsigned long addr; | ||
346 | void *p; | ||
347 | int n; | ||
348 | int res; | ||
349 | |||
350 | len = iov->iov_len - offset; | ||
351 | if (len > i->count) | ||
352 | len = i->count; | ||
353 | if (len > maxsize) | ||
354 | len = maxsize; | ||
355 | addr = (unsigned long)iov->iov_base + offset; | ||
356 | len += *start = addr & (PAGE_SIZE - 1); | ||
357 | addr &= ~(PAGE_SIZE - 1); | ||
358 | n = (len + PAGE_SIZE - 1) / PAGE_SIZE; | ||
359 | |||
360 | p = kmalloc(n * sizeof(struct page *), GFP_KERNEL); | ||
361 | if (!p) | ||
362 | p = vmalloc(n * sizeof(struct page *)); | ||
363 | if (!p) | ||
364 | return -ENOMEM; | ||
365 | |||
366 | res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, p); | ||
367 | if (unlikely(res < 0)) { | ||
368 | kvfree(p); | ||
369 | return res; | ||
370 | } | ||
371 | *pages = p; | ||
372 | return (res == n ? len : res * PAGE_SIZE) - *start; | ||
373 | } | ||
374 | |||
375 | static int iov_iter_npages_iovec(const struct iov_iter *i, int maxpages) | ||
376 | { | ||
377 | size_t offset = i->iov_offset; | ||
378 | size_t size = i->count; | ||
379 | const struct iovec *iov = i->iov; | ||
380 | int npages = 0; | ||
381 | int n; | ||
382 | |||
383 | for (n = 0; size && n < i->nr_segs; n++, iov++) { | ||
384 | unsigned long addr = (unsigned long)iov->iov_base + offset; | ||
385 | size_t len = iov->iov_len - offset; | ||
386 | offset = 0; | ||
387 | if (unlikely(!len)) /* empty segment */ | ||
388 | continue; | ||
389 | if (len > size) | ||
390 | len = size; | ||
391 | npages += (addr + len + PAGE_SIZE - 1) / PAGE_SIZE | ||
392 | - addr / PAGE_SIZE; | ||
393 | if (npages >= maxpages) /* don't bother going further */ | ||
394 | return maxpages; | ||
395 | size -= len; | ||
396 | offset = 0; | ||
397 | } | ||
398 | return min(npages, maxpages); | ||
399 | } | ||
400 | |||
401 | static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len) | ||
402 | { | ||
403 | char *from = kmap_atomic(page); | ||
404 | memcpy(to, from + offset, len); | ||
405 | kunmap_atomic(from); | ||
406 | } | ||
407 | |||
408 | static void memcpy_to_page(struct page *page, size_t offset, char *from, size_t len) | ||
409 | { | ||
410 | char *to = kmap_atomic(page); | ||
411 | memcpy(to + offset, from, len); | ||
412 | kunmap_atomic(to); | ||
413 | } | ||
414 | |||
415 | static size_t copy_page_to_iter_bvec(struct page *page, size_t offset, size_t bytes, | ||
416 | struct iov_iter *i) | ||
417 | { | ||
418 | size_t skip, copy, wanted; | ||
419 | const struct bio_vec *bvec; | ||
420 | void *kaddr, *from; | ||
421 | |||
422 | if (unlikely(bytes > i->count)) | ||
423 | bytes = i->count; | ||
424 | |||
425 | if (unlikely(!bytes)) | ||
426 | return 0; | ||
427 | |||
428 | wanted = bytes; | ||
429 | bvec = i->bvec; | ||
430 | skip = i->iov_offset; | ||
431 | copy = min_t(size_t, bytes, bvec->bv_len - skip); | ||
432 | |||
433 | kaddr = kmap_atomic(page); | ||
434 | from = kaddr + offset; | ||
435 | memcpy_to_page(bvec->bv_page, skip + bvec->bv_offset, from, copy); | ||
436 | skip += copy; | ||
437 | from += copy; | ||
438 | bytes -= copy; | ||
439 | while (bytes) { | ||
440 | bvec++; | ||
441 | copy = min(bytes, (size_t)bvec->bv_len); | ||
442 | memcpy_to_page(bvec->bv_page, bvec->bv_offset, from, copy); | ||
443 | skip = copy; | ||
444 | from += copy; | ||
445 | bytes -= copy; | ||
446 | } | ||
447 | kunmap_atomic(kaddr); | ||
448 | if (skip == bvec->bv_len) { | ||
449 | bvec++; | ||
450 | skip = 0; | ||
451 | } | ||
452 | i->count -= wanted - bytes; | ||
453 | i->nr_segs -= bvec - i->bvec; | ||
454 | i->bvec = bvec; | ||
455 | i->iov_offset = skip; | ||
456 | return wanted - bytes; | ||
457 | } | ||
458 | |||
459 | static size_t copy_page_from_iter_bvec(struct page *page, size_t offset, size_t bytes, | ||
460 | struct iov_iter *i) | ||
461 | { | ||
462 | size_t skip, copy, wanted; | ||
463 | const struct bio_vec *bvec; | ||
464 | void *kaddr, *to; | ||
465 | |||
466 | if (unlikely(bytes > i->count)) | ||
467 | bytes = i->count; | ||
468 | |||
469 | if (unlikely(!bytes)) | ||
470 | return 0; | ||
471 | |||
472 | wanted = bytes; | ||
473 | bvec = i->bvec; | ||
474 | skip = i->iov_offset; | ||
475 | |||
476 | kaddr = kmap_atomic(page); | ||
477 | |||
478 | to = kaddr + offset; | ||
479 | |||
480 | copy = min(bytes, bvec->bv_len - skip); | ||
481 | |||
482 | memcpy_from_page(to, bvec->bv_page, bvec->bv_offset + skip, copy); | ||
483 | |||
484 | to += copy; | ||
485 | skip += copy; | ||
486 | bytes -= copy; | ||
487 | |||
488 | while (bytes) { | ||
489 | bvec++; | ||
490 | copy = min(bytes, (size_t)bvec->bv_len); | ||
491 | memcpy_from_page(to, bvec->bv_page, bvec->bv_offset, copy); | ||
492 | skip = copy; | ||
493 | to += copy; | ||
494 | bytes -= copy; | ||
495 | } | ||
496 | kunmap_atomic(kaddr); | ||
497 | if (skip == bvec->bv_len) { | ||
498 | bvec++; | ||
499 | skip = 0; | ||
500 | } | ||
501 | i->count -= wanted; | ||
502 | i->nr_segs -= bvec - i->bvec; | ||
503 | i->bvec = bvec; | ||
504 | i->iov_offset = skip; | ||
505 | return wanted; | ||
506 | } | ||
507 | |||
508 | static size_t copy_from_user_bvec(struct page *page, | ||
509 | struct iov_iter *i, unsigned long offset, size_t bytes) | ||
510 | { | ||
511 | char *kaddr; | ||
512 | size_t left; | ||
513 | const struct bio_vec *bvec; | ||
514 | size_t base = i->iov_offset; | ||
515 | |||
516 | kaddr = kmap_atomic(page); | ||
517 | for (left = bytes, bvec = i->bvec; left; bvec++, base = 0) { | ||
518 | size_t copy = min(left, bvec->bv_len - base); | ||
519 | if (!bvec->bv_len) | ||
520 | continue; | ||
521 | memcpy_from_page(kaddr + offset, bvec->bv_page, | ||
522 | bvec->bv_offset + base, copy); | ||
523 | offset += copy; | ||
524 | left -= copy; | ||
525 | } | ||
526 | kunmap_atomic(kaddr); | ||
527 | return bytes; | ||
528 | } | ||
529 | |||
530 | static void advance_bvec(struct iov_iter *i, size_t bytes) | ||
531 | { | ||
532 | BUG_ON(i->count < bytes); | ||
533 | |||
534 | if (likely(i->nr_segs == 1)) { | ||
535 | i->iov_offset += bytes; | ||
536 | i->count -= bytes; | ||
537 | } else { | ||
538 | const struct bio_vec *bvec = i->bvec; | ||
539 | size_t base = i->iov_offset; | ||
540 | unsigned long nr_segs = i->nr_segs; | ||
541 | |||
542 | /* | ||
543 | * The !iov->iov_len check ensures we skip over unlikely | ||
544 | * zero-length segments (without overruning the iovec). | ||
545 | */ | ||
546 | while (bytes || unlikely(i->count && !bvec->bv_len)) { | ||
547 | int copy; | ||
548 | |||
549 | copy = min(bytes, bvec->bv_len - base); | ||
550 | BUG_ON(!i->count || i->count < copy); | ||
551 | i->count -= copy; | ||
552 | bytes -= copy; | ||
553 | base += copy; | ||
554 | if (bvec->bv_len == base) { | ||
555 | bvec++; | ||
556 | nr_segs--; | ||
557 | base = 0; | ||
558 | } | ||
559 | } | ||
560 | i->bvec = bvec; | ||
561 | i->iov_offset = base; | ||
562 | i->nr_segs = nr_segs; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | static unsigned long alignment_bvec(const struct iov_iter *i) | ||
567 | { | ||
568 | const struct bio_vec *bvec = i->bvec; | ||
569 | unsigned long res; | ||
570 | size_t size = i->count; | ||
571 | size_t n; | ||
572 | |||
573 | if (!size) | ||
574 | return 0; | ||
575 | |||
576 | res = bvec->bv_offset + i->iov_offset; | ||
577 | n = bvec->bv_len - i->iov_offset; | ||
578 | if (n >= size) | ||
579 | return res | size; | ||
580 | size -= n; | ||
581 | res |= n; | ||
582 | while (size > (++bvec)->bv_len) { | ||
583 | res |= bvec->bv_offset | bvec->bv_len; | ||
584 | size -= bvec->bv_len; | ||
585 | } | ||
586 | res |= bvec->bv_offset | size; | ||
587 | return res; | ||
588 | } | ||
589 | |||
590 | static ssize_t get_pages_bvec(struct iov_iter *i, | ||
591 | struct page **pages, size_t maxsize, | ||
592 | size_t *start) | ||
593 | { | ||
594 | const struct bio_vec *bvec = i->bvec; | ||
595 | size_t len = bvec->bv_len - i->iov_offset; | ||
596 | if (len > i->count) | ||
597 | len = i->count; | ||
598 | if (len > maxsize) | ||
599 | len = maxsize; | ||
600 | *start = bvec->bv_offset + i->iov_offset; | ||
601 | |||
602 | get_page(*pages = bvec->bv_page); | ||
603 | |||
604 | return len; | ||
605 | } | ||
606 | |||
607 | static ssize_t get_pages_alloc_bvec(struct iov_iter *i, | ||
608 | struct page ***pages, size_t maxsize, | ||
609 | size_t *start) | ||
610 | { | ||
611 | const struct bio_vec *bvec = i->bvec; | ||
612 | size_t len = bvec->bv_len - i->iov_offset; | ||
613 | if (len > i->count) | ||
614 | len = i->count; | ||
615 | if (len > maxsize) | ||
616 | len = maxsize; | ||
617 | *start = bvec->bv_offset + i->iov_offset; | ||
618 | |||
619 | *pages = kmalloc(sizeof(struct page *), GFP_KERNEL); | ||
620 | if (!*pages) | ||
621 | return -ENOMEM; | ||
622 | |||
623 | get_page(**pages = bvec->bv_page); | ||
624 | |||
625 | return len; | ||
626 | } | ||
627 | |||
628 | static int iov_iter_npages_bvec(const struct iov_iter *i, int maxpages) | ||
629 | { | ||
630 | size_t offset = i->iov_offset; | ||
631 | size_t size = i->count; | ||
632 | const struct bio_vec *bvec = i->bvec; | ||
633 | int npages = 0; | ||
634 | int n; | ||
635 | |||
636 | for (n = 0; size && n < i->nr_segs; n++, bvec++) { | ||
637 | size_t len = bvec->bv_len - offset; | ||
638 | offset = 0; | ||
639 | if (unlikely(!len)) /* empty segment */ | ||
640 | continue; | ||
641 | if (len > size) | ||
642 | len = size; | ||
643 | npages++; | ||
644 | if (npages >= maxpages) /* don't bother going further */ | ||
645 | return maxpages; | ||
646 | size -= len; | ||
647 | offset = 0; | ||
648 | } | ||
649 | return min(npages, maxpages); | ||
650 | } | ||
651 | |||
652 | size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, | ||
653 | struct iov_iter *i) | ||
654 | { | ||
655 | if (i->type & ITER_BVEC) | ||
656 | return copy_page_to_iter_bvec(page, offset, bytes, i); | ||
657 | else | ||
658 | return copy_page_to_iter_iovec(page, offset, bytes, i); | ||
659 | } | ||
660 | EXPORT_SYMBOL(copy_page_to_iter); | ||
661 | |||
662 | size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, | ||
663 | struct iov_iter *i) | ||
664 | { | ||
665 | if (i->type & ITER_BVEC) | ||
666 | return copy_page_from_iter_bvec(page, offset, bytes, i); | ||
667 | else | ||
668 | return copy_page_from_iter_iovec(page, offset, bytes, i); | ||
669 | } | ||
670 | EXPORT_SYMBOL(copy_page_from_iter); | ||
671 | |||
672 | size_t iov_iter_copy_from_user_atomic(struct page *page, | ||
673 | struct iov_iter *i, unsigned long offset, size_t bytes) | ||
674 | { | ||
675 | if (i->type & ITER_BVEC) | ||
676 | return copy_from_user_bvec(page, i, offset, bytes); | ||
677 | else | ||
678 | return copy_from_user_atomic_iovec(page, i, offset, bytes); | ||
679 | } | ||
680 | EXPORT_SYMBOL(iov_iter_copy_from_user_atomic); | ||
681 | |||
682 | void iov_iter_advance(struct iov_iter *i, size_t size) | ||
683 | { | ||
684 | if (i->type & ITER_BVEC) | ||
685 | advance_bvec(i, size); | ||
686 | else | ||
687 | advance_iovec(i, size); | ||
688 | } | ||
689 | EXPORT_SYMBOL(iov_iter_advance); | ||
690 | |||
213 | /* | 691 | /* |
214 | * Return the count of just the current iov_iter segment. | 692 | * Return the count of just the current iov_iter segment. |
215 | */ | 693 | */ |
216 | size_t iov_iter_single_seg_count(const struct iov_iter *i) | 694 | size_t iov_iter_single_seg_count(const struct iov_iter *i) |
217 | { | 695 | { |
218 | const struct iovec *iov = i->iov; | ||
219 | if (i->nr_segs == 1) | 696 | if (i->nr_segs == 1) |
220 | return i->count; | 697 | return i->count; |
698 | else if (i->type & ITER_BVEC) | ||
699 | return min(i->count, i->iov->iov_len - i->iov_offset); | ||
221 | else | 700 | else |
222 | return min(i->count, iov->iov_len - i->iov_offset); | 701 | return min(i->count, i->bvec->bv_len - i->iov_offset); |
223 | } | 702 | } |
224 | EXPORT_SYMBOL(iov_iter_single_seg_count); | 703 | EXPORT_SYMBOL(iov_iter_single_seg_count); |
704 | |||
705 | unsigned long iov_iter_alignment(const struct iov_iter *i) | ||
706 | { | ||
707 | if (i->type & ITER_BVEC) | ||
708 | return alignment_bvec(i); | ||
709 | else | ||
710 | return alignment_iovec(i); | ||
711 | } | ||
712 | EXPORT_SYMBOL(iov_iter_alignment); | ||
713 | |||
714 | ssize_t iov_iter_get_pages(struct iov_iter *i, | ||
715 | struct page **pages, size_t maxsize, | ||
716 | size_t *start) | ||
717 | { | ||
718 | if (i->type & ITER_BVEC) | ||
719 | return get_pages_bvec(i, pages, maxsize, start); | ||
720 | else | ||
721 | return get_pages_iovec(i, pages, maxsize, start); | ||
722 | } | ||
723 | EXPORT_SYMBOL(iov_iter_get_pages); | ||
724 | |||
725 | ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, | ||
726 | struct page ***pages, size_t maxsize, | ||
727 | size_t *start) | ||
728 | { | ||
729 | if (i->type & ITER_BVEC) | ||
730 | return get_pages_alloc_bvec(i, pages, maxsize, start); | ||
731 | else | ||
732 | return get_pages_alloc_iovec(i, pages, maxsize, start); | ||
733 | } | ||
734 | EXPORT_SYMBOL(iov_iter_get_pages_alloc); | ||
735 | |||
736 | int iov_iter_npages(const struct iov_iter *i, int maxpages) | ||
737 | { | ||
738 | if (i->type & ITER_BVEC) | ||
739 | return iov_iter_npages_bvec(i, maxpages); | ||
740 | else | ||
741 | return iov_iter_npages_iovec(i, maxpages); | ||
742 | } | ||
743 | EXPORT_SYMBOL(iov_iter_npages); | ||
diff --git a/mm/page_io.c b/mm/page_io.c index 58b50d2901fe..243a9b76e5ce 100644 --- a/mm/page_io.c +++ b/mm/page_io.c | |||
@@ -264,9 +264,17 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, | |||
264 | struct kiocb kiocb; | 264 | struct kiocb kiocb; |
265 | struct file *swap_file = sis->swap_file; | 265 | struct file *swap_file = sis->swap_file; |
266 | struct address_space *mapping = swap_file->f_mapping; | 266 | struct address_space *mapping = swap_file->f_mapping; |
267 | struct iovec iov = { | 267 | struct bio_vec bv = { |
268 | .iov_base = kmap(page), | 268 | .bv_page = page, |
269 | .iov_len = PAGE_SIZE, | 269 | .bv_len = PAGE_SIZE, |
270 | .bv_offset = 0 | ||
271 | }; | ||
272 | struct iov_iter from = { | ||
273 | .type = ITER_BVEC | WRITE, | ||
274 | .count = PAGE_SIZE, | ||
275 | .iov_offset = 0, | ||
276 | .nr_segs = 1, | ||
277 | .bvec = &bv | ||
270 | }; | 278 | }; |
271 | 279 | ||
272 | init_sync_kiocb(&kiocb, swap_file); | 280 | init_sync_kiocb(&kiocb, swap_file); |
@@ -275,10 +283,9 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, | |||
275 | 283 | ||
276 | set_page_writeback(page); | 284 | set_page_writeback(page); |
277 | unlock_page(page); | 285 | unlock_page(page); |
278 | ret = mapping->a_ops->direct_IO(KERNEL_WRITE, | 286 | ret = mapping->a_ops->direct_IO(ITER_BVEC | WRITE, |
279 | &kiocb, &iov, | 287 | &kiocb, &from, |
280 | kiocb.ki_pos, 1); | 288 | kiocb.ki_pos); |
281 | kunmap(page); | ||
282 | if (ret == PAGE_SIZE) { | 289 | if (ret == PAGE_SIZE) { |
283 | count_vm_event(PSWPOUT); | 290 | count_vm_event(PSWPOUT); |
284 | ret = 0; | 291 | ret = 0; |
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c index 8505c9262b35..5077afcd9e11 100644 --- a/mm/process_vm_access.c +++ b/mm/process_vm_access.c | |||
@@ -46,11 +46,7 @@ static int process_vm_rw_pages(struct page **pages, | |||
46 | copy = len; | 46 | copy = len; |
47 | 47 | ||
48 | if (vm_write) { | 48 | if (vm_write) { |
49 | if (copy > iov_iter_count(iter)) | 49 | copied = copy_page_from_iter(page, offset, copy, iter); |
50 | copy = iov_iter_count(iter); | ||
51 | copied = iov_iter_copy_from_user(page, iter, | ||
52 | offset, copy); | ||
53 | iov_iter_advance(iter, copied); | ||
54 | set_page_dirty_lock(page); | 50 | set_page_dirty_lock(page); |
55 | } else { | 51 | } else { |
56 | copied = copy_page_to_iter(page, offset, copy, iter); | 52 | copied = copy_page_to_iter(page, offset, copy, iter); |
@@ -278,7 +274,7 @@ static ssize_t process_vm_rw(pid_t pid, | |||
278 | if (rc <= 0) | 274 | if (rc <= 0) |
279 | goto free_iovecs; | 275 | goto free_iovecs; |
280 | 276 | ||
281 | iov_iter_init(&iter, iov_l, liovcnt, rc, 0); | 277 | iov_iter_init(&iter, vm_write ? WRITE : READ, iov_l, liovcnt, rc); |
282 | 278 | ||
283 | rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, | 279 | rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, |
284 | iovstack_r, &iov_r); | 280 | iovstack_r, &iov_r); |
@@ -341,7 +337,7 @@ compat_process_vm_rw(compat_pid_t pid, | |||
341 | &iov_l); | 337 | &iov_l); |
342 | if (rc <= 0) | 338 | if (rc <= 0) |
343 | goto free_iovecs; | 339 | goto free_iovecs; |
344 | iov_iter_init(&iter, iov_l, liovcnt, rc, 0); | 340 | iov_iter_init(&iter, vm_write ? WRITE : READ, iov_l, liovcnt, rc); |
345 | rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, | 341 | rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, |
346 | UIO_FASTIOV, iovstack_r, | 342 | UIO_FASTIOV, iovstack_r, |
347 | &iov_r); | 343 | &iov_r); |
diff --git a/mm/shmem.c b/mm/shmem.c index 5402481c28d1..f484c276e994 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -1406,8 +1406,7 @@ shmem_write_end(struct file *file, struct address_space *mapping, | |||
1406 | return copied; | 1406 | return copied; |
1407 | } | 1407 | } |
1408 | 1408 | ||
1409 | static ssize_t shmem_file_aio_read(struct kiocb *iocb, | 1409 | static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) |
1410 | const struct iovec *iov, unsigned long nr_segs, loff_t pos) | ||
1411 | { | 1410 | { |
1412 | struct file *file = iocb->ki_filp; | 1411 | struct file *file = iocb->ki_filp; |
1413 | struct inode *inode = file_inode(file); | 1412 | struct inode *inode = file_inode(file); |
@@ -1416,15 +1415,8 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb, | |||
1416 | unsigned long offset; | 1415 | unsigned long offset; |
1417 | enum sgp_type sgp = SGP_READ; | 1416 | enum sgp_type sgp = SGP_READ; |
1418 | int error = 0; | 1417 | int error = 0; |
1419 | ssize_t retval; | 1418 | ssize_t retval = 0; |
1420 | size_t count; | ||
1421 | loff_t *ppos = &iocb->ki_pos; | 1419 | loff_t *ppos = &iocb->ki_pos; |
1422 | struct iov_iter iter; | ||
1423 | |||
1424 | retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE); | ||
1425 | if (retval) | ||
1426 | return retval; | ||
1427 | iov_iter_init(&iter, iov, nr_segs, count, 0); | ||
1428 | 1420 | ||
1429 | /* | 1421 | /* |
1430 | * Might this read be for a stacking filesystem? Then when reading | 1422 | * Might this read be for a stacking filesystem? Then when reading |
@@ -1500,14 +1492,14 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb, | |||
1500 | * Ok, we have the page, and it's up-to-date, so | 1492 | * Ok, we have the page, and it's up-to-date, so |
1501 | * now we can copy it to user space... | 1493 | * now we can copy it to user space... |
1502 | */ | 1494 | */ |
1503 | ret = copy_page_to_iter(page, offset, nr, &iter); | 1495 | ret = copy_page_to_iter(page, offset, nr, to); |
1504 | retval += ret; | 1496 | retval += ret; |
1505 | offset += ret; | 1497 | offset += ret; |
1506 | index += offset >> PAGE_CACHE_SHIFT; | 1498 | index += offset >> PAGE_CACHE_SHIFT; |
1507 | offset &= ~PAGE_CACHE_MASK; | 1499 | offset &= ~PAGE_CACHE_MASK; |
1508 | 1500 | ||
1509 | page_cache_release(page); | 1501 | page_cache_release(page); |
1510 | if (!iov_iter_count(&iter)) | 1502 | if (!iov_iter_count(to)) |
1511 | break; | 1503 | break; |
1512 | if (ret < nr) { | 1504 | if (ret < nr) { |
1513 | error = -EFAULT; | 1505 | error = -EFAULT; |
@@ -2629,13 +2621,13 @@ static const struct file_operations shmem_file_operations = { | |||
2629 | .mmap = shmem_mmap, | 2621 | .mmap = shmem_mmap, |
2630 | #ifdef CONFIG_TMPFS | 2622 | #ifdef CONFIG_TMPFS |
2631 | .llseek = shmem_file_llseek, | 2623 | .llseek = shmem_file_llseek, |
2632 | .read = do_sync_read, | 2624 | .read = new_sync_read, |
2633 | .write = do_sync_write, | 2625 | .write = new_sync_write, |
2634 | .aio_read = shmem_file_aio_read, | 2626 | .read_iter = shmem_file_read_iter, |
2635 | .aio_write = generic_file_aio_write, | 2627 | .write_iter = generic_file_write_iter, |
2636 | .fsync = noop_fsync, | 2628 | .fsync = noop_fsync, |
2637 | .splice_read = shmem_file_splice_read, | 2629 | .splice_read = shmem_file_splice_read, |
2638 | .splice_write = generic_file_splice_write, | 2630 | .splice_write = iter_file_splice_write, |
2639 | .fallocate = shmem_fallocate, | 2631 | .fallocate = shmem_fallocate, |
2640 | #endif | 2632 | #endif |
2641 | }; | 2633 | }; |
diff --git a/mm/vmscan.c b/mm/vmscan.c index e01ded365440..0f16ffe8eb67 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c | |||
@@ -464,7 +464,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping, | |||
464 | * stalls if we need to run get_block(). We could test | 464 | * stalls if we need to run get_block(). We could test |
465 | * PagePrivate for that. | 465 | * PagePrivate for that. |
466 | * | 466 | * |
467 | * If this process is currently in __generic_file_aio_write() against | 467 | * If this process is currently in __generic_file_write_iter() against |
468 | * this page's queue, we can perform writeback even if that | 468 | * this page's queue, we can perform writeback even if that |
469 | * will block. | 469 | * will block. |
470 | * | 470 | * |
diff --git a/net/ceph/pagevec.c b/net/ceph/pagevec.c index 815a2249cfa9..555013034f7a 100644 --- a/net/ceph/pagevec.c +++ b/net/ceph/pagevec.c | |||
@@ -53,7 +53,10 @@ void ceph_put_page_vector(struct page **pages, int num_pages, bool dirty) | |||
53 | set_page_dirty_lock(pages[i]); | 53 | set_page_dirty_lock(pages[i]); |
54 | put_page(pages[i]); | 54 | put_page(pages[i]); |
55 | } | 55 | } |
56 | kfree(pages); | 56 | if (is_vmalloc_addr(pages)) |
57 | vfree(pages); | ||
58 | else | ||
59 | kfree(pages); | ||
57 | } | 60 | } |
58 | EXPORT_SYMBOL(ceph_put_page_vector); | 61 | EXPORT_SYMBOL(ceph_put_page_vector); |
59 | 62 | ||
@@ -165,36 +168,6 @@ void ceph_copy_from_page_vector(struct page **pages, | |||
165 | EXPORT_SYMBOL(ceph_copy_from_page_vector); | 168 | EXPORT_SYMBOL(ceph_copy_from_page_vector); |
166 | 169 | ||
167 | /* | 170 | /* |
168 | * copy user data from a page vector into a user pointer | ||
169 | */ | ||
170 | int ceph_copy_page_vector_to_user(struct page **pages, | ||
171 | void __user *data, | ||
172 | loff_t off, size_t len) | ||
173 | { | ||
174 | int i = 0; | ||
175 | int po = off & ~PAGE_CACHE_MASK; | ||
176 | int left = len; | ||
177 | int l, bad; | ||
178 | |||
179 | while (left > 0) { | ||
180 | l = min_t(int, left, PAGE_CACHE_SIZE-po); | ||
181 | bad = copy_to_user(data, page_address(pages[i]) + po, l); | ||
182 | if (bad == l) | ||
183 | return -EFAULT; | ||
184 | data += l - bad; | ||
185 | left -= l - bad; | ||
186 | if (po) { | ||
187 | po += l - bad; | ||
188 | if (po == PAGE_CACHE_SIZE) | ||
189 | po = 0; | ||
190 | } | ||
191 | i++; | ||
192 | } | ||
193 | return len; | ||
194 | } | ||
195 | EXPORT_SYMBOL(ceph_copy_page_vector_to_user); | ||
196 | |||
197 | /* | ||
198 | * Zero an extent within a page vector. Offset is relative to the | 171 | * Zero an extent within a page vector. Offset is relative to the |
199 | * start of the first page. | 172 | * start of the first page. |
200 | */ | 173 | */ |