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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * datalink syseventd module. 28 * 29 * The purpose of this module is to identify all datalink related events, 30 * and react accordingly. 31 */ 32 33 #include <errno.h> 34 #include <sys/sysevent/eventdefs.h> 35 #include <string.h> 36 #include <libnvpair.h> 37 #include <librcm.h> 38 #include <libsysevent.h> 39 40 static rcm_handle_t *rcm_hdl = NULL; 41 42 /*ARGSUSED*/ 43 static int 44 datalink_deliver_event(sysevent_t *ev, int unused) 45 { 46 const char *class = sysevent_get_class_name(ev); 47 const char *subclass = sysevent_get_subclass_name(ev); 48 nvlist_t *nvl; 49 int err = 0; 50 51 if (strcmp(class, EC_DATALINK) != 0 || 52 strcmp(subclass, ESC_DATALINK_PHYS_ADD) != 0) { 53 return (0); 54 } 55 56 if (sysevent_get_attr_list(ev, &nvl) != 0) 57 return (EINVAL); 58 59 if (rcm_notify_event(rcm_hdl, RCM_RESOURCE_LINK_NEW, 0, nvl, NULL) != 60 RCM_SUCCESS) { 61 err = EINVAL; 62 } 63 64 nvlist_free(nvl); 65 return (err); 66 } 67 68 static struct slm_mod_ops datalink_mod_ops = { 69 SE_MAJOR_VERSION, 70 SE_MINOR_VERSION, 71 SE_MAX_RETRY_LIMIT, 72 datalink_deliver_event 73 }; 74 75 struct slm_mod_ops * 76 slm_init() 77 { 78 if (rcm_alloc_handle(NULL, 0, NULL, &rcm_hdl) != RCM_SUCCESS) 79 return (NULL); 80 81 return (&datalink_mod_ops); 82 } 83 84 void 85 slm_fini() 86 { 87 (void) rcm_free_handle(rcm_hdl); 88 rcm_hdl = NULL; 89 } 90