xref: /illumos-gate/usr/src/uts/common/io/rsm/rsmka_util.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/user.h>
32 #include <sys/buf.h>
33 #include <sys/systm.h>
34 #include <sys/vm.h>
35 #include <sys/uio.h>
36 #include <vm/seg.h>
37 #include <sys/stat.h>
38 
39 #include <sys/time.h>
40 #include <sys/varargs.h>
41 
42 #include <sys/rsm/rsm.h>
43 
44 /* lint -w2 */
45 
46 extern char *vsprintf_len(size_t, char *, const char *, va_list);
47 extern char *sprintf(char *buf, const char *fmt, ...);
48 
49 /*
50  * From kmdb, read printfs using : *rsmka_dbg/s
51  */
52 #define	RSMKA_BUFSIZE	0x10000
53 
54 char    rsmka_buf[RSMKA_BUFSIZE];
55 char    *rsmka_dbg = rsmka_buf;
56 char    *rsmka_buf_end = rsmka_buf;
57 char    *rsmka_buf_top = rsmka_buf + RSMKA_BUFSIZE - 256;
58 kmutex_t rsmka_buf_lock;
59 
60 int rsmdbg_category = RSM_KERNEL_ALL;
61 #ifdef DEBUG
62 int rsmdbg_level = RSM_DEBUG_VERBOSE;
63 #else
64 int rsmdbg_level = RSM_NOTICE;
65 #endif
66 
67 void dbprintf(char *fmt, ...) {
68 	va_list ap;
69 /* lint -save -e40 */
70 	va_start(ap, fmt);
71 /* lint -restore */
72 	mutex_enter(&rsmka_buf_lock);
73 	(void) vsprintf_len(255, rsmka_buf_end, fmt, ap);
74 	rsmka_buf_end += strlen(rsmka_buf_end);
75 	if (rsmka_buf_end > rsmka_buf_top) {
76 		rsmka_buf_end = rsmka_buf;
77 	}
78 	va_end(ap);
79 	mutex_exit(&rsmka_buf_lock);
80 }
81 
82 void
83 dbg_printf(int msg_category, int msg_level, char *fmt, ...)
84 {
85 	if ((msg_category & rsmdbg_category) &&
86 	    (msg_level <= rsmdbg_level)) {
87 		va_list	ap;
88 		va_start(ap, fmt);
89 		mutex_enter(&rsmka_buf_lock);
90 		(void) sprintf(rsmka_buf_end, "%16" PRIx64 ":",
91 			curthread->t_did);
92 		rsmka_buf_end += 17;
93 		(void) vsprintf_len(255, rsmka_buf_end, fmt, ap);
94 		rsmka_buf_end += strlen(rsmka_buf_end);
95 		if (rsmka_buf_end > rsmka_buf_top) {
96 			rsmka_buf_end = rsmka_buf;
97 		}
98 		mutex_exit(&rsmka_buf_lock);
99 		va_end(ap);
100 	}
101 }
102