xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_dr.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * FMD Dynamic Reconfiguration (DR) Event Handling
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * Fault manager scheme plug-ins must track characteristics of individual
33*7c478bd9Sstevel@tonic-gate  * pieces of hardware.  As these components can be added or removed by a DR
34*7c478bd9Sstevel@tonic-gate  * operation, we need to provide a means by which plug-ins can determine when
35*7c478bd9Sstevel@tonic-gate  * they need to re-examine the current configuration.  We provide a simple
36*7c478bd9Sstevel@tonic-gate  * mechanism whereby this task can be implemented using lazy evaluation: a
37*7c478bd9Sstevel@tonic-gate  * simple 64-bit generation counter is maintained and incremented on *any* DR.
38*7c478bd9Sstevel@tonic-gate  * Schemes can store the generation number in scheme-specific data structures,
39*7c478bd9Sstevel@tonic-gate  * and then revalidate their contents if the current generation number has
40*7c478bd9Sstevel@tonic-gate  * changed since the resource information was cached.  This method saves time,
41*7c478bd9Sstevel@tonic-gate  * avoids the complexity of direct participation in DR, avoids the need for
42*7c478bd9Sstevel@tonic-gate  * resource-specific processing of DR events, and is relatively easy to port
43*7c478bd9Sstevel@tonic-gate  * to other systems that support dynamic reconfiguration.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/dr.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h>
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #include <stdio.h>
51*7c478bd9Sstevel@tonic-gate #include <libsysevent.h>
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #undef MUTEX_HELD
54*7c478bd9Sstevel@tonic-gate #undef RW_READ_HELD
55*7c478bd9Sstevel@tonic-gate #undef RW_WRITE_HELD
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #include <fmd_error.h>
58*7c478bd9Sstevel@tonic-gate #include <fmd_subr.h>
59*7c478bd9Sstevel@tonic-gate #include <fmd.h>
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate static void
62*7c478bd9Sstevel@tonic-gate fmd_dr_event(sysevent_t *sep)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate 	uint64_t gen;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&fmd.d_stats_lock);
67*7c478bd9Sstevel@tonic-gate 	gen = fmd.d_stats->ds_dr_gen.fmds_value.ui64++;
68*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&fmd.d_stats_lock);
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	TRACE((FMD_DBG_XPRT, "dr event %p, gen=%llu", (void *)sep, gen));
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate  * Initialize DR event subscription.  Note: sysevent_bind_handle() calls
75*7c478bd9Sstevel@tonic-gate  * door_create() internally.  Door servers in fmd must be setup as fmd threads,
76*7c478bd9Sstevel@tonic-gate  * and fmd_transport_init() already calls door_server_create() for us.  We
77*7c478bd9Sstevel@tonic-gate  * therefore rely on fmd_transport_init() being called before fmd_dr_init().
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate void
80*7c478bd9Sstevel@tonic-gate fmd_dr_init(void)
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	const char *subclass = ESC_DR_AP_STATE_CHANGE;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	ASSERT(fmd.d_xprt_chan != NULL); /* fmd_transport_init() has happened */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	if ((fmd.d_dr_hdl = sysevent_bind_handle(fmd_dr_event)) == NULL)
87*7c478bd9Sstevel@tonic-gate 		fmd_error(EFMD_EXIT, "failed to bind handle for DR sysevent");
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	if (sysevent_subscribe_event(fmd.d_dr_hdl, EC_DR, &subclass, 1) == -1)
90*7c478bd9Sstevel@tonic-gate 		fmd_error(EFMD_EXIT, "failed to subscribe for DR sysevent");
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate void
94*7c478bd9Sstevel@tonic-gate fmd_dr_fini(void)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 	if (fmd.d_dr_hdl != NULL) {
97*7c478bd9Sstevel@tonic-gate 		sysevent_unsubscribe_event(fmd.d_dr_hdl, EC_DR);
98*7c478bd9Sstevel@tonic-gate 		sysevent_unbind_handle(fmd.d_dr_hdl);
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate }
101