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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <unistd.h>
30 #include <netdb.h>
31 #include <errno.h>
32 
33 #include "util.h"
34 #include "cimKeys.h"
35 #include "ctrl_descriptors.h"
36 #include "providerNames.h"
37 #include "messageStrings.h"
38 #include "Solaris_MPXIOController.h"
39 
40 #define	MPXIO_GETINSTANCE	"MPXIO_CONTROLLER,GET_INSTANCE"
41 #define	MPXIO_ENUMINSTANCES	"MPXIO_CONTROLLER,ENUM_INSTANCES"
42 #define	MPXIO_ENUMINSTANCENAMES	"MPXIO_CONTROLLER,ENUM_INSTANCENAMES"
43 #define	MPXIO_CREATEINSTANCE	"MPXIO_CONTROLLER,CREATE_INSTANCE"
44 #define	MPXIO_DELETEINSTANCE	"MPXIO_CONTROLLER,DELETE_INSTANCE"
45 #define	MPXIO_SETINSTANCE	"MPXIO_CONTROLLER,SET_INSTANCE"
46 #define	MPXIO_GETPROPERTY	"MPXIO_CONTROLLER,GET_PROPERTY"
47 #define	MPXIO_SETPROPERTY	"MPXIO_CONTROLLER,SET_PROPERTY"
48 #define	MPXIO_INVOKEMETHOD	"MPXIO_CONTROLLER,INVOKE_METHOD"
49 #define	MPXIO_EXECQUERY		"MPXIO_CONTROLLER,EXEC_QUERY"
50 
51 /*
52  * Solaris_MPXIOController provider
53  *
54  * It is important to note that all memory allocated by these functions
55  * and passed to the CIMOM, is freed by the CIMOM as the caller.
56  */
57 
58 /*
59  * Name: cp_getInstance_Solaris_MPXIOController
60  *
61  * Description: Returns an instance which matches the passed in object path
62  * if found.
63  *
64  * Parameters:
65  *      pOP - An CCIMObjectPath * which contains the information on
66  *      the class for which to find the instance.
67  * Returns:
68  *      CCIMInstance * if matched instance is found. Otherwise, NULL.
69  */
70 
71 /* ARGSUSED */
72 CCIMInstance*
cp_getInstance_Solaris_MPXIOController(CCIMObjectPath * pOP)73 cp_getInstance_Solaris_MPXIOController(CCIMObjectPath* pOP)
74 {
75 	CCIMInstance		*inst = NULL;
76 	CCIMPropertyList	*pCurPropList;
77 	dm_descriptor_t		mpxioctrl_descriptor;
78 	char			*name;
79 	int			error;
80 
81 	if (pOP == NULL ||
82 	    pOP->mKeyProperties == NULL) {
83 	    util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
84 		NULL, &error);
85 	    return ((CCIMInstance *)NULL);
86 	}
87 
88 	pCurPropList = pOP->mKeyProperties;
89 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
90 	    &error);
91 
92 	if (error != 0 || name == NULL) {
93 	    util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
94 		NULL, &error);
95 	    return ((CCIMInstance*)NULL);
96 	}
97 
98 	mpxioctrl_descriptor =
99 	    dm_get_descriptor_by_name(DM_CONTROLLER, name, &error);
100 
101 	/*
102 	 * Not found. Return a null instance.
103 	 */
104 	if (error == ENODEV) {
105 	    return ((CCIMInstance *)NULL);
106 	}
107 
108 	if (error != 0) {
109 	    util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
110 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
111 	    return ((CCIMInstance*)NULL);
112 	}
113 
114 	/* Turn this descriptor in to a mpxio controller instance */
115 
116 	inst = ctrl_descriptor_toCCIMInstance(
117 	    hostName, mpxioctrl_descriptor, MPXIO_CONTROLLER, &error);
118 	dm_free_descriptor(mpxioctrl_descriptor);
119 
120 	if (error != 0) {
121 	    util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
122 		MPXIOCTRL_DESC_TO_INSTANCE_FAILURE, NULL,
123 		&error);
124 	    return ((CCIMInstance*)NULL);
125 	}
126 
127 	return (inst);
128 }
129 
130 /*
131  * Name: cp_enumInstances_Solaris_MPXIOController
132  *
133  * Description: Returns an instancelist of MPXIO controllers, if found.
134  *
135  * Parameters:
136  *      pOP - An CCIMObjectPath * which contains the information on
137  *      the class for which to find the instance.
138  * Returns:
139  *      CCIMInstanceList * if matched instance is found. Otherwise, NULL.
140  */
141 
142 /* ARGSUSED */
143 CCIMInstanceList*
cp_enumInstances_Solaris_MPXIOController(CCIMObjectPath * pOP)144 cp_enumInstances_Solaris_MPXIOController(CCIMObjectPath* pOP)
145 {
146 	CCIMInstanceList	*instList = NULL;
147 	dm_descriptor_t		*mpxioctrl_descriptorp;
148 	int			error;
149 	int			filter[1];
150 
151 	filter[0] = DM_FILTER_END;
152 
153 	mpxioctrl_descriptorp = dm_get_descriptors(DM_CONTROLLER, filter,
154 	    &error);
155 
156 	/*
157 	 * If no devices, return NULL. CIMOM expects NULL. Do not set
158 	 * last error. If set, the CIMOM will assume an error and
159 	 * throw an exception.
160 	 */
161 
162 	if (mpxioctrl_descriptorp == NULL ||
163 	    mpxioctrl_descriptorp[0] == NULL) {
164 	    return ((CCIMInstanceList *)NULL);
165 	}
166 	if (error != 0) {
167 	    util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
168 		DM_GET_DESCRIPTORS, NULL, &error);
169 	    return ((CCIMInstanceList *)NULL);
170 	}
171 
172 	/* convert controllers to CCIMInstanceList */
173 	instList = ctrl_descriptors_toCCIMInstanceList(MPXIO_CONTROLLER,
174 	    mpxioctrl_descriptorp, &error, 1, "scsi_vhci");
175 	dm_free_descriptors(mpxioctrl_descriptorp);
176 
177 	if (error != 0) {
178 	    util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
179 		MPXIOCTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
180 	    return ((CCIMInstanceList *)NULL);
181 	}
182 
183 	return (instList);
184 }
185 
186 /*
187  * Name: cp_enumInstanceNames_Solaris_MPXIOController
188  *
189  * Description: Returns an object pathlist of MPXIO controllers, if found.
190  *
191  * Parameters:
192  *      pOP - An CCIMObjectPath * which contains the information on
193  *      the class for which to find the instance.
194  * Returns:
195  *      CCIMObjectPathList * if matched instance is found. Otherwise, NULL.
196  */
197 
198 /* ARGSUSED */
199 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_MPXIOController(CCIMObjectPath * pOP)200 cp_enumInstanceNames_Solaris_MPXIOController(CCIMObjectPath * pOP) {
201 
202 	CCIMInstanceList	*instList = NULL;
203 	CCIMObjectPathList	*objList = NULL;
204 	int			error;
205 
206 	if (pOP == NULL) {
207 	    util_handleError(MPXIO_ENUMINSTANCENAMES,
208 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
209 	    return ((CCIMObjectPathList *)NULL);
210 	}
211 
212 	/*
213 	 * Call in to enumInstances and then convert the instance list in
214 	 * to an object list.
215 	 */
216 
217 	instList = cp_enumInstances_Solaris_MPXIOController(pOP);
218 	if (instList != NULL) {
219 	    objList = cim_createObjectPathList(instList);
220 	    cim_freeInstanceList(instList);
221 	}
222 
223 	return (objList);
224 }
225 
226 /*
227  * Creating an instance of a Solaris_MPXIOController is not supported.
228  */
229 
230 /* ARGSUSED */
231 CCIMObjectPath*
cp_createInstance_Solaris_MPXIOController(CCIMObjectPath * pOP,CCIMInstance * pInst)232 cp_createInstance_Solaris_MPXIOController(CCIMObjectPath* pOP,
233     CCIMInstance* pInst)
234 {
235 	int	error;
236 
237 	util_handleError(MPXIO_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
238 	    NULL, &error);
239 	return ((CCIMObjectPath*)NULL);
240 }
241 
242 /*
243  * Deleting an instance of a Solaris_MPXIOController is not supported.
244  */
245 
246 /* ARGSUSED */
247 CIMBool
cp_deleteInstance_Solaris_MPXIOController(CCIMObjectPath * pInst)248 cp_deleteInstance_Solaris_MPXIOController(CCIMObjectPath* pInst)
249 {
250 
251 	int	error;
252 
253 	util_handleError(MPXIO_DELETEINSTANCE,
254 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
255 	return (cim_false);
256 }
257 
258 /*
259  * Name: cp_getProperty_Solaris_MPXIOController
260  *
261  * Description: Returns the property requested, if found.
262  *
263  * Parameters:
264  *	pOP - An CCIMObjectPath * which contains the information on
265  *	the class for which to find the instances.
266  * Returns:
267  *	CCIMProperty * if found.
268  */
269 
270 /* ARGSUSED */
271 CCIMProperty	*
cp_getProperty_Solaris_MPXIOController(CCIMObjectPath * pOP,char * pPropName)272 cp_getProperty_Solaris_MPXIOController(CCIMObjectPath *pOP,
273     char *pPropName)
274 {
275 
276 	CCIMProperty	*prop = NULL;
277 	CCIMInstance	*inst = NULL;
278 	int		error = 0;
279 
280 	if (pOP == NULL) {
281 	    util_handleError(MPXIO_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
282 		NULL, &error);
283 	    return ((CCIMProperty *)NULL);
284 	}
285 
286 	inst = cp_getInstance_Solaris_MPXIOController(pOP);
287 	if (inst == NULL) {
288 	    return ((CCIMProperty *)NULL);
289 	}
290 
291 	prop = cim_getProperty(inst, pPropName);
292 	cim_freeInstance(inst);
293 	return (prop);
294 }
295 
296 /*
297  * Setting an instance of a Solaris_MPXIOController is not supported.
298  */
299 
300 /* ARGSUSED */
301 CIMBool
cp_setInstance_Solaris_MPXIOController(CCIMObjectPath * pOP,CCIMInstance * pInst)302 cp_setInstance_Solaris_MPXIOController(CCIMObjectPath* pOP, CCIMInstance* pInst)
303 {
304 
305 	int	error;
306 
307 	util_handleError(MPXIO_SETINSTANCE, CIM_ERR_NOT_SUPPORTED,
308 	    NULL, NULL, &error);
309 	return (cim_false);
310 }
311 
312 /*
313  * Setting properties on an instance of a Solaris_MPXIOController is not
314  * supported.
315  */
316 
317 /* ARGSUSED */
318 CIMBool
cp_setProperty_Solaris_MPXIOController(CCIMObjectPath * pOP,CCIMProperty * pProp)319 cp_setProperty_Solaris_MPXIOController(CCIMObjectPath* pOP, CCIMProperty* pProp)
320 {
321 
322 	int	error;
323 
324 	util_handleError(MPXIO_SETPROPERTY, CIM_ERR_NOT_SUPPORTED,
325 	    NULL, NULL, &error);
326 	return (cim_false);
327 }
328 
329 /*
330  *  No methods available on an instance of a Solaris_MPXIOController.
331  */
332 
333 /* ARGSUSED */
334 CCIMProperty*
cp_invokeMethod_Solaris_MPXIOController(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)335 cp_invokeMethod_Solaris_MPXIOController(CCIMObjectPath* op, cimchar* methodName,
336     CCIMPropertyList* inParams, CCIMPropertyList* outParams)
337 {
338 	CCIMProperty	*retVal = (CCIMProperty*)NULL;
339 	return (retVal);
340 }
341 
342 /*
343  * Name: cp_execQuery_Solaris_MPXIOController
344  *
345  * Description:
346  * Returns an instance list which matches the query if any are found.
347  *
348  * Parameters:
349  *      CCIMObjectPath *op - An CCIMObjectPath * which contains the
350  *      information on the class for which to find the instances.
351  *
352  *      selectList - Not used
353  *      nonJoinExp - Not used
354  *
355  * Returns:
356  *      CCIMInstanceList * if matched instance is found. Otherwise, NULL.
357  */
358 /*
359  * Currently, there is no WQL parser for the C providers. As a result,
360  * what is returned to the CIMOM is a list of instances with
361  * a NULL value at the beginning of the list. This NULL value indicates
362  * to the CIMOM that it must do the filtering for the client.
363  */
364 
365 /* ARGSUSED */
366 CCIMInstanceList*
cp_execQuery_Solaris_MPXIOController(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)367 cp_execQuery_Solaris_MPXIOController(CCIMObjectPath *op, cimchar *selectList,
368     cimchar *nonJoinExp, cimchar *queryExp, int queryType)
369 {
370 	CCIMInstanceList	*instList = NULL;
371 	CCIMInstanceList	*result;
372 	CCIMInstance		*emptyInst;
373 	CCIMException		*ex;
374 	int			error;
375 
376 	if (op == NULL) {
377 	    util_handleError(MPXIO_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
378 		NULL, &error);
379 	    return ((CCIMInstanceList *)NULL);
380 	}
381 
382 	instList = cp_enumInstances_Solaris_MPXIOController(op);
383 
384 	if (instList == NULL) {
385 	    return ((CCIMInstanceList *)NULL);
386 	}
387 	/*
388 	 * Create a null instance and add it to the beginning
389 	 * of the list to indicate to the CIMOM that no filtering
390 	 * was done.
391 	 */
392 
393 	emptyInst = cim_createInstance("");
394 	if (emptyInst == NULL) {
395 	    ex = cim_getLastError();
396 	    util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
397 		CREATE_INSTANCE_FAILURE, ex, &error);
398 	    cim_freeInstanceList(instList);
399 	    return ((CCIMInstanceList *)NULL);
400 	}
401 
402 	result = cim_createInstanceList();
403 	if (result == NULL) {
404 	    ex = cim_getLastError();
405 	    util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
406 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
407 	    cim_freeInstance(emptyInst);
408 	    cim_freeInstanceList(instList);
409 	    return ((CCIMInstanceList *)NULL);
410 	}
411 
412 	result = cim_addInstance(result, emptyInst);
413 	if (result == NULL) {
414 	    ex = cim_getLastError();
415 	    util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
416 		ADD_INSTANCE_FAILURE, ex, &error);
417 	    cim_freeInstanceList(instList);
418 	    cim_freeInstance(emptyInst);
419 	    return ((CCIMInstanceList *)NULL);
420 	}
421 
422 	/*
423 	 * Since copying the original list to the new list will
424 	 * leave no way to free the original list, manually
425 	 * concatenate the original list to the new one.
426 	 */
427 
428 	result->mNext = instList;
429 	return (result);
430 }
431