1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte * CDDL HEADER START
3*fcf3ce44SJohn Forte *
4*fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte *
8*fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte * and limitations under the License.
12*fcf3ce44SJohn Forte *
13*fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte *
19*fcf3ce44SJohn Forte * CDDL HEADER END
20*fcf3ce44SJohn Forte */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*fcf3ce44SJohn Forte * Use is subject to license terms.
24*fcf3ce44SJohn Forte */
25*fcf3ce44SJohn Forte
26*fcf3ce44SJohn Forte #include <string.h>
27*fcf3ce44SJohn Forte #include <syslog.h>
28*fcf3ce44SJohn Forte #include <errno.h>
29*fcf3ce44SJohn Forte #include <unistd.h>
30*fcf3ce44SJohn Forte #include <stropts.h>
31*fcf3ce44SJohn Forte
32*fcf3ce44SJohn Forte #include "mp_utils.h"
33*fcf3ce44SJohn Forte
34*fcf3ce44SJohn Forte
35*fcf3ce44SJohn Forte MP_STATUS
MP_GetPathLogicalUnitProperties(MP_OID oid,MP_PATH_LOGICAL_UNIT_PROPERTIES * pProps)36*fcf3ce44SJohn Forte MP_GetPathLogicalUnitProperties(MP_OID oid,
37*fcf3ce44SJohn Forte MP_PATH_LOGICAL_UNIT_PROPERTIES *pProps)
38*fcf3ce44SJohn Forte {
39*fcf3ce44SJohn Forte mp_iocdata_t mp_ioctl;
40*fcf3ce44SJohn Forte mp_path_prop_t pathInfo;
41*fcf3ce44SJohn Forte
42*fcf3ce44SJohn Forte int ioctlStatus = 0;
43*fcf3ce44SJohn Forte
44*fcf3ce44SJohn Forte MP_OID initPortOID;
45*fcf3ce44SJohn Forte MP_OID targetPortOID;
46*fcf3ce44SJohn Forte MP_OID luOID;
47*fcf3ce44SJohn Forte
48*fcf3ce44SJohn Forte MP_STATUS mpStatus = MP_STATUS_SUCCESS;
49*fcf3ce44SJohn Forte
50*fcf3ce44SJohn Forte
51*fcf3ce44SJohn Forte
52*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()", " - enter");
53*fcf3ce44SJohn Forte
54*fcf3ce44SJohn Forte
55*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
56*fcf3ce44SJohn Forte "oid.objectSequenceNumber = %llx",
57*fcf3ce44SJohn Forte oid.objectSequenceNumber);
58*fcf3ce44SJohn Forte
59*fcf3ce44SJohn Forte
60*fcf3ce44SJohn Forte if (g_scsi_vhci_fd < 0) {
61*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
62*fcf3ce44SJohn Forte "invalid driver file handle");
63*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
64*fcf3ce44SJohn Forte " - error exit");
65*fcf3ce44SJohn Forte return (MP_STATUS_FAILED);
66*fcf3ce44SJohn Forte }
67*fcf3ce44SJohn Forte
68*fcf3ce44SJohn Forte (void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
69*fcf3ce44SJohn Forte (void) memset(&pathInfo, 0, sizeof (mp_path_prop_t));
70*fcf3ce44SJohn Forte
71*fcf3ce44SJohn Forte mp_ioctl.mp_cmd = MP_GET_PATH_PROP;
72*fcf3ce44SJohn Forte mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
73*fcf3ce44SJohn Forte mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
74*fcf3ce44SJohn Forte mp_ioctl.mp_obuf = (caddr_t)&pathInfo;
75*fcf3ce44SJohn Forte mp_ioctl.mp_olen = sizeof (mp_path_prop_t);
76*fcf3ce44SJohn Forte mp_ioctl.mp_xfer = MP_XFER_READ;
77*fcf3ce44SJohn Forte
78*fcf3ce44SJohn Forte ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
79*fcf3ce44SJohn Forte
80*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
81*fcf3ce44SJohn Forte " IOCTL call returned: %d", ioctlStatus);
82*fcf3ce44SJohn Forte
83*fcf3ce44SJohn Forte if (ioctlStatus < 0) {
84*fcf3ce44SJohn Forte ioctlStatus = errno;
85*fcf3ce44SJohn Forte }
86*fcf3ce44SJohn Forte
87*fcf3ce44SJohn Forte if (ioctlStatus != 0) {
88*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
89*fcf3ce44SJohn Forte "IOCTL call failed. IOCTL error is: %d",
90*fcf3ce44SJohn Forte ioctlStatus);
91*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
92*fcf3ce44SJohn Forte "IOCTL call failed. IOCTL error is: %s",
93*fcf3ce44SJohn Forte strerror(ioctlStatus));
94*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
95*fcf3ce44SJohn Forte "IOCTL call failed. mp_ioctl.mp_errno: %x",
96*fcf3ce44SJohn Forte mp_ioctl.mp_errno);
97*fcf3ce44SJohn Forte
98*fcf3ce44SJohn Forte if (ENOTSUP == ioctlStatus) {
99*fcf3ce44SJohn Forte mpStatus = MP_STATUS_UNSUPPORTED;
100*fcf3ce44SJohn Forte } else if (0 == mp_ioctl.mp_errno) {
101*fcf3ce44SJohn Forte mpStatus = MP_STATUS_FAILED;
102*fcf3ce44SJohn Forte } else {
103*fcf3ce44SJohn Forte mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
104*fcf3ce44SJohn Forte }
105*fcf3ce44SJohn Forte
106*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
107*fcf3ce44SJohn Forte " - error exit");
108*fcf3ce44SJohn Forte
109*fcf3ce44SJohn Forte return (mpStatus);
110*fcf3ce44SJohn Forte }
111*fcf3ce44SJohn Forte
112*fcf3ce44SJohn Forte (void) memset(pProps, 0, sizeof (MP_PATH_LOGICAL_UNIT_PROPERTIES));
113*fcf3ce44SJohn Forte
114*fcf3ce44SJohn Forte pProps->disabled = pathInfo.disabled;
115*fcf3ce44SJohn Forte
116*fcf3ce44SJohn Forte initPortOID.objectSequenceNumber = pathInfo.initPort.id;
117*fcf3ce44SJohn Forte initPortOID.objectType = MP_OBJECT_TYPE_INITIATOR_PORT;
118*fcf3ce44SJohn Forte initPortOID.ownerId = g_pluginOwnerID;
119*fcf3ce44SJohn Forte
120*fcf3ce44SJohn Forte (void) memcpy(&pProps->initiatorPortOid, &initPortOID, sizeof (MP_OID));
121*fcf3ce44SJohn Forte
122*fcf3ce44SJohn Forte targetPortOID.objectSequenceNumber = pathInfo.targetPort.id;
123*fcf3ce44SJohn Forte targetPortOID.objectType = MP_OBJECT_TYPE_TARGET_PORT;
124*fcf3ce44SJohn Forte targetPortOID.ownerId = g_pluginOwnerID;
125*fcf3ce44SJohn Forte
126*fcf3ce44SJohn Forte (void) memcpy(&pProps->targetPortOid, &targetPortOID, sizeof (MP_OID));
127*fcf3ce44SJohn Forte
128*fcf3ce44SJohn Forte luOID.objectSequenceNumber = pathInfo.logicalUnit.id;
129*fcf3ce44SJohn Forte luOID.objectType = MP_OBJECT_TYPE_MULTIPATH_LU;
130*fcf3ce44SJohn Forte luOID.ownerId = g_pluginOwnerID;
131*fcf3ce44SJohn Forte
132*fcf3ce44SJohn Forte (void) memcpy(&pProps->logicalUnitOid, &luOID, sizeof (MP_OID));
133*fcf3ce44SJohn Forte
134*fcf3ce44SJohn Forte pProps->logicalUnitNumber = pathInfo.logicalUnit.id;
135*fcf3ce44SJohn Forte
136*fcf3ce44SJohn Forte switch (pathInfo.pathState) {
137*fcf3ce44SJohn Forte
138*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_ACTIVE:
139*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_PASSIVE:
140*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_OKAY;
141*fcf3ce44SJohn Forte break;
142*fcf3ce44SJohn Forte
143*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_PATH_ERR:
144*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_PATH_ERR;
145*fcf3ce44SJohn Forte break;
146*fcf3ce44SJohn Forte
147*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_LU_ERR:
148*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_LU_ERR;
149*fcf3ce44SJohn Forte break;
150*fcf3ce44SJohn Forte
151*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_RESERVED:
152*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_RESERVED;
153*fcf3ce44SJohn Forte break;
154*fcf3ce44SJohn Forte
155*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_REMOVED:
156*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_REMOVED;
157*fcf3ce44SJohn Forte break;
158*fcf3ce44SJohn Forte
159*fcf3ce44SJohn Forte case MP_DRVR_PATH_STATE_TRANSITIONING:
160*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_TRANSITIONING;
161*fcf3ce44SJohn Forte break;
162*fcf3ce44SJohn Forte
163*fcf3ce44SJohn Forte default:
164*fcf3ce44SJohn Forte pProps->pathState = MP_PATH_STATE_UNKNOWN;
165*fcf3ce44SJohn Forte
166*fcf3ce44SJohn Forte }
167*fcf3ce44SJohn Forte
168*fcf3ce44SJohn Forte pProps->weight = pathInfo.weight;
169*fcf3ce44SJohn Forte
170*fcf3ce44SJohn Forte
171*fcf3ce44SJohn Forte log(LOG_INFO, "MP_GetPathLogicalUnitProperties()", " - exit");
172*fcf3ce44SJohn Forte
173*fcf3ce44SJohn Forte return (MP_STATUS_SUCCESS);
174*fcf3ce44SJohn Forte }
175