Skip to content

Commit 06bac7c

Browse files
robntonyhutter
authored andcommitted
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 <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16181
1 parent 8de4925 commit 06bac7c

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

cmd/zdb/zdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,8 @@ dump_debug_buffer(void)
938938
* We use write() instead of printf() so that this function
939939
* is safe to call from a signal handler.
940940
*/
941-
ret = write(STDOUT_FILENO, "\n", 1);
942-
zfs_dbgmsg_print("zdb");
941+
ret = write(STDERR_FILENO, "\n", 1);
942+
zfs_dbgmsg_print(STDERR_FILENO, "zdb");
943943
}
944944

945945
#define BACKTRACE_SZ 100

cmd/ztest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ dump_debug_buffer(void)
593593
* We use write() instead of printf() so that this function
594594
* is safe to call from a signal handler.
595595
*/
596-
ret = write(STDOUT_FILENO, "\n", 1);
597-
zfs_dbgmsg_print("ztest");
596+
ret = write(STDERR_FILENO, "\n", 1);
597+
zfs_dbgmsg_print(STDERR_FILENO, "ztest");
598598
}
599599

600600
#define BACKTRACE_SZ 100

include/sys/zfs_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extern void zfs_dbgmsg_fini(void);
103103

104104
#ifndef _KERNEL
105105
extern int dprintf_find_string(const char *string);
106-
extern void zfs_dbgmsg_print(const char *tag);
106+
extern void zfs_dbgmsg_print(int fd, const char *tag);
107107
#endif
108108

109109
#ifdef __cplusplus

module/os/freebsd/zfs/zfs_debug.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,30 +232,29 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
232232
#else
233233

234234
void
235-
zfs_dbgmsg_print(const char *tag)
235+
zfs_dbgmsg_print(int fd, const char *tag)
236236
{
237237
ssize_t ret __attribute__((unused));
238238

239-
mutex_enter(&zfs_dbgmsgs_lock);
240-
241239
/*
242240
* We use write() in this function instead of printf()
243241
* so it is safe to call from a signal handler.
244242
*/
245-
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
246-
ret = write(STDOUT_FILENO, tag, strlen(tag));
247-
ret = write(STDOUT_FILENO, ") START:\n", 9);
243+
ret = write(fd, "ZFS_DBGMSG(", 11);
244+
ret = write(fd, tag, strlen(tag));
245+
ret = write(fd, ") START:\n", 9);
246+
247+
mutex_enter(&zfs_dbgmsgs_lock);
248248

249-
for (zfs_dbgmsg_t zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
249+
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
250250
zdm = list_next(&zfs_dbgmsgs, zdm))
251-
ret = write(STDOUT_FILENO, zdm->zdm_msg,
252-
strlen(zdm->zdm_msg));
253-
ret = write(STDOUT_FILENO, "\n", 1);
251+
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
252+
ret = write(fd, "\n", 1);
254253
}
255254

256-
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
257-
ret = write(STDOUT_FILENO, tag, strlen(tag));
258-
ret = write(STDOUT_FILENO, ") END\n", 6);
255+
ret = write(fd, "ZFS_DBGMSG(", 11);
256+
ret = write(fd, tag, strlen(tag));
257+
ret = write(fd, ") END\n", 6);
259258

260259
mutex_exit(&zfs_dbgmsgs_lock);
261260
}

module/os/linux/zfs/zfs_debug.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
220220
#else
221221

222222
void
223-
zfs_dbgmsg_print(const char *tag)
223+
zfs_dbgmsg_print(int fd, const char *tag)
224224
{
225225
ssize_t ret __attribute__((unused));
226226

@@ -230,20 +230,19 @@ zfs_dbgmsg_print(const char *tag)
230230
* We use write() in this function instead of printf()
231231
* so it is safe to call from a signal handler.
232232
*/
233-
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
234-
ret = write(STDOUT_FILENO, tag, strlen(tag));
235-
ret = write(STDOUT_FILENO, ") START:\n", 9);
233+
ret = write(fd, "ZFS_DBGMSG(", 11);
234+
ret = write(fd, tag, strlen(tag));
235+
ret = write(fd, ") START:\n", 9);
236236

237237
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
238238
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
239-
ret = write(STDOUT_FILENO, zdm->zdm_msg,
240-
strlen(zdm->zdm_msg));
241-
ret = write(STDOUT_FILENO, "\n", 1);
239+
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
240+
ret = write(fd, "\n", 1);
242241
}
243242

244-
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
245-
ret = write(STDOUT_FILENO, tag, strlen(tag));
246-
ret = write(STDOUT_FILENO, ") END\n", 6);
243+
ret = write(fd, "ZFS_DBGMSG(", 11);
244+
ret = write(fd, tag, strlen(tag));
245+
ret = write(fd, ") END\n", 6);
247246

248247
mutex_exit(&zfs_dbgmsgs.pl_lock);
249248
}

0 commit comments

Comments
 (0)