os-cmpi-xen

view src/Xen_ComputerSystem.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 e717d287cf85
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 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
19 // Contributors: Jim Fehlig, <jfehlig@novell.com>
20 // Description:
21 // ============================================================================
23 #include <string.h>
25 #include "provider_common.h"
27 /* Include the required CMPI data types, function headers, and macros */
28 #include "cmpidt.h"
29 #include "cmpift.h"
30 #include "cmpimacs.h"
32 /* Include utility functions */
33 #include "cmpiutil.h"
35 /* Include _SBLIM_TRACE() logging support */
36 #include "cmpitrace.h"
38 /* Include Xen utilities */
39 #include "xen_utils.h"
41 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
42 #include "Xen_ComputerSystem_Resource.h"
45 // ----------------------------------------------------------------------------
46 // COMMON GLOBAL VARIABLES
47 // ----------------------------------------------------------------------------
49 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
50 static const CMPIBroker *_BROKER;
52 /* Xen session object. Initialize when the provider is loaded, close when
53 * provider unloaded. */
54 static xen_utils_session *session = NULL;
57 // ============================================================================
58 // CMPI INSTANCE PROVIDER FUNCTION TABLE
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // Info for the class supported by the instance provider
63 // ----------------------------------------------------------------------------
65 /* Name of the class implemented by this instance provider. */
66 /*** CUSTOMIZE FOR EACH PROVIDER ***/
67 static char * _CLASSNAME = "Xen_ComputerSystem";
69 /* NULL terminated list of key properties of this class. */
70 /*** CUSTOMIZE FOR EACH PROVIDER ***/
71 const static char * _KEYNAMES[] = {"Name", "CreationClassName", NULL};
73 // ----------------------------------------------------------------------------
74 // Cleanup()
75 // Perform any necessary cleanup immediately before this provider is unloaded.
76 // ----------------------------------------------------------------------------
77 static CMPIStatus Cleanup(
78 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
79 const CMPIContext * context, /* [in] Additional context info, if any. */
80 CMPIBoolean terminating) /* [in] True if MB is terminating */
81 {
82 (void)terminating;
83 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
85 _SBLIM_ENTER("Cleanup");
86 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
87 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
89 if (session) {
90 xen_utils_xen_close(session);
91 session = NULL;
92 }
93 _SBLIM_RETURNSTATUS(status);
94 }
96 // ----------------------------------------------------------------------------
97 // EnumInstanceNames()
98 // Return a list of all the instances names (return their object paths only).
99 // ----------------------------------------------------------------------------
100 static CMPIStatus EnumInstanceNames(
101 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
102 const CMPIContext * context, /* [in] Additional context info, if any. */
103 const CMPIResult * results, /* [out] Results of this operation. */
104 const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
105 {
106 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
107 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
108 _RESOURCE * resource; /* Handle to each system resource. */
109 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
110 int found = 0; /* Found any instances? */
112 _SBLIM_ENTER("EnumInstanceNames");
113 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
114 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
115 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
116 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
118 if (!xen_utils_validate_session(&session)) {
119 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
120 goto exit;
121 }
123 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
124 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
125 goto exit;
126 }
128 /* Get a handle to the list of system resources. */
129 if (!Xen_ComputerSystem_getResources(session, &resources)) {
130 _SBLIM_TRACE(1,("--- _getResources() failed"));
131 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
132 goto exit;
133 }
135 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
136 while (Xen_ComputerSystem_getNextResource(session, resources, &resource)) {
137 /* Create a new CMPIInstance to store this resource. */
138 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
139 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
140 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
141 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
142 goto exit;
143 }
145 /* Set the instance property values from the resource data. */
146 if (!Xen_ComputerSystem_setInstanceFromResource(resource, instance, _BROKER)) {
147 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
148 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
149 goto exit;
150 }
152 /* Free the resource data. */
153 if (!Xen_ComputerSystem_freeResource(resource)) {
154 _SBLIM_TRACE(1,("--- _freeResource() failed"));
155 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
156 goto exit;
157 }
159 /* Return the CMPIObjectPath for this instance. */
160 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
161 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
162 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
163 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
164 goto exit;
165 }
166 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
168 // _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
169 CMReturnObjectPath(results, objectpath);
170 found++;
171 }
173 _SBLIM_TRACE(2,("--- %d object paths found", found));
175 exit:
176 CMReturnDone(results);
178 /* Free the list of system resources. */
179 if (!Xen_ComputerSystem_freeResources(resources)) {
180 _SBLIM_TRACE(1,("--- _freeResources() failed"));
181 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
182 }
184 _SBLIM_RETURNSTATUS(status);
185 }
187 // ----------------------------------------------------------------------------
188 // EnumInstances()
189 // Return a list of all the instances (return all the instance data).
190 // ----------------------------------------------------------------------------
191 static CMPIStatus EnumInstances(
192 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
193 const CMPIContext * context, /* [in] Additional context info, if any. */
194 const CMPIResult * results, /* [out] Results of this operation. */
195 const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
196 const char ** properties) /* [in] List of desired properties (NULL=all). */
197 {
198 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
199 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
200 _RESOURCE * resource; /* Handle to each system resource. */
201 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
202 int found = 0; /* Found any resource instances? */
204 _SBLIM_ENTER("EnumInstances");
205 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
206 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
207 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
208 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
210 if (!xen_utils_validate_session(&session)) {
211 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
212 goto exit;
213 }
215 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
216 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
217 goto exit;
218 }
220 /* Get a handle to the list of system resources. */
221 if (!Xen_ComputerSystem_getResources(session, &resources)) {
222 _SBLIM_TRACE(1,("--- _getResources() failed"));
223 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
224 goto exit;
225 }
227 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
228 while (Xen_ComputerSystem_getNextResource(session, resources, &resource)) {
229 /* Create a new CMPIInstance to store this resource. */
230 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
231 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
232 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
233 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
234 goto exit;
235 }
237 /* Setup a filter to only return the desired properties. */
238 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
239 if (status.rc != CMPI_RC_OK) {
240 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
241 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
242 goto exit;
243 }
245 /* Set the instance property values from the resource data. */
246 if (!Xen_ComputerSystem_setInstanceFromResource(resource, instance, _BROKER)) {
247 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
248 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
249 goto exit;
250 }
252 /* Free the resource data. */
253 if (!Xen_ComputerSystem_freeResource(resource)) {
254 _SBLIM_TRACE(1,("--- _freeResource() failed"));
255 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
256 goto exit;
257 }
259 /* Return the CMPIInstance for this instance. */
260 // _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
261 CMReturnInstance(results, instance);
262 found++;
263 }
265 _SBLIM_TRACE(2,("--- %d instances found", found));
267 exit:
268 CMReturnDone(results);
270 /* Free the list of system resources. */
271 if (!Xen_ComputerSystem_freeResources(resources)) {
272 _SBLIM_TRACE(1,("--- _freeResources() failed"));
273 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
274 }
276 _SBLIM_RETURNSTATUS(status);
277 }
279 // ----------------------------------------------------------------------------
280 // GetInstance()
281 // Return the instance data for the specified instance only.
282 // ----------------------------------------------------------------------------
283 static CMPIStatus GetInstance(
284 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
285 const CMPIContext * context, /* [in] Additional context info, if any. */
286 const CMPIResult * results, /* [out] Results of this operation. */
287 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
288 const char ** properties) /* [in] List of desired properties (NULL=all). */
289 {
290 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
291 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
292 _RESOURCE * resource; /* Handle to the system resource. */
293 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
294 int found = 0; /* Found the target instance? */
296 if (!xen_utils_validate_session(&session)) {
297 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
298 goto exit;
299 }
301 _SBLIM_ENTER("GetInstance");
302 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
303 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
304 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
305 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
307 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
308 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
309 goto exit;
310 }
312 /* Get a handle to the list of system resources. */
313 if (!Xen_ComputerSystem_getResources(session, &resources)) {
314 _SBLIM_TRACE(1,("--- _getResources() failed"));
315 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
316 goto exit;
317 }
319 /* Get the target resource. */
320 found = Xen_ComputerSystem_getResourceForObjectPath(session, resources, &resource, reference);
321 if (!found || (resource == NULL)) {
322 _SBLIM_TRACE(1,("--- Target instance not found"));
323 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
324 goto exit;
325 }
327 /* Create a new CMPIInstance to store this resource. */
328 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
329 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
330 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
331 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
332 goto exit;
333 }
335 /* Setup a filter to only return the desired properties. */
336 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
337 if (status.rc != CMPI_RC_OK) {
338 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
339 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
340 goto exit;
341 }
343 /* Set the instance property values from the resource data. */
344 if (!Xen_ComputerSystem_setInstanceFromResource(resource, instance, _BROKER)) {
345 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
346 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
347 goto exit;
348 }
350 /* Free the resource data. */
351 if (!Xen_ComputerSystem_freeResource(resource)) {
352 _SBLIM_TRACE(1,("--- _freeResource() failed"));
353 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
354 goto exit;
355 }
357 /* Return the CMPIInstance for this instance. */
358 // _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
359 CMReturnInstance(results, instance);
361 _SBLIM_TRACE(2,("--- instance found"));
363 exit:
364 CMReturnDone(results);
366 /* Free the list of system resources. */
367 if (!Xen_ComputerSystem_freeResources(resources)) {
368 _SBLIM_TRACE(1,("--- _freeResources() failed"));
369 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
370 }
372 _SBLIM_RETURNSTATUS(status);
373 }
375 // ----------------------------------------------------------------------------
376 // SetInstance()
377 // Save modified instance data for the specified instance.
378 // ----------------------------------------------------------------------------
379 static CMPIStatus SetInstance(
380 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
381 const CMPIContext * context, /* [in] Additional context info, if any. */
382 const CMPIResult * results, /* [out] Results of this operation. */
383 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
384 const CMPIInstance * newinstance,
385 const char **properties) /* [in] Contains the new instance data. */
386 {
387 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
388 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
389 _RESOURCE * resource; /* Handle to the system resource. */
390 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
391 int found = 0; /* Found the target instance? */
393 _SBLIM_ENTER("SetInstance");
394 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
395 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
396 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
397 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
398 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
400 if (!xen_utils_validate_session(&session)) {
401 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
402 goto exit;
403 }
405 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
406 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
407 goto exit;
408 }
410 /* Get a handle to the list of system resources. */
411 if (!Xen_ComputerSystem_getResources(session, &resources)) {
412 _SBLIM_TRACE(1,("--- _getResources() failed"));
413 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
414 goto exit;
415 }
417 /* Get the target resource. */
418 found = Xen_ComputerSystem_getResourceForObjectPath(session, resources, &resource, reference);
419 if (!found || (resource == NULL)) {
420 _SBLIM_TRACE(1,("--- Target instance not found"));
421 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
422 goto exit;
423 }
425 _SBLIM_TRACE(2,("--- instance found", found));
427 /* Update the target resource data with the new instance property values. */
428 int rc = Xen_ComputerSystem_setResourceFromInstance(resource, newinstance, _BROKER);
430 /* Free the resource data. */
431 if (!Xen_ComputerSystem_freeResource(resource)) {
432 _SBLIM_TRACE(1,("--- _freeResource() failed"));
433 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
434 goto exit;
435 }
437 if (rc != 1) {
438 if (rc == -1) {
439 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
440 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
441 } else {
442 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
443 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
444 }
445 goto exit;
446 }
448 exit:
449 /* Free the list of system resources. */
450 if (!Xen_ComputerSystem_freeResources(resources)) {
451 _SBLIM_TRACE(1,("--- _freeResources() failed"));
452 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
453 }
455 _SBLIM_RETURNSTATUS(status);
456 }
458 // ----------------------------------------------------------------------------
459 // CreateInstance()
460 // Create a new instance from the specified instance data.
461 // ----------------------------------------------------------------------------
462 static CMPIStatus CreateInstance(
463 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
464 const CMPIContext * context, /* [in] Additional context info, if any. */
465 const CMPIResult * results, /* [out] Results of this operation. */
466 const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
467 const CMPIInstance * newinstance) /* [in] Contains the new instance data. */
468 {
469 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
470 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
471 _RESOURCE * resource; /* Handle to the system resource. */
472 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
473 int found = 0; /* Found the target instance? */
475 _SBLIM_ENTER("CreateInstance");
476 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
477 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
478 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
479 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
480 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
482 if (!xen_utils_validate_session(&session)) {
483 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
484 goto exit;
485 }
487 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
488 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
489 goto exit;
490 }
492 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
493 reference = CMGetObjectPath(newinstance, NULL);
495 /* Get a handle to the list of system resources. */
496 if (!Xen_ComputerSystem_getResources(session, &resources)) {
497 _SBLIM_TRACE(1,("--- _getResources() failed"));
498 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
499 goto exit;
500 }
502 /* Get the target resource. */
503 found = Xen_ComputerSystem_getResourceForObjectPath(session, resources, &resource, reference);
505 /* Free the resource data. */
506 if (!Xen_ComputerSystem_freeResource(resource)) {
507 _SBLIM_TRACE(1,("--- _freeResource() failed"));
508 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
509 goto exit;
510 }
512 if (found) {
513 _SBLIM_TRACE(1,("--- Target instance already exists"));
514 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
515 goto exit;
516 }
518 /* Create a new resource with the new instance property values. */
519 int rc = Xen_ComputerSystem_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
520 if (rc != 1) {
521 if (rc == -1) {
522 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
523 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
524 } else {
525 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
526 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
527 }
528 goto exit;
529 }
531 /* Return the object path for the newly created instance. */
532 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
533 CMSetNameSpace(objectpath, namespace);
534 CMReturnObjectPath(results, objectpath);
535 CMReturnDone(results);
537 exit:
538 /* Free the list of system resources. */
539 if (!Xen_ComputerSystem_freeResources(resources)) {
540 _SBLIM_TRACE(1,("--- _freeResources() failed"));
541 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
542 }
544 _SBLIM_RETURNSTATUS(status);
545 }
547 // ----------------------------------------------------------------------------
548 // DeleteInstance()
549 // Delete or remove the specified instance from the system.
550 // ----------------------------------------------------------------------------
551 static CMPIStatus DeleteInstance(
552 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
553 const CMPIContext * context, /* [in] Additional context info, if any. */
554 const CMPIResult * results, /* [out] Results of this operation. */
555 const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
556 {
557 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
558 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
559 _RESOURCE * resource; /* Handle to the system resource. */
560 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
561 int found = 0; /* Found the target instance? */
563 _SBLIM_ENTER("DeleteInstance");
564 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
565 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
566 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
567 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
569 if (!xen_utils_validate_session(&session)) {
570 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
571 goto exit;
572 }
574 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
575 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
576 goto exit;
577 }
579 /* Get a handle to the list of system resources. */
580 if (!Xen_ComputerSystem_getResources(session, &resources)) {
581 _SBLIM_TRACE(1,("--- _getResources() failed"));
582 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
583 goto exit;
584 }
586 /* Get the target resource. */
587 found = Xen_ComputerSystem_getResourceForObjectPath(session, resources, &resource, reference);
588 if (!found || (resource == NULL)) {
589 _SBLIM_TRACE(1,("--- Target instance not found"));
590 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
591 goto exit;
592 }
594 _SBLIM_TRACE(2,("--- instance found", found));
596 /* Delete the target resource. */
597 int rc = Xen_ComputerSystem_deleteResource(session, resources, resource);
599 /* Free the resource data. */
600 if (!Xen_ComputerSystem_freeResource(resource)) {
601 _SBLIM_TRACE(1,("--- _freeResource() failed"));
602 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
603 goto exit;
604 }
606 if (rc != 1) {
607 if (rc == -1) {
608 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
609 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
610 } else {
611 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
612 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
613 }
614 goto exit;
615 }
617 exit:
618 /* Free the list of system resources. */
619 if (!Xen_ComputerSystem_freeResources(resources)) {
620 _SBLIM_TRACE(1,("--- _freeResources() failed"));
621 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
622 }
624 _SBLIM_RETURNSTATUS(status);
625 }
628 // ----------------------------------------------------------------------------
629 // ExecQuery()
630 // Return a list of all the instances that satisfy the specified query filter.
631 // ----------------------------------------------------------------------------
632 static CMPIStatus ExecQuery(
633 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
634 const CMPIContext * context, /* [in] Additional context info, if any. */
635 const CMPIResult * results, /* [out] Results of this operation. */
636 const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
637 const char * language, /* [in] Name of the query language. */
638 const char * query) /* [in] Text of the query written in the query language. */
639 {
640 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
641 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
643 _SBLIM_ENTER("ExecQuery");
644 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
645 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
646 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
647 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
648 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
649 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
651 if (!xen_utils_validate_session(&session)) {
652 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
653 goto exit;
654 }
656 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
657 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
658 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_NAMESPACE, "Invalid namespace specified for Xen_ComputerSystem");
659 goto exit;
660 }
662 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
663 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
665 CMReturnDone(results);
667 exit:
668 _SBLIM_RETURNSTATUS(status);
669 }
671 // ----------------------------------------------------------------------------
672 // InstInitialize()
673 // Perform any necessary initialization immediately after the instance provider
674 // is first loaded.
675 // ----------------------------------------------------------------------------
676 static void InstInitialize(
677 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
678 const CMPIContext * context) /* [in] Additional context info, if any. */
679 {
680 _SBLIM_ENTER("InstInitialize");
681 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
682 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
684 /* Initialized Xen session object. */
685 if (session == NULL)
686 xen_utils_xen_init(&session);
688 _SBLIM_RETURN();
689 }
691 // ============================================================================
692 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
693 // ============================================================================
694 CMInstanceMIStub( , Xen_ComputerSystem, _BROKER, InstInitialize(&mi, ctx));
697 // ============================================================================
698 // CMPI METHOD PROVIDER FUNCTION TABLE
699 // ============================================================================
701 // ----------------------------------------------------------------------------
702 // MethodCleanup()
703 // Perform any necessary cleanup immediately before this provider is unloaded.
704 // ----------------------------------------------------------------------------
705 static CMPIStatus MethodCleanup(
706 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
707 const CMPIContext * context, /* [in] Additional context info, if any. */
708 CMPIBoolean terminating) /* [in] True if MB is terminating */
709 {
710 (void)terminating;
711 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
713 _SBLIM_ENTER("MethodCleanup");
714 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
715 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
717 if (session) {
718 xen_utils_xen_close(session);
719 session = NULL;
720 }
721 _SBLIM_RETURNSTATUS(status);
722 }
724 /* Needed for stat() */
725 #include <sys/types.h>
726 #include <sys/stat.h>
727 #include <unistd.h>
730 // ----------------------------------------------------------------------------
731 // InvokeMethod()
732 // Execute an extrinsic method on the specified instance.
733 // ----------------------------------------------------------------------------
734 static CMPIStatus InvokeMethod(
735 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self') */
736 const CMPIContext * context, /* [in] Additional context info, if any */
737 const CMPIResult * results, /* [out] Results of this operation */
738 const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */
739 const char * methodname, /* [in] Name of the method to apply against the reference object */
740 const CMPIArgs * argsin, /* [in] Method input arguments */
741 CMPIArgs * argsout) /* [in] Method output arguments */
742 {
743 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
744 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
745 _RESOURCE * resource = NULL; /* Handle to the system resource. */
746 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
747 int found = 0; /* Found the target instance? */
748 unsigned long rc = 0;
749 CMPIData argdata;
750 char error_msg[XEN_UTILS_ERROR_BUF_LEN];
752 _SBLIM_ENTER("InvokeMethod");
753 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
754 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
755 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
756 _SBLIM_TRACE(2, ("--- methodname=\"%s\"", methodname));
757 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
759 if (!xen_utils_validate_session(&session)) {
760 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
761 goto exit;
762 }
764 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
765 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
766 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_NAMESPACE, "Invalid namespace specified for Xen_ComputerSystem");
767 goto exit;
768 }
770 /* Only support RequestStateChange() for now. */
771 if (strcmp(methodname, "RequestStateChange")) {
772 _SBLIM_TRACE(1,("--- Method \"%s\" is not supported", methodname));
773 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, NULL);
774 goto exit;
775 }
777 /* Check that the method has the correct number of arguments. */
778 int argcount = CMGetArgCount(argsin, NULL);
779 _SBLIM_TRACE(2, ("--- argsin=%d", argcount));
780 if ((argcount < 1) || (argcount > 2)) {
781 _SBLIM_TRACE(1,("--- Incorrect number of method arguments"));
782 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Incorrect number of method arguments");
783 goto exit;
784 }
786 /* Get a handle to the list of system resources. */
787 if (!Xen_ComputerSystem_getResources(session, &resources)) {
788 _SBLIM_TRACE(1,("--- _getResources() failed"));
789 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
790 goto exit;
791 }
793 /* Get the target resource. */
794 found = Xen_ComputerSystem_getResourceForObjectPath(session, resources, &resource, reference);
795 if (!found || (resource == NULL)) {
796 _SBLIM_TRACE(1,("--- Target instance not found"));
797 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
798 goto exit;
799 }
801 _SBLIM_TRACE(2,("--- instance found"));
803 /* Get RequestedState parameter. */
804 argdata = CMGetArgAt(argsin, 0, NULL, &status);
805 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
806 _SBLIM_TRACE(1,("--- CMGetArgAt(0) failed"));
807 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
808 goto exit;
809 }
811 if (argdata.type != CMPI_uint16) {
812 _SBLIM_TRACE(1,("--- Invalid parameter type \"%s\", expected uint16", _CMPITypeName(argdata.type)));
813 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid parameter type");
814 goto exit;
815 }
817 int requestedState = argdata.value.uint16;
818 _SBLIM_TRACE(2,("--- RequestedState = \"%d\"", requestedState));
820 /* TODO:
821 * Support TimeoutPeriod parameter once we have Job support.
822 * For now, return appropriate error if TimeoutPeriod has been specified.
823 */
824 if (argcount == 2) {
825 argdata = CMGetArgAt(argsin, 1, NULL, &status);
826 if (status.rc != CMPI_RC_OK) {
827 _SBLIM_TRACE(1,("--- CMGetArgAt(1) failed"));
828 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Cannot get method input argument");
829 goto exit;
830 }
831 if (!CMIsNullValue(argdata)) {
832 if (argdata.type != CMPI_dateTime) {
833 _SBLIM_TRACE(1,("--- Invalid parameter type \"%s\", expected DateTime", _CMPITypeName(argdata.type)));
834 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid parameter type");
835 goto exit;
836 }
837 CMPIDateTime *dt = argdata.value.dateTime;
838 unsigned long long time = CMGetBinaryFormat(dt, &status);
839 if (status.rc != CMPI_RC_OK) {
840 _SBLIM_TRACE(1,("--- Failed to convert DateTime to binary format"));
841 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Failed to convert DateTime to binary format");
842 goto exit;
843 }
844 if (time != 0) {
845 _SBLIM_TRACE(1,("--- TimeoutPeriod specified but not supported"));
846 CMSetStatusWithChars(_BROKER, &status, 4098, "TimeoutPeriod specified but not supported");
847 goto exit;
848 }
849 }
850 }
852 /* Move the system to the requested state. */
853 rc = 0; /* Default to 'Completed with No Error' return code */
854 if (requestedState == 2) { /* 2 == Enabled */
855 /* Can go to Enabled from Defined, Paused, or Suspended states. */
856 if (resource->power_state == XEN_VM_POWER_STATE_HALTED) {
857 if (!xen_vm_start(session->xen, resource->handle, false)) {
858 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
859 _SBLIM_TRACE(1, ("--- xen_vm_start() failed: %s", error_msg));
860 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
861 rc = 4; // "Failed"
862 }
863 }
864 else if (resource->power_state == XEN_VM_POWER_STATE_PAUSED) {
865 if (!xen_vm_unpause(session->xen, resource->handle)) {
866 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
867 _SBLIM_TRACE(1, ("--- xen_vm_unpause() failed: %s", error_msg));
868 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
869 rc = 4; // "Failed
870 }
871 }
872 else if (resource->power_state == XEN_VM_POWER_STATE_SUSPENDED) {
873 if (!xen_vm_resume(session->xen, resource->handle, false)) {
874 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
875 _SBLIM_TRACE(1, ("--- xen_vm_resume() failed: %s", error_msg));
876 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
877 rc = 4; // "Failed
878 }
879 }
880 else {
881 _SBLIM_TRACE(1, ("--- Invalid state transition - domain currently in state %s", xen_vm_power_state_to_string(resource->power_state)));
882 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Invalid state transition - VirtualSystem already active");
883 rc = 4097; // "Invalid State Transition"
884 }
885 }
886 /* 3 == Disabled and 4 == Shutdown
887 * We'll treat these state transitions the same.
888 */
889 else if (requestedState == 3 || requestedState == 4) {
890 /* Can go to Disabled or Shutdown from Active, Paused, or Suspended states. */
891 if (resource->power_state == XEN_VM_POWER_STATE_RUNNING) {
892 /* Initiate an asynchronous graceful shutdown of the domain's OS. */
893 if (!xen_vm_clean_shutdown(session->xen, resource->handle)) {
894 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
895 _SBLIM_TRACE(1, ("--- xen_vm_clean_shutdown() failed: %s", error_msg));
896 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
897 rc = 4; // "Failed"
898 }
899 } else if ((resource->power_state == XEN_VM_POWER_STATE_SUSPENDED) ||
900 (resource->power_state == XEN_VM_POWER_STATE_PAUSED)) {
901 /*
902 * TODO:
903 * How do we shutdown a paused or suspended vm? For now do a
904 * hard shutdown.
905 */
906 if (!xen_vm_hard_shutdown(session->xen, resource->handle)) {
907 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
908 _SBLIM_TRACE(1, ("--- xen_vm_hard_shutdown() failed: %s", error_msg));
909 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
910 rc = 4; // "Failed"
911 }
912 }
913 else {
914 _SBLIM_TRACE(1, ("--- Domain must be in Active, Paused, or Suspended state to Deactivate"));
915 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Invalide state transition - VirtualSystem already disabled");
916 rc = 4097; // "Invalid State Transition"
917 }
918 }
919 /* 10 == Reboot and 11 == Reset
920 * We'll treat these state transitions the same for now.
921 */
922 else if (requestedState == 10 || requestedState == 11) {
923 /* Can Reboot or Reset only when in Active, Paused, or Suspended
924 * states. Not sure what a Paused or Suspended domain looks like
925 * after a reboot or reset. Need clarification in the Virtual
926 * System Profile. For now we'll restrict this set to Active
927 * state only.
928 */
929 if (resource->power_state == XEN_VM_POWER_STATE_RUNNING) {
930 if (!xen_vm_clean_reboot(session->xen, resource->handle)) {
931 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
932 _SBLIM_TRACE(1, ("--- xen_vm_clean_reboot() failed: %s", error_msg));
933 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
934 rc = 4; // "Failed"
935 }
936 }
937 else {
938 _SBLIM_TRACE(1, ("--- Domain is not active - unable to reboot"));
939 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Invalide state transition - VirtualSystem must be active to reboot");
940 rc = 4097; // "Invalid State Transition"
941 }
942 }
943 else if (requestedState == 9) { /* 9 == Quiesce */
944 /* Can go to Quiese or Pause from Active state only. */
945 if (resource->power_state == XEN_VM_POWER_STATE_RUNNING) {
946 if (!xen_vm_pause(session->xen, resource->handle)) {
947 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
948 _SBLIM_TRACE(1, ("--- xen_vm_pause() failed: %s", error_msg));
949 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
950 rc = 4; // "Failed"
951 }
952 }
953 else {
954 _SBLIM_TRACE(1, ("--- Domain is not active - unable to pause"));
955 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Invalide state transition - VirtualSystem must be active to quiese or pause");
956 rc = 4097; // "Invalid State Transition"
957 }
958 }
959 /*
960 * As per CR00022, Offline indicates a transition to the
961 * 'Enabled but Offline' EnabledState - aka Suspend.
962 */
963 else if (requestedState == 6) { /* 6 == Offline */
964 /* Virtual System Profile says we can go to Suspended from Active
965 * or Paused states. Xen does not allow a Paused domain to be
966 * suspended, so we'll enforce Active state.
967 */
968 if (resource->power_state == XEN_VM_POWER_STATE_RUNNING) {
969 if (!xen_vm_suspend(session->xen, resource->handle)) {
970 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
971 _SBLIM_TRACE(1, ("--- xen_vm_suspend() failed: %s", error_msg));
972 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
973 rc = 4; // "Failed"
974 }
975 }
976 else {
977 _SBLIM_TRACE(1, ("--- Domain is not active - unable to suspend"));
978 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Invalide state transition - VirtualSystem must be active to suspend");
979 rc = 4097; // "Invalid State Transition"
980 }
981 }
982 else {
983 _SBLIM_TRACE(1, ("--- Unknown state %d", requestedState));
984 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid state requested");
985 rc = 4097; // "Invalid State Transition"
986 }
988 CMReturnData(results, (CMPIValue *)&rc, CMPI_uint32);
989 CMReturnDone(results);
991 exit:
992 /* Free the resource data. */
993 if (!Xen_ComputerSystem_freeResource(resource))
994 _SBLIM_TRACE(1,("--- _freeResource() failed"));
996 /* Free the list of system resources. */
997 if (!Xen_ComputerSystem_freeResources(resources))
998 _SBLIM_TRACE(1,("--- _freeResources() failed"));
1000 _SBLIM_RETURNSTATUS(status);
1003 // ----------------------------------------------------------------------------
1004 // MethodInitialize()
1005 // Perform any necessary initialization immediately after the method provider
1006 // is first loaded.
1007 // ----------------------------------------------------------------------------
1008 static void MethodInitialize(
1009 CMPIMethodMI * self, /* [in] Handle to this provider (i.e. 'self'). */
1010 const CMPIContext * context) /* [in] Additional context info, if any. */
1012 _SBLIM_ENTER("MethodInitialize");
1013 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
1014 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
1016 /* Initialized Xen session object. */
1017 if (session == NULL)
1018 xen_utils_xen_init(&session);
1020 _SBLIM_RETURN();
1024 // ============================================================================
1025 // CMPI METHOD PROVIDER FUNCTION TABLE SETUP
1026 // ============================================================================
1027 CMMethodMIStub( , Xen_ComputerSystem, _BROKER, MethodInitialize(&mi, ctx));