os-cmpi-xen
changeset 103:fa1ca0490794
Integrated new 'Cmpilr' instance provider interface into build (Gareth Bestor).
Ported Xen_VirtualSystemManagementCapabilities and Xen_DiskSettingData to new 'Cmpilr' interface.
Added some convenience functions to xen utils.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Ported Xen_VirtualSystemManagementCapabilities and Xen_DiskSettingData to new 'Cmpilr' interface.
Added some convenience functions to xen utils.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author | Jim Fehlig <jfehlig@novell.com> |
---|---|
date | Wed May 09 17:24:20 2007 -0600 (2007-05-09) |
parents | 1903faaf4d37 |
children | b66e845be7e4 |
files | ChangeLog src/Makefile.am src/Xen_ComputerSystemSettingData_Resource.c src/Xen_DiskSettingData.c src/Xen_DiskSettingData_Resource.c src/Xen_DiskSettingData_Resource.h src/Xen_VirtualSystemManagementCapabilities.c src/Xen_VirtualSystemManagementCapabilities_Resource.c src/Xen_VirtualSystemManagementCapabilities_Resource.h src/cmpilr.c src/cmpilr.h src/cmpitrace.c src/cmpitrace.h src/xen_utils.c src/xen_utils.h |
line diff
1.1 --- a/ChangeLog Mon Apr 30 10:27:59 2007 -0600 1.2 +++ b/ChangeLog Wed May 09 17:24:20 2007 -0600 1.3 @@ -1,3 +1,12 @@ 1.4 +------------------------------------------------------------------- 1.5 +Wed May 9 17:19:27 MDT 2007 - jfehlig@novell.com 1.6 + 1.7 + - Integrated new 'Cmpilr' instance provider interface into 1.8 + build (Gareth Bestor) 1.9 + - Ported Xen_VirtualSystemManagementCapabilities and 1.10 + Xen_DiskSettingData to new 'Cmpilr' interface. 1.11 + - Added some convenience functions to xen utils. 1.12 + 1.13 ------------------------------------------------------------------- 1.14 Mon Apr 30 10:25:14 MDT 2007 - jfehlig@novell.com 1.15
2.1 --- a/src/Makefile.am Mon Apr 30 10:27:59 2007 -0600 2.2 +++ b/src/Makefile.am Wed May 09 17:24:20 2007 -0600 2.3 @@ -43,6 +43,7 @@ providerdir=@PROVIDERDIR@ 2.4 noinst_HEADERS = \ 2.5 cmpiutil.h \ 2.6 cmpitrace.h \ 2.7 + cmpilr.h 2.8 provider_common.h \ 2.9 xen_utils.h \ 2.10 Xen_ComputerSystem_Resource.h \ 2.11 @@ -58,14 +59,12 @@ noinst_HEADERS = \ 2.12 Xen_ProcessorSettingData_Resource.h \ 2.13 Xen_MemorySettingData_Resource.h \ 2.14 Xen_NetworkPortSettingData_Resource.h \ 2.15 - Xen_DiskSettingData_Resource.h \ 2.16 Xen_ConsoleSettingData_Resource.h \ 2.17 Xen_MemoryPool_Resource.h \ 2.18 Xen_ProcessorPool_Resource.h \ 2.19 Xen_ProcessorCapabilitiesSettingData_Resource.h \ 2.20 Xen_MemoryCapabilitiesSettingData_Resource.h \ 2.21 - Xen_ComputerSystemCapabilities_Resource.h \ 2.22 - Xen_VirtualSystemManagementCapabilities_Resource.h 2.23 + Xen_ComputerSystemCapabilities_Resource.h 2.24 2.25 # LIST ANY UTILITY LIBRARIES, THEIR SOURCE FILE(S), AND ANY LIBS REQUIRED FOR LINKING HERE 2.26 # libXen_utils contains Xen API and CMPI wrapper functions for the providers 2.27 @@ -137,7 +136,7 @@ provider_LTLIBRARIES = \ 2.28 # libXen_HostedNetworkPort.la 2.29 2.30 2.31 -libXen_ProviderCommon_la_SOURCES = cmpitrace.c cmpiutil.c xen_utils.c 2.32 +libXen_ProviderCommon_la_SOURCES = cmpitrace.c cmpiutil.c xen_utils.c cmpilr.c 2.33 libXen_ProviderCommon_la_CFLAGS = @LIBXEN_CFLAGS@ @LIBXML2_CFLAGS@ 2.34 libXen_ProviderCommon_la_LIBADD = @LIBXEN_LIBS@ @LIBXML2_LIBS@ -lpthread 2.35 libXen_ProviderCommon_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ 2.36 @@ -297,7 +296,7 @@ libXen_NetworkPortElementSettingData_la_ 2.37 libXen_NetworkPortElementSettingData_la_LIBADD = libXen_ProviderCommon.la 2.38 libXen_NetworkPortElementSettingData_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ 2.39 2.40 -libXen_DiskSettingData_la_SOURCES = Xen_DiskSettingData.c Xen_DiskSettingData_Resource.c 2.41 +libXen_DiskSettingData_la_SOURCES = Xen_DiskSettingData.c 2.42 libXen_DiskSettingData_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ 2.43 libXen_DiskSettingData_la_LIBADD = libXen_ProviderCommon.la 2.44 libXen_DiskSettingData_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ 2.45 @@ -387,8 +386,8 @@ libXen_ComputerSystemCapabilities_la_CFL 2.46 libXen_ComputerSystemCapabilities_la_LIBADD = libXen_ProviderCommon.la 2.47 libXen_ComputerSystemCapabilities_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ 2.48 2.49 -libXen_VirtualSystemManagementCapabilities_la_SOURCES = Xen_VirtualSystemManagementCapabilities.c Xen_VirtualSystemManagementCapabilities_Resource.c 2.50 -libXen_VirtualSystemManagementCapabilities_la_CFLAGS = -I../ 2.51 +libXen_VirtualSystemManagementCapabilities_la_SOURCES = Xen_VirtualSystemManagementCapabilities.c 2.52 +libXen_VirtualSystemManagementCapabilities_la_CFLAGS = -I../ @LIBXEN_CFLAGS@ 2.53 libXen_VirtualSystemManagementCapabilities_la_LIBADD = libXen_ProviderCommon.la 2.54 libXen_VirtualSystemManagementCapabilities_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@ 2.55
3.1 --- a/src/Xen_ComputerSystemSettingData_Resource.c Mon Apr 30 10:27:59 2007 -0600 3.2 +++ b/src/Xen_ComputerSystemSettingData_Resource.c Wed May 09 17:24:20 2007 -0600 3.3 @@ -157,7 +157,7 @@ int Xen_ComputerSystemSettingData_setIns 3.4 char inst_id[1024]; 3.5 int prop_bool_val; 3.6 char *prop_string_val; 3.7 - char hvm_boot_order[1024]; 3.8 + char *hvm_boot_order; 3.9 if (resource == NULL) return 0; 3.10 if (CMIsNullObject(instance)) return 0; 3.11 3.12 @@ -165,7 +165,7 @@ int Xen_ComputerSystemSettingData_setIns 3.13 snprintf(inst_id, 1024, "Xen:%s", resource->name_label); 3.14 CMSetProperty(instance, "InstanceID",(CMPIValue *)inst_id, CMPI_chars); 3.15 // There must be an easier way of figuring out pv/hvm, but, until we figure that out, we will keep this - Raj 3.16 - if (xen_utils_get_value_from_map(resource->hvm_boot_params, "order", hvm_boot_order)&& (hvm_boot_order[0] != '\0')) { 3.17 + if ((hvm_boot_order = xen_utils_get_value_from_map(resource->hvm_boot_params, "order"))) { 3.18 /* HVM settings */ 3.19 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"hvm-3.0-unknown", CMPI_chars); 3.20 CMSetProperty(instance, "BootOrder", (CMPIValue *)hvm_boot_order, CMPI_chars);
4.1 --- a/src/Xen_DiskSettingData.c Mon Apr 30 10:27:59 2007 -0600 4.2 +++ b/src/Xen_DiskSettingData.c Wed May 09 17:24:20 2007 -0600 4.3 @@ -1,4 +1,4 @@ 4.4 -// Copyright (C) 2006 IBM Corporation 4.5 +// Copyright (C) 2007 Novell, Inc. 4.6 // 4.7 // This library is free software; you can redistribute it and/or 4.8 // modify it under the terms of the GNU Lesser General Public 4.9 @@ -14,609 +14,393 @@ 4.10 // License along with this library; if not, write to the Free Software 4.11 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 4.12 // ============================================================================ 4.13 -// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 4.14 -// Contributors: Jim Fehlig, <jfehlig@novell.com> 4.15 -// Description: 4.16 +// Authors: Jim Fehlig, <jfehlig@novell.com> 4.17 +// Contributors: 4.18 +// Description: A class used to represent the settings of Xen virtual 4.19 +// block device (vbd). The settings are available for 4.20 +// inspection/manipulation regardless of domain state. 4.21 // ============================================================================ 4.22 4.23 -/* Include the required CMPI data types, function headers, and macros */ 4.24 +/* Common declarations for each CMPI "Cimpler" instance provider */ 4.25 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 4.26 #include "cmpidt.h" 4.27 -#include "cmpift.h" 4.28 #include "cmpimacs.h" 4.29 - 4.30 -/* Include utility functions */ 4.31 -#include "cmpiutil.h" 4.32 +#include "cmpilr.h" 4.33 4.34 -/* Include _SBLIM_TRACE() logging support */ 4.35 -#include "cmpitrace.h" 4.36 4.37 -/* Include Xen utilities */ 4.38 -#include "xen_utils.h" 4.39 - 4.40 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ 4.41 -#include "Xen_DiskSettingData_Resource.h" 4.42 +static const CMPIInstanceMI* mi; 4.43 4.44 4.45 -// ---------------------------------------------------------------------------- 4.46 -// COMMON GLOBAL VARIABLES 4.47 -// ---------------------------------------------------------------------------- 4.48 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr) 4.49 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn) 4.50 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 4.51 + 4.52 +#include <stdlib.h> 4.53 + 4.54 +#include <xen_common.h> 4.55 +#include <xen_vm.h> 4.56 +#include <xen_vbd.h> 4.57 +#include <xen_vdi.h> 4.58 +#include <xen_string_string_map.h> 4.59 4.60 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ 4.61 -static const CMPIBroker *_BROKER; 4.62 +#include "cmpitrace.h" 4.63 +#include "xen_utils.h" 4.64 +#include "provider_common.h" 4.65 + 4.66 + 4.67 +/* C struct to store the data for all resources. */ 4.68 +typedef struct { 4.69 + xen_vbd_set *disks; 4.70 + unsigned int currentdisknum; 4.71 +} _RESOURCES; 4.72 + 4.73 4.74 /* Xen session object. Initialize when the provider is loaded, close when 4.75 * provider unloaded. */ 4.76 static xen_utils_session *session = NULL; 4.77 4.78 4.79 -// ============================================================================ 4.80 -// CMPI INSTANCE PROVIDER FUNCTION TABLE 4.81 -// ============================================================================ 4.82 - 4.83 -// ---------------------------------------------------------------------------- 4.84 -// Info for the class supported by the instance provider 4.85 -// ---------------------------------------------------------------------------- 4.86 - 4.87 -/* Name of the class implemented by this instance provider. */ 4.88 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 4.89 -static char * _CLASSNAME = "Xen_DiskSettingData"; 4.90 - 4.91 -/* NULL terminated list of key properties of this class. */ 4.92 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 4.93 -const static char * _KEYNAMES[] = {"InstanceID", NULL}; 4.94 +static int load() 4.95 +{ 4.96 + /* Initialized Xen session object. */ 4.97 + if (!session) 4.98 + xen_utils_xen_init(&session); 4.99 4.100 -// ---------------------------------------------------------------------------- 4.101 -// Cleanup() 4.102 -// Perform any necessary cleanup immediately before this provider is unloaded. 4.103 -// ---------------------------------------------------------------------------- 4.104 -static CMPIStatus Cleanup( 4.105 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.106 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.107 - CMPIBoolean terminating) /* [in] True if MB is terminating */ 4.108 + return 1; 4.109 +} 4.110 + 4.111 + 4.112 +static int unload(CMPIBoolean terminating) 4.113 { 4.114 - CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ 4.115 - 4.116 - _SBLIM_ENTER("Cleanup"); 4.117 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.118 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.119 - 4.120 + (void) terminating; 4.121 + 4.122 if (session) { 4.123 xen_utils_xen_close(session); 4.124 session = NULL; 4.125 } 4.126 - _SBLIM_RETURNSTATUS(status); 4.127 + 4.128 + return 1; 4.129 } 4.130 4.131 -// ---------------------------------------------------------------------------- 4.132 -// EnumInstanceNames() 4.133 -// Return a list of all the instances names (return their object paths only). 4.134 -// ---------------------------------------------------------------------------- 4.135 -static CMPIStatus EnumInstanceNames( 4.136 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.137 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.138 - const CMPIResult * results, /* [out] Results of this operation. */ 4.139 - const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ 4.140 + 4.141 +static void* beginEnum() 4.142 { 4.143 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.144 - _RESOURCES * resources; /* Handle to the list of system resources. */ 4.145 - _RESOURCE * resource; /* Handle to each system resource. */ 4.146 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.147 - int found = 0; /* Found any instances? */ 4.148 - 4.149 - _SBLIM_ENTER("EnumInstanceNames"); 4.150 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.151 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.152 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.153 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.154 + _RESOURCES *resources; 4.155 + xen_domain_resources *res = NULL; 4.156 + xen_vbd_set *all_disks = NULL; 4.157 + xen_vm_record *vm_rec = NULL; 4.158 + 4.159 + resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); 4.160 + if (resources == NULL) 4.161 + return NULL; 4.162 4.163 if (!xen_utils_validate_session(&session)) { 4.164 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.165 - goto exit; 4.166 - } 4.167 - 4.168 - /* Get a handle to the list of system resources. */ 4.169 - if (!Xen_DiskSettingData_getResources(session, &resources)) { 4.170 - _SBLIM_TRACE(1,("--- _getResources() failed")); 4.171 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 4.172 - goto exit; 4.173 - } 4.174 - 4.175 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 4.176 - while (Xen_DiskSettingData_getNextResource(session, resources, &resource)) { 4.177 - /* Create a new CMPIInstance to store this resource. */ 4.178 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 4.179 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 4.180 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 4.181 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 4.182 - goto exit; 4.183 - } 4.184 - 4.185 - /* Set the instance property values from the resource data. */ 4.186 - if (!Xen_DiskSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { 4.187 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 4.188 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 4.189 - goto exit; 4.190 - } 4.191 - 4.192 - /* Free the resource data. */ 4.193 - if (!Xen_DiskSettingData_freeResource(resource)) { 4.194 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 4.195 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 4.196 - goto exit; 4.197 - } 4.198 - 4.199 - /* Return the CMPIObjectPath for this instance. */ 4.200 - CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); 4.201 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { 4.202 - _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); 4.203 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); 4.204 - goto exit; 4.205 - } 4.206 - CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ 4.207 - 4.208 - _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); 4.209 - CMReturnObjectPath(results, objectpath); 4.210 - found++; 4.211 - } 4.212 - 4.213 - _SBLIM_TRACE(2,("--- %d object paths found", found)); 4.214 - CMReturnDone(results); 4.215 - 4.216 -exit: 4.217 - /* Free the list of system resources. */ 4.218 - if (!Xen_DiskSettingData_freeResources(resources)) { 4.219 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 4.220 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 4.221 - } 4.222 - 4.223 - _SBLIM_RETURNSTATUS(status); 4.224 -} 4.225 - 4.226 -// ---------------------------------------------------------------------------- 4.227 -// EnumInstances() 4.228 -// Return a list of all the instances (return all the instance data). 4.229 -// ---------------------------------------------------------------------------- 4.230 -static CMPIStatus EnumInstances( 4.231 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.232 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.233 - const CMPIResult * results, /* [out] Results of this operation. */ 4.234 - const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ 4.235 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 4.236 -{ 4.237 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.238 - _RESOURCES * resources; /* Handle to the list of system resources. */ 4.239 - _RESOURCE * resource; /* Handle to each system resource. */ 4.240 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.241 - int found = 0; /* Found any resource instances? */ 4.242 - 4.243 - _SBLIM_ENTER("EnumInstances"); 4.244 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.245 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.246 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.247 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.248 - 4.249 - if (!xen_utils_validate_session(&session)) { 4.250 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.251 - goto exit; 4.252 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.253 + ("--- Unable to establish connection with Xend")); 4.254 + return NULL; 4.255 } 4.256 4.257 - /* Get a handle to the list of system resources. */ 4.258 - if (!Xen_DiskSettingData_getResources(session, &resources)) { 4.259 - _SBLIM_TRACE(1,("--- _getResources() failed")); 4.260 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 4.261 - goto exit; 4.262 - } 4.263 - 4.264 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 4.265 - while (Xen_DiskSettingData_getNextResource(session, resources, &resource)) { 4.266 - /* Create a new CMPIInstance to store this resource. */ 4.267 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 4.268 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 4.269 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 4.270 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 4.271 - goto exit; 4.272 - } 4.273 - 4.274 - /* Setup a filter to only return the desired properties. */ 4.275 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 4.276 - if (status.rc != CMPI_RC_OK) { 4.277 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 4.278 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 4.279 - goto exit; 4.280 - } 4.281 - 4.282 - /* Set the instance property values from the resource data. */ 4.283 - if (!Xen_DiskSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { 4.284 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 4.285 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 4.286 - goto exit; 4.287 - } 4.288 - 4.289 - /* Free the resource data. */ 4.290 - if (!Xen_DiskSettingData_freeResource(resource)) { 4.291 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 4.292 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 4.293 - goto exit; 4.294 - } 4.295 - 4.296 - /* Return the CMPIInstance for this instance. */ 4.297 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 4.298 - CMReturnInstance(results, instance); 4.299 - found++; 4.300 - } 4.301 - 4.302 - _SBLIM_TRACE(2,("--- %d instances found", found)); 4.303 - CMReturnDone(results); 4.304 - 4.305 -exit: 4.306 - /* Free the list of system resources. */ 4.307 - if (!Xen_DiskSettingData_freeResources(resources)) { 4.308 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 4.309 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 4.310 - } 4.311 - 4.312 - _SBLIM_RETURNSTATUS(status); 4.313 -} 4.314 + /* Get a list of domain resources. */ 4.315 + if (!xen_utils_get_domain_resources(session, &res)) 4.316 + goto Error; 4.317 4.318 -// ---------------------------------------------------------------------------- 4.319 -// GetInstance() 4.320 -// Return the instance data for the specified instance only. 4.321 -// ---------------------------------------------------------------------------- 4.322 -static CMPIStatus GetInstance( 4.323 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.324 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.325 - const CMPIResult * results, /* [out] Results of this operation. */ 4.326 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 4.327 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 4.328 -{ 4.329 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.330 - _RESOURCES * resources; /* Handle to the list of system resources. */ 4.331 - _RESOURCE * resource; /* Handle to the system resource. */ 4.332 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.333 - int found = 0; /* Found the target instance? */ 4.334 - 4.335 - _SBLIM_ENTER("GetInstance"); 4.336 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.337 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.338 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.339 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.340 - 4.341 - if (!xen_utils_validate_session(&session)) { 4.342 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.343 - goto exit; 4.344 + /* Create list of disk resources from disks found in each domain. */ 4.345 + while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) { 4.346 + xen_vbd_set *vbd_set; 4.347 + if (!xen_vm_get_vbds(session->xen, &vbd_set, vm_rec->handle)) 4.348 + goto Error; 4.349 + 4.350 + if (!xen_vbd_set_concat(&all_disks, vbd_set)) 4.351 + goto Error; 4.352 + 4.353 + xen_vm_record_free(vm_rec); 4.354 } 4.355 + 4.356 + resources->disks = all_disks; 4.357 + resources->currentdisknum = 0; 4.358 + 4.359 + return resources; 4.360 + 4.361 + Error: 4.362 + if (session && session->xen) { 4.363 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.364 4.365 - /* Get a handle to the list of system resources. */ 4.366 - if (!Xen_DiskSettingData_getResources(session, &resources)) { 4.367 - _SBLIM_TRACE(1,("--- _getResources() failed")); 4.368 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 4.369 - goto exit; 4.370 - } 4.371 - 4.372 - /* Get the target resource. */ 4.373 - found = Xen_DiskSettingData_getResourceForObjectPath(session, &resource, reference); 4.374 - if (!found || (resource == NULL)) { 4.375 - _SBLIM_TRACE(1,("--- Target instance not found")); 4.376 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 4.377 - goto exit; 4.378 - } 4.379 - 4.380 - /* Create a new CMPIInstance to store this resource. */ 4.381 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 4.382 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 4.383 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 4.384 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 4.385 - goto exit; 4.386 - } 4.387 - 4.388 - /* Setup a filter to only return the desired properties. */ 4.389 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 4.390 - if (status.rc != CMPI_RC_OK) { 4.391 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 4.392 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 4.393 - goto exit; 4.394 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.395 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.396 + ("--- failed to retrieve vbd resource from Xend: \"%s\"", 4.397 + error_msg)); 4.398 } 4.399 4.400 - /* Set the instance property values from the resource data. */ 4.401 - if (!Xen_DiskSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) { 4.402 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 4.403 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 4.404 - goto exit; 4.405 - } 4.406 - 4.407 - /* Free the resource data. */ 4.408 - if (!Xen_DiskSettingData_freeResource(resource)) { 4.409 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 4.410 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 4.411 - goto exit; 4.412 - } 4.413 - 4.414 - /* Return the CMPIInstance for this instance. */ 4.415 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 4.416 - CMReturnInstance(results, instance); 4.417 - 4.418 - _SBLIM_TRACE(2,("--- instance found")); 4.419 - CMReturnDone(results); 4.420 - 4.421 -exit: 4.422 - /* Free the list of system resources. */ 4.423 - if (!Xen_DiskSettingData_freeResources(resources)) { 4.424 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 4.425 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 4.426 - } 4.427 - 4.428 - _SBLIM_RETURNSTATUS(status); 4.429 + xen_vm_record_free(vm_rec); 4.430 + xen_utils_free_domain_resources(res); 4.431 + free(resources); 4.432 + return NULL; 4.433 } 4.434 4.435 -// ---------------------------------------------------------------------------- 4.436 -// SetInstance() 4.437 -// Save modified instance data for the specified instance. 4.438 -// ---------------------------------------------------------------------------- 4.439 -static CMPIStatus SetInstance( 4.440 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.441 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.442 - const CMPIResult * results, /* [out] Results of this operation. */ 4.443 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 4.444 - const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ 4.445 - const char **properties) 4.446 + 4.447 +static void endEnum(void* res_list) 4.448 { 4.449 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.450 - _RESOURCES * resources; /* Handle to the list of system resources. */ 4.451 - _RESOURCE * resource; /* Handle to the system resource. */ 4.452 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.453 - int found = 0; /* Found the target instance? */ 4.454 - 4.455 - _SBLIM_ENTER("SetInstance"); 4.456 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.457 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.458 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.459 - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); 4.460 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.461 - 4.462 - if (!xen_utils_validate_session(&session)) { 4.463 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.464 - goto exit; 4.465 - } 4.466 - 4.467 - /* Get a handle to the list of system resources. */ 4.468 - if (!Xen_DiskSettingData_getResources(session, &resources)) { 4.469 - _SBLIM_TRACE(1,("--- _getResources() failed")); 4.470 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 4.471 - goto exit; 4.472 + _RESOURCES *resources = (_RESOURCES *)res_list; 4.473 + 4.474 + if (resources) { 4.475 + if (resources->disks) 4.476 + xen_vbd_set_free(resources->disks); 4.477 + free(resources); 4.478 } 4.479 - 4.480 - /* Get the target resource. */ 4.481 - found = Xen_DiskSettingData_getResourceForObjectPath(session, &resource, reference); 4.482 - if (!found || (resource == NULL)) { 4.483 - _SBLIM_TRACE(1,("--- Target instance not found")); 4.484 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 4.485 - goto exit; 4.486 - } 4.487 - 4.488 - _SBLIM_TRACE(2,("--- instance found", found)); 4.489 - 4.490 - /* Update the target resource data with the new instance property values. */ 4.491 - int rc = Xen_DiskSettingData_setResourceFromInstance(resource, newinstance, _BROKER); 4.492 - 4.493 - /* Free the resource data. */ 4.494 - if (!Xen_DiskSettingData_freeResource(resource)) { 4.495 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 4.496 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 4.497 - goto exit; 4.498 - } 4.499 - 4.500 - if (rc != 1) { 4.501 - if (rc == -1) { 4.502 - _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported")); 4.503 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 4.504 - } else { 4.505 - _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed")); 4.506 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties"); 4.507 - } 4.508 - goto exit; 4.509 - } 4.510 - 4.511 -exit: 4.512 - /* Free the list of system resources. */ 4.513 - if (!Xen_DiskSettingData_freeResources(resources)) { 4.514 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 4.515 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 4.516 - } 4.517 - 4.518 - _SBLIM_RETURNSTATUS(status); 4.519 } 4.520 4.521 -// ---------------------------------------------------------------------------- 4.522 -// CreateInstance() 4.523 -// Create a new instance from the specified instance data. 4.524 -// ---------------------------------------------------------------------------- 4.525 -static CMPIStatus CreateInstance( 4.526 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.527 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.528 - const CMPIResult * results, /* [out] Results of this operation. */ 4.529 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 4.530 - const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ 4.531 + 4.532 +static void* getNext(void* res_list) 4.533 { 4.534 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.535 - _RESOURCES * resources; /* Handle to the list of system resources. */ 4.536 - _RESOURCE * resource; /* Handle to the system resource. */ 4.537 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.538 - int found = 0; /* Found the target instance? */ 4.539 + _RESOURCES *resources = (_RESOURCES *)res_list; 4.540 + xen_vbd_record *vbd_rec; 4.541 4.542 - _SBLIM_ENTER("CreateInstance"); 4.543 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.544 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.545 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.546 - _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL)))); 4.547 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.548 + if (resources == NULL || resources->disks == NULL) 4.549 + return NULL; 4.550 + 4.551 + /* Check if reached the end of the list of disks. */ 4.552 + if (resources->currentdisknum == resources->disks->size) 4.553 + return NULL; 4.554 4.555 if (!xen_utils_validate_session(&session)) { 4.556 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.557 - goto exit; 4.558 - } 4.559 - 4.560 - /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */ 4.561 - reference = CMGetObjectPath(newinstance, NULL); 4.562 - 4.563 - /* Get a handle to the list of system resources. */ 4.564 - if (!Xen_DiskSettingData_getResources(session, &resources)) { 4.565 - _SBLIM_TRACE(1,("--- _getResources() failed")); 4.566 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 4.567 - goto exit; 4.568 - } 4.569 - 4.570 - /* Get the target resource. */ 4.571 - found = Xen_DiskSettingData_getResourceForObjectPath(session, &resource, reference); 4.572 - 4.573 - /* Free the resource data. */ 4.574 - if (!Xen_DiskSettingData_freeResource(resource)) { 4.575 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 4.576 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 4.577 - goto exit; 4.578 - } 4.579 - 4.580 - if (found) { 4.581 - _SBLIM_TRACE(1,("--- Target instance already exists")); 4.582 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists"); 4.583 - goto exit; 4.584 - } 4.585 - 4.586 - /* Create a new resource with the new instance property values. */ 4.587 - int rc = Xen_DiskSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER); 4.588 - if (rc != 1) { 4.589 - if (rc == -1) { 4.590 - _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported")); 4.591 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 4.592 - } else { 4.593 - _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed")); 4.594 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties"); 4.595 - } 4.596 - goto exit; 4.597 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.598 + ("--- Unable to establish connection with Xend")); 4.599 + return NULL; 4.600 } 4.601 4.602 - /* Return the object path for the newly created instance. */ 4.603 - CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL); 4.604 - CMSetNameSpace(objectpath, namespace); 4.605 - CMReturnObjectPath(results, objectpath); 4.606 - CMReturnDone(results); 4.607 + /* Get the current disk record. */ 4.608 + if (!xen_vbd_get_record(session->xen, &vbd_rec, 4.609 + resources->disks->contents[resources->currentdisknum])) { 4.610 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.611 + 4.612 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.613 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.614 + ("--- failed to retrieve vbd resource from Xend: \"%s\"", 4.615 + error_msg)); 4.616 + 4.617 + return NULL; 4.618 + } 4.619 + 4.620 + resources->currentdisknum++; 4.621 + return (void *)vbd_rec; 4.622 +} 4.623 4.624 -exit: 4.625 - /* Free the list of system resources. */ 4.626 - if (!Xen_DiskSettingData_freeResources(resources)) { 4.627 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 4.628 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 4.629 - } 4.630 4.631 - _SBLIM_RETURNSTATUS(status); 4.632 +static int get(void* res_list, void** res) 4.633 +{ 4.634 + if (res == NULL || *res == NULL) 4.635 + return 0; 4.636 + /* 4.637 + * WARNING! 4.638 + * What needs to be done here? It looks as though inst2res() will have 4.639 + * been called on parameter res before a call to this function - in 4.640 + * which case res will be populated. 4.641 + */ 4.642 + return 1; 4.643 } 4.644 4.645 -// ---------------------------------------------------------------------------- 4.646 -// DeleteInstance() 4.647 -// Delete or remove the specified instance from the system. 4.648 -// ---------------------------------------------------------------------------- 4.649 -static CMPIStatus DeleteInstance( 4.650 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.651 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.652 - const CMPIResult * results, /* [out] Results of this operation. */ 4.653 - const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ 4.654 + 4.655 +static void release(void* res) 4.656 +{ 4.657 + xen_vbd_record_free(res); 4.658 +} 4.659 + 4.660 + 4.661 +static int add(void** res_list, void* res) 4.662 { 4.663 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.664 - _RESOURCE * resource = NULL; /* Handle to the system resource. */ 4.665 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.666 - int found = 0; /* Found the target instance? */ 4.667 - char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.668 - 4.669 + xen_vbd_record *new_vbd_rec = (xen_vbd_record *)res; 4.670 + 4.671 + (void)res_list; 4.672 + 4.673 + if (new_vbd_rec == NULL || new_vbd_rec->vm == NULL) 4.674 + return 0; 4.675 + 4.676 if (!xen_utils_validate_session(&session)) { 4.677 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon"); 4.678 - goto exit; 4.679 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.680 + ("--- Unable to establish connection with Xend")); 4.681 + return 0; 4.682 } 4.683 4.684 - _SBLIM_ENTER("DeleteInstance"); 4.685 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.686 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.687 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.688 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.689 - 4.690 - /* Get the target resource. */ 4.691 - found = Xen_DiskSettingData_getResourceForObjectPath(session, &resource, reference); 4.692 - if (!found || (resource == NULL)) { 4.693 - _SBLIM_TRACE(1,("--- Target instance not found")); 4.694 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 4.695 - goto exit; 4.696 + xen_vbd new_vbd; 4.697 + if (!xen_vbd_create(session->xen, &new_vbd, new_vbd_rec)) { 4.698 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.699 + 4.700 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.701 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.702 + ("--- xen_vbd_create failed: \"%s\"", error_msg)); 4.703 + 4.704 + return 0; 4.705 } 4.706 4.707 - _SBLIM_TRACE(2,("--- instance found", found)); 4.708 - 4.709 - /* Delete the target resource. */ 4.710 - if (!Xen_DiskSettingData_deleteResource(session, resource)) { 4.711 - XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.712 - _SBLIM_TRACE(1,("--- deleteResource failed: %s", error_msg)); 4.713 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg); 4.714 - goto exit; 4.715 - } 4.716 - 4.717 -exit: 4.718 - /* Free the resource. */ 4.719 - if (resource) 4.720 - Xen_DiskSettingData_freeResource(resource); 4.721 - 4.722 - _SBLIM_RETURNSTATUS(status); 4.723 + xen_vbd_free(new_vbd); 4.724 + return 1; 4.725 } 4.726 4.727 4.728 -// ---------------------------------------------------------------------------- 4.729 -// ExecQuery() 4.730 -// Return a list of all the instances that satisfy the specified query filter. 4.731 -// ---------------------------------------------------------------------------- 4.732 -static CMPIStatus ExecQuery( 4.733 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.734 - const CMPIContext * context, /* [in] Additional context info, if any. */ 4.735 - const CMPIResult * results, /* [out] Results of this operation. */ 4.736 - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ 4.737 - const char * language, /* [in] Name of the query language. */ 4.738 - const char * query) /* [in] Text of the query written in the query language. */ 4.739 +static int delete(void** res_list, void* res) 4.740 { 4.741 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 4.742 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 4.743 + xen_vbd_record *vbd_rec = (xen_vbd_record *)res; 4.744 + 4.745 + (void)res_list; 4.746 + 4.747 + if (vbd_rec == NULL) 4.748 + return 0; 4.749 + 4.750 + if (!xen_utils_validate_session(&session)) { 4.751 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.752 + ("--- Unable to establish connection with Xend")); 4.753 + return 0; 4.754 + } 4.755 4.756 - _SBLIM_ENTER("ExecQuery"); 4.757 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.758 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.759 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 4.760 - _SBLIM_TRACE(2, ("--- language=\"%s\"", language)); 4.761 - _SBLIM_TRACE(2, ("--- query=\"%s\"", query)); 4.762 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 4.763 + if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) { 4.764 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.765 + 4.766 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.767 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.768 + ("--- xen_vbd_destroy failed: \"%s\"", error_msg)); 4.769 + 4.770 + return 0; 4.771 + } 4.772 4.773 - /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */ 4.774 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL); 4.775 + return 1; 4.776 +} 4.777 + 4.778 4.779 - CMReturnDone(results); 4.780 - 4.781 -exit: 4.782 - _SBLIM_RETURNSTATUS(status); 4.783 +static int modify(void** res_list, void* res) 4.784 +{ 4.785 + return -1; /* unsupported */ 4.786 } 4.787 4.788 -// ---------------------------------------------------------------------------- 4.789 -// Initialize() 4.790 -// Perform any necessary initialization immediately after this provider is 4.791 -// first loaded. 4.792 -// ---------------------------------------------------------------------------- 4.793 -static void Initialize( 4.794 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 4.795 - const CMPIContext * context) /* [in] Additional context info, if any. */ 4.796 + 4.797 +/* Set CMPIInstance properties from the resource data. */ 4.798 +static int res2inst(void* res, CMPIInstance* inst) 4.799 { 4.800 - _SBLIM_ENTER("Initialize"); 4.801 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 4.802 - // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 4.803 + xen_vbd_record *vbd_rec = (xen_vbd_record *)res; 4.804 + char buf[MAX_INSTANCEID_LEN]; 4.805 + 4.806 + if (vbd_rec == NULL || CMIsNullObject(inst)) 4.807 + return 0; 4.808 + 4.809 + if (!xen_utils_validate_session(&session)) { 4.810 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.811 + ("--- Unable to establish connection with Xend")); 4.812 + return 0; 4.813 + } 4.814 + 4.815 + xen_vm_record_opt *vm_rec_opt = vbd_rec->vm; 4.816 + if (vm_rec_opt->is_record) { 4.817 + snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", 4.818 + vm_rec_opt->u.record->name_label, vbd_rec->uuid); 4.819 + } 4.820 + else { 4.821 + char *name = NULL; 4.822 + 4.823 + if (!xen_vm_get_name_label(session->xen, &name, vm_rec_opt->u.handle)) 4.824 + return 0; 4.825 + snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", 4.826 + name, vbd_rec->uuid); 4.827 + free(name); 4.828 + } 4.829 + 4.830 + /* Set the CMPIInstance properties from the resource data. */ 4.831 + CMSetProperty(inst, "InstanceID",(CMPIValue *)buf, CMPI_chars); 4.832 + CMSetProperty(inst, "ElementName",(CMPIValue *)vbd_rec->device, CMPI_chars); 4.833 + 4.834 + int type = 19; /* 19 == Storage Extent */ 4.835 + CMSetProperty(inst, "ResourceType",(CMPIValue *)&type, CMPI_uint16); 4.836 + 4.837 + int virtualized = 3; /* 3 == Virtualized */ 4.838 + CMSetProperty(inst, "ConsumerVisibility" , 4.839 + (CMPIValue *)&virtualized, CMPI_uint16); 4.840 4.841 - /* Initialized Xen session object. */ 4.842 - if (session == NULL) 4.843 - xen_utils_xen_init(&session); 4.844 + /* 4.845 + * TODO: Need to figure this out. May have to adhoc some up and 4.846 + * coming virtual storage-related profile. 4.847 + */ 4.848 + unsigned long long disks = 1; 4.849 + CMSetProperty(inst, "Reservation",(CMPIValue *)&disks, CMPI_uint64); 4.850 + CMSetProperty(inst, "Limit",(CMPIValue *)&disks, CMPI_uint64); 4.851 + CMSetProperty(inst, "AllocationUnits",(CMPIValue *)"Blocks", CMPI_chars); 4.852 + CMSetProperty(inst, "VirtualQuantity",(CMPIValue *)&disks, CMPI_uint64); 4.853 + 4.854 + int alloctype = 1; 4.855 + CMSetProperty(inst, "AutomaticAllocation" , 4.856 + (CMPIValue *)&alloctype, CMPI_boolean); 4.857 + CMSetProperty(inst, "AutomaticDeallocation" , 4.858 + (CMPIValue *)&alloctype, CMPI_boolean); 4.859 4.860 - _SBLIM_RETURN(); 4.861 + char *mode; 4.862 + if (vbd_rec->mode == XEN_VBD_MODE_RW) 4.863 + mode = "w"; 4.864 + else 4.865 + mode = "r"; 4.866 + 4.867 + xen_vdi_record_opt *vdi_rec_opt = vbd_rec->vdi; 4.868 + char *image; 4.869 + xen_string_string_map *vdi_params = NULL; 4.870 + if (xen_vdi_get_other_config(session->xen, &vdi_params, vdi_rec_opt->u.handle)) { 4.871 + if ((image = xen_utils_get_value_from_map(vdi_params, "location"))) { 4.872 + snprintf(buf, MAX_INSTANCEID_LEN, "%s,%s,%s", 4.873 + image, vbd_rec->device, mode); 4.874 + CMSetProperty(inst, "DiskConfigInfo",(CMPIValue *)buf, CMPI_chars); 4.875 + } 4.876 + } 4.877 + 4.878 + xen_string_string_map_free(vdi_params); 4.879 + 4.880 + /* 4.881 + * TODO: 4.882 + * PoolID, Weight, HostResource (mapped device in dom0) 4.883 + */ 4.884 + 4.885 + return 1; 4.886 } 4.887 4.888 -// ============================================================================ 4.889 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP 4.890 -// ============================================================================ 4.891 -CMInstanceMIStub( , Xen_DiskSettingData, _BROKER, Initialize(&mi, ctx)); 4.892 + 4.893 +/* Set resource data from the CMPIInstance properties. */ 4.894 +static int inst2res(CMPIInstance* inst, void** res) 4.895 +{ 4.896 + CMPIData data; 4.897 + char *inst_id; 4.898 + char uuid[MAX_SYSTEM_NAME_LEN]; 4.899 + int ccode; 4.900 + CMPIStatus status = {CMPI_RC_OK, NULL}; 4.901 + 4.902 + if (CMIsNullObject(inst) || res == NULL) 4.903 + return 0; 4.904 + 4.905 + data = CMGetProperty(inst, "InstanceID", &status); 4.906 + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data)) 4.907 + return 0; 4.908 + 4.909 + inst_id = CMGetCharPtr(data.value.string); 4.910 + if ((inst_id == NULL) || (*inst_id == '\0')) 4.911 + return 0; 4.912 + 4.913 + /* Extract the disk uuid from InstanceID property. */ 4.914 + if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN)) 4.915 + return 0; 4.916 + 4.917 + if (!xen_utils_validate_session(&session)) { 4.918 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.919 + ("--- Unable to establish connection with Xend")); 4.920 + return 0; 4.921 + } 4.922 + 4.923 + if (!xen_vbd_get_record(session->xen, (xen_vbd_record **)res, (xen_vbd)uuid)) { 4.924 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 4.925 + 4.926 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 4.927 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 4.928 + ("--- xen_vbd_destroy failed: \"%s\"", error_msg)); 4.929 + 4.930 + return 0; 4.931 + } 4.932 + 4.933 + return 1; 4.934 +} 4.935 + 4.936 + 4.937 +/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/ 4.938 +/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */ 4.939 +CMPILRInstanceMIStub(Xen_DiskSettingData, Xen_DiskSettingData, mi)
5.1 --- a/src/Xen_DiskSettingData_Resource.c Mon Apr 30 10:27:59 2007 -0600 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,306 +0,0 @@ 5.4 -// Copyright (C) 2006 IBM Corporation 5.5 -// 5.6 -// This library is free software; you can redistribute it and/or 5.7 -// modify it under the terms of the GNU Lesser General Public 5.8 -// License as published by the Free Software Foundation; either 5.9 -// version 2.1 of the License, or (at your option) any later version. 5.10 -// 5.11 -// This library is distributed in the hope that it will be useful, 5.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 5.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 5.14 -// Lesser General Public License for more details. 5.15 -// 5.16 -// You should have received a copy of the GNU Lesser General Public 5.17 -// License along with this library; if not, write to the Free Software 5.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 5.19 -// ============================================================================ 5.20 -// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 5.21 -// Tokunbo Adeshiyan, <tokunbo@us.ibm.com> 5.22 -// Contributors: Jim Fehlig, <jfehlig@novell.com> 5.23 -// Description: 5.24 -// ============================================================================ 5.25 - 5.26 -#include <stdlib.h> 5.27 -#include <string.h> 5.28 -#include <assert.h> 5.29 - 5.30 -#include <xen_common.h> 5.31 -#include <xen_vm.h> 5.32 -#include <xen_vbd.h> 5.33 - 5.34 -#include "Xen_DiskSettingData_Resource.h" 5.35 - 5.36 -/* Include the required CMPI data types, function headers, and macros. */ 5.37 -#include "cmpidt.h" 5.38 -#include "cmpift.h" 5.39 -#include "cmpimacs.h" 5.40 -#include "cmpiutil.h" 5.41 - 5.42 -#include "xen_utils.h" 5.43 -#include "provider_common.h" 5.44 - 5.45 -// ---------------------------------------------------------------------------- 5.46 - 5.47 -static int concat_disk_lists(xen_vbd_set **target, xen_vbd_set *source) 5.48 -{ 5.49 - 5.50 - int total_size; 5.51 - int i, j; 5.52 - 5.53 - /* Nothing to concatenate if source is empty */ 5.54 - if (source == NULL || source->size == 0) 5.55 - return 1; 5.56 - 5.57 - /* If targe is empty, assign source to target */ 5.58 - if (*target == NULL) { 5.59 - *target = source; 5.60 - return 1; 5.61 - } 5.62 - 5.63 - /* realloc memory and append source to target */ 5.64 - total_size = (*target)->size + source->size; 5.65 - *target = realloc(*target, sizeof(xen_vbd_set) + (total_size * sizeof(xen_vbd))); 5.66 - if (*target == NULL) 5.67 - return 0; 5.68 - 5.69 - for (j = (*target)->size, i = 0; i < source->size; i++) { 5.70 - (*target)->contents[j + i] = source->contents[i]; 5.71 - source->contents[i] = NULL; 5.72 - } 5.73 - (*target)->size = total_size; 5.74 - 5.75 - /* Free source list - it has been copied to target */ 5.76 - xen_vbd_set_free(source); 5.77 - return 1; 5.78 -} 5.79 - 5.80 - 5.81 -/* Get a handle to the list of all system resources for this class. */ 5.82 -int Xen_DiskSettingData_getResources(xen_utils_session *session, 5.83 - _RESOURCES ** resources) 5.84 -{ 5.85 - xen_domain_resources *res; 5.86 - xen_vbd_set *all_disks = NULL; 5.87 - xen_vm_record *vm_rec = NULL; 5.88 - 5.89 - /* malloc a new handle for the resources list. */ 5.90 - *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); 5.91 - if (*resources == NULL) 5.92 - return 0; 5.93 - 5.94 - /* Get a list of domain resources. */ 5.95 - if (!xen_utils_get_domain_resources(session, &res)) { 5.96 - *resources = NULL; 5.97 - return 0; 5.98 - } 5.99 - 5.100 - /* Create list of disk resources from disks found in each domain. */ 5.101 - while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) { 5.102 - xen_vbd_set *vbd_set; 5.103 - if (!xen_vm_get_vbds(session->xen, &vbd_set, vm_rec->handle)) 5.104 - goto Error; 5.105 - 5.106 - if (!concat_disk_lists(&all_disks, vbd_set)) 5.107 - goto Error; 5.108 - 5.109 - xen_vm_record_free(vm_rec); 5.110 - } 5.111 - 5.112 - (*resources)->disks = all_disks; 5.113 - (*resources)->currentdisknum = 0; 5.114 - 5.115 - return 1; 5.116 - 5.117 - Error: 5.118 - xen_vm_record_free(vm_rec); 5.119 - xen_utils_free_domain_resources(res); 5.120 - free(*resources); 5.121 - *resources = NULL; 5.122 - return 0; 5.123 -} 5.124 - 5.125 -// ---------------------------------------------------------------------------- 5.126 - 5.127 -/* Free/deallocate/cleanup the resources list after use. */ 5.128 -int Xen_DiskSettingData_freeResources(_RESOURCES * resources) 5.129 -{ 5.130 - if (resources != NULL) { 5.131 - if (resources->disks != NULL) 5.132 - xen_vbd_set_free(resources->disks); 5.133 - free(resources); 5.134 - resources = NULL; 5.135 - } 5.136 - 5.137 - return 1; 5.138 -} 5.139 - 5.140 -// ---------------------------------------------------------------------------- 5.141 - 5.142 -/* Iterator to get the next resource from the resources list. */ 5.143 -int Xen_DiskSettingData_getNextResource(xen_utils_session *session, 5.144 - _RESOURCES * resources, 5.145 - _RESOURCE ** resource) 5.146 -{ 5.147 - if (resources == NULL || resources->disks == NULL) 5.148 - return 0; 5.149 - 5.150 - /* Check if reached the end of the list of disks. */ 5.151 - if (resources->currentdisknum == resources->disks->size) 5.152 - return 0; 5.153 - 5.154 - /* Get the current disk record. */ 5.155 - if (!xen_vbd_get_record(session->xen, resource, resources->disks->contents[resources->currentdisknum])) 5.156 - return 0; 5.157 - 5.158 - resources->currentdisknum++; 5.159 - return 1; 5.160 -} 5.161 - 5.162 -// ---------------------------------------------------------------------------- 5.163 - 5.164 -/* Get the specific resource that matches the CMPI object path. */ 5.165 -int Xen_DiskSettingData_getResourceForObjectPath(xen_utils_session *session, 5.166 - _RESOURCE ** resource, 5.167 - const CMPIObjectPath * objectpath) 5.168 -{ 5.169 - char *instId; 5.170 - char uuid[MAX_SYSTEM_NAME_LEN]; 5.171 - int ccode; 5.172 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 5.173 - 5.174 - if (CMIsNullObject(objectpath)) return 0; 5.175 - 5.176 - /* Obtain the target resource identifier from the CMPIObjectPath key(s). */ 5.177 - CMPIData iddata = CMGetKey(objectpath, "InstanceID", &status); 5.178 - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(iddata)) return 0; 5.179 - 5.180 - instId = CMGetCharPtr(iddata.value.string); 5.181 - if ((instId == NULL) || (*instId == '\0')) return 0; 5.182 - 5.183 - /* Extract the disk uuid from InstanceID property. */ 5.184 - if (!_CMPIStrncpyDeviceNameFromID(uuid, instId, MAX_SYSTEM_NAME_LEN)) 5.185 - return 0; 5.186 - 5.187 - xen_vbd vbd; 5.188 - if (!xen_vbd_get_by_uuid(session->xen, &vbd, uuid)) 5.189 - return 0; 5.190 - 5.191 - ccode = xen_vbd_get_record(session->xen, resource, vbd); 5.192 - xen_vbd_free(vbd); 5.193 - return ccode; 5.194 -} 5.195 - 5.196 -// ---------------------------------------------------------------------------- 5.197 - 5.198 -/* Free/deallocate/cleanup the resource after use. */ 5.199 -int Xen_DiskSettingData_freeResource(_RESOURCE * resource) 5.200 -{ 5.201 - xen_vbd_record_free(resource); 5.202 - return 1; 5.203 -} 5.204 - 5.205 -// ---------------------------------------------------------------------------- 5.206 - 5.207 -/* Set the property values of a CMPI instance from a specific resource. */ 5.208 -int Xen_DiskSettingData_setInstanceFromResource(xen_utils_session *session, 5.209 - _RESOURCE * resource, 5.210 - const CMPIInstance * instance, 5.211 - const CMPIBroker * broker) 5.212 -{ 5.213 - char buf[MAX_INSTANCEID_LEN]; 5.214 - xen_vm_record *alloced_vm_rec = NULL; 5.215 - xen_vm_record *vm_rec; 5.216 - 5.217 - if (resource == NULL) return 0; 5.218 - if (CMIsNullObject(instance)) return 0; 5.219 - 5.220 - xen_vm_record_opt *vm_rec_opt = resource->vm; 5.221 - if (vm_rec_opt->is_record) { 5.222 - vm_rec = vm_rec_opt->u.record; 5.223 - } 5.224 - else { 5.225 - if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) { 5.226 - /* Error description in session object! */ 5.227 - return 0; 5.228 - } 5.229 - alloced_vm_rec = vm_rec; 5.230 - } 5.231 - 5.232 - /* Set the CMPIInstance properties from the resource data. */ 5.233 - snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:%s", vm_rec->name_label, resource->uuid); 5.234 - CMSetProperty(instance, "InstanceID",(CMPIValue *)buf, CMPI_chars); 5.235 - CMSetProperty(instance, "ElementName",(CMPIValue *)resource->device, CMPI_chars); 5.236 - 5.237 - int type = 19; /* 19 == Storage Extent */ 5.238 - CMSetProperty(instance, "ResourceType",(CMPIValue *)&type, CMPI_uint16); 5.239 - 5.240 - int virtualized = 3; /* 3 == Virtualized */ 5.241 - CMSetProperty(instance, "ConsumerVisibility" , (CMPIValue *)&virtualized, CMPI_uint16); 5.242 - 5.243 - /* 5.244 - * TODO: Need to figure this out. May have to adhoc some up and 5.245 - * coming virtual storage-related profile. 5.246 - */ 5.247 - unsigned long long disks = 1; 5.248 - CMSetProperty(instance, "Reservation",(CMPIValue *)&disks, CMPI_uint64); 5.249 - CMSetProperty(instance, "Limit",(CMPIValue *)&disks, CMPI_uint64); 5.250 - CMSetProperty(instance, "AllocationUnits",(CMPIValue *)"Blocks", CMPI_chars); 5.251 - CMSetProperty(instance, "VirtualQuantity",(CMPIValue *)&disks, CMPI_uint64); 5.252 - 5.253 - int alloctype = 1; 5.254 - CMSetProperty(instance, "AutomaticAllocation" , (CMPIValue *)&alloctype, CMPI_boolean); 5.255 - CMSetProperty(instance, "AutomaticDeallocation" , (CMPIValue *)&alloctype, CMPI_boolean); 5.256 - 5.257 - char *mode; 5.258 - if (resource->mode == XEN_VBD_MODE_RW) 5.259 - mode = "w"; 5.260 - else 5.261 - mode = "r"; 5.262 - 5.263 -/* snprintf(buf, MAX_INSTANCEID_LEN, "%s,%s,%s", resource->image, resource->device, mode); 5.264 - CMSetProperty(instance, "DiskConfigInfo",(CMPIValue *)buf, CMPI_chars); 5.265 - VDI<->VBD issue 5.266 -*/ 5.267 - /* 5.268 - * TODO: 5.269 - * PoolID, Weight, HostResource (mapped device in dom0) 5.270 - */ 5.271 - 5.272 - if (alloced_vm_rec) 5.273 - xen_vm_record_free(alloced_vm_rec); 5.274 - 5.275 - return 1; 5.276 -} 5.277 - 5.278 -// ---------------------------------------------------------------------------- 5.279 - 5.280 -/* Delete the specified resource from the system. */ 5.281 -int Xen_DiskSettingData_deleteResource(xen_utils_session *session, 5.282 - _RESOURCE * resource) 5.283 -{ 5.284 - return xen_vbd_destroy(session->xen, resource->handle); 5.285 -} 5.286 - 5.287 -// ---------------------------------------------------------------------------- 5.288 - 5.289 -/* Modify the specified resource using the property values of a CMPI instance. */ 5.290 -int Xen_DiskSettingData_setResourceFromInstance(_RESOURCE * resource, 5.291 - const CMPIInstance * instance, 5.292 - const CMPIBroker * broker) 5.293 -{ 5.294 - /* Unsupported. */ 5.295 - return -1; 5.296 -} 5.297 - 5.298 -// ---------------------------------------------------------------------------- 5.299 - 5.300 -/* Create a new resource using the property values of a CMPI instance. */ 5.301 -int Xen_DiskSettingData_createResourceFromInstance(_RESOURCES * resources, 5.302 - _RESOURCE ** resource, 5.303 - const CMPIInstance * instance, 5.304 - const CMPIBroker * broker) 5.305 -{ 5.306 - /* Unsupported. */ 5.307 - return -1; 5.308 -} 5.309 -
6.1 --- a/src/Xen_DiskSettingData_Resource.h Mon Apr 30 10:27:59 2007 -0600 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,105 +0,0 @@ 6.4 -// Copyright (C) 2006 IBM Corporation 6.5 -// 6.6 -// This library is free software; you can redistribute it and/or 6.7 -// modify it under the terms of the GNU Lesser General Public 6.8 -// License as published by the Free Software Foundation; either 6.9 -// version 2.1 of the License, or (at your option) any later version. 6.10 -// 6.11 -// This library is distributed in the hope that it will be useful, 6.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 6.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 6.14 -// Lesser General Public License for more details. 6.15 -// 6.16 -// You should have received a copy of the GNU Lesser General Public 6.17 -// License along with this library; if not, write to the Free Software 6.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6.19 -// ============================================================================ 6.20 -// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 6.21 -// Tokunbo Adeshiyan, <tokunbo@us.ibm.com> 6.22 -// Contributors: Jim Fehlig, <jfehlig@novell.com> 6.23 -// Description: 6.24 -// ============================================================================ 6.25 - 6.26 -/* Include required libxen headers. */ 6.27 -#include <xen_common.h> 6.28 -#include <xen_vbd.h> 6.29 - 6.30 -#include "xen_utils.h" 6.31 - 6.32 -/* Include the required CMPI data types. */ 6.33 -#include "cmpidt.h" 6.34 - 6.35 - 6.36 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 6.37 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. 6.38 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS 6.39 - LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. 6.40 - THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN 6.41 - ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ 6.42 -typedef struct { 6.43 - xen_vbd_set *disks; 6.44 - unsigned int currentdisknum; 6.45 -} _RESOURCES; 6.46 - 6.47 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 6.48 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. 6.49 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH 6.50 - RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE 6.51 - PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE 6.52 - ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ 6.53 -typedef xen_vbd_record _RESOURCE; 6.54 - 6.55 - 6.56 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ 6.57 - 6.58 -// ---------------------------------------------------------------------------- 6.59 -// Generic resource access methods for CMPI providers. 6.60 -// Return value: 6.61 -// -1 = Unsupported 6.62 -// 0 = Failed 6.63 -// 1 = OK 6.64 -// ---------------------------------------------------------------------------- 6.65 - 6.66 -/* Get a handle to the list of all system resources for this class. */ 6.67 -int Xen_DiskSettingData_getResources(xen_utils_session *session, 6.68 - _RESOURCES ** resources); 6.69 - 6.70 -/* Free/deallocate/cleanup the resources list after use. */ 6.71 -int Xen_DiskSettingData_freeResources(_RESOURCES * resources); 6.72 - 6.73 -/* Iterator to get the next resource from the resources list. */ 6.74 -int Xen_DiskSettingData_getNextResource(xen_utils_session *session, 6.75 - _RESOURCES * resources, 6.76 - _RESOURCE ** resource); 6.77 - 6.78 -/* Get the specific resource that matches the CMPI object path. */ 6.79 -int Xen_DiskSettingData_getResourceForObjectPath(xen_utils_session *session, 6.80 - _RESOURCE ** resource, 6.81 - const CMPIObjectPath * objectpath); 6.82 - 6.83 -/* Free/deallocate/cleanup a resource after use. */ 6.84 -int Xen_DiskSettingData_freeResource(_RESOURCE * resource); 6.85 - 6.86 -/* Set the property values of a CMPI instance from a specific resource. */ 6.87 -int Xen_DiskSettingData_setInstanceFromResource(xen_utils_session *session, 6.88 - _RESOURCE * resource, 6.89 - const CMPIInstance * instance, 6.90 - const CMPIBroker * broker); 6.91 - 6.92 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS 6.93 - 6.94 -/* Delete the specified resource from the system. */ 6.95 -int Xen_DiskSettingData_deleteResource(xen_utils_session *session, 6.96 - _RESOURCE * resource); 6.97 - 6.98 -/* Modify the specified resource using the property values of a CMPI instance. */ 6.99 -int Xen_DiskSettingData_setResourceFromInstance(_RESOURCE * resource, 6.100 - const CMPIInstance * instance, 6.101 - const CMPIBroker * broker); 6.102 - 6.103 -/* Create a new resource using the property values of a CMPI instance. */ 6.104 -int Xen_DiskSettingData_createResourceFromInstance(_RESOURCES * resources, 6.105 - _RESOURCE ** resource, 6.106 - const CMPIInstance * instance, 6.107 - const CMPIBroker * broker); 6.108 -
7.1 --- a/src/Xen_VirtualSystemManagementCapabilities.c Mon Apr 30 10:27:59 2007 -0600 7.2 +++ b/src/Xen_VirtualSystemManagementCapabilities.c Wed May 09 17:24:20 2007 -0600 7.3 @@ -1,4 +1,4 @@ 7.4 -// Copyright (C) 2006 Novell, Inc. 7.5 +// Copyright (C) 2007 Novell, Inc. 7.6 // 7.7 // This library is free software; you can redistribute it and/or 7.8 // modify it under the terms of the GNU Lesser General Public 7.9 @@ -21,409 +21,289 @@ 7.10 // methods are supported. 7.11 // ============================================================================ 7.12 7.13 -/* Include the required CMPI data types, function headers, and macros */ 7.14 +/* Common declarations for each CMPI "Cimpler" instance provider */ 7.15 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 7.16 #include "cmpidt.h" 7.17 -#include "cmpift.h" 7.18 #include "cmpimacs.h" 7.19 +#include "cmpilr.h" 7.20 7.21 7.22 -// ---------------------------------------------------------------------------- 7.23 -// COMMON GLOBAL VARIABLES 7.24 -// ---------------------------------------------------------------------------- 7.25 - 7.26 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */ 7.27 -static const CMPIBroker *_BROKER; 7.28 - 7.29 -/* Include utility functions */ 7.30 -#include "cmpiutil.h" 7.31 - 7.32 -/* Include _SBLIM_TRACE() logging support */ 7.33 -#include "cmpitrace.h" 7.34 - 7.35 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */ 7.36 -#include "Xen_VirtualSystemManagementCapabilities_Resource.h" 7.37 +static const CMPIInstanceMI* mi; 7.38 7.39 7.40 -// ============================================================================ 7.41 -// CMPI INSTANCE PROVIDER FUNCTION TABLE 7.42 -// ============================================================================ 7.43 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr) 7.44 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn) 7.45 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 7.46 7.47 -// ---------------------------------------------------------------------------- 7.48 -// Info for the class supported by the instance provider 7.49 -// ---------------------------------------------------------------------------- 7.50 +#include <stdlib.h> 7.51 7.52 -/* Name of the class implemented by this instance provider. */ 7.53 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 7.54 -static char * _CLASSNAME = "Xen_VirtualSystemManagementCapabilities"; 7.55 +#include <xen_common.h> 7.56 +#include <xen_host.h> 7.57 7.58 -/* NULL terminated list of key properties of this class. */ 7.59 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 7.60 -const static char * _KEYNAMES[] = {"InstanceID", NULL}; 7.61 +#include "cmpitrace.h" 7.62 +#include "xen_utils.h" 7.63 + 7.64 7.65 -// ---------------------------------------------------------------------------- 7.66 -// Cleanup() 7.67 -// Perform any necessary cleanup immediately before this provider is unloaded. 7.68 -// ---------------------------------------------------------------------------- 7.69 -static CMPIStatus Cleanup( 7.70 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.71 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.72 - CMPIBoolean terminating) /* [in] True if MB is terminating */ 7.73 +/* C struct to store the data for all resources. */ 7.74 +typedef struct { 7.75 + int finished; 7.76 +} _RESOURCES; 7.77 + 7.78 + 7.79 +/* Xen session object. Initialize when the provider is loaded, close when 7.80 + * provider unloaded. */ 7.81 +static xen_utils_session *session = NULL; 7.82 + 7.83 + 7.84 +static int load() 7.85 { 7.86 - CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ 7.87 + /* Initialized Xen session object. */ 7.88 + if (!session) 7.89 + xen_utils_xen_init(&session); 7.90 7.91 - _SBLIM_ENTER("Cleanup"); 7.92 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 7.93 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 7.94 - 7.95 - /* Nothing needs to be done for cleanup. */ 7.96 - _SBLIM_RETURNSTATUS(status); 7.97 + return 1; 7.98 } 7.99 7.100 -// ---------------------------------------------------------------------------- 7.101 -// EnumInstanceNames() 7.102 -// Return a list of all the instances names (return their object paths only). 7.103 -// ---------------------------------------------------------------------------- 7.104 -static CMPIStatus EnumInstanceNames( 7.105 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.106 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.107 - const CMPIResult * results, /* [out] Results of this operation. */ 7.108 - const CMPIObjectPath * reference) /* [in] Contains target namespace and classname. */ 7.109 + 7.110 +static int unload(CMPIBoolean terminating) 7.111 { 7.112 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 7.113 - _RESOURCES * resources; /* Handle to the list of system resources. */ 7.114 - _RESOURCE * resource; /* Handle to each system resource. */ 7.115 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 7.116 - int found = 0; /* Found any instances? */ 7.117 - 7.118 - _SBLIM_ENTER("EnumInstanceNames"); 7.119 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 7.120 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 7.121 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 7.122 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 7.123 - 7.124 - /* Get a handle to the list of system resources. */ 7.125 - if (!Xen_VirtualSystemManagementCapabilities_getResources(&resources)) { 7.126 - _SBLIM_TRACE(1,("--- _getResources() failed")); 7.127 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 7.128 - goto exit; 7.129 - } 7.130 - 7.131 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 7.132 - while (Xen_VirtualSystemManagementCapabilities_getNextResource(resources, &resource)) { 7.133 - /* Create a new CMPIInstance to store this resource. */ 7.134 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 7.135 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 7.136 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 7.137 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 7.138 - goto exit; 7.139 - } 7.140 - 7.141 - /* Set the instance property values from the resource data. */ 7.142 - if (!Xen_VirtualSystemManagementCapabilities_setInstanceFromResource(resource, instance, _BROKER)) { 7.143 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 7.144 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 7.145 - goto exit; 7.146 - } 7.147 - 7.148 - /* Free the resource data. */ 7.149 - if (!Xen_VirtualSystemManagementCapabilities_freeResource(resource)) { 7.150 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 7.151 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 7.152 - goto exit; 7.153 - } 7.154 - 7.155 - /* Return the CMPIObjectPath for this instance. */ 7.156 - CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status); 7.157 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { 7.158 - _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg))); 7.159 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance"); 7.160 - goto exit; 7.161 - } 7.162 - CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */ 7.163 - 7.164 - _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL)))); 7.165 - CMReturnObjectPath(results, objectpath); 7.166 - found++; 7.167 - } 7.168 - 7.169 - _SBLIM_TRACE(2,("--- %d object paths found", found)); 7.170 - CMReturnDone(results); 7.171 - 7.172 -exit: 7.173 - /* Free the list of system resources. */ 7.174 - if (!Xen_VirtualSystemManagementCapabilities_freeResources(resources)) { 7.175 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 7.176 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 7.177 - } 7.178 - 7.179 - _SBLIM_RETURNSTATUS(status); 7.180 -} 7.181 - 7.182 -// ---------------------------------------------------------------------------- 7.183 -// EnumInstances() 7.184 -// Return a list of all the instances (return all the instance data). 7.185 -// ---------------------------------------------------------------------------- 7.186 -static CMPIStatus EnumInstances( 7.187 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.188 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.189 - const CMPIResult * results, /* [out] Results of this operation. */ 7.190 - const CMPIObjectPath * reference, /* [in] Contains target namespace and classname. */ 7.191 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 7.192 -{ 7.193 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 7.194 - _RESOURCES * resources; /* Handle to the list of system resources. */ 7.195 - _RESOURCE * resource; /* Handle to each system resource. */ 7.196 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 7.197 - int found = 0; /* Found any resource instances? */ 7.198 - 7.199 - _SBLIM_ENTER("EnumInstances"); 7.200 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 7.201 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 7.202 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 7.203 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 7.204 - 7.205 - /* Get a handle to the list of system resources. */ 7.206 - if (!Xen_VirtualSystemManagementCapabilities_getResources(&resources)) { 7.207 - _SBLIM_TRACE(1,("--- _getResources() failed")); 7.208 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 7.209 - goto exit; 7.210 + (void) terminating; 7.211 + 7.212 + if (session) { 7.213 + xen_utils_xen_close(session); 7.214 + session = NULL; 7.215 } 7.216 7.217 - /* Enumerate thru the list of system resources and return a CMPIInstance for each. */ 7.218 - while (Xen_VirtualSystemManagementCapabilities_getNextResource(resources, &resource)) { 7.219 - /* Create a new CMPIInstance to store this resource. */ 7.220 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 7.221 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 7.222 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 7.223 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 7.224 - goto exit; 7.225 - } 7.226 + return 1; 7.227 +} 7.228 7.229 - /* Setup a filter to only return the desired properties. */ 7.230 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 7.231 - if (status.rc != CMPI_RC_OK) { 7.232 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 7.233 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 7.234 - goto exit; 7.235 - } 7.236 - 7.237 - /* Set the instance property values from the resource data. */ 7.238 - if (!Xen_VirtualSystemManagementCapabilities_setInstanceFromResource(resource, instance, _BROKER)) { 7.239 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 7.240 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 7.241 - goto exit; 7.242 - } 7.243 7.244 - /* Free the resource data. */ 7.245 - if (!Xen_VirtualSystemManagementCapabilities_freeResource(resource)) { 7.246 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 7.247 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 7.248 - goto exit; 7.249 - } 7.250 +static void* beginEnum() 7.251 +{ 7.252 + _RESOURCES *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES)); 7.253 + if (resources == NULL) 7.254 + return NULL; 7.255 7.256 - /* Return the CMPIInstance for this instance. */ 7.257 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 7.258 - CMReturnInstance(results, instance); 7.259 - found++; 7.260 - } 7.261 - 7.262 - _SBLIM_TRACE(2,("--- %d instances found", found)); 7.263 - CMReturnDone(results); 7.264 - 7.265 -exit: 7.266 - /* Free the list of system resources. */ 7.267 - if (!Xen_VirtualSystemManagementCapabilities_freeResources(resources)) { 7.268 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 7.269 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 7.270 - } 7.271 - 7.272 - _SBLIM_RETURNSTATUS(status); 7.273 + return resources; 7.274 } 7.275 7.276 -// ---------------------------------------------------------------------------- 7.277 -// GetInstance() 7.278 -// Return the instance data for the specified instance only. 7.279 -// ---------------------------------------------------------------------------- 7.280 -static CMPIStatus GetInstance( 7.281 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.282 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.283 - const CMPIResult * results, /* [out] Results of this operation. */ 7.284 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 7.285 - const char ** properties) /* [in] List of desired properties (NULL=all). */ 7.286 + 7.287 +static void endEnum(void* res_list) 7.288 { 7.289 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 7.290 - _RESOURCES * resources; /* Handle to the list of system resources. */ 7.291 - _RESOURCE * resource; /* Handle to the system resource. */ 7.292 - char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ 7.293 - int found = 0; /* Found the target instance? */ 7.294 + free(res_list); 7.295 +} 7.296 + 7.297 7.298 - _SBLIM_ENTER("GetInstance"); 7.299 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 7.300 - _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 7.301 - _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); 7.302 - _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); 7.303 +static void* getNext(void* res_list) 7.304 +{ 7.305 + xen_host host; 7.306 + xen_host_record *host_rec; 7.307 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 7.308 7.309 - /* Get a handle to the list of system resources. */ 7.310 - if (!Xen_VirtualSystemManagementCapabilities_getResources(&resources)) { 7.311 - _SBLIM_TRACE(1,("--- _getResources() failed")); 7.312 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources"); 7.313 - goto exit; 7.314 - } 7.315 + if (res_list == NULL || ((_RESOURCES *)res_list)->finished) 7.316 + return NULL; 7.317 + 7.318 + ((_RESOURCES *)res_list)->finished = 1; 7.319 7.320 - /* Get the target resource. */ 7.321 - found = Xen_VirtualSystemManagementCapabilities_getResourceForObjectPath(resources, &resource, reference); 7.322 - if (!found || (resource == NULL)) { 7.323 - _SBLIM_TRACE(1,("--- Target instance not found")); 7.324 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found"); 7.325 - goto exit; 7.326 + if (!xen_utils_validate_session(&session)) { 7.327 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 7.328 + ("--- Unable to establish connection with Xend")); 7.329 + return NULL; 7.330 } 7.331 7.332 - /* Create a new CMPIInstance to store this resource. */ 7.333 - CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status); 7.334 - if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) { 7.335 - _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); 7.336 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); 7.337 - goto exit; 7.338 - } 7.339 - 7.340 - /* Setup a filter to only return the desired properties. */ 7.341 - status = CMSetPropertyFilter(instance, properties, _KEYNAMES); 7.342 - if (status.rc != CMPI_RC_OK) { 7.343 - _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg))); 7.344 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter"); 7.345 - goto exit; 7.346 - } 7.347 - 7.348 - /* Set the instance property values from the resource data. */ 7.349 - if (!Xen_VirtualSystemManagementCapabilities_setInstanceFromResource(resource, instance, _BROKER)) { 7.350 - _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed")); 7.351 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data"); 7.352 - goto exit; 7.353 + xen_session_get_this_host(session->xen, &host, session->xen); 7.354 + xen_host_get_record(session->xen, &host_rec, host); 7.355 + if (!session->xen->ok) { 7.356 + /* Error description in session object. */ 7.357 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 7.358 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 7.359 + ("--- failed to retrieve host record from Xend: \"%s\"", 7.360 + error_msg)); 7.361 + return NULL; 7.362 } 7.363 - 7.364 - /* Free the resource data. */ 7.365 - if (!Xen_VirtualSystemManagementCapabilities_freeResource(resource)) { 7.366 - _SBLIM_TRACE(1,("--- _freeResource() failed")); 7.367 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data"); 7.368 - goto exit; 7.369 - } 7.370 - 7.371 - /* Return the CMPIInstance for this instance. */ 7.372 - _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL)))); 7.373 - CMReturnInstance(results, instance); 7.374 - 7.375 - _SBLIM_TRACE(2,("--- instance found")); 7.376 - CMReturnDone(results); 7.377 - 7.378 -exit: 7.379 - /* Free the list of system resources. */ 7.380 - if (!Xen_VirtualSystemManagementCapabilities_freeResources(resources)) { 7.381 - _SBLIM_TRACE(1,("--- _freeResources() failed")); 7.382 - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources"); 7.383 - } 7.384 - 7.385 - _SBLIM_RETURNSTATUS(status); 7.386 + 7.387 + return (void *)host_rec; 7.388 } 7.389 7.390 -// ---------------------------------------------------------------------------- 7.391 -// SetInstance() 7.392 -// Save modified instance data for the specified instance. 7.393 -// ---------------------------------------------------------------------------- 7.394 -static CMPIStatus SetInstance( 7.395 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.396 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.397 - const CMPIResult * results, /* [out] Results of this operation. */ 7.398 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 7.399 - const CMPIInstance * newinstance, /* [in] Contains the new instance data. */ 7.400 - const char **properties) 7.401 + 7.402 +static int get(void* res_list, void** res) 7.403 { 7.404 - _SBLIM_ENTER("SetInstance"); 7.405 + xen_host host; 7.406 + xen_host_record *host_rec; 7.407 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 7.408 + 7.409 + (void) res_list; 7.410 + 7.411 + if (!xen_utils_validate_session(&session)) { 7.412 + _SBLIM_TRACE(1, ("--- Unable to establish connection with Xend")); 7.413 + return 0; 7.414 + } 7.415 7.416 - /* Do not support modification of capabilities. */ 7.417 - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; 7.418 - 7.419 - _SBLIM_RETURNSTATUS(status); 7.420 + xen_session_get_this_host(session->xen, &host, session->xen); 7.421 + xen_host_get_record(session->xen, &host_rec, host); 7.422 + if (!session->xen->ok) { 7.423 + /* Error description in session object. */ 7.424 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 7.425 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 7.426 + ("--- failed to retrieve host record from Xend: \"%s\"", 7.427 + error_msg)); 7.428 + return 0; 7.429 + } 7.430 + 7.431 + *res = (void *)host_rec; 7.432 + return 1; 7.433 } 7.434 7.435 -// ---------------------------------------------------------------------------- 7.436 -// CreateInstance() 7.437 -// Create a new instance from the specified instance data. 7.438 -// ---------------------------------------------------------------------------- 7.439 -static CMPIStatus CreateInstance( 7.440 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.441 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.442 - const CMPIResult * results, /* [out] Results of this operation. */ 7.443 - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and object path. */ 7.444 - const CMPIInstance * newinstance) /* [in] Contains the new instance data. */ 7.445 + 7.446 +static void release(void* res) 7.447 { 7.448 - _SBLIM_ENTER("CreateInstance"); 7.449 - 7.450 - /* Do not support explicit creation of capabilities. */ 7.451 - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; 7.452 - 7.453 - _SBLIM_RETURNSTATUS(status); 7.454 -} 7.455 - 7.456 -// ---------------------------------------------------------------------------- 7.457 -// DeleteInstance() 7.458 -// Delete or remove the specified instance from the system. 7.459 -// ---------------------------------------------------------------------------- 7.460 -static CMPIStatus DeleteInstance( 7.461 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.462 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.463 - const CMPIResult * results, /* [out] Results of this operation. */ 7.464 - const CMPIObjectPath * reference) /* [in] Contains the target namespace, classname and object path. */ 7.465 -{ 7.466 - _SBLIM_ENTER("DeleteInstance"); 7.467 - 7.468 - /* Do not support explicit deletion of capabilities. */ 7.469 - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; 7.470 - 7.471 - _SBLIM_RETURNSTATUS(status); 7.472 + xen_host_record_free(res); 7.473 } 7.474 7.475 7.476 -// ---------------------------------------------------------------------------- 7.477 -// ExecQuery() 7.478 -// Return a list of all the instances that satisfy the specified query filter. 7.479 -// ---------------------------------------------------------------------------- 7.480 -static CMPIStatus ExecQuery( 7.481 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.482 - const CMPIContext * context, /* [in] Additional context info, if any. */ 7.483 - const CMPIResult * results, /* [out] Results of this operation. */ 7.484 - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ 7.485 - const char * language, /* [in] Name of the query language. */ 7.486 - const char * query) /* [in] Text of the query written in the query language. */ 7.487 +static int add(void** res_list, void* res) 7.488 +{ 7.489 + return -1; /* unsupported */ 7.490 +} 7.491 + 7.492 + 7.493 +static int delete(void** res_list, void* res) 7.494 { 7.495 - _SBLIM_ENTER("ExecQuery"); 7.496 + return -1; /* unsupported */ 7.497 +} 7.498 + 7.499 7.500 - /* 7.501 - * TODO: 7.502 - * Currently not supported. 7.503 - */ 7.504 - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; 7.505 - 7.506 - _SBLIM_RETURNSTATUS(status); 7.507 +static int modify(void** res_list, void* res) 7.508 +{ 7.509 + return -1; /* unsupported */ 7.510 } 7.511 7.512 -// ---------------------------------------------------------------------------- 7.513 -// Initialize() 7.514 -// Perform any necessary initialization immediately after this provider is 7.515 -// first loaded. 7.516 -// ---------------------------------------------------------------------------- 7.517 -static void Initialize( 7.518 - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ 7.519 - const CMPIContext * context) /* [in] Additional context info, if any. */ 7.520 + 7.521 +/* Set CMPIInstance properties from the resource data. */ 7.522 +static int res2inst(void* res, CMPIInstance* inst) 7.523 { 7.524 - _SBLIM_ENTER("Initialize"); 7.525 - _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); 7.526 - // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); 7.527 + xen_host_record *host_rec; 7.528 + int supported; 7.529 + 7.530 + if (res == NULL) 7.531 + return 0; 7.532 + 7.533 + if (CMIsNullObject(inst)) 7.534 + return 0; 7.535 + 7.536 + host_rec = (xen_host_record *)res; 7.537 + 7.538 + /* Set the CMPIInstance properties from the resource data. */ 7.539 + if (host_rec->name_label) { 7.540 + CMSetProperty(inst, "InstanceID", 7.541 + (CMPIValue *)host_rec->name_label, CMPI_chars); 7.542 + CMSetProperty(inst, "ElementName", 7.543 + (CMPIValue *)host_rec->name_label, CMPI_chars); 7.544 + } 7.545 + else 7.546 + { 7.547 + CMSetProperty(inst, "InstanceID", 7.548 + (CMPIValue *)"Xen Hypervisor", CMPI_chars); 7.549 + CMSetProperty(inst, "ElementName", 7.550 + (CMPIValue *)"Xen Hypervisor", CMPI_chars); 7.551 + } 7.552 + 7.553 + supported = 0; 7.554 + CMSetProperty(inst, "ElementNameEditSupported", 7.555 + (CMPIValue *)&supported, CMPI_boolean); 7.556 + /* 7.557 + * TODO: 7.558 + * Do we want to support enabling and disabling the management 7.559 + * service? I.e. starting / stopping xend. 7.560 + */ 7.561 + CMPIArray *statesSupported = CMNewArray(_BROKER, 1, CMPI_uint16, NULL); 7.562 + int state = 2; /* 'Enabled' */ 7.563 + CMSetArrayElementAt(statesSupported, 0, (CMPIValue *)&state, CMPI_uint16); 7.564 + CMSetProperty(inst, "RequestedStatesSupported", 7.565 + (CMPIValue *)&statesSupported, CMPI_uint16A); 7.566 7.567 - /* Nothing needs to be done to initialize this provider */ 7.568 - _SBLIM_RETURN(); 7.569 + /* 7.570 + * Known VirtualSystemTypes Xen supports are: 7.571 + * 7.572 + * xen-3.0-x86_32, xen-3.0-x86_32p, xen-3.0-x86_64, 7.573 + * hvm-3.0-x86_32, hvm-3.0-x86_32p, hvm-3.0-x86_64 7.574 + * 7.575 + */ 7.576 + xen_string_set *caps = host_rec->capabilities; 7.577 + if (caps && caps->size > 0) { 7.578 + CMPIValue value; 7.579 + int ndx; 7.580 + 7.581 + value.array = CMNewArray(_BROKER, caps->size, CMPI_string, NULL); 7.582 + for (ndx = 0; ndx < caps->size; ndx++) 7.583 + { 7.584 + CMPIString* tmp = CMNewString(_BROKER, (caps->contents[ndx]), NULL); 7.585 + CMSetArrayElementAt(value.array, ndx, &tmp, CMPI_string); 7.586 + } 7.587 + 7.588 + CMSetProperty(inst, "VirtualSystemTypesSupported",&value, CMPI_stringA); 7.589 + } 7.590 + 7.591 + /* 7.592 + * TODO: 7.593 + * We only support DefineSystem and DestroySystem at the 7.594 + * moment. Need to add others here when they are implemented in 7.595 + * Xen_VirtualSystemManagementService. 7.596 + * Also need to add the asynchronous methods supported once that is 7.597 + * implemented. 7.598 + */ 7.599 + CMPIArray *syncMethodsSupported = CMNewArray(_BROKER, 3, CMPI_uint16, NULL); 7.600 + supported = 2; /* 'DefineSystemSupported' */ 7.601 + CMSetArrayElementAt(syncMethodsSupported, 0, 7.602 + (CMPIValue *)&supported, CMPI_uint16); 7.603 + supported = 3; /* 'DestroySystemSupported */ 7.604 + CMSetArrayElementAt(syncMethodsSupported, 1, 7.605 + (CMPIValue *)&supported, CMPI_uint16); 7.606 + supported = 10; /* 'AddResourceSupported */ 7.607 + CMSetArrayElementAt(syncMethodsSupported, 2, 7.608 + (CMPIValue *)&supported, CMPI_uint16); 7.609 + CMSetProperty(inst, "SynchronousMethodsSupported", 7.610 + (CMPIValue *)&syncMethodsSupported, CMPI_uint16A); 7.611 + 7.612 + return 1; 7.613 } 7.614 7.615 -// ============================================================================ 7.616 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP 7.617 -// ============================================================================ 7.618 -CMInstanceMIStub( , Xen_VirtualSystemManagementCapabilities, _BROKER, Initialize(&mi, ctx)); 7.619 + 7.620 +/* Set resource data from the CMPIInstance properties. */ 7.621 +static int inst2res(CMPIInstance* inst, void** res) 7.622 +{ 7.623 + xen_host host; 7.624 + xen_host_record *host_rec; 7.625 + char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 7.626 + 7.627 + (void) inst; 7.628 + 7.629 + /* 7.630 + * Since we only have one VirtualSystemManagementService on this host 7.631 + * we'll just create the resource as usual. 7.632 + */ 7.633 + if (!xen_utils_validate_session(&session)) { 7.634 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 7.635 + ("--- Unable to establish connection with Xend")); 7.636 + return 0; 7.637 + } 7.638 + 7.639 + xen_session_get_this_host(session->xen, &host, session->xen); 7.640 + xen_host_get_record(session->xen, &host_rec, host); 7.641 + if (!session->xen->ok) { 7.642 + /* Error description in session object. */ 7.643 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 7.644 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 7.645 + ("--- failed to retrieve host record from Xend: \"%s\"", 7.646 + error_msg)); 7.647 + return 0; 7.648 + } 7.649 + 7.650 + *res = (void *)host_rec; 7.651 + return 1; 7.652 +} 7.653 + 7.654 + 7.655 +/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/ 7.656 +/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */ 7.657 +CMPILRInstanceMIStub(Xen_VirtualSystemManagementCapabilities, Xen_VirtualSystemManagementCapabilities, mi)
8.1 --- a/src/Xen_VirtualSystemManagementCapabilities_Resource.c Mon Apr 30 10:27:59 2007 -0600 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,254 +0,0 @@ 8.4 -// Copyright (C) 2006 Novell, Inc. 8.5 -// 8.6 -// This library is free software; you can redistribute it and/or 8.7 -// modify it under the terms of the GNU Lesser General Public 8.8 -// License as published by the Free Software Foundation; either 8.9 -// version 2.1 of the License, or (at your option) any later version. 8.10 -// 8.11 -// This library is distributed in the hope that it will be useful, 8.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 8.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 8.14 -// Lesser General Public License for more details. 8.15 -// 8.16 -// You should have received a copy of the GNU Lesser General Public 8.17 -// License along with this library; if not, write to the Free Software 8.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 8.19 -// ============================================================================ 8.20 -// Authors: Jim Fehlig, <jfehlig@novell.com> 8.21 -// Contributors: 8.22 -// Description: Encapsulates the resources used to instrument 8.23 -// Xen_VirtualSystemManagementCapabilities. 8.24 -// ============================================================================ 8.25 - 8.26 -#include <stdio.h> 8.27 -#include <string.h> 8.28 -#include <unistd.h> 8.29 -#include <stdlib.h> 8.30 - 8.31 -#include "Xen_VirtualSystemManagementCapabilities_Resource.h" 8.32 - 8.33 -/* Include the required CMPI data types, function headers, and macros. */ 8.34 -#include "cmpidt.h" 8.35 -#include "cmpift.h" 8.36 -#include "cmpimacs.h" 8.37 - 8.38 - 8.39 -// ---------------------------------------------------------------------------- 8.40 - 8.41 -/* Get a handle to the list of all system resources for this class. */ 8.42 -int Xen_VirtualSystemManagementCapabilities_getResources( _RESOURCES ** resources ) 8.43 -{ 8.44 - /* malloc a new handle for the resources list. */ 8.45 - *resources = (_RESOURCES *)malloc(sizeof(_RESOURCES)); 8.46 - if (*resources == NULL) return 0; 8.47 - 8.48 - (*resources)->finished = 0; 8.49 - 8.50 - return 1; 8.51 -} 8.52 - 8.53 -// ---------------------------------------------------------------------------- 8.54 - 8.55 -/* Free/deallocate/cleanup the resources list after use. */ 8.56 -int Xen_VirtualSystemManagementCapabilities_freeResources( _RESOURCES * resources ) 8.57 -{ 8.58 - if (resources != NULL) { 8.59 - free(resources); 8.60 - resources = NULL; 8.61 - } 8.62 - 8.63 - return 1; 8.64 -} 8.65 - 8.66 -// ---------------------------------------------------------------------------- 8.67 - 8.68 -/* Iterator to get the next resource from the resources list. */ 8.69 -int Xen_VirtualSystemManagementCapabilities_getNextResource( _RESOURCES * resources, _RESOURCE ** resource ) 8.70 -{ 8.71 - if (resources == NULL) return 0; 8.72 - if (resources->finished) return 0; 8.73 - 8.74 - /* Generate raw data for the single resource. */ 8.75 - *resource = (_RESOURCE *)malloc(sizeof(_RESOURCE)); 8.76 - if (*resource == NULL) return 0; 8.77 - 8.78 - (*resource)->name = strdup("Xen Hypervisor"); 8.79 - 8.80 - /* Single resource so no more resources in the list. */ 8.81 - resources->finished = 1; 8.82 - 8.83 - return 1; 8.84 -} 8.85 - 8.86 -// ---------------------------------------------------------------------------- 8.87 - 8.88 -/* Get the specific resource that matches the CMPI object path. */ 8.89 -int Xen_VirtualSystemManagementCapabilities_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath ) 8.90 -{ 8.91 - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ 8.92 - 8.93 - if (resources == NULL) return 0; 8.94 - if (CMIsNullObject(objectpath)) return 0; 8.95 - 8.96 - /* Obtain the name from the CMPIObjectPath key. */ 8.97 - CMPIData namedata = CMGetKey(objectpath, "InstanceID", &status); 8.98 - if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) return 0; 8.99 - 8.100 - /* Extract the name string from the CMPIString. */ 8.101 - char * name = CMGetCharPtr(namedata.value.string); 8.102 - if ((name == NULL) || (*name == '\0')) return 0; 8.103 - 8.104 - /* Check that the name is correct. */ 8.105 - if (strcmp(name, "Xen Hypervisor") != 0) return 0; 8.106 - 8.107 - /* Generate raw data for the single resource. */ 8.108 - *resource = (_RESOURCE *)malloc(sizeof(_RESOURCE)); 8.109 - if (*resource == NULL) return 0; 8.110 - 8.111 - (*resource)->name = strdup("Xen Hypervisor"); 8.112 - 8.113 - return 1; 8.114 -} 8.115 - 8.116 -// ---------------------------------------------------------------------------- 8.117 - 8.118 -/* Free/deallocate/cleanup the resource after use. */ 8.119 -int Xen_VirtualSystemManagementCapabilities_freeResource( _RESOURCE * resource ) 8.120 -{ 8.121 - if (resource != NULL) { 8.122 - if (resource->name != NULL) free(resource->name); 8.123 - free(resource); 8.124 - resource = NULL; 8.125 - } 8.126 - 8.127 - return 1; 8.128 -} 8.129 - 8.130 -// ---------------------------------------------------------------------------- 8.131 - 8.132 -/* Set the property values of a CMPI instance from a specific resource. */ 8.133 -int Xen_VirtualSystemManagementCapabilities_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker ) 8.134 -{ 8.135 - char **cap_array = NULL; 8.136 - int num_cap = 0; 8.137 - int ndx; 8.138 - 8.139 - if (resource == NULL) return 0; 8.140 - if (CMIsNullObject(instance)) return 0; 8.141 - 8.142 - /* Set the CMPIInstance properties from the resource data. */ 8.143 - CMSetProperty(instance, "InstanceID",(CMPIValue *)resource->name, CMPI_chars); 8.144 - CMSetProperty(instance, "ElementName",(CMPIValue *)resource->name, CMPI_chars); 8.145 - 8.146 - int nameEditSupported = 0; 8.147 - CMSetProperty(instance, "ElementNameEditSupported",(CMPIValue *)&nameEditSupported, CMPI_boolean); 8.148 - 8.149 - /* 8.150 - * TODO: 8.151 - * Do we want to support enabling and disabling the management 8.152 - * service? I.e. starting / stopping xend. 8.153 - */ 8.154 - CMPIArray *statesSupported = CMNewArray(broker, 1, CMPI_uint16, NULL); 8.155 - int state = 2; /* 'Enabled' */ 8.156 - CMSetArrayElementAt(statesSupported, 0, (CMPIValue *)&state, CMPI_uint16); 8.157 - CMSetProperty(instance, "RequestedStatesSupported",(CMPIValue *)&statesSupported, CMPI_uint16A); 8.158 - 8.159 - /* 8.160 - * VirtualSystemTypes supported will be screen-scraped from 'xm info' 8.161 - * for now. Know types are: 8.162 - * 8.163 - * xen-3.0-x86_64, xen-3.0-x86_32p, 8.164 - * hvm-3.0-x86_32, hvm-3.0-x86_32p, hvm-3.0-x86_64 8.165 - * 8.166 - * TODO: 8.167 - * Get some capabilities exposed through Xen API and replace this mess. 8.168 - */ 8.169 - FILE *cmd = popen("xm info | gawk -F: '/^xen_caps/ {print $2}'","r"); 8.170 - if (cmd == NULL) 8.171 - goto Exit; 8.172 - 8.173 - char cap_str[2048]; 8.174 - cap_str[0] = '\0'; 8.175 - fgets(cap_str, 2048, cmd); 8.176 - pclose(cmd); 8.177 - 8.178 - char *tok, *next_tok; 8.179 - tok = strtok_r(cap_str, " ", &next_tok); 8.180 - while (tok) { 8.181 - cap_array = (char **)realloc(cap_array, sizeof(char *) * (num_cap + 1)); 8.182 - if (cap_array == NULL) 8.183 - goto Exit; 8.184 - 8.185 - cap_array[num_cap] = strdup(tok); 8.186 - tok = strtok_r(NULL, " ", &next_tok); 8.187 - num_cap++; 8.188 - } 8.189 - 8.190 - if (num_cap > 0) { 8.191 - CMPIValue value; 8.192 - 8.193 - value.array = CMNewArray(broker, num_cap, CMPI_string, NULL); 8.194 - int ndx; 8.195 - for (ndx = 0; ndx < num_cap; ndx++) 8.196 - { 8.197 - CMPIString* tmp = CMNewString(broker, cap_array[ndx], NULL); 8.198 - CMSetArrayElementAt(value.array, ndx, &tmp, CMPI_string); 8.199 - } 8.200 - 8.201 - CMSetProperty(instance, "VirtualSystemTypesSupported",&value, CMPI_stringA); 8.202 - } 8.203 - 8.204 - /* 8.205 - * TODO: 8.206 - * We only support DefineSystem and DestroySystem at the 8.207 - * moment. Need to add others here when they are implemented in 8.208 - * Xen_VirtualSystemManagementService. 8.209 - * Also need to add the asynchronous methods supported once that is 8.210 - * implemented. 8.211 - */ 8.212 - CMPIArray *syncMethodsSupported = CMNewArray(broker, 3, CMPI_uint16, NULL); 8.213 - int supported = 2; /* 'DefineSystemSupported' */ 8.214 - CMSetArrayElementAt(syncMethodsSupported, 0, (CMPIValue *)&supported, CMPI_uint16); 8.215 - supported = 3; /* 'DestroySystemSupported */ 8.216 - CMSetArrayElementAt(syncMethodsSupported, 1, (CMPIValue *)&supported, CMPI_uint16); 8.217 - supported = 10; /* 'AddResourceSupported */ 8.218 - CMSetArrayElementAt(syncMethodsSupported, 2, (CMPIValue *)&supported, CMPI_uint16); 8.219 - CMSetProperty(instance, "SynchronousMethodsSupported",(CMPIValue *)&syncMethodsSupported, CMPI_uint16A); 8.220 - 8.221 - Exit: 8.222 - if (cap_array) { 8.223 - for (ndx = 0; ndx < num_cap; ndx++) 8.224 - free(cap_array[ndx]); 8.225 - free(cap_array); 8.226 - } 8.227 - 8.228 - return 1; 8.229 -} 8.230 - 8.231 -// ---------------------------------------------------------------------------- 8.232 - 8.233 -/* Delete the specified resource from the system. */ 8.234 -int Xen_VirtualSystemManagementCapabilities_deleteResource( _RESOURCES * resources, _RESOURCE * resource ) 8.235 -{ 8.236 - /* Unsupported. */ 8.237 - return -1; 8.238 -} 8.239 - 8.240 -// ---------------------------------------------------------------------------- 8.241 - 8.242 -/* Modify the specified resource using the property values of a CMPI instance. */ 8.243 -int Xen_VirtualSystemManagementCapabilities_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker ) 8.244 -{ 8.245 - /* Unsupported. */ 8.246 - return -1; 8.247 -} 8.248 - 8.249 -// ---------------------------------------------------------------------------- 8.250 - 8.251 -/* Create a new resource using the property values of a CMPI instance. */ 8.252 -int Xen_VirtualSystemManagementCapabilities_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker ) 8.253 -{ 8.254 - /* Unsupported. */ 8.255 - return -1; 8.256 -} 8.257 -
9.1 --- a/src/Xen_VirtualSystemManagementCapabilities_Resource.h Mon Apr 30 10:27:59 2007 -0600 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,84 +0,0 @@ 9.4 -// Copyright (C) 2006 Novell, Inc. 9.5 -// 9.6 -// This library is free software; you can redistribute it and/or 9.7 -// modify it under the terms of the GNU Lesser General Public 9.8 -// License as published by the Free Software Foundation; either 9.9 -// version 2.1 of the License, or (at your option) any later version. 9.10 -// 9.11 -// This library is distributed in the hope that it will be useful, 9.12 -// but WITHOUT ANY WARRANTY; without even the implied warranty of 9.13 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 9.14 -// Lesser General Public License for more details. 9.15 -// 9.16 -// You should have received a copy of the GNU Lesser General Public 9.17 -// License along with this library; if not, write to the Free Software 9.18 -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 9.19 -// ============================================================================ 9.20 -// Authors: Jim Fehlig, <jfehlig@novell.com> 9.21 -// Contributors: 9.22 -// Description: Encapsulates the resources used to instrument 9.23 -// Xen_VirtualSystemManagementCapabilities. 9.24 -// ============================================================================ 9.25 - 9.26 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 9.27 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES. 9.28 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS 9.29 - LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC. 9.30 - THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN 9.31 - ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ 9.32 -typedef struct { 9.33 - int finished; 9.34 -} _RESOURCES; 9.35 - 9.36 -/*** CUSTOMIZE FOR EACH PROVIDER ***/ 9.37 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE. 9.38 - THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH 9.39 - RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE 9.40 - PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE 9.41 - ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */ 9.42 -typedef struct { 9.43 - char *name; 9.44 -} _RESOURCE; 9.45 - 9.46 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */ 9.47 - 9.48 -/* Include the required CMPI data types. */ 9.49 -#include "cmpidt.h" 9.50 - 9.51 -// ---------------------------------------------------------------------------- 9.52 -// Generic resource access methods for CMPI providers. 9.53 -// Return value: 9.54 -// -1 = Unsupported 9.55 -// 0 = Failed 9.56 -// 1 = OK 9.57 -// ---------------------------------------------------------------------------- 9.58 - 9.59 -/* Get a handle to the list of all system resources for this class. */ 9.60 -int Xen_VirtualSystemManagementCapabilities_getResources( _RESOURCES ** resources ); 9.61 - 9.62 -/* Free/deallocate/cleanup the resources list after use. */ 9.63 -int Xen_VirtualSystemManagementCapabilities_freeResources( _RESOURCES * resources ); 9.64 - 9.65 -/* Iterator to get the next resource from the resources list. */ 9.66 -int Xen_VirtualSystemManagementCapabilities_getNextResource( _RESOURCES * resources, _RESOURCE ** resource ); 9.67 - 9.68 -/* Get the specific resource that matches the CMPI object path. */ 9.69 -int Xen_VirtualSystemManagementCapabilities_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath ); 9.70 - 9.71 -/* Free/deallocate/cleanup a resource after use. */ 9.72 -int Xen_VirtualSystemManagementCapabilities_freeResource( _RESOURCE * resource ); 9.73 - 9.74 -/* Set the property values of a CMPI instance from a specific resource. */ 9.75 -int Xen_VirtualSystemManagementCapabilities_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker ); 9.76 - 9.77 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS 9.78 - 9.79 -/* Delete the specified resource from the system. */ 9.80 -int Xen_VirtualSystemManagementCapabilities_deleteResource( _RESOURCES * resources, _RESOURCE * resource ); 9.81 - 9.82 -/* Modify the specified resource using the property values of a CMPI instance. */ 9.83 -int Xen_VirtualSystemManagementCapabilities_setResourceFromInstance( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker ); 9.84 - 9.85 -/* Create a new resource using the property values of a CMPI instance. */ 9.86 -int Xen_VirtualSystemManagementCapabilities_createResourceFromInstance( _RESOURCES * resources, _RESOURCE ** resource, const CMPIInstance * instance, const CMPIBroker * broker ); 9.87 -
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/cmpilr.c Wed May 09 17:24:20 2007 -0600 10.3 @@ -0,0 +1,508 @@ 10.4 +// Copyright (C) 2007 IBM Corp. 10.5 +// 10.6 +// This library is free software; you can redistribute it and/or 10.7 +// modify it under the terms of the GNU Lesser General Public 10.8 +// License as published by the Free Software Foundation; either 10.9 +// version 2.1 of the License, or (at your option) any later version. 10.10 +// 10.11 +// This library is distributed in the hope that it will be useful, 10.12 +// but WITHOUT ANY WARRANTY; without even the implied warranty of 10.13 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10.14 +// Lesser General Public License for more details. 10.15 +// 10.16 +// You should have received a copy of the GNU Lesser General Public 10.17 +// License along with this library; if not, write to the Free Software 10.18 +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 10.19 +// ============================================================================ 10.20 +// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 10.21 +// ============================================================================ 10.22 + 10.23 +#include "cmpidt.h" 10.24 +#include "cmpift.h" 10.25 +#include "cmpimacs.h" 10.26 +#include "cmpilr.h" 10.27 + 10.28 +#include "cmpitrace.h" 10.29 + 10.30 + 10.31 +/* Redefine the CMGetCharPtr() macro to better handle NULL CMPI_strings. */ 10.32 +#undef CMGetCharPtr 10.33 +#define CMGetCharPtr(s) (((s)==NULL || *((void**)(s))==NULL)? NULL : (char*)((s)->hdl)) 10.34 + 10.35 +/* Shortcuts to the resource specific implementation data and function table. */ 10.36 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr) 10.37 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn) 10.38 +#define _FT (((CMPIResource*)(mi->hdl))->ft) 10.39 + 10.40 + 10.41 +/* ------------------------------------------------------------------------- */ 10.42 + 10.43 +static int op2res(CMPIObjectPath* op, void** res, CMPIInstanceMI* mi) 10.44 +{ 10.45 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.46 + 10.47 + /* Create a new CMPIInstance for the CMPIObjectPath. */ 10.48 + CMPIInstance* inst = CMNewInstance(_BROKER, op, &status); 10.49 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) return 0; 10.50 + 10.51 + /* Set the CMPIInstance key properties from the CMPIObjectPath keys. */ 10.52 + int numkeys = CMGetKeyCount(op, &status); 10.53 + if (status.rc != CMPI_RC_OK) return 0; 10.54 + CMPIString* keyname; 10.55 + int i; 10.56 + for (i=0; i<numkeys; i++) { 10.57 + CMPIData key = CMGetKeyAt(op, i, &keyname, &status); 10.58 + if (status.rc != CMPI_RC_OK) return 0; 10.59 + status = CMSetProperty(inst, CMGetCharPtr(keyname), &(key.value), key.type); 10.60 + if (status.rc != CMPI_RC_OK) return 0; 10.61 + } 10.62 + 10.63 + /* Create a partial resource from the CMPIInstance key properties. */ 10.64 + return _FT->inst2res(inst, res); 10.65 +} 10.66 + 10.67 +/* ------------------------------------------------------------------------- */ 10.68 + 10.69 +static int getres4op(void** res, CMPIObjectPath* op, CMPIInstanceMI* mi) 10.70 +{ 10.71 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.72 + 10.73 + int rc = op2res(op, res, mi); 10.74 + if (!rc || !*res) return 0; 10.75 + 10.76 + /* Get handle to the list of resources. */ 10.77 + void* resList = _FT->beginEnum(); 10.78 + if (!resList) { 10.79 + _FT->release(*res); 10.80 + return 0; 10.81 + } 10.82 + 10.83 + /* First try to get the target resource directly. */ 10.84 + rc = _FT->get(resList, res); 10.85 + if (rc == 0) { /* get() failed */ 10.86 + _FT->release(*res); 10.87 + _FT->endEnum(resList); 10.88 + return 0; 10.89 + } else if (rc == -1) { /*get() unsupported */ 10.90 + /*FIXME - enumerate all to look for match instead*/ 10.91 + _FT->release(*res); 10.92 + _FT->endEnum(resList); 10.93 + return 0; 10.94 + } 10.95 + 10.96 + _FT->endEnum(resList); 10.97 + return 1; 10.98 +} 10.99 + 10.100 +/* ------------------------------------------------------------------------- */ 10.101 +/* The generic CMPILR resource-agnostic CMPI instance provider functions. */ 10.102 +/* ------------------------------------------------------------------------- */ 10.103 + 10.104 +CMPIStatus CMPILR_cleanup 10.105 + (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating) 10.106 +{ 10.107 + _SBLIM_ENTER("CMPILR_cleanup"); 10.108 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.109 + 10.110 + /* Run the provider's unload() routine. */ 10.111 + if (!_FT->unload(terminating)) { 10.112 + if (!terminating) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_DO_NOT_UNLOAD, "unload() failed") 10.113 + else CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unload() failed"); 10.114 + } 10.115 + 10.116 + _SBLIM_RETURNSTATUS(status); 10.117 +} 10.118 + 10.119 +/* ------------------------------------------------------------------------- */ 10.120 + 10.121 +CMPIStatus CMPILR_enumInstanceNames 10.122 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.123 + const CMPIObjectPath* ref) 10.124 +{ 10.125 + _SBLIM_ENTER("CMPILR_enumInstanceNames"); 10.126 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.127 + 10.128 + /* Get handle to the list of resources. */ 10.129 + void* resList = _FT->beginEnum(); 10.130 + if (!resList) { 10.131 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.132 + _SBLIM_RETURNSTATUS(status); 10.133 + } 10.134 + 10.135 + /* Enumerate all the resources and return a CMPIObjectPath for each. */ 10.136 + char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL)); 10.137 + int found = 0; 10.138 + while (1) { 10.139 + /* Create a new CMPIObjectPath for the next resource. */ 10.140 + CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status); 10.141 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) { 10.142 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed"); 10.143 + break; 10.144 + } 10.145 + 10.146 + /* Create a new CMPIInstance for the next resource. */ 10.147 + CMPIInstance* inst = CMNewInstance(_BROKER, op, &status); 10.148 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) { 10.149 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed"); 10.150 + break; 10.151 + } 10.152 + 10.153 + /* Get the next resource. */ 10.154 + void* res = _FT->getNext(resList); 10.155 + if (!res) break; /* while() loop exit! */ 10.156 + 10.157 + /* Set the CMPIInstance properties from the resource data. */ 10.158 + int rc = _FT->res2inst(res, inst); 10.159 + _FT->release(res); 10.160 + if (!rc) { 10.161 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed"); 10.162 + break; 10.163 + } 10.164 + 10.165 + /* Get the CMPIObjectPath for this CMPIInstance. */ 10.166 + op = CMGetObjectPath(inst, &status); 10.167 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) { 10.168 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMGetObjectPath() failed"); 10.169 + break; 10.170 + } 10.171 + status = CMSetNameSpace(op, ns); /* CMGetObjectPath() does not preserve the instance's namespace! */ 10.172 + if (status.rc != CMPI_RC_OK) { 10.173 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetNameSpace() failed"); 10.174 + break; 10.175 + } 10.176 + 10.177 + /* Return the CMPIObjectPath for the resource. */ 10.178 + status = CMReturnObjectPath(rslt, op); 10.179 + if (status.rc != CMPI_RC_OK) { 10.180 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnObjectPath() failed"); 10.181 + break; 10.182 + } 10.183 + found++; 10.184 + } /* while() */ 10.185 + _FT->endEnum(resList); 10.186 + 10.187 + if (found) {if (status.rc == CMPI_RC_OK) CMReturnDone(rslt);} 10.188 + else CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND); 10.189 + 10.190 + _SBLIM_RETURNSTATUS(status); 10.191 +} 10.192 + 10.193 +/* ------------------------------------------------------------------------- */ 10.194 + 10.195 +CMPIStatus CMPILR_enumInstances 10.196 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.197 + const CMPIObjectPath* ref, const char** properties) 10.198 +{ 10.199 + _SBLIM_ENTER("CMPILR_enumInstances"); 10.200 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.201 + 10.202 + /* Get handle to the list of resources. */ 10.203 + void* resList = _FT->beginEnum(); 10.204 + if (!resList) { 10.205 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.206 + _SBLIM_RETURNSTATUS(status); 10.207 + } 10.208 + 10.209 + /* Enumerate all the resources and return a CMPIObjectPath for each. */ 10.210 + char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL)); 10.211 + int found = 0; 10.212 + while (1) { 10.213 + /* Create a new CMPIObjectPath for the next resource. */ 10.214 + CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status); 10.215 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) { 10.216 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed"); 10.217 + break; 10.218 + } 10.219 + 10.220 + /* Create a new CMPIInstance for the next resource. */ 10.221 + CMPIInstance* inst = CMNewInstance(_BROKER, op, &status); 10.222 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) { 10.223 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed"); 10.224 + break; 10.225 + } 10.226 + 10.227 + /* Get the next resource. */ 10.228 + void* res = _FT->getNext(resList); 10.229 + if (!res) break; /* while() loop exit! */ 10.230 + 10.231 + /* Set the property filter for this CMPIInstance, if specified. */ 10.232 + if (properties != NULL) { 10.233 + status = CMSetPropertyFilter(inst, properties, NULL); 10.234 + if (status.rc != CMPI_RC_OK) { 10.235 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetPropertyFilter() failed"); 10.236 + break; 10.237 + } 10.238 + } 10.239 + 10.240 + /* Set the CMPIInstance properties from the resource data. */ 10.241 + int rc = _FT->res2inst(res, inst); 10.242 + _FT->release(res); 10.243 + if (!rc) { 10.244 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed"); 10.245 + break; 10.246 + } 10.247 + 10.248 + /* Return the CMPIInstance for the resource. */ 10.249 + status = CMReturnInstance(rslt, inst); 10.250 + if (status.rc != CMPI_RC_OK) { 10.251 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed"); 10.252 + break; 10.253 + } 10.254 + found++; 10.255 + } /* while() */ 10.256 + _FT->endEnum(resList); 10.257 + 10.258 + if (found) {if (status.rc == CMPI_RC_OK) CMReturnDone(rslt);} 10.259 + else CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND); 10.260 + 10.261 + _SBLIM_RETURNSTATUS(status); 10.262 +} 10.263 + 10.264 +/* ------------------------------------------------------------------------- */ 10.265 + 10.266 +CMPIStatus CMPILR_getInstance 10.267 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.268 + const CMPIObjectPath* ref, const char** properties) 10.269 +{ 10.270 + _SBLIM_ENTER("CMPILR_getInstance"); 10.271 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.272 + 10.273 + /* Create a new CMPIInstance for the resource. */ 10.274 + CMPIInstance* inst = CMNewInstance(_BROKER, ref, &status); 10.275 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) { 10.276 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed"); 10.277 + _SBLIM_RETURNSTATUS(status); 10.278 + } 10.279 + 10.280 + /* Set the property filter for this CMPIInstance, if specified. */ 10.281 + if (properties != NULL) { 10.282 + status = CMSetPropertyFilter(inst, properties, NULL); 10.283 + if (status.rc != CMPI_RC_OK) { 10.284 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMSetPropertyFilter() failed"); 10.285 + _SBLIM_RETURNSTATUS(status); 10.286 + } 10.287 + } 10.288 + 10.289 + /* Try to get the target resource. */ 10.290 + void* res; 10.291 + int rc = getres4op(&res, (CMPIObjectPath*)ref, mi); 10.292 + if (!rc) { 10.293 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed"); 10.294 + _SBLIM_RETURNSTATUS(status); 10.295 + } 10.296 + 10.297 + /* Set the CMPIInstance properties from the resource data. */ 10.298 + rc = _FT->res2inst(res, inst); 10.299 + _FT->release(res); 10.300 + if (!rc) { 10.301 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed"); 10.302 + _SBLIM_RETURNSTATUS(status); 10.303 + } 10.304 + 10.305 + /* Return the CMPIInstance for the resource. */ 10.306 + status = CMReturnInstance(rslt, inst); 10.307 + if (status.rc != CMPI_RC_OK) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed"); 10.308 + 10.309 + if (status.rc == CMPI_RC_OK) CMReturnDone(rslt); 10.310 + 10.311 + _SBLIM_RETURNSTATUS(status); 10.312 +} 10.313 + 10.314 +/* ------------------------------------------------------------------------- */ 10.315 + 10.316 +CMPIStatus CMPILR_createInstance 10.317 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.318 + const CMPIObjectPath* ref, const CMPIInstance* inst) 10.319 +{ 10.320 + _SBLIM_ENTER("CMPILR_createInstance"); 10.321 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.322 + 10.323 + /* Try to get the target resource. */ 10.324 + void* res; 10.325 + int rc = getres4op(&res, (CMPIObjectPath*)ref, mi); 10.326 + if (rc) { 10.327 + _FT->release(res); 10.328 + CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS); 10.329 + _SBLIM_RETURNSTATUS(status); 10.330 + } 10.331 + 10.332 + rc = _FT->inst2res((CMPIInstance*)inst, &res); 10.333 + if (!rc || !res) { 10.334 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "inst2res() failed"); 10.335 + _SBLIM_RETURNSTATUS(status); 10.336 + } 10.337 + 10.338 + /* Get handle to the list of resources. */ 10.339 + void* resList = _FT->beginEnum(); 10.340 + if (!resList) { 10.341 + _FT->release(res); 10.342 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.343 + _SBLIM_RETURNSTATUS(status); 10.344 + } 10.345 + 10.346 + /* Add the target resource. */ 10.347 + rc = _FT->add(&resList, res); 10.348 + if (rc == -1) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, "add() unsupported") 10.349 + else if (!rc) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "add() failed"); 10.350 + 10.351 + _FT->release(res); 10.352 + _FT->endEnum(resList); 10.353 + 10.354 + _SBLIM_RETURNSTATUS(status); 10.355 +} 10.356 + 10.357 +/* ------------------------------------------------------------------------- */ 10.358 + 10.359 +CMPIStatus CMPILR_modifyInstance 10.360 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.361 + const CMPIObjectPath* ref, const CMPIInstance* inst, const char** properties) 10.362 +{ 10.363 + _SBLIM_ENTER("CMPILR_modifyInstance"); 10.364 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.365 + 10.366 + /* Try to get the target resource. */ 10.367 + void* res; 10.368 + int rc = getres4op(&res, (CMPIObjectPath*)ref, mi); 10.369 + if (!rc) { 10.370 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed"); 10.371 + _SBLIM_RETURNSTATUS(status); 10.372 + } 10.373 + 10.374 + rc = _FT->inst2res((CMPIInstance*)inst, &res); 10.375 + if (!rc || !res) { 10.376 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "inst2res() failed"); 10.377 + _SBLIM_RETURNSTATUS(status); 10.378 + } 10.379 + 10.380 + /* Get handle to the list of resources. */ 10.381 + void* resList = _FT->beginEnum(); 10.382 + if (!resList) { 10.383 + _FT->release(res); 10.384 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.385 + _SBLIM_RETURNSTATUS(status); 10.386 + } 10.387 + 10.388 + /* Add the target resource. */ 10.389 + rc = _FT->modify(&resList, res); 10.390 + if (rc == -1) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, "modify() unsupported") 10.391 + else if (!rc) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "modify() failed"); 10.392 + 10.393 + _FT->release(res); 10.394 + _FT->endEnum(resList); 10.395 + 10.396 + _SBLIM_RETURNSTATUS(status); 10.397 +} 10.398 + 10.399 +/* ------------------------------------------------------------------------- */ 10.400 + 10.401 +CMPIStatus CMPILR_deleteInstance 10.402 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.403 + const CMPIObjectPath* ref) 10.404 +{ 10.405 + _SBLIM_ENTER("CMPILR_deleteInstance"); 10.406 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.407 + 10.408 + /* Try to get the target resource. */ 10.409 + void* res; 10.410 + int rc = getres4op(&res, (CMPIObjectPath*)ref, mi); 10.411 + if (!rc) { 10.412 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed"); 10.413 + _SBLIM_RETURNSTATUS(status); 10.414 + } 10.415 + 10.416 + /* Get handle to the list of resources. */ 10.417 + void* resList = _FT->beginEnum(); 10.418 + if (!resList) { 10.419 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.420 + _SBLIM_RETURNSTATUS(status); 10.421 + } 10.422 + 10.423 + /* Delete the target resource. */ 10.424 + rc = _FT->delete(&resList, res); 10.425 + if (rc == -1) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, "delete() unsupported") 10.426 + else if (!rc) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "delete() failed"); 10.427 + 10.428 + _FT->release(res); 10.429 + _FT->endEnum(resList); 10.430 + 10.431 + _SBLIM_RETURNSTATUS(status); 10.432 +} 10.433 + 10.434 +/* ------------------------------------------------------------------------- */ 10.435 + 10.436 +CMPIStatus CMPILR_execQuery 10.437 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 10.438 + const CMPIObjectPath* ref, const char* query, const char* lang) 10.439 +{ 10.440 + _SBLIM_ENTER("CMPILR_execQuery"); 10.441 + CMPIStatus status = {CMPI_RC_OK, NULL}; 10.442 + 10.443 + /* Create a new select expression from the query. */ 10.444 + CMPISelectExp* expr = CMNewSelectExp(_BROKER, query, lang, NULL, &status); 10.445 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(expr)) { 10.446 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_QUERY, "CMNewSelectExp() failed"); 10.447 + _SBLIM_RETURNSTATUS(status); 10.448 + } 10.449 + 10.450 + /* Get handle to the list of resources. */ 10.451 + void* resList = _FT->beginEnum(); 10.452 + if (!resList) { 10.453 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed"); 10.454 + _SBLIM_RETURNSTATUS(status); 10.455 + } 10.456 + 10.457 + /* Enumerate all the resources and return a CMPIInstance for any that match the query. */ 10.458 + char* ns = CMGetCharPtr(CMGetNameSpace(ref, NULL)); 10.459 + int found = 0; 10.460 + while (1) { 10.461 + /* Create a new CMPIObjectPath for the next resource. */ 10.462 + CMPIObjectPath* op = CMNewObjectPath(_BROKER, ns, _CLASS, &status); 10.463 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) { 10.464 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewObjectPath() failed"); 10.465 + break; 10.466 + } 10.467 + 10.468 + /* Create a new CMPIInstance for the next resource. */ 10.469 + CMPIInstance* inst = CMNewInstance(_BROKER, op, &status); 10.470 + if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) { 10.471 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMNewInstance() failed"); 10.472 + break; 10.473 + } 10.474 + 10.475 + /* Get the next resource. */ 10.476 + void* res = _FT->getNext(resList); 10.477 + if (!res) break; /* while() loop exit! */ 10.478 + 10.479 + /* Set the CMPIInstance properties from the resource data. */ 10.480 + int rc = _FT->res2inst(res, inst); 10.481 + _FT->release(res); 10.482 + if (!rc) { 10.483 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "res2inst() failed"); 10.484 + break; 10.485 + } 10.486 + 10.487 + /* Evaluate the select expression against this CMPIInstance. */ 10.488 + rc = CMEvaluateSelExp(expr, inst, &status); 10.489 + if (status.rc != CMPI_RC_OK) { 10.490 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMEvaluateSelExp() failed"); 10.491 + break; 10.492 + } 10.493 + 10.494 + /* Return the CMPIInstance for the resource if it matches the original query. */ 10.495 + if (rc) { 10.496 + status = CMReturnInstance(rslt, inst); 10.497 + if (status.rc != CMPI_RC_OK) { 10.498 + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "CMReturnInstance() failed"); 10.499 + break; 10.500 + } 10.501 + found++; 10.502 + } 10.503 + } /* while() */ 10.504 + _FT->endEnum(resList); 10.505 + 10.506 + if (found) {if (status.rc == CMPI_RC_OK) CMReturnDone(rslt);} 10.507 + else CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND); 10.508 + 10.509 + _SBLIM_RETURNSTATUS(status); 10.510 +} 10.511 +
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/cmpilr.h Wed May 09 17:24:20 2007 -0600 11.3 @@ -0,0 +1,148 @@ 11.4 +// Copyright (C) 2007 IBM Corp. 11.5 +// 11.6 +// This library is free software; you can redistribute it and/or 11.7 +// modify it under the terms of the GNU Lesser General Public 11.8 +// License as published by the Free Software Foundation; either 11.9 +// version 2.1 of the License, or (at your option) any later version. 11.10 +// 11.11 +// This library is distributed in the hope that it will be useful, 11.12 +// but WITHOUT ANY WARRANTY; without even the implied warranty of 11.13 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11.14 +// Lesser General Public License for more details. 11.15 +// 11.16 +// You should have received a copy of the GNU Lesser General Public 11.17 +// License along with this library; if not, write to the Free Software 11.18 +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 11.19 +// ============================================================================ 11.20 +// Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com> 11.21 +// ============================================================================ 11.22 + 11.23 +#if !defined(__CMPITLR_H__) 11.24 +#define __CMPILR_H__ 11.25 + 11.26 +#include "cmpidt.h" 11.27 + 11.28 +/* ------------------------------------------------------------------------- */ 11.29 +/* The generic CMPILR function table to manage system resources. */ 11.30 +/* ------------------------------------------------------------------------- */ 11.31 + 11.32 +typedef struct _CMPIResourceFT { 11.33 + int (*load)(); 11.34 + int (*unload)(CMPIBoolean terminating); 11.35 + void* (*beginEnum)(); 11.36 + void (*endEnum)(void* resList); 11.37 + void* (*getNext)(void* resList); 11.38 + int (*get)(void* resList, void** res); 11.39 + void (*release)(void* res); 11.40 + int (*add)(void** resList, void* res); 11.41 + int (*delete)(void** resList, void* res); 11.42 + int (*modify)(void** resList, void* res); 11.43 + int (*res2inst)(void* res, CMPIInstance* inst); 11.44 + int (*inst2res)(CMPIInstance* inst, void** res); 11.45 +} CMPIResourceFT; 11.46 + 11.47 +/* ------------------------------------------------------------------------- */ 11.48 +/* The generic CMPIPR encapsulated object for system resources. */ 11.49 +/* ------------------------------------------------------------------------- */ 11.50 + 11.51 +typedef struct _CMPIResource { 11.52 + void* hdl; /* Opaque pointer to any resource specific implementation data. */ 11.53 + const CMPIBroker* brkr; /* Handle to the CIM broker/CIMOM. */ 11.54 + char* cn; /* The resource provider's CIM class */ 11.55 + CMPIResourceFT* ft; /* Pointer to the resource specific function table. */ 11.56 +} CMPIResource; 11.57 + 11.58 +/* ------------------------------------------------------------------------- */ 11.59 +/* The generic CMPILR resource-agnostic CMPI instance provider functions. */ 11.60 +/* ------------------------------------------------------------------------- */ 11.61 + 11.62 +CMPIStatus CMPILR_cleanup 11.63 + (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating); 11.64 + 11.65 +CMPIStatus CMPILR_enumInstanceNames 11.66 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.67 + const CMPIObjectPath* ref); 11.68 + 11.69 +CMPIStatus CMPILR_enumInstanceNames 11.70 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.71 + const CMPIObjectPath* ref); 11.72 + 11.73 +CMPIStatus CMPILR_enumInstances 11.74 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.75 + const CMPIObjectPath* ref, const char** properties); 11.76 + 11.77 +CMPIStatus CMPILR_getInstance 11.78 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.79 + const CMPIObjectPath* ref, const char** properties); 11.80 + 11.81 +CMPIStatus CMPILR_createInstance 11.82 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.83 + const CMPIObjectPath* ref, const CMPIInstance* inst); 11.84 + 11.85 +CMPIStatus CMPILR_modifyInstance 11.86 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.87 + const CMPIObjectPath* ref, const CMPIInstance* inst, const char** properties); 11.88 + 11.89 +CMPIStatus CMPILR_deleteInstance 11.90 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.91 + const CMPIObjectPath* ref); 11.92 + 11.93 +CMPIStatus CMPILR_execQuery 11.94 + (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, 11.95 + const CMPIObjectPath* ref, const char* lang, const char* query); 11.96 + 11.97 +/* ------------------------------------------------------------------------- */ 11.98 +/* Macro generates the function table and _Create_InstanceMI provider entry */ 11.99 +/* point for a CMPILR instance provider. */ 11.100 +/* ------------------------------------------------------------------------- */ 11.101 + 11.102 +#define CMPILRInstanceMIStub(cn,pn,mi) \ 11.103 +static CMPIResourceFT resFT = {\ 11.104 + load,\ 11.105 + unload,\ 11.106 + beginEnum,\ 11.107 + endEnum,\ 11.108 + getNext,\ 11.109 + get,\ 11.110 + release,\ 11.111 + add,\ 11.112 + delete,\ 11.113 + modify,\ 11.114 + res2inst,\ 11.115 + inst2res,\ 11.116 +};\ 11.117 +static CMPIResource res = {\ 11.118 + NULL,\ 11.119 + NULL,\ 11.120 + #cn,\ 11.121 + &resFT,\ 11.122 +};\ 11.123 +static CMPIInstanceMIFT instMIFT = {\ 11.124 + CMPICurrentVersion,\ 11.125 + CMPICurrentVersion,\ 11.126 + "instance" #pn,\ 11.127 + CMPILR_cleanup,\ 11.128 + CMPILR_enumInstanceNames,\ 11.129 + CMPILR_enumInstances,\ 11.130 + CMPILR_getInstance,\ 11.131 + CMPILR_createInstance,\ 11.132 + CMPILR_modifyInstance,\ 11.133 + CMPILR_deleteInstance,\ 11.134 + CMPILR_execQuery,\ 11.135 +};\ 11.136 +EXTERN_C \ 11.137 +CMPIInstanceMI* pn##_Create_InstanceMI(const CMPIBroker* brkr, const CMPIContext* ctx){\ 11.138 + static CMPIInstanceMI instMI = {\ 11.139 + (void*)&res,\ 11.140 + &instMIFT,\ 11.141 + };\ 11.142 + mi = &instMI;\ 11.143 + ((CMPIResource*)instMI.hdl)->brkr = brkr;\ 11.144 + if (!((CMPIResource*)instMI.hdl)->ft->load()) {\ 11.145 + return NULL;\ 11.146 + }\ 11.147 + return &instMI;\ 11.148 +}; 11.149 + 11.150 + 11.151 +#endif /* __CMPILR_H__ */
12.1 --- a/src/cmpitrace.c Mon Apr 30 10:27:59 2007 -0600 12.2 +++ b/src/cmpitrace.c Wed May 09 17:24:20 2007 -0600 12.3 @@ -34,10 +34,10 @@ 12.4 #include "cmpitrace.h" 12.5 12.6 /* Maximum length of trace message text. */ 12.7 -#define _MAXLENGTH 4096 12.8 +#define _MAXLENGTH 2048 12.9 12.10 /* By default log all trace messages. */ 12.11 -int _SBLIM_TRACE_LEVEL = 0xff; 12.12 +int _SBLIM_TRACE_LEVEL = _SBLIM_TRACE_LEVEL_ALL; 12.13 12.14 /* By default log trace messages to stderr. */ 12.15 static char * _SBLIM_TRACE_FILE = NULL; 12.16 @@ -103,8 +103,26 @@ void _sblim_trace( int level, char * src 12.17 /* Strip off the directory path from the compile-time src filename. */ 12.18 if (index(srcfile,'/') != NULL) srcfile = index(srcfile,'/')+1; 12.19 12.20 + char *level_str; 12.21 + switch (level) { 12.22 + case _SBLIM_TRACE_LEVEL_ERROR: 12.23 + level_str = "ERROR"; 12.24 + break; 12.25 + case _SBLIM_TRACE_LEVEL_WARNING: 12.26 + level_str = "WARNING"; 12.27 + break; 12.28 + case _SBLIM_TRACE_LEVEL_INFO: 12.29 + level_str = "INFO"; 12.30 + break; 12.31 + case _SBLIM_TRACE_LEVEL_DEBUG: 12.32 + level_str = "DEBUG"; 12.33 + break; 12.34 + default: 12.35 + level_str = "DEBUG"; 12.36 + } 12.37 + 12.38 /* Format and print the trace message. */ 12.39 - fprintf(ferr, "[%i] [%s] %d --- %s(%i) : %s\n", level, tm, pid, srcfile, srcline, msg); 12.40 + fprintf(ferr, "[%s] [%s] %d --- %s(%i) : %s\n", level_str, tm, pid, srcfile, srcline, msg); 12.41 if (tm != NULL) free(tm); 12.42 12.43 if ((_SBLIM_TRACE_FILE != NULL)) fclose(ferr);
13.1 --- a/src/cmpitrace.h Mon Apr 30 10:27:59 2007 -0600 13.2 +++ b/src/cmpitrace.h Wed May 09 17:24:20 2007 -0600 13.3 @@ -23,8 +23,18 @@ 13.4 // http://sblim.sourceforge.net/ 13.5 // ============================================================================ 13.6 13.7 +#if !defined(__CMPITRACE_H__) 13.8 +#define __CMPITRACE_H__ 13.9 + 13.10 #include <stdlib.h> 13.11 13.12 +#define _SBLIM_TRACE_LEVEL_ALL 0xff 13.13 +#define _SBLIM_TRACE_LEVEL_DEBUG _SBLIM_TRACE_LEVEL_ALL 13.14 +#define _SBLIM_TRACE_LEVEL_INFO 0x03 13.15 +#define _SBLIM_TRACE_LEVEL_WARNING 0x02 13.16 +#define _SBLIM_TRACE_LEVEL_ERROR 0x01 13.17 + 13.18 + 13.19 #ifdef SBLIM_DEBUG 13.20 13.21 /* Setup _SBLIM_TRACE() macros. */ 13.22 @@ -35,27 +45,27 @@ 13.23 13.24 #define _SBLIM_ENTER( f ) \ 13.25 char * __func_ = f; \ 13.26 - _SBLIM_TRACE(1,("Entering %s()", __func_)); 13.27 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("Entering %s()", __func_)); 13.28 13.29 #define _SBLIM_EXIT() { \ 13.30 - _SBLIM_TRACE(1,("Exiting %s()", __func_)); \ 13.31 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("Exiting %s()", __func_)); \ 13.32 return; } 13.33 13.34 #define _SBLIM_RETURN( v ) { \ 13.35 - _SBLIM_TRACE(1,("Exiting %s()", __func_)); \ 13.36 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("Exiting %s()", __func_)); \ 13.37 return v; } 13.38 13.39 #define _SBLIM_RETURNSTATUS( s ) { \ 13.40 - _SBLIM_TRACE(1,("Exiting %s()=%s", __func_, (s.rc == CMPI_RC_OK)? "OK":"Failed")); \ 13.41 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("Exiting %s()=%s", __func_, (s.rc == CMPI_RC_OK)? "OK":"Failed")); \ 13.42 return s; } 13.43 13.44 #define _SBLIM_ABORT() { \ 13.45 - _SBLIM_TRACE(1,("Aborting %s()", __func_)); \ 13.46 + _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO,("Aborting %s()", __func_)); \ 13.47 abort(); } 13.48 13.49 #define _SBLIM_TRACE_FUNCTION( LEVEL, f ) \ 13.50 if ((LEVEL <= _SBLIM_TRACE_LEVEL) && (LEVEL > 0)) { \ 13.51 - _SBLIM_TRACE(1,("Calling trace function %f()", #f)); \ 13.52 + _SBLIM_TRACE(LEVEL,("Calling trace function %f()", #f)); \ 13.53 {f;} } 13.54 13.55 #else /* #ifdef SBLIM_DEBUG */ 13.56 @@ -76,3 +86,5 @@ extern int _SBLIM_TRACE_LEVEL; 13.57 extern void _sblim_trace( int level, char * file, int line, char * msg ); 13.58 extern char * _sblim_format_trace( char * fmt, ... ); 13.59 13.60 + 13.61 +#endif /* __CMPITRACE_H__ */
14.1 --- a/src/xen_utils.c Mon Apr 30 10:27:59 2007 -0600 14.2 +++ b/src/xen_utils.c Wed May 09 17:24:20 2007 -0600 14.3 @@ -265,8 +265,6 @@ static int xen_utils_xend_connect_unix(c 14.4 } 14.5 14.6 14.7 - 14.8 - 14.9 /* 14.10 * Callback function invoked by libxenapi when the libraray 14.11 * has data to send. 14.12 @@ -370,6 +368,34 @@ static int xen_utils_get_session(xen_uti 14.13 14.14 14.15 /* 14.16 + * Generate exported functions for concatenating lists of references. 14.17 + */ 14.18 +XEN_UTILS_REF_LIST_CONCAT(xen_vm) 14.19 +XEN_UTILS_REF_LIST_CONCAT(xen_vdi) 14.20 +XEN_UTILS_REF_LIST_CONCAT(xen_vbd) 14.21 +XEN_UTILS_REF_LIST_CONCAT(xen_vif) 14.22 + 14.23 + 14.24 +/* 14.25 + * Generate exported functions for adding a reference (e.g. xen_vm) to a list 14.26 + * of references. 14.27 + */ 14.28 +XEN_UTILS_REF_LIST_ADD(xen_vm) 14.29 +XEN_UTILS_REF_LIST_ADD(xen_vdi) 14.30 +XEN_UTILS_REF_LIST_ADD(xen_vbd) 14.31 +XEN_UTILS_REF_LIST_ADD(xen_vif) 14.32 + 14.33 + 14.34 +/* 14.35 + * Generate exported functions for adding a device (e.g. vbd) to a list 14.36 + * of such devices. 14.37 + */ 14.38 +XEN_UTILS_DEV_LIST_ADD(xen_vdi_record) 14.39 +XEN_UTILS_DEV_LIST_ADD(xen_vbd_record) 14.40 +XEN_UTILS_DEV_LIST_ADD(xen_vif_record) 14.41 + 14.42 + 14.43 +/* 14.44 * Initialize a session with Xen. Providers should acquire a Xen 14.45 * Session when loaded into the cimom, i.e. when the provider's 14.46 * Initialize() method is invoked by the cimom. 14.47 @@ -682,25 +708,28 @@ int xen_utils_is_domain_active(xen_utils 14.48 return 1; 14.49 } 14.50 14.51 + 14.52 /* 14.53 - * Extract the value from a string map given a key 14.54 + * Extract a value with given key. 14.55 + * Returns pointer to value on success, NULL on failure. 14.56 * 14.57 */ 14.58 -int xen_utils_get_value_from_map(xen_string_string_map *map, const char *key, char *val) 14.59 +char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key) 14.60 { 14.61 - int i=0; 14.62 + int i = 0; 14.63 // Make sure you have a good value 14.64 - if(!map) return 0; 14.65 + if(!map) 14.66 + return NULL; 14.67 + 14.68 // String map is empty 14.69 - if (map->size==0) return 0; 14.70 - while (i<map->size) 14.71 - { // Found key 14.72 - if (strcmp(key, map->contents[i].key)==0) 14.73 - { 14.74 - val=strdup(map->contents[i].val); 14.75 - return 1; 14.76 - } 14.77 - i++; 14.78 + if (map->size == 0) 14.79 + return NULL; 14.80 + 14.81 + while (i < map->size) { 14.82 + if (strcmp(key, map->contents[i].key) == 0) 14.83 + return map->contents[i].val; 14.84 + i++; 14.85 } 14.86 - return 0; 14.87 -} 14.88 \ No newline at end of file 14.89 + 14.90 + return NULL; 14.91 +}
15.1 --- a/src/xen_utils.h Mon Apr 30 10:27:59 2007 -0600 15.2 +++ b/src/xen_utils.h Wed May 09 17:24:20 2007 -0600 15.3 @@ -27,6 +27,10 @@ 15.4 15.5 #include <xen_common.h> 15.6 #include <xen_vm.h> 15.7 +#include <xen_vdi.h> 15.8 +#include <xen_vbd.h> 15.9 +#include <xen_vif.h> 15.10 + 15.11 15.12 #include <cmpidt.h> 15.13 15.14 @@ -87,6 +91,127 @@ typedef struct { 15.15 15.16 15.17 /* 15.18 + * This macro can be used to generate functions for concatenating lists of 15.19 + * Xen API reference objects (UUIDs). This macro is used in xen_utils.c to 15.20 + * generate the xen_*_set_concat() functions declared below. 15.21 + */ 15.22 +#define XEN_UTILS_REF_LIST_CONCAT(type__) \ 15.23 +int type__ ## _set_concat(type__ ## _set **target, type__ ## _set *source) \ 15.24 +{ \ 15.25 + int total_size; \ 15.26 + int i, j; \ 15.27 + /* Nothing to concatenate if source is empty */ \ 15.28 + if (source == NULL || source->size == 0) \ 15.29 + return 1; \ 15.30 + /* If targe is empty, assign source to target */ \ 15.31 + if (*target == NULL) { \ 15.32 + *target = source; \ 15.33 + return 1; \ 15.34 + } \ 15.35 + /* realloc memory and append source to target */ \ 15.36 + total_size = (*target)->size + source->size; \ 15.37 + *target = realloc(*target, sizeof(type__ ## _set) + \ 15.38 + (total_size * sizeof(type__))); \ 15.39 + if (*target == NULL) \ 15.40 + return 0; \ 15.41 + for (j = (*target)->size, i = 0; i < source->size; i++) { \ 15.42 + (*target)->contents[j + i] = source->contents[i]; \ 15.43 + source->contents[i] = NULL; \ 15.44 + } \ 15.45 + (*target)->size = total_size; \ 15.46 + /* Free source list - it has been copied to target */ \ 15.47 + type__ ## _set_free(source); \ 15.48 + return 1; \ 15.49 +} 15.50 + 15.51 + 15.52 +int xen_vm_set_concat(xen_vm_set **target, xen_vm_set *source); 15.53 +int xen_vdi_set_concat(xen_vdi_set **target, xen_vdi_set *source); 15.54 +int xen_vbd_set_concat(xen_vbd_set **target, xen_vbd_set *source); 15.55 +int xen_vif_set_concat(xen_vif_set **target, xen_vif_set *source); 15.56 + 15.57 + 15.58 +/* 15.59 + * This macro can be used to generate functions for adding a Xen API 15.60 + * reference objects (UUIDs) to a list of UUIDs. Currently, libxenapi 15.61 + * does not support growing lists. For now, the macro is used in xen_utils.c to 15.62 + * generate the xen_*_set_add() functions declared below. 15.63 + * 15.64 + * TODO: 15.65 + * Submit this upstream so xen_*_set_add functions are available in 15.66 + * the c-bindings? 15.67 + */ 15.68 +#define XEN_UTILS_REF_LIST_ADD(type__) \ 15.69 +int type__ ## _set_add(type__ ## _set *list, type__ device) \ 15.70 +{ \ 15.71 + if (list == NULL) { \ 15.72 + list = type__ ## _set_alloc(1); \ 15.73 + if (list == NULL) \ 15.74 + return 0; \ 15.75 + list->size = 1; \ 15.76 + list->contents[0] = device; \ 15.77 + return 1; \ 15.78 + } \ 15.79 + \ 15.80 + /* List is not empty. Grow the list and add the new device */ \ 15.81 + int new_len = sizeof(type__ ## _set) + ((list->size + 1) * sizeof(type__)); \ 15.82 + list = realloc(list, new_len); \ 15.83 + if (list == NULL) \ 15.84 + return 0; \ 15.85 + list->contents[list->size] = device; \ 15.86 + list->size++; \ 15.87 + return 1; \ 15.88 +} 15.89 + 15.90 + 15.91 +int xen_vm_set_add(xen_vm_set *list, xen_vm vm); 15.92 +int xen_vdi_set_add(xen_vdi_set *list, xen_vdi vdi); 15.93 +int xen_vbd_set_add(xen_vbd_set *list, xen_vbd vbd); 15.94 +int xen_vif_set_add(xen_vif_set *list, xen_vif vif); 15.95 + 15.96 + 15.97 +/* 15.98 + * This macro can be used to generate functions for adding a Xen API 15.99 + * object to a list of such objects. Currently, libxenapi does not 15.100 + * support growing lists. For now, the macro is used in xen_utils.c to 15.101 + * generate the xen_*_set_add() functions declared below. 15.102 + * 15.103 + * TODO: 15.104 + * 1. It is very similar to above :-). I can't figure out a clean way to 15.105 + * handle slight difference (second parameter of the generated function). 15.106 + * 15.107 + * 2. Submit this upstream so xen_*_set_add functions are available in 15.108 + * the c-bindings? 15.109 + */ 15.110 +#define XEN_UTILS_DEV_LIST_ADD(type__) \ 15.111 +int type__ ## _set_add(type__ ## _set *list, type__ *device) \ 15.112 +{ \ 15.113 + if (list == NULL) { \ 15.114 + list = type__ ## _set_alloc(1); \ 15.115 + if (list == NULL) \ 15.116 + return 0; \ 15.117 + list->size = 1; \ 15.118 + list->contents[0] = device; \ 15.119 + return 1; \ 15.120 + } \ 15.121 + \ 15.122 + /* List is not empty. Grow the list and add the new device */ \ 15.123 + int new_len = sizeof(type__ ## _set) + ((list->size + 1) * sizeof(type__)); \ 15.124 + list = realloc(list, new_len); \ 15.125 + if (list == NULL) \ 15.126 + return 0; \ 15.127 + list->contents[list->size] = device; \ 15.128 + list->size++; \ 15.129 + return 1; \ 15.130 +} 15.131 + 15.132 + 15.133 +int xen_vdi_record_set_add(xen_vdi_record_set *list, xen_vdi_record *device); 15.134 +int xen_vbd_record_set_add(xen_vbd_record_set *list, xen_vbd_record *device); 15.135 +int xen_vif_record_set_add(xen_vif_record_set *list, xen_vif_record *device); 15.136 + 15.137 + 15.138 +/* 15.139 * Initialize a session with Xen. Providers should acquire a Xen 15.140 * Session when loaded into the cimom, i.e. when the provider's 15.141 * Initialize() method is invoked by the cimom. 15.142 @@ -180,10 +305,11 @@ int xen_utils_is_domain_active(xen_utils 15.143 15.144 15.145 /* 15.146 - * Extract the value from a string map given a key 15.147 + * Extract a value with given key. 15.148 + * Returns pointer to value on success, NULL on failure. 15.149 * 15.150 */ 15.151 -int xen_utils_get_value_from_map(xen_string_string_map *map, const char *key, char *val); 15.152 +char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key); 15.153 15.154 15.155