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