Mercurial > illumos > illumos-gate
annotate usr/src/cmd/svc/startd/startd.h @ 12979:ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
PSARC/2009/618 snmp-notify: SNMP Notification Daemon for Software Events
PSARC/2009/619 smtp-notify: Email Notification Daemon for Software Events
PSARC/2010/225 fmd for non-global Solaris zones
PSARC/2010/226 Solaris Instance UUID
PSARC/2010/227 nvlist_nvflag(3NVPAIR)
PSARC/2010/228 libfmevent additions
PSARC/2010/257 sysevent_evc_setpropnvl and sysevent_evc_getpropnvl
PSARC/2010/265 FMRI and FMA Event Stabilty, 'ireport' category 1 event class, and the 'sw' FMRI scheme
PSARC/2010/278 FMA/SMF integration: instance state transitions
PSARC/2010/279 Modelling panics within FMA
PSARC/2010/290 logadm.conf upgrade
6392476 fmdump needs to pretty-print
6393375 userland ereport/ireport event generation interfaces
6445732 Add email notification agent for FMA and software events
6804168 RFE: Allow an efficient means to monitor SMF services status changes
6866661 scf_values_destroy(3SCF) will segfault if is passed NULL
6884709 Add snmp notification agent for FMA and software events
6884712 Add private interface to tap into libfmd_msg macro expansion capabilities
6897919 fmd to run in a non-global zone
6897937 fmd use of non-private doors is not safe
6900081 add a UUID to Solaris kernel image for use in crashdump identification
6914884 model panic events as a defect diagnosis in FMA
6944862 fmd_case_open_uuid, fmd_case_uuisresolved, fmd_nvl_create_defect
6944866 log legacy sysevents in fmd
6944867 enumerate svc scheme in topo
6944868 software-diagnosis and software-response fmd modules
6944870 model SMF maintenance state as a defect diagnosis in FMA
6944876 savecore runs in foreground for systems with zfs root and dedicated dump
6965796 Implement notification parameters for SMF state transitions and FMA events
6968287 SUN-FM-MIB.mib needs to be updated to reflect Oracle information
6972331 logadm.conf upgrade PSARC/2010/290
author | Gavin Maltby <gavin.maltby@oracle.com> |
---|---|
date | Fri, 30 Jul 2010 17:04:17 +1000 |
parents | 91b62f7b8186 |
children | 790945ad7848 |
rev | line source |
---|---|
0 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
1712 | 5 * Common Development and Distribution License (the "License"). |
6 * You may not use this file except in compliance with the License. | |
0 | 7 * |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 * or http://www.opensolaris.org/os/licensing. | |
10 * See the License for the specific language governing permissions | |
11 * and limitations under the License. | |
12 * | |
13 * When distributing Covered Code, include this CDDL HEADER in each | |
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 * If applicable, add the following below this CDDL HEADER, with the | |
16 * fields enclosed by brackets "[]" replaced with your own identifying | |
17 * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 * | |
19 * CDDL HEADER END | |
20 */ | |
11466
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
21 |
0 | 22 /* |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 24 */ |
25 | |
26 #ifndef _STARTD_H | |
27 #define _STARTD_H | |
28 | |
29 #include <sys/time.h> | |
30 #include <librestart.h> | |
31 #include <librestart_priv.h> | |
32 #include <libscf.h> | |
33 #include <libsysevent.h> | |
34 #include <libuutil.h> | |
35 #include <pthread.h> | |
11466
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
36 #include <synch.h> |
0 | 37 #include <stdio.h> |
38 #include <syslog.h> | |
39 #include <umem.h> | |
40 | |
41 #ifdef __cplusplus | |
42 extern "C" { | |
43 #endif | |
44 | |
45 /* | |
11466
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
46 * We want MUTEX_HELD, but we also want pthreads. So we're stuck with this |
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
47 * for the native build, at least until the build machines can catch up |
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
48 * with the latest version of MUTEX_HELD() in <synch.h>. |
0 | 49 */ |
11466
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
50 #if defined(NATIVE_BUILD) |
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
51 #undef MUTEX_HELD |
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
52 #define MUTEX_HELD(m) _mutex_held((mutex_t *)(m)) |
d60272412fb0
6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents:
9333
diff
changeset
|
53 #endif |
0 | 54 |
55 #ifndef NDEBUG | |
56 | |
57 #define MUTEX_LOCK(mp) { \ | |
58 int err; \ | |
59 if ((err = pthread_mutex_lock((mp))) != 0) { \ | |
60 (void) fprintf(stderr, \ | |
61 "pthread_mutex_lock() failed on %s:%d: %s\n", \ | |
62 __FILE__, __LINE__, strerror(err)); \ | |
63 abort(); \ | |
64 } \ | |
65 } | |
66 | |
67 #define MUTEX_UNLOCK(mp) { \ | |
68 int err; \ | |
69 if ((err = pthread_mutex_unlock((mp))) != 0) { \ | |
70 (void) fprintf(stderr, \ | |
71 "pthread_mutex_unlock() failed on %s:%d: %s\n", \ | |
72 __FILE__, __LINE__, strerror(err)); \ | |
73 abort(); \ | |
74 } \ | |
75 } | |
76 | |
77 #else | |
78 | |
79 #define MUTEX_LOCK(mp) (void) pthread_mutex_lock((mp)) | |
80 #define MUTEX_UNLOCK(mp) (void) pthread_mutex_unlock((mp)) | |
81 | |
82 #endif | |
83 | |
84 #ifndef NDEBUG | |
85 #define bad_error(func, err) { \ | |
86 (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \ | |
87 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \ | |
88 abort(); \ | |
89 } | |
90 #else | |
91 #define bad_error(func, err) abort() | |
92 #endif | |
93 | |
94 | |
95 #define min(a, b) (((a) < (b)) ? (a) : (b)) | |
96 | |
97 #define FAULT_COUNT_INCR 0 | |
98 #define FAULT_COUNT_RESET 1 | |
99 | |
100 #define FAULT_THRESHOLD 3 | |
101 | |
102 #define MAX_CONFIGD_RETRIES 5 | |
11996
91b62f7b8186
PSARC 2010/013 SMF Early Manifest Import
Tom Whitten <Thomas.Whitten@Sun.COM>
parents:
11482
diff
changeset
|
103 #define MAX_EMI_RETRIES 5 |
0 | 104 #define MAX_MOUNT_RETRIES 5 |
105 #define MAX_SULOGIN_RETRIES 5 | |
106 | |
107 #define RETURN_SUCCESS 0 | |
108 #define RETURN_RETRY -1 | |
109 #define RETURN_FATAL -2 | |
110 | |
111 #define LIBSCF_SUCCESS 0 | |
112 #define LIBSCF_PROPERTY_ABSENT -1 | |
113 #define LIBSCF_PGROUP_ABSENT -2 | |
114 #define LIBSCF_PROPERTY_ERROR -3 | |
115 | |
116 #define METHOD_START 0 | |
117 #define METHOD_STOP 1 | |
118 #define METHOD_REFRESH 2 | |
119 | |
120 #define METHOD_TIMEOUT_INFINITE 0 | |
121 | |
122 /* | |
123 * Contract cookies used by startd. | |
124 */ | |
125 #define CONFIGD_COOKIE 0x10 | |
126 #define SULOGIN_COOKIE 0x11 | |
127 #define METHOD_START_COOKIE 0x20 | |
128 #define METHOD_OTHER_COOKIE 0x21 | |
129 #define MONITOR_COOKIE 0x30 | |
11996
91b62f7b8186
PSARC 2010/013 SMF Early Manifest Import
Tom Whitten <Thomas.Whitten@Sun.COM>
parents:
11482
diff
changeset
|
130 #define EMI_COOKIE 0x31 |
0 | 131 |
132 | |
133 #define ALLOC_RETRY 3 | |
134 #define ALLOC_DELAY 10 | |
135 #define ALLOC_DELAY_MULT 10 | |
136 | |
137 #define safe_scf_scope_create(h) \ | |
138 libscf_object_create((void *(*)(scf_handle_t *))scf_scope_create, (h)) | |
139 #define safe_scf_service_create(h) \ | |
140 libscf_object_create((void *(*)(scf_handle_t *))scf_service_create, (h)) | |
141 #define safe_scf_instance_create(h) libscf_object_create( \ | |
142 (void *(*)(scf_handle_t *))scf_instance_create, (h)) | |
143 #define safe_scf_snapshot_create(h) libscf_object_create( \ | |
144 (void *(*)(scf_handle_t *))scf_snapshot_create, (h)) | |
145 #define safe_scf_snaplevel_create(h) libscf_object_create( \ | |
146 (void *(*)(scf_handle_t *))scf_snaplevel_create, (h)) | |
147 #define safe_scf_pg_create(h) \ | |
148 libscf_object_create((void *(*)(scf_handle_t *))scf_pg_create, (h)) | |
149 #define safe_scf_property_create(h) libscf_object_create( \ | |
150 (void *(*)(scf_handle_t *))scf_property_create, (h)) | |
151 #define safe_scf_value_create(h) \ | |
152 libscf_object_create((void *(*)(scf_handle_t *))scf_value_create, (h)) | |
153 #define safe_scf_iter_create(h) \ | |
154 libscf_object_create((void *(*)(scf_handle_t *))scf_iter_create, (h)) | |
155 #define safe_scf_transaction_create(h) libscf_object_create( \ | |
156 (void *(*)(scf_handle_t *)) scf_transaction_create, (h)) | |
157 #define safe_scf_entry_create(h) \ | |
158 libscf_object_create((void *(*)(scf_handle_t *))scf_entry_create, (h)) | |
159 | |
160 #define startd_alloc(sz) \ | |
161 startd_alloc_retry((void *(*)(size_t, int))umem_alloc, (sz)) | |
162 #define startd_zalloc(sz) \ | |
163 startd_alloc_retry((void *(*)(size_t, int))umem_zalloc, (sz)) | |
164 | |
165 | |
166 extern pthread_mutexattr_t mutex_attrs; | |
167 | |
168 /* | |
169 * Definitions for administrative actions. | |
170 * Note that the ordering in admin_action_t, admin_actions, and admin_events | |
171 * must match. admin_actions and admin_events are defined in startd.c. | |
172 */ | |
173 #define NACTIONS 6 | |
174 | |
175 typedef enum { | |
176 ADMIN_EVENT_DEGRADED = 0x0, | |
177 ADMIN_EVENT_MAINT_OFF, | |
178 ADMIN_EVENT_MAINT_ON, | |
179 ADMIN_EVENT_MAINT_ON_IMMEDIATE, | |
180 ADMIN_EVENT_REFRESH, | |
181 ADMIN_EVENT_RESTART | |
182 } admin_action_t; | |
183 | |
184 extern const char * const admin_actions[NACTIONS]; | |
185 extern const int admin_events[NACTIONS]; | |
186 | |
187 #define LOG_DATE_SIZE 32 /* Max size of timestamp in log output */ | |
188 | |
189 extern ssize_t max_scf_name_size; | |
190 extern ssize_t max_scf_value_size; | |
191 extern ssize_t max_scf_fmri_size; | |
192 | |
193 extern mode_t fmask; | |
194 extern mode_t dmask; | |
195 | |
196 #define LOG_PREFIX_EARLY "/etc/svc/volatile/" | |
197 #define LOG_PREFIX_NORMAL "/var/svc/log/" | |
198 | |
199 #define LOG_SUFFIX ".log" | |
200 | |
201 #define STARTD_DEFAULT_LOG "svc.startd.log" | |
11996
91b62f7b8186
PSARC 2010/013 SMF Early Manifest Import
Tom Whitten <Thomas.Whitten@Sun.COM>
parents:
11482
diff
changeset
|
202 #define EMI_LOG ((const char *) "system-early-manifest-import:default.log") |
0 | 203 |
204 extern const char *log_directory; /* Current log directory path */ | |
205 | |
206 #define FS_TIMEZONE_DIR "/usr/share/lib/zoneinfo" | |
207 #define FS_LOCALE_DIR "/usr/lib/locale" | |
208 | |
209 /* | |
210 * Simple dictionary representation. | |
211 */ | |
212 typedef struct dictionary { | |
213 uu_list_t *dict_list; | |
214 int dict_new_id; | |
215 pthread_mutex_t dict_lock; | |
216 } dictionary_t; | |
217 | |
218 typedef struct dict_entry { | |
219 int de_id; | |
220 const char *de_name; | |
221 uu_list_node_t de_link; | |
222 } dict_entry_t; | |
223 | |
224 extern dictionary_t *dictionary; | |
225 | |
226 typedef struct timeout_queue { | |
227 uu_list_t *tq_list; | |
228 pthread_mutex_t tq_lock; | |
229 } timeout_queue_t; | |
230 | |
231 typedef struct timeout_entry { | |
232 hrtime_t te_timeout; /* timeout expiration time */ | |
233 ctid_t te_ctid; | |
234 char *te_fmri; | |
235 char *te_logstem; | |
236 volatile int te_fired; | |
237 uu_list_node_t te_link; | |
238 } timeout_entry_t; | |
239 | |
240 extern timeout_queue_t *timeouts; | |
241 | |
242 /* | |
243 * State definitions. | |
244 */ | |
245 typedef enum { | |
246 STATE_NONE = 0x0, | |
247 STATE_UNINIT, | |
248 STATE_MAINT, | |
249 STATE_OFFLINE, | |
250 STATE_DISABLED, | |
251 STATE_ONLINE, | |
252 STATE_DEGRADED | |
253 } instance_state_t; | |
254 | |
255 #define STATE_MAX (STATE_DEGRADED + 1) | |
256 | |
257 extern const char * const instance_state_str[STATE_MAX]; | |
258 | |
259 typedef enum { | |
260 GVT_UNSUPPORTED = -1, | |
261 GVT_UNKNOWN = 0, | |
262 GVT_SVC, /* service */ | |
263 GVT_INST, /* instance */ | |
264 GVT_FILE, /* file: */ | |
265 GVT_GROUP /* dependency group */ | |
266 } gv_type_t; | |
267 | |
268 typedef enum { | |
269 DEPGRP_UNSUPPORTED = -1, | |
270 DEPGRP_REQUIRE_ANY = 1, | |
271 DEPGRP_REQUIRE_ALL, | |
272 DEPGRP_EXCLUDE_ALL, | |
273 DEPGRP_OPTIONAL_ALL | |
274 } depgroup_type_t; | |
275 | |
276 typedef enum { | |
277 METHOD_RESTART_UNKNOWN = -1, | |
278 METHOD_RESTART_ALL = 0, | |
279 METHOD_RESTART_EXTERNAL_FAULT, | |
280 METHOD_RESTART_ANY_FAULT, | |
281 METHOD_RESTART_OTHER | |
282 } method_restart_t; | |
283 | |
2339
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
284 typedef enum { |
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
285 PROPAGATE_START, |
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
286 PROPAGATE_STOP, |
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
287 PROPAGATE_SAT |
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
288 } propagate_event_t; |
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
289 |
0 | 290 /* |
291 * Graph representation. | |
292 */ | |
293 #define GV_CONFIGURED 0x01 /* Service exists in repository, ready */ | |
294 #define GV_ENABLED 0x02 /* Service should be online */ | |
295 #define GV_ENBLD_NOOVR 0x04 /* GV_ENABLED, ignoring override */ | |
296 #define GV_INSUBGRAPH 0x08 /* Current milestone depends on service */ | |
7475
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
297 #define GV_DEATHROW 0x10 /* Service is on deathrow */ |
7630
5bae4a95e656
6422793 when running "svcadm disable" shutdown dependents before shutting down requested service
Renaud Manus <Renaud.Manus@Sun.COM>
parents:
7475
diff
changeset
|
298 #define GV_TOOFFLINE 0x20 /* Services in subtree to offline */ |
5bae4a95e656
6422793 when running "svcadm disable" shutdown dependents before shutting down requested service
Renaud Manus <Renaud.Manus@Sun.COM>
parents:
7475
diff
changeset
|
299 #define GV_TODISABLE 0x40 /* Services in subtree to disable */ |
0 | 300 |
301 /* ID must come first to support search */ | |
302 typedef struct graph_vertex { | |
303 int gv_id; | |
304 char *gv_name; | |
305 uu_list_node_t gv_link; | |
306 | |
307 uint_t gv_flags; | |
308 restarter_instance_state_t gv_state; | |
309 | |
310 gv_type_t gv_type; | |
311 | |
312 depgroup_type_t gv_depgroup; | |
313 restarter_error_t gv_restart; | |
314 | |
315 void (*gv_start_f)(struct graph_vertex *); | |
316 void (*gv_post_online_f)(void); | |
317 void (*gv_post_disable_f)(void); | |
318 | |
319 int gv_restarter_id; | |
320 evchan_t *gv_restarter_channel; | |
321 | |
322 int gv_delegate_initialized; | |
323 evchan_t *gv_delegate_channel; | |
324 | |
325 uu_list_t *gv_dependencies; | |
326 uu_list_t *gv_dependents; | |
1712 | 327 |
328 /* | |
329 * gv_refs represents the number of references besides dependencies. | |
330 * The vertex cannot be removed when gv_refs > 0. | |
331 * | |
332 * Currently, only relevant for GVT_SVC and GVT_INST type vertices. | |
333 */ | |
334 int gv_refs; | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
335 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
336 int32_t gv_stn_tset; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
337 int32_t gv_reason; |
0 | 338 } graph_vertex_t; |
339 | |
340 typedef struct graph_edge { | |
341 graph_vertex_t *ge_vertex; | |
342 uu_list_node_t ge_link; | |
343 graph_vertex_t *ge_parent; | |
344 } graph_edge_t; | |
345 | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
346 int libscf_get_info_events_all(scf_propertygroup_t *); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
347 int32_t libscf_get_stn_tset(scf_instance_t *); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
348 |
0 | 349 /* |
1958 | 350 * Restarter transition outcomes |
0 | 351 */ |
352 typedef enum { | |
1958 | 353 MAINT_REQUESTED, |
0 | 354 START_REQUESTED, |
355 START_FAILED_REPEATEDLY, | |
356 START_FAILED_CONFIGURATION, | |
357 START_FAILED_FATAL, | |
358 START_FAILED_TIMEOUT_FATAL, | |
359 START_FAILED_OTHER | |
360 } start_outcome_t; | |
361 | |
362 typedef void (*instance_hook_t)(void); | |
363 | |
364 typedef struct service_hook_assn { | |
365 char *sh_fmri; | |
366 instance_hook_t sh_pre_online_hook; | |
367 instance_hook_t sh_post_online_hook; | |
368 instance_hook_t sh_post_offline_hook; | |
369 } service_hook_assn_t; | |
370 | |
371 /* | |
372 * Restarter instance stop reasons. | |
373 */ | |
374 typedef enum { | |
375 RSTOP_EXIT = 0x0, /* exited or empty */ | |
376 RSTOP_CORE, /* core dumped */ | |
377 RSTOP_SIGNAL, /* external fatal signal received */ | |
378 RSTOP_HWERR, /* uncorrectable hardware error */ | |
379 RSTOP_DEPENDENCY, /* dependency activity caused stop */ | |
380 RSTOP_DISABLE, /* disabled */ | |
381 RSTOP_RESTART /* restart requested */ | |
382 } stop_cause_t; | |
383 | |
384 /* | |
385 * Restarter instance maintenance clear reasons. | |
386 */ | |
387 typedef enum { | |
388 RUNMAINT_CLEAR = 0x0, | |
389 RUNMAINT_DISABLE | |
390 } unmaint_cause_t; | |
391 | |
392 /* | |
393 * Restarter instance flags | |
394 */ | |
395 #define RINST_CONTRACT 0x00000000 /* progeny constitute inst */ | |
396 #define RINST_TRANSIENT 0x10000000 /* inst operates momentarily */ | |
397 #define RINST_WAIT 0x20000000 /* child constitutes inst */ | |
398 #define RINST_STYLE_MASK 0xf0000000 | |
399 | |
400 #define RINST_RETAKE_RUNNING 0x01000000 /* pending running snapshot */ | |
401 #define RINST_RETAKE_START 0x02000000 /* pending start snapshot */ | |
402 | |
403 #define RINST_RETAKE_MASK 0x0f000000 | |
404 | |
11482
7315713fb22c
6311392 The Quick and the Dead: rapid-fire svcadm restart leads to maintenance
Sean Wilcox <Sean.Wilcox@Sun.COM>
parents:
11466
diff
changeset
|
405 #define RINST_START_TIMES 5 /* failures to consider */ |
7315713fb22c
6311392 The Quick and the Dead: rapid-fire svcadm restart leads to maintenance
Sean Wilcox <Sean.Wilcox@Sun.COM>
parents:
11466
diff
changeset
|
406 #define RINST_FAILURE_RATE_NS 600000000000LL /* 1 failure/10 minutes */ |
0 | 407 |
408 /* Number of events in the queue when we start dropping ADMIN events. */ | |
409 #define RINST_QUEUE_THRESHOLD 100 | |
410 | |
411 typedef struct restarter_inst { | |
412 int ri_id; | |
413 instance_data_t ri_i; | |
414 char *ri_common_name; /* template localized name */ | |
415 char *ri_C_common_name; /* C locale name */ | |
416 | |
417 char *ri_logstem; /* logfile name */ | |
418 char *ri_utmpx_prefix; | |
419 uint_t ri_flags; | |
420 instance_hook_t ri_pre_online_hook; | |
421 instance_hook_t ri_post_online_hook; | |
422 instance_hook_t ri_post_offline_hook; | |
423 | |
424 hrtime_t ri_start_time[RINST_START_TIMES]; | |
425 uint_t ri_start_index; /* times started */ | |
426 | |
427 uu_list_node_t ri_link; | |
428 pthread_mutex_t ri_lock; | |
429 | |
430 /* | |
431 * When we start a thread to we execute a method for this instance, we | |
432 * put the thread id in ri_method_thread. Threads with ids other than | |
433 * this which acquire ri_lock while ri_method_thread is nonzero should | |
434 * wait on ri_method_cv. ri_method_waiters should be incremented while | |
435 * waiting so the instance won't be deleted. | |
436 */ | |
437 pthread_t ri_method_thread; | |
438 pthread_cond_t ri_method_cv; | |
439 uint_t ri_method_waiters; | |
440 | |
441 /* | |
442 * These fields are provided so functions can operate on this structure | |
443 * and the repository without worrying about whether the instance has | |
444 * been deleted from the repository (this is possible because | |
445 * ri_i.i_fmri names the instance this structure represents -- see | |
446 * libscf_reget_inst()). ri_m_inst is the scf_instance_t for the | |
447 * instance, and ri_mi_deleted is true if the instance has been deleted. | |
448 */ | |
449 scf_instance_t *ri_m_inst; | |
450 boolean_t ri_mi_deleted; | |
451 | |
452 /* | |
453 * We maintain a pointer to any pending timeout for this instance | |
454 * for quick reference/deletion. | |
455 */ | |
456 timeout_entry_t *ri_timeout; | |
457 | |
458 /* | |
459 * Instance event queue. Graph events are queued here as a list | |
460 * of restarter_instance_qentry_t's, and the lock is held separately. | |
461 * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be | |
462 * grabbed first. ri_queue_lock protects all ri_queue_* structure | |
463 * members. | |
464 */ | |
465 pthread_mutex_t ri_queue_lock; | |
466 pthread_cond_t ri_queue_cv; | |
467 uu_list_t *ri_queue; | |
468 int ri_queue_thread; | |
469 | |
470 } restarter_inst_t; | |
471 | |
472 typedef struct restarter_instance_list { | |
473 uu_list_t *ril_instance_list; | |
474 pthread_mutex_t ril_lock; | |
475 } restarter_instance_list_t; | |
476 | |
477 typedef struct restarter_instance_qentry { | |
478 restarter_event_type_t riq_type; | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
479 int32_t riq_reason; |
0 | 480 uu_list_node_t riq_link; |
481 } restarter_instance_qentry_t; | |
482 | |
483 typedef struct fork_info { | |
484 int sf_id; | |
485 int sf_method_type; | |
486 restarter_error_t sf_event_type; | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
487 restarter_str_t sf_reason; |
0 | 488 } fork_info_t; |
489 | |
490 typedef struct wait_info { | |
491 uu_list_node_t wi_link; | |
492 | |
493 int wi_fd; /* psinfo file descriptor */ | |
494 id_t wi_pid; /* process ID */ | |
495 const char *wi_fmri; /* instance FMRI */ | |
496 int wi_parent; /* startd is parent */ | |
7219
343338355d03
6691596 *svc.startd* can spawn the same process multiple times for a single wait style service
rm88369
parents:
5680
diff
changeset
|
497 int wi_ignore; /* ignore events */ |
0 | 498 } wait_info_t; |
499 | |
500 #define STARTD_LOG_FILE 0x1 | |
501 #define STARTD_LOG_TERMINAL 0x2 | |
502 #define STARTD_LOG_SYSLOG 0x4 | |
503 | |
504 #define STARTD_BOOT_QUIET 0x1 | |
505 #define STARTD_BOOT_VERBOSE 0x2 | |
506 | |
5680
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
507 /* |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
508 * Internal debug flags used to reduce the amount of data sent to the |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
509 * internal debug buffer. They can be turned on & off dynamically using |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
510 * internal_debug_flags variable in mdb. By default, they're off. |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
511 */ |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
512 #define DEBUG_DEPENDENCIES 0x1 |
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
513 |
0 | 514 typedef struct startd_state { |
515 /* Logging configuration */ | |
516 char *st_log_prefix; /* directory prefix */ | |
517 char *st_log_file; /* startd file in above dir */ | |
518 uint_t st_log_flags; /* message destination */ | |
519 int st_log_level_min; /* minimum required to log */ | |
520 int st_log_timezone_known; /* timezone is available */ | |
521 int st_log_locale_known; /* locale is available */ | |
522 int st_log_login_reached; /* login service reached */ | |
523 | |
524 /* Boot configuration */ | |
525 uint_t st_boot_flags; /* serial boot, etc. */ | |
526 uint_t st_initial; /* first startd on system */ | |
527 | |
528 /* System configuration */ | |
529 char *st_subgraph; /* milestone subgraph request */ | |
530 | |
531 uint_t st_load_complete; /* graph load completed */ | |
532 uint_t st_load_instances; /* restarter instances to load */ | |
533 pthread_mutex_t st_load_lock; | |
534 pthread_cond_t st_load_cv; | |
535 | |
536 /* Repository configuration */ | |
537 pid_t st_configd_pid; /* PID of our svc.configd */ | |
538 /* instance */ | |
539 int st_configd_lives; /* configd started */ | |
540 pthread_mutex_t st_configd_live_lock; | |
541 pthread_cond_t st_configd_live_cv; | |
542 | |
543 char *st_door_path; | |
544 | |
545 /* General information */ | |
546 uint_t st_flags; | |
547 struct timeval st_start_time; /* effective system start time */ | |
548 char *st_locale; | |
549 } startd_state_t; | |
550 | |
551 extern startd_state_t *st; | |
552 | |
553 extern boolean_t booting_to_single_user; | |
554 | |
555 extern const char *event_names[]; | |
556 | |
557 /* | |
558 * Structures for contract to instance hash table, implemented in | |
559 * contract.c and used by restarter.c and method.c | |
560 */ | |
561 typedef struct contract_entry { | |
562 ctid_t ce_ctid; | |
563 int ce_instid; | |
564 | |
565 uu_list_node_t ce_link; | |
566 } contract_entry_t; | |
567 | |
4244
77e7b46e3d5e
6243574 Services can be shown online with empty contracts
jeanm
parents:
2747
diff
changeset
|
568 extern volatile uint16_t storing_contract; |
77e7b46e3d5e
6243574 Services can be shown online with empty contracts
jeanm
parents:
2747
diff
changeset
|
569 |
0 | 570 uu_list_pool_t *contract_list_pool; |
571 | |
572 /* contract.c */ | |
573 ctid_t contract_init(void); | |
574 void contract_abandon(ctid_t); | |
575 int contract_kill(ctid_t, int, const char *); | |
576 int contract_is_empty(ctid_t); | |
577 void contract_hash_init(); | |
578 void contract_hash_store(ctid_t, int); | |
579 void contract_hash_remove(ctid_t); | |
580 int lookup_inst_by_contract(ctid_t); | |
581 | |
582 /* dict.c */ | |
583 void dict_init(void); | |
584 int dict_lookup_byname(const char *); | |
585 int dict_insert(const char *); | |
586 | |
587 /* expand.c */ | |
588 int expand_method_tokens(const char *, scf_instance_t *, | |
589 scf_snapshot_t *, int, char **); | |
590 | |
591 /* env.c */ | |
592 void init_env(void); | |
593 char **set_smf_env(char **, size_t, const char *, | |
594 const restarter_inst_t *, const char *); | |
595 | |
596 /* file.c */ | |
597 int file_ready(graph_vertex_t *); | |
598 | |
599 /* fork.c */ | |
600 int fork_mount(char *, char *); | |
601 void fork_sulogin(boolean_t, const char *, ...); | |
602 void fork_rc_script(char, const char *, boolean_t); | |
603 | |
604 void *fork_configd_thread(void *); | |
605 | |
606 pid_t startd_fork1(int *); | |
8944
e4ff744ddfe1
6805730 some simple changes would make 'init 5' much faster
Dan Price <dp@eng.sun.com>
parents:
8823
diff
changeset
|
607 void fork_with_timeout(const char *, uint_t, uint_t); |
11996
91b62f7b8186
PSARC 2010/013 SMF Early Manifest Import
Tom Whitten <Thomas.Whitten@Sun.COM>
parents:
11482
diff
changeset
|
608 void fork_emi(); |
0 | 609 |
610 /* graph.c */ | |
611 void graph_init(void); | |
612 void *single_user_thread(void *); | |
613 void *graph_thread(void *); | |
614 void *graph_event_thread(void *); | |
615 void *repository_event_thread(void *); | |
616 int dgraph_add_instance(const char *, scf_instance_t *, boolean_t); | |
617 void graph_engine_start(void); | |
1958 | 618 void graph_enable_by_vertex(graph_vertex_t *, int, int); |
619 int refresh_vertex(graph_vertex_t *, scf_instance_t *); | |
620 void vertex_send_event(graph_vertex_t *, restarter_event_type_t); | |
621 void graph_start_if_satisfied(graph_vertex_t *); | |
2747
87ae3ca2e4c8
6448732 shutdown is vulnerable to restarting services
bustos
parents:
2339
diff
changeset
|
622 int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *, |
87ae3ca2e4c8
6448732 shutdown is vulnerable to restarting services
bustos
parents:
2339
diff
changeset
|
623 restarter_instance_state_t); |
1958 | 624 void graph_transition_sulogin(restarter_instance_state_t, |
625 restarter_instance_state_t); | |
2339
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
626 void graph_transition_propagate(graph_vertex_t *, propagate_event_t, |
1958 | 627 restarter_error_t); |
7630
5bae4a95e656
6422793 when running "svcadm disable" shutdown dependents before shutting down requested service
Renaud Manus <Renaud.Manus@Sun.COM>
parents:
7475
diff
changeset
|
628 void graph_offline_subtree_leaves(graph_vertex_t *, void *); |
9333
71fd5798e2e3
6622195 SMF occasionally does not honor prerequisite dependencies and take service offline when deps fail
Renaud Manus <Renaud.Manus@Sun.COM>
parents:
8944
diff
changeset
|
629 void offline_vertex(graph_vertex_t *); |
0 | 630 |
631 /* libscf.c - common */ | |
632 char *inst_fmri_to_svc_fmri(const char *); | |
633 void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *); | |
634 int libscf_instance_get_fmri(scf_instance_t *, char **); | |
635 int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **); | |
636 int libscf_lookup_instance(const char *, scf_instance_t *); | |
637 int libscf_set_reconfig(int); | |
638 scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *, | |
639 const char *, boolean_t); | |
640 int libscf_inst_set_count_prop(scf_instance_t *, const char *, | |
641 const char *pgtype, uint32_t, const char *, uint64_t); | |
642 | |
643 /* libscf.c - used by graph.c */ | |
7475
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
644 int libscf_get_deathrow(scf_handle_t *, scf_instance_t *, int *); |
0 | 645 int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *, |
646 const char *, int *, int *, char **); | |
647 int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *, | |
648 uint32_t, scf_propertygroup_t *); | |
649 int libscf_read_states(const scf_propertygroup_t *, | |
650 restarter_instance_state_t *, restarter_instance_state_t *); | |
651 int depgroup_empty(scf_handle_t *, scf_propertygroup_t *); | |
652 gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *); | |
653 depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *); | |
654 restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *); | |
655 int libscf_set_enable_ovr(scf_instance_t *, int); | |
7475
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
656 int libscf_set_deathrow(scf_instance_t *, int); |
0 | 657 int libscf_delete_enable_ovr(scf_instance_t *); |
658 int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *, | |
659 char *, size_t); | |
660 int libscf_extract_runlevel(scf_property_t *, char *); | |
661 int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone); | |
662 | |
663 typedef int (*callback_t)(void *, void *); | |
664 | |
665 int walk_dependency_pgs(scf_instance_t *, callback_t, void *); | |
666 int walk_property_astrings(scf_property_t *, callback_t, void *); | |
11482
7315713fb22c
6311392 The Quick and the Dead: rapid-fire svcadm restart leads to maintenance
Sean Wilcox <Sean.Wilcox@Sun.COM>
parents:
11466
diff
changeset
|
667 void libscf_reset_start_times(restarter_inst_t *, int); |
0 | 668 |
669 /* libscf.c - used by restarter.c/method.c/expand.c */ | |
670 char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *, | |
671 scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *, | |
672 uint8_t *); | |
673 void libscf_populate_graph(scf_handle_t *h); | |
674 int update_fault_count(restarter_inst_t *, int); | |
675 int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t, | |
676 int64_t); | |
677 int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *, | |
678 char **); | |
679 int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **, | |
680 char **); | |
681 | |
682 int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *, | |
683 ctid_t *, ctid_t *, pid_t *); | |
684 int libscf_write_start_pid(scf_instance_t *, pid_t); | |
685 int libscf_write_method_status(scf_instance_t *, const char *, int); | |
686 int libscf_note_method_log(scf_instance_t *, const char *, const char *); | |
687 | |
688 scf_handle_t *libscf_handle_create_bound(scf_version_t); | |
689 void libscf_handle_rebind(scf_handle_t *); | |
690 scf_handle_t *libscf_handle_create_bound_loop(void); | |
691 | |
692 scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *); | |
693 int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t); | |
694 int libscf_snapshots_refresh(scf_instance_t *, const char *); | |
695 | |
696 int instance_is_transient_style(restarter_inst_t *); | |
697 int instance_is_wait_style(restarter_inst_t *); | |
698 | |
699 int libscf_create_self(scf_handle_t *); | |
700 | |
701 void libscf_reget_instance(restarter_inst_t *); | |
702 | |
703 /* log.c */ | |
704 void log_init(); | |
705 void log_error(int, const char *, ...); | |
706 void log_framework(int, const char *, ...); | |
5680
0c36d39ff12f
6626457 boot time increases exponentially with S10U4 + VxVM 5.0 + SunCluster 3.2
rm88369
parents:
4244
diff
changeset
|
707 void log_framework2(int, int, const char *, ...); |
0 | 708 void log_console(int, const char *, ...); |
709 void log_preexec(void); | |
710 void setlog(const char *); | |
711 void log_transition(const restarter_inst_t *, start_outcome_t); | |
712 void log_instance(const restarter_inst_t *, boolean_t, const char *, ...); | |
713 void log_instance_fmri(const char *, const char *, boolean_t, | |
714 const char *, ...); | |
715 | |
716 /* method.c */ | |
717 void *method_thread(void *); | |
718 void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t); | |
719 | |
720 /* misc.c */ | |
721 void startd_close(int); | |
722 void startd_fclose(FILE *); | |
723 int fmri_canonify(const char *, char **, boolean_t); | |
724 int fs_is_read_only(char *, ulong_t *); | |
725 int fs_remount(char *); | |
726 void xstr_sanitize(char *); | |
727 | |
728 /* restarter.c */ | |
729 void restarter_init(void); | |
730 void restarter_start(void); | |
731 int instance_in_transition(restarter_inst_t *); | |
732 int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *, | |
733 restarter_instance_state_t, restarter_instance_state_t, restarter_error_t, | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11996
diff
changeset
|
734 restarter_str_t); |
0 | 735 int stop_instance_fmri(scf_handle_t *, const char *, uint_t); |
736 restarter_inst_t *inst_lookup_by_id(int); | |
737 void restarter_mark_pending_snapshot(const char *, uint_t); | |
738 void *restarter_post_fsminimal_thread(void *); | |
739 void timeout_insert(restarter_inst_t *, ctid_t, uint64_t); | |
740 void timeout_remove(restarter_inst_t *, ctid_t); | |
741 void timeout_init(void); | |
742 int is_timeout_ovr(restarter_inst_t *); | |
743 | |
744 /* startd.c */ | |
745 void *safe_realloc(void *, size_t); | |
746 char *safe_strdup(const char *s); | |
747 void *startd_alloc_retry(void *(*)(size_t, int), size_t); | |
748 void startd_free(void *, size_t); | |
749 uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t, | |
750 uu_compare_fn_t *, uint32_t); | |
751 uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t); | |
752 pthread_t startd_thread_create(void *(*)(void *), void *); | |
753 | |
754 /* special.c */ | |
755 void special_null_transition(void); | |
756 void special_online_hooks_get(const char *, instance_hook_t *, | |
757 instance_hook_t *, instance_hook_t *); | |
758 | |
1958 | 759 /* transition.c */ |
760 int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t, | |
2339
73c7b85b6be0
6440500 no login prompt (hang) when filesystem/local fails
lianep
parents:
1958
diff
changeset
|
761 restarter_instance_state_t); |
1958 | 762 |
0 | 763 /* utmpx.c */ |
764 void utmpx_init(void); | |
765 void utmpx_clear_old(void); | |
766 int utmpx_mark_init(pid_t, char *); | |
767 void utmpx_mark_dead(pid_t, int, boolean_t); | |
768 char utmpx_get_runlevel(void); | |
769 void utmpx_set_runlevel(char, char, boolean_t); | |
770 void utmpx_write_boottime(void); | |
771 | |
772 /* wait.c */ | |
773 void wait_init(void); | |
774 void wait_prefork(void); | |
775 void wait_postfork(pid_t); | |
776 int wait_register(pid_t, const char *, int, int); | |
777 void *wait_thread(void *); | |
7219
343338355d03
6691596 *svc.startd* can spawn the same process multiple times for a single wait style service
rm88369
parents:
5680
diff
changeset
|
778 void wait_ignore_by_fmri(const char *); |
0 | 779 |
780 /* proc.c */ | |
781 ctid_t proc_get_ctid(); | |
782 | |
7475
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
783 /* deathrow.c */ |
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
784 extern void deathrow_init(); |
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
785 extern void deathrow_fini(); |
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
786 extern boolean_t is_fmri_in_deathrow(const char *); |
9a5f7406e094
6438829 SMF svcs are not removed when performing a pkgrm in an alternate root
Philippe Jung <Philippe.Jung@Sun.COM>
parents:
7219
diff
changeset
|
787 |
0 | 788 #ifdef __cplusplus |
789 } | |
790 #endif | |
791 | |
792 #endif /* _STARTD_H */ |