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 /*
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * FMA event subscription interfaces - subscribe to FMA protocol
28 * from outside the fault manager.
29 */
30
31 #include <sys/types.h>
32 #include <atomic.h>
33 #include <libsysevent.h>
34 #include <libuutil.h>
35 #include <pthread.h>
36 #include <stdarg.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <strings.h>
40 #include <unistd.h>
41 #include <fm/libtopo.h>
42
43 #include <fm/libfmevent.h>
44
45 #include "fmev_impl.h"
46
188 {
189 fmev_shdl_impl_t *ihdl = HDL2IHDL(hdl);
190
191 if (!FMEV_API_ENTER(hdl, 1))
192 return (fmev_errno);
193
194 if (!shdlctl_start(ihdl))
195 return (fmev_seterr(FMEVERR_BUSY));
196
197 sysevent_subattr_thrcreate(ihdl->sh_attr, func, cookie);
198
199 shdlctl_end(ihdl);
200 return (fmev_seterr(FMEV_SUCCESS));
201 }
202
203 /*
204 * Our door service function. We return 0 regardless so that the kernel
205 * does not keep either retrying (EAGAIN) or bleat to cmn_err.
206 */
207
208 uint64_t fmev_proxy_cb_inval;
209 uint64_t fmev_proxy_cb_enomem;
210
211 int
212 fmev_proxy_cb(sysevent_t *sep, void *arg)
213 {
214 struct fmev_subinfo *sip = arg;
215 fmev_shdl_impl_t *ihdl = sip->si_ihdl;
216 nvlist_t *nvl;
217 char *class;
218 fmev_t ev;
219
220 if (sip == NULL || sip->si_cb == NULL) {
221 fmev_proxy_cb_inval++;
222 return (0);
223 }
224
225 if ((ev = fmev_sysev2fmev(IHDL2HDL(ihdl), sep, &class, &nvl)) == NULL) {
226 fmev_proxy_cb_enomem++;
227 return (0);
228 }
229
230 if (ihdl->sh_flags & SHDL_FL_SERIALIZE)
231 (void) pthread_mutex_lock(&ihdl->sh_srlz_lock);
232
233 sip->si_cb(ev, class, nvl, sip->si_cbarg);
234
235 if (ihdl->sh_flags & SHDL_FL_SERIALIZE)
236 (void) pthread_mutex_unlock(&ihdl->sh_srlz_lock);
237
238 fmev_rele(ev); /* release hold obtained in fmev_sysev2fmev */
239
240 return (0);
241 }
242
243 static volatile uint32_t fmev_subid;
244
|
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 /*
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright (c) 2018, Joyent, Inc.
28 */
29
30 /*
31 * FMA event subscription interfaces - subscribe to FMA protocol
32 * from outside the fault manager.
33 */
34
35 #include <sys/types.h>
36 #include <atomic.h>
37 #include <libsysevent.h>
38 #include <libuutil.h>
39 #include <pthread.h>
40 #include <stdarg.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <strings.h>
44 #include <unistd.h>
45 #include <fm/libtopo.h>
46
47 #include <fm/libfmevent.h>
48
49 #include "fmev_impl.h"
50
192 {
193 fmev_shdl_impl_t *ihdl = HDL2IHDL(hdl);
194
195 if (!FMEV_API_ENTER(hdl, 1))
196 return (fmev_errno);
197
198 if (!shdlctl_start(ihdl))
199 return (fmev_seterr(FMEVERR_BUSY));
200
201 sysevent_subattr_thrcreate(ihdl->sh_attr, func, cookie);
202
203 shdlctl_end(ihdl);
204 return (fmev_seterr(FMEV_SUCCESS));
205 }
206
207 /*
208 * Our door service function. We return 0 regardless so that the kernel
209 * does not keep either retrying (EAGAIN) or bleat to cmn_err.
210 */
211
212 uint64_t fmev_proxy_cb_enomem;
213
214 int
215 fmev_proxy_cb(sysevent_t *sep, void *arg)
216 {
217 struct fmev_subinfo *sip = arg;
218 fmev_shdl_impl_t *ihdl = sip->si_ihdl;
219 nvlist_t *nvl;
220 char *class;
221 fmev_t ev;
222
223 if ((ev = fmev_sysev2fmev(IHDL2HDL(ihdl), sep, &class, &nvl)) == NULL) {
224 fmev_proxy_cb_enomem++;
225 return (0);
226 }
227
228 if (ihdl->sh_flags & SHDL_FL_SERIALIZE)
229 (void) pthread_mutex_lock(&ihdl->sh_srlz_lock);
230
231 sip->si_cb(ev, class, nvl, sip->si_cbarg);
232
233 if (ihdl->sh_flags & SHDL_FL_SERIALIZE)
234 (void) pthread_mutex_unlock(&ihdl->sh_srlz_lock);
235
236 fmev_rele(ev); /* release hold obtained in fmev_sysev2fmev */
237
238 return (0);
239 }
240
241 static volatile uint32_t fmev_subid;
242
|