xref: /titanic_51/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_GetPathLogicalUnitProperties.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <string.h>
27 #include <syslog.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <stropts.h>
31 
32 #include "mp_utils.h"
33 
34 
35 MP_STATUS
36 MP_GetPathLogicalUnitProperties(MP_OID oid,
37 	MP_PATH_LOGICAL_UNIT_PROPERTIES *pProps)
38 {
39 	mp_iocdata_t   	mp_ioctl;
40 	mp_path_prop_t	pathInfo;
41 
42 	int ioctlStatus = 0;
43 
44 	MP_OID initPortOID;
45 	MP_OID targetPortOID;
46 	MP_OID luOID;
47 
48 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
49 
50 
51 
52 	log(LOG_INFO, "MP_GetPathLogicalUnitProperties()", " - enter");
53 
54 
55 	log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
56 		"oid.objectSequenceNumber = %llx",
57 		oid.objectSequenceNumber);
58 
59 
60 	if (g_scsi_vhci_fd < 0) {
61 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
62 		    "invalid driver file handle");
63 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
64 			" - error exit");
65 		return (MP_STATUS_FAILED);
66 	}
67 
68 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
69 	(void) memset(&pathInfo, 0, sizeof (mp_path_prop_t));
70 
71 	mp_ioctl.mp_cmd  = MP_GET_PATH_PROP;
72 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
73 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
74 	mp_ioctl.mp_obuf = (caddr_t)&pathInfo;
75 	mp_ioctl.mp_olen = sizeof (mp_path_prop_t);
76 	mp_ioctl.mp_xfer = MP_XFER_READ;
77 
78 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
79 
80 	log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
81 		" IOCTL call returned: %d", ioctlStatus);
82 
83 	if (ioctlStatus < 0) {
84 		ioctlStatus = errno;
85 	}
86 
87 	if (ioctlStatus != 0) {
88 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
89 		    "IOCTL call failed.  IOCTL error is: %d",
90 			ioctlStatus);
91 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
92 		    "IOCTL call failed.  IOCTL error is: %s",
93 			strerror(ioctlStatus));
94 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
95 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
96 			mp_ioctl.mp_errno);
97 
98 		if (ENOTSUP == ioctlStatus) {
99 			mpStatus = MP_STATUS_UNSUPPORTED;
100 		} else if (0 == mp_ioctl.mp_errno) {
101 			mpStatus = MP_STATUS_FAILED;
102 		} else {
103 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
104 		}
105 
106 		log(LOG_INFO, "MP_GetPathLogicalUnitProperties()",
107 			" - error exit");
108 
109 		return (mpStatus);
110 	}
111 
112 	(void) memset(pProps, 0, sizeof (MP_PATH_LOGICAL_UNIT_PROPERTIES));
113 
114 	pProps->disabled = pathInfo.disabled;
115 
116 	initPortOID.objectSequenceNumber = pathInfo.initPort.id;
117 	initPortOID.objectType = MP_OBJECT_TYPE_INITIATOR_PORT;
118 	initPortOID.ownerId = g_pluginOwnerID;
119 
120 	(void) memcpy(&pProps->initiatorPortOid, &initPortOID, sizeof (MP_OID));
121 
122 	targetPortOID.objectSequenceNumber = pathInfo.targetPort.id;
123 	targetPortOID.objectType = MP_OBJECT_TYPE_TARGET_PORT;
124 	targetPortOID.ownerId = g_pluginOwnerID;
125 
126 	(void) memcpy(&pProps->targetPortOid, &targetPortOID, sizeof (MP_OID));
127 
128 	luOID.objectSequenceNumber = pathInfo.logicalUnit.id;
129 	luOID.objectType = MP_OBJECT_TYPE_MULTIPATH_LU;
130 	luOID.ownerId = g_pluginOwnerID;
131 
132 	(void) memcpy(&pProps->logicalUnitOid, &luOID, sizeof (MP_OID));
133 
134 	pProps->logicalUnitNumber = pathInfo.logicalUnit.id;
135 
136 	switch (pathInfo.pathState) {
137 
138 		case MP_DRVR_PATH_STATE_ACTIVE:
139 		case MP_DRVR_PATH_STATE_PASSIVE:
140 			pProps->pathState = MP_PATH_STATE_OKAY;
141 			break;
142 
143 		case MP_DRVR_PATH_STATE_PATH_ERR:
144 			pProps->pathState = MP_PATH_STATE_PATH_ERR;
145 			break;
146 
147 		case MP_DRVR_PATH_STATE_LU_ERR:
148 			pProps->pathState = MP_PATH_STATE_LU_ERR;
149 			break;
150 
151 		case MP_DRVR_PATH_STATE_RESERVED:
152 			pProps->pathState = MP_PATH_STATE_RESERVED;
153 			break;
154 
155 		case MP_DRVR_PATH_STATE_REMOVED:
156 			pProps->pathState = MP_PATH_STATE_REMOVED;
157 			break;
158 
159 		case MP_DRVR_PATH_STATE_TRANSITIONING:
160 			pProps->pathState = MP_PATH_STATE_TRANSITIONING;
161 			break;
162 
163 		default:
164 			pProps->pathState = MP_PATH_STATE_UNKNOWN;
165 
166 	}
167 
168 	pProps->weight = pathInfo.weight;
169 
170 
171 	log(LOG_INFO, "MP_GetPathLogicalUnitProperties()", " - exit");
172 
173 	return (MP_STATUS_SUCCESS);
174 }
175