xref: /illumos-gate/usr/src/cmd/fm/fminject/common/inj.h (revision 7aec1d6e)
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  */
227c478bd9Sstevel@tonic-gate /*
23*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate #ifndef _INJ_H
287c478bd9Sstevel@tonic-gate #define	_INJ_H
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * FMA Error injector
347c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate #include <stdio.h>
377c478bd9Sstevel@tonic-gate #include <libnvpair.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <inj_list.h>
417c478bd9Sstevel@tonic-gate #include <inj_hash.h>
437c478bd9Sstevel@tonic-gate #include <fm/fmd_log.h>
457c478bd9Sstevel@tonic-gate #ifdef __cplusplus
467c478bd9Sstevel@tonic-gate extern "C" {
477c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate /*
50*7aec1d6eScindi  * The injector allows for the declaration, definition, and injection of four
51*7aec1d6eScindi  * types of things - Events, FMRIs, Authorities, and lists.  The first three
52*7aec1d6eScindi  * are essentially lists with extra membership requirements (FMRIs, for
53*7aec1d6eScindi  * example, must include a member called `scheme').  So while each has a
54*7aec1d6eScindi  * different function within the FMA framework, we can use a single struct to
55*7aec1d6eScindi  * store all three.  The inj_itemtype_t enum is used to describe which of the
56*7aec1d6eScindi  * four types is being represented by a given object.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate typedef enum inj_itemtype {
597c478bd9Sstevel@tonic-gate 	ITEMTYPE_EVENT,
607c478bd9Sstevel@tonic-gate 	ITEMTYPE_FMRI,
61*7aec1d6eScindi 	ITEMTYPE_AUTH,
62*7aec1d6eScindi 	ITEMTYPE_LIST
637c478bd9Sstevel@tonic-gate } inj_itemtype_t;
65*7aec1d6eScindi #define	ITEMTYPE_NITEMS		4
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * The member name-value pairs of Events, FMRIs, and Authorities are typed.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate typedef enum inj_memtype {
717c478bd9Sstevel@tonic-gate 	MEMTYPE_UNKNOWN,
727c478bd9Sstevel@tonic-gate 	MEMTYPE_INT8,
737c478bd9Sstevel@tonic-gate 	MEMTYPE_INT16,
747c478bd9Sstevel@tonic-gate 	MEMTYPE_INT32,
757c478bd9Sstevel@tonic-gate 	MEMTYPE_INT64,
767c478bd9Sstevel@tonic-gate 	MEMTYPE_UINT8,
777c478bd9Sstevel@tonic-gate 	MEMTYPE_UINT16,
787c478bd9Sstevel@tonic-gate 	MEMTYPE_UINT32,
797c478bd9Sstevel@tonic-gate 	MEMTYPE_UINT64,
807c478bd9Sstevel@tonic-gate 	MEMTYPE_BOOL,
817c478bd9Sstevel@tonic-gate 	MEMTYPE_STRING,
827c478bd9Sstevel@tonic-gate 	MEMTYPE_ENUM,
837c478bd9Sstevel@tonic-gate 	MEMTYPE_EVENT,
847c478bd9Sstevel@tonic-gate 	MEMTYPE_FMRI,
85*7aec1d6eScindi 	MEMTYPE_AUTH,
86*7aec1d6eScindi 	MEMTYPE_LIST
877c478bd9Sstevel@tonic-gate } inj_memtype_t;
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Declarations
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * Each declared item, be it an event, an fmri, or an authority, consists of
937c478bd9Sstevel@tonic-gate  * an inj_decl_t and a string of inj_declmem_t's, one of the latter for each
947c478bd9Sstevel@tonic-gate  * declared member.
957c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	DECL_F_AUTOENA	0x1	/* ENA member to be auto-generated for event */
997c478bd9Sstevel@tonic-gate typedef struct inj_decl {
1007c478bd9Sstevel@tonic-gate 	inj_list_t decl_members;	/* List of declared members */
1017c478bd9Sstevel@tonic-gate 	inj_hash_t decl_memhash;	/* Hash of said members */
1037c478bd9Sstevel@tonic-gate 	const char *decl_name;		/* Name of declared item */
1047c478bd9Sstevel@tonic-gate 	inj_itemtype_t decl_type;	/* Type of declared item */
1067c478bd9Sstevel@tonic-gate 	uint_t decl_lineno;		/* Line # of first member declared */
1077c478bd9Sstevel@tonic-gate 	uint_t decl_flags;		/* DECL_F_* */
1087c478bd9Sstevel@tonic-gate } inj_decl_t;
1107c478bd9Sstevel@tonic-gate #define	DECLMEM_F_ARRAY	0x1	/* This member is an array of the given type */
1127c478bd9Sstevel@tonic-gate typedef struct inj_declmem {
1137c478bd9Sstevel@tonic-gate 	inj_list_t dlm_memlist;		/* List of declared members */
1157c478bd9Sstevel@tonic-gate 	const char *dlm_name;		/* Name of this member */
1167c478bd9Sstevel@tonic-gate 	inj_memtype_t dlm_type;		/* Type of this member */
1187c478bd9Sstevel@tonic-gate 	uint_t dlm_flags;		/* DECLMEM_F_* */
1197c478bd9Sstevel@tonic-gate 	uint_t dlm_arrdim;		/* If arr flag set, dim of array */
1217c478bd9Sstevel@tonic-gate 	union {
1227c478bd9Sstevel@tonic-gate 		inj_hash_t *_dlm_enumvals; /* If enum, hash of poss. values */
1237c478bd9Sstevel@tonic-gate 		inj_decl_t *_dlm_decl;	/* If evt, etc., ptr to decl for same */
1247c478bd9Sstevel@tonic-gate 	} _dlm_u;
1257c478bd9Sstevel@tonic-gate } inj_declmem_t;
1277c478bd9Sstevel@tonic-gate #define	dlm_enumvals	_dlm_u._dlm_enumvals
1287c478bd9Sstevel@tonic-gate #define	dlm_decl	_dlm_u._dlm_decl
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * Definitions
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  * Each defined item consists of an inj_defn_t and a string of inj_defnmem_t's,
1347c478bd9Sstevel@tonic-gate  * one of the latter for each defined member.  The inj_defn_t also contains a
1357c478bd9Sstevel@tonic-gate  * pointer to the corresponding declaration, thus allowing for correctness
1367c478bd9Sstevel@tonic-gate  * checking.
1377c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate typedef struct inj_defn {
1407c478bd9Sstevel@tonic-gate 	inj_list_t defn_members;	/* List of defined members */
1417c478bd9Sstevel@tonic-gate 	const char *defn_name;		/* Name of this definition */
1427c478bd9Sstevel@tonic-gate 	inj_decl_t *defn_decl;		/* Ptr to decl this defn instantiates */
1437c478bd9Sstevel@tonic-gate 	uint_t defn_lineno;		/* Line # of first member defined */
1457c478bd9Sstevel@tonic-gate 	nvlist_t *defn_nvl;		/* Built from validated members */
1467c478bd9Sstevel@tonic-gate } inj_defn_t;
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Embodiment of the information that we know about a given defined member at
1507c478bd9Sstevel@tonic-gate  * the time of definition.  These values are assigned before the individual
1517c478bd9Sstevel@tonic-gate  * definition members are paired with their corresponding declarations, so we
1527c478bd9Sstevel@tonic-gate  * don't know whether a given IDENT is, for example, an enum or an fmri
1537c478bd9Sstevel@tonic-gate  * reference.  Without these values, we wouldn't be able to distinguish between
1547c478bd9Sstevel@tonic-gate  * a quoted string and an identifier, for example, and thus would have a harder
1557c478bd9Sstevel@tonic-gate  * time with syntactic validation.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate typedef enum inj_defnmemtype {
1587c478bd9Sstevel@tonic-gate 	DEFNMEM_IMM,
1597c478bd9Sstevel@tonic-gate 	DEFNMEM_IDENT,
1607c478bd9Sstevel@tonic-gate 	DEFNMEM_QSTRING,
1617c478bd9Sstevel@tonic-gate 	DEFNMEM_EVENT,
1627c478bd9Sstevel@tonic-gate 	DEFNMEM_FMRI,
1637c478bd9Sstevel@tonic-gate 	DEFNMEM_AUTH,
1647c478bd9Sstevel@tonic-gate 	DEFNMEM_ARRAY,
165*7aec1d6eScindi 	DEFNMEM_LIST
1667c478bd9Sstevel@tonic-gate } inj_defnmemtype_t;
1687c478bd9Sstevel@tonic-gate typedef struct inj_defnmem {
1697c478bd9Sstevel@tonic-gate 	inj_list_t dfm_memlist;		/* List of defined members */
1717c478bd9Sstevel@tonic-gate 	inj_defnmemtype_t dfm_type;	/* Type of this member, from parser */
1727c478bd9Sstevel@tonic-gate 	uint_t dfm_lineno;		/* Last line of this member's defn */
1747c478bd9Sstevel@tonic-gate 	union {
1757c478bd9Sstevel@tonic-gate 		const char *_dfm_str;	/* String value of member */
176*7aec1d6eScindi 		inj_list_t _dfm_list;	/* Enum, evt, auth, arr, list vals */
1777c478bd9Sstevel@tonic-gate 	} _dfm_u;
1787c478bd9Sstevel@tonic-gate } inj_defnmem_t;
1807c478bd9Sstevel@tonic-gate #define	dfm_str		_dfm_u._dfm_str
1817c478bd9Sstevel@tonic-gate #define	dfm_list	_dfm_u._dfm_list
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * Operations performed by the injector (aside from declarations and
1857c478bd9Sstevel@tonic-gate  * definitions)
1867c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate /* events and priorities list for the randomize command */
1897c478bd9Sstevel@tonic-gate typedef struct inj_randelem {
1907c478bd9Sstevel@tonic-gate 	struct inj_randelem *re_next;
1917c478bd9Sstevel@tonic-gate 	inj_defn_t *re_event;
1927c478bd9Sstevel@tonic-gate 	uint_t re_prob;
1937c478bd9Sstevel@tonic-gate } inj_randelem_t;
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Operations themselves are structured as a tree of inj_cmd_t's.  Each one has
1977c478bd9Sstevel@tonic-gate  * a command type and type-specific command data.  The "program" is run via
1987c478bd9Sstevel@tonic-gate  * iteration through the tree, with the injector performing the operation
1997c478bd9Sstevel@tonic-gate  * requested by a given node.
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate typedef enum inj_cmd_type {
2027c478bd9Sstevel@tonic-gate 	CMD_SEND_EVENT,
2037c478bd9Sstevel@tonic-gate 	CMD_SLEEP,
2047c478bd9Sstevel@tonic-gate 	CMD_REPEAT,
2057c478bd9Sstevel@tonic-gate 	CMD_RANDOM
2067c478bd9Sstevel@tonic-gate } inj_cmd_type_t;
2087c478bd9Sstevel@tonic-gate typedef struct inj_cmd {
2097c478bd9Sstevel@tonic-gate 	inj_list_t cmd_list;		/* List of commands */
2107c478bd9Sstevel@tonic-gate 	inj_cmd_type_t cmd_type;	/* Type of this command */
2127c478bd9Sstevel@tonic-gate 	union {
2137c478bd9Sstevel@tonic-gate 		inj_defn_t *_cmd_event;	/* If send_event, evt to send */
2147c478bd9Sstevel@tonic-gate 		inj_randelem_t **_cmd_rand;	/* List of evts & probs */
2157c478bd9Sstevel@tonic-gate 		struct inj_cmd *_cmd_subcmd;	/* If repeat, cmd to be rpt'd */
2167c478bd9Sstevel@tonic-gate 	} _cmd_u;
2177c478bd9Sstevel@tonic-gate 	uint_t		cmd_num;	/* If repeat, repeat count */
2187c478bd9Sstevel@tonic-gate } inj_cmd_t;
2207c478bd9Sstevel@tonic-gate #define	cmd_event	_cmd_u._cmd_event
2217c478bd9Sstevel@tonic-gate #define	cmd_rand	_cmd_u._cmd_rand
2227c478bd9Sstevel@tonic-gate #define	cmd_subcmd	_cmd_u._cmd_subcmd
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * We support retargetable event-delivery mechanisms.  Each method implements
2267c478bd9Sstevel@tonic-gate  * a copy of the following ops vector, thus allowing us to switch mechanisms
2277c478bd9Sstevel@tonic-gate  * simply by switching the structure.
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate typedef struct inj_mode_ops {
2307c478bd9Sstevel@tonic-gate 	void *(*mo_open)(const char *);		/* Init mechanism */
2317c478bd9Sstevel@tonic-gate 	void (*mo_send)(void *, nvlist_t *);	/* Send a single nvlist */
2327c478bd9Sstevel@tonic-gate 	void (*mo_close)(void *);		/* Shut down mechanism */
2337c478bd9Sstevel@tonic-gate } inj_mode_ops_t;
2357c478bd9Sstevel@tonic-gate extern int verbose;
2367c478bd9Sstevel@tonic-gate extern int quiet;
2387c478bd9Sstevel@tonic-gate extern inj_list_t *inj_logfile_read(fmd_log_t *);
2397c478bd9Sstevel@tonic-gate extern inj_list_t *inj_program_read(const char *);
2407c478bd9Sstevel@tonic-gate extern void inj_program_run(inj_list_t *, const inj_mode_ops_t *, void *);
2427c478bd9Sstevel@tonic-gate extern void *inj_alloc(size_t);
2437c478bd9Sstevel@tonic-gate extern void *inj_zalloc(size_t);
2447c478bd9Sstevel@tonic-gate extern void inj_free(void *, size_t);
2467c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate #endif
2507c478bd9Sstevel@tonic-gate #endif /* _INJ_H */