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>
34 #include <sys/sunddi.h>
35 #include <sys/types.h>
38 #include "libdiskmgt.h"
39 #include "disks_private.h"
41 static int get_status(disk_t
*diskp
, int fd
, nvlist_t
*attrs
);
44 alias_get_assoc_descriptors(descriptor_t
*desc
, dm_desc_type_t type
,
49 return (drive_get_assocs(desc
, errp
));
57 alias_get_attributes(descriptor_t
*dp
, int *errp
)
60 nvlist_t
*attrs
= NULL
;
62 /* Find the alias for this descriptor */
65 for (ap
= dp
->p
.disk
->aliases
; ap
!= NULL
; ap
= ap
->next
) {
66 if (libdiskmgt_str_eq(dp
->name
, ap
->alias
)) {
67 /* we found the alias for this descriptor */
69 if (nvlist_alloc(&attrs
, NVATTRS
, 0) != 0) {
74 if (ap
->target
>= 0) {
75 if (nvlist_add_uint32(attrs
, DM_LUN
, ap
->lun
) != 0) {
81 if (nvlist_add_uint32(attrs
, DM_TARGET
, ap
->target
) != 0) {
88 if (ap
->wwn
!= NULL
) {
89 if (nvlist_add_string(attrs
, DM_WWN
, ap
->wwn
) != 0) {
96 if (ap
->devpaths
!= NULL
) {
97 /* get the status for this alias */
100 fd
= open(ap
->devpaths
->devpath
, O_RDONLY
|O_NDELAY
);
102 if ((*errp
= get_status(dp
->p
.disk
, fd
, attrs
)) != 0) {
121 alias_get_descriptor_by_name(char *name
, int *errp
)
123 descriptor_t
**aliases
;
125 descriptor_t
*alias
= NULL
;
127 aliases
= cache_get_descriptors(DM_ALIAS
, errp
);
132 for (i
= 0; aliases
[i
]; i
++) {
133 if (libdiskmgt_str_eq(name
, aliases
[i
]->name
)) {
136 /* clean up the unused descriptors */
137 cache_free_descriptor(aliases
[i
]);
151 alias_get_descriptors(int filter
[], int *errp
)
153 return (cache_get_descriptors(DM_ALIAS
, errp
));
157 alias_get_name(descriptor_t
*desc
)
164 alias_get_stats(descriptor_t
*dp
, int stat_type
, int *errp
)
166 /* There are no stat types defined for aliases */
172 alias_make_descriptors()
177 dp
= cache_get_disklist();
183 if (ap
->alias
!= NULL
) {
184 cache_load_desc(DM_ALIAS
, dp
, ap
->alias
, NULL
, &error
);
198 get_status(disk_t
*diskp
, int fd
, nvlist_t
*attrs
)
200 struct dk_minfo minfo
;
202 /* Make sure media is inserted and spun up. */
203 if (fd
>= 0 && media_read_info(fd
, &minfo
)) {
205 if (nvlist_add_uint32(attrs
, DM_STATUS
, DM_DISK_UP
) != 0) {
210 /* Not ready, so either no media or dead. */
212 if (diskp
->removable
) {
213 /* This is a removable drive with no media. */
214 if (nvlist_add_uint32(attrs
, DM_STATUS
, DM_DISK_UP
) != 0) {
218 /* not removable, so must be dead */
219 if (nvlist_add_uint32(attrs
, DM_STATUS
, DM_DISK_DOWN
) != 0) {