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 <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16181
This commit is contained in:
Rob Norris 2024-05-10 13:58:26 +10:00 committed by Brian Behlendorf
parent fa99d9cd9c
commit 3c941d1818
5 changed files with 26 additions and 28 deletions

View File

@ -837,8 +837,8 @@ dump_debug_buffer(void)
* We use write() instead of printf() so that this function * We use write() instead of printf() so that this function
* is safe to call from a signal handler. * is safe to call from a signal handler.
*/ */
ret = write(STDOUT_FILENO, "\n", 1); ret = write(STDERR_FILENO, "\n", 1);
zfs_dbgmsg_print("zdb"); zfs_dbgmsg_print(STDERR_FILENO, "zdb");
} }
static void sig_handler(int signo) static void sig_handler(int signo)

View File

@ -615,8 +615,8 @@ dump_debug_buffer(void)
* We use write() instead of printf() so that this function * We use write() instead of printf() so that this function
* is safe to call from a signal handler. * is safe to call from a signal handler.
*/ */
ret = write(STDOUT_FILENO, "\n", 1); ret = write(STDERR_FILENO, "\n", 1);
zfs_dbgmsg_print("ztest"); zfs_dbgmsg_print(STDERR_FILENO, "ztest");
} }
static void sig_handler(int signo) static void sig_handler(int signo)

View File

@ -104,7 +104,7 @@ extern void zfs_dbgmsg_fini(void);
#ifndef _KERNEL #ifndef _KERNEL
extern int dprintf_find_string(const char *string); 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 #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -232,30 +232,29 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
#else #else
void void
zfs_dbgmsg_print(const char *tag) zfs_dbgmsg_print(int fd, const char *tag)
{ {
ssize_t ret __attribute__((unused)); ssize_t ret __attribute__((unused));
mutex_enter(&zfs_dbgmsgs_lock);
/* /*
* We use write() in this function instead of printf() * We use write() in this function instead of printf()
* so it is safe to call from a signal handler. * so it is safe to call from a signal handler.
*/ */
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(STDOUT_FILENO, tag, strlen(tag)); ret = write(fd, tag, strlen(tag));
ret = write(STDOUT_FILENO, ") START:\n", 9); 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)) zdm = list_next(&zfs_dbgmsgs, zdm))
ret = write(STDOUT_FILENO, zdm->zdm_msg, ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
strlen(zdm->zdm_msg)); ret = write(fd, "\n", 1);
ret = write(STDOUT_FILENO, "\n", 1);
} }
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(STDOUT_FILENO, tag, strlen(tag)); ret = write(fd, tag, strlen(tag));
ret = write(STDOUT_FILENO, ") END\n", 6); ret = write(fd, ") END\n", 6);
mutex_exit(&zfs_dbgmsgs_lock); mutex_exit(&zfs_dbgmsgs_lock);
} }

View File

@ -221,7 +221,7 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
#else #else
void void
zfs_dbgmsg_print(const char *tag) zfs_dbgmsg_print(int fd, const char *tag)
{ {
ssize_t ret __attribute__((unused)); ssize_t ret __attribute__((unused));
@ -231,20 +231,19 @@ zfs_dbgmsg_print(const char *tag)
* We use write() in this function instead of printf() * We use write() in this function instead of printf()
* so it is safe to call from a signal handler. * so it is safe to call from a signal handler.
*/ */
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(STDOUT_FILENO, tag, strlen(tag)); ret = write(fd, tag, strlen(tag));
ret = write(STDOUT_FILENO, ") START:\n", 9); ret = write(fd, ") START:\n", 9);
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL; for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) { zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
ret = write(STDOUT_FILENO, zdm->zdm_msg, ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
strlen(zdm->zdm_msg)); ret = write(fd, "\n", 1);
ret = write(STDOUT_FILENO, "\n", 1);
} }
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11); ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(STDOUT_FILENO, tag, strlen(tag)); ret = write(fd, tag, strlen(tag));
ret = write(STDOUT_FILENO, ") END\n", 6); ret = write(fd, ") END\n", 6);
mutex_exit(&zfs_dbgmsgs.pl_lock); mutex_exit(&zfs_dbgmsgs.pl_lock);
} }