xref: /titanic_44/usr/src/cmd/fm/fmd/common/fmd_ckpt.h (revision d9638e547d8811f2c689977f8dd2a353938b61fd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*d9638e54Smws 
237c478bd9Sstevel@tonic-gate /*
24*d9638e54Smws  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_FMD_CKPT_H
297c478bd9Sstevel@tonic-gate #define	_FMD_CKPT_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Fault Manager Checkpoint Format (FCF)
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * Fault manager modules can checkpoint state in the FCF format so that they
437c478bd9Sstevel@tonic-gate  * can survive restarts, module failures, and reboots.  The FCF format is
447c478bd9Sstevel@tonic-gate  * versioned and extensible so that it can be revised and so that internal data
457c478bd9Sstevel@tonic-gate  * structures can be modified or extended compatibly.  It is also specified as
467c478bd9Sstevel@tonic-gate  * a Project Private interface so that incompatible changes can occur as we see
477c478bd9Sstevel@tonic-gate  * fit.  All FCF structures use fixed-size types so that the 32-bit and 64-bit
487c478bd9Sstevel@tonic-gate  * forms are identical and consumers can use either data model transparently.
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  * The file layout is structured as follows:
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * +---------------+-------------------+----- ... ----+---- ... ------+
537c478bd9Sstevel@tonic-gate  * |   fcf_hdr_t   |  fcf_sec_t[ ... ] |   section    |   section     |
547c478bd9Sstevel@tonic-gate  * | (file header) | (section headers) |   #1 data    |   #N data     |
557c478bd9Sstevel@tonic-gate  * +---------------+-------------------+----- ... ----+---- ... ------+
567c478bd9Sstevel@tonic-gate  * |<------------ fcf_hdr.fcfh_filesz ------------------------------->|
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * The file header stores meta-data including a magic number, data model for
597c478bd9Sstevel@tonic-gate  * the checkpointed module, data encoding, and other miscellaneous properties.
607c478bd9Sstevel@tonic-gate  * The header describes its own size and the size of the section headers.  By
617c478bd9Sstevel@tonic-gate  * convention, an array of section headers follows the file header, and then
627c478bd9Sstevel@tonic-gate  * the data for all the individual sections listed in the section header table.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * The section headers describe the size, offset, alignment, and section type
657c478bd9Sstevel@tonic-gate  * for each section.  Sections are described using a set of #defines that tell
667c478bd9Sstevel@tonic-gate  * the consumer what kind of data is expected.  Sections can contain links to
677c478bd9Sstevel@tonic-gate  * other sections by storing a fcf_secidx_t, an index into the section header
687c478bd9Sstevel@tonic-gate  * array, inside of the section data structures.  The section header includes
697c478bd9Sstevel@tonic-gate  * an entry size so that sections with data arrays can grow their structures.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  * Finally, strings are always stored in ELF-style string tables along with a
727c478bd9Sstevel@tonic-gate  * string table section index and string table offset.  Therefore strings in
737c478bd9Sstevel@tonic-gate  * FCF are always arbitrary-length and not bound to the current implementation.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	FCF_ID_SIZE	16	/* total size of fcfh_ident[] in bytes */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate typedef struct fcf_hdr {
797c478bd9Sstevel@tonic-gate 	uint8_t fcfh_ident[FCF_ID_SIZE]; /* identification bytes (see below) */
807c478bd9Sstevel@tonic-gate 	uint32_t fcfh_flags;		/* file attribute flags (if any) */
817c478bd9Sstevel@tonic-gate 	uint32_t fcfh_hdrsize;		/* size of file header in bytes */
827c478bd9Sstevel@tonic-gate 	uint32_t fcfh_secsize;		/* size of section header in bytes */
837c478bd9Sstevel@tonic-gate 	uint32_t fcfh_secnum;		/* number of section headers */
847c478bd9Sstevel@tonic-gate 	uint64_t fcfh_secoff;		/* file offset of section headers */
857c478bd9Sstevel@tonic-gate 	uint64_t fcfh_filesz;		/* file size of entire FCF file */
867c478bd9Sstevel@tonic-gate 	uint64_t fcfh_cgen;		/* checkpoint generation number */
877c478bd9Sstevel@tonic-gate 	uint64_t fcfh_pad;		/* reserved for future use */
887c478bd9Sstevel@tonic-gate } fcf_hdr_t;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	FCF_ID_MAG0	0	/* first byte of magic number */
917c478bd9Sstevel@tonic-gate #define	FCF_ID_MAG1	1	/* second byte of magic number */
927c478bd9Sstevel@tonic-gate #define	FCF_ID_MAG2	2	/* third byte of magic number */
937c478bd9Sstevel@tonic-gate #define	FCF_ID_MAG3	3	/* fourth byte of magic number */
947c478bd9Sstevel@tonic-gate #define	FCF_ID_MODEL	4	/* FCF data model (see below) */
957c478bd9Sstevel@tonic-gate #define	FCF_ID_ENCODING	5	/* FCF data encoding (see below) */
967c478bd9Sstevel@tonic-gate #define	FCF_ID_VERSION	6	/* FCF file format major version (see below) */
977c478bd9Sstevel@tonic-gate #define	FCF_ID_PAD	7	/* start of padding bytes (all zeroes) */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	FCF_MAG_MAG0	0x7F	/* FCF_ID_MAG[0-3] */
1007c478bd9Sstevel@tonic-gate #define	FCF_MAG_MAG1	'F'
1017c478bd9Sstevel@tonic-gate #define	FCF_MAG_MAG2	'C'
1027c478bd9Sstevel@tonic-gate #define	FCF_MAG_MAG3	'F'
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	FCF_MAG_STRING	"\177FCF"
1057c478bd9Sstevel@tonic-gate #define	FCF_MAG_STRLEN	4
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	FCF_MODEL_NONE	0	/* FCF_ID_MODEL */
1087c478bd9Sstevel@tonic-gate #define	FCF_MODEL_ILP32	1
1097c478bd9Sstevel@tonic-gate #define	FCF_MODEL_LP64	2
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #ifdef _LP64
1127c478bd9Sstevel@tonic-gate #define	FCF_MODEL_NATIVE	FCF_MODEL_LP64
1137c478bd9Sstevel@tonic-gate #else
1147c478bd9Sstevel@tonic-gate #define	FCF_MODEL_NATIVE	FCF_MODEL_ILP32
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	FCF_ENCODE_NONE	0	/* FCF_ID_ENCODING */
1187c478bd9Sstevel@tonic-gate #define	FCF_ENCODE_LSB	1
1197c478bd9Sstevel@tonic-gate #define	FCF_ENCODE_MSB	2
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
1227c478bd9Sstevel@tonic-gate #define	FCF_ENCODE_NATIVE	FCF_ENCODE_MSB
1237c478bd9Sstevel@tonic-gate #else
1247c478bd9Sstevel@tonic-gate #define	FCF_ENCODE_NATIVE	FCF_ENCODE_LSB
1257c478bd9Sstevel@tonic-gate #endif
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	FCF_VERSION_1	1	/* FCF_ID_VERSION */
1287c478bd9Sstevel@tonic-gate #define	FCF_VERSION	FCF_VERSION_1
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	FCF_FL_VALID	0	/* mask of all valid fcfh_flags bits */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate typedef uint32_t fcf_secidx_t;	/* section header table index type */
1337c478bd9Sstevel@tonic-gate typedef uint32_t fcf_stridx_t;	/* string table index type */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	FCF_SECIDX_NONE	0	/* null value for section indices */
1367c478bd9Sstevel@tonic-gate #define	FCF_STRIDX_NONE	0	/* null value for string indices */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate typedef struct fcf_sec {
1397c478bd9Sstevel@tonic-gate 	uint32_t fcfs_type;	/* section type (see below) */
1407c478bd9Sstevel@tonic-gate 	uint32_t fcfs_align;	/* section data memory alignment */
1417c478bd9Sstevel@tonic-gate 	uint32_t fcfs_flags;	/* section flags (if any) */
1427c478bd9Sstevel@tonic-gate 	uint32_t fcfs_entsize;	/* size of section entry (if table) */
1437c478bd9Sstevel@tonic-gate 	uint64_t fcfs_offset;	/* offset of section data within file */
1447c478bd9Sstevel@tonic-gate 	uint64_t fcfs_size;	/* size of section data in bytes */
1457c478bd9Sstevel@tonic-gate } fcf_sec_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * Section types (fcfs_type values).  These #defines should be kept in sync
1497c478bd9Sstevel@tonic-gate  * with the decoding table declared in fmd_mdb.c in the fcf_sec() dcmd, and
1507c478bd9Sstevel@tonic-gate  * with the size and alignment table declared at the top of fmd_ckpt.c.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate #define	FCF_SECT_NONE		0	/* null section */
1537c478bd9Sstevel@tonic-gate #define	FCF_SECT_STRTAB		1	/* string table */
1547c478bd9Sstevel@tonic-gate #define	FCF_SECT_MODULE		2	/* module meta-data (fcf_mod_t) */
1557c478bd9Sstevel@tonic-gate #define	FCF_SECT_CASE		3	/* case meta-data (fcf_case_t) */
1567c478bd9Sstevel@tonic-gate #define	FCF_SECT_BUFS		4	/* buffer list (fcf_buf_t) */
1577c478bd9Sstevel@tonic-gate #define	FCF_SECT_BUFFER		5	/* module data buffer */
1587c478bd9Sstevel@tonic-gate #define	FCF_SECT_SERD		6	/* serd list (fcf_serd_t) */
1597c478bd9Sstevel@tonic-gate #define	FCF_SECT_EVENTS		7	/* event list (fcf_event_t) */
1607c478bd9Sstevel@tonic-gate #define	FCF_SECT_NVLISTS	8	/* nvlist list (fcf_nvl_t) */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate typedef struct fcf_module {
1637c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfm_name;	/* module basename */
1647c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfm_path;	/* module path */
1657c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfm_desc;	/* description */
1667c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfm_vers;	/* version */
1677c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfm_bufs; /* FCF_SECT_BUFS containing global buffers */
1687c478bd9Sstevel@tonic-gate } fcf_module_t;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate typedef struct fcf_case {
1717c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfc_uuid;	/* case uuid */
1727c478bd9Sstevel@tonic-gate 	uint32_t fcfc_state;	/* case state (see below) */
1737c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfc_bufs;	/* FCF_SECT_BUFS containing buffers */
1747c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfc_principal; /* FCF_SECT_EVENTS containing principal */
1757c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfc_events; /* FCF_SECT_EVENTS containing events */
1767c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfc_suspects; /* FCF_SECT_NVLISTS containing suspects */
1777c478bd9Sstevel@tonic-gate } fcf_case_t;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #define	FCF_CASE_UNSOLVED	0
1807c478bd9Sstevel@tonic-gate #define	FCF_CASE_SOLVED		1
181*d9638e54Smws #define	FCF_CASE_CLOSE_WAIT	2
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate typedef struct fcf_buf {
1847c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfb_name;	/* buffer name */
1857c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfb_data;	/* FCF_SECT_BUFFER containing data */
1867c478bd9Sstevel@tonic-gate } fcf_buf_t;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate typedef struct fcf_serd {
1897c478bd9Sstevel@tonic-gate 	fcf_stridx_t fcfd_name;	/* engine name */
1907c478bd9Sstevel@tonic-gate 	fcf_secidx_t fcfd_events; /* FCF_SECT_EVENTS containing events */
1917c478bd9Sstevel@tonic-gate 	uint32_t fcfd_pad;	/* reserved for future use */
1927c478bd9Sstevel@tonic-gate 	uint32_t fcfd_n;	/* engine N parameter */
1937c478bd9Sstevel@tonic-gate 	uint64_t fcfd_t;	/* engine T parameter */
1947c478bd9Sstevel@tonic-gate } fcf_serd_t;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate typedef struct fcf_event {
1977c478bd9Sstevel@tonic-gate 	uint64_t fcfe_todsec;	/* seconds since gettimeofday(3C) epoch */
1987c478bd9Sstevel@tonic-gate 	uint64_t fcfe_todnsec;	/* nanoseconds past value of fcfe_todsec */
1997c478bd9Sstevel@tonic-gate 	uint32_t fcfe_major;	/* major number from log file st_dev */
2007c478bd9Sstevel@tonic-gate 	uint32_t fcfe_minor;	/* minor number from log file st_rdev */
2017c478bd9Sstevel@tonic-gate 	uint64_t fcfe_inode;	/* inode number from log file st_ino */
2027c478bd9Sstevel@tonic-gate 	uint64_t fcfe_offset;	/* event offset within log file */
2037c478bd9Sstevel@tonic-gate } fcf_event_t;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate typedef struct fcf_nvlist {
2067c478bd9Sstevel@tonic-gate 	uint64_t fcfn_size;	/* size of packed nvlist after this header */
2077c478bd9Sstevel@tonic-gate } fcf_nvl_t;
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * The checkpoint subsystem provides a very simple set of interfaces to the
2117c478bd9Sstevel@tonic-gate  * reset of fmd: namely, checkpoints can be saved, restored, or deleted by mod.
2127c478bd9Sstevel@tonic-gate  * In the reference implementation, these are implemented to use FCF files.
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate struct fmd_module;		/* see <fmd_module.h> */
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate extern void fmd_ckpt_save(struct fmd_module *);
2187c478bd9Sstevel@tonic-gate extern void fmd_ckpt_restore(struct fmd_module *);
2197c478bd9Sstevel@tonic-gate extern void fmd_ckpt_delete(struct fmd_module *);
2207c478bd9Sstevel@tonic-gate extern void fmd_ckpt_rename(struct fmd_module *);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate #endif
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #endif	/* _FMD_CKPT_H */
227