os-cmpi-xen

annotate src/Xen_ProcessorPool.c @ 25:16d625984bc4

Lots of work on MemoryPool and its associations. Also fixed bugs in various
associations that were discovered while working on the MemoryPool associations.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author jfehlig@jfehlig3.provo.novell.com
date Thu Sep 28 17:07:14 2006 -0600 (2006-09-28)
parents 94fc22b52c5d
children 33d4316c01a2
rev   line source
jbulpin@0 1 // Copyright (C) 2006 IBM Corporation
jbulpin@0 2 //
jbulpin@0 3 // This library is free software; you can redistribute it and/or
jbulpin@0 4 // modify it under the terms of the GNU Lesser General Public
jbulpin@0 5 // License as published by the Free Software Foundation; either
jbulpin@0 6 // version 2.1 of the License, or (at your option) any later version.
jbulpin@0 7 //
jbulpin@0 8 // This library is distributed in the hope that it will be useful,
jbulpin@0 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
jbulpin@0 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
jbulpin@0 11 // Lesser General Public License for more details.
jbulpin@0 12 //
jbulpin@0 13 // You should have received a copy of the GNU Lesser General Public
jbulpin@0 14 // License along with this library; if not, write to the Free Software
jbulpin@0 15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
jbulpin@0 16 // ============================================================================
jbulpin@0 17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
jfehlig@25 18 // Jim Fehlig, <jfehlig@novell.com>
jbulpin@0 19 // Contributors:
jbulpin@0 20 // Description:
jbulpin@0 21 // ============================================================================
jbulpin@0 22
jbulpin@0 23 /* Include the required CMPI data types, function headers, and macros */
jbulpin@0 24 #include "cmpidt.h"
jbulpin@0 25 #include "cmpift.h"
jbulpin@0 26 #include "cmpimacs.h"
jbulpin@0 27
jfehlig@25 28 #include "provider_common.h"
jbulpin@0 29
jbulpin@0 30 // ----------------------------------------------------------------------------
jbulpin@0 31 // COMMON GLOBAL VARIABLES
jbulpin@0 32 // ----------------------------------------------------------------------------
jbulpin@0 33
jbulpin@0 34 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */
jbulpin@0 35 static CMPIBroker *_BROKER;
jbulpin@0 36
jbulpin@0 37 /* Include utility functions */
jbulpin@0 38 #include "cmpiutil.h"
jbulpin@0 39
jbulpin@0 40 /* Include _SBLIM_TRACE() logging support */
jbulpin@0 41 #include "cmpitrace.h"
jbulpin@0 42
jbulpin@0 43 /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
jbulpin@0 44 #include "Xen_ProcessorPool_Resource.h"
jbulpin@0 45
jbulpin@0 46
jbulpin@0 47 // ============================================================================
jbulpin@0 48 // CMPI INSTANCE PROVIDER FUNCTION TABLE
jbulpin@0 49 // ============================================================================
jbulpin@0 50
jbulpin@0 51 // ----------------------------------------------------------------------------
jbulpin@0 52 // Info for the class supported by the instance provider
jbulpin@0 53 // ----------------------------------------------------------------------------
jbulpin@0 54
jbulpin@0 55 /* Name of the class implemented by this instance provider. */
jbulpin@0 56 /*** CUSTOMIZE FOR EACH PROVIDER ***/
jbulpin@0 57 static char * _CLASSNAME = "Xen_ProcessorPool";
jbulpin@0 58
jbulpin@0 59 /* NULL terminated list of key properties of this class. */
jbulpin@0 60 /*** CUSTOMIZE FOR EACH PROVIDER ***/
jfehlig@14 61 const static char * _KEYNAMES[] = {"InstanceID", NULL};
jbulpin@0 62
jbulpin@0 63 // ----------------------------------------------------------------------------
jbulpin@0 64 // Cleanup()
jbulpin@0 65 // Perform any necessary cleanup immediately before this provider is unloaded.
jbulpin@0 66 // ----------------------------------------------------------------------------
jbulpin@0 67 static CMPIStatus Cleanup(
jbulpin@0 68 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 69 CMPIContext * context) /* [in] Additional context info, if any. */
jbulpin@0 70 {
jbulpin@0 71 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */
jbulpin@0 72
jbulpin@0 73 _SBLIM_ENTER("Cleanup");
jbulpin@0 74 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 75 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 76
jbulpin@0 77 /* Nothing needs to be done for cleanup. */
jbulpin@0 78
jbulpin@0 79 exit:
jbulpin@0 80 _SBLIM_RETURNSTATUS(status);
jbulpin@0 81 }
jbulpin@0 82
jbulpin@0 83 // ----------------------------------------------------------------------------
jbulpin@0 84 // EnumInstanceNames()
jbulpin@0 85 // Return a list of all the instances names (return their object paths only).
jbulpin@0 86 // ----------------------------------------------------------------------------
jbulpin@0 87 static CMPIStatus EnumInstanceNames(
jbulpin@0 88 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 89 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 90 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 91 CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */
jbulpin@0 92 {
jbulpin@0 93 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 94 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 95 _RESOURCE * resource; /* Handle to each system resource. */
jbulpin@0 96 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 97 int found = 0; /* Found any instances? */
jbulpin@0 98
jbulpin@0 99 _SBLIM_ENTER("EnumInstanceNames");
jbulpin@0 100 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 101 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 102 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 103 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 104
jfehlig@25 105 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 106 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 107 goto exit;
jfehlig@25 108 }
jfehlig@25 109
jbulpin@0 110 /* Get a handle to the list of system resources. */
jbulpin@0 111 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 112 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 113 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 114 goto exit;
jbulpin@0 115 }
jbulpin@0 116
jbulpin@0 117 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
jfehlig@16 118 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
jbulpin@0 119 /* Create a new CMPIInstance to store this resource. */
jbulpin@0 120 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jbulpin@0 121 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jbulpin@0 122 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 123 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jbulpin@0 124 goto exit;
jbulpin@0 125 }
jbulpin@0 126
jbulpin@0 127 /* Set the instance property values from the resource data. */
jbulpin@0 128 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
jbulpin@0 129 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jbulpin@0 130 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jbulpin@0 131 goto exit;
jbulpin@0 132 }
jbulpin@0 133
jbulpin@0 134 /* Free the resource data. */
jbulpin@0 135 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 136 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 137 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 138 goto exit;
jbulpin@0 139 }
jbulpin@0 140
jbulpin@0 141 /* Return the CMPIObjectPath for this instance. */
jbulpin@0 142 CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
jbulpin@0 143 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
jbulpin@0 144 _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 145 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
jbulpin@0 146 goto exit;
jbulpin@0 147 }
jbulpin@0 148 CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
jbulpin@0 149
jbulpin@0 150 _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
jbulpin@0 151 CMReturnObjectPath(results, objectpath);
jbulpin@0 152 found++;
jbulpin@0 153 }
jbulpin@0 154
jbulpin@0 155 _SBLIM_TRACE(2,("--- %d object paths found", found));
jbulpin@0 156 CMReturnDone(results);
jbulpin@0 157
jbulpin@0 158 exit:
jbulpin@0 159 /* Free the list of system resources. */
jbulpin@0 160 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 161 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 162 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 163 }
jbulpin@0 164
jbulpin@0 165 _SBLIM_RETURNSTATUS(status);
jbulpin@0 166 }
jbulpin@0 167
jbulpin@0 168 // ----------------------------------------------------------------------------
jbulpin@0 169 // EnumInstances()
jbulpin@0 170 // Return a list of all the instances (return all the instance data).
jbulpin@0 171 // ----------------------------------------------------------------------------
jbulpin@0 172 static CMPIStatus EnumInstances(
jbulpin@0 173 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 174 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 175 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 176 CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */
jbulpin@0 177 const char ** properties) /* [in] List of desired properties (NULL=all). */
jbulpin@0 178 {
jbulpin@0 179 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 180 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 181 _RESOURCE * resource; /* Handle to each system resource. */
jbulpin@0 182 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 183 int found = 0; /* Found any resource instances? */
jbulpin@0 184
jbulpin@0 185 _SBLIM_ENTER("EnumInstances");
jbulpin@0 186 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 187 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 188 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 189 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 190
jfehlig@25 191 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 192 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 193 goto exit;
jfehlig@25 194 }
jfehlig@25 195
jbulpin@0 196 /* Get a handle to the list of system resources. */
jbulpin@0 197 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 198 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 199 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 200 goto exit;
jbulpin@0 201 }
jbulpin@0 202
jbulpin@0 203 /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
jfehlig@16 204 while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) {
jbulpin@0 205 /* Create a new CMPIInstance to store this resource. */
jbulpin@0 206 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jbulpin@0 207 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jbulpin@0 208 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 209 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jbulpin@0 210 goto exit;
jbulpin@0 211 }
jbulpin@0 212
jbulpin@0 213 /* Setup a filter to only return the desired properties. */
jbulpin@0 214 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
jbulpin@0 215 if (status.rc != CMPI_RC_OK) {
jbulpin@0 216 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 217 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
jbulpin@0 218 goto exit;
jbulpin@0 219 }
jbulpin@0 220
jbulpin@0 221 /* Set the instance property values from the resource data. */
jbulpin@0 222 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
jbulpin@0 223 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jbulpin@0 224 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jbulpin@0 225 goto exit;
jbulpin@0 226 }
jbulpin@0 227
jbulpin@0 228 /* Free the resource data. */
jbulpin@0 229 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 230 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 231 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 232 goto exit;
jbulpin@0 233 }
jbulpin@0 234
jbulpin@0 235 /* Return the CMPIInstance for this instance. */
jbulpin@0 236 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jbulpin@0 237 CMReturnInstance(results, instance);
jbulpin@0 238 found++;
jbulpin@0 239 }
jbulpin@0 240
jbulpin@0 241 _SBLIM_TRACE(2,("--- %d instances found", found));
jbulpin@0 242 CMReturnDone(results);
jbulpin@0 243
jbulpin@0 244 exit:
jbulpin@0 245 /* Free the list of system resources. */
jbulpin@0 246 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 247 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 248 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 249 }
jbulpin@0 250
jbulpin@0 251 _SBLIM_RETURNSTATUS(status);
jbulpin@0 252 }
jbulpin@0 253
jbulpin@0 254 // ----------------------------------------------------------------------------
jbulpin@0 255 // GetInstance()
jbulpin@0 256 // Return the instance data for the specified instance only.
jbulpin@0 257 // ----------------------------------------------------------------------------
jbulpin@0 258 static CMPIStatus GetInstance(
jbulpin@0 259 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 260 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 261 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 262 CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jbulpin@0 263 const char ** properties) /* [in] List of desired properties (NULL=all). */
jbulpin@0 264 {
jbulpin@0 265 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 266 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 267 _RESOURCE * resource; /* Handle to the system resource. */
jbulpin@0 268 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 269 int found = 0; /* Found the target instance? */
jbulpin@0 270
jbulpin@0 271 _SBLIM_ENTER("GetInstance");
jbulpin@0 272 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 273 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 274 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 275 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 276
jfehlig@25 277 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 278 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 279 goto exit;
jfehlig@25 280 }
jfehlig@25 281
jbulpin@0 282 /* Get a handle to the list of system resources. */
jbulpin@0 283 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 284 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 285 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 286 goto exit;
jbulpin@0 287 }
jbulpin@0 288
jbulpin@0 289 /* Get the target resource. */
jfehlig@16 290 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
jbulpin@0 291 if (!found || (resource == NULL)) {
jbulpin@0 292 _SBLIM_TRACE(1,("--- Target instance not found"));
jbulpin@0 293 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jbulpin@0 294 goto exit;
jbulpin@0 295 }
jbulpin@0 296
jbulpin@0 297 /* Create a new CMPIInstance to store this resource. */
jbulpin@0 298 CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
jbulpin@0 299 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
jbulpin@0 300 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 301 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
jbulpin@0 302 goto exit;
jbulpin@0 303 }
jbulpin@0 304
jbulpin@0 305 /* Setup a filter to only return the desired properties. */
jbulpin@0 306 status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
jbulpin@0 307 if (status.rc != CMPI_RC_OK) {
jbulpin@0 308 _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
jbulpin@0 309 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
jbulpin@0 310 goto exit;
jbulpin@0 311 }
jbulpin@0 312
jbulpin@0 313 /* Set the instance property values from the resource data. */
jbulpin@0 314 if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) {
jbulpin@0 315 _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
jbulpin@0 316 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
jbulpin@0 317 goto exit;
jbulpin@0 318 }
jbulpin@0 319
jbulpin@0 320 /* Free the resource data. */
jbulpin@0 321 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 322 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 323 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 324 goto exit;
jbulpin@0 325 }
jbulpin@0 326
jbulpin@0 327 /* Return the CMPIInstance for this instance. */
jbulpin@0 328 _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
jbulpin@0 329 CMReturnInstance(results, instance);
jbulpin@0 330
jbulpin@0 331 _SBLIM_TRACE(2,("--- instance found"));
jbulpin@0 332 CMReturnDone(results);
jbulpin@0 333
jbulpin@0 334 exit:
jbulpin@0 335 /* Free the list of system resources. */
jbulpin@0 336 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 337 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 338 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 339 }
jbulpin@0 340
jbulpin@0 341 _SBLIM_RETURNSTATUS(status);
jbulpin@0 342 }
jbulpin@0 343
jbulpin@0 344 // ----------------------------------------------------------------------------
jbulpin@0 345 // SetInstance()
jbulpin@0 346 // Save modified instance data for the specified instance.
jbulpin@0 347 // ----------------------------------------------------------------------------
jbulpin@0 348 static CMPIStatus SetInstance(
jbulpin@0 349 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 350 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 351 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 352 CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jbulpin@0 353 CMPIInstance * newinstance) /* [in] Contains the new instance data. */
jbulpin@0 354 {
jbulpin@0 355 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 356 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 357 _RESOURCE * resource; /* Handle to the system resource. */
jbulpin@0 358 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 359 int found = 0; /* Found the target instance? */
jbulpin@0 360
jbulpin@0 361 _SBLIM_ENTER("SetInstance");
jbulpin@0 362 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 363 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 364 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 365 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
jbulpin@0 366 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 367
jfehlig@25 368 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 369 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 370 goto exit;
jfehlig@25 371 }
jfehlig@25 372
jbulpin@0 373 /* Get a handle to the list of system resources. */
jbulpin@0 374 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 375 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 376 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 377 goto exit;
jbulpin@0 378 }
jbulpin@0 379
jbulpin@0 380 /* Get the target resource. */
jfehlig@16 381 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
jbulpin@0 382 if (!found || (resource == NULL)) {
jbulpin@0 383 _SBLIM_TRACE(1,("--- Target instance not found"));
jbulpin@0 384 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jbulpin@0 385 goto exit;
jbulpin@0 386 }
jbulpin@0 387
jbulpin@0 388 _SBLIM_TRACE(2,("--- instance found", found));
jbulpin@0 389
jbulpin@0 390 /* Update the target resource data with the new instance property values. */
jbulpin@0 391 int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER);
jbulpin@0 392
jbulpin@0 393 /* Free the resource data. */
jbulpin@0 394 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 395 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 396 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 397 goto exit;
jbulpin@0 398 }
jbulpin@0 399
jbulpin@0 400 if (rc != 1) {
jbulpin@0 401 if (rc == -1) {
jbulpin@0 402 _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
jbulpin@0 403 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jbulpin@0 404 } else {
jbulpin@0 405 _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
jbulpin@0 406 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
jbulpin@0 407 }
jbulpin@0 408 goto exit;
jbulpin@0 409 }
jbulpin@0 410
jbulpin@0 411 exit:
jbulpin@0 412 /* Free the list of system resources. */
jbulpin@0 413 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 414 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 415 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 416 }
jbulpin@0 417
jbulpin@0 418 _SBLIM_RETURNSTATUS(status);
jbulpin@0 419 }
jbulpin@0 420
jbulpin@0 421 // ----------------------------------------------------------------------------
jbulpin@0 422 // CreateInstance()
jbulpin@0 423 // Create a new instance from the specified instance data.
jbulpin@0 424 // ----------------------------------------------------------------------------
jbulpin@0 425 static CMPIStatus CreateInstance(
jbulpin@0 426 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 427 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 428 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 429 CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */
jbulpin@0 430 CMPIInstance * newinstance) /* [in] Contains the new instance data. */
jbulpin@0 431 {
jbulpin@0 432 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 433 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 434 _RESOURCE * resource; /* Handle to the system resource. */
jbulpin@0 435 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 436 int found = 0; /* Found the target instance? */
jbulpin@0 437
jbulpin@0 438 _SBLIM_ENTER("CreateInstance");
jbulpin@0 439 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 440 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 441 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 442 _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
jbulpin@0 443 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 444
jfehlig@25 445 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 446 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 447 goto exit;
jfehlig@25 448 }
jfehlig@25 449
jbulpin@0 450 /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
jbulpin@0 451 reference = CMGetObjectPath(newinstance, NULL);
jbulpin@0 452
jbulpin@0 453 /* Get a handle to the list of system resources. */
jbulpin@0 454 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 455 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 456 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 457 goto exit;
jbulpin@0 458 }
jbulpin@0 459
jbulpin@0 460 /* Get the target resource. */
jfehlig@16 461 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
jbulpin@0 462
jbulpin@0 463 /* Free the resource data. */
jbulpin@0 464 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 465 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 466 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 467 goto exit;
jbulpin@0 468 }
jbulpin@0 469
jbulpin@0 470 if (found) {
jbulpin@0 471 _SBLIM_TRACE(1,("--- Target instance already exists"));
jbulpin@0 472 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
jbulpin@0 473 goto exit;
jbulpin@0 474 }
jbulpin@0 475
jbulpin@0 476 /* Create a new resource with the new instance property values. */
jbulpin@0 477 int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
jbulpin@0 478 if (rc != 1) {
jbulpin@0 479 if (rc == -1) {
jbulpin@0 480 _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
jbulpin@0 481 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jbulpin@0 482 } else {
jbulpin@0 483 _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
jbulpin@0 484 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
jbulpin@0 485 }
jbulpin@0 486 goto exit;
jbulpin@0 487 }
jbulpin@0 488
jbulpin@0 489 /* Return the object path for the newly created instance. */
jbulpin@0 490 CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
jbulpin@0 491 CMSetNameSpace(objectpath, namespace);
jbulpin@0 492 CMReturnObjectPath(results, objectpath);
jbulpin@0 493 CMReturnDone(results);
jbulpin@0 494
jbulpin@0 495 exit:
jbulpin@0 496 /* Free the list of system resources. */
jbulpin@0 497 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 498 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 499 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 500 }
jbulpin@0 501
jbulpin@0 502 _SBLIM_RETURNSTATUS(status);
jbulpin@0 503 }
jbulpin@0 504
jbulpin@0 505 // ----------------------------------------------------------------------------
jbulpin@0 506 // DeleteInstance()
jbulpin@0 507 // Delete or remove the specified instance from the system.
jbulpin@0 508 // ----------------------------------------------------------------------------
jbulpin@0 509 static CMPIStatus DeleteInstance(
jbulpin@0 510 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 511 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 512 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 513 CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */
jbulpin@0 514 {
jbulpin@0 515 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jfehlig@25 516 _RESOURCES * resources = NULL; /* Handle to the list of system resources. */
jbulpin@0 517 _RESOURCE * resource; /* Handle to the system resource. */
jbulpin@0 518 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 519 int found = 0; /* Found the target instance? */
jbulpin@0 520
jbulpin@0 521 _SBLIM_ENTER("DeleteInstance");
jbulpin@0 522 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 523 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 524 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 525 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 526
jfehlig@25 527 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 528 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 529 goto exit;
jfehlig@25 530 }
jfehlig@25 531
jbulpin@0 532 /* Get a handle to the list of system resources. */
jbulpin@0 533 if (!Xen_ProcessorPool_getResources(&resources)) {
jbulpin@0 534 _SBLIM_TRACE(1,("--- _getResources() failed"));
jbulpin@0 535 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
jbulpin@0 536 goto exit;
jbulpin@0 537 }
jbulpin@0 538
jbulpin@0 539 /* Get the target resource. */
jfehlig@16 540 found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context);
jbulpin@0 541 if (!found || (resource == NULL)) {
jbulpin@0 542 _SBLIM_TRACE(1,("--- Target instance not found"));
jbulpin@0 543 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
jbulpin@0 544 goto exit;
jbulpin@0 545 }
jbulpin@0 546
jbulpin@0 547 _SBLIM_TRACE(2,("--- instance found", found));
jbulpin@0 548
jbulpin@0 549 /* Delete the target resource. */
jbulpin@0 550 int rc = Xen_ProcessorPool_deleteResource(resources, resource);
jbulpin@0 551
jbulpin@0 552 /* Free the resource data. */
jbulpin@0 553 if (!Xen_ProcessorPool_freeResource(resource)) {
jbulpin@0 554 _SBLIM_TRACE(1,("--- _freeResource() failed"));
jbulpin@0 555 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
jbulpin@0 556 goto exit;
jbulpin@0 557 }
jbulpin@0 558
jbulpin@0 559 if (rc != 1) {
jbulpin@0 560 if (rc == -1) {
jbulpin@0 561 _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
jbulpin@0 562 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jbulpin@0 563 } else {
jbulpin@0 564 _SBLIM_TRACE(1,("--- _deleteResource() failed"));
jbulpin@0 565 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
jbulpin@0 566 }
jbulpin@0 567 goto exit;
jbulpin@0 568 }
jbulpin@0 569
jbulpin@0 570 exit:
jbulpin@0 571 /* Free the list of system resources. */
jbulpin@0 572 if (!Xen_ProcessorPool_freeResources(resources)) {
jbulpin@0 573 _SBLIM_TRACE(1,("--- _freeResources() failed"));
jbulpin@0 574 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
jbulpin@0 575 }
jbulpin@0 576
jbulpin@0 577 _SBLIM_RETURNSTATUS(status);
jbulpin@0 578 }
jbulpin@0 579
jbulpin@0 580
jbulpin@0 581 // ----------------------------------------------------------------------------
jbulpin@0 582 // ExecQuery()
jbulpin@0 583 // Return a list of all the instances that satisfy the specified query filter.
jbulpin@0 584 // ----------------------------------------------------------------------------
jbulpin@0 585 static CMPIStatus ExecQuery(
jbulpin@0 586 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 587 CMPIContext * context, /* [in] Additional context info, if any. */
jbulpin@0 588 CMPIResult * results, /* [out] Results of this operation. */
jbulpin@0 589 CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */
jbulpin@0 590 char * language, /* [in] Name of the query language. */
jbulpin@0 591 char * query) /* [in] Text of the query written in the query language. */
jbulpin@0 592 {
jbulpin@0 593 CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */
jbulpin@0 594 char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
jbulpin@0 595
jbulpin@0 596 _SBLIM_ENTER("ExecQuery");
jbulpin@0 597 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jbulpin@0 598 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 599 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
jbulpin@0 600 _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
jbulpin@0 601 _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
jbulpin@0 602 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
jbulpin@0 603
jfehlig@25 604 if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
jfehlig@25 605 _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME));
jfehlig@25 606 goto exit;
jfehlig@25 607 }
jfehlig@25 608
jbulpin@0 609 /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
jbulpin@0 610 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
jbulpin@0 611
jbulpin@0 612 CMReturnDone(results);
jbulpin@0 613
jbulpin@0 614 exit:
jbulpin@0 615 _SBLIM_RETURNSTATUS(status);
jbulpin@0 616 }
jbulpin@0 617
jbulpin@0 618 // ----------------------------------------------------------------------------
jbulpin@0 619 // Initialize()
jbulpin@0 620 // Perform any necessary initialization immediately after this provider is
jbulpin@0 621 // first loaded.
jbulpin@0 622 // ----------------------------------------------------------------------------
jbulpin@0 623 static void Initialize(
jbulpin@0 624 CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */
jbulpin@0 625 CMPIContext * context) /* [in] Additional context info, if any. */
jbulpin@0 626 {
jbulpin@0 627 _SBLIM_ENTER("Initialize");
jbulpin@0 628 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
jfehlig@1 629 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
jbulpin@0 630
jbulpin@0 631 /* Nothing needs to be done to initialize this provider */
jbulpin@0 632
jbulpin@0 633 exit:
jbulpin@0 634 _SBLIM_RETURN();
jbulpin@0 635 }
jbulpin@0 636
jbulpin@0 637 // ============================================================================
jbulpin@0 638 // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
jbulpin@0 639 // ============================================================================
jfehlig@1 640 CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));