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