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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <libdevinfo.h>
32 #include <sys/sunddi.h>
33 #include <sys/types.h>
34 #include <sys/scsi/conf/autoconf.h>
36 #include "libdiskmgt.h"
37 #include "disks_private.h"
39 static descriptor_t
**get_assoc_buses(descriptor_t
*desc
, int *errp
);
40 static descriptor_t
**get_assoc_drives(descriptor_t
*desc
, int *errp
);
41 static descriptor_t
**get_assoc_paths(descriptor_t
*desc
, int *errp
);
44 controller_get_assoc_descriptors(descriptor_t
*desc
, dm_desc_type_t type
,
49 return (get_assoc_drives(desc
, errp
));
51 return (get_assoc_paths(desc
, errp
));
53 return (get_assoc_buses(desc
, errp
));
61 controller_get_attributes(descriptor_t
*dp
, int *errp
)
66 if (nvlist_alloc(&attrs
, NVATTRS
, 0) != 0) {
71 cp
= dp
->p
.controller
;
73 if (nvlist_add_string(attrs
, DM_CTYPE
, cp
->ctype
) != 0) {
80 if (nvlist_add_boolean(attrs
, DM_MULTIPLEX
) != 0) {
87 if (cp
->scsi_options
!= -1) {
88 if (cp
->scsi_options
& SCSI_OPTIONS_FAST
) {
89 if (nvlist_add_boolean(attrs
, DM_FAST
) != 0) {
95 if (cp
->scsi_options
& SCSI_OPTIONS_WIDE
) {
96 if (nvlist_add_boolean(attrs
, DM_WIDE
) != 0) {
102 if (cp
->scsi_options
& SCSI_OPTIONS_FAST20
) {
103 if (nvlist_add_boolean(attrs
, DM_FAST20
) != 0) {
109 if (cp
->scsi_options
& SCSI_OPTIONS_FAST40
) {
110 if (nvlist_add_boolean(attrs
, DM_FAST40
) != 0) {
116 if (cp
->scsi_options
& SCSI_OPTIONS_FAST80
) {
117 if (nvlist_add_boolean(attrs
, DM_FAST80
) != 0) {
126 if (nvlist_add_uint32(attrs
, DM_CLOCK
, cp
->freq
) != 0) {
138 controller_get_descriptor_by_name(char *name
, int *errp
)
140 descriptor_t
**controllers
;
142 descriptor_t
*controller
= NULL
;
144 controllers
= cache_get_descriptors(DM_CONTROLLER
, errp
);
149 for (i
= 0; controllers
[i
]; i
++) {
150 if (libdiskmgt_str_eq(name
, controllers
[i
]->p
.controller
->name
)) {
151 controller
= controllers
[i
];
153 /* clean up the unused descriptors */
154 cache_free_descriptor(controllers
[i
]);
159 if (controller
== NULL
) {
168 controller_get_descriptors(int filter
[], int *errp
)
170 return (cache_get_descriptors(DM_CONTROLLER
, errp
));
174 controller_get_name(descriptor_t
*desc
)
176 return (desc
->p
.controller
->name
);
181 controller_get_stats(descriptor_t
*dp
, int stat_type
, int *errp
)
183 /* There are no stat types defined for controllers */
189 controller_make_descriptors()
194 cp
= cache_get_controllerlist();
196 cache_load_desc(DM_CONTROLLER
, cp
, NULL
, NULL
, &error
);
206 static descriptor_t
**
207 get_assoc_buses(descriptor_t
*desc
, int *errp
)
210 descriptor_t
**buses
;
213 cp
= desc
->p
.controller
;
215 /* make the snapshot */
216 buses
= (descriptor_t
**)calloc(2, sizeof (descriptor_t
*));
222 if (cp
->bus
!= NULL
) {
223 buses
[pos
++] = cache_get_desc(DM_BUS
, cp
->bus
, NULL
, NULL
, errp
);
225 cache_free_descriptors(buses
);
235 static descriptor_t
**
236 get_assoc_drives(descriptor_t
*desc
, int *errp
)
239 descriptor_t
**drives
;
243 cp
= desc
->p
.controller
;
245 /* Count how many we have. */
246 for (cnt
= 0; cp
->disks
[cnt
]; cnt
++);
248 /* make the snapshot */
249 drives
= (descriptor_t
**)calloc(cnt
+ 1, sizeof (descriptor_t
*));
250 if (drives
== NULL
) {
255 for (i
= 0; cp
->disks
[i
]; i
++) {
256 drives
[i
] = cache_get_desc(DM_DRIVE
, cp
->disks
[i
], NULL
, NULL
,
259 cache_free_descriptors(drives
);
269 static descriptor_t
**
270 get_assoc_paths(descriptor_t
*desc
, int *errp
)
274 descriptor_t
**paths
;
277 pp
= desc
->p
.controller
->paths
;
279 /* Count how many we have. */
282 for (; pp
[cnt
]; cnt
++);
285 /* make the snapshot */
286 paths
= (descriptor_t
**)calloc(cnt
+ 1, sizeof (descriptor_t
*));
293 * The name field of the descriptor is not filled in. Thus, we
294 * know not to try to lookup drive-path state information within
295 * the path code if we try to get attributes for this descriptor.
297 for (i
= 0; i
< cnt
; i
++) {
298 paths
[i
] = cache_get_desc(DM_PATH
, pp
[i
], NULL
, NULL
, errp
);
300 cache_free_descriptors(paths
);