Conventional zone files allow both direct and buffered writes. An asynchronous direct write can remain active after its submitting thread releases the inode lock. A buffered write can then dirty page cache before direct I/O completion performs post-write invalidation, causing the invalidation to fail and record -EIO in the mapping error sequence. After taking the exclusive inode lock, wait for active DIO before running buffered write checks. Return -EAGAIN when an IOCB_NOWAIT request would otherwise block. Fixes: 4008e2a0b01a ("zonefs: Reorganize code") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao --- fs/zonefs/file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 5b34849be7a2..8635a795c24c 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -576,6 +576,14 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, inode_lock(inode); } + if (atomic_read(&inode->i_dio_count)) { + if (iocb->ki_flags & IOCB_NOWAIT) { + ret = -EAGAIN; + goto inode_unlock; + } + inode_dio_wait(inode); + } + ret = zonefs_write_checks(iocb, from); if (ret <= 0) goto inode_unlock; -- 2.34.1