[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once
From: |
Peter Xu |
Subject: |
Re: [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once |
Date: |
Wed, 16 May 2018 11:07:50 +0800 |
User-agent: |
Mutt/1.9.3 (2018-01-21) |
On Tue, May 15, 2018 at 10:29:39AM -0500, Eric Blake wrote:
> On 05/15/2018 04:13 AM, 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() really quite often
> > when there can be any DDOS attack. To avoid that, we can introduce a
> > print-once function for it.
> >
> > CC: Markus Armbruster <address@hidden>
> > Signed-off-by: Peter Xu <address@hidden>
> > ---
> > We can for sure introduce similar functions for the rest of the
> > error_*() functions, it's just an idea to see whether we'd like it
> > in general.
> > ---
> > include/qemu/error-report.h | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> > diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
> > index e1c8ae1a52..efebb80e2c 100644
> > --- a/include/qemu/error-report.h
> > +++ b/include/qemu/error-report.h
> > @@ -44,6 +44,18 @@ 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);
> > +#define error_report_once(fmt, ...) \
> > + ({ \
> > + static bool __print_once; \
>
> Double-underscore names are reserved for the compiler's use, not ours.
> Better would be naming this:
>
> static bool print_once_;
>
> with a trailing underscore, or at most a single leading underscore.
>
> > + bool __ret_print_once = !__print_once; \
>
> Same comment for this variable.
Sure!
(I am wondering why Linux is always using that way to name lots of
variables, and I'm surprised that I got 385350 after I run this under
the Linux repo: 'git grep "__[a-z][a-z]" | wc -l', even considering
some false positives)
Thanks,
--
Peter Xu
Re: [Qemu-devel] [PATCH RFC] qemu-error: introduce error_report_once, Stefan Hajnoczi, 2018/05/31