infra: add flood protected syslogging

This commit is contained in:
Thomas Schoebel-Theuer 2014-01-28 10:51:17 +01:00
parent a654d9d84b
commit d4b31d8bf9
3 changed files with 33 additions and 0 deletions

View File

@ -58,6 +58,12 @@ int brick_say_syslog_min = 1;
EXPORT_SYMBOL_GPL(brick_say_syslog_min);
int brick_say_syslog_max = -1;
EXPORT_SYMBOL_GPL(brick_say_syslog_max);
int brick_say_syslog_flood_class = 3;
EXPORT_SYMBOL_GPL(brick_say_syslog_flood_class);
int brick_say_syslog_flood_limit = 20;
EXPORT_SYMBOL_GPL(brick_say_syslog_flood_limit);
int brick_say_syslog_flood_recovery = 300;
EXPORT_SYMBOL_GPL(brick_say_syslog_flood_recovery);
int delay_say_on_overflow =
#ifdef CONFIG_MARS_DEBUG
1;
@ -70,6 +76,9 @@ static atomic_t say_alloc_channels = ATOMIC_INIT(0);
static atomic_t say_alloc_names = ATOMIC_INIT(0);
static atomic_t say_alloc_pages = ATOMIC_INIT(0);
static unsigned long flood_start_jiffies = 0;
static int flood_count = 0;
struct say_channel {
char *ch_name;
struct say_channel *ch_next;
@ -611,11 +620,29 @@ void out_to_file(struct file *file, char *buf, int len)
}
}
static inline
void reset_flood(void)
{
if (flood_start_jiffies &&
(long)jiffies >= (long)(flood_start_jiffies + brick_say_syslog_flood_recovery * HZ)) {
flood_start_jiffies = 0;
flood_count = 0;
}
}
static
void out_to_syslog(int class, char *buf, int len)
{
reset_flood();
if (class >= brick_say_syslog_min && class <= brick_say_syslog_max) {
buf[len] = '\0';
printk("%s", buf);
} else if (class >= brick_say_syslog_flood_class && brick_say_syslog_flood_class >= 0 && class != SAY_TOTAL) {
flood_start_jiffies = jiffies;
if (++flood_count <= brick_say_syslog_flood_limit) {
buf[len] = '\0';
printk("%s", buf);
}
}
}

View File

@ -13,6 +13,9 @@ extern int brick_say_logging;
extern int brick_say_debug;
extern int brick_say_syslog_min;
extern int brick_say_syslog_max;
extern int brick_say_syslog_flood_class;
extern int brick_say_syslog_flood_limit;
extern int brick_say_syslog_flood_recovery;
extern int delay_say_on_overflow;
// printk() replacements

View File

@ -270,6 +270,9 @@ ctl_table mars_table[] = {
INT_ENTRY("logger_do_crc", trans_logger_do_crc, 0600),
INT_ENTRY("syslog_min_class", brick_say_syslog_min, 0600),
INT_ENTRY("syslog_max_class", brick_say_syslog_max, 0600),
INT_ENTRY("syslog_flood_class", brick_say_syslog_flood_class, 0600),
INT_ENTRY("syslog_flood_limit", brick_say_syslog_flood_limit, 0600),
INT_ENTRY("syslog_flood_recovery_s", brick_say_syslog_flood_recovery, 0600),
INT_ENTRY("delay_say_on_overflow",delay_say_on_overflow, 0600),
INT_ENTRY("mapfree_period_sec", mapfree_period_sec, 0600),
INT_ENTRY("mapfree_grace_keep_mb", mapfree_grace_keep_mb, 0600),