os-cmpi-xen

view src/Xen_Console.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 a11f71a8dc62
children 3a6f2019ef11
line source
1 // Copyright (C) 2006 Unisys 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: Rajagopalan Subrahmanian, <raj.subrahmanian@unisys.com>
18 // Contributors:
19 // Description: This file
20 // ============================================================================
22 /* Include the required CMPI data types, function headers, and macros */
23 #include "cmpidt.h"
24 #include "cmpift.h"
25 #include "cmpimacs.h"
27 /* Include utility functions */
28 #include "cmpiutil.h"
30 /* Include _SBLIM_TRACE() logging support */
31 #include "cmpitrace.h"
33 /* Include Xen utilities */
34 #include "xen_utils.h"
36 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
37 #include "Xen_Console_Resource.h"
40 // ----------------------------------------------------------------------------
41 // COMMON GLOBAL VARIABLES
42 // ----------------------------------------------------------------------------
44 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
45 static const CMPIBroker *_BROKER;
47 /* Xen session object. Initialize when the provider is loaded, close when
48 * provider unloaded. */
49 static xen_utils_session *session = NULL;
52 // ============================================================================
53 // CMPI INSTANCE PROVIDER FUNCTION TABLE
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // Info for the class supported by the instance provider
58 // ----------------------------------------------------------------------------
60 /* Name of the class implemented by this instance provider. */
61 /*** CUSTOMIZE FOR EACH PROVIDER ***/
62 static char * _CLASSNAME = "Xen_Console";
64 /* NULL terminated list of key properties of this class. */
65 /*** CUSTOMIZE FOR EACH PROVIDER ***/
66 const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL};
68 // ----------------------------------------------------------------------------
69 // Cleanup()
70 // Perform any necessary cleanup immediately before this provider is unloaded.
71 // ----------------------------------------------------------------------------
72 static CMPIStatus Cleanup(
73 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
74 const CMPIContext * context, /* [in] Additional context info, if any. */
75 CMPIBoolean terminating) /* [in] True if MB is terminating */
76 {
77 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
79 _SBLIM_ENTER("Cleanup");
80 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
81 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
83 if (session) {
84 xen_utils_xen_close(session);
85 session = NULL;
86 }
87 _SBLIM_RETURNSTATUS(status);
88 }
90 // ----------------------------------------------------------------------------
91 // EnumInstanceNames()
92 // Return a list of all the instances names (return their object paths only).
93 // ----------------------------------------------------------------------------
94 static CMPIStatus EnumInstanceNames(
95 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
96 const CMPIContext * context, /* [in] Additional context info, if any. */
97 const CMPIResult * results, /* [out] Results of this operation. */
98 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
99 {
100 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
101 _RESOURCES * resources; /* Handle to the list of system resources. */
102 _RESOURCE * resource; /* Handle to each system resource. */
103 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
104 int found = 0; /* Found any instances? */
106 _SBLIM_ENTER("EnumInstanceNames");
107 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
108 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
109 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
110 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
112 if (!xen_utils_validate_session(&session)) {
113 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
114 goto exit;
115 }
117 /* Get a handle to the list of system resources. */
118 if (!Xen_Console_getResources(session, &resources)) {
119 _SBLIM_TRACE(1,("--- _getResources() failed"));
120 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
121 goto exit;
122 }
124 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
125 while (Xen_Console_getNextResource(session, resources, &resource)) {
126 /* Create a new CMPIInstance to store this resource. */
127 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
128 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
129 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
130 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
131 goto exit;
132 }
134 /* Set the instance property values from the resource data. */
135 if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) {
136 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
137 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
138 goto exit;
139 }
141 /* Free the resource data. */
142 if (!Xen_Console_freeResource(resource)) {
143 _SBLIM_TRACE(1,("--- _freeResource() failed"));
144 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
145 goto exit;
146 }
148 /* Return the CMPIObjectPath for this instance. */
149 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
150 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
151 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
152 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
153 goto exit;
154 }
155 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
157 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
158 CMReturnObjectPath(results, objectpath);
159 found++;
160 }
162 _SBLIM_TRACE(2,("--- %d object paths found", found));
163 CMReturnDone(results);
165 exit:
166 /* Free the list of system resources. */
167 if (!Xen_Console_freeResources(resources)) {
168 _SBLIM_TRACE(1,("--- _freeResources() failed"));
169 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
170 }
172 _SBLIM_RETURNSTATUS(status);
173 }
175 // ----------------------------------------------------------------------------
176 // EnumInstances()
177 // Return a list of all the instances (return all the instance data).
178 // ----------------------------------------------------------------------------
179 static CMPIStatus EnumInstances(
180 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
181 const CMPIContext * context, /* [in] Additional context info, if any. */
182 const CMPIResult * results, /* [out] Results of this operation. */
183 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
184 const char ** properties) /* [in] List of desired properties (NULL=all). */
185 {
186 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
187 _RESOURCES * resources; /* Handle to the list of system resources. */
188 _RESOURCE * resource; /* Handle to each system resource. */
189 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
190 int found = 0; /* Found any resource instances? */
192 _SBLIM_ENTER("EnumInstances");
193 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
194 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
195 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
196 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
198 if (!xen_utils_validate_session(&session)) {
199 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
200 goto exit;
201 }
203 /* Get a handle to the list of system resources. */
204 if (!Xen_Console_getResources(session, &resources)) {
205 _SBLIM_TRACE(1,("--- _getResources() failed"));
206 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
207 goto exit;
208 }
210 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
211 while (Xen_Console_getNextResource(session, resources, &resource)) {
212 /* Create a new CMPIInstance to store this resource. */
213 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
214 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
215 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
216 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
217 goto exit;
218 }
220 /* Setup a filter to only return the desired properties. */
221 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
222 if (status.rc != CMPI_RC_OK) {
223 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
224 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
225 goto exit;
226 }
228 /* Set the instance property values from the resource data. */
229 if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) {
230 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
231 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
232 goto exit;
233 }
235 /* Free the resource data. */
236 if (!Xen_Console_freeResource(resource)) {
237 _SBLIM_TRACE(1,("--- _freeResource() failed"));
238 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
239 goto exit;
240 }
242 /* Return the CMPIInstance for this instance. */
243 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
244 CMReturnInstance(results, instance);
245 found++;
246 }
248 _SBLIM_TRACE(2,("--- %d instances found", found));
249 CMReturnDone(results);
251 exit:
252 /* Free the list of system resources. */
253 if (!Xen_Console_freeResources(resources)) {
254 _SBLIM_TRACE(1,("--- _freeResources() failed"));
255 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
256 }
258 _SBLIM_RETURNSTATUS(status);
259 }
261 // ----------------------------------------------------------------------------
262 // GetInstance()
263 // Return the instance data for the specified instance only.
264 // ----------------------------------------------------------------------------
265 static CMPIStatus GetInstance(
266 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
267 const CMPIContext * context, /* [in] Additional context info, if any. */
268 const CMPIResult * results, /* [out] Results of this operation. */
269 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
270 const char ** properties) /* [in] List of desired properties (NULL=all). */
271 {
272 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
273 _RESOURCES * resources; /* Handle to the list of system resources. */
274 _RESOURCE * resource; /* Handle to the system resource. */
275 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
276 int found = 0; /* Found the target instance? */
278 _SBLIM_ENTER("GetInstance");
279 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
280 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
281 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
282 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
284 if (!xen_utils_validate_session(&session)) {
285 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
286 goto exit;
287 }
289 /* Get a handle to the list of system resources. */
290 if (!Xen_Console_getResources(session, &resources)) {
291 _SBLIM_TRACE(1,("--- _getResources() failed"));
292 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
293 goto exit;
294 }
296 /* Get the target resource. */
297 found = Xen_Console_getResourceForObjectPath(session, &resource, reference);
298 if (!found || (resource == NULL)) {
299 _SBLIM_TRACE(1,("--- Target instance not found"));
300 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
301 goto exit;
302 }
304 /* Create a new CMPIInstance to store this resource. */
305 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
306 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
307 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
308 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
309 goto exit;
310 }
312 /* Setup a filter to only return the desired properties. */
313 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
314 if (status.rc != CMPI_RC_OK) {
315 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
316 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
317 goto exit;
318 }
320 /* Set the instance property values from the resource data. */
321 if (!Xen_Console_setInstanceFromResource(session, resource, instance, _BROKER)) {
322 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
323 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
324 goto exit;
325 }
327 /* Free the resource data. */
328 if (!Xen_Console_freeResource(resource)) {
329 _SBLIM_TRACE(1,("--- _freeResource() failed"));
330 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
331 goto exit;
332 }
334 /* Return the CMPIInstance for this instance. */
335 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
336 CMReturnInstance(results, instance);
338 _SBLIM_TRACE(2,("--- instance found"));
339 CMReturnDone(results);
341 exit:
342 /* Free the list of system resources. */
343 if (!Xen_Console_freeResources(resources)) {
344 _SBLIM_TRACE(1,("--- _freeResources() failed"));
345 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
346 }
348 _SBLIM_RETURNSTATUS(status);
349 }
351 // ----------------------------------------------------------------------------
352 // SetInstance()
353 // Save modified instance data for the specified instance.
354 // ----------------------------------------------------------------------------
355 static CMPIStatus SetInstance(
356 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
357 const CMPIContext * context, /* [in] Additional context info, if any. */
358 const CMPIResult * results, /* [out] Results of this operation. */
359 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
360 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
361 const char **properties)
362 {
363 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
364 _RESOURCES * resources; /* Handle to the list of system resources. */
365 _RESOURCE * resource; /* Handle to the system resource. */
366 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
367 int found = 0; /* Found the target instance? */
369 _SBLIM_ENTER("SetInstance");
370 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
371 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
372 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
373 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
374 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
376 if (!xen_utils_validate_session(&session)) {
377 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
378 goto exit;
379 }
381 /* Get a handle to the list of system resources. */
382 if (!Xen_Console_getResources(session, &resources)) {
383 _SBLIM_TRACE(1,("--- _getResources() failed"));
384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
385 goto exit;
386 }
388 /* Get the target resource. */
389 found = Xen_Console_getResourceForObjectPath(session, &resource, reference);
390 if (!found || (resource == NULL)) {
391 _SBLIM_TRACE(1,("--- Target instance not found"));
392 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
393 goto exit;
394 }
396 _SBLIM_TRACE(2,("--- instance found", found));
398 /* Update the target resource data with the new instance property values. */
399 int rc = Xen_Console_setResourceFromInstance(resource, newinstance, _BROKER);
401 /* Free the resource data. */
402 if (!Xen_Console_freeResource(resource)) {
403 _SBLIM_TRACE(1,("--- _freeResource() failed"));
404 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
405 goto exit;
406 }
408 if (rc != 1) {
409 if (rc == -1) {
410 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
411 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
412 } else {
413 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
414 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
415 }
416 goto exit;
417 }
419 exit:
420 /* Free the list of system resources. */
421 if (!Xen_Console_freeResources(resources)) {
422 _SBLIM_TRACE(1,("--- _freeResources() failed"));
423 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
424 }
426 _SBLIM_RETURNSTATUS(status);
427 }
429 // ----------------------------------------------------------------------------
430 // CreateInstance()
431 // Create a new instance from the specified instance data.
432 // ----------------------------------------------------------------------------
433 static CMPIStatus CreateInstance(
434 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
435 const CMPIContext * context, /* [in] Additional context info, if any. */
436 const CMPIResult * results, /* [out] Results of this operation. */
437 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
438 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
439 {
440 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
441 _RESOURCES * resources; /* Handle to the list of system resources. */
442 _RESOURCE * resource; /* Handle to the system resource. */
443 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
444 int found = 0; /* Found the target instance? */
446 _SBLIM_ENTER("CreateInstance");
447 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
448 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
449 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
450 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
451 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
453 if (!xen_utils_validate_session(&session)) {
454 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
455 goto exit;
456 }
458 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
459 reference = CMGetObjectPath(newinstance, NULL);
461 /* Get a handle to the list of system resources. */
462 if (!Xen_Console_getResources(session, &resources)) {
463 _SBLIM_TRACE(1,("--- _getResources() failed"));
464 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
465 goto exit;
466 }
468 /* Get the target resource. */
469 found = Xen_Console_getResourceForObjectPath(session, &resource, reference);
471 /* Free the resource data. */
472 if (!Xen_Console_freeResource(resource)) {
473 _SBLIM_TRACE(1,("--- _freeResource() failed"));
474 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
475 goto exit;
476 }
478 if (found) {
479 _SBLIM_TRACE(1,("--- Target instance already exists"));
480 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
481 goto exit;
482 }
484 /* Create a new resource with the new instance property values. */
485 int rc = Xen_Console_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
486 if (rc != 1) {
487 if (rc == -1) {
488 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
489 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
490 } else {
491 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
492 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
493 }
494 goto exit;
495 }
497 /* Return the object path for the newly created instance. */
498 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
499 CMSetNameSpace(objectpath, namespace);
500 CMReturnObjectPath(results, objectpath);
501 CMReturnDone(results);
503 exit:
504 /* Free the list of system resources. */
505 if (!Xen_Console_freeResources(resources)) {
506 _SBLIM_TRACE(1,("--- _freeResources() failed"));
507 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
508 }
510 _SBLIM_RETURNSTATUS(status);
511 }
513 // ----------------------------------------------------------------------------
514 // DeleteInstance()
515 // Delete or remove the specified instance from the system.
516 // ----------------------------------------------------------------------------
517 static CMPIStatus DeleteInstance(
518 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
519 const CMPIContext * context, /* [in] Additional context info, if any. */
520 const CMPIResult * results, /* [out] Results of this operation. */
521 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
522 {
523 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
524 _RESOURCES * resources; /* Handle to the list of system resources. */
525 _RESOURCE * resource; /* Handle to the system resource. */
526 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
527 int found = 0; /* Found the target instance? */
529 _SBLIM_ENTER("DeleteInstance");
530 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
531 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
532 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
533 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
535 if (!xen_utils_validate_session(&session)) {
536 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
537 goto exit;
538 }
540 /* Get a handle to the list of system resources. */
541 if (!Xen_Console_getResources(session, &resources)) {
542 _SBLIM_TRACE(1,("--- _getResources() failed"));
543 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
544 goto exit;
545 }
547 /* Get the target resource. */
548 found = Xen_Console_getResourceForObjectPath(session, &resource, reference);
549 if (!found || (resource == NULL)) {
550 _SBLIM_TRACE(1,("--- Target instance not found"));
551 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
552 goto exit;
553 }
555 _SBLIM_TRACE(2,("--- instance found", found));
557 /* Delete the target resource. */
558 int rc = Xen_Console_deleteResource(resources, resource);
560 /* Free the resource data. */
561 if (!Xen_Console_freeResource(resource)) {
562 _SBLIM_TRACE(1,("--- _freeResource() failed"));
563 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
564 goto exit;
565 }
567 if (rc != 1) {
568 if (rc == -1) {
569 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
570 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
571 } else {
572 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
573 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
574 }
575 goto exit;
576 }
578 exit:
579 /* Free the list of system resources. */
580 if (!Xen_Console_freeResources(resources)) {
581 _SBLIM_TRACE(1,("--- _freeResources() failed"));
582 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
583 }
585 _SBLIM_RETURNSTATUS(status);
586 }
589 // ----------------------------------------------------------------------------
590 // ExecQuery()
591 // Return a list of all the instances that satisfy the specified query filter.
592 // ----------------------------------------------------------------------------
593 static CMPIStatus ExecQuery(
594 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
595 const CMPIContext * context, /* [in] Additional context info, if any. */
596 const CMPIResult * results, /* [out] Results of this operation. */
597 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
598 const char * language, /* [in] Name of the query language. */
599 const char * query) /* [in] Text of the query written in the query language. */
600 {
601 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
602 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
604 _SBLIM_ENTER("ExecQuery");
605 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
606 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
607 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
608 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
609 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
610 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
612 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
613 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
615 CMReturnDone(results);
617 exit:
618 _SBLIM_RETURNSTATUS(status);
619 }
621 // ----------------------------------------------------------------------------
622 // Initialize()
623 // Perform any necessary initialization immediately after this provider is
624 // first loaded.
625 // ----------------------------------------------------------------------------
626 static void Initialize(
627 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
628 const CMPIContext * context) /* [in] Additional context info, if any. */
629 {
630 _SBLIM_ENTER("Initialize");
631 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
632 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
634 /* Initialized Xen session object. */
635 if (session == NULL)
636 xen_utils_xen_init(&session);
638 _SBLIM_RETURN();
639 }
641 // ============================================================================
642 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
643 // ============================================================================
644 CMInstanceMIStub( , Xen_Console, _BROKER, Initialize(&mi, ctx));