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