mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Fix dbgmsg printing in ztest and zdb
This patch resolves a problem where the -G option in both zdb and ztest would cause the code to call __dprintf() to print zfs_dbgmsg output. This function was not properly wired to add messages to the dbgmsg log as it is in userspace and so the messages were simply dropped. This patch also tries to add some degree of distinction to dprintf() (which now prints directly to stdout) and zfs_dbgmsg() (which adds messages to an internal list that can be dumped with zfs_dbgmsg_print()). In addition, this patch corrects an issue where ztest used a global variable to decide whether to dump the dbgmsg buffer on a crash. This did not work because ztest spins up more instances of itself using execv(), which did not copy the global variable to the new process. The option has been moved to the ztest_shared_opts_t which already exists for interprocess communication. This patch also changes zfs_dbgmsg_print() to use write() calls instead of printf() so that it will not fail when used in a signal handler. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Serapheim Dimitropoulos <serapheim.dimitro@delphix.com> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Signed-off-by: Tom Caputi <tcaputi@datto.com> Closes #8010
This commit is contained in:
committed by
Brian Behlendorf
parent
c04812f964
commit
ab4c009e3d
+30
-5
@@ -783,7 +783,8 @@ dprintf_setup(int *argc, char **argv)
|
||||
* =========================================================================
|
||||
*/
|
||||
void
|
||||
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
|
||||
__dprintf(boolean_t dprint, const char *file, const char *func,
|
||||
int line, const char *fmt, ...)
|
||||
{
|
||||
const char *newfile;
|
||||
va_list adx;
|
||||
@@ -798,9 +799,14 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
|
||||
newfile = file;
|
||||
}
|
||||
|
||||
if (dprintf_print_all ||
|
||||
dprintf_find_string(newfile) ||
|
||||
dprintf_find_string(func)) {
|
||||
if (dprint) {
|
||||
/* dprintf messages are printed immediately */
|
||||
|
||||
if (!dprintf_print_all &&
|
||||
!dprintf_find_string(newfile) &&
|
||||
!dprintf_find_string(func))
|
||||
return;
|
||||
|
||||
/* Print out just the function name if requested */
|
||||
flockfile(stdout);
|
||||
if (dprintf_find_string("pid"))
|
||||
@@ -813,11 +819,30 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
|
||||
(void) printf("%llu ", gethrtime());
|
||||
if (dprintf_find_string("long"))
|
||||
(void) printf("%s, line %d: ", newfile, line);
|
||||
(void) printf("%s: ", func);
|
||||
(void) printf("dprintf: %s: ", func);
|
||||
va_start(adx, fmt);
|
||||
(void) vprintf(fmt, adx);
|
||||
va_end(adx);
|
||||
funlockfile(stdout);
|
||||
} else {
|
||||
/* zfs_dbgmsg is logged for dumping later */
|
||||
size_t size;
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
size = 1024;
|
||||
buf = umem_alloc(size, UMEM_NOFAIL);
|
||||
i = snprintf(buf, size, "%s:%d:%s(): ", newfile, line, func);
|
||||
|
||||
if (i < size) {
|
||||
va_start(adx, fmt);
|
||||
(void) vsnprintf(buf + i, size - i, fmt, adx);
|
||||
va_end(adx);
|
||||
}
|
||||
|
||||
__zfs_dbgmsg(buf);
|
||||
|
||||
umem_free(buf, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user