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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2016 Nexenta Systems, Inc.
29 * datalink syseventd module.
31 * The purpose of this module is to identify all datalink related events,
32 * and react accordingly.
36 #include <sys/sysevent/eventdefs.h>
38 #include <libnvpair.h>
40 #include <libsysevent.h>
41 #include "sysevent_signal.h"
43 extern void syseventd_err_print(char *, ...);
47 struct event_list
*next
;
50 static rcm_handle_t
*rcm_hdl
= NULL
;
51 static boolean_t dl_exiting
;
52 static thread_t dl_notify_tid
;
55 static struct event_list
*dl_events
;
59 datalink_notify_thread(void *arg
)
61 struct event_list
*tmp_events
, *ep
;
63 (void) mutex_lock(&dl_mx
);
65 while (! dl_exiting
|| dl_events
!= NULL
) {
66 if (dl_events
== NULL
) {
67 (void) cond_wait(&dl_cv
, &dl_mx
);
71 tmp_events
= dl_events
;
74 (void) mutex_unlock(&dl_mx
);
76 while (tmp_events
!= NULL
) {
77 struct sigaction cbuf
, dfl
;
80 * Ignore SIGCLD for the
81 * duration of the rcm_notify_event call.
83 (void) memset(&dfl
, 0, sizeof (dfl
));
84 dfl
.sa_handler
= SIG_IGN
;
85 (void) sigaction(SIGCHLD
, &dfl
, &cbuf
);
88 * Send the PHYSLINK_NEW event to network_rcm to update
89 * the network devices cache accordingly.
91 if (rcm_notify_event(rcm_hdl
, RCM_RESOURCE_PHYSLINK_NEW
,
92 0, tmp_events
->ev
, NULL
) != RCM_SUCCESS
)
93 syseventd_err_print("datalink_mod: Can not "
94 "notify event: %s\n", strerror(errno
));
96 (void) sigaction(SIGCHLD
, &cbuf
, NULL
);
98 tmp_events
= tmp_events
->next
;
103 (void) mutex_lock(&dl_mx
);
106 (void) mutex_unlock(&dl_mx
);
113 datalink_deliver_event(sysevent_t
*ev
, int unused
)
115 const char *class = sysevent_get_class_name(ev
);
116 const char *subclass
= sysevent_get_subclass_name(ev
);
118 struct event_list
*newp
, **elpp
;
120 if (strcmp(class, EC_DATALINK
) != 0 ||
121 strcmp(subclass
, ESC_DATALINK_PHYS_ADD
) != 0) {
125 if (sysevent_get_attr_list(ev
, &nvl
) != 0)
129 * rcm_notify_event() needs to be called asynchronously otherwise when
130 * sysevent queue is full, deadlock will happen.
132 if ((newp
= malloc(sizeof (struct event_list
))) == NULL
)
139 * queue up at the end of the event list and signal notify_thread to
142 (void) mutex_lock(&dl_mx
);
144 while (*elpp
!= NULL
)
145 elpp
= &(*elpp
)->next
;
147 (void) cond_signal(&dl_cv
);
148 (void) mutex_unlock(&dl_mx
);
153 static struct slm_mod_ops datalink_mod_ops
= {
157 datalink_deliver_event
164 dl_exiting
= B_FALSE
;
166 if (rcm_alloc_handle(NULL
, 0, NULL
, &rcm_hdl
) != RCM_SUCCESS
)
169 (void) mutex_init(&dl_mx
, USYNC_THREAD
, NULL
);
170 (void) cond_init(&dl_cv
, USYNC_THREAD
, NULL
);
172 if (thr_create(NULL
, 0, datalink_notify_thread
, NULL
, 0,
173 &dl_notify_tid
) != 0) {
174 (void) rcm_free_handle(rcm_hdl
);
175 (void) mutex_destroy(&dl_mx
);
176 (void) cond_destroy(&dl_cv
);
180 return (&datalink_mod_ops
);
186 (void) mutex_lock(&dl_mx
);
188 (void) cond_signal(&dl_cv
);
189 (void) mutex_unlock(&dl_mx
);
190 (void) thr_join(dl_notify_tid
, NULL
, NULL
);
192 (void) mutex_destroy(&dl_mx
);
193 (void) cond_destroy(&dl_cv
);
194 (void) rcm_free_handle(rcm_hdl
);