4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
30 #include <libdevinfo.h>
35 static int getOidList(di_node_t root_node
,
36 MP_OID_LIST
*pOidList
,
44 int haveList
= (NULL
!= pOidList
);
49 di_node_t sv_node
= DI_NODE_NIL
;
50 di_node_t sv_child_node
= DI_NODE_NIL
;
57 log(LOG_INFO
, "getOidList()", " - enter");
60 sv_node
= di_drv_first_node("scsi_vhci", root_node
);
61 if (DI_NODE_NIL
== sv_node
) {
62 log(LOG_INFO
, "getOidList()", " - di_drv_first_node() failed");
67 sv_child_node
= di_child_node(sv_node
);
69 while (DI_NODE_NIL
!= sv_child_node
) {
71 (void) di_prop_lookup_strings(DDI_DEV_T_ANY
, sv_child_node
,
72 "inquiry-product-id", &pid
);
74 pidSize
= strlen(pid
);
76 (void) di_prop_lookup_strings(DDI_DEV_T_ANY
, sv_child_node
,
77 "inquiry-vendor-id", &vid
);
79 vidSize
= strlen(vid
);
81 if ((0 == strncmp(pProductID
, pid
, pidSize
)) &&
82 (0 == strncmp(pVendorID
, vid
, vidSize
))) {
84 instNum
= di_instance(sv_child_node
);
85 majorNum
= di_driver_major(sv_child_node
);
87 if (haveList
&& numNodes
< pOidList
->oidCount
) {
90 osn
= MP_STORE_INST_TO_ID(instNum
, osn
);
91 osn
= MP_STORE_MAJOR_TO_ID(majorNum
, osn
);
93 pOidList
->oids
[numNodes
].objectType
=
94 MP_OBJECT_TYPE_MULTIPATH_LU
;
96 pOidList
->oids
[numNodes
].ownerId
=
99 pOidList
->oids
[numNodes
].objectSequenceNumber
=
106 sv_child_node
= di_sibling_node(sv_child_node
);
110 log(LOG_INFO
, "getOidList()", " - numNodes: %d", numNodes
);
111 log(LOG_INFO
, "getOidList()", " - exit");
118 MP_GetMultipathLusDevProd(MP_OID oid
, MP_OID_LIST
**ppList
)
120 di_node_t root_node
= DI_NODE_NIL
;
122 MP_STATUS mpStatus
= MP_STATUS_SUCCESS
;
128 mp_iocdata_t mp_ioctl
;
129 mp_dev_prod_prop_t devProdInfo
;
131 char inqProductID
[256];
132 char inqVendorID
[256];
135 log(LOG_INFO
, "MP_GetMultipathLusDevProd()", " - enter");
137 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
138 "oid.objectSequenceNumber = %llx",
139 oid
.objectSequenceNumber
);
141 if (g_scsi_vhci_fd
< 0) {
142 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
143 "invalid driver file handle");
144 log(LOG_INFO
, "MP_GetMultipathLusDevProd",
146 return (MP_STATUS_FAILED
);
149 (void) memset(&mp_ioctl
, 0, sizeof (mp_iocdata_t
));
150 (void) memset(&devProdInfo
, 0, sizeof (mp_dev_prod_prop_t
));
152 mp_ioctl
.mp_cmd
= MP_GET_DEV_PROD_PROP
;
153 mp_ioctl
.mp_ibuf
= (caddr_t
)&oid
.objectSequenceNumber
;
154 mp_ioctl
.mp_ilen
= sizeof (oid
.objectSequenceNumber
);
155 mp_ioctl
.mp_obuf
= (caddr_t
)&devProdInfo
;
156 mp_ioctl
.mp_olen
= sizeof (mp_dev_prod_prop_t
);
157 mp_ioctl
.mp_xfer
= MP_XFER_READ
;
159 ioctlStatus
= ioctl(g_scsi_vhci_fd
, MP_CMD
, &mp_ioctl
);
161 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
162 " IOCTL call returned: %d", ioctlStatus
);
164 if (ioctlStatus
< 0) {
168 if (ioctlStatus
!= 0) {
169 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
170 "IOCTL call failed. IOCTL error is: %d",
172 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
173 "IOCTL call failed. IOCTL error is: %s",
174 strerror(ioctlStatus
));
175 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
176 "IOCTL call failed. mp_ioctl.mp_errno: %x",
179 if (ENOTSUP
== ioctlStatus
) {
180 mpStatus
= MP_STATUS_UNSUPPORTED
;
181 } else if (0 == mp_ioctl
.mp_errno
) {
182 mpStatus
= MP_STATUS_FAILED
;
184 mpStatus
= getStatus4ErrorCode(mp_ioctl
.mp_errno
);
187 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
193 (void) strncpy(inqProductID
, devProdInfo
.prodInfo
.product
,
194 sizeof (devProdInfo
.prodInfo
.product
));
196 (void) strncpy(inqVendorID
, devProdInfo
.prodInfo
.vendor
,
197 sizeof (devProdInfo
.prodInfo
.vendor
));
199 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
200 " - inqProductID: [%s]", inqProductID
);
201 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
202 " - inqVendorID: [%s]", inqVendorID
);
204 root_node
= di_init("/", DINFOCACHE
);
205 if (DI_NODE_NIL
== root_node
) {
206 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
207 " - di_init() failed");
209 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
212 return (MP_STATUS_FAILED
);
215 numNodes
= getOidList(root_node
, NULL
, inqProductID
, inqVendorID
);
218 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
219 " - unable to get OID list.");
221 log(LOG_INFO
, "MP_GetMultipathLusDevProd()", " - error exit");
225 return (MP_STATUS_FAILED
);
231 *ppList
= createOidList(1);
232 if (NULL
== *ppList
) {
234 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
235 " - unable to create OID list.");
237 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
242 return (MP_STATUS_INSUFFICIENT_MEMORY
);
245 (*ppList
)->oids
[0].objectType
= MP_OBJECT_TYPE_MULTIPATH_LU
;
246 (*ppList
)->oids
[0].ownerId
= g_pluginOwnerID
;
248 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
249 " - returning empty list.");
251 return (MP_STATUS_SUCCESS
);
254 *ppList
= createOidList(numNodes
);
255 if (NULL
== *ppList
) {
256 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
257 "no memory for *ppList");
258 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
260 return (MP_STATUS_INSUFFICIENT_MEMORY
);
263 (*ppList
)->oidCount
= numNodes
;
265 numNodes
= getOidList(root_node
, *ppList
, inqProductID
, inqVendorID
);
267 for (i
= 0; i
< (*ppList
)->oidCount
; i
++) {
269 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
270 "(*ppList)->oids[%d].objectType = %d",
271 i
, (*ppList
)->oids
[i
].objectType
);
272 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
273 "(*ppList)->oids[%d].ownerId = %d",
274 i
, (*ppList
)->oids
[i
].ownerId
);
275 log(LOG_INFO
, "MP_GetMultipathLusDevProd()",
276 "(*ppList)->oids[%d].objectSequenceNumber = %llx",
277 i
, (*ppList
)->oids
[i
].objectSequenceNumber
);
283 log(LOG_INFO
, "MP_GetMultipathLusDevProd()", " - exit");
285 return (MP_STATUS_SUCCESS
);