Message ID | 20250206131438.1505542-2-clg@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | vfio: Improve error reporting when MMIO region mapping fails | expand |
On 2/6/25 14:14, Cédric Le Goater wrote: > 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> > Signed-off-by: Cédric Le Goater <clg@redhat.com> > --- > include/qapi/error.h | 12 ++++++++++++ > util/error.c | 11 +++++++++++ > 2 files changed, 23 insertions(+) Hello Markus, Are you ok with this change ? Should we take it through the vfio queue ? Thanks, C. > diff --git a/include/qapi/error.h b/include/qapi/error.h > index 71f8fb2c50eee9a544992d0c05263c9793956fe1..f5fe2162623e5770d652f7415ebc25172d97616e 100644 > --- a/include/qapi/error.h > +++ b/include/qapi/error.h > @@ -466,6 +466,18 @@ void warn_reportf_err(Error *err, const char *fmt, ...) > 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 > diff --git a/util/error.c b/util/error.c > index e5e247209a9e0796074a9794f5598325f22f8d35..673011b89e95f488817b86c31cd389386b2558bb 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;
Cédric Le Goater <clg@redhat.com> writes: > On 2/6/25 14:14, Cédric Le Goater wrote: >> 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> >> Signed-off-by: Cédric Le Goater <clg@redhat.com> >> --- >> include/qapi/error.h | 12 ++++++++++++ >> util/error.c | 11 +++++++++++ >> 2 files changed, 23 insertions(+) > > Hello Markus, > > Are you ok with this change ? Should we take it through the vfio queue ? Yes, please. Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff --git a/include/qapi/error.h b/include/qapi/error.h index 71f8fb2c50eee9a544992d0c05263c9793956fe1..f5fe2162623e5770d652f7415ebc25172d97616e 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -466,6 +466,18 @@ void warn_reportf_err(Error *err, const char *fmt, ...) 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 diff --git a/util/error.c b/util/error.c index e5e247209a9e0796074a9794f5598325f22f8d35..673011b89e95f488817b86c31cd389386b2558bb 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;
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> Signed-off-by: Cédric Le Goater <clg@redhat.com> --- include/qapi/error.h | 12 ++++++++++++ util/error.c | 11 +++++++++++ 2 files changed, 23 insertions(+)