fault-inject: parse as natural 1-based value for fail-nth write interface
authorAkinobu Mita <akinobu.mita@gmail.com>
Fri, 14 Jul 2017 21:49:52 +0000 (14:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 14 Jul 2017 22:05:13 +0000 (15:05 -0700)
The value written to fail-nth file is parsed as 0-based.  Parsing as
one-based is more natural to understand and it enables to cancel the
previous setup by simply writing '0'.

This change also converts task->fail_nth from signed to unsigned int.

Link: http://lkml.kernel.org/r/1491490561-10485-3-git-send-email-akinobu.mita@gmail.com
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Documentation/fault-injection/fault-injection.txt
fs/proc/base.c
include/linux/sched.h

index 192d8cbcc5f998f47c76bfca653b61201f7fe160..a32190508751c330422b3d7aa40419fb84276fde 100644 (file)
@@ -138,8 +138,8 @@ o proc entries
 
 - /proc/self/task/<current-tid>/fail-nth:
 
 
 - /proc/self/task/<current-tid>/fail-nth:
 
-       Write to this file of integer N makes N-th call in the current task fail
-       (N is 0-based). Read from this file returns a single char 'Y' or 'N'
+       Write to this file of integer N makes N-th call in the task fail.
+       Read from this file returns a single char 'Y' or 'N'
        that says if the fault setup with a previous write to this file was
        injected or not, and disables the fault if it wasn't yet injected.
        Note that this file enables all types of faults (slab, futex, etc).
        that says if the fault setup with a previous write to this file was
        injected or not, and disables the fault if it wasn't yet injected.
        Note that this file enables all types of faults (slab, futex, etc).
@@ -320,7 +320,7 @@ int main()
        system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait");
        sprintf(buf, "/proc/self/task/%ld/fail-nth", syscall(SYS_gettid));
        fail_nth = open(buf, O_RDWR);
        system("echo N > /sys/kernel/debug/failslab/ignore-gfp-wait");
        sprintf(buf, "/proc/self/task/%ld/fail-nth", syscall(SYS_gettid));
        fail_nth = open(buf, O_RDWR);
-       for (i = 0;; i++) {
+       for (i = 1;; i++) {
                sprintf(buf, "%d", i);
                write(fail_nth, buf, strlen(buf));
                res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
                sprintf(buf, "%d", i);
                write(fail_nth, buf, strlen(buf));
                res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
@@ -339,7 +339,6 @@ int main()
 
 An example output:
 
 
 An example output:
 
-0-th fault Y: res=-1/23
 1-th fault Y: res=-1/23
 2-th fault Y: res=-1/23
 3-th fault Y: res=-1/12
 1-th fault Y: res=-1/23
 2-th fault Y: res=-1/23
 3-th fault Y: res=-1/12
index 5d93512beea11878efe6cd2984e84ba23a728c51..c1fdaecb8d23c99009d2aec5ec635f86b99ebd5b 100644 (file)
@@ -1360,7 +1360,8 @@ static ssize_t proc_fail_nth_write(struct file *file, const char __user *buf,
                                   size_t count, loff_t *ppos)
 {
        struct task_struct *task;
                                   size_t count, loff_t *ppos)
 {
        struct task_struct *task;
-       int err, n;
+       int err;
+       unsigned int n;
 
        task = get_proc_task(file_inode(file));
        if (!task)
 
        task = get_proc_task(file_inode(file));
        if (!task)
@@ -1368,12 +1369,10 @@ static ssize_t proc_fail_nth_write(struct file *file, const char __user *buf,
        put_task_struct(task);
        if (task != current)
                return -EPERM;
        put_task_struct(task);
        if (task != current)
                return -EPERM;
-       err = kstrtoint_from_user(buf, count, 0, &n);
+       err = kstrtouint_from_user(buf, count, 0, &n);
        if (err)
                return err;
        if (err)
                return err;
-       if (n < 0 || n == INT_MAX)
-               return -EINVAL;
-       current->fail_nth = n + 1;
+       current->fail_nth = n;
        return count;
 }
 
        return count;
 }
 
index 3822d749fc9ee8263ba8daadde5cec5edfb7516d..2ba9ec93423f97e97d0dd5ed99d0ee7fb23038f8 100644 (file)
@@ -974,7 +974,7 @@ struct task_struct {
 
 #ifdef CONFIG_FAULT_INJECTION
        int                             make_it_fail;
 
 #ifdef CONFIG_FAULT_INJECTION
        int                             make_it_fail;
-       int fail_nth;
+       unsigned int                    fail_nth;
 #endif
        /*
         * When (nr_dirtied >= nr_dirtied_pause), it's time to call
 #endif
        /*
         * When (nr_dirtied >= nr_dirtied_pause), it's time to call