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 "methods.h"
36 #include "disk_descriptors.h"
37 #include "providerNames.h"
38 #include "messageStrings.h"
39
40 #define DISK_GETINSTANCE "DISK,GET_INSTANCE"
41 #define DISK_ENUMINSTANCES "DISK,ENUM_INSTANCES"
42 #define DISK_ENUMINSTANCENAMES "DISK,ENUM_INSTANCENAMES"
43 #define DISK_CREATEINSTANCE "DISK,CREATE_INSTANCE"
44 #define DISK_DELETEINSTANCE "DISK,DELETE_INSTANCE"
45 #define DISK_SETINSTANCE "DISK,SET_INSTANCE"
46 #define DISK_GETPROPERTY "DISK,GET_PROPERTY"
47 #define DISK_SETPROPERTY "DISK,SET_PROPERTY"
48 #define DISK_INVOKEMETHOD "DISK,INVOKE_METHOD"
49 #define DISK_EXECQUERY "DISK,EXEC_QUERY"
50
51 /*
52 * Solaris_Disk provider
53 *
54 * It is important to note that all memory allocated by these functions
55 * and passed to the CIMOM, is freed by the CIMOM as the caller.
56 */
57
58
59 /*
60 * Name: cp_getInstance_Solaris_Disk
61 *
62 * Description: Returns an instance which matches the passed in object path
63 * if found.
64 *
65 * Parameters:
66 * pOP - An CCIMObjectPath * which contains the information on
67 * the class for which to find the instance.
68 * Returns:
69 * CCIMInstance * if matched instance is found. Otherwise, NULL.
70 */
71
72 /* ARGSUSED */
73 CCIMInstance*
cp_getInstance_Solaris_Disk(CCIMObjectPath * pOP)74 cp_getInstance_Solaris_Disk(CCIMObjectPath* pOP)
75 {
76 CCIMInstance *inst = NULL;
77 CCIMPropertyList *pCurPropList;
78 dm_descriptor_t disk_descriptor;
79 char *name;
80 int error;
81
82 if (pOP == NULL || pOP->mKeyProperties == NULL) {
83 util_handleError(DISK_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
84 NULL, &error);
85 return ((CCIMInstance *)NULL);
86 }
87
88 pCurPropList = pOP->mKeyProperties;
89 name = (cimchar *)util_getKeyValue(pCurPropList, string, TAG, &error);
90
91 if (error != 0 || name == NULL) {
92 util_handleError(DISK_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
93 NULL, &error);
94 return ((CCIMInstance *)NULL);
95 }
96
97 disk_descriptor = dm_get_descriptor_by_name(DM_MEDIA, name, &error);
98
99 /*
100 * Not found. Return a null instance.
101 */
102 if (error == ENODEV) {
103 return ((CCIMInstance *)NULL);
104 }
105
106 if (error != 0) {
107 util_handleError(DISK_GETINSTANCE, CIM_ERR_FAILED,
108 DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
109 return ((CCIMInstance *)NULL);
110 }
111
112 /* Turn this descriptor in to a disk drive instance */
113
114 inst = disk_descriptor_toCCIMInstance(
115 hostName, disk_descriptor, DISK, &error);
116 dm_free_descriptor(disk_descriptor);
117
118 if (error != 0) {
119 util_handleError(DISK_GETINSTANCE, CIM_ERR_FAILED,
120 DISK_DESC_TO_INSTANCE_FAILURE, NULL, &error);
121 return ((CCIMInstance *)NULL);
122 }
123
124 return (inst);
125 }
126
127 /*
128 * Name: cp_enumInstances_Solaris_Disk
129 *
130 * Description: Returns a list of instances if found.
131 *
132 * Parameters:
133 * pOP - An CCIMObjectPath * which contains the information on
134 * the class for which to find the instance.
135 * Returns:
136 * CCIMInstanceList * if matched instance is found. Otherwise, NULL.
137 */
138
139 /* ARGSUSED */
140 CCIMInstanceList*
cp_enumInstances_Solaris_Disk(CCIMObjectPath * pOP)141 cp_enumInstances_Solaris_Disk(CCIMObjectPath* pOP)
142 {
143 CCIMInstanceList* instList = NULL;
144 dm_descriptor_t *disk_descriptorp;
145 int error;
146
147 disk_descriptorp = dm_get_descriptors(DM_MEDIA, NULL, &error);
148
149 if (disk_descriptorp == NULL ||
150 disk_descriptorp[0] == NULL) {
151 return ((CCIMInstanceList *)NULL);
152 }
153 if (error != 0) {
154 util_handleError(DISK_ENUMINSTANCENAMES, CIM_ERR_FAILED,
155 DM_GET_DESCRIPTORS, NULL, &error);
156 return ((CCIMInstanceList *)NULL);
157 }
158
159 /* convert drive descriptors to CCIMInstanceList */
160 instList = disk_descriptors_toCCIMInstanceList(DISK,
161 disk_descriptorp, &error);
162 dm_free_descriptors(disk_descriptorp);
163
164 if (error != 0) {
165 util_handleError(DISK_ENUMINSTANCES, CIM_ERR_FAILED,
166 DISK_DESC_TO_INSTANCE_FAILURE, NULL, &error);
167 return ((CCIMInstanceList *)NULL);
168 }
169
170 return (instList);
171 }
172
173 /*
174 * Name: cp_enumInstanceNames_Solaris_Disk
175 *
176 * Description: Returns a list of instances if found.
177 *
178 * Parameters:
179 * pOP - An CCIMObjectPath * which contains the information on
180 * the class for which to find the instance.
181 * Returns:
182 * CCIMObjectPathList * if matched instance is found. Otherwise, NULL.
183 */
184
185 /* ARGSUSED */
186 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_Disk(CCIMObjectPath * pOP)187 cp_enumInstanceNames_Solaris_Disk(CCIMObjectPath * pOP) {
188
189 CCIMInstanceList *instList;
190 CCIMObjectPathList *objList = NULL;
191 int error;
192
193 if (pOP == NULL) {
194 util_handleError(DISK_ENUMINSTANCENAMES, CIM_ERR_INVALID_PARAMETER,
195 NULL, NULL, &error);
196 return ((CCIMObjectPathList *)NULL);
197 }
198
199 /*
200 * Call in to enumInstances and then convert the instance list in
201 * to an object list.
202 */
203
204 instList = cp_enumInstances_Solaris_Disk(pOP);
205
206 if (instList != NULL) {
207 objList = cim_createObjectPathList(instList);
208 cim_freeInstanceList(instList);
209 }
210
211 return (objList);
212 }
213
214 /*
215 * Creating an instance of a Solaris_Disk is not supported.
216 */
217
218 /* ARGSUSED */
219 CCIMObjectPath*
cp_createInstance_Solaris_Disk(CCIMObjectPath * pOP,CCIMInstance * pInst)220 cp_createInstance_Solaris_Disk(CCIMObjectPath* pOP, CCIMInstance* pInst)
221 {
222 int error;
223
224 util_handleError(DISK_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
225 NULL, &error);
226 return ((CCIMObjectPath *)NULL);
227 }
228
229 /*
230 * Deleting an instance of a Solaris_Disk is not supported.
231 */
232
233 /* ARGSUSED */
234 CIMBool
cp_deleteInstance_Solaris_Disk(CCIMObjectPath * pInst)235 cp_deleteInstance_Solaris_Disk(CCIMObjectPath* pInst)
236 {
237
238 int error;
239
240 util_handleError(DISK_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
241 NULL, &error);
242 return (cim_false);
243 }
244
245 /*
246 * Name: cp_getProperty_Solaris_Disk
247 *
248 * Description: Returns the property requested, if found.
249 *
250 * Parameters:
251 * pOP - An CCIMObjectPath * which contains the information on
252 * the class for which to find the instances.
253 * Returns:
254 * CCIMProperty * if found.
255 */
256
257 /* ARGSUSED */
258 CCIMProperty *
cp_getProperty_Solaris_Disk(CCIMObjectPath * pOP,char * pPropName)259 cp_getProperty_Solaris_Disk(CCIMObjectPath *pOP, char *pPropName)
260 {
261
262 CCIMProperty *prop = NULL;
263 CCIMInstance *inst = NULL;
264 int error;
265
266 if (pOP == NULL) {
267 util_handleError(DISK_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
268 NULL, &error);
269 return ((CCIMProperty *)NULL);
270 }
271
272 inst = cp_getInstance_Solaris_Disk(pOP);
273 if (inst == NULL) {
274 return ((CCIMProperty *)NULL);
275 }
276
277 prop = cim_getProperty(inst, pPropName);
278 cim_freeInstance(inst);
279 return (prop);
280 }
281
282 /* This provider cannot set an instance of a Solaris_Disk object. */
283
284 /* ARGSUSED */
285 CIMBool
cp_setInstance_Solaris_Disk(CCIMObjectPath * pOP,CCIMInstance * pInst)286 cp_setInstance_Solaris_Disk(CCIMObjectPath* pOP, CCIMInstance* pInst)
287 {
288
289 int error;
290
291 util_handleError(DISK_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, NULL,
292 &error);
293 return (cim_false);
294 }
295
296 /* This provider cannot set an instance of a Solaris_Disk object. */
297
298 /* ARGSUSED */
299 CIMBool
cp_setProperty_Solaris_Disk(CCIMObjectPath * pOP,CCIMProperty * pProp)300 cp_setProperty_Solaris_Disk(CCIMObjectPath* pOP, CCIMProperty* pProp)
301 {
302
303 int error;
304
305 util_handleError(DISK_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
306 NULL, &error);
307 return (cim_false);
308 }
309
310 /* invokeMethod function dispatches to the various method implementations */
311 CCIMProperty*
cp_invokeMethod_Solaris_Disk(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)312 cp_invokeMethod_Solaris_Disk(CCIMObjectPath* op, cimchar* methodName,
313 CCIMPropertyList* inParams, CCIMPropertyList* outParams)
314 {
315 CCIMProperty *retVal = (CCIMProperty *)NULL;
316 int error;
317
318 /* dispatch code for various methods */
319 if (strcasecmp("createFDiskPartitions", methodName) == 0) {
320 retVal = create_fdisk_partitions(inParams, op);
321 return (retVal);
322 } else if (strcasecmp("createPartitions", methodName) == 0) {
323 retVal = create_partitions(inParams, op);
324 return (retVal);
325 } else if (strcasecmp("labelDisk", methodName) == 0) {
326 retVal = label_disk(inParams, op);
327 return (retVal);
328 } else if (strcasecmp("getDiskGeometry", methodName) == 0) {
329 retVal = get_disk_geometry(outParams, op);
330 return (retVal);
331 }
332
333 /*
334 * We fell through the dispatch logic. There is no function
335 * that matches 'methodName'.
336 */
337
338 util_handleError(DISK_INVOKEMETHOD, CIM_ERR_FAILED,
339 NO_SUCH_METHOD, NULL, &error);
340 return (retVal);
341 }
342
343 /*
344 * Name: cp_execQuery_Solaris_Disk
345 *
346 * Description:
347 * Returns an instance list which matches the query if any are found.
348 *
349 * Parameters:
350 * CCIMObjectPath *op - An CCIMObjectPath * which contains the
351 * information on the class for which to find the instances.
352 *
353 * selectList - Not used
354 * nonJoinExp - Not used
355 *
356 * Returns:
357 * CCIMInstance * if matched instance is found. Otherwise, NULL.
358 */
359
360 /*
361 * Currently, there is no WQL parser for the C providers. As a result,
362 * what is returned to the CIMOM is a list of instances with
363 * a NULL value at the beginning of the list. This NULL value indicates
364 * to the CIMOM that it must do the filtering for the client.
365 */
366
367 /* ARGSUSED */
368 CCIMInstanceList*
cp_execQuery_Solaris_Disk(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)369 cp_execQuery_Solaris_Disk(CCIMObjectPath *op, cimchar *selectList,
370 cimchar *nonJoinExp, cimchar *queryExp, int queryType)
371 {
372 CCIMInstanceList *instList = NULL;
373 CCIMInstanceList *result;
374 CCIMInstance *emptyInst;
375 CCIMException *ex;
376 int error;
377
378 if (op == NULL) {
379 util_handleError(DISK_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
380 NULL, &error);
381 return ((CCIMInstanceList *)NULL);
382 }
383
384 instList = cp_enumInstances_Solaris_Disk(op);
385
386 if (instList == NULL) {
387 return ((CCIMInstanceList *)NULL);
388 }
389 /*
390 * Create a null instance and add it to the beginning
391 * of the list to indicate to the CIMOM that no filtering
392 * was done.
393 */
394
395 emptyInst = cim_createInstance("");
396 if (emptyInst == NULL) {
397 ex = cim_getLastError();
398 util_handleError(DISK_EXECQUERY, CIM_ERR_FAILED,
399 CREATE_INSTANCE_FAILURE, ex, &error);
400 cim_freeInstanceList(instList);
401 return ((CCIMInstanceList *)NULL);
402 }
403
404 result = cim_createInstanceList();
405 if (result == NULL) {
406 ex = cim_getLastError();
407 util_handleError(DISK_EXECQUERY, CIM_ERR_FAILED,
408 CREATE_INSTANCE_LIST_FAILURE, ex, &error);
409 cim_freeInstance(emptyInst);
410 cim_freeInstanceList(instList);
411 return ((CCIMInstanceList *)NULL);
412 }
413
414 result = cim_addInstance(result, emptyInst);
415 if (result == NULL) {
416 ex = cim_getLastError();
417 util_handleError(DISK_EXECQUERY, CIM_ERR_FAILED,
418 ADD_INSTANCE_FAILURE, ex, &error);
419 cim_freeInstance(emptyInst);
420 cim_freeInstanceList(instList);
421 return ((CCIMInstanceList *)NULL);
422 }
423
424 /*
425 * Since copying the original list to the new list will
426 * leave no way to free the original list, manually
427 * concatenate the original list to the new one.
428 */
429
430 result->mNext = instList;
431 return (result);
432 }
433