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