xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_ckpt.h (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 #ifndef	_FMD_CKPT_H
28 #define	_FMD_CKPT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Fault Manager Checkpoint Format (FCF)
40  *
41  * Fault manager modules can checkpoint state in the FCF format so that they
42  * can survive restarts, module failures, and reboots.  The FCF format is
43  * versioned and extensible so that it can be revised and so that internal data
44  * structures can be modified or extended compatibly.  It is also specified as
45  * a Project Private interface so that incompatible changes can occur as we see
46  * fit.  All FCF structures use fixed-size types so that the 32-bit and 64-bit
47  * forms are identical and consumers can use either data model transparently.
48  *
49  * The file layout is structured as follows:
50  *
51  * +---------------+-------------------+----- ... ----+---- ... ------+
52  * |   fcf_hdr_t   |  fcf_sec_t[ ... ] |   section    |   section     |
53  * | (file header) | (section headers) |   #1 data    |   #N data     |
54  * +---------------+-------------------+----- ... ----+---- ... ------+
55  * |<------------ fcf_hdr.fcfh_filesz ------------------------------->|
56  *
57  * The file header stores meta-data including a magic number, data model for
58  * the checkpointed module, data encoding, and other miscellaneous properties.
59  * The header describes its own size and the size of the section headers.  By
60  * convention, an array of section headers follows the file header, and then
61  * the data for all the individual sections listed in the section header table.
62  *
63  * The section headers describe the size, offset, alignment, and section type
64  * for each section.  Sections are described using a set of #defines that tell
65  * the consumer what kind of data is expected.  Sections can contain links to
66  * other sections by storing a fcf_secidx_t, an index into the section header
67  * array, inside of the section data structures.  The section header includes
68  * an entry size so that sections with data arrays can grow their structures.
69  *
70  * Finally, strings are always stored in ELF-style string tables along with a
71  * string table section index and string table offset.  Therefore strings in
72  * FCF are always arbitrary-length and not bound to the current implementation.
73  */
74 
75 #define	FCF_ID_SIZE	16	/* total size of fcfh_ident[] in bytes */
76 
77 typedef struct fcf_hdr {
78 	uint8_t fcfh_ident[FCF_ID_SIZE]; /* identification bytes (see below) */
79 	uint32_t fcfh_flags;		/* file attribute flags (if any) */
80 	uint32_t fcfh_hdrsize;		/* size of file header in bytes */
81 	uint32_t fcfh_secsize;		/* size of section header in bytes */
82 	uint32_t fcfh_secnum;		/* number of section headers */
83 	uint64_t fcfh_secoff;		/* file offset of section headers */
84 	uint64_t fcfh_filesz;		/* file size of entire FCF file */
85 	uint64_t fcfh_cgen;		/* checkpoint generation number */
86 	uint64_t fcfh_pad;		/* reserved for future use */
87 } fcf_hdr_t;
88 
89 #define	FCF_ID_MAG0	0	/* first byte of magic number */
90 #define	FCF_ID_MAG1	1	/* second byte of magic number */
91 #define	FCF_ID_MAG2	2	/* third byte of magic number */
92 #define	FCF_ID_MAG3	3	/* fourth byte of magic number */
93 #define	FCF_ID_MODEL	4	/* FCF data model (see below) */
94 #define	FCF_ID_ENCODING	5	/* FCF data encoding (see below) */
95 #define	FCF_ID_VERSION	6	/* FCF file format major version (see below) */
96 #define	FCF_ID_PAD	7	/* start of padding bytes (all zeroes) */
97 
98 #define	FCF_MAG_MAG0	0x7F	/* FCF_ID_MAG[0-3] */
99 #define	FCF_MAG_MAG1	'F'
100 #define	FCF_MAG_MAG2	'C'
101 #define	FCF_MAG_MAG3	'F'
102 
103 #define	FCF_MAG_STRING	"\177FCF"
104 #define	FCF_MAG_STRLEN	4
105 
106 #define	FCF_MODEL_NONE	0	/* FCF_ID_MODEL */
107 #define	FCF_MODEL_ILP32	1
108 #define	FCF_MODEL_LP64	2
109 
110 #ifdef _LP64
111 #define	FCF_MODEL_NATIVE	FCF_MODEL_LP64
112 #else
113 #define	FCF_MODEL_NATIVE	FCF_MODEL_ILP32
114 #endif
115 
116 #define	FCF_ENCODE_NONE	0	/* FCF_ID_ENCODING */
117 #define	FCF_ENCODE_LSB	1
118 #define	FCF_ENCODE_MSB	2
119 
120 #ifdef _BIG_ENDIAN
121 #define	FCF_ENCODE_NATIVE	FCF_ENCODE_MSB
122 #else
123 #define	FCF_ENCODE_NATIVE	FCF_ENCODE_LSB
124 #endif
125 
126 #define	FCF_VERSION_1	1	/* FCF_ID_VERSION */
127 #define	FCF_VERSION	FCF_VERSION_1
128 
129 #define	FCF_FL_VALID	0	/* mask of all valid fcfh_flags bits */
130 
131 typedef uint32_t fcf_secidx_t;	/* section header table index type */
132 typedef uint32_t fcf_stridx_t;	/* string table index type */
133 
134 #define	FCF_SECIDX_NONE	0	/* null value for section indices */
135 #define	FCF_STRIDX_NONE	0	/* null value for string indices */
136 
137 typedef struct fcf_sec {
138 	uint32_t fcfs_type;	/* section type (see below) */
139 	uint32_t fcfs_align;	/* section data memory alignment */
140 	uint32_t fcfs_flags;	/* section flags (if any) */
141 	uint32_t fcfs_entsize;	/* size of section entry (if table) */
142 	uint64_t fcfs_offset;	/* offset of section data within file */
143 	uint64_t fcfs_size;	/* size of section data in bytes */
144 } fcf_sec_t;
145 
146 /*
147  * Section types (fcfs_type values).  These #defines should be kept in sync
148  * with the decoding table declared in fmd_mdb.c in the fcf_sec() dcmd, and
149  * with the size and alignment table declared at the top of fmd_ckpt.c.
150  */
151 #define	FCF_SECT_NONE		0	/* null section */
152 #define	FCF_SECT_STRTAB		1	/* string table */
153 #define	FCF_SECT_MODULE		2	/* module meta-data (fcf_mod_t) */
154 #define	FCF_SECT_CASE		3	/* case meta-data (fcf_case_t) */
155 #define	FCF_SECT_BUFS		4	/* buffer list (fcf_buf_t) */
156 #define	FCF_SECT_BUFFER		5	/* module data buffer */
157 #define	FCF_SECT_SERD		6	/* serd list (fcf_serd_t) */
158 #define	FCF_SECT_EVENTS		7	/* event list (fcf_event_t) */
159 #define	FCF_SECT_NVLISTS	8	/* nvlist list (fcf_nvl_t) */
160 
161 typedef struct fcf_module {
162 	fcf_stridx_t fcfm_name;	/* module basename */
163 	fcf_stridx_t fcfm_path;	/* module path */
164 	fcf_stridx_t fcfm_desc;	/* description */
165 	fcf_stridx_t fcfm_vers;	/* version */
166 	fcf_secidx_t fcfm_bufs; /* FCF_SECT_BUFS containing global buffers */
167 } fcf_module_t;
168 
169 typedef struct fcf_case {
170 	fcf_stridx_t fcfc_uuid;	/* case uuid */
171 	uint32_t fcfc_state;	/* case state (see below) */
172 	fcf_secidx_t fcfc_bufs;	/* FCF_SECT_BUFS containing buffers */
173 	fcf_secidx_t fcfc_principal; /* FCF_SECT_EVENTS containing principal */
174 	fcf_secidx_t fcfc_events; /* FCF_SECT_EVENTS containing events */
175 	fcf_secidx_t fcfc_suspects; /* FCF_SECT_NVLISTS containing suspects */
176 } fcf_case_t;
177 
178 #define	FCF_CASE_UNSOLVED	0
179 #define	FCF_CASE_SOLVED		1
180 #define	FCF_CASE_CLOSED		2
181 
182 typedef struct fcf_buf {
183 	fcf_stridx_t fcfb_name;	/* buffer name */
184 	fcf_secidx_t fcfb_data;	/* FCF_SECT_BUFFER containing data */
185 } fcf_buf_t;
186 
187 typedef struct fcf_serd {
188 	fcf_stridx_t fcfd_name;	/* engine name */
189 	fcf_secidx_t fcfd_events; /* FCF_SECT_EVENTS containing events */
190 	uint32_t fcfd_pad;	/* reserved for future use */
191 	uint32_t fcfd_n;	/* engine N parameter */
192 	uint64_t fcfd_t;	/* engine T parameter */
193 } fcf_serd_t;
194 
195 typedef struct fcf_event {
196 	uint64_t fcfe_todsec;	/* seconds since gettimeofday(3C) epoch */
197 	uint64_t fcfe_todnsec;	/* nanoseconds past value of fcfe_todsec */
198 	uint32_t fcfe_major;	/* major number from log file st_dev */
199 	uint32_t fcfe_minor;	/* minor number from log file st_rdev */
200 	uint64_t fcfe_inode;	/* inode number from log file st_ino */
201 	uint64_t fcfe_offset;	/* event offset within log file */
202 } fcf_event_t;
203 
204 typedef struct fcf_nvlist {
205 	uint64_t fcfn_size;	/* size of packed nvlist after this header */
206 } fcf_nvl_t;
207 
208 /*
209  * The checkpoint subsystem provides a very simple set of interfaces to the
210  * reset of fmd: namely, checkpoints can be saved, restored, or deleted by mod.
211  * In the reference implementation, these are implemented to use FCF files.
212  */
213 
214 struct fmd_module;		/* see <fmd_module.h> */
215 
216 extern void fmd_ckpt_save(struct fmd_module *);
217 extern void fmd_ckpt_restore(struct fmd_module *);
218 extern void fmd_ckpt_delete(struct fmd_module *);
219 extern void fmd_ckpt_rename(struct fmd_module *);
220 
221 #ifdef	__cplusplus
222 }
223 #endif
224 
225 #endif	/* _FMD_CKPT_H */
226