From 16266b47a13a2f9796ad3fba567315d66f8850f5 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Fri, 10 May 2024 13:58:26 +1000 Subject: [PATCH] zdb/ztest: send dbgmsg output to stderr And, make the output fd an arg to zfs_dbgmsg_print(). This is a change in behaviour, but keeps it consistent with where crash traces go, and it's easy to argue this is what we want anyway; this is information about the task, not the actual output of the task. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #16181 --- cmd/zdb/zdb.c | 4 ++-- cmd/ztest.c | 4 ++-- include/sys/zfs_debug.h | 2 +- module/os/freebsd/zfs/zfs_debug.c | 25 ++++++++++++------------- module/os/linux/zfs/zfs_debug.c | 19 +++++++++---------- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 52b8fe8ae..f7114b712 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -938,8 +938,8 @@ dump_debug_buffer(void) * We use write() instead of printf() so that this function * is safe to call from a signal handler. */ - ret = write(STDOUT_FILENO, "\n", 1); - zfs_dbgmsg_print("zdb"); + ret = write(STDERR_FILENO, "\n", 1); + zfs_dbgmsg_print(STDERR_FILENO, "zdb"); } #define BACKTRACE_SZ 100 diff --git a/cmd/ztest.c b/cmd/ztest.c index 2601b2796..9b9e2e8a9 100644 --- a/cmd/ztest.c +++ b/cmd/ztest.c @@ -593,8 +593,8 @@ dump_debug_buffer(void) * We use write() instead of printf() so that this function * is safe to call from a signal handler. */ - ret = write(STDOUT_FILENO, "\n", 1); - zfs_dbgmsg_print("ztest"); + ret = write(STDERR_FILENO, "\n", 1); + zfs_dbgmsg_print(STDERR_FILENO, "ztest"); } #define BACKTRACE_SZ 100 diff --git a/include/sys/zfs_debug.h b/include/sys/zfs_debug.h index a1dfef1d8..62fa34cd1 100644 --- a/include/sys/zfs_debug.h +++ b/include/sys/zfs_debug.h @@ -103,7 +103,7 @@ extern void zfs_dbgmsg_fini(void); #ifndef _KERNEL extern int dprintf_find_string(const char *string); -extern void zfs_dbgmsg_print(const char *tag); +extern void zfs_dbgmsg_print(int fd, const char *tag); #endif #ifdef __cplusplus diff --git a/module/os/freebsd/zfs/zfs_debug.c b/module/os/freebsd/zfs/zfs_debug.c index 3e832a910..c4cebe102 100644 --- a/module/os/freebsd/zfs/zfs_debug.c +++ b/module/os/freebsd/zfs/zfs_debug.c @@ -232,30 +232,29 @@ __dprintf(boolean_t dprint, const char *file, const char *func, #else void -zfs_dbgmsg_print(const char *tag) +zfs_dbgmsg_print(int fd, const char *tag) { ssize_t ret __attribute__((unused)); - mutex_enter(&zfs_dbgmsgs_lock); - /* * 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); + ret = write(fd, "ZFS_DBGMSG(", 11); + ret = write(fd, tag, strlen(tag)); + ret = write(fd, ") START:\n", 9); - for (zfs_dbgmsg_t zdm = list_head(&zfs_dbgmsgs); zdm != NULL; + mutex_enter(&zfs_dbgmsgs_lock); + + for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL; zdm = list_next(&zfs_dbgmsgs, zdm)) - ret = write(STDOUT_FILENO, zdm->zdm_msg, - strlen(zdm->zdm_msg)); - ret = write(STDOUT_FILENO, "\n", 1); + ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg)); + ret = write(fd, "\n", 1); } - ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); - ret = write(STDOUT_FILENO, tag, strlen(tag)); - ret = write(STDOUT_FILENO, ") END\n", 6); + ret = write(fd, "ZFS_DBGMSG(", 11); + ret = write(fd, tag, strlen(tag)); + ret = write(fd, ") END\n", 6); mutex_exit(&zfs_dbgmsgs_lock); } diff --git a/module/os/linux/zfs/zfs_debug.c b/module/os/linux/zfs/zfs_debug.c index 90ee72b55..733b4a574 100644 --- a/module/os/linux/zfs/zfs_debug.c +++ b/module/os/linux/zfs/zfs_debug.c @@ -220,7 +220,7 @@ __dprintf(boolean_t dprint, const char *file, const char *func, #else void -zfs_dbgmsg_print(const char *tag) +zfs_dbgmsg_print(int fd, const char *tag) { ssize_t ret __attribute__((unused)); @@ -230,20 +230,19 @@ zfs_dbgmsg_print(const char *tag) * 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); + ret = write(fd, "ZFS_DBGMSG(", 11); + ret = write(fd, tag, strlen(tag)); + ret = write(fd, ") START:\n", 9); 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, - strlen(zdm->zdm_msg)); - ret = write(STDOUT_FILENO, "\n", 1); + ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg)); + ret = write(fd, "\n", 1); } - ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); - ret = write(STDOUT_FILENO, tag, strlen(tag)); - ret = write(STDOUT_FILENO, ") END\n", 6); + ret = write(fd, "ZFS_DBGMSG(", 11); + ret = write(fd, tag, strlen(tag)); + ret = write(fd, ") END\n", 6); mutex_exit(&zfs_dbgmsgs.pl_lock); }