17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5724365f7Ssethg * Common Development and Distribution License (the "License"). 6724365f7Ssethg * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*e5dcf7beSRobert Johnston * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * FMD Dynamic Reconfiguration (DR) Event Handling 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * Fault manager scheme plug-ins must track characteristics of individual 307c478bd9Sstevel@tonic-gate * pieces of hardware. As these components can be added or removed by a DR 317c478bd9Sstevel@tonic-gate * operation, we need to provide a means by which plug-ins can determine when 327c478bd9Sstevel@tonic-gate * they need to re-examine the current configuration. We provide a simple 337c478bd9Sstevel@tonic-gate * mechanism whereby this task can be implemented using lazy evaluation: a 347c478bd9Sstevel@tonic-gate * simple 64-bit generation counter is maintained and incremented on *any* DR. 357c478bd9Sstevel@tonic-gate * Schemes can store the generation number in scheme-specific data structures, 367c478bd9Sstevel@tonic-gate * and then revalidate their contents if the current generation number has 377c478bd9Sstevel@tonic-gate * changed since the resource information was cached. This method saves time, 387c478bd9Sstevel@tonic-gate * avoids the complexity of direct participation in DR, avoids the need for 397c478bd9Sstevel@tonic-gate * resource-specific processing of DR events, and is relatively easy to port 407c478bd9Sstevel@tonic-gate * to other systems that support dynamic reconfiguration. 4124db4641Seschrock * 4224db4641Seschrock * The dr generation is only incremented in response to hardware changes. Since 4324db4641Seschrock * ASRUs can be in any scheme, including the device scheme, we must also be 4424db4641Seschrock * aware of software configuration changes which may affect the resource cache. 4524db4641Seschrock * In addition, we take a snapshot of the topology whenever a reconfiguration 4624db4641Seschrock * event occurs and notify any modules of the change. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #include <sys/types.h> 5024db4641Seschrock #include <sys/sunddi.h> 517c478bd9Sstevel@tonic-gate #include <sys/sysevent/dr.h> 527c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include <stdio.h> 5524db4641Seschrock #include <string.h> 56d9638e54Smws #include <unistd.h> 577c478bd9Sstevel@tonic-gate #include <libsysevent.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #undef MUTEX_HELD 607c478bd9Sstevel@tonic-gate #undef RW_READ_HELD 617c478bd9Sstevel@tonic-gate #undef RW_WRITE_HELD 627c478bd9Sstevel@tonic-gate 63724365f7Ssethg #include <fmd_asru.h> 647c478bd9Sstevel@tonic-gate #include <fmd_error.h> 6524db4641Seschrock #include <fmd_event.h> 66724365f7Ssethg #include <fmd_fmri.h> 6724db4641Seschrock #include <fmd_module.h> 687c478bd9Sstevel@tonic-gate #include <fmd_subr.h> 6924db4641Seschrock #include <fmd_topo.h> 707c478bd9Sstevel@tonic-gate #include <fmd.h> 717c478bd9Sstevel@tonic-gate 729af3851aSeschrock void 7324db4641Seschrock fmd_dr_event(sysevent_t *sep) 74724365f7Ssethg { 7524db4641Seschrock uint64_t gen; 7624db4641Seschrock fmd_event_t *e; 7724db4641Seschrock const char *class = sysevent_get_class_name(sep); 789af3851aSeschrock const char *subclass = sysevent_get_subclass_name(sep); 7924db4641Seschrock hrtime_t evtime; 8024db4641Seschrock fmd_topo_t *ftp, *prev; 8124db4641Seschrock boolean_t update_topo = B_FALSE; 82724365f7Ssethg 8324db4641Seschrock if (strcmp(class, EC_DR) == 0) { 849af3851aSeschrock if (strcmp(subclass, ESC_DR_AP_STATE_CHANGE) != 0 && 859af3851aSeschrock strcmp(subclass, ESC_DR_TARGET_STATE_CHANGE) != 0) 869af3851aSeschrock return; 879af3851aSeschrock 889af3851aSeschrock /* 899af3851aSeschrock * The DR generation is only changed in response to DR events. 909af3851aSeschrock */ 9124db4641Seschrock update_topo = B_TRUE; 92724365f7Ssethg 9324db4641Seschrock (void) pthread_mutex_lock(&fmd.d_stats_lock); 9424db4641Seschrock gen = fmd.d_stats->ds_dr_gen.fmds_value.ui64++; 9524db4641Seschrock (void) pthread_mutex_unlock(&fmd.d_stats_lock); 9624db4641Seschrock 9724db4641Seschrock TRACE((FMD_DBG_XPRT, "dr event %p, gen=%llu", 9824db4641Seschrock (void *)sep, gen)); 999af3851aSeschrock } else if (strcmp(class, EC_DEVFS) == 0) { 1009af3851aSeschrock /* 1019af3851aSeschrock * A devfs configuration event can change the topology, 1029af3851aSeschrock * as disk nodes only exist when the device is configured. 1039af3851aSeschrock */ 1049af3851aSeschrock update_topo = B_TRUE; 105*e5dcf7beSRobert Johnston } else if (strcmp(class, EC_PLATFORM) == 0) { 106*e5dcf7beSRobert Johnston if (strcmp(subclass, ESC_PLATFORM_SP_RESET) == 0) { 107*e5dcf7beSRobert Johnston /* 108*e5dcf7beSRobert Johnston * Since we rely on the SP to enumerate fans, 109*e5dcf7beSRobert Johnston * power-supplies and sensors/leds, it would be prudent 110*e5dcf7beSRobert Johnston * to take a new snapshot if the SP resets. 111*e5dcf7beSRobert Johnston */ 112*e5dcf7beSRobert Johnston update_topo = B_TRUE; 113*e5dcf7beSRobert Johnston } 1149af3851aSeschrock } else if (strcmp(class, EC_ZFS) == 0) { 1159af3851aSeschrock /* 1169af3851aSeschrock * These events can change the resource cache. 1179af3851aSeschrock */ 1189af3851aSeschrock if (strcmp(subclass, ESC_ZFS_VDEV_CLEAR) != 0 && 1199af3851aSeschrock strcmp(subclass, ESC_ZFS_VDEV_REMOVE) != 0 && 1209af3851aSeschrock strcmp(subclass, ESC_ZFS_POOL_DESTROY) != 0) 1219af3851aSeschrock return; 1229af3851aSeschrock } else if (strcmp(class, EC_DEV_ADD) == 0 || 1239af3851aSeschrock strcmp(class, EC_DEV_REMOVE) == 0) { 1249af3851aSeschrock if (strcmp(subclass, ESC_DISK) != 0) 1259af3851aSeschrock return; 12624db4641Seschrock } 1277c478bd9Sstevel@tonic-gate 128724365f7Ssethg /* 12924db4641Seschrock * Take a topo snapshot and notify modules of the change. Picking an 13024db4641Seschrock * accurate time here is difficult. On one hand, we have the timestamp 13124db4641Seschrock * of the underlying sysevent, indicating when the reconfiguration event 13224db4641Seschrock * occurred. On the other hand, we are taking the topo snapshot 13324db4641Seschrock * asynchronously, and hence the timestamp of the snapshot is the 13424db4641Seschrock * current time. Pretending this topo snapshot was valid at the time 13524db4641Seschrock * the sysevent was posted seems wrong, so we instead opt for the 13624db4641Seschrock * current time as an upper bound on the snapshot validity. 13724db4641Seschrock * 13824db4641Seschrock * Along these lines, we keep track of the last time we dispatched a 13924db4641Seschrock * topo snapshot. If the sysevent occurred before the last topo 14024db4641Seschrock * snapshot, then don't bother dispatching another topo change event. 14124db4641Seschrock * We've already indicated (to the best of our ability) the change in 14224db4641Seschrock * topology. This prevents endless topo snapshots in response to a 14324db4641Seschrock * flurry of sysevents. 144724365f7Ssethg */ 14524db4641Seschrock sysevent_get_time(sep, &evtime); 14624db4641Seschrock prev = fmd_topo_hold(); 14724db4641Seschrock if (evtime <= prev->ft_time && 14824db4641Seschrock fmd.d_clockops == &fmd_timeops_native) { 14924db4641Seschrock fmd_topo_rele(prev); 15024db4641Seschrock return; 15124db4641Seschrock } 15224db4641Seschrock fmd_topo_rele(prev); 153724365f7Ssethg 15424db4641Seschrock if (update_topo) 15524db4641Seschrock fmd_topo_update(); 1567c478bd9Sstevel@tonic-gate 15724db4641Seschrock ftp = fmd_topo_hold(); 15824db4641Seschrock e = fmd_event_create(FMD_EVT_TOPO, ftp->ft_time, NULL, ftp); 15924db4641Seschrock fmd_modhash_dispatch(fmd.d_mod_hash, e); 1607c478bd9Sstevel@tonic-gate } 161