os-cmpi-xen

view src/Xen_ProcessorPool.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 75b18359b74d
children 26f10941718e
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 // Jim Fehlig, <jfehlig@novell.com>
19 // Contributors:
20 // Description:
21 // ============================================================================
23 #include <string.h>
25 /* Include the required CMPI data types, function headers, and macros */
26 #include "cmpidt.h"
27 #include "cmpift.h"
28 #include "cmpimacs.h"
30 #include "provider_common.h"
32 // ----------------------------------------------------------------------------
33 // COMMON GLOBAL VARIABLES
34 // ----------------------------------------------------------------------------
36 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
37 static const CMPIBroker *_BROKER;
39 /* Include utility functions */
40 #include "cmpiutil.h"
42 /* Include _SBLIM_TRACE() logging support */
43 #include "cmpitrace.h"
45 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
46 #include "Xen_ProcessorPool_Resource.h"
49 // ============================================================================
50 // CMPI INSTANCE PROVIDER FUNCTION TABLE
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // Info for the class supported by the instance provider
55 // ----------------------------------------------------------------------------
57 /* Name of the class implemented by this instance provider. */
58 /*** CUSTOMIZE FOR EACH PROVIDER ***/
59 static char * _CLASSNAME = "Xen_ProcessorPool";
61 /* NULL terminated list of key properties of this class. */
62 /*** CUSTOMIZE FOR EACH PROVIDER ***/
63 const static char * _KEYNAMES[] = {"InstanceID", NULL};
65 // ----------------------------------------------------------------------------
66 // Cleanup()
67 // Perform any necessary cleanup immediately before this provider is unloaded.
68 // ----------------------------------------------------------------------------
69 static CMPIStatus Cleanup(
70 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
71 const CMPIContext * context, /* [in] Additional context info, if any. */
72 CMPIBoolean terminating) /* [in] True if MB is terminating */
73 {
74 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
76 _SBLIM_ENTER("Cleanup");
77 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
78 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
80 /* Nothing needs to be done for cleanup. */
81 _SBLIM_RETURNSTATUS(status);
82 }
84 // ----------------------------------------------------------------------------
85 // EnumInstanceNames()
86 // Return a list of all the instances names (return their object paths only).
87 // ----------------------------------------------------------------------------
88 static CMPIStatus EnumInstanceNames(
89 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
90 const CMPIContext * context, /* [in] Additional context info, if any. */
91 const CMPIResult * results, /* [out] Results of this operation. */
92 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
93 {
94 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
95 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
96 _RESOURCE * resource; /* Handle to each system resource. */
97 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
98 int found = 0; /* Found any instances? */
100 _SBLIM_ENTER("EnumInstanceNames");
101 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
102 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
103 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
104 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
106 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
107 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
108 goto exit;
109 }
111 /* Get a handle to the list of system resources. */
112 if (!Xen_ProcessorPool_getResources(&resources)) {
113 _SBLIM_TRACE(1,("--- _getResources() failed"));
114 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
115 goto exit;
116 }
118 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
119 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
120 /* Create a new CMPIInstance to store this resource. */
121 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
122 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
123 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
124 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
125 goto exit;
126 }
128 /* Set the instance property values from the resource data. */
129 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
130 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
131 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
132 goto exit;
133 }
135 /* Free the resource data. */
136 if (!Xen_ProcessorPool_freeResource(resource)) {
137 _SBLIM_TRACE(1,("--- _freeResource() failed"));
138 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
139 goto exit;
140 }
142 /* Return the CMPIObjectPath for this instance. */
143 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
144 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
145 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
146 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
147 goto exit;
148 }
149 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
151 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
152 CMReturnObjectPath(results, objectpath);
153 found++;
154 }
156 _SBLIM_TRACE(2,("--- %d object paths found", found));
157 CMReturnDone(results);
159 exit:
160 /* Free the list of system resources. */
161 if (!Xen_ProcessorPool_freeResources(resources)) {
162 _SBLIM_TRACE(1,("--- _freeResources() failed"));
163 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
164 }
166 _SBLIM_RETURNSTATUS(status);
167 }
169 // ----------------------------------------------------------------------------
170 // EnumInstances()
171 // Return a list of all the instances (return all the instance data).
172 // ----------------------------------------------------------------------------
173 static CMPIStatus EnumInstances(
174 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
175 const CMPIContext * context, /* [in] Additional context info, if any. */
176 const CMPIResult * results, /* [out] Results of this operation. */
177 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
178 const char ** properties) /* [in] List of desired properties (NULL=all). */
179 {
180 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
181 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
182 _RESOURCE * resource; /* Handle to each system resource. */
183 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
184 int found = 0; /* Found any resource instances? */
186 _SBLIM_ENTER("EnumInstances");
187 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
188 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
189 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
190 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
192 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
193 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
194 goto exit;
195 }
197 /* Get a handle to the list of system resources. */
198 if (!Xen_ProcessorPool_getResources(&resources)) {
199 _SBLIM_TRACE(1,("--- _getResources() failed"));
200 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
201 goto exit;
202 }
204 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
205 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
206 /* Create a new CMPIInstance to store this resource. */
207 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
208 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
209 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
210 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
211 goto exit;
212 }
214 /* Setup a filter to only return the desired properties. */
215 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
216 if (status.rc != CMPI_RC_OK) {
217 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
218 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
219 goto exit;
220 }
222 /* Set the instance property values from the resource data. */
223 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
224 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
225 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
226 goto exit;
227 }
229 /* Free the resource data. */
230 if (!Xen_ProcessorPool_freeResource(resource)) {
231 _SBLIM_TRACE(1,("--- _freeResource() failed"));
232 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
233 goto exit;
234 }
236 /* Return the CMPIInstance for this instance. */
237 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
238 CMReturnInstance(results, instance);
239 found++;
240 }
242 _SBLIM_TRACE(2,("--- %d instances found", found));
243 CMReturnDone(results);
245 exit:
246 /* Free the list of system resources. */
247 if (!Xen_ProcessorPool_freeResources(resources)) {
248 _SBLIM_TRACE(1,("--- _freeResources() failed"));
249 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
250 }
252 _SBLIM_RETURNSTATUS(status);
253 }
255 // ----------------------------------------------------------------------------
256 // GetInstance()
257 // Return the instance data for the specified instance only.
258 // ----------------------------------------------------------------------------
259 static CMPIStatus GetInstance(
260 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
261 const CMPIContext * context, /* [in] Additional context info, if any. */
262 const CMPIResult * results, /* [out] Results of this operation. */
263 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
264 const char ** properties) /* [in] List of desired properties (NULL=all). */
265 {
266 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
267 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
268 _RESOURCE * resource; /* Handle to the system resource. */
269 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
270 int found = 0; /* Found the target instance? */
272 _SBLIM_ENTER("GetInstance");
273 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
274 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
275 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
276 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
278 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
279 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
280 goto exit;
281 }
283 /* Get a handle to the list of system resources. */
284 if (!Xen_ProcessorPool_getResources(&resources)) {
285 _SBLIM_TRACE(1,("--- _getResources() failed"));
286 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
287 goto exit;
288 }
290 /* Get the target resource. */
291 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
292 if (!found || (resource == NULL)) {
293 _SBLIM_TRACE(1,("--- Target instance not found"));
294 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
295 goto exit;
296 }
298 /* Create a new CMPIInstance to store this resource. */
299 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
300 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
301 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
302 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
303 goto exit;
304 }
306 /* Setup a filter to only return the desired properties. */
307 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
308 if (status.rc != CMPI_RC_OK) {
309 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
310 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
311 goto exit;
312 }
314 /* Set the instance property values from the resource data. */
315 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
316 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
317 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
318 goto exit;
319 }
321 /* Free the resource data. */
322 if (!Xen_ProcessorPool_freeResource(resource)) {
323 _SBLIM_TRACE(1,("--- _freeResource() failed"));
324 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
325 goto exit;
326 }
328 /* Return the CMPIInstance for this instance. */
329 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
330 CMReturnInstance(results, instance);
332 _SBLIM_TRACE(2,("--- instance found"));
333 CMReturnDone(results);
335 exit:
336 /* Free the list of system resources. */
337 if (!Xen_ProcessorPool_freeResources(resources)) {
338 _SBLIM_TRACE(1,("--- _freeResources() failed"));
339 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
340 }
342 _SBLIM_RETURNSTATUS(status);
343 }
345 // ----------------------------------------------------------------------------
346 // SetInstance()
347 // Save modified instance data for the specified instance.
348 // ----------------------------------------------------------------------------
349 static CMPIStatus SetInstance(
350 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
351 const CMPIContext * context, /* [in] Additional context info, if any. */
352 const CMPIResult * results, /* [out] Results of this operation. */
353 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
354 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
355 const char **properties)
356 {
357 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
358 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
359 _RESOURCE * resource; /* Handle to the system resource. */
360 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
361 int found = 0; /* Found the target instance? */
363 _SBLIM_ENTER("SetInstance");
364 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
365 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
366 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
367 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
368 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
370 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
371 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
372 goto exit;
373 }
375 /* Get a handle to the list of system resources. */
376 if (!Xen_ProcessorPool_getResources(&resources)) {
377 _SBLIM_TRACE(1,("--- _getResources() failed"));
378 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
379 goto exit;
380 }
382 /* Get the target resource. */
383 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
384 if (!found || (resource == NULL)) {
385 _SBLIM_TRACE(1,("--- Target instance not found"));
386 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
387 goto exit;
388 }
390 _SBLIM_TRACE(2,("--- instance found", found));
392 /* Update the target resource data with the new instance property values. */
393 int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER);
395 /* Free the resource data. */
396 if (!Xen_ProcessorPool_freeResource(resource)) {
397 _SBLIM_TRACE(1,("--- _freeResource() failed"));
398 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
399 goto exit;
400 }
402 if (rc != 1) {
403 if (rc == -1) {
404 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
405 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
406 } else {
407 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
408 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
409 }
410 goto exit;
411 }
413 exit:
414 /* Free the list of system resources. */
415 if (!Xen_ProcessorPool_freeResources(resources)) {
416 _SBLIM_TRACE(1,("--- _freeResources() failed"));
417 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
418 }
420 _SBLIM_RETURNSTATUS(status);
421 }
423 // ----------------------------------------------------------------------------
424 // CreateInstance()
425 // Create a new instance from the specified instance data.
426 // ----------------------------------------------------------------------------
427 static CMPIStatus CreateInstance(
428 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
429 const CMPIContext * context, /* [in] Additional context info, if any. */
430 const CMPIResult * results, /* [out] Results of this operation. */
431 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
432 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
433 {
434 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
435 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
436 _RESOURCE * resource; /* Handle to the system resource. */
437 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
438 int found = 0; /* Found the target instance? */
440 _SBLIM_ENTER("CreateInstance");
441 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
442 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
443 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
444 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
445 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
447 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
448 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
449 goto exit;
450 }
452 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
453 reference = CMGetObjectPath(newinstance, NULL);
455 /* Get a handle to the list of system resources. */
456 if (!Xen_ProcessorPool_getResources(&resources)) {
457 _SBLIM_TRACE(1,("--- _getResources() failed"));
458 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
459 goto exit;
460 }
462 /* Get the target resource. */
463 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
465 /* Free the resource data. */
466 if (!Xen_ProcessorPool_freeResource(resource)) {
467 _SBLIM_TRACE(1,("--- _freeResource() failed"));
468 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
469 goto exit;
470 }
472 if (found) {
473 _SBLIM_TRACE(1,("--- Target instance already exists"));
474 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
475 goto exit;
476 }
478 /* Create a new resource with the new instance property values. */
479 int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
480 if (rc != 1) {
481 if (rc == -1) {
482 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
483 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
484 } else {
485 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
486 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
487 }
488 goto exit;
489 }
491 /* Return the object path for the newly created instance. */
492 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
493 CMSetNameSpace(objectpath, namespace);
494 CMReturnObjectPath(results, objectpath);
495 CMReturnDone(results);
497 exit:
498 /* Free the list of system resources. */
499 if (!Xen_ProcessorPool_freeResources(resources)) {
500 _SBLIM_TRACE(1,("--- _freeResources() failed"));
501 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
502 }
504 _SBLIM_RETURNSTATUS(status);
505 }
507 // ----------------------------------------------------------------------------
508 // DeleteInstance()
509 // Delete or remove the specified instance from the system.
510 // ----------------------------------------------------------------------------
511 static CMPIStatus DeleteInstance(
512 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
513 const CMPIContext * context, /* [in] Additional context info, if any. */
514 const CMPIResult * results, /* [out] Results of this operation. */
515 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
516 {
517 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
518 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
519 _RESOURCE * resource; /* Handle to the system resource. */
520 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
521 int found = 0; /* Found the target instance? */
523 _SBLIM_ENTER("DeleteInstance");
524 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
525 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
526 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
527 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
529 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
530 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
531 goto exit;
532 }
534 /* Get a handle to the list of system resources. */
535 if (!Xen_ProcessorPool_getResources(&resources)) {
536 _SBLIM_TRACE(1,("--- _getResources() failed"));
537 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
538 goto exit;
539 }
541 /* Get the target resource. */
542 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
543 if (!found || (resource == NULL)) {
544 _SBLIM_TRACE(1,("--- Target instance not found"));
545 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
546 goto exit;
547 }
549 _SBLIM_TRACE(2,("--- instance found", found));
551 /* Delete the target resource. */
552 int rc = Xen_ProcessorPool_deleteResource(resources, resource);
554 /* Free the resource data. */
555 if (!Xen_ProcessorPool_freeResource(resource)) {
556 _SBLIM_TRACE(1,("--- _freeResource() failed"));
557 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
558 goto exit;
559 }
561 if (rc != 1) {
562 if (rc == -1) {
563 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
564 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
565 } else {
566 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
567 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
568 }
569 goto exit;
570 }
572 exit:
573 /* Free the list of system resources. */
574 if (!Xen_ProcessorPool_freeResources(resources)) {
575 _SBLIM_TRACE(1,("--- _freeResources() failed"));
576 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
577 }
579 _SBLIM_RETURNSTATUS(status);
580 }
583 // ----------------------------------------------------------------------------
584 // ExecQuery()
585 // Return a list of all the instances that satisfy the specified query filter.
586 // ----------------------------------------------------------------------------
587 static CMPIStatus ExecQuery(
588 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
589 const CMPIContext * context, /* [in] Additional context info, if any. */
590 const CMPIResult * results, /* [out] Results of this operation. */
591 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
592 const char * language, /* [in] Name of the query language. */
593 const char * query) /* [in] Text of the query written in the query language. */
594 {
595 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
596 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
598 _SBLIM_ENTER("ExecQuery");
599 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
600 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
601 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
602 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
603 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
604 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
606 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
607 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
608 goto exit;
609 }
611 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
612 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
614 CMReturnDone(results);
616 exit:
617 _SBLIM_RETURNSTATUS(status);
618 }
620 // ----------------------------------------------------------------------------
621 // Initialize()
622 // Perform any necessary initialization immediately after this provider is
623 // first loaded.
624 // ----------------------------------------------------------------------------
625 static void Initialize(
626 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
627 const CMPIContext * context) /* [in] Additional context info, if any. */
628 {
629 _SBLIM_ENTER("Initialize");
630 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
631 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
633 /* Nothing needs to be done to initialize this provider */
634 _SBLIM_RETURN();
635 }
637 // ============================================================================
638 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
639 // ============================================================================
640 CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));