@@ -201,12 +201,12 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
201
201
unsigned int blkbits = blksize_bits (bdev_logical_block_size (iomap -> bdev ));
202
202
unsigned int fs_block_size = i_blocksize (inode ), pad ;
203
203
unsigned int align = iov_iter_alignment (dio -> submit .iter );
204
- struct iov_iter iter ;
205
204
struct bio * bio ;
206
205
bool need_zeroout = false;
207
206
bool use_fua = false;
208
207
int nr_pages , ret = 0 ;
209
208
size_t copied = 0 ;
209
+ size_t orig_count ;
210
210
211
211
if ((pos | length | align ) & ((1 << blkbits ) - 1 ))
212
212
return - EINVAL ;
@@ -236,15 +236,18 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
236
236
}
237
237
238
238
/*
239
- * Operate on a partial iter trimmed to the extent we were called for.
240
- * We'll update the iter in the dio once we're done with this extent.
239
+ * Save the original count and trim the iter to just the extent we
240
+ * are operating on right now. The iter will be re-expanded once
241
+ * we are done.
241
242
*/
242
- iter = * dio -> submit .iter ;
243
- iov_iter_truncate (& iter , length );
243
+ orig_count = iov_iter_count ( dio -> submit .iter ) ;
244
+ iov_iter_truncate (dio -> submit . iter , length );
244
245
245
- nr_pages = iov_iter_npages (& iter , BIO_MAX_PAGES );
246
- if (nr_pages <= 0 )
247
- return nr_pages ;
246
+ nr_pages = iov_iter_npages (dio -> submit .iter , BIO_MAX_PAGES );
247
+ if (nr_pages <= 0 ) {
248
+ ret = nr_pages ;
249
+ goto out ;
250
+ }
248
251
249
252
if (need_zeroout ) {
250
253
/* zero out from the start of the block to the write offset */
@@ -257,7 +260,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
257
260
size_t n ;
258
261
if (dio -> error ) {
259
262
iov_iter_revert (dio -> submit .iter , copied );
260
- return 0 ;
263
+ copied = ret = 0 ;
264
+ goto out ;
261
265
}
262
266
263
267
bio = bio_alloc (GFP_KERNEL , nr_pages );
@@ -268,7 +272,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
268
272
bio -> bi_private = dio ;
269
273
bio -> bi_end_io = iomap_dio_bio_end_io ;
270
274
271
- ret = bio_iov_iter_get_pages (bio , & iter );
275
+ ret = bio_iov_iter_get_pages (bio , dio -> submit . iter );
272
276
if (unlikely (ret )) {
273
277
/*
274
278
* We have to stop part way through an IO. We must fall
@@ -294,13 +298,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
294
298
bio_set_pages_dirty (bio );
295
299
}
296
300
297
- iov_iter_advance (dio -> submit .iter , n );
298
-
299
301
dio -> size += n ;
300
302
pos += n ;
301
303
copied += n ;
302
304
303
- nr_pages = iov_iter_npages (& iter , BIO_MAX_PAGES );
305
+ nr_pages = iov_iter_npages (dio -> submit . iter , BIO_MAX_PAGES );
304
306
iomap_dio_submit_bio (dio , iomap , bio );
305
307
} while (nr_pages );
306
308
@@ -318,6 +320,9 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
318
320
if (pad )
319
321
iomap_dio_zero (dio , iomap , pos , fs_block_size - pad );
320
322
}
323
+ out :
324
+ /* Undo iter limitation to current extent */
325
+ iov_iter_reexpand (dio -> submit .iter , orig_count - copied );
321
326
if (copied )
322
327
return copied ;
323
328
return ret ;
@@ -400,7 +405,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
400
405
struct address_space * mapping = iocb -> ki_filp -> f_mapping ;
401
406
struct inode * inode = file_inode (iocb -> ki_filp );
402
407
size_t count = iov_iter_count (iter );
403
- loff_t pos = iocb -> ki_pos , start = pos ;
408
+ loff_t pos = iocb -> ki_pos ;
404
409
loff_t end = iocb -> ki_pos + count - 1 , ret = 0 ;
405
410
unsigned int flags = IOMAP_DIRECT ;
406
411
struct blk_plug plug ;
@@ -456,14 +461,14 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
456
461
}
457
462
458
463
if (iocb -> ki_flags & IOCB_NOWAIT ) {
459
- if (filemap_range_has_page (mapping , start , end )) {
464
+ if (filemap_range_has_page (mapping , pos , end )) {
460
465
ret = - EAGAIN ;
461
466
goto out_free_dio ;
462
467
}
463
468
flags |= IOMAP_NOWAIT ;
464
469
}
465
470
466
- ret = filemap_write_and_wait_range (mapping , start , end );
471
+ ret = filemap_write_and_wait_range (mapping , pos , end );
467
472
if (ret )
468
473
goto out_free_dio ;
469
474
@@ -474,7 +479,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
474
479
* pretty crazy thing to do, so we don't support it 100%.
475
480
*/
476
481
ret = invalidate_inode_pages2_range (mapping ,
477
- start >> PAGE_SHIFT , end >> PAGE_SHIFT );
482
+ pos >> PAGE_SHIFT , end >> PAGE_SHIFT );
478
483
if (ret )
479
484
dio_warn_stale_pagecache (iocb -> ki_filp );
480
485
ret = 0 ;
0 commit comments