Skip to content

Commit

Permalink
ratelimit: add ratelimit_state_init()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
OGAWAHirofumi authored and torvalds committed May 25, 2010
1 parent d8521fc commit f40c396
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/linux/ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _LINUX_RATELIMIT_H

#include <linux/param.h>
#include <linux/spinlock_types.h>
#include <linux/spinlock.h>

#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
#define DEFAULT_RATELIMIT_BURST 10
Expand All @@ -25,6 +25,17 @@ struct ratelimit_state {
.burst = burst_init, \
}

static inline void ratelimit_state_init(struct ratelimit_state *rs,
int interval, int burst)
{
spin_lock_init(&rs->lock);
rs->interval = interval;
rs->burst = burst;
rs->printed = 0;
rs->missed = 0;
rs->begin = 0;
}

extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
#define __ratelimit(state) ___ratelimit(state, __func__)

Expand Down

0 comments on commit f40c396

Please sign in to comment.