Skip to contentSkip to conversation

ext4: don't block for O_DIRECT if IOCB_NOWAIT is set

PATCH Applied Jens Axboe 2 participants 2 messages May 24, 2020 – May 29, 2020 ext4 file system

lore
Share & tools
lore

Jens Axboe

author
#0 lore raw

PATCH 1/1 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.

---

fs/ext4/file.c +6 -0
index 0d624250a62b..3ac95f4cada6 100644
@@ -495,6 +495,12 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (ret <= 0)
 		return ret;
 
+	/* if we're going to block and IOCB_NOWAIT is set, return -EAGAIN */
+	if ((iocb->ki_flags & IOCB_NOWAIT) && (unaligned_io || extend)) {
+		ret = -EAGAIN;
+		goto out;
+	}
+
 	offset = iocb->ki_pos;
 	count = ret;
 
Signature · 1 line
Jens Axboe
maintainer Applied
#1 lore raw
Quoted 8 lines · Jens Axboe

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.

Thanks, applied.

- Ted