mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +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
@@ -225,6 +225,7 @@ dump_debug_buffer(void)
|
||||
{
|
||||
if (dump_opt['G']) {
|
||||
(void) printf("\n");
|
||||
(void) fflush(stdout);
|
||||
zfs_dbgmsg_print("zdb");
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -178,6 +178,7 @@ typedef struct ztest_shared_opts {
|
||||
uint64_t zo_metaslab_force_ganging;
|
||||
int zo_mmp_test;
|
||||
int zo_special_vdevs;
|
||||
int zo_dump_dbgmsg;
|
||||
} ztest_shared_opts_t;
|
||||
|
||||
static const ztest_shared_opts_t ztest_opts_defaults = {
|
||||
@@ -484,7 +485,6 @@ static kmutex_t ztest_checkpoint_lock;
|
||||
static pthread_rwlock_t ztest_name_lock;
|
||||
|
||||
static boolean_t ztest_dump_core = B_TRUE;
|
||||
static boolean_t ztest_dump_debug_buffer = B_FALSE;
|
||||
static boolean_t ztest_exiting;
|
||||
|
||||
/* Global commit callback list */
|
||||
@@ -533,10 +533,16 @@ _umem_logging_init(void)
|
||||
static void
|
||||
dump_debug_buffer(void)
|
||||
{
|
||||
if (!ztest_dump_debug_buffer)
|
||||
ssize_t ret __attribute__((unused));
|
||||
|
||||
if (!ztest_opts.zo_dump_dbgmsg)
|
||||
return;
|
||||
|
||||
(void) printf("\n");
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
|
||||
@@ -591,10 +597,11 @@ fatal(int do_perror, char *message, ...)
|
||||
(void) fprintf(stderr, "%s\n", buf);
|
||||
fatal_msg = buf; /* to ease debugging */
|
||||
|
||||
dump_debug_buffer();
|
||||
|
||||
if (ztest_dump_core)
|
||||
abort();
|
||||
else
|
||||
dump_debug_buffer();
|
||||
|
||||
exit(3);
|
||||
}
|
||||
|
||||
@@ -866,7 +873,7 @@ process_options(int argc, char **argv)
|
||||
usage(B_FALSE);
|
||||
break;
|
||||
case 'G':
|
||||
ztest_dump_debug_buffer = B_TRUE;
|
||||
zo->zo_dump_dbgmsg = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage(B_TRUE);
|
||||
|
||||
Reference in New Issue
Block a user