Skip to content

Commit 6adc4a2

Browse files
Dmitry Monakhovtorvalds
Dmitry Monakhov
authored andcommittedDec 13, 2014
fault-inject: add ratelimit option
Current debug levels are not optimal. Especially if one want to provoke big numbers of faults(broken device simulator) then any verbose level will produce giant numbers of identical logging messages. Let's add ratelimit parameter for that purpose. Signed-off-by: Dmitry Monakhov <[email protected]> Acked-by: Akinobu Mita <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 89e3f90 commit 6adc4a2

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed
 

‎include/linux/fault-inject.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/types.h>
77
#include <linux/debugfs.h>
8+
#include <linux/ratelimit.h>
89
#include <linux/atomic.h>
910

1011
/*
@@ -25,14 +26,18 @@ struct fault_attr {
2526
unsigned long reject_end;
2627

2728
unsigned long count;
29+
struct ratelimit_state ratelimit_state;
30+
struct dentry *dname;
2831
};
2932

30-
#define FAULT_ATTR_INITIALIZER { \
31-
.interval = 1, \
32-
.times = ATOMIC_INIT(1), \
33-
.require_end = ULONG_MAX, \
34-
.stacktrace_depth = 32, \
35-
.verbose = 2, \
33+
#define FAULT_ATTR_INITIALIZER { \
34+
.interval = 1, \
35+
.times = ATOMIC_INIT(1), \
36+
.require_end = ULONG_MAX, \
37+
.stacktrace_depth = 32, \
38+
.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
39+
.verbose = 2, \
40+
.dname = NULL, \
3641
}
3742

3843
#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER

‎lib/fault-inject.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ EXPORT_SYMBOL_GPL(setup_fault_attr);
4040

4141
static void fail_dump(struct fault_attr *attr)
4242
{
43-
if (attr->verbose > 0)
44-
printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
45-
if (attr->verbose > 1)
46-
dump_stack();
43+
if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
44+
printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
45+
"name %pd, interval %lu, probability %lu, "
46+
"space %d, times %d\n", attr->dname,
47+
attr->probability, attr->interval,
48+
atomic_read(&attr->space),
49+
atomic_read(&attr->times));
50+
if (attr->verbose > 1)
51+
dump_stack();
52+
}
4753
}
4854

4955
#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
@@ -202,6 +208,12 @@ struct dentry *fault_create_debugfs_attr(const char *name,
202208
goto fail;
203209
if (!debugfs_create_ul("verbose", mode, dir, &attr->verbose))
204210
goto fail;
211+
if (!debugfs_create_u32("verbose_ratelimit_interval_ms", mode, dir,
212+
&attr->ratelimit_state.interval))
213+
goto fail;
214+
if (!debugfs_create_u32("verbose_ratelimit_burst", mode, dir,
215+
&attr->ratelimit_state.burst))
216+
goto fail;
205217
if (!debugfs_create_bool("task-filter", mode, dir, &attr->task_filter))
206218
goto fail;
207219

@@ -222,6 +234,7 @@ struct dentry *fault_create_debugfs_attr(const char *name,
222234

223235
#endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
224236

237+
attr->dname = dget(dir);
225238
return dir;
226239
fail:
227240
debugfs_remove_recursive(dir);

0 commit comments

Comments
 (0)