Skip to contentSkip to conversation

fs: fix lost error code in dio_complete

PATCH Superseded Maximilian Heyne 3 participants 5 messages Oct 30, 2018 – Nov 1, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fix lost error code in dio_complete

commit e259221763a40403d5bb232209998e8c45804ab8 ("fs: simplify the generic_write_sync prototype") reworked callers of generic_write_sync(), and ended up dropping the error return for the directio path. Prior to that commit, in dio_complete(), an error would be bubbled up the stack, but after that commit, errors passed on to dio_complete were eaten up.

This was reported on the list earlier, and a fix was proposed in
https://lore.kernel.org/lkml/[email protected]/, but never followed up with. We recently hit this bug in our testing where fencing io errors, which were previously erroring out with EIO, were being returned as success operations after this commit.

The fix proposed on the list earlier was a little short -- it would have still called generic_write_sync() in case ret already contained an error. This fix ensures generic_write_sync() is only called when there's no pending error in the write.

---
 fs/direct-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/direct-io.c +2 -2
index 093fb54cd316..199146036093 100644
@@ -325,8 +325,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
 		 */
 		dio->iocb->ki_pos += transferred;
 
-		if (dio->op == REQ_OP_WRITE)
-			ret = generic_write_sync(dio->iocb,  transferred);
+		if (ret > 0 && dio->op == REQ_OP_WRITE)
+			ret = generic_write_sync(dio->iocb, ret);
 		dio->iocb->ki_complete(dio->iocb, ret, 0);
 	}
 
Signature · 8 lines
2.16.2

Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
#2 lore raw
In reply to Maximilian Heyne
Quoted 36 lines · Maximilian Heyne

commit e259221763a40403d5bb232209998e8c45804ab8 ("fs: simplify the generic_write_sync prototype") reworked callers of generic_write_sync(), and ended up dropping the error return for the directio path. Prior to that commit, in dio_complete(), an error would be bubbled up the stack, but after that commit, errors passed on to dio_complete were eaten up.

This was reported on the list earlier, and a fix was proposed in
https://lore.kernel.org/lkml/[email protected]/, but never followed up with.  We recently hit this bug in our testing where fencing io errors, which were previously erroring out with EIO, were being returned as success operations after this commit.

The fix proposed on the list earlier was a little short -- it would have still called generic_write_sync() in case ret already contained an error.  This fix ensures generic_write_sync() is only called when there's no pending error in the write.

---
 fs/direct-io.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
fs/direct-io.c +0 -0
index 093fb54cd316..199146036093 100644
@@ -325,8 +325,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
  		 */
  		dio->iocb->ki_pos += transferred;

fs/direct-io.c static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) · line 329

Quoted 4 lines
fs/direct-io.c +2 -2
-		if (dio->op == REQ_OP_WRITE)
-			ret = generic_write_sync(dio->iocb,  transferred);
+		if (ret > 0 && dio->op == REQ_OP_WRITE)
+			ret = generic_write_sync(dio->iocb, ret);

Is the s/transferred/ret/ change necessary?  Needs explaining, at least.

Quoted 3 lines

  dio->iocb->ki_complete(dio->iocb, ret, 0); }

Thanks,

Amit
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

#3 lore raw
Quoted 11 lines · Amit
Quoted 10 lines · Maximilian Heyne

[...]

fs/direct-io.c +0 -0
index 093fb54cd316..199146036093 100644
@@ -325,8 +325,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
  		 */
  		dio->iocb->ki_pos += transferred;
 
Quoted 5 lines

fs/direct-io.c static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) · line 329

Quoted 4 lines
fs/direct-io.c +2 -2
-		if (dio->op == REQ_OP_WRITE)
-			ret = generic_write_sync(dio->iocb,  transferred);
+		if (ret > 0 && dio->op == REQ_OP_WRITE)
+			ret = generic_write_sync(dio->iocb, ret);

Is the s/transferred/ret/ change necessary?  Needs explaining, at least.

In an above code line ret is set to transferred. So the change is a no op. However, in my opinion the construct then looks cleaner.

Quoted 8 lines

fs/direct-io.c static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) · line 332

Quoted 3 lines
fs/direct-io.c +0 -0
  		dio->iocb->ki_complete(dio->iocb, ret, 0);
  	}
 

Thanks,

Amit

Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

#4 lore raw
Quoted 19 lines · Maximilian Heyne
Quoted 5 lines · Amit
Quoted 3 lines · Maximilian Heyne

[...]

Quoted 13 lines

fs/direct-io.c static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) · line 329

Quoted 12 lines
fs/direct-io.c +0 -0
index 093fb54cd316..199146036093 100644
@@ -325,8 +325,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
   		 */
   		dio->iocb->ki_pos += transferred;

fs/direct-io.c +2 -2
-		if (dio->op == REQ_OP_WRITE)
-			ret = generic_write_sync(dio->iocb,  transferred);
+		if (ret > 0 && dio->op == REQ_OP_WRITE)
+			ret = generic_write_sync(dio->iocb, ret);

Is the s/transferred/ret/ change necessary?  Needs explaining, at least.

Quoted 2 lines

In an above code line ret is set to transferred. So the change is a no op. However, in my opinion the construct then looks cleaner.

Yes, makes it also in line with the other callers, so this is good, thanks.

Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B