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 "providerNames.h"
36 #include "messageStrings.h"
37 #include "disk_descriptors.h"
38 #include "realizesdiskdrive_descriptors.h"
39 #include "Solaris_RealizesDiskDrive.h"
40 
41 #define	REALIZES_GETINSTANCE		"REALIZES_DISKDRIVE,GET_INSTANCE"
42 #define	REALIZES_ENUMINSTANCES		"REALIZES_DISKDRIVE,ENUM_INSTANCES"
43 #define	REALIZES_ENUMINSTANCENAMES \
44 	"REALIZES_BASEDONDISK,ENUM_INSTANCENAMES"
45 #define	REALIZES_CREATEINSTANCE		"REALIZES_DISKDRIVE,CREATE_INSTANCE"
46 #define	REALIZES_DELETEINSTANCE		"REALIZES_DISKDRIVE,DELETE_INSTANCE"
47 #define	REALIZES_SETINSTANCE		"REALIZES_DISKDRIVE,SET_INSTANCE"
48 #define	REALIZES_SETPROPERTY		"REALIZES_DISKDRIVE,SET_PROPERTY"
49 #define	REALIZES_GETPROPERTY		"REALIZES_DISKDRIVE,GET_PROPERTY"
50 #define	REALIZES_INVOKEMETHOD		"REALIZES_DISKDRIVE,INVOKE_METHOD"
51 #define	REALIZES_EXECQUERY		"REALIZES_DISKDRIVE,EXEC_QUERY"
52 #define	REALIZES_ASSOCIATORS		"REALIZES_DISKDRIVE,ASSOCIATORS"
53 #define	REALIZES_ASSOCIATORNAMES	"REALIZES_DISKDRIVE,ASSOCIATOR_NAMES"
54 #define	REALIZES_REFERENCES		"REALIZES_DISKDRIVE,REFERENCES"
55 #define	REALIZES_REFERENCENAMES		"REALIZES_DISKDRIVE,REFERENCE_NAMES"
56 
57 
58 static
59 CCIMInstanceList  *
60 createRealizesDiskDriveList(CCIMObjectPath *pObjectName,
61     cimchar *pObjectNameRole, CCIMObjectPathList *objList,
62 	cimchar *objRole, int *error);
63 /*
64  * Solaris_RealizesDiskDrive provider
65  *
66  * It is important to note that all memory allocated by these functions
67  * and passed to the CIMOM, is freed by the door process prior to
68  * sending a copy of the data to the CIMOM.
69  */
70 
71 /*
72  * Name: cp_getInstance_Solaris_RealizesDiskDrive
73  *
74  * Description: Returns an instance of Solaris_RealizesDiskDrive if one
75  *  is found that matches the object path passed in .
76  *
77  * Parameters:
78  *	pOP - An CCIMObjectPath * which contains the information on
79  *	the class for which to find the instance.
80  * Returns: CCIMInstance * if match is found, or NULL if not.
81  *
82  */
83 
84 /* ARGSUSED */
85 CCIMInstance*
cp_getInstance_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP)86 cp_getInstance_Solaris_RealizesDiskDrive(CCIMObjectPath* pOP)
87 {
88 
89 	CCIMInstance 		*inst = NULL;
90 	CCIMPropertyList	*pCurPropList;
91 	CCIMObjectPath		*antOp = NULL;
92 	CCIMObjectPath		*depOp = NULL;
93 	dm_descriptor_t		d_descriptor;
94 	char			*name;
95 	int			error;
96 
97 	if (pOP == NULL ||
98 	    (pCurPropList = pOP->mKeyProperties) == NULL) {
99 	    util_handleError(REALIZES_GETINSTANCE,
100 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
101 	    return ((CCIMInstance *)NULL);
102 	}
103 
104 	antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
105 	    ANTECEDENT, &error);
106 
107 	if (error == 0) {
108 	    depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
109 		DEPENDENT, &error);
110 	}
111 
112 	if (error != 0) {
113 	    util_handleError(REALIZES_GETINSTANCE,
114 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
115 	    return ((CCIMInstance *)NULL);
116 	}
117 
118 	/*
119 	 * In this provider, the antecedent has no provider, therefore
120 	 * we check the validity of this request based on a match
121 	 * from the device api to the dependent name. The dependent in
122 	 * this case is a disk drive.
123 	 */
124 
125 	if ((pCurPropList = depOp->mKeyProperties) == NULL) {
126 	    util_handleError(REALIZES_GETINSTANCE,
127 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
128 	    return ((CCIMInstance *)NULL);
129 	}
130 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
131 	    &error);
132 	if (error != 0) {
133 	    util_handleError(REALIZES_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
134 		NULL, NULL, &error);
135 	    return ((CCIMInstance *)NULL);
136 	}
137 
138 	d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name,
139 	    &error);
140 	/*
141 	 * Not found. Return a null instance.
142 	 */
143 
144 	if (error == ENODEV || d_descriptor == NULL) {
145 	    return ((CCIMInstance *)NULL);
146 	}
147 
148 	if (error != 0) {
149 	    util_handleError(REALIZES_GETINSTANCE, CIM_ERR_FAILED,
150 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
151 	    return ((CCIMInstance *)NULL);
152 	}
153 
154 	/*
155 	 * Turn this in to a realizes diskdrive instance.
156 	 */
157 
158 	inst = realizesdiskdrive_descriptor_toCCIMInstance(
159 	    hostName, antOp, d_descriptor, REALIZES_DISKDRIVE, &error);
160 	dm_free_descriptor(d_descriptor);
161 
162 	if (error != 0) {
163 	    util_handleError(REALIZES_GETINSTANCE, CIM_ERR_FAILED,
164 		REALIZESDD_DESC_TO_INSTANCE_FAILURE, NULL, &error);
165 	    return ((CCIMInstance *)NULL);
166 	}
167 	return (inst);
168 }
169 
170 /*
171  * Name: cp_enumInstances_Solaris_RealizesDiskDrive
172  *
173  * Description: Returns a linked list of instances of this association.
174  *
175  * Parameters:
176  *	pOP - An CCIMObjectPath * which contains the information on
177  *	the class for which to find the instances.
178  * Returns:
179  *	CCIMInstanceList * if istances are found. NULL otherwise.
180  */
181 
182 /* ARGSUSED */
183 CCIMInstanceList*
cp_enumInstances_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP)184 cp_enumInstances_Solaris_RealizesDiskDrive(CCIMObjectPath* pOP)
185 {
186 	CCIMInstanceList	*instList = NULL;
187 	CCIMObjectPathList	*objList;
188 	CCIMObjectPathList	*tmpObjList;
189 	CCIMPropertyList	*pCurPropList;
190 	CCIMObjectPath		*objPath;
191 	CCIMInstance		*inst;
192 	CCIMException		*ex;
193 	dm_descriptor_t		d_descriptor;
194 	int			error = 0;
195 	int			filter[2];
196 
197 	filter[0] = DM_MT_FIXED;
198 	filter[1] = DM_FILTER_END;
199 
200 	/*
201 	 * First see if there are any physical package instances on this
202 	 * system. If none found, then we cannot enumerate instances of
203 	 * this association. We will return an empty list.
204 	 */
205 
206 	inst = cim_createInstance(PHYSICAL_PACKAGE);
207 	if (inst == NULL) {
208 	    ex = cim_getLastError();
209 	    util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
210 		CREATE_INSTANCE, ex, &error);
211 	    return ((CCIMInstanceList *)NULL);
212 	}
213 
214 	objPath = cim_createObjectPath(inst);
215 	cim_freeInstance(inst);
216 
217 	if (objPath == NULL) {
218 	    ex = cim_getLastError();
219 	    util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
220 		CREATE_OBJECT_PATH_FAILURE, ex, &error);
221 	    return ((CCIMInstanceList *)NULL);
222 	}
223 	objList = cimom_enumerateInstanceNames(objPath, cim_false);
224 	cim_freeObjectPath(objPath);
225 
226 	/*
227 	 * NULL means error. Empty list does not.
228 	 */
229 	if (objList == NULL) {
230 	    ex = cim_getLastError();
231 	    util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
232 		ENUM_INSTANCENAMES_FAILURE, ex, &error);
233 	    return ((CCIMInstanceList *)NULL);
234 	}
235 	if (objList->mDataObject == NULL) {
236 	    return ((CCIMInstanceList *)NULL);
237 	}
238 
239 	instList = cim_createInstanceList();
240 	if (instList == NULL) {
241 	    ex = cim_getLastError();
242 	    util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
243 		CREATE_INSTANCE, ex, &error);
244 	    return ((CCIMInstanceList *)NULL);
245 	}
246 
247 	for (tmpObjList = objList; tmpObjList->mDataObject != NULL;
248 	    tmpObjList = tmpObjList->mNext) {
249 		/*
250 		 * Make sure there is a device associated with the instance of
251 		 * the physical package.
252 		 */
253 
254 	    char *name = NULL;
255 
256 	    if ((pCurPropList =
257 		((CCIMObjectPath *)tmpObjList->mDataObject)->mKeyProperties)
258 		    == NULL) {
259 		util_handleError(REALIZES_ENUMINSTANCES,
260 		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
261 		return ((CCIMInstanceList *)NULL);
262 	    }
263 
264 	    name = (cimchar *)util_getKeyValue(pCurPropList, string, TAG,
265 		&error);
266 	    if (error != 0 || name == NULL) {
267 		util_handleError(REALIZES_ENUMINSTANCES,
268 		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
269 		cim_freeInstanceList(instList);
270 		cim_freeObjectPathList(objList);
271 		return ((CCIMInstanceList *)NULL);
272 	    }
273 
274 	    d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name, &error);
275 	    if (error == ENODEV || d_descriptor == NULL) {
276 		continue;
277 	    }
278 
279 	    if (error != 0) {
280 		util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
281 		    DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
282 		cim_freeInstanceList(instList);
283 		cim_freeObjectPathList(objList);
284 		return ((CCIMInstanceList *)NULL);
285 	    }
286 	    inst = realizesdiskdrive_descriptor_toCCIMInstance(hostName,
287 		tmpObjList->mDataObject, d_descriptor,
288 		    REALIZES_DISKDRIVE, &error);
289 	    dm_free_descriptor(d_descriptor);
290 
291 	    if (error != 0) {
292 		util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
293 		    REALIZESDD_DESC_TO_INSTANCE_FAILURE, NULL, &error);
294 		cim_freeInstanceList(instList);
295 		cim_freeObjectPathList(objList);
296 		return ((CCIMInstanceList *)NULL);
297 	    }
298 	    instList = cim_addInstance(instList, inst);
299 	    if (instList == NULL) {
300 		util_handleError(REALIZES_ENUMINSTANCES, CIM_ERR_FAILED,
301 		    ADD_INSTANCE_FAILURE, NULL, &error);
302 		cim_freeObjectPathList(objList);
303 		cim_freeInstance(inst);
304 		return ((CCIMInstanceList *)NULL);
305 	    }
306 	}
307 
308 	cim_freeObjectPathList(objList);
309 	if (instList->mDataObject == NULL) {
310 	    cim_freeInstanceList(instList);
311 	    instList = NULL;
312 	}
313 	return (instList);
314 }
315 
316 /*
317  * Name: cp_enumInstanceNames_Solaris_RealizesDiskDrive
318  *
319  * Description: Returns a linked list of CCIMObjectPath *
320  *      of Solaris_RealizesDiskDrive objects if found.
321  *
322  * Parameters:
323  *	pOP - An CCIMObjectPath * which contains the information on
324  *	the class for which to find the instances.
325  * Returns:
326  *	CCIMObjectPathList * if objects are found. NULL Otherwise.
327  */
328 
329 /* ARGSUSED */
330 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP)331 cp_enumInstanceNames_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP) {
332 
333 	CCIMInstanceList	*instList;
334 	CCIMObjectPathList	*objList = NULL;
335 	int			error;
336 
337 
338 	if (pOP == NULL) {
339 	    util_handleError(REALIZES_ENUMINSTANCENAMES,
340 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
341 	    return ((CCIMObjectPathList *)NULL);
342 	}
343 
344 	/*
345 	 * Call in to enumInstances and then convert the instance list in
346 	 * to an object list.
347 	 */
348 
349 	instList = cp_enumInstances_Solaris_RealizesDiskDrive(pOP);
350 
351 	if (instList != NULL) {
352 	    objList = cim_createObjectPathList(instList);
353 	    cim_freeInstanceList(instList);
354 	}
355 
356 	return (objList);
357 }
358 
359 /*
360  * Creating an instance of a Solaris_RealizesDiskDrive is not supported.
361  */
362 
363 /* ARGSUSED */
364 CCIMObjectPath*
cp_createInstance_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP,CCIMInstance * pInst)365 cp_createInstance_Solaris_RealizesDiskDrive(
366     CCIMObjectPath* pOP, CCIMInstance* pInst)
367 {
368 	int	error;
369 
370 	util_handleError(REALIZES_CREATEINSTANCE,
371 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
372 	return ((CCIMObjectPath *)NULL);
373 }
374 
375 
376 /*
377  * Deleting an instance of a Solaris_RealizesDiskDrive is not supported.
378  */
379 
380 /* ARGSUSED */
381 CIMBool
cp_deleteInstance_Solaris_RealizesDiskDrive(CCIMObjectPath * pInst)382 cp_deleteInstance_Solaris_RealizesDiskDrive(CCIMObjectPath* pInst)
383 {
384 	int	error;
385 
386 	util_handleError(REALIZES_DELETEINSTANCE,
387 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
388 	return (cim_false);
389 }
390 
391 /*
392  * Name: cp_getProperty_Solaris_RealizesDiskDrive
393  *
394  * Description: Returns the property requested, if found.
395  *
396  * Parameters:
397  *	pOP - An CCIMObjectPath * which contains the information on
398  *	the class for which to find the instances.
399  * Returns:
400  *	CCIMProperty * if found.
401  */
402 
403 /* ARGSUSED */
404 CCIMProperty	*
cp_getProperty_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP,char * pPropName)405 cp_getProperty_Solaris_RealizesDiskDrive(CCIMObjectPath *pOP,
406     char *pPropName)
407 {
408 
409 	CCIMProperty	*prop = NULL;
410 	CCIMInstance	*inst = NULL;
411 	int		error = 0;
412 
413 	if (pOP == NULL) {
414 	    util_handleError(REALIZES_GETPROPERTY,
415 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
416 	    return ((CCIMProperty *)NULL);
417 	}
418 
419 	inst = cp_getInstance_Solaris_RealizesDiskDrive(pOP);
420 	if (inst == NULL) {
421 	    return ((CCIMProperty *)NULL);
422 	}
423 
424 	prop = cim_getProperty(inst, pPropName);
425 	cim_freeInstance(inst);
426 	return (prop);
427 }
428 /*
429  * Setting an instance of a Solaris_RealizesDiskDrive is not supported.
430  */
431 
432 /* ARGSUSED */
433 CIMBool
cp_setInstance_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP,CCIMInstance * pInst)434 cp_setInstance_Solaris_RealizesDiskDrive(
435     CCIMObjectPath* pOP, CCIMInstance* pInst)
436 {
437 	int	error;
438 
439 	util_handleError(REALIZES_SETINSTANCE,
440 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
441 	return (cim_false);
442 }
443 
444 
445 /*
446  * Setting a property on a Solaris_RealizesDiskDrive is not supported.
447  */
448 
449 /* ARGSUSED */
450 CIMBool
cp_setProperty_Solaris_RealizesDiskDrive(CCIMObjectPath * pOP,CCIMProperty * pProp)451 cp_setProperty_Solaris_RealizesDiskDrive(
452     CCIMObjectPath* pOP, CCIMProperty* pProp)
453 {
454 	int	error;
455 
456 	util_handleError(REALIZES_SETPROPERTY,
457 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
458 	return (cim_false);
459 }
460 
461 /*
462  * No Methods for Solaris_RealizesDiskDrive.
463  */
464 
465 /* ARGSUSED */
466 CCIMProperty*
cp_invokeMethod_Solaris_RealizesDiskDrive(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)467 cp_invokeMethod_Solaris_RealizesDiskDrive(
468     CCIMObjectPath* op, cimchar* methodName,
469 	CCIMPropertyList* inParams, CCIMPropertyList* outParams)
470 {
471 	CCIMProperty	*retVal = (CCIMProperty	*)NULL;
472 	return (retVal);
473 }
474 
475 /*
476  * Name: cp_execQuery_Solaris_RealizesDiskDrive
477  *
478  * Description:
479  * Returns an instance list which matches the query if any are found.
480  *
481  * Parameters:
482  *	CCIMObjectPath *op - An CCIMObjectPath * which contains the
483  *	information on the class for which to find the instances.
484  *
485  * 	selectList - Not used
486  *	nonJoinExp - Not used
487  *
488  * Returns:
489  *	CCIMInstance * if matched instance is found. Otherwise, NULL.
490  */
491 /*
492  * Currently, there is no WQL parser for the C providers. As a result,
493  * what is returned to the CIMOM is a list of instances with
494  * a NULL value at the beginning of the list. This NULL value indicates
495  * to the CIMOM that it must do the filtering for the client.
496  */
497 
498 /* ARGSUSED */
499 CCIMInstanceList*
cp_execQuery_Solaris_RealizesDiskDrive(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)500 cp_execQuery_Solaris_RealizesDiskDrive(
501     CCIMObjectPath *op, cimchar *selectList, cimchar *nonJoinExp,
502 	cimchar *queryExp, int queryType)
503 {
504 	CCIMInstanceList	*instList = NULL;
505 	CCIMInstanceList	*result;
506 	CCIMInstance		*emptyInst;
507 	CCIMException		*ex;
508 	int			error;
509 
510 	if (op == NULL) {
511 	    util_handleError(REALIZES_EXECQUERY, CIM_ERR_INVALID_PARAMETER,
512 		NULL, NULL, &error);
513 	    return ((CCIMInstanceList *)NULL);
514 	}
515 
516 	instList = cp_enumInstances_Solaris_RealizesDiskDrive(op);
517 
518 	if (instList == NULL) {
519 	    return ((CCIMInstanceList *)NULL);
520 	}
521 
522 	/*
523 	 * Create a null instance and add it to the beginning
524 	 * of the list to indicate to the CIMOM that no filtering
525 	 * was done.
526 	 */
527 
528 	emptyInst = cim_createInstance("");
529 	if (emptyInst == NULL) {
530 	    ex = cim_getLastError();
531 	    util_handleError(REALIZES_EXECQUERY, CIM_ERR_FAILED,
532 		CREATE_INSTANCE_FAILURE, ex, &error);
533 	    return ((CCIMInstanceList *)NULL);
534 	}
535 
536 	result = cim_createInstanceList();
537 	if (result == NULL) {
538 	    ex = cim_getLastError();
539 	    util_handleError(REALIZES_EXECQUERY, CIM_ERR_FAILED,
540 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
541 	    cim_freeInstance(emptyInst);
542 	    cim_freeInstanceList(instList);
543 	    return ((CCIMInstanceList *)NULL);
544 	}
545 
546 	result = cim_addInstance(result, emptyInst);
547 	if (result == NULL) {
548 	    ex = cim_getLastError();
549 	    util_handleError(REALIZES_EXECQUERY, CIM_ERR_FAILED,
550 		ADD_INSTANCE_FAILURE, ex, &error);
551 	    cim_freeInstance(emptyInst);
552 	    cim_freeInstanceList(instList);
553 	    return ((CCIMInstanceList *)NULL);
554 	}
555 
556 	/*
557 	 * Since copying the original list to the new list will
558 	 * leave no way to free the original list, manually
559 	 * concatenate the original list to the new one.
560 	 */
561 
562 	result->mNext = instList;
563 	return (result);
564 }
565 
566 /*
567  * Name: cp_associators_Solaris_RealizesDiskDrive
568  *
569  * Description:
570  * Returns a instances of objects associated with the passed in
571  * object if there are any.
572  *
573  * Parameters:
574  *
575  *	CCIMObjectPath *pAssocName - The name of the association that
576  *	the client wants information about.
577  *
578  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
579  *	information on the class for which to find the associated instances.
580  *
581  *	cimchar *pResultClass - If specified, only return instances that
582  *	are of this class type.
583  *
584  *      cimchar *pRole - If specified, must be valid for the object path
585  *	passed in requesting the associated instances.
586  *
587  *	cimchar *pResultRole - If specified, only return instances that
588  *	are playing this role in the association.
589  *
590  *
591  * Returns:
592  *	CCIMInstanceList * if associated objects are found. NULL Otherwise.
593  */
594 
595 /* ARGSUSED */
596 CCIMInstanceList *
cp_associators_Solaris_RealizesDiskDrive(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pResultClass,cimchar * pRole,cimchar * pResultRole)597 cp_associators_Solaris_RealizesDiskDrive(CCIMObjectPath *pAssocName,
598     CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
599 	cimchar *pResultRole)
600 {
601 	CCIMPropertyList	*pCurPropList;
602 	CCIMInstanceList	*instList = NULL;
603 	CCIMInstance		*inst = NULL;
604 	CCIMException		*ex;
605 	dm_descriptor_t		obj_desc;
606 	char			*name;
607 	int			error = 0;
608 	int			isAntecedent = 0;
609 
610 	if (pObjectName == NULL ||
611 	    pObjectName->mName == NULL ||
612 		pObjectName->mKeyProperties == NULL) {
613 	    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER,
614 		NULL, NULL, &error);
615 	    return ((CCIMInstanceList *)NULL);
616 	}
617 
618 	if (strcasecmp(pObjectName->mName, PHYSICAL_PACKAGE) == 0) {
619 	    isAntecedent = 1;
620 	}
621 
622 	if (pRole != NULL) {
623 	    if (strcasecmp(pRole, ANTECEDENT) == 0) {
624 		if (isAntecedent != 1) {
625 		    util_handleError(REALIZES_ASSOCIATORS,
626 			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
627 		    return ((CCIMInstanceList *)NULL);
628 		}
629 	    }
630 	}
631 
632 	pCurPropList = pObjectName->mKeyProperties;
633 	/*
634 	 * Get the key. It will either be deviceid or tag. These are
635 	 * mutually exclusive.
636 	 */
637 	if (isAntecedent) {
638 	    name = (cimchar *)util_getKeyValue(pCurPropList, string, TAG,
639 		&error);
640 	} else {
641 	    name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
642 		&error);
643 	}
644 
645 	/*
646 	 * We went through the whole list and didn't find the necessary
647 	 * key value.
648 	 */
649 
650 	if (error != 0) {
651 	    util_handleError(REALIZES_ASSOCIATORS,
652 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
653 	    return ((CCIMInstanceList *)NULL);
654 	}
655 
656 	obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name, &error);
657 	/*
658 	 * No device found.
659 	 */
660 	if (error == ENODEV || obj_desc == NULL) {
661 	    return ((CCIMInstanceList *)NULL);
662 
663 	}
664 	if (error != 0) {
665 	    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
666 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
667 	    return ((CCIMInstanceList *)NULL);
668 	}
669 
670 	if (isAntecedent == 1) {
671 		/*
672 		 * Physical package calling this method, return instances of the
673 		 * disk drive associated with this physical package.
674 		 */
675 
676 	    inst = disk_descriptor_toCCIMInstance(hostName, obj_desc, DISK,
677 		&error);
678 	    dm_free_descriptor(obj_desc);
679 
680 	    if (error != 0) {
681 		ex = cim_getLastError();
682 		util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
683 		    DISK_DESC_TO_INSTANCE_FAILURE, ex, &error);
684 		return ((CCIMInstanceList *)NULL);
685 	    }
686 
687 	    instList = cim_createInstanceList();
688 	    if (instList == NULL) {
689 		ex = cim_getLastError();
690 		util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
691 		    CREATE_INSTANCE_LIST_FAILURE, ex, &error);
692 		cim_freeInstance(inst);
693 		return ((CCIMInstanceList *)NULL);
694 	    }
695 	    instList = cim_addInstance(instList, inst);
696 
697 	    if (instList == NULL) {
698 		ex = cim_getLastError();
699 		util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
700 		    ADD_INSTANCE_FAILURE, ex, &error);
701 		cim_freeInstance(inst);
702 		return ((CCIMInstanceList *)NULL);
703 	    }
704 	} else {
705 		/*
706 		 * This is the disk calling this function. Return the physical
707 		 * package instances, if any, that are found on this system.
708 		 * Turn the object descriptor in to a CCIMObjectPath. Then, ask
709 		 * the CIMOM for any instances of this.
710 		 */
711 
712 		CCIMObjectPath	*ob;
713 		CCIMInstance	*in =
714 		    cim_createInstance(PHYSICAL_PACKAGE);
715 
716 		if (in == NULL) {
717 		    ex = cim_getLastError();
718 		    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
719 			CREATE_INSTANCE_FAILURE, ex, &error);
720 		    return ((CCIMInstanceList *)NULL);
721 		}
722 
723 		util_doProperty(
724 		    DEVICEID, string, name, cim_true, inst, &error);
725 
726 		ob = cim_createObjectPath(in);
727 		cim_freeInstance(in);
728 
729 		if (ob == NULL) {
730 		    ex = cim_getLastError();
731 		    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
732 			CREATE_OBJECT_PATH_FAILURE, ex, &error);
733 		    return ((CCIMInstanceList *)NULL);
734 		}
735 
736 		inst = cimom_getInstance(ob, cim_false, cim_false,
737 		    cim_false, cim_false, NULL, 0);
738 		cim_freeObjectPath(ob);
739 
740 		/*
741 		 * NULL indicates error. Empty object does not.
742 		 */
743 		if (inst == NULL) {
744 		    ex = cim_getLastError();
745 		    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
746 			GET_INSTANCE_FAILURE, ex, &error);
747 		    return ((CCIMInstanceList *)NULL);
748 		}
749 
750 		if (inst->mProperties == NULL) {
751 		    return ((CCIMInstanceList *)NULL);
752 		}
753 
754 		instList = cim_createInstanceList();
755 		if (instList == NULL) {
756 		    ex = cim_getLastError();
757 		    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
758 			CREATE_INSTANCE_LIST_FAILURE, ex, &error);
759 		    cim_freeInstance(inst);
760 		    return ((CCIMInstanceList *)NULL);
761 		}
762 		instList = cim_addInstance(instList, inst);
763 
764 		if (instList == NULL) {
765 		    ex = cim_getLastError();
766 		    util_handleError(REALIZES_ASSOCIATORS, CIM_ERR_FAILED,
767 			ADD_INSTANCE_FAILURE, ex, &error);
768 		    cim_freeInstance(inst);
769 		    return ((CCIMInstanceList *)NULL);
770 		}
771 	}
772 
773 	return (instList);
774 }
775 
776 /*
777  * Name: cp_associatorNames_Solaris_RealizesDiskDrive
778  *
779  * Description:
780  * Returns a list of objects associated with the passed in
781  * object if there are any via the object CCIMObjectPath.
782  *
783  * Parameters:
784  *
785  *	CCIMObjectPath *pAssocName - The name of the association that
786  *	the client wants information about.
787  *
788  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
789  *	information on the class for which to find the associated instances.
790  *
791  *	cimchar *pResultClass - If specified, only return instances that
792  *	are of this class type.
793  *
794  *      cimchar *pRole - If specified, must be valid for the object path
795  *	passed in requesting the associated instances.
796  *
797  *	cimchar *pResultRole - If specified, only return instances that
798  *	are playing this role in the association.
799  *
800  *
801  * Returns:
802  *	CCIMObjectPathList * if associated objects are found. NULL otherwise.
803  */
804 
805 /* ARGSUSED */
806 CCIMObjectPathList *
cp_associatorNames_Solaris_RealizesDiskDrive(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pResultClass,cimchar * pRole,cimchar * pResultRole)807 cp_associatorNames_Solaris_RealizesDiskDrive(CCIMObjectPath *pAssocName,
808     CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
809 	cimchar *pResultRole)
810 {
811 
812 	CCIMInstanceList	*instList;
813 	CCIMObjectPathList	*objList = NULL;
814 	int			error;
815 
816 
817 	if (pObjectName == NULL) {
818 	    util_handleError(REALIZES_ASSOCIATORNAMES,
819 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
820 	    return ((CCIMObjectPathList *)NULL);
821 	}
822 
823 	instList =
824 	    cp_associators_Solaris_RealizesDiskDrive(
825 		pAssocName, pObjectName, pResultClass, pRole, pResultRole);
826 
827 	if (instList != NULL) {
828 	    objList = cim_createObjectPathList(instList);
829 	    cim_freeInstanceList(instList);
830 	}
831 
832 	return (objList);
833 }
834 
835 /*
836  * Name: cp_references_Solaris_RealizesDiskDrive
837  *
838  * Description:
839  * Returns a instances of objects that have references to the passed in
840  * object if there are any.
841  *
842  * Parameters:
843  *
844  *	CCIMObjectPath *pAssocName - The name of the association that
845  *	the client wants information about.
846  *
847  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
848  *	information on the class for which to find the associated instances.
849  *
850  *      cimchar *pRole - If specified, must be valid for the object path
851  *	passed in requesting the associated instances.
852  *
853  * Returns:
854  *	CCIMInstanceList * if associated objects are found. NULL otherwise.
855  */
856 
857 /* ARGSUSED */
858 CCIMInstanceList *
cp_references_Solaris_RealizesDiskDrive(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)859 cp_references_Solaris_RealizesDiskDrive(CCIMObjectPath *pAssocName,
860 CCIMObjectPath *pObjectName, char *pRole)
861 {
862 
863 	CCIMInstanceList	*instList = NULL;
864 	CCIMObjectPathList	*objList;
865 	int			error;
866 
867 	if (pObjectName == NULL) {
868 	    util_handleError(REALIZES_REFERENCES,
869 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
870 	    return ((CCIMInstanceList *)NULL);
871 	}
872 	/*
873 	 * Get the list of those objects that are referred to by
874 	 * the calling object.
875 	 */
876 
877 	objList =
878 	    cp_associatorNames_Solaris_RealizesDiskDrive(
879 		pAssocName, pObjectName, NULL, NULL, NULL);
880 
881 	if (objList == NULL) {
882 	    return ((CCIMInstanceList *)NULL);
883 	}
884 
885 	/*
886 	 * Now generate the list of instances to return.
887 	 */
888 
889 	if ((strcasecmp(pObjectName->mName, PHYSICAL_PACKAGE)) == 0) {
890 	    instList = createRealizesDiskDriveList(pObjectName, ANTECEDENT,
891 		objList, DEPENDENT, &error);
892 	} else {
893 	    instList = createRealizesDiskDriveList(pObjectName, DEPENDENT,
894 		objList, ANTECEDENT, &error);
895 	}
896 
897 	cim_freeObjectPathList(objList);
898 	return (instList);
899 }
900 
901 /*
902  * Name: cp_referenceNames_Solaris_RealizesDiskDrive
903  *
904  * Description:
905  * Returns a instances of objects that have references to the passed in
906  * object if there are any.
907  *
908  * Parameters:
909  *
910  *	CCIMObjectPath *pAssocName - The name of the association that
911  *	the client wants information about.
912  *
913  *	CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
914  *	information on the class for which to find the associated instances.
915  *
916  *      cimchar *pRole - If specified, must be valid for the object path
917  *	passed in requesting the associated instances.
918  *
919  *
920  * Returns:
921  *	CCIMInstanceList * if associated objects are found. NULL otherwise.
922  *
923  */
924 /* ARGSUSED */
925 CCIMObjectPathList *
cp_referenceNames_Solaris_RealizesDiskDrive(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,cimchar * pRole)926 cp_referenceNames_Solaris_RealizesDiskDrive(CCIMObjectPath *pAssocName,
927     CCIMObjectPath *pObjectName, cimchar *pRole)
928 {
929 
930 	CCIMInstanceList	*instList = NULL;
931 	CCIMObjectPathList	*objList = NULL;
932 	int			error;
933 
934 	if (pObjectName == NULL) {
935 	    util_handleError(REALIZES_REFERENCENAMES,
936 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
937 	    return ((CCIMObjectPathList *)NULL);
938 	}
939 
940 	instList =
941 	    cp_references_Solaris_RealizesDiskDrive(pAssocName,
942 		pObjectName, pRole);
943 
944 	if (instList != NULL) {
945 	    objList = cim_createObjectPathList(instList);
946 	    cim_freeInstanceList(instList);
947 	}
948 
949 	return (objList);
950 }
951 
952 /*
953  * Create the association class with the passed in attributes.
954  */
955 static
956 CCIMInstanceList  *
createRealizesDiskDriveList(CCIMObjectPath * pObjectName,cimchar * pObjectNameRole,CCIMObjectPathList * objList,cimchar * objRole,int * error)957 createRealizesDiskDriveList(CCIMObjectPath *pObjectName,
958     cimchar *pObjectNameRole, CCIMObjectPathList *objList,
959 	cimchar *objRole, int *error)
960 {
961 
962 	CCIMObjectPathList	*tmpList;
963 	CCIMInstanceList	*instList = NULL;
964 	CCIMInstance		*inst;
965 	CCIMObjectPath		*obj1;
966 	CCIMObjectPath		*obj2;
967 	CCIMException		*ex;
968 
969 	*error = 0;
970 
971 	/*
972 	 * If no objects associated with this one, return NULL.
973 	 */
974 	if (objList == NULL) {
975 	    return ((CCIMInstanceList *)NULL);
976 	}
977 
978 	instList = cim_createInstanceList();
979 	if (instList == NULL) {
980 	    ex = cim_getLastError();
981 	    util_handleError(REALIZES_DISKDRIVE,
982 		CIM_ERR_FAILED, CREATE_INSTANCE_FAILURE, ex, error);
983 	    return ((CCIMInstanceList *)NULL);
984 	}
985 
986 	tmpList = objList;
987 	while (tmpList != NULL) {
988 	    obj1 = tmpList->mDataObject;
989 	    obj2 = cim_copyObjectPath(pObjectName);
990 	    if (obj2 == NULL) {
991 		ex = cim_getLastError();
992 		util_handleError(REALIZES_DISKDRIVE, CIM_ERR_FAILED,
993 		    COPY_OBJPATH_FAILURE, ex, error);
994 		return ((CCIMInstanceList *)NULL);
995 	    }
996 
997 	    inst = cim_createInstance(REALIZES_DISKDRIVE);
998 	    if (inst == NULL) {
999 		ex = cim_getLastError();
1000 		util_handleError(REALIZES_DISKDRIVE,
1001 		    CIM_ERR_FAILED, CREATE_INSTANCE_FAILURE, ex, error);
1002 		return ((CCIMInstanceList *)NULL);
1003 	    }
1004 
1005 	    util_doReferenceProperty(pObjectNameRole, obj2, cim_true,
1006 		inst, error);
1007 	    cim_freeObjectPath(obj2);
1008 
1009 	    if (*error != 0) {
1010 		ex = cim_getLastError();
1011 		util_handleError(REALIZES_DISKDRIVE,
1012 		    CIM_ERR_FAILED, ADD_PROPERTY_FAILURE, ex, error);
1013 		cim_freeInstance(inst);
1014 		return ((CCIMInstanceList *)NULL);
1015 	    }
1016 
1017 	    util_doReferenceProperty(objRole, obj1, cim_true, inst, error);
1018 
1019 	    if (*error != 0) {
1020 		ex = cim_getLastError();
1021 		util_handleError(REALIZES_DISKDRIVE, CIM_ERR_FAILED,
1022 		    ADD_PROPERTY_FAILURE, ex, error);
1023 		cim_freeInstance(inst);
1024 		return ((CCIMInstanceList *)NULL);
1025 	    }
1026 	    instList = cim_addInstance(instList, inst);
1027 	    if (instList == NULL) {
1028 		ex = cim_getLastError();
1029 		util_handleError(REALIZES_DISKDRIVE, CIM_ERR_FAILED,
1030 		    ADD_INSTANCE_FAILURE, ex, error);
1031 		cim_freeInstance(inst);
1032 		return ((CCIMInstanceList *)NULL);
1033 	    }
1034 
1035 	    tmpList = tmpList->mNext;
1036 	}
1037 	return (instList);
1038 }
1039