Skip to contentSkip to conversation

fault-inject: fix wrong should_fail() decision in task context

PATCH In review Akinobu Mita 2 participants 2 messages Aug 2, 2017

Subsystems (2)
lore
Share & tools
lore

Akinobu Mita

author maintainer
#0 lore raw

PATCH 1/1 fault-inject: fix wrong should_fail() decision in task context

Commit 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth") unintentionally broke a conditional statement in should_fail(). Any faults are not injected in the task context by the change when the systematic fault injection is not used.

This change restores to the previous correct behaviour.

Fixes 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth")
Cc Dmitry Vyukov <[email protected]>
Cc Lu Fengqi <[email protected]>
---
 lib/fault-inject.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/fault-inject.c +5 -3
index 7d315fd..cf7b129 100644
@@ -110,10 +110,12 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 	if (in_task()) {
 		unsigned int fail_nth = READ_ONCE(current->fail_nth);
 
-		if (fail_nth && !WRITE_ONCE(current->fail_nth, fail_nth - 1))
-			goto fail;
+		if (fail_nth) {
+			if (!WRITE_ONCE(current->fail_nth, fail_nth - 1))
+				goto fail;
 
-		return false;
+			return false;
+		}
 	}
 
 	/* No need to check any other properties if the probability is 0 */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 41 lines · Akinobu Mita

Commit 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth") unintentionally broke a conditional statement in should_fail(). Any faults are not injected in the task context by the change when the systematic fault injection is not used.

This change restores to the previous correct behaviour.

Fixes 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth")
Cc Dmitry Vyukov <[email protected]>
Cc Lu Fengqi <[email protected]>

---
lib/fault-inject.c | 8 +++++---

1 file changed, 5 insertions(+), 3 deletions(-)
lib/fault-inject.c +5 -3
index 7d315fd..cf7b129 100644
@@ -110,10 +110,12 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 	if (in_task()) {
 		unsigned int fail_nth = READ_ONCE(current->fail_nth);
 
-		if (fail_nth && !WRITE_ONCE(current->fail_nth, fail_nth - 1))
-			goto fail;
+		if (fail_nth) {
+			if (!WRITE_ONCE(current->fail_nth, fail_nth - 1))
+				goto fail;
 
-		return false;
+			return false;
+		}
 	}
 
 	/* No need to check any other properties if the probability is 0 */
Signature · 1 line
2.7.4

With this fix, I can produce the IO ERROR by the fail_make_request.

Signature · 2 lines
Thanks,
Lu