1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _RCM_SCRIPT_IMPL_H
28*7c478bd9Sstevel@tonic-gate #define	_RCM_SCRIPT_IMPL_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #define	TRUE	1
35*7c478bd9Sstevel@tonic-gate #define	FALSE	0
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate /* Minimum and maximum rcm scripting API version supported. */
38*7c478bd9Sstevel@tonic-gate #define	SCRIPT_API_MIN_VER		1
39*7c478bd9Sstevel@tonic-gate #define	SCRIPT_API_MAX_VER		1
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * Default maximum time (in seconds) allocated for an rcm command
43*7c478bd9Sstevel@tonic-gate  * before SIGABRT is sent.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate #define	SCRIPT_CMD_TIMEOUT		60
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  * Maximum time (in seconds) allocated after sending SIGABRT before
49*7c478bd9Sstevel@tonic-gate  * the script is killed.
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate #define	SCRIPT_ABORT_TIMEOUT		10
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * Maximum time (in seconds) for which the rcm daemon checks whether
55*7c478bd9Sstevel@tonic-gate  * a script is killed or not after the rcm daemon kills the script.
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate #define	SCRIPT_KILL_TIMEOUT		3
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /* Maximum number of command line parameters passed to a script */
60*7c478bd9Sstevel@tonic-gate #define	MAX_ARGS			16
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /* Maximum number of environment parameters passed to a script */
63*7c478bd9Sstevel@tonic-gate #define	MAX_ENV_PARAMS			64
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define	MAX_LINE_LEN			(4*1024)
66*7c478bd9Sstevel@tonic-gate #define	MAX_FLAGS_NAME_LEN		64
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /* exit codes */
69*7c478bd9Sstevel@tonic-gate typedef enum {
70*7c478bd9Sstevel@tonic-gate 	E_SUCCESS,
71*7c478bd9Sstevel@tonic-gate 	E_FAILURE,
72*7c478bd9Sstevel@tonic-gate 	E_UNSUPPORTED_CMD,
73*7c478bd9Sstevel@tonic-gate 	E_REFUSE
74*7c478bd9Sstevel@tonic-gate } script_exit_codes_t;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /* This structure is used to maintain a list of current dr'ed resources */
77*7c478bd9Sstevel@tonic-gate typedef struct {
78*7c478bd9Sstevel@tonic-gate 	rcm_queue_t queue;
79*7c478bd9Sstevel@tonic-gate 	char *resource_name;
80*7c478bd9Sstevel@tonic-gate } drreq_t;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * Main data structure for rcm scripting. There will be one instance of
84*7c478bd9Sstevel@tonic-gate  * this structure for every rcm script. A pointer to this structure is
85*7c478bd9Sstevel@tonic-gate  * kept in module structure.
86*7c478bd9Sstevel@tonic-gate  */
87*7c478bd9Sstevel@tonic-gate typedef struct script_info {
88*7c478bd9Sstevel@tonic-gate 	/*
89*7c478bd9Sstevel@tonic-gate 	 * Used to maintain a queue of script_info structures
90*7c478bd9Sstevel@tonic-gate 	 * Global variable script_info_q is the head of the queue.
91*7c478bd9Sstevel@tonic-gate 	 */
92*7c478bd9Sstevel@tonic-gate 	rcm_queue_t queue;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	rcm_queue_t drreq_q;	/* queue head for current dr'ed resources */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	module_t *module;
97*7c478bd9Sstevel@tonic-gate 	rcm_handle_t *hdl;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	char *script_full_name;	/* name of the script including path */
100*7c478bd9Sstevel@tonic-gate 	char *script_name;	/* name of the script without path component */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/*
103*7c478bd9Sstevel@tonic-gate 	 * file descriptors used to communicate with the script
104*7c478bd9Sstevel@tonic-gate 	 * pipe1 is used to capture script's stdout
105*7c478bd9Sstevel@tonic-gate 	 * pipe2 is used to capture script's stderr
106*7c478bd9Sstevel@tonic-gate 	 */
107*7c478bd9Sstevel@tonic-gate 	int pipe1[2];
108*7c478bd9Sstevel@tonic-gate 	int pipe2[2];
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	pid_t pid;		/* process id of the script process */
111*7c478bd9Sstevel@tonic-gate 	thread_t tid;		/* thread id of the stderr reader thread */
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	/*
114*7c478bd9Sstevel@tonic-gate 	 * Lock to protect the fileds in this structure and also to protect
115*7c478bd9Sstevel@tonic-gate 	 * the communication channel to the script.
116*7c478bd9Sstevel@tonic-gate 	 */
117*7c478bd9Sstevel@tonic-gate 	mutex_t channel_lock;
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	int ver;		/* scripting api version of the script */
120*7c478bd9Sstevel@tonic-gate 	int cmd;		/* current rcm scripting command */
121*7c478bd9Sstevel@tonic-gate 	int cmd_timeout;	/* timeout value in seconds */
122*7c478bd9Sstevel@tonic-gate 	int exit_status;	/* exit status of the script */
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	/* time stamp of the script when it was last run */
125*7c478bd9Sstevel@tonic-gate 	time_t lastrun;
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	char *func_info_buf;
128*7c478bd9Sstevel@tonic-gate 	char *func_info_buf_curptr;
129*7c478bd9Sstevel@tonic-gate 	int func_info_buf_len;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	char *resource_usage_info_buf;
132*7c478bd9Sstevel@tonic-gate 	char *resource_usage_info_buf_curptr;
133*7c478bd9Sstevel@tonic-gate 	int resource_usage_info_buf_len;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	char *failure_reason_buf;
136*7c478bd9Sstevel@tonic-gate 	char *failure_reason_buf_curptr;
137*7c478bd9Sstevel@tonic-gate 	int failure_reason_buf_len;
138*7c478bd9Sstevel@tonic-gate 	uint_t flags;
139*7c478bd9Sstevel@tonic-gate } script_info_t;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * script_info_t:flags
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate #define	STDERR_THREAD_CREATED	1
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate #define	PARENT_END_OF_PIPE	0
147*7c478bd9Sstevel@tonic-gate #define	CHILD_END_OF_PIPE	1
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #define	PS_STATE_FILE_VER	1
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate typedef struct state_element {
152*7c478bd9Sstevel@tonic-gate 	uint32_t flags;
153*7c478bd9Sstevel@tonic-gate 	uint32_t reserved;	/* for 64 bit alignment */
154*7c478bd9Sstevel@tonic-gate 	/* followed by actual state element */
155*7c478bd9Sstevel@tonic-gate } state_element_t;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate  * state_element_t:flags
159*7c478bd9Sstevel@tonic-gate  * The following flag when set indicates that the state element is
160*7c478bd9Sstevel@tonic-gate  * currently in use. When not set indicates that the state element is free.
161*7c478bd9Sstevel@tonic-gate  */
162*7c478bd9Sstevel@tonic-gate #define	STATE_ELEMENT_IN_USE	0x1
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate /*
165*7c478bd9Sstevel@tonic-gate  * This structure defines the layout of state file used by rcm scripting
166*7c478bd9Sstevel@tonic-gate  */
167*7c478bd9Sstevel@tonic-gate typedef struct state_file {
168*7c478bd9Sstevel@tonic-gate 	uint32_t version;
169*7c478bd9Sstevel@tonic-gate 	uint32_t max_elements;	/* number of state elements */
170*7c478bd9Sstevel@tonic-gate 	/* followed by an array of state elements of type state_element_t */
171*7c478bd9Sstevel@tonic-gate } state_file_t;
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate typedef struct state_file_descr {
174*7c478bd9Sstevel@tonic-gate 	uint32_t version;
175*7c478bd9Sstevel@tonic-gate 	int fd;			/* file descriptor to the state file */
176*7c478bd9Sstevel@tonic-gate 	size_t element_size;	/* size of one state element */
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	/*
179*7c478bd9Sstevel@tonic-gate 	 * number of state elements to allocate at a time when the state file
180*7c478bd9Sstevel@tonic-gate 	 * grows.
181*7c478bd9Sstevel@tonic-gate 	 */
182*7c478bd9Sstevel@tonic-gate 	int chunk_size;
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate 	/*
185*7c478bd9Sstevel@tonic-gate 	 * index into the state element array where the next search will
186*7c478bd9Sstevel@tonic-gate 	 * begin for an empty slot.
187*7c478bd9Sstevel@tonic-gate 	 */
188*7c478bd9Sstevel@tonic-gate 	int index;
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	/* pointer to mmapped state file */
191*7c478bd9Sstevel@tonic-gate 	state_file_t *state_file;
192*7c478bd9Sstevel@tonic-gate } state_file_descr_t;
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /* round up to n byte boundary. n must be power of 2 for this macro to work */
195*7c478bd9Sstevel@tonic-gate #define	RSCR_ROUNDUP(x, n)	(((x) + ((n) - 1)) & (~((n) - 1)))
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate typedef struct ps_state_element {
198*7c478bd9Sstevel@tonic-gate 	pid_t pid;
199*7c478bd9Sstevel@tonic-gate 	char script_name[MAXNAMELEN];
200*7c478bd9Sstevel@tonic-gate } ps_state_element_t;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate /* maximum number of additional env variables for capacity specific stuff */
203*7c478bd9Sstevel@tonic-gate #define	MAX_CAPACITY_PARAMS	10
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate typedef struct capacity_descr {
206*7c478bd9Sstevel@tonic-gate 	char *resource_name;
207*7c478bd9Sstevel@tonic-gate 	int match_type;
208*7c478bd9Sstevel@tonic-gate 	struct {
209*7c478bd9Sstevel@tonic-gate 		char *nvname;
210*7c478bd9Sstevel@tonic-gate 		char *envname;
211*7c478bd9Sstevel@tonic-gate 	} param[MAX_CAPACITY_PARAMS];
212*7c478bd9Sstevel@tonic-gate } capacity_descr_t;
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate /* capacity_descr_t:match_type */
215*7c478bd9Sstevel@tonic-gate #define	MATCH_INVALID		0
216*7c478bd9Sstevel@tonic-gate #define	MATCH_EXACT		1
217*7c478bd9Sstevel@tonic-gate #define	MATCH_PREFIX		2
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate #endif
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate #endif /* _RCM_SCRIPT_IMPL_H */
224