]> git.proxmox.com Git - mirror_zfs.git/blobdiff - lib/libzpool/kernel.c
Fix dbgmsg printing in ztest and zdb
[mirror_zfs.git] / lib / libzpool / kernel.c
index 5baf52514a7b58e232da66f709ee5b8c82a86679..f5eafb9172549f66e6ca8e693d40c495ae804c10 100644 (file)
@@ -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);
        }
 }