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 <errno.h>
31 
32 #include "util.h"
33 #include "cimKeys.h"
34 #include "providerNames.h"
35 #include "messageStrings.h"
36 #include "drive_descriptors.h"
37 #include "ctrl_descriptors.h"
38 #include "Solaris_IDEInterface.h"
39 
40 #define	IDE_GETINSTANCE		"IDE_INTERFACE,GET_INSTANCE"
41 #define	IDE_ENUMINSTANCES	"IDE_INTERFACE,ENUM_INSTANCES"
42 #define	IDE_ENUMINSTANCENAMES	"IDE_INTERFACE,ENUM_INSTANCENAMES"
43 #define	IDE_CREATEINSTANCE	"IDE_INTERFACE,CREATE_INSTANCE"
44 #define	IDE_DELETEINSTANCE	"IDE_INTERFACE,DELETE_INSTANCE"
45 #define	IDE_SETINSTANCE		"IDE_INTERFACE,SET_INSTANCE"
46 #define	IDE_GETPROPERTY		"IDE_INTERFACE,GET_PROPERTY"
47 #define	IDE_SETPROPERTY		"IDE_INTERFACE,SET_PROPERTY"
48 #define	IDE_INVOKEMETHOD	"IDE_INTERFACE,INVOKE_METHOD"
49 #define	IDE_EXECQUERY		"IDE_INTERFACE,EXEC_QUERY"
50 #define	IDE_ASSOCIATORS		"IDE_INTERFACE,ASSOCIATORS"
51 #define	IDE_ASSOCIATORNAMES	"IDE_INTERFACE,ASSOCIATOR_NAMES"
52 #define	IDE_REFERENCES		"IDE_INTERFACE,REFERENCES"
53 #define	IDE_REFERENCENAMES	"IDE_INTERFACE,REFERENCE_NAMES"
54 
55 
56 static
57 CCIMInstanceList *
58 ideIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
59 	CCIMObjectPathList *objList, cimchar *objRole, int *error);
60 
61 static
62 CCIMInstance  *
63 ideIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
64 	CCIMObjectPath *obj2, cimchar *obj2Role, int *error);
65 
66 /*
67  * Solaris_IDEInterface provider
68  *
69  * It is important to note that all memory allocated by these functions
70  * and passed to the CIMOM, is freed by the door process prior to
71  * sending a copy of the data to the CIMOM.
72  */
73 
74 /*
75  * Name: cp_getInstance_Solaris_IDEInterface
76  *
77  * Description: Returns an instance which matches the passed in object path
78  * if found.
79  *
80  * Parameters:
81  *	pOP - An CCIMObjectPath * which contains the information on
82  *	the class for which to find the instance.
83  * Returns:
84  *	CCIMInstance * if matched instance is found. Otherwise, NULL.
85  */
86 
87 /* ARGSUSED */
88 CCIMInstance*
cp_getInstance_Solaris_IDEInterface(CCIMObjectPath * pOP)89 cp_getInstance_Solaris_IDEInterface(CCIMObjectPath* pOP)
90 {
91 	CCIMInstance* 		inst = NULL;
92 	CCIMPropertyList* 	pCurPropList;
93 	dm_descriptor_t		d_descriptor;
94 	dm_descriptor_t		c_descriptor;
95 	CCIMObjectPath		*antOp = NULL;
96 	CCIMObjectPath		*depOp = NULL;
97 	int			error;
98 	char			*name;
99 
100 	if (pOP == NULL) {
101 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
102 		NULL, &error);
103 	    return ((CCIMInstance *)NULL);
104 	}
105 
106 	if ((pCurPropList = pOP->mKeyProperties) == NULL) {
107 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
108 		NULL, &error);
109 	    return ((CCIMInstance *)NULL);
110 	}
111 
112 	antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
113 	    ANTECEDENT, &error);
114 
115 	if (error == 0) {
116 	    depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
117 		DEPENDENT, &error);
118 	}
119 
120 	if (error != 0) {
121 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
122 		NULL, NULL, &error);
123 	    return ((CCIMInstance *)NULL);
124 	}
125 
126 	/*
127 	 * Now, get the name of the antecedent from the object path.
128 	 */
129 
130 	if ((pCurPropList = antOp->mKeyProperties) == NULL) {
131 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
132 		NULL, &error);
133 	    return ((CCIMInstance *)NULL);
134 	}
135 
136 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
137 	    &error);
138 
139 	if (error != 0) {
140 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
141 		NULL, NULL, &error);
142 	}
143 
144 	/*
145 	 * The only reason it is needed to get the descriptor for these
146 	 * two devices is to verify that they still exist and are valid.
147 	 * If they are not found, then getting the instance for this
148 	 * association as passed in by the client is not possible.
149 	 */
150 	c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
151 	    &error);
152 	/*
153 	 * Not found. Return a null instance.
154 	 */
155 
156 	if (c_descriptor == NULL || error == ENODEV) {
157 	    return ((CCIMInstance *)NULL);
158 	}
159 
160 	if (error != 0) {
161 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
162 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
163 	    return ((CCIMInstance*)NULL);
164 	}
165 	dm_free_descriptor(c_descriptor);
166 
167 	/*
168 	 * Now, get the name of the dependent from the object path.
169 	 */
170 
171 	if ((pCurPropList = depOp->mKeyProperties) == NULL) {
172 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
173 		NULL, &error);
174 	    return ((CCIMInstance *)NULL);
175 	}
176 
177 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
178 	    &error);
179 
180 	if (error != 0) {
181 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
182 		NULL, NULL, &error);
183 	    return ((CCIMInstance *)NULL);
184 	}
185 
186 	d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name,
187 	    &error);
188 	/*
189 	 * Not found. Return a null instance.
190 	 */
191 
192 	if (d_descriptor == NULL || error == ENODEV) {
193 	    d_descriptor = dm_get_descriptor_by_name(DM_ALIAS, name,
194 		&error);
195 	    if (d_descriptor == NULL || error == ENODEV) {
196 		util_handleError(IDE_GETINSTANCE, CIM_ERR_NOT_FOUND,
197 		    NULL, NULL, &error);
198 		return ((CCIMInstance *)NULL);
199 	    }
200 	}
201 
202 	if (error != 0) {
203 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
204 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
205 	    return ((CCIMInstance *)NULL);
206 	}
207 
208 	dm_free_descriptor(d_descriptor);
209 
210 	/*
211 	 * At this point I have verified I have the two devices that
212 	 * are part of this association. Use the object paths I got
213 	 * earlier to create the ideinterface instance.
214 	 */
215 	inst = ideIntAssocToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);
216 
217 	if (error != 0) {
218 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
219 		IDEINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
220 	    return ((CCIMInstance *)NULL);
221 	}
222 
223 	return (inst);
224 }
225 
226 /*
227  * Name: cp_enumInstances_Solaris_IDEInterface
228  *
229  * Description: Returns a linked list of instances of
230  *      Solaris_IDEInterface if found.
231  *
232  * Parameters:
233  *	pOP - An CCIMObjectPath * which contains the information on
234  *	the class for which to find the instances.
235  * Returns:
236  *	CCIMInstanceList * if istances are found. If no instances,
237  *	NULL is returned. On error, NULL is returned.
238  */
239 
240 /* ARGSUSED */
241 CCIMInstanceList*
cp_enumInstances_Solaris_IDEInterface(CCIMObjectPath * pOP)242 cp_enumInstances_Solaris_IDEInterface(CCIMObjectPath* pOP)
243 {
244 	CCIMInstanceList	*instList = NULL;
245 	CCIMObjectPathList	*cObjList = NULL;
246 	CCIMObjectPathList	*tmpObjList;
247 	CCIMObjectPath		*objPath;
248 	CCIMInstance		*inst;
249 	CCIMException		*ex;
250 	dm_descriptor_t		*d_descriptorp = NULL;
251 	int			error = 0;
252 
253 	/*
254 	 * Get the list of IDE Controllers. Then get the associated drives
255 	 * via the device api.
256 	 */
257 
258 	objPath = cim_createEmptyObjectPath(IDE_CONTROLLER);
259 	if (objPath == NULL) {
260 	    ex = cim_getLastError();
261 	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
262 		CREATE_OBJECT_PATH, ex, &error);
263 	    return ((CCIMInstanceList *)NULL);
264 	}
265 
266 	cObjList = cimom_enumerateInstanceNames(objPath, cim_false);
267 	cim_freeObjectPath(objPath);
268 
269 	/*
270 	 * NULL means error.
271 	 */
272 	if (cObjList == NULL) {
273 	    ex = cim_getLastError();
274 	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
275 		ENUM_INSTANCENAMES_FAILURE, ex, &error);
276 	    return ((CCIMInstanceList *)NULL);
277 	}
278 
279 	if (cObjList->mDataObject == NULL) {
280 	    return ((CCIMInstanceList *)NULL);
281 	}
282 
283 	instList = cim_createInstanceList();
284 	if (instList == NULL) {
285 	    ex = cim_getLastError();
286 	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
287 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
288 	    return ((CCIMInstanceList *)NULL);
289 	}
290 	/*
291 	 * Loop through all of these controller objects and get the associated
292 	 * disks.
293 	 */
294 
295 	for (tmpObjList = cObjList;
296 	    tmpObjList != NULL && tmpObjList->mDataObject != NULL;
297 		tmpObjList = tmpObjList->mNext) {
298 
299 	    char 		*name = NULL;
300 	    CCIMObjectPath 	*cOp;
301 	    CCIMInstanceList	*tmpList = NULL;
302 	    CCIMInstanceList	*tmpList1;
303 	    CCIMPropertyList	*pCurPropList;
304 	    CCIMObjectPathList	*dObjList;
305 	    CCIMInstanceList	*tL;
306 	    dm_descriptor_t	c_descriptor = NULL;
307 	    error = 0;
308 
309 	    cOp = tmpObjList->mDataObject;
310 	    if ((pCurPropList = cOp->mKeyProperties) == NULL) {
311 		util_handleError(IDE_ENUMINSTANCES,
312 		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
313 		cim_freeObjectPathList(cObjList);
314 		cim_freeInstanceList(instList);
315 		return ((CCIMInstanceList *)NULL);
316 	    }
317 
318 	    name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
319 		&error);
320 
321 	    if (error != 0) {
322 		util_handleError(IDE_ENUMINSTANCES,
323 		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
324 		cim_freeObjectPathList(cObjList);
325 		cim_freeInstanceList(instList);
326 		return ((CCIMInstanceList *)NULL);
327 	    }
328 
329 	    c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
330 		&error);
331 	    if (c_descriptor == NULL || error == ENODEV) {
332 		continue;
333 	    }
334 	    if (error != 0) {
335 		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
336 		    DM_GET_DESC_BYNAME_FAILURE, NULL,
337 			&error);
338 		cim_freeObjectPathList(cObjList);
339 		cim_freeInstanceList(instList);
340 		return ((CCIMInstanceList *)NULL);
341 	    }
342 
343 	    d_descriptorp = dm_get_associated_descriptors(c_descriptor,
344 		DM_DRIVE, &error);
345 	    dm_free_descriptor(c_descriptor);
346 
347 		/*
348 		 * If there are no drives associated with this controller,
349 		 * continue on to the next controller.
350 		 */
351 
352 	    if (d_descriptorp == NULL) {
353 		continue;
354 	    }
355 
356 	    if (d_descriptorp[0] == NULL) {
357 		dm_free_descriptors(d_descriptorp);
358 		continue;
359 	    }
360 
361 	    if (error == ENODEV) {
362 		continue;
363 	    }
364 
365 	    if (error != 0) {
366 		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
367 		    DM_GET_ASSOC_FAILURE, NULL, &error);
368 		cim_freeInstanceList(instList);
369 		cim_freeObjectPathList(cObjList);
370 		return ((CCIMInstanceList *)NULL);
371 	    }
372 
373 	    tmpList = drive_descriptors_toCCIMObjPathInstList(
374 		DISK_DRIVE, d_descriptorp, &error);
375 	    dm_free_descriptors(d_descriptorp);
376 	    d_descriptorp = NULL;
377 
378 	    if (error != 0) {
379 		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
380 		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
381 		cim_freeInstanceList(instList);
382 		cim_freeObjectPathList(cObjList);
383 		return ((CCIMInstanceList *)NULL);
384 	    }
385 
386 		/*
387 		 * It is possible that the controller does not have a drive
388 		 * associated with it. If this is true, the list will be
389 		 * NULL.
390 		 */
391 
392 	    if (tmpList == NULL) {
393 		continue;
394 	    }
395 
396 	    dObjList = cim_createObjectPathList(tmpList);
397 	    cim_freeInstanceList(tmpList);
398 
399 	    if (dObjList == NULL) {
400 		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
401 		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
402 		cim_freeInstanceList(instList);
403 		cim_freeObjectPathList(cObjList);
404 		return ((CCIMInstanceList *)NULL);
405 	    }
406 	    tmpList1 = ideIntAssocToInstList(
407 		cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
408 	    cim_freeObjectPathList(dObjList);
409 
410 	    if (error != 0) {
411 		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
412 		    IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
413 		cim_freeInstanceList(instList);
414 		cim_freeObjectPathList(cObjList);
415 		return ((CCIMInstanceList *)NULL);
416 	    }
417 
418 	    tL = tmpList1;
419 	    do {
420 		inst = cim_copyInstance(tL->mDataObject);
421 		instList = cim_addInstance(instList, inst);
422 		if (instList == NULL) {
423 		    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
424 			ADD_INSTANCE_FAILURE, NULL, &error);
425 		    cim_freeObjectPathList(cObjList);
426 		    cim_freeObjectPathList(tmpList1);
427 		    return ((CCIMInstanceList *)NULL);
428 		}
429 		tL = tL->mNext;
430 	    } while (tL && tL->mDataObject != NULL);
431 
432 	    cim_freeInstanceList(tmpList1);
433 	} /* end for */
434 
435 	cim_freeObjectPathList(cObjList);
436 	/*
437 	 * It is possible I will have an empty instance list at
438 	 * this point. So, I must check and NULL this out if
439 	 * there are no entries.
440 	 */
441 	if (instList->mDataObject == NULL) {
442 	    cim_freeInstanceList(instList);
443 	    instList = NULL;
444 	}
445 	return (instList);
446 }
447 
448 /*
449  * Name: cp_enumInstanceNames_Solaris_IDEInterface
450  *
451  * Description: Returns a linked list of CCIMObjectPath *
452  *      of Solaris_IDEInterface if found.
453  *
454  * Parameters:
455  *	pOP - An CCIMObjectPath * which contains the information on
456  *	the class for which to find the instances.
457  * Returns:
458  *	CCIMObjectPathList * if objects are found. If no objects,
459  *	an empty list is returned. On error, NULL is returned.
460  */
461 
462 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_IDEInterface(CCIMObjectPath * pOP)463 cp_enumInstanceNames_Solaris_IDEInterface(CCIMObjectPath * pOP) {
464 
465 	CCIMInstanceList	*instList;
466 	CCIMObjectPathList	*objList = NULL;
467 	int			error;
468 
469 	if (pOP == NULL) {
470 	    util_handleError(IDE_ENUMINSTANCENAMES,
471 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
472 	    return ((CCIMObjectPathList *)NULL);
473 	}
474 
475 	/*
476 	 * Call in to enumInstances and then convert the instance list in
477 	 * to an object list.
478 	 */
479 
480 	instList = cp_enumInstances_Solaris_IDEInterface(pOP);
481 
482 	if (instList != NULL) {
483 	    objList = cim_createObjectPathList(instList);
484 	    cim_freeInstanceList(instList);
485 	}
486 
487 	return (objList);
488 }
489 
490 /*
491  * Creating an instance of a Solaris_IDEInterface is not supported.
492  */
493 
494 /* ARGSUSED */
495 CCIMObjectPath*
cp_createInstance_Solaris_IDEInterface(CCIMObjectPath * pOP,CCIMInstance * pInst)496 cp_createInstance_Solaris_IDEInterface(CCIMObjectPath* pOP,
497     CCIMInstance* pInst)
498 {
499 	int	error;
500 
501 	util_handleError(IDE_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
502 	    NULL, &error);
503 	return ((CCIMObjectPath *)NULL);
504 }
505 
506 /*
507  * Deleting an instance of a Solaris_IDEInterface is not supported.
508  */
509 
510 /* ARGSUSED */
511 CIMBool
cp_deleteInstance_Solaris_IDEInterface(CCIMObjectPath * pInst)512 cp_deleteInstance_Solaris_IDEInterface(CCIMObjectPath* pInst)
513 {
514 	int	error;
515 
516 	util_handleError(
517 	    IDE_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
518 	return (cim_false);
519 }
520 /*
521  * Name: cp_getProperty_Solaris_IIDEInterface
522  *
523  * Description: Returns the property requested, if found.
524  *
525  * Parameters:
526  *	pOP - An CCIMObjectPath * which contains the information on
527  *	the class for which to find the instances.
528  * Returns:
529  *	CCIMProperty * if found.
530  */
531 
532 /* ARGSUSED */
533 CCIMProperty	*
cp_getProperty_Solaris_IDEInterface(CCIMObjectPath * pOP,char * pPropName)534 cp_getProperty_Solaris_IDEInterface(CCIMObjectPath *pOP,
535     char *pPropName)
536 {
537 
538 	CCIMProperty	*prop = NULL;
539 	CCIMInstance	*inst = NULL;
540 	int		error = 0;
541 
542 	if (pOP == NULL) {
543 	    util_handleError(IDE_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
544 		NULL, &error);
545 	    return ((CCIMProperty *)NULL);
546 	}
547 
548 	inst = cp_getInstance_Solaris_IDEInterface(pOP);
549 	if (inst == NULL) {
550 	    return ((CCIMProperty *)NULL);
551 	}
552 
553 	prop = cim_getProperty(inst, pPropName);
554 	cim_freeInstance(inst);
555 	return (prop);
556 }
557 
558 /*
559  * Setting an instance of a Solaris_IDEInterface is not supported.
560  */
561 
562 /* ARGSUSED */
563 CIMBool
cp_setInstance_Solaris_IDEInterface(CCIMObjectPath * pOP,CCIMInstance * pInst)564 cp_setInstance_Solaris_IDEInterface(CCIMObjectPath* pOP, CCIMInstance* pInst)
565 {
566 	int	error;
567 
568 	util_handleError(
569 	    IDE_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
570 	return (cim_false);
571 }
572 
573 
574 /*
575  * Setting a property on a Solaris_IDEInterface is not supported.
576  */
577 
578 /* ARGSUSED */
579 CIMBool
cp_setProperty_Solaris_IDEInterface(CCIMObjectPath * pOP,CCIMProperty * pProp)580 cp_setProperty_Solaris_IDEInterface(CCIMObjectPath* pOP, CCIMProperty* pProp)
581 {
582 	int	error;
583 
584 	util_handleError(
585 	    IDE_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
586 	return (cim_false);
587 }
588 
589 /*
590  * No Methods for Solaris_IDEInterface.
591  */
592 
593 /* ARGSUSED */
594 CCIMProperty*
cp_invokeMethod_Solaris_IDEInterface(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)595 cp_invokeMethod_Solaris_IDEInterface(
596     CCIMObjectPath* op, cimchar* methodName,
597 	CCIMPropertyList* inParams, CCIMPropertyList* outParams)
598 {
599 	CCIMProperty 	*retVal = (CCIMProperty *)NULL;
600 	return (retVal);
601 }
602 
603 /*
604  * Name: cp_execQuery_Solaris_IDEInterface
605  *
606  * Description:
607  * Returns an instance list which matches the query if any are found.
608  *
609  * Parameters:
610  *	CCIMObjectPath *op - An CCIMObjectPath * which contains the
611  *	information on the class for which to find the instances.
612  *
613  * 	selectList - Not used
614  *	nonJoinExp - Not used
615  *
616  * Returns:
617  *	CCIMInstanceList * if matched instance is found. Otherwise, NULL.
618  */
619 /*
620  * Currently, there is no WQL parser for the C providers. As a result,
621  * what is returned to the CIMOM is a list of instances with
622  * a NULL value at the beginning of the list. This NULL value indicates
623  * to the CIMOM that it must do the filtering for the client.
624  */
625 
626 /* ARGSUSED */
627 CCIMInstanceList*
cp_execQuery_Solaris_IDEInterface(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)628 cp_execQuery_Solaris_IDEInterface(CCIMObjectPath *op,
629     cimchar *selectList, cimchar *nonJoinExp, cimchar *queryExp, int queryType)
630 {
631 	CCIMInstanceList	*instList = NULL;
632 	CCIMInstanceList	*result;
633 	CCIMInstance		*emptyInst;
634 	CCIMException		*ex;
635 	int			error;
636 
637 	if (op == NULL) {
638 	    util_handleError(IDE_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
639 		NULL, &error);
640 	    return ((CCIMInstanceList *)NULL);
641 	}
642 
643 	instList = cimom_enumerateInstances(op, cim_false, cim_false, cim_false,
644 	    cim_false, cim_false, NULL, 0);
645 
646 		/*
647 		 * NULL means error.
648 		 */
649 	if (instList == NULL) {
650 	    ex = cim_getLastError();
651 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
652 		ENUM_INSTANCES_FAILURE, ex, &error);
653 	    return ((CCIMInstanceList *)NULL);
654 	}
655 
656 	if (instList->mDataObject ==  NULL) {
657 	    return ((CCIMInstanceList *)NULL);
658 	}
659 	/*
660 	 * Create a null instance and add it to the beginning
661 	 * of the list to indicate to the CIMOM that no filtering
662 	 * was done.
663 	 */
664 
665 	emptyInst = cim_createInstance("");
666 	if (emptyInst == NULL) {
667 	    ex = cim_getLastError();
668 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
669 		CREATE_INSTANCE_FAILURE, ex, &error);
670 	    return ((CCIMInstanceList *)NULL);
671 	}
672 
673 	result = cim_createInstanceList();
674 	if (result == NULL) {
675 	    ex = cim_getLastError();
676 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
677 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
678 	    cim_freeInstance(emptyInst);
679 	    cim_freeInstanceList(instList);
680 	    return ((CCIMInstanceList *)NULL);
681 	}
682 
683 	result = cim_addInstance(result, emptyInst);
684 	if (result == NULL) {
685 	    ex = cim_getLastError();
686 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
687 		ADD_INSTANCE_FAILURE, ex, &error);
688 	    cim_freeInstance(emptyInst);
689 	    cim_freeInstanceList(instList);
690 	    return ((CCIMInstanceList *)NULL);
691 	}
692 
693 	/*
694 	 * Since copying the original list to the new list will
695 	 * leave no way to free the original list, manually
696 	 * concatenate the original list to the new one.
697 	 */
698 
699 	result->mNext = instList;
700 	return (result);
701 }
702 
703 /*
704  * Name: cp_associators_Solaris_IDEInterface
705  *
706  * Description:
707  * Returns instances of objects associated with the passed in
708  * object if there are any.
709  *
710  * Parameters:
711  *
712  *	CCIMObjectPath *pAssocName - The name of the association that
713  *	the client wants information about.
714  *
715  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
716  *	information on the class for which to find the associated instances.
717  *
718  *	cimchar *pResultClass - If specified, only return instances that
719  *	are of this class type.
720  *
721  *      cimchar *pRole - If specified, must be valid for the object path
722  *	passed in requesting the associated instances.
723  *
724  *	cimchar *pResultRole - If specified, only return instances that
725  *	are playing this role in the association.
726  *
727  *
728  * Returns:
729  *	CCIMInstanceList * if associated objects are found. Thist list
730  *	may be empty. NULL is returned on error.
731  */
732 
733 /* ARGSUSED */
734 CCIMInstanceList *
cp_associators_Solaris_IDEInterface(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pResultClass,cimchar * pRole,cimchar * pResultRole)735 cp_associators_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
736     CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
737 	cimchar *pResultRole)
738 {
739 	CCIMPropertyList	*pCurPropList;
740 	CCIMInstanceList	*instList = NULL;
741 	dm_descriptor_t		*assoc_descriptors = NULL;
742 	dm_descriptor_t		*tmpList = NULL;
743 	dm_descriptor_t		obj_desc = NULL;
744 	char			*name;
745 	int			error = 0;
746 	int			isAntecedent = 0;
747 	int			isAlias = 0;
748 
749 	if ((pObjectName == NULL ||
750 	    (pCurPropList = pObjectName->mKeyProperties) == NULL)) {
751 	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
752 		NULL, &error);
753 	    return ((CCIMInstanceList *)NULL);
754 	}
755 
756 	if (strcasecmp(pObjectName->mName, IDE_CONTROLLER) == 0) {
757 	    isAntecedent = 1;
758 	}
759 
760 	if (pRole != NULL) {
761 	    if (strcasecmp(pRole, ANTECEDENT) == 0) {
762 		if (isAntecedent != 1) {
763 		    util_handleError(IDE_ASSOCIATORS,
764 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
765 		    return ((CCIMInstanceList *)NULL);
766 		}
767 	    } else if (strcasecmp(pRole, DEPENDENT) == 0) {
768 		if (isAntecedent == 1) {
769 		    util_handleError(IDE_ASSOCIATORS,
770 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
771 		    return ((CCIMInstanceList *)NULL);
772 		}
773 	    }
774 	}
775 
776 	/*
777 	 * Both ide controller and disk drive have deviceid as the
778 	 * key.
779 	 */
780 
781 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
782 	    &error);
783 	if (error != 0) {
784 	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
785 		NULL, &error);
786 	    return ((CCIMInstanceList *)NULL);
787 	}
788 
789 	if (isAntecedent) {
790 	    obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name,
791 		&error);
792 	} else {
793 	    obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name,
794 		&error);
795 	    if (obj_desc == NULL || error == ENODEV) {
796 		isAlias = 1;
797 		obj_desc = dm_get_descriptor_by_name(DM_ALIAS, name, &error);
798 	    }
799 	}
800 
801 	if (obj_desc == NULL) {
802 	    return ((CCIMInstanceList *)NULL);
803 	}
804 
805 	if (error != 0) {
806 	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
807 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
808 	    return ((CCIMInstanceList *)NULL);
809 	}
810 
811 	if (isAlias) {
812 	    tmpList = dm_get_associated_descriptors(obj_desc, DM_DRIVE,
813 		&error);
814 	    if (tmpList == NULL) {
815 		return ((CCIMInstanceList *)NULL);
816 	    }
817 
818 	    if (tmpList[0] == NULL) {
819 		dm_free_descriptors(tmpList);
820 		return ((CCIMInstanceList *)NULL);
821 	    }
822 	}
823 
824 
825 	if (isAntecedent) {
826 		/*
827 		 * Get associated descriptors.
828 		 */
829 
830 	    assoc_descriptors = dm_get_associated_descriptors(obj_desc,
831 		DM_DRIVE, &error);
832 	    dm_free_descriptor(obj_desc);
833 
834 	    if (assoc_descriptors == NULL) {
835 		return (instList);
836 	    }
837 
838 	    if (assoc_descriptors[0] == NULL) {
839 		dm_free_descriptors(assoc_descriptors);
840 		return (instList);
841 	    }
842 
843 	    if (error != 0) {
844 		util_handleError(IDE_ASSOCIATORS,  CIM_ERR_FAILED,
845 		    DM_GET_ASSOC_FAILURE, NULL, &error);
846 		return ((CCIMInstanceList *)NULL);
847 	    }
848 
849 		/*
850 		 * Generate the inst list of the associated disk drives.
851 		 */
852 
853 	    instList = drive_descriptors_toCCIMObjPathInstList(DISK_DRIVE,
854 		assoc_descriptors, &error);
855 	    dm_free_descriptors(assoc_descriptors);
856 
857 	    if (error != 0) {
858 		util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
859 		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
860 		return ((CCIMInstanceList *)NULL);
861 	    }
862 	} else {
863 		/*
864 		 * This is the disk drive calling this function. Return the
865 		 * controllers that are associated with this disk.
866 		 */
867 
868 	    if (tmpList == NULL && obj_desc == NULL) {
869 		return ((CCIMInstanceList *)NULL);
870 	    }
871 
872 	    if (tmpList != NULL) {
873 		assoc_descriptors = dm_get_associated_descriptors(tmpList[0],
874 		    DM_CONTROLLER, &error);
875 		dm_free_descriptors(tmpList);
876 	    } else {
877 		assoc_descriptors = dm_get_associated_descriptors(obj_desc,
878 		    DM_CONTROLLER, &error);
879 		dm_free_descriptor(obj_desc);
880 	    }
881 
882 	    if (assoc_descriptors == NULL) {
883 		return ((CCIMInstanceList *)NULL);
884 	    }
885 
886 	    if (assoc_descriptors[0] == NULL) {
887 		dm_free_descriptors(assoc_descriptors);
888 		return ((CCIMInstanceList *)NULL);
889 	    }
890 
891 	    if (error != 0) {
892 		util_handleError(IDE_ASSOCIATORS,  CIM_ERR_FAILED,
893 		    DM_GET_ASSOC_FAILURE, NULL, &error);
894 		return ((CCIMInstanceList *)NULL);
895 	    }
896 
897 	    instList = ctrl_descriptors_toCCIMInstanceList(IDE_CONTROLLER,
898 		assoc_descriptors, &error, 2, "ata", "pcata");
899 	    dm_free_descriptors(assoc_descriptors);
900 
901 	    if (error != 0) {
902 		util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
903 		    IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
904 		return ((CCIMInstanceList *)NULL);
905 	    }
906 	}
907 
908 	return (instList);
909 }
910 
911 /*
912  * Name: cp_associatorNames_Solaris_IDEInterface
913  *
914  * Description:
915  * Returns a list of objects associated with the passed in
916  * object if there are any via the object CCIMObjectPath.
917  *
918  * Parameters:
919  *
920  *	CCIMObjectPath *pAssocName - The name of the association that
921  *	the client wants information about.
922  *
923  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
924  *	information on the class for which to find the associated instances.
925  *
926  *	cimchar *pResultClass - If specified, only return instances that
927  *	are of this class type.
928  *
929  *      cimchar *pRole - If specified, must be valid for the object path
930  *	passed in requesting the associated instances.
931  *
932  *	cimchar *pResultRole - If specified, only return instances that
933  *	are playing this role in the association.
934  *
935  *
936  * Returns:
937  *	CCIMObjectPathList * if associated objects are found. Thist list
938  *	may be empty. NULL is returned on error.
939  */
940 /* ARGSUSED */
941 CCIMObjectPathList *
cp_associatorNames_Solaris_IDEInterface(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pResultClass,cimchar * pRole,cimchar * pResultRole)942 cp_associatorNames_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
943     CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
944 	cimchar *pResultRole)
945 {
946 
947 	CCIMInstanceList	*instList;
948 	CCIMObjectPathList	*objList = NULL;
949 	int			error;
950 
951 	if (pObjectName == NULL) {
952 	    util_handleError(IDE_ASSOCIATORNAMES,
953 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
954 	    return ((CCIMObjectPathList *)NULL);
955 	}
956 
957 	instList =
958 	    cp_associators_Solaris_IDEInterface(
959 		pAssocName, pObjectName, pResultClass, pRole, pResultRole);
960 
961 	if (instList != NULL) {
962 	    objList = cim_createObjectPathList(instList);
963 	    cim_freeInstanceList(instList);
964 	}
965 
966 	return (objList);
967 }
968 
969 /*
970  * Name: cp_references_Solaris_IDEInterface
971  *
972  * Description:
973  * Returns instances of objects that have references to the passed in
974  * object if there are any.
975  *
976  * Parameters:
977  *
978  *	CCIMObjectPath *pAssocName - The name of the association that
979  *	the client wants information about.
980  *
981  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
982  *	information on the class for which to find the associated instances.
983  *
984  *      cimchar *pRole - If specified, must be valid for the object path
985  *	passed in requesting the associated instances.
986  *
987  * Returns:
988  *	CCIMInstanceList * if associated objects are found. Thist list
989  *	may be empty. NULL is returned on error.
990  */
991 
992 /* ARGSUSED */
993 CCIMInstanceList *
cp_references_Solaris_IDEInterface(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)994 cp_references_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
995 CCIMObjectPath *pObjectName, char *pRole)
996 {
997 
998 	CCIMInstanceList	*instList = NULL;
999 	CCIMObjectPathList	*objList;
1000 	int			error;
1001 
1002 	if (pObjectName == NULL) {
1003 	    util_handleError(IDE_REFERENCES, CIM_ERR_INVALID_PARAMETER,
1004 		NULL, NULL, &error);
1005 	    return ((CCIMInstanceList *)NULL);
1006 	}
1007 
1008 	/*
1009 	 * Get the list of those objects that are referred to by
1010 	 * the calling object.
1011 	 */
1012 
1013 	objList =
1014 	    cp_associatorNames_Solaris_IDEInterface(
1015 		pAssocName, pObjectName, NULL, NULL, NULL);
1016 
1017 	if (objList == NULL) {
1018 	    return ((CCIMInstanceList *)NULL);
1019 	}
1020 
1021 	/*
1022 	 * Now generate the list of instances to return.
1023 	 */
1024 
1025 	if ((strcasecmp(pObjectName->mName, IDE_CONTROLLER)) == 0) {
1026 	    instList = ideIntAssocToInstList(pObjectName,
1027 		ANTECEDENT, objList, DEPENDENT, &error);
1028 	} else {
1029 	    instList = ideIntAssocToInstList(pObjectName,
1030 		DEPENDENT, objList, ANTECEDENT, &error);
1031 	}
1032 
1033 	cim_freeObjectPathList(objList);
1034 	return (instList);
1035 }
1036 
1037 /*
1038  * Name: cp_referenceNames_Solaris_IDEInterface
1039  *
1040  * Description:
1041  * Returns a instances of objects that have references to the passed in
1042  * object if there are any.
1043  *
1044  * Parameters:
1045  *
1046  *	CCIMObjectPath *pAssocName - The name of the association that
1047  *	the client wants information about.
1048  *
1049  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
1050  *	information on the class for which to find the associated instances.
1051  *
1052  *      cimchar *pRole - If specified, must be valid for the object path
1053  *	passed in requesting the associated instances.
1054  *
1055  *
1056  * Returns:
1057  *	CCIMInstanceList * if associated objects are found. Thist list
1058  *	may be empty. NULL is returned on error.
1059  *
1060  */
1061 /* ARGSUSED */
1062 CCIMObjectPathList *
cp_referenceNames_Solaris_IDEInterface(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pRole)1063 cp_referenceNames_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
1064     CCIMObjectPath *pObjectName, cimchar *pRole)
1065 {
1066 
1067 	CCIMInstanceList	*instList;
1068 	CCIMObjectPathList	*objList = NULL;
1069 	int			error;
1070 
1071 	if (pObjectName == NULL) {
1072 	    util_handleError(IDE_REFERENCENAMES,
1073 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
1074 	    return ((CCIMObjectPathList *)NULL);
1075 	}
1076 
1077 	instList =
1078 	    cp_references_Solaris_IDEInterface(pAssocName, pObjectName, pRole);
1079 
1080 	if (instList != NULL) {
1081 	    objList = cim_createObjectPathList(instList);
1082 	    cim_freeInstanceList(instList);
1083 	}
1084 
1085 	return (objList);
1086 }
1087 
1088 /*
1089  * Create the association class with the passed in attributes.
1090  */
1091 static
1092 CCIMInstanceList  *
ideIntAssocToInstList(CCIMObjectPath * pObjectName,cimchar * pObjectNameRole,CCIMObjectPathList * objList,cimchar * objRole,int * error)1093 ideIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
1094 	CCIMObjectPathList *objList, cimchar *objRole, int *error)
1095 {
1096 
1097 	CCIMObjectPathList	*tmpList;
1098 	CCIMInstanceList	*instList = NULL;
1099 	CCIMInstance		*inst;
1100 	CCIMObjectPath		*obj1;
1101 	CCIMObjectPath		*obj2;
1102 	CCIMException		*ex;
1103 
1104 	*error = 0;
1105 
1106 	if (objList == NULL) {
1107 	    return ((CCIMInstanceList *)NULL);
1108 	}
1109 
1110 	instList = cim_createInstanceList();
1111 	if (instList == NULL) {
1112 	    ex = cim_getLastError();
1113 	    util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
1114 		CREATE_INSTANCE_FAILURE, ex, error);
1115 	    return ((CCIMInstanceList *)NULL);
1116 	}
1117 
1118 	tmpList = objList;
1119 	while (tmpList != NULL) {
1120 	    obj1 = tmpList->mDataObject;
1121 	    obj2 = cim_copyObjectPath(pObjectName);
1122 	    if (obj2 == NULL) {
1123 		ex = cim_getLastError();
1124 		util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
1125 		    COPY_OBJPATH_FAILURE, ex, error);
1126 		return ((CCIMInstanceList *)NULL);
1127 	    }
1128 
1129 	    inst = ideIntAssocToInst(obj1, objRole, obj2, pObjectNameRole,
1130 			error);
1131 	    cim_freeObjectPath(obj2);
1132 
1133 	    if (*error != 0) {
1134 		cim_freeInstanceList(instList);
1135 		return ((CCIMInstanceList *)NULL);
1136 	    }
1137 
1138 	    instList = cim_addInstance(instList, inst);
1139 	    if (instList == NULL) {
1140 		ex = cim_getLastError();
1141 		util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
1142 		    ADD_INSTANCE_FAILURE, ex, error);
1143 		cim_freeInstance(inst);
1144 		return ((CCIMInstanceList *)NULL);
1145 	    }
1146 	    tmpList = tmpList->mNext;
1147 	}
1148 	return (instList);
1149 }
1150 
1151 /*
1152  * Create an instance of the class with the passed in attributes.
1153  */
1154 static
1155 CCIMInstance  *
ideIntAssocToInst(CCIMObjectPath * obj1,cimchar * obj1Role,CCIMObjectPath * obj2,cimchar * obj2Role,int * error)1156 ideIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
1157 	CCIMObjectPath *obj2, cimchar *obj2Role, int *error)
1158 {
1159 
1160 	CCIMInstance	*inst = NULL;
1161 	CCIMException	*ex;
1162 
1163 	*error = 0;
1164 
1165 	inst = cim_createInstance(IDE_INTERFACE);
1166 	if (inst == NULL) {
1167 	    ex = cim_getLastError();
1168 	    util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
1169 		IDEINT_ASSOC_TO_INSTANCE_FAILURE, ex, error);
1170 	    return ((CCIMInstance *)NULL);
1171 	}
1172 
1173 	util_doReferenceProperty(obj2Role, obj2, cim_true, inst, error);
1174 	util_doReferenceProperty(obj1Role, obj1, cim_true, inst, error);
1175 	if (*error != 0) {
1176 	    ex = cim_getLastError();
1177 	    util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
1178 		CREATE_REFPROP_FAILURE, ex, error);
1179 	    cim_freeInstance(inst);
1180 	    return ((CCIMInstance *)NULL);
1181 	}
1182 	return (inst);
1183 }
1184