xref: /illumos-gate/usr/src/uts/common/sys/log.h (revision 03100a6332bd4edc7a53091fcf7c9a7131bcdaa7)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /*	  All Rights Reserved	*/
28 
29 #ifndef _SYS_LOG_H
30 #define	_SYS_LOG_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <sys/types.h>
35 #include <sys/strlog.h>
36 #include <sys/stream.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	LOG_CONSMIN	0		/* /dev/conslog minor */
43 #define	LOG_LOGMIN	5		/* /dev/log minor */
44 #define	LOG_BACKLOG	LOG_LOGMIN	/* console backlog queue */
45 
46 #define	LOG_LOGMINIDX	0		/* index of smallest /dev/log clone */
47 #define	LOG_LOGMAXIDX	15		/* up to 16 /dev/log clones */
48 #define	LOG_NUMCLONES	(LOG_LOGMAXIDX - LOG_LOGMINIDX + 1)
49 
50 #define	LOG_MID		44		/* module ID */
51 #define	LOG_MINPS	0		/* min packet size */
52 #define	LOG_MAXPS	1024		/* max packet size */
53 #define	LOG_LOWAT	2048		/* threshold for backenable */
54 #define	LOG_HIWAT	1048576		/* threshold for tossing messages */
55 
56 #define	LOG_MAGIC	0xf00d4109U	/* "food for log" - unsent msg magic */
57 #define	LOG_RECENTSIZE	8192		/* queue of most recent messages */
58 #define	LOG_MINFREE	4096		/* message cache low water mark */
59 #define	LOG_MAXFREE	8192		/* message cache high water mark */
60 
61 typedef struct log log_t;
62 typedef int (log_filter_t)(log_t *, log_ctl_t *);
63 
64 struct log {
65 	queue_t		*log_q;		/* message queue */
66 	log_filter_t	*log_wanted;	/* message filter */
67 	mblk_t		*log_data;	/* parameters for filter */
68 	uint16_t	log_flags;	/* message type (e.g. SL_CONSOLE) */
69 	short		log_inuse;	/* is this log device open? */
70 	int		log_overflow;	/* messages lost due to QFULL */
71 	zoneid_t	log_zoneid;	/* zone id of log */
72 	major_t		log_major;	/* device type */
73 	minor_t		log_minor;	/* minor number of associated device */
74 };
75 
76 /* Array of /dev/log minor devices */
77 typedef struct log_zone {
78 	log_t lz_clones[LOG_NUMCLONES];
79 	uint16_t lz_active;	/* active types (OR of all log_flags fields) */
80 } log_zone_t;
81 
82 #define	LOG_MSGSIZE	200
83 
84 typedef struct log_dump {
85 	uint32_t	ld_magic;	/* LOG_MAGIC */
86 	uint32_t	ld_msgsize;	/* MBLKL(mp->b_cont) */
87 	uint32_t	ld_csum;	/* checksum32(log_ctl) */
88 	uint32_t	ld_msum;	/* checksum32(message text) */
89 	/*
90 	 * log_ctl and message text follow here -- see dump_messages()
91 	 */
92 } log_dump_t;
93 
94 #ifdef _KERNEL
95 
96 /* global zone variables */
97 extern log_zone_t log_global;
98 extern queue_t *log_consq;	/* primary console reader queue */
99 extern queue_t *log_backlogq;	/* console backlog queue */
100 extern queue_t *log_intrq;	/* pending high-level interrupt message queue */
101 
102 extern log_filter_t log_error;
103 extern log_filter_t log_trace;
104 extern log_filter_t log_console;
105 
106 extern void log_init(void);
107 extern void log_enter(void);
108 extern void log_exit(void);
109 extern void log_update(log_t *, queue_t *, short, log_filter_t);
110 extern mblk_t *log_makemsg(int, int, int, int, int, void *, size_t, int);
111 extern void log_freemsg(mblk_t *);
112 extern void log_sendmsg(mblk_t *, zoneid_t);
113 extern void log_flushq(queue_t *);
114 extern void log_printq(queue_t *);
115 extern log_t *log_alloc(minor_t);
116 extern void log_free(log_t *);
117 extern void log_flushall();
118 
119 #endif	/* _KERNEL */
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _SYS_LOG_H */
126