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
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <libnvpair.h>
38 #include <sys/types.h>
43 #include <fm/fmd_log.h>
50 * The injector allows for the declaration, definition, and injection of four
51 * types of things - Events, FMRIs, Authorities, and lists. The first three
52 * are essentially lists with extra membership requirements (FMRIs, for
53 * example, must include a member called `scheme'). So while each has a
54 * different function within the FMA framework, we can use a single struct to
55 * store all three. The inj_itemtype_t enum is used to describe which of the
56 * four types is being represented by a given object.
58 typedef enum inj_itemtype
{
65 #define ITEMTYPE_NITEMS 4
68 * The member name-value pairs of Events, FMRIs, and Authorities are typed.
70 typedef enum inj_memtype
{
92 * Each declared item, be it an event, an fmri, or an authority, consists of
93 * an inj_decl_t and a string of inj_declmem_t's, one of the latter for each
97 #define DECL_F_AUTOENA 0x1 /* ENA member to be auto-generated for event */
99 typedef struct inj_decl
{
100 inj_list_t decl_members
; /* List of declared members */
101 inj_hash_t decl_memhash
; /* Hash of said members */
103 const char *decl_name
; /* Name of declared item */
104 inj_itemtype_t decl_type
; /* Type of declared item */
106 uint_t decl_lineno
; /* Line # of first member declared */
107 uint_t decl_flags
; /* DECL_F_* */
110 #define DECLMEM_F_ARRAY 0x1 /* This member is an array of the given type */
112 typedef struct inj_declmem
{
113 inj_list_t dlm_memlist
; /* List of declared members */
115 const char *dlm_name
; /* Name of this member */
116 inj_memtype_t dlm_type
; /* Type of this member */
118 uint_t dlm_flags
; /* DECLMEM_F_* */
119 uint_t dlm_arrdim
; /* If arr flag set, dim of array */
122 inj_hash_t
*_dlm_enumvals
; /* If enum, hash of poss. values */
123 inj_decl_t
*_dlm_decl
; /* If evt, etc., ptr to decl for same */
127 #define dlm_enumvals _dlm_u._dlm_enumvals
128 #define dlm_decl _dlm_u._dlm_decl
133 * Each defined item consists of an inj_defn_t and a string of inj_defnmem_t's,
134 * one of the latter for each defined member. The inj_defn_t also contains a
135 * pointer to the corresponding declaration, thus allowing for correctness
139 typedef struct inj_defn
{
140 inj_list_t defn_members
; /* List of defined members */
141 const char *defn_name
; /* Name of this definition */
142 inj_decl_t
*defn_decl
; /* Ptr to decl this defn instantiates */
143 uint_t defn_lineno
; /* Line # of first member defined */
145 nvlist_t
*defn_nvl
; /* Built from validated members */
149 * Embodiment of the information that we know about a given defined member at
150 * the time of definition. These values are assigned before the individual
151 * definition members are paired with their corresponding declarations, so we
152 * don't know whether a given IDENT is, for example, an enum or an fmri
153 * reference. Without these values, we wouldn't be able to distinguish between
154 * a quoted string and an identifier, for example, and thus would have a harder
155 * time with syntactic validation.
157 typedef enum inj_defnmemtype
{
168 typedef struct inj_defnmem
{
169 inj_list_t dfm_memlist
; /* List of defined members */
171 inj_defnmemtype_t dfm_type
; /* Type of this member, from parser */
172 uint_t dfm_lineno
; /* Last line of this member's defn */
175 const char *_dfm_str
; /* String value of member */
176 inj_list_t _dfm_list
; /* Enum, evt, auth, arr, list vals */
180 #define dfm_str _dfm_u._dfm_str
181 #define dfm_list _dfm_u._dfm_list
184 * Operations performed by the injector (aside from declarations and
188 /* events and priorities list for the randomize command */
189 typedef struct inj_randelem
{
190 struct inj_randelem
*re_next
;
191 inj_defn_t
*re_event
;
196 * Operations themselves are structured as a tree of inj_cmd_t's. Each one has
197 * a command type and type-specific command data. The "program" is run via
198 * iteration through the tree, with the injector performing the operation
199 * requested by a given node.
201 typedef enum inj_cmd_type
{
208 typedef struct inj_cmd
{
209 inj_list_t cmd_list
; /* List of commands */
210 inj_cmd_type_t cmd_type
; /* Type of this command */
213 inj_defn_t
*_cmd_event
; /* If send_event, evt to send */
214 inj_randelem_t
**_cmd_rand
; /* List of evts & probs */
215 struct inj_cmd
*_cmd_subcmd
; /* If repeat, cmd to be rpt'd */
217 uint_t cmd_num
; /* If repeat, repeat count */
220 #define cmd_event _cmd_u._cmd_event
221 #define cmd_rand _cmd_u._cmd_rand
222 #define cmd_subcmd _cmd_u._cmd_subcmd
225 * We support retargetable event-delivery mechanisms. Each method implements
226 * a copy of the following ops vector, thus allowing us to switch mechanisms
227 * simply by switching the structure.
229 typedef struct inj_mode_ops
{
230 void *(*mo_open
)(const char *); /* Init mechanism */
231 void (*mo_send
)(void *, nvlist_t
*); /* Send a single nvlist */
232 void (*mo_close
)(void *); /* Shut down mechanism */
238 extern inj_list_t
*inj_logfile_read(fmd_log_t
*);
239 extern inj_list_t
*inj_program_read(const char *);
240 extern void inj_program_run(inj_list_t
*, const inj_mode_ops_t
*, void *);
242 extern void *inj_alloc(size_t);
243 extern void *inj_zalloc(size_t);
244 extern void inj_free(void *, size_t);