xref: /onnv-gate/usr/src/cmd/fm/fmd/common/fmd_dr.c (revision 13131:87d7bfd32811)
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
52027Ssethg  * Common Development and Distribution License (the "License").
62027Ssethg  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2212066SRobert.Johnston@Sun.COM  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * FMD Dynamic Reconfiguration (DR) Event Handling
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  * Fault manager scheme plug-ins must track characteristics of individual
290Sstevel@tonic-gate  * pieces of hardware.  As these components can be added or removed by a DR
300Sstevel@tonic-gate  * operation, we need to provide a means by which plug-ins can determine when
310Sstevel@tonic-gate  * they need to re-examine the current configuration.  We provide a simple
320Sstevel@tonic-gate  * mechanism whereby this task can be implemented using lazy evaluation: a
330Sstevel@tonic-gate  * simple 64-bit generation counter is maintained and incremented on *any* DR.
340Sstevel@tonic-gate  * Schemes can store the generation number in scheme-specific data structures,
350Sstevel@tonic-gate  * and then revalidate their contents if the current generation number has
360Sstevel@tonic-gate  * changed since the resource information was cached.  This method saves time,
370Sstevel@tonic-gate  * avoids the complexity of direct participation in DR, avoids the need for
380Sstevel@tonic-gate  * resource-specific processing of DR events, and is relatively easy to port
390Sstevel@tonic-gate  * to other systems that support dynamic reconfiguration.
404198Seschrock  *
414198Seschrock  * The dr generation is only incremented in response to hardware changes.  Since
424198Seschrock  * ASRUs can be in any scheme, including the device scheme, we must also be
434198Seschrock  * aware of software configuration changes which may affect the resource cache.
444198Seschrock  * In addition, we take a snapshot of the topology whenever a reconfiguration
454198Seschrock  * event occurs and notify any modules of the change.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #include <sys/types.h>
494198Seschrock #include <sys/sunddi.h>
500Sstevel@tonic-gate #include <sys/sysevent/dr.h>
510Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #include <stdio.h>
544198Seschrock #include <string.h>
551193Smws #include <unistd.h>
560Sstevel@tonic-gate #include <libsysevent.h>
570Sstevel@tonic-gate 
580Sstevel@tonic-gate #undef MUTEX_HELD
590Sstevel@tonic-gate #undef RW_READ_HELD
600Sstevel@tonic-gate #undef RW_WRITE_HELD
610Sstevel@tonic-gate 
622027Ssethg #include <fmd_asru.h>
630Sstevel@tonic-gate #include <fmd_error.h>
644198Seschrock #include <fmd_event.h>
652027Ssethg #include <fmd_fmri.h>
664198Seschrock #include <fmd_module.h>
670Sstevel@tonic-gate #include <fmd_subr.h>
684198Seschrock #include <fmd_topo.h>
690Sstevel@tonic-gate #include <fmd.h>
700Sstevel@tonic-gate 
717171Seschrock void
fmd_dr_event(sysevent_t * sep)720Sstevel@tonic-gate fmd_dr_event(sysevent_t *sep)
730Sstevel@tonic-gate {
740Sstevel@tonic-gate 	uint64_t gen;
754198Seschrock 	fmd_event_t *e;
764198Seschrock 	const char *class = sysevent_get_class_name(sep);
777171Seschrock 	const char *subclass = sysevent_get_subclass_name(sep);
784198Seschrock 	hrtime_t evtime;
794198Seschrock 	fmd_topo_t *ftp, *prev;
804198Seschrock 
814198Seschrock 	if (strcmp(class, EC_DR) == 0) {
827171Seschrock 		if (strcmp(subclass, ESC_DR_AP_STATE_CHANGE) != 0 &&
837171Seschrock 		    strcmp(subclass, ESC_DR_TARGET_STATE_CHANGE) != 0)
847171Seschrock 			return;
8512066SRobert.Johnston@Sun.COM 	/* LINTED: E_NOP_IF_STMT */
867171Seschrock 	} else if (strcmp(class, EC_DEVFS) == 0) {
877171Seschrock 		/*
887171Seschrock 		 * A devfs configuration event can change the topology,
897171Seschrock 		 * as disk nodes only exist when the device is configured.
907171Seschrock 		 */
918526SRobert.Johnston@Sun.COM 	} else if (strcmp(class, EC_PLATFORM) == 0) {
927171Seschrock 		/*
9312066SRobert.Johnston@Sun.COM 		 * Since we rely on the SP to enumerate fans,
9412066SRobert.Johnston@Sun.COM 		 * power-supplies and sensors/leds, it would be prudent
9512066SRobert.Johnston@Sun.COM 		 * to take a new snapshot if the SP resets.
967171Seschrock 		 */
9712066SRobert.Johnston@Sun.COM 		if (strcmp(subclass, ESC_PLATFORM_SP_RESET) != 0)
987171Seschrock 			return;
997171Seschrock 	} else if (strcmp(class, EC_DEV_ADD) == 0 ||
1007171Seschrock 	    strcmp(class, EC_DEV_REMOVE) == 0) {
1017171Seschrock 		if (strcmp(subclass, ESC_DISK) != 0)
1027171Seschrock 			return;
10312066SRobert.Johnston@Sun.COM 	} else
10412066SRobert.Johnston@Sun.COM 		return;
1050Sstevel@tonic-gate 
1062027Ssethg 	/*
1074198Seschrock 	 * Take a topo snapshot and notify modules of the change.  Picking an
1084198Seschrock 	 * accurate time here is difficult.  On one hand, we have the timestamp
1094198Seschrock 	 * of the underlying sysevent, indicating when the reconfiguration event
1104198Seschrock 	 * occurred.  On the other hand, we are taking the topo snapshot
1114198Seschrock 	 * asynchronously, and hence the timestamp of the snapshot is the
1124198Seschrock 	 * current time.  Pretending this topo snapshot was valid at the time
1134198Seschrock 	 * the sysevent was posted seems wrong, so we instead opt for the
1144198Seschrock 	 * current time as an upper bound on the snapshot validity.
1154198Seschrock 	 *
1164198Seschrock 	 * Along these lines, we keep track of the last time we dispatched a
1174198Seschrock 	 * topo snapshot.  If the sysevent occurred before the last topo
1184198Seschrock 	 * snapshot, then don't bother dispatching another topo change event.
1194198Seschrock 	 * We've already indicated (to the best of our ability) the change in
1204198Seschrock 	 * topology.  This prevents endless topo snapshots in response to a
1214198Seschrock 	 * flurry of sysevents.
1222027Ssethg 	 */
1234198Seschrock 	sysevent_get_time(sep, &evtime);
1244198Seschrock 	prev = fmd_topo_hold();
1259728SEric.Schrock@Sun.COM 	if (evtime <= prev->ft_time_begin &&
1264198Seschrock 	    fmd.d_clockops == &fmd_timeops_native) {
1274198Seschrock 		fmd_topo_rele(prev);
1284198Seschrock 		return;
1294198Seschrock 	}
1304198Seschrock 	fmd_topo_rele(prev);
1312027Ssethg 
13212066SRobert.Johnston@Sun.COM 	(void) pthread_mutex_lock(&fmd.d_stats_lock);
13312066SRobert.Johnston@Sun.COM 	gen = fmd.d_stats->ds_dr_gen.fmds_value.ui64++;
13412066SRobert.Johnston@Sun.COM 	(void) pthread_mutex_unlock(&fmd.d_stats_lock);
13512066SRobert.Johnston@Sun.COM 
13612066SRobert.Johnston@Sun.COM 	TRACE((FMD_DBG_XPRT, "dr event %p, gen=%llu", (void *)sep, gen));
137*13131SHyon.Kim@Sun.COM 	fmd_topo_update();
1380Sstevel@tonic-gate 
1394198Seschrock 	ftp = fmd_topo_hold();
1409728SEric.Schrock@Sun.COM 	e = fmd_event_create(FMD_EVT_TOPO, ftp->ft_time_end, NULL, ftp);
1414198Seschrock 	fmd_modhash_dispatch(fmd.d_mod_hash, e);
1420Sstevel@tonic-gate }
143