os-cmpi-xen
changeset 119:5a5f465c4191
Converted Xen_Processor to new instance provider resource abstraction interface.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author | Jim Fehlig <jfehlig@novell.com> |
---|---|
date | Mon Jun 04 17:01:42 2007 -0600 (2007-06-04) |
parents | 8ecc856bd445 |
children | 0ea27641bb83 |
files | ChangeLog src/Makefile.am src/Xen_Processor.c src/Xen_Processor_Resource.c src/Xen_Processor_Resource.h |
line diff
1.1 --- a/ChangeLog Mon Jun 04 16:47:54 2007 -0600 1.2 +++ b/ChangeLog Mon Jun 04 17:01:42 2007 -0600 1.3 @@ -1,3 +1,11 @@ 1.4 +------------------------------------------------------------------- 1.5 +Mon Jun 4 16:57:17 MDT 2007 - jfehlig@novell.com 1.6 + 1.7 + - Fixed memory leak in Xen_Disk 1.8 + - Optimizations and cleanup in xen_utils 1.9 + - Converted Xen_Processor to new instance resource 1.10 + abstraction layer. 1.11 + 1.12 ------------------------------------------------------------------- 1.13 Wed May 30 15:42:24 MDT 2007 - jfehlig@novell.com 1.14
2.1 --- a/src/Makefile.am Mon Jun 04 16:47:54 2007 -0600 2.2 +++ b/src/Makefile.am Mon Jun 04 17:01:42 2007 -0600 2.3 @@ -49,7 +49,6 @@ noinst_HEADERS = \ 2.4 Xen_ComputerSystem_Resource.h \ 2.5 Xen_VirtualSystemManagementService_Resource.h \ 2.6 Xen_Memory_Resource.h \ 2.7 - Xen_Processor_Resource.h \ 2.8 Xen_NetworkPort_Resource.h \ 2.9 Xen_Console_Resource.h \ 2.10 Xen_VirtualizationCapabilities_Resource.h \ 2.11 @@ -168,7 +167,7 @@ libXen_ComputerSystemMemory_la_SOURCES = 2.12 libXen_ComputerSystemMemory_la_LIBADD = libXen_ProviderCommon.la 2.13 libXen_ComputerSystemMemory_la_LDFLAGS = -module -avoid-version -no-undefined 2.14 2.15 -libXen_Processor_la_SOURCES = Xen_Processor.c Xen_Processor_Resource.c 2.16 +libXen_Processor_la_SOURCES = Xen_Processor.c 2.17 libXen_Processor_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ 2.18 libXen_Processor_la_LIBADD = libXen_ProviderCommon.la 2.19 libXen_Processor_la_LDFLAGS = -module -avoid-version -no-undefined
3.1 --- a/src/Xen_Processor.c Mon Jun 04 16:47:54 2007 -0600 3.2 +++ b/src/Xen_Processor.c Mon Jun 04 17:01:42 2007 -0600 3.3 @@ -17,629 +17,364 @@ 3.4 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 3.5 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com> 3.6 // Contributors: Jim Fehlig, <jfehlig@novell.com> 3.7 +// Raj Subrahmanian <raj.subrahmanian@unisys.com> 3.8 // Description: 3.9 // ============================================================================ 3.10 3.11 -/* Include the required CMPI data types, function headers, and macros */ 3.12 +/* Common declarations for each CMPI "Cimpler" instance provider */ 3.13 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3.14 #include "cmpidt.h" 3.15 -#include "cmpift.h" 3.16 #include "cmpimacs.h" 3.17 +#include "cmpilr.h" 3.18 + 3.19 + 3.20 +static const CMPIInstanceMI* mi; 3.21 + 3.22 3.23 -/* Include utility functions */ 3.24 -#include "cmpiutil.h" 3.25 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr) 3.26 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn) 3.27 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 3.28 + 3.29 +#include <stdlib.h> 3.30 +#include <assert.h> 3.31 3.32 -/* Include _SBLIM_TRACE() logging support */ 3.33 +#include <xen_common.h> 3.34 +#include <xen_host.h> 3.35 +#include <xen_vm.h> 3.36 +#include <xen_vm_metrics.h> 3.37 + 3.38 #include "cmpitrace.h" 3.39 - 3.40 -/* Include Xen utilities */ 3.41 #include "xen_utils.h" 3.42 3.43 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ 3.44 -#include "Xen_Processor_Resource.h" 3.45 + 3.46 +/* C struct to store data for a single resource. */ 3.47 +typedef struct _RESOURCE_S { 3.48 + struct _RESOURCE_S *next; 3.49 + unsigned int vcpu_id; 3.50 + char *domain_name; 3.51 +} _RESOURCE; 3.52 3.53 3.54 -// ---------------------------------------------------------------------------- 3.55 -// COMMON GLOBAL VARIABLES 3.56 -// ---------------------------------------------------------------------------- 3.57 +/* C struct to store the data for all resources. */ 3.58 +typedef struct { 3.59 + _RESOURCE* vcpus; 3.60 + _RESOURCE* cur_vcpu; 3.61 +} _RESOURCES; 3.62 3.63 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ 3.64 -static const CMPIBroker *_BROKER; 3.65 3.66 /* Xen session object. Initialize when the provider is loaded, close when 3.67 * provider unloaded. */ 3.68 static xen_utils_session *session = NULL; 3.69 3.70 3.71 -// ============================================================================ 3.72 -// CMPI INSTANCE PROVIDER FUNCTION TABLE 3.73 -// ============================================================================ 3.74 - 3.75 -// ---------------------------------------------------------------------------- 3.76 -// Info for the class supported by the instance provider 3.77 -// ---------------------------------------------------------------------------- 3.78 - 3.79 -/* Name of the class implemented by this instance provider. */ 3.80 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 3.81 -static char * _CLASSNAME = "Xen_Processor"; 3.82 - 3.83 -/* NULL terminated list of key properties of this class. */ 3.84 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 3.85 -const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL}; 3.86 +static int load() 3.87 +{ 3.88 + /* Initialized Xen session object. */ 3.89 + if (!session) 3.90 + xen_utils_xen_init(&session); 3.91 3.92 -// ---------------------------------------------------------------------------- 3.93 -// Cleanup() 3.94 -// Perform any necessary cleanup immediately before this provider is unloaded. 3.95 -// ---------------------------------------------------------------------------- 3.96 -static CMPIStatus Cleanup( 3.97 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.98 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.99 - CMPIBoolean terminating) /* [in] True if MB is terminating */ 3.100 + return 1; 3.101 +} 3.102 + 3.103 + 3.104 +static int unload(CMPIBoolean terminating) 3.105 { 3.106 - CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ 3.107 - 3.108 - _SBLIM_ENTER("Cleanup"); 3.109 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.110 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.111 - 3.112 + (void) terminating; 3.113 + 3.114 if (session) { 3.115 xen_utils_xen_close(session); 3.116 session = NULL; 3.117 } 3.118 - _SBLIM_RETURNSTATUS(status); 3.119 + 3.120 + return 1; 3.121 } 3.122 3.123 -// ---------------------------------------------------------------------------- 3.124 -// EnumInstanceNames() 3.125 -// Return a list of all the instances names (return their object paths only). 3.126 -// ---------------------------------------------------------------------------- 3.127 -static CMPIStatus EnumInstanceNames( 3.128 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.129 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.130 - const CMPIResult * results, /* [out] Results of this operation. */ 3.131 - const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ 3.132 + 3.133 +static int beginEnum(void **res_list, CMPIStatus *status) 3.134 { 3.135 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.136 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.137 - _RESOURCE * resource; /* Handle to each system resource. */ 3.138 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.139 - int found = 0; /* Found any instances? */ 3.140 - 3.141 - _SBLIM_ENTER("EnumInstanceNames"); 3.142 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.143 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.144 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.145 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.146 - 3.147 + _RESOURCES *resources; 3.148 + xen_vm_set *vms; 3.149 + xen_vm_metrics vm_metrics; 3.150 + xen_vm_record *vm_rec; 3.151 + size_t vm_ndx; 3.152 + int64_t vcpus_ndx; 3.153 + 3.154 if (!xen_utils_validate_session(&session)) { 3.155 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.156 - goto exit; 3.157 - } 3.158 - 3.159 - /* Get a handle to the list of system resources. */ 3.160 - if (!Xen_Processor_getResources(session, &resources)) { 3.161 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.162 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.163 - goto exit; 3.164 - } 3.165 - 3.166 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 3.167 - while (Xen_Processor_getNextResource(session, resources, &resource)) { 3.168 - /* Create a new CMPIInstance to store this resource. */ 3.169 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 3.170 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 3.171 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 3.172 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 3.173 - goto exit; 3.174 - } 3.175 - 3.176 - /* Set the instance property values from the resource data. */ 3.177 - if (!Xen_Processor_setInstanceFromResource(resource, instance, _BROKER, resources)) { 3.178 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 3.179 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 3.180 - goto exit; 3.181 - } 3.182 - 3.183 - /* Free the resource data. */ 3.184 - if (!Xen_Processor_freeResource(resource)) { 3.185 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.186 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.187 - goto exit; 3.188 - } 3.189 - 3.190 - /* Return the CMPIObjectPath for this instance. */ 3.191 - CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); 3.192 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { 3.193 - _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); 3.194 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); 3.195 - goto exit; 3.196 - } 3.197 - CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ 3.198 - 3.199 - _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); 3.200 - CMReturnObjectPath(results, objectpath); 3.201 - found++; 3.202 - } 3.203 - 3.204 - _SBLIM_TRACE(2,("--- %d object paths found", found)); 3.205 - CMReturnDone(results); 3.206 - 3.207 -exit: 3.208 - /* Free the list of system resources. */ 3.209 - if (!Xen_Processor_freeResources(resources)) { 3.210 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.211 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.212 - } 3.213 - 3.214 - _SBLIM_RETURNSTATUS(status); 3.215 -} 3.216 - 3.217 -// ---------------------------------------------------------------------------- 3.218 -// EnumInstances() 3.219 -// Return a list of all the instances (return all the instance data). 3.220 -// ---------------------------------------------------------------------------- 3.221 -static CMPIStatus EnumInstances( 3.222 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.223 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.224 - const CMPIResult * results, /* [out] Results of this operation. */ 3.225 - const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ 3.226 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 3.227 -{ 3.228 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.229 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.230 - _RESOURCE * resource; /* Handle to each system resource. */ 3.231 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.232 - int found = 0; /* Found any resource instances? */ 3.233 - 3.234 - _SBLIM_ENTER("EnumInstances"); 3.235 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.236 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.237 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.238 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.239 - 3.240 - if (!xen_utils_validate_session(&session)) { 3.241 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.242 - goto exit; 3.243 - } 3.244 - 3.245 - /* Get a handle to the list of system resources. */ 3.246 - if (!Xen_Processor_getResources(session, &resources)) { 3.247 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.248 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.249 - goto exit; 3.250 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.251 + ("--- Unable to establish connection with Xend")); 3.252 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.253 + "Unable to establish connection with Xend"); 3.254 + return 0; 3.255 } 3.256 3.257 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 3.258 - while (Xen_Processor_getNextResource(session, resources, &resource)) { 3.259 - /* Create a new CMPIInstance to store this resource. */ 3.260 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 3.261 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 3.262 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 3.263 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 3.264 - goto exit; 3.265 - } 3.266 - 3.267 - /* Setup a filter to only return the desired properties. */ 3.268 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 3.269 - if (status.rc != CMPI_RC_OK) { 3.270 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 3.271 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 3.272 - goto exit; 3.273 - } 3.274 - 3.275 - /* Set the instance property values from the resource data. */ 3.276 - if (!Xen_Processor_setInstanceFromResource(resource, instance, _BROKER, resources)) { 3.277 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 3.278 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 3.279 - goto exit; 3.280 - } 3.281 - 3.282 - /* Free the resource data. */ 3.283 - if (!Xen_Processor_freeResource(resource)) { 3.284 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.285 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.286 - goto exit; 3.287 - } 3.288 - 3.289 - /* Return the CMPIInstance for this instance. */ 3.290 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 3.291 - CMReturnInstance(results, instance); 3.292 - found++; 3.293 - } 3.294 - 3.295 - _SBLIM_TRACE(2,("--- %d instances found", found)); 3.296 - CMReturnDone(results); 3.297 - 3.298 -exit: 3.299 - /* Free the list of system resources. */ 3.300 - if (!Xen_Processor_freeResources(resources)) { 3.301 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.302 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.303 - } 3.304 - 3.305 - _SBLIM_RETURNSTATUS(status); 3.306 -} 3.307 + /* malloc a new handle for the resources list. */ 3.308 + resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); 3.309 + if (resources == NULL) 3.310 + return 0; 3.311 3.312 -// ---------------------------------------------------------------------------- 3.313 -// GetInstance() 3.314 -// Return the instance data for the specified instance only. 3.315 -// ---------------------------------------------------------------------------- 3.316 -static CMPIStatus GetInstance( 3.317 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.318 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.319 - const CMPIResult * results, /* [out] Results of this operation. */ 3.320 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 3.321 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 3.322 -{ 3.323 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.324 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.325 - _RESOURCE * resource; /* Handle to the system resource. */ 3.326 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.327 - int found = 0; /* Found the target instance? */ 3.328 - 3.329 - _SBLIM_ENTER("GetInstance"); 3.330 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.331 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.332 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.333 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.334 - 3.335 - if (!xen_utils_validate_session(&session)) { 3.336 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.337 - goto exit; 3.338 - } 3.339 - 3.340 - /* Get a handle to the list of system resources. */ 3.341 - if (!Xen_Processor_getResources(session, &resources)) { 3.342 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.343 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.344 - goto exit; 3.345 - } 3.346 - 3.347 - /* Get the target resource. */ 3.348 - found = Xen_Processor_getResourceForObjectPath(session, resources, &resource, reference); 3.349 - if (!found || (resource == NULL)) { 3.350 - _SBLIM_TRACE(1,("--- Target instance not found")); 3.351 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 3.352 - goto exit; 3.353 - } 3.354 - 3.355 - /* Create a new CMPIInstance to store this resource. */ 3.356 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 3.357 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 3.358 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 3.359 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 3.360 - goto exit; 3.361 - } 3.362 - 3.363 - /* Setup a filter to only return the desired properties. */ 3.364 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 3.365 - if (status.rc != CMPI_RC_OK) { 3.366 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 3.367 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 3.368 - goto exit; 3.369 - } 3.370 - 3.371 - /* Set the instance property values from the resource data. */ 3.372 - if (!Xen_Processor_setInstanceFromResource(resource, instance, _BROKER, resources)) { 3.373 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 3.374 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 3.375 - goto exit; 3.376 - } 3.377 - 3.378 - /* Free the resource data. */ 3.379 - if (!Xen_Processor_freeResource(resource)) { 3.380 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.381 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.382 - goto exit; 3.383 + if(!xen_host_get_resident_vms(session->xen, &vms, session->host)) { 3.384 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.385 + ("--- Failed to retrieve list of domains from host")); 3.386 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.387 + "Failed to retrieve list of domains from host"); 3.388 + free(resources); 3.389 + return 0; 3.390 } 3.391 3.392 - /* Return the CMPIInstance for this instance. */ 3.393 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 3.394 - CMReturnInstance(results, instance); 3.395 - 3.396 - _SBLIM_TRACE(2,("--- instance found")); 3.397 - CMReturnDone(results); 3.398 - 3.399 -exit: 3.400 - /* Free the list of system resources. */ 3.401 - if (!Xen_Processor_freeResources(resources)) { 3.402 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.403 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.404 - } 3.405 - 3.406 - _SBLIM_RETURNSTATUS(status); 3.407 -} 3.408 - 3.409 -// ---------------------------------------------------------------------------- 3.410 -// SetInstance() 3.411 -// Save modified instance data for the specified instance. 3.412 -// ---------------------------------------------------------------------------- 3.413 -static CMPIStatus SetInstance( 3.414 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.415 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.416 - const CMPIResult * results, /* [out] Results of this operation. */ 3.417 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 3.418 - const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ 3.419 - const char **properties) 3.420 -{ 3.421 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.422 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.423 - _RESOURCE * resource; /* Handle to the system resource. */ 3.424 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.425 - int found = 0; /* Found the target instance? */ 3.426 - 3.427 - _SBLIM_ENTER("SetInstance"); 3.428 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.429 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.430 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.431 - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); 3.432 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.433 - 3.434 - if (!xen_utils_validate_session(&session)) { 3.435 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.436 - goto exit; 3.437 - } 3.438 + /* 3.439 + * Iterate through domains. For those not halted, create a 3.440 + * vcpu resource for each vcpu in use by the domain. 3.441 + */ 3.442 + for (vm_ndx = 0; vm_ndx < vms->size; vm_ndx++) { 3.443 + int64_t vcpus_number; 3.444 3.445 - /* Get a handle to the list of system resources. */ 3.446 - if (!Xen_Processor_getResources(session, &resources)) { 3.447 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.448 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.449 - goto exit; 3.450 - } 3.451 - 3.452 - /* Get the target resource. */ 3.453 - found = Xen_Processor_getResourceForObjectPath(session, resources, &resource, reference); 3.454 - if (!found || (resource == NULL)) { 3.455 - _SBLIM_TRACE(1,("--- Target instance not found")); 3.456 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 3.457 - goto exit; 3.458 - } 3.459 - 3.460 - _SBLIM_TRACE(2,("--- instance found", found)); 3.461 - 3.462 - /* Update the target resource data with the new instance property values. */ 3.463 - int rc = Xen_Processor_setResourceFromInstance(resource, newinstance, _BROKER); 3.464 + vm_rec = NULL; 3.465 + vm_metrics = NULL; 3.466 + if (!xen_vm_get_record(session->xen, &vm_rec, vms->contents[vm_ndx])) { 3.467 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.468 + ("--- Failed to retrieve VM record from xend")); 3.469 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.470 + "Failed to retrieve VM record from xend"); 3.471 + goto Error; 3.472 + } 3.473 + 3.474 + if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) { 3.475 + xen_vm_record_free(vm_rec); 3.476 + continue; 3.477 + } 3.478 + 3.479 + xen_vm_get_metrics(session->xen, &vm_metrics, vms->contents[vm_ndx]); 3.480 + xen_vm_metrics_get_vcpus_number(session->xen, &vcpus_number, vm_metrics); 3.481 + if (!session->xen->ok) { 3.482 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.483 + ("--- Failed to retrieve domain vcpu data from xend")); 3.484 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.485 + "Failed to retrieve domain vcpu data from xend"); 3.486 + goto Error; 3.487 + } 3.488 + 3.489 + for (vcpus_ndx = 0; vcpus_ndx < vcpus_number; vcpus_ndx++) { 3.490 + _RESOURCE *vcpu = (_RESOURCE *)calloc(1, sizeof(_RESOURCE)); 3.491 + if (vcpu == NULL ) 3.492 + goto Error; 3.493 + 3.494 + vcpu->vcpu_id = vcpus_ndx; 3.495 + vcpu->domain_name = strdup(vm_rec->name_label); 3.496 + 3.497 + if (resources->vcpus == NULL) 3.498 + resources->vcpus = vcpu; 3.499 + else 3.500 + resources->cur_vcpu->next = vcpu; 3.501 3.502 - /* Free the resource data. */ 3.503 - if (!Xen_Processor_freeResource(resource)) { 3.504 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.505 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.506 - goto exit; 3.507 + resources->cur_vcpu = vcpu; 3.508 + } 3.509 + 3.510 + xen_vm_record_free(vm_rec); 3.511 + xen_vm_metrics_free(vm_metrics); 3.512 } 3.513 + 3.514 + xen_vm_set_free(vms); 3.515 3.516 - if (rc != 1) { 3.517 - if (rc == -1) { 3.518 - _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); 3.519 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 3.520 - } else { 3.521 - _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); 3.522 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); 3.523 - } 3.524 - goto exit; 3.525 - } 3.526 + /* Set cur_vcpu to beginning of resource list. */ 3.527 + resources->cur_vcpu = resources->vcpus; 3.528 + *res_list = (void *)resources; 3.529 + return 1; 3.530 3.531 -exit: 3.532 - /* Free the list of system resources. */ 3.533 - if (!Xen_Processor_freeResources(resources)) { 3.534 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.535 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.536 - } 3.537 - 3.538 - _SBLIM_RETURNSTATUS(status); 3.539 + Error: 3.540 + xen_vm_record_free(vm_rec); 3.541 + xen_vm_metrics_free(vm_metrics); 3.542 + xen_vm_set_free(vms); 3.543 + free(resources); 3.544 + return 0; 3.545 } 3.546 3.547 -// ---------------------------------------------------------------------------- 3.548 -// CreateInstance() 3.549 -// Create a new instance from the specified instance data. 3.550 -// ---------------------------------------------------------------------------- 3.551 -static CMPIStatus CreateInstance( 3.552 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.553 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.554 - const CMPIResult * results, /* [out] Results of this operation. */ 3.555 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 3.556 - const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ 3.557 + 3.558 +static void endEnum(void *res_list) 3.559 { 3.560 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.561 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.562 - _RESOURCE * resource; /* Handle to the system resource. */ 3.563 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.564 - int found = 0; /* Found the target instance? */ 3.565 - 3.566 - _SBLIM_ENTER("CreateInstance"); 3.567 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.568 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.569 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.570 - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); 3.571 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.572 - 3.573 - if (!xen_utils_validate_session(&session)) { 3.574 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.575 - goto exit; 3.576 - } 3.577 - 3.578 - /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ 3.579 - reference = CMGetObjectPath(newinstance, NULL); 3.580 - 3.581 - /* Get a handle to the list of system resources. */ 3.582 - if (!Xen_Processor_getResources(session, &resources)) { 3.583 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.584 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.585 - goto exit; 3.586 - } 3.587 - 3.588 - /* Get the target resource. */ 3.589 - found = Xen_Processor_getResourceForObjectPath(session, resources, &resource, reference); 3.590 - 3.591 - /* Free the resource data. */ 3.592 - if (!Xen_Processor_freeResource(resource)) { 3.593 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.594 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.595 - goto exit; 3.596 - } 3.597 - 3.598 - if (found) { 3.599 - _SBLIM_TRACE(1,("--- Target instance already exists")); 3.600 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); 3.601 - goto exit; 3.602 - } 3.603 - 3.604 - /* Create a new resource with the new instance property values. */ 3.605 - int rc = Xen_Processor_createResourceFromInstance(resources, &resource, newinstance, _BROKER); 3.606 - if (rc != 1) { 3.607 - if (rc == -1) { 3.608 - _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); 3.609 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 3.610 - } else { 3.611 - _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); 3.612 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); 3.613 + if (res_list) { 3.614 + _RESOURCE *res = ((_RESOURCES *)res_list)->vcpus; 3.615 + while (res) { 3.616 + free(res->domain_name); 3.617 + _RESOURCE *temp = res->next; 3.618 + free(res); 3.619 + res = temp; 3.620 } 3.621 - goto exit; 3.622 + free(res_list); 3.623 } 3.624 - 3.625 - /* Return the object path for the newly created instance. */ 3.626 - CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); 3.627 - CMSetNameSpace(objectpath, namespace); 3.628 - CMReturnObjectPath(results, objectpath); 3.629 - CMReturnDone(results); 3.630 - 3.631 -exit: 3.632 - /* Free the list of system resources. */ 3.633 - if (!Xen_Processor_freeResources(resources)) { 3.634 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.635 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.636 - } 3.637 - 3.638 - _SBLIM_RETURNSTATUS(status); 3.639 -} 3.640 - 3.641 -// ---------------------------------------------------------------------------- 3.642 -// DeleteInstance() 3.643 -// Delete or remove the specified instance from the system. 3.644 -// ---------------------------------------------------------------------------- 3.645 -static CMPIStatus DeleteInstance( 3.646 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.647 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.648 - const CMPIResult * results, /* [out] Results of this operation. */ 3.649 - const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ 3.650 -{ 3.651 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.652 - _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ 3.653 - _RESOURCE * resource; /* Handle to the system resource. */ 3.654 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.655 - int found = 0; /* Found the target instance? */ 3.656 - 3.657 - _SBLIM_ENTER("DeleteInstance"); 3.658 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.659 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.660 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.661 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.662 - 3.663 - if (!xen_utils_validate_session(&session)) { 3.664 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 3.665 - goto exit; 3.666 - } 3.667 - 3.668 - /* Get a handle to the list of system resources. */ 3.669 - if (!Xen_Processor_getResources(session, &resources)) { 3.670 - _SBLIM_TRACE(1,("--- _getResources() failed")); 3.671 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 3.672 - goto exit; 3.673 - } 3.674 - 3.675 - /* Get the target resource. */ 3.676 - found = Xen_Processor_getResourceForObjectPath(session, resources, &resource, reference); 3.677 - if (!found || (resource == NULL)) { 3.678 - _SBLIM_TRACE(1,("--- Target instance not found")); 3.679 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 3.680 - goto exit; 3.681 - } 3.682 - 3.683 - _SBLIM_TRACE(2,("--- instance found", found)); 3.684 - 3.685 - /* Delete the target resource. */ 3.686 - int rc = Xen_Processor_deleteResource(resources, resource); 3.687 - 3.688 - /* Free the resource data. */ 3.689 - if (!Xen_Processor_freeResource(resource)) { 3.690 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 3.691 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 3.692 - goto exit; 3.693 - } 3.694 - 3.695 - if (rc != 1) { 3.696 - if (rc == -1) { 3.697 - _SBLIM_TRACE(1,("--- __deleteResource() unsupported")); 3.698 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 3.699 - } else { 3.700 - _SBLIM_TRACE(1,("--- _deleteResource() failed")); 3.701 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource"); 3.702 - } 3.703 - goto exit; 3.704 - } 3.705 - 3.706 -exit: 3.707 - /* Free the list of system resources. */ 3.708 - if (!Xen_Processor_freeResources(resources)) { 3.709 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 3.710 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 3.711 - } 3.712 - 3.713 - _SBLIM_RETURNSTATUS(status); 3.714 } 3.715 3.716 3.717 -// ---------------------------------------------------------------------------- 3.718 -// ExecQuery() 3.719 -// Return a list of all the instances that satisfy the specified query filter. 3.720 -// ---------------------------------------------------------------------------- 3.721 -static CMPIStatus ExecQuery( 3.722 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.723 - const CMPIContext * context, /* [in] Additional context info, if any. */ 3.724 - const CMPIResult * results, /* [out] Results of this operation. */ 3.725 - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ 3.726 - const char * language, /* [in] Name of the query language. */ 3.727 - const char * query) /* [in] Text of the query written in the query language. */ 3.728 +/* Iterator to get the next resource from the resources list. */ 3.729 +static int getNext(void *res_list, void **res, CMPIStatus *status) 3.730 { 3.731 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 3.732 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 3.733 + _RESOURCES *resources = (_RESOURCES *)res_list; 3.734 + _RESOURCE *resource; 3.735 + 3.736 + if (resources == NULL) 3.737 + return 0; 3.738 + 3.739 + if (resources->cur_vcpu == NULL) 3.740 + return 0; 3.741 + 3.742 + /* A resource's life is independent of resources list. Make a copy. */ 3.743 + resource = (_RESOURCE *)malloc(sizeof(_RESOURCE)); 3.744 + if (resource == NULL) { 3.745 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.746 + ("--- Failed to malloc memory for processor resource")); 3.747 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.748 + "Failed to malloc memory for processor resource"); 3.749 + return 0; 3.750 + } 3.751 + 3.752 + resource->vcpu_id = resources->cur_vcpu->vcpu_id; 3.753 + resource->domain_name = strdup(resources->cur_vcpu->domain_name); 3.754 + 3.755 + /* Move to the next resource in the list. */ 3.756 + resources->cur_vcpu = resources->cur_vcpu->next; 3.757 + 3.758 + *res = resource; 3.759 + return 1; 3.760 +} 3.761 + 3.762 3.763 - _SBLIM_ENTER("ExecQuery"); 3.764 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.765 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.766 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 3.767 - _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); 3.768 - _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); 3.769 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 3.770 +static int get(void *res_list, void **res, CMPIStatus *status) 3.771 +{ 3.772 + if (res == NULL || *res == NULL) 3.773 + return 0; 3.774 + /* 3.775 + * WARNING! 3.776 + * What needs to be done here? It looks as though inst2res() will have 3.777 + * been called on parameter res before a call to this function - in 3.778 + * which case res will be populated. 3.779 + */ 3.780 + return 1; 3.781 +} 3.782 + 3.783 3.784 - /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ 3.785 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 3.786 +static void release(void *res) 3.787 +{ 3.788 + _RESOURCE *resource = (_RESOURCE *)res; 3.789 + 3.790 + if (resource) { 3.791 + if (resource->domain_name) 3.792 + free(resource->domain_name); 3.793 + free(resource); 3.794 + } 3.795 +} 3.796 + 3.797 3.798 - CMReturnDone(results); 3.799 +static int add(void **res_list, void *res, CMPIStatus *status) 3.800 +{ 3.801 + return -1; /* unsupported */ 3.802 +} 3.803 + 3.804 3.805 -exit: 3.806 - _SBLIM_RETURNSTATUS(status); 3.807 +static int delete(void **res_list, void *res, CMPIStatus *status) 3.808 +{ 3.809 + return -1; /* unsupported */ 3.810 +} 3.811 + 3.812 + 3.813 +static int modify(void **res_list, void *res, CMPIStatus *status) 3.814 +{ 3.815 + return -1; /* unsupported */ 3.816 } 3.817 3.818 -// ---------------------------------------------------------------------------- 3.819 -// Initialize() 3.820 -// Perform any necessary initialization immediately after this provider is 3.821 -// first loaded. 3.822 -// ---------------------------------------------------------------------------- 3.823 -static void Initialize( 3.824 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 3.825 - const CMPIContext * context) /* [in] Additional context info, if any. */ 3.826 + 3.827 +/* Set CMPIInstance properties from the resource data. */ 3.828 +static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status) 3.829 { 3.830 - _SBLIM_ENTER("Initialize"); 3.831 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 3.832 - // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 3.833 + if (res == NULL) 3.834 + return 0; 3.835 + if (CMIsNullObject(inst)) 3.836 + return 0; 3.837 + 3.838 + _RESOURCE *resource = (_RESOURCE *)res; 3.839 3.840 - /* Initialized Xen session object. */ 3.841 - if (session == NULL) 3.842 - xen_utils_xen_init(&session); 3.843 + /* Set the CMPIInstance properties from the resource data. */ 3.844 + CMSetProperty(inst, "SystemCreationClassName", 3.845 + (CMPIValue *)"Xen_ComputerSystem", CMPI_chars); 3.846 + CMSetProperty(inst, "SystemName", 3.847 + (CMPIValue *)resource->domain_name, CMPI_chars); 3.848 + CMSetProperty(inst, "CreationClassName", 3.849 + (CMPIValue *)"Xen_Processor", CMPI_chars); 3.850 + 3.851 + char deviceid[1024]; 3.852 + sprintf(deviceid, "VCPU%d", resource->vcpu_id); 3.853 + CMSetProperty(inst, "DeviceID",(CMPIValue *)deviceid, CMPI_chars); 3.854 3.855 - _SBLIM_RETURN(); 3.856 + CMSetProperty(inst, "Caption",(CMPIValue *)"Processor", CMPI_chars); 3.857 + CMSetProperty(inst, "Description", 3.858 + (CMPIValue *)"Xen Virtual Processor", CMPI_chars); 3.859 + CMSetProperty(inst, "Purpose",(CMPIValue *)"Processor", CMPI_chars); 3.860 + CMSetProperty(inst, "Name",(CMPIValue *)deviceid, CMPI_chars); 3.861 + CMSetProperty(inst, "Status", (CMPIValue *)"OK", CMPI_chars); 3.862 + 3.863 + return 1; 3.864 } 3.865 3.866 -// ============================================================================ 3.867 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP 3.868 -// ============================================================================ 3.869 -CMInstanceMIStub( , Xen_Processor, _BROKER, Initialize(&mi, ctx)); 3.870 + 3.871 +/* Set resource data from the CMPIInstance properties. */ 3.872 +static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status) 3.873 +{ 3.874 + CMPIData data; 3.875 + char *prop_val; 3.876 + _RESOURCE *resource; 3.877 + 3.878 + if (CMIsNullObject(inst) || res == NULL) 3.879 + return 0; 3.880 + 3.881 + /* Obtain the target domain name from instance's "SystemName" property. */ 3.882 + data = CMGetProperty(inst, "SystemName", status); 3.883 + if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data)) 3.884 + return 0; 3.885 + 3.886 + prop_val = CMGetCharPtr(data.value.string); 3.887 + if ((prop_val == NULL) || (*prop_val == '\0')) 3.888 + return 0; 3.889 + 3.890 + /* Create resource. */ 3.891 + resource = (_RESOURCE *)malloc(sizeof(_RESOURCE)); 3.892 + if (resource == NULL) { 3.893 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.894 + ("--- Failed to malloc memory for processor resource")); 3.895 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, 3.896 + "Failed to malloc memory for processor resource"); 3.897 + return 0; 3.898 + } 3.899 + 3.900 + /* Populate domain_name and vcpu_id fields. */ 3.901 + resource->domain_name = strdup(prop_val); 3.902 + 3.903 + /* Set the vcpu_id from the DeviceID */ 3.904 + data = CMGetProperty(inst, "DeviceID", status); 3.905 + if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data)) { 3.906 + free(resource->domain_name); 3.907 + free(resource); 3.908 + return 0; 3.909 + } 3.910 + 3.911 + prop_val = CMGetCharPtr(data.value.string); 3.912 + if ((prop_val == NULL) || (*prop_val == '\0')) { 3.913 + free(resource->domain_name); 3.914 + free(resource); 3.915 + return 0; 3.916 + } 3.917 + 3.918 + char *p; 3.919 + if ((p = strstr(prop_val, "VCPU")) == NULL) { 3.920 + free(resource->domain_name); 3.921 + free(resource); 3.922 + return 0; 3.923 + } 3.924 + 3.925 + resource->vcpu_id = atoi(p + 4); 3.926 + 3.927 + *res = (void *)resource; 3.928 + return 1; 3.929 +} 3.930 + 3.931 + 3.932 +/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/ 3.933 +/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */ 3.934 +CMPILRInstanceMIStub(Xen_Processor, Xen_Processor, mi)
4.1 --- a/src/Xen_Processor_Resource.c Mon Jun 04 16:47:54 2007 -0600 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,271 +0,0 @@ 4.4 -// Copyright (C) 2006 IBM Corporation 4.5 -// 4.6 -// This library is free software; you can redistribute it and/or 4.7 -// modify it under the terms of the GNU Lesser General Public 4.8 -// License as published by the Free Software Foundation; either 4.9 -// version 2.1 of the License, or (at your option) any later version. 4.10 -// 4.11 -// This library is distributed in the hope that it will be useful, 4.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 4.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 4.14 -// Lesser General Public License for more details. 4.15 -// 4.16 -// You should have received a copy of the GNU Lesser General Public 4.17 -// License along with this library; if not, write to the Free Software 4.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 4.19 -// ============================================================================ 4.20 -// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 4.21 -// Tokunbo Adeshiyan, <tokunbo@us.ibm.com> 4.22 -// Contributors: Jim Fehlig, <jfehlig@novell.com> 4.23 -// Raj Subrahmanian <raj.subrahmanian@unisys.com> 4.24 -// Description: 4.25 -// ============================================================================ 4.26 - 4.27 -#include <stdlib.h> 4.28 -#include <assert.h> 4.29 - 4.30 -#include <xen_common.h> 4.31 -#include <xen_vm.h> 4.32 -#include <xen_vm_metrics.h> 4.33 - 4.34 -#include "Xen_Processor_Resource.h" 4.35 - 4.36 -/* Include the required CMPI data types, function headers, and macros. */ 4.37 -#include "cmpidt.h" 4.38 -#include "cmpift.h" 4.39 -#include "cmpimacs.h" 4.40 - 4.41 -#include "xen_utils.h" 4.42 - 4.43 -// ---------------------------------------------------------------------------- 4.44 - 4.45 -/* Get a handle to the list of all system resources for this class. */ 4.46 -int Xen_Processor_getResources(xen_utils_session *session, 4.47 - _RESOURCES ** resources) 4.48 -{ 4.49 - /* malloc a new handle for the resources list. */ 4.50 - *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); 4.51 - if (*resources == NULL) return 0; 4.52 - 4.53 - if (!xen_utils_get_domain_resources(session, &((*resources)->domains))) { 4.54 - free(*resources); 4.55 - *resources = NULL; 4.56 - return 0; 4.57 - } 4.58 - 4.59 - /* Start iterating from the first processor of the first Xen domain name. */ 4.60 - (*resources)->currentprocessornum = 0; 4.61 - return 1; 4.62 -} 4.63 - 4.64 -// ---------------------------------------------------------------------------- 4.65 - 4.66 -/* Free/deallocate/cleanup the resources list after use. */ 4.67 -int Xen_Processor_freeResources(_RESOURCES * resources) 4.68 -{ 4.69 - if (resources != NULL) { 4.70 - if (resources->domains != NULL) 4.71 - xen_utils_free_domain_resources(resources->domains); 4.72 - free(resources); 4.73 - resources = NULL; 4.74 - } 4.75 - 4.76 - return 1; 4.77 -} 4.78 - 4.79 -// ---------------------------------------------------------------------------- 4.80 -// This function was changed to extract the vcpus_number value from the metrics structure rather 4.81 -// Raj - 04/04/2007 4.82 -/* Iterator to get the next resource from the resources list. */ 4.83 -int Xen_Processor_getNextResource(xen_utils_session *session, 4.84 - _RESOURCES * resources, 4.85 - _RESOURCE ** resource) 4.86 -{ 4.87 - int64_t vcpus_number; 4.88 - if (resources == NULL) return 0; 4.89 - 4.90 - /* Check if reached the end of the list of Xen domain names. */ 4.91 - if (!XEN_UTILS_MORE_DOMAIN_RESOURCES(resources->domains)) 4.92 - return 0; 4.93 - 4.94 - /* Get the current domain. */ 4.95 - if (!xen_utils_get_current_domain_resource(session, resources->domains, resource)) 4.96 - return 0; 4.97 - 4.98 - /* Only serve up processors if the domain is not halted */ 4.99 - if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED) 4.100 - goto NextDomain; 4.101 - 4.102 - /* Move to the next resource in the list. 4.103 - * Note this implies processor numbers start at 1. */ 4.104 - resources->currentprocessornum++; 4.105 - 4.106 - /* Return success while there are still processor devices for this domain. */ 4.107 - // Get the vcpus_number 4.108 - if ((*resource)->metrics->is_record) 4.109 - vcpus_number=(*resource)->metrics->u.record->vcpus_number; 4.110 - else 4.111 - xen_vm_metrics_get_vcpus_number(session->xen, &vcpus_number, (*resource)->metrics->u.handle); 4.112 - if (resources->currentprocessornum <= vcpus_number) 4.113 - return 1; 4.114 - 4.115 - NextDomain: 4.116 - /* All processors in this domain have been exhausted. */ 4.117 - /* Start serving up processors for the next domain, if it exists */ 4.118 - Xen_Processor_freeResource(*resource); 4.119 - XEN_UTILS_INC_DOMAIN_RESOURCE_COUNT(resources->domains); 4.120 - if (!XEN_UTILS_MORE_DOMAIN_RESOURCES(resources->domains)) 4.121 - return 0; 4.122 - 4.123 - /* Get the next domain resource. */ 4.124 - if (!xen_utils_get_current_domain_resource(session, resources->domains, resource)) 4.125 - return 0; 4.126 - 4.127 - /* Only serve up processors if the domain is not inactive */ 4.128 - if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED) 4.129 - goto NextDomain; 4.130 - 4.131 - /* Start at the first processor for this 'next' domain. */ 4.132 - resources->currentprocessornum = 1; 4.133 - 4.134 - return 1; 4.135 -} 4.136 - 4.137 -// ---------------------------------------------------------------------------- 4.138 - 4.139 -/* Get the specific resource that matches the CMPI object path. */ 4.140 -int Xen_Processor_getResourceForObjectPath(xen_utils_session *session, 4.141 - _RESOURCES * resources, 4.142 - _RESOURCE ** resource, 4.143 - const CMPIObjectPath * objectpath) 4.144 -{ 4.145 - CMPIData namedata; 4.146 - char *keyvalue; 4.147 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.148 - 4.149 - if (resources == NULL) return 0; 4.150 - if (CMIsNullObject(objectpath)) return 0; 4.151 - 4.152 - /* Obtain the target domain name from the CMPIObjectPath "SystemName" key. */ 4.153 - namedata = CMGetKey(objectpath, "SystemName", &status); 4.154 - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0; 4.155 - 4.156 - /* Extract the domain name string from the CMPIString. */ 4.157 - keyvalue = CMGetCharPtr(namedata.value.string); 4.158 - if ((keyvalue == NULL) || (*keyvalue == '\0')) return 0; 4.159 - 4.160 - /* Get the domain data for the target domain name. */ 4.161 - xen_vm_set *vms; 4.162 - if (!xen_vm_get_by_name_label(session->xen, &vms, keyvalue)) { 4.163 - /* Error is in session object! */ 4.164 - *resource = NULL; 4.165 - return 0; 4.166 - } 4.167 - 4.168 - assert(vms->size == 1); 4.169 - if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) { 4.170 - /* Error description in session object! */ 4.171 - xen_vm_set_free(vms); 4.172 - return 0; 4.173 - } 4.174 - 4.175 - xen_vm_set_free(vms); 4.176 - 4.177 - /* Set the currentprocessornum from the DeviceID */ 4.178 - namedata = CMGetKey(objectpath, "DeviceID", &status); 4.179 - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) { 4.180 - Xen_Processor_freeResource(*resource); 4.181 - return 0; 4.182 - } 4.183 - 4.184 - keyvalue = CMGetCharPtr(namedata.value.string); 4.185 - if ((keyvalue == NULL) || (*keyvalue == '\0')) { 4.186 - Xen_Processor_freeResource(*resource); 4.187 - return 0; 4.188 - } 4.189 - 4.190 - char *p; 4.191 - if ((p = strstr(keyvalue, "CPU")) == NULL) { 4.192 - Xen_Processor_freeResource(*resource); 4.193 - return 0; 4.194 - } 4.195 - else 4.196 - resources->currentprocessornum = atoi(p + 3); 4.197 - 4.198 - return 1; 4.199 -} 4.200 - 4.201 -// ---------------------------------------------------------------------------- 4.202 - 4.203 -/* Free/deallocate/cleanup the resource after use. */ 4.204 -int Xen_Processor_freeResource(_RESOURCE * resource) 4.205 -{ 4.206 - return xen_utils_free_domain_resource(resource); 4.207 -} 4.208 - 4.209 -// ---------------------------------------------------------------------------- 4.210 - 4.211 -/* Set the property values of a CMPI instance from a specific resource. */ 4.212 -int Xen_Processor_setInstanceFromResource(_RESOURCE * resource, 4.213 - const CMPIInstance * instance, 4.214 - const CMPIBroker * broker, 4.215 - _RESOURCES * resources) 4.216 -{ 4.217 - if (resource == NULL) return 0; 4.218 - if (CMIsNullObject(instance)) return 0; 4.219 - 4.220 - /* Set the CMPIInstance properties from the resource data. */ 4.221 - CMSetProperty(instance, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars); 4.222 - CMSetProperty(instance, "SystemName",(CMPIValue *)resource->name_label, CMPI_chars); 4.223 - CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_Processor", CMPI_chars); 4.224 - 4.225 - char deviceid[1024]; 4.226 - sprintf(deviceid, "CPU%d", resources->currentprocessornum); 4.227 - CMSetProperty(instance, "DeviceID",(CMPIValue *)deviceid, CMPI_chars); 4.228 - 4.229 - CMSetProperty(instance, "Caption",(CMPIValue *)"Processor", CMPI_chars); 4.230 - CMSetProperty(instance, "Description",(CMPIValue *)"Processor", CMPI_chars); 4.231 - CMSetProperty(instance, "Purpose",(CMPIValue *)"Processor", CMPI_chars); 4.232 - CMSetProperty(instance, "Name",(CMPIValue *)deviceid, CMPI_chars); 4.233 - 4.234 - if (resource->power_state != XEN_VM_POWER_STATE_HALTED) { 4.235 - CMSetProperty(instance, "Status", (CMPIValue *)"OK", CMPI_chars); 4.236 - } else { 4.237 - CMSetProperty(instance, "Status", (CMPIValue *)"No Contact", CMPI_chars); 4.238 - } 4.239 - 4.240 - return 1; 4.241 -} 4.242 - 4.243 -// ---------------------------------------------------------------------------- 4.244 - 4.245 -/* Delete the specified resource from the system. */ 4.246 -int Xen_Processor_deleteResource(_RESOURCES * resources, _RESOURCE * resource) 4.247 -{ 4.248 - /* Unsupported. */ 4.249 - return -1; 4.250 -} 4.251 - 4.252 -// ---------------------------------------------------------------------------- 4.253 - 4.254 -/* Modify the specified resource using the property values of a CMPI instance. */ 4.255 -int Xen_Processor_setResourceFromInstance(_RESOURCE * resource, 4.256 - const CMPIInstance * instance, 4.257 - const CMPIBroker * broker) 4.258 -{ 4.259 - /* Unsupported. */ 4.260 - return -1; 4.261 -} 4.262 - 4.263 -// ---------------------------------------------------------------------------- 4.264 - 4.265 -/* Create a new resource using the property values of a CMPI instance. */ 4.266 -int Xen_Processor_createResourceFromInstance(_RESOURCES * resources, 4.267 - _RESOURCE ** resource, 4.268 - const CMPIInstance * instance, 4.269 - const CMPIBroker * broker) 4.270 -{ 4.271 - /* Unsupported. */ 4.272 - return -1; 4.273 -} 4.274 -
5.1 --- a/src/Xen_Processor_Resource.h Mon Jun 04 16:47:54 2007 -0600 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,103 +0,0 @@ 5.4 -// Copyright (C) 2006 IBM Corporation 5.5 -// 5.6 -// This library is free software; you can redistribute it and/or 5.7 -// modify it under the terms of the GNU Lesser General Public 5.8 -// License as published by the Free Software Foundation; either 5.9 -// version 2.1 of the License, or (at your option) any later version. 5.10 -// 5.11 -// This library is distributed in the hope that it will be useful, 5.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 5.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 5.14 -// Lesser General Public License for more details. 5.15 -// 5.16 -// You should have received a copy of the GNU Lesser General Public 5.17 -// License along with this library; if not, write to the Free Software 5.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 5.19 -// ============================================================================ 5.20 -// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 5.21 -// Tokunbo Adeshiyan, <tokunbo@us.ibm.com> 5.22 -// Contributors: Jim Fehlig, <jfehlig@novell.com> 5.23 -// Description: 5.24 -// ============================================================================ 5.25 - 5.26 -/* Include required libxen headers. */ 5.27 -#include <xen_common.h> 5.28 -#include <xen_vm.h> 5.29 - 5.30 -#include "xen_utils.h" 5.31 - 5.32 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 5.33 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. 5.34 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS 5.35 - LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. 5.36 - THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN 5.37 - ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ 5.38 -typedef struct { 5.39 - xen_domain_resources *domains; 5.40 - unsigned int currentprocessornum; 5.41 -} _RESOURCES; 5.42 - 5.43 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 5.44 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. 5.45 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH 5.46 - RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE 5.47 - PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE 5.48 - ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ 5.49 -typedef xen_vm_record _RESOURCE; 5.50 - 5.51 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ 5.52 - 5.53 -/* Include the required CMPI data types. */ 5.54 -#include "cmpidt.h" 5.55 - 5.56 -// ---------------------------------------------------------------------------- 5.57 -// Generic resource access methods for CMPI providers. 5.58 -// Return value: 5.59 -// -1 = Unsupported 5.60 -// 0 = Failed 5.61 -// 1 = OK 5.62 -// ---------------------------------------------------------------------------- 5.63 - 5.64 -/* Get a handle to the list of all system resources for this class. */ 5.65 -int Xen_Processor_getResources(xen_utils_session *session, 5.66 - _RESOURCES ** resources); 5.67 - 5.68 -/* Free/deallocate/cleanup the resources list after use. */ 5.69 -int Xen_Processor_freeResources( _RESOURCES * resources ); 5.70 - 5.71 -/* Iterator to get the next resource from the resources list. */ 5.72 -int Xen_Processor_getNextResource(xen_utils_session *session, 5.73 - _RESOURCES * resources, 5.74 - _RESOURCE ** resource); 5.75 - 5.76 -/* Get the specific resource that matches the CMPI object path. */ 5.77 -int Xen_Processor_getResourceForObjectPath(xen_utils_session *session, 5.78 - _RESOURCES * resources, 5.79 - _RESOURCE ** resource, 5.80 - const CMPIObjectPath * objectpath); 5.81 - 5.82 -/* Free/deallocate/cleanup a resource after use. */ 5.83 -int Xen_Processor_freeResource(_RESOURCE * resource); 5.84 - 5.85 -/* Set the property values of a CMPI instance from a specific resource. */ 5.86 -int Xen_Processor_setInstanceFromResource(_RESOURCE * resource, 5.87 - const CMPIInstance * instance, 5.88 - const CMPIBroker * broker, 5.89 - _RESOURCES * resources); 5.90 - 5.91 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS 5.92 - 5.93 -/* Delete the specified resource from the system. */ 5.94 -int Xen_Processor_deleteResource(_RESOURCES * resources, _RESOURCE * resource); 5.95 - 5.96 -/* Modify the specified resource using the property values of a CMPI instance. */ 5.97 -int Xen_Processor_setResourceFromInstance(_RESOURCE * resource, 5.98 - const CMPIInstance * instance, 5.99 - const CMPIBroker * broker); 5.100 - 5.101 -/* Create a new resource using the property values of a CMPI instance. */ 5.102 -int Xen_Processor_createResourceFromInstance(_RESOURCES * resources, 5.103 - _RESOURCE ** resource, 5.104 - const CMPIInstance * instance, 5.105 - const CMPIBroker * broker); 5.106 -