summaryrefslogtreecommitdiffstats
path: root/fs/direct-io.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-10-18 14:43:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-10-18 14:43:40 -0400
commit020b3023762fdf6cc816ed154e3b1f8eafaf0836 (patch)
treea45c77db6c2e6ad300125bf54943d9df16b87b6e /fs/direct-io.c
parent3e0cc09a3a2c40ec1ffb6b4e12da86e98feccb11 (diff)
parentffe51f0142a291a957eebb9687cafb15f2b3fc14 (diff)
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Three small fixes: - A fix for skd, it was using kfree() to free a structure allocate with kmem_cache_alloc(). - Stable fix for nbd, fixing a regression using the normal ioctl based tools. - Fix for a previous fix in this series, that fixed up inconsistencies between buffered and direct IO" * 'for-linus' of git://git.kernel.dk/linux-block: fs: Avoid invalidation in interrupt context in dio_complete() nbd: don't set the device size until we're connected skd: Use kmem_cache_free
Diffstat (limited to 'fs/direct-io.c')
-rw-r--r--fs/direct-io.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 96415c65bbdc..563254869e2f 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -45,6 +45,12 @@
45#define DIO_PAGES 64 45#define DIO_PAGES 64
46 46
47/* 47/*
48 * Flags for dio_complete()
49 */
50#define DIO_COMPLETE_ASYNC 0x01 /* This is async IO */
51#define DIO_COMPLETE_INVALIDATE 0x02 /* Can invalidate pages */
52
53/*
48 * This code generally works in units of "dio_blocks". A dio_block is 54 * This code generally works in units of "dio_blocks". A dio_block is
49 * somewhere between the hard sector size and the filesystem block size. it 55 * somewhere between the hard sector size and the filesystem block size. it
50 * is determined on a per-invocation basis. When talking to the filesystem 56 * is determined on a per-invocation basis. When talking to the filesystem
@@ -225,7 +231,7 @@ static inline struct page *dio_get_page(struct dio *dio,
225 * filesystems can use it to hold additional state between get_block calls and 231 * filesystems can use it to hold additional state between get_block calls and
226 * dio_complete. 232 * dio_complete.
227 */ 233 */
228static ssize_t dio_complete(struct dio *dio, ssize_t ret, bool is_async) 234static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
229{ 235{
230 loff_t offset = dio->iocb->ki_pos; 236 loff_t offset = dio->iocb->ki_pos;
231 ssize_t transferred = 0; 237 ssize_t transferred = 0;
@@ -266,7 +272,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, bool is_async)
266 * one is a pretty crazy thing to do, so we don't support it 100%. If 272 * one is a pretty crazy thing to do, so we don't support it 100%. If
267 * this invalidation fails, tough, the write still worked... 273 * this invalidation fails, tough, the write still worked...
268 */ 274 */
269 if (ret > 0 && dio->op == REQ_OP_WRITE && 275 if (flags & DIO_COMPLETE_INVALIDATE &&
276 ret > 0 && dio->op == REQ_OP_WRITE &&
270 dio->inode->i_mapping->nrpages) { 277 dio->inode->i_mapping->nrpages) {
271 err = invalidate_inode_pages2_range(dio->inode->i_mapping, 278 err = invalidate_inode_pages2_range(dio->inode->i_mapping,
272 offset >> PAGE_SHIFT, 279 offset >> PAGE_SHIFT,
@@ -285,7 +292,7 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, bool is_async)
285 if (!(dio->flags & DIO_SKIP_DIO_COUNT)) 292 if (!(dio->flags & DIO_SKIP_DIO_COUNT))
286 inode_dio_end(dio->inode); 293 inode_dio_end(dio->inode);
287 294
288 if (is_async) { 295 if (flags & DIO_COMPLETE_ASYNC) {
289 /* 296 /*
290 * generic_write_sync expects ki_pos to have been updated 297 * generic_write_sync expects ki_pos to have been updated
291 * already, but the submission path only does this for 298 * already, but the submission path only does this for
@@ -306,7 +313,7 @@ static void dio_aio_complete_work(struct work_struct *work)
306{ 313{
307 struct dio *dio = container_of(work, struct dio, complete_work); 314 struct dio *dio = container_of(work, struct dio, complete_work);
308 315
309 dio_complete(dio, 0, true); 316 dio_complete(dio, 0, DIO_COMPLETE_ASYNC | DIO_COMPLETE_INVALIDATE);
310} 317}
311 318
312static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio); 319static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio);
@@ -348,7 +355,7 @@ static void dio_bio_end_aio(struct bio *bio)
348 queue_work(dio->inode->i_sb->s_dio_done_wq, 355 queue_work(dio->inode->i_sb->s_dio_done_wq,
349 &dio->complete_work); 356 &dio->complete_work);
350 } else { 357 } else {
351 dio_complete(dio, 0, true); 358 dio_complete(dio, 0, DIO_COMPLETE_ASYNC);
352 } 359 }
353 } 360 }
354} 361}
@@ -1360,7 +1367,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
1360 dio_await_completion(dio); 1367 dio_await_completion(dio);
1361 1368
1362 if (drop_refcount(dio) == 0) { 1369 if (drop_refcount(dio) == 0) {
1363 retval = dio_complete(dio, retval, false); 1370 retval = dio_complete(dio, retval, DIO_COMPLETE_INVALIDATE);
1364 } else 1371 } else
1365 BUG_ON(retval != -EIOCBQUEUED); 1372 BUG_ON(retval != -EIOCBQUEUED);
1366 1373