qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 1/2] qemu-error: introduce {error|warn}_repor


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v3 1/2] qemu-error: introduce {error|warn}_report_once
Date: Wed, 23 May 2018 13:04:46 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 05/22/2018 10:18 PM, Peter Xu wrote:
I stole the printk_once() macro.

I always wanted to be able to print some error directly if there is a
buffer to dump, however we can't use error_report() where the code path
can be triggered by DDOS attack.  To avoid that, we can introduce a
print-once-like function for it.  Meanwhile, we also introduce the
corresponding helper for warn_report().

CC: Markus Armbruster <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
---
  include/qemu/error-report.h | 26 ++++++++++++++++++++++++++
  1 file changed, 26 insertions(+)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index e1c8ae1a52..3e6e84801f 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -44,6 +44,32 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
  void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
  void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+/* Similar to error_report(), but it only prints the message once. */
+#define error_report_once(fmt, ...)             \
+    ({                                          \
+        static bool __print_once;               \
+        bool __ret_print_once = !__print_once;  \

In v1 you were asked to avoid leading double underscore (https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg03442.html; use things like 'print_once_' instead) and to document the return value of these macros (https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg03503.html; having the return value makes it possible to write conditional code that caches further information about a first, but not repeat, failures). Why hasn't that happened?

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]