Skip to content

Commit 8de4925

Browse files
robntonyhutter
authored andcommitted
zfs_dbgmsg_print: make FreeBSD and Linux consistent
FreeBSD was using fprintf(), which might not be signal-safe. Meanwhile, Linux's locking did not cover the header output. This two quirks are unrelated, but both have the same response: be like the other one. So with this commit, both functions are the same except for the names of their lock and list variables. 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 86e5569 commit 8de4925

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

module/os/freebsd/zfs/zfs_debug.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,29 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
234234
void
235235
zfs_dbgmsg_print(const char *tag)
236236
{
237-
zfs_dbgmsg_t *zdm;
237+
ssize_t ret __attribute__((unused));
238238

239-
(void) printf("ZFS_DBGMSG(%s):\n", tag);
240239
mutex_enter(&zfs_dbgmsgs_lock);
241-
for (zdm = list_head(&zfs_dbgmsgs); zdm;
240+
241+
/*
242+
* We use write() in this function instead of printf()
243+
* so it is safe to call from a signal handler.
244+
*/
245+
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
246+
ret = write(STDOUT_FILENO, tag, strlen(tag));
247+
ret = write(STDOUT_FILENO, ") START:\n", 9);
248+
249+
for (zfs_dbgmsg_t zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
242250
zdm = list_next(&zfs_dbgmsgs, zdm))
243-
(void) printf("%s\n", zdm->zdm_msg);
251+
ret = write(STDOUT_FILENO, zdm->zdm_msg,
252+
strlen(zdm->zdm_msg));
253+
ret = write(STDOUT_FILENO, "\n", 1);
254+
}
255+
256+
ret = write(STDOUT_FILENO, "ZFS_DBGMSG(", 11);
257+
ret = write(STDOUT_FILENO, tag, strlen(tag));
258+
ret = write(STDOUT_FILENO, ") END\n", 6);
259+
244260
mutex_exit(&zfs_dbgmsgs_lock);
245261
}
246262
#endif /* _KERNEL */

module/os/linux/zfs/zfs_debug.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ zfs_dbgmsg_print(const char *tag)
224224
{
225225
ssize_t ret __attribute__((unused));
226226

227+
mutex_enter(&zfs_dbgmsgs.pl_lock);
228+
227229
/*
228230
* We use write() in this function instead of printf()
229231
* so it is safe to call from a signal handler.
@@ -232,7 +234,6 @@ zfs_dbgmsg_print(const char *tag)
232234
ret = write(STDOUT_FILENO, tag, strlen(tag));
233235
ret = write(STDOUT_FILENO, ") START:\n", 9);
234236

235-
mutex_enter(&zfs_dbgmsgs.pl_lock);
236237
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
237238
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
238239
ret = write(STDOUT_FILENO, zdm->zdm_msg,

0 commit comments

Comments
 (0)