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 Tony Hutter
parent 63f70d3c61
commit 16266b47a1
5 changed files with 26 additions and 28 deletions

View File

@ -938,8 +938,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");
} }
#define BACKTRACE_SZ 100 #define BACKTRACE_SZ 100

View File

@ -593,8 +593,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");
} }
#define BACKTRACE_SZ 100 #define BACKTRACE_SZ 100

View File

@ -103,7 +103,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

@ -220,7 +220,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));
@ -230,20 +230,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);
} }