os-cmpi-xen

view src/Xen_ProcessorPool_Resource.c @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents 0ab270c76de2
children
line source
1 // Copyright (C) 2006 IBM Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
19 // Description:
20 // ============================================================================
22 #include <string.h>
24 #include "Xen_ProcessorPool_Resource.h"
26 /* Include the required CMPI data types, function headers, and macros. */
27 #include "cmpidt.h"
28 #include "cmpift.h"
29 #include "cmpimacs.h"
31 #include "provider_common.h"
33 #include <stdlib.h>
36 static char * _RESOURCECLASSNAME = "CIM_Processor";
39 // ----------------------------------------------------------------------------
41 static int populate_resource( _RESOURCE * resource, const CMPIBroker * broker, const CMPIContext * context )
42 {
43 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
44 /* Get the number of host processors from the SMASH host instrumentation. */
45 CMPIObjectPath *objectpath = CMNewObjectPath(broker, HOST_INSTRUMENTATION_NS, _RESOURCECLASSNAME, &status);
46 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
47 return 0;
48 }
50 CMPIEnumeration *instances = CBEnumInstances(broker, context, objectpath, NULL, &status);
51 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) {
52 return 0;
53 }
55 /* Count the number of resources found. */
56 while (CMHasNext(instances, NULL)) {
57 /* Don't need to do anything with the instances at this time except
58 count them (and move the iterator). */
59 CMPIData data = CMGetNext(instances, NULL);
61 resource->capacity++;
62 }
64 /* Xen does not currently support dedicated processor allocation,
65 therefore no processors can be exclusively 'reserved' by a DomU. */
66 resource->reserved = 0;
68 return 1;
69 }
71 /* Get a handle to the list of all system resources for this class. */
72 int Xen_ProcessorPool_getResources( _RESOURCES ** resources )
73 {
74 /* malloc a new handle for the resources list. */
75 *resources = (_RESOURCES *)malloc(sizeof(_RESOURCES));
76 if (*resources == NULL) return 0;
78 (*resources)->finished = 0;
80 return 1;
81 }
83 // ----------------------------------------------------------------------------
85 /* Free/deallocate/cleanup the resources list after use. */
86 int Xen_ProcessorPool_freeResources( _RESOURCES * resources )
87 {
88 if (resources != NULL) {
89 free(resources);
90 resources = NULL;
91 }
93 return 1;
94 }
96 // ----------------------------------------------------------------------------
98 /* Iterator to get the next resource from the resources list. */
99 int Xen_ProcessorPool_getNextResource( _RESOURCES * resources, _RESOURCE ** resource, const CMPIBroker * broker, const CMPIContext * context )
100 {
101 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
102 if (resources == NULL) return 0;
103 if (resources->finished) return 0;
105 /* Generate raw data for the single resource. */
106 *resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
107 if (*resource == NULL) return 0;
109 if (populate_resource(*resource, broker, context) == 0) {
110 free(*resource);
111 *resource = NULL;
112 return 0;
113 }
115 /* Single resource so no more resources in the list. */
116 resources->finished = 1;
118 return 1;
119 }
121 // ----------------------------------------------------------------------------
123 /* Get the specific resource that matches the CMPI object path. */
124 int Xen_ProcessorPool_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath, const CMPIBroker * broker, const CMPIContext * context )
125 {
126 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
128 if (resources == NULL) return 0;
129 if (CMIsNullObject(objectpath)) return 0;
131 /* Obtain the name from the CMPIObjectPath key. */
132 CMPIData namedata = CMGetKey(objectpath, "InstanceID", &status);
133 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
135 /* Extract the name string from the CMPIString. */
136 char * name = CMGetCharPtr(namedata.value.string);
137 if ((name == NULL) || (*name == '\0')) return 0;
139 /* Check that the name is correct. */
140 if (strcmp(name, "XenProcessorPool") != 0) return 0;
142 /* Generate raw data for the single resource. */
143 *resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
144 if (*resource == NULL) return 0;
146 if (populate_resource(*resource, broker, context) == 0) {
147 free(*resource);
148 *resource == NULL;
149 return 0;
150 }
152 return 1;
153 }
155 // ----------------------------------------------------------------------------
157 /* Free/deallocate/cleanup the resource after use. */
158 int Xen_ProcessorPool_freeResource( _RESOURCE * resource )
159 {
160 if (resource != NULL) {
161 free(resource);
162 resource = NULL;
163 }
165 return 1;
166 }
168 // ----------------------------------------------------------------------------
170 /* Set the property values of a CMPI instance from a specific resource. */
171 int Xen_ProcessorPool_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
172 {
173 if (resource == NULL) return 0;
174 if (CMIsNullObject(instance)) return 0;
176 CMSetProperty(instance, "InstanceID",(CMPIValue *)"XenProcessorPool", CMPI_chars);
177 CMSetProperty(instance, "PoolID",(CMPIValue *)"XenProcessorPool", CMPI_chars);
179 int type = 3; /* 3 == Processor */
180 CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
182 CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Cores", CMPI_chars);
184 CMSetProperty(instance, "Capacity",(CMPIValue *)&(resource->capacity), CMPI_uint64);
185 CMSetProperty(instance, "Reserved",(CMPIValue *)&(resource->reserved), CMPI_uint64);
187 int primordial = 1;
188 CMSetProperty(instance, "Primordial" , (CMPIValue *)&primordial, CMPI_boolean);
190 return 1;
191 }
193 // ----------------------------------------------------------------------------
195 /* Delete the specified resource from the system. */
196 int Xen_ProcessorPool_deleteResource( _RESOURCES * resources, _RESOURCE * resource )
197 {
198 /* Unsupported. */
199 return -1;
200 }
202 // ----------------------------------------------------------------------------
204 /* Modify the specified resource using the property values of a CMPI instance. */
205 int Xen_ProcessorPool_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker )
206 {
207 /* Unsupported. */
208 return -1;
209 }
211 // ----------------------------------------------------------------------------
213 /* Create a new resource using the property values of a CMPI instance. */
214 int Xen_ProcessorPool_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker )
215 {
216 /* Unsupported. */
217 return -1;
218 }