xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_log.h (revision f498645a3eecf2ddd304b4ea9c7f1b4c155ff79e)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_LOG_H
28 #define	_FMD_LOG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <pthread.h>
35 #include <exacct.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <fmd_api.h>
42 
43 typedef struct fmd_log {
44 	char *log_name;			/* file pathname */
45 	char *log_tag;			/* file content tag */
46 	int log_fd;			/* file descriptor */
47 	struct stat64 log_stat;		/* status of file at log_open() time */
48 	ea_file_t log_ea;		/* exacct file structure */
49 	pthread_mutex_t log_lock;	/* lock for flags, refs, off, append */
50 	pthread_cond_t log_cv;		/* condition variable for waiters */
51 	int log_flags;			/* file flags (see below) */
52 	uint_t log_refs;		/* file reference count */
53 	uint_t log_pending;		/* number of pending log commits */
54 	off64_t log_toc;		/* offset of table of contents */
55 	off64_t log_beg;		/* offset of first data record */
56 	off64_t log_off;		/* offset at which to append */
57 	off64_t log_skip;		/* offset to skip to for replay */
58 	uint64_t log_minfree;		/* minimum free bytes for filesystem */
59 	char *log_uuid;			/* uuid string for this log file */
60 	uint_t log_uuidlen;		/* length of log_uuid (not incl. \0) */
61 } fmd_log_t;
62 
63 #define	FMD_LF_EAOPEN	0x1		/* log_ea is open and valid */
64 #define	FMD_LF_REPLAY	0x2		/* log records should use replay tag */
65 #define	FMD_LF_DIRTY	0x4		/* log toc should be updated */
66 #define	FMD_LF_BUSY	0x8		/* log is busy; skip updates */
67 
68 typedef void fmd_log_f(fmd_log_t *, fmd_event_t *, void *);
69 
70 #define	FMD_LOG_ERROR	"error"		/* tag for error log files */
71 #define	FMD_LOG_FAULT	"fault"		/* tag for fault log files */
72 #define	FMD_LOG_ASRU	"asru"		/* tag for asru log files */
73 #define	FMD_LOG_XPRT	"xprt"		/* tag for transport log files */
74 
75 extern fmd_log_t *fmd_log_tryopen(const char *, const char *, const char *);
76 extern fmd_log_t *fmd_log_open(const char *, const char *, const char *);
77 extern void fmd_log_close(fmd_log_t *);
78 
79 extern void fmd_log_hold_pending(fmd_log_t *);
80 extern void fmd_log_hold(fmd_log_t *);
81 extern void fmd_log_rele(fmd_log_t *);
82 
83 extern void fmd_log_append(fmd_log_t *, fmd_event_t *, fmd_case_t *);
84 extern void fmd_log_commit(fmd_log_t *, fmd_event_t *);
85 extern void fmd_log_decommit(fmd_log_t *, fmd_event_t *);
86 extern void fmd_log_replay(fmd_log_t *, fmd_log_f *, void *);
87 extern void fmd_log_update(fmd_log_t *);
88 extern fmd_log_t *fmd_log_rotate(fmd_log_t *);
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _FMD_LOG_H */
95