os-cmpi-xen

view src/Xen_MemoryElementSettingData.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 28127889bbd8
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 the required CMPI data types, function headers, and macros */
25 #include "cmpidt.h"
26 #include "cmpift.h"
27 #include "cmpimacs.h"
29 /* Include utility functions */
30 #include "cmpiutil.h"
32 /* Include _SBLIM_TRACE() logging support */
33 #include "cmpitrace.h"
35 #include "xen_utils.h"
36 #include "provider_common.h"
39 // ----------------------------------------------------------------------------
40 // COMMON GLOBAL VARIABLES
41 // ----------------------------------------------------------------------------
43 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
44 static const CMPIBroker *_BROKER;
46 /* Xen session object. Initialize when the provider is loaded, close when
47 * provider unloaded. */
48 static xen_utils_session *session = NULL;
51 // ============================================================================
52 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE
53 // ============================================================================
55 // ----------------------------------------------------------------------------
56 // Info for the class supported by the association provider
57 // ----------------------------------------------------------------------------
59 /* Name of the left and right hand side classes of this association. */
60 static char * _ASSOCCLASS = "Xen_MemoryElementSettingData";
61 static char * _TARGETCLASS = "Xen_MemorySettingData";
62 static char * _LHSPROPERTYNAME = "SettingData";
63 static char * _RHSPROPERTYNAME = "ManagedElement";
64 static char * _KEYNAME = "InstanceID";
66 // ----------------------------------------------------------------------------
67 // AssociationCleanup()
68 // Perform any necessary cleanup immediately before this provider is unloaded.
69 // ----------------------------------------------------------------------------
70 static CMPIStatus AssociationCleanup(
71 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
72 const CMPIContext * context, /* [in] Additional context info, if any. */
73 CMPIBoolean terminating) /* [in] True if MB is terminating */
74 {
75 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
77 _SBLIM_ENTER("AssociationCleanup");
78 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
79 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
81 if (session) {
82 xen_utils_xen_close(session);
83 session = NULL;
84 }
85 _SBLIM_RETURNSTATUS(status);
86 }
89 // ----------------------------------------------------------------------------
90 // AssociatorNames()
91 // ----------------------------------------------------------------------------
92 static CMPIStatus AssociatorNames(
93 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
94 const CMPIContext * context, /* [in] Additional context info, if any. */
95 const CMPIResult * results, /* [out] Results of this operation. */
96 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */
97 const char * assocClass,
98 const char * resultClass,
99 const char * role,
100 const char * resultRole)
101 {
102 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
103 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
104 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
106 _SBLIM_ENTER("AssociatorNames");
107 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
108 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
109 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
110 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
111 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
112 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
113 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
114 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
115 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
117 /* Check that the requested association class, if any, is supported. */
118 if (assocClass != NULL) {
119 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
120 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
121 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
122 goto exit;
123 }
124 }
126 /* Check that the reference matches the required role, if any. */
127 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
128 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
129 goto exit;
130 }
132 /*
133 * Target and source class are the same for this association since XenCIM
134 * implements the "Single Configuration" approach described in the
135 * Virtual System Profile. In the Single Configuration approach this
136 * association associates the same object - so just return the incoming
137 * reference.
138 */
139 CMReturnObjectPath(results, reference);
141 CMReturnDone(results);
143 exit:
144 _SBLIM_RETURNSTATUS(status);
145 }
148 // ----------------------------------------------------------------------------
149 // Associators()
150 // ----------------------------------------------------------------------------
151 static CMPIStatus Associators(
152 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
153 const CMPIContext * context, /* [in] Additional context info, if any. */
154 const CMPIResult * results, /* [out] Results of this operation. */
155 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
156 const char *assocClass,
157 const char *resultClass,
158 const char *role,
159 const char *resultRole,
160 const char ** properties) /* [in] List of desired properties (NULL=all). */
161 {
162 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
163 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
164 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
166 _SBLIM_ENTER("Associators");
167 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
168 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
169 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
170 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
171 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
172 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
173 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
174 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
175 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
177 /* Check that the requested association class, if any, is supported. */
178 if (assocClass != NULL) {
179 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
180 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
181 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
182 goto exit;
183 }
184 }
186 /* Check that the reference matches the required role, if any. */
187 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
188 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
189 goto exit;
190 }
192 /*
193 * Target and source class are the same for this association since XenCIM
194 * implements the "Single Configuration" approach described in the
195 * Virtual System Profile. In the Single Configuration approach this
196 * association associates the same object - so just return the instance
197 * specified by the incoming reference.
198 */
199 CMPIInstance * instance = CBGetInstance(_BROKER, context, reference, properties, &status);
200 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
201 _SBLIM_TRACE(1,("--- CBGetInstance() failed - %s", CMGetCharPtr(status.msg)));
202 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot retrieve instance of target class");
203 goto exit;
204 }
205 CMReturnInstance(results, instance);
207 CMReturnDone(results);
209 exit:
210 _SBLIM_RETURNSTATUS(status);
211 }
214 // ----------------------------------------------------------------------------
215 // ReferenceNames()
216 // ----------------------------------------------------------------------------
217 static CMPIStatus ReferenceNames(
218 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
219 const CMPIContext * context, /* [in] Additional context info, if any. */
220 const CMPIResult * results, /* [out] Results of this operation. */
221 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */
222 const char *assocClass,
223 const char *role)
224 {
225 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
226 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
227 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
229 _SBLIM_ENTER("ReferenceNames");
230 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
231 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
232 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
233 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
234 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
235 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
236 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
238 /* Check that the requested association class, if any, is supported. */
239 if (assocClass != NULL) {
240 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
241 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
242 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
243 goto exit;
244 }
245 }
247 /* Check that the reference matches the required role, if any. */
248 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
249 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
250 goto exit;
251 }
253 /*
254 * Target and source class are the same for this association since XenCIM
255 * implements the "Single Configuration" approach described in the
256 * Virtual System Profile. In the Single Configuration approach this
257 * association associates the same object - so just create an object path
258 * for the association and return it.
259 */
260 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, &status);
261 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
262 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg)));
263 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath");
264 goto exit;
265 }
267 /*
268 * Assign the references in the association. Same reference goes
269 * in both sides of the association.
270 */
271 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
272 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
274 CMReturnObjectPath(results, refobjectpath);
276 exit:
277 _SBLIM_RETURNSTATUS(status);
278 }
281 // ----------------------------------------------------------------------------
282 // References()
283 // ----------------------------------------------------------------------------
284 static CMPIStatus References(
285 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
286 const CMPIContext * context, /* [in] Additional context info, if any. */
287 const CMPIResult * results, /* [out] Results of this operation. */
288 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */
289 const char *assocClass,
290 const char *role,
291 const char **properties) /* [in] List of desired properties (NULL=all). */
292 {
293 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
294 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
295 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */
296 char domainname[MAX_SYSTEM_NAME_LEN];
298 _SBLIM_ENTER("References");
299 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
300 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
301 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
302 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
303 _SBLIM_TRACE(2, ("--- role=\"%s\"", role));
304 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
305 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
307 if (!xen_utils_validate_session(&session)) {
308 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
309 goto exit;
310 }
312 /* Check that the requested association class, if any, is supported. */
313 if (assocClass != NULL) {
314 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL);
315 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
316 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request."));
317 goto exit;
318 }
319 }
321 /* Check that the reference matches the required role, if any. */
322 if ((role != NULL) && strcmp(role, sourceclass) != 0) {
323 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request."));
324 goto exit;
325 }
327 /*
328 * Target and source class are the same for this association since XenCIM
329 * implements the "Single Configuration" approach described in the
330 * Virtual System Profile. In the Single Configuration approach this
331 * association associates the same object - so just create an instance
332 * of the association and return it.
333 */
334 CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace, _ASSOCCLASS, &status);
335 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
336 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
337 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
338 goto exit;
339 }
341 /*
342 * Assign the references in the association. Same reference goes
343 * in both sides of the association.
344 */
345 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
346 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
348 /* Fill in other properties of the association instance. */
349 int propVal = 1; // 1 == Is Default
350 CMSetProperty(refinstance, "IsDefault", (CMPIValue *)&propVal, CMPI_uint16);
352 /* If the vm is active, IsCurrent should be to 1, otherwise 2. */
353 CMPIData namedata = CMGetKey(reference, _KEYNAME, NULL);
354 _CMPIStrncpySystemNameFromID(domainname, CMGetCharPtr(namedata.value.string), MAX_SYSTEM_NAME_LEN);
356 int isActive;
357 if (xen_utils_is_domain_active(session, domainname, &isActive)) {
358 if (isActive) {
359 CMSetProperty(refinstance, "IsCurrent", (CMPIValue *)&propVal, CMPI_uint16);
360 }
361 else {
362 propVal = 2; // 2 == Is Not Current
363 CMSetProperty(refinstance, "IsCurrent", (CMPIValue *)&propVal, CMPI_uint16);
364 }
365 }
367 propVal = 2; // 2 == Is Not Next
368 CMSetProperty(refinstance, "IsNext", (CMPIValue *)&propVal, CMPI_uint16);
370 CMReturnInstance(results, refinstance);
372 exit:
373 _SBLIM_RETURNSTATUS(status);
374 }
377 // ----------------------------------------------------------------------------
378 // AssociationInitialize()
379 // Perform any necessary initialization immediately after this provider is
380 // first loaded.
381 // ----------------------------------------------------------------------------
382 static void AssociationInitialize(
383 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */
384 const CMPIContext * context) /* [in] Additional context info, if any. */
385 {
386 _SBLIM_ENTER("AssociationInitialize");
387 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
388 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
390 /* Initialized Xen session object. */
391 if (session == NULL)
392 xen_utils_xen_init(&session);
394 _SBLIM_RETURN();
395 }
398 // ============================================================================
399 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP
400 // ============================================================================
401 CMAssociationMIStub( , Xen_MemoryElementSettingData, _BROKER, AssociationInitialize(&mi, ctx));