xref: /illumos-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_GetPluginPropertiesPlugin.c (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
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 "mp_utils.h"
27 
28 #include <string.h>
29 #include <syslog.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <stropts.h>
33 
34 
35 
36 MP_STATUS
37 MP_GetPluginPropertiesPlugin(MP_PLUGIN_PROPERTIES *pProps)
38 {
39 	mp_iocdata_t		mp_ioctl;
40 	mp_driver_prop_t	driverInfo;
41 
42 	int ioctlStatus = 0;
43 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
44 
45 	log(LOG_INFO, "MP_GetPluginPropertiesPlugin()", " - enter");
46 
47 	if (g_scsi_vhci_fd < 0) {
48 		log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
49 		    "invalid driver file handle");
50 		return (MP_STATUS_FAILED);
51 	}
52 
53 	(void) memset(pProps, 0, sizeof (MP_PLUGIN_PROPERTIES));
54 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
55 	(void) memset(&driverInfo, 0, sizeof (mp_driver_prop_t));
56 
57 	mp_ioctl.mp_cmd  = MP_GET_DRIVER_PROP;
58 	mp_ioctl.mp_obuf = (caddr_t)&driverInfo;
59 	mp_ioctl.mp_olen = sizeof (mp_driver_prop_t);
60 	mp_ioctl.mp_xfer = MP_XFER_READ;
61 
62 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
63 
64 	log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
65 		" IOCTL call returned: %d", ioctlStatus);
66 
67 	if (ioctlStatus < 0) {
68 		ioctlStatus = errno;
69 	}
70 
71 	if (ioctlStatus != 0) {
72 		log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
73 		    "IOCTL call failed.  IOCTL error is: %d",
74 			ioctlStatus);
75 		log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
76 		    "IOCTL call failed.  IOCTL error is: %s",
77 			strerror(ioctlStatus));
78 		log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
79 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
80 			mp_ioctl.mp_errno);
81 
82 		if (ENOTSUP == ioctlStatus) {
83 			mpStatus = MP_STATUS_UNSUPPORTED;
84 		} else if (0 == mp_ioctl.mp_errno) {
85 			mpStatus = MP_STATUS_FAILED;
86 		} else {
87 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
88 		}
89 
90 		log(LOG_INFO, "MP_GetPluginPropertiesPlugin()",
91 			" - error exit");
92 
93 		return (mpStatus);
94 	}
95 
96 	(void) wcsncpy(pProps->vendor, L"Sun Microsystems", 255);
97 
98 	pProps->autoFailbackSupport = driverInfo.autoFailbackSupport;
99 	pProps->autoProbingSupport  = driverInfo.autoProbingSupport;
100 
101 #ifdef BUILD_TIME
102 	(void) mbstowcs(pProps->buildTime, BUILD_TIME, 256);
103 #endif
104 
105 	pProps->canOverridePaths = driverInfo.canOverridePaths;
106 	pProps->canSetTPGAccess  = driverInfo.canSetTPGAccess;
107 	pProps->currentFailbackPollingRate =
108 		driverInfo.currentFailbackPollingRate;
109 	pProps->currentProbingPollingRate  =
110 		driverInfo.currentProbingPollingRate;
111 	pProps->defaultloadBalanceType =
112 		driverInfo.defaultLoadBalanceType;
113 
114 	(void) strncpy(pProps->deviceFileNamespace,
115 	    driverInfo.deviceFileNamespace, 255);
116 
117 	(void) strncpy(pProps->driverName, "scsi_vhci", 255);
118 
119 	(void) wcsncpy(pProps->driverVendor, L"Sun Microsystems", 255);
120 
121 	(void) mbstowcs(pProps->driverVersion, driverInfo.driverVersion, 256);
122 
123 	pProps->exposesPathDeviceFiles = driverInfo.exposesPathDeviceFiles;
124 	pProps->failbackPollingRateMax = driverInfo.failbackPollingRateMax;
125 
126 	(void) strncpy(pProps->fileName, "libmpscsi_vhci.so", 255);
127 
128 	(void) wcsncpy(pProps->implementationVersion, L"1.0.0.0", 255);
129 
130 	pProps->maximumWeight = driverInfo.maximumWeight;
131 	pProps->onlySupportsSpecifiedProducts =
132 		driverInfo.onlySupportsSpecifiedProducts;
133 
134 	pProps->pluginAutoFailbackEnabled = driverInfo.autoFailbackEnabled;
135 	pProps->pluginAutoProbingEnabled  = driverInfo.autoProbingEnabled;
136 
137 	pProps->probingPollingRateMax = driverInfo.probingPollingRateMax;
138 
139 	pProps->supportedLoadBalanceTypes =
140 		driverInfo.supportedLoadBalanceTypes;
141 	pProps->supportedMpVersion = MP_LIBVERSION;
142 
143 
144 	log(LOG_INFO, "MP_GetPluginPropertiesPlugin()", " - exit");
145 
146 	return (MP_STATUS_SUCCESS);
147 }
148