ratelimit: add ratelimit_state_init()
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Mon, 24 May 2010 21:33:11 +0000 (14:33 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 25 May 2010 15:07:03 +0000 (08:07 -0700)
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>
include/linux/ratelimit.h

index 668cf1b..8f69d09 100644 (file)
@@ -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
@@ -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__)