aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Le Goater <clg@redhat.com>2025-02-06 14:14:29 +0100
committerCédric Le Goater <clg@redhat.com>2025-02-11 14:15:19 +0100
commit96b339cc4cc7e3d2da0e615e1851d3250b526ea5 (patch)
tree6dfd5c2fc39b7ca39d24c587e8d6682421a6de4a
parent7b3d5b84cbd742356a1afc6b0fa489d0663f235d (diff)
downloadqemu-96b339cc4cc7e3d2da0e615e1851d3250b526ea5.zip
qemu-96b339cc4cc7e3d2da0e615e1851d3250b526ea5.tar.gz
qemu-96b339cc4cc7e3d2da0e615e1851d3250b526ea5.tar.bz2
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 <armbru@redhat.com> Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Link: https://lore.kernel.org/qemu-devel/20250206131438.1505542-2-clg@redhat.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
-rw-r--r--include/qapi/error.h12
-rw-r--r--util/error.c11
2 files changed, 23 insertions, 0 deletions
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 71f8fb2..f5fe216 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -467,6 +467,18 @@ void error_reportf_err(Error *err, const char *fmt, ...)
G_GNUC_PRINTF(2, 3);
/*
+ * Similar to warn_report_err(), except it prints the message just once.
+ * Return true when it prints, false otherwise.
+ */
+bool warn_report_err_once_cond(bool *printed, Error *err);
+
+#define warn_report_err_once(err) \
+ ({ \
+ static bool print_once_; \
+ warn_report_err_once_cond(&print_once_, err); \
+ })
+
+/*
* Just like error_setg(), except you get to specify the error class.
* Note: use of error classes other than ERROR_CLASS_GENERIC_ERROR is
* strongly discouraged.
diff --git a/util/error.c b/util/error.c
index e5e2472..673011b 100644
--- a/util/error.c
+++ b/util/error.c
@@ -247,6 +247,17 @@ void warn_report_err(Error *err)
error_free(err);
}
+bool warn_report_err_once_cond(bool *printed, Error *err)
+{
+ if (*printed) {
+ error_free(err);
+ return false;
+ }
+ *printed = true;
+ warn_report_err(err);
+ return true;
+}
+
void error_reportf_err(Error *err, const char *fmt, ...)
{
va_list ap;