os-cmpi-xen

view src/Xen_Memory_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 // Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
19 // Contributors: Jim Fehlig, <jfehlig@novell.com>
20 // Raj Subrahmanian <raj.subrahmanian@unisys.com>
21 // Description:
22 // ============================================================================
24 #include <xen_common.h>
25 #include <xen_vm.h>
26 #include <xen_vm_metrics.h>
28 #include <stdlib.h>
29 #include <assert.h>
31 #include "Xen_Memory_Resource.h"
33 /* Include the required CMPI data types, function headers, and macros. */
34 #include "cmpidt.h"
35 #include "cmpift.h"
36 #include "cmpimacs.h"
38 #include "xen_utils.h"
40 // ----------------------------------------------------------------------------
42 /* Get a handle to the list of all system resources for this class. */
43 int Xen_Memory_getResources(xen_utils_session *session,
44 _RESOURCES ** resources)
45 {
46 return xen_utils_get_domain_resources(session, resources);
47 }
49 // ----------------------------------------------------------------------------
51 /* Free/deallocate/cleanup the resources list after use. */
52 int Xen_Memory_freeResources(_RESOURCES * resources)
53 {
54 return xen_utils_free_domain_resources(resources);
55 }
57 // ----------------------------------------------------------------------------
59 /* Iterator to get the next resource from the resources list. */
60 int Xen_Memory_getNextResource(xen_utils_session *session,
61 _RESOURCES * resources,
62 _RESOURCE ** resource)
63 {
64 /* Check if reached the end of the list of Xen domain names. */
65 if (!XEN_UTILS_MORE_DOMAIN_RESOURCES(resources))
66 return 0;
68 /* Get the current domain. */
69 if (!xen_utils_get_next_domain_resource(session, resources, resource))
70 return 0;
72 /* Only serve up memory devices if the domain is not halted */
73 if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED)
74 goto NextDomain;
76 return 1;
78 NextDomain:
79 /* All memory devices in this domain have been exhausted. */
80 /* Start serving up memory devices for the next domain, if it exists */
81 Xen_Memory_freeResource(*resource);
82 if (!XEN_UTILS_MORE_DOMAIN_RESOURCES(resources))
83 return 0;
85 /* Get the next domain resource. */
86 if (!xen_utils_get_next_domain_resource(session, resources, resource))
87 return 0;
89 /* Only serve up block devices if the domain is not inactive */
90 if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED)
91 goto NextDomain;
93 return 1;
94 }
96 // ----------------------------------------------------------------------------
98 /* Get the specific resource that matches the CMPI object path. */
99 int Xen_Memory_getResourceForObjectPath(xen_utils_session *session,
100 _RESOURCES * resources,
101 _RESOURCE ** resource,
102 const CMPIObjectPath * objectpath)
103 {
104 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
106 if (resources == NULL) return 0;
107 if (CMIsNullObject(objectpath)) return 0;
109 /* Obtain the target domain name from the CMPIObjectPath "SystemName" key. */
110 CMPIData namedata = CMGetKey(objectpath, "SystemName", &status);
111 if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0;
113 /* Extract the domain name string from the CMPIString. */
114 char * domainname = CMGetCharPtr(namedata.value.string);
115 if ((domainname == NULL) || (*domainname == '\0')) return 0;
117 /* Get the domain data for the target domain name. */
118 xen_vm_set *vms;
119 if (!xen_vm_get_by_name_label(session->xen, &vms, domainname)) {
120 /* Error is in session object! */
121 *resource = NULL;
122 return 0;
123 }
125 assert(vms->size == 1);
126 if (!xen_vm_get_record(session->xen, resource, vms->contents[0])) {
127 /* Error description in session object! */
128 xen_vm_set_free(vms);
129 return 0;
130 }
132 xen_vm_set_free(vms);
134 return 1;
135 }
137 // ----------------------------------------------------------------------------
139 /* Free/deallocate/cleanup the resource after use. */
140 int Xen_Memory_freeResource(_RESOURCE * resource)
141 {
142 return xen_utils_free_domain_resource(resource);
143 }
145 // ----------------------------------------------------------------------------
147 /* Set the property values of a CMPI instance from a specific resource.
148 Added session parameter so that the memory_actual value can be picked up from xen_vm_metrics : Raj Subrahmanian 04/04/2007*/
149 int Xen_Memory_setInstanceFromResource(xen_utils_session *session,
150 _RESOURCE * resource,
151 const CMPIInstance * instance,
152 const CMPIBroker * broker)
153 {
154 if (resource == NULL) return 0;
155 if (CMIsNullObject(instance)) return 0;
157 /* Set the CMPIInstance properties from the resource data. */
158 CMSetProperty(instance, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars);
159 CMSetProperty(instance, "SystemName",(CMPIValue *)resource->name_label, CMPI_chars);
160 CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_Memory", CMPI_chars);
161 CMSetProperty(instance, "DeviceID",(CMPIValue *)"Memory1", CMPI_chars);
163 CMSetProperty(instance, "Caption",(CMPIValue *)"Main Memory", CMPI_chars);
164 CMSetProperty(instance, "Description",(CMPIValue *)"Main Memory", CMPI_chars);
165 CMSetProperty(instance, "Purpose",(CMPIValue *)"Main Memory", CMPI_chars);
166 CMSetProperty(instance, "Name",(CMPIValue *)"Memory1", CMPI_chars);
168 /* BlockSize should be set to 1 as per Core/CIM_StorageExtent.mof. */
169 uint64_t blocksize = 1;
170 CMSetProperty(instance, "BlockSize", (CMPIValue *)&blocksize, CMPI_uint64);
172 int64_t blocks = resource->memory_dynamic_max;
173 CMSetProperty(instance, "NumberOfBlocks", (CMPIValue *)&blocks, CMPI_uint64);
175 // Get the memory_actual
176 if (resource->metrics->is_record)
177 blocks=resource->metrics->u.record->memory_actual;
178 else
179 xen_vm_metrics_get_memory_actual(session->xen, &blocks, resource->metrics->u.handle);
180 CMSetProperty(instance, "ConsumableBlocks", (CMPIValue *)&blocks, CMPI_uint64);
182 if (resource->power_state == XEN_VM_POWER_STATE_RUNNING)
183 CMSetProperty(instance, "Status", (CMPIValue *)"OK", CMPI_chars);
184 else
185 CMSetProperty(instance, "Status", (CMPIValue *)"No Contact", CMPI_chars);
187 return 1;
188 }
190 // ----------------------------------------------------------------------------
192 /* Delete the specified resource from the system. */
193 int Xen_Memory_deleteResource(_RESOURCES * resources, _RESOURCE * resource)
194 {
195 /* Unsupported. */
196 return -1;
197 }
199 // ----------------------------------------------------------------------------
201 /* Modify the specified resource using the property values of a CMPI instance. */
202 int Xen_Memory_setResourceFromInstance(_RESOURCE * resource,
203 const CMPIInstance * instance,
204 const CMPIBroker * broker)
205 {
206 /* TODO - support ballooning DomU memory here */
208 /* Unsupported. */
209 return -1;
210 }
212 // ----------------------------------------------------------------------------
214 /* Create a new resource using the property values of a CMPI instance. */
215 int Xen_Memory_createResourceFromInstance(_RESOURCES * resources,
216 _RESOURCE ** resource,
217 const CMPIInstance * instance,
218 const CMPIBroker * broker)
219 {
220 /* Unsupported. */
221 return -1;
222 }