os-cmpi-xen

changeset 108:1ada37af7d08

Converted Xen_Disk to use new instance provider interface.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri May 11 13:14:41 2007 -0600 (2007-05-11)
parents 69ad830f2a6e
children 64e363d418df
files ChangeLog src/Makefile.am src/Xen_Disk.c src/Xen_Disk_Resource.c src/Xen_Disk_Resource.h
line diff
     1.1 --- a/ChangeLog	Fri May 11 13:09:28 2007 -0600
     1.2 +++ b/ChangeLog	Fri May 11 13:14:41 2007 -0600
     1.3 @@ -1,3 +1,12 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Fri May 11 13:11:08 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +        - Added function to tracing interface for tracing error
     1.8 +          descriptions in XenAPI session object.
     1.9 +        - Xen_DiskSettingData and Xen_VirtualSystemManagementCapabilities
    1.10 +          classes now use new tracing interface.
    1.11 +        - Converted Xen_Disk to new instance provider interface.
    1.12 +
    1.13  -------------------------------------------------------------------
    1.14  Wed May  9 18:01:49 MDT 2007 - jfehlig@novell.com
    1.15  
     2.1 --- a/src/Makefile.am	Fri May 11 13:09:28 2007 -0600
     2.2 +++ b/src/Makefile.am	Fri May 11 13:14:41 2007 -0600
     2.3 @@ -50,7 +50,6 @@ noinst_HEADERS = \
     2.4  	Xen_VirtualSystemManagementService_Resource.h \
     2.5  	Xen_Memory_Resource.h \
     2.6  	Xen_Processor_Resource.h \
     2.7 -	Xen_Disk_Resource.h \
     2.8  	Xen_NetworkPort_Resource.h \
     2.9  	Xen_Console_Resource.h \
    2.10  	Xen_VirtualizationCapabilities_Resource.h \
    2.11 @@ -185,7 +184,7 @@ libXen_ComputerSystemProcessor_la_SOURCE
    2.12  libXen_ComputerSystemProcessor_la_LIBADD = libXen_ProviderCommon.la
    2.13  libXen_ComputerSystemProcessor_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@
    2.14  
    2.15 -libXen_Disk_la_SOURCES = Xen_Disk.c Xen_Disk_Resource.c
    2.16 +libXen_Disk_la_SOURCES = Xen_Disk.c
    2.17  libXen_Disk_la_CFLAGS = -I../ @LIBXEN_CFLAGS@
    2.18  libXen_Disk_la_LIBADD = libXen_ProviderCommon.la
    2.19  libXen_Disk_la_LDFLAGS = -version-info @PROVIDER_VERSION_INFO@
     3.1 --- a/src/Xen_Disk.c	Fri May 11 13:09:28 2007 -0600
     3.2 +++ b/src/Xen_Disk.c	Fri May 11 13:14:41 2007 -0600
     3.3 @@ -1,4 +1,4 @@
     3.4 -// Copyright (C) 2006 IBM Corporation
     3.5 +// Copyright (C) 2007 Novell, Inc.
     3.6  //
     3.7  //    This library is free software; you can redistribute it and/or
     3.8  //    modify it under the terms of the GNU Lesser General Public
     3.9 @@ -17,607 +17,388 @@
    3.10  // Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    3.11  //                Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
    3.12  // Contributors:  Jim Fehlig, <jfehlig@novell.com>
    3.13 -// Description:
    3.14 +// Description:   A class used to represent a Xen virtual block device (vbd).
    3.15 +//
    3.16  // ============================================================================
    3.17  
    3.18 -/* Include the required CMPI data types, function headers, and macros */
    3.19 +/* Common declarations for each CMPI "Cimpler" instance provider */
    3.20 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    3.21  #include "cmpidt.h"
    3.22 -#include "cmpift.h"
    3.23  #include "cmpimacs.h"
    3.24 -
    3.25 -/* Include utility functions */
    3.26 -#include "cmpiutil.h"
    3.27 +#include "cmpilr.h"
    3.28  
    3.29 -/* Include _SBLIM_TRACE() logging support */
    3.30 -#include "cmpitrace.h"
    3.31  
    3.32 -/* Include Xen utilities */
    3.33 -#include "xen_utils.h"
    3.34 -
    3.35 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    3.36 -#include "Xen_Disk_Resource.h"
    3.37 +static const CMPIInstanceMI* mi;
    3.38  
    3.39  
    3.40 -// ----------------------------------------------------------------------------
    3.41 -// COMMON GLOBAL VARIABLES
    3.42 -// ----------------------------------------------------------------------------
    3.43 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    3.44 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    3.45 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    3.46 +
    3.47 +#include <stdlib.h>
    3.48 +
    3.49 +#include <xen_common.h>
    3.50 +#include <xen_vm.h>
    3.51 +#include <xen_vbd.h>
    3.52 +#include <xen_vdi.h>
    3.53 +#include <xen_string_string_map.h>
    3.54  
    3.55 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    3.56 -static const CMPIBroker *_BROKER;
    3.57 +#include "cmpitrace.h"
    3.58 +#include "xen_utils.h"
    3.59 +#include "provider_common.h"
    3.60 +
    3.61 +
    3.62 +/* C struct to store the data for all resources. */
    3.63 +typedef struct {
    3.64 +   xen_vbd_set *disks;
    3.65 +   unsigned int currentdisknum;
    3.66 +} _RESOURCES;
    3.67 +
    3.68  
    3.69  /* Xen session object.  Initialize when the provider is loaded, close when
    3.70   * provider unloaded. */
    3.71  static xen_utils_session *session = NULL;
    3.72  
    3.73  
    3.74 -// ============================================================================
    3.75 -// CMPI INSTANCE PROVIDER FUNCTION TABLE
    3.76 -// ============================================================================
    3.77 -
    3.78 -// ----------------------------------------------------------------------------
    3.79 -// Info for the class supported by the instance provider
    3.80 -// ----------------------------------------------------------------------------
    3.81 -
    3.82 -/* Name of the class implemented by this instance provider. */
    3.83 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    3.84 -static char * _CLASSNAME = "Xen_Disk";
    3.85 -
    3.86 -/* NULL terminated list of key properties of this class. */
    3.87 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    3.88 -const static char * _KEYNAMES[] = {"SystemName", "SystemCreationClassName", "DeviceID", "CreationClassName", NULL};
    3.89 +static int load()
    3.90 +{
    3.91 +   /* Initialized Xen session object. */
    3.92 +   if (!session)
    3.93 +      xen_utils_xen_init(&session);
    3.94  
    3.95 -// ----------------------------------------------------------------------------
    3.96 -// Cleanup()
    3.97 -// Perform any necessary cleanup immediately before this provider is unloaded.
    3.98 -// ----------------------------------------------------------------------------
    3.99 -static CMPIStatus Cleanup(
   3.100 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.101 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.102 -        CMPIBoolean terminating)   /* [in] True if MB is terminating */
   3.103 +   return 1;
   3.104 +}
   3.105 +
   3.106 +
   3.107 +static int unload(CMPIBoolean terminating)
   3.108  {
   3.109 -   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
   3.110 -
   3.111 -   _SBLIM_ENTER("Cleanup");
   3.112 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.113 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.114 -
   3.115 +   (void) terminating;
   3.116 +   
   3.117     if (session) {
   3.118        xen_utils_xen_close(session);
   3.119        session = NULL;
   3.120     }
   3.121 -   _SBLIM_RETURNSTATUS(status);
   3.122 +
   3.123 +   return 1;
   3.124  }
   3.125  
   3.126 -// ----------------------------------------------------------------------------
   3.127 -// EnumInstanceNames()
   3.128 -// Return a list of all the instances names (return their object paths only).
   3.129 -// ----------------------------------------------------------------------------
   3.130 -static CMPIStatus EnumInstanceNames(
   3.131 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.132 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.133 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.134 -		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   3.135 +
   3.136 +static void* beginEnum()
   3.137  {
   3.138 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.139 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.140 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.141 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.142 -   int found = 0;				/* Found any instances? */
   3.143 -  
   3.144 -   _SBLIM_ENTER("EnumInstanceNames");
   3.145 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.146 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.147 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.148 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.149 +   _RESOURCES *resources;
   3.150 +   xen_domain_resources *res = NULL;
   3.151 +   xen_vbd_set *all_disks = NULL;
   3.152 +   xen_vm_record *vm_rec = NULL;
   3.153 +   
   3.154 +   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
   3.155 +   if (resources == NULL)
   3.156 +      return NULL;
   3.157  
   3.158     if (!xen_utils_validate_session(&session)) {
   3.159 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.160 -      goto exit;
   3.161 -   }
   3.162 -
   3.163 -   /* Get a handle to the list of system resources. */
   3.164 -   if (!Xen_Disk_getResources(session, &resources)) {
   3.165 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.166 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.167 -      goto exit;
   3.168 -   }
   3.169 -
   3.170 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.171 -   while (Xen_Disk_getNextResource(session, resources, &resource)) {
   3.172 -      /* Create a new CMPIInstance to store this resource. */
   3.173 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.174 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.175 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.176 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.177 -         goto exit;
   3.178 -      }
   3.179 -
   3.180 -      /* Set the instance property values from the resource data. */
   3.181 -      if (!Xen_Disk_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.182 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.183 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.184 -         goto exit;
   3.185 -      }
   3.186 -
   3.187 -      /* Free the resource data. */
   3.188 -      if (!Xen_Disk_freeResource(resource)) {
   3.189 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.190 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.191 -         goto exit;
   3.192 -      }
   3.193 -
   3.194 -      /* Return the CMPIObjectPath for this instance. */
   3.195 -      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   3.196 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   3.197 -         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   3.198 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   3.199 -         goto exit;
   3.200 -      }
   3.201 -      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   3.202 -     
   3.203 -      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   3.204 -      CMReturnObjectPath(results, objectpath);
   3.205 -      found++;
   3.206 -   }
   3.207 -
   3.208 -   _SBLIM_TRACE(2,("--- %d object paths found", found));
   3.209 -   CMReturnDone(results);
   3.210 -
   3.211 -exit:
   3.212 -   /* Free the list of system resources. */
   3.213 -   if (!Xen_Disk_freeResources(resources)) {
   3.214 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.215 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.216 -   }
   3.217 -  
   3.218 -   _SBLIM_RETURNSTATUS(status);
   3.219 -}
   3.220 -
   3.221 -// ----------------------------------------------------------------------------
   3.222 -// EnumInstances()
   3.223 -// Return a list of all the instances (return all the instance data).
   3.224 -// ----------------------------------------------------------------------------
   3.225 -static CMPIStatus EnumInstances(
   3.226 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.227 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.228 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.229 -		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   3.230 -		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   3.231 -{
   3.232 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.233 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.234 -   _RESOURCE * resource;			/* Handle to each system resource. */
   3.235 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.236 -   int found = 0;				/* Found any resource instances? */
   3.237 -
   3.238 -   _SBLIM_ENTER("EnumInstances");
   3.239 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.240 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.241 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.242 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.243 -
   3.244 -   if (!xen_utils_validate_session(&session)) {
   3.245 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.246 -      goto exit;
   3.247 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.248 +                   ("--- Unable to establish connection with Xend"));
   3.249 +      return NULL;
   3.250     }
   3.251  
   3.252 -   /* Get a handle to the list of system resources. */
   3.253 -   if (!Xen_Disk_getResources(session, &resources)) {
   3.254 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.255 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.256 -      goto exit;
   3.257 -   }
   3.258 -
   3.259 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   3.260 -   while (Xen_Disk_getNextResource(session, resources, &resource)) {
   3.261 -      /* Create a new CMPIInstance to store this resource. */
   3.262 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.263 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.264 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.265 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.266 -         goto exit;
   3.267 -      }
   3.268 +   /* Get a list of domain resources. */
   3.269 +   if (!xen_utils_get_domain_resources(session, &res))
   3.270 +      goto Error;
   3.271  
   3.272 -      /* Setup a filter to only return the desired properties. */
   3.273 -      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.274 -      if (status.rc != CMPI_RC_OK) {
   3.275 -         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.276 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.277 -         goto exit;
   3.278 -      }
   3.279 -
   3.280 -      /* Set the instance property values from the resource data. */
   3.281 -      if (!Xen_Disk_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.282 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.283 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.284 -         goto exit;
   3.285 -      }
   3.286 -
   3.287 -      /* Free the resource data. */
   3.288 -      if (!Xen_Disk_freeResource(resource)) {
   3.289 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.290 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.291 -         goto exit;
   3.292 +   /* Create list of disk resources from disks found in each domain. */
   3.293 +   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   3.294 +      /* Ignore halted vms */
   3.295 +      if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) {
   3.296 +         xen_vm_record_free(vm_rec);
   3.297 +         continue;
   3.298        }
   3.299  
   3.300 -      /* Return the CMPIInstance for this instance. */
   3.301 -      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.302 -      CMReturnInstance(results, instance);
   3.303 -      found++;
   3.304 -   }
   3.305 -
   3.306 -   _SBLIM_TRACE(2,("--- %d instances found", found));
   3.307 -   CMReturnDone(results);
   3.308 -
   3.309 -exit:
   3.310 -   /* Free the list of system resources. */
   3.311 -   if (!Xen_Disk_freeResources(resources)) {
   3.312 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.313 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.314 +      xen_vbd_set *vbd_set;
   3.315 +      if (!xen_vm_get_vbds(session->xen, &vbd_set, vm_rec->handle))
   3.316 +         goto Error;
   3.317 +      
   3.318 +      if (!xen_vbd_set_concat(&all_disks, vbd_set))
   3.319 +         goto Error;
   3.320 +      
   3.321 +      xen_vm_record_free(vm_rec);
   3.322     }
   3.323 -
   3.324 -   _SBLIM_RETURNSTATUS(status);
   3.325 -}
   3.326 -
   3.327 -// ----------------------------------------------------------------------------
   3.328 -// GetInstance()
   3.329 -// Return the instance data for the specified instance only.
   3.330 -// ----------------------------------------------------------------------------
   3.331 -static CMPIStatus GetInstance(
   3.332 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.333 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.334 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.335 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.336 -		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   3.337 -{
   3.338 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.339 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.340 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.341 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.342 -   int found = 0;				/* Found the target instance? */
   3.343 -
   3.344 -   _SBLIM_ENTER("GetInstance");
   3.345 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.346 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.347 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.348 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.349 -
   3.350 -   if (!xen_utils_validate_session(&session)) {
   3.351 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.352 -      goto exit;
   3.353 -   }
   3.354 -
   3.355 -   /* Get a handle to the list of system resources. */
   3.356 -   if (!Xen_Disk_getResources(session, &resources)) {
   3.357 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.358 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.359 -      goto exit;
   3.360 -   }
   3.361 -
   3.362 -   /* Get the target resource. */
   3.363 -   found = Xen_Disk_getResourceForObjectPath(session, &resource, reference);
   3.364 -   if (!found || (resource == NULL)) {
   3.365 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.366 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.367 -      goto exit;
   3.368 -   }
   3.369 -
   3.370 -   /* Create a new CMPIInstance to store this resource. */
   3.371 -   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   3.372 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   3.373 -      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   3.374 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   3.375 -      goto exit;
   3.376 -   }
   3.377 -
   3.378 -   /* Setup a filter to only return the desired properties. */
   3.379 -   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   3.380 -   if (status.rc != CMPI_RC_OK) {
   3.381 -      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   3.382 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   3.383 -      goto exit;
   3.384 +   
   3.385 +   resources->disks = all_disks;
   3.386 +   resources->currentdisknum = 0;
   3.387 +   
   3.388 +   return resources;
   3.389 +   
   3.390 + Error:
   3.391 +   if (session && session->xen) {
   3.392 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.393 +                   ("--- failed to retrieve vbd resources from Xend:"));
   3.394 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.395 +                            xen_utils_trace_error(session->xen));
   3.396     }
   3.397  
   3.398 -   /* Set the instance property values from the resource data. */
   3.399 -   if (!Xen_Disk_setInstanceFromResource(session, resource, instance, _BROKER)) {
   3.400 -      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   3.401 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   3.402 -      goto exit;
   3.403 -   }
   3.404 -
   3.405 -   /* Free the resource data. */
   3.406 -   if (!Xen_Disk_freeResource(resource)) {
   3.407 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.408 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.409 -      goto exit;
   3.410 -   }
   3.411 -
   3.412 -   /* Return the CMPIInstance for this instance. */
   3.413 -   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   3.414 -   CMReturnInstance(results, instance);
   3.415 -
   3.416 -   _SBLIM_TRACE(2,("--- instance found"));
   3.417 -   CMReturnDone(results);
   3.418 -
   3.419 -exit:
   3.420 -   /* Free the list of system resources. */
   3.421 -   if (!Xen_Disk_freeResources(resources)) {
   3.422 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.423 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.424 -   }
   3.425 -
   3.426 -   _SBLIM_RETURNSTATUS(status);
   3.427 +   xen_vm_record_free(vm_rec);
   3.428 +   xen_utils_free_domain_resources(res);
   3.429 +   free(resources);
   3.430 +   return NULL;
   3.431  }
   3.432  
   3.433 -// ----------------------------------------------------------------------------
   3.434 -// SetInstance()
   3.435 -// Save modified instance data for the specified instance.
   3.436 -// ----------------------------------------------------------------------------
   3.437 -static CMPIStatus SetInstance(
   3.438 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.439 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.440 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.441 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.442 -		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   3.443 -        const char **properties)
   3.444 +
   3.445 +static void endEnum(void* res_list)
   3.446  {
   3.447 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.448 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.449 -   _RESOURCE * resource;	       		/* Handle to the system resource. */
   3.450 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.451 -   int found = 0;				/* Found the target instance? */
   3.452 -
   3.453 -   _SBLIM_ENTER("SetInstance");
   3.454 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.455 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.456 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.457 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.458 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.459 -
   3.460 -   if (!xen_utils_validate_session(&session)) {
   3.461 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.462 -      goto exit;
   3.463 -   }
   3.464 -
   3.465 -   /* Get a handle to the list of system resources. */
   3.466 -   if (!Xen_Disk_getResources(session, &resources)) {
   3.467 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.468 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.469 -      goto exit;
   3.470 +   _RESOURCES *resources = (_RESOURCES *)res_list;
   3.471 +   
   3.472 +   if (resources) {
   3.473 +      if (resources->disks)
   3.474 +          xen_vbd_set_free(resources->disks);
   3.475 +       free(resources);
   3.476     }
   3.477 -
   3.478 -   /* Get the target resource. */
   3.479 -   found = Xen_Disk_getResourceForObjectPath(session, &resource, reference);
   3.480 -   if (!found || (resource == NULL)) {
   3.481 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.482 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.483 -      goto exit;
   3.484 -   }
   3.485 -
   3.486 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.487 -
   3.488 -   /* Update the target resource data with the new instance property values. */
   3.489 -   int rc = Xen_Disk_setResourceFromInstance(resource, newinstance, _BROKER);
   3.490 -
   3.491 -   /* Free the resource data. */
   3.492 -   if (!Xen_Disk_freeResource(resource)) {
   3.493 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.494 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.495 -      goto exit;
   3.496 -   }
   3.497 -
   3.498 -   if (rc != 1) {
   3.499 -      if (rc == -1) {
   3.500 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   3.501 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.502 -      } else {
   3.503 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   3.504 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   3.505 -      }
   3.506 -      goto exit;
   3.507 -   }
   3.508 -
   3.509 -exit:
   3.510 -   /* Free the list of system resources. */
   3.511 -   if (!Xen_Disk_freeResources(resources)) {
   3.512 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.513 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.514 -   }
   3.515 -
   3.516 -   _SBLIM_RETURNSTATUS(status);
   3.517  }
   3.518  
   3.519 -// ----------------------------------------------------------------------------
   3.520 -// CreateInstance()
   3.521 -// Create a new instance from the specified instance data.
   3.522 -// ----------------------------------------------------------------------------
   3.523 -static CMPIStatus CreateInstance(
   3.524 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.525 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.526 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.527 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   3.528 -		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   3.529 +
   3.530 +static void* getNext(void* res_list)
   3.531  {
   3.532 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.533 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   3.534 -   _RESOURCE * resource;			/* Handle to the system resource. */
   3.535 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.536 -   int found = 0;				/* Found the target instance? */
   3.537 +   _RESOURCES *resources = (_RESOURCES *)res_list;
   3.538 +   xen_vbd_record *vbd_rec;
   3.539  
   3.540 -   _SBLIM_ENTER("CreateInstance");
   3.541 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.542 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.543 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.544 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   3.545 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.546 +   if (resources == NULL || resources->disks == NULL)
   3.547 +      return NULL;
   3.548 +
   3.549 +   /* Check if reached the end of the list of disks. */
   3.550 +   if (resources->currentdisknum == resources->disks->size)
   3.551 +      return NULL;
   3.552  
   3.553     if (!xen_utils_validate_session(&session)) {
   3.554 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.555 -      goto exit;
   3.556 -   }
   3.557 -
   3.558 -   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   3.559 -   reference = CMGetObjectPath(newinstance, NULL);
   3.560 -
   3.561 -   /* Get a handle to the list of system resources. */
   3.562 -   if (!Xen_Disk_getResources(session, &resources)) {
   3.563 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   3.564 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   3.565 -      goto exit;
   3.566 -   }
   3.567 -
   3.568 -   /* Get the target resource. */
   3.569 -   found = Xen_Disk_getResourceForObjectPath(session, &resource, reference);
   3.570 -
   3.571 -   /* Free the resource data. */
   3.572 -   if (!Xen_Disk_freeResource(resource)) {
   3.573 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   3.574 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   3.575 -      goto exit;
   3.576 -   }
   3.577 -
   3.578 -   if (found) {
   3.579 -      _SBLIM_TRACE(1,("--- Target instance already exists"));
   3.580 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   3.581 -      goto exit;
   3.582 -   }
   3.583 -
   3.584 -   /* Create a new resource with the new instance property values. */
   3.585 -   int rc = Xen_Disk_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   3.586 -   if (rc != 1) {
   3.587 -      if (rc == -1) {
   3.588 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   3.589 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.590 -      } else {
   3.591 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   3.592 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   3.593 -      }
   3.594 -      goto exit;
   3.595 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.596 +                   ("--- Unable to establish connection with Xend"));
   3.597 +      return NULL;
   3.598     }
   3.599  
   3.600 -   /* Return the object path for the newly created instance. */
   3.601 -   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   3.602 -   CMSetNameSpace(objectpath, namespace);
   3.603 -   CMReturnObjectPath(results, objectpath);
   3.604 -   CMReturnDone(results);
   3.605 +   /* Get the current disk record. */
   3.606 +   if (!xen_vbd_get_record(session->xen, &vbd_rec,
   3.607 +                           resources->disks->contents[resources->currentdisknum])) {
   3.608 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.609 +                   ("--- failed to retrieve vbd resources from Xend:"));
   3.610 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.611 +                            xen_utils_trace_error(session->xen));
   3.612 +      return NULL;
   3.613 +   }
   3.614 +   
   3.615 +   resources->currentdisknum++;
   3.616 +   return (void *)vbd_rec;
   3.617 +}
   3.618  
   3.619 -exit:
   3.620 -   /* Free the list of system resources. */
   3.621 -   if (!Xen_Disk_freeResources(resources)) {
   3.622 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   3.623 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   3.624 -   }
   3.625  
   3.626 -   _SBLIM_RETURNSTATUS(status);
   3.627 +static int get(void* res_list, void** res)
   3.628 +{
   3.629 +   if (res == NULL || *res == NULL)
   3.630 +      return 0;
   3.631 +   /*
   3.632 +    * WARNING!
   3.633 +    * What needs to be done here?  It looks as though inst2res() will have
   3.634 +    * been called on parameter res before a call to this function - in
   3.635 +    * which case res will be populated.
   3.636 +    */
   3.637 +   return 1;
   3.638  }
   3.639  
   3.640 -// ----------------------------------------------------------------------------
   3.641 -// DeleteInstance()
   3.642 -// Delete or remove the specified instance from the system.
   3.643 -// ----------------------------------------------------------------------------
   3.644 -static CMPIStatus DeleteInstance(
   3.645 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.646 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.647 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.648 -		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   3.649 +
   3.650 +static void release(void* res)
   3.651 +{
   3.652 +   xen_vbd_record_free(res);
   3.653 +}
   3.654 +
   3.655 +
   3.656 +static int add(void** res_list, void* res)
   3.657  {
   3.658 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   3.659 -   _RESOURCE * resource = NULL;		/* Handle to the system resource. */
   3.660 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.661 -   int found = 0;				/* Found the target instance? */
   3.662 -   char error_msg[XEN_UTILS_ERROR_BUF_LEN];
   3.663 -
   3.664 -   _SBLIM_ENTER("DeleteInstance");
   3.665 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.666 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.667 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.668 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.669 -
   3.670 +   xen_vbd_record *new_vbd_rec = (xen_vbd_record *)res;
   3.671 +   
   3.672 +   (void)res_list;
   3.673 +   
   3.674 +   if (new_vbd_rec == NULL || new_vbd_rec->vm == NULL)
   3.675 +      return 0;
   3.676 +   
   3.677     if (!xen_utils_validate_session(&session)) {
   3.678 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   3.679 -      goto exit;
   3.680 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.681 +                   ("--- Unable to establish connection with Xend"));
   3.682 +      return 0;
   3.683     }
   3.684  
   3.685 -   /* Get the target resource. */
   3.686 -   found = Xen_Disk_getResourceForObjectPath(session, &resource, reference);
   3.687 -   if (!found || (resource == NULL)) {
   3.688 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   3.689 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   3.690 -      goto exit;
   3.691 +   xen_vbd new_vbd;
   3.692 +   if (!xen_vbd_create(session->xen, &new_vbd, new_vbd_rec)) {
   3.693 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.694 +                   ("--- xen_vbd_create failed:"));
   3.695 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.696 +                            xen_utils_trace_error(session->xen));
   3.697 +      return 0;
   3.698     }
   3.699  
   3.700 -   _SBLIM_TRACE(2,("--- instance found", found));
   3.701 -
   3.702 -   /* Delete the target resource. */
   3.703 -   if (!Xen_Disk_deleteResource(session, resource)) {
   3.704 -      XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen);
   3.705 -      _SBLIM_TRACE(1,("--- deleteResource failed: %s", error_msg));
   3.706 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, error_msg);
   3.707 -      goto exit;
   3.708 -   }
   3.709 -
   3.710 -exit:
   3.711 -   /* Free the resource. */
   3.712 -   if (resource)
   3.713 -      Xen_Disk_freeResource(resource);
   3.714 -
   3.715 -   _SBLIM_RETURNSTATUS(status);
   3.716 +   xen_vbd_free(new_vbd);
   3.717 +   return 1;
   3.718  }
   3.719  
   3.720  
   3.721 -// ----------------------------------------------------------------------------
   3.722 -// ExecQuery()
   3.723 -// Return a list of all the instances that satisfy the specified query filter.
   3.724 -// ----------------------------------------------------------------------------
   3.725 -static CMPIStatus ExecQuery(
   3.726 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.727 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   3.728 -		const CMPIResult * results,		/* [out] Results of this operation. */
   3.729 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   3.730 -		const char * language,		/* [in] Name of the query language. */
   3.731 -		const char * query)			/* [in] Text of the query written in the query language. */
   3.732 +static int delete(void** res_list, void* res)
   3.733  {
   3.734 -   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   3.735 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   3.736 +   xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.737 +   
   3.738 +   (void)res_list;
   3.739 +   
   3.740 +   if (vbd_rec == NULL)
   3.741 +      return 0;
   3.742 +   
   3.743 +   if (!xen_utils_validate_session(&session)) {
   3.744 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.745 +                   ("--- Unable to establish connection with Xend"));
   3.746 +      return 0;
   3.747 +   }
   3.748  
   3.749 -   _SBLIM_ENTER("ExecQuery");
   3.750 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.751 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.752 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   3.753 -   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   3.754 -   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   3.755 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   3.756 +   if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) {
   3.757 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.758 +                   ("--- xen_vbd_create failed:"));
   3.759 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.760 +                            xen_utils_trace_error(session->xen));
   3.761 +      return 0;
   3.762 +   }
   3.763  
   3.764 -   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   3.765 -   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   3.766 +   return 1;
   3.767 +}
   3.768 +
   3.769  
   3.770 -   CMReturnDone(results);
   3.771 -
   3.772 -exit:
   3.773 -   _SBLIM_RETURNSTATUS(status);
   3.774 +static int modify(void** res_list, void* res)
   3.775 +{
   3.776 +   return -1; /* unsupported */
   3.777  }
   3.778  
   3.779 -// ----------------------------------------------------------------------------
   3.780 -// Initialize()
   3.781 -// Perform any necessary initialization immediately after this provider is
   3.782 -// first loaded.
   3.783 -// ----------------------------------------------------------------------------
   3.784 -static void Initialize(
   3.785 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   3.786 -		const CMPIContext * context)		/* [in] Additional context info, if any. */
   3.787 +
   3.788 +/* Set CMPIInstance properties from the resource data. */
   3.789 +static int res2inst(void* res, CMPIInstance* inst)
   3.790  {
   3.791 -   _SBLIM_ENTER("Initialize");
   3.792 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   3.793 -   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   3.794 +   xen_vm_record *alloced_vm_rec = NULL;
   3.795 +   xen_vm_record *vm_rec;
   3.796 +   xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.797 +   char buf[MAX_INSTANCEID_LEN];
   3.798 +   
   3.799 +   if (vbd_rec == NULL || CMIsNullObject(inst))
   3.800 +      return 0;
   3.801 +
   3.802 +   if (!xen_utils_validate_session(&session)) {
   3.803 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.804 +                   ("--- Unable to establish connection with Xend"));
   3.805 +      return 0;
   3.806 +   }
   3.807 +
   3.808 +   xen_vm_record_opt *vm_rec_opt = vbd_rec->vm;
   3.809 +   if (vm_rec_opt->is_record) {
   3.810 +      vm_rec = vm_rec_opt->u.record;
   3.811 +   }
   3.812 +   else {
   3.813 +      if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) {
   3.814 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.815 +                      ("--- xen_vm_get_record failed:"));
   3.816 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.817 +                               xen_utils_trace_error(session->xen));
   3.818 +         return 0;
   3.819 +      }
   3.820 +      alloced_vm_rec = vm_rec;
   3.821 +   }
   3.822  
   3.823 -   /* Initialized Xen session object. */
   3.824 -   if (session == NULL)
   3.825 -      xen_utils_xen_init(&session);
   3.826 +   CMSetProperty(inst, "SystemCreationClassName",
   3.827 +                 (CMPIValue *)"Xen_ComputerSystem", CMPI_chars);
   3.828 +   CMSetProperty(inst, "SystemName",
   3.829 +                 (CMPIValue *)vm_rec->name_label, CMPI_chars);
   3.830 +   CMSetProperty(inst, "CreationClassName",
   3.831 +                 (CMPIValue *)"Xen_Disk", CMPI_chars);
   3.832 +   CMSetProperty(inst, "DeviceID",
   3.833 +                 (CMPIValue *)vbd_rec->uuid, CMPI_chars);
   3.834 +   CMSetProperty(inst, "Caption",
   3.835 +                 (CMPIValue *)"Disk", CMPI_chars);
   3.836 +   CMSetProperty(inst, "Description",
   3.837 +                 (CMPIValue *)"Xen Virtual Disk", CMPI_chars);
   3.838 +   CMSetProperty(inst, "Purpose",
   3.839 +                 (CMPIValue *)"Virtual Disk for Xen Domain", CMPI_chars);
   3.840 +   CMSetProperty(inst, "Name",
   3.841 +                 (CMPIValue *)vbd_rec->device, CMPI_chars);
   3.842 +   CMSetProperty(inst, "DeviceName",
   3.843 +                 (CMPIValue *)vbd_rec->device, CMPI_chars);
   3.844  
   3.845 -   _SBLIM_RETURN();
   3.846 +   char *mode;
   3.847 +   int access;
   3.848 +   if (vbd_rec->mode == XEN_VBD_MODE_RW) {
   3.849 +      mode = "w";
   3.850 +      access = 3;
   3.851 +   }
   3.852 +   else {
   3.853 +      mode = "r";
   3.854 +      access = 1;
   3.855 +   }
   3.856 +   
   3.857 +   CMSetProperty(inst, "Mode",(CMPIValue *)mode, CMPI_chars);
   3.858 +   CMSetProperty(inst, "Access",(CMPIValue *)&access, CMPI_uint16);
   3.859 +
   3.860 +   xen_vdi_record_opt *vdi_rec_opt = vbd_rec->vdi;
   3.861 +   char *image;
   3.862 +   xen_string_string_map *vdi_params = NULL;
   3.863 +   if (xen_vdi_get_other_config(session->xen, &vdi_params, vdi_rec_opt->u.handle)) {
   3.864 +      if ((image = xen_utils_get_value_from_map(vdi_params, "location"))) {
   3.865 +         CMSetProperty(inst, "Device",(CMPIValue *)image, CMPI_chars);
   3.866 +         snprintf(buf, MAX_INSTANCEID_LEN, "%s,%s,%s",
   3.867 +                  image, vbd_rec->device, mode);
   3.868 +         CMSetProperty(inst, "DiskConfigInfo",(CMPIValue *)buf, CMPI_chars);
   3.869 +      }
   3.870 +   }
   3.871 +   
   3.872 +   xen_string_string_map_free(vdi_params);
   3.873 +
   3.874 +   if (vm_rec->power_state != XEN_VM_POWER_STATE_HALTED) {
   3.875 +      CMSetProperty(inst, "Status", (CMPIValue *)"OK", CMPI_chars);
   3.876 +   } else {
   3.877 +      CMSetProperty(inst, "Status", (CMPIValue *)"No Contact", CMPI_chars);
   3.878 +   }
   3.879 +
   3.880 +   if (alloced_vm_rec)
   3.881 +      xen_vm_record_free(alloced_vm_rec);
   3.882 +
   3.883 +   return 1;
   3.884  }
   3.885  
   3.886 -// ============================================================================
   3.887 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
   3.888 -// ============================================================================
   3.889 -CMInstanceMIStub( , Xen_Disk, _BROKER, Initialize(&mi, ctx));
   3.890 +
   3.891 +/* Set resource data from the CMPIInstance properties. */ 
   3.892 +static int inst2res(CMPIInstance* inst, void** res)
   3.893 +{
   3.894 +   CMPIData data;
   3.895 +   char *dev_uuid;
   3.896 +   char uuid[MAX_SYSTEM_NAME_LEN];
   3.897 +   int ccode;
   3.898 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   3.899 +
   3.900 +   if (CMIsNullObject(inst) || res == NULL)
   3.901 +      return 0;
   3.902 +
   3.903 +   data = CMGetProperty(inst, "DeviceID", &status);
   3.904 +   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.905 +      return 0;
   3.906 +
   3.907 +   dev_uuid = CMGetCharPtr(data.value.string);
   3.908 +   if ((dev_uuid == NULL) || (*dev_uuid == '\0'))
   3.909 +      return 0;
   3.910 +
   3.911 +   if (!xen_utils_validate_session(&session)) {
   3.912 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.913 +                   ("--- Unable to establish connection with Xend"));
   3.914 +      return 0;
   3.915 +   }
   3.916 +
   3.917 +   if (!xen_vbd_get_record(session->xen, (xen_vbd_record **)res, (xen_vbd)dev_uuid)) {
   3.918 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.919 +                   ("--- xen_vbd_destroy failed:"));
   3.920 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.921 +                            xen_utils_trace_error(session->xen));
   3.922 +      return 0;
   3.923 +   }
   3.924 +
   3.925 +   return 1;
   3.926 +}
   3.927 +
   3.928 +
   3.929 +/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   3.930 +/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   3.931 +CMPILRInstanceMIStub(Xen_Disk, Xen_Disk, mi)
     4.1 --- a/src/Xen_Disk_Resource.c	Fri May 11 13:09:28 2007 -0600
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,308 +0,0 @@
     4.4 -// Copyright (C) 2006 IBM Corporation
     4.5 -//
     4.6 -//    This library is free software; you can redistribute it and/or
     4.7 -//    modify it under the terms of the GNU Lesser General Public
     4.8 -//    License as published by the Free Software Foundation; either
     4.9 -//    version 2.1 of the License, or (at your option) any later version.
    4.10 -//
    4.11 -//    This library is distributed in the hope that it will be useful,
    4.12 -//    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.13 -//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.14 -//    Lesser General Public License for more details.
    4.15 -//
    4.16 -//    You should have received a copy of the GNU Lesser General Public
    4.17 -//    License along with this library; if not, write to the Free Software
    4.18 -//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.19 -// ============================================================================
    4.20 -// Authors:       Dr. Gareth S. Bestor, <bestor@us.ibm.com>
    4.21 -//                Tokunbo Adeshiyan, <tokunbo@us.ibm.com>
    4.22 -// Contributors:  Jim Fehlig, <jfehlig@novell.com>
    4.23 -// Description:
    4.24 -// ============================================================================
    4.25 -
    4.26 -#include <string.h>
    4.27 -#include <stdlib.h>
    4.28 -#include <assert.h>
    4.29 -
    4.30 -#include <xen_common.h>
    4.31 -#include <xen_vm.h>
    4.32 -#include <xen_vbd.h>
    4.33 -
    4.34 -#include "Xen_Disk_Resource.h"
    4.35 -
    4.36 -
    4.37 -/* Include the required CMPI data types, function headers, and macros. */
    4.38 -#include "cmpidt.h"
    4.39 -#include "cmpift.h"
    4.40 -#include "cmpimacs.h"
    4.41 -
    4.42 -#include "xen_utils.h"
    4.43 -
    4.44 -// ----------------------------------------------------------------------------
    4.45 -
    4.46 -static int concat_disk_lists(xen_vbd_set **target, xen_vbd_set *source)
    4.47 -{
    4.48 -
    4.49 -   int total_size;
    4.50 -   int i, j;
    4.51 -   
    4.52 -   /* Nothing to concatenate if source is empty */
    4.53 -   if (source == NULL || source->size == 0)
    4.54 -      return 1;
    4.55 -   
    4.56 -   /* If targe is empty, assign source to target */
    4.57 -   if (*target == NULL) {
    4.58 -      *target = source;
    4.59 -      return 1;
    4.60 -   }
    4.61 -   
    4.62 -   /* realloc memory and append source to target */
    4.63 -   total_size = (*target)->size + source->size;
    4.64 -   *target = realloc(*target, sizeof(xen_vbd_set) + (total_size * sizeof(xen_vbd)));
    4.65 -   if (*target == NULL)
    4.66 -      return 0;
    4.67 -   
    4.68 -   for (j = (*target)->size, i = 0; i < source->size; i++) {
    4.69 -      (*target)->contents[j + i] = source->contents[i];
    4.70 -      source->contents[i] = NULL;
    4.71 -   }
    4.72 -   (*target)->size = total_size;
    4.73 -   
    4.74 -   /* Free source list - it has been copied to target */
    4.75 -   xen_vbd_set_free(source);
    4.76 -   return 1;
    4.77 -}
    4.78 -
    4.79 -
    4.80 -/* Get a handle to the list of all system resources for this class. */
    4.81 -int Xen_Disk_getResources(xen_utils_session *session,
    4.82 -                          _RESOURCES ** resources)
    4.83 -{
    4.84 -   xen_domain_resources *res;
    4.85 -   xen_vbd_set *all_disks = NULL;
    4.86 -   xen_vm_record *vm_rec = NULL;
    4.87 -   
    4.88 -   /* malloc a new handle for the resources list. */
    4.89 -   *resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
    4.90 -   if (*resources == NULL)
    4.91 -      return 0;
    4.92 -
    4.93 -   /* Get a list of domain resources. */
    4.94 -   if (!xen_utils_get_domain_resources(session, &res)) {
    4.95 -      *resources = NULL;
    4.96 -      return 0;
    4.97 -   }
    4.98 -
    4.99 -   /* Create list of disk resources from disks found in each domain. */
   4.100 -   while (xen_utils_get_next_domain_resource(session, res, &vm_rec)) {
   4.101 -      /* Ignore halted vms */
   4.102 -      if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) {
   4.103 -         xen_vm_record_free(vm_rec);
   4.104 -         continue;
   4.105 -      }
   4.106 -      
   4.107 -      xen_vbd_set *vbd_set;
   4.108 -      if (!xen_vm_get_vbds(session->xen, &vbd_set, vm_rec->handle))
   4.109 -         goto Error;
   4.110 -      
   4.111 -      if (!concat_disk_lists(&all_disks, vbd_set))
   4.112 -         goto Error;
   4.113 -      
   4.114 -      xen_vm_record_free(vm_rec);
   4.115 -   }
   4.116 -   
   4.117 -   (*resources)->disks = all_disks;
   4.118 -   (*resources)->currentdisknum = 0;
   4.119 -   
   4.120 -   return 1;
   4.121 -   
   4.122 - Error:
   4.123 -   xen_vm_record_free(vm_rec);
   4.124 -   xen_utils_free_domain_resources(res);
   4.125 -   free(*resources);
   4.126 -   *resources = NULL;
   4.127 -   return 0;
   4.128 -}
   4.129 -
   4.130 -// ----------------------------------------------------------------------------
   4.131 -
   4.132 -/* Free/deallocate/cleanup the resources list after use. */
   4.133 -int Xen_Disk_freeResources(_RESOURCES * resources)
   4.134 -{
   4.135 -   if (resources != NULL) {
   4.136 -       if (resources->disks != NULL)
   4.137 -          xen_vbd_set_free(resources->disks);
   4.138 -       free(resources);
   4.139 -       resources = NULL;
   4.140 -   }
   4.141 -   
   4.142 -   return 1;
   4.143 -}
   4.144 -
   4.145 -// ----------------------------------------------------------------------------
   4.146 -
   4.147 -/* Iterator to get the next resource from the resources list. */
   4.148 -int Xen_Disk_getNextResource(xen_utils_session *session,
   4.149 -                             _RESOURCES * resources,
   4.150 -                             _RESOURCE ** resource)
   4.151 -{
   4.152 -   if (resources == NULL || resources->disks == NULL)
   4.153 -      return 0;
   4.154 -
   4.155 -   /* Check if reached the end of the list of disks. */
   4.156 -   if (resources->currentdisknum == resources->disks->size)
   4.157 -      return 0;
   4.158 -
   4.159 -   /* Get the current disk record. */
   4.160 -   if (!xen_vbd_get_record(session->xen, resource, resources->disks->contents[resources->currentdisknum]))
   4.161 -      return 0;
   4.162 -   
   4.163 -   resources->currentdisknum++;
   4.164 -   return 1;
   4.165 -}
   4.166 -
   4.167 -// ----------------------------------------------------------------------------
   4.168 -
   4.169 -/* Get the specific resource that matches the CMPI object path. */
   4.170 -int Xen_Disk_getResourceForObjectPath(xen_utils_session *session,
   4.171 -                                      _RESOURCE ** resource,
   4.172 -                                      const CMPIObjectPath * objectpath)
   4.173 -{
   4.174 -   CMPIData namedata;
   4.175 -   char *keyvalue;
   4.176 -   int ccode;
   4.177 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   4.178 -
   4.179 -   if (CMIsNullObject(objectpath)) return 0;
   4.180 -
   4.181 -   /* Get the disk resource based on DeviceID (disk uuid) */
   4.182 -   namedata = CMGetKey(objectpath, "DeviceID", &status);
   4.183 -   if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata))
   4.184 -      return 0;
   4.185 -
   4.186 -   keyvalue = CMGetCharPtr(namedata.value.string);
   4.187 -   if ((keyvalue == NULL) || (*keyvalue == '\0'))
   4.188 -      return 0;
   4.189 -
   4.190 -   xen_vbd vbd;
   4.191 -   if (!xen_vbd_get_by_uuid(session->xen, &vbd, keyvalue))
   4.192 -      return 0;
   4.193 -      
   4.194 -   ccode = xen_vbd_get_record(session->xen, resource, vbd);
   4.195 -   xen_vbd_free(vbd);
   4.196 -   return ccode;
   4.197 -}
   4.198 -
   4.199 -// ----------------------------------------------------------------------------
   4.200 -
   4.201 -/* Free/deallocate/cleanup the resource after use. */
   4.202 -int Xen_Disk_freeResource(_RESOURCE * resource)
   4.203 -{
   4.204 -   xen_vbd_record_free(resource);
   4.205 -   return 1;
   4.206 -}
   4.207 -
   4.208 -// ---------------------------------------------------------------------------- 
   4.209 -
   4.210 -/* Set the property values of a CMPI instance from a specific resource. */
   4.211 -int Xen_Disk_setInstanceFromResource(xen_utils_session *session,
   4.212 -                                     _RESOURCE * resource,
   4.213 -                                     const CMPIInstance * instance,
   4.214 -                                     const CMPIBroker * broker)
   4.215 -{
   4.216 -   xen_vm_record *alloced_vm_rec = NULL;
   4.217 -   xen_vm_record *vm_rec;
   4.218 -   
   4.219 -   if (resource == NULL) return 0;
   4.220 -   if (CMIsNullObject(instance)) return 0;
   4.221 -
   4.222 -   xen_vm_record_opt *vm_rec_opt = resource->vm;
   4.223 -   if (vm_rec_opt->is_record) {
   4.224 -      vm_rec = vm_rec_opt->u.record;
   4.225 -   }
   4.226 -   else {
   4.227 -      if (!xen_vm_get_record(session->xen, &vm_rec, vm_rec_opt->u.handle)) {
   4.228 -      /* Error description in session object! */
   4.229 -         return 0;
   4.230 -      }
   4.231 -      alloced_vm_rec = vm_rec;
   4.232 -   }
   4.233 -
   4.234 -   /* Set the CMPIInstance properties from the resource data. */
   4.235 -   CMSetProperty(instance, "SystemCreationClassName",(CMPIValue *)"Xen_ComputerSystem", CMPI_chars);
   4.236 -   CMSetProperty(instance, "SystemName",(CMPIValue *)vm_rec->name_label, CMPI_chars);
   4.237 -   CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_Disk", CMPI_chars);
   4.238 -   
   4.239 -   CMSetProperty(instance, "DeviceID",(CMPIValue *)resource->uuid, CMPI_chars);
   4.240 -
   4.241 -   CMSetProperty(instance, "Caption",(CMPIValue *)"Disk", CMPI_chars);
   4.242 -   CMSetProperty(instance, "Description",(CMPIValue *)"Disk", CMPI_chars);
   4.243 -   CMSetProperty(instance, "Purpose",(CMPIValue *)"Disk", CMPI_chars);
   4.244 -
   4.245 -   CMSetProperty(instance, "Name",(CMPIValue *)resource->device, CMPI_chars);
   4.246 -
   4.247 -   //CMSetProperty(instance, "Device",(CMPIValue *)resource->image, CMPI_chars); VDI <-> VBD issue
   4.248 -   CMSetProperty(instance, "DeviceName",(CMPIValue *)resource->device, CMPI_chars);
   4.249 -
   4.250 -   char *mode;
   4.251 -   int access;
   4.252 -   if (resource->mode == XEN_VBD_MODE_RW) {
   4.253 -      mode = "w";
   4.254 -      access = 3;
   4.255 -   }
   4.256 -   else {
   4.257 -      mode = "r";
   4.258 -      access = 1;
   4.259 -   }
   4.260 -   
   4.261 -   CMSetProperty(instance, "Mode",(CMPIValue *)mode, CMPI_chars);
   4.262 -   CMSetProperty(instance, "Access",(CMPIValue *)&access, CMPI_uint16);
   4.263 -
   4.264 -   char diskinfo[1024];
   4.265 -   //snprintf(diskinfo, 1024, "%s,%s,%s", resource->image, resource->device, mode); VDI<->VBD issue
   4.266 -   CMSetProperty(instance, "DiskConfigInfo",(CMPIValue *)diskinfo, CMPI_chars);
   4.267 -
   4.268 -   if (vm_rec->power_state != XEN_VM_POWER_STATE_HALTED) {
   4.269 -      CMSetProperty(instance, "Status", (CMPIValue *)"OK", CMPI_chars);
   4.270 -   } else {
   4.271 -      CMSetProperty(instance, "Status", (CMPIValue *)"No Contact", CMPI_chars);
   4.272 -   }
   4.273 -
   4.274 -   if (alloced_vm_rec)
   4.275 -      xen_vm_record_free(alloced_vm_rec);
   4.276 -
   4.277 -   return 1;
   4.278 -}
   4.279 -
   4.280 -// ----------------------------------------------------------------------------
   4.281 -
   4.282 -/* Delete the specified resource from the system. */
   4.283 -int Xen_Disk_deleteResource(xen_utils_session *session,
   4.284 -                            _RESOURCE * resource)
   4.285 -{
   4.286 -   return xen_vbd_destroy(session->xen, resource->handle);
   4.287 -}
   4.288 -
   4.289 -// ----------------------------------------------------------------------------
   4.290 -
   4.291 -/* Modify the specified resource using the property values of a CMPI instance. */
   4.292 -int Xen_Disk_setResourceFromInstance(_RESOURCE * resource,
   4.293 -                                     const CMPIInstance * instance,
   4.294 -                                     const CMPIBroker * broker)
   4.295 -{
   4.296 -   /* Unsupported. */
   4.297 -   return -1;
   4.298 -}
   4.299 -
   4.300 -// ----------------------------------------------------------------------------
   4.301 -
   4.302 -/* Create a new resource using the property values of a CMPI instance. */
   4.303 -int Xen_Disk_createResourceFromInstance(_RESOURCES * resources,
   4.304 -                                        _RESOURCE ** resource,
   4.305 -                                        const CMPIInstance * instance,
   4.306 -                                        const CMPIBroker * broker)
   4.307 -{
   4.308 -   /* Unsupported. */
   4.309 -   return -1;
   4.310 -}
   4.311 -
     5.1 --- a/src/Xen_Disk_Resource.h	Fri May 11 13:09:28 2007 -0600
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,104 +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 required libxen headers. */
    5.27 -#include <xen_common.h>
    5.28 -#include <xen_vbd.h>
    5.29 -
    5.30 -#include "xen_utils.h"
    5.31 -
    5.32 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.33 -/* DEFINE A HANDLE TO REPRESENT THE 'LIST' OF ALL SYSTEM RESOURCES.
    5.34 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW THIS
    5.35 -   LIST IS IMPLEMENTED - IT MAY BE AN ARRAY, LINKED LIST, FILE, ETC.
    5.36 -   THIS HANDLE IS PASSED INTO THE APPROPRIATE RESOURCE ACCESS METHODS WHEN
    5.37 -   ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */
    5.38 -typedef struct {
    5.39 -   xen_vbd_set *disks;
    5.40 -   unsigned int currentdisknum;
    5.41 -} _RESOURCES;
    5.42 -
    5.43 -
    5.44 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.45 -/* DEFINE A HANDLE TO BE USED FOR EACH INSTANCE OF A SYSTEM RESOURCE.
    5.46 -   THE MAIN PROVIDER CODE DOES NOT NEED TO KNOW THE PARTICULARS OF HOW EACH
    5.47 -   RESOURCE IS REPRESENTED, BUT TYPICALLY IT IS A STRUCTURE MIRRORING THE
    5.48 -   PROPERTIES IN THE CIM CLASS. THIS HANDLE IS PASSED BETWEEN THE RESOURCE
    5.49 -   ACCESS METHODS WHEN MANIPULATING SPECIFIC RESOURCE INSTANCES. */
    5.50 -typedef xen_vbd_record  _RESOURCE;
    5.51 -
    5.52 -/* NOTHING BELOW THIS LINE SHOULD NEED TO BE CHANGED. */
    5.53 -
    5.54 -/* Include the required CMPI data types. */
    5.55 -#include "cmpidt.h"
    5.56 -
    5.57 -// ----------------------------------------------------------------------------
    5.58 -// Generic resource access methods for CMPI providers.
    5.59 -// Return value:
    5.60 -//	-1 = Unsupported
    5.61 -//	 0 = Failed
    5.62 -//	 1 = OK
    5.63 -// ----------------------------------------------------------------------------
    5.64 -
    5.65 -/* Get a handle to the list of all system resources for this class. */
    5.66 -int Xen_Disk_getResources(xen_utils_session *session,
    5.67 -                          _RESOURCES ** resources);
    5.68 -
    5.69 -/* Free/deallocate/cleanup the resources list after use. */
    5.70 -int Xen_Disk_freeResources(_RESOURCES * resources);
    5.71 -
    5.72 -/* Iterator to get the next resource from the resources list. */
    5.73 -int Xen_Disk_getNextResource(xen_utils_session *session,
    5.74 -                             _RESOURCES * resources,
    5.75 -                             _RESOURCE ** resource);
    5.76 -
    5.77 -/* Get the specific resource that matches the CMPI object path. */
    5.78 -int Xen_Disk_getResourceForObjectPath(xen_utils_session *session,
    5.79 -                                      _RESOURCE ** resource,
    5.80 -                                      const CMPIObjectPath * objectpath);
    5.81 -
    5.82 -/* Free/deallocate/cleanup a resource after use. */
    5.83 -int Xen_Disk_freeResource(_RESOURCE * resource);
    5.84 -
    5.85 -/* Set the property values of a CMPI instance from a specific resource. */
    5.86 -int Xen_Disk_setInstanceFromResource(xen_utils_session *session,
    5.87 -                                     _RESOURCE * resource,
    5.88 -                                     const CMPIInstance * instance,
    5.89 -                                     const CMPIBroker * broker);
    5.90 -
    5.91 -// THE FOLLOWING METHODS MAY/NOT BE SUPPORTED BY THE SYSTEM FOR THIS CLASS
    5.92 -
    5.93 -/* Delete the specified resource from the system. */
    5.94 -int Xen_Disk_deleteResource(xen_utils_session *session,
    5.95 -                            _RESOURCE * resource);
    5.96 -
    5.97 -/* Modify the specified resource using the property values of a CMPI instance. */
    5.98 -int Xen_Disk_setResourceFromInstance(_RESOURCE * resource,
    5.99 -                                     const CMPIInstance * instance,
   5.100 -                                     const CMPIBroker * broker);
   5.101 -
   5.102 -/* Create a new resource using the property values of a CMPI instance. */
   5.103 -int Xen_Disk_createResourceFromInstance(_RESOURCES * resources,
   5.104 -                                        _RESOURCE ** resource,
   5.105 -                                        const CMPIInstance * instance,
   5.106 -                                        const CMPIBroker * broker);
   5.107 -