os-cmpi-xen

view src/Xen_MemorySettingData_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 b66e845be7e4
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 // Raj Subrahmanian <raj.subrahmanian@unisys.com>
20 // Description:
21 // ============================================================================
23 #include <stdlib.h>
24 #include <string.h>
25 #include <assert.h>
27 #include <xen_common.h>
28 #include <xen_vm.h>
29 #include <xen_vm_metrics.h>
30 #include "Xen_MemorySettingData_Resource.h"
32 /* Include the required CMPI data types, function headers, and macros. */
33 #include "cmpidt.h"
34 #include "cmpift.h"
35 #include "cmpimacs.h"
37 /* Include _SBLIM_TRACE() logging support */
38 #include "cmpitrace.h"
40 #include "xen_utils.h"
41 #include "provider_common.h"
43 // ----------------------------------------------------------------------------
45 /* Get a handle to the list of all system resources for this class. */
46 int Xen_MemorySettingData_getResources(xen_utils_session *session,
47 _RESOURCES ** resources)
48 {
49 return xen_utils_get_domain_resources(session, resources);
50 }
52 // ----------------------------------------------------------------------------
54 /* Free/deallocate/cleanup the resources list after use. */
55 int Xen_MemorySettingData_freeResources(_RESOURCES * resources)
56 {
57 return xen_utils_free_domain_resources(resources);
58 }
60 // ----------------------------------------------------------------------------
62 /* Iterator to get the next resource from the resources list. */
63 int Xen_MemorySettingData_getNextResource(xen_utils_session *session,
64 _RESOURCES * resources,
65 _RESOURCE ** resource)
66 {
67 return xen_utils_get_next_domain_resource(session, resources, resource);
68 }
70 // ----------------------------------------------------------------------------
72 /* Get the specific resource that matches the CMPI object path. */
73 int Xen_MemorySettingData_getResourceForObjectPath(xen_utils_session *session,
74 _RESOURCES * resources,
75 _RESOURCE ** resource,
76 const CMPIObjectPath * objectpath)
77 {
78 char *instId;
79 char name [MAX_SYSTEM_NAME_LEN];
80 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
82 /* Check input params are valid. */
83 if (resources == NULL) return 0;
84 if (CMIsNullObject(objectpath)) return 0;
86 /* Obtain the target resource identifier from the CMPIObjectPath key(s). */
87 CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status);
88 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0;
90 /* Extract the id string from the CMPIString. */
91 instId = CMGetCharPtr(iddata.value.string);
92 if ((instId == NULL) || (*instId == '\0')) return 0;
94 /* Extract the system name from InstanceID property. */
95 if (!_CMPIStrncpySystemNameFromID(name, instId, MAX_SYSTEM_NAME_LEN))
96 return 0;
98 /* Get the domain data for the target domain name. */
99 xen_vm_set *vms;
100 if (!xen_vm_get_by_name_label(session->xen, &vms, name)) {
101 /* Error is in session object! */
102 *resource = NULL;
103 return 0;
104 }
106 assert(vms->size == 1);
107 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
108 /* Error description in session object! */
109 xen_vm_set_free(vms);
110 return 0;
111 }
113 xen_vm_set_free(vms);
115 return 1;
116 }
118 // ----------------------------------------------------------------------------
120 /* Free/deallocate/cleanup the resource after use. */
121 int Xen_MemorySettingData_freeResource(_RESOURCE * resource)
122 {
123 return xen_utils_free_domain_resource(resource);
124 }
126 // ----------------------------------------------------------------------------
128 /* Set the property values of a CMPI instance from a specific resource. */
129 int Xen_MemorySettingData_setInstanceFromResource(xen_utils_session *session,
130 _RESOURCE * resource,
131 const CMPIInstance * instance,
132 const CMPIBroker * broker)
133 {
134 char buf[1024];
136 if (resource == NULL) return 0;
137 if (CMIsNullObject(instance)) return 0;
139 /* Set the CMPIInstance properties from the resource data. */
140 snprintf(buf, 1024, "Xen:%s:Memory1", resource->name_label);
141 CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars);
143 CMSetProperty(instance, "ElementName",(CMPIValue *)"Memory1", CMPI_chars);
145 int type = 4; /* 4 == Memory */
146 CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16);
148 int consumerVisibility = 2; /* 2 == Passed-Through */
149 CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&consumerVisibility, CMPI_uint16);
151 int64_t memory;
152 // Get the memory_actual
153 if (resource->metrics->is_record)
154 memory=resource->metrics->u.record->memory_actual;
155 else
156 xen_vm_metrics_get_memory_actual(session->xen, &memory, resource->metrics->u.handle);;
157 CMSetProperty(instance, "Reservation",(CMPIValue *)&memory, CMPI_uint64);
158 memory = resource->memory_dynamic_max;
159 CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&memory, CMPI_uint64);
160 CMSetProperty(instance, "Limit",(CMPIValue *)&memory, CMPI_uint64);
162 CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Bytes", CMPI_chars);
164 int alloctype = 1;
165 CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean);
166 CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean);
168 /*
169 * TODO:
170 * PoolID, Weight, HostResource
171 */
173 return 1;
174 }
176 // ----------------------------------------------------------------------------
178 /* Delete the specified resource from the system. */
179 int Xen_MemorySettingData_deleteResource(_RESOURCES * resources,
180 _RESOURCE * resource)
181 {
182 /* Unsupported. */
183 return -1;
184 }
186 // ----------------------------------------------------------------------------
188 /* Modify the specified resource using the property values of a CMPI instance. */
189 int Xen_MemorySettingData_setResourceFromInstance(xen_utils_session *session,
190 _RESOURCE * resource,
191 const CMPIInstance * instance)
192 {
193 CMPIData propertyvalue;
194 uint64_t req_mem;
196 CMPIStatus status = {CMPI_RC_OK, NULL};
198 /* Only support modifying the amount of memory. */
199 _SBLIM_TRACE(2,("--- modifying %s memory settings", resource->name_label));
200 propertyvalue = CMGetProperty(instance, "VirtualQuantity", &status);
201 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
202 _SBLIM_TRACE(1,("--- Unable to determine VirtualQuantity in Memory RASD"));
203 return 0;
204 }
206 req_mem = propertyvalue.value.uint64;
207 if ((req_mem < resource->memory_static_min) ||
208 (req_mem > resource->memory_static_max)) {
209 _SBLIM_TRACE(1,("--- Unable to set memory outside of range %lld Mb - %lld Mb",
210 resource->memory_static_min,
211 resource->memory_static_max));
212 return 0;
213 }
215 if (req_mem > resource->memory_dynamic_max)
216 return (xen_vm_set_memory_dynamic_max(session->xen, resource->handle, req_mem));
217 else
218 return (xen_vm_set_memory_dynamic_max(session->xen, resource->handle, req_mem));
219 }
221 // ----------------------------------------------------------------------------
223 /* Create a new resource using the property values of a CMPI instance. */
224 int Xen_MemorySettingData_createResourceFromInstance(_RESOURCES * resources,
225 _RESOURCE ** resource,
226 const CMPIInstance * instance,
227 const CMPIBroker * broker)
228 {
229 /* Unsupported. */
230 return -1;
231 }