aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 13:30:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 13:30:18 -0400
commit16b9057804c02e2d351e9c8f606e909b43cbd9e7 (patch)
treea3ac6e1d9d57a8abf4267e5ead3f2de1309335eb /drivers
parent5c02c392cd2320e8d612376d6b72b6548a680923 (diff)
parentc2338f2dc7c1e9f6202f370c64ffd7f44f3d4b51 (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() ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/raw.c8
-rw-r--r--drivers/mtd/nand/nandsim.c4
-rw-r--r--drivers/staging/lustre/lustre/include/lclient.h11
-rw-r--r--drivers/staging/lustre/lustre/lclient/lcommon_cl.c48
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c112
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h3
-rw-r--r--drivers/staging/lustre/lustre/llite/rw.c3
-rw-r--r--drivers/staging/lustre/lustre/llite/rw26.c102
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c29
-rw-r--r--drivers/usb/gadget/storage_common.c4
10 files changed, 85 insertions, 239 deletions
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
286static const struct file_operations raw_fops = { 286static 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,
720void ccc_io_update_iov(const struct lu_env *env, 720void 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
750int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io, 731int 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
1183static ssize_t ll_file_aio_read(struct kiocb *iocb, const struct iovec *iov, 1181static 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
1211static 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 */
1242static ssize_t ll_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 1205static 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
1270static 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 */
3145struct file_operations ll_file_operations = { 3071struct 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
3160struct file_operations ll_file_operations_flock = { 3086struct 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 */
3178struct file_operations ll_file_operations_noflock = { 3104struct 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
231ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, 228ssize_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))
365static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb, 362static 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 }
472out: 450out:
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);