From: "Richard W.M. Jones" <rjones@redhat.com>
To: armbru@redhat.com
Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org, agraf@suse.de
Subject: [Qemu-devel] [PATCH v3 1/2] Add a simple mechanism to protect against error message floods.
Date: Wed, 8 Jul 2015 13:50:42 +0100 [thread overview]
Message-ID: <1436359843-15612-2-git-send-email-rjones@redhat.com> (raw)
In-Reply-To: <1436359843-15612-1-git-send-email-rjones@redhat.com>
You can now write code like this:
FLOOD_COUNTER(errcount, 100);
...
NO_FLOOD(errcount,
error_report("oops, something bad happened"),
error_report("further errors suppressed"));
which would print the "oops, ..." error message up to 100 times,
followed by the "further errors suppressed" message once, and then
nothing else.
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
include/qemu/no-flood.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 include/qemu/no-flood.h
diff --git a/include/qemu/no-flood.h b/include/qemu/no-flood.h
new file mode 100644
index 0000000..90a24da
--- /dev/null
+++ b/include/qemu/no-flood.h
@@ -0,0 +1,34 @@
+/*
+ * Suppress error floods.
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * Author: Richard W.M. Jones <rjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef __QEMU_NO_FLOOD_H
+#define __QEMU_NO_FLOOD_H 1
+
+#include "qemu/atomic.h"
+
+/* Suggested initial value is 100 */
+#define FLOOD_COUNTER(counter_name, initial) \
+ static int counter_name = (initial)
+
+#define NO_FLOOD(counter_name, code, suppress_message) \
+ do { \
+ int t_##counter_name = atomic_fetch_add(&counter_name, 0); \
+ if (t_##counter_name > 0) { \
+ code; \
+ if (t_##counter_name == 1) { \
+ suppress_message; \
+ } \
+ atomic_dec(&counter_name); \
+ } \
+} while (0)
+
+#endif
--
2.3.1
next prev parent reply other threads:[~2015-07-08 12:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-08 12:50 [Qemu-devel] [PATCH v3 0/2] block/curl: Don't lose original error when a connection fails Richard W.M. Jones
2015-07-08 12:50 ` Richard W.M. Jones [this message]
2015-07-08 13:26 ` [Qemu-devel] [PATCH v3 1/2] Add a simple mechanism to protect against error message floods Kevin Wolf
2015-07-08 13:38 ` Paolo Bonzini
2015-07-08 12:50 ` [Qemu-devel] [PATCH v3 2/2] block/curl: Don't lose original error when a connection fails Richard W.M. Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436359843-15612-2-git-send-email-rjones@redhat.com \
--to=rjones@redhat.com \
--cc=agraf@suse.de \
--cc=armbru@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).