diff --git a/scst/include/backport.h b/scst/include/backport.h index 9fae2e744..d12657087 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -365,6 +365,28 @@ static inline __attribute__ ((format (printf, 1, 2))) int no_printk(const char *s, ...) { return 0; } #endif +/* */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) +/* See also commit 717115e1a585 */ + +#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) +#define DEFAULT_RATELIMIT_BURST 10 + +struct ratelimit_state { + int interval; + int burst; +}; + +#define DEFINE_RATELIMIT_STATE(name, interval, burst) \ + struct ratelimit_state name = {interval, burst,} + +static inline int __ratelimit(struct ratelimit_state *rs) +{ + return 1; +} +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) && !defined(kfree_rcu) diff --git a/scst/include/scst_debug.h b/scst/include/scst_debug.h index 18a052c98..00ea2c559 100644 --- a/scst/include/scst_debug.h +++ b/scst/include/scst_debug.h @@ -31,6 +31,10 @@ #include /* for WARN_ON_ONCE */ #endif +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27) +#include +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) /* * See also the following commits: @@ -284,6 +288,16 @@ do { \ #endif /* CONFIG_SCST_DEBUG || CONFIG_SCST_TRACING */ +#define PRINT_ERROR_RATELIMITED(format, args...) \ + do { \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (__ratelimit(&_rs)) \ + PRINT_ERROR(format, ##args); \ + } while (0) + #ifdef CONFIG_SCST_DEBUG #define TRACE_DBG_FLAG(trace, format, args...) \ diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 4b9295d26..80aad71aa 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -6486,7 +6486,8 @@ static void blockio_endio(struct bio *bio) if (unlikely(error != 0)) { unsigned long flags; - PRINT_ERROR("BLOCKIO for cmd %p finished with error %d", + PRINT_ERROR_RATELIMITED( + "BLOCKIO for cmd %p finished with error %d", blockio_work->cmd, error); /*