xref: /illumos-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_GetProprietaryLBProp.c (revision 07a48826732249fcd3aa8dd53c8389595e9f1fbc)
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 <syslog.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <stropts.h>
30 
31 
32 #include "mp_utils.h"
33 
34 
35 MP_STATUS
36 MP_GetProprietaryLoadBalanceProperties(MP_OID oid,
37 	MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES *pProps)
38 {
39 	mp_iocdata_t				mp_ioctl;
40 	mp_proprietary_loadbalance_prop_t	lbProps;
41 
42 	int ioctlStatus = 0;
43 
44 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
45 
46 
47 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()", " - enter");
48 
49 
50 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
51 		"oid.objectSequenceNumber = %llx",
52 		oid.objectSequenceNumber);
53 
54 	if (g_scsi_vhci_fd < 0) {
55 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
56 		    "invalid driver file handle");
57 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties",
58 			" - error exit");
59 		return (MP_STATUS_FAILED);
60 	}
61 
62 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
63 	(void) memset(&lbProps, 0, sizeof (mp_proprietary_loadbalance_prop_t));
64 
65 	mp_ioctl.mp_cmd  = MP_GET_PROPRIETARY_LOADBALANCE_PROP;
66 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
67 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
68 	mp_ioctl.mp_obuf = (caddr_t)&lbProps;
69 	mp_ioctl.mp_olen = sizeof (mp_proprietary_loadbalance_prop_t);
70 	mp_ioctl.mp_xfer = MP_XFER_READ;
71 
72 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
73 
74 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
75 		" IOCTL call returned: %d", ioctlStatus);
76 
77 	if (ioctlStatus < 0) {
78 		ioctlStatus = errno;
79 	}
80 
81 	if (ioctlStatus != 0) {
82 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
83 		    "IOCTL call failed.  IOCTL error is: %d",
84 			ioctlStatus);
85 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
86 		    "IOCTL call failed.  IOCTL error is: %s",
87 			strerror(ioctlStatus));
88 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
89 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
90 			mp_ioctl.mp_errno);
91 
92 		if (ENOTSUP == ioctlStatus) {
93 			mpStatus = MP_STATUS_UNSUPPORTED;
94 		} else if (0 == mp_ioctl.mp_errno) {
95 			mpStatus = MP_STATUS_FAILED;
96 		} else {
97 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
98 		}
99 
100 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()",
101 			" - error exit");
102 
103 		return (mpStatus);
104 	}
105 
106 	(void) memset(pProps, 0,
107 	    sizeof (MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES));
108 
109 	(void) mbstowcs(pProps->name, lbProps.name, 256);
110 
111 	/*
112 	 *
113 	 * Get:
114 	 *
115 	 * pProps->proprietaryPropertyCount &
116 	 * pProps->proprietaryProperties
117 	 *
118 	 * when they are available
119 	 *
120 	 */
121 
122 	pProps->typeIndex = lbProps.typeIndex;
123 	(void) mbstowcs(pProps->vendorName, lbProps.vendorName, 256);
124 
125 
126 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceProperties()", " - exit");
127 
128 	return (MP_STATUS_SUCCESS);
129 }
130