[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/9] util/error: Introduce warn_report_once_err()
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v2 1/9] util/error: Introduce warn_report_once_err() |
Date: |
Fri, 31 Jan 2025 09:30:05 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Cédric Le Goater <clg@redhat.com> writes:
> 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.
Stuff involving the Error type should not go into qemu/error-report.h.
Precedence: warn_report_err() & friends are in qapi/error.h even though
they're straightforward wrappers around warn_report() & friends for easy
use with Error.
[PATCH v2 2/9] vfio/pci: Replace "iommu_device" by "vIOMMU", Cédric Le Goater, 2025/01/30
[PATCH v2 3/9] vfio: Rephrase comment in vfio_listener_region_add() error path, Cédric Le Goater, 2025/01/30
[PATCH v2 5/9] vfio: Improve error reporting when MMIO region mapping fails, Cédric Le Goater, 2025/01/30
[PATCH v2 6/9] vfio: Remove reports of DMA mapping errors in backends, Cédric Le Goater, 2025/01/30
[PATCH v2 4/9] vfio: Introduce vfio_get_vfio_device(), Cédric Le Goater, 2025/01/30
[PATCH v2 8/9] vfio: Check compatibility of CPU and IOMMU address space width, Cédric Le Goater, 2025/01/30
[PATCH v2 7/9] cpu: Introduce cpu_get_phys_bits(), Cédric Le Goater, 2025/01/30