Print this page
patch more-manpage
patch cleanup
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man9f/nvlist_alloc.9f
+++ new/usr/src/man/man9f/nvlist_alloc.9f
1 1 '\" te
2 2 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
3 3 .\" 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.
4 4 .\" 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.
5 5 .\" 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]
6 -.TH NVLIST_ALLOC 9F "Jan 16, 2006"
6 +.TH NVLIST_ALLOC 9F "Feb 15, 2016"
7 7 .SH NAME
8 8 nvlist_alloc, nvlist_free, nvlist_size, nvlist_pack, nvlist_unpack, nvlist_dup,
9 9 nv_alloc_init, nv_alloc_fini, nvlist_xalloc, nvlist_xpack, nvlist_xunpack,
10 10 nvlist_xdup, nvlist_merge \- Manage a name-value pair list
11 11 .SH SYNOPSIS
12 12 .LP
13 13 .nf
14 14 #include <sys/nvpair.h>
15 15
16 16 List Manipulation:
17 17
18 18 \fBint\fR \fBnvlist_alloc\fR(\fBnvlist_t **\fR\fInvlp\fR, \fBuint_t\fR \fInvflag\fR,
19 19 \fBint\fR \fIkmflag\fR);
20 20 .fi
21 21
22 22 .LP
23 23 .nf
24 24 \fBint\fR \fBnvlist_xalloc\fR(\fBnvlist_t **\fR\fInvlp\fR, \fBuint_t\fR \fInvflag\fR, \fBnv_alloc_t *\fR\fInva\fR);
25 25 .fi
26 26
27 27 .LP
28 28 .nf
29 29 \fBvoid\fR \fBnvlist_free\fR(\fBnvlist_t *\fR\fInvl\fR);
30 30 .fi
31 31
32 32 .LP
33 33 .nf
34 34 \fBint\fR \fBnvlist_size\fR(\fBnvlist_t *\fR\fInvl\fR, \fBsize_t *\fR\fIsize\fR, \fBint\fR \fIencoding\fR);
35 35 .fi
36 36
37 37 .LP
38 38 .nf
39 39 \fBint\fR \fBnvlist_pack\fR(\fBnvlist_t *\fR\fInvl\fR, \fBchar **\fR\fIbufp\fR, \fBsize_t *\fR\fIbuflen\fR, \fBint\fR \fIencoding\fR,
40 40 \fBint\fR \fIflag\fR);
41 41 .fi
42 42
43 43 .LP
44 44 .nf
45 45 \fBint\fR \fBnvlist_xpack\fR(\fBnvlist_t *\fR\fInvl\fR, \fBchar **\fR\fIbufp\fR, \fBsize_t *\fR\fIbuflen\fR, \fBint\fR \fIencoding\fR,
46 46 \fBnv_alloc_t *\fR\fInva\fR);
47 47 .fi
48 48
49 49 .LP
50 50 .nf
51 51 \fBint\fR \fBnvlist_unpack\fR(\fBchar *\fR\fIbuf\fR, \fBsize_t\fR \fIbuflen\fR, \fBnvlist_t **\fR\fInvlp\fR, \fBint\fR \fIflag\fR);
52 52 .fi
53 53
54 54 .LP
55 55 .nf
56 56 \fBint\fR \fBnvlist_xunpack\fR(\fBchar *\fR\fIbuf\fR, \fBsize_t\fR \fIbuflen\fR, \fBnvlist_t **\fR\fInvlp\fR,
57 57 \fBnv_alloc_t *\fR\fInva\fR);
58 58 .fi
59 59
60 60 .LP
61 61 .nf
62 62 \fBint\fR \fBnvlist_dup\fR(\fBnvlist_t *\fR\fInvl\fR, \fBnvlist_t **\fR\fInvlp\fR, \fBint\fR \fIflag\fR);
63 63 .fi
64 64
65 65 .LP
66 66 .nf
67 67 \fBint\fR \fBnvlist_xdup\fR(\fBnvlist_t *\fR\fInvl\fR, \fBnvlist_t **\fR\fInvlp\fR, \fBnv_alloc_t *\fR\fInva\fR);
68 68 .fi
69 69
70 70 .LP
71 71 .nf
72 72 \fBint\fR \fBnvlist_merge\fR(\fBnvlist_t *\fR\fIdst\fR, \fBnvlist_t *\fR\fInvl\fR, \fBint\fR \fIflag\fR);
73 73 .fi
74 74
75 75 .LP
76 76 .nf
77 77 Pluggable Allocator Configuration:
78 78
79 79 \fBnv_alloc_t *\fR\fBnvlist_lookup_nv_alloc\fR(\fBnvlist_t *);\fR
80 80 .fi
81 81
82 82 .LP
83 83 .nf
84 84 \fBint\fR \fBnv_alloc_init\fR(\fBnv_alloc_t *\fR\fInva\fR,
85 85 \fBconst nv_alloc_ops_t *\fR \fInvo,\fR/* args */ ...);
86 86 .fi
87 87
88 88 .LP
89 89 .nf
90 90 \fBvoid\fR \fBnv_alloc_reset\fR(\fBnv_alloc_t *\fR\fInva\fR);
91 91 .fi
92 92
93 93 .LP
94 94 .nf
95 95 \fBvoid\fR \fBnv_alloc_fini\fR(\fBnv_alloc_t *\fR\fInva\fR);
96 96 .fi
97 97
98 98 .LP
99 99 .nf
100 100 Pluggable Allocation Initialization with Fixed Allocator:
101 101
102 102 \fBint\fR \fBnv_alloc_init\fR(\fBnv_alloc_t *\fR\fInva\fR,
103 103 \fBnv_fixed_ops\fR, \fBvoid *\fR \fIbufptr\fR, \fBsize_t\fR sz);
104 104 .fi
105 105
106 106 .SH INTERFACE LEVEL
107 107 .sp
108 108 .LP
109 109 Solaris DDI specific (Solaris DDI)
110 110 .SH PARAMETERS
111 111 .sp
112 112 .ne 2
113 113 .na
114 114 \fB\fInvlp\fR\fR
115 115 .ad
116 116 .RS 12n
117 117 Address of a pointer to list of name-value pairs (\fBnvlist_t\fR).
118 118 .RE
119 119
120 120 .sp
121 121 .ne 2
122 122 .na
123 123 \fB\fInvflag\fR\fR
124 124 .ad
125 125 .RS 12n
126 126 Specify bit fields defining \fBnvlist_t\fR properties:
127 127 .sp
128 128 .ne 2
129 129 .na
130 130 \fB\fBNV_UNIQUE_NAME\fR\fR
131 131 .ad
132 132 .RS 23n
133 133 \fBnvpair\fR names are unique.
134 134 .RE
135 135
136 136 .sp
137 137 .ne 2
138 138 .na
139 139 \fB\fBNV_UNIQUE_NAME_TYPE\fR\fR
140 140 .ad
141 141 .RS 23n
142 142 Name-data type combination is unique
143 143 .RE
144 144
145 145 .RE
146 146
147 147 .sp
148 148 .ne 2
149 149 .na
150 150 \fB\fIkmflag\fR\fR
151 151 .ad
152 152 .RS 12n
153 153 Kernel memory allocation policy, either \fBKM_SLEEP\fR or \fBKM_NOSLEEP\fR.
154 154 .RE
155 155
156 156 .sp
157 157 .ne 2
158 158 .na
159 159 \fB\fInvl\fR\fR
160 160 .ad
161 161 .RS 12n
162 162 \fBnvlist_t\fR to be processed.
163 163 .RE
164 164
165 165 .sp
166 166 .ne 2
167 167 .na
168 168 \fB\fIdst\fR\fR
169 169 .ad
170 170 .RS 12n
171 171 Destination \fBnvlist_t\fR.
172 172 .RE
173 173
174 174 .sp
175 175 .ne 2
176 176 .na
177 177 \fB\fIsize\fR\fR
178 178 .ad
179 179 .RS 12n
180 180 Pointer to buffer to contain the encoded size.
181 181 .RE
182 182
183 183 .sp
184 184 .ne 2
185 185 .na
186 186 \fB\fIbufp\fR\fR
187 187 .ad
188 188 .RS 12n
189 189 Address of buffer to pack \fBnvlist\fR into. Must be 8-byte aligned. If NULL,
190 190 library will allocate memory.
191 191 .RE
192 192
193 193 .sp
194 194 .ne 2
195 195 .na
196 196 \fB\fIbuf\fR\fR
197 197 .ad
198 198 .RS 12n
199 199 Buffer containing packed \fBnvlist_t\fR.
200 200 .RE
201 201
202 202 .sp
203 203 .ne 2
204 204 .na
205 205 \fB\fIbuflen\fR\fR
206 206 .ad
207 207 .RS 12n
208 208 Size of buffer \fIbufp\fR or \fIbuf\fR points to.
209 209 .RE
210 210
211 211 .sp
212 212 .ne 2
213 213 .na
214 214 \fB\fIencoding\fR\fR
215 215 .ad
216 216 .RS 12n
217 217 Encoding method for packing.
218 218 .RE
219 219
220 220 .sp
221 221 .ne 2
222 222 .na
223 223 \fB\fInvo\fR\fR
224 224 .ad
225 225 .RS 12n
226 226 Pluggable allocator operations pointer (nv_alloc_ops_t).
227 227 .RE
228 228
229 229 .sp
230 230 .ne 2
231 231 .na
232 232 \fB\fInva\fR\fR
233 233 .ad
234 234 .RS 12n
235 235 Points to a nv_alloc_t structure to be used for the specified \fBnvlist_t\fR.
236 236 .RE
237 237
238 238 .SH DESCRIPTION
239 239 .sp
240 240 .LP
241 241 List Manipulation:
242 242 .sp
243 243 .LP
244 244 The \fBnvlist_alloc()\fR function allocates a new name-value pair list and
245 245 updates \fInvlp\fR to point to the handle. The argument \fInvflag\fR specifies
246 246 \fBnvlist_t\fR properties to remain persistent across packing, unpacking, and
247 247 duplication.
248 248 .sp
249 249 .LP
250 250 If \fBNV_UNIQUE_NAME\fR is specified for nvflag, existing nvpairs with matching
251 251 names are removed before the new nvpair is added. If \fBNV_UNIQUE_NAME_TYPE\fR
↓ open down ↓ |
235 lines elided |
↑ open up ↑ |
252 252 is specified for nvflag, existing nvpairs with matching names and data types
253 253 are removed before the new nvpair is added. See \fBnvlist_add_byte\fR(9F) for
254 254 more details.
255 255 .sp
256 256 .LP
257 257 The \fBnvlist_xalloc()\fR function differs from \fBnvlist_alloc()\fR in that
258 258 \fBnvlist_xalloc()\fR can use a different allocator, as described in the
259 259 Pluggable Allocators section.
260 260 .sp
261 261 .LP
262 -The \fBnvlist_free()\fR function frees a name-value pair list.
262 +The \fBnvlist_free()\fR function frees a name-value pair list. If \fInvl\fR
263 +is a null pointer, no action occurs.
263 264 .sp
264 265 .LP
265 266 The \fBnvlist_size()\fR function returns the minimum size of a contiguous
266 267 buffer large enough to pack \fInvl\fR. The \fIencoding\fR parameter specifies
267 268 the method of encoding when packing \fInvl\fR. Supported encoding methods are:
268 269 .sp
269 270 .ne 2
270 271 .na
271 272 \fB\fBNV_ENCODE_NATIVE\fR\fR
272 273 .ad
273 274 .RS 20n
274 275 Straight \fBbcopy()\fR as described in \fBbcopy\fR(9F).
275 276 .RE
276 277
277 278 .sp
278 279 .ne 2
279 280 .na
280 281 \fB\fBNV_ENCODE_XDR\fR\fR
281 282 .ad
282 283 .RS 20n
283 284 Use XDR encoding, suitable for sending to another host.
284 285 .RE
285 286
286 287 .sp
287 288 .LP
288 289 The \fBnvlist_pack()\fR function packs \fInvl\fR into contiguous memory
289 290 starting at *\fIbufp\fR. The \fIencoding\fR parameter specifies the method of
290 291 encoding (see above).
291 292 .RS +4
292 293 .TP
293 294 .ie t \(bu
294 295 .el o
295 296 If *\fIbufp\fR is not NULL, *\fIbufp\fR is expected to be a caller-allocated
296 297 buffer of size *\fIbuflen\fR. The \fIkmflag\fR argument is ignored.
297 298 .RE
298 299 .RS +4
299 300 .TP
300 301 .ie t \(bu
301 302 .el o
302 303 If *\fIbufp\fR is NULL, the library allocates memory and updates *\fIbufp\fR to
303 304 point to the memory and updates *\fIbuflen\fR to contain the size of the
304 305 allocated memory. The value of \fIkmflag\fR indicates the memory allocation
305 306 policy
306 307 .RE
307 308 .sp
308 309 .LP
309 310 The \fBnvlist_xpack()\fR function differs from \fBnvlist_pack()\fR in that
310 311 \fBnvlist_xpack()\fR can use a different allocator.
311 312 .sp
312 313 .LP
313 314 The \fBnvlist_unpack()\fR function takes a buffer with a packed \fBnvlist_t\fR
314 315 and unpacks it into a searchable \fBnvlist_t\fR. The library allocates memory
315 316 for \fBnvlist_t\fR. The caller is responsible for freeing the memory by calling
316 317 \fBnvlist_free()\fR.
317 318 .sp
318 319 .LP
319 320 The \fBnvlist_xunpack()\fR function differs from \fBnvlist_unpack()\fR in that
320 321 \fBnvlist_xunpack()\fR can use a different allocator.
321 322 .sp
322 323 .LP
323 324 The \fBnvlist_dup()\fR function makes a copy of \fInvl\fR and updates
324 325 \fInvlp\fR to point to the copy.
325 326 .sp
326 327 .LP
327 328 The \fBnvlist_xdup()\fR function differs from \fBnvlist_dup()\fR in that
328 329 \fBnvlist_xdup()\fR can use a different allocator.
329 330 .sp
330 331 .LP
331 332 The \fBnvlist_merge()\fR function adds copies of all name-value pairs from
332 333 \fBnvlist_t\fR \fInvl\fR to \fBnvlist_t dst\fR. Name-value pairs in dst are
333 334 replaced with name-value pairs from \fBnvl\fR which have identical names (if
334 335 dst has the type \fBNV_UNIQUE_NAME\fR), or identical names and types (if dst
335 336 has the type \fBNV_UNIQUE_NAME_TYPE\fR).
336 337 .sp
337 338 .LP
338 339 The \fBnvlist_lookup_nv_alloc()\fR function retrieves the pointer to the
339 340 allocator used when manipulating a name-value pair list.
340 341 .SS "PLUGGABLE ALLOCATORS"
341 342 .sp
342 343 .LP
343 344 Using Pluggable Allocators:
344 345 .sp
345 346 .LP
346 347 The \fBnv_alloc_init()\fR, \fBnv_alloc_reset()\fR and \fBnv_alloc_fini()\fR
347 348 functions provide an interface that specifies the allocator to be used when
348 349 manipulating a name-value pair list.
349 350 .sp
350 351 .LP
351 352 The \fBnv_alloc_init()\fR determines allocator properties and puts them into
352 353 the \fInva\fR argument. You need to specify the \fInv_arg\fR argument, the
353 354 \fInvo\fR argument and an optional variable argument list. The optional
354 355 arguments are passed to the (*\fBnv_ao_init()\fR) function.
355 356 .sp
356 357 .LP
357 358 The \fInva\fR argument must be passed to \fBnvlist_xalloc()\fR,
358 359 \fBnvlist_xpack()\fR, \fBnvlist_xunpack()\fR and \fBnvlist_xdup()\fR.
359 360 .sp
360 361 .LP
361 362 The \fBnv_alloc_reset()\fR function resets the allocator properties to the data
362 363 specified by \fBnv_alloc_init()\fR. When no (*\fBnv_ao_reset()\fR) function is
363 364 specified, \fBnv_alloc_reset()\fR is without effect.
364 365 .sp
365 366 .LP
366 367 The \fBnv_alloc_fini()\fR destroys the allocator properties determined by
367 368 \fBnv_alloc_init()\fR. When a (*\fBnv_ao_fini()\fR) routine is specified, it is
368 369 called from \fBnv_alloc_fini()\fR.
369 370 .sp
370 371 .LP
371 372 The disposition of the allocated objects and the memory used to store them is
372 373 left to the allocator implementation.
373 374 .sp
374 375 .LP
375 376 The `nv_alloc_sleep' and `nv_alloc_nosleep' nv_alloc_t pointers may be used
376 377 with nvlist_xalloc to mimic the behavior of nvlist_alloc with KM_SLEEP and
377 378 KM_NOSLEEP, respectively.
378 379 .sp
379 380 .in +2
380 381 .nf
381 382 o nv_alloc_nosleep
382 383 o nv_alloc_sleep
383 384 .fi
384 385 .in -2
385 386
386 387 .sp
387 388 .LP
388 389 The nvpair framework provides a fixed-buffer allocator, accessible via
389 390 nv_fixed_ops.
390 391 .sp
391 392 .in +2
392 393 .nf
393 394 o nv_fixed_ops
394 395 .fi
395 396 .in -2
396 397
397 398 .sp
398 399 .LP
399 400 Given a buffer size and address, the fixed-buffer allocator allows for the
400 401 creation of nvlists in contexts where malloc or kmem_alloc services may not be
401 402 available. The fixed-buffer allocator is designed primarily to support the
402 403 creation of nvlists.
403 404 .sp
404 405 .LP
405 406 Memory freed using \fBnvlist_free()\fR, pair-removal, or similar routines is
406 407 not reclaimed.
407 408 .sp
408 409 .LP
409 410 When used to initialize the fixed-buffer allocator, nv_alloc_init should be
410 411 called as follows:
411 412 .sp
412 413 .in +2
413 414 .nf
414 415 int nv_alloc_init(nv_alloc_t *nva, const nv_alloc_ops_t *nvo,
415 416 void *bufptr, size_t sz);
416 417 .fi
417 418 .in -2
418 419
419 420 .sp
420 421 .LP
421 422 When invoked on a fixed-buffer, the \fBnv_alloc_reset()\fR function resets the
422 423 fixed buffer and prepares it for re-use. The framework consumer is responsible
423 424 for freeing the buffer passed to \fBnv_alloc_init()\fR.
424 425 .SS "CREATING PLUGGABLE ALLOCATORS"
425 426 .sp
426 427 .LP
427 428 Any producer of name-value pairs may possibily specify his own allocator
428 429 routines. You must provide the following pluggable allocator operations in the
429 430 allocator implementation.
430 431 .sp
431 432 .in +2
432 433 .nf
433 434 int (*nv_ao_init)(nv_alloc_t *nva, va_list nv_valist);
434 435 void (*nv_ao_fini)(nv_alloc_t *nva);
435 436 void *(*nv_ao_alloc)(nv_alloc_t *nva, size_t sz);
436 437 void (*nv_ao_reset)(nv_alloc_t *nva);
437 438 void (*nv_ao_free)(nv_alloc_t *nva, void *buf, size_t sz);
438 439 .fi
439 440 .in -2
440 441
441 442 .sp
442 443 .LP
443 444 The \fInva\fR argument of the allocator implementation is always the first
444 445 argument.
445 446 .sp
446 447 .LP
447 448 The optional (*\fBnv_ao_init()\fR ) function is responsible for filling the
448 449 data specified by \fBnv_alloc_init()\fR into the \fBnva_arg()\fR argument. The
449 450 (*\fBnv_ao_init()\fR) function is called only when \fBnv_alloc_init()\fR is
450 451 executed.
451 452 .sp
452 453 .LP
453 454 The optional (*\fBnv_ao_fini()\fR) function is responsible for the cleanup of
454 455 the allocator implementation. It is called by \fBnv_alloc_fini()\fR.
455 456 .sp
456 457 .LP
457 458 The required (*\fBnv_ao_alloc()\fR) function is used in the nvpair allocation
458 459 framework for memory allocation. The sz argument specifies the size of the
459 460 requested buffer.
460 461 .sp
461 462 .LP
462 463 The optional (*\fBnv_ao_reset()\fR) function is responsible for resetting the
463 464 nva_arg argument to the data specified by \fBnv_alloc_init()\fR.
464 465 .sp
465 466 .LP
466 467 The required (*\fBnv_ao_free()\fR) function is used in the nvpair allocator
467 468 framework for memory de-allocation. The argument buf is a pointer to a block
468 469 previously allocated by (*\fBnv_ao_alloc()\fR) function. The size argument sz
469 470 must exactly match the original allocation.
470 471 .sp
471 472 .LP
472 473 The disposition of the allocated objects and the memory used to store them is
473 474 left to the allocator implementation.
474 475 .SH RETURN VALUES
475 476 .sp
476 477 .LP
477 478 For \fBnvlist_alloc()\fR, \fBnvlist_dup()\fR, \fBnvlist_xalloc()\fR, and
478 479 \fBnvlist_xdup()\fR:
479 480 .sp
480 481 .ne 2
481 482 .na
482 483 \fB\fB0\fR\fR
483 484 .ad
484 485 .RS 10n
485 486 success
486 487 .RE
487 488
488 489 .sp
489 490 .ne 2
490 491 .na
491 492 \fB\fBEINVAL\fR\fR
492 493 .ad
493 494 .RS 10n
494 495 invalid argument
495 496 .RE
496 497
497 498 .sp
498 499 .ne 2
499 500 .na
500 501 \fB\fBENOMEM\fR\fR
501 502 .ad
502 503 .RS 10n
503 504 insufficient memory
504 505 .RE
505 506
506 507 .sp
507 508 .LP
508 509 For \fBnvlist_pack()\fR, \fBnvlist_unpack()\fR, \fBnvlist_xpack()\fR, and
509 510 \fBnvlist_xunpack()\fR:
510 511 .sp
511 512 .ne 2
512 513 .na
513 514 \fB\fB0\fR\fR
514 515 .ad
515 516 .RS 11n
516 517 success
517 518 .RE
518 519
519 520 .sp
520 521 .ne 2
521 522 .na
522 523 \fB\fBEINVAL\fR\fR
523 524 .ad
524 525 .RS 11n
525 526 invalid argument
526 527 .RE
527 528
528 529 .sp
529 530 .ne 2
530 531 .na
531 532 \fB\fBENOMEM\fR\fR
532 533 .ad
533 534 .RS 11n
534 535 insufficient memory
535 536 .RE
536 537
537 538 .sp
538 539 .ne 2
539 540 .na
540 541 \fB\fBEFAULT\fR\fR
541 542 .ad
542 543 .RS 11n
543 544 encode/decode error
544 545 .RE
545 546
546 547 .sp
547 548 .ne 2
548 549 .na
549 550 \fB\fBENOTSUP\fR\fR
550 551 .ad
551 552 .RS 11n
552 553 encode/decode method not supported
553 554 .RE
554 555
555 556 .sp
556 557 .LP
557 558 For \fBnvlist_size()\fR:
558 559 .sp
559 560 .ne 2
560 561 .na
561 562 \fB\fB0\fR\fR
562 563 .ad
563 564 .RS 10n
564 565 success
565 566 .RE
566 567
567 568 .sp
568 569 .ne 2
569 570 .na
570 571 \fB\fBEINVAL\fR\fR
571 572 .ad
572 573 .RS 10n
573 574 invalid argument
574 575 .RE
575 576
576 577 .sp
577 578 .LP
578 579 For \fBnvlist_lookup_nv_alloc()\fR:
579 580 .sp
580 581 .LP
581 582 pointer to the allocator
582 583 .SH USAGE
583 584 .sp
584 585 .LP
585 586 The fixed-buffer allocator is very simple allocator. It uses a pre-allocated
586 587 buffer for memory allocations and it can be used in interrupt context. You are
587 588 responsible for allocation and de-allocation for the pre-allocated buffer.
588 589 .SH EXAMPLES
589 590 .sp
590 591 .in +2
591 592 .nf
592 593 /*
593 594 * using the fixed-buffer allocator.
594 595 */
595 596 #include <sys/nvpair.h>
596 597
597 598 /* initialize the nvpair allocator framework */
598 599 static nv_alloc_t *
599 600 init(char *buf, size_t size)
600 601 {
601 602 nv_alloc_t *nvap;
602 603
603 604 if ((nvap = kmem_alloc(sizeof(nv_alloc_t), KM_SLEEP)) == NULL)
604 605 return (NULL);
605 606
606 607 if (nv_alloc_init(nvap, nv_fixed_ops, buf, size) == 0)
607 608 return (nvap);
608 609
609 610 return (NULL);
610 611 }
611 612
612 613 static void
613 614 fini(nv_alloc_t *nvap)
614 615 {
615 616 nv_alloc_fini(nvap);
616 617 kmem_free(nvap, sizeof(nv_alloc_t));
617 618 }
618 619 static int
619 620 interrupt_context(nv_alloc_t *nva)
620 621 {
621 622 nvlist_t *nvl;
622 623 int error;
623 624
624 625 if ((error = nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nva)) != 0)
625 626 return (-1);
626 627
627 628 if ((error = nvlist_add_int32(nvl, "name", 1234)) == 0)
628 629 error = send_nvl(nvl);
629 630
630 631 nvlist_free(nvl);
631 632 return (error);
632 633 }
633 634 .fi
634 635 .in -2
635 636
636 637 .SH CONTEXT
637 638 .sp
638 639 .LP
639 640 The \fBnvlist_alloc()\fR, \fBnvlist_pack()\fR, \fBnvlist_unpack()\fR, and
640 641 \fBnvlist_dup()\fR functions can be called from interrupt context only if the
641 642 \fBKM_NOSLEEP\fR flag is set. They can be called from user context with any
642 643 valid flag.
643 644 .sp
644 645 .LP
645 646 The \fBnvlist_xalloc()\fR, \fBnvlist_xpack()\fR, \fBnvlist_xunpack()\fR, and
646 647 \fBnvlist_xdup()\fR functions can be called from interrupt context only if (1)
647 648 the default allocator is used and the \fBKM_NOSLEEP\fR flag is set or (2) the
648 649 specified allocator did not sleep for free memory (for example, it uses a
649 650 pre-allocated buffer for memory allocations).
650 651 .sp
651 652 .LP
652 653 These functions can be called from user or kernel context with any valid flag.
↓ open down ↓ |
380 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX