os-cmpi-xen

view src/Xen_ProcessorPool.c @ 143:fc498265d293

Fixed warning (and bug) in Xen_DiskSettingData.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Thu Aug 16 17:49:08 2007 -0600 (2007-08-16)
parents 26f10941718e
children
line source
1 // Copyright (C) 2007 Novell, Inc.
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: Xen implementation of CIM_ResourcePool for CPU.
20 // ============================================================================
22 /* Common declarations for each CMPI "Cimpler" instance provider */
23 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
24 #include <cmpidt.h>
25 #include <cmpimacs.h>
27 #include "cmpilify.h"
30 static const CMPIInstanceMI* mi;
33 #define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
34 #define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
35 #define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
37 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 #include <stdlib.h>
41 #include <xen_common.h>
42 #include <xen_host.h>
43 #include <xen_host_cpu.h>
45 #include "cmpitrace.h"
46 #include "xen_utils.h"
47 #include "provider_common.h"
49 /* Class keys */
50 static const char *keys[] = {"InstanceID", NULL};
53 /* Xen session object. Initialize when the provider is loaded, close when
54 * provider unloaded. */
55 static xen_utils_session *session = NULL;
58 static CMPIrc load()
59 {
60 /* Initialized Xen session object. */
61 if (!session)
62 xen_utils_xen_init(&session);
64 return CMPI_RC_OK;
65 }
68 static CMPIrc unload(const int terminating)
69 {
70 (void)terminating;
72 /* Close Xen session object. */
73 if (session) {
74 xen_utils_xen_close(session);
75 session = NULL;
76 }
78 return CMPI_RC_OK;
79 }
82 /* Get the single instance. */
83 static CMPIrc get(void **res, const char** properties)
84 {
85 xen_host_cpu_set *host_cpus;
87 (void)properties;
89 if (!xen_utils_validate_session(&session)) {
90 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
91 ("--- Unable to establish connection with Xend"));
92 return CMPI_RC_ERR_FAILED;
93 }
95 if (!xen_host_get_host_cpus(session->xen, &host_cpus, session->host)) {
96 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
97 ("--- Failed to retrieve host cpus from Xend"));
98 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
99 xen_utils_trace_error(session->xen));
100 return CMPI_RC_ERR_FAILED;
101 }
103 *res = (void *)host_cpus;
104 return CMPI_RC_OK;
105 }
108 static void release(void *res)
109 {
110 if (res)
111 xen_host_cpu_set_free((xen_host_cpu_set *)res);
112 }
115 /* Set CMPIInstance properties from the resource data. */
116 static CMPIrc setproperties(CMPIInstance *inst, const void *res,
117 const char **properties)
118 {
119 xen_host_cpu_set *host_cpus = (xen_host_cpu_set *)res;
120 char *host_name;
121 char buf[MAX_INSTANCEID_LEN];
122 uint64_t prop_val_64;
123 int prop_val_32;
125 if (host_cpus == NULL)
126 return CMPI_RC_ERR_FAILED;
128 if (CMIsNullObject(inst))
129 return CMPI_RC_ERR_FAILED;
131 /* Setup a filter to only return the desired properties. */
132 CMSetPropertyFilter(inst, properties, keys);
134 session->xen->ok = true;
135 xen_host_get_name_label(session->xen, &host_name, session->host);
136 if (session->xen->ok) {
137 snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:ProcessorPool",
138 host_name);
139 CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
140 free(host_name);
141 }
142 else {
143 CMSetProperty(inst, "InstanceID",
144 (CMPIValue *)"Xen:ProcessorPool", CMPI_chars);
145 }
147 CMSetProperty(inst, "PoolID", (CMPIValue *)"XenProcessorPool", CMPI_chars);
149 prop_val_32 = 3; /* 3 == Processor */
150 CMSetProperty(inst, "ResourceType", (CMPIValue *)&prop_val_32, CMPI_uint16);
151 CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"Cores", CMPI_chars);
153 /* Capacity is the number of items in xen_host_cpu_set. */
154 prop_val_64 = host_cpus->size;
155 CMSetProperty(inst, "Capacity", (CMPIValue *)&prop_val_64, CMPI_uint64);
157 /*
158 * Xen does not currently support dedicated processor allocation,
159 * therefore no processors can be exclusively 'reserved' by a DomU.
160 */
161 prop_val_64 = 0;
162 CMSetProperty(inst, "Reserved", (CMPIValue *)&prop_val_64, CMPI_uint64);
164 prop_val_32 = 1;
165 CMSetProperty(inst, "Primordial" , (CMPIValue *)&prop_val_32, CMPI_boolean);
167 return CMPI_RC_OK;
168 }
171 /* Setup CMPILIFY function tables and instance provider entry point.*/
172 /* CMPILIFYInstance1ROMIStub(<CLASS>,<PROVIDERNAME>,<KEYS>,<MIHANDLE>) */
173 CMPILIFYInstance1ROMIStub(Xen_ProcessorPool, Xen_ProcessorPool, keys, mi)