xref: /onnv-gate/usr/src/cmd/fm/fmd/common/fmd_dr.c (revision 1193:e784a8fa27da)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1193Smws  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * FMD Dynamic Reconfiguration (DR) Event Handling
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * Fault manager scheme plug-ins must track characteristics of individual
330Sstevel@tonic-gate  * pieces of hardware.  As these components can be added or removed by a DR
340Sstevel@tonic-gate  * operation, we need to provide a means by which plug-ins can determine when
350Sstevel@tonic-gate  * they need to re-examine the current configuration.  We provide a simple
360Sstevel@tonic-gate  * mechanism whereby this task can be implemented using lazy evaluation: a
370Sstevel@tonic-gate  * simple 64-bit generation counter is maintained and incremented on *any* DR.
380Sstevel@tonic-gate  * Schemes can store the generation number in scheme-specific data structures,
390Sstevel@tonic-gate  * and then revalidate their contents if the current generation number has
400Sstevel@tonic-gate  * changed since the resource information was cached.  This method saves time,
410Sstevel@tonic-gate  * avoids the complexity of direct participation in DR, avoids the need for
420Sstevel@tonic-gate  * resource-specific processing of DR events, and is relatively easy to port
430Sstevel@tonic-gate  * to other systems that support dynamic reconfiguration.
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #include <sys/types.h>
470Sstevel@tonic-gate #include <sys/sysevent/dr.h>
480Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #include <stdio.h>
51*1193Smws #include <unistd.h>
520Sstevel@tonic-gate #include <libsysevent.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #undef MUTEX_HELD
550Sstevel@tonic-gate #undef RW_READ_HELD
560Sstevel@tonic-gate #undef RW_WRITE_HELD
570Sstevel@tonic-gate 
580Sstevel@tonic-gate #include <fmd_error.h>
590Sstevel@tonic-gate #include <fmd_subr.h>
600Sstevel@tonic-gate #include <fmd.h>
610Sstevel@tonic-gate 
620Sstevel@tonic-gate static void
630Sstevel@tonic-gate fmd_dr_event(sysevent_t *sep)
640Sstevel@tonic-gate {
650Sstevel@tonic-gate 	uint64_t gen;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	(void) pthread_mutex_lock(&fmd.d_stats_lock);
680Sstevel@tonic-gate 	gen = fmd.d_stats->ds_dr_gen.fmds_value.ui64++;
690Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&fmd.d_stats_lock);
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	TRACE((FMD_DBG_XPRT, "dr event %p, gen=%llu", (void *)sep, gen));
720Sstevel@tonic-gate }
730Sstevel@tonic-gate 
740Sstevel@tonic-gate void
750Sstevel@tonic-gate fmd_dr_init(void)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate 	const char *subclass = ESC_DR_AP_STATE_CHANGE;
780Sstevel@tonic-gate 
79*1193Smws 	if (geteuid() != 0)
80*1193Smws 		return; /* legacy sysevent mechanism is still root-only */
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	if ((fmd.d_dr_hdl = sysevent_bind_handle(fmd_dr_event)) == NULL)
830Sstevel@tonic-gate 		fmd_error(EFMD_EXIT, "failed to bind handle for DR sysevent");
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	if (sysevent_subscribe_event(fmd.d_dr_hdl, EC_DR, &subclass, 1) == -1)
860Sstevel@tonic-gate 		fmd_error(EFMD_EXIT, "failed to subscribe for DR sysevent");
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
890Sstevel@tonic-gate void
900Sstevel@tonic-gate fmd_dr_fini(void)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate 	if (fmd.d_dr_hdl != NULL) {
930Sstevel@tonic-gate 		sysevent_unsubscribe_event(fmd.d_dr_hdl, EC_DR);
940Sstevel@tonic-gate 		sysevent_unbind_handle(fmd.d_dr_hdl);
950Sstevel@tonic-gate 	}
960Sstevel@tonic-gate }
97