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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* evnv.c -- eversholt specific nvpair manipulation functions
*
* this module provides the simulated fault management exercise.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <libnvpair.h>
#include "evnv.h"
#include "out.h"
#define min(a, b) (((a) <= (b)) ? (a) : (b))
extern nv_alloc_t Eft_nv_hdl;
static void
outindent(int depth)
{
while (depth-- > 0)
out(O_ALTFP|O_VERB3|O_NONL, " ");
}
/*
* evnv_cmpnvl -- compare two asrus in their nvlist form
*/
int
evnv_cmpnvl(nvlist_t *nvl1, nvlist_t *nvl2, int depth)
{
/*
* an assumption here is that each list was constructed in the
* same order, which is a safe assumption since we built the
* list of ourself (well, libtopo did at any rate)
*/
data_type_t t1, t2;
nvlist_t **la1 = NULL;
nvlist_t **la2 = NULL;
nvlist_t *l1 = NULL;
nvlist_t *l2 = NULL;
nvpair_t *p1 = NULL;
nvpair_t *p2 = NULL;
uint64_t lv1, lv2;
uint_t m, na1, na2;
char *s1, *s2;
int ret, i;
for (;;) {
p1 = nvlist_next_nvpair(nvl1, p1);
p2 = nvlist_next_nvpair(nvl2, p2);
if (p1 == NULL && p2 == NULL) {
outindent(depth);
out(O_ALTFP|O_VERB3, "equal nvls\n");
return (0);
}
if (p1 == NULL)
return (-1);
if (p2 == NULL)
return (1);
s1 = nvpair_name(p1);
s2 = nvpair_name(p2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: pair %s vs %s", s1, s2);
if ((ret = strcmp(s1, s2)) != 0)
return (ret);
t1 = nvpair_type(p1);
t2 = nvpair_type(p2);
if (t1 != t2)
return (t1 - t2);
/*
* We don't compare all possible types, just the
* ones we know are likely to actually be present
* in nvlists we've generated.
*/
switch (t1) {
case DATA_TYPE_NVLIST:
(void) nvpair_value_nvlist(p1, &l1);
(void) nvpair_value_nvlist(p2, &l2);
if ((ret = evnv_cmpnvl(l1, l2, depth + 1)) != 0)
return (ret);
break;
case DATA_TYPE_NVLIST_ARRAY:
(void) nvpair_value_nvlist_array(p1, &la1, &na1);
(void) nvpair_value_nvlist_array(p2, &la2, &na2);
m = min(na1, na2);
for (i = 0; i < m; i++) {
if ((ret =
evnv_cmpnvl(*la1, *la2, depth + 1)) != 0)
return (ret);
la1++;
la2++;
}
if (na1 < na2)
return (-1);
else if (na2 < na1)
return (1);
break;
case DATA_TYPE_STRING:
(void) nvpair_value_string(p1, &s1);
(void) nvpair_value_string(p2, &s2);
if ((ret = strcmp(s1, s2)) != 0) {
outindent(depth);
if (ret < 0)
out(O_ALTFP|O_VERB3,
"cmpnvl: %s < %s", s1, s2);
else
out(O_ALTFP|O_VERB3,
"cmpnvl: %s > %s", s1, s2);
return (ret);
}
break;
case DATA_TYPE_UINT64:
lv1 = lv2 = 0;
(void) nvpair_value_uint64(p1, &lv1);
(void) nvpair_value_uint64(p2, &lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %llu vs %llu", lv1, lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_INT64:
lv1 = lv2 = 0;
(void) nvpair_value_int64(p1, (int64_t *)&lv1);
(void) nvpair_value_int64(p2, (int64_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %lld vs %lld", lv1, lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_UINT32:
lv1 = lv2 = 0;
(void) nvpair_value_uint32(p1, (uint32_t *)&lv1);
(void) nvpair_value_uint32(p2, (uint32_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %u vs %u",
*(uint32_t *)&lv1, *(uint32_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_INT32:
lv1 = lv2 = 0;
(void) nvpair_value_int32(p1, (int32_t *)&lv1);
(void) nvpair_value_int32(p2, (int32_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %d vs %d",
*(int32_t *)&lv1, *(int32_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_UINT16:
lv1 = lv2 = 0;
(void) nvpair_value_uint16(p1, (uint16_t *)&lv1);
(void) nvpair_value_uint16(p2, (uint16_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %u vs %u",
*(uint16_t *)&lv1, *(uint16_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_INT16:
lv1 = lv2 = 0;
(void) nvpair_value_int16(p1, (int16_t *)&lv1);
(void) nvpair_value_int16(p2, (int16_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %d vs %d",
*(int16_t *)&lv1, *(int16_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_UINT8:
lv1 = lv2 = 0;
(void) nvpair_value_uint8(p1, (uint8_t *)&lv1);
(void) nvpair_value_uint8(p2, (uint8_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %u vs %u",
*(uint8_t *)&lv1, *(uint8_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
case DATA_TYPE_INT8:
lv1 = lv2 = 0;
(void) nvpair_value_int8(p1, (int8_t *)&lv1);
(void) nvpair_value_int8(p2, (int8_t *)&lv2);
outindent(depth);
out(O_ALTFP|O_VERB3, "cmpnvl: %d vs %d",
*(int8_t *)&lv1, *(int8_t *)&lv2);
if (lv1 > lv2)
return (1);
else if (lv2 > lv1)
return (-1);
break;
}
}
}
/*
* evnv_dupnvl -- duplicate a payload nvlist, keeping only the interesting stuff
*/
nvlist_t *
evnv_dupnvl(nvlist_t *nvp)
{
nvlist_t *retval = NULL;
int nvret;
if (nvp == NULL)
return (NULL);
if ((nvret = nvlist_xdup(nvp, &retval, &Eft_nv_hdl)) != 0)
out(O_DIE, "dupnvl: dup failed: %d", nvret);
return (retval);
}
|