summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/ddi_log_sysevent.9f
blob: 6194c137da9f5d52a8e7f554ea87f34c877dd3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
'\" te
.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH DDI_LOG_SYSEVENT 9F "Jan 16, 2006"
.SH NAME
ddi_log_sysevent \- log system event for drivers
.SH SYNOPSIS
.LP
.nf
#include <sys/ddi.h>
#include <sys/sunddi.h>



\fBint\fR \fBddi_log_sysevent\fR(\fBdev_info_t *\fR\fIdip\fR, \fBchar *\fR\fIvendor\fR,
     \fBchar *\fR\fIclass\fR, \fBchar *\fR\fIsubclass\fR, \fBnvlist_t *\fR\fIattr_list\fR,
     \fBsysevent_id_t *\fR\fIeidp\fR, \fBint\fR \fIsleep_flag\fR);
.fi

.SH INTERFACE LEVEL
.sp
.LP
Solaris DDI specific (Solaris DDI).
.SH PARAMETERS
.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 14n
A pointer to the \fBdev_info\fR node for this driver.
.RE

.sp
.ne 2
.na
\fB\fIvendor\fR\fR
.ad
.RS 14n
A pointer to a string defining the vendor. Third-party drivers should use their
company's stock symbol (or similarly enduring identifier). Sun-supplied drivers
should use \fBDDI_VENDOR_SUNW\fR.
.RE

.sp
.ne 2
.na
\fB\fIclass\fR\fR
.ad
.RS 14n
A pointer to a string defining the event class.
.RE

.sp
.ne 2
.na
\fB\fIsubclass\fR\fR
.ad
.RS 14n
A pointer to a string defining the event subclass.
.RE

.sp
.ne 2
.na
\fB\fIattr_list\fR\fR
.ad
.RS 14n
A pointer to an \fBnvlist_t\fR, listing the name-value attributes associated
with the event or NULL if there are no such attributes for this event.
.RE

.sp
.ne 2
.na
\fB\fIeidp\fR\fR
.ad
.RS 14n
The address of a \fBsysevent_id_t\fR structure in which the event's sequence
number and timestamp are returned if the event is successfully queued. May be
NULL if this information is not of interest. See below for the definition of
\fBsysevent_id_t\fR.
.RE

.sp
.ne 2
.na
\fB\fIsleep_flag\fR\fR
.ad
.RS 14n
Indicates how a caller wants to handle the possibility of resources not being
available. If \fIsleep_flag\fR is \fBDDI_NOSLEEP\fR, the caller does not care
if the allocation fails or the queue is full and can handle a failure
appropriately. If \fBsleep_flag\fR is \fBDDI_SLEEP\fR, the caller wishes to
have the allocation and queuing routines wait for resources to become
available.
.RE

.SH DESCRIPTION
.sp
.LP
The \fBddi_log_sysevent()\fR function causes a system event, of the specified
class and subclass, to be generated on behalf of the driver and queued for
delivery to \fBsyseventd\fR, the user-land \fBsysevent\fR daemon.
.sp
.LP
The publisher string for the event is constructed using the vendor name and
driver name, with the format:
.sp
.in +2
.nf
"\fI<vendor>\fR:kern:\fI<driver-name>\fR"
.fi
.in -2
.sp

.sp
.LP
The two fields of \fBeidp\fR, \fBeid_seq\fR and \fBeid_ts\fR, are sufficient to
uniquely identify an event.
.SH STRUCTURE MEMBERS
.sp
.LP
The structure members of \fBsysevent_id_t\fR are:
.sp
.in +2
.nf
     uint64_t   eid_seq;        /* sysevent sequence number */
     hrtime_t   eid_ts;         /* sysevent timestamp */
.fi
.in -2

.SH RETURN VALUES
.sp
.LP
The \fBddi_log_sysevent()\fR function returns:
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 18n
The event has been queued for delivery successfully.
.RE

.sp
.ne 2
.na
\fB\fBDDI_ENOMEM\fR\fR
.ad
.RS 18n
There is not enough memory to queue the system event at this time.
\fBDDI_ENOMEM\fR cannot be returned when \fIsleep_flag\fR is \fBDDI_SLEEP\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_EBUSY\fR\fR
.ad
.RS 18n
The system event queue is full at this time. \fBDDI_EBUSY\fR cannot be returned
when \fIsleep_flag\fR is \fBDDI_SLEEP\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_ETRANSPORT\fR\fR
.ad
.RS 18n
The \fBsyseventd\fR daemon is not responding and events cannot be queued or
delivered at this time. \fBDDI_ETRANSPORT\fR can be returned even when
\fIsleep_flag\fR is \fBDDI_SLEEP\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_ECONTEXT\fR\fR
.ad
.RS 18n
\fIsleep_flag\fR is DDI_SLEEP and the driver is running in interrupt context.
.RE

.sp
.LP
\fBddi_log_sysevent\fR supports the following data types:
.br
.in +2
DATA_TYPE_BYTE
.in -2
.br
.in +2
DATA_TYPE_INT16
.in -2
.br
.in +2
DATA_TYPE_UINT16
.in -2
.br
.in +2
DATA_TYPE_INT32
.in -2
.br
.in +2
DATA_TYPE_UINT32
.in -2
.br
.in +2
DATA_TYPE_INT64
.in -2
.br
.in +2
DATA_TYPE_UINT64
.in -2
.br
.in +2
DATA_TYPE_STRING
.in -2
.br
.in +2
DATA_TYPE_BYTE_ARRAY
.in -2
.br
.in +2
DATA_TYPE_INT16_ARRAY
.in -2
.br
.in +2
DATA_TYPE_UINT16_ARRAY
.in -2
.br
.in +2
DATA_TYPE_INT32_ARRAY
.in -2
.br
.in +2
DATA_TYPE_UINT32_ARRAY
.in -2
.br
.in +2
DATA_TYPE_INT64_ARRAY
.in -2
.br
.in +2
DATA_TYPE_UINT64_ARRAY
.in -2
.SH CONTEXT
.sp
.LP
The \fBddi_log_sysevent()\fR function can be called from user, interrupt, or
kernel context, except when \fIsleep_flag\fR is \fBDDI_SLEEP\fR, in which case
it cannot be called from interrupt context.
.SH EXAMPLES
.LP
\fBExample 1 \fRLogging System Event with No Attributes
.sp
.in +2
.nf
    if (ddi_log_sysevent(dip, DDI_VENDOR_SUNW, "class", "subclass",
        NULL, NULL, DDI_SLEEP) != DDI_SUCCESS) {
        cmn_err(CE_WARN, "error logging system event\en");
    }
.fi
.in -2

.LP
\fBExample 2 \fRLogging System Event with Two Name/Value Attributes, an Integer
and a String
.sp
.in +2
.nf
nvlist_t    *attr_list;
sysevent_id_t   eid;

if (nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_SLEEP) == 0)
{
    err = nvlist_add_uint32(attr_list, int_name, int_value);
    if (err == 0)
        err = nvlist_add_string(attr_list, str_name, str_value);
    if (err == 0)
        err = ddi_log_sysevent(dip, DDI_VENDOR_SUNW,
          "class", "subclass", attr_list, &eid, DDI_SLEEP);
    if (err != DDI_SUCCESS)
        cmn_err(CE_WARN, "error logging system event\en");
    nvlist_free(attr_list);
    }
.fi
.in -2

.LP
\fBExample 3 \fRUse Timeout to Handle \fBnvlist\fR and System Event Resource
Allocation Failures
.sp
.LP
Since no blocking calls are made, this example would be useable from a driver
needing to generate an event from interrupt context.

.sp
.in +2
.nf
static int
    xx_se_timeout_handler(xx_state_t *xx)
    {
        xx->xx_timeoutid = (xx_generate_event(xx) ?
            timeout(xx_se_timeout_handler, xx, 4) : 0);
    }

    static int
    xx_generate_event(xx_state_t *xx)
    {
        int err;

        err = nvlist_alloc(&xx->xx_ev_attrlist, NV_UNIQUE_NAME_TYPE, 0);
        if (err != 0)
            return (1);
        err = nvlist_add_uint32(&xx->xx_ev_attrlist,
            xx->xx_ev_name, xx->xx_ev_value);
        if (err != 0) {
            nvlist_free(xx->xx_ev_attrlist);
            return(1);
        }

        err = ddi_log_sysevent(xx->xx_dip, DDI_VENDOR_SUNW,
            xx->xx_ev_class, xx->xx_ev_sbclass,
            xx->xx_ev_attrlist, NULL, DDI_NOSLEEP);
        nvlist_free(xx->xx_ev_attrlist);
        if (err == DDI_SUCCESS || err == DDI_ETRANSPORT) {
            if (err == DDI_ETRANSPORT)
                cmn_err(CE_WARN, "cannot log system event\en");
            return (0);
        }
        return (1);
    }
.fi
.in -2

.SH SEE ALSO
.sp
.LP
\fBsyseventd\fR(1M), \fBattributes\fR(5), \fBnvlist_add_boolean\fR(9F),
\fBnvlist_alloc\fR(9F)
.sp
.LP
\fIWriting Device Drivers\fR