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