jbulpin@0: // Copyright (C) 2006 IBM Corporation jbulpin@0: // jbulpin@0: // This library is free software; you can redistribute it and/or jbulpin@0: // modify it under the terms of the GNU Lesser General Public jbulpin@0: // License as published by the Free Software Foundation; either jbulpin@0: // version 2.1 of the License, or (at your option) any later version. jbulpin@0: // jbulpin@0: // This library is distributed in the hope that it will be useful, jbulpin@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of jbulpin@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU jbulpin@0: // Lesser General Public License for more details. jbulpin@0: // jbulpin@0: // You should have received a copy of the GNU Lesser General Public jbulpin@0: // License along with this library; if not, write to the Free Software jbulpin@0: // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA jbulpin@0: // ============================================================================ jbulpin@0: // Authors: Dr. Gareth S. Bestor, jfehlig@25: // Jim Fehlig, jbulpin@0: // Contributors: jbulpin@0: // Description: jbulpin@0: // ============================================================================ jbulpin@0: jfehlig@32: #include jfehlig@32: jbulpin@0: /* Include the required CMPI data types, function headers, and macros */ jbulpin@0: #include "cmpidt.h" jbulpin@0: #include "cmpift.h" jbulpin@0: #include "cmpimacs.h" jbulpin@0: jfehlig@25: #include "provider_common.h" jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // COMMON GLOBAL VARIABLES jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: jbulpin@0: /* Handle to the CIM broker. Initialized when the provider lib is loaded. */ jfehlig@31: static const CMPIBroker *_BROKER; jbulpin@0: jbulpin@0: /* Include utility functions */ jbulpin@0: #include "cmpiutil.h" jbulpin@0: jbulpin@0: /* Include _SBLIM_TRACE() logging support */ jbulpin@0: #include "cmpitrace.h" jbulpin@0: jbulpin@0: /* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ jbulpin@0: #include "Xen_ProcessorPool_Resource.h" jbulpin@0: jbulpin@0: jbulpin@0: // ============================================================================ jbulpin@0: // CMPI INSTANCE PROVIDER FUNCTION TABLE jbulpin@0: // ============================================================================ jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // Info for the class supported by the instance provider jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: jbulpin@0: /* Name of the class implemented by this instance provider. */ jbulpin@0: /*** CUSTOMIZE FOR EACH PROVIDER ***/ jbulpin@0: static char * _CLASSNAME = "Xen_ProcessorPool"; jbulpin@0: jbulpin@0: /* NULL terminated list of key properties of this class. */ jbulpin@0: /*** CUSTOMIZE FOR EACH PROVIDER ***/ jfehlig@14: const static char * _KEYNAMES[] = {"InstanceID", NULL}; jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // Cleanup() jbulpin@0: // Perform any necessary cleanup immediately before this provider is unloaded. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus Cleanup( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: CMPIBoolean terminating) /* [in] True if MB is terminating */ jbulpin@0: { jbulpin@0: CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("Cleanup"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: jbulpin@0: /* Nothing needs to be done for cleanup. */ jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // EnumInstanceNames() jbulpin@0: // Return a list of all the instances names (return their object paths only). jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus EnumInstanceNames( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to each system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found any instances? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("EnumInstanceNames"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ jfehlig@16: while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) { jbulpin@0: /* Create a new CMPIInstance to store this resource. */ jbulpin@0: CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); jbulpin@0: if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { jbulpin@0: _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Set the instance property values from the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) { jbulpin@0: _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Return the CMPIObjectPath for this instance. */ jbulpin@0: CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); jbulpin@0: if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { jbulpin@0: _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ jbulpin@0: jbulpin@0: _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); jbulpin@0: CMReturnObjectPath(results, objectpath); jbulpin@0: found++; jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_TRACE(2,("--- %d object paths found", found)); jbulpin@0: CMReturnDone(results); jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // EnumInstances() jbulpin@0: // Return a list of all the instances (return all the instance data). jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus EnumInstances( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ jbulpin@0: const char ** properties) /* [in] List of desired properties (NULL=all). */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to each system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found any resource instances? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("EnumInstances"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ jfehlig@16: while (Xen_ProcessorPool_getNextResource(resources, &resource, _BROKER, context)) { jbulpin@0: /* Create a new CMPIInstance to store this resource. */ jbulpin@0: CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); jbulpin@0: if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { jbulpin@0: _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Setup a filter to only return the desired properties. */ jbulpin@0: status = CMSetPropertyFilter(instance, properties, _KEYNAMES); jbulpin@0: if (status.rc != CMPI_RC_OK) { jbulpin@0: _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Set the instance property values from the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) { jbulpin@0: _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Return the CMPIInstance for this instance. */ jbulpin@0: _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); jbulpin@0: CMReturnInstance(results, instance); jbulpin@0: found++; jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_TRACE(2,("--- %d instances found", found)); jbulpin@0: CMReturnDone(results); jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // GetInstance() jbulpin@0: // Return the instance data for the specified instance only. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus GetInstance( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ jbulpin@0: const char ** properties) /* [in] List of desired properties (NULL=all). */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to the system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found the target instance? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("GetInstance"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Get the target resource. */ jfehlig@16: found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context); jbulpin@0: if (!found || (resource == NULL)) { jbulpin@0: _SBLIM_TRACE(1,("--- Target instance not found")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Create a new CMPIInstance to store this resource. */ jbulpin@0: CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); jbulpin@0: if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { jbulpin@0: _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Setup a filter to only return the desired properties. */ jbulpin@0: status = CMSetPropertyFilter(instance, properties, _KEYNAMES); jbulpin@0: if (status.rc != CMPI_RC_OK) { jbulpin@0: _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Set the instance property values from the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_setInstanceFromResource(resource, instance, _BROKER)) { jbulpin@0: _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Return the CMPIInstance for this instance. */ jbulpin@0: _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); jbulpin@0: CMReturnInstance(results, instance); jbulpin@0: jbulpin@0: _SBLIM_TRACE(2,("--- instance found")); jbulpin@0: CMReturnDone(results); jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // SetInstance() jbulpin@0: // Save modified instance data for the specified instance. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus SetInstance( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ jfehlig@31: const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ jfehlig@31: const char **properties) jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to the system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found the target instance? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("SetInstance"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Get the target resource. */ jfehlig@16: found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context); jbulpin@0: if (!found || (resource == NULL)) { jbulpin@0: _SBLIM_TRACE(1,("--- Target instance not found")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_TRACE(2,("--- instance found", found)); jbulpin@0: jbulpin@0: /* Update the target resource data with the new instance property values. */ jbulpin@0: int rc = Xen_ProcessorPool_setResourceFromInstance(resource, newinstance, _BROKER); jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: if (rc != 1) { jbulpin@0: if (rc == -1) { jbulpin@0: _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); jbulpin@0: } else { jbulpin@0: _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); jbulpin@0: } jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // CreateInstance() jbulpin@0: // Create a new instance from the specified instance data. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus CreateInstance( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ jfehlig@31: const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to the system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found the target instance? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("CreateInstance"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ jbulpin@0: reference = CMGetObjectPath(newinstance, NULL); jbulpin@0: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Get the target resource. */ jfehlig@16: found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context); jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: if (found) { jbulpin@0: _SBLIM_TRACE(1,("--- Target instance already exists")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Create a new resource with the new instance property values. */ jbulpin@0: int rc = Xen_ProcessorPool_createResourceFromInstance(resources, &resource, newinstance, _BROKER); jbulpin@0: if (rc != 1) { jbulpin@0: if (rc == -1) { jbulpin@0: _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); jbulpin@0: } else { jbulpin@0: _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); jbulpin@0: } jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Return the object path for the newly created instance. */ jbulpin@0: CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); jbulpin@0: CMSetNameSpace(objectpath, namespace); jbulpin@0: CMReturnObjectPath(results, objectpath); jbulpin@0: CMReturnDone(results); jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // DeleteInstance() jbulpin@0: // Delete or remove the specified instance from the system. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus DeleteInstance( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jfehlig@25: _RESOURCES * resources = NULL; /* Handle to the list of system resources. */ jbulpin@0: _RESOURCE * resource; /* Handle to the system resource. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: int found = 0; /* Found the target instance? */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("DeleteInstance"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* Get a handle to the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_getResources(&resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _getResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: /* Get the target resource. */ jfehlig@16: found = Xen_ProcessorPool_getResourceForObjectPath(resources, &resource, reference, _BROKER, context); jbulpin@0: if (!found || (resource == NULL)) { jbulpin@0: _SBLIM_TRACE(1,("--- Target instance not found")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_TRACE(2,("--- instance found", found)); jbulpin@0: jbulpin@0: /* Delete the target resource. */ jbulpin@0: int rc = Xen_ProcessorPool_deleteResource(resources, resource); jbulpin@0: jbulpin@0: /* Free the resource data. */ jbulpin@0: if (!Xen_ProcessorPool_freeResource(resource)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: if (rc != 1) { jbulpin@0: if (rc == -1) { jbulpin@0: _SBLIM_TRACE(1,("--- __deleteResource() unsupported")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); jbulpin@0: } else { jbulpin@0: _SBLIM_TRACE(1,("--- _deleteResource() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource"); jbulpin@0: } jbulpin@0: goto exit; jbulpin@0: } jbulpin@0: jbulpin@0: exit: jbulpin@0: /* Free the list of system resources. */ jbulpin@0: if (!Xen_ProcessorPool_freeResources(resources)) { jbulpin@0: _SBLIM_TRACE(1,("--- _freeResources() failed")); jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); jbulpin@0: } jbulpin@0: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // ExecQuery() jbulpin@0: // Return a list of all the instances that satisfy the specified query filter. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static CMPIStatus ExecQuery( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context, /* [in] Additional context info, if any. */ jfehlig@31: const CMPIResult * results, /* [out] Results of this operation. */ jfehlig@31: const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ jfehlig@31: const char * language, /* [in] Name of the query language. */ jfehlig@31: const char * query) /* [in] Text of the query written in the query language. */ jbulpin@0: { jbulpin@0: CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ jbulpin@0: char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ jbulpin@0: jbulpin@0: _SBLIM_ENTER("ExecQuery"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jbulpin@0: _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); jbulpin@0: _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); jbulpin@0: _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); jbulpin@0: _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); jbulpin@0: jfehlig@25: if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) { jfehlig@25: _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for %s", namespace, _CLASSNAME)); jfehlig@25: goto exit; jfehlig@25: } jfehlig@25: jbulpin@0: /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ jbulpin@0: CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); jbulpin@0: jbulpin@0: CMReturnDone(results); jbulpin@0: jbulpin@0: exit: jbulpin@0: _SBLIM_RETURNSTATUS(status); jbulpin@0: } jbulpin@0: jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: // Initialize() jbulpin@0: // Perform any necessary initialization immediately after this provider is jbulpin@0: // first loaded. jbulpin@0: // ---------------------------------------------------------------------------- jbulpin@0: static void Initialize( jbulpin@0: CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ jfehlig@31: const CMPIContext * context) /* [in] Additional context info, if any. */ jbulpin@0: { jbulpin@0: _SBLIM_ENTER("Initialize"); jbulpin@0: _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); jfehlig@1: // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); jbulpin@0: jbulpin@0: /* Nothing needs to be done to initialize this provider */ jbulpin@0: _SBLIM_RETURN(); jbulpin@0: } jbulpin@0: jbulpin@0: // ============================================================================ jbulpin@0: // CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP jbulpin@0: // ============================================================================ jfehlig@1: CMInstanceMIStub( , Xen_ProcessorPool, _BROKER, Initialize(&mi, ctx));