spl: Add cmn_err_once() to log a message only on the first call

Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Attila Fülöp <attila@fueloep.org>
Closes #14567
This commit is contained in:
Attila Fülöp
2023-03-07 22:44:11 +01:00
committed by GitHub
parent 4628bb9c60
commit 1191387012
3 changed files with 84 additions and 0 deletions
+17
View File
@@ -29,6 +29,7 @@
#else
#include <stdarg.h>
#endif
#include <sys/atomic.h>
#define CE_CONT 0 /* continuation */
#define CE_NOTE 1 /* notice */
@@ -45,4 +46,20 @@ extern void vpanic(const char *, va_list)
#define fm_panic panic
#define cmn_err_once(ce, ...) \
{ \
static volatile uint32_t printed = 0; \
if (atomic_cas_32(&printed, 0, 1) == 0) { \
cmn_err(ce, __VA_ARGS__); \
} \
}
#define vcmn_err_once(ce, fmt, ap) \
{ \
static volatile uint32_t printed = 0; \
if (atomic_cas_32(&printed, 0, 1) == 0) { \
vcmn_err(ce, fmt, ap); \
} \
}
#endif /* SPL_CMN_ERR_H */