From: "Cédric Le Goater" <clg@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v2 1/9] util/error: Introduce warn_report_once_err()
Date: Thu, 30 Jan 2025 22:26:42 +0100 [thread overview]
Message-ID: <06a2532d-bbfa-4a7d-aade-7813173d8ca2@redhat.com> (raw)
In-Reply-To: <20250130105529.205cbdb2.alex.williamson@redhat.com>
On 1/30/25 18:55, Alex Williamson wrote:
> On Thu, 30 Jan 2025 14:43:38 +0100
> Cédric Le Goater <clg@redhat.com> wrote:
>
>> Depending on the configuration, a passthrough device may produce
>> recurring DMA mapping errors at runtime and produce a lot of
>> output. It is useful to report only once.
>>
>> Cc: Markus Armbruster <armbru@redhat.com>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>> include/qapi/error.h | 5 +++++
>> util/error.c | 9 +++++++++
>> 2 files changed, 14 insertions(+)
>>
>> diff --git a/include/qapi/error.h b/include/qapi/error.h
>> index 71f8fb2c50eee9a544992d0c05263c9793956fe1..b6ea274882b9788b64d4bb213c3458d7c674a881 100644
>> --- a/include/qapi/error.h
>> +++ b/include/qapi/error.h
>> @@ -448,6 +448,11 @@ void error_free_or_abort(Error **errp);
>> */
>> void warn_report_err(Error *err);
>>
>> +/*
>> + * Convenience function to call warn_report_err() once.
>> + */
>> +void warn_report_once_err(Error *err);
>> +
>
> Turning it into a macro would do what you want:
>
> #define warn_report_once_err(err) ({ \
> static bool print_once_; \
> if (!print_once_) { \
> warn_report_err(err); \
> print_once_ = true; \
> } \
> })
>
> So long as we only want once per call site and not once per object,
> which would pull in something like warn_report_once_cond(). Thanks,
yeah. I came up with this :
/*
* TODO: move to util/
*/
static bool warn_report_once_err_cond(bool *printed, Error *err)
{
if (*printed) {
error_free(err);
return false;
}
*printed = true;
warn_report_err(err);
return true;
}
#define warn_report_once_err(err) \
({ \
static bool print_once_; \
warn_report_once_err_cond(&print_once_, err); \
})
I don't know where to put it though. It sits in between qapi/error.h
and qemu/error-report.h.
Thanks,
C.
> Alex
>
>> /*
>> * Convenience function to error_report() and free @err.
>> * The report includes hints added with error_append_hint().
>> diff --git a/util/error.c b/util/error.c
>> index e5e247209a9e0796074a9794f5598325f22f8d35..b8a211cccaa609a93091b86316144a0ad0a02662 100644
>> --- a/util/error.c
>> +++ b/util/error.c
>> @@ -247,6 +247,15 @@ void warn_report_err(Error *err)
>> error_free(err);
>> }
>>
>> +void warn_report_once_err(Error *err)
>> +{
>> + static bool print_once_;
>> + if (!print_once_) {
>> + warn_report_err(err);
>> + print_once_ = true;
>> + }
>> +}
>> +
>> void error_reportf_err(Error *err, const char *fmt, ...)
>> {
>> va_list ap;
>
next prev parent reply other threads:[~2025-01-30 21:27 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 13:43 [PATCH v2 0/9]vfio: Improve error reporting when MMIO region mapping fails Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 1/9] util/error: Introduce warn_report_once_err() Cédric Le Goater
2025-01-30 14:25 ` Markus Armbruster
2025-01-30 16:03 ` Cédric Le Goater
2025-01-30 16:28 ` Cédric Le Goater
2025-01-30 17:55 ` Alex Williamson
2025-01-30 21:26 ` Cédric Le Goater [this message]
2025-01-31 8:30 ` Markus Armbruster
2025-01-30 13:43 ` [PATCH v2 2/9] vfio/pci: Replace "iommu_device" by "vIOMMU" Cédric Le Goater
2025-02-10 14:28 ` Philippe Mathieu-Daudé
2025-01-30 13:43 ` [PATCH v2 3/9] vfio: Rephrase comment in vfio_listener_region_add() error path Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 4/9] vfio: Introduce vfio_get_vfio_device() Cédric Le Goater
2025-02-10 14:32 ` Philippe Mathieu-Daudé
2025-02-10 16:19 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 5/9] vfio: Improve error reporting when MMIO region mapping fails Cédric Le Goater
2025-02-10 14:36 ` Philippe Mathieu-Daudé
2025-02-10 16:17 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 6/9] vfio: Remove reports of DMA mapping errors in backends Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 7/9] cpu: Introduce cpu_get_phys_bits() Cédric Le Goater
2025-02-10 14:40 ` Philippe Mathieu-Daudé
2025-03-06 10:37 ` Philippe Mathieu-Daudé
2025-03-06 14:41 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 8/9] vfio: Check compatibility of CPU and IOMMU address space width Cédric Le Goater
2025-01-30 18:58 ` Alex Williamson
2025-01-31 12:42 ` Cédric Le Goater
2025-01-31 13:23 ` Gerd Hoffmann
2025-01-31 17:03 ` Cédric Le Goater
2025-02-06 7:54 ` Gerd Hoffmann
2025-02-06 17:05 ` Cédric Le Goater
2025-01-31 22:18 ` Alex Williamson
2025-02-06 8:22 ` Gerd Hoffmann
2025-03-06 10:33 ` Philippe Mathieu-Daudé
2025-09-05 13:04 ` Daniel Kral
2025-09-08 8:35 ` Cédric Le Goater
2025-01-30 13:43 ` [PATCH v2 9/9] vfio: Remove superfluous error report in vfio_listener_region_add() Cédric Le Goater
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=06a2532d-bbfa-4a7d-aade-7813173d8ca2@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=armbru@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).