Skip to contentSkip to conversation

ext4: Do not block RWF_NOWAIT dio write on unallocated space

PATCH Applied Jan Kara 3 participants 4 messages Jul 8, 2020 – Aug 6, 2020 ext4 file system

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Do not block RWF_NOWAIT dio write on unallocated space

Since commit 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") we don't properly bail out of RWF_NOWAIT direct IO write if underlying blocks are not allocated. Also ext4_dio_write_checks() does not honor RWF_NOWAIT when re-acquiring i_rwsem. Fix both issues.

Fixes 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure")
---
 fs/ext4/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ext4/file.c +4 -0
index 2a01e31a032c..8f742b53f1d4 100644
@@ -428,6 +428,10 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from,
 	 */
 	if (*ilock_shared && (!IS_NOSEC(inode) || *extend ||
 	     !ext4_overwrite_io(inode, offset, count))) {
+		if (iocb->ki_flags & IOCB_NOWAIT) {
+			ret = -EAGAIN;
+			goto out;
+		}
 		inode_unlock_shared(inode);
 		*ilock_shared = false;
 		inode_lock(inode);
Signature · 1 line
2.16.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jan Kara

Since commit 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") we don't properly bail out of RWF_NOWAIT direct IO write if underlying blocks are not allocated. Also ext4_dio_write_checks() does not honor RWF_NOWAIT when re-acquiring i_rwsem. Fix both issues.

Fixes 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure")

LGTM, feel free to add

Quoted 20 lines
---
  fs/ext4/file.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/ext4/file.c +4 -0
index 2a01e31a032c..8f742b53f1d4 100644
@@ -428,6 +428,10 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from,
  	 */
  	if (*ilock_shared && (!IS_NOSEC(inode) || *extend ||
  	     !ext4_overwrite_io(inode, offset, count))) {
+		if (iocb->ki_flags & IOCB_NOWAIT) {
+			ret = -EAGAIN;
+			goto out;
+		}
  		inode_unlock_shared(inode);
  		*ilock_shared = false;
  		inode_lock(inode);
author reviewer
#2 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

Since commit 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") we don't properly bail out of RWF_NOWAIT direct IO write if underlying blocks are not allocated. Also ext4_dio_write_checks() does not honor RWF_NOWAIT when re-acquiring i_rwsem. Fix both issues.

Fixes 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure")

Ted, can you please merge this patch? Thanks!

Honza

Quoted 22 lines
---
 fs/ext4/file.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ext4/file.c +4 -0
index 2a01e31a032c..8f742b53f1d4 100644
@@ -428,6 +428,10 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from,
 	 */
 	if (*ilock_shared && (!IS_NOSEC(inode) || *extend ||
 	     !ext4_overwrite_io(inode, offset, count))) {
+		if (iocb->ki_flags & IOCB_NOWAIT) {
+			ret = -EAGAIN;
+			goto out;
+		}
 		inode_unlock_shared(inode);
 		*ilock_shared = false;
 		inode_lock(inode);
Signature · 1 line
2.16.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#3 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

Since commit 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") we don't properly bail out of RWF_NOWAIT direct IO write if underlying blocks are not allocated. Also ext4_dio_write_checks() does not honor RWF_NOWAIT when re-acquiring i_rwsem. Fix both issues.

Fixes 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure")

Applied, thanks.

- Ted