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