[Devel] [PATCH RH7 5/5] ext4: Use initial count in ext4_ind_direct_IO()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Jun 22 19:19:45 MSK 2021


We can't use iov_iter_count() here, since iter is advanced in:

__blockdev_direct_IO()->do_direct_IO()->dio_refill_pages().

In case of iter is completely advanced and direct IO failed
on last page, iov_iter_count(iter) returns 0 here. Then,
we have end == isize, and ext4_truncate_failed_write()
is not called (this function cancels partially completed
writes). In further, we have a written extent after
inode size, since ext4_update_i_disksize() is not called
in this function.

Note, that BUG actually becomes visible after 884dd390d7a0
"new helper: iov_iter_npages()", while it's introduced earlier.

https://jira.sw.ru/browse/PSBM-129846

Fixes: 6072179f278a "ext4: Use iov_iter argument in direct_IO functions"
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 fs/ext4/indirect.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index b598607e19c2..513d05de0cc4 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -730,7 +730,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
 
 		if (unlikely((rw & WRITE) && ret < 0)) {
 			loff_t isize = i_size_read(inode);
-			loff_t end = offset + iov_iter_count(iter);
+			loff_t end = offset + count;
 
 			if (end > isize)
 				ext4_truncate_failed_write(inode);




More information about the Devel mailing list