]> git.proxmox.com Git - mirror_zfs.git/commitdiff
OpenZFS 7277 - zdb should be able to print zfs_dbgmsg's
authorGeorge Melikov <mail@gmelikov.ru>
Sat, 28 Jan 2017 20:16:43 +0000 (23:16 +0300)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sat, 28 Jan 2017 20:16:43 +0000 (12:16 -0800)
Porting notes:
- 'zfs_dbgmsg_print()' reintroduced to userspace.

Authored by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Ported-by: George Melikov <mail@gmelikov.ru>
OpenZFS-issue: https://www.illumos.org/issues/7277
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/29bdd2f
Closes #5684

cmd/zdb/zdb.c
include/sys/zfs_debug.h
man/man8/zdb.8
module/zfs/zfs_debug.c

index 938df822705f8c267ce7bbef62a3bb2cadd535d6..6a36aa1ef94f55e89b983fe865618f546b4ee92f 100644 (file)
@@ -21,7 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2015, Intel Corporation.
  */
 
@@ -126,7 +126,7 @@ static void
 usage(void)
 {
        (void) fprintf(stderr,
-           "Usage: %s [-CumMdibcsDvhLXFPA] [-t txg] [-e [-p path...]] "
+           "Usage: %s [-CumMdibcsDvhLXFPAG] [-t txg] [-e [-p path...]] "
            "[-U config] [-I inflight I/Os] [-x dumpdir] poolname [object...]\n"
            "       %s [-divPA] [-e -p path...] [-U config] dataset "
            "[object...]\n"
@@ -187,12 +187,23 @@ usage(void)
        (void) fprintf(stderr, "        -I <number of inflight I/Os> -- "
            "specify the maximum number of "
            "checksumming I/Os [default is 200]\n");
+       (void) fprintf(stderr, "        -G dump zfs_dbgmsg buffer before "
+           "exiting\n");
        (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
            "to make only that option verbose\n");
        (void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
        exit(1);
 }
 
+static void
+dump_debug_buffer(void)
+{
+       if (dump_opt['G']) {
+               (void) printf("\n");
+               zfs_dbgmsg_print("zdb");
+       }
+}
+
 /*
  * Called for usage errors that are discovered after a call to spa_open(),
  * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
@@ -209,6 +220,8 @@ fatal(const char *fmt, ...)
        va_end(ap);
        (void) fprintf(stderr, "\n");
 
+       dump_debug_buffer();
+
        exit(1);
 }
 
@@ -3197,8 +3210,10 @@ dump_zpool(spa_t *spa)
        if (dump_opt['h'])
                dump_history(spa);
 
-       if (rc != 0)
+       if (rc != 0) {
+               dump_debug_buffer();
                exit(rc);
+       }
 }
 
 #define        ZDB_FLAG_CHECKSUM       0x0001
@@ -3692,7 +3707,7 @@ main(int argc, char **argv)
                spa_config_path = spa_config_path_env;
 
        while ((c = getopt(argc, argv,
-           "bcdhilmMI:suCDRSAFLXx:evp:t:U:PV")) != -1) {
+           "bcdhilmMI:suCDRSAFLXx:evp:t:U:PVG")) != -1) {
                switch (c) {
                case 'b':
                case 'c':
@@ -3708,6 +3723,7 @@ main(int argc, char **argv)
                case 'M':
                case 'R':
                case 'S':
+               case 'G':
                        dump_opt[c]++;
                        dump_all = 0;
                        break;
@@ -3939,6 +3955,8 @@ main(int argc, char **argv)
        fuid_table_destroy();
        sa_loaded = B_FALSE;
 
+       dump_debug_buffer();
+
        libzfs_fini(g_zfs);
        kernel_fini();
 
index a2f61e5b290bdd4fa68ee1ad5e16eebb99c6c6d0..b9b06a5ad13f455ddfe2b5c3c10895e7efec9626 100644 (file)
@@ -73,6 +73,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);
 #endif
 
 #ifdef __cplusplus
index efa1f41eb5756c04da1b1dc74ef19a956110c63a..271e512d5eed9b47f2445d41b59fd8214ad6bb77 100644 (file)
 .\"
 .\"
 .\" Copyright 2012, Richard Lowe.
-.\" Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+.\" Copyright (c) 2012, 2016 by Delphix. All rights reserved.
 .\"
-.TH "ZDB" "8" "February 15, 2012" "" ""
+.TH "ZDB" "8" "Feb 4, 2016" "" ""
 
 .SH "NAME"
 \fBzdb\fR - Display zpool debugging and consistency information
 
 .SH "SYNOPSIS"
-\fBzdb\fR [-CumdibcsDvhLMXFPA] [-e [-p \fIpath\fR...]] [-t \fItxg\fR]
+\fBzdb\fR [-CumdibcsDvhLMXFPAG] [-e [-p \fIpath\fR...]] [-t \fItxg\fR]
     [-U \fIcache\fR] [-I \fIinflight I/Os\fR] [-x \fIdumpdir\fR]
     [\fIpoolname\fR [\fIobject\fR ...]]
 
@@ -397,6 +397,17 @@ Attempt to make an unreadable pool readable by trying progressively older
 transactions.
 .RE
 
+.sp
+.ne 2
+.na
+\fB-G\fR
+.ad
+.sp .6
+.RS 4n
+Dump the contents of the zfs_dbgmsg buffer before exiting zdb. zfs_dbgmsg is
+a buffer used by ZFS to dump advanced debug information.
+.RE
+
 .sp
 .ne 2
 .na
index b553d21e4787490d81a9ebf6be566e62931622ac..76a3ad91c91211e94de80445022675a66cbb40e0 100644 (file)
@@ -228,6 +228,21 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...)
 
        kmem_free(buf, size);
 }
+
+#else
+
+void
+zfs_dbgmsg_print(const char *tag)
+{
+       zfs_dbgmsg_t *zdm;
+
+       (void) printf("ZFS_DBGMSG(%s):\n", tag);
+       mutex_enter(&zfs_dbgmsgs_lock);
+       for (zdm = list_head(&zfs_dbgmsgs); zdm;
+           zdm = list_next(&zfs_dbgmsgs, zdm))
+               (void) printf("%s\n", zdm->zdm_msg);
+       mutex_exit(&zfs_dbgmsgs_lock);
+}
 #endif /* _KERNEL */
 
 #ifdef _KERNEL