fault-inject: make fail-nth read/write interface symmetric
The read interface for fail-nth looks a bit odd. Read from this file returns "NYYYY..." or "YYYYY..." (this makes me surprise when cat this file). Because there is no EOF condition. The first character indicates current->fail_nth is zero or not, and then current->fail_nth is reset to zero. Just returning task->fail_nth value is more natural to understand. Link: http://lkml.kernel.org/r/1491490561-10485-4-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>zero-colors
parent
9049f2f6e7
commit
bfc740938d
|
@ -139,9 +139,9 @@ 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 task fail.
|
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'
|
Read from this file returns a integer value. A value of '0' indicates
|
||||||
that says if the fault setup with a previous write to this file was
|
that the fault setup with a previous write to this file was injected.
|
||||||
injected or not, and disables the fault if it wasn't yet injected.
|
A positive integer N indicates that the fault wasn't yet injected.
|
||||||
Note that this file enables all types of faults (slab, futex, etc).
|
Note that this file enables all types of faults (slab, futex, etc).
|
||||||
This setting takes precedence over all other generic debugfs settings
|
This setting takes precedence over all other generic debugfs settings
|
||||||
like probability, interval, times, etc. But per-capability settings
|
like probability, interval, times, etc. But per-capability settings
|
||||||
|
@ -325,13 +325,14 @@ int main()
|
||||||
write(fail_nth, buf, strlen(buf));
|
write(fail_nth, buf, strlen(buf));
|
||||||
res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
|
res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
|
||||||
err = errno;
|
err = errno;
|
||||||
read(fail_nth, buf, 1);
|
pread(fail_nth, buf, sizeof(buf), 0);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
}
|
}
|
||||||
printf("%d-th fault %c: res=%d/%d\n", i, buf[0], res, err);
|
printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y',
|
||||||
if (buf[0] != 'Y')
|
res, err);
|
||||||
|
if (atoi(buf))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1380,7 +1380,8 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf,
|
||||||
size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
int err;
|
char numbuf[PROC_NUMBUF];
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
task = get_proc_task(file_inode(file));
|
task = get_proc_task(file_inode(file));
|
||||||
if (!task)
|
if (!task)
|
||||||
|
@ -1388,13 +1389,10 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf,
|
||||||
put_task_struct(task);
|
put_task_struct(task);
|
||||||
if (task != current)
|
if (task != current)
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (count < 1)
|
len = snprintf(numbuf, sizeof(numbuf), "%u\n", task->fail_nth);
|
||||||
return -EINVAL;
|
len = simple_read_from_buffer(buf, count, ppos, numbuf, len);
|
||||||
err = put_user((char)(current->fail_nth ? 'N' : 'Y'), buf);
|
|
||||||
if (err)
|
return len;
|
||||||
return err;
|
|
||||||
current->fail_nth = 0;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations proc_fail_nth_operations = {
|
static const struct file_operations proc_fail_nth_operations = {
|
||||||
|
|
Loading…
Reference in New Issue