os-cmpi-xen

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