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