1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * FMD Dynamic Reconfiguration (DR) Event Handling 31 * 32 * Fault manager scheme plug-ins must track characteristics of individual 33 * pieces of hardware. As these components can be added or removed by a DR 34 * operation, we need to provide a means by which plug-ins can determine when 35 * they need to re-examine the current configuration. We provide a simple 36 * mechanism whereby this task can be implemented using lazy evaluation: a 37 * simple 64-bit generation counter is maintained and incremented on *any* DR. 38 * Schemes can store the generation number in scheme-specific data structures, 39 * and then revalidate their contents if the current generation number has 40 * changed since the resource information was cached. This method saves time, 41 * avoids the complexity of direct participation in DR, avoids the need for 42 * resource-specific processing of DR events, and is relatively easy to port 43 * to other systems that support dynamic reconfiguration. 44 */ 45 46 #include <sys/types.h> 47 #include <sys/sysevent/dr.h> 48 #include <sys/sysevent/eventdefs.h> 49 50 #include <stdio.h> 51 #include <unistd.h> 52 #include <libsysevent.h> 53 54 #undef MUTEX_HELD 55 #undef RW_READ_HELD 56 #undef RW_WRITE_HELD 57 58 #include <fmd_error.h> 59 #include <fmd_subr.h> 60 #include <fmd.h> 61 62 static void 63 fmd_dr_event(sysevent_t *sep) 64 { 65 uint64_t gen; 66 67 (void) pthread_mutex_lock(&fmd.d_stats_lock); 68 gen = fmd.d_stats->ds_dr_gen.fmds_value.ui64++; 69 (void) pthread_mutex_unlock(&fmd.d_stats_lock); 70 71 TRACE((FMD_DBG_XPRT, "dr event %p, gen=%llu", (void *)sep, gen)); 72 } 73 74 void 75 fmd_dr_init(void) 76 { 77 const char *subclass = ESC_DR_AP_STATE_CHANGE; 78 79 if (geteuid() != 0) 80 return; /* legacy sysevent mechanism is still root-only */ 81 82 if ((fmd.d_dr_hdl = sysevent_bind_handle(fmd_dr_event)) == NULL) 83 fmd_error(EFMD_EXIT, "failed to bind handle for DR sysevent"); 84 85 if (sysevent_subscribe_event(fmd.d_dr_hdl, EC_DR, &subclass, 1) == -1) 86 fmd_error(EFMD_EXIT, "failed to subscribe for DR sysevent"); 87 } 88 89 void 90 fmd_dr_fini(void) 91 { 92 if (fmd.d_dr_hdl != NULL) { 93 sysevent_unsubscribe_event(fmd.d_dr_hdl, EC_DR); 94 sysevent_unbind_handle(fmd.d_dr_hdl); 95 } 96 } 97