Skip to content

Commit 6e014c6

Browse files
axboetytso
authored andcommitted
ext4: don't block for O_DIRECT if IOCB_NOWAIT is set
Running with some debug patches to detect illegal blocking triggered the extend/unaligned condition in ext4. If ext4 needs to extend the file (and hence go to buffered IO), or if the app is doing unaligned IO, then ext4 asks the iomap code to wait for IO completion. If the caller asked for no-wait semantics by setting IOCB_NOWAIT, then ext4 should return -EAGAIN instead. Signed-off-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent ba98890 commit 6e014c6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/ext4/file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
502502
if (ret <= 0)
503503
return ret;
504504

505+
/* if we're going to block and IOCB_NOWAIT is set, return -EAGAIN */
506+
if ((iocb->ki_flags & IOCB_NOWAIT) && (unaligned_io || extend)) {
507+
ret = -EAGAIN;
508+
goto out;
509+
}
510+
505511
offset = iocb->ki_pos;
506512
count = ret;
507513

0 commit comments

Comments
 (0)