From: Eric Blake <eblake@redhat.com>
To: Peter Xu <peterx@redhat.com>, qemu-devel@nongnu.org
Cc: "Jason Wang" <jasowang@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/2] qemu-error: introduce {error|warn}_report_once
Date: Wed, 23 May 2018 13:04:46 -0500 [thread overview]
Message-ID: <32769328-e52a-db6b-d963-973f174f4462@redhat.com> (raw)
In-Reply-To: <20180523031805.27101-2-peterx@redhat.com>
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 <armbru@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> 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
next prev parent reply other threads:[~2018-05-23 18:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 3:18 [Qemu-devel] [PATCH v3 0/2] error-report: introduce {error|warn}_report_once Peter Xu
2018-05-23 3:18 ` [Qemu-devel] [PATCH v3 1/2] qemu-error: " Peter Xu
2018-05-23 18:04 ` Eric Blake [this message]
2018-05-23 3:18 ` [Qemu-devel] [PATCH v3 2/2] intel-iommu: start to use error_report_once Peter Xu
2018-05-23 15:09 ` Philippe Mathieu-Daudé
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=32769328-e52a-db6b-d963-973f174f4462@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=f4bug@amsat.org \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--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).