os-cmpi-xen

view src/Xen_VirtualizationCapabilities.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents 33d4316c01a2
children
line source
1 // Copyright (C) 2006 IBM Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Description:
20 // ============================================================================
22 /* Include the required CMPI data types, function headers, and macros */
23 #include "cmpidt.h"
24 #include "cmpift.h"
25 #include "cmpimacs.h"
28 // ----------------------------------------------------------------------------
29 // COMMON GLOBAL VARIABLES
30 // ----------------------------------------------------------------------------
32 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
33 static const CMPIBroker *_BROKER;
35 /* Include utility functions */
36 #include "cmpiutil.h"
38 /* Include _SBLIM_TRACE() logging support */
39 #include "cmpitrace.h"
41 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
42 #include "Xen_VirtualizationCapabilities_Resource.h"
45 // ============================================================================
46 // CMPI INSTANCE PROVIDER FUNCTION TABLE
47 // ============================================================================
49 // ----------------------------------------------------------------------------
50 // Info for the class supported by the instance provider
51 // ----------------------------------------------------------------------------
53 /* Name of the class implemented by this instance provider. */
54 /*** CUSTOMIZE FOR EACH PROVIDER ***/
55 static char * _CLASSNAME = "Xen_VirtualizationCapabilities";
57 /* NULL terminated list of key properties of this class. */
58 /*** CUSTOMIZE FOR EACH PROVIDER ***/
59 const static char * _KEYNAMES[] = {"InstanceID", NULL};
61 // ----------------------------------------------------------------------------
62 // Cleanup()
63 // Perform any necessary cleanup immediately before this provider is unloaded.
64 // ----------------------------------------------------------------------------
65 static CMPIStatus Cleanup(
66 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
67 const CMPIContext * context, /* [in] Additional context info, if any. */
68 CMPIBoolean terminating) /* [in] True if MB is terminating */
69 {
70 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
72 _SBLIM_ENTER("Cleanup");
73 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
74 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
76 /* Nothing needs to be done for cleanup. */
77 _SBLIM_RETURNSTATUS(status);
78 }
80 // ----------------------------------------------------------------------------
81 // EnumInstanceNames()
82 // Return a list of all the instances names (return their object paths only).
83 // ----------------------------------------------------------------------------
84 static CMPIStatus EnumInstanceNames(
85 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
86 const CMPIContext * context, /* [in] Additional context info, if any. */
87 const CMPIResult * results, /* [out] Results of this operation. */
88 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
89 {
90 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
91 _RESOURCES * resources; /* Handle to the list of system resources. */
92 _RESOURCE * resource; /* Handle to each system resource. */
93 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
94 int found = 0; /* Found any instances? */
96 _SBLIM_ENTER("EnumInstanceNames");
97 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
98 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
99 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
100 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
102 /* Get a handle to the list of system resources. */
103 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
104 _SBLIM_TRACE(1,("--- _getResources() failed"));
105 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
106 goto exit;
107 }
109 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
110 while (Xen_VirtualizationCapabilities_getNextResource(resources, &resource)) {
111 /* Create a new CMPIInstance to store this resource. */
112 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
113 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
114 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
115 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
116 goto exit;
117 }
119 /* Set the instance property values from the resource data. */
120 if (!Xen_VirtualizationCapabilities_setInstanceFromResource(resource, instance, _BROKER, resources)) {
121 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
122 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
123 goto exit;
124 }
126 /* Free the resource data. */
127 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
128 _SBLIM_TRACE(1,("--- _freeResource() failed"));
129 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
130 goto exit;
131 }
133 /* Return the CMPIObjectPath for this instance. */
134 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
135 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
136 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
137 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
138 goto exit;
139 }
140 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
142 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
143 CMReturnObjectPath(results, objectpath);
144 found++;
145 }
147 _SBLIM_TRACE(2,("--- %d object paths found", found));
148 CMReturnDone(results);
150 exit:
151 /* Free the list of system resources. */
152 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
153 _SBLIM_TRACE(1,("--- _freeResources() failed"));
154 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
155 }
157 _SBLIM_RETURNSTATUS(status);
158 }
160 // ----------------------------------------------------------------------------
161 // EnumInstances()
162 // Return a list of all the instances (return all the instance data).
163 // ----------------------------------------------------------------------------
164 static CMPIStatus EnumInstances(
165 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
166 const CMPIContext * context, /* [in] Additional context info, if any. */
167 const CMPIResult * results, /* [out] Results of this operation. */
168 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
169 const char ** properties) /* [in] List of desired properties (NULL=all). */
170 {
171 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
172 _RESOURCES * resources; /* Handle to the list of system resources. */
173 _RESOURCE * resource; /* Handle to each system resource. */
174 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
175 int found = 0; /* Found any resource instances? */
177 _SBLIM_ENTER("EnumInstances");
178 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
179 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
180 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
181 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
183 /* Get a handle to the list of system resources. */
184 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
185 _SBLIM_TRACE(1,("--- _getResources() failed"));
186 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
187 goto exit;
188 }
190 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
191 while (Xen_VirtualizationCapabilities_getNextResource(resources, &resource)) {
192 /* Create a new CMPIInstance to store this resource. */
193 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
194 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
195 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
196 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
197 goto exit;
198 }
200 /* Setup a filter to only return the desired properties. */
201 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
202 if (status.rc != CMPI_RC_OK) {
203 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
204 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
205 goto exit;
206 }
208 /* Set the instance property values from the resource data. */
209 if (!Xen_VirtualizationCapabilities_setInstanceFromResource(resource, instance, _BROKER, resources)) {
210 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
211 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
212 goto exit;
213 }
215 /* Free the resource data. */
216 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
217 _SBLIM_TRACE(1,("--- _freeResource() failed"));
218 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
219 goto exit;
220 }
222 /* Return the CMPIInstance for this instance. */
223 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
224 CMReturnInstance(results, instance);
225 found++;
226 }
228 _SBLIM_TRACE(2,("--- %d instances found", found));
229 CMReturnDone(results);
231 exit:
232 /* Free the list of system resources. */
233 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
234 _SBLIM_TRACE(1,("--- _freeResources() failed"));
235 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
236 }
238 _SBLIM_RETURNSTATUS(status);
239 }
241 // ----------------------------------------------------------------------------
242 // GetInstance()
243 // Return the instance data for the specified instance only.
244 // ----------------------------------------------------------------------------
245 static CMPIStatus GetInstance(
246 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
247 const CMPIContext * context, /* [in] Additional context info, if any. */
248 const CMPIResult * results, /* [out] Results of this operation. */
249 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
250 const char ** properties) /* [in] List of desired properties (NULL=all). */
251 {
252 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
253 _RESOURCES * resources; /* Handle to the list of system resources. */
254 _RESOURCE * resource; /* Handle to the system resource. */
255 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
256 int found = 0; /* Found the target instance? */
258 _SBLIM_ENTER("GetInstance");
259 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
260 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
261 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
262 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
264 /* Get a handle to the list of system resources. */
265 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
266 _SBLIM_TRACE(1,("--- _getResources() failed"));
267 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
268 goto exit;
269 }
271 /* Get the target resource. */
272 found = Xen_VirtualizationCapabilities_getResourceForObjectPath(resources, &resource, reference);
273 if (!found || (resource == NULL)) {
274 _SBLIM_TRACE(1,("--- Target instance not found"));
275 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
276 goto exit;
277 }
279 /* Create a new CMPIInstance to store this resource. */
280 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
281 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
282 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
283 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
284 goto exit;
285 }
287 /* Setup a filter to only return the desired properties. */
288 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
289 if (status.rc != CMPI_RC_OK) {
290 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
291 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
292 goto exit;
293 }
295 /* Set the instance property values from the resource data. */
296 if (!Xen_VirtualizationCapabilities_setInstanceFromResource(resource, instance, _BROKER, resources)) {
297 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
298 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
299 goto exit;
300 }
302 /* Free the resource data. */
303 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
304 _SBLIM_TRACE(1,("--- _freeResource() failed"));
305 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
306 goto exit;
307 }
309 /* Return the CMPIInstance for this instance. */
310 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
311 CMReturnInstance(results, instance);
313 _SBLIM_TRACE(2,("--- instance found"));
314 CMReturnDone(results);
316 exit:
317 /* Free the list of system resources. */
318 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
319 _SBLIM_TRACE(1,("--- _freeResources() failed"));
320 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
321 }
323 _SBLIM_RETURNSTATUS(status);
324 }
326 // ----------------------------------------------------------------------------
327 // SetInstance()
328 // Save modified instance data for the specified instance.
329 // ----------------------------------------------------------------------------
330 static CMPIStatus SetInstance(
331 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
332 const CMPIContext * context, /* [in] Additional context info, if any. */
333 const CMPIResult * results, /* [out] Results of this operation. */
334 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
335 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
336 const char **properties)
337 {
338 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
339 _RESOURCES * resources; /* Handle to the list of system resources. */
340 _RESOURCE * resource; /* Handle to the system resource. */
341 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
342 int found = 0; /* Found the target instance? */
344 _SBLIM_ENTER("SetInstance");
345 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
346 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
347 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
348 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
349 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
351 /* Get a handle to the list of system resources. */
352 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
353 _SBLIM_TRACE(1,("--- _getResources() failed"));
354 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
355 goto exit;
356 }
358 /* Get the target resource. */
359 found = Xen_VirtualizationCapabilities_getResourceForObjectPath(resources, &resource, reference);
360 if (!found || (resource == NULL)) {
361 _SBLIM_TRACE(1,("--- Target instance not found"));
362 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
363 goto exit;
364 }
366 _SBLIM_TRACE(2,("--- instance found", found));
368 /* Update the target resource data with the new instance property values. */
369 int rc = Xen_VirtualizationCapabilities_setResourceFromInstance(resource, newinstance, _BROKER);
371 /* Free the resource data. */
372 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
373 _SBLIM_TRACE(1,("--- _freeResource() failed"));
374 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
375 goto exit;
376 }
378 if (rc != 1) {
379 if (rc == -1) {
380 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
381 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
382 } else {
383 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
385 }
386 goto exit;
387 }
389 exit:
390 /* Free the list of system resources. */
391 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
392 _SBLIM_TRACE(1,("--- _freeResources() failed"));
393 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
394 }
396 _SBLIM_RETURNSTATUS(status);
397 }
399 // ----------------------------------------------------------------------------
400 // CreateInstance()
401 // Create a new instance from the specified instance data.
402 // ----------------------------------------------------------------------------
403 static CMPIStatus CreateInstance(
404 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
405 const CMPIContext * context, /* [in] Additional context info, if any. */
406 const CMPIResult * results, /* [out] Results of this operation. */
407 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
408 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
409 {
410 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
411 _RESOURCES * resources; /* Handle to the list of system resources. */
412 _RESOURCE * resource; /* Handle to the system resource. */
413 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
414 int found = 0; /* Found the target instance? */
416 _SBLIM_ENTER("CreateInstance");
417 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
418 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
419 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
420 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
421 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
423 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
424 reference = CMGetObjectPath(newinstance, NULL);
426 /* Get a handle to the list of system resources. */
427 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
428 _SBLIM_TRACE(1,("--- _getResources() failed"));
429 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
430 goto exit;
431 }
433 /* Get the target resource. */
434 found = Xen_VirtualizationCapabilities_getResourceForObjectPath(resources, &resource, reference);
436 /* Free the resource data. */
437 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
438 _SBLIM_TRACE(1,("--- _freeResource() failed"));
439 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
440 goto exit;
441 }
443 if (found) {
444 _SBLIM_TRACE(1,("--- Target instance already exists"));
445 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
446 goto exit;
447 }
449 /* Create a new resource with the new instance property values. */
450 int rc = Xen_VirtualizationCapabilities_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
451 if (rc != 1) {
452 if (rc == -1) {
453 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
454 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
455 } else {
456 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
457 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
458 }
459 goto exit;
460 }
462 /* Return the object path for the newly created instance. */
463 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
464 CMSetNameSpace(objectpath, namespace);
465 CMReturnObjectPath(results, objectpath);
466 CMReturnDone(results);
468 exit:
469 /* Free the list of system resources. */
470 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
471 _SBLIM_TRACE(1,("--- _freeResources() failed"));
472 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
473 }
475 _SBLIM_RETURNSTATUS(status);
476 }
478 // ----------------------------------------------------------------------------
479 // DeleteInstance()
480 // Delete or remove the specified instance from the system.
481 // ----------------------------------------------------------------------------
482 static CMPIStatus DeleteInstance(
483 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
484 const CMPIContext * context, /* [in] Additional context info, if any. */
485 const CMPIResult * results, /* [out] Results of this operation. */
486 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
487 {
488 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
489 _RESOURCES * resources; /* Handle to the list of system resources. */
490 _RESOURCE * resource; /* Handle to the system resource. */
491 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
492 int found = 0; /* Found the target instance? */
494 _SBLIM_ENTER("DeleteInstance");
495 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
496 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
497 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
498 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
500 /* Get a handle to the list of system resources. */
501 if (!Xen_VirtualizationCapabilities_getResources(&resources)) {
502 _SBLIM_TRACE(1,("--- _getResources() failed"));
503 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
504 goto exit;
505 }
507 /* Get the target resource. */
508 found = Xen_VirtualizationCapabilities_getResourceForObjectPath(resources, &resource, reference);
509 if (!found || (resource == NULL)) {
510 _SBLIM_TRACE(1,("--- Target instance not found"));
511 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
512 goto exit;
513 }
515 _SBLIM_TRACE(2,("--- instance found", found));
517 /* Delete the target resource. */
518 int rc = Xen_VirtualizationCapabilities_deleteResource(resources, resource);
520 /* Free the resource data. */
521 if (!Xen_VirtualizationCapabilities_freeResource(resource)) {
522 _SBLIM_TRACE(1,("--- _freeResource() failed"));
523 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
524 goto exit;
525 }
527 if (rc != 1) {
528 if (rc == -1) {
529 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
530 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
531 } else {
532 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
533 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
534 }
535 goto exit;
536 }
538 exit:
539 /* Free the list of system resources. */
540 if (!Xen_VirtualizationCapabilities_freeResources(resources)) {
541 _SBLIM_TRACE(1,("--- _freeResources() failed"));
542 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
543 }
545 _SBLIM_RETURNSTATUS(status);
546 }
549 // ----------------------------------------------------------------------------
550 // ExecQuery()
551 // Return a list of all the instances that satisfy the specified query filter.
552 // ----------------------------------------------------------------------------
553 static CMPIStatus ExecQuery(
554 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
555 const CMPIContext * context, /* [in] Additional context info, if any. */
556 const CMPIResult * results, /* [out] Results of this operation. */
557 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
558 const char * language, /* [in] Name of the query language. */
559 const char * query) /* [in] Text of the query written in the query language. */
560 {
561 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
562 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
564 _SBLIM_ENTER("ExecQuery");
565 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
566 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
567 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
568 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
569 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
570 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
572 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
573 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
575 CMReturnDone(results);
577 exit:
578 _SBLIM_RETURNSTATUS(status);
579 }
581 // ----------------------------------------------------------------------------
582 // Initialize()
583 // Perform any necessary initialization immediately after this provider is
584 // first loaded.
585 // ----------------------------------------------------------------------------
586 static void Initialize(
587 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
588 const CMPIContext * context) /* [in] Additional context info, if any. */
589 {
590 _SBLIM_ENTER("Initialize");
591 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
592 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
594 /* Nothing needs to be done to initialize this provider */
595 _SBLIM_RETURN();
596 }
598 // ============================================================================
599 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
600 // ============================================================================
601 CMInstanceMIStub( , Xen_VirtualizationCapabilities, _BROKER, Initialize(&mi, ctx));