4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/zfs_context.h>
29 kmutex_t zfs_dbgmsgs_lock
;
30 int zfs_dbgmsg_maxsize
= 1<<20; /* 1MB */
35 list_create(&zfs_dbgmsgs
, sizeof (zfs_dbgmsg_t
),
36 offsetof(zfs_dbgmsg_t
, zdm_node
));
37 mutex_init(&zfs_dbgmsgs_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
45 while ((zdm
= list_remove_head(&zfs_dbgmsgs
)) != NULL
) {
46 int size
= sizeof (zfs_dbgmsg_t
) + strlen(zdm
->zdm_msg
);
48 zfs_dbgmsg_size
-= size
;
50 mutex_destroy(&zfs_dbgmsgs_lock
);
51 ASSERT3U(zfs_dbgmsg_size
, ==, 0);
55 * Print these messages by running:
56 * echo ::zfs_dbgmsg | mdb -k
58 * Monitor these messages by running:
59 * dtrace -q -n 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}'
62 zfs_dbgmsg(const char *fmt
, ...)
69 size
= vsnprintf(NULL
, 0, fmt
, adx
);
73 * There is one byte of string in sizeof (zfs_dbgmsg_t), used
74 * for the terminating null.
76 zdm
= kmem_alloc(sizeof (zfs_dbgmsg_t
) + size
, KM_SLEEP
);
77 zdm
->zdm_timestamp
= gethrestime_sec();
80 (void) vsnprintf(zdm
->zdm_msg
, size
+ 1, fmt
, adx
);
83 DTRACE_PROBE1(zfs__dbgmsg
, char *, zdm
->zdm_msg
);
85 mutex_enter(&zfs_dbgmsgs_lock
);
86 list_insert_tail(&zfs_dbgmsgs
, zdm
);
87 zfs_dbgmsg_size
+= sizeof (zfs_dbgmsg_t
) + size
;
88 while (zfs_dbgmsg_size
> zfs_dbgmsg_maxsize
) {
89 zdm
= list_remove_head(&zfs_dbgmsgs
);
90 size
= sizeof (zfs_dbgmsg_t
) + strlen(zdm
->zdm_msg
);
92 zfs_dbgmsg_size
-= size
;
94 mutex_exit(&zfs_dbgmsgs_lock
);