Print this page
OS-1840 fmdump shall emit JSON (copyright fixes 2)
OS-1840 fmdump shall emit JSON (rm feedback)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/nvpair/fnvpair.c
+++ new/usr/src/common/nvpair/fnvpair.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
24 25 */
25 26
26 27 #include <sys/nvpair.h>
27 28 #include <sys/kmem.h>
28 29 #include <sys/debug.h>
29 30 #ifndef _KERNEL
30 31 #include <stdlib.h>
31 32 #endif
32 33
34 +#pragma weak fnvlist_lookup_uint8_t = fnvlist_lookup_uint8
35 +#pragma weak fnvpair_value_uint8_t = fnvpair_value_uint8
36 +
33 37 /*
34 38 * "Force" nvlist wrapper.
35 39 *
36 40 * These functions wrap the nvlist_* functions with assertions that assume
37 41 * the operation is successful. This allows the caller's code to be much
38 42 * more readable, especially for the fnvlist_lookup_* and fnvpair_value_*
39 43 * functions, which can return the requested value (rather than filling in
40 44 * a pointer).
41 45 *
42 46 * These functions use NV_UNIQUE_NAME, encoding NV_ENCODE_NATIVE, and allocate
43 47 * with KM_SLEEP.
44 48 *
45 49 * More wrappers should be added as needed -- for example
46 50 * nvlist_lookup_*_array and nvpair_value_*_array.
47 51 */
48 52
49 53 nvlist_t *
50 54 fnvlist_alloc(void)
51 55 {
52 56 nvlist_t *nvl;
53 57 VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP));
54 58 return (nvl);
55 59 }
56 60
57 61 void
58 62 fnvlist_free(nvlist_t *nvl)
59 63 {
60 64 nvlist_free(nvl);
61 65 }
62 66
63 67 size_t
64 68 fnvlist_size(nvlist_t *nvl)
65 69 {
66 70 size_t size;
67 71 VERIFY0(nvlist_size(nvl, &size, NV_ENCODE_NATIVE));
68 72 return (size);
69 73 }
70 74
71 75 /*
72 76 * Returns allocated buffer of size *sizep. Caller must free the buffer with
73 77 * fnvlist_pack_free().
74 78 */
75 79 char *
76 80 fnvlist_pack(nvlist_t *nvl, size_t *sizep)
77 81 {
78 82 char *packed = 0;
79 83 VERIFY3U(nvlist_pack(nvl, &packed, sizep, NV_ENCODE_NATIVE,
80 84 KM_SLEEP), ==, 0);
81 85 return (packed);
82 86 }
83 87
84 88 /*ARGSUSED*/
85 89 void
86 90 fnvlist_pack_free(char *pack, size_t size)
87 91 {
88 92 #ifdef _KERNEL
89 93 kmem_free(pack, size);
90 94 #else
91 95 free(pack);
92 96 #endif
93 97 }
94 98
95 99 nvlist_t *
96 100 fnvlist_unpack(char *buf, size_t buflen)
97 101 {
98 102 nvlist_t *rv;
99 103 VERIFY0(nvlist_unpack(buf, buflen, &rv, KM_SLEEP));
100 104 return (rv);
101 105 }
102 106
103 107 nvlist_t *
104 108 fnvlist_dup(nvlist_t *nvl)
105 109 {
106 110 nvlist_t *rv;
107 111 VERIFY0(nvlist_dup(nvl, &rv, KM_SLEEP));
108 112 return (rv);
109 113 }
110 114
111 115 void
112 116 fnvlist_merge(nvlist_t *dst, nvlist_t *src)
113 117 {
114 118 VERIFY0(nvlist_merge(dst, src, KM_SLEEP));
115 119 }
116 120
117 121 void
118 122 fnvlist_add_boolean(nvlist_t *nvl, const char *name)
119 123 {
120 124 VERIFY0(nvlist_add_boolean(nvl, name));
121 125 }
122 126
123 127 void
124 128 fnvlist_add_boolean_value(nvlist_t *nvl, const char *name, boolean_t val)
125 129 {
126 130 VERIFY0(nvlist_add_boolean_value(nvl, name, val));
127 131 }
128 132
129 133 void
130 134 fnvlist_add_byte(nvlist_t *nvl, const char *name, uchar_t val)
131 135 {
132 136 VERIFY0(nvlist_add_byte(nvl, name, val));
133 137 }
134 138
135 139 void
136 140 fnvlist_add_int8(nvlist_t *nvl, const char *name, int8_t val)
137 141 {
138 142 VERIFY0(nvlist_add_int8(nvl, name, val));
139 143 }
140 144
141 145 void
142 146 fnvlist_add_uint8(nvlist_t *nvl, const char *name, uint8_t val)
143 147 {
144 148 VERIFY0(nvlist_add_uint8(nvl, name, val));
145 149 }
146 150
147 151 void
148 152 fnvlist_add_int16(nvlist_t *nvl, const char *name, int16_t val)
149 153 {
150 154 VERIFY0(nvlist_add_int16(nvl, name, val));
151 155 }
152 156
153 157 void
154 158 fnvlist_add_uint16(nvlist_t *nvl, const char *name, uint16_t val)
155 159 {
156 160 VERIFY0(nvlist_add_uint16(nvl, name, val));
157 161 }
158 162
159 163 void
160 164 fnvlist_add_int32(nvlist_t *nvl, const char *name, int32_t val)
161 165 {
162 166 VERIFY0(nvlist_add_int32(nvl, name, val));
163 167 }
164 168
165 169 void
166 170 fnvlist_add_uint32(nvlist_t *nvl, const char *name, uint32_t val)
167 171 {
168 172 VERIFY0(nvlist_add_uint32(nvl, name, val));
169 173 }
170 174
171 175 void
172 176 fnvlist_add_int64(nvlist_t *nvl, const char *name, int64_t val)
173 177 {
174 178 VERIFY0(nvlist_add_int64(nvl, name, val));
175 179 }
176 180
177 181 void
178 182 fnvlist_add_uint64(nvlist_t *nvl, const char *name, uint64_t val)
179 183 {
180 184 VERIFY0(nvlist_add_uint64(nvl, name, val));
181 185 }
182 186
183 187 void
184 188 fnvlist_add_string(nvlist_t *nvl, const char *name, const char *val)
185 189 {
186 190 VERIFY0(nvlist_add_string(nvl, name, val));
187 191 }
188 192
189 193 void
190 194 fnvlist_add_nvlist(nvlist_t *nvl, const char *name, nvlist_t *val)
191 195 {
192 196 VERIFY0(nvlist_add_nvlist(nvl, name, val));
193 197 }
194 198
195 199 void
196 200 fnvlist_add_nvpair(nvlist_t *nvl, nvpair_t *pair)
197 201 {
198 202 VERIFY0(nvlist_add_nvpair(nvl, pair));
199 203 }
200 204
201 205 void
202 206 fnvlist_add_boolean_array(nvlist_t *nvl, const char *name,
203 207 boolean_t *val, uint_t n)
204 208 {
205 209 VERIFY0(nvlist_add_boolean_array(nvl, name, val, n));
206 210 }
207 211
208 212 void
209 213 fnvlist_add_byte_array(nvlist_t *nvl, const char *name, uchar_t *val, uint_t n)
210 214 {
211 215 VERIFY0(nvlist_add_byte_array(nvl, name, val, n));
212 216 }
213 217
214 218 void
215 219 fnvlist_add_int8_array(nvlist_t *nvl, const char *name, int8_t *val, uint_t n)
216 220 {
217 221 VERIFY0(nvlist_add_int8_array(nvl, name, val, n));
218 222 }
219 223
220 224 void
221 225 fnvlist_add_uint8_array(nvlist_t *nvl, const char *name, uint8_t *val, uint_t n)
222 226 {
223 227 VERIFY0(nvlist_add_uint8_array(nvl, name, val, n));
224 228 }
225 229
226 230 void
227 231 fnvlist_add_int16_array(nvlist_t *nvl, const char *name, int16_t *val, uint_t n)
228 232 {
229 233 VERIFY0(nvlist_add_int16_array(nvl, name, val, n));
230 234 }
231 235
232 236 void
233 237 fnvlist_add_uint16_array(nvlist_t *nvl, const char *name,
234 238 uint16_t *val, uint_t n)
235 239 {
236 240 VERIFY0(nvlist_add_uint16_array(nvl, name, val, n));
237 241 }
238 242
239 243 void
240 244 fnvlist_add_int32_array(nvlist_t *nvl, const char *name, int32_t *val, uint_t n)
241 245 {
242 246 VERIFY0(nvlist_add_int32_array(nvl, name, val, n));
243 247 }
244 248
245 249 void
246 250 fnvlist_add_uint32_array(nvlist_t *nvl, const char *name,
247 251 uint32_t *val, uint_t n)
248 252 {
249 253 VERIFY0(nvlist_add_uint32_array(nvl, name, val, n));
250 254 }
251 255
252 256 void
253 257 fnvlist_add_int64_array(nvlist_t *nvl, const char *name, int64_t *val, uint_t n)
254 258 {
255 259 VERIFY0(nvlist_add_int64_array(nvl, name, val, n));
256 260 }
257 261
258 262 void
259 263 fnvlist_add_uint64_array(nvlist_t *nvl, const char *name,
260 264 uint64_t *val, uint_t n)
261 265 {
262 266 VERIFY0(nvlist_add_uint64_array(nvl, name, val, n));
263 267 }
264 268
265 269 void
266 270 fnvlist_add_string_array(nvlist_t *nvl, const char *name,
267 271 char * const *val, uint_t n)
268 272 {
269 273 VERIFY0(nvlist_add_string_array(nvl, name, val, n));
270 274 }
271 275
272 276 void
273 277 fnvlist_add_nvlist_array(nvlist_t *nvl, const char *name,
274 278 nvlist_t **val, uint_t n)
275 279 {
276 280 VERIFY0(nvlist_add_nvlist_array(nvl, name, val, n));
277 281 }
278 282
279 283 void
280 284 fnvlist_remove(nvlist_t *nvl, const char *name)
281 285 {
282 286 VERIFY0(nvlist_remove_all(nvl, name));
283 287 }
284 288
285 289 void
286 290 fnvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *pair)
287 291 {
288 292 VERIFY0(nvlist_remove_nvpair(nvl, pair));
289 293 }
290 294
291 295 nvpair_t *
292 296 fnvlist_lookup_nvpair(nvlist_t *nvl, const char *name)
293 297 {
294 298 nvpair_t *rv;
295 299 VERIFY0(nvlist_lookup_nvpair(nvl, name, &rv));
296 300 return (rv);
297 301 }
298 302
299 303 /* returns B_TRUE if the entry exists */
300 304 boolean_t
301 305 fnvlist_lookup_boolean(nvlist_t *nvl, const char *name)
302 306 {
303 307 return (nvlist_lookup_boolean(nvl, name) == 0);
304 308 }
305 309
306 310 boolean_t
307 311 fnvlist_lookup_boolean_value(nvlist_t *nvl, const char *name)
308 312 {
309 313 boolean_t rv;
310 314 VERIFY0(nvlist_lookup_boolean_value(nvl, name, &rv));
311 315 return (rv);
312 316 }
313 317
314 318 uchar_t
315 319 fnvlist_lookup_byte(nvlist_t *nvl, const char *name)
316 320 {
317 321 uchar_t rv;
318 322 VERIFY0(nvlist_lookup_byte(nvl, name, &rv));
319 323 return (rv);
320 324 }
321 325
322 326 int8_t
323 327 fnvlist_lookup_int8(nvlist_t *nvl, const char *name)
324 328 {
325 329 int8_t rv;
326 330 VERIFY0(nvlist_lookup_int8(nvl, name, &rv));
327 331 return (rv);
328 332 }
329 333
330 334 int16_t
331 335 fnvlist_lookup_int16(nvlist_t *nvl, const char *name)
332 336 {
333 337 int16_t rv;
334 338 VERIFY0(nvlist_lookup_int16(nvl, name, &rv));
335 339 return (rv);
336 340 }
337 341
338 342 int32_t
339 343 fnvlist_lookup_int32(nvlist_t *nvl, const char *name)
340 344 {
341 345 int32_t rv;
342 346 VERIFY0(nvlist_lookup_int32(nvl, name, &rv));
343 347 return (rv);
344 348 }
↓ open down ↓ |
302 lines elided |
↑ open up ↑ |
345 349
346 350 int64_t
347 351 fnvlist_lookup_int64(nvlist_t *nvl, const char *name)
348 352 {
349 353 int64_t rv;
350 354 VERIFY0(nvlist_lookup_int64(nvl, name, &rv));
351 355 return (rv);
352 356 }
353 357
354 358 uint8_t
355 -fnvlist_lookup_uint8_t(nvlist_t *nvl, const char *name)
359 +fnvlist_lookup_uint8(nvlist_t *nvl, const char *name)
356 360 {
357 361 uint8_t rv;
358 362 VERIFY0(nvlist_lookup_uint8(nvl, name, &rv));
359 363 return (rv);
360 364 }
361 365
362 366 uint16_t
363 367 fnvlist_lookup_uint16(nvlist_t *nvl, const char *name)
364 368 {
365 369 uint16_t rv;
366 370 VERIFY0(nvlist_lookup_uint16(nvl, name, &rv));
367 371 return (rv);
368 372 }
369 373
370 374 uint32_t
371 375 fnvlist_lookup_uint32(nvlist_t *nvl, const char *name)
372 376 {
373 377 uint32_t rv;
374 378 VERIFY0(nvlist_lookup_uint32(nvl, name, &rv));
375 379 return (rv);
376 380 }
377 381
378 382 uint64_t
379 383 fnvlist_lookup_uint64(nvlist_t *nvl, const char *name)
380 384 {
381 385 uint64_t rv;
382 386 VERIFY0(nvlist_lookup_uint64(nvl, name, &rv));
383 387 return (rv);
384 388 }
385 389
386 390 char *
387 391 fnvlist_lookup_string(nvlist_t *nvl, const char *name)
388 392 {
389 393 char *rv;
390 394 VERIFY0(nvlist_lookup_string(nvl, name, &rv));
391 395 return (rv);
392 396 }
393 397
394 398 nvlist_t *
395 399 fnvlist_lookup_nvlist(nvlist_t *nvl, const char *name)
396 400 {
397 401 nvlist_t *rv;
398 402 VERIFY0(nvlist_lookup_nvlist(nvl, name, &rv));
399 403 return (rv);
400 404 }
401 405
402 406 boolean_t
403 407 fnvpair_value_boolean_value(nvpair_t *nvp)
404 408 {
405 409 boolean_t rv;
406 410 VERIFY0(nvpair_value_boolean_value(nvp, &rv));
407 411 return (rv);
408 412 }
409 413
410 414 uchar_t
411 415 fnvpair_value_byte(nvpair_t *nvp)
412 416 {
413 417 uchar_t rv;
414 418 VERIFY0(nvpair_value_byte(nvp, &rv));
415 419 return (rv);
416 420 }
417 421
418 422 int8_t
419 423 fnvpair_value_int8(nvpair_t *nvp)
420 424 {
421 425 int8_t rv;
422 426 VERIFY0(nvpair_value_int8(nvp, &rv));
423 427 return (rv);
424 428 }
425 429
426 430 int16_t
427 431 fnvpair_value_int16(nvpair_t *nvp)
428 432 {
429 433 int16_t rv;
430 434 VERIFY0(nvpair_value_int16(nvp, &rv));
431 435 return (rv);
432 436 }
433 437
434 438 int32_t
435 439 fnvpair_value_int32(nvpair_t *nvp)
436 440 {
437 441 int32_t rv;
438 442 VERIFY0(nvpair_value_int32(nvp, &rv));
439 443 return (rv);
440 444 }
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
441 445
442 446 int64_t
443 447 fnvpair_value_int64(nvpair_t *nvp)
444 448 {
445 449 int64_t rv;
446 450 VERIFY0(nvpair_value_int64(nvp, &rv));
447 451 return (rv);
448 452 }
449 453
450 454 uint8_t
451 -fnvpair_value_uint8_t(nvpair_t *nvp)
455 +fnvpair_value_uint8(nvpair_t *nvp)
452 456 {
453 457 uint8_t rv;
454 458 VERIFY0(nvpair_value_uint8(nvp, &rv));
455 459 return (rv);
456 460 }
457 461
458 462 uint16_t
459 463 fnvpair_value_uint16(nvpair_t *nvp)
460 464 {
461 465 uint16_t rv;
462 466 VERIFY0(nvpair_value_uint16(nvp, &rv));
463 467 return (rv);
464 468 }
465 469
466 470 uint32_t
467 471 fnvpair_value_uint32(nvpair_t *nvp)
468 472 {
469 473 uint32_t rv;
470 474 VERIFY0(nvpair_value_uint32(nvp, &rv));
471 475 return (rv);
472 476 }
473 477
474 478 uint64_t
475 479 fnvpair_value_uint64(nvpair_t *nvp)
476 480 {
477 481 uint64_t rv;
478 482 VERIFY0(nvpair_value_uint64(nvp, &rv));
479 483 return (rv);
480 484 }
481 485
482 486 char *
483 487 fnvpair_value_string(nvpair_t *nvp)
484 488 {
485 489 char *rv;
486 490 VERIFY0(nvpair_value_string(nvp, &rv));
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
487 491 return (rv);
488 492 }
489 493
490 494 nvlist_t *
491 495 fnvpair_value_nvlist(nvpair_t *nvp)
492 496 {
493 497 nvlist_t *rv;
494 498 VERIFY0(nvpair_value_nvlist(nvp, &rv));
495 499 return (rv);
496 500 }
501 +
502 +double
503 +fnvpair_value_double(nvpair_t *nvp)
504 +{
505 + double rv;
506 + VERIFY0(nvpair_value_double(nvp, &rv));
507 + return (rv);
508 +}
509 +
510 +hrtime_t
511 +fnvpair_value_hrtime(nvpair_t *nvp)
512 +{
513 + hrtime_t rv;
514 + VERIFY0(nvpair_value_hrtime(nvp, &rv));
515 + return (rv);
516 +}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX