os-cmpi-xen

view src/Xen_OperatingSystem.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 7ca3bbf0810a
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 <string.h>
24 /* Include the required CMPI data types, function headers, and macros */
25 #include "cmpidt.h"
26 #include "cmpift.h"
27 #include "cmpimacs.h"
29 /* Include utility functions */
30 #include "cmpiutil.h"
32 /* Include _SBLIM_TRACE() logging support */
33 #include "cmpitrace.h"
35 /* Include Xen utilities */
36 #include "xen_utils.h"
38 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
39 #include "Xen_OperatingSystem_Resource.h"
42 // ----------------------------------------------------------------------------
43 // COMMON GLOBAL VARIABLES
44 // ----------------------------------------------------------------------------
46 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
47 static const CMPIBroker *_BROKER;
49 /* Xen session object. Initialize when the provider is loaded, close when
50 * provider unloaded. */
51 static xen_utils_session *session = NULL;
54 // ============================================================================
55 // CMPI INSTANCE PROVIDER FUNCTION TABLE
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // Info for the class supported by the instance provider
60 // ----------------------------------------------------------------------------
62 /* Name of the class implemented by this instance provider. */
63 /*** CUSTOMIZE FOR EACH PROVIDER ***/
64 static char * _CLASSNAME = "Xen_OperatingSystem";
66 /* NULL terminated list of key properties of this class. */
67 /*** CUSTOMIZE FOR EACH PROVIDER ***/
68 const static char * _KEYNAMES[] = {"CSName", "CSCreationClassName", "Name", "CreationClassName", NULL};
70 // ----------------------------------------------------------------------------
71 // Cleanup()
72 // Perform any necessary cleanup immediately before this provider is unloaded.
73 // ----------------------------------------------------------------------------
74 static CMPIStatus Cleanup(
75 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
76 const CMPIContext * context, /* [in] Additional context info, if any. */
77 CMPIBoolean terminating) /* [in] True if MB is terminating */
78 {
79 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
81 _SBLIM_ENTER("Cleanup");
82 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
83 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
85 if (session) {
86 xen_utils_xen_close(session);
87 session = NULL;
88 }
89 _SBLIM_RETURNSTATUS(status);
90 }
92 // ----------------------------------------------------------------------------
93 // EnumInstanceNames()
94 // Return a list of all the instances names (return their object paths only).
95 // ----------------------------------------------------------------------------
96 static CMPIStatus EnumInstanceNames(
97 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
98 const CMPIContext * context, /* [in] Additional context info, if any. */
99 const CMPIResult * results, /* [out] Results of this operation. */
100 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
101 {
102 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
103 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
104 _RESOURCE * resource; /* Handle to each system resource. */
105 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
106 int found = 0; /* Found any instances? */
108 _SBLIM_ENTER("EnumInstanceNames");
109 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
110 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
111 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
112 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
114 if (!xen_utils_validate_session(&session)) {
115 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
116 goto exit;
117 }
119 /* Get a handle to the list of system resources. */
120 if (!Xen_OperatingSystem_getResources(session, &resources)) {
121 _SBLIM_TRACE(1,("--- _getResources() failed"));
122 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
123 goto exit;
124 }
126 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
127 while (Xen_OperatingSystem_getNextResource(session, resources, &resource)) {
128 /* Create a new CMPIInstance to store this resource. */
129 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
130 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
131 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
132 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
133 goto exit;
134 }
136 /* Set the instance property values from the resource data. */
137 if (!Xen_OperatingSystem_setInstanceFromResource(session,resource, instance, _BROKER)) {
138 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
139 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
140 goto exit;
141 }
143 /* Free the resource data. */
144 if (!Xen_OperatingSystem_freeResource(resource)) {
145 _SBLIM_TRACE(1,("--- _freeResource() failed"));
146 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
147 goto exit;
148 }
150 /* Return the CMPIObjectPath for this instance. */
151 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
152 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
153 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
154 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
155 goto exit;
156 }
157 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
159 // _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
160 CMReturnObjectPath(results, objectpath);
161 found++;
162 }
164 _SBLIM_TRACE(2,("--- %d object paths found", found));
165 CMReturnDone(results);
167 exit:
168 /* Free the list of system resources. */
169 if (!Xen_OperatingSystem_freeResources(resources)) {
170 _SBLIM_TRACE(1,("--- _freeResources() failed"));
171 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
172 }
174 _SBLIM_RETURNSTATUS(status);
175 }
177 // ----------------------------------------------------------------------------
178 // EnumInstances()
179 // Return a list of all the instances (return all the instance data).
180 // ----------------------------------------------------------------------------
181 static CMPIStatus EnumInstances(
182 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
183 const CMPIContext * context, /* [in] Additional context info, if any. */
184 const CMPIResult * results, /* [out] Results of this operation. */
185 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
186 const char ** properties) /* [in] List of desired properties (NULL=all). */
187 {
188 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
189 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
190 _RESOURCE * resource; /* Handle to each system resource. */
191 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
192 int found = 0; /* Found any resource instances? */
194 _SBLIM_ENTER("EnumInstances");
195 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
196 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
197 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
198 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
200 if (!xen_utils_validate_session(&session)) {
201 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
202 goto exit;
203 }
205 /* Get a handle to the list of system resources. */
206 if (!Xen_OperatingSystem_getResources(session, &resources)) {
207 _SBLIM_TRACE(1,("--- _getResources() failed"));
208 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
209 goto exit;
210 }
212 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
213 while (Xen_OperatingSystem_getNextResource(session, resources, &resource)) {
214 /* Create a new CMPIInstance to store this resource. */
215 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
216 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
217 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
218 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
219 goto exit;
220 }
222 /* Setup a filter to only return the desired properties. */
223 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
224 if (status.rc != CMPI_RC_OK) {
225 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
226 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
227 goto exit;
228 }
230 /* Set the instance property values from the resource data. */
231 if (!Xen_OperatingSystem_setInstanceFromResource(session, resource, instance, _BROKER)) {
232 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
233 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
234 goto exit;
235 }
237 /* Free the resource data. */
238 if (!Xen_OperatingSystem_freeResource(resource)) {
239 _SBLIM_TRACE(1,("--- _freeResource() failed"));
240 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
241 goto exit;
242 }
244 /* Return the CMPIInstance for this instance. */
245 // _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
246 CMReturnInstance(results, instance);
247 found++;
248 }
250 _SBLIM_TRACE(2,("--- %d instances found", found));
251 CMReturnDone(results);
253 exit:
254 /* Free the list of system resources. */
255 if (!Xen_OperatingSystem_freeResources(resources)) {
256 _SBLIM_TRACE(1,("--- _freeResources() failed"));
257 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
258 }
260 _SBLIM_RETURNSTATUS(status);
261 }
263 // ----------------------------------------------------------------------------
264 // GetInstance()
265 // Return the instance data for the specified instance only.
266 // ----------------------------------------------------------------------------
267 static CMPIStatus GetInstance(
268 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
269 const CMPIContext * context, /* [in] Additional context info, if any. */
270 const CMPIResult * results, /* [out] Results of this operation. */
271 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
272 const char ** properties) /* [in] List of desired properties (NULL=all). */
273 {
274 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
275 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
276 _RESOURCE * resource; /* Handle to the system resource. */
277 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
278 int found = 0; /* Found the target instance? */
280 _SBLIM_ENTER("GetInstance");
281 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
282 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
283 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
284 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
286 if (!xen_utils_validate_session(&session)) {
287 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
288 goto exit;
289 }
291 /* Get a handle to the list of system resources. */
292 if (!Xen_OperatingSystem_getResources(session, &resources)) {
293 _SBLIM_TRACE(1,("--- _getResources() failed"));
294 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
295 goto exit;
296 }
298 /* Get the target resource. */
299 found = Xen_OperatingSystem_getResourceForObjectPath(session, resources, &resource, reference);
300 if (!found || (resource == NULL)) {
301 _SBLIM_TRACE(1,("--- Target instance not found"));
302 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
303 goto exit;
304 }
306 /* Create a new CMPIInstance to store this resource. */
307 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
308 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
309 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
310 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
311 goto exit;
312 }
314 /* Setup a filter to only return the desired properties. */
315 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
316 if (status.rc != CMPI_RC_OK) {
317 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
318 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
319 goto exit;
320 }
322 /* Set the instance property values from the resource data. */
323 if (!Xen_OperatingSystem_setInstanceFromResource(session,resource, instance, _BROKER)) {
324 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
325 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
326 goto exit;
327 }
329 /* Free the resource data. */
330 if (!Xen_OperatingSystem_freeResource(resource)) {
331 _SBLIM_TRACE(1,("--- _freeResource() failed"));
332 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
333 goto exit;
334 }
336 /* Return the CMPIInstance for this instance. */
337 // _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
338 CMReturnInstance(results, instance);
340 _SBLIM_TRACE(2,("--- instance found"));
341 CMReturnDone(results);
343 exit:
344 /* Free the list of system resources. */
345 if (!Xen_OperatingSystem_freeResources(resources)) {
346 _SBLIM_TRACE(1,("--- _freeResources() failed"));
347 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
348 }
350 _SBLIM_RETURNSTATUS(status);
351 }
353 // ----------------------------------------------------------------------------
354 // SetInstance()
355 // Save modified instance data for the specified instance.
356 // ----------------------------------------------------------------------------
357 static CMPIStatus SetInstance(
358 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
359 const CMPIContext * context, /* [in] Additional context info, if any. */
360 const CMPIResult * results, /* [out] Results of this operation. */
361 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
362 const CMPIInstance * newinstance, /* [in] Contains the new instance data. */
363 const char **properties)
364 {
365 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
366 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
367 _RESOURCE * resource; /* Handle to the system resource. */
368 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
369 int found = 0; /* Found the target instance? */
371 _SBLIM_ENTER("SetInstance");
372 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
373 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
374 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
375 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
376 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
378 if (!xen_utils_validate_session(&session)) {
379 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
380 goto exit;
381 }
383 /* Get a handle to the list of system resources. */
384 if (!Xen_OperatingSystem_getResources(session, &resources)) {
385 _SBLIM_TRACE(1,("--- _getResources() failed"));
386 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
387 goto exit;
388 }
390 /* Get the target resource. */
391 found = Xen_OperatingSystem_getResourceForObjectPath(session, resources, &resource, reference);
392 if (!found || (resource == NULL)) {
393 _SBLIM_TRACE(1,("--- Target instance not found"));
394 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
395 goto exit;
396 }
398 _SBLIM_TRACE(2,("--- instance found", found));
400 /* Update the target resource data with the new instance property values. */
401 int rc = Xen_OperatingSystem_setResourceFromInstance(resource, newinstance, _BROKER);
403 /* Free the resource data. */
404 if (!Xen_OperatingSystem_freeResource(resource)) {
405 _SBLIM_TRACE(1,("--- _freeResource() failed"));
406 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
407 goto exit;
408 }
410 if (rc != 1) {
411 if (rc == -1) {
412 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
413 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
414 } else {
415 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
416 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
417 }
418 goto exit;
419 }
421 exit:
422 /* Free the list of system resources. */
423 if (!Xen_OperatingSystem_freeResources(resources)) {
424 _SBLIM_TRACE(1,("--- _freeResources() failed"));
425 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
426 }
428 _SBLIM_RETURNSTATUS(status);
429 }
431 // ----------------------------------------------------------------------------
432 // CreateInstance()
433 // Create a new instance from the specified instance data.
434 // ----------------------------------------------------------------------------
435 static CMPIStatus CreateInstance(
436 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
437 const CMPIContext * context, /* [in] Additional context info, if any. */
438 const CMPIResult * results, /* [out] Results of this operation. */
439 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
440 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
441 {
442 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
443 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
444 _RESOURCE * resource; /* Handle to the system resource. */
445 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
446 int found = 0; /* Found the target instance? */
448 _SBLIM_ENTER("CreateInstance");
449 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
450 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
451 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
452 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
453 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
455 if (!xen_utils_validate_session(&session)) {
456 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
457 goto exit;
458 }
460 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
461 reference = CMGetObjectPath(newinstance, NULL);
463 /* Get a handle to the list of system resources. */
464 if (!Xen_OperatingSystem_getResources(session, &resources)) {
465 _SBLIM_TRACE(1,("--- _getResources() failed"));
466 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
467 goto exit;
468 }
470 /* Get the target resource. */
471 found = Xen_OperatingSystem_getResourceForObjectPath(session, resources, &resource, reference);
473 /* Free the resource data. */
474 if (!Xen_OperatingSystem_freeResource(resource)) {
475 _SBLIM_TRACE(1,("--- _freeResource() failed"));
476 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
477 goto exit;
478 }
480 if (found) {
481 _SBLIM_TRACE(1,("--- Target instance already exists"));
482 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
483 goto exit;
484 }
486 /* Create a new resource with the new instance property values. */
487 int rc = Xen_OperatingSystem_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
488 if (rc != 1) {
489 if (rc == -1) {
490 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
491 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
492 } else {
493 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
494 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
495 }
496 goto exit;
497 }
499 /* Return the object path for the newly created instance. */
500 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
501 CMSetNameSpace(objectpath, namespace);
502 CMReturnObjectPath(results, objectpath);
503 CMReturnDone(results);
505 exit:
506 /* Free the list of system resources. */
507 if (!Xen_OperatingSystem_freeResources(resources)) {
508 _SBLIM_TRACE(1,("--- _freeResources() failed"));
509 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
510 }
512 _SBLIM_RETURNSTATUS(status);
513 }
515 // ----------------------------------------------------------------------------
516 // DeleteInstance()
517 // Delete or remove the specified instance from the system.
518 // ----------------------------------------------------------------------------
519 static CMPIStatus DeleteInstance(
520 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
521 const CMPIContext * context, /* [in] Additional context info, if any. */
522 const CMPIResult * results, /* [out] Results of this operation. */
523 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
524 {
525 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
526 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
527 _RESOURCE * resource; /* Handle to the system resource. */
528 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
529 int found = 0; /* Found the target instance? */
531 _SBLIM_ENTER("DeleteInstance");
532 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
533 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
534 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
535 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
537 if (!xen_utils_validate_session(&session)) {
538 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
539 goto exit;
540 }
542 /* Get a handle to the list of system resources. */
543 if (!Xen_OperatingSystem_getResources(session, &resources)) {
544 _SBLIM_TRACE(1,("--- _getResources() failed"));
545 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
546 goto exit;
547 }
549 /* Get the target resource. */
550 found = Xen_OperatingSystem_getResourceForObjectPath(session, resources, &resource, reference);
551 if (!found || (resource == NULL)) {
552 _SBLIM_TRACE(1,("--- Target instance not found"));
553 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
554 goto exit;
555 }
557 _SBLIM_TRACE(2,("--- instance found", found));
559 /* Delete the target resource. */
560 int rc = Xen_OperatingSystem_deleteResource(resources, resource);
562 /* Free the resource data. */
563 if (!Xen_OperatingSystem_freeResource(resource)) {
564 _SBLIM_TRACE(1,("--- _freeResource() failed"));
565 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
566 goto exit;
567 }
569 if (rc != 1) {
570 if (rc == -1) {
571 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
572 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
573 } else {
574 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
575 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
576 }
577 goto exit;
578 }
580 exit:
581 /* Free the list of system resources. */
582 if (!Xen_OperatingSystem_freeResources(resources)) {
583 _SBLIM_TRACE(1,("--- _freeResources() failed"));
584 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
585 }
587 _SBLIM_RETURNSTATUS(status);
588 }
591 // ----------------------------------------------------------------------------
592 // ExecQuery()
593 // Return a list of all the instances that satisfy the specified query filter.
594 // ----------------------------------------------------------------------------
595 static CMPIStatus ExecQuery(
596 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
597 const CMPIContext * context, /* [in] Additional context info, if any. */
598 const CMPIResult * results, /* [out] Results of this operation. */
599 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
600 const char * language, /* [in] Name of the query language. */
601 const char * query) /* [in] Text of the query written in the query language. */
602 {
603 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
604 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
606 _SBLIM_ENTER("ExecQuery");
607 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
608 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
609 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
610 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
611 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
612 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
614 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
615 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
617 CMReturnDone(results);
619 exit:
620 _SBLIM_RETURNSTATUS(status);
621 }
623 // ----------------------------------------------------------------------------
624 // Initialize()
625 // Perform any necessary initialization immediately after this provider is
626 // first loaded.
627 // ----------------------------------------------------------------------------
628 static void InstInitialize(
629 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
630 const CMPIContext * context) /* [in] Additional context info, if any. */
631 {
632 _SBLIM_ENTER("InstInitialize");
633 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
634 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
636 /* Initialized Xen session object. */
637 if (session == NULL)
638 xen_utils_xen_init(&session);
640 _SBLIM_RETURN();
641 }
643 // ============================================================================
644 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
645 // ============================================================================
646 CMInstanceMIStub( , Xen_OperatingSystem, _BROKER, InstInitialize(&mi, ctx));
649 // ============================================================================
650 // CMPI METHOD PROVIDER FUNCTION TABLE
651 // ============================================================================
653 // ----------------------------------------------------------------------------
654 // MethodCleanup()
655 // Perform any necessary cleanup immediately before this provider is unloaded.
656 // ----------------------------------------------------------------------------
657 static CMPIStatus MethodCleanup(
658 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
659 const CMPIContext * context, /* [in] Additional context info, if any. */
660 CMPIBoolean terminating) /* [in] True if MB is terminating */
661 {
662 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
664 _SBLIM_ENTER("MethodCleanup");
665 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
666 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
668 if (session) {
669 xen_utils_xen_close(session);
670 session = NULL;
671 }
672 _SBLIM_RETURNSTATUS(status);
673 }
675 // ----------------------------------------------------------------------------
676 // InvokeMethod()
677 // Execute an extrinsic method on the specified instance.
678 // ----------------------------------------------------------------------------
679 static CMPIStatus InvokeMethod(
680 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self') */
681 const CMPIContext * context, /* [in] Additional context info, if any */
682 const CMPIResult * results, /* [out] Results of this operation */
683 const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */
684 const char * methodname, /* [in] Name of the method to apply against the reference object */
685 const CMPIArgs * argsin, /* [in] Method input arguments */
686 CMPIArgs * argsout) /* [in] Method output arguments */
687 {
688 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
689 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
690 _RESOURCE * resource; /* Handle to the system resource. */
691 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
692 int found = 0; /* Found the target instance? */
693 unsigned long rc = 0;
695 _SBLIM_ENTER("InvokeMethod");
696 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
697 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
698 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
699 _SBLIM_TRACE(2, ("--- methodname=\"%s\"", methodname));
700 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
702 if (!xen_utils_validate_session(&session)) {
703 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
704 goto exit;
705 }
707 /* Check that the method has the correct number of arguments. */
708 int argcount = CMGetArgCount(argsin, NULL);
709 _SBLIM_TRACE(2, ("--- # argsin=%d", argcount));
710 if (argcount != 0) {
711 _SBLIM_TRACE(1,("--- Incorrect number of method arguments"));
712 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Incorrect number of method arguments");
713 goto exit;
714 }
716 /* Get a handle to the list of system resources. */
717 if (!Xen_OperatingSystem_getResources(session, &resources)) {
718 _SBLIM_TRACE(1,("--- _getResources() failed"));
719 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
720 goto exit;
721 }
723 /* Get the target resource. */
724 found = Xen_OperatingSystem_getResourceForObjectPath(session, resources, &resource, reference);
725 if (!found || (resource == NULL)) {
726 _SBLIM_TRACE(1,("--- Target instance not found"));
727 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
728 goto exit;
729 }
731 _SBLIM_TRACE(2,("--- instance found", found));
733 /* Invoke the method on the target instance. */
734 rc = 1;
735 if (strcmp(methodname, "Reboot") == 0) {
736 if (xen_vm_clean_reboot(session->xen, resource->handle) != 0) {
737 _SBLIM_TRACE(1, ("--- xen_vm_clean_reboot() failed"));
738 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to reboot VirtualSystem");
739 rc = 0;
740 }
741 }
742 else {
743 _SBLIM_TRACE(1, ("--- Unrecognized method name - \"%s\"", methodname));
744 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_FOUND, "Unrecognized method name");
745 rc = 0;
746 }
748 /* Free the resource data. */
749 if (!Xen_OperatingSystem_freeResource(resource)) {
750 _SBLIM_TRACE(1,("--- _freeResource() failed"));
751 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
752 goto exit;
753 }
755 CMReturnData(results, (CMPIValue *)&rc, CMPI_uint32);
756 CMReturnDone(results);
758 exit:
759 /* Free the list of system resources. */
760 if (!Xen_OperatingSystem_freeResources(resources)) {
761 _SBLIM_TRACE(1,("--- _freeResources() failed"));
762 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
763 }
765 _SBLIM_RETURNSTATUS(status);
766 }
768 // ----------------------------------------------------------------------------
769 // MethodInitialize()
770 // Perform any necessary initialization immediately after the method provider
771 // is first loaded.
772 // ----------------------------------------------------------------------------
773 static void MethodInitialize(
774 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
775 const CMPIContext * context) /* [in] Additional context info, if any. */
776 {
777 _SBLIM_ENTER("MethodInitialize");
778 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
779 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
781 /* Initialized Xen session object. */
782 if (session == NULL)
783 xen_utils_xen_init(&session);
785 _SBLIM_RETURN();
786 }
789 // ============================================================================
790 // CMPI METHOD PROVIDER FUNCTION TABLE SETUP
791 // ============================================================================
792 CMMethodMIStub( , Xen_OperatingSystem, _BROKER, MethodInitialize(&mi, ctx));