Skip to content

Commit f40c396

Browse files
OGAWAHirofumitorvalds
authored andcommitted
ratelimit: add ratelimit_state_init()
For now, all users of ratelimit_state allocates it statically, so DEFINE_RATELIMIT_STATE() is enough. But, I want to use ratelimit_state for fs, i.e. per super_block to suppress too many error reports. So, this adds ratelimit_state_init() to initialize ratelimite_state which is dynamically allocated, instead of opencoding. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d8521fc commit f40c396

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎include/linux/ratelimit.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _LINUX_RATELIMIT_H
33

44
#include <linux/param.h>
5-
#include <linux/spinlock_types.h>
5+
#include <linux/spinlock.h>
66

77
#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
88
#define DEFAULT_RATELIMIT_BURST 10
@@ -25,6 +25,17 @@ struct ratelimit_state {
2525
.burst = burst_init, \
2626
}
2727

28+
static inline void ratelimit_state_init(struct ratelimit_state *rs,
29+
int interval, int burst)
30+
{
31+
spin_lock_init(&rs->lock);
32+
rs->interval = interval;
33+
rs->burst = burst;
34+
rs->printed = 0;
35+
rs->missed = 0;
36+
rs->begin = 0;
37+
}
38+
2839
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
2940
#define __ratelimit(state) ___ratelimit(state, __func__)
3041

0 commit comments

Comments
 (0)