All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <mita@miraclelinux.com>
To: linux-kernel@vger.kernel.org
Cc: ak@suse.de, akpm@osdl.org, okuji@enbug.org
Subject: [patch 6/6] process filtering for fault-injection capabilities
Date: Thu, 31 Aug 2006 19:08:02 +0900	[thread overview]
Message-ID: <20060831100821.807784048@localhost.localdomain> (raw)
In-Reply-To: 20060831100756.866727476@localhost.localdomain

[-- Attachment #1: process-filter.patch --]
[-- Type: text/plain, Size: 7012 bytes --]

This patch provides process filtering feature.

Example:

# modprobe should_fail_knobs
# echo 1 > /debug/failslab/process-filter
# echo 30 > /debug/failslab/probability
# find /lib/modules/`uname -r` -name '*.ko' -exec basename {} .ko \; > list
# for i in `cat list`;do failmodprobe $i;done

failmodprobe:
-------------
#!/bin/bash
echo 1 > /proc/self/make-it-fail
exec modprobe $*

Signed-off-by: Akinobu Mita <mita@miraclelinux.com>

 fs/proc/base.c              |   77 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sched.h       |    3 +
 include/linux/should_fail.h |    3 +
 lib/should_fail.c           |   11 ++++--
 lib/should_fail_knobs.c     |   10 +++++
 5 files changed, 101 insertions(+), 3 deletions(-)

Index: work-shouldfail/fs/proc/base.c
===================================================================
--- work-shouldfail.orig/fs/proc/base.c
+++ work-shouldfail/fs/proc/base.c
@@ -138,6 +138,9 @@ enum pid_directory_inos {
 #endif
 	PROC_TGID_OOM_SCORE,
 	PROC_TGID_OOM_ADJUST,
+#ifdef CONFIG_SHOULD_FAIL
+	PROC_TGID_SHOULD_FAIL,
+#endif
 	PROC_TID_INO,
 	PROC_TID_STATUS,
 	PROC_TID_MEM,
@@ -181,6 +184,9 @@ enum pid_directory_inos {
 #endif
 	PROC_TID_OOM_SCORE,
 	PROC_TID_OOM_ADJUST,
+#ifdef CONFIG_SHOULD_FAIL
+	PROC_TID_SHOULD_FAIL,
+#endif
 
 	/* Add new entries before this */
 	PROC_TID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
@@ -240,6 +246,9 @@ static struct pid_entry tgid_base_stuff[
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+#ifdef CONFIG_SHOULD_FAIL
+	E(PROC_TGID_SHOULD_FAIL, "make-it-fail", S_IFREG|S_IWUSR|S_IRUGO),
+#endif
 	{0,0,NULL,0}
 };
 static struct pid_entry tid_base_stuff[] = {
@@ -282,6 +291,9 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+#ifdef CONFIG_SHOULD_FAIL
+	E(PROC_TID_SHOULD_FAIL, "make-it-fail", S_IFREG|S_IWUSR|S_IRUGO),
+#endif
 	{0,0,NULL,0}
 };
 
@@ -992,6 +1004,65 @@ static struct file_operations proc_login
 };
 #endif
 
+#ifdef CONFIG_SHOULD_FAIL
+static ssize_t proc_should_fail_read(struct file * file, char __user * buf,
+				     size_t count, loff_t *ppos)
+{
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	char buffer[PROC_NUMBUF];
+	size_t len;
+	int make_it_fail;
+	loff_t __ppos = *ppos;
+
+	if (!task)
+		return -ESRCH;
+	make_it_fail = task->make_it_fail;
+	put_task_struct(task);
+
+	len = snprintf(buffer, sizeof(buffer), "%i\n", make_it_fail);
+	if (__ppos >= len)
+		return 0;
+	if (count > len-__ppos)
+		count = len-__ppos;
+	if (copy_to_user(buf, buffer + __ppos, count))
+		return -EFAULT;
+	*ppos = __ppos + count;
+	return count;
+}
+
+static ssize_t proc_should_fail_write(struct file * file,
+			const char __user * buf, size_t count, loff_t *ppos)
+{
+	struct task_struct *task;
+	char buffer[PROC_NUMBUF], *end;
+	int make_it_fail;
+
+	if (!capable(CAP_SYS_RESOURCE))
+		return -EPERM;
+	memset(buffer, 0, sizeof(buffer));
+	if (count > sizeof(buffer) - 1)
+		count = sizeof(buffer) - 1;
+	if (copy_from_user(buffer, buf, count))
+		return -EFAULT;
+	make_it_fail = simple_strtol(buffer, &end, 0);
+	if (*end == '\n')
+		end++;
+	task = get_proc_task(file->f_dentry->d_inode);
+	if (!task)
+		return -ESRCH;
+	task->make_it_fail = make_it_fail;
+	put_task_struct(task);
+	if (end - buffer == 0)
+		return -EIO;
+	return end - buffer;
+}
+
+static struct file_operations proc_should_fail_operations = {
+	.read		= proc_should_fail_read,
+	.write		= proc_should_fail_write,
+};
+#endif
+
 #ifdef CONFIG_SECCOMP
 static ssize_t seccomp_read(struct file *file, char __user *buf,
 			    size_t count, loff_t *ppos)
@@ -1834,6 +1905,12 @@ static struct dentry *proc_pident_lookup
 			inode->i_fop = &proc_loginuid_operations;
 			break;
 #endif
+#ifdef CONFIG_SHOULD_FAIL
+		case PROC_TID_SHOULD_FAIL:
+		case PROC_TGID_SHOULD_FAIL:
+			inode->i_fop = &proc_should_fail_operations;
+			break;
+#endif
 		default:
 			printk("procfs: impossible type (%d)",p->type);
 			iput(inode);
Index: work-shouldfail/include/linux/sched.h
===================================================================
--- work-shouldfail.orig/include/linux/sched.h
+++ work-shouldfail/include/linux/sched.h
@@ -997,6 +997,9 @@ struct task_struct {
 	spinlock_t delays_lock;
 	struct task_delay_info *delays;
 #endif
+#ifdef CONFIG_SHOULD_FAIL
+	int make_it_fail;
+#endif
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
Index: work-shouldfail/include/linux/should_fail.h
===================================================================
--- work-shouldfail.orig/include/linux/should_fail.h
+++ work-shouldfail/include/linux/should_fail.h
@@ -27,6 +27,9 @@ struct should_fail_data {
 	atomic_t space;
 
 	unsigned long count;
+
+	/* process filter */
+	unsigned long process_filter;
 };
 
 #define DEFINE_SHOULD_FAIL(name) \
Index: work-shouldfail/lib/should_fail.c
===================================================================
--- work-shouldfail.orig/lib/should_fail.c
+++ work-shouldfail/lib/should_fail.c
@@ -13,16 +13,18 @@ int setup_should_fail(struct should_fail
 	unsigned long interval;
 	int times;
 	int space;
+	unsigned long filter;
 
-	/* "<probability>,<interval>,<times>,<space>" */
-	if (sscanf(str, "%lu,%lu,%d,%d", &probability, &interval, &times,
-		   &space) < 4)
+	/* "<probability>,<interval>,<times>,<space>,<process-filter>" */
+	if (sscanf(str, "%lu,%lu,%d,%d,%d", &probability, &interval, &times,
+		   &space, &filter) < 5)
 		return 0;
 
 	data->probability = probability;
 	data->interval = interval;
 	atomic_set(&data->times, times);
 	atomic_set(&data->space, space);
+	data->process_filter = filter;
 
 	return 1;
 }
@@ -54,6 +56,9 @@ void should_fail_srandom(unsigned long e
 
 int should_fail(struct should_fail_data *data, ssize_t size)
 {
+	if (data->process_filter && !current->make_it_fail)
+		return 0;
+
 	if (atomic_read(&max_failures(data)) == 0)
 		return 0;
 
Index: work-shouldfail/lib/should_fail_knobs.c
===================================================================
--- work-shouldfail.orig/lib/should_fail_knobs.c
+++ work-shouldfail/lib/should_fail_knobs.c
@@ -8,6 +8,7 @@ struct should_fail_knobs {
 	struct dentry *interval_file;
 	struct dentry *times_file;
 	struct dentry *space_file;
+	struct dentry *filter_file;
 };
 
 static void debugfs_ul_set(void *data, u64 val)
@@ -66,6 +67,10 @@ static void cleanup_should_fail_knobs(st
 			debugfs_remove(knobs->space_file);
 			knobs->space_file = NULL;
 		}
+		if (knobs->filter_file) {
+			debugfs_remove(knobs->filter_file);
+			knobs->filter_file = NULL;
+		}
 		debugfs_remove(knobs->dir);
 		knobs->dir = NULL;
 	}
@@ -105,6 +110,11 @@ static int init_should_fail_knobs(struct
 		goto fail;
 	knobs->space_file = file;
 
+	file = debugfs_create_ul("process-filter", mode, dir, &data->process_filter);
+	if (!file)
+		goto fail;
+	knobs->filter_file = file;
+
 	return 0;
 fail:
 	cleanup_should_fail_knobs(knobs);

--

  parent reply	other threads:[~2006-08-31 10:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-31 10:07 [patch 0/6] RFC: fault-injection capabilities (v2) Akinobu Mita
2006-08-31 10:07 ` [patch 1/6] fault-injection capabilities infrastructure Akinobu Mita
2006-08-31 10:22   ` Andi Kleen
2006-08-31 10:07 ` [patch 2/6] fault-injection capability for kmalloc Akinobu Mita
2006-08-31 10:07 ` [patch 3/6] fault-injection capability for alloc_pages() Akinobu Mita
2006-08-31 10:25   ` Andi Kleen
2006-08-31 10:35     ` Akinobu Mita
2006-08-31 10:45       ` Andi Kleen
2006-08-31 10:08 ` [patch 4/6] fault-injection capability for disk IO Akinobu Mita
2006-08-31 10:08 ` [patch 5/6] debugfs entries for configuration Akinobu Mita
2006-08-31 10:08 ` Akinobu Mita [this message]
2006-08-31 17:29 ` [patch 0/6] RFC: fault-injection capabilities (v2) Josh Triplett
2006-08-31 18:31   ` Kyle Moffett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060831100821.807784048@localhost.localdomain \
    --to=mita@miraclelinux.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=okuji@enbug.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.