Skip to contentSkip to conversation

ext2: preserve completed DIO bytes when buffered fallback fails

PATCH In review Hungyu Lin 3 participants 3 messages Nov 2

Subsystems (2)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 ext2: preserve completed DIO bytes when buffered fallback fails

ext2_dio_write_iter() can complete part of a direct write before falling back to buffered I/O for a hole inside i_size. If generic_perform_write() then fails, its error overwrites the completed direct-I/O byte count.

For example, on a full filesystem, an 8 KiB write to a file with an allocated 4 KiB prefix and a 4 KiB hole overwrites the prefix but returns ENOSPC and leaves the file position unchanged. GNU dd with oflag=direct consequently reports zero bytes written.

Preserve a positive direct-I/O result and return the buffered error when no bytes were direct-written. This restores the fallback policy of generic_file_write_iter(), which ext2 used before its iomap conversion.

Fixes fb5de4358e1a ("ext2: Move direct-io to use iomap")
---
 fs/ext2/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext2/file.c +2 -1
index 67fe423c3828..8ddc149d4884 100644
@@ -145,7 +145,8 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		pos = iocb->ki_pos;
 		status = generic_perform_write(iocb, from);
 		if (unlikely(status < 0)) {
-			ret = status;
+			if (!ret)
+				ret = status;
 			goto out_unlock;
 		}
 
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

ext2_dio_write_iter() can complete part of a direct write before falling back to buffered I/O for a hole inside i_size. If generic_perform_write() then fails, its error overwrites the completed direct-I/O byte count.

For example, on a full filesystem, an 8 KiB write to a file with an allocated 4 KiB prefix and a 4 KiB hole overwrites the prefix but returns ENOSPC and leaves the file position unchanged. GNU dd with oflag=direct consequently reports zero bytes written.

Quoted 7 lines

Preserve a positive direct-I/O result and return the buffered error when no bytes were direct-written. This restores the fallback policy of generic_file_write_iter(), which ext2 used before its iomap conversion.

Fixes fb5de4358e1a ("ext2: Move direct-io to use iomap")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Hungyu Lin
Quoted 10 lines · Hungyu Lin

ext2_dio_write_iter() can complete part of a direct write before falling back to buffered I/O for a hole inside i_size. If generic_perform_write() then fails, its error overwrites the completed direct-I/O byte count.

For example, on a full filesystem, an 8 KiB write to a file with an allocated 4 KiB prefix and a 4 KiB hole overwrites the prefix but returns ENOSPC and leaves the file position unchanged. GNU dd with oflag=direct consequently reports zero bytes written.

Quoted 7 lines

Preserve a positive direct-I/O result and return the buffered error when no bytes were direct-written. This restores the fallback policy of generic_file_write_iter(), which ext2 used before its iomap conversion.

Fixes fb5de4358e1a ("ext2: Move direct-io to use iomap")

Thanks. Applied to my tree.

Honza

Quoted 21 lines
---
 fs/ext2/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext2/file.c +2 -1
index 67fe423c3828..8ddc149d4884 100644
@@ -145,7 +145,8 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		pos = iocb->ki_pos;
 		status = generic_perform_write(iocb, from);
 		if (unlikely(status < 0)) {
-			ret = status;
+			if (!ret)
+				ret = status;
 			goto out_unlock;
 		}
 
Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR