os-cmpi-xen

diff src/Xen_ProcessorPool.c @ 137:26f10941718e

Ported Xen_ProcessorPool to 'Cmpilify' interface.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jul 27 15:57:34 2007 -0600 (2007-07-27)
parents 75b18359b74d
children
line diff
     1.1 --- a/src/Xen_ProcessorPool.c	Fri Jul 27 10:28:41 2007 -0600
     1.2 +++ b/src/Xen_ProcessorPool.c	Fri Jul 27 15:57:34 2007 -0600
     1.3 @@ -1,4 +1,4 @@
     1.4 -// Copyright (C) 2006 IBM Corporation
     1.5 +// Copyright (C) 2007 Novell, Inc.
     1.6  //
     1.7  //    This library is free software; you can redistribute it and/or
     1.8  //    modify it under the terms of the GNU Lesser General Public
     1.9 @@ -15,626 +15,159 @@
    1.10  //    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.11  // ============================================================================
    1.12  // Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    1.13 -//                Jim Fehlig, <jfehlig@novell.com>
    1.14 -// Contributors:
    1.15 -// Description:
    1.16 +// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    1.17 +// Description:   Xen implementation of CIM_ResourcePool for CPU.
    1.18  // ============================================================================
    1.19  
    1.20 -#include <string.h>
    1.21 -
    1.22 -/* Include the required CMPI data types, function headers, and macros */
    1.23 -#include "cmpidt.h"
    1.24 -#include "cmpift.h"
    1.25 -#include "cmpimacs.h"
    1.26 -
    1.27 -#include "provider_common.h"
    1.28 +/* Common declarations for each CMPI "Cimpler" instance provider */
    1.29 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    1.30 +#include <cmpidt.h>
    1.31 +#include <cmpimacs.h>
    1.32  
    1.33 -// ----------------------------------------------------------------------------
    1.34 -// COMMON GLOBAL VARIABLES
    1.35 -// ----------------------------------------------------------------------------
    1.36 -
    1.37 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    1.38 -static const CMPIBroker *_BROKER;
    1.39 +#include "cmpilify.h"
    1.40  
    1.41 -/* Include utility functions */
    1.42 -#include "cmpiutil.h"
    1.43  
    1.44 -/* Include _SBLIM_TRACE() logging support */
    1.45 -#include "cmpitrace.h"
    1.46 -
    1.47 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    1.48 -#include "Xen_ProcessorPool_Resource.h"
    1.49 +static const CMPIInstanceMI* mi;
    1.50  
    1.51  
    1.52 -// ============================================================================
    1.53 -// CMPI INSTANCE PROVIDER FUNCTION TABLE
    1.54 -// ============================================================================
    1.55 +#define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
    1.56 +#define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
    1.57 +#define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
    1.58  
    1.59 -// ----------------------------------------------------------------------------
    1.60 -// Info for the class supported by the instance provider
    1.61 -// ----------------------------------------------------------------------------
    1.62 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    1.63 +
    1.64 +#include <stdlib.h>
    1.65  
    1.66 -/* Name of the class implemented by this instance provider. */
    1.67 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    1.68 -static char * _CLASSNAME = "Xen_ProcessorPool";
    1.69 +#include <xen_common.h>
    1.70 +#include <xen_host.h>
    1.71 +#include <xen_host_cpu.h>
    1.72  
    1.73 -/* NULL terminated list of key properties of this class. */
    1.74 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    1.75 -const static char * _KEYNAMES[] = {"InstanceID", NULL};
    1.76 +#include "cmpitrace.h"
    1.77 +#include "xen_utils.h"
    1.78 +#include "provider_common.h"
    1.79  
    1.80 -// ----------------------------------------------------------------------------
    1.81 -// Cleanup()
    1.82 -// Perform any necessary cleanup immediately before this provider is unloaded.
    1.83 -// ----------------------------------------------------------------------------
    1.84 -static CMPIStatus Cleanup(
    1.85 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
    1.86 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
    1.87 -      CMPIBoolean terminating)   /* [in] True if MB is terminating */
    1.88 +/* Class keys */
    1.89 +static const char *keys[] = {"InstanceID", NULL};
    1.90 +
    1.91 +
    1.92 +/* Xen session object.  Initialize when the provider is loaded, close when
    1.93 + * provider unloaded. */
    1.94 +static xen_utils_session *session = NULL;
    1.95 +
    1.96 +
    1.97 +static CMPIrc load()
    1.98  {
    1.99 -   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
   1.100 +   /* Initialized Xen session object. */
   1.101 +   if (!session)
   1.102 +      xen_utils_xen_init(&session);
   1.103  
   1.104 -   _SBLIM_ENTER("Cleanup");
   1.105 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.106 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.107 -
   1.108 -   /* Nothing needs to be done for cleanup. */
   1.109 -   _SBLIM_RETURNSTATUS(status);
   1.110 +   return CMPI_RC_OK;
   1.111  }
   1.112  
   1.113 -// ----------------------------------------------------------------------------
   1.114 -// EnumInstanceNames()
   1.115 -// Return a list of all the instances names (return their object paths only).
   1.116 -// ----------------------------------------------------------------------------
   1.117 -static CMPIStatus EnumInstanceNames(
   1.118 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.119 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.120 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.121 -		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   1.122 -{
   1.123 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.124 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.125 -   _RESOURCE * resource;			/* Handle to each system resource. */
   1.126 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.127 -   int found = 0;				/* Found any instances? */
   1.128 -  
   1.129 -   _SBLIM_ENTER("EnumInstanceNames");
   1.130 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.131 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.132 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.133 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.134  
   1.135 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.136 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.137 -      goto exit;
   1.138 -   }
   1.139 -
   1.140 -   /* Get a handle to the list of system resources. */
   1.141 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.142 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.143 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.144 -      goto exit;
   1.145 -   }
   1.146 -
   1.147 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   1.148 -   while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
   1.149 -      /* Create a new CMPIInstance to store this resource. */
   1.150 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   1.151 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   1.152 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   1.153 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   1.154 -         goto exit;
   1.155 -      }
   1.156 -
   1.157 -      /* Set the instance property values from the resource data. */
   1.158 -      if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   1.159 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   1.160 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   1.161 -         goto exit;
   1.162 -      }
   1.163 -
   1.164 -      /* Free the resource data. */
   1.165 -      if (!Xen_ProcessorPool_freeResource(resource)) {
   1.166 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.167 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.168 -         goto exit;
   1.169 -      }
   1.170 -
   1.171 -      /* Return the CMPIObjectPath for this instance. */
   1.172 -      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   1.173 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   1.174 -         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   1.175 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   1.176 -         goto exit;
   1.177 -      }
   1.178 -      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   1.179 -     
   1.180 -      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   1.181 -      CMReturnObjectPath(results, objectpath);
   1.182 -      found++;
   1.183 -   }
   1.184 -
   1.185 -   _SBLIM_TRACE(2,("--- %d object paths found", found));
   1.186 -   CMReturnDone(results);
   1.187 -
   1.188 -exit:
   1.189 -   /* Free the list of system resources. */
   1.190 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.191 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.192 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.193 -   }
   1.194 -  
   1.195 -   _SBLIM_RETURNSTATUS(status);
   1.196 -}
   1.197 -
   1.198 -// ----------------------------------------------------------------------------
   1.199 -// EnumInstances()
   1.200 -// Return a list of all the instances (return all the instance data).
   1.201 -// ----------------------------------------------------------------------------
   1.202 -static CMPIStatus EnumInstances(
   1.203 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.204 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.205 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.206 -		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   1.207 -		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   1.208 +static CMPIrc unload(const int terminating)
   1.209  {
   1.210 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.211 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.212 -   _RESOURCE * resource;			/* Handle to each system resource. */
   1.213 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.214 -   int found = 0;				/* Found any resource instances? */
   1.215 -
   1.216 -   _SBLIM_ENTER("EnumInstances");
   1.217 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.218 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.219 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.220 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.221 -
   1.222 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.223 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.224 -      goto exit;
   1.225 -   }
   1.226 -
   1.227 -   /* Get a handle to the list of system resources. */
   1.228 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.229 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.230 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.231 -      goto exit;
   1.232 -   }
   1.233 -
   1.234 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   1.235 -   while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
   1.236 -      /* Create a new CMPIInstance to store this resource. */
   1.237 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   1.238 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   1.239 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   1.240 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   1.241 -         goto exit;
   1.242 -      }
   1.243 -
   1.244 -      /* Setup a filter to only return the desired properties. */
   1.245 -      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   1.246 -      if (status.rc != CMPI_RC_OK) {
   1.247 -         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   1.248 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   1.249 -         goto exit;
   1.250 -      }
   1.251 -
   1.252 -      /* Set the instance property values from the resource data. */
   1.253 -      if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   1.254 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   1.255 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   1.256 -         goto exit;
   1.257 -      }
   1.258 -
   1.259 -      /* Free the resource data. */
   1.260 -      if (!Xen_ProcessorPool_freeResource(resource)) {
   1.261 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.262 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.263 -         goto exit;
   1.264 -      }
   1.265 -
   1.266 -      /* Return the CMPIInstance for this instance. */
   1.267 -      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   1.268 -      CMReturnInstance(results, instance);
   1.269 -      found++;
   1.270 -   }
   1.271 -
   1.272 -   _SBLIM_TRACE(2,("--- %d instances found", found));
   1.273 -   CMReturnDone(results);
   1.274 -
   1.275 -exit:
   1.276 -   /* Free the list of system resources. */
   1.277 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.278 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.279 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.280 -   }
   1.281 -
   1.282 -   _SBLIM_RETURNSTATUS(status);
   1.283 -}
   1.284 -
   1.285 -// ----------------------------------------------------------------------------
   1.286 -// GetInstance()
   1.287 -// Return the instance data for the specified instance only.
   1.288 -// ----------------------------------------------------------------------------
   1.289 -static CMPIStatus GetInstance(
   1.290 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.291 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.292 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.293 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   1.294 -		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   1.295 -{
   1.296 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.297 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.298 -   _RESOURCE * resource;			/* Handle to the system resource. */
   1.299 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.300 -   int found = 0;				/* Found the target instance? */
   1.301 -
   1.302 -   _SBLIM_ENTER("GetInstance");
   1.303 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.304 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.305 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.306 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.307 -
   1.308 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.309 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.310 -      goto exit;
   1.311 -   }
   1.312 -
   1.313 -   /* Get a handle to the list of system resources. */
   1.314 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.315 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.316 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.317 -      goto exit;
   1.318 -   }
   1.319 -
   1.320 -   /* Get the target resource. */
   1.321 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   1.322 -   if (!found || (resource == NULL)) {
   1.323 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   1.324 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   1.325 -      goto exit;
   1.326 +   (void)terminating;
   1.327 +   
   1.328 +   /* Close Xen session object. */
   1.329 +   if (session) {
   1.330 +      xen_utils_xen_close(session);
   1.331 +      session = NULL;
   1.332     }
   1.333  
   1.334 -   /* Create a new CMPIInstance to store this resource. */
   1.335 -   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   1.336 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   1.337 -      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   1.338 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   1.339 -      goto exit;
   1.340 -   }
   1.341 -
   1.342 -   /* Setup a filter to only return the desired properties. */
   1.343 -   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   1.344 -   if (status.rc != CMPI_RC_OK) {
   1.345 -      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   1.346 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   1.347 -      goto exit;
   1.348 -   }
   1.349 -
   1.350 -   /* Set the instance property values from the resource data. */
   1.351 -   if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   1.352 -      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   1.353 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   1.354 -      goto exit;
   1.355 -   }
   1.356 -
   1.357 -   /* Free the resource data. */
   1.358 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   1.359 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.360 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.361 -      goto exit;
   1.362 -   }
   1.363 -
   1.364 -   /* Return the CMPIInstance for this instance. */
   1.365 -   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   1.366 -   CMReturnInstance(results, instance);
   1.367 -
   1.368 -   _SBLIM_TRACE(2,("--- instance found"));
   1.369 -   CMReturnDone(results);
   1.370 -
   1.371 -exit:
   1.372 -   /* Free the list of system resources. */
   1.373 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.374 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.375 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.376 -   }
   1.377 -
   1.378 -   _SBLIM_RETURNSTATUS(status);
   1.379 -}
   1.380 -
   1.381 -// ----------------------------------------------------------------------------
   1.382 -// SetInstance()
   1.383 -// Save modified instance data for the specified instance.
   1.384 -// ----------------------------------------------------------------------------
   1.385 -static CMPIStatus SetInstance(
   1.386 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.387 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.388 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.389 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   1.390 -		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   1.391 -      const char **properties)
   1.392 -{
   1.393 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.394 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.395 -   _RESOURCE * resource;	       		/* Handle to the system resource. */
   1.396 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.397 -   int found = 0;				/* Found the target instance? */
   1.398 -
   1.399 -   _SBLIM_ENTER("SetInstance");
   1.400 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.401 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.402 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.403 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   1.404 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.405 -
   1.406 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.407 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.408 -      goto exit;
   1.409 -   }
   1.410 -
   1.411 -   /* Get a handle to the list of system resources. */
   1.412 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.413 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.414 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.415 -      goto exit;
   1.416 -   }
   1.417 -
   1.418 -   /* Get the target resource. */
   1.419 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   1.420 -   if (!found || (resource == NULL)) {
   1.421 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   1.422 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   1.423 -      goto exit;
   1.424 -   }
   1.425 -
   1.426 -   _SBLIM_TRACE(2,("--- instance found", found));
   1.427 -
   1.428 -   /* Update the target resource data with the new instance property values. */
   1.429 -   int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER);
   1.430 -
   1.431 -   /* Free the resource data. */
   1.432 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   1.433 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.434 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.435 -      goto exit;
   1.436 -   }
   1.437 -
   1.438 -   if (rc != 1) {
   1.439 -      if (rc == -1) {
   1.440 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   1.441 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   1.442 -      } else {
   1.443 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   1.444 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   1.445 -      }
   1.446 -      goto exit;
   1.447 -   }
   1.448 -
   1.449 -exit:
   1.450 -   /* Free the list of system resources. */
   1.451 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.452 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.453 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.454 -   }
   1.455 -
   1.456 -   _SBLIM_RETURNSTATUS(status);
   1.457 -}
   1.458 -
   1.459 -// ----------------------------------------------------------------------------
   1.460 -// CreateInstance()
   1.461 -// Create a new instance from the specified instance data.
   1.462 -// ----------------------------------------------------------------------------
   1.463 -static CMPIStatus CreateInstance(
   1.464 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.465 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.466 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.467 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   1.468 -		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   1.469 -{
   1.470 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.471 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.472 -   _RESOURCE * resource;			/* Handle to the system resource. */
   1.473 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.474 -   int found = 0;				/* Found the target instance? */
   1.475 -
   1.476 -   _SBLIM_ENTER("CreateInstance");
   1.477 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.478 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.479 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.480 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   1.481 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.482 -
   1.483 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.484 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.485 -      goto exit;
   1.486 -   }
   1.487 -
   1.488 -   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   1.489 -   reference = CMGetObjectPath(newinstance, NULL);
   1.490 -
   1.491 -   /* Get a handle to the list of system resources. */
   1.492 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.493 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.494 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.495 -      goto exit;
   1.496 -   }
   1.497 -
   1.498 -   /* Get the target resource. */
   1.499 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   1.500 -
   1.501 -   /* Free the resource data. */
   1.502 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   1.503 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.504 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.505 -      goto exit;
   1.506 -   }
   1.507 -
   1.508 -   if (found) {
   1.509 -      _SBLIM_TRACE(1,("--- Target instance already exists"));
   1.510 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   1.511 -      goto exit;
   1.512 -   }
   1.513 -
   1.514 -   /* Create a new resource with the new instance property values. */
   1.515 -   int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   1.516 -   if (rc != 1) {
   1.517 -      if (rc == -1) {
   1.518 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   1.519 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   1.520 -      } else {
   1.521 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   1.522 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   1.523 -      }
   1.524 -      goto exit;
   1.525 -   }
   1.526 -
   1.527 -   /* Return the object path for the newly created instance. */
   1.528 -   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   1.529 -   CMSetNameSpace(objectpath, namespace);
   1.530 -   CMReturnObjectPath(results, objectpath);
   1.531 -   CMReturnDone(results);
   1.532 -
   1.533 -exit:
   1.534 -   /* Free the list of system resources. */
   1.535 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.536 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.537 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.538 -   }
   1.539 -
   1.540 -   _SBLIM_RETURNSTATUS(status);
   1.541 -}
   1.542 -
   1.543 -// ----------------------------------------------------------------------------
   1.544 -// DeleteInstance()
   1.545 -// Delete or remove the specified instance from the system.
   1.546 -// ----------------------------------------------------------------------------
   1.547 -static CMPIStatus DeleteInstance(
   1.548 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.549 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.550 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.551 -		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   1.552 -{
   1.553 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   1.554 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   1.555 -   _RESOURCE * resource;		/* Handle to the system resource. */
   1.556 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.557 -   int found = 0;				/* Found the target instance? */
   1.558 -
   1.559 -   _SBLIM_ENTER("DeleteInstance");
   1.560 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.561 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.562 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.563 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.564 -
   1.565 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.566 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.567 -      goto exit;
   1.568 -   }
   1.569 -
   1.570 -   /* Get a handle to the list of system resources. */
   1.571 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   1.572 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   1.573 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   1.574 -      goto exit;
   1.575 -   }
   1.576 -
   1.577 -   /* Get the target resource. */
   1.578 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   1.579 -   if (!found || (resource == NULL)) {
   1.580 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   1.581 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   1.582 -      goto exit;
   1.583 -   }
   1.584 -
   1.585 -   _SBLIM_TRACE(2,("--- instance found", found));
   1.586 -
   1.587 -   /* Delete the target resource. */
   1.588 -   int rc = Xen_ProcessorPool_deleteResource(resources, resource);
   1.589 -
   1.590 -   /* Free the resource data. */
   1.591 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   1.592 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   1.593 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   1.594 -      goto exit;
   1.595 -   }
   1.596 -
   1.597 -   if (rc != 1) {
   1.598 -      if (rc == -1) {
   1.599 -         _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
   1.600 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   1.601 -      } else {
   1.602 -         _SBLIM_TRACE(1,("--- _deleteResource() failed"));
   1.603 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
   1.604 -      }
   1.605 -      goto exit;
   1.606 -   }
   1.607 -
   1.608 -exit:
   1.609 -   /* Free the list of system resources. */
   1.610 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   1.611 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   1.612 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   1.613 -   }
   1.614 -
   1.615 -   _SBLIM_RETURNSTATUS(status);
   1.616 +   return CMPI_RC_OK;
   1.617  }
   1.618  
   1.619  
   1.620 -// ----------------------------------------------------------------------------
   1.621 -// ExecQuery()
   1.622 -// Return a list of all the instances that satisfy the specified query filter.
   1.623 -// ----------------------------------------------------------------------------
   1.624 -static CMPIStatus ExecQuery(
   1.625 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.626 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   1.627 -		const CMPIResult * results,		/* [out] Results of this operation. */
   1.628 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   1.629 -		const char * language,		/* [in] Name of the query language. */
   1.630 -		const char * query)			/* [in] Text of the query written in the query language. */
   1.631 +/* Get the single instance. */
   1.632 +static CMPIrc get(void **res, const char** properties)
   1.633  {
   1.634 -   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   1.635 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   1.636 +   xen_host_cpu_set *host_cpus;
   1.637  
   1.638 -   _SBLIM_ENTER("ExecQuery");
   1.639 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.640 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.641 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   1.642 -   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   1.643 -   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   1.644 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   1.645 +   (void)properties;
   1.646 +   
   1.647 +   if (!xen_utils_validate_session(&session)) {
   1.648 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   1.649 +                   ("--- Unable to establish connection with Xend"));
   1.650 +      return CMPI_RC_ERR_FAILED;
   1.651 +   }
   1.652  
   1.653 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   1.654 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   1.655 -      goto exit;
   1.656 +   if (!xen_host_get_host_cpus(session->xen, &host_cpus, session->host)) {
   1.657 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   1.658 +                   ("--- Failed to retrieve host cpus from Xend"));
   1.659 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   1.660 +                            xen_utils_trace_error(session->xen));
   1.661 +      return CMPI_RC_ERR_FAILED;
   1.662     }
   1.663  
   1.664 -   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   1.665 -   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   1.666 +   *res = (void *)host_cpus;
   1.667 +   return CMPI_RC_OK;
   1.668 +}
   1.669 +
   1.670  
   1.671 -   CMReturnDone(results);
   1.672 -
   1.673 -exit:
   1.674 -   _SBLIM_RETURNSTATUS(status);
   1.675 +static void release(void *res)
   1.676 +{
   1.677 +   if (res)
   1.678 +      xen_host_cpu_set_free((xen_host_cpu_set *)res);
   1.679  }
   1.680  
   1.681 -// ----------------------------------------------------------------------------
   1.682 -// Initialize()
   1.683 -// Perform any necessary initialization immediately after this provider is
   1.684 -// first loaded.
   1.685 -// ----------------------------------------------------------------------------
   1.686 -static void Initialize(
   1.687 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   1.688 -		const CMPIContext * context)		/* [in] Additional context info, if any. */
   1.689 +
   1.690 +/* Set CMPIInstance properties from the resource data. */
   1.691 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   1.692 +                            const char **properties)
   1.693  {
   1.694 -   _SBLIM_ENTER("Initialize");
   1.695 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   1.696 -   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   1.697 +   xen_host_cpu_set *host_cpus = (xen_host_cpu_set *)res;
   1.698 +   char *host_name;
   1.699 +   char buf[MAX_INSTANCEID_LEN];
   1.700 +   uint64_t prop_val_64;
   1.701 +   int prop_val_32;
   1.702 +
   1.703 +   if (host_cpus == NULL)
   1.704 +      return CMPI_RC_ERR_FAILED;
   1.705 +
   1.706 +   if (CMIsNullObject(inst))
   1.707 +      return CMPI_RC_ERR_FAILED;
   1.708 +
   1.709 +   /* Setup a filter to only return the desired properties. */
   1.710 +   CMSetPropertyFilter(inst, properties, keys);
   1.711  
   1.712 -   /* Nothing needs to be done to initialize this provider */
   1.713 -   _SBLIM_RETURN();
   1.714 +   session->xen->ok = true;
   1.715 +   xen_host_get_name_label(session->xen, &host_name, session->host);
   1.716 +   if (session->xen->ok) {
   1.717 +      snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:ProcessorPool",
   1.718 +               host_name);
   1.719 +      CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
   1.720 +      free(host_name);
   1.721 +   }
   1.722 +   else {
   1.723 +      CMSetProperty(inst, "InstanceID",
   1.724 +                    (CMPIValue *)"Xen:ProcessorPool", CMPI_chars);
   1.725 +   }
   1.726 +   
   1.727 +   CMSetProperty(inst, "PoolID", (CMPIValue *)"XenProcessorPool", CMPI_chars);
   1.728 +
   1.729 +   prop_val_32 = 3; /* 3 == Processor */
   1.730 +   CMSetProperty(inst, "ResourceType", (CMPIValue *)&prop_val_32, CMPI_uint16);
   1.731 +   CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"Cores", CMPI_chars);
   1.732 +
   1.733 +   /* Capacity is the number of items in xen_host_cpu_set. */
   1.734 +   prop_val_64 = host_cpus->size;
   1.735 +   CMSetProperty(inst, "Capacity", (CMPIValue *)&prop_val_64, CMPI_uint64);
   1.736 +
   1.737 +   /*
   1.738 +    * Xen does not currently support dedicated processor allocation,
   1.739 +    * therefore no processors can be exclusively 'reserved' by a DomU.
   1.740 +    */
   1.741 +   prop_val_64 = 0;
   1.742 +   CMSetProperty(inst, "Reserved", (CMPIValue *)&prop_val_64, CMPI_uint64);
   1.743 +
   1.744 +   prop_val_32 = 1;
   1.745 +   CMSetProperty(inst, "Primordial" , (CMPIValue *)&prop_val_32, CMPI_boolean);
   1.746 +
   1.747 +   return CMPI_RC_OK;
   1.748  }
   1.749  
   1.750 -// ============================================================================
   1.751 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
   1.752 -// ============================================================================
   1.753 -CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));
   1.754 +
   1.755 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   1.756 +/* CMPILIFYInstance1ROMIStub(<CLASS>,<PROVIDERNAME>,<KEYS>,<MIHANDLE>) */
   1.757 +CMPILIFYInstance1ROMIStub(Xen_ProcessorPool, Xen_ProcessorPool, keys, mi)