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 
33 #include "mp_utils.h"
34 
35 
36 
37 MP_STATUS
MP_GetTargetPortGroupProperties(MP_OID oid,MP_TARGET_PORT_GROUP_PROPERTIES * pProps)38 MP_GetTargetPortGroupProperties(MP_OID oid,
39 	MP_TARGET_PORT_GROUP_PROPERTIES *pProps)
40 {
41 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
42 
43 
44 	log(LOG_INFO, "MP_GetTargetPortGroupProperties()", " - enter");
45 
46 
47 	mpStatus = getTargetPortGroupProperties(oid, pProps);
48 
49 
50 	log(LOG_INFO, "MP_GetTargetPortGroupProperties()", " - exit");
51 
52 	return (mpStatus);
53 }
54 
55 
56 MP_STATUS
getTargetPortGroupProperties(MP_OID oid,MP_TARGET_PORT_GROUP_PROPERTIES * pProps)57 getTargetPortGroupProperties(MP_OID oid,
58 	MP_TARGET_PORT_GROUP_PROPERTIES *pProps)
59 {
60 	mp_iocdata_t	mp_ioctl;
61 	mp_tpg_prop_t	tpgProps;
62 
63 	int ioctlStatus = 0;
64 
65 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
66 
67 
68 	log(LOG_INFO, "getTargetPortGroupProperties()", " - enter");
69 
70 	if (g_scsi_vhci_fd < 0) {
71 		log(LOG_INFO, "getTargetPortGroupProperties()",
72 		    "invalid driver file handle");
73 		log(LOG_INFO, "getTargetPortGroupProperties",
74 			" - error exit");
75 		return (MP_STATUS_FAILED);
76 	}
77 
78 	log(LOG_INFO, "getTargetPortGroupProperties()",
79 		"oid.objectSequenceNumber = %llx",
80 		oid.objectSequenceNumber);
81 
82 	(void) memset(pProps, 0, sizeof (MP_TARGET_PORT_GROUP_PROPERTIES));
83 	(void) memset(&tpgProps, 0, sizeof (mp_tpg_prop_t));
84 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
85 
86 	mp_ioctl.mp_cmd  = MP_GET_TPG_PROP;
87 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
88 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
89 	mp_ioctl.mp_obuf = (caddr_t)&tpgProps;
90 	mp_ioctl.mp_olen = sizeof (mp_tpg_prop_t);
91 	mp_ioctl.mp_xfer = MP_XFER_READ;
92 
93 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
94 
95 	log(LOG_INFO, "getTargetPortGroupProperties()",
96 		" IOCTL call returned: %d", ioctlStatus);
97 
98 	if (ioctlStatus < 0) {
99 		ioctlStatus = errno;
100 	}
101 
102 	if (ioctlStatus != 0) {
103 		log(LOG_INFO, "getTargetPortGroupProperties()",
104 		    "IOCTL call failed.  IOCTL error is: %d",
105 			ioctlStatus);
106 		log(LOG_INFO, "getTargetPortGroupProperties()",
107 		    "IOCTL call failed.  IOCTL error is: %s",
108 			strerror(ioctlStatus));
109 		log(LOG_INFO, "getTargetPortGroupProperties()",
110 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
111 			mp_ioctl.mp_errno);
112 
113 		if (ENOTSUP == ioctlStatus) {
114 			mpStatus = MP_STATUS_UNSUPPORTED;
115 		} else if (0 == mp_ioctl.mp_errno) {
116 			mpStatus = MP_STATUS_FAILED;
117 		} else {
118 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
119 		}
120 
121 		log(LOG_INFO, "getTargetPortGroupProperties()",
122 			" - error exit");
123 
124 		return (mpStatus);
125 	}
126 
127 	pProps->accessState = tpgProps.accessState;
128 	pProps->explicitFailover = tpgProps.explicitFailover;
129 	pProps->preferredLuPath = tpgProps.preferredLuPath;
130 	pProps->supportsLuAssignment = tpgProps.supportsLuAssignment;
131 	pProps->tpgID = tpgProps.tpgId;
132 
133 
134 	log(LOG_INFO, "getTargetPortGroupProperties()", " - exit");
135 
136 	return (MP_STATUS_SUCCESS);
137 }
138