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