aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2024-05-10 13:54:08 +1000
committerBrian Behlendorf <[email protected]>2024-05-14 09:48:56 -0700
commitfa99d9cd9cbc6aca3245afcfe321b8226985597d (patch)
tree44f15fc371b83e049944232eb81864e97c200427
parent1ea8c59441cd215d4f45cbe839cbfe51c6e32068 (diff)
zfs_dbgmsg_print: make FreeBSD and Linux consistent
FreeBSD was using fprintf(), which might not be signal-safe. Meanwhile, Linux's locking did not cover the header output. This two quirks are unrelated, but both have the same response: be like the other one. So with this commit, both functions are the same except for the names of their lock and list variables. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16181
-rw-r--r--module/os/freebsd/zfs/zfs_debug.c24
-rw-r--r--module/os/linux/zfs/zfs_debug.c3
2 files changed, 22 insertions, 5 deletions
diff --git a/module/os/freebsd/zfs/zfs_debug.c b/module/os/freebsd/zfs/zfs_debug.c
index 78d50c6fd..3e832a910 100644
--- a/module/os/freebsd/zfs/zfs_debug.c
+++ b/module/os/freebsd/zfs/zfs_debug.c
@@ -234,13 +234,29 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
void
zfs_dbgmsg_print(const char *tag)
{
- zfs_dbgmsg_t *zdm;
+ ssize_t ret __attribute__((unused));
- (void) printf("ZFS_DBGMSG(%s):\n", tag);
mutex_enter(&zfs_dbgmsgs_lock);
- for (zdm = list_head(&zfs_dbgmsgs); zdm;
+
+ /*
+ * We use write() in this function instead of printf()
+ * so it is safe to call from a signal handler.
+ */
+ ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
+ ret = write(STDOUT_FILENO, tag, strlen(tag));
+ ret = write(STDOUT_FILENO, ") START:\n", 9);
+
+ for (zfs_dbgmsg_t zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
zdm = list_next(&zfs_dbgmsgs, zdm))
- (void) printf("%s\n", zdm->zdm_msg);
+ ret = write(STDOUT_FILENO, zdm->zdm_msg,
+ strlen(zdm->zdm_msg));
+ ret = write(STDOUT_FILENO, "\n", 1);
+ }
+
+ ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
+ ret = write(STDOUT_FILENO, tag, strlen(tag));
+ ret = write(STDOUT_FILENO, ") END\n", 6);
+
mutex_exit(&zfs_dbgmsgs_lock);
}
#endif /* _KERNEL */
diff --git a/module/os/linux/zfs/zfs_debug.c b/module/os/linux/zfs/zfs_debug.c
index f707959c9..bc5c028dc 100644
--- a/module/os/linux/zfs/zfs_debug.c
+++ b/module/os/linux/zfs/zfs_debug.c
@@ -225,6 +225,8 @@ zfs_dbgmsg_print(const char *tag)
{
ssize_t ret __attribute__((unused));
+ mutex_enter(&zfs_dbgmsgs.pl_lock);
+
/*
* We use write() in this function instead of printf()
* so it is safe to call from a signal handler.
@@ -233,7 +235,6 @@ zfs_dbgmsg_print(const char *tag)
ret = write(STDOUT_FILENO, tag, strlen(tag));
ret = write(STDOUT_FILENO, ") START:\n", 9);
- mutex_enter(&zfs_dbgmsgs.pl_lock);
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
ret = write(STDOUT_FILENO, zdm->zdm_msg,