Skip to content

Commit 3486237

Browse files
committed
iomap: cleanup up iomap_dio_bio_end_io()
Make the logic a bit easier to follow: 1) Add a release_bio out path, as everybody needs to touch that, and have our bio ref check jump there if it's non-zero. 2) Add a kiocb local variable. 3) Add comments for each of the three conditions (sync, inline, or async workqueue punt). No functional changes in this patch. Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ccff6d1 commit 3486237

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

fs/iomap/direct-io.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,43 @@ void iomap_dio_bio_end_io(struct bio *bio)
152152
{
153153
struct iomap_dio *dio = bio->bi_private;
154154
bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
155+
struct kiocb *iocb = dio->iocb;
155156

156157
if (bio->bi_status)
157158
iomap_dio_set_error(dio, blk_status_to_errno(bio->bi_status));
159+
if (!atomic_dec_and_test(&dio->ref))
160+
goto release_bio;
158161

159-
if (atomic_dec_and_test(&dio->ref)) {
160-
if (dio->wait_for_completion) {
161-
struct task_struct *waiter = dio->submit.waiter;
162-
WRITE_ONCE(dio->submit.waiter, NULL);
163-
blk_wake_io_task(waiter);
164-
} else if (dio->flags & IOMAP_DIO_WRITE) {
165-
struct inode *inode = file_inode(dio->iocb->ki_filp);
166-
167-
WRITE_ONCE(dio->iocb->private, NULL);
168-
INIT_WORK(&dio->aio.work, iomap_dio_complete_work);
169-
queue_work(inode->i_sb->s_dio_done_wq, &dio->aio.work);
170-
} else {
171-
WRITE_ONCE(dio->iocb->private, NULL);
172-
iomap_dio_complete_work(&dio->aio.work);
173-
}
162+
/*
163+
* Synchronous dio, task itself will handle any completion work
164+
* that needs after IO. All we need to do is wake the task.
165+
*/
166+
if (dio->wait_for_completion) {
167+
struct task_struct *waiter = dio->submit.waiter;
168+
169+
WRITE_ONCE(dio->submit.waiter, NULL);
170+
blk_wake_io_task(waiter);
171+
goto release_bio;
172+
}
173+
174+
/* Read completion can always complete inline. */
175+
if (!(dio->flags & IOMAP_DIO_WRITE)) {
176+
WRITE_ONCE(iocb->private, NULL);
177+
iomap_dio_complete_work(&dio->aio.work);
178+
goto release_bio;
174179
}
175180

181+
/*
182+
* Async DIO completion that requires filesystem level completion work
183+
* gets punted to a work queue to complete as the operation may require
184+
* more IO to be issued to finalise filesystem metadata changes or
185+
* guarantee data integrity.
186+
*/
187+
WRITE_ONCE(iocb->private, NULL);
188+
INIT_WORK(&dio->aio.work, iomap_dio_complete_work);
189+
queue_work(file_inode(iocb->ki_filp)->i_sb->s_dio_done_wq,
190+
&dio->aio.work);
191+
release_bio:
176192
if (should_dirty) {
177193
bio_check_pages_dirty(bio);
178194
} else {

0 commit comments

Comments
 (0)