Skip to content

Commit 96b339c

Browse files
committed
util/error: Introduce warn_report_err_once()
Depending on the configuration of the host and VM, a passthrough device may generate recurring DMA mapping errors at runtime. In such cases, reporting the issue once is sufficient. We have already the warn/error_report_once() routines taking a format and arguments. Using the same design pattern, add a new warning variant taking an 'Error *' parameter. Cc: Markus Armbruster <[email protected]> Reviewed-by: Alex Williamson <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]>
1 parent 7b3d5b8 commit 96b339c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/qapi/error.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,18 @@ void warn_reportf_err(Error *err, const char *fmt, ...)
466466
void error_reportf_err(Error *err, const char *fmt, ...)
467467
G_GNUC_PRINTF(2, 3);
468468

469+
/*
470+
* Similar to warn_report_err(), except it prints the message just once.
471+
* Return true when it prints, false otherwise.
472+
*/
473+
bool warn_report_err_once_cond(bool *printed, Error *err);
474+
475+
#define warn_report_err_once(err) \
476+
({ \
477+
static bool print_once_; \
478+
warn_report_err_once_cond(&print_once_, err); \
479+
})
480+
469481
/*
470482
* Just like error_setg(), except you get to specify the error class.
471483
* Note: use of error classes other than ERROR_CLASS_GENERIC_ERROR is

util/error.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ void warn_report_err(Error *err)
247247
error_free(err);
248248
}
249249

250+
bool warn_report_err_once_cond(bool *printed, Error *err)
251+
{
252+
if (*printed) {
253+
error_free(err);
254+
return false;
255+
}
256+
*printed = true;
257+
warn_report_err(err);
258+
return true;
259+
}
260+
250261
void error_reportf_err(Error *err, const char *fmt, ...)
251262
{
252263
va_list ap;

0 commit comments

Comments
 (0)