4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * evnv.c -- eversholt specific nvpair manipulation functions
28 * this module provides the simulated fault management exercise.
31 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <libnvpair.h>
39 #define min(a, b) (((a) <= (b)) ? (a) : (b))
41 extern nv_alloc_t Eft_nv_hdl
;
47 out(O_ALTFP
|O_VERB3
|O_NONL
, " ");
51 * evnv_cmpnvl -- compare two asrus in their nvlist form
54 evnv_cmpnvl(nvlist_t
*nvl1
, nvlist_t
*nvl2
, int depth
)
57 * an assumption here is that each list was constructed in the
58 * same order, which is a safe assumption since we built the
59 * list of ourself (well, libtopo did at any rate)
62 nvlist_t
**la1
= NULL
;
63 nvlist_t
**la2
= NULL
;
74 p1
= nvlist_next_nvpair(nvl1
, p1
);
75 p2
= nvlist_next_nvpair(nvl2
, p2
);
76 if (p1
== NULL
&& p2
== NULL
) {
78 out(O_ALTFP
|O_VERB3
, "equal nvls\n");
88 out(O_ALTFP
|O_VERB3
, "cmpnvl: pair %s vs %s", s1
, s2
);
89 if ((ret
= strcmp(s1
, s2
)) != 0)
96 * We don't compare all possible types, just the
97 * ones we know are likely to actually be present
98 * in nvlists we've generated.
101 case DATA_TYPE_NVLIST
:
102 (void) nvpair_value_nvlist(p1
, &l1
);
103 (void) nvpair_value_nvlist(p2
, &l2
);
104 if ((ret
= evnv_cmpnvl(l1
, l2
, depth
+ 1)) != 0)
107 case DATA_TYPE_NVLIST_ARRAY
:
108 (void) nvpair_value_nvlist_array(p1
, &la1
, &na1
);
109 (void) nvpair_value_nvlist_array(p2
, &la2
, &na2
);
111 for (i
= 0; i
< m
; i
++) {
113 evnv_cmpnvl(*la1
, *la2
, depth
+ 1)) != 0)
123 case DATA_TYPE_STRING
:
124 (void) nvpair_value_string(p1
, &s1
);
125 (void) nvpair_value_string(p2
, &s2
);
126 if ((ret
= strcmp(s1
, s2
)) != 0) {
130 "cmpnvl: %s < %s", s1
, s2
);
133 "cmpnvl: %s > %s", s1
, s2
);
137 case DATA_TYPE_UINT64
:
139 (void) nvpair_value_uint64(p1
, &lv1
);
140 (void) nvpair_value_uint64(p2
, &lv2
);
142 out(O_ALTFP
|O_VERB3
, "cmpnvl: %llu vs %llu", lv1
, lv2
);
148 case DATA_TYPE_INT64
:
150 (void) nvpair_value_int64(p1
, (int64_t *)&lv1
);
151 (void) nvpair_value_int64(p2
, (int64_t *)&lv2
);
153 out(O_ALTFP
|O_VERB3
, "cmpnvl: %lld vs %lld", lv1
, lv2
);
159 case DATA_TYPE_UINT32
:
161 (void) nvpair_value_uint32(p1
, (uint32_t *)&lv1
);
162 (void) nvpair_value_uint32(p2
, (uint32_t *)&lv2
);
164 out(O_ALTFP
|O_VERB3
, "cmpnvl: %u vs %u",
165 *(uint32_t *)&lv1
, *(uint32_t *)&lv2
);
171 case DATA_TYPE_INT32
:
173 (void) nvpair_value_int32(p1
, (int32_t *)&lv1
);
174 (void) nvpair_value_int32(p2
, (int32_t *)&lv2
);
176 out(O_ALTFP
|O_VERB3
, "cmpnvl: %d vs %d",
177 *(int32_t *)&lv1
, *(int32_t *)&lv2
);
183 case DATA_TYPE_UINT16
:
185 (void) nvpair_value_uint16(p1
, (uint16_t *)&lv1
);
186 (void) nvpair_value_uint16(p2
, (uint16_t *)&lv2
);
188 out(O_ALTFP
|O_VERB3
, "cmpnvl: %u vs %u",
189 *(uint16_t *)&lv1
, *(uint16_t *)&lv2
);
195 case DATA_TYPE_INT16
:
197 (void) nvpair_value_int16(p1
, (int16_t *)&lv1
);
198 (void) nvpair_value_int16(p2
, (int16_t *)&lv2
);
200 out(O_ALTFP
|O_VERB3
, "cmpnvl: %d vs %d",
201 *(int16_t *)&lv1
, *(int16_t *)&lv2
);
207 case DATA_TYPE_UINT8
:
209 (void) nvpair_value_uint8(p1
, (uint8_t *)&lv1
);
210 (void) nvpair_value_uint8(p2
, (uint8_t *)&lv2
);
212 out(O_ALTFP
|O_VERB3
, "cmpnvl: %u vs %u",
213 *(uint8_t *)&lv1
, *(uint8_t *)&lv2
);
221 (void) nvpair_value_int8(p1
, (int8_t *)&lv1
);
222 (void) nvpair_value_int8(p2
, (int8_t *)&lv2
);
224 out(O_ALTFP
|O_VERB3
, "cmpnvl: %d vs %d",
225 *(int8_t *)&lv1
, *(int8_t *)&lv2
);
236 * evnv_dupnvl -- duplicate a payload nvlist, keeping only the interesting stuff
239 evnv_dupnvl(nvlist_t
*nvp
)
241 nvlist_t
*retval
= NULL
;
247 if ((nvret
= nvlist_xdup(nvp
, &retval
, &Eft_nv_hdl
)) != 0)
248 out(O_DIE
, "dupnvl: dup failed: %d", nvret
);