12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include "statcommon.h"
26 #include "dsr.h"
27
28 #include <sys/dklabel.h>
29 #include <sys/dktp/fdisk.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <unistd.h>
33 #include <strings.h>
34 #include <errno.h>
35 #include <limits.h>
36
37 static void insert_iodev(struct snapshot *ss, struct iodev_snapshot *iodev);
38
39 static struct iodev_snapshot *
40 make_controller(int cid)
41 {
42 struct iodev_snapshot *new;
43
44 new = safe_alloc(sizeof (struct iodev_snapshot));
45 (void) memset(new, 0, sizeof (struct iodev_snapshot));
46 new->is_type = IODEV_CONTROLLER;
47 new->is_id.id = cid;
48 new->is_parent_id.id = IODEV_NO_ID;
49
50 (void) snprintf(new->is_name, sizeof (new->is_name), "c%d", cid);
51
130 pos->is_type == IODEV_DISK)
131 return (pos);
132 if (pos->is_type != IODEV_CONTROLLER)
133 continue;
134 for (pos2 = pos->is_children; pos2; pos2 = pos2->is_next) {
135 if (pos2->is_type != IODEV_DISK)
136 continue;
137 if (id_match(&iodev->is_parent_id, &pos2->is_id))
138 return (pos2);
139 }
140 }
141
142 return (NULL);
143 }
144
145 /*
146 * Introduce an index into the list to speed up insert_into looking for the
147 * right position in the list. This index is an AVL tree of all the
148 * iodev_snapshot in the list.
149 */
150
151 #define offsetof(s, m) (size_t)(&(((s *)0)->m)) /* for avl_create */
152
153 static int
154 avl_iodev_cmp(const void* is1, const void* is2)
155 {
156 int c = iodev_cmp((struct iodev_snapshot *)is1,
157 (struct iodev_snapshot *)is2);
158
159 if (c > 0)
160 return (1);
161
162 if (c < 0)
163 return (-1);
164
165 return (0);
166 }
167
168 static void
169 ix_new_list(struct iodev_snapshot *elem)
170 {
171 avl_tree_t *l = malloc(sizeof (avl_tree_t));
172
|
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include "statcommon.h"
26 #include "dsr.h"
27
28 #include <sys/dklabel.h>
29 #include <sys/dktp/fdisk.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stddef.h>
33 #include <unistd.h>
34 #include <strings.h>
35 #include <errno.h>
36 #include <limits.h>
37
38 static void insert_iodev(struct snapshot *ss, struct iodev_snapshot *iodev);
39
40 static struct iodev_snapshot *
41 make_controller(int cid)
42 {
43 struct iodev_snapshot *new;
44
45 new = safe_alloc(sizeof (struct iodev_snapshot));
46 (void) memset(new, 0, sizeof (struct iodev_snapshot));
47 new->is_type = IODEV_CONTROLLER;
48 new->is_id.id = cid;
49 new->is_parent_id.id = IODEV_NO_ID;
50
51 (void) snprintf(new->is_name, sizeof (new->is_name), "c%d", cid);
52
131 pos->is_type == IODEV_DISK)
132 return (pos);
133 if (pos->is_type != IODEV_CONTROLLER)
134 continue;
135 for (pos2 = pos->is_children; pos2; pos2 = pos2->is_next) {
136 if (pos2->is_type != IODEV_DISK)
137 continue;
138 if (id_match(&iodev->is_parent_id, &pos2->is_id))
139 return (pos2);
140 }
141 }
142
143 return (NULL);
144 }
145
146 /*
147 * Introduce an index into the list to speed up insert_into looking for the
148 * right position in the list. This index is an AVL tree of all the
149 * iodev_snapshot in the list.
150 */
151 static int
152 avl_iodev_cmp(const void* is1, const void* is2)
153 {
154 int c = iodev_cmp((struct iodev_snapshot *)is1,
155 (struct iodev_snapshot *)is2);
156
157 if (c > 0)
158 return (1);
159
160 if (c < 0)
161 return (-1);
162
163 return (0);
164 }
165
166 static void
167 ix_new_list(struct iodev_snapshot *elem)
168 {
169 avl_tree_t *l = malloc(sizeof (avl_tree_t));
170
|