From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935392AbdDFO4v (ORCPT ); Thu, 6 Apr 2017 10:56:51 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33063 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935429AbdDFO41 (ORCPT ); Thu, 6 Apr 2017 10:56:27 -0400 From: Akinobu Mita To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Cc: Akinobu Mita , Dmitry Vyukov Subject: [PATCH -mm 3/5] fault-inject: make fail-nth read/write interface symmetric Date: Thu, 6 Apr 2017 23:55:59 +0900 Message-Id: <1491490561-10485-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491490561-10485-1-git-send-email-akinobu.mita@gmail.com> References: <1491490561-10485-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: Dmitry Vyukov Signed-off-by: Akinobu Mita --- Documentation/fault-injection/fault-injection.txt | 13 +++++++------ fs/proc/base.c | 14 ++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Documentation/fault-injection/fault-injection.txt b/Documentation/fault-injection/fault-injection.txt index a321905..370ddcb 100644 --- a/Documentation/fault-injection/fault-injection.txt +++ b/Documentation/fault-injection/fault-injection.txt @@ -139,9 +139,9 @@ o proc entries - /proc/self/task//fail-nth: 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. + Read from this file returns a integer value. A value of '0' indicates + that the fault setup with a previous write to this file was 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). This setting takes precedence over all other generic debugfs settings like probability, interval, times, etc. But per-capability settings @@ -325,13 +325,14 @@ int main() write(fail_nth, buf, strlen(buf)); res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds); err = errno; - read(fail_nth, buf, 1); + pread(fail_nth, buf, sizeof(buf), 0); if (res == 0) { close(fds[0]); close(fds[1]); } - printf("%d-th fault %c: res=%d/%d\n", i, buf[0], res, err); - if (buf[0] != 'Y') + printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y', + res, err); + if (atoi(buf)) break; } return 0; diff --git a/fs/proc/base.c b/fs/proc/base.c index 42c52e2..9d14215 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1383,7 +1383,8 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct task_struct *task; - int err; + char numbuf[PROC_NUMBUF]; + ssize_t len; task = get_proc_task(file_inode(file)); if (!task) @@ -1391,13 +1392,10 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf, put_task_struct(task); if (task != current) return -EPERM; - if (count < 1) - return -EINVAL; - err = put_user((char)(current->fail_nth ? 'N' : 'Y'), buf); - if (err) - return err; - current->fail_nth = 0; - return 1; + len = snprintf(numbuf, sizeof(numbuf), "%u\n", task->fail_nth); + len = simple_read_from_buffer(buf, count, ppos, numbuf, len); + + return len; } static const struct file_operations proc_fail_nth_operations = { -- 2.7.4