os-cmpi-xen

changeset 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 86c5f863cf9d
children c0beaacf5b03
files ChangeLog src/Makefile.am src/Xen_ProcessorPool.c src/Xen_ProcessorPool_Resource.c src/Xen_ProcessorPool_Resource.h
line diff
     1.1 --- a/ChangeLog	Fri Jul 27 10:28:41 2007 -0600
     1.2 +++ b/ChangeLog	Fri Jul 27 15:57:34 2007 -0600
     1.3 @@ -1,3 +1,8 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Fri Jul 27 15:56:35 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +         - Ported Xen_ProcessorPool to 'Cmpilify' interface.
     1.8 +
     1.9  -------------------------------------------------------------------
    1.10  Fri Jul 27 10:27:37 MDT 2007 - jfehlig@novell.com
    1.11  
     2.1 --- a/src/Makefile.am	Fri Jul 27 10:28:41 2007 -0600
     2.2 +++ b/src/Makefile.am	Fri Jul 27 15:57:34 2007 -0600
     2.3 @@ -51,7 +51,6 @@ noinst_HEADERS = \
     2.4  	Xen_NetworkPort_Resource.h \
     2.5  	Xen_VirtualizationCapabilities_Resource.h \
     2.6  	Xen_NetworkPortSettingData_Resource.h \
     2.7 -	Xen_ProcessorPool_Resource.h \
     2.8  	Xen_ProcessorCapabilitiesSettingData_Resource.h \
     2.9  	Xen_MemoryCapabilitiesSettingData_Resource.h
    2.10  
    2.11 @@ -306,8 +305,8 @@ libXen_MemoryPoolComponent_la_SOURCES = 
    2.12  libXen_MemoryPoolComponent_la_LIBADD = libXen_ProviderCommon.la
    2.13  libXen_MemoryPoolComponent_la_LDFLAGS = -module -avoid-version -no-undefined
    2.14  
    2.15 -libXen_ProcessorPool_la_SOURCES = Xen_ProcessorPool.c Xen_ProcessorPool_Resource.c
    2.16 -libXen_ProcessorPool_la_CFLAGS = -I../
    2.17 +libXen_ProcessorPool_la_SOURCES = Xen_ProcessorPool.c
    2.18 +libXen_ProcessorPool_la_CFLAGS = -I../ @LIBXEN_CFLAGS@
    2.19  libXen_ProcessorPool_la_LIBADD = libXen_ProviderCommon.la -lxenstore
    2.20  libXen_ProcessorPool_la_LDFLAGS = -module -avoid-version -no-undefined
    2.21  
     3.1 --- a/src/Xen_ProcessorPool.c	Fri Jul 27 10:28:41 2007 -0600
     3.2 +++ b/src/Xen_ProcessorPool.c	Fri Jul 27 15:57:34 2007 -0600
     3.3 @@ -1,4 +1,4 @@
     3.4 -// Copyright (C) 2006 IBM Corporation
     3.5 +// Copyright (C) 2007 Novell, Inc.
     3.6  //
     3.7  //    This library is free software; you can redistribute it and/or
     3.8  //    modify it under the terms of the GNU Lesser General Public
     3.9 @@ -15,626 +15,159 @@
    3.10  //    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.11  // ============================================================================
    3.12  // Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    3.13 -//                Jim Fehlig, <jfehlig@novell.com>
    3.14 -// Contributors:
    3.15 -// Description:
    3.16 +// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    3.17 +// Description:   Xen implementation of CIM_ResourcePool for CPU.
    3.18  // ============================================================================
    3.19  
    3.20 -#include <string.h>
    3.21 -
    3.22 -/* Include the required CMPI data types, function headers, and macros */
    3.23 -#include "cmpidt.h"
    3.24 -#include "cmpift.h"
    3.25 -#include "cmpimacs.h"
    3.26 -
    3.27 -#include "provider_common.h"
    3.28 +/* Common declarations for each CMPI "Cimpler" instance provider */
    3.29 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    3.30 +#include <cmpidt.h>
    3.31 +#include <cmpimacs.h>
    3.32  
    3.33 -// ----------------------------------------------------------------------------
    3.34 -// COMMON GLOBAL VARIABLES
    3.35 -// ----------------------------------------------------------------------------
    3.36 -
    3.37 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    3.38 -static const CMPIBroker *_BROKER;
    3.39 +#include "cmpilify.h"
    3.40  
    3.41 -/* Include utility functions */
    3.42 -#include "cmpiutil.h"
    3.43  
    3.44 -/* Include _SBLIM_TRACE() logging support */
    3.45 -#include "cmpitrace.h"
    3.46 -
    3.47 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    3.48 -#include "Xen_ProcessorPool_Resource.h"
    3.49 +static const CMPIInstanceMI* mi;
    3.50  
    3.51  
    3.52 -// ============================================================================
    3.53 -// CMPI INSTANCE PROVIDER FUNCTION TABLE
    3.54 -// ============================================================================
    3.55 +#define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
    3.56 +#define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
    3.57 +#define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
    3.58  
    3.59 -// ----------------------------------------------------------------------------
    3.60 -// Info for the class supported by the instance provider
    3.61 -// ----------------------------------------------------------------------------
    3.62 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    3.63 +
    3.64 +#include <stdlib.h>
    3.65  
    3.66 -/* Name of the class implemented by this instance provider. */
    3.67 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    3.68 -static char * _CLASSNAME = "Xen_ProcessorPool";
    3.69 +#include <xen_common.h>
    3.70 +#include <xen_host.h>
    3.71 +#include <xen_host_cpu.h>
    3.72  
    3.73 -/* NULL terminated list of key properties of this class. */
    3.74 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    3.75 -const static char * _KEYNAMES[] = {"InstanceID", NULL};
    3.76 +#include "cmpitrace.h"
    3.77 +#include "xen_utils.h"
    3.78 +#include "provider_common.h"
    3.79  
    3.80 -// ----------------------------------------------------------------------------
    3.81 -// Cleanup()
    3.82 -// Perform any necessary cleanup immediately before this provider is unloaded.
    3.83 -// ----------------------------------------------------------------------------
    3.84 -static CMPIStatus Cleanup(
    3.85 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
    3.86 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
    3.87 -      CMPIBoolean terminating)   /* [in] True if MB is terminating */
    3.88 +/* Class keys */
    3.89 +static const char *keys[] = {"InstanceID", NULL};
    3.90 +
    3.91 +
    3.92 +/* Xen session object.  Initialize when the provider is loaded, close when
    3.93 + * provider unloaded. */
    3.94 +static xen_utils_session *session = NULL;
    3.95 +
    3.96 +
    3.97 +static CMPIrc load()
    3.98  {
    3.99 -   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
   3.100 +   /* Initialized Xen session object. */
   3.101 +   if (!session)
   3.102 +      xen_utils_xen_init(&session);
   3.103  
   3.104 -   _SBLIM_ENTER("Cleanup");
   3.105 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.106 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.107 -
   3.108 -   /* Nothing needs to be done for cleanup. */
   3.109 -   _SBLIM_RETURNSTATUS(status);
   3.110 +   return CMPI_RC_OK;
   3.111  }
   3.112  
   3.113 -// ----------------------------------------------------------------------------
   3.114 -// EnumInstanceNames()
   3.115 -// Return a list of all the instances names (return their object paths only).
   3.116 -// ----------------------------------------------------------------------------
   3.117 -static CMPIStatus EnumInstanceNames(
   3.118 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.119 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.120 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.121 -		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   3.122 -{
   3.123 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.124 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.125 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.126 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.127 -   int found = 0;				/* Found any instances? */
   3.128 -  
   3.129 -   _SBLIM_ENTER("EnumInstanceNames");
   3.130 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.131 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.132 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.133 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.134  
   3.135 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.136 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.137 -      goto exit;
   3.138 -   }
   3.139 -
   3.140 -   /* Get a handle to the list of system resources. */
   3.141 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.142 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.143 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.144 -      goto exit;
   3.145 -   }
   3.146 -
   3.147 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.148 -   while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
   3.149 -      /* Create a new CMPIInstance to store this resource. */
   3.150 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.151 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.152 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.153 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.154 -         goto exit;
   3.155 -      }
   3.156 -
   3.157 -      /* Set the instance property values from the resource data. */
   3.158 -      if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   3.159 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.160 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.161 -         goto exit;
   3.162 -      }
   3.163 -
   3.164 -      /* Free the resource data. */
   3.165 -      if (!Xen_ProcessorPool_freeResource(resource)) {
   3.166 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.167 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.168 -         goto exit;
   3.169 -      }
   3.170 -
   3.171 -      /* Return the CMPIObjectPath for this instance. */
   3.172 -      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   3.173 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   3.174 -         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   3.175 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   3.176 -         goto exit;
   3.177 -      }
   3.178 -      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   3.179 -     
   3.180 -      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   3.181 -      CMReturnObjectPath(results, objectpath);
   3.182 -      found++;
   3.183 -   }
   3.184 -
   3.185 -   _SBLIM_TRACE(2,("--- %d object paths found", found));
   3.186 -   CMReturnDone(results);
   3.187 -
   3.188 -exit:
   3.189 -   /* Free the list of system resources. */
   3.190 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.191 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.192 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.193 -   }
   3.194 -  
   3.195 -   _SBLIM_RETURNSTATUS(status);
   3.196 -}
   3.197 -
   3.198 -// ----------------------------------------------------------------------------
   3.199 -// EnumInstances()
   3.200 -// Return a list of all the instances (return all the instance data).
   3.201 -// ----------------------------------------------------------------------------
   3.202 -static CMPIStatus EnumInstances(
   3.203 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.204 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.205 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.206 -		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   3.207 -		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   3.208 +static CMPIrc unload(const int terminating)
   3.209  {
   3.210 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.211 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.212 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.213 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.214 -   int found = 0;				/* Found any resource instances? */
   3.215 -
   3.216 -   _SBLIM_ENTER("EnumInstances");
   3.217 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.218 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.219 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.220 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.221 -
   3.222 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.223 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.224 -      goto exit;
   3.225 -   }
   3.226 -
   3.227 -   /* Get a handle to the list of system resources. */
   3.228 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.229 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.230 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.231 -      goto exit;
   3.232 -   }
   3.233 -
   3.234 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.235 -   while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
   3.236 -      /* Create a new CMPIInstance to store this resource. */
   3.237 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.238 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.239 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.240 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.241 -         goto exit;
   3.242 -      }
   3.243 -
   3.244 -      /* Setup a filter to only return the desired properties. */
   3.245 -      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.246 -      if (status.rc != CMPI_RC_OK) {
   3.247 -         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.248 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.249 -         goto exit;
   3.250 -      }
   3.251 -
   3.252 -      /* Set the instance property values from the resource data. */
   3.253 -      if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   3.254 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.255 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.256 -         goto exit;
   3.257 -      }
   3.258 -
   3.259 -      /* Free the resource data. */
   3.260 -      if (!Xen_ProcessorPool_freeResource(resource)) {
   3.261 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.262 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.263 -         goto exit;
   3.264 -      }
   3.265 -
   3.266 -      /* Return the CMPIInstance for this instance. */
   3.267 -      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.268 -      CMReturnInstance(results, instance);
   3.269 -      found++;
   3.270 -   }
   3.271 -
   3.272 -   _SBLIM_TRACE(2,("--- %d instances found", found));
   3.273 -   CMReturnDone(results);
   3.274 -
   3.275 -exit:
   3.276 -   /* Free the list of system resources. */
   3.277 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.278 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.279 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.280 -   }
   3.281 -
   3.282 -   _SBLIM_RETURNSTATUS(status);
   3.283 -}
   3.284 -
   3.285 -// ----------------------------------------------------------------------------
   3.286 -// GetInstance()
   3.287 -// Return the instance data for the specified instance only.
   3.288 -// ----------------------------------------------------------------------------
   3.289 -static CMPIStatus GetInstance(
   3.290 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.291 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.292 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.293 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.294 -		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   3.295 -{
   3.296 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.297 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.298 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.299 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.300 -   int found = 0;				/* Found the target instance? */
   3.301 -
   3.302 -   _SBLIM_ENTER("GetInstance");
   3.303 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.304 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.305 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.306 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.307 -
   3.308 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.309 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.310 -      goto exit;
   3.311 -   }
   3.312 -
   3.313 -   /* Get a handle to the list of system resources. */
   3.314 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.315 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.316 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.317 -      goto exit;
   3.318 -   }
   3.319 -
   3.320 -   /* Get the target resource. */
   3.321 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   3.322 -   if (!found || (resource == NULL)) {
   3.323 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.324 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.325 -      goto exit;
   3.326 +   (void)terminating;
   3.327 +   
   3.328 +   /* Close Xen session object. */
   3.329 +   if (session) {
   3.330 +      xen_utils_xen_close(session);
   3.331 +      session = NULL;
   3.332     }
   3.333  
   3.334 -   /* Create a new CMPIInstance to store this resource. */
   3.335 -   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.336 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.337 -      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.338 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.339 -      goto exit;
   3.340 -   }
   3.341 -
   3.342 -   /* Setup a filter to only return the desired properties. */
   3.343 -   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.344 -   if (status.rc != CMPI_RC_OK) {
   3.345 -      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.346 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.347 -      goto exit;
   3.348 -   }
   3.349 -
   3.350 -   /* Set the instance property values from the resource data. */
   3.351 -   if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
   3.352 -      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.353 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.354 -      goto exit;
   3.355 -   }
   3.356 -
   3.357 -   /* Free the resource data. */
   3.358 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   3.359 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.360 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.361 -      goto exit;
   3.362 -   }
   3.363 -
   3.364 -   /* Return the CMPIInstance for this instance. */
   3.365 -   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.366 -   CMReturnInstance(results, instance);
   3.367 -
   3.368 -   _SBLIM_TRACE(2,("--- instance found"));
   3.369 -   CMReturnDone(results);
   3.370 -
   3.371 -exit:
   3.372 -   /* Free the list of system resources. */
   3.373 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.374 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.375 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.376 -   }
   3.377 -
   3.378 -   _SBLIM_RETURNSTATUS(status);
   3.379 -}
   3.380 -
   3.381 -// ----------------------------------------------------------------------------
   3.382 -// SetInstance()
   3.383 -// Save modified instance data for the specified instance.
   3.384 -// ----------------------------------------------------------------------------
   3.385 -static CMPIStatus SetInstance(
   3.386 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.387 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.388 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.389 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.390 -		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   3.391 -      const char **properties)
   3.392 -{
   3.393 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.394 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.395 -   _RESOURCE * resource;	       		/* Handle to the system resource. */
   3.396 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.397 -   int found = 0;				/* Found the target instance? */
   3.398 -
   3.399 -   _SBLIM_ENTER("SetInstance");
   3.400 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.401 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.402 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.403 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.404 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.405 -
   3.406 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.407 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.408 -      goto exit;
   3.409 -   }
   3.410 -
   3.411 -   /* Get a handle to the list of system resources. */
   3.412 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.413 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.414 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.415 -      goto exit;
   3.416 -   }
   3.417 -
   3.418 -   /* Get the target resource. */
   3.419 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   3.420 -   if (!found || (resource == NULL)) {
   3.421 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.422 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.423 -      goto exit;
   3.424 -   }
   3.425 -
   3.426 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.427 -
   3.428 -   /* Update the target resource data with the new instance property values. */
   3.429 -   int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER);
   3.430 -
   3.431 -   /* Free the resource data. */
   3.432 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   3.433 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.434 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.435 -      goto exit;
   3.436 -   }
   3.437 -
   3.438 -   if (rc != 1) {
   3.439 -      if (rc == -1) {
   3.440 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   3.441 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.442 -      } else {
   3.443 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   3.444 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   3.445 -      }
   3.446 -      goto exit;
   3.447 -   }
   3.448 -
   3.449 -exit:
   3.450 -   /* Free the list of system resources. */
   3.451 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.452 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.453 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.454 -   }
   3.455 -
   3.456 -   _SBLIM_RETURNSTATUS(status);
   3.457 -}
   3.458 -
   3.459 -// ----------------------------------------------------------------------------
   3.460 -// CreateInstance()
   3.461 -// Create a new instance from the specified instance data.
   3.462 -// ----------------------------------------------------------------------------
   3.463 -static CMPIStatus CreateInstance(
   3.464 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.465 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.466 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.467 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.468 -		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   3.469 -{
   3.470 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.471 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.472 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.473 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.474 -   int found = 0;				/* Found the target instance? */
   3.475 -
   3.476 -   _SBLIM_ENTER("CreateInstance");
   3.477 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.478 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.479 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.480 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.481 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.482 -
   3.483 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.484 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.485 -      goto exit;
   3.486 -   }
   3.487 -
   3.488 -   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   3.489 -   reference = CMGetObjectPath(newinstance, NULL);
   3.490 -
   3.491 -   /* Get a handle to the list of system resources. */
   3.492 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.493 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.494 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.495 -      goto exit;
   3.496 -   }
   3.497 -
   3.498 -   /* Get the target resource. */
   3.499 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   3.500 -
   3.501 -   /* Free the resource data. */
   3.502 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   3.503 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.504 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.505 -      goto exit;
   3.506 -   }
   3.507 -
   3.508 -   if (found) {
   3.509 -      _SBLIM_TRACE(1,("--- Target instance already exists"));
   3.510 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   3.511 -      goto exit;
   3.512 -   }
   3.513 -
   3.514 -   /* Create a new resource with the new instance property values. */
   3.515 -   int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   3.516 -   if (rc != 1) {
   3.517 -      if (rc == -1) {
   3.518 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   3.519 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.520 -      } else {
   3.521 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   3.522 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   3.523 -      }
   3.524 -      goto exit;
   3.525 -   }
   3.526 -
   3.527 -   /* Return the object path for the newly created instance. */
   3.528 -   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   3.529 -   CMSetNameSpace(objectpath, namespace);
   3.530 -   CMReturnObjectPath(results, objectpath);
   3.531 -   CMReturnDone(results);
   3.532 -
   3.533 -exit:
   3.534 -   /* Free the list of system resources. */
   3.535 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.536 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.537 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.538 -   }
   3.539 -
   3.540 -   _SBLIM_RETURNSTATUS(status);
   3.541 -}
   3.542 -
   3.543 -// ----------------------------------------------------------------------------
   3.544 -// DeleteInstance()
   3.545 -// Delete or remove the specified instance from the system.
   3.546 -// ----------------------------------------------------------------------------
   3.547 -static CMPIStatus DeleteInstance(
   3.548 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.549 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.550 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.551 -		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   3.552 -{
   3.553 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.554 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.555 -   _RESOURCE * resource;		/* Handle to the system resource. */
   3.556 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.557 -   int found = 0;				/* Found the target instance? */
   3.558 -
   3.559 -   _SBLIM_ENTER("DeleteInstance");
   3.560 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.561 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.562 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.563 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.564 -
   3.565 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.566 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.567 -      goto exit;
   3.568 -   }
   3.569 -
   3.570 -   /* Get a handle to the list of system resources. */
   3.571 -   if (!Xen_ProcessorPool_getResources(&resources)) {
   3.572 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.573 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.574 -      goto exit;
   3.575 -   }
   3.576 -
   3.577 -   /* Get the target resource. */
   3.578 -   found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
   3.579 -   if (!found || (resource == NULL)) {
   3.580 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.581 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.582 -      goto exit;
   3.583 -   }
   3.584 -
   3.585 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.586 -
   3.587 -   /* Delete the target resource. */
   3.588 -   int rc = Xen_ProcessorPool_deleteResource(resources, resource);
   3.589 -
   3.590 -   /* Free the resource data. */
   3.591 -   if (!Xen_ProcessorPool_freeResource(resource)) {
   3.592 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.593 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.594 -      goto exit;
   3.595 -   }
   3.596 -
   3.597 -   if (rc != 1) {
   3.598 -      if (rc == -1) {
   3.599 -         _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
   3.600 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.601 -      } else {
   3.602 -         _SBLIM_TRACE(1,("--- _deleteResource() failed"));
   3.603 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
   3.604 -      }
   3.605 -      goto exit;
   3.606 -   }
   3.607 -
   3.608 -exit:
   3.609 -   /* Free the list of system resources. */
   3.610 -   if (!Xen_ProcessorPool_freeResources(resources)) {
   3.611 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.612 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.613 -   }
   3.614 -
   3.615 -   _SBLIM_RETURNSTATUS(status);
   3.616 +   return CMPI_RC_OK;
   3.617  }
   3.618  
   3.619  
   3.620 -// ----------------------------------------------------------------------------
   3.621 -// ExecQuery()
   3.622 -// Return a list of all the instances that satisfy the specified query filter.
   3.623 -// ----------------------------------------------------------------------------
   3.624 -static CMPIStatus ExecQuery(
   3.625 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.626 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.627 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.628 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   3.629 -		const char * language,		/* [in] Name of the query language. */
   3.630 -		const char * query)			/* [in] Text of the query written in the query language. */
   3.631 +/* Get the single instance. */
   3.632 +static CMPIrc get(void **res, const char** properties)
   3.633  {
   3.634 -   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   3.635 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.636 +   xen_host_cpu_set *host_cpus;
   3.637  
   3.638 -   _SBLIM_ENTER("ExecQuery");
   3.639 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.640 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.641 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.642 -   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   3.643 -   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   3.644 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.645 +   (void)properties;
   3.646 +   
   3.647 +   if (!xen_utils_validate_session(&session)) {
   3.648 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.649 +                   ("--- Unable to establish connection with Xend"));
   3.650 +      return CMPI_RC_ERR_FAILED;
   3.651 +   }
   3.652  
   3.653 -   if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
   3.654 -      _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
   3.655 -      goto exit;
   3.656 +   if (!xen_host_get_host_cpus(session->xen, &host_cpus, session->host)) {
   3.657 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.658 +                   ("--- Failed to retrieve host cpus from Xend"));
   3.659 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.660 +                            xen_utils_trace_error(session->xen));
   3.661 +      return CMPI_RC_ERR_FAILED;
   3.662     }
   3.663  
   3.664 -   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   3.665 -   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.666 +   *res = (void *)host_cpus;
   3.667 +   return CMPI_RC_OK;
   3.668 +}
   3.669 +
   3.670  
   3.671 -   CMReturnDone(results);
   3.672 -
   3.673 -exit:
   3.674 -   _SBLIM_RETURNSTATUS(status);
   3.675 +static void release(void *res)
   3.676 +{
   3.677 +   if (res)
   3.678 +      xen_host_cpu_set_free((xen_host_cpu_set *)res);
   3.679  }
   3.680  
   3.681 -// ----------------------------------------------------------------------------
   3.682 -// Initialize()
   3.683 -// Perform any necessary initialization immediately after this provider is
   3.684 -// first loaded.
   3.685 -// ----------------------------------------------------------------------------
   3.686 -static void Initialize(
   3.687 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.688 -		const CMPIContext * context)		/* [in] Additional context info, if any. */
   3.689 +
   3.690 +/* Set CMPIInstance properties from the resource data. */
   3.691 +static CMPIrc setproperties(CMPIInstance *inst, const void *res,
   3.692 +                            const char **properties)
   3.693  {
   3.694 -   _SBLIM_ENTER("Initialize");
   3.695 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.696 -   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.697 +   xen_host_cpu_set *host_cpus = (xen_host_cpu_set *)res;
   3.698 +   char *host_name;
   3.699 +   char buf[MAX_INSTANCEID_LEN];
   3.700 +   uint64_t prop_val_64;
   3.701 +   int prop_val_32;
   3.702 +
   3.703 +   if (host_cpus == NULL)
   3.704 +      return CMPI_RC_ERR_FAILED;
   3.705 +
   3.706 +   if (CMIsNullObject(inst))
   3.707 +      return CMPI_RC_ERR_FAILED;
   3.708 +
   3.709 +   /* Setup a filter to only return the desired properties. */
   3.710 +   CMSetPropertyFilter(inst, properties, keys);
   3.711  
   3.712 -   /* Nothing needs to be done to initialize this provider */
   3.713 -   _SBLIM_RETURN();
   3.714 +   session->xen->ok = true;
   3.715 +   xen_host_get_name_label(session->xen, &host_name, session->host);
   3.716 +   if (session->xen->ok) {
   3.717 +      snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:ProcessorPool",
   3.718 +               host_name);
   3.719 +      CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
   3.720 +      free(host_name);
   3.721 +   }
   3.722 +   else {
   3.723 +      CMSetProperty(inst, "InstanceID",
   3.724 +                    (CMPIValue *)"Xen:ProcessorPool", CMPI_chars);
   3.725 +   }
   3.726 +   
   3.727 +   CMSetProperty(inst, "PoolID", (CMPIValue *)"XenProcessorPool", CMPI_chars);
   3.728 +
   3.729 +   prop_val_32 = 3; /* 3 == Processor */
   3.730 +   CMSetProperty(inst, "ResourceType", (CMPIValue *)&prop_val_32, CMPI_uint16);
   3.731 +   CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"Cores", CMPI_chars);
   3.732 +
   3.733 +   /* Capacity is the number of items in xen_host_cpu_set. */
   3.734 +   prop_val_64 = host_cpus->size;
   3.735 +   CMSetProperty(inst, "Capacity", (CMPIValue *)&prop_val_64, CMPI_uint64);
   3.736 +
   3.737 +   /*
   3.738 +    * Xen does not currently support dedicated processor allocation,
   3.739 +    * therefore no processors can be exclusively 'reserved' by a DomU.
   3.740 +    */
   3.741 +   prop_val_64 = 0;
   3.742 +   CMSetProperty(inst, "Reserved", (CMPIValue *)&prop_val_64, CMPI_uint64);
   3.743 +
   3.744 +   prop_val_32 = 1;
   3.745 +   CMSetProperty(inst, "Primordial" , (CMPIValue *)&prop_val_32, CMPI_boolean);
   3.746 +
   3.747 +   return CMPI_RC_OK;
   3.748  }
   3.749  
   3.750 -// ============================================================================
   3.751 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
   3.752 -// ============================================================================
   3.753 -CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));
   3.754 +
   3.755 +/* Setup CMPILIFY function tables and instance provider entry point.*/
   3.756 +/* CMPILIFYInstance1ROMIStub(<CLASS>,<PROVIDERNAME>,<KEYS>,<MIHANDLE>) */
   3.757 +CMPILIFYInstance1ROMIStub(Xen_ProcessorPool, Xen_ProcessorPool, keys, mi)
     4.1 --- a/src/Xen_ProcessorPool_Resource.c	Fri Jul 27 10:28:41 2007 -0600
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,219 +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 -// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    4.22 -// Description:
    4.23 -// ============================================================================
    4.24 -
    4.25 -#include <string.h>
    4.26 -
    4.27 -#include "Xen_ProcessorPool_Resource.h"
    4.28 -
    4.29 -/* Include the required CMPI data types, function headers, and macros. */
    4.30 -#include "cmpidt.h"
    4.31 -#include "cmpift.h"
    4.32 -#include "cmpimacs.h"
    4.33 -
    4.34 -#include "provider_common.h"
    4.35 -
    4.36 -#include <stdlib.h>
    4.37 -
    4.38 -
    4.39 -static char * _RESOURCECLASSNAME = "CIM_Processor";
    4.40 -
    4.41 -
    4.42 -// ----------------------------------------------------------------------------
    4.43 -
    4.44 -static int populate_resource( _RESOURCE * resource, const CMPIBroker * broker, const CMPIContext * context )
    4.45 -{
    4.46 -   CMPIStatus status = { CMPI_RC_OK, NULL };    /* Return status of CIM operations. */
    4.47 -   /* Get the number of host processors from the SMASH host instrumentation. */
    4.48 -   CMPIObjectPath *objectpath = CMNewObjectPath(broker, HOST_INSTRUMENTATION_NS, _RESOURCECLASSNAME, &status);
    4.49 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
    4.50 -      return 0;
    4.51 -   }
    4.52 -
    4.53 -   CMPIEnumeration *instances = CBEnumInstances(broker, context, objectpath, NULL, &status);
    4.54 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
    4.55 -      return 0;
    4.56 -   }
    4.57 -
    4.58 -   /* Count the number of resources found. */
    4.59 -   while (CMHasNext(instances, NULL)) {
    4.60 -      /* Don't need to do anything with the instances at this time except
    4.61 -         count them (and move the iterator). */
    4.62 -      CMPIData data = CMGetNext(instances, NULL);
    4.63 -
    4.64 -      resource->capacity++;
    4.65 -   }
    4.66 -
    4.67 -   /* Xen does not currently support dedicated processor allocation,
    4.68 -      therefore no processors can be exclusively 'reserved' by a DomU. */
    4.69 -   resource->reserved = 0;
    4.70 -
    4.71 -   return 1;
    4.72 -}
    4.73 -
    4.74 -/* Get a handle to the list of all system resources for this class. */
    4.75 -int Xen_ProcessorPool_getResources( _RESOURCES ** resources )
    4.76 -{
    4.77 -   /* malloc a new handle for the resources list. */
    4.78 -   *resources = (_RESOURCES *)malloc(sizeof(_RESOURCES));
    4.79 -   if (*resources == NULL) return 0;
    4.80 -
    4.81 -   (*resources)->finished = 0;
    4.82 -
    4.83 -   return 1;
    4.84 -}
    4.85 -
    4.86 -// ----------------------------------------------------------------------------
    4.87 -
    4.88 -/* Free/deallocate/cleanup the resources list after use. */
    4.89 -int Xen_ProcessorPool_freeResources( _RESOURCES * resources )
    4.90 -{
    4.91 -   if (resources != NULL) {
    4.92 -       free(resources);
    4.93 -       resources = NULL;
    4.94 -   }
    4.95 -   
    4.96 -   return 1;
    4.97 -}
    4.98 -
    4.99 -// ----------------------------------------------------------------------------
   4.100 -
   4.101 -/* Iterator to get the next resource from the resources list. */
   4.102 -int Xen_ProcessorPool_getNextResource( _RESOURCES * resources, _RESOURCE ** resource, const CMPIBroker * broker, const CMPIContext * context )
   4.103 -{
   4.104 -   CMPIStatus status = { CMPI_RC_OK, NULL };    /* Return status of CIM operations. */
   4.105 -   if (resources == NULL) return 0;
   4.106 -   if (resources->finished) return 0;
   4.107 -
   4.108 -   /* Generate raw data for the single resource. */
   4.109 -   *resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   4.110 -   if (*resource == NULL) return 0;
   4.111 -
   4.112 -   if (populate_resource(*resource, broker, context) == 0) {
   4.113 -      free(*resource);
   4.114 -      *resource = NULL;
   4.115 -      return 0;
   4.116 -   }
   4.117 - 
   4.118 -   /* Single resource so no more resources in the list. */
   4.119 -   resources->finished = 1;
   4.120 -
   4.121 -   return 1;
   4.122 -}
   4.123 -
   4.124 -// ----------------------------------------------------------------------------
   4.125 -
   4.126 -/* Get the specific resource that matches the CMPI object path. */
   4.127 -int Xen_ProcessorPool_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath, const CMPIBroker * broker, const CMPIContext * context )
   4.128 -{
   4.129 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   4.130 -
   4.131 -   if (resources == NULL) return 0;
   4.132 -   if (CMIsNullObject(objectpath)) return 0;
   4.133 -
   4.134 -   /* Obtain the name from the CMPIObjectPath key. */
   4.135 -   CMPIData namedata = CMGetKey(objectpath, "InstanceID", &status);
   4.136 -   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
   4.137 -
   4.138 -   /* Extract the name string from the CMPIString. */
   4.139 -   char * name = CMGetCharPtr(namedata.value.string);
   4.140 -   if ((name == NULL) || (*name == '\0')) return 0;
   4.141 -
   4.142 -   /* Check that the name is correct. */
   4.143 -   if (strcmp(name, "XenProcessorPool") != 0) return 0;
   4.144 -
   4.145 -   /* Generate raw data for the single resource. */
   4.146 -   *resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   4.147 -   if (*resource == NULL) return 0;
   4.148 -
   4.149 -   if (populate_resource(*resource, broker, context) == 0) {
   4.150 -      free(*resource);
   4.151 -      *resource == NULL;
   4.152 -      return 0;
   4.153 -   }
   4.154 -
   4.155 -   return 1;
   4.156 -}
   4.157 -
   4.158 -// ----------------------------------------------------------------------------
   4.159 -
   4.160 -/* Free/deallocate/cleanup the resource after use. */
   4.161 -int Xen_ProcessorPool_freeResource( _RESOURCE * resource )
   4.162 -{
   4.163 -   if (resource != NULL) {
   4.164 -      free(resource);
   4.165 -      resource = NULL;
   4.166 -   }
   4.167 -   
   4.168 -   return 1;
   4.169 -}
   4.170 -
   4.171 -// ---------------------------------------------------------------------------- 
   4.172 -
   4.173 -/* Set the property values of a CMPI instance from a specific resource. */
   4.174 -int Xen_ProcessorPool_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
   4.175 -{
   4.176 -   if (resource == NULL) return 0;
   4.177 -   if (CMIsNullObject(instance)) return 0;
   4.178 -
   4.179 -   CMSetProperty(instance, "InstanceID",(CMPIValue *)"XenProcessorPool", CMPI_chars);
   4.180 -   CMSetProperty(instance, "PoolID",(CMPIValue *)"XenProcessorPool", CMPI_chars);
   4.181 -
   4.182 -   int type = 3; /* 3 == Processor */
   4.183 -   CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
   4.184 -
   4.185 -   CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Cores", CMPI_chars);
   4.186 -
   4.187 -   CMSetProperty(instance, "Capacity",(CMPIValue *)&(resource->capacity), CMPI_uint64);
   4.188 -   CMSetProperty(instance, "Reserved",(CMPIValue *)&(resource->reserved), CMPI_uint64);
   4.189 -
   4.190 -   int primordial = 1;
   4.191 -   CMSetProperty(instance, "Primordial" , (CMPIValue *)&primordial, CMPI_boolean);
   4.192 -
   4.193 -   return 1;
   4.194 -}
   4.195 -
   4.196 -// ----------------------------------------------------------------------------
   4.197 -
   4.198 -/* Delete the specified resource from the system. */
   4.199 -int Xen_ProcessorPool_deleteResource( _RESOURCES * resources, _RESOURCE * resource )
   4.200 -{
   4.201 -   /* Unsupported. */
   4.202 -   return -1;
   4.203 -}
   4.204 -
   4.205 -// ----------------------------------------------------------------------------
   4.206 -
   4.207 -/* Modify the specified resource using the property values of a CMPI instance. */
   4.208 -int Xen_ProcessorPool_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
   4.209 -{
   4.210 -   /* Unsupported. */
   4.211 -   return -1;
   4.212 -}
   4.213 -
   4.214 -// ----------------------------------------------------------------------------
   4.215 -
   4.216 -/* Create a new resource using the property values of a CMPI instance. */
   4.217 -int Xen_ProcessorPool_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker )
   4.218 -{
   4.219 -   /* Unsupported. */
   4.220 -   return -1;
   4.221 -}
   4.222 -
     5.1 --- a/src/Xen_ProcessorPool_Resource.h	Fri Jul 27 10:28:41 2007 -0600
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,84 +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 -// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    5.22 -// Description:
    5.23 -// ============================================================================
    5.24 -
    5.25 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.26 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES.
    5.27 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS
    5.28 -   LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC.
    5.29 -   THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN
    5.30 -   ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */
    5.31 -typedef struct {
    5.32 -   int finished;
    5.33 -} _RESOURCES;
    5.34 -
    5.35 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.36 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE.
    5.37 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH
    5.38 -   RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE
    5.39 -   PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE
    5.40 -   ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */
    5.41 -typedef struct {
    5.42 -   unsigned long long capacity;
    5.43 -   unsigned long long reserved;
    5.44 -} _RESOURCE;
    5.45 -
    5.46 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */
    5.47 -
    5.48 -/* Include the required CMPI data types. */
    5.49 -#include "cmpidt.h"
    5.50 -
    5.51 -// ----------------------------------------------------------------------------
    5.52 -// Generic resource access methods for CMPI providers.
    5.53 -// Return value:
    5.54 -//	-1 = Unsupported
    5.55 -//	 0 = Failed
    5.56 -//	 1 = OK
    5.57 -// ----------------------------------------------------------------------------
    5.58 -
    5.59 -/* Get a handle to the list of all system resources for this class. */
    5.60 -int Xen_ProcessorPool_getResources( _RESOURCES ** resources );
    5.61 -
    5.62 -/* Free/deallocate/cleanup the resources list after use. */
    5.63 -int Xen_ProcessorPool_freeResources( _RESOURCES * resources );
    5.64 -
    5.65 -/* Iterator to get the next resource from the resources list. */
    5.66 -int Xen_ProcessorPool_getNextResource( _RESOURCES * resources, _RESOURCE ** resource, const CMPIBroker * broker, const CMPIContext * context );
    5.67 -
    5.68 -/* Get the specific resource that matches the CMPI object path. */
    5.69 -int Xen_ProcessorPool_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath, const CMPIBroker * broker, const CMPIContext * context );
    5.70 -
    5.71 -/* Free/deallocate/cleanup a resource after use. */
    5.72 -int Xen_ProcessorPool_freeResource( _RESOURCE * resource );
    5.73 -
    5.74 -/* Set the property values of a CMPI instance from a specific resource. */
    5.75 -int Xen_ProcessorPool_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker );
    5.76 -
    5.77 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS
    5.78 -
    5.79 -/* Delete the specified resource from the system. */
    5.80 -int Xen_ProcessorPool_deleteResource( _RESOURCES * resources, _RESOURCE * resource );
    5.81 -
    5.82 -/* Modify the specified resource using the property values of a CMPI instance. */
    5.83 -int Xen_ProcessorPool_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker );
    5.84 -
    5.85 -/* Create a new resource using the property values of a CMPI instance. */
    5.86 -int Xen_ProcessorPool_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker );
    5.87 -