log.h revision 068ccd7a3ca82dd23e4f5d606c56438d503cc60b
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/*
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * CDDL HEADER START
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao *
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * The contents of this file are subject to the terms of the
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * Common Development and Distribution License, Version 1.0 only
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * (the "License"). You may not use this file except in compliance
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * with the License.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao *
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * or http://www.opensolaris.org/os/licensing.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * See the License for the specific language governing permissions
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * and limitations under the License.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao *
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * When distributing Covered Code, include this CDDL HEADER in each
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * If applicable, add the following below this CDDL HEADER, with the
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * fields enclosed by brackets "[]" replaced with your own identifying
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * information: Portions Copyright [yyyy] [name of copyright owner]
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao *
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * CDDL HEADER END
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/*
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * Use is subject to license terms.
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/* All Rights Reserved */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#ifndef _SYS_LOG_H
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define _SYS_LOG_H
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#pragma ident "%Z%%M% %I% %E% SMI"
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#include <sys/types.h>
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#include <sys/strlog.h>
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#include <sys/stream.h>
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#ifdef __cplusplus
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern "C" {
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#endif
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_CONSMIN 0 /* /dev/conslog minor */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_LOGMIN 5 /* /dev/log minor */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_BACKLOG LOG_LOGMIN /* console backlog queue */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_LOGMINIDX 0 /* index of smallest /dev/log clone */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_LOGMAXIDX 15 /* up to 16 /dev/log clones */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_NUMCLONES (LOG_LOGMAXIDX - LOG_LOGMINIDX + 1)
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MID 44 /* module ID */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MINPS 0 /* min packet size */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MAXPS 1024 /* max packet size */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_LOWAT 2048 /* threshold for backenable */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_HIWAT 1048576 /* threshold for tossing messages */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MAGIC 0xf00d4109U /* "food for log" - unsent msg magic */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_RECENTSIZE 8192 /* queue of most recent messages */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MINFREE 4096 /* message cache low water mark */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MAXFREE 8192 /* message cache high water mark */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaotypedef struct log log_t;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaotypedef int (log_filter_t)(log_t *, log_ctl_t *);
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaostruct log {
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao queue_t *log_q; /* message queue */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao log_filter_t *log_wanted; /* message filter */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao mblk_t *log_data; /* parameters for filter */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint16_t log_flags; /* message type (e.g. SL_CONSOLE) */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao short log_inuse; /* is this log device open? */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao int log_overflow; /* messages lost due to QFULL */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao zoneid_t log_zoneid; /* zone id of log */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao major_t log_major; /* device type */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao minor_t log_minor; /* minor number of associated device */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao};
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/* Array of /dev/log minor devices */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaotypedef struct log_zone {
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao log_t lz_clones[LOG_NUMCLONES];
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint16_t lz_active; /* active types (OR of all log_flags fields) */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao} log_zone_t;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#define LOG_MSGSIZE 200
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaotypedef struct log_dump {
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint32_t ld_magic; /* LOG_MAGIC */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint32_t ld_msgsize; /* MBLKL(mp->b_cont) */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint32_t ld_csum; /* checksum32(log_ctl) */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao uint32_t ld_msum; /* checksum32(message text) */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao /*
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao * log_ctl and message text follow here -- see dump_messages()
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao} log_dump_t;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao#ifdef _KERNEL
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao/* global zone variables */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern log_zone_t log_global;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern queue_t *log_consq; /* primary console reader queue */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern queue_t *log_backlogq; /* console backlog queue */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern queue_t *log_intrq; /* pending high-level interrupt message queue */
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern log_filter_t log_error;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern log_filter_t log_trace;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern log_filter_t log_console;
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiao
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern void log_init(void);
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern void log_enter(void);
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern void log_exit(void);
dd3988293c1bf1c272110c5f9ff36639cdc564aaSizhang Xiaoextern void log_update(log_t *, queue_t *, short, log_filter_t);
extern mblk_t *log_makemsg(int, int, int, int, int, void *, size_t, int);
extern void log_freemsg(mblk_t *);
extern void log_sendmsg(mblk_t *, zoneid_t);
extern void log_flushq(queue_t *);
extern void log_printq(queue_t *);
extern log_t *log_alloc(minor_t);
extern void log_free(log_t *);
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_LOG_H */