Skip to contentSkip to conversation

iomap: fix a regression for partial write errors

PATCH In review Christoph Hellwig 3 participants 6 messages Jul 14, 2023 – Jul 17, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iomap: fix a regression for partial write errors

When write* wrote some data it should return the amount of written data and not the error code that caused it to stop. Fix a recent regression in iomap_file_buffered_write that caused it to return the errno instead.

Fixes 219580eea1ee ("iomap: update ki_pos in iomap_file_buffered_write")
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index adb92cdb24b009..7cc9f7274883a5 100644
@@ -872,7 +872,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	while ((ret = iomap_iter(&iter, ops)) > 0)
 		iter.processed = iomap_write_iter(&iter, i);
 
-	if (unlikely(ret < 0))
+	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
 	iocb->ki_pos += ret;
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 iomap: micro optimize the ki_pos assignment in iomap_file_buffered_write

We have the new value for ki_pos right at hand in iter.pos, so assign that instead of recalculating it from ret.

---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index 7cc9f7274883a5..aa8967cca1a31b 100644
@@ -875,7 +875,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
-	iocb->ki_pos += ret;
+	iocb->ki_pos = iter.pos;
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iomap_file_buffered_write);
Signature · 1 line
2.39.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] iomap: micro optimize the ki_pos assignment in iomap_file_buffered_write

Quoted 4 lines · Christoph Hellwig

We have the new value for ki_pos right at hand in iter.pos, so assign that instead of recalculating it from ret.

Looks ok, will test...

--D

Quoted 20 lines
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index 7cc9f7274883a5..aa8967cca1a31b 100644
@@ -875,7 +875,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
-	iocb->ki_pos += ret;
+	iocb->ki_pos = iter.pos;
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iomap_file_buffered_write);
Signature · 1 line
2.39.2
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] iomap: micro optimize the ki_pos assignment in iomap_file_buffered_write

In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

We have the new value for ki_pos right at hand in iter.pos, so assign that instead of recalculating it from ret.

Looks good to me. Feel free to add -

Quoted 20 lines
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index 7cc9f7274883a5..aa8967cca1a31b 100644
@@ -875,7 +875,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
-	iocb->ki_pos += ret;
+	iocb->ki_pos = iter.pos;
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iomap_file_buffered_write);
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#4 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

When write* wrote some data it should return the amount of written data and not the error code that caused it to stop. Fix a recent regression in iomap_file_buffered_write that caused it to return the errno instead.

Fixes 219580eea1ee ("iomap: update ki_pos in iomap_file_buffered_write")

Simple enough reversion, sorry for the breakage...

--D

Quoted 20 lines
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index adb92cdb24b009..7cc9f7274883a5 100644
@@ -872,7 +872,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	while ((ret = iomap_iter(&iter, ops)) > 0)
 		iter.processed = iomap_write_iter(&iter, i);
 
-	if (unlikely(ret < 0))
+	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
 	iocb->ki_pos += ret;
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#5 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

When write* wrote some data it should return the amount of written data and not the error code that caused it to stop. Fix a recent regression in iomap_file_buffered_write that caused it to return the errno instead.

Agreed. Reviewed the change and it looks right to me. Feel free to add -

Quoted 5 lines
Fixes 219580eea1ee ("iomap: update ki_pos in iomap_file_buffered_write")

---

In case anyone wanted to see before and after test failures output of

./runltp -f syscalls -s writev07 -d /mnt1/test

<without this patch>
tst_test.c:1558: TINFO: Timeout per run is 0h 00m 30s writev07.c:50: TINFO: starting test with initial file offset: 0 writev07.c:73: TINFO: got EFAULT
writev07.c:78: TFAIL: file was written to writev07.c:84: TPASS: offset stayed unchanged writev07.c:50: TINFO: starting test with initial file offset: 65 writev07.c:73: TINFO: got EFAULT
writev07.c:78: TFAIL: file was written to writev07.c:84: TPASS: offset stayed unchanged writev07.c:50: TINFO: starting test with initial file offset: 4096 writev07.c:73: TINFO: got EFAULT
writev07.c:80: TPASS: file stayed untouched writev07.c:84: TPASS: offset stayed unchanged writev07.c:50: TINFO: starting test with initial file offset: 4097 writev07.c:73: TINFO: got EFAULT
writev07.c:80: TPASS: file stayed untouched writev07.c:84: TPASS: offset stayed unchanged

Summary:

passed   6
failed   2
broken   0
skipped  0

warnings 0

<with this patch>
tst_test.c:1558: TINFO: Timeout per run is 0h 00m 30s writev07.c:50: TINFO: starting test with initial file offset: 0 writev07.c:94: TINFO: writev() has written 64 bytes writev07.c:105: TPASS: file has expected content writev07.c:116: TPASS: offset at 64 as expected writev07.c:50: TINFO: starting test with initial file offset: 65 writev07.c:94: TINFO: writev() has written 64 bytes writev07.c:105: TPASS: file has expected content writev07.c:116: TPASS: offset at 129 as expected writev07.c:50: TINFO: starting test with initial file offset: 4096 writev07.c:94: TINFO: writev() has written 64 bytes writev07.c:105: TPASS: file has expected content writev07.c:116: TPASS: offset at 4160 as expected writev07.c:50: TINFO: starting test with initial file offset: 4097 writev07.c:94: TINFO: writev() has written 64 bytes writev07.c:105: TPASS: file has expected content writev07.c:116: TPASS: offset at 4161 as expected

Summary:

passed   8
failed   0
broken   0
skipped  0

warnings 0

Quoted 18 lines
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
index adb92cdb24b009..7cc9f7274883a5 100644
@@ -872,7 +872,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
 	while ((ret = iomap_iter(&iter, ops)) > 0)
 		iter.processed = iomap_write_iter(&iter, i);
 
-	if (unlikely(ret < 0))
+	if (unlikely(iter.pos == iocb->ki_pos))
 		return ret;
 	ret = iter.pos - iocb->ki_pos;
 	iocb->ki_pos += ret;
Signature · 1 line
2.39.2

-ritesh