Skip to content

Commit

Permalink
zdb/ztest: send dbgmsg output to stderr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robn authored and behlendorf committed May 14, 2024
1 parent fa99d9c commit 3c941d1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,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");
}

static void sig_handler(int signo)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,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");
}

static void sig_handler(int signo)
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zfs_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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
Expand Down
25 changes: 12 additions & 13 deletions module/os/freebsd/zfs/zfs_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

mutex_enter(&zfs_dbgmsgs_lock);

for (zfs_dbgmsg_t zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
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);
}
Expand Down
19 changes: 9 additions & 10 deletions module/os/linux/zfs/zfs_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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));

Expand All @@ -231,20 +231,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);
}
Expand Down

0 comments on commit 3c941d1

Please sign in to comment.